diff --git a/frontend/src/app/shared/components/fields/macros/work-package-quickinfo-macro.component.ts b/frontend/src/app/shared/components/fields/macros/work-package-quickinfo-macro.component.ts
index e2d605349d82..840d6f5945af 100644
--- a/frontend/src/app/shared/components/fields/macros/work-package-quickinfo-macro.component.ts
+++ b/frontend/src/app/shared/components/fields/macros/work-package-quickinfo-macro.component.ts
@@ -91,7 +91,9 @@ export class WorkPackageQuickinfoMacroComponent implements OnInit {
ngOnInit() {
const element = this.elementRef.nativeElement as HTMLElement;
- const id:string = element.dataset.id!;
+ // Prefer `data-display-id`; fall back to `data-id` for legacy
+ // stored markdown emitted before the attribute split.
+ const id:string = element.dataset.displayId ?? element.dataset.id!;
this.detailed = element.dataset.detailed === 'true';
this.workPackageHoverCardUrl = this.pathHelper.workPackageHoverCardPath(id);
diff --git a/frontend/src/vendor/ckeditor/ckeditor.js b/frontend/src/vendor/ckeditor/ckeditor.js
index 9eade6d6bbc7..1c2d1da000a7 100644
--- a/frontend/src/vendor/ckeditor/ckeditor.js
+++ b/frontend/src/vendor/ckeditor/ckeditor.js
@@ -2,5 +2,5 @@
* @license Copyright (c) 2003-2026, CKSource Holding sp. z o.o. All rights reserved.
* For licensing, see LICENSE.md.
*/
-!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.OPEditor=t():e.OPEditor=t()}(self,(()=>(()=>{var e={428:e=>{var t=!0,o=!1,i=!1;function n(e,t,o){var i=e.attrIndex(t),n=[t,o];i<0?e.attrPush(n):e.attrs[i]=n}function s(e,t){for(var o=e[t].level-1,i=t-1;i>=0;i--)if(e[i].level===o)return i;return-1}function r(e,t){return"inline"===e[t].type&&function(e){return"paragraph_open"===e.type}(e[t-1])&&function(e){return"list_item_open"===e.type}(e[t-2])&&function(e){return 0===e.content.indexOf("[ ] ")||0===e.content.indexOf("[x] ")||0===e.content.indexOf("[X] ")}(e[t])}function a(e,n){if(e.children.unshift(function(e,o){var i=new o("html_inline","",0),n=t?' disabled="" ':"";0===e.content.indexOf("[ ] ")?i.content='':0!==e.content.indexOf("[x] ")&&0!==e.content.indexOf("[X] ")||(i.content='');return i}(e,n)),e.children[1].content=e.children[1].content.slice(3),e.content=e.content.slice(3),o)if(i){e.children.pop();var s="task-item-"+Math.ceil(1e7*Math.random()-1e3);e.children[0].content=e.children[0].content.slice(0,-1)+' id="'+s+'">',e.children.push(function(e,t,o){var i=new o("html_inline","",0);return i.content='",i.attrs=[{for:t}],i}(e.content,s,n))}else e.children.unshift(function(e){var t=new e("html_inline","",0);return t.content="",t}(n))}e.exports=function(e,l){l&&(t=!l.enabled,o=!!l.label,i=!!l.labelAfter),e.core.ruler.after("inline","github-task-lists",(function(e){for(var o=e.tokens,i=2;i{var i,n=function(){var e=String.fromCharCode,t="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",o="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+-$",i={};function n(e,t){if(!i[e]){i[e]={};for(var o=0;o>>8,o[2*i+1]=r%256}return o},decompressFromUint8Array:function(t){if(null==t)return s.decompress(t);for(var o=new Array(t.length/2),i=0,n=o.length;i>=1}else{for(n=1,i=0;i>=1}0==--u&&(u=Math.pow(2,m),m++),delete a[d]}else for(n=r[d],i=0;i>=1;0==--u&&(u=Math.pow(2,m),m++),r[c]=h++,d=String(l)}if(""!==d){if(Object.prototype.hasOwnProperty.call(a,d)){if(d.charCodeAt(0)<256){for(i=0;i>=1}else{for(n=1,i=0;i>=1}0==--u&&(u=Math.pow(2,m),m++),delete a[d]}else for(n=r[d],i=0;i>=1;0==--u&&(u=Math.pow(2,m),m++)}for(n=2,i=0;i>=1;for(;;){if(p<<=1,f==t-1){g.push(o(p));break}f++}return g.join("")},decompress:function(e){return null==e?"":""==e?null:s._decompress(e.length,32768,(function(t){return e.charCodeAt(t)}))},_decompress:function(t,o,i){var n,s,r,a,l,c,d,u=[],h=4,m=4,g=3,p="",f=[],b={val:i(0),position:o,index:1};for(n=0;n<3;n+=1)u[n]=n;for(r=0,l=Math.pow(2,2),c=1;c!=l;)a=b.val&b.position,b.position>>=1,0==b.position&&(b.position=o,b.val=i(b.index++)),r|=(a>0?1:0)*c,c<<=1;switch(r){case 0:for(r=0,l=Math.pow(2,8),c=1;c!=l;)a=b.val&b.position,b.position>>=1,0==b.position&&(b.position=o,b.val=i(b.index++)),r|=(a>0?1:0)*c,c<<=1;d=e(r);break;case 1:for(r=0,l=Math.pow(2,16),c=1;c!=l;)a=b.val&b.position,b.position>>=1,0==b.position&&(b.position=o,b.val=i(b.index++)),r|=(a>0?1:0)*c,c<<=1;d=e(r);break;case 2:return""}for(u[3]=d,s=d,f.push(d);;){if(b.index>t)return"";for(r=0,l=Math.pow(2,g),c=1;c!=l;)a=b.val&b.position,b.position>>=1,0==b.position&&(b.position=o,b.val=i(b.index++)),r|=(a>0?1:0)*c,c<<=1;switch(d=r){case 0:for(r=0,l=Math.pow(2,8),c=1;c!=l;)a=b.val&b.position,b.position>>=1,0==b.position&&(b.position=o,b.val=i(b.index++)),r|=(a>0?1:0)*c,c<<=1;u[m++]=e(r),d=m-1,h--;break;case 1:for(r=0,l=Math.pow(2,16),c=1;c!=l;)a=b.val&b.position,b.position>>=1,0==b.position&&(b.position=o,b.val=i(b.index++)),r|=(a>0?1:0)*c,c<<=1;u[m++]=e(r),d=m-1,h--;break;case 2:return f.join("")}if(0==h&&(h=Math.pow(2,g),g++),u[d])p=u[d];else{if(d!==m)return null;p=s+s.charAt(0)}f.push(p),u[m++]=s+p.charAt(0),s=p,0==--h&&(h=Math.pow(2,g),g++)}}};return s}();void 0===(i=function(){return n}.call(t,o,t,e))||(e.exports=i)}},t={};function o(i){var n=t[i];if(void 0!==n)return n.exports;var s=t[i]={exports:{}};return e[i](s,s.exports,o),s.exports}o.n=e=>{var t=e&&e.__esModule?()=>e.default:()=>e;return o.d(t,{a:t}),t},o.d=(e,t)=>{for(var i in t)o.o(t,i)&&!o.o(e,i)&&Object.defineProperty(e,i,{enumerable:!0,get:t[i]})},o.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),o.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var i={};return(()=>{"use strict";var e={};o.r(e),o.d(e,{decode:()=>qx,encode:()=>Wx,format:()=>Ux,parse:()=>sE});var t={};o.r(t),o.d(t,{Any:()=>lE,Cc:()=>cE,Cf:()=>dE,P:()=>rE,S:()=>aE,Z:()=>uE});var i={};o.r(i),o.d(i,{arrayReplaceAt:()=>LE,assign:()=>BE,escapeHtml:()=>QE,escapeRE:()=>XE,fromCodePoint:()=>jE,has:()=>NE,isMdAsciiPunct:()=>iT,isPunctChar:()=>oT,isSpace:()=>eT,isString:()=>FE,isValidEntityCode:()=>zE,isWhiteSpace:()=>tT,lib:()=>sT,normalizeReference:()=>nT,unescapeAll:()=>UE,unescapeMd:()=>WE});var n={};function s(e){return null!==e&&("object"==typeof e||"function"==typeof e)}function r(e){return"string"==typeof e||e instanceof String}function a(e){if("object"!=typeof e)return!1;if(null==e)return!1;if(null===Object.getPrototypeOf(e))return!0;if("[object Object]"!==Object.prototype.toString.call(e)){const t=e[Symbol.toStringTag];if(null==t)return!1;return!!Object.getOwnPropertyDescriptor(e,Symbol.toStringTag)?.writable&&e.toString()===`[object ${t}]`}let t=e;for(;null!==Object.getPrototypeOf(t);)t=Object.getPrototypeOf(t);return Object.getPrototypeOf(e)===t}function l(e){return Object.getOwnPropertySymbols(e).filter((t=>Object.prototype.propertyIsEnumerable.call(e,t)))}function c(e){return null==e?void 0===e?"[object Undefined]":"[object Null]":Object.prototype.toString.call(e)}o.r(n),o.d(n,{parseLinkDestination:()=>aT,parseLinkLabel:()=>rT,parseLinkTitle:()=>lT});const d="[object RegExp]",u="[object String]",h="[object Number]",m="[object Boolean]",g="[object Arguments]",p="[object Symbol]",f="[object Date]",b="[object Map]",w="[object Set]",y="[object Array]",k="[object ArrayBuffer]",v="[object Object]",C="[object DataView]",A="[object Uint8Array]",x="[object Uint8ClampedArray]",E="[object Uint16Array]",T="[object Uint32Array]",P="[object Int8Array]",S="[object Int16Array]",I="[object Int32Array]",R="[object Float32Array]",O="[object Float64Array]";function V(e){return null==e||"object"!=typeof e&&"function"!=typeof e}function D(e){return ArrayBuffer.isView(e)&&!(e instanceof DataView)}function F(e,t,o,i=new Map,n=void 0){const s=n?.(e,t,o,i);if(void 0!==s)return s;if(V(e))return e;if(i.has(e))return i.get(e);if(Array.isArray(e)){const t=new Array(e.length);i.set(e,t);for(let s=0;s{const r=t?.(o,i,n,s);if(void 0!==r)return r;if("object"==typeof e){if(c(e)===v&&"function"!=typeof e.constructor){const t={};return s.set(e,t),M(t,e,n,s),t}switch(Object.prototype.toString.call(e)){case h:case u:case m:{const t=new e.constructor(e?.valueOf());return M(t,e),t}case g:{const t={};return M(t,e),t.length=e.length,t[Symbol.iterator]=e[Symbol.iterator],t}default:return}}}))}function B(e){return"object"==typeof e&&null!==e}function L(e){return B(e)&&1===e.nodeType&&!a(e)}function z(e){return"function"==typeof e}function j(e){return N(e)}function q(e){return"__proto__"===e}function $(e){return null!==e&&"object"==typeof e&&"[object Arguments]"===c(e)}function H(e){return null!=e&&"function"!=typeof e&&function(e){return Number.isSafeInteger(e)&&e>=0}(e.length)}function W(e){return D(e)}function U(e,t,o,i){if(V(e)&&(e=Object(e)),null==t||"object"!=typeof t)return e;if(i.has(t))return function(e){if(V(e))return e;if(Array.isArray(e)||D(e)||e instanceof ArrayBuffer||"undefined"!=typeof SharedArrayBuffer&&e instanceof SharedArrayBuffer)return e.slice(0);const t=Object.getPrototypeOf(e);if(null==t)return Object.assign(Object.create(t),e);const o=t.constructor;if(e instanceof Date||e instanceof Map||e instanceof Set)return new o(e);if(e instanceof RegExp){const t=new o(e);return t.lastIndex=e.lastIndex,t}if(e instanceof DataView)return new o(e.buffer.slice(0));if(e instanceof Error){let t;return t=e instanceof AggregateError?new o(e.errors,e.message,{cause:e.cause}):new o(e.message,{cause:e.cause}),t.stack=e.stack,Object.assign(t,e),t}if("undefined"!=typeof File&&e instanceof File)return new o([e],e.name,{type:e.type,lastModified:e.lastModified});if("object"==typeof e){const o=Object.create(t);return Object.assign(o,e)}return e}(i.get(t));if(i.set(t,e),Array.isArray(t)){t=t.slice();for(let e=0;e-1}function ee(e){return e.indexOf("windows")>-1}function te(e){return!!e.match(/gecko\/\d+/)}function oe(e){return e.indexOf(" applewebkit/")>-1&&-1===e.indexOf("chrome")}function ie(e){return!!e.match(/iphone|ipad/i)||X(e)&&navigator.maxTouchPoints>0}function ne(e){return e.indexOf("android")>-1}function se(e){return e.indexOf("chrome/")>-1&&e.indexOf("edge/")<0}function re(){let e=!1;try{e=0==="ć".search(new RegExp("[\\p{L}]","u"))}catch{}return e}function ae(e,t,o,i){o=o||function(e,t){return e===t};const n=Array.isArray(e)?e:Array.prototype.slice.call(e),s=Array.isArray(t)?t:Array.prototype.slice.call(t),r=function(e,t,o){const i=le(e,t,o);if(-1===i)return{firstIndex:-1,lastIndexOld:-1,lastIndexNew:-1};const n=ce(e,i),s=ce(t,i),r=le(n,s,o),a=e.length-r,l=t.length-r;return{firstIndex:i,lastIndexOld:a,lastIndexNew:l}}(n,s,o),a=i?function(e,t){const{firstIndex:o,lastIndexOld:i,lastIndexNew:n}=e;if(-1===o)return Array(t).fill("equal");let s=[];o>0&&(s=s.concat(Array(o).fill("equal")));n-o>0&&(s=s.concat(Array(n-o).fill("insert")));i-o>0&&(s=s.concat(Array(i-o).fill("delete")));n0&&o.push({index:i,type:"insert",values:e.slice(i,s)});n-i>0&&o.push({index:i+(s-i),type:"delete",howMany:n-i});return o}(s,r);return a}function le(e,t,o){for(let i=0;i200||n>200||i+n>300)return de.fastDiff(e,t,o,!0);let s,r;if(nc?-1:1;d[i+h]&&(d[i]=d[i+h].slice(0)),d[i]||(d[i]=[]),d[i].push(n>c?s:r);let m=Math.max(n,c),g=m-i;for(;gc;m--)u[m]=h(m);u[c]=h(c),g++}while(u[c]!==l);return d[c].slice(1)}de.fastDiff=ae;class ue{source;name;path;stop;off;return;constructor(e,t){this.source=e,this.name=t,this.path=[],this.stop=function e(){e.called=!0},this.off=function e(){e.called=!0}}}const he=new Array(256).fill("").map(((e,t)=>("0"+t.toString(16)).slice(-2)));function me(){const[e,t,o,i]=crypto.getRandomValues(new Uint32Array(4));return"e"+he[255&e]+he[e>>8&255]+he[e>>16&255]+he[e>>24&255]+he[255&t]+he[t>>8&255]+he[t>>16&255]+he[t>>24&255]+he[255&o]+he[o>>8&255]+he[o>>16&255]+he[o>>24&255]+he[255&i]+he[i>>8&255]+he[i>>16&255]+he[i>>24&255]}const ge={get(e="normal"){return"number"!=typeof e?this[e]||this.normal:e},highest:1e5,high:1e3,normal:0,low:-1e3,lowest:-1e5};function pe(e,t){const o=ge.get(t.priority);let i=0,n=e.length;for(;i>1;ge.get(e[t].priority){if("object"==typeof t&&null!==t){if(i.has(t))return`[object ${t.constructor.name}]`;i.add(t)}return t},s=t?` ${JSON.stringify(t,n)}`:"",r=we(e),a=o?`\nOriginal error: ${o.name}: ${o.message}`:"";return e+s+r+a}(e,o,i)),this.name="CKEditorError",this.context=t,this.data=o,i&&(this.stack=i.stack)}is(e){return"CKEditorError"===e}static rethrowUnexpectedError(e,t){if(e.is&&e.is("CKEditorError"))throw e;throw new fe("unexpected-error",t,void 0,e)}}function be(e,t){console.warn(...ye(e,t))}function we(e){return`\nRead more: https://ckeditor.com/docs/ckeditor5/latest/support/error-codes.html#error-${e}`}function ye(e,t){const o=we(e);return t?[e,t,o]:[e,o]}const _e=new Date(2026,2,31);if(globalThis.CKEDITOR_VERSION)throw new fe("ckeditor-duplicated-modules",null);globalThis.CKEDITOR_VERSION="48.0.0";const ke=Symbol("listeningTo"),ve=Symbol("emitterId"),Ce=Symbol("delegations"),Ae=xe(Object);function xe(e){if(!e)return Ae;return class extends e{on(e,t,o){this.listenTo(this,e,t,o)}once(e,t,o){let i=!1;this.listenTo(this,e,((e,...o)=>{i||(i=!0,e.off(),t.call(this,e,...o))}),o)}off(e,t){this.stopListening(this,e,t)}listenTo(e,t,o,i={}){let n,s;this[ke]||(this[ke]={});const r=this[ke];Te(e)||Ee(e);const a=Te(e);(n=r[a])||(n=r[a]={emitter:e,callbacks:{}}),(s=n.callbacks[t])||(s=n.callbacks[t]=[]),s.push(o),function(e,t,o,i,n){t._addEventListener?t._addEventListener(o,i,n):e._addEventListener.call(t,o,i,n)}(this,e,t,o,i)}stopListening(e,t,o){const i=this[ke];let n=e&&Te(e);const s=i&&n?i[n]:void 0,r=s&&t?s.callbacks[t]:void 0;if(!(!i||e&&!s||t&&!r))if(o){Re(this,e,t,o);-1!==r.indexOf(o)&&(1===r.length?delete s.callbacks[t]:Re(this,e,t,o))}else if(r){for(;o=r.pop();)Re(this,e,t,o);delete s.callbacks[t]}else if(s){for(t in s.callbacks)this.stopListening(e,t);delete i[n]}else{for(n in i)this.stopListening(i[n].emitter);delete this[ke]}}fire(e,...t){try{const o=e instanceof ue?e:new ue(this,e),i=o.name;let n=function(e,t){if(!e._events)return null;let o=t;do{const t=e._events[o];if(t&&t.callbacks&&t.callbacks.length)return t.callbacks;const i=o.lastIndexOf(":");o=i>-1?o.substring(0,i):""}while(o);return null}(this,i);if(o.path.push(this),n){n=n.slice();for(let e=0;e{this[Ce]||(this[Ce]=new Map),e.forEach((e=>{const i=this[Ce].get(e);i?i.set(t,o):this[Ce].set(e,new Map([[t,o]]))}))}}}stopDelegating(e,t){if(this[Ce])if(e)if(t){const o=this[Ce].get(e);o&&o.delete(t)}else this[Ce].delete(e);else this[Ce].clear()}_addEventListener(e,t,o){!function(e,t){const o=Pe(e);if(o[t])return;let i=t,n=null;const s=[];for(;""!==i&&!o[i];)o[i]={callbacks:[],childEvents:[]},s.push(o[i]),n&&o[i].childEvents.push(n),n=i,i=i.substr(0,i.lastIndexOf(":"));if(""!==i){for(const e of s)e.callbacks=o[i].callbacks.slice();o[i].childEvents.push(n)}}(this,e);const i=Se(this,e),n={callback:t,priority:ge.get(o.priority)};for(const e of i)pe(e,n)}_removeEventListener(e,t){const o=Se(this,e);for(const e of o)for(let o=0;o{this.set(t,e[t])}),this);Le(this);const o=this[Oe];if(e in this&&!o.has(e))throw new fe("observable-set-cannot-override",this);Object.defineProperty(this,e,{enumerable:!0,configurable:!0,get:()=>o.get(e),set(t){const i=o.get(e);let n=this.fire(`set:${e}`,e,t,i);void 0===n&&(n=t),i===n&&o.has(e)||(o.set(e,n),this.fire(`change:${e}`,e,n,i))}}),this[e]=t}bind(...e){if(!e.length||!qe(e))throw new fe("observable-bind-wrong-properties",this);if(new Set(e).size!==e.length)throw new fe("observable-bind-duplicate-properties",this);Le(this);const t=this[De];e.forEach((e=>{if(t.has(e))throw new fe("observable-bind-rebind",this)}));const o=new Map;return e.forEach((e=>{const i={property:e,to:[]};t.set(e,i),o.set(e,i)})),{to:ze,toMany:je,_observable:this,_bindProperties:e,_to:[],_bindings:o}}unbind(...e){if(!this[Oe])return;const t=this[De],o=this[Ve];if(e.length){if(!qe(e))throw new fe("observable-unbind-wrong-properties",this);e.forEach((e=>{const i=t.get(e);i&&(i.to.forEach((([e,t])=>{const n=o.get(e),s=n[t];s.delete(i),s.size||delete n[t],Object.keys(n).length||(o.delete(e),this.stopListening(e,"change"))})),t.delete(e))}))}else o.forEach(((e,t)=>{this.stopListening(t,"change")})),o.clear(),t.clear()}decorate(e){Le(this);const t=this[e];if(!t)throw new fe("observablemixin-cannot-decorate-undefined",this,{object:this,methodName:e});this.on(e,((e,o)=>{e.return=t.apply(this,o)})),this[e]=function(...t){return this.fire(e,t)},this[e][Me]=t,this[Fe]||(this[Fe]=[]),this[Fe].push(e)}stopListening(e,t,o){if(!e&&this[Fe]){for(const e of this[Fe])this[e]=this[e][Me];delete this[Fe]}super.stopListening(e,t,o)}[Oe];[Fe];[De];[Ve]}}function Le(e){e[Oe]||(Object.defineProperty(e,Oe,{value:new Map}),Object.defineProperty(e,Ve,{value:new Map}),Object.defineProperty(e,De,{value:new Map}))}function ze(...e){const t=function(...e){if(!e.length)throw new fe("observable-bind-to-parse-error",null);const t={to:[]};let o;"function"==typeof e[e.length-1]&&(t.callback=e.pop());return e.forEach((e=>{if("string"==typeof e)o.properties.push(e);else{if("object"!=typeof e)throw new fe("observable-bind-to-parse-error",null);o={observable:e,properties:[]},t.to.push(o)}})),t}(...e),o=Array.from(this._bindings.keys()),i=o.length;if(!t.callback&&t.to.length>1)throw new fe("observable-bind-to-no-callback",this);if(i>1&&t.callback)throw new fe("observable-bind-to-extra-callback",this);var n;t.to.forEach((e=>{if(e.properties.length&&e.properties.length!==i)throw new fe("observable-bind-to-properties-length",this);e.properties.length||(e.properties=this._bindProperties)})),this._to=t.to,t.callback&&(this._bindings.get(o[0]).callback=t.callback),n=this._observable,this._to.forEach((e=>{const t=n[Ve];let o;t.get(e.observable)||n.listenTo(e.observable,"change",((i,s)=>{o=t.get(e.observable)[s],o&&o.forEach((e=>{$e(n,e.property)}))}))})),function(e){let t;e._bindings.forEach(((o,i)=>{e._to.forEach((n=>{t=n.properties[o.callback?0:e._bindProperties.indexOf(i)],o.to.push([n.observable,t]),function(e,t,o,i){const n=e[Ve],s=n.get(o),r=s||{};r[i]||(r[i]=new Set);r[i].add(t),s||n.set(o,r)}(e._observable,o,n.observable,t)}))}))}(this),this._bindProperties.forEach((e=>{$e(this._observable,e)}))}function je(e,t,o){if(this._bindings.size>1)throw new fe("observable-bind-to-many-not-one-binding",this);this.to(...function(e,t){const o=e.map((e=>[e,t]));return Array.prototype.concat.apply([],o)}(e,t),o)}function qe(e){return e.every((e=>"string"==typeof e))}function $e(e,t){const o=e[De].get(t);let i;o.callback?i=o.callback.apply(e,o.to.map((e=>e[0][e[1]]))):(i=o.to[0],i=i[0][i[1]]),Object.prototype.hasOwnProperty.call(e,t)?e[t]=i:e.set(t,i)}function He(e){let t=0;for(const o of e)t++;return t}function We(e,t){const o=Math.min(e.length,t.length);for(let i=0;i{this._setToTarget(e,i,t[i],o)}))}}function Je(e){return N(e,Ze)}function Ze(e){return L(e)||"function"==typeof e?e:void 0}function Qe(e){if(e){if(e.defaultView)return e instanceof e.defaultView.Document;if(e.ownerDocument&&e.ownerDocument.defaultView)return e instanceof e.ownerDocument.defaultView.Node}return!1}function Ye(e){const t=Object.prototype.toString.apply(e);return"[object Window]"==t||"[object global]"==t}const Xe=et(xe());function et(e){if(!e)return Xe;return class extends e{listenTo(e,t,o,i={}){if(Qe(e)||Ye(e)||e instanceof J.window.EventTarget){const n={capture:!!i.useCapture,passive:!!i.usePassive},s=this._getProxyEmitter(e,n)||new tt(e,n);this.listenTo(s,t,o,i)}else super.listenTo(e,t,o,i)}stopListening(e,t,o){if(Qe(e)||Ye(e)||e instanceof J.window.EventTarget){const i=this._getAllProxyEmitters(e);for(const e of i)this.stopListening(e,t,o)}else super.stopListening(e,t,o)}_getProxyEmitter(e,t){return function(e,t){const o=e[ke];return o&&o[t]?o[t].emitter:null}(this,ot(e,t))}_getAllProxyEmitters(e){return[{capture:!1,passive:!1},{capture:!1,passive:!0},{capture:!0,passive:!1},{capture:!0,passive:!0}].map((t=>this._getProxyEmitter(e,t))).filter((e=>!!e))}}}class tt extends(xe()){_domNode;_options;constructor(e,t){super(),Ee(this,ot(e,t)),this._domNode=e,this._options=t}_domListeners;attach(e){if(this._domListeners&&this._domListeners[e])return;const t=this._createDomListener(e);this._domNode.addEventListener(e,t,this._options),this._domListeners||(this._domListeners={}),this._domListeners[e]=t}detach(e){let t;!this._domListeners[e]||(t=this._events[e])&&t.callbacks.length||this._domListeners[e].removeListener()}_addEventListener(e,t,o){this.attach(e),xe().prototype._addEventListener.call(this,e,t,o)}_removeEventListener(e,t){xe().prototype._removeEventListener.call(this,e,t),this.detach(e)}_createDomListener(e){const t=t=>{this.fire(e,t)};return t.removeListener=()=>{this._domNode.removeEventListener(e,t,this._options),delete this._domListeners[e]},t}}function ot(e,t){let o=function(e){return e["data-ck-expando"]||(e["data-ck-expando"]=me())}(e);for(const e of Object.keys(t).sort())t[e]&&(o+="-"+e);return o}function it(e){const t=[];let o=e;for(;o&&o.nodeType!=Node.DOCUMENT_NODE;)t.unshift(o),o=o.parentNode;return t}function nt(e){const t=e.ownerDocument.defaultView.getComputedStyle(e);return{top:parseInt(t.borderTopWidth,10),right:parseInt(t.borderRightWidth,10),bottom:parseInt(t.borderBottomWidth,10),left:parseInt(t.borderLeftWidth,10)}}function st(e){if(!e.target)return null;const t=e.target.ownerDocument,o=e.clientX,i=e.clientY;let n=null;return t.caretRangeFromPoint&&t.caretRangeFromPoint(o,i)?n=t.caretRangeFromPoint(o,i):e.rangeParent&&(n=t.createRange(),n.setStart(e.rangeParent,e.rangeOffset),n.collapse(!0)),n}function rt(e){return e&&e.parentNode?e.offsetParent===J.document.body?null:e.offsetParent:null}function at(e){return"[object Text]"==Object.prototype.toString.call(e)}function lt(e){return"[object Range]"==Object.prototype.toString.apply(e)}const ct=["top","right","bottom","left","width","height"],dt=new Set(["relative","absolute","fixed","sticky"]);class ut{top;right;bottom;left;width;height;_source;constructor(e){const t=lt(e);if(Object.defineProperty(this,"_source",{value:e._source||e,writable:!0,enumerable:!1}),gt(e)||t)if(t){const t=ut.getDomRangeRects(e);ht(this,ut.getBoundingRect(t))}else ht(this,e.getBoundingClientRect());else if(Ye(e)){const{innerWidth:t,innerHeight:o}=e;ht(this,{top:0,right:t,bottom:o,left:0,width:t,height:o})}else ht(this,e)}clone(){return new ut(this)}moveTo(e,t){return this.top=t,this.right=e+this.width,this.bottom=t+this.height,this.left=e,this}moveBy(e,t){return this.top+=t,this.right+=e,this.left+=e,this.bottom+=t,this}getIntersection(e){const t={top:Math.max(this.top,e.top),right:Math.min(this.right,e.right),bottom:Math.min(this.bottom,e.bottom),left:Math.max(this.left,e.left),width:0,height:0};if(t.width=t.right-t.left,t.height=t.bottom-t.top,t.width<0||t.height<0)return null;{const e=new ut(t);return e._source=this._source,e}}getIntersectionArea(e){const t=this.getIntersection(e);return t?t.getArea():0}getArea(){return this.width*this.height}getVisible(){const e=this._source;let t=this.clone();if(mt(e))return t;let o,i=e,n=e.parentNode||e.commonAncestorContainer;for(;n&&!mt(n);){const e="visible"===((s=n)instanceof HTMLElement?s.ownerDocument.defaultView.getComputedStyle(s).overflow:"visible");if(ft(i)&&(o=i),e||o&&"absolute"===pt(o)&&!ft(n)){i=n,n=n.parentNode;continue}const r=new ut(n),a=t.getIntersection(r);if(!a)return null;a.getArea(){const o=new ut(t);return o._source=e,o}))}static getBoundingRect(e){const t={left:Number.POSITIVE_INFINITY,top:Number.POSITIVE_INFINITY,right:Number.NEGATIVE_INFINITY,bottom:Number.NEGATIVE_INFINITY,width:0,height:0};let o=0;for(const i of e)o++,t.left=Math.min(t.left,i.left),t.top=Math.min(t.top,i.top),t.right=Math.max(t.right,i.right),t.bottom=Math.max(t.bottom,i.bottom);return 0==o?null:(t.width=t.right-t.left,t.height=t.bottom-t.top,new ut(t))}}function ht(e,t){for(const o of ct)e[o]=t[o]}function mt(e){return!!gt(e)&&e===e.ownerDocument.body}function gt(e){return null!==e&&"object"==typeof e&&1===e.nodeType&&"function"==typeof e.getBoundingClientRect}function pt(e){return e.ownerDocument.defaultView.getComputedStyle(e).position}function ft(e){return e instanceof HTMLElement&&dt.has(pt(e))}class bt{_element;_callback;static _observerInstance=null;static _elementCallbacks=null;constructor(e,t){bt._observerInstance||bt._createObserver(),this._element=e,this._callback=t,bt._addElementCallback(e,t),bt._observerInstance.observe(e)}get element(){return this._element}destroy(){bt._deleteElementCallback(this._element,this._callback)}static _addElementCallback(e,t){bt._elementCallbacks||(bt._elementCallbacks=new Map);let o=bt._elementCallbacks.get(e);o||(o=new Set,bt._elementCallbacks.set(e,o)),o.add(t)}static _deleteElementCallback(e,t){const o=bt._getElementCallbacks(e);o&&(o.delete(t),o.size||(bt._elementCallbacks.delete(e),bt._observerInstance.unobserve(e))),bt._elementCallbacks&&!bt._elementCallbacks.size&&(bt._observerInstance=null,bt._elementCallbacks=null)}static _getElementCallbacks(e){return bt._elementCallbacks?bt._elementCallbacks.get(e):null}static _createObserver(){bt._observerInstance=new J.window.ResizeObserver((e=>{for(const t of e){const e=bt._getElementCallbacks(t.target);if(e)for(const o of e)o(t)}}))}}function wt(e,t){e instanceof HTMLTextAreaElement&&(e.value=t),e.innerHTML=t}function yt(e){return t=>t+e}function _t(e){let t=0;for(;e.previousSibling;)e=e.previousSibling,t++;return t}function kt(e,t,o){e.insertBefore(o,e.childNodes[t]||null)}function vt(e){return e&&e.nodeType===Node.COMMENT_NODE}function Ct(e){return!!e&&(at(e)?Ct(e.parentElement):!!e.getClientRects&&!!e.getClientRects().length)}function At({element:e,target:t,positions:o,limiter:i,fitInViewport:n,viewportOffsetConfig:s}){z(t)&&(t=t()),z(i)&&(i=i());const r=rt(e),a=Et(s),l=new ut(e),c=xt(t,a);let d;if(!c||!a.getIntersection(c))return null;const u={targetRect:c,elementRect:l,positionedElementAncestor:r,viewportRect:a};if(i||n){if(i){const e=xt(i,a);e&&(u.limiterRect=e)}d=function(e,t){const{elementRect:o}=t,i=o.getArea(),n=e.map((e=>new Tt(e,t))).filter((e=>!!e.name));let s=0,r=null;for(const e of n){const{limiterIntersectionArea:t,viewportIntersectionArea:o}=e;if(t===i)return e;const n=o**2+t**2;n>s&&(s=n,r=e)}return r}(o,u)}else d=new Tt(o[0],u);return d}function xt(e,t){const o=new ut(e).getVisible();return o?o.getIntersection(t):null}function Et(e){e=Object.assign({top:0,bottom:0,left:0,right:0},e);const t=new ut(J.window);return t.top+=e.top,t.height-=e.top,t.bottom-=e.bottom,t.height-=e.bottom,t.left+=e.left,t.right-=e.right,t.width-=e.left+e.right,t}class Tt{name;config;_positioningFunctionCoordinates;_options;_cachedRect;_cachedAbsoluteRect;constructor(e,t){const o=e(t.targetRect,t.elementRect,t.viewportRect,t.limiterRect);if(!o)return;const{left:i,top:n,name:s,config:r}=o;this.name=s,this.config=r,this._positioningFunctionCoordinates={left:i,top:n},this._options=t}get left(){return this._absoluteRect.left}get top(){return this._absoluteRect.top}get limiterIntersectionArea(){const e=this._options.limiterRect;return e?e.getIntersectionArea(this._rect):0}get viewportIntersectionArea(){return this._options.viewportRect.getIntersectionArea(this._rect)}get _rect(){return this._cachedRect||(this._cachedRect=this._options.elementRect.clone().moveTo(this._positioningFunctionCoordinates.left,this._positioningFunctionCoordinates.top)),this._cachedRect}get _absoluteRect(){return this._cachedAbsoluteRect||(this._cachedAbsoluteRect=this._rect.toAbsoluteRect()),this._cachedAbsoluteRect}}function Pt(e){const t=e.parentNode;t&&t.removeChild(e)}function St(){const e=J.window.visualViewport;if(!e||!Y.isiOS&&!Y.isSafari)return{left:0,top:0};return{left:Math.max(Math.round(e.offsetLeft),0),top:Math.max(Math.round(e.offsetTop),0)}}function It({window:e,rect:t,alignToTop:o,forceScroll:i,viewportOffset:n}){const s=t.clone().moveBy(0,n.bottom),r=t.clone().moveBy(0,-n.top),a=new ut(e).excludeScrollbarsAndBorders(),l=o&&i,c=[r,s].every((e=>a.contains(e)));let{scrollX:d,scrollY:u}=e;const h=d,m=u;l?u-=a.top-t.top+n.top:c||(Vt(r,a)?u-=a.top-t.top+n.top:Ot(s,a)&&(u+=o?t.top-a.top-n.top:t.bottom-a.bottom+n.bottom)),c||(Dt(t,a)?d-=a.left-t.left+n.left:Ft(t,a)&&(d+=t.right-a.right+n.right)),d==h&&u===m||e.scrollTo(d,u)}function Rt({parent:e,getRect:t,alignToTop:o,forceScroll:i,ancestorOffset:n=0,limiterElement:s}){const r=Mt(e),a=o&&i;let l,c,d;const u=s||r.document.body;for(;e!=u;)c=t(),l=new ut(e).excludeScrollbarsAndBorders(),d=l.contains(c),a?e.scrollTop-=l.top-c.top+n:d||(Vt(c,l)?e.scrollTop-=l.top-c.top+n:Ot(c,l)&&(e.scrollTop+=o?c.top-l.top-n:c.bottom-l.bottom+n)),d||(Dt(c,l)?e.scrollLeft-=l.left-c.left+n:Ft(c,l)&&(e.scrollLeft+=c.right-l.right+n)),e=e.parentNode}function Ot(e,t){return e.bottom>t.bottom}function Vt(e,t){return e.topt.right}function Mt(e){return lt(e)?e.startContainer.ownerDocument.defaultView:e.ownerDocument.defaultView}function Nt(e){if(lt(e)){let t=e.commonAncestorContainer;return at(t)&&(t=t.parentNode),t}return e.parentNode}function Bt(e,t){const o=Mt(e),i=new ut(e);if(o===t)return i;{let e=o;for(;e!=t;){const t=e.frameElement,o=new ut(t).excludeScrollbarsAndBorders();i.moveBy(o.left,o.top),e=e.parent}}return i}const Lt={ctrl:"⌃",cmd:"⌘",alt:"⌥",shift:"⇧"},zt={ctrl:"Ctrl+",alt:"Alt+",shift:"Shift+"},jt={37:"←",38:"↑",39:"→",40:"↓",9:"⇥",33:"Page Up",34:"Page Down"},qt=Gt(),$t=Object.fromEntries(Object.entries(qt).map((([e,t])=>{let o;return o=t in jt?jt[t]:e.charAt(0).toUpperCase()+e.slice(1),[t,o]})));function Ht(e){let t;if("string"==typeof e){if(t=qt[e.toLowerCase()],!t)throw new fe("keyboard-unknown-key",null,{key:e})}else t=e.keyCode+(e.altKey?qt.alt:0)+(e.ctrlKey?qt.ctrl:0)+(e.shiftKey?qt.shift:0)+(e.metaKey?qt.cmd:0);return t}function Wt(e){return"string"==typeof e&&(e=function(e){return e.split("+").map((e=>e.trim()))}(e)),e.map((e=>"string"==typeof e?function(e){if(e.endsWith("!"))return Ht(e.slice(0,-1));const t=Ht(e);return(Y.isMac||Y.isiOS)&&t==qt.ctrl?qt.cmd:t}(e):e)).reduce(((e,t)=>t+e),0)}function Ut(e,t){let o=Wt(e);const i=t?"Mac"===t:Y.isMac||Y.isiOS;return Object.entries(i?Lt:zt).reduce(((e,[t,i])=>(o&qt[t]&&(o&=~qt[t],e+=i),e)),"")+(o?$t[o]:"")}function Kt(e,t){const o="ltr"===t;switch(e){case qt.arrowleft:return o?"left":"right";case qt.arrowright:return o?"right":"left";case qt.arrowup:return"up";case qt.arrowdown:return"down"}}function Gt(){const e={pageup:33,pagedown:34,end:35,home:36,arrowleft:37,arrowup:38,arrowright:39,arrowdown:40,backspace:8,delete:46,enter:13,space:32,esc:27,tab:9,ctrl:1114112,shift:2228224,alt:4456448,cmd:8912896};for(let t=65;t<=90;t++){e[String.fromCharCode(t).toLowerCase()]=t}for(let t=48;t<=57;t++)e[t-48]=t;for(let t=112;t<=123;t++)e["f"+(t-111)]=t;return Object.assign(e,{"'":222,",":108,"-":109,".":110,"/":111,";":186,"=":187,"[":219,"\\":220,"]":221,"`":223}),e}const Jt=["ar","ara","dv","div","fa","per","fas","he","heb","ku","kur","ug","uig","ur","urd"];function Zt(e){return Jt.includes(e)?"rtl":"ltr"}function Qt(e){return Array.isArray(e)?e:[e]}function Yt(e,t,o=1,i){if("number"!=typeof o)throw new fe("translation-service-quantity-not-a-number",null,{quantity:o});const n=i||J.window.CKEDITOR_TRANSLATIONS,s=function(e){return Object.keys(e).length}(n);1===s&&(e=Object.keys(n)[0]);const r=t.id||t.string;if(0===s||!function(e,t,o){return!!o[e]&&!!o[e].dictionary[t]}(e,r,n))return 1!==o?t.plural:t.string;const a=n[e].dictionary,l=n[e].getPluralForm||(e=>1===e?0:1),c=a[r];if("string"==typeof c)return c;return c[Number(l(o))]}J.window.CKEDITOR_TRANSLATIONS||(J.window.CKEDITOR_TRANSLATIONS={});class Xt{uiLanguage;uiLanguageDirection;contentLanguage;contentLanguageDirection;t;translations;constructor({uiLanguage:e="en",contentLanguage:t,translations:o}={}){this.uiLanguage=e,this.contentLanguage=t||this.uiLanguage,this.uiLanguageDirection=Zt(this.uiLanguage),this.contentLanguageDirection=Zt(this.contentLanguage),this.translations=function(e){return Array.isArray(e)?e.reduce(((e,t)=>G(e,t))):e}(o),this.t=(e,t)=>this._t(e,t)}_t(e,t=[]){t=Qt(t),"string"==typeof e&&(e={string:e});const o=!!e.plural?t[0]:1;return function(e,t){return e.replace(/%(\d+)/g,((e,o)=>othis._items.length||t<0)throw new fe("collection-add-item-invalid-index",this);let o=0;for(const i of e){const e=this._getItemIdBeforeAdding(i),n=t+o;this._items.splice(n,0,i),this._itemMap.set(e,i),this.fire("add",i,n),o++}return this.fire("change",{added:e,removed:[],index:t}),this}get(e){let t;if("string"==typeof e)t=this._itemMap.get(e);else{if("number"!=typeof e)throw new fe("collection-get-invalid-arg",this);t=this._items[e]}return t||null}has(e){if("string"==typeof e)return this._itemMap.has(e);{const t=e[this._idProperty];return t&&this._itemMap.has(t)}}getIndex(e){let t;return t="string"==typeof e?this._itemMap.get(e):e,t?this._items.indexOf(t):-1}remove(e){const[t,o]=this._remove(e);return this.fire("change",{added:[],removed:[t],index:o}),t}map(e,t){return this._items.map(e,t)}forEach(e,t){this._items.forEach(e,t)}find(e,t){return this._items.find(e,t)}filter(e,t){return this._items.filter(e,t)}clear(){this._bindToCollection&&(this.stopListening(this._bindToCollection),this._bindToCollection=null);const e=Array.from(this._items);for(;this.length;)this._remove(0);this.fire("change",{added:[],removed:e,index:0})}bindTo(e){if(this._bindToCollection)throw new fe("collection-bind-to-rebind",this);return this._bindToCollection=e,{as:e=>{this._setUpBindToBinding((t=>new e(t)))},using:e=>{"function"==typeof e?this._setUpBindToBinding(e):this._setUpBindToBinding((t=>t[e]))}}}_setUpBindToBinding(e){const t=this._bindToCollection,o=(o,i,n)=>{const s=t._bindToCollection==this,r=t._bindToInternalToExternalMap.get(i);if(s&&r)this._bindToExternalToInternalMap.set(i,r),this._bindToInternalToExternalMap.set(r,i);else{const o=e(i);if(!o)return void this._skippedIndexesFromExternal.push(n);let s=n;for(const e of this._skippedIndexesFromExternal)n>e&&s--;for(const e of t._skippedIndexesFromExternal)s>=e&&s++;this._bindToExternalToInternalMap.set(i,o),this._bindToInternalToExternalMap.set(o,i),this.add(o,s);for(let e=0;e{const i=this._bindToExternalToInternalMap.get(t);i&&this.remove(i),this._skippedIndexesFromExternal=this._skippedIndexesFromExternal.reduce(((e,t)=>(ot&&e.push(t),e)),[])}))}_getItemIdBeforeAdding(e){const t=this._idProperty;let o;if(t in e){if(o=e[t],"string"!=typeof o)throw new fe("collection-add-invalid-id",this);if(this.get(o))throw new fe("collection-add-item-already-exists",this)}else e[t]=o=me();return o}_remove(e){let t,o,i,n=!1;const s=this._idProperty;if("string"==typeof e?(o=e,i=this._itemMap.get(o),n=!i,i&&(t=this._items.indexOf(i))):"number"==typeof e?(t=e,i=this._items[t],n=!i,i&&(o=i[s])):(i=e,o=i[s],t=this._items.indexOf(i),n=-1==t||!this._itemMap.get(o)),n)throw new fe("collection-remove-404",this);this._items.splice(t,1),this._itemMap.delete(o);const r=this._bindToInternalToExternalMap.get(i);return this._bindToInternalToExternalMap.delete(i),this._bindToExternalToInternalMap.delete(r),this.fire("remove",i,t),[i,t]}[Symbol.iterator](){return this._items[Symbol.iterator]()}}function to(e){const t=e.next();return t.done?null:t.value}class oo extends(et(Be())){_elements=new Set;_externalViews=new Set;_blurTimeout=null;constructor(){super(),this.set("isFocused",!1),this.set("focusedElement",null)}get elements(){return Array.from(this._elements.values())}get externalViews(){return Array.from(this._externalViews.values())}add(e){if(no(e))this._addElement(e);else if(io(e))this._addView(e);else{if(!e.element)throw new fe("focustracker-add-view-missing-element",{focusTracker:this,view:e});this._addElement(e.element)}}remove(e){no(e)?this._removeElement(e):io(e)?this._removeView(e):this._removeElement(e.element)}_addElement(e){if(this._elements.has(e))throw new fe("focustracker-add-element-already-exist",this);this.listenTo(e,"focus",(()=>{const t=this.externalViews.find((t=>function(e,t){if(so(e,t))return!0;return!!t.focusTracker.externalViews.find((t=>so(e,t)))}(e,t)));t?this._focus(t.element):this._focus(e)}),{useCapture:!0}),this.listenTo(e,"blur",(()=>{this._blur()}),{useCapture:!0}),this._elements.add(e)}_removeElement(e){this._elements.has(e)&&(this.stopListening(e),this._elements.delete(e)),e===this.focusedElement&&this._blur()}_addView(e){e.element&&this._addElement(e.element),this.listenTo(e.focusTracker,"change:focusedElement",(()=>{e.focusTracker.focusedElement?e.element&&this._focus(e.element):this._blur()})),this._externalViews.add(e)}_removeView(e){e.element&&this._removeElement(e.element),this.stopListening(e.focusTracker),this._externalViews.delete(e)}destroy(){this.stopListening(),this._elements.clear(),this._externalViews.clear(),this.isFocused=!1,this.focusedElement=null}_focus(e){this._clearBlurTimeout(),this.focusedElement=e,this.isFocused=!0}_blur(){if(this.elements.find((e=>e.contains(document.activeElement))))return;this.externalViews.find((e=>e.focusTracker.isFocused&&!e.focusTracker._blurTimeout))||(this._clearBlurTimeout(),this._blurTimeout=setTimeout((()=>{this.focusedElement=null,this.isFocused=!1}),0))}_clearBlurTimeout(){clearTimeout(this._blurTimeout),this._blurTimeout=null}}function io(e){return"focusTracker"in e&&e.focusTracker instanceof oo}function no(e){return L(e)}function so(e,t){return!!t.element&&t.element.contains(document.activeElement)&&e.contains(t.element)}class ro{_listener;constructor(){this._listener=new(et())}listenTo(e){this._listener.listenTo(e,"keydown",((e,t)=>{this._listener.fire("_keydown:"+Ht(t),t)}))}set(e,t,o={}){const i=Wt(e),n=o.priority;this._listener.listenTo(this._listener,"_keydown:"+i,((e,i)=>{o.filter&&!o.filter(i)||(t(i,(()=>{i.preventDefault(),i.stopPropagation(),e.stop()})),e.return=!0)}),{priority:n})}press(e){return!!this._listener.fire("_keydown:"+Ht(e),e)}stopListening(e){this._listener.stopListening(e)}destroy(){this.stopListening()}}function ao(e){return Ue(e)?new Map(e):function(e){const t=new Map;for(const o in e)t.set(o,e[o]);return t}(e)}function lo(e,t,o){const i=e.length,n=t.length;for(let t=i-1;t>=o;t--)e[t+n]=e[t];for(let i=0;ie(...n)),t)}return i.cancel=()=>{clearTimeout(o)},i}function uo(e){try{if(!e.startsWith("ey"))return null;const t=atob(e.replace(/-/g,"+").replace(/_/g,"/"));return JSON.parse(t)}catch{return null}}function ho(e,t){return!!(o=e.charAt(t-1))&&1==o.length&&/[\ud800-\udbff]/.test(o)&&function(e){return!!e&&1==e.length&&/[\udc00-\udfff]/.test(e)}(e.charAt(t));var o}function mo(e,t){return!!(o=e.charAt(t))&&1==o.length&&/[\u0300-\u036f\u1ab0-\u1aff\u1dc0-\u1dff\u20d0-\u20ff\ufe20-\ufe2f]/.test(o);var o}const go=fo();function po(e,t){const o=String(e).matchAll(go);return Array.from(o).some((e=>e.indexe.source)).join("|")+")";return new RegExp(`${e}|${t}(?:${t})*`,"ug")}function bo(e){if(!e)return null;const t=function(e){const t=e.split(".");if(3!=t.length)return null;return t[1]}(e);return t?uo(t):null}function wo(e){switch(typeof e){case"number":case"symbol":return!1;case"string":return e.includes(".")||e.includes("[")||e.includes("]")}}function yo(e){return"string"==typeof e||"symbol"==typeof e?e:Object.is(e?.valueOf?.(),-0)?"-0":String(e)}function _o(e){if(null==e)return"";if("string"==typeof e)return e;if(Array.isArray(e))return e.map(_o).join(",");const t=String(e);return"0"===t&&Object.is(Number(e),-0)?"-0":t}function ko(e){if(Array.isArray(e))return e.map(yo);if("symbol"==typeof e)return[e];const t=[],o=(e=_o(e)).length;if(0===o)return t;let i=0,n="",s="",r=!1;for(46===e.charCodeAt(0)&&(t.push(""),i++);i{const i=e[t];Object.hasOwn(e,t)&&Co(i,o)&&(void 0!==o||t in e)||(e[t]=o)},xo=/^(?:0|[1-9]\d*)$/;function Eo(e,t=Number.MAX_SAFE_INTEGER){switch(typeof e){case"number":return Number.isInteger(e)&&e>=0&&eo),(()=>{}))}function Oo(e){const t=e?.constructor;return e===("function"==typeof t?t.prototype:Object.prototype)}function Vo(e){if(!e)return 0===e?e:0;if((e=function(e){return To(e)?NaN:Number(e)}(e))===1/0||e===-1/0){return(e<0?-1:1)*Number.MAX_VALUE}return e==e?e:0}function Do(e,t){if((e=function(e){const t=Vo(e),o=t%1;return o?t-o:t}(e))<1||!Number.isSafeInteger(e))return[];const o=new Array(e);for(let i=0;i`${e}`)),o=new Set(t);i=e,"undefined"!=typeof Buffer&&Buffer.isBuffer(i)&&(o.add("offset"),o.add("parent"));var i;W(e)&&(o.add("buffer"),o.add("byteLength"),o.add("byteOffset"));const n=Mo(e).filter((e=>!o.has(e)));if(Array.isArray(e))return[...t,...n];return[...t.filter((t=>Object.hasOwn(e,t))),...n]}(e):Oo(e)?function(e){const t=Mo(e);return t.filter((e=>"constructor"!==e))}(e):Mo(e);default:return Mo(Object(e))}}function Mo(e){const t=[];for(const o in e)t.push(o);return t}function No(e,...t){for(let o=0;o{null!==s&&(e.apply(n,s),n=void 0,s=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),n=void 0,s=null},h=function(...e){if(o?.aborted)return;n=this,s=e;const t=null==c;d(),r&&t&&l()};return h.schedule=d,h.cancel=u,h.flush=()=>{l()},o?.addEventListener("abort",u,{once:!0}),h}function zo(e,t=0,o={}){"object"!=typeof o&&(o={});const{leading:i=!1,trailing:n=!0,maxWait:s}=o,r=Array(2);let a;i&&(r[0]="leading"),n&&(r[1]="trailing");let l=null;const c=Lo((function(...t){a=e.apply(this,t),l=null}),t,{edges:r}),d=function(...t){return null!=s&&(null===l&&(l=Date.now()),Date.now()-l>=s)?(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 jo(e,t){if(!Number.isInteger(e)||e<0)throw new Error("n must be a non-negative integer.");let o=0;return(...i)=>{if(++o>=e)return t(...i)}}function qo(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 $o(e,t,o){return Ho(e,t,void 0,void 0,void 0,void 0,o)}function Ho(e,t,o,i,n,s,r){const a=r(e,t,o,i,n,s);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 Wo(e,t,s,r)}return Wo(e,t,s,r)}function Wo(e,t,o,i){if(Object.is(e,t))return!0;let n=c(e),s=c(t);if(n===g&&(n=v),s===g&&(s=v),n!==s)return!1;switch(n){case u:return e.toString()===t.toString();case h:return Co(e.valueOf(),t.valueOf());case m:case f:case p:return Object.is(e.valueOf(),t.valueOf());case d:return e.source===t.source&&e.flags===t.flags;case"[object Function]":return e===t}const r=(o=o??new Map).get(e),a=o.get(t);if(null!=r&&null!=a)return r===t;o.set(e,t),o.set(t,e);try{switch(n){case b:if(e.size!==t.size)return!1;for(const[n,s]of e.entries())if(!t.has(n)||!Ho(s,t.get(n),n,e,t,o,i))return!1;return!0;case w:{if(e.size!==t.size)return!1;const n=Array.from(e.values()),s=Array.from(t.values());for(let r=0;rHo(a,n,void 0,e,t,o,i)));if(-1===l)return!1;s.splice(l,1)}return!0}case y:case A:case x:case E:case T:case"[object BigUint64Array]":case P:case S:case I:case"[object BigInt64Array]":case R:case O:if("undefined"!=typeof Buffer&&Buffer.isBuffer(e)!==Buffer.isBuffer(t))return!1;if(e.length!==t.length)return!1;for(let n=0;n{}),$o(e,t,((...i)=>{const n=o(...i);return void 0!==n?Boolean(n):e instanceof Map&&t instanceof Map||e instanceof Set&&t instanceof Set?Uo(Array.from(e),Array.from(t),jo(2,o)):void 0}))}function Ko(e,t){return $o(e,t,K)}function Go(e){if(V(e))return e;const t=c(e);if(!function(e){switch(c(e)){case g:case y:case k:case C:case m:case f:case R:case O:case P:case S:case I:case b:case h:case v:case d:case w:case u:case p:case A:case x:case E:case T:return!0;default:return!1}}(e))return{};if(o=e,Array.isArray(o)){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 o;if(W(e)){const t=e;return new(0,t.constructor)(t.buffer,t.byteOffset,t.length)}if(t===k)return new ArrayBuffer(e.byteLength);if(t===C){const t=e,o=t.buffer,i=t.byteOffset,n=t.byteLength,s=new ArrayBuffer(n),r=new Uint8Array(o,i,n);return new Uint8Array(s).set(r),new DataView(s)}if(t===m||t===h||t===u){const o=new(0,e.constructor)(e.valueOf());return t===u?function(e,t){const o=t.valueOf().length;for(const i in t)Object.hasOwn(t,i)&&(Number.isNaN(Number(i))||Number(i)>=o)&&(e[i]=t[i])}(o,e):Jo(o,e),o}if(t===f)return new Date(Number(e));if(t===d){const t=e,o=new RegExp(t.source,t.flags);return o.lastIndex=t.lastIndex,o}if(t===p)return Object(Symbol.prototype.valueOf.call(e));if(t===b){const t=e,o=new Map;return t.forEach(((e,t)=>{o.set(t,e)})),o}if(t===w){const t=e,o=new Set;return t.forEach((e=>{o.add(e)})),o}if(t===g){const t=e,o={};return Jo(o,t),o.length=t.length,o[Symbol.iterator]=t[Symbol.iterator],o}const i={};return function(e,t){const o=Object.getPrototypeOf(t);if(null!==o){"function"==typeof t.constructor&&Object.setPrototypeOf(e,o)}}(i,e),Jo(i,e),function(e,t){const o=Object.getOwnPropertySymbols(t);for(let i=0;iei([[t,r]],e)))}Zo.has(s)||(Zo.set(s,new Map),s.registerPostFixer((e=>ei(Zo.get(s),e))),s.on("change:isComposing",(()=>{e.change((e=>ei(Zo.get(s),e)))}),{priority:"high"})),t.is("editableElement")&&t.on("change:placeholder",((e,t,o)=>r(o))),t.placeholder?r(t.placeholder):o&&r(o),o&&function(){Qo||be("enableViewPlaceholder-deprecated-text-option");Qo=!0}()}function Xo(e,t){return!!t.hasClass("ck-placeholder")&&(e.removeClass("ck-placeholder",t),!0)}function ei(e,t){const o=[];let i=!1;for(const[n,s]of e)s.isDirectHost&&(o.push(n),ti(t,n,s)&&(i=!0));for(const[n,s]of e){if(s.isDirectHost)continue;const e=oi(n);e!==s.hostElement&&s.hostElement&&(t.removeAttribute("data-placeholder",s.hostElement),Xo(t,s.hostElement),s.hostElement=null,i=!0),e&&(o.includes(e)||(s.hostElement=e,ti(t,n,s)&&(i=!0)))}return i}function ti(e,t,o){const{text:i,isDirectHost:n,hostElement:s}=o;let r=!1;s.getAttribute("data-placeholder")!==i&&(e.setAttribute("data-placeholder",i,s),r=!0);return(n||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 o=e.document,i=o.selection.anchor;return!(o.isComposing&&i&&i.parent===e||!t&&o.isFocused&&(!i||i.parent===e))}(s,o.keepOnFocus)?function(e,t){return!t.hasClass("ck-placeholder")&&(e.addClass("ck-placeholder",t),!0)}(e,s)&&(r=!0):Xo(e,s)&&(r=!0),r}function oi(e){if(e.childCount){const t=e.getChild(0);if(t.is("element")&&!t.is("uiElement")&&!t.is("attributeElement"))return t}return null}class ii{is(){throw new Error("is() method is abstract")}}class ni extends(xe(ii)){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 o=e.includeSelf?this:this.parent;for(;o;)t[e.parentFirst?"push":"unshift"](o),o=o.parent;return t}getCommonAncestor(e,t={}){const o=this.getAncestors(t),i=e.getAncestors(t);let n=0;for(;o[n]==i[n]&&o[n];)n++;return 0===n?null:o[n-1]}isBefore(e){if(this==e)return!1;if(this.root!==e.root)return!1;const t=this.getPath(),o=e.getPath(),i=We(t,o);switch(i){case"prefix":return!0;case"extension":return!1;default:return t[i]e.data.length)throw new fe("view-textproxy-wrong-offsetintext",this);if(o<0||t+o>e.data.length)throw new fe("view-textproxy-wrong-length",this);this.data=e.data.substring(t,t+o),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 o=e.includeSelf?this.textNode:this.parent;for(;null!==o;)t[e.parentFirst?"push":"unshift"](o),o=o.parent;return t}}ri.prototype.is=function(e){return"$textProxy"===e||"view:$textProxy"===e||"textProxy"===e||"view:textProxy"===e};class ai{_consumables=new Map;add(e,t){let o;e.is("$text")||e.is("documentFragment")?this._consumables.set(e,!0):(this._consumables.has(e)?o=this._consumables.get(e):(o=new li(e),this._consumables.set(e,o)),o.add(t?ci(t):e._getConsumables()))}test(e,t){const o=this._consumables.get(e);return void 0===o?null:e.is("$text")||e.is("documentFragment")?o:o.test(ci(t))}consume(e,t){if(e.is("$text")||e.is("documentFragment"))return!!this.test(e,t)&&(this._consumables.set(e,!1),!0);const o=this._consumables.get(e);return void 0!==o&&o.consume(ci(t))}revert(e,t){const o=this._consumables.get(e);void 0!==o&&(e.is("$text")||e.is("documentFragment")?this._consumables.set(e,!0):o.revert(ci(t)))}static createFrom(e,t){if(t||(t=new ai),e.is("$text"))t.add(e);else if(e.is("element")||e.is("documentFragment")){t.add(e);for(const o of e.getChildren())ai.createFrom(o,t)}return t}}class li{element;_canConsumeName=null;_attributes=new Map;constructor(e){this.element=e}add(e){e.name&&(this._canConsumeName=!0);for(const[t,o]of e.attributes)if(o){let e=this._attributes.get(t);e&&"boolean"!=typeof e||(e=new Map,this._attributes.set(t,e)),e.set(o,!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,o]of e.attributes){const e=this._attributes.get(t);if(void 0===e)return null;if(!1===e)return!1;if(!0!==e)if(o){const t=e.get(o);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,o]of e.attributes){const e=this._attributes.get(t);if("boolean"==typeof e)for(const[e]of this.element._getConsumables(t,o).attributes)this._attributes.set(e,!1);else if(o)for(const[,i]of this.element._getConsumables(t,o).attributes)e.set(i,!1);else for(const t of e.keys())e.set(t,!1)}return!0}revert(e){e.name&&(this._canConsumeName=!0);for(const[t,o]of e.attributes){const e=this._attributes.get(t);if(!1!==e){if(void 0!==e&&!0!==e)if(o){!1===e.get(o)&&e.set(o,!0)}else for(const t of e.keys())e.set(t,!0)}else this._attributes.set(t,!0)}}}function ci(e){const t=[];return"attributes"in e&&e.attributes&&di(t,e.attributes),"classes"in e&&e.classes&&di(t,e.classes,"class"),"styles"in e&&e.styles&&di(t,e.styles,"style"),{name:e.name||!1,attributes:t}}function di(e,t,o){if("string"!=typeof t)for(const i of t)Array.isArray(i)?e.push(i):e.push(o?[o,i]:[i]);else e.push(o?[o,t]:[t])}class ui{_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 o=this._isElementMatching(t,e);if(o)return{element:t,pattern:e,match:o}}return null}matchAll(...e){const t=[];for(const o of e)for(const e of this._patterns){const i=this._isElementMatching(o,e);i&&t.push({element:o,pattern:e,match:i})}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 o=t(e);return o&&"object"==typeof o?ci(o):o}const o={};if(t.name&&(o.name=function(e,t){if(e instanceof RegExp)return!!t.match(e);return e===t}(t.name,e.name),!o.name))return null;const i=[];return t.attributes&&!function(e,t,o){let i;"object"!=typeof e||e instanceof RegExp||Array.isArray(e)?i=["class","style"]:(void 0!==e.style&&be("matcher-pattern-deprecated-attributes-style-key",e),void 0!==e.class&&be("matcher-pattern-deprecated-attributes-class-key",e));return t._collectAttributesMatch(mi(e),o,i)}(t.attributes,e,i)||t.classes&&!function(e,t,o){return t._collectAttributesMatch(mi(e,"class"),o)}(t.classes,e,i)||t.styles&&!function(e,t,o){return t._collectAttributesMatch(mi(e,"style"),o)}(t.styles,e,i)?null:(i.length&&(o.attributes=i),o)}}function hi(e,t){return!0===e||e===t||e instanceof RegExp&&!!String(t).match(e)}function mi(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||be("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 o=[];for(const i in e)Object.prototype.hasOwnProperty.call(e,i)&&o.push(t?[t,i,e[i]]:[i,e[i]]);return o}class gi{_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,o=0,i=0,n=null;const s=new Map;if(""===e)return s;";"!=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,s(e))for(const[t,o]of Object.entries(e))this._styleProcessor.toNormalizedForm(t,o,this._styles);else this._styleProcessor.toNormalizedForm(e,t,this._styles)}remove(e){const t={};for(const o of Qt(e)){const e=fi(o),i=vo(this._styles,e);if(i)bi(t,e,i);else{const e=this.getAsString(o);void 0!==e&&this._styleProcessor.toNormalizedForm(o,e,t)}}Object.keys(t).length&&(wi(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]&&!s(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 o of t)e.push(...this._styleProcessor.getReducedForm(o,this._styles));return e}_clone(){const e=new this.constructor(this._styleProcessor);return e.set(this.getNormalized()),e}_getTokensMatch(e,t){const o=[];for(const i of this.getStyleNames(!0))if(hi(e,i)){if(!0===t){o.push(i);continue}hi(t,this.getAsString(i))&&o.push(i)}return o.length?o:void 0}_getConsumables(e){const t=[];if(e){t.push(e);for(const o of this._styleProcessor.getRelatedStyles(e))t.push(o)}else for(const e of this.getStyleNames()){for(const o of this._styleProcessor.getRelatedStyles(e))t.push(o);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}}class pi{_normalizers;_extractors;_reducers;_consumables;constructor(){this._normalizers=new Map,this._extractors=new Map,this._reducers=new Map,this._consumables=new Map}toNormalizedForm(e,t,o){if(s(t))bi(o,fi(e),t);else if(this._normalizers.has(e)){const i=this._normalizers.get(e),{path:n,value:s}=i(t);bi(o,n,s)}else bi(o,e,t)}getNormalized(e,t){if(!e)return G({},t);if(void 0!==t[e])return t[e];if(this._extractors.has(e)){const o=this._extractors.get(e);if("string"==typeof o)return vo(t,o);const i=o(e,t);if(i)return i}return vo(t,fi(e))}getReducedForm(e,t){const o=this.getNormalized(e,t);if(void 0===o)return[];if(this._reducers.has(e)){return this._reducers.get(e)(o)}return[[e,o]]}getStyleNames(e){const t=new Set;for(const o of this._consumables.keys()){const i=this.getNormalized(o,e);i&&("object"!=typeof i||Object.keys(i).length)&&t.add(o)}for(const o of Object.keys(e))t.add(o);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 o of t)this._mapStyleNames(o,[e])}_mapStyleNames(e,t){this._consumables.has(e)||this._consumables.set(e,[]),this._consumables.get(e).push(...t)}}function fi(e){return e.replace("-",".")}function bi(e,t,o){let i=o;s(o)&&!Array.isArray(o)&&(i=G({},vo(e,t),o)),Ro(e,t,i)}function wi(e,t){for(const o of Object.keys(t))null===e[o]||Array.isArray(e[o])||"object"!=typeof e[o]||"object"!=typeof t[o]?delete e[o]:(wi(e[o],t[o]),Object.keys(e[o]).length||delete e[o])}class yi{_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 Qt(e))t&&this._set.add(t)}remove(e){for(const t of Qt(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 o of e.split(/\s+/)){if(!this._set.has(o))return;t.push(o)}return t}for(const o of this._set.keys())o.match(e)&&t.push(o);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}}class _i extends ni{name;_unsafeAttributesToRender=[];_attrs;_children;_customProperties=new Map;get _classes(){return this._attrs.get("class")}get _styles(){return this._attrs.get("style")}constructor(e,t,o,i){super(e),this.name=t,this._attrs=this._parseAttributes(o),this._children=[],i&&this._insertChild(0,i)}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||(vi(this.name,e)||ki(this.name,e)?this._attrs.get(e).has(t):this._attrs.get(e)===t))}isSimilar(e){if(!(e instanceof _i))return!1;if(this===e)return!0;if(this.name!=e.name)return!1;if(this._attrs.size!==e._attrs.size)return!1;for(const[t,o]of this._attrs){const i=e._attrs.get(t);if(void 0===i)return!1;if("string"==typeof o||"string"==typeof i){if(i!==o)return!1}else if(!o.isSimilar(i))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 ui(...e);let o=this.parent;for(;o&&!o.is("documentFragment");){if(t.match(o))return o;o=o.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),o=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}"`:"")+(""==o?"":` ${o}`)}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 o of this.getChildren())t.push(o._clone(e));const o=new this.constructor(this.document,this.name,this._attrs,t);return o._customProperties=new Map(this._customProperties),o.getFillerOffset=this.getFillerOffset,o._unsafeAttributesToRender=this._unsafeAttributesToRender,o}_appendChild(e){return this._insertChild(this.childCount,e)}_insertChild(e,t){this._fireChange("children",this,{index:e});let o=0;const i=function(e,t){if("string"==typeof t)return[new si(e,t)];Ue(t)||(t=[t]);const o=[];for(const i of t)"string"==typeof i?o.push(new si(e,i)):i instanceof ri?o.push(new si(e,i.data)):o.push(i);return o}(this.document,t);for(const t of i)null!==t.parent&&t._remove(),t.parent=this,t.document=this.document,this._children.splice(e,0,t),e++,o++;return o}_removeChildren(e,t=1){this._fireChange("children",this,{index:e});for(let o=e;ot&&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}}xi.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 Ei=Symbol("rootName");class Ti extends xi{constructor(e,t){super(e,t),this.rootName="main"}get rootName(){return this.getCustomProperty(Ei)}set rootName(e){this._setCustomProperty(Ei,e)}toJSON(){return this.rootName}set _name(e){this.name=e}}Ti.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};class Pi{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=Si._createAt(e.startPosition):this._position=Si._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,o;do{o=this.position,t=this.next()}while(!t.done&&e(t.value));t.done||(this._position=o)}jumpTo(e){this._boundaryStartParent&&e.isBefore(this.boundaries.start)?e=this.boundaries.start:this._boundaryEndParent&&e.isAfter(this.boundaries.end)&&(e=this.boundaries.end),this._position=e.clone()}next(){return"forward"==this.direction?this._next():this._previous()}_next(){let e=this.position.clone();const t=this.position,o=e.parent;if(null===o.parent&&e.offset===o.childCount)return{done:!0,value:void 0};if(o===this._boundaryEndParent&&e.offset==this.boundaries.end.offset)return{done:!0,value:void 0};let i;if(o&&o.is("view:$text")){if(e.isAtEnd)return this._position=Si._createAfter(o),this._next();i=o.data[e.offset]}else i=o.getChild(e.offset);if("string"==typeof i){let i;if(this.singleCharacters)i=1;else{i=(o===this._boundaryEndParent?this.boundaries.end.offset:o.data.length)-e.offset}const n=new ri(o,e.offset,i);return e.offset+=i,this._position=e,this._formatReturnValue("text",n,t,e,i)}if(i&&i.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 Si(i,0);return this._position=e,this._formatReturnValue("elementStart",i,t,e,1)}if(i&&i.is("view:$text")){if(this.singleCharacters)return e=new Si(i,0),this._position=e,this._next();let o,n=i.data.length;return i==this._boundaryEndParent?(n=this.boundaries.end.offset,o=new ri(i,0,n),e=Si._createAfter(o)):(o=new ri(i,0,i.data.length),e.offset++),this._position=e,this._formatReturnValue("text",o,t,e,n)}return e=Si._createAfter(o),this._position=e,this.ignoreElementEnd?this._next():this._formatReturnValue("elementEnd",o,t,e)}_previous(){let e=this.position.clone();const t=this.position,o=e.parent;if(null===o.parent&&0===e.offset)return{done:!0,value:void 0};if(o==this._boundaryStartParent&&e.offset==this.boundaries.start.offset)return{done:!0,value:void 0};let i;if(o.is("view:$text")){if(e.isAtStart)return this._position=Si._createBefore(o),this._previous();i=o.data[e.offset-1]}else i=o.getChild(e.offset-1);if("string"==typeof i){let i;if(this.singleCharacters)i=1;else{const t=o===this._boundaryStartParent?this.boundaries.start.offset:0;i=e.offset-t}e.offset-=i;const n=new ri(o,e.offset,i);return this._position=e,this._formatReturnValue("text",n,t,e,i)}if(i&&i.is("view:element"))return this.shallow?(e.offset--,this._position=e,this._formatReturnValue("elementStart",i,t,e,1)):(e=new Si(i,i.childCount),this._position=e,this.ignoreElementEnd?this._previous():this._formatReturnValue("elementEnd",i,t,e));if(i&&i.is("view:$text")){if(this.singleCharacters)return e=new Si(i,i.data.length),this._position=e,this._previous();let o,n=i.data.length;if(i==this._boundaryStartParent){const t=this.boundaries.start.offset;o=new ri(i,t,i.data.length-t),n=o.data.length,e=Si._createBefore(o)}else o=new ri(i,0,i.data.length),e.offset--;return this._position=e,this._formatReturnValue("text",o,t,e,n)}return e=Si._createBefore(o),this._position=e,this._formatReturnValue("elementStart",o,t,e,1)}_formatReturnValue(e,t,o,i,n){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)?o=Si._createAfter(t.textNode):(i=Si._createAfter(t.textNode),this._position=i)),0===t.offsetInText&&("backward"!=this.direction||this.boundaries&&this.boundaries.start.isEqual(this.position)?o=Si._createBefore(t.textNode):(i=Si._createBefore(t.textNode),this._position=i))),{done:!1,value:{type:e,item:t,previousPosition:o,nextPosition:i,length:n}}}}class Si extends ii{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 xi);){if(!e.parent)return null;e=e.parent}return e}getShiftedBy(e){const t=Si._createAt(this),o=t.offset+e;return t.offset=o<0?0:o,t}getLastMatchingPosition(e,t={}){t.startPosition=this;const o=new Pi(t);return o.skip(e),o.position}getAncestors(){return this.parent.is("documentFragment")?[this.parent]:this.parent.getAncestors({includeSelf:!0})}getCommonAncestor(e){const t=this.getAncestors(),o=e.getAncestors();let i=0;for(;t[i]==o[i]&&t[i];)i++;return 0===i?null:t[i-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():[],o=e.parent.is("node")?e.parent.getPath():[];t.push(this.offset),o.push(e.offset);const i=We(t,o);switch(i){case"prefix":return"before";case"extension":return"after";default:return t[i]0?new this(o,i):new this(i,o)}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(Si._createBefore(e),t)}}function Ri(e){return!(!e.item.is("attributeElement")&&!e.item.is("uiElement"))}Ii.prototype.is=function(e){return"range"===e||"view:range"===e};class Oi extends(xe(ii)){_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 o=!1;for(const i of e._ranges)if(t.isEqual(i)){o=!0;break}if(!o)return!1}return!0}isSimilar(e){if(this.isBackward!=e.isBackward)return!1;const t=He(this.getRanges());if(t!=He(e.getRanges()))return!1;if(0==t)return!0;for(let t of this.getRanges()){t=t.getTrimmed();let o=!1;for(let i of e.getRanges())if(i=i.getTrimmed(),t.start.isEqual(i.start)&&t.end.isEqual(i.end)){o=!0;break}if(!o)return!1}return!0}getSelectedElement(){return 1!==this.rangeCount?null:this.getFirstRange().getContainedElement()}setTo(...e){let[t,o,i]=e;if("object"==typeof o&&(i=o,o=void 0),null===t)this._setRanges([]),this._setFakeOptions(i);else if(t instanceof Oi||t instanceof Vi)this._setRanges(t.getRanges(),t.isBackward),this._setFakeOptions({fake:t.isFake,label:t.fakeSelectionLabel});else if(t instanceof Ii)this._setRanges([t],i&&i.backward),this._setFakeOptions(i);else if(t instanceof Si)this._setRanges([new Ii(t)]),this._setFakeOptions(i);else if(t instanceof ni){const e=!!i&&!!i.backward;let n;if(void 0===o)throw new fe("view-selection-setto-required-second-parameter",this);n="in"==o?Ii._createIn(t):"on"==o?Ii._createOn(t):new Ii(Si._createAt(t,o)),this._setRanges([n],e),this._setFakeOptions(i)}else{if(!Ue(t))throw new fe("view-selection-setto-not-selectable",this);this._setRanges(t,i&&i.backward),this._setFakeOptions(i)}this.fire("change")}setFocus(e,t){if(null===this.anchor)throw new fe("view-selection-setfocus-no-ranges",this);const o=Si._createAt(e,t);if("same"==o.compareWith(this.focus))return;const i=this.anchor;this._ranges.pop(),"before"==o.compareWith(i)?this._addRange(new Ii(o,i),!0):this._addRange(new Ii(i,o)),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 Ii))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 Ii(e.start,e.end))}}Oi.prototype.is=function(e){return"selection"===e||"view:selection"===e};class Vi extends(xe(ii)){_selection;constructor(...e){super(),this._selection=new Oi,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)}}Vi.prototype.is=function(e){return"selection"===e||"documentSelection"==e||"view:selection"==e||"view:documentSelection"==e};class Di extends ue{startRange;_eventPhase;_currentTarget;constructor(e,t,o){super(e,t),this.startRange=o,this._eventPhase="none",this._currentTarget=null}get eventPhase(){return this._eventPhase}get currentTarget(){return this._currentTarget}}const Fi=Symbol("bubblingEmitter"),Mi=Symbol("bubblingCallbacks"),Ni=Symbol("bubblingContexts");function Bi(e){return class extends e{fire(e,...t){try{const o=e instanceof ue?e:new ue(this,e),i=ji(this),n=$i(this);if(Li(o,"capturing",this),zi(i,"$capture",o,...t))return o.return;const s=o.startRange||this.selection.getFirstRange(),r=s?s.getContainedElement():null,a=!!r&&function(e,t){for(const o of e)if(o(t))return!0;return!1}(n,r);let l=r||function(e){if(!e)return null;const t=e.start.parent,o=e.end.parent,i=t.getPath(),n=o.getPath();return i.length>n.length?t:o}(s);if(Li(o,"atTarget",l),!a){if(zi(i,"$text",o,...t))return o.return;Li(o,"bubbling",l)}for(;l;){if(l.is("element")&&zi(i,l,o,...t))return o.return;l=l.parent,Li(o,"bubbling",l)}return Li(o,"bubbling",this),zi(i,"$document",o,...t),o.return}catch(e){fe.rethrowUnexpectedError(e,this)}}_addEventListener(e,t,o){const i=Qt(o.context||"$document"),n=ji(this),s=qi(this);for(const e of i)"function"==typeof e&&$i(this).add(e);const r=function(e,t,o){return function(i,n){const{currentTarget:s,eventArgs:r}=n;if("string"!=typeof s){if(s.is("rootElement")&&t.includes("$root"))o.call(e,i,...r);else if(t.includes(s.name))o.call(e,i,...r);else for(const n of t)if("function"==typeof n&&n(s))return void o.call(e,i,...r)}else t.includes(s)&&o.call(e,i,...r)}}(this,i,t);s.set(t,r),this.listenTo(n,e,r,o)}_removeEventListener(e,t){const o=ji(this),i=qi(this),n=i.get(t);n&&(i.delete(t),this.stopListening(o,e,n))}}}function Li(e,t,o){e instanceof Di&&(e._eventPhase=t,e._currentTarget=o)}function zi(e,t,o,...i){return e.fire(o,{currentTarget:t,eventArgs:i}),!!o.stop.called}function ji(e){return e[Fi]||(e[Fi]=new(xe())),e[Fi]}function qi(e){return e[Mi]||(e[Mi]=new Map),e[Mi]}function $i(e){return e[Ni]||(e[Ni]=new Set),e[Ni]}class Hi extends(Bi(Be())){selection;roots;stylesProcessor;_postFixers=new Set;constructor(e){super(),this.selection=new Vi,this.roots=new eo({idProperty:"rootName"}),this.stylesProcessor=e,this.set("isReadOnly",!1),this.set("isFocused",!1),this.set("isSelecting",!1),this.set("isComposing",!1)}getRoot(e="main"){return this.roots.get(e)}registerPostFixer(e){this._postFixers.add(e)}destroy(){this.roots.forEach((e=>e.destroy())),this.stopListening()}_callPostFixers(e){let t=!1;do{for(const o of this._postFixers)if(t=o(e),t)break}while(t)}}class Wi extends _i{static DEFAULT_PRIORITY=10;_priority=10;_id=null;_clonesGroup=null;constructor(e,t,o,i){super(e,t,o,i),this.getFillerOffset=Ui}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 Ui(){if(Ki(this))return null;let e=this.parent;for(;e&&e.is("attributeElement");){if(Ki(e)>1)return null;e=e.parent}return!e||Ki(e)>1?null:this.childCount}function Ki(e){return Array.from(e.getChildren()).filter((e=>!e.is("uiElement"))).length}Wi.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};class Gi extends _i{constructor(e,t,o,i){super(e,t,o,i),this.getFillerOffset=Ji}toJSON(){const e=super.toJSON();return e.type="EmptyElement",e}_insertChild(e,t){if(t&&(t instanceof ni||Array.from(t).length>0))throw new fe("view-emptyelement-cannot-add",[this,t]);return 0}}function Ji(){return null}Gi.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};class Zi extends _i{constructor(e,t,o,i){super(e,t,o,i),this.getFillerOffset=Yi}_insertChild(e,t){if(t&&(t instanceof ni||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 Qi(e){e.document.on("arrowKey",((t,o)=>function(e,t,o){if(t.keyCode==qt.arrowright){const e=t.domTarget.ownerDocument.defaultView.getSelection(),i=1==e.rangeCount&&e.getRangeAt(0).collapsed;if(i||t.shiftKey){const t=e.focusNode,n=e.focusOffset,s=o.domPositionToView(t,n);if(null===s)return;let r=!1;const a=s.getLastMatchingPosition((e=>(e.item.is("uiElement")&&(r=!0),!(!e.item.is("uiElement")&&!e.item.is("attributeElement")))));if(r){const t=o.viewPositionToDom(a);i?e.collapse(t.parent,t.offset):e.extend(t.parent,t.offset)}}}}(0,o,e.domConverter)),{priority:"low"})}function Yi(){return null}Zi.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};class Xi extends _i{constructor(e,t,o,i){super(e,t,o,i),this.getFillerOffset=en}toJSON(){const e=super.toJSON();return e.type="RawElement",e}_insertChild(e,t){if(t&&(t instanceof ni||Array.from(t).length>0))throw new fe("view-rawelement-cannot-add",[this,t]);return 0}render(e,t){}}function en(){return null}Xi.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};class tn extends(xe(ii)){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 o=0;const i=function(e,t){if("string"==typeof t)return[new si(e,t)];Ue(t)||(t=[t]);return Array.from(t).map((t=>"string"==typeof t?new si(e,t):t instanceof ri?new si(e,t.data):t))}(this.document,t);for(const t of i)null!==t.parent&&t._remove(),t.parent=this,this._children.splice(e,0,t),e++,o++;return o}_removeChildren(e,t=1){this._fireChange("children",this,{index:e});for(let o=e;o{const o=e[e.length-1],i=!t.is("uiElement");return o&&o.breakAttributes==i?o.nodes.push(t):e.push({breakAttributes:i,nodes:[t]}),e}),[]);let i=null,n=e;for(const{nodes:e,breakAttributes:t}of o){const o=this._insertNodes(n,e,t);i||(i=o.start),n=o.end}return i?new Ii(i,n):new Ii(e)}remove(e){const t=e instanceof Ii?e:Ii._createOn(e);if(hn(t,this.document),t.isCollapsed)return new tn(this.document);const{start:o,end:i}=this._breakAttributesRange(t,!0),n=o.parent,s=i.offset-o.offset,r=n._removeChildren(o.offset,s);for(const e of r)this._removeFromClonedElementsGroup(e);const a=this.mergeAttributes(o);return t.start=a,t.end=a.clone(),new tn(this.document,r)}clear(e,t){hn(e,this.document);const o=e.getWalker({direction:"backward",ignoreElementEnd:!0});for(const i of o){const o=i.item;let n;if(o.is("element")&&t.isSimilar(o))n=Ii._createOn(o);else if(!i.nextPosition.isAfter(e.start)&&o.is("$textProxy")){const e=o.getAncestors().find((e=>e.is("element")&&t.isSimilar(e)));e&&(n=Ii._createIn(e))}n&&(n.end.isAfter(e.end)&&(n.end=e.end),n.start.isBefore(e.start)&&(n.start=e.start),this.remove(n))}}move(e,t){let o;if(t.isAfter(e.end)){const i=(t=this._breakAttributes(t,!0)).parent,n=i.childCount;e=this._breakAttributesRange(e,!0),o=this.remove(e),t.offset+=i.childCount-n}else o=this.remove(e);return this.insert(t,o)}wrap(e,t){if(!(t instanceof Wi))throw new fe("view-writer-wrap-invalid-attribute",this.document);if(hn(e,this.document),e.isCollapsed){let i=e.start;i.parent.is("element")&&(o=i.parent,!Array.from(o.getChildren()).some((e=>!e.is("uiElement"))))&&(i=i.getLastMatchingPosition((e=>e.item.is("uiElement")))),i=this._wrapPosition(i,t);const n=this.document.selection;return n.isCollapsed&&n.getFirstPosition().isEqual(e.start)&&this.setSelection(i),new Ii(i)}return this._wrapRange(e,t);var o}unwrap(e,t){if(!(t instanceof Wi))throw new fe("view-writer-unwrap-invalid-attribute",this.document);if(hn(e,this.document),e.isCollapsed)return e;const{start:o,end:i}=this._breakAttributesRange(e,!0),n=o.parent,s=this._unwrapChildren(n,o.offset,i.offset,t),r=this.mergeAttributes(s.start);r.isEqual(s.start)||s.end.offset--;const a=this.mergeAttributes(s.end);return new Ii(r,a)}rename(e,t){const o=new Ci(this.document,e,t.getAttributes());return this.insert(Si._createAfter(t),o),this.move(Ii._createIn(t),Si._createAt(o,0)),this.remove(Ii._createOn(t)),o}clearClonedElementsGroup(e){this._cloneGroups.delete(e)}createPositionAt(e,t){return Si._createAt(e,t)}createPositionAfter(e){return Si._createAfter(e)}createPositionBefore(e){return Si._createBefore(e)}createRange(e,t){return new Ii(e,t)}createRangeOn(e){return Ii._createOn(e)}createRangeIn(e){return Ii._createIn(e)}createSelection(...e){return new Oi(...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,o){let i,n;if(i=o?nn(e):e.parent.is("$text")?e.parent.parent:e.parent,!i)throw new fe("view-writer-invalid-position-container",this.document);n=o?this._breakAttributes(e,!0):e.parent.is("$text")?an(e):e;const s=i._insertChild(n.offset,t);for(const e of t)this._addToClonedElementsGroup(e);const r=n.getShiftedBy(s),a=this.mergeAttributes(n);a.isEqual(n)||r.offset--;const l=this.mergeAttributes(r);return new Ii(a,l)}_wrapChildren(e,t,o,i){let n=t;const s=[];for(;n!1,e.parent._insertChild(e.offset,o);const i=new Ii(e,e.getShiftedBy(1));this.wrap(i,t);const n=new Si(o.parent,o.index);o._remove();const s=n.nodeBefore,r=n.nodeAfter;return s&&s.is("view:$text")&&r&&r.is("view:$text")?ln(s,r):rn(n)}_breakAttributesRange(e,t=!1){const o=e.start,i=e.end;if(hn(e,this.document),e.isCollapsed){const o=this._breakAttributes(e.start,t);return new Ii(o,o)}const n=this._breakAttributes(i,t),s=n.parent.childCount,r=this._breakAttributes(o,t);return n.offset+=n.parent.childCount-s,new Ii(r,n)}_breakAttributes(e,t=!1){const o=e.offset,i=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&&i.is("$text")&&un(i.parent))return e.clone();if(un(i))return e.clone();if(i.is("$text"))return this._breakAttributes(an(e),t);if(o==i.childCount){const e=new Si(i.parent,i.index+1);return this._breakAttributes(e,t)}if(0===o){const e=new Si(i.parent,i.index);return this._breakAttributes(e,t)}{const e=i.index+1,n=i._clone();i.parent._insertChild(e,n),this._addToClonedElementsGroup(n);const s=i.childCount-o,r=i._removeChildren(o,s);n._appendChild(r);const a=new Si(i.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 o=this._cloneGroups.get(t);o||(o=new Set,this._cloneGroups.set(t,o)),o.add(e),e._clonesGroup=o}_removeFromClonedElementsGroup(e){if(e.is("element"))for(const t of e.getChildren())this._removeFromClonedElementsGroup(t);const t=e.id;if(!t)return;const o=this._cloneGroups.get(t);o&&o.delete(e)}}function nn(e){let t=e.parent;for(;!un(t);){if(!t)return;t=t.parent}return t}function sn(e,t){return e.priorityt.priority)&&e.getIdentity()o instanceof e)))throw new fe("view-writer-insert-invalid-node-type",t);o.is("$text")||dn(o.getChildren(),t)}}function un(e){return e&&(e.is("containerElement")||e.is("documentFragment"))}function hn(e,t){const o=nn(e.start),i=nn(e.end);if(!o||!i||o!==i)throw new fe("view-writer-invalid-range-container",t)}const mn=e=>e.createTextNode(" "),gn=e=>{const t=e.createElement("span");return t.dataset.ckeFiller="true",t.innerText=" ",t},pn=e=>{const t=e.createElement("br");return t.dataset.ckeFiller="true",t},fn="".repeat(7);function bn(e){return"string"==typeof e?e.substr(0,7)===fn:at(e)&&e.data.substr(0,7)===fn}function wn(e){return 7==e.data.length&&bn(e)}function yn(e){const t="string"==typeof e?e:e.data;return bn(e)?t.slice(7):t}function _n(e,t){if(t.keyCode==qt.arrowleft){const e=t.domTarget.ownerDocument.defaultView.getSelection();if(1==e.rangeCount&&e.getRangeAt(0).collapsed){const t=e.getRangeAt(0).startContainer,o=e.getRangeAt(0).startOffset;bn(t)&&o<=7&&e.collapse(t,0)}}}class kn extends(Be()){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=Si._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),o=t.parent.ownerDocument;bn(t.parent)?this._inlineFiller=t.parent:this._inlineFiller=vn(o,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 o=Array.from(t.childNodes),i=Array.from(this.domConverter.viewChildrenToDom(e,{withChildren:!1})),n=this._diffNodeLists(o,i),s=this._findUpdateActions(n,o,i,Cn);if(-1!==s.indexOf("update")){const t={equal:0,insert:0,delete:0};for(const n of s)if("update"===n){const n=t.equal+t.insert,s=t.equal+t.delete,r=e.getChild(n);!r||r.is("uiElement")||r.is("rawElement")||this._updateElementMappings(r,o[s]),Pt(i[n]),t.equal++}else t[n]++}}_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")?Si._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&&at(t.parent)&&bn(t.parent))}_removeInlineFiller(){const e=this._inlineFiller;if(!bn(e))throw new fe("view-renderer-filler-was-lost",this);wn(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,o=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 i=e.nodeBefore,n=e.nodeAfter;return!(i instanceof si||n instanceof si)&&(!!(o!==t.getFillerOffset()||i&&i.is("element","br"))&&(!Y.isAndroid||!i&&!n))}_updateText(e,t){const o=this.domConverter.findCorrespondingDomText(e);let i=this.domConverter.viewToDom(e).data;const n=t.inlineFillerPosition;n&&n.parent==e.parent&&n.offset==e.index&&(i=fn+i),this._updateTextNode(o,i)}_updateAttrs(e){const t=this.domConverter.mapViewToDom(e);if(t){for(const o of Array.from(t.attributes)){const i=o.name;e.hasAttribute(i)||this.domConverter.removeDomElementAttribute(t,i)}for(const o of e.getAttributeKeys())this.domConverter.setDomElementAttribute(t,o,e.getAttribute(o),e)}}_updateChildren(e,t){const o=this.domConverter.mapViewToDom(e);if(!o)return;if(Y.isAndroid){let e=null;for(const t of Array.from(o.childNodes)){if(e&&at(e)&&at(t)){o.normalize();break}e=t}}const i=t.inlineFillerPosition,n=o.childNodes,s=Array.from(this.domConverter.viewChildrenToDom(e,{bind:!0}));i&&i.parent===e&&vn(o.ownerDocument,s,i.offset);const r=this._diffNodeLists(n,s),a=this._findUpdateActions(r,n,s,An);let l=0;const c=new Set;for(const e of a)"delete"===e?(c.add(n[l]),Pt(n[l])):"equal"!==e&&"update"!==e||l++;l=0;for(const e of a)"insert"===e?(kt(o,l,s[l]),l++):"update"===e?(this._updateTextNode(n[l],s[l].data),l++):"equal"===e&&(this._markDescendantTextToSync(this.domConverter.domToView(s[l])),l++);for(const e of c)e.parentNode||this.domConverter.unbindDomElement(e)}_diffNodeLists(e,t){return de(e=function(e,t){const o=Array.from(e);if(0==o.length||!t)return o;o[o.length-1]==t&&o.pop();return o}(e,this._fakeSelectionContainer),t,xn.bind(null,this.domConverter))}_findUpdateActions(e,t,o,i){if(-1===e.indexOf("insert")||-1===e.indexOf("delete"))return e;let n=[],s=[],r=[];const a={equal:0,insert:0,delete:0};for(const l of e)"insert"===l?r.push(o[a.equal+a.insert]):"delete"===l?s.push(t[a.equal+a.delete]):(n=n.concat(de(s,r,i).map((e=>"equal"===e?"update":e))),n.push("equal"),s=[],r=[]),a[l]++;return n.concat(de(s,r,i).map((e=>"equal"===e?"update":e)))}_updateTextNode(e,t){const o=e.data;o!=t&&(Y.isAndroid&&this.isComposing&&o.replace(/\u00A0/g," ")==t.replace(/\u00A0/g," ")||this._updateTextNodeInternal(e,t))}_updateTextNodeInternal(e,t){const o=ae(e.data,t);for(const t of o)"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 o=this._fakeSelectionContainer;if(this.domConverter.bindFakeSelection(o,this.selection),!this._fakeSelectionNeedsUpdate(e))return;o.parentElement&&o.parentElement==e||e.appendChild(o),o.textContent=this.selection.fakeSelectionLabel||" ";const i=t.getSelection(),n=t.createRange();i.removeAllRanges(),n.selectNodeContents(o),i.addRange(n)}_updateDomSelection(e){const t=e.ownerDocument.defaultView.getSelection();if(!this._domSelectionNeedsUpdate(t))return;const o=this.domConverter.viewPositionToDom(this.selection.anchor),i=this.domConverter.viewPositionToDom(this.selection.focus);t.setBaseAndExtent(o.parent,o.offset,i.parent,i.offset),Y.isGecko&&function(e,t){let o=e.parent,i=e.offset;at(o)&&wn(o)&&(i=_t(o)+1,o=o.parentNode);if(o.nodeType!=Node.ELEMENT_NODE||i!=o.childNodes.length-1)return;const n=o.childNodes[i];n&&"BR"==n.tagName&&t.addRange(t.getRangeAt(0))}(i,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,o=e.ownerDocument.getSelection();return!t||t.parentElement!==e||(o.anchorNode!==t&&!t.contains(o.anchorNode)||t.textContent!==this.selection.fakeSelectionLabel)}_removeDomSelection(){for(const e of this.domDocuments){const t=e.getSelection();if(t.rangeCount){const o=e.activeElement,i=this.domConverter.mapDomToView(o);o&&i&&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 vn(e,t,o){const i=t instanceof Array?t:t.childNodes,n=i[o];if(at(n))return n.data=fn+n.data,n;{const n=e.createTextNode(fn);return Array.isArray(t)?i.splice(o,0,n):kt(t,o,n),n}}function Cn(e,t){return Qe(e)&&Qe(t)&&!at(e)&&!at(t)&&!vt(e)&&!vt(t)&&e.tagName.toLowerCase()===t.tagName.toLowerCase()}function An(e,t){return Qe(e)&&Qe(t)&&at(e)&&at(t)}function xn(e,t,o){return t===o||(at(t)&&at(o)?t.data===o.data:!(!e.isBlockFiller(t)||!e.isBlockFiller(o)))}const En=pn(J.document),Tn=mn(J.document),Pn=gn(J.document),Sn="data-ck-unsafe-attribute-",In="data-ck-unsafe-element";class Rn{document;renderingMode;blockFillerMode;preElements;blockElements;inlineObjectElements;unsafeElements;_domDocument;_domToViewMapping=new WeakMap;_viewToDomMapping=new WeakMap;_fakeSelectionMapping=new WeakMap;_rawContentElementMatcher=new ui;_inlineObjectElementMatcher=new ui;_elementsWithTemporaryCustomProperties=new Set;constructor(e,{blockFillerMode:t,renderingMode:o="editing"}={}){this.document=e,this.renderingMode=o,this.blockFillerMode=t||("editing"===o?"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?J.document:J.document.implementation.createHTMLDocument("")}get domDocument(){return this._domDocument}bindFakeSelection(e,t){this._fakeSelectionMapping.set(e,new Oi(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,o){return"data"===this.renderingMode||!(e=e.toLowerCase()).startsWith("on")&&("srcdoc"!==e&&("img"===o&&("src"===e||"srcset"===e)||("source"===o&&"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 o=(new DOMParser).parseFromString(t,"text/html"),i=o.createDocumentFragment(),n=o.body.childNodes;for(;n.length>0;)i.appendChild(n[0]);const s=o.createTreeWalker(i,NodeFilter.SHOW_ELEMENT),r=[];let a;for(;a=s.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)&&(Bn(t),e.replaceWith(this._createReplacementDomElement(t,e)))}for(;e.firstChild;)e.firstChild.remove();e.append(i)}viewToDom(e,t={}){if(e.is("$text")){const t=this._processDataFromViewText(e);return this._domDocument.createTextNode(t)}{const o=e;if(this.mapViewToDom(o)){if(!o.getCustomProperty("editingPipeline:doNotReuseOnce"))return this.mapViewToDom(o);this._elementsWithTemporaryCustomProperties.add(o)}let i;if(o.is("documentFragment"))i=this._domDocument.createDocumentFragment(),t.bind&&this.bindDocumentFragments(i,o);else{if(o.is("uiElement"))return i="$comment"===o.name?this._domDocument.createComment(o.getCustomProperty("$rawContent")):o.render(this._domDocument,this),t.bind&&this.bindElements(i,o),i;this._shouldRenameElement(o.name)?(Bn(o.name),i=this._createReplacementDomElement(o.name)):i=o.hasAttribute("xmlns")?this._domDocument.createElementNS(o.getAttribute("xmlns"),o.name):this._domDocument.createElement(o.name),o.is("rawElement")&&o.render(i,this),t.bind&&this.bindElements(i,o);for(const e of o.getAttributeKeys())this.setDomElementAttribute(i,e,o.getAttribute(e),o)}if(!1!==t.withChildren)for(const e of this.viewChildrenToDom(o,t))i instanceof HTMLTemplateElement?i.content.appendChild(e):i.appendChild(e);return i}}setDomElementAttribute(e,t,o,i){const n=this.shouldRenderAttribute(t,o,e.tagName.toLowerCase())||i&&i.shouldRenderUnsafeAttribute(t);n||be("domconverter-unsafe-attribute-detected",{domElement:e,key:t,value:o}),function(e){try{J.document.createAttribute(e)}catch{return!1}return!0}(t)?(e.hasAttribute(t)&&!n?e.removeAttribute(t):e.hasAttribute(Sn+t)&&n&&e.removeAttribute(Sn+t),e.setAttribute(n?t:Sn+t,o)):be("domconverter-invalid-attribute-detected",{domElement:e,key:t,value:o})}removeDomElementAttribute(e,t){t!=In&&(e.removeAttribute(t),e.removeAttribute(Sn+t))}*viewChildrenToDom(e,t={}){const o=e.getFillerOffset&&e.getFillerOffset();let i=0;for(const n of e.getChildren()){o===i&&(yield this._getBlockFiller());const e=n.is("element")&&!!n.getCustomProperty("dataPipeline:transparentRendering")&&!to(n.getAttributes());if(e&&"data"==this.renderingMode)if(n.is("rawElement")){const e=this._domDocument.createElement(n.name);n.render(e,this),yield*[...e.childNodes]}else yield*this.viewChildrenToDom(n,t);else e&&be("domconverter-transparent-rendering-unsupported-in-editing-pipeline",{viewElement:n}),yield this.viewToDom(n,t);i++}o===i&&(yield this._getBlockFiller())}viewRangeToDom(e){const t=this.viewPositionToDom(e.start),o=this.viewPositionToDom(e.end),i=this._domDocument.createRange();return i.setStart(t.parent,t.offset),i.setEnd(o.parent,o.offset),i}viewPositionToDom(e){const t=e.parent;if(t.is("$text")){const o=this.findCorrespondingDomText(t);if(!o)return null;let i=e.offset;return bn(o)&&(i+=7),o.data&&i>o.data.length&&(i=o.data.length),{parent:o,offset:i}}{let o,i,n;if(0===e.offset){if(o=this.mapViewToDom(t),!o)return null;n=o.childNodes[0]}else{const t=e.nodeBefore;if(i=t.is("$text")?this.findCorrespondingDomText(t):this.mapViewToDom(t),!i)return null;o=i.parentNode,n=i.nextSibling}if(at(n)&&bn(n))return{parent:n,offset:7};return{parent:o,offset:i?_t(i)+1:0}}}domToView(e,t={}){const o=[],i=this._domToView(e,t,o),n=i.next().value;return n?(i.next(),this._processDomInlineNodes(null,o,t),"br"==this.blockFillerMode&&Mn(n)||n.is("$text")&&0==n.data.length?null:n):null}*domChildrenToView(e,t={},o=[]){let i=[];i=e instanceof HTMLTemplateElement?[...e.content.childNodes]:[...e.childNodes];for(let n=0;n{const{scrollLeft:t,scrollTop:o}=e;n.push([t,o])})),t.focus({preventScroll:!0}),On(t,(e=>{const[t,o]=n.shift();e.scrollLeft=t,e.scrollTop=o})),J.window.scrollTo(o,i)}_clearDomSelection(){const e=this.mapViewToDom(this.document.selection.editableElement);if(!e)return;const t=e.ownerDocument.defaultView.getSelection(),o=this.domSelectionToView(t);o&&o.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(En):!!Nn(e,this.blockElements)||(e.isEqualNode(Pn)||function(e,t){const o=e.isEqualNode(Tn);return o&&Vn(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 o=t.collapsed;return t.detach(),o}getHostViewElement(e){const t=it(e);for(t.pop();t.length;){const e=t.pop(),o=this._domToViewMapping.get(e);if(o&&(o.is("uiElement")||o.is("rawElement")))return o}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 mn(this._domDocument);case"markedNbsp":return gn(this._domDocument);case"br":return pn(this._domDocument)}}_isDomSelectionPositionCorrect(e,t){if(at(e)&&bn(e)&&t<7)return!1;if(this.isElement(e)&&bn(e.childNodes[t]))return!1;const o=this.mapDomToView(e);return!o||!o.is("uiElement")&&!o.is("rawElement")}*_domToView(e,t,o){if("br"!=this.blockFillerMode&&Nn(e,this.blockElements))return null;const i=this.getHostViewElement(e);if(i)return i;if(vt(e)&&t.skipComments)return null;if(at(e)){if(wn(e))return null;{const t=e.data;if(""===t)return null;const i=new si(this.document,t);return o.push(i),i}}{let i=this.mapDomToView(e);if(i)return this._isInlineObjectElement(i)&&o.push(i),i;if(this.isDocumentFragment(e))i=new tn(this.document),t.bind&&this.bindDocumentFragments(e,i);else{i=this._createViewElement(e,t),t.bind&&this.bindElements(e,i);const n=e.attributes;if(n)for(let e=n.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 o=new Pi({startPosition:t?Si._createAfter(e):Si._createBefore(e),direction:t?"forward":"backward"});for(const{item:e}of o){if(e.is("$textProxy"))return e;if(!e.is("element")||!e.getCustomProperty("dataPipeline:transparentRendering")){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(vt(e))return new Zi(this.document,"$comment");const o=t.keepOriginalCase?e.tagName:e.tagName.toLowerCase();return new _i(this.document,o)}_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 o=this._domDocument.createElement("span");if(o.setAttribute(In,e),t){for(;t.firstChild;)o.appendChild(t.firstChild);for(const e of t.getAttributeNames())o.setAttribute(e,t.getAttribute(e))}return o}}function On(e,t){let o=e;for(;o;)t(o),o=o.parentElement}function Vn(e,t){const o=e.parentNode;return!!o&&!!o.tagName&&t.includes(o.tagName.toLowerCase())}function Dn(e,t,o){return" "==t&&e&&e.is("element")&&1==e.childCount&&o.includes(e.name)}function Fn(e,t){return" "==t&&e&&e.is("element","span")&&1==e.childCount&&e.hasAttribute("data-cke-filler")}function Mn(e){return e.is("element","br")&&e.hasAttribute("data-cke-filler")}function Nn(e,t){return"BR"===e.tagName&&Vn(e,t)&&1===e.parentNode.childNodes.length}function Bn(e){"script"===e&&be("domconverter-unsafe-script-element-detected"),"style"===e&&be("domconverter-unsafe-style-element-detected")}class Ln extends(et()){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] *")}}class zn{view;document;domEvent;domTarget;constructor(e,t,o){this.view=e,this.document=e.document,this.domEvent=t,this.domTarget=t.target,No(this,o)}get target(){return this.view.domConverter.mapDomToView(this.domTarget)}preventDefault(){this.domEvent.preventDefault()}stopPropagation(){this.domEvent.stopPropagation()}}class jn extends Ln{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,o){this.isEnabled&&this.document.fire(e,new zn(this.view,t,o))}}class qn extends jn{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 Ht(this)}};this.fire(e.type,e,t)}}class $n extends Ln{_fireSelectionChangeDoneDebounced;constructor(e){super(e),this._fireSelectionChangeDoneDebounced=zo((e=>{this.document.fire("selectionChangeDone",e)}),200)}observe(){const e=this.document;e.on("arrowKey",((t,o)=>{e.selection.isFake&&this.isEnabled&&o.preventDefault()}),{context:"$capture"}),e.on("arrowKey",((t,o)=>{e.selection.isFake&&this.isEnabled&&this._handleSelectionMove(o.keyCode)}),{priority:"lowest"})}stopObserving(){}destroy(){super.destroy(),this._fireSelectionChangeDoneDebounced.cancel()}_handleSelectionMove(e){const t=this.document.selection,o=new Oi(t.getRanges(),{backward:t.isBackward,fake:!1});e!=qt.arrowleft&&e!=qt.arrowup||o.setTo(o.getFirstPosition()),e!=qt.arrowright&&e!=qt.arrowdown||o.setTo(o.getLastPosition());const i={oldSelection:t,newSelection:o,domSelection:null};this.document.fire("selectionChange",i),this._fireSelectionChangeDoneDebounced(i)}}class Hn extends Ln{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,o=new Set,i=new Set;for(const o of e){const e=t.mapDomToView(o.target);e&&(e.is("uiElement")||e.is("rawElement")||"childList"!==o.type||this._isBogusBrMutation(o)||i.add(e))}for(const n of e){const e=t.mapDomToView(n.target);if((!e||!e.is("uiElement")&&!e.is("rawElement"))&&"characterData"===n.type){const e=t.findCorrespondingViewText(n.target);e&&!i.has(e.parent)?o.add(e):!e&&bn(n.target)&&i.add(t.mapDomToView(n.target.parentNode))}}const n=[];for(const e of o)n.push({type:"text",node:e});for(const e of i){const o=t.mapViewToDom(e);Uo(Array.from(e.getChildren()),Array.from(t.domChildrenToView(o,{withChildren:!1})),Wn)||n.push({type:"children",node:e})}n.length&&this.document.fire("mutations",{mutations:n})}_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 Wn(e,t){if(!Array.isArray(e))return e===t||!(!e.is("$text")||!t.is("$text"))&&e.data===t.data}class Un extends jn{_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)}}class Kn extends Ln{mutationObserver;focusObserver;selection;domConverter;_documents=new WeakSet;_fireSelectionChangeDoneDebounced;_clearInfiniteLoopInterval;_documentIsSelectingInactivityTimeoutDebounced;_loopbackCounter=0;_pendingSelectionChange=new Set;constructor(e){super(e),this.mutationObserver=e.getObserver(Hn),this.focusObserver=e.getObserver(Un),this.selection=this.document.selection,this.domConverter=e.domConverter,this._fireSelectionChangeDoneDebounced=zo((e=>{this.document.fire("selectionChangeDone",e)}),200),this._clearInfiniteLoopInterval=setInterval((()=>this._clearInfiniteLoop()),1e3),this._documentIsSelectingInactivityTimeoutDebounced=zo((()=>this.document.isSelecting=!1),5e3),this.view.document.on("change:isFocused",((e,t,o)=>{if(o&&this._pendingSelectionChange.size){for(const e of Array.from(this._pendingSelectionChange))this._handleSelectionChange(e);this._pendingSelectionChange.clear()}}))}observe(e){const t=e.ownerDocument,o=()=>{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",o,{priority:"highest",useCapture:!0}),this.listenTo(e,"keyup",o,{priority:"highest",useCapture:!0}),this._documents.has(t)||(this.listenTo(t,"mouseup",o,{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 o=this.domConverter.domSelectionToView(t);if(0!=o.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(o)||!this.domConverter.isDomSelectionCorrect(t))if(++this._loopbackCounter>60)this._reportInfiniteLoop();else if(function(e){return Array.from(e.getRanges()).flatMap((e=>[e.start.root,e.end.root])).every((e=>e&&e.is("rootElement")))}(o))if(this.selection.isSimilar(o))this.view.forceRender();else{const e={oldSelection:this.selection,newSelection:o,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}}class Gn extends jn{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})}}class Jn{_files;_native;constructor(e,t={}){this._files=t.cacheFiles?Zn(e):null,this._native=e}get files(){return this._files||(this._files=Zn(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,o){this._native.setDragImage(e,t,o)}get isCanceled(){return"none"==this._native.dropEffect||!!this._native.mozUserCancelled}}function Zn(e){const t=Array.from(e.files||[]),o=Array.from(e.items||[]);return t.length?t:o.filter((e=>"file"===e.kind)).map((e=>e.getAsFile()))}class Qn extends jn{domEventType="beforeinput";onDomEvent(e){const t=e.getTargetRanges(),o=this.view,i=o.document;let n=null,s=null,r=[];if(e.dataTransfer&&(n=new Jn(e.dataTransfer)),null!==e.data?s=e.data:n&&(s=n.getData("text/plain")),i.selection.isFake)r=Array.from(i.selection.getRanges()),e.preventDefault();else if(t.length)r=t.map((t=>{let i=o.domConverter.domPositionToView(t.startContainer,t.startOffset);const n=o.domConverter.domPositionToView(t.endContainer,t.endOffset);if(i&&bn(t.startContainer)&&t.startOffset<7){e.preventDefault();let o=7-t.startOffset;i=i.getLastMatchingPosition((e=>!(!e.item.is("attributeElement")&&!e.item.is("uiElement"))||!(!e.item.is("$textProxy")||!o--)),{direction:"backward",singleCharacters:!0})}return function(e,t){for(;e.parentNode;){if(at(e)){if(t!=e.data.length)return!1}else if(t!=e.childNodes.length)return!1;if((t=_t(e)+1)<(e=e.parentNode).childNodes.length&&bn(e.childNodes[t]))return!0}return!1}(t.endContainer,t.endOffset)&&e.preventDefault(),i?o.createRange(i,n):n?o.createRange(n):void 0})).filter((e=>!!e));else if(Y.isAndroid){const t=e.target.ownerDocument.defaultView.getSelection();r=Array.from(o.domConverter.domSelectionToView(t).getRanges())}if(Y.isAndroid&&"insertCompositionText"==e.inputType&&s&&s.endsWith("\n"))this.fire(e.type,e,{inputType:"insertParagraph",targetRanges:[o.createRange(r[0].end)]});else if(["insertText","insertReplacementText"].includes(e.inputType)&&s&&s.includes("\n")){const t=s.split(/\n{1,2}/g);let o=r;e.preventDefault();for(let s=0;s{if(this.isEnabled&&((o=t.keyCode)==qt.arrowright||o==qt.arrowleft||o==qt.arrowup||o==qt.arrowdown)){const o=new Di(this.document,"arrowKey",this.document.selection.getFirstRange());this.document.fire(o,t),o.stop.called&&e.stop()}var o}))}observe(){}stopObserving(){}}class Xn extends Ln{constructor(e){super(e);const t=this.document;t.on("keydown",((e,o)=>{if(!this.isEnabled||o.keyCode!=qt.tab||o.ctrlKey)return;const i=new Di(t,"tab",t.selection.getFirstRange());t.fire(i,o),i.stop.called&&e.stop()}))}observe(){}stopObserving(){}}class es extends(Be()){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 Hi(e),this.domConverter=new Rn(this.document),this.set("isRenderingInProgress",!1),this.set("hasDomSelection",!1),this._renderer=new kn(this.domConverter,this.document.selection),this._renderer.bind("isFocused","isSelecting","isComposing").to(this.document,"isFocused","isSelecting","isComposing"),this._writer=new on(this.document),this.addObserver(Hn),this.addObserver(Un),this.addObserver(Kn),this.addObserver(qn),this.addObserver($n),this.addObserver(Gn),this.addObserver(Yn),this.addObserver(Qn),this.addObserver(Xn),this.document.on("arrowKey",_n,{priority:"low"}),Qi(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 o=this.document.getRoot(t);o._name=e.tagName.toLowerCase();const i={};for(const{name:t,value:n}of Array.from(e.attributes))i[t]=n,"class"===t?this._writer.addClass(n.split(" "),o):o.hasAttribute(t)||this._writer.setAttribute(t,n,o);this._initialDomRootAttributes.set(e,i);const n=()=>{this._writer.setAttribute("contenteditable",(!o.isReadOnly).toString(),o),o.isReadOnly?this._writer.addClass("ck-read-only",o):this._writer.removeClass("ck-read-only",o)};n(),this.domRoots.set(t,e),this.domConverter.bindElements(e,o),this._renderer.markToSync("children",o),this._renderer.markToSync("attributes",o),this._renderer.domDocuments.add(e.ownerDocument),o.on("change:children",((e,t)=>this._renderer.markToSync("children",t))),o.on("change:attributes",((e,t)=>this._renderer.markToSync("attributes",t))),o.on("change:text",((e,t)=>this._renderer.markToSync("text",t))),o.on("change:isReadOnly",(()=>this.change(n))),o.on("change",(()=>{this._hasChangedSinceTheLastRendering=!0}));for(const o of this._observers.values())o.observe(e,t)}detachDomRoot(e){const t=this.domRoots.get(e);Array.from(t.attributes).forEach((({name:e})=>t.removeAttribute(e)));const o=this._initialDomRootAttributes.get(t);for(const e in o)t.setAttribute(e,o[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,o]of this.domRoots)t.observe(o,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:o=20,ancestorOffset:i=20}={}){const n=this.document.selection.getFirstRange();if(!n)return;const s=j({alignToTop:e,forceScroll:t,viewportOffset:o,ancestorOffset:i});"number"==typeof o&&(o={top:o,bottom:o,left:o,right:o});const r={target:this.domConverter.viewRangeToDom(n),viewportOffset:o,ancestorOffset:i,alignToTop:e,forceScroll:t};this.fire("scrollToTheSelection",r,s),function({target:e,viewportOffset:t=0,ancestorOffset:o=0,alignToTop:i,forceScroll:n}){const s=Mt(e);let r=s,a=null;for(t=function(e){return"number"==typeof e?{top:e,bottom:e,left:e,right:e}:e}(t);r;){let l;l=Nt(r==s?e:a),Rt({parent:l,getRect:()=>Bt(e,r),alignToTop:i,ancestorOffset:o,forceScroll:n});let c=Bt(e,r);const d=Bt(l,r);if(c.height>d.height){const e=c.getIntersection(d);e&&(c=e)}if(It({window:r,rect:c,viewportOffset:t,alignToTop:i,forceScroll:n}),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(Un).flush(),this.change((()=>{}))}destroy(){for(const e of this._observers.values())e.destroy();this.document.destroy(),this.stopListening()}createPositionAt(e,t){return Si._createAt(e,t)}createPositionAfter(e){return Si._createAfter(e)}createPositionBefore(e){return Si._createBefore(e)}createRange(e,t){return new Ii(e,t)}createRangeOn(e){return Ii._createOn(e)}createRangeIn(e){return Ii._createIn(e)}createSelection(...e){return new Oi(...e)}_disableRendering(e){this._renderingDisabled=e,0==e&&this.change((()=>{}))}_render(){this.isRenderingInProgress=!0,this.disableObservers(),this._renderer.render(),this.enableObservers(),this.isRenderingInProgress=!1}}class ts{is(){throw new Error("is() method is abstract")}}class os extends ts{textNode;data;offsetInText;constructor(e,t,o){if(super(),this.textNode=e,t<0||t>e.offsetSize)throw new fe("model-textproxy-wrong-offsetintext",this);if(o<0||t+o>e.offsetSize)throw new fe("model-textproxy-wrong-length",this);this.data=e.data.substring(t,t+o),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 o=e.includeSelf?this:this.parent;for(;o;)t[e.parentFirst?"push":"unshift"](o),o=o.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()}}os.prototype.is=function(e){return"$textProxy"===e||"model:$textProxy"===e||"textProxy"===e||"model:textProxy"===e};class is{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=ss._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,o,i,n;do{i=this.position,n=this._visitedParent,({done:t,value:o}=this.next())}while(!t&&e(o));t||(this._position=i,this._visitedParent=n)}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(),o=this._visitedParent;if(null===o.parent&&t.offset===o.maxOffset)return{done:!0,value:void 0};if(o===this._boundaryEndParent&&t.offset==this.boundaries.end.offset)return{done:!0,value:void 0};const i=rs(t,o),n=i||as(t,o,i);if(n&&n.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=n;return this._position=t,ns("elementStart",n,e,t,1)}if(n&&n.is("model:$text")){let i;if(this.singleCharacters)i=1;else{let e=n.endOffset;this._boundaryEndParent==o&&this.boundaries.end.offsete&&(e=this.boundaries.start.offset),i=t.offset-e}const n=t.offset-s.startOffset,r=new os(s,n-i,i);return t.offset-=i,this._position=t,ns("text",r,e,t,i)}return t.path.pop(),this._position=t,this._visitedParent=o.parent,ns("elementStart",o,e,t,1)}}function ns(e,t,o,i,n){return{done:!1,value:{type:e,item:t,previousPosition:o,nextPosition:i,length:n}}}class ss extends ts{root;path;stickiness;constructor(e,t,o="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=o}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 cs(e,this,o);if(-1===t)return cs(this,e,o)}return this.path.length===e.path.length||(this.path.length>e.path.length?ds(this.path,t):ds(e.path,t))}hasSameParentAs(e){if(this.root!==e.root)return!1;return"same"==We(this.getParentPath(),e.getParentPath())}getTransformedByOperation(e){let t;switch(e.type){case"insert":t=this._getTransformedByInsertOperation(e);break;case"move":case"remove":case"reinsert":t=this._getTransformedByMoveOperation(e);break;case"split":t=this._getTransformedBySplitOperation(e);break;case"merge":t=this._getTransformedByMergeOperation(e);break;default:t=ss._createAt(this)}return t}_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(e){const t=e.movedRange;let o;return t.containsPosition(this)||t.start.isEqual(this)?(o=this._getCombined(e.sourcePosition,e.targetPosition),e.sourcePosition.isBefore(e.targetPosition)&&(o=o._getTransformedByDeletion(e.deletionPosition,1))):o=this.isEqual(e.deletionPosition)?ss._createAt(e.deletionPosition):this._getTransformedByMove(e.deletionPosition,e.graveyardPosition,1),o}_getTransformedByDeletion(e,t){const o=ss._createAt(this);if(this.root!=e.root)return o;if("same"==We(e.getParentPath(),this.getParentPath())){if(e.offsetthis.offset)return null;o.offset-=t}}else if("prefix"==We(e.getParentPath(),this.getParentPath())){const i=e.path.length-1;if(e.offset<=this.path[i]){if(e.offset+t>this.path[i])return null;o.path[i]-=t}}return o}_getTransformedByInsertion(e,t){const o=ss._createAt(this);if(this.root!=e.root)return o;if("same"==We(e.getParentPath(),this.getParentPath()))(e.offset=t;){if(e.path[i]+n!==o.maxOffset)return!1;n=1,i--,o=o.parent}return!0}(e,o+1))}function ds(e,t){for(;tt+1;){const t=i.maxOffset-o.offset;0!==t&&e.push(new us(o,o.getShiftedBy(t))),o.path=o.path.slice(0,-1),o.offset++,i=i.parent}for(;o.path.length<=this.end.path.length;){const t=this.end.path[o.path.length-1],i=t-o.offset;0!==i&&e.push(new us(o,o.getShiftedBy(i))),o.offset=t,o.path.push(0)}return e}getWalker(e={}){return e.boundaries=this,new is(e)}*getItems(e={}){e.boundaries=this,e.ignoreElementEnd=!0;const t=new is(e);for(const e of t)yield e.item}*getPositions(e={}){e.boundaries=this;const t=new is(e);yield t.position;for(const e of t)yield e.nextPosition}getTransformedByOperation(e){switch(e.type){case"insert":return this._getTransformedByInsertOperation(e);case"move":case"remove":case"reinsert":return this._getTransformedByMoveOperation(e);case"split":return[this._getTransformedBySplitOperation(e)];case"merge":return[this._getTransformedByMergeOperation(e)]}return[new us(this.start,this.end)]}getTransformedByOperations(e){const t=[new us(this.start,this.end)];for(const o of e)for(let e=0;e0?new this(o,i):new this(i,o)}static _createIn(e){return new this(ss._createAt(e,0),ss._createAt(e,e.maxOffset))}static _createOn(e){return this._createFromPositionAndShift(ss._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 o=e.indexOf(t),i=new this(t.start,t.end);for(let t=o-1;t>=0&&e[t].end.isEqual(i.start);t--)i.start=ss._createAt(e[t].start);for(let t=o+1;t{if(t.viewPosition)return;const o=this._modelToViewMapping.get(t.modelPosition.parent);if(!o)throw new fe("mapping-model-position-view-parent-not-found",this,{modelPosition:t.modelPosition});t.viewPosition=this.findPositionIn(o,t.modelPosition.offset)}),{priority:"low"}),this.on("viewToModelPosition",((e,t)=>{if(t.modelPosition)return;const o=this.findMappedViewAncestor(t.viewPosition),i=this._viewToModelMapping.get(o),n=this._toModelOffset(t.viewPosition.parent,t.viewPosition.offset,o);t.modelPosition=ss._createAt(i,n)}),{priority:"low"})}bindElements(e,t){this._modelToViewMapping.set(e,t),this._viewToModelMapping.set(t,e)}unbindViewElement(e,t={}){const o=this.toModelElement(e);if(this._elementToMarkerNames.has(e))for(const t of this._elementToMarkerNames.get(e))this._unboundMarkerNames.add(t);if(t.defer)this._deferredBindingRemovals.set(e,e.root);else{this._viewToModelMapping.delete(e)&&this._cache.stopTracking(e),this._modelToViewMapping.get(o)==e&&this._modelToViewMapping.delete(o)}}unbindModelElement(e){const t=this.toViewElement(e);if(this._modelToViewMapping.delete(e),this._viewToModelMapping.get(t)==e){this._viewToModelMapping.delete(t)&&this._cache.stopTracking(t)}}bindElementToMarker(e,t){const o=this._markerNameToElements.get(t)||new Set;o.add(e);const i=this._elementToMarkerNames.get(e)||new Set;i.add(t),this._markerNameToElements.set(t,o),this._elementToMarkerNames.set(e,i)}unbindElementFromMarkerName(e,t){const o=this._markerNameToElements.get(t);o&&(o.delete(e),0==o.size&&this._markerNameToElements.delete(t));const i=this._elementToMarkerNames.get(e);i&&(i.delete(t),0==i.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 us(this.toModelPosition(e.start),this.toModelPosition(e.end))}toViewRange(e){return new Ii(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 o={modelPosition:e,mapper:this,isPhantom:t.isPhantom};return this.fire("modelToViewPosition",o),o.viewPosition}markerNameToElements(e){const t=this._markerNameToElements.get(e);if(!t)return null;const o=new Set;for(const e of t)if(e.is("attributeElement"))for(const t of e.getElementsWithSameId())o.add(t);else o.add(e);return o}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,o){if(o!=e){return this._toModelOffset(e.parent,e.index,o)+this._toModelOffset(e,t,e)}if(e.is("$text"))return t;let i=0;for(let o=0;o0;){const e=t.pop(),i=e.name&&this._viewToModelLengthCallbacks.size>0&&this._viewToModelLengthCallbacks.get(e.name);if(i)o+=i(e);else if(this._viewToModelMapping.has(e))o+=1;else if(e.is("$text"))o+=e.data.length;else{if(e.is("uiElement"))continue;for(const o of e.getChildren())t.push(o)}}return o}findPositionIn(e,t){if(0===t)return this._moveViewPositionToTextNode(new Si(e,0));if(0==this._viewToModelLengthCallbacks.size&&this._viewToModelMapping.has(e)){const o=this._cache.getClosest(e,t);return this._findPositionStartingFrom(o.viewPosition,o.modelOffset,t,e,!0)}return this._findPositionStartingFrom(new Si(e,0),0,t,e,!1)}_findPositionStartingFrom(e,t,o,i,n){let s,r=e.parent,a=e.offset;if(r.is("$text"))return new Si(r,o-t);let l=t,c=0;for(;l{this._clearCacheInsideParent(t,o.index)};_invalidateOnTextChangeCallback=(e,t)=>{this._clearCacheAfter(t)};save(e,t,o,i){const n=this._cachedMapping.get(o),s=n.cacheMap.get(i);if(s){const o=e.getChild(t-1),i=s.viewPosition.nodeBefore?this._nodeToCacheListIndex.get(s.viewPosition.nodeBefore):0;return void this._nodeToCacheListIndex.set(o,i)}const r={viewPosition:new Si(e,t),modelOffset:i};n.maxModelOffset=i>n.maxModelOffset?i:n.maxModelOffset,n.cacheMap.set(i,r);let a=n.cacheList.length-1;for(;a>=0&&n.cacheList[a].modelOffset>i;)a--;if(n.cacheList.splice(a+1,0,r),t>0){const o=e.getChild(t-1);this._nodeToCacheListIndex.set(o,a+1)}}getClosest(e,t){const o=this._cachedMapping.get(e);let i;if(o)if(t>o.maxModelOffset)i=o.cacheList[o.cacheList.length-1];else{const e=o.cacheMap.get(t);i=e||this._findInCacheList(o.cacheList,t)}else i=this.startTracking(e);return{modelOffset:i.modelOffset,viewPosition:i.viewPosition.clone()}}startTracking(e){const t={viewPosition:new Si(e,0),modelOffset:0},o={maxModelOffset:0,cacheList:[t],cacheMap:new Map([[0,t]])};return this._cachedMapping.set(e,o),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 o=e.getChild(t-1);this._clearCacheAfter(o)}}_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 o=e.parent;for(;!this._cachedMapping.has(o);)o=o.parent;this._clearCacheFromCacheIndex(o,t)}_clearCacheFromCacheIndex(e,t){0===t&&(t=1);const o=this._cachedMapping.get(e),i=o.cacheList[t-1];if(!i)return;o.maxModelOffset=i.modelOffset;const n=o.cacheList.splice(t);for(const e of n){o.cacheMap.delete(e.modelOffset);const t=e.viewPosition.nodeBefore;this._nodeToCacheListIndex.delete(t)}}_findInCacheList(e,t){let o=0,i=e.length-1,n=i-o>>1,s=e[n];for(;o>1),s=e[n];return s.modelOffset<=t?s:e[n-1]}}class gs{_consumable=new Map;_textProxyRegistry=new Map;add(e,t){t=ps(t),e instanceof os&&(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=ps(t),e instanceof os&&(e=this._getSymbolForTextProxy(e)),!!this.test(e,t)&&(this._consumable.get(e).set(t,!1),!0)}test(e,t){t=ps(t),e instanceof os&&(e=this._getSymbolForTextProxy(e));const o=this._consumable.get(e);if(void 0===o)return null;const i=o.get(t);return void 0===i?null:i}revert(e,t){t=ps(t),e instanceof os&&(e=this._getSymbolForTextProxy(e));const o=this.test(e,t);return!1===o?(this._consumable.get(e).set(t,!0),!0):!0!==o&&null}verifyAllConsumed(e){const t=[];for(const[o,i]of this._consumable)for(const[n,s]of i){const i=n.split(":")[0];s&&e==i&&t.push({event:n,item:o.name||o.description})}if(t.length)throw new fe("conversion-model-consumable-not-consumed",null,{items:t})}_getSymbolForTextProxy(e){let t=null;const o=this._textProxyRegistry.get(e.startOffset);if(o){const i=o.get(e.endOffset);i&&(t=i.get(e.parent))}return t||(t=this._addSymbolForTextProxy(e)),t}_addSymbolForTextProxy(e){const t=e.startOffset,o=e.endOffset,i=e.parent,n=Symbol("$textProxy:"+e.data);let s,r;return s=this._textProxyRegistry.get(t),s||(s=new Map,this._textProxyRegistry.set(t,s)),r=s.get(o),r||(r=new Map,s.set(o,r)),r.set(i,n),n}}function ps(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]}class fs extends(xe()){_conversionApi;_firedEventsMap;constructor(e){super(),this._conversionApi={dispatcher:this,...e},this._firedEventsMap=new WeakMap}convertChanges(e,t,o){const i=e.getRefreshedItems(),n=this._createConversionApi(o,i);for(const t of e.getMarkersToRemove())this._convertMarkerRemove(t.name,t.range,n);const s=this._reduceChanges(e.getChanges(),i);for(const e of s)"insert"===e.type?this._convertInsert(us._createFromPositionAndShift(e.position,e.length),n):"reinsert"===e.type?this._convertReinsert(us._createFromPositionAndShift(e.position,e.length),n):"remove"===e.type?this._convertRemove(e.position,e.length,e.name,n):this._convertAttribute(e.range,e.attributeKey,e.attributeOldValue,e.attributeNewValue,n);n.mapper.flushDeferredBindings();for(const e of n.mapper.flushUnboundMarkerNames()){const o=t.get(e).getRange();this._convertMarkerRemove(e,o,n),this._convertMarkerAdd(e,o,n)}for(const t of e.getMarkersToAdd())this._convertMarkerAdd(t.name,t.range,n);n.consumable.verifyAllConsumed("insert")}convert(e,t,o,i={}){const n=this._createConversionApi(o,void 0,i);this._convertInsert(e,n);for(const[e,o]of t)this._convertMarkerAdd(e,o,n);n.consumable.verifyAllConsumed("insert")}convertSelection(e,t,o){const i=this._createConversionApi(o);this.fire("cleanSelection",{selection:e},i);const n=e.getFirstPosition().root;if(!i.mapper.toViewElement(n))return;const s=Array.from(t.getMarkersAtPosition(e.getFirstPosition()));if(this._addConsumablesForSelection(i.consumable,e,s),this.fire("selection",{selection:e},i),e.isCollapsed){for(const t of s)if(i.consumable.test(e,"addMarker:"+t.name)){const o=t.getRange();if(!bs(e.getFirstPosition(),t,i.mapper))continue;const n={item:e,markerName:t.name,markerRange:o};this.fire(`addMarker:${t.name}`,n,i)}for(const t of e.getAttributeKeys())if(i.consumable.test(e,"attribute:"+t)){const o={item:e,range:e.getFirstRange(),attributeKey:t,attributeOldValue:null,attributeNewValue:e.getAttribute(t)};this.fire(`attribute:${t}:$text`,o,i)}}}_convertInsert(e,t,o={}){o.doNotAddConsumables||this._addConsumablesForInsert(t.consumable,e);for(const o of e.getWalker({shallow:!0}))this._testAndFire("insert",ws(o),t)}_convertRemove(e,t,o,i){this.fire(`remove:${o}`,{position:e,length:t},i)}_convertAttribute(e,t,o,i,n){this._addConsumablesForRange(n.consumable,e,`attribute:${t}`);for(const s of e){const e={item:s.item,range:us._createFromPositionAndShift(s.previousPosition,s.length),attributeKey:t,attributeOldValue:o,attributeNewValue:i};this._testAndFire(`attribute:${t}`,e,n)}}_convertReinsert(e,t){const o=Array.from(e.getWalker({shallow:!0}));this._addConsumablesForInsert(t.consumable,o);for(const e of o.map(ws))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,o){if("$graveyard"==t.root.rootName)return;const i=`addMarker:${e}`;if(o.consumable.add(t,i),this.fire(i,{markerName:e,markerRange:t},o),o.consumable.consume(t,i)){this._addConsumablesForRange(o.consumable,t,i);for(const n of t.getItems()){if(!o.consumable.test(n,i))continue;const s={item:n,range:us._createOn(n),markerName:e,markerRange:t};this.fire(i,s,o)}}}_convertMarkerRemove(e,t,o){"$graveyard"!=t.root.rootName&&this.fire(`removeMarker:${e}`,{markerName:e,markerRange:t},o)}_reduceChanges(e,t){const o={changes:e,refreshedItems:t};return this.fire("reduceChanges",o),o.changes}_addConsumablesForInsert(e,t){for(const o of t){const t=o.item;if(null===e.test(t,"insert")){e.add(t,"insert");for(const o of t.getAttributeKeys())e.add(t,"attribute:"+o)}}return e}_addConsumablesForRange(e,t,o){for(const i of t.getItems())e.add(i,o);return e}_addConsumablesForSelection(e,t,o){e.add(t,"selection");for(const i of o)e.add(t,"addMarker:"+i.name);for(const o of t.getAttributeKeys())e.add(t,"attribute:"+o);return e}_testAndFire(e,t,o){const i=function(e,t){const o=t.item.is("element")?t.item.name:"$text";return`${e}:${o}`}(e,t),n=t.item.is("$textProxy")?o.consumable._getSymbolForTextProxy(t.item):t.item,s=this._firedEventsMap.get(o),r=s.get(n);if(r){if(r.has(i))return;r.add(i)}else s.set(n,new Set([i]));this.fire(i,t,o)}_testAndFireAddAttributes(e,t){const o={item:e,range:us._createOn(e)};for(const e of o.item.getAttributeKeys())o.attributeKey=e,o.attributeOldValue=null,o.attributeNewValue=o.item.getAttribute(e),this._testAndFire(`attribute:${e}`,o,t)}_createConversionApi(e,t=new Set,o={}){const i={...this._conversionApi,consumable:new gs,writer:e,options:o,convertItem:e=>this._convertInsert(us._createOn(e),i),convertChildren:e=>this._convertInsert(us._createIn(e),i,{doNotAddConsumables:!0}),convertAttributes:e=>this._testAndFireAddAttributes(e,i),canReuseView:e=>!t.has(i.mapper.toModelElement(e))};return this._firedEventsMap.set(i,new Map),i}}function bs(e,t,o){const i=t.getRange(),n=Array.from(e.getAncestors());n.shift(),n.reverse();return!n.some((e=>{if(i.containsItem(e)){return!!o.toViewElement(e).getCustomProperty("addHighlight")}}))}function ws(e){return{item:e.item,range:us._createFromPositionAndShift(e.previousPosition,e.length)}}class ys extends ts{parent=null;_attrs;_index=null;_startOffset=null;constructor(e){super(),this._attrs=ao(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 o=e.includeSelf?this:this.parent;for(;o;)t[e.parentFirst?"push":"unshift"](o),o=o.parent;return t}getCommonAncestor(e,t={}){const o=this.getAncestors(t),i=e.getAncestors(t);let n=0;for(;o[n]==i[n]&&o[n];)n++;return 0===n?null:o[n-1]}isBefore(e){if(this==e)return!1;if(this.root!==e.root)return!1;const t=this.getPath(),o=e.getPath(),i=We(t,o);switch(i){case"prefix":return!0;case"extension":return!1;default:return t[i](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=ao(e)}_removeAttribute(e){return this._attrs.delete(e)}_clearAttributes(){this._attrs.clear()}}ys.prototype.is=function(e){return"node"===e||"model:node"===e};class _s extends(xe(ts)){_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 o=!1;for(const i of e._ranges)if(t.isEqual(i)){o=!0;break}if(!o)return!1}return!0}*getRanges(){for(const e of this._ranges)yield new us(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 us(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 us(e.start,e.end):null}getFirstPosition(){const e=this.getFirstRange();return e?e.start.clone():null}getLastPosition(){const e=this.getLastRange();return e?e.end.clone():null}setTo(...e){let[t,o,i]=e;if("object"==typeof o&&(i=o,o=void 0),null===t)this._setRanges([]);else if(t instanceof _s)this._setRanges(t.getRanges(),t.isBackward);else if(t&&"function"==typeof t.getRanges)this._setRanges(t.getRanges(),t.isBackward);else if(t instanceof us)this._setRanges([t],!!i&&!!i.backward);else if(t instanceof ss)this._setRanges([new us(t)]);else if(t instanceof ys){const e=!!i&&!!i.backward;let n;if("in"==o)n=us._createIn(t);else if("on"==o)n=us._createOn(t);else{if(void 0===o)throw new fe("model-selection-setto-required-second-parameter",[this,t]);n=new us(ss._createAt(t,o))}this._setRanges([n],e)}else{if(!Ue(t))throw new fe("model-selection-setto-not-selectable",[this,t]);this._setRanges(t,i&&!!i.backward)}}_setRanges(e,t=!1){const o=Array.from(e),i=o.some((t=>{if(!(t instanceof us))throw new fe("model-selection-set-ranges-not-range",[this,e]);return this._ranges.every((e=>!e.isEqual(t)))}));(o.length!==this._ranges.length||i)&&(this._replaceAllRanges(o),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 o=ss._createAt(e,t);if("same"==o.compareWith(this.focus))return;const i=this.anchor;this._ranges.length&&this._popRange(),"before"==o.compareWith(i)?(this._pushRange(new us(o,i)),this._lastRangeBackward=!0):(this._pushRange(new us(i,o)),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 o=Cs(t.start,e);xs(o,t)&&(yield o);const i=t.getWalker();for(const o of i){const n=o.item;"elementEnd"==o.type&&vs(n,e,t)?yield n:"elementStart"==o.type&&n.is("model:element")&&n.root.document.model.schema.isBlock(n)&&i.jumpTo(ss._createAt(n,"end"))}const n=Cs(t.end,e);Es(n,t)&&(yield n)}}containsEntireContent(e=this.anchor.root){const t=ss._createAt(e,0),o=ss._createAt(e,"end");return t.isTouching(this.getFirstPosition())&&o.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 us(e.start,e.end))}_checkRange(e){for(let t=0;t0;)this._popRange()}_popRange(){this._ranges.pop()}}function ks(e,t){return!t.has(e)&&(t.add(e),e.root.document.model.schema.isBlock(e)&&!!e.parent)}function vs(e,t,o){return ks(e,t)&&As(e,o)}function Cs(e,t){const o=e.parent.root.document.model.schema,i=e.parent.getAncestors({parentFirst:!0,includeSelf:!0});let n=!1;const s=i.find((e=>!n&&(n=o.isLimit(e),!n&&ks(e,t))));return i.forEach((e=>t.add(e))),s}function As(e,t){const o=function(e){const t=e.root.document.model.schema;let o=e.parent;for(;o;){if(t.isBlock(o))return o;o=o.parent}}(e);if(!o)return!0;return!t.containsRange(us._createOn(o),!0)}function xs(e,t){return!!e&&(!(!t.isCollapsed&&!e.isEmpty)||!t.start.isTouching(ss._createAt(e,e.maxOffset))&&As(e,t))}function Es(e,t){return!!e&&(!(!t.isCollapsed&&!e.isEmpty)||!t.end.isTouching(ss._createAt(e,0))&&As(e,t))}_s.prototype.is=function(e){return"selection"===e||"model:selection"===e};class Ts extends(xe(us)){constructor(e,t){super(e,t),Ps.call(this)}detach(){this.stopListening()}toRange(){return new us(this.start,this.end)}static fromRange(e){return new Ts(e.start,e.end)}}function Ps(){this.listenTo(this.root.document.model,"applyOperation",((e,t)=>{const o=t[0];o.isDocumentOperation&&Ss.call(this,o)}),{priority:"low"})}function Ss(e){const t=this.getTransformedByOperation(e),o=us._createFromRanges(t),i=!o.isEqual(this),n=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 s=null;if(i){"$graveyard"==o.root.rootName&&(s="remove"==e.type?e.sourcePosition:e.deletionPosition);const t=this.toRange();this.start=o.start,this.end=o.end,this.fire("change:range",t,{deletionPosition:s})}else n&&this.fire("change:content",this.toRange(),{deletionPosition:s})}Ts.prototype.is=function(e){return"liveRange"===e||"model:liveRange"===e||"range"==e||"model:range"===e};class Is extends ys{_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 Is(this.data,this.getAttributes())}static fromJSON(e){return new Is(e.data,e.attributes)}}Is.prototype.is=function(e){return"$text"===e||"model:$text"===e||"text"===e||"model:text"===e||"node"===e||"model:node"===e};const Rs="selection:";class Os extends(xe(ts)){_selection;constructor(e){super(),this._selection=new Vs(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 Rs+e}static _isStoreAttributeKey(e){return e.startsWith(Rs)}}Os.prototype.is=function(e){return"selection"===e||"model:selection"==e||"documentSelection"==e||"model:documentSelection"==e};class Vs extends _s{markers=new eo({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 o=t[0];o.isDocumentOperation&&"marker"!=o.type&&"rename"!=o.type&&"noop"!=o.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,o,i)=>{this._updateMarker(t,i)})),this.listenTo(this._document,"change",((e,t)=>{!function(e,t){const o=e.document.differ;for(const i of o.getChanges()){if("insert"!=i.type)continue;const o=i.position.parent;i.length===o.maxOffset&&e.enqueueChange(t,(e=>{const t=Array.from(o.getAttributeKeys()).filter((e=>e.startsWith(Rs)));for(const i of t)e.removeAttribute(i,o)}))}}(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=Ts.fromRange(e);return t.on("change:range",((e,o,i)=>{if(this._hasChangedRange=!0,t.root==this._document.graveyard){this._selectionRestorePosition=i.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 o=t.name.split(":",1)[0];if(!this._observedMarkers.has(o))continue;const i=t.getRange();for(const o of this.getRanges())i.containsRange(o,!o.isCollapsed)&&e.push(t)}const o=Array.from(this.markers);for(const o of e)this.markers.has(o)||(this.markers.add(o),t=!0);for(const o of Array.from(this.markers))e.includes(o)||(this.markers.remove(o),t=!0);t&&this.fire("change:marker",{oldMarkers:o,directChange:!1})}_updateMarker(e,t){const o=e.name.split(":",1)[0];if(!this._observedMarkers.has(o))return;let i=!1;const n=Array.from(this.markers),s=this.markers.has(e);if(t){let o=!1;for(const e of this.getRanges())if(t.containsRange(e,!e.isCollapsed)){o=!0;break}o&&!s?(this.markers.add(e),i=!0):!o&&s&&(this.markers.remove(e),i=!0)}else s&&(this.markers.remove(e),i=!0);i&&this.fire("change:marker",{oldMarkers:n,directChange:!1})}_updateAttributes(e){const t=ao(this._getSurroundingAttributes()),o=ao(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 i=[];for(const[e,t]of this.getAttributes())o.has(e)&&o.get(e)===t||i.push(e);for(const[e]of o)this.hasAttribute(e)||i.push(e);i.length>0&&this.fire("change:attribute",{attributeKeys:i,directChange:!1})}_setAttribute(e,t,o=!0){const i=o?"normal":"low";if("low"==i&&"normal"==this._attributePriority.get(e))return!1;return super.getAttribute(e)!==t&&(this._attrs.set(e,t),this._attributePriority.set(e,i),!0)}_removeAttribute(e,t=!0){const o=t?"normal":"low";return("low"!=o||"normal"!=this._attributePriority.get(e))&&(this._attributePriority.set(e,o),!!super.hasAttribute(e)&&(this._attrs.delete(e),!0))}_setAttributesTo(e){const t=new Set;for(const[t,o]of this.getAttributes())e.get(t)!==o&&this._removeAttribute(t,!1);for(const[o,i]of e){this._setAttribute(o,i,!1)&&t.add(o)}return t}*getStoredAttributes(){const e=this.getFirstPosition().parent;if(this.isCollapsed&&e.isEmpty)for(const t of e.getAttributeKeys())if(t.startsWith(Rs)){const o=t.substr(10);yield[o,e.getAttribute(t)]}}_getSurroundingAttributes(){const e=this.getFirstPosition(),t=this._model.schema;if("$graveyard"==e.root.rootName)return null;let o=null;if(this.isCollapsed){const i=e.textNode?e.textNode:e.nodeBefore,n=e.textNode?e.textNode:e.nodeAfter;if(this.isGravityOverridden||(o=Ds(i,t)),o||(o=Ds(n,t)),!this.isGravityOverridden&&!o){let e=i;for(;e&&!o;)e=e.previousSibling,o=Ds(e,t)}if(!o){let e=n;for(;e&&!o;)e=e.nextSibling,o=Ds(e,t)}o||(o=this.getStoredAttributes())}else{const e=this.getFirstRange();for(const i of e){if(i.item.is("element")&&t.isObject(i.item)){o=Ds(i.item,t);break}if("text"==i.type){o=i.item.getAttributes();break}}}return o}_fixGraveyardSelection(e){const t=this._model.schema.getNearestSelectionRange(e);t&&this._pushRange(t)}}function Ds(e,t){if(!e)return null;if(e instanceof os||e instanceof Is)return e.getAttributes();if(!t.isInline(e))return null;if(!t.isObject(e))return[];const o=[];for(const[i,n]of e.getAttributes())t.checkAttribute("$text",i)&&!1!==t.getAttributeProperties(i).copyFromObject&&o.push([i,n]);return o}class Fs{_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 o=[];for(const e of t){if(!(e instanceof ys))throw new fe("model-nodelist-insertnodes-not-node",this);o.push(e)}let i=this.indexToOffset(e);lo(this._nodes,o,e),lo(this._offsetToNode,function(e){const t=[];let o=0;for(const i 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()))}}class Ms extends ys{name;_children=new Fs;constructor(e,t,o){super(t),this.name=e,o&&this._insertChild(0,o)}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 o of e)t=t.getChildAtOffset(o);return t}findAncestor(e,t={}){let o=t.includeSelf?this:this.parent;for(;o;){if(o.name===e)return o;o=o.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(e=!1){const t=e?function(e){const t=[];for(const o of e)t.push(o._clone(!0));return t}(this._children):void 0;return new Ms(this.name,this.getAttributes(),t)}_appendChild(e){this._insertChild(this.childCount,e)}_insertChild(e,t){const o=function(e){if("string"==typeof e)return[new Is(e)];Ue(e)||(e=[e]);const t=[];for(const o of e)"string"==typeof o?t.push(new Is(o)):o instanceof os?t.push(new Is(o.data,o.getAttributes())):t.push(o);return t}(t);for(const e of o)null!==e.parent&&e._remove(),e.parent=this;this._children._insertNodes(e,o)}_removeChildren(e,t=1){const o=this._children._removeNodes(e,t);for(const e of o)e.parent=null;return o}_removeChildrenArray(e){this._children._removeNodesArray(e);for(const t of e)t.parent=null}static fromJSON(e){let t;if(e.children){t=[];for(const o of e.children)o.name?t.push(Ms.fromJSON(o)):t.push(Is.fromJSON(o))}return new Ms(e.name,e.attributes,t)}}Ms.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};class Ns{_dispatchers;constructor(e){this._dispatchers=e}add(e){for(const t of this._dispatchers)e(t);return this}}class Bs extends Ns{elementToElement(e){return this.add(function(e){const t=Us(e.model),o=Ks(e.view,"container");t.attributes.length&&(t.children=!0);return i=>{i.on(`insert:${t.name}`,js(o,Ys(t)),{priority:e.converterPriority||"normal"}),(t.children||t.attributes.length)&&i.on("reduceChanges",Qs(t),{priority:"low"})}}(e))}elementToStructure(e){return this.add(function(e){const t=Us(e.model),o=Ks(e.view,"container");return t.children=!0,i=>{if(i._conversionApi.schema.checkChild(t.name,"$text"))throw new fe("conversion-element-to-structure-disallowed-text",i,{elementName:t.name});var n,s;i.on(`insert:${t.name}`,(n=o,s=Ys(t),(e,t,o)=>{if(!s(t.item,o.consumable,{preflight:!0}))return;const i=new Map;o.writer._registerSlotFactory(function(e,t,o){return(i,n)=>{const s=i.createContainerElement("$slot");let r=null;if("children"===n)r=Array.from(e.getChildren());else{if("function"!=typeof n)throw new fe("conversion-slot-mode-unknown",o.dispatcher,{modeOrFilter:n});r=Array.from(e.getChildren()).filter((e=>n(e)))}return t.set(s,r),s}}(t.item,i,o));const r=n(t.item,o,t);if(o.writer._clearSlotFactory(),!r)return;!function(e,t,o){const i=Array.from(t.values()).flat(),n=new Set(i);if(n.size!=i.length)throw new fe("conversion-slot-filter-overlap",o.dispatcher,{element:e});if(n.size!=e.childCount)throw new fe("conversion-slot-filter-incomplete",o.dispatcher,{element:e})}(t.item,i,o),s(t.item,o.consumable);const a=t.reconversion&&Hs(t.item,o)||o.mapper.toViewPosition(t.range.start);o.mapper.bindElements(t.item,r),o.writer.insert(a,r),o.convertAttributes(t.item),function(e,t,o,i){o.mapper.on("modelToViewPosition",r,{priority:"highest"});let n=null,s=null;for([n,s]of t)Xs(e,s,o,i),o.writer.setCustomProperty("$structureSlotParent",!0,n.parent),o.writer.move(o.writer.createRangeIn(n),o.writer.createPositionBefore(n)),o.writer.remove(n);function r(e,t){const o=t.modelPosition.nodeAfter,i=s.indexOf(o);i<0||(t.viewPosition=t.mapper.findPositionIn(n,i))}o.mapper.off("modelToViewPosition",r)}(r,i,o,{reconversion:t.reconversion})}),{priority:e.converterPriority||"normal"}),i.on("reduceChanges",Qs(t),{priority:"low"})}}(e))}attributeToElement(e){return this.add(function(e){e=j(e);let t=e.model;"string"==typeof t&&(t={key:t});let o=`attribute:${t.key}`;t.name&&(o+=":"+t.name);if(t.values)for(const o of t.values)e.view[o]=Ks(e.view[o],"attribute");else e.view=Ks(e.view,"attribute");const i=Gs(e);return t=>{t.on(o,zs(i),{priority:e.converterPriority||"normal"})}}(e))}attributeToAttribute(e){return this.add(function(e){e=j(e);let t=e.model;"string"==typeof t&&(t={key:t});let o=`attribute:${t.key}`;t.name&&(o+=":"+t.name);if(t.values)for(const o of t.values)e.view[o]=Js(e.view[o]);else e.view=Js(e.view);const i=Gs(e);return t=>{var n;t.on(o,(n=i,(e,t,o)=>{if(!o.consumable.test(t.item,e.name))return;const i=n(t.attributeOldValue,o,t),s=n(t.attributeNewValue,o,t);if(!i&&!s)return;o.consumable.consume(t.item,e.name);const r=o.mapper.toViewElement(t.item),a=o.writer;if(!r)throw new fe("conversion-attribute-to-attribute-on-text",o.dispatcher,t);if(null!==t.attributeOldValue&&i){let e=i.value;"style"==i.key&&(e="string"==typeof i.value?new gi(a.document.stylesProcessor).setTo(i.value).getStylesEntries().map((([e])=>e)):Object.keys(i.value)),a.removeAttribute(i.key,e,r)}if(null!==t.attributeNewValue&&s){let e=s.value;"style"==s.key&&"string"==typeof s.value&&(e=Object.fromEntries(new gi(a.document.stylesProcessor).setTo(s.value).getStylesEntries())),a.setAttribute(s.key,e,!1,r)}}),{priority:e.converterPriority||"normal"})}}(e))}markerToElement(e){return this.add(function(e){const t=Ks(e.view,"ui");return o=>{o.on(`addMarker:${e.model}`,qs(t),{priority:e.converterPriority||"normal"}),o.on(`removeMarker:${e.model}`,((e,t,o)=>{const i=o.mapper.markerNameToElements(t.markerName);if(i){for(const e of i)o.mapper.unbindElementFromMarkerName(e,t.markerName),o.writer.clear(o.writer.createRangeOn(e),e);o.writer.clearClonedElementsGroup(t.markerName),e.stop()}}),{priority:e.converterPriority||"normal"})}}(e))}markerToHighlight(e){return this.add(function(e){return t=>{var o;t.on(`addMarker:${e.model}`,(o=e.view,(e,t,i)=>{if(!t.item)return;if(!(t.item instanceof _s||t.item instanceof Os||t.item.is("$textProxy")))return;const n=Zs(o,t,i);if(!n)return;if(!i.consumable.consume(t.item,e.name))return;const s=i.writer,r=Ls(s,n),a=s.document.selection;if(t.item instanceof _s||t.item instanceof Os)s.wrap(a.getFirstRange(),r);else{const e=i.mapper.toViewRange(t.range),o=s.wrap(e,r);for(const e of o.getItems())if(e.is("attributeElement")&&e.isSimilar(r)){i.mapper.bindElementToMarker(e,t.markerName);break}}}),{priority:e.converterPriority||"normal"}),t.on(`addMarker:${e.model}`,function(e){return(t,o,i)=>{if(!o.item)return;if(!(o.item instanceof Ms))return;const n=Zs(e,o,i);if(!n)return;if(!i.consumable.test(o.item,t.name))return;const s=i.mapper.toViewElement(o.item);if(s&&s.getCustomProperty("addHighlight")){i.consumable.consume(o.item,t.name);for(const e of us._createIn(o.item))i.consumable.consume(e.item,t.name);s.getCustomProperty("addHighlight")(s,n,i.writer),i.mapper.bindElementToMarker(s,o.markerName)}}}(e.view),{priority:e.converterPriority||"normal"}),t.on(`removeMarker:${e.model}`,function(e){return(t,o,i)=>{if(o.markerRange.isCollapsed)return;const n=Zs(e,o,i);if(!n)return;const s=Ls(i.writer,n),r=i.mapper.markerNameToElements(o.markerName);if(r){for(const e of r)if(i.mapper.unbindElementFromMarkerName(e,o.markerName),e.is("attributeElement"))i.writer.unwrap(i.writer.createRangeOn(e),s);else{e.getCustomProperty("removeHighlight")(e,n.id,i.writer)}i.writer.clearClonedElementsGroup(o.markerName),t.stop()}}}(e.view),{priority:e.converterPriority||"normal"})}}(e))}markerToData(e){return this.add(function(e){e=j(e);const t=e.model;let o=e.view;o||(o=o=>({group:t,name:o.substr(e.model.length+1)}));return i=>{var n;i.on(`addMarker:${t}`,(n=o,(e,t,o)=>{const i=n(t.markerName,o);if(!i)return;const s=t.markerRange;o.consumable.consume(s,e.name)&&(Ws(s,!1,o,t,i),Ws(s,!0,o,t,i),e.stop())}),{priority:e.converterPriority||"normal"}),i.on(`removeMarker:${t}`,function(e){return(t,o,i)=>{const n=e(o.markerName,i);if(!n)return;const s=i.mapper.markerNameToElements(o.markerName);if(s){for(const e of s)i.mapper.unbindElementFromMarkerName(e,o.markerName),e.is("containerElement")?(r(`data-${n.group}-start-before`,e),r(`data-${n.group}-start-after`,e),r(`data-${n.group}-end-before`,e),r(`data-${n.group}-end-after`,e)):i.writer.clear(i.writer.createRangeOn(e),e);i.writer.clearClonedElementsGroup(o.markerName),t.stop()}function r(e,t){if(t.hasAttribute(e)){const o=new Set(t.getAttribute(e).split(","));o.delete(n.name),0==o.size?i.writer.removeAttribute(e,t):i.writer.setAttribute(e,Array.from(o).join(","),t)}}}}(o),{priority:e.converterPriority||"normal"})}}(e))}}function Ls(e,t){const o=e.createAttributeElement("span",t.attributes);return t.classes&&o._addClass(t.classes),"number"==typeof t.priority&&(o._priority=t.priority),o._id=t.id,o}function zs(e){return(t,o,i)=>{if(!i.consumable.test(o.item,t.name))return;const n=e(o.attributeOldValue,i,o),s=e(o.attributeNewValue,i,o);if(!n&&!s)return;i.consumable.consume(o.item,t.name);const r=i.writer,a=r.document.selection;if(o.item instanceof _s||o.item instanceof Os)r.wrap(a.getFirstRange(),s);else{let e=i.mapper.toViewRange(o.range);null!==o.attributeOldValue&&n&&(e=r.unwrap(e,n)),null!==o.attributeNewValue&&s&&r.wrap(e,s)}}}function js(e,t=tr){return(o,i,n)=>{if(!t(i.item,n.consumable,{preflight:!0}))return;const s=e(i.item,n,i);if(!s)return;t(i.item,n.consumable);const r=i.reconversion&&Hs(i.item,n)||n.mapper.toViewPosition(i.range.start);n.mapper.bindElements(i.item,s),n.writer.insert(r,s),n.convertAttributes(i.item),Xs(s,i.item.getChildren(),n,{reconversion:i.reconversion})}}function qs(e){return(t,o,i)=>{o.isOpening=!0;const n=e(o,i);o.isOpening=!1;const s=e(o,i);if(!n||!s)return;const r=o.markerRange;if(r.isCollapsed&&!i.consumable.consume(r,t.name))return;for(const e of r)if(!i.consumable.consume(e.item,t.name))return;const a=i.mapper,l=i.writer;l.insert(a.toViewPosition(r.start),n),i.mapper.bindElementToMarker(n,o.markerName),r.isCollapsed||(l.insert(a.toViewPosition(r.end),s),i.mapper.bindElementToMarker(s,o.markerName)),t.stop()}}function $s(e,t){const o=t.writer.remove(e);for(const e of t.writer.createRangeIn(o).getItems())t.mapper.unbindViewElement(e,{defer:!0});return e.start}function Hs(e,t){const o=t.mapper.toViewElement(e);return o&&$s(t.writer.createRangeOn(o),t)}function Ws(e,t,o,i,n){const s=t?e.start:e.end,r=s.nodeAfter&&s.nodeAfter.is("element")?s.nodeAfter:null,a=s.nodeBefore&&s.nodeBefore.is("element")?s.nodeBefore:null;if(r||a){let e,s;t&&r||!t&&!a?(e=r,s=!0):(e=a,s=!1);const l=o.mapper.toViewElement(e);if(l)return void function(e,t,o,i,n,s){const r=`data-${s.group}-${t?"start":"end"}-${o?"before":"after"}`,a=e.hasAttribute(r)?e.getAttribute(r).split(","):[];a.unshift(s.name),i.writer.setAttribute(r,a.join(","),e),i.mapper.bindElementToMarker(e,n.markerName)}(l,t,s,o,i,n)}!function(e,t,o,i,n){const s=`${n.group}-${t?"start":"end"}`,r=n.name?{name:n.name}:null,a=o.writer.createUIElement(s,r);o.writer.insert(e,a),o.mapper.bindElementToMarker(a,i.markerName)}(o.mapper.toViewPosition(s),t,o,i,n)}function Us(e){return"string"==typeof e&&(e={name:e}),{name:e.name,attributes:e.attributes?Qt(e.attributes):[],children:!!e.children}}function Ks(e,t){return"function"==typeof e?e:(o,i)=>function(e,t,o){"string"==typeof e&&(e={name:e});let i;const n=t.writer,s=Object.assign({},e.attributes);if("container"==o)i=n.createContainerElement(e.name,s);else if("attribute"==o){const t={priority:e.priority||Wi.DEFAULT_PRIORITY};i=n.createAttributeElement(e.name,s,t)}else i=n.createUIElement(e.name,s);if(e.styles){const t=Object.keys(e.styles);for(const o of t)n.setStyle(o,e.styles[o],i)}if(e.classes){const t=e.classes;if("string"==typeof t)n.addClass(t,i);else for(const e of t)n.addClass(e,i)}return i}(e,i,t)}function Gs(e){return e.model.values?(t,o,i)=>{const n=e.view[t];return n?n(t,o,i):null}:e.view}function Js(e){return"string"==typeof e?t=>({key:e,value:t}):"object"==typeof e?e.value?()=>e:t=>({key:e.key,value:t}):e}function Zs(e,t,o){const i="function"==typeof e?e(t,o):{...e};return i?(i.priority||(i.priority=10),i.id||(i.id=t.markerName),i):null}function Qs(e){const t=function(e){return(t,o)=>{if(!t.is("element",e.name))return!1;if("attribute"==o.type){if(e.attributes.includes(o.attributeKey))return!0}else if(e.children)return!0;return!1}}(e);return(e,o)=>{const i=[];o.reconvertedElements||(o.reconvertedElements=new Set);for(const e of o.changes){const n="attribute"==e.type?e.range.start.nodeAfter:e.position.parent;if(n&&t(n,e)&&"reinsert"!=e.type){if("insert"==e.type&&"rename"==e.action&&o.refreshedItems.add(e.position.nodeAfter),!o.reconvertedElements.has(n)){o.reconvertedElements.add(n);const e=ss._createBefore(n);let t=i.length;for(let o=i.length-1;o>=0;o--){const n=i[o],s=("attribute"==n.type?n.range.start:n.position).compareWith(e);if("before"==s||"remove"==n.type&&"same"==s)break;t=o}i.splice(t,0,{type:"reinsert",name:n.name,position:e,length:1})}}else i.push(e)}o.changes=i}}function Ys(e){return(t,o,i={})=>{const n=["insert"];for(const o of e.attributes)t.hasAttribute(o)&&n.push(`attribute:${o}`);return!!n.every((e=>o.test(t,e)))&&(i.preflight||n.forEach((e=>o.consume(t,e))),!0)}}function Xs(e,t,o,i){for(const n of t)er(e.root,n,o,i)||o.convertItem(n)}function er(e,t,o,i){const{writer:n,mapper:s}=o;if(!i.reconversion)return!1;const r=s.toViewElement(t);return!(!r||r.root==e)&&(!!o.canReuseView(r)&&(n.move(n.createRangeOn(r),s.toViewPosition(ss._createBefore(t))),!0))}function tr(e,t,{preflight:o}={}){return o?t.test(e,"insert"):t.consume(e,"insert")}function or(e){const{schema:t,document:o}=e.model;for(const i of o.getRoots())if(i.isEmpty&&!t.checkChild(i,"$text")&&t.checkChild(i,"paragraph"))return e.insertElement("paragraph",i),!0;return!1}function ir(e,t,o){const i=o.createContext(e);return!!o.checkChild(i,"paragraph")&&!!o.checkChild(i.push("paragraph"),t)}function nr(e,t){const o=t.createElement("paragraph");return t.insert(o,e),t.createPositionAt(o,0)}class sr extends Ns{elementToElement(e){return this.add(rr(e))}elementToAttribute(e){return this.add(function(e){e=j(e),cr(e);const t=dr(e,!1),o=ar(e.view),i=o?`element:${o}`:"element";return o=>{o.on(i,t,{priority:e.converterPriority||"low"})}}(e))}attributeToAttribute(e){return this.add(function(e){e=j(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,o=void 0===e.view.value?/[\s\S]*/:e.view.value;let i;if("class"==t||"style"==t){const e="class"==t?"classes":"styles";i={[e]:o}}else i={attributes:{[t]:o}};e.view.name&&(i.name=e.view.name);return e.view=i,t}(e));cr(e,t);const o=dr(e,!0);return t=>{t.on("element",o,{priority:e.converterPriority||"low"})}}(e))}elementToMarker(e){return this.add(function(e){const t=function(e){return(t,o)=>{const i="string"==typeof e?e:e(t,o);return o.writer.createElement("$marker",{"data-name":i})}}(e.model);return rr({...e,model:t})}(e))}dataToMarker(e){return this.add(function(e){e=j(e),e.model||(e.model=t=>t?e.view+":"+t:e.view);const t={view:e.view,model:e.model},o=lr(ur(t,"start")),i=lr(ur(t,"end"));return n=>{n.on(`element:${e.view}-start`,o,{priority:e.converterPriority||"normal"}),n.on(`element:${e.view}-end`,i,{priority:e.converterPriority||"normal"});const s=ge.low,r=ge.highest,a=ge.get(e.converterPriority)/r;n.on("element",function(e){return(t,o,i)=>{const n=`data-${e.view}`;function s(t,n){for(const s of n){const n=e.model(s,i),r=i.writer.createElement("$marker",{"data-name":n});i.writer.insert(r,t),o.modelCursor.isEqual(t)?o.modelCursor=o.modelCursor.getShiftedBy(1):o.modelCursor=o.modelCursor._getTransformedByInsertion(t,1),o.modelRange=o.modelRange._getTransformedByInsertion(t,1)[0]}}(i.consumable.test(o.viewItem,{attributes:n+"-end-after"})||i.consumable.test(o.viewItem,{attributes:n+"-start-after"})||i.consumable.test(o.viewItem,{attributes:n+"-end-before"})||i.consumable.test(o.viewItem,{attributes:n+"-start-before"}))&&(o.modelRange||Object.assign(o,i.convertChildren(o.viewItem,o.modelCursor)),i.consumable.consume(o.viewItem,{attributes:n+"-end-after"})&&s(o.modelRange.end,o.viewItem.getAttribute(n+"-end-after").split(",")),i.consumable.consume(o.viewItem,{attributes:n+"-start-after"})&&s(o.modelRange.end,o.viewItem.getAttribute(n+"-start-after").split(",")),i.consumable.consume(o.viewItem,{attributes:n+"-end-before"})&&s(o.modelRange.start,o.viewItem.getAttribute(n+"-end-before").split(",")),i.consumable.consume(o.viewItem,{attributes:n+"-start-before"})&&s(o.modelRange.start,o.viewItem.getAttribute(n+"-start-before").split(",")))}}(t),{priority:s+a})}}(e))}}function rr(e){const t=lr(e=j(e)),o=ar(e.view),i=o?`element:${o}`:"element";return o=>{o.on(i,t,{priority:e.converterPriority||"normal"})}}function ar(e){return"string"==typeof e?e:"object"==typeof e&&"string"==typeof e.name?e.name:null}function lr(e){const t=new ui(e.view);return(o,i,n)=>{const s=t.match(i.viewItem);if(!s)return;const r=s.match;if(r.name=!0,!n.consumable.test(i.viewItem,r))return;const a=function(e,t,o){return e instanceof Function?e(t,o):o.writer.createElement(e)}(e.model,i.viewItem,n);a&&n.safeInsert(a,i.modelCursor)&&(n.consumable.consume(i.viewItem,r),n.convertChildren(i.viewItem,a),n.updateConversionResult(a,i))}}function cr(e,t=null){const o=null===t||(e=>e.getAttribute(t)),i="object"!=typeof e.model?e.model:e.model.key,n="object"!=typeof e.model||void 0===e.model.value?o:e.model.value;e.model={key:i,value:n}}function dr(e,t){const o=new ui(e.view);return(i,n,s)=>{if(!n.modelRange&&t)return;const r=o.match(n.viewItem);if(!r)return;if(!function(e,t){const o="function"==typeof e?e(t):e;if("object"==typeof o&&!ar(o))return!1;return!o.classes&&!o.attributes&&!o.styles}(e.view,n.viewItem)?delete r.match.name:r.match.name=!0,!s.consumable.test(n.viewItem,r.match))return;const a=e.model.key,l="function"==typeof e.model.value?e.model.value(n.viewItem,s,n):e.model.value;if(null==l)return;n.modelRange||Object.assign(n,s.convertChildren(n.viewItem,n.modelCursor));const c=function(e,t,o,i){let n=!1;for(const s of Array.from(e.getItems({shallow:o})))i.schema.checkAttribute(s,t.key)&&(n=!0,s.hasAttribute(t.key)||i.writer.setAttribute(t.key,t.value,s));return n}(n.modelRange,{key:a,value:l},t,s);c&&(s.consumable.test(n.viewItem,{name:!0})&&(r.match.name=!0),s.consumable.consume(n.viewItem,r.match))}}function ur(e,t){return{view:`${e.view}-${t}`,model:(t,o)=>{const i=t.getAttribute("name"),n=e.model(i,o);return o.writer.createElement("$marker",{"data-name":n})}}}class hr extends(Be()){model;view;mapper;downcastDispatcher;constructor(e,t){super(),this.model=e,this.view=new es(t),this.mapper=new hs,this.downcastDispatcher=new fs({mapper:this.mapper,schema:e.schema});const o=this.model.document,i=o.selection,n=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(o,"change",(()=>{this.view.change((e=>{this.downcastDispatcher.convertChanges(o.differ,n,e),this.downcastDispatcher.convertSelection(i,n,e)}))}),{priority:"low"}),this.listenTo(this.view.document,"selectionChange",function(e,t){return(o,i)=>{const n=i.newSelection,s=[];for(const e of n.getRanges())s.push(t.toModelRange(e));const r=e.createSelection(s,{backward:n.isBackward});r.isEqual(e.document.selection)||e.change((e=>{e.setSelection(r)}))}}(this.model,this.mapper)),this.downcastDispatcher.on("insert:$text",((e,t,o)=>{if(!o.consumable.consume(t.item,e.name))return;const i=o.writer,n=o.mapper.toViewPosition(t.range.start),s=i.createText(t.item.data);i.insert(n,s)}),{priority:"lowest"}),this.downcastDispatcher.on("insert",((e,t,o)=>{o.convertAttributes(t.item),t.reconversion||!t.item.is("element")||t.item.isEmpty||o.convertChildren(t.item)}),{priority:"lowest"}),this.downcastDispatcher.on("remove",((e,t,o)=>{if(t.reconversion)return;const i=o.mapper.toViewPosition(t.position),n=t.position.getShiftedBy(t.length),s=o.mapper.toViewPosition(n,{isPhantom:!0});$s(o.writer.createRange(i,s).getTrimmed(),o)}),{priority:"low"}),this.downcastDispatcher.on("cleanSelection",((e,t,o)=>{const i=o.writer,n=i.document.selection;for(const e of n.getRanges())e.isCollapsed&&e.end.parent.isAttached()&&o.writer.mergeAttributes(e.start);i.setSelection(null)})),this.downcastDispatcher.on("selection",((e,t,o)=>{const i=t.selection;if(i.isCollapsed)return;if(!o.consumable.consume(i,"selection"))return;const n=[];for(const e of i.getRanges())n.push(o.mapper.toViewRange(e));o.writer.setSelection(n,{backward:i.isBackward})}),{priority:"low"}),this.downcastDispatcher.on("selection",((e,t,o)=>{const i=t.selection;if(!i.isCollapsed)return;if(!o.consumable.consume(i,"selection"))return;const n=o.writer,s=i.getFirstPosition(),r=o.mapper.toViewPosition(s),a=n.breakAttributes(r);n.setSelection(a)}),{priority:"low"}),this.view.document.roots.bindTo(this.model.document.roots).using((e=>{if("$graveyard"==e.rootName)return null;const t=new Ti(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,o=this.model.markers.get(t);if(!o)throw new fe("editingcontroller-reconvertmarker-marker-not-exist",this,{markerName:t});this.model.change((()=>{this.model.markers._refresh(o)}))}reconvertItem(e){this.model.change((()=>{this.model.document.differ._refreshItem(e)}))}}class mr extends(Be()){_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 gr(t[0])}),{priority:"highest"}),this.on("checkChild",((e,t)=>{t[0]=new gr(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 o=this.getDefinition(e.last);if(!o)return!1;const i=this._evaluateAttributeChecks(e,t);return void 0!==i?i:o.allowAttributes.includes(t)}checkMerge(e,t){if(e instanceof ss){const t=e.nodeBefore,o=e.nodeAfter;if(!(t instanceof Ms))throw new fe("schema-check-merge-no-element-before",this);if(!(o instanceof Ms))throw new fe("schema-check-merge-no-element-after",this);return this.checkMerge(t,o)}if(this.isLimit(e)||this.isLimit(t))return!1;for(const o of t.getChildren())if(!this.checkChild(e,o))return!1;return!0}addChildCheck(e,t){const o=void 0!==t?t:this._genericCheckSymbol,i=this._customChildChecks.get(o)||[];i.push(e),this._customChildChecks.set(o,i)}addAttributeCheck(e,t){const o=void 0!==t?t:this._genericCheckSymbol,i=this._customAttributeChecks.get(o)||[];i.push(e),this._customAttributeChecks.set(o,i)}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;if(e instanceof ss)t=e.parent;else{t=(e instanceof us?[e]:Array.from(e.getRanges())).reduce(((e,t)=>{const o=t.getCommonAncestor();return e?e.getCommonAncestor(o,{includeSelf:!0}):o}),null)}for(;!this.isLimit(t)&&t.parent;)t=t.parent;return t}checkAttributeInSelection(e,t){if(e.isCollapsed){const o=[...e.getFirstPosition().getAncestors(),new Is("",e.getAttributes())];return this.checkAttribute(o,t)}{const o=e.getRanges();for(const e of o)for(const o of e)if(this.checkAttribute(o.item,t))return!0}return!1}*getValidRanges(e,t,o={}){e=function*(e){for(const t of e)yield*t.getMinimalFlatRanges()}(e);for(const i of e)yield*this._getValidRangesForRange(i,t,o)}getNearestSelectionRange(e,t="both"){if("$graveyard"==e.root.rootName)return null;if(this.checkChild(e,"$text"))return new us(e);let o,i;const n=e.getAncestors().reverse().find((e=>this.isLimit(e)))||e.root;"both"!=t&&"backward"!=t||(o=new is({boundaries:us._createIn(n),startPosition:e,direction:"backward"})),"both"!=t&&"forward"!=t||(i=new is({boundaries:us._createIn(n),startPosition:e}));for(const e of function*(e,t){let o=!1;for(;!o;){if(o=!0,e){const t=e.next();t.done||(o=!1,yield{walker:e,value:t.value})}if(t){const e=t.next();e.done||(o=!1,yield{walker:t,value:e.value})}}}(o,i)){const t=e.walker==o?"elementEnd":"elementStart",i=e.value;if(i.type==t&&this.isObject(i.item))return us._createOn(i.item);if(this.checkChild(i.nextPosition,"$text"))return new us(i.nextPosition)}return null}findAllowedParent(e,t){let o=e.parent;for(;o;){if(this.checkChild(o,t))return o;if(this.isLimit(o))return null;o=o.parent}return null}setAllowedAttributes(e,t,o){const i=o.model;for(const[n,s]of Object.entries(t))i.schema.checkAttribute(e,n)&&o.setAttribute(n,s,e)}removeDisallowedAttributes(e,t){for(const o of e)if(o.is("$text"))Tr(this,o,t);else{const e=us._createIn(o).getPositions();for(const o of e){Tr(this,o.nodeBefore||o.parent,t)}}}getAttributesWithProperty(e,t,o){const i={};for(const[n,s]of e.getAttributes()){const e=this.getAttributeProperties(n);void 0!==e[t]&&(void 0!==o&&o!==e[t]||(i[n]=s))}return i}createContext(e){return new gr(e)}_clearCache(){this._compiledDefinitions=null}_compile(){const e={},t=this._sourceDefinitions,o=Object.keys(t);for(const i of o)e[i]=pr(t[i],i);const i=Object.values(e);for(const t of i)fr(e,t),br(e,t),wr(e,t),yr(e,t);for(const t of i)_r(e,t);for(const t of i)kr(e,t);for(const t of i)vr(e,t);for(const t of i)Cr(e,t);for(const t of i)Ar(e,t);this._compiledDefinitions=function(e){const t={};for(const o of Object.values(e))t[o.name]={name:o.name,isBlock:!!o.isBlock,isContent:!!o.isContent,isInline:!!o.isInline,isLimit:!!o.isLimit,isObject:!!o.isObject,isSelectable:!!o.isSelectable,allowIn:Array.from(o.allowIn).filter((t=>!!e[t])),allowChildren:Array.from(o.allowChildren).filter((t=>!!e[t])),allowAttributes:Array.from(o.allowAttributes)};return t}(e)}_checkContextMatch(e,t){const o=e.last;let i=this._evaluateChildChecks(e,t);if(i=void 0!==i?i:t.allowIn.includes(o.name),!i)return!1;const n=this.getDefinition(o),s=e.trimLast();return!!n&&(0==s.length||this._checkContextMatch(s,n))}_evaluateChildChecks(e,t){const o=this._customChildChecks.get(this._genericCheckSymbol)||[],i=this._customChildChecks.get(t.name)||[];for(const n of[...o,...i]){const o=n(e,t);if(void 0!==o)return o}}_evaluateAttributeChecks(e,t){const o=this._customAttributeChecks.get(this._genericCheckSymbol)||[],i=this._customAttributeChecks.get(t)||[];for(const n of[...o,...i]){const o=n(e,t);if(void 0!==o)return o}}*_getValidRangesForRange(e,t,o){let i=e.start,n=e.start;for(const s of e.getItems({shallow:!0})){if(s.is("element"))if(o.includeEmptyRanges&&s.isEmpty){const e=this.createContext(s);this.checkChild(e,"$text")&&this.checkAttribute(e.push("$text"),t)&&(yield us._createIn(s))}else yield*this._getValidRangesForRange(us._createIn(s),t,o);this.checkAttribute(s,t)||(i.isEqual(n)||(yield new us(i,n)),i=ss._createAfter(s)),n=ss._createAfter(s)}i.isEqual(n)||(yield new us(i,n))}findOptimalInsertionRange(e,t){const o=e.getSelectedElement();if(o&&this.isObject(o)&&!this.isInline(o))return"before"==t||"after"==t?new us(ss._createAt(o,t)):us._createOn(o);const i=to(e.getSelectedBlocks());if(!i)return new us(e.focus);if(i.isEmpty)return new us(ss._createAt(i,0));const n=ss._createAfter(i);return e.focus.isTouching(n)?new us(n):new us(ss._createBefore(i))}}class gr{_items;constructor(e){if(e instanceof gr)return e;let t;t="string"==typeof e?[e]:Array.isArray(e)?e:e.getAncestors({includeSelf:!0}),this._items=t.map(Er)}get length(){return this._items.length}get last(){return this._items[this._items.length-1]}[Symbol.iterator](){return this._items[Symbol.iterator]()}push(e){const t=new gr([e]);return t._items=[...this._items,...t._items],t}trimLast(){const e=new gr([]);return e._items=this._items.slice(0,-1),e}getItem(e){return this._items[e]}*getNames(){yield*this._items.map((e=>e.name))}endsWith(e){return Array.from(this.getNames()).join(" ").endsWith(e)}startsWith(e){return Array.from(this.getNames()).join(" ").startsWith(e)}}function pr(e,t){const o={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 o of e){const e=Object.keys(o).filter((e=>e.startsWith("is")));for(const i of e)t[i]=!!o[i]}}(e,o),xr(e,o,"allowIn"),xr(e,o,"allowChildren"),xr(e,o,"disallowIn"),xr(e,o,"disallowChildren"),xr(e,o,"allowContentOf"),xr(e,o,"allowWhere"),xr(e,o,"allowAttributes"),xr(e,o,"disallowAttributes"),xr(e,o,"allowAttributesOf"),xr(e,o,"inheritTypesFrom"),function(e,t){for(const o of e){const e=o.inheritAllFrom;e&&(t.allowContentOf.add(e),t.allowWhere.add(e),t.allowAttributesOf.add(e),t.inheritTypesFrom.add(e))}}(e,o),o}function fr(e,t){for(const o of t.allowIn){const i=e[o];i?i.allowChildren.add(t.name):t.allowIn.delete(o)}}function br(e,t){for(const o of t.allowChildren){const i=e[o];i?i.allowIn.add(t.name):t.allowChildren.delete(o)}}function wr(e,t){for(const o of t.disallowIn){const i=e[o];i?i.disallowChildren.add(t.name):t.disallowIn.delete(o)}}function yr(e,t){for(const o of t.disallowChildren){const i=e[o];i?i.disallowIn.add(t.name):t.disallowChildren.delete(o)}}function _r(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 kr(e,t){for(const o of t.allowContentOf){const i=e[o];i&&(i.disallowChildren.forEach((o=>{t.allowChildren.has(o)||(t.disallowChildren.add(o),e[o].disallowIn.add(t.name))})),i.allowChildren.forEach((o=>{t.disallowChildren.has(o)||(t.allowChildren.add(o),e[o].allowIn.add(t.name))})))}}function vr(e,t){for(const o of t.allowWhere){const i=e[o];i&&(i.disallowIn.forEach((o=>{t.allowIn.has(o)||(t.disallowIn.add(o),e[o].disallowChildren.add(t.name))})),i.allowIn.forEach((o=>{t.disallowIn.has(o)||(t.allowIn.add(o),e[o].allowChildren.add(t.name))})))}}function Cr(e,t){for(const o of t.allowAttributesOf){const i=e[o];if(!i)return;i.allowAttributes.forEach((e=>{t.disallowAttributes.has(e)||t.allowAttributes.add(e)}))}}function Ar(e,t){for(const o of t.inheritTypesFrom){const i=e[o];if(i){const e=Object.keys(i).filter((e=>e.startsWith("is")));for(const o of e)o in t||(t[o]=i[o])}}}function xr(e,t,o){for(const i of e){let e=i[o];"string"==typeof e&&(e=[e]),Array.isArray(e)&&e.forEach((e=>t[o].add(e)))}}function Er(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 Tr(e,t,o){for(const i of t.getAttributeKeys())e.checkAttribute(t,i)||o.removeAttribute(i,t)}class Pr extends(xe()){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,o=["$root"]){this.fire("viewCleanup",e),this._modelCursor=function(e,t){let o;for(const i of new gr(e)){const e={};for(const t of i.getAttributeKeys())e[t]=i.getAttribute(t);const n=t.createElement(i.name,e);o&&t.insert(n,o),o=ss._createAt(n,0)}return o}(o,t),this.conversionApi.writer=t,this.conversionApi.consumable=ai.createFrom(e),this.conversionApi.store={};const{modelRange:i}=this._convertItem(e,this._modelCursor),n=t.createDocumentFragment();if(i){this._removeEmptyElements();const e=this._modelCursor.parent,o=e._removeChildren(0,e.childCount);n._insertChild(0,o),n.markers=function(e,t){const o=new Set,i=new Map,n=us._createIn(e).getItems();for(const e of n)e.is("element","$marker")&&o.add(e);for(const e of o){const o=e.getAttribute("data-name"),n=t.createPositionBefore(e);i.has(o)?i.get(o).end=n.clone():i.set(o,new us(n.clone())),t.remove(e)}return i}(n,t)}return this._modelCursor=null,this._splitParts.clear(),this._cursorParents.clear(),this._emptyElementsToKeep.clear(),this.conversionApi.writer=null,this.conversionApi.store=null,n}_convertItem(e,t){const o={viewItem:e,modelCursor:t,modelRange:null};if(e.is("element")?this.fire(`element:${e.name}`,o,this.conversionApi):e.is("$text")?this.fire("text",o,this.conversionApi):this.fire("documentFragment",o,this.conversionApi),o.modelRange&&!(o.modelRange instanceof us))throw new fe("view-conversion-dispatcher-incorrect-result",this);return{modelRange:o.modelRange,modelCursor:o.modelCursor}}_convertChildren(e,t){let o=t.is("position")?t:ss._createAt(t,0);const i=new us(o);for(const t of Array.from(e.getChildren())){const e=this._convertItem(t,o);e.modelRange instanceof us&&(i.end=e.modelRange.end,o=e.modelCursor)}return{modelRange:i,modelCursor:o}}_safeInsert(e,t){const o=this._splitToAllowedParent(e,t);return!!o&&(this.conversionApi.writer.insert(e,o.position),!0)}_updateConversionResult(e,t){const o=this._getSplitParts(e),i=this.conversionApi.writer;t.modelRange||(t.modelRange=i.createRange(i.createPositionBefore(e),i.createPositionAfter(o[o.length-1])));const n=this._cursorParents.get(e);t.modelCursor=n?i.createPositionAt(n,0):t.modelRange.end}_splitToAllowedParent(e,t){const{schema:o,writer:i}=this.conversionApi;let n=o.findAllowedParent(t,e);if(n){if(n===t.parent)return{position:t};this._modelCursor.parent.getAncestors().includes(n)&&(n=null)}if(!n)return ir(t,e,o)?{position:nr(t,i)}:null;const s=this.conversionApi.writer.split(t,n),r=[];for(const e of s.range.getWalker())if("elementEnd"==e.type)r.push(e.item);else{const t=r.pop(),o=e.item;this._registerSplitPair(t,o)}const a=s.range.end.parent;return this._cursorParents.set(e,a),{position:s.position,cursorParent:a}}_registerSplitPair(e,t){this._splitParts.has(e)||this._splitParts.set(e,[e]);const o=this._splitParts.get(e);this._splitParts.set(t,o),o.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 o=e.get(t.parent)||[];o.push(t),this._splitParts.delete(t),e.set(t.parent,o)}for(const[t,o]of e)t._removeChildrenArray(o);e.size&&this._removeEmptyElements()}}class Sr{getHtml(e){const t=J.document.implementation.createHTMLDocument("").createElement("div");return t.appendChild(e),t.innerHTML}}class Ir{domParser;domConverter;htmlWriter;skipComments=!0;constructor(e){this.domParser=new DOMParser,this.domConverter=new Rn(e,{renderingMode:"data"}),this.htmlWriter=new Sr}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"),o=t.createDocumentFragment(),i=t.body.childNodes;for(;i.length>0;)o.appendChild(i[0]);return o}}class Rr extends(xe()){model;mapper;downcastDispatcher;upcastDispatcher;viewDocument;stylesProcessor;htmlProcessor;processor;_viewWriter;constructor(e,t){super(),this.model=e,this.mapper=new hs,this.downcastDispatcher=new fs({mapper:this.mapper,schema:e.schema}),this.downcastDispatcher.on("insert:$text",((e,t,o)=>{if(!o.consumable.consume(t.item,e.name))return;const i=o.writer,n=o.mapper.toViewPosition(t.range.start),s=i.createText(t.item.data);i.insert(n,s)}),{priority:"lowest"}),this.downcastDispatcher.on("insert",((e,t,o)=>{o.convertAttributes(t.item),t.reconversion||!t.item.is("element")||t.item.isEmpty||o.convertChildren(t.item)}),{priority:"lowest"}),this.upcastDispatcher=new Pr({schema:e.schema}),this.viewDocument=new Hi(t),this.stylesProcessor=t,this.htmlProcessor=new Ir(this.viewDocument),this.processor=this.htmlProcessor,this._viewWriter=new on(this.viewDocument),this.upcastDispatcher.on("text",((e,t,{schema:o,consumable:i,writer:n})=>{let s=t.modelCursor;if(!i.test(t.viewItem))return;if(!o.checkChild(s,"$text")){if(!ir(s,"$text",o))return;if(0==t.viewItem.data.trim().length)return;s=nr(s,n)}i.consume(t.viewItem);const r=n.createText(t.viewItem.data);n.insert(r,s),t.modelRange=n.createRange(s,s.getShiftedBy(r.offsetSize)),t.modelCursor=t.modelRange.end}),{priority:"lowest"}),this.upcastDispatcher.on("element",((e,t,o)=>{if(!t.modelRange&&o.consumable.consume(t.viewItem,{name:!0})){const{modelRange:e,modelCursor:i}=o.convertChildren(t.viewItem,t.modelCursor);t.modelRange=e,t.modelCursor=i}}),{priority:"lowest"}),this.upcastDispatcher.on("documentFragment",((e,t,o)=>{if(!t.modelRange&&o.consumable.consume(t.viewItem,{name:!0})){const{modelRange:e,modelCursor:i}=o.convertChildren(t.viewItem,t.modelCursor);t.modelRange=e,t.modelCursor=i}}),{priority:"lowest"}),Be().prototype.decorate.call(this,"init"),Be().prototype.decorate.call(this,"set"),Be().prototype.decorate.call(this,"get"),Be().prototype.decorate.call(this,"toView"),Be().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:o="empty"}=e;if(!this._checkIfRootsExists([t]))throw new fe("datacontroller-get-non-existent-root",this);const i=this.model.document.getRoot(t);return i.isAttached()||be("datacontroller-get-detached-root",this),"empty"!==o||this.model.hasContent(i,{ignoreWhitespaces:!0})?this.stringify(i,e):""}stringify(e,t={}){const o=this.toView(e,t);return this.processor.toData(o)}toView(e,t={}){const o=this.viewDocument,i=this._viewWriter;this.mapper.clearBindings();const n=us._createIn(e),s=new tn(o);this.mapper.bindElements(e,s);const r=e.is("documentFragment")?e.markers:function(e){const t=[],o=e.root.document;if(!o)return new Map;const i=us._createIn(e);for(const e of o.model.markers){const o=e.getRange(),n=o.isCollapsed,s=o.start.isEqual(i.start)||o.end.isEqual(i.end);if(n&&s)t.push([e.name,o]);else{const n=i.getIntersection(o);n&&t.push([e.name,n])}}return t.sort((([e,t],[o,i])=>{if("after"!==t.end.compareWith(i.start))return 1;if("before"!==t.start.compareWith(i.end))return-1;switch(t.start.compareWith(i.start)){case"before":return 1;case"after":return-1;default:switch(t.end.compareWith(i.end)){case"before":return 1;case"after":return-1;default:return o.localeCompare(e)}}})),new Map(t)}(e);return this.downcastDispatcher.convert(n,r,i,t),s}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 o of Object.keys(t)){const i=this.model.document.getRoot(o);e.insert(this.parse(t[o],i),i,0)}})),Promise.resolve()}set(e,t={}){let o={};if("string"==typeof e?o.main=e:o=e,!this._checkIfRootsExists(Object.keys(o)))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(o)){const i=this.model.document.getRoot(t);e.remove(e.createRangeIn(i)),e.insert(this.parse(o[t],i),i,0)}}))}parse(e,t="$root"){const o=this.processor.toView(e);return this.toModel(o,t)}toModel(e,t="$root"){return this.model.change((o=>this.upcastDispatcher.convert(e,o,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}}class Or{_helpers=new Map;_downcast;_upcast;constructor(e,t){this._downcast=Qt(e),this._createConversionHelpers({name:"downcast",dispatchers:this._downcast,isDowncast:!0}),this._upcast=Qt(t),this._createConversionHelpers({name:"upcast",dispatchers:this._upcast,isDowncast:!1})}addAlias(e,t){const o=this._downcast.includes(t);if(!this._upcast.includes(t)&&!o)throw new fe("conversion-add-alias-dispatcher-not-registered",this);this._createConversionHelpers({name:e,dispatchers:[t],isDowncast:o})}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:o}of Vr(e))this.for("upcast").elementToElement({model:t,view:o,converterPriority:e.converterPriority})}attributeToElement(e){this.for("downcast").attributeToElement(e);for(const{model:t,view:o}of Vr(e))this.for("upcast").elementToAttribute({view:o,model:t,converterPriority:e.converterPriority})}attributeToAttribute(e){this.for("downcast").attributeToAttribute(e);for(const{model:t,view:o}of Vr(e))this.for("upcast").attributeToAttribute({view:o,model:t})}_createConversionHelpers({name:e,dispatchers:t,isDowncast:o}){if(this._helpers.has(e))throw new fe("conversion-group-exists",this);const i=o?new Bs(t):new sr(t);this._helpers.set(e,i)}}function*Vr(e){if(e.model.values)for(const t of e.model.values){const o={key:e.model.key,value:t},i=e.view[t],n=e.upcastAlso?e.upcastAlso[t]:void 0;yield*Dr(o,i,n)}else yield*Dr(e.model,e.view,e.upcastAlso)}function*Dr(e,t,o){if(yield{model:e,view:t},o)for(const t of Qt(o))yield{model:e,view:t}}class Fr{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 Mr(e,t){const o=Lr(t),i=o.reduce(((e,t)=>e+t.offsetSize),0),n=e.parent;jr(e);const s=e.index;return n._insertChild(s,o),zr(n,s+o.length),zr(n,s),new us(e,e.getShiftedBy(i))}function Nr(e){if(!e.isFlat)throw new fe("operation-utils-remove-range-not-flat",this);const t=e.start.parent;jr(e.start),jr(e.end);const o=t._removeChildren(e.start.index,e.end.index-e.start.index);return zr(t,e.start.index),o}function Br(e,t){if(!e.isFlat)throw new fe("operation-utils-move-range-not-flat",this);const o=Nr(e);return Mr(t=t._getTransformedByDeletion(e.start,e.end.offset-e.start.offset),o)}function Lr(e){const t=[];!function e(o){if("string"==typeof o)t.push(new Is(o));else if(o instanceof os)t.push(new Is(o.data,o.getAttributes()));else if(o instanceof ys)t.push(o);else if(Ue(o))for(const t of o)e(t)}(e);for(let e=1;ee.maxOffset)throw new fe("move-operation-nodes-do-not-exist",this);if(e===t&&o=o&&this.targetPosition.path[e]e._clone(!0)))),t=new Hr(this.position,e,this.baseVersion);return t.shouldReceiveAttributes=this.shouldReceiveAttributes,t}getReversed(){const e=this.position.root.document.graveyard,t=new ss(e,[0]);return new $r(this.position,this.nodes.maxOffset,t,this.baseVersion+1)}_validate(){const e=this.position.parent;if(!e||e.maxOffsete._clone(!0)))),Mr(this.position,e)}toJSON(){const e=super.toJSON();return e.position=this.position.toJSON(),e.nodes=this.nodes.toJSON(),e}static get className(){return"InsertOperation"}static fromJSON(e,t){const o=[];for(const t of e.nodes)t.name?o.push(Ms.fromJSON(t)):o.push(Is.fromJSON(t));const i=new Hr(ss.fromJSON(e.position,t),o,e.baseVersion);return i.shouldReceiveAttributes=e.shouldReceiveAttributes,i}}class Wr extends Fr{splitPosition;howMany;insertionPosition;graveyardPosition;constructor(e,t,o,i,n){super(n),this.splitPosition=e.clone(),this.splitPosition.stickiness="toNext",this.howMany=t,this.insertionPosition=o,this.graveyardPosition=i?i.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 ss(this.insertionPosition.root,e)}get movedRange(){const e=this.splitPosition.getShiftedBy(Number.POSITIVE_INFINITY);return new us(this.splitPosition,e)}get affectedSelectable(){const e=[us._createFromPositionAndShift(this.splitPosition,0),us._createFromPositionAndShift(this.insertionPosition,0)];return this.graveyardPosition&&e.push(us._createFromPositionAndShift(this.graveyardPosition,0)),e}clone(){return new Wr(this.splitPosition,this.howMany,this.insertionPosition,this.graveyardPosition,this.baseVersion)}getReversed(){const e=this.splitPosition.root.document.graveyard,t=new ss(e,[0]);return new Ur(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 $r&&(e.targetPosition.isEqual(t.sourcePosition)||e.targetPosition.isBefore(t.sourcePosition)?this._setRelation(e,t,"insertBefore"):this._setRelation(e,t,"insertAfter"));else if(e instanceof Wr){if(t instanceof Ur)e.splitPosition.isBefore(t.sourcePosition)&&this._setRelation(e,t,"splitBefore");else if(t instanceof $r)if(e.splitPosition.isEqual(t.sourcePosition)||e.splitPosition.isBefore(t.sourcePosition))this._setRelation(e,t,"splitBefore");else{const o=us._createFromPositionAndShift(t.sourcePosition,t.howMany);if(e.splitPosition.hasSameParentAs(t.sourcePosition)&&o.containsPosition(e.splitPosition)){const i=o.end.offset-e.splitPosition.offset,n=e.splitPosition.offset-o.start.offset;this._setRelation(e,t,{howMany:i,offset:n})}}}else if(e instanceof Ur)t instanceof Ur?(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 Wr?e.sourcePosition.isEqual(t.splitPosition)&&this._setRelation(e,t,"splitAtSource"):t instanceof $r&&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 Kr){const o=e.newRange;if(!o)return;if(t instanceof Ur){const i=o.start.isEqual(t.targetPosition),n=o.start.isEqual(t.deletionPosition),s=o.end.isEqual(t.deletionPosition),r=o.end.isEqual(t.sourcePosition);(i||n||s||r)&&this._setRelation(e,t,{wasInLeftElement:i,wasStartBeforeMergedElement:n,wasEndBeforeMergedElement:s,wasInRightElement:r})}}}getContext(e,t,o){return{aIsStrong:o,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 o=this.originalOperations.get(t),i=this._history.getUndoneOperation(o);if(!i)return null;const n=this.originalOperations.get(e),s=this._relations.get(n);return s&&s.get(i)||null}_setRelation(e,t,o){const i=this.originalOperations.get(e),n=this.originalOperations.get(t);let s=this._relations.get(i);s||(s=new Map,this._relations.set(i,s)),s.set(n,o)}}function aa(e,t){for(const o of e)o.baseVersion=t++}function la(e,t){for(let o=0;o{if(e.key===t.key&&e.range.start.hasSameParentAs(t.range.start)){const i=e.range.getDifference(t.range).map((t=>new Gr(t,e.key,e.oldValue,e.newValue,0))),n=e.range.getIntersection(t.range);return n&&o.aIsStrong&&i.push(new Gr(n,t.key,t.newValue,e.newValue,0)),0==i.length?[new Jr(0)]:i}return[e]})),oa(Gr,Hr,((e,t)=>{if(e.range.start.hasSameParentAs(t.position)&&e.range.containsPosition(t.position)){const o=e.range._getTransformedByInsertion(t.position,t.howMany,!t.shouldReceiveAttributes).map((t=>new Gr(t,e.key,e.oldValue,e.newValue,e.baseVersion)));if(t.shouldReceiveAttributes){const i=da(t,e.key,e.oldValue);i&&o.unshift(i)}return o}return e.range=e.range._getTransformedByInsertion(t.position,t.howMany,!1)[0],[e]})),oa(Gr,Ur,((e,t)=>{const o=[];e.range.start.hasSameParentAs(t.deletionPosition)&&(e.range.containsPosition(t.deletionPosition)||e.range.start.isEqual(t.deletionPosition))&&o.push(us._createFromPositionAndShift(t.graveyardPosition,1));const i=e.range._getTransformedByMergeOperation(t);return i.isCollapsed||o.push(i),o.map((t=>new Gr(t,e.key,e.oldValue,e.newValue,e.baseVersion)))})),oa(Gr,$r,((e,t)=>{const o=function(e,t){const o=us._createFromPositionAndShift(t.sourcePosition,t.howMany);let i=null,n=[];o.containsRange(e,!0)?i=e:e.start.hasSameParentAs(o.start)?(n=e.getDifference(o),i=e.getIntersection(o)):n=[e];const s=[];for(let e of n){e=e._getTransformedByDeletion(t.sourcePosition,t.howMany);const o=t.getMovedRangeStart(),i=e.start.hasSameParentAs(o),n=e._getTransformedByInsertion(o,t.howMany,i);s.push(...n)}i&&s.push(i._getTransformedByMove(t.sourcePosition,t.targetPosition,t.howMany,!1)[0]);return s}(e.range,t);return o.map((t=>new Gr(t,e.key,e.oldValue,e.newValue,e.baseVersion)))})),oa(Gr,Wr,((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 o=e.clone();return o.range=new us(t.moveTargetPosition.clone(),e.range.end._getCombined(t.splitPosition,t.moveTargetPosition)),e.range.end=t.splitPosition.clone(),e.range.end.stickiness="toPrevious",[e,o]}return e.range=e.range._getTransformedBySplitOperation(t),[e]})),oa(Hr,Gr,((e,t)=>{const o=[e];if(e.shouldReceiveAttributes&&e.position.hasSameParentAs(t.range.start)&&t.range.containsPosition(e.position)){const i=da(e,t.key,t.newValue);i&&o.push(i)}return o})),oa(Hr,Hr,((e,t,o)=>(e.position.isEqual(t.position)&&o.aIsStrong||(e.position=e.position._getTransformedByInsertOperation(t)),[e]))),oa(Hr,$r,((e,t)=>(e.position=e.position._getTransformedByMoveOperation(t),[e]))),oa(Hr,Wr,((e,t)=>(e.position=e.position._getTransformedBySplitOperation(t),[e]))),oa(Hr,Ur,((e,t)=>(e.position=e.position._getTransformedByMergeOperation(t),[e]))),oa(Kr,Hr,((e,t)=>(e.oldRange&&(e.oldRange=e.oldRange._getTransformedByInsertOperation(t)[0]),e.newRange&&(e.newRange=e.newRange._getTransformedByInsertOperation(t)[0]),[e]))),oa(Kr,Kr,((e,t,o)=>{if(e.name==t.name){if(!o.aIsStrong)return[new Jr(0)];e.oldRange=t.newRange?t.newRange.clone():null}return[e]})),oa(Kr,Ur,((e,t)=>(e.oldRange&&(e.oldRange=e.oldRange._getTransformedByMergeOperation(t)),e.newRange&&(e.newRange=e.newRange._getTransformedByMergeOperation(t)),[e]))),oa(Kr,$r,((e,t)=>{const o=[e];if(e.oldRange&&(e.oldRange=us._createFromRanges(e.oldRange._getTransformedByMoveOperation(t))),e.newRange){const i=e.newRange._getTransformedByMoveOperation(t);e.newRange=i[0];for(let t=1;t{if(e.oldRange&&(e.oldRange=e.oldRange._getTransformedBySplitOperation(t)),e.newRange){if(o.abRelation){const i=e.newRange._getTransformedBySplitOperation(t);return e.newRange.start.isEqual(t.splitPosition)?o.abRelation.wasStartBeforeMergedElement?e.newRange.start=ss._createAt(t.insertionPosition):o.abRelation.wasInLeftElement?e.newRange.start=ss._createAt(e.newRange.start):e.newRange.start=ss._createAt(t.moveTargetPosition):e.newRange.start=i.start,e.newRange.end.isEqual(t.splitPosition)?e.newRange.end.isEqual(t.splitPosition)&&o.abRelation.wasEndBeforeMergedElement?e.newRange.end=ss._createAt(t.insertionPosition):o.abRelation.wasInRightElement?e.newRange.end=ss._createAt(t.moveTargetPosition):e.newRange.end=ss._createAt(e.newRange.end):e.newRange.end=i.end,[e]}e.newRange=e.newRange._getTransformedBySplitOperation(t)}return[e]})),oa(Ur,Hr,((e,t)=>(e.sourcePosition.hasSameParentAs(t.position)&&(e.howMany+=t.howMany),e.sourcePosition=e.sourcePosition._getTransformedByInsertOperation(t),e.targetPosition=e.targetPosition._getTransformedByInsertOperation(t),[e]))),oa(Ur,Ur,((e,t,o)=>{if(e.sourcePosition.isEqual(t.sourcePosition)&&e.targetPosition.isEqual(t.targetPosition)){if(o.bWasUndone){const o=t.graveyardPosition.path.slice();return o.push(0),e.sourcePosition=new ss(t.graveyardPosition.root,o),e.howMany=0,[e]}return[new Jr(0)]}if(e.sourcePosition.isEqual(t.sourcePosition)&&!e.targetPosition.isEqual(t.targetPosition)&&!o.bWasUndone&&"splitAtSource"!=o.abRelation){const i="$graveyard"==e.targetPosition.root.rootName,n="$graveyard"==t.targetPosition.root.rootName;if(n&&!i||!(i&&!n)&&o.aIsStrong){const o=t.targetPosition._getTransformedByMergeOperation(t),i=e.targetPosition._getTransformedByMergeOperation(t);return[new $r(o,e.howMany,i,0)]}return[new Jr(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)&&o.aIsStrong||(e.graveyardPosition=e.graveyardPosition._getTransformedByMergeOperation(t)),[e]})),oa(Ur,$r,((e,t,o)=>{const i=us._createFromPositionAndShift(t.sourcePosition,t.howMany);return"remove"==t.type&&!o.bWasUndone&&e.deletionPosition.hasSameParentAs(t.sourcePosition)&&i.containsPosition(e.sourcePosition)?[new Jr(0)]:(t.sourcePosition.getShiftedBy(t.howMany).isEqual(e.sourcePosition)?e.sourcePosition.stickiness="toNone":t.targetPosition.isEqual(e.sourcePosition)&&"mergeSourceAffected"==o.abRelation?e.sourcePosition.stickiness="toNext":t.sourcePosition.isEqual(e.targetPosition)?(e.targetPosition.stickiness="toNone",e.howMany-=t.howMany):t.targetPosition.isEqual(e.targetPosition)&&"mergeTargetWasBefore"==o.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])})),oa(Ur,Wr,((e,t,o)=>{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)){if(t.graveyardPosition&&e.deletionPosition.isEqual(t.graveyardPosition)||"mergeTargetNotMoved"==o.abRelation)return e.sourcePosition=e.sourcePosition._getTransformedBySplitOperation(t),[e]}if(e.sourcePosition.isEqual(t.splitPosition)){if("mergeSourceNotMoved"==o.abRelation)return e.howMany=0,e.targetPosition=e.targetPosition._getTransformedBySplitOperation(t),[e];if("mergeSameElement"==o.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]})),oa($r,Hr,((e,t)=>{const o=us._createFromPositionAndShift(e.sourcePosition,e.howMany)._getTransformedByInsertOperation(t,!1)[0];return e.sourcePosition=o.start,e.howMany=o.end.offset-o.start.offset,e.targetPosition.isEqual(t.position)||(e.targetPosition=e.targetPosition._getTransformedByInsertOperation(t)),[e]})),oa($r,$r,((e,t,o)=>{const i=us._createFromPositionAndShift(e.sourcePosition,e.howMany),n=us._createFromPositionAndShift(t.sourcePosition,t.howMany);let s,r=o.aIsStrong,a=!o.aIsStrong;if("insertBefore"==o.abRelation||"insertAfter"==o.baRelation?a=!0:"insertAfter"!=o.abRelation&&"insertBefore"!=o.baRelation||(a=!1),s=e.targetPosition.isEqual(t.targetPosition)&&a?e.targetPosition._getTransformedByDeletion(t.sourcePosition,t.howMany):e.targetPosition._getTransformedByMove(t.sourcePosition,t.targetPosition,t.howMany),ua(e,t)&&ua(t,e))return[t.getReversed()];if(i.containsPosition(t.targetPosition)&&i.containsRange(n,!0))return i.start=i.start._getTransformedByMove(t.sourcePosition,t.targetPosition,t.howMany),i.end=i.end._getTransformedByMove(t.sourcePosition,t.targetPosition,t.howMany),ha([i],s);if(n.containsPosition(e.targetPosition)&&n.containsRange(i,!0))return i.start=i.start._getCombined(t.sourcePosition,t.getMovedRangeStart()),i.end=i.end._getCombined(t.sourcePosition,t.getMovedRangeStart()),ha([i],s);const l=We(e.sourcePosition.getParentPath(),t.sourcePosition.getParentPath());if("prefix"==l||"extension"==l)return i.start=i.start._getTransformedByMove(t.sourcePosition,t.targetPosition,t.howMany),i.end=i.end._getTransformedByMove(t.sourcePosition,t.targetPosition,t.howMany),ha([i],s);"remove"!=e.type||"remove"==t.type||o.aWasUndone||o.forceWeakRemove?"remove"==e.type||"remove"!=t.type||o.bWasUndone||o.forceWeakRemove||(r=!1):r=!0;const c=[],d=i.getDifference(n);for(const e of d){e.start=e.start._getTransformedByDeletion(t.sourcePosition,t.howMany),e.end=e.end._getTransformedByDeletion(t.sourcePosition,t.howMany);const o="same"==We(e.start.getParentPath(),t.getMovedRangeStart().getParentPath()),i=e._getTransformedByInsertion(t.getMovedRangeStart(),t.howMany,o);c.push(...i)}const u=i.getIntersection(n);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?n.start.isBefore(i.start)||n.start.isEqual(i.start)?c.unshift(u):c.push(u):c.splice(1,0,u)),0===c.length?[new Jr(e.baseVersion)]:ha(c,s)})),oa($r,Wr,((e,t,o)=>{let i=e.targetPosition.clone();if(e.targetPosition.isEqual(t.insertionPosition)&&t.graveyardPosition&&"moveTargetAfter"!=o.abRelation||(i=e.targetPosition._getTransformedBySplitOperation(t)),e.sourcePosition.isEqual(t.insertionPosition)&&"firstToMoveMerged"==o.abRelation)return e.howMany++,e.targetPosition=i,[e];const n=us._createFromPositionAndShift(e.sourcePosition,e.howMany);if(n.end.isEqual(t.insertionPosition))return t.graveyardPosition&&"lastToMoveMerged"!=o.abRelation||e.howMany++,e.targetPosition=i,[e];if(n.start.hasSameParentAs(t.splitPosition)&&n.containsPosition(t.splitPosition)){let e=new us(t.splitPosition,n.end);e=e._getTransformedBySplitOperation(t);return ha([new us(n.start,t.splitPosition),e],i)}e.targetPosition.isEqual(t.splitPosition)&&"insertAtSource"==o.abRelation&&(i=t.moveTargetPosition),e.targetPosition.isEqual(t.insertionPosition)&&"insertBetween"==o.abRelation&&(i=e.targetPosition);const s=[n._getTransformedBySplitOperation(t)];if(t.graveyardPosition){const i=n.start.isEqual(t.graveyardPosition)||n.containsPosition(t.graveyardPosition);e.howMany>1&&i&&!o.aWasUndone&&s.push(us._createFromPositionAndShift(t.insertionPosition,1))}return ha(s,i)})),oa($r,Ur,((e,t,o)=>{const i=us._createFromPositionAndShift(e.sourcePosition,e.howMany);if(t.deletionPosition.hasSameParentAs(e.sourcePosition)&&i.containsPosition(t.sourcePosition))if("remove"!=e.type||o.forceWeakRemove){if(1==e.howMany)return o.bWasUndone?(e.sourcePosition=t.graveyardPosition.clone(),e.targetPosition=e.targetPosition._getTransformedByMergeOperation(t),[e]):[new Jr(0)]}else if(!o.aWasUndone){const o=[];let i=t.graveyardPosition.clone(),n=t.targetPosition._getTransformedByMergeOperation(t);const s=e.targetPosition.getTransformedByOperation(t);e.howMany>1&&(o.push(new $r(e.sourcePosition,e.howMany-1,s,0)),i=i._getTransformedByMove(e.sourcePosition,s,e.howMany-1),n=n._getTransformedByMove(e.sourcePosition,s,e.howMany-1));const r=t.deletionPosition._getCombined(e.sourcePosition,s),a=new $r(i,1,r,0),l=a.getMovedRangeStart().path.slice();l.push(0);const c=new ss(a.targetPosition.root,l);n=n._getTransformedByMove(i,r,1);const d=new $r(n,t.howMany,c,0);return o.push(a),o.push(d),o}const n=us._createFromPositionAndShift(e.sourcePosition,e.howMany)._getTransformedByMergeOperation(t);return e.sourcePosition=n.start,e.howMany=n.end.offset-n.start.offset,e.targetPosition=e.targetPosition._getTransformedByMergeOperation(t),[e]})),oa(Zr,Hr,((e,t)=>(e.position=e.position._getTransformedByInsertOperation(t),[e]))),oa(Zr,Ur,((e,t)=>e.position.isEqual(t.deletionPosition)?(e.position=t.graveyardPosition.clone(),e.position.stickiness="toNext",[e]):(e.position=e.position._getTransformedByMergeOperation(t),[e]))),oa(Zr,$r,((e,t)=>(e.position=e.position._getTransformedByMoveOperation(t),[e]))),oa(Zr,Zr,((e,t,o)=>{if(e.position.isEqual(t.position)){if(!o.aIsStrong)return[new Jr(0)];e.oldName=t.newName}return[e]})),oa(Zr,Wr,((e,t)=>{if("same"==We(e.position.path,t.splitPosition.getParentPath())&&!t.graveyardPosition){const t=new Zr(e.position.getShiftedBy(1),e.oldName,e.newName,0);return[e,t]}return e.position=e.position._getTransformedBySplitOperation(t),[e]})),oa(Qr,Qr,((e,t,o)=>{if(e.root===t.root&&e.key===t.key){if(!o.aIsStrong)return[new Jr(0)];e.oldValue=t.newValue}return[e]})),oa(Yr,Yr,((e,t)=>e.rootName===t.rootName&&e.isAdd===t.isAdd?[new Jr(0)]:[e])),oa(Wr,Hr,((e,t)=>(e.splitPosition.hasSameParentAs(t.position)&&e.splitPosition.offset{if(!e.graveyardPosition&&!o.bWasUndone&&e.splitPosition.hasSameParentAs(t.sourcePosition)){const o=t.graveyardPosition.path.slice();o.push(0);const i=new ss(t.graveyardPosition.root,o),n=Wr.getInsertionPosition(new ss(t.graveyardPosition.root,o)),s=new Wr(i,0,n,null,0);return e.splitPosition=e.splitPosition._getTransformedByMergeOperation(t),e.insertionPosition=Wr.getInsertionPosition(e.splitPosition),e.graveyardPosition=s.insertionPosition.clone(),e.graveyardPosition.stickiness="toNext",[s,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=Wr.getInsertionPosition(e.splitPosition),e.graveyardPosition&&(e.graveyardPosition=e.graveyardPosition._getTransformedByMergeOperation(t)),[e]})),oa(Wr,$r,((e,t,o)=>{const i=us._createFromPositionAndShift(t.sourcePosition,t.howMany);if(e.graveyardPosition){const n=i.start.isEqual(e.graveyardPosition)||i.containsPosition(e.graveyardPosition);if(!o.bWasUndone&&n){const o=e.splitPosition._getTransformedByMoveOperation(t),i=e.graveyardPosition._getTransformedByMoveOperation(t),n=i.path.slice();n.push(0);const s=new ss(i.root,n);return[new $r(o,e.howMany,s,0)]}e.graveyardPosition=e.graveyardPosition._getTransformedByMoveOperation(t)}const n=e.splitPosition.isEqual(t.targetPosition);if(n&&("insertAtSource"==o.baRelation||"splitBefore"==o.abRelation))return e.howMany+=t.howMany,e.splitPosition=e.splitPosition._getTransformedByDeletion(t.sourcePosition,t.howMany),e.insertionPosition=Wr.getInsertionPosition(e.splitPosition),[e];if(n&&o.abRelation&&o.abRelation.howMany){const{howMany:t,offset:i}=o.abRelation;return e.howMany+=t,e.splitPosition=e.splitPosition.getShiftedBy(i),[e]}if(e.splitPosition.hasSameParentAs(t.sourcePosition)&&i.containsPosition(e.splitPosition)){const o=t.howMany-(e.splitPosition.offset-t.sourcePosition.offset);return e.howMany-=o,e.splitPosition.hasSameParentAs(t.targetPosition)&&e.splitPosition.offset{if(e.splitPosition.isEqual(t.splitPosition)){if(!e.graveyardPosition&&!t.graveyardPosition)return[new Jr(0)];if(e.graveyardPosition&&t.graveyardPosition&&e.graveyardPosition.isEqual(t.graveyardPosition))return[new Jr(0)];if("splitBefore"==o.abRelation)return e.howMany=0,e.graveyardPosition=e.graveyardPosition._getTransformedBySplitOperation(t),[e]}if(e.graveyardPosition&&t.graveyardPosition&&e.graveyardPosition.isEqual(t.graveyardPosition)){const i="$graveyard"==e.splitPosition.root.rootName,n="$graveyard"==t.splitPosition.root.rootName;if(n&&!i||!(i&&!n)&&o.aIsStrong){const o=[];return t.howMany&&o.push(new $r(t.moveTargetPosition,t.howMany,t.splitPosition,0)),e.howMany&&o.push(new $r(e.splitPosition,e.howMany,e.moveTargetPosition,0)),o}return[new Jr(0)]}if(e.graveyardPosition&&(e.graveyardPosition=e.graveyardPosition._getTransformedBySplitOperation(t)),e.splitPosition.isEqual(t.insertionPosition)&&"splitBefore"==o.abRelation)return e.howMany++,[e];if(t.splitPosition.isEqual(e.insertionPosition)&&"splitBefore"==o.baRelation){const o=t.insertionPosition.path.slice();o.push(0);const i=new ss(t.insertionPosition.root,o);return[e,new $r(e.insertionPosition,1,i,0)]}return e.splitPosition.hasSameParentAs(t.splitPosition)&&e.splitPosition.offset{const o=t[0];o.isDocumentOperation&&pa.call(this,o)}),{priority:"low"})}function pa(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)}}ma.prototype.is=function(e){return"livePosition"===e||"model:livePosition"===e||"position"==e||"model:position"===e};class fa{operations;isUndoable;isLocal;isUndo;isTyping;constructor(e={}){"string"==typeof e&&(e="transparent"===e?{isUndoable:!1}:{},be("batch-constructor-deprecated-string-type"));const{isUndoable:t=!0,isLocal:o=!0,isUndo:i=!1,isTyping:n=!1}=e;this.operations=[],this.isUndoable=t,this.isLocal=o,this.isUndo=i,this.isTyping=n}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}}class ba{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),o=this._isInInsertedElement(t.targetPosition.parent);e||this._markRemove(t.sourcePosition.parent,t.sourcePosition.offset,t.howMany),o||this._markInsert(t.targetPosition.parent,t.getMovedRangeStart().offset,t.howMany);const i=us._createFromPositionAndShift(t.sourcePosition,t.howMany);for(const e of i.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=us._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 o=us._createFromPositionAndShift(t.splitPosition,t.howMany);for(const e of o.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 o=t.graveyardPosition.parent;this._markInsert(o,t.graveyardPosition.offset,1),this._setElementState(e,"move");const i=t.targetPosition.parent;if(!this._isInInsertedElement(i)){this._markInsert(i,t.targetPosition.offset,e.maxOffset);const o=us._createFromPositionAndShift(t.sourcePosition,t.howMany);for(const e of o.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,o){t.range&&t.range.root.is("rootElement")&&!t.range.root._isLoaded&&(t.range=null),o.range&&o.range.root.is("rootElement")&&!o.range.root._isLoaded&&(o.range=null);let i=this._changedMarkers.get(e);i?i.newMarkerData=o:(i={newMarkerData:o,oldMarkerData:t},this._changedMarkers.set(e,i)),null==i.oldMarkerData.range&&null==o.range&&this._changedMarkers.delete(e)}getMarkersToRemove(){const e=[];for(const[t,o]of this._changedMarkers)null!=o.oldMarkerData.range&&e.push({name:t,range:o.oldMarkerData.range});return e}getMarkersToAdd(){const e=[];for(const[t,o]of this._changedMarkers)null!=o.newMarkerData.range&&e.push({name:t,range:o.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 o=e.range&&!t.range,i=!e.range&&t.range,n=e.range&&t.range&&!e.range.isEqual(t.range);if(o||i||n)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 o=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(ka),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=us._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 o=this._changedRoots.get(e);void 0!==o.state?(delete o.state,void 0===o.attributes&&this._changedRoots.delete(e)):o.state=t?"attached":"detached"}_bufferRootAttributeChange(e,t,o,i){const n=this._changedRoots.get(e)||{name:e},s=n.attributes||{};if(s[t]){const e=s[t];i===e.oldValue?delete s[t]:e.newValue=i}else s[t]={oldValue:o,newValue:i};0===Object.entries(s).length?(delete n.attributes,void 0===n.state&&this._changedRoots.delete(e)):(n.attributes=s,this._changedRoots.set(e,n))}_markInsert(e,t,o){if(e.root.is("rootElement")&&!e.root._isLoaded)return;const i={type:"insert",offset:t,howMany:o,count:this._changeCount++};this._markChange(e,i)}_markRemove(e,t,o){if(e.root.is("rootElement")&&!e.root._isLoaded)return;const i={type:"remove",offset:t,howMany:o,count:this._changeCount++};this._markChange(e,i),this._removeAllNestedChanges(e,t,o)}_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 o=this._getChangesForElement(e);this._handleChange(t,o),o.push(t);for(let e=0;eo&&this._elementState.set(e,t)}_getDiffActionForNode(e,t){if(!e.is("element"))return t;if(!this._elementsSnapshots.has(e))return t;const o=this._elementState.get(e);return o&&"move"!=o?o: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=ya(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 o of t){const i=e.offset+e.howMany,n=o.offset+o.howMany;if("insert"==e.type&&("insert"==o.type&&(e.offset<=o.offset?o.offset+=e.howMany:e.offseto.offset){if(i>n){const e={type:"attribute",offset:n,howMany:i-n,count:this._changeCount++};this._handleChange(e,t),t.push(e)}e.nodesToHandle=o.offset-e.offset,e.howMany=e.nodesToHandle}else e.offset>=o.offset&&e.offsetn?(e.nodesToHandle=i-n,e.offset=n):e.nodesToHandle=0);if("remove"==o.type&&e.offseto.offset){const n={type:"attribute",offset:o.offset,howMany:i-o.offset,count:this._changeCount++};this._handleChange(n,t),t.push(n),e.nodesToHandle=o.offset-e.offset,e.howMany=e.nodesToHandle}"attribute"==o.type&&(e.offset>=o.offset&&i<=n?(e.nodesToHandle=0,e.howMany=0,e.offset=0):e.offset<=o.offset&&i>=n&&(o.howMany=0))}}e.howMany=e.nodesToHandle,delete e.nodesToHandle}_getInsertDiff(e,t,o,i,n){const s={type:"insert",position:ss._createAt(e,t),name:i.name,attributes:new Map(i.attributes),length:1,changeCount:this._changeCount++,action:o};return"insert"!=o&&n&&(s.before={name:n.name,attributes:new Map(n.attributes)}),s}_getRemoveDiff(e,t,o,i){return{type:"remove",action:o,position:ss._createAt(e,t),name:i.name,attributes:new Map(i.attributes),length:1,changeCount:this._changeCount++}}_getAttributesDiff(e,t,o){const i=[];o=new Map(o);for(const[n,s]of t){const t=o.has(n)?o.get(n):null;t!==s&&i.push({type:"attribute",position:e.start,range:e.clone(),length:1,attributeKey:n,attributeOldValue:s,attributeNewValue:t,changeCount:this._changeCount++}),o.delete(n)}for(const[t,n]of o)i.push({type:"attribute",position:e.start,range:e.clone(),length:1,attributeKey:t,attributeOldValue:null,attributeNewValue:n,changeCount:this._changeCount++});return i}_isInInsertedElement(e){const t=e.parent;if(!t)return!1;const o=this._changesInElement.get(t),i=e.startOffset;if(o)for(const e of o)if("insert"==e.type&&i>=e.offset&&ii){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 o=this._operations[0];void 0===e&&(e=o.baseVersion);let i=t-1;for(const[t,o]of this._gaps)e>t&&et&&ithis.lastOperation.baseVersion)return[];let n=this._baseVersionToOperationIndex.get(e);void 0===n&&(n=0);let s=this._baseVersionToOperationIndex.get(i);return void 0===s&&(s=this._operations.length-1),this._operations.slice(n,s+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}}class Ca extends Ms{rootName;_document;_isAttached=!0;_isLoaded=!0;constructor(e,t,o="main"){super(t),this._document=e,this.rootName=o}get document(){return this._document}isAttached(){return this._isAttached}toJSON(){return this.rootName}}Ca.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 Aa="$graveyard";class xa extends(xe()){model;history;selection;roots;differ;isReadOnly;_postFixers;_hasSelectionChangedFromTheLastChangeBlock;constructor(e){super(),this.model=e,this.history=new va,this.selection=new Os(this),this.roots=new eo({idProperty:"rootName"}),this.differ=new ba(e.markers),this.isReadOnly=!1,this._postFixers=new Set,this._hasSelectionChangedFromTheLastChangeBlock=!1,this.createRoot("$root",Aa),this.listenTo(e,"applyOperation",((e,t)=>{const o=t[0];o.isDocumentOperation&&this.differ.bufferOperation(o)}),{priority:"high"}),this.listenTo(e,"applyOperation",((e,t)=>{const o=t[0];o.isDocumentOperation&&this.history.addOperation(o)}),{priority:"low"}),this.listenTo(this.selection,"change",(()=>{this._hasSelectionChangedFromTheLastChangeBlock=!0})),this.listenTo(e.markers,"update",((e,t,o,i,n)=>{const s={...t.getData(),range:i};this.differ.bufferMarkerChange(t.name,n,s),null===o&&t.on("change",((e,o)=>{const i=t.getData();this.differ.bufferMarkerChange(t.name,{...i,range:o},i)}))})),this.registerPostFixer((e=>{let t=!1;for(const o of this.roots)o.isAttached()||o.isEmpty||(e.remove(e.createRangeIn(o)),t=!0);for(const o of this.model.markers)o.getRange().root.isAttached()||(e.removeMarker(o),t=!0);return t}))}get version(){return this.history.version}set version(e){this.history.version=e}get graveyard(){return this.getRoot(Aa)}createRoot(e="$root",t="main"){if(this.roots.get(t))throw new fe("model-document-createroot-name-exists",this,{name:t});const o=new Ca(this,e,t);return this.roots.add(o),o}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=Go(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,o=t.schema,i=t.createPositionFromPath(e,[0]);return o.getNearestSelectionRange(i)||t.createRange(i)}_validateSelectionRange(e){return e.start.isValid()&&e.end.isValid()&&Ea(e.start)&&Ea(e.end)}_callPostFixers(e){let t=!1;do{for(const o of this._postFixers)if(this.selection.refresh(),t=o(e),t)break}while(t)}}function Ea(e){const t=e.textNode;if(t){const o=t.data,i=e.offset-t.startOffset;return!ho(o,i)&&!mo(o,i)}return!0}class Ta extends(xe()){_markers=new Map;[Symbol.iterator](){return this._markers.values()}has(e){const t=e instanceof Pa?e.name:e;return this._markers.has(t)}get(e){return this._markers.get(e)||null}_set(e,t,o=!1,i=!1){const n=e instanceof Pa?e.name:e;if(n.includes(","))throw new fe("markercollection-incorrect-marker-name",this);const s=this._markers.get(n);if(s){const e=s.getData(),r=s.getRange();let a=!1;return r.isEqual(t)||(s._attachLiveRange(Ts.fromRange(t)),a=!0),o!=s.managedUsingOperations&&(s._managedUsingOperations=o,a=!0),"boolean"==typeof i&&i!=s.affectsData&&(s._affectsData=i,a=!0),a&&this.fire(`update:${n}`,s,r,t,e),s}const r=Ts.fromRange(t),a=new Pa(n,r,o,i);return this._markers.set(n,a),this.fire(`update:${n}`,a,null,t,{...a.getData(),range:null}),a}_remove(e){const t=e instanceof Pa?e.name:e,o=this._markers.get(t);return!!o&&(this._markers.delete(t),this.fire(`update:${t}`,o,o.getRange(),null,o.getData()),this._destroyMarker(o),!0)}_refresh(e){const t=e instanceof Pa?e.name:e,o=this._markers.get(t);if(!o)throw new fe("markercollection-refresh-marker-not-exists",this);const i=o.getRange();this.fire(`update:${t}`,o,i,i,o.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=null,this.stopListening()}*getMarkersGroup(e){for(const t of this._markers.values())t.name.startsWith(e+":")&&(yield t)}_destroyMarker(e){e.stopListening(),e._detachLiveRange()}}class Pa extends(xe(ts)){name;_managedUsingOperations;_affectsData;_liveRange;constructor(e,t,o,i){super(),this.name=e,this._liveRange=this._attachLiveRange(t),this._managedUsingOperations=o,this._affectsData=i}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}}Pa.prototype.is=function(e){return"marker"===e||"model:marker"===e};class Sa extends Fr{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(){Nr(us._createFromPositionAndShift(this.sourcePosition,this.howMany))}static get className(){return"DetachOperation"}}class Ia extends ts{markers=new Map;_children=new Fs;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 o of e)t=t.getChildAtOffset(o);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(e){const t=[];for(const o of e)o.name?t.push(Ms.fromJSON(o)):t.push(Is.fromJSON(o));return new Ia(t)}_appendChild(e){this._insertChild(this.childCount,e)}_insertChild(e,t){const o=function(e){if("string"==typeof e)return[new Is(e)];Ue(e)||(e=[e]);return Array.from(e).map((e=>"string"==typeof e?new Is(e):e instanceof os?new Is(e.data,e.getAttributes()):e))}(t);for(const e of o)null!==e.parent&&e._remove(),e.parent=this;this._children._insertNodes(e,o)}_removeChildren(e,t=1){const o=this._children._removeNodes(e,t);for(const e of o)e.parent=null;return o}_removeChildrenArray(e){this._children._removeNodesArray(e);for(const t of e)t.parent=null}}Ia.prototype.is=function(e){return"documentFragment"===e||"model:documentFragment"===e};class Ra{model;batch;constructor(e,t){this.model=e,this.batch=t}createText(e,t){return new Is(e,t)}createElement(e,t){return new Ms(e,t)}createDocumentFragment(){return new Ia}cloneElement(e,t=!0){return e._clone(t)}insert(e,t,o=0){if(this._assertWriterUsedCorrectly(),e instanceof Is&&""==e.data)return;const i=ss._createAt(t,o);if(e.parent){if(Ma(e.root,i.root))return void this.move(us._createOn(e),i);if(e.root.document)throw new fe("model-writer-insert-forbidden-move",this);this.remove(e)}const n=i.root.document?i.root.document.version:null,s=e instanceof Ia?e._removeChildren(0,e.childCount):e,r=new Hr(i,s,n);if(e instanceof Is&&(r.shouldReceiveAttributes=!0),this.batch.addOperation(r),this.model.applyOperation(r),e instanceof Ia)for(const[t,o]of e.markers){const e=ss._createAt(o.root,0),n={range:new us(o.start._getCombined(e,i),o.end._getCombined(e,i)),usingOperation:!0,affectsData:!0};this.model.markers.has(t)?this.updateMarker(t,n):this.addMarker(t,n)}}insertText(e,t,o,i){t instanceof Ia||t instanceof Ms||t instanceof ss?this.insert(this.createText(e),t,o):this.insert(this.createText(e,t),o,i)}insertElement(e,t,o,i){t instanceof Ia||t instanceof Ms||t instanceof ss?this.insert(this.createElement(e),t,o):this.insert(this.createElement(e,t),o,i)}append(e,t){this.insert(e,t,"end")}appendText(e,t,o){t instanceof Ia||t instanceof Ms?this.insert(this.createText(e),t,"end"):this.insert(this.createText(e,t),o,"end")}appendElement(e,t,o){t instanceof Ia||t instanceof Ms?this.insert(this.createElement(e),t,"end"):this.insert(this.createElement(e,t),o,"end")}setAttribute(e,t,o){if(this._assertWriterUsedCorrectly(),o instanceof us){const i=o.getMinimalFlatRanges();for(const o of i)Oa(this,e,t,o)}else Va(this,e,t,o)}setAttributes(e,t){for(const[o,i]of ao(e))this.setAttribute(o,i,t)}removeAttribute(e,t){if(this._assertWriterUsedCorrectly(),t instanceof us){const o=t.getMinimalFlatRanges();for(const t of o)Oa(this,e,null,t)}else Va(this,e,null,t)}clearAttributes(e){this._assertWriterUsedCorrectly();const t=e=>{for(const t of e.getAttributeKeys())this.removeAttribute(t,e)};if(e instanceof us)for(const o of e.getItems())t(o);else t(e)}move(e,t,o){if(this._assertWriterUsedCorrectly(),!(e instanceof us))throw new fe("writer-move-invalid-range",this);if(!e.isFlat)throw new fe("writer-move-range-not-flat",this);const i=ss._createAt(t,o);if(i.isEqual(e.start))return;if(this._addOperationForAffectedMarkers("move",e),!Ma(e.root,i.root))throw new fe("writer-move-different-document",this);const n=e.root.document?e.root.document.version:null,s=new $r(e.start,e.end.offset-e.start.offset,i,n);this.batch.addOperation(s),this.model.applyOperation(s)}remove(e){this._assertWriterUsedCorrectly();const t=(e instanceof us?e:us._createOn(e)).getMinimalFlatRanges().reverse();for(const e of t)this._addOperationForAffectedMarkers("move",e),Fa(e.start,e.end.offset-e.start.offset,this.batch,this.model)}merge(e){this._assertWriterUsedCorrectly();const t=e.nodeBefore,o=e.nodeAfter;if(this._addOperationForAffectedMarkers("merge",e),!(t instanceof Ms))throw new fe("writer-merge-no-element-before",this);if(!(o instanceof Ms))throw new fe("writer-merge-no-element-after",this);e.root.document?this._merge(e):this._mergeDetached(e)}createPositionFromPath(e,t,o){return this.model.createPositionFromPath(e,t,o)}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,o=e.nodeAfter;this.move(us._createIn(o),ss._createAt(t,"end")),this.remove(o)}_merge(e){const t=ss._createAt(e.nodeBefore,"end"),o=ss._createAt(e.nodeAfter,0),i=e.root.document.graveyard,n=new ss(i,[0]),s=e.root.document.version,r=new Ur(o,e.nodeAfter.maxOffset,t,n,s);this.batch.addOperation(r),this.model.applyOperation(r)}rename(e,t){if(this._assertWriterUsedCorrectly(),!(e instanceof Ms))throw new fe("writer-rename-not-element-instance",this);const o=e.root.document?e.root.document.version:null,i=new Zr(ss._createBefore(e),e.name,t,o);this.batch.addOperation(i),this.model.applyOperation(i)}split(e,t){this._assertWriterUsedCorrectly();let o,i,n=e.parent;if(!n.parent)throw new fe("writer-split-element-no-parent",this);if(t||(t=n.parent),!e.parent.getAncestors({includeSelf:!0}).includes(t))throw new fe("writer-split-invalid-limit-element",this);do{const t=n.root.document?n.root.document.version:null,s=n.maxOffset-e.offset,r=Wr.getInsertionPosition(e),a=new Wr(e,s,r,null,t);this.batch.addOperation(a),this.model.applyOperation(a),o||i||(o=n,i=e.parent.nextSibling),n=(e=this.createPositionAfter(e.parent)).parent}while(n!==t);return{position:e,range:new us(ss._createAt(o,"end"),ss._createAt(i,0))}}wrap(e,t){if(this._assertWriterUsedCorrectly(),!e.isFlat)throw new fe("writer-wrap-range-not-flat",this);const o=t instanceof Ms?t:new Ms(t);if(o.childCount>0)throw new fe("writer-wrap-element-not-empty",this);if(null!==o.parent)throw new fe("writer-wrap-element-attached",this);this.insert(o,e.start);const i=new us(e.start.getShiftedBy(1),e.end.getShiftedBy(1));this.move(i,ss._createAt(o,0))}unwrap(e){if(this._assertWriterUsedCorrectly(),null===e.parent)throw new fe("writer-unwrap-element-no-parent",this);this.move(us._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 o=t.usingOperation,i=t.range,n=void 0!==t.affectsData&&t.affectsData;if(this.model.markers.has(e))throw new fe("writer-addmarker-marker-exists",this);if(!i)throw new fe("writer-addmarker-no-range",this);return o?(Da(this,e,null,i,n),this.model.markers.get(e)):this.model.markers._set(e,i,o,n)}updateMarker(e,t){this._assertWriterUsedCorrectly();const o="string"==typeof e?e:e.name,i=this.model.markers.get(o);if(!i)throw new fe("writer-updatemarker-marker-not-exists",this);if(!t)return be("writer-updatemarker-reconvert-using-editingcontroller",{markerName:o}),void this.model.markers._refresh(i);const n="boolean"==typeof t.usingOperation,s="boolean"==typeof t.affectsData,r=s?t.affectsData:i.affectsData;if(!n&&!t.range&&!s)throw new fe("writer-updatemarker-wrong-options",this);const a=i.getRange(),l=t.range?t.range:a;n&&t.usingOperation!==i.managedUsingOperations?t.usingOperation?Da(this,o,null,l,r):(Da(this,o,a,null,r),this.model.markers._set(o,l,void 0,r)):i.managedUsingOperations?Da(this,o,a,l,r):this.model.markers._set(o,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 o=this.model.markers.get(t);if(!o.managedUsingOperations)return void this.model.markers._remove(t);Da(this,t,o.getRange(),null,o.affectsData)}addRoot(e,t="$root"){this._assertWriterUsedCorrectly();const o=this.model.document.getRoot(e);if(o&&o.isAttached())throw new fe("writer-addroot-root-exists",this);const i=this.model.document,n=new Yr(e,t,!0,i,i.version);return this.batch.addOperation(n),this.model.applyOperation(n),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 o=this.model.document,i=new Yr(t.rootName,t.name,!1,o,o.version);this.batch.addOperation(i),this.model.applyOperation(i)}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,o]of ao(e))this._setSelectionAttribute(t,o)}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 o=this.model.document.selection;if(o.isCollapsed&&o.anchor.parent.isEmpty){const i=Os._getStoreAttributeKey(e);this.setAttribute(i,t,o.anchor.parent)}o._setAttribute(e,t)}_removeSelectionAttribute(e){const t=this.model.document.selection;if(t.isCollapsed&&t.anchor.parent.isEmpty){const o=Os._getStoreAttributeKey(e);this.removeAttribute(o,t.anchor.parent)}t._removeAttribute(e)}_assertWriterUsedCorrectly(){if(this.model._currentWriter!==this)throw new fe("writer-incorrect-use",this)}_addOperationForAffectedMarkers(e,t){for(const o of this.model.markers){if(!o.managedUsingOperations)continue;const i=o.getRange();let n=!1;if("move"===e){const e=t;n=e.containsPosition(i.start)||e.start.isEqual(i.start)||e.containsPosition(i.end)||e.end.isEqual(i.end)}else{const e=t,o=e.nodeBefore,s=e.nodeAfter,r=i.start.parent==o&&i.start.isAtEnd,a=i.end.parent==s&&0==i.end.offset,l=i.end.nodeAfter==s,c=i.start.nodeAfter==s;n=r||a||l||c}n&&this.updateMarker(o.name,{range:i})}}}function Oa(e,t,o,i){const n=e.model,s=n.document;let r,a,l,c=i.start;for(const e of i.getWalker({shallow:!0}))l=e.item.getAttribute(t),r&&a!=l&&(a!=o&&d(),c=r),r=e.nextPosition,a=l;function d(){const i=new us(c,r),l=i.root.document?s.version:null,d=new Gr(i,t,a,o,l);e.batch.addOperation(d),n.applyOperation(d)}r instanceof ss&&r!=c&&a!=o&&d()}function Va(e,t,o,i){const n=e.model,s=n.document,r=i.getAttribute(t);let a,l;if(r!=o){if(i.root===i){const e=i.document?s.version:null;l=new Qr(i,t,r,o,e)}else{a=new us(ss._createBefore(i),e.createPositionAfter(i));const n=a.root.document?s.version:null;l=new Gr(a,t,r,o,n)}e.batch.addOperation(l),n.applyOperation(l)}}function Da(e,t,o,i,n){const s=e.model,r=s.document,a=new Kr(t,o,i,s.markers,!!n,r.version);e.batch.addOperation(a),s.applyOperation(a)}function Fa(e,t,o,i){let n;if(e.root.document){const o=i.document,s=new ss(o.graveyard,[0]);n=new $r(e,t,s,o.version)}else n=new Sa(e,t);o.addOperation(n),i.applyOperation(n)}function Ma(e,t){return e===t||e instanceof Ca&&t instanceof Ca}function Na(e){e.document.registerPostFixer((t=>function(e,t){const o=t.document.selection,i=t.schema,n=[];let s=!1;for(const e of o.getRanges()){const t=Ba(e,i);t&&!t.isEqual(e)?(n.push(t),s=!0):n.push(e)}s&&e.setSelection(function(e){const t=[...e],o=new Set;let i=1;for(;i!o.has(t)))}(n),{backward:o.isBackward});return!1}(t,e)))}function Ba(e,t){return e.isCollapsed?function(e,t){const o=e.start,i=t.getNearestSelectionRange(o);if(!i){const e=o.getAncestors().reverse().find((e=>t.isObject(e)));return e?us._createOn(e):null}if(!i.isCollapsed)return i;const n=i.start;if(o.isEqual(n))return null;return new us(n)}(e,t):function(e,t){const{start:o,end:i}=e,n=t.checkChild(o,"$text"),s=t.checkChild(i,"$text"),r=t.getLimitElement(o),a=t.getLimitElement(i);if(r===a){if(n&&s)return null;if(function(e,t,o){const i=e.nodeAfter&&!o.isLimit(e.nodeAfter)||o.checkChild(e,"$text"),n=t.nodeBefore&&!o.isLimit(t.nodeBefore)||o.checkChild(t,"$text");return i||n}(o,i,t)){const e=o.nodeAfter&&t.isSelectable(o.nodeAfter)?null:t.getNearestSelectionRange(o,"forward"),n=i.nodeBefore&&t.isSelectable(i.nodeBefore)?null:t.getNearestSelectionRange(i,"backward"),s=e?e.start:o,r=n?n.end:i;return new us(s,r)}}const l=r&&!r.is("rootElement"),c=a&&!a.is("rootElement");if(l||c){const e=o.nodeAfter&&i.nodeBefore&&o.nodeAfter.parent===i.nodeBefore.parent,n=l&&(!e||!za(o.nodeAfter,t)),s=c&&(!e||!za(i.nodeBefore,t));let d=o,u=i;return n&&(d=ss._createBefore(La(r,t))),s&&(u=ss._createAfter(La(a,t))),new us(d,u)}return null}(e,t)}function La(e,t){let o=e,i=o;for(;t.isLimit(i)&&i.parent;)o=i,i=i.parent;return o}function za(e,t){return e&&t.isSelectable(e)}function ja(e,t,o={}){if(t.isCollapsed)return;const i=t.getFirstRange();if("$graveyard"==i.root.rootName)return;const n=e.schema;e.change((e=>{if(!o.doNotResetEntireContent&&function(e,t){const o=e.getLimitElement(t);if(!t.containsEntireContent(o))return!1;const i=t.getFirstRange();if(i.start.parent==i.end.parent)return!1;return e.checkChild(o,"paragraph")}(n,t))return void function(e,t){const o=e.model.schema.getLimitElement(t);e.remove(e.createRangeIn(o)),Wa(e,e.createPositionAt(o,0),t)}(e,t);const s={};if(!o.doNotAutoparagraph){const e=t.getSelectedElement();e&&Object.assign(s,n.getAttributesWithProperty(e,"copyOnReplace",!0))}let r,a;o.doNotFixSelection?(r=ma.fromPosition(i.start,"toPrevious"),a=ma.fromPosition(i.end,"toNext")):[r,a]=function(e){const t=e.root.document.model,o=e.start;let i=e.end;if(t.hasContent(e,{ignoreMarkers:!0})){const o=function(e){const t=e.parent,o=t.root.document.model.schema,i=t.getAncestors({parentFirst:!0,includeSelf:!0});for(const e of i){if(o.isLimit(e))return null;if(o.isBlock(e))return e}}(i);if(o&&i.isTouching(t.createPositionAt(o,0))){const o=t.createSelection(e);t.modifySelection(o,{direction:"backward"});const n=o.getLastPosition(),s=t.createRange(n,i);t.hasContent(s,{ignoreMarkers:!0})||(i=n)}}return[ma.fromPosition(o,"toPrevious"),ma.fromPosition(i,"toNext")]}(i),r.isTouching(a)||e.remove(e.createRange(r,a)),o.leaveUnmerged||(!function(e,t,o){const i=e.model;if(!Ha(e.model.schema,t,o))return;const[n,s]=function(e,t){const o=e.getAncestors(),i=t.getAncestors();let n=0;for(;o[n]&&o[n]==i[n];)n++;return[o[n],i[n]]}(t,o);if(!n||!s)return;!i.hasContent(n,{ignoreMarkers:!0})&&i.hasContent(s,{ignoreMarkers:!0})?$a(e,t,o,n.parent):qa(e,t,o,n.parent)}(e,r,a),n.removeDisallowedAttributes(r.parent.getChildren(),e)),Ua(e,t,r),!o.doNotAutoparagraph&&function(e,t){const o=e.checkChild(t,"$text"),i=e.checkChild(t,"paragraph");return!o&&i}(n,r)&&Wa(e,r,t,s),r.detach(),a.detach()}))}function qa(e,t,o,i){const n=t.parent,s=o.parent;if(n!=i&&s!=i){for(t=e.createPositionAfter(n),(o=e.createPositionBefore(s)).isEqual(t)||e.insert(s,t),e.merge(t);o.parent.isEmpty;){const t=o.parent;o=e.createPositionBefore(t),e.remove(t)}Ha(e.model.schema,t,o)&&qa(e,t,o,i)}}function $a(e,t,o,i){const n=t.parent,s=o.parent;if(n!=i&&s!=i){for(t=e.createPositionAfter(n),(o=e.createPositionBefore(s)).isEqual(t)||e.insert(n,o);t.parent.isEmpty;){const o=t.parent;t=e.createPositionBefore(o),e.remove(o)}o=e.createPositionBefore(s),function(e,t){const o=t.nodeBefore,i=t.nodeAfter;o.name!=i.name&&e.rename(o,i.name);e.clearAttributes(o),e.setAttributes(Object.fromEntries(i.getAttributes()),o),e.merge(t)}(e,o),Ha(e.model.schema,t,o)&&$a(e,t,o,i)}}function Ha(e,t,o){const i=t.parent,n=o.parent;return i!=n&&(!e.isLimit(i)&&!e.isLimit(n)&&function(e,t,o){const i=new us(e,t);for(const e of i.getWalker())if(o.isLimit(e.item))return!1;return!0}(t,o,e))}function Wa(e,t,o,i={}){const n=e.createElement("paragraph");e.model.schema.setAllowedAttributes(n,i,e),e.insert(n,t),Ua(e,o,e.createPositionAt(n,0))}function Ua(e,t,o){t instanceof Os?e.setSelection(o):t.setTo(o)}function Ka(e,t){const o=[];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=>{o.push(e.start.parent),t.remove(e)})),o.forEach((e=>{let o=e;for(;o.parent&&o.isEmpty;){const e=t.createRangeOn(o);o=o.parent,t.remove(e)}}))}class Ga{model;writer;position;canMergeWith;schema;_documentFragment;_documentFragmentPosition;_firstNode=null;_lastNode=null;_lastAutoParagraph=null;_filterAttributesAndChildrenOf=[];_affectedStart=null;_affectedEnd=null;_nodeToSelect=null;constructor(e,t,o){this.model=e,this.writer=t,this.position=o,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 o=[],i=[],n=this.writer.createRangeIn(e).getWalker({ignoreElementEnd:!0});for(const{item:e}of n){const s=e.parent;this.schema.checkChild(s,e)||(e.is("element")&&!this.schema.isObject(e)?(i.push(e),t.push(s)):o.push(e),n.jumpTo(this.writer.createPositionAfter(e)))}for(const e of i)this.writer.unwrap(e);for(const e of o)this.writer.remove(e)}}_updateLastNodeFromAutoParagraph(e){const t=this.writer.createPositionAfter(this._lastNode),o=this.writer.createPositionAfter(e);if(o.isAfter(t)){if(this._lastNode=e,this.position.parent!=e||!this.position.isAtEnd)throw new fe("insertcontent-invalid-insertion-position",this);this.position=o,this._setAffectedBoundaries(this.position)}}getSelectionRange(){return this._nodeToSelect?us._createOn(this._nodeToSelect):this.model.schema.getNearestSelectionRange(this.position)}getAffectedRange(){return this._affectedStart?new us(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=ma.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=ma.fromPosition(e,"toPrevious")),this._affectedEnd&&!this._affectedEnd.isBefore(e)||(this._affectedEnd&&this._affectedEnd.detach(),this._affectedEnd=ma.fromPosition(e,"toNext"))}_mergeOnLeft(){const e=this._firstNode;if(!(e instanceof Ms))return;if(!this._canMergeLeft(e))return;const t=ma._createBefore(e);t.stickiness="toNext";const o=ma.fromPosition(this.position,"toNext");this._affectedStart.isEqual(t)&&(this._affectedStart.detach(),this._affectedStart=ma._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=ma._createAt(t.nodeBefore,"end","toNext")),this.position=o.toPosition(),o.detach(),this._filterAttributesAndChildrenOf.push(this.position.parent),t.detach()}_mergeOnRight(){const e=this._lastNode;if(!(e instanceof Ms))return;if(!this._canMergeRight(e))return;const t=ma._createAfter(e);if(t.stickiness="toNext",!this.position.isEqual(t))throw new fe("insertcontent-invalid-insertion-position",this);this.position=ss._createAt(t.nodeBefore,"end");const o=ma.fromPosition(this.position,"toPrevious");this._affectedEnd.isEqual(t)&&(this._affectedEnd.detach(),this._affectedEnd=ma._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=ma._createAt(t.nodeBefore,0,"toPrevious")),this.position=o.toPosition(),o.detach(),this._filterAttributesAndChildrenOf.push(this.position.parent),t.detach()}_canMergeLeft(e){const t=e.previousSibling;return t instanceof Ms&&this.canMergeWith.has(t)&&this.model.schema.checkMerge(t,e)}_canMergeRight(e){const t=e.nextSibling;return t instanceof Ms&&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 o=this.schema.createContext(e);return this.schema.checkChild(o,t)||this.schema.checkChild(o,"paragraph")&&this.schema.checkChild(o.push("paragraph"),t)?e:this.schema.isLimit(e)?null:this._getAllowedIn(e.parent,t)}}function Ja(e,t,o,i={}){if(!e.schema.isObject(t))throw new fe("insertobject-element-not-an-object",e,{object:t});const n=o||e.document.selection;let s=n;i.findOptimalPosition&&e.schema.isBlock(t)&&(s=e.createSelection(e.schema.findOptimalInsertionRange(n,i.findOptimalPosition)));const r=to(n.getSelectedBlocks()),a={};return r&&Object.assign(a,e.schema.getAttributesWithProperty(r,"copyOnReplace",!0)),e.change((o=>{s.isCollapsed||e.deleteContent(s,{doNotAutoparagraph:!0});let n=t;const r=s.anchor.parent,l=e.schema.createContext(r);!e.schema.checkChild(l,t)&&e.schema.checkChild(l,"paragraph")&&e.schema.checkChild(l.push("paragraph"),t)&&(n=o.createElement("paragraph"),o.insert(t,n)),e.schema.setAllowedAttributes(n,a,o);const c=e.insertContent(n,s);return c.isCollapsed||i.setSelection&&function(e,t,o,i){const n=e.model;if("on"==o)return void e.setSelection(t,"on");if("after"!=o)throw new fe("insertobject-invalid-place-parameter-value",n);let s=t.nextSibling;if(n.schema.isInline(t))return void e.setSelection(t,"after");const r=s&&n.schema.checkChild(s,"$text");!r&&n.schema.checkChild(t.parent,"paragraph")&&(s=e.createElement("paragraph"),n.schema.setAllowedAttributes(s,i,e),n.insertContent(s,e.createPositionAfter(t)));s&&e.setSelection(s,0)}(o,t,i.setSelection,a),c}))}function Za(e,t){const{isForward:o,walker:i,unit:n,schema:s,treatEmojiAsSingleUnit:r}=e,{type:a,item:l,nextPosition:c}=t;if("text"==a)return"word"===e.unit?function(e,t){let o=e.position.textNode;o||(o=t?e.position.nodeAfter:e.position.nodeBefore);for(;o&&o.is("$text");){const i=e.position.offset-o.startOffset;if(Xa(o,i,t))o=t?e.position.nodeAfter:e.position.nodeBefore;else{if(Ya(o.data,i,t))break;e.next()}}return e.position}(i,o):function(e,t,o){const i=e.position.textNode;if(i){const n=i.data;let s=e.position.offset-i.startOffset;for(;ho(n,s)||"character"==t&&mo(n,s)||o&&po(n,s);)e.next(),s=e.position.offset-i.startOffset}return e.position}(i,n,r);if(a==(o?"elementStart":"elementEnd")){if(s.isSelectable(l))return ss._createAt(l,o?"after":"before");if(s.checkChild(c,"$text"))return c}else{if(s.isLimit(l))return void i.skip((()=>!0));if(s.checkChild(c,"$text"))return c}}function Qa(e,t){const o=e.root,i=ss._createAt(o,t?"end":0);return t?new us(e,i):new us(i,e)}function Ya(e,t,o){const i=t+(o?0:-1);return' ,.?!:;"-()'.includes(e.charAt(i))}function Xa(e,t,o){return t===(o?e.offsetSize:0)}class el extends(Be()){markers;document;schema;_config;_pendingChanges;_currentWriter;constructor(e){super(),this.markers=new Ta,this.document=new xa(this),this.schema=new mr,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("$container",{allowIn:["$root","$container"]}),this.schema.register("$block",{allowIn:["$root","$container"],isBlock:!0}),this.schema.register("$blockObject",{allowWhere:"$block",isBlock:!0,isObject:!0}),this.schema.register("$inlineObject",{allowWhere:"$text",allowAttributesOf:"$text",isInline:!0,isObject:!0}),this.schema.register("$text",{allowIn:"$block",isInline:!0,isContent:!0}),this.schema.register("$clipboardHolder",{allowContentOf:"$root",allowChildren:"$text",isLimit:!0}),this.schema.register("$documentFragment",{allowContentOf:"$root",allowChildren:"$text",isLimit:!0}),this.schema.register("$marker"),this.schema.addChildCheck((()=>!0),"$marker"),Na(this),this.document.registerPostFixer(or),this.on("insertContent",((e,[t,o])=>{e.return=function(e,t,o){return e.change((i=>{const n=o||e.document.selection;n.isCollapsed||e.deleteContent(n,{doNotAutoparagraph:!0});const s=new Ga(e,i,n.anchor),r=[];let a;if(t.is("documentFragment")){if(t.markers.size){const e=[];for(const[o,i]of t.markers){const{start:t,end:n}=i,s=t.isEqual(n);e.push({position:t,name:o,isCollapsed:s},{position:n,name:o,isCollapsed:s})}e.sort((({position:e},{position:t})=>e.isBefore(t)?1:-1));for(const{position:o,name:n,isCollapsed:s}of e){let e=null,a=null;const l=o.parent===t&&o.isAtStart,c=o.parent===t&&o.isAtEnd;l||c?s&&(a=l?"start":"end"):(e=i.createElement("$marker"),i.insert(e,o)),r.push({name:n,element:e,collapsed:a})}}a=t.getChildren()}else a=[t];s.handleNodes(a);let l=s.getSelectionRange();if(t.is("documentFragment")&&r.length){const e=l?Ts.fromRange(l):null,t={};for(let e=r.length-1;e>=0;e--){const{name:o,element:n,collapsed:a}=r[e],l=!t[o];if(l&&(t[o]=[]),n){const e=i.createPositionAt(n,"before");t[o].push(e),i.remove(n)}else{const e=s.getAffectedRange();if(!e){a&&t[o].push(s.position);continue}a?t[o].push(e[a]):t[o].push(l?e.start:e.end)}}for(const[e,[o,n]]of Object.entries(t))o&&n&&o.root===n.root&&o.root.document&&!i.model.markers.has(e)&&i.addMarker(e,{usingOperation:!0,affectsData:!0,range:new us(o,n)});e&&(l=e.toRange(),e.detach())}l&&(n instanceof Os?i.setSelection(l):n.setTo(l));const c=s.getAffectedRange()||e.createRange(n.anchor);return s.destroy(),c}))}(this,t,o)})),this.on("insertObject",((e,[t,o,i])=>{e.return=Ja(this,t,o,i)})),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 fa,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 fa):e instanceof fa||(e=new fa(e)):e=new fa,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,o,...i){const n=tl(t,o);return this.fire("insertContent",[e,n,o,...i])}insertObject(e,t,o,i,...n){const s=tl(t,o);return this.fire("insertObject",[e,s,i,i,...n])}deleteContent(e,t){ja(this,e,t)}modifySelection(e,t){!function(e,t,o={}){const i=e.schema,n="backward"!=o.direction,s=o.unit?o.unit:"character",r=!!o.treatEmojiAsSingleUnit,a=t.focus,l=new is({boundaries:Qa(a,n),singleCharacters:!0,direction:n?"forward":"backward"}),c={walker:l,schema:i,isForward:n,unit:s,treatEmojiAsSingleUnit:r};let d;for(;d=l.next();){if(d.done)return;const o=Za(c,d.value);if(o)return void(t instanceof Os?e.change((e=>{e.setSelectionFocus(o)})):t.setFocus(o))}}(this,e,t)}getSelectedContent(e){return function(e,t){return e.change((e=>{const o=e.createDocumentFragment(),i=t.getFirstRange();if(!i||i.isCollapsed)return o;const n=i.start.root,s=i.start.getCommonPath(i.end),r=n.getNodeByPath(s);let a;a=i.start.parent==i.end.parent?i:e.createRange(e.createPositionAt(r,i.start.path[s.length]),e.createPositionAt(r,i.end.path[s.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(),o):e.append(e.cloneElement(t,!0),o);if(a!=i){const t=i._getTransformedByMove(a.start,e.createPositionAt(o,0),l)[0],n=e.createRange(e.createPositionAt(o,0),t.start);Ka(e.createRange(t.end,e.createPositionAt(o,"end")),e),Ka(n,e)}return o}))}(this,e)}hasContent(e,t={}){let o;o=e.is("selection")?Array.from(e.getRanges()):e.is("range")?[e]:[us._createIn(e)];for(const e of o)if(this._rangeHasContent(e,t))return!0;return!1}_rangeHasContent(e,t){if(e.isCollapsed)return!1;const{ignoreWhitespaces:o=!1,ignoreMarkers:i=!1}=t;if(!i)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(!o)return!0;if(-1!==t.data.search(/\S/))return!0}return!1}canEditAt(e){const t=tl(e);return this.fire("canEditAt",[t])}createPositionFromPath(e,t,o){return new ss(e,t,o)}createPositionAt(e,t){return ss._createAt(e,t)}createPositionAfter(e){return ss._createAfter(e)}createPositionBefore(e){return ss._createBefore(e)}createRange(e,t){return new us(e,t)}createRangeIn(e){return us._createIn(e)}createRangeOn(e){return us._createOn(e)}createSelection(...e){return new _s(...e)}createBatch(e){return new fa(e)}createOperationFromJSON(e){return ea.fromJSON(e,this.document)}destroy(){this.document.destroy(),this.stopListening()}_runPendingChanges(){const e=[];this.fire("_beforeChanges");try{for(;this._pendingChanges.length;){const t=this._pendingChanges[0].batch;this._currentWriter=new Ra(this,t);const o=this._pendingChanges[0].callback(this._currentWriter);e.push(o),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 tl(e,t){if(e)return e instanceof _s||e instanceof Os?e:e instanceof ys?t||0===t?new _s(e,t):e.is("rootElement")?new _s(e,"in"):new _s(e,"on"):new _s(e)}class ol extends jn{domEventType="click";onDomEvent(e){this.fire(e.type,e)}}class il extends jn{domEventType=["mousedown","mouseup","mouseover","mouseout"];onDomEvent(e){this.fire(e.type,e)}}class nl extends jn{domEventType=["touchstart","touchend","touchmove"];onDomEvent(e){this.fire(e.type,e)}}class sl extends jn{domEventType=["pointerdown","pointerup","pointermove"];onDomEvent(e){this.fire(e.type,e)}}class rl{document;constructor(e){this.document=e}createDocumentFragment(e){return new tn(this.document,e)}createElement(e,t,o){return new _i(this.document,e,t,o)}createText(e){return new si(this.document,e)}clone(e,t=!1){return e._clone(t)}appendChild(e,t){return t._appendChild(e)}insertChild(e,t,o){return o._insertChild(e,t)}removeChildren(e,t,o){return o._removeChildren(e,t)}remove(e){const t=e.parent;return t?this.removeChildren(t.getChildIndex(e),1,t):[]}replace(e,t){const o=e.parent;if(o){const i=o.getChildIndex(e);return this.removeChildren(i,1,o),this.insertChild(i,t,o),!0}return!1}unwrapElement(e){const t=e.parent;if(t){const o=t.getChildIndex(e);this.remove(e),this.insertChild(o,e.getChildren(),t)}}rename(e,t){const o=new _i(this.document,e,t.getAttributes(),t.getChildren());return this.replace(t,o)?o:null}setAttribute(e,t,o){o._setAttribute(e,t)}removeAttribute(e,t){t._removeAttribute(e)}addClass(e,t){t._addClass(e)}removeClass(e,t){t._removeClass(e)}setStyle(e,t,o){a(e)&&void 0===o?t._setStyle(e):o._setStyle(e,t)}removeStyle(e,t){t._removeStyle(e)}setCustomProperty(e,t,o){o._setCustomProperty(e,t)}removeCustomProperty(e,t){return t._removeCustomProperty(e)}createPositionAt(e,t){return Si._createAt(e,t)}createPositionAfter(e){return Si._createAfter(e)}createPositionBefore(e){return Si._createBefore(e)}createRange(e,t){return new Ii(e,t)}createRangeOn(e){return Ii._createOn(e)}createRangeIn(e){return Ii._createIn(e)}createSelection(...e){return new Oi(...e)}}const al=/^#([0-9a-f]{3,4}|[0-9a-f]{6}|[0-9a-f]{8})$/i,ll=/^rgb\([ ]?([0-9]{1,3}[ %]?,[ ]?){2,3}[0-9]{1,3}[ %]?\)$/i,cl=/^rgba\([ ]?([0-9]{1,3}[ %]?,[ ]?){3}(1|[0-9]+%|[0]?\.?[0-9]+)\)$/i,dl=/^hsl\([ ]?([0-9]{1,3}[ %]?[,]?[ ]*){3}(1|[0-9]+%|[0]?\.?[0-9]+)?\)$/i,ul=/^hsla\([ ]?([0-9]{1,3}[ %]?,[ ]?){2,3}(1|[0-9]+%|[0]?\.?[0-9]+)\)$/i,hl=/\w+\((?:[^()]|\([^()]*\))*\)|\S+/gi,ml=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 gl(e){return e.startsWith("#")?al.test(e):e.startsWith("rgb")?ll.test(e)||cl.test(e):e.startsWith("hsl")?dl.test(e)||ul.test(e):ml.has(e.toLowerCase())}const pl=["none","hidden","dotted","dashed","solid","double","groove","ridge","inset","outset"];function fl(e){return pl.includes(e)}const bl=/^([+-]?[0-9]*([.][0-9]+)?(px|cm|mm|in|pc|pt|ch|em|ex|rem|vh|vw|vmin|vmax)|0)$/;function wl(e){return bl.test(e)}const yl=/^[+-]?[0-9]*([.][0-9]+)?%$/;function _l(e){return yl.test(e)}const kl=["auto","cover","contain"];const vl=["repeat-x","repeat-y","repeat","space","round","no-repeat"];const Cl=["center","top","bottom","left","right"];function Al(e){return Cl.includes(e)}const xl=["fixed","scroll","local"];function El(e){return xl.includes(e)}const Tl=["border-box","padding-box","content-box"];function Pl(e){return Tl.includes(e)}const Sl=["border-box","padding-box","content-box","text"];function Il(e){return Sl.includes(e)}function Rl(e=""){if(""===e)return{top:void 0,right:void 0,bottom:void 0,left:void 0};const t=Fl(e),o=t[0],i=t[2]||o,n=t[1]||o;return{top:o,bottom:i,right:n,left:t[3]||n}}function Ol(e){return t=>{const{top:o,right:i,bottom:n,left:s}=t,r=[];return[o,i,s,n].every((e=>!!e))?r.push([e,Vl(t)]):(o&&r.push([e+"-top",o]),i&&r.push([e+"-right",i]),n&&r.push([e+"-bottom",n]),s&&r.push([e+"-left",s])),r}}function Vl({top:e,right:t,bottom:o,left:i}){const n=[];return i!==t?n.push(e,t,o,i):o!==e?n.push(e,t,o):t!==e?n.push(e,t):n.push(e),n.join(" ")}function Dl(e){return t=>({path:e,value:Rl(t)})}function Fl(e){const t=e.trim().slice(0,1500).matchAll(hl);return Array.from(t).map((e=>e[0]))}const Ml={image:"none",repeat:"repeat",position:"0% 0%",size:"auto",origin:"padding-box",clip:"border-box",attachment:"scroll"},Nl=["linear-gradient","repeating-linear-gradient","radial-gradient","repeating-radial-gradient","conic-gradient","repeating-conic-gradient","url"];function Bl(e){e.setNormalizer("background-color",(e=>({path:"background.color",value:e})));for(const t in Ml)e.setNormalizer(`background-${t}`,Ll(`background.${t}`)),e.setReducer(`background-${t}`,zl(`background-${t}`));e.setNormalizer("background",(e=>{const t=function(e){return $l(e).map(jl).filter((e=>null!==e))}(e);t.length||t.push({...ql(),color:e});const o=function(e){const t={image:[],position:[],size:[],repeat:[],attachment:[],origin:[],clip:[]};for(const o of e)t.position.push(o.position.join(" ")),t.size.push(o.size.join(" ")),t.repeat.push(o.repeat.join(" ")),t.image.push(o.image),t.attachment.push(o.attachment),t.origin.push(o.origin),t.clip.push(o.clip);return e.at(-1)?.color&&(t.color=e.at(-1).color),t}(t);return{path:"background",value:o}})),e.setReducer("background",(e=>{const t=e,o=Object.keys(Ml).every((e=>{const o=t[e];return void 0!==o&&(!Array.isArray(o)||o.length>0)}));return o?function(e){const t=[],o=function(e){const t=function(e){let t=0;for(const o of Object.values(e))Array.isArray(o)&&o.length>t&&(t=o.length);return t}(e),o=Array.from({length:t},((t,o)=>{const i=ql();return e.image?.[o]&&(i.image=e.image[o]),e.position?.[o]&&(i.position=e.position[o].split(" ")),e.size?.[o]&&(i.size=e.size[o].split(" ")),e.repeat?.[o]&&(i.repeat=e.repeat[o].split(" ")),e.attachment?.[o]&&(i.attachment=e.attachment[o]),e.origin?.[o]&&(i.origin=e.origin[o]),e.clip?.[o]&&(i.clip=e.clip[o]),i}));return e.color&&(o.at(-1).color=e.color),o}(e).map((e=>function(e){const t=[];e.image&&e.image!==Ml.image&&t.push(e.image);const o=e.position.join(" "),i=!o||o===Ml.position;i||t.push(o);const n=e.size.join(" ");n&&n!==Ml.size&&(i&&t.push("0% 0%"),t.push("/",n));const s=e.repeat.join(" ");s&&s!==Ml.repeat&&t.push(s),e.attachment&&e.attachment!==Ml.attachment&&t.push(e.attachment);const r=e.origin===Ml.origin,a=e.clip===Ml.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 o&&t.push(["background",o]),t}(t):function(e){const t=[];for(const o in Ml){const i=e[o];Array.isArray(i)&&t.push([`background-${o}`,i.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 Ll(e){return t=>({path:e,value:$l(t)})}function zl(e){return t=>{const o=t.join(", ");return[[e,o]]}}function jl(e){const t={},{value:o,image:i}=function(e){for(const t of Nl){const o=t+"(",i=e.indexOf(o);if(i<0)continue;let n=t,s=0;for(let o=i+t.length;o"constructor"!==e)).length:0===t.length}return!0}(t)?null:{...ql(),...t}}function ql(){return{attachment:Ml.attachment,image:Ml.image,origin:Ml.origin,clip:Ml.clip,position:Ml.position.split(" "),repeat:Ml.repeat.split(" "),size:Ml.size.split(" ")}}function $l(e){const t=[];let o="",i=0;for(const n of e){if("("===n)i++;else if(")"===n)i--;else if(","===n&&0===i){t.push(o.trim()),o="";continue}o+=n}return o.trim()&&t.push(o.trim()),t}function Hl(e){e.setNormalizer("border",(e=>{const{color:t,style:o,width:i}=Ql(e);return{path:"border",value:{color:Rl(t),style:Rl(o),width:Rl(i)}}})),e.setNormalizer("border-top",Wl("top")),e.setNormalizer("border-right",Wl("right")),e.setNormalizer("border-bottom",Wl("bottom")),e.setNormalizer("border-left",Wl("left")),e.setNormalizer("border-color",Ul("color")),e.setNormalizer("border-width",Ul("width")),e.setNormalizer("border-style",Ul("style")),e.setNormalizer("border-top-color",Gl("color","top")),e.setNormalizer("border-top-style",Gl("style","top")),e.setNormalizer("border-top-width",Gl("width","top")),e.setNormalizer("border-right-color",Gl("color","right")),e.setNormalizer("border-right-style",Gl("style","right")),e.setNormalizer("border-right-width",Gl("width","right")),e.setNormalizer("border-bottom-color",Gl("color","bottom")),e.setNormalizer("border-bottom-style",Gl("style","bottom")),e.setNormalizer("border-bottom-width",Gl("width","bottom")),e.setNormalizer("border-left-color",Gl("color","left")),e.setNormalizer("border-left-style",Gl("style","left")),e.setNormalizer("border-left-width",Gl("width","left")),e.setExtractor("border-top",Jl("top")),e.setExtractor("border-right",Jl("right")),e.setExtractor("border-bottom",Jl("bottom")),e.setExtractor("border-left",Jl("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",Ol("border-color")),e.setReducer("border-style",Ol("border-style")),e.setReducer("border-width",Ol("border-width")),e.setReducer("border-top",Yl("top")),e.setReducer("border-right",Yl("right")),e.setReducer("border-bottom",Yl("bottom")),e.setReducer("border-left",Yl("left")),e.setReducer("border",function(){return t=>{const o=Zl(t,"top"),i=Zl(t,"right"),n=Zl(t,"bottom"),s=Zl(t,"left"),r=[o,i,n,s],a={width:e(r,"width"),style:e(r,"style"),color:e(r,"color")},l=Xl(a,"all");if(l.length)return l;const c=Object.entries(a).reduce(((e,[t,o])=>(o&&(e.push([`border-${t}`,o]),r.forEach((e=>delete e[t]))),e)),[]);return[...c,...Xl(o,"top"),...Xl(i,"right"),...Xl(n,"bottom"),...Xl(s,"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 Wl(e){return t=>{const{color:o,style:i,width:n}=Ql(t),s={};return void 0!==o&&(s.color={[e]:o}),void 0!==i&&(s.style={[e]:i}),void 0!==n&&(s.width={[e]:n}),{path:"border",value:s}}}function Ul(e){return t=>({path:"border",value:Kl(t,e)})}function Kl(e,t){return{[t]:Rl(e)}}function Gl(e,t){return o=>({path:"border",value:{[e]:{[t]:o}}})}function Jl(e){return(t,o)=>{if(o.border)return Zl(o.border,e)}}function Zl(e,t){const o={};return e.width&&e.width[t]&&(o.width=e.width[t]),e.style&&e.style[t]&&(o.style=e.style[t]),e.color&&e.color[t]&&(o.color=e.color[t]),o}function Ql(e){const t={},o=Fl(e);for(const e of o)wl(e)||/thin|medium|thick/.test(e)?t.width=e:fl(e)?t.style=e:t.color=e;return t}function Yl(e){return t=>Xl(t,e)}function Xl(e,t){const o=[];if(e&&e.width&&o.push("width"),e&&e.style&&o.push("style"),e&&e.color&&o.push("color"),3==o.length){const i=o.map((t=>e[t])).join(" ");return["all"==t?["border",i]:[`border-${t}`,i]]}return"all"==t?[]:o.map((o=>[`border-${t}-${o}`,e[o]]))}function ec(e){e.setNormalizer("margin",Dl("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",Ol("margin")),e.setStyleRelation("margin",["margin-top","margin-right","margin-bottom","margin-left"])}function tc(e){e.setNormalizer("padding",Dl("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",Ol("padding")),e.setStyleRelation("padding",["padding-top","padding-right","padding-bottom","padding-left"])}Symbol("_treeDump");function oc(e,t=0,o={}){const{leading:i=!0,trailing:n=!0}=o;return zo(e,t,{leading:i,maxWait:t,trailing:n})}class ic{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 o=this._listeners[e]||[];for(const e of o)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 o=this._shouldRestart();this.state="crashed",this._fire("stateChange"),this._fire("error",{error:e,causesRestart:o}),o?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(){if(this.crashes.length<=this._crashNumberLimit)return!0;return(this.crashes[this.crashes.length-1].date-this.crashes[this.crashes.length-1-this._crashNumberLimit].date)/this._crashNumberLimit>this._minimumNonErrorTimePeriod}}function nc(e,t=new Set){const o=[e],i=new Set;let n=0;for(;o.length>n;){const e=o[n++];if(!i.has(e)&&sc(e)&&!t.has(e))if(i.add(e),Symbol.iterator in e)try{for(const t of e)o.push(t)}catch{}else for(const t in e)"defaultValue"!==t&&o.push(e[t])}return i}function sc(e){const t=Object.prototype.toString.call(e),o=typeof e;return!("number"===o||"boolean"===o||"string"===o||"symbol"===o||"function"===o||"[object Date]"===t||"[object RegExp]"===t||"[object Module]"===t||null==e||e._watchdogExcluded||e instanceof EventTarget||e instanceof Event)}function rc(e,t,o=new Set){if(e===t&&("object"==typeof(i=e)&&null!==i))return!0;var i;const n=nc(e,o),s=nc(t,o);for(const e of n)if(s.has(e))return!0;return!1}function ac(e,t,o){const i=t.root,n=t.roots||Object.create(null);o&&!n[o]&&(n[o]=i||Object.create(null));const s=function(e){return!!e&&"object"==typeof e&&!Array.isArray(e)&&(t=e,!L(t));var t}(e),r=function(e,t,o){return t||!o?e.initialData||Object.create(null):{[o]:e.initialData}}(t,s,o),a=Array.from(new Set([...s?Object.keys(e):[],...Object.keys(n),...Object.keys(r)]));for(const e of a){const o=n[e]||Object.create(null);o.initialData="",o.placeholder??=lc(t,"placeholder",e),o.label??=lc(t,"label",e),n[e]=o}t.roots=n}function lc(e,t,o){const i=e[t];if(i)return"string"==typeof i?i:i[o]}class cc extends ic{_editor=null;_lifecyclePromise=null;_throttledSave;_data;_lastDocumentVersion;_elementOrData;_editorAttachTo=null;_isSingleRootEditor=!0;_isUsingConfigBasedCreator=!1;_editables={};_config;_excludedProps;constructor(e,t={}){super(t),this._throttledSave=oc(this._save.bind(this),"number"==typeof t.saveInterval?t.saveInterval:5e3),e&&(this._creator=(t,o)=>void 0===o?e.create(t):e.create(t,o)),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?ac(this._isSingleRootEditor?"":{},this._config,!!this._isSingleRootEditor&&"main"):ac(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(dc);const t={};for(const[o,i]of Object.entries(this._data.roots)){const n=e.roots[o]||Object.create(null);n.initialData="",i.isLoaded?n.lazyLoad=!1:delete n.modelAttributes,t[o]=n}if(e.roots=t,delete e.initialData,delete e.root,this._isUsingConfigBasedCreator)return this.create(e,e.context);const o=this._isSingleRootEditor?this._editorAttachTo||"":this._editables;return this.create(o,e,e.context)})).then((()=>{this._fire("restart")}))}create(e=(this._isUsingConfigBasedCreator?this._config:this._elementOrData),t=(this._isUsingConfigBasedCreator?void 0:this._config),o){const i=this._detectConfigBasedCreator(e,t),n=i?void 0:e,s=i?e:t,r=i?t:o;return this._lifecyclePromise=Promise.resolve(this._lifecyclePromise).then((()=>{if(super._startErrorHandling(),this._isUsingConfigBasedCreator=i,this._elementOrData=n,this._config=this._cloneEditorConfiguration(s||{}),this._config.context=r,i){this._editorAttachTo=null;const e=this._config.roots?Object.keys(this._config.roots).length:0,t=this._config.initialData,o=t&&"object"==typeof t;this._isSingleRootEditor=!o&&e<=1}else this._editorAttachTo=uc(n)?n:null,this._isSingleRootEditor=uc(n)||"string"==typeof n;return i?this._creator(this._config):this._creator(n,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:o}=e,i=o.has("CommentsRepository")&&o.get("CommentsRepository"),n=o.has("TrackChanges")&&o.get("TrackChanges"),s={roots:{},markers:{},commentThreads:JSON.stringify([]),suggestions:JSON.stringify([])};t.forEach((e=>{s.roots[e.rootName]={content:JSON.stringify(Array.from(e.getChildren())),attributes:JSON.stringify(Array.from(e.getAttributes())),isLoaded:e._isLoaded}}));for(const t of e.model.markers)t._affectsData&&(s.markers[t.name]={rangeJSON:t.getRange().toJSON(),usingOperation:t._managedUsingOperations,affectsData:t._affectsData});return i&&(s.commentThreads=JSON.stringify(i.getCommentThreads({toJSON:!0,skipNotAttached:!0}))),n&&(s.suggestions=JSON.stringify(n.getSuggestions({toJSON:!0,skipNotAttached:!0}))),s}_getEditables(){const e={};for(const t of this.editor.model.document.getRootNames()){const o=this.editor.ui.getEditableElement(t);o&&(e[t]=o)}return e}_isErrorComingFromThisItem(e){return rc(this._editor,e.context,this._excludedProps)}_detectConfigBasedCreator(e,t){if("string"==typeof e||uc(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||uc(e))))return!1}return!0}_cloneEditorConfiguration(e){return N(e,((e,t)=>uc(e)||"context"===t?e:void 0))}}class dc{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 o=e.createElement(t.name,t.attributes);if(t.children)for(const i of t.children)o._appendChild(this._createNode(e,i));return o}return e.createText(t.data,t.attributes)}_restoreEditorData(e){const t=this.editor;Object.entries(this._data.roots).forEach((([o,{content:i,attributes:n}])=>{const s=JSON.parse(i),r=JSON.parse(n),a=t.model.document.getRoot(o);for(const[t,o]of r)e.setAttribute(t,o,a);for(const t of s){const o=this._createNode(e,t);e.insert(o,a,"end")}})),Object.entries(this._data.markers).forEach((([o,i])=>{const{document:n}=t.model,{rangeJSON:{start:s,end:r},...a}=i,l=n.getRoot(s.root),c=e.createPositionFromPath(l,s.path,s.stickiness),d=e.createPositionFromPath(l,r.path,r.stickiness),u=e.createRange(c,d);e.addMarker(o,{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 uc(e){return L(e)}const hc=Symbol("MainQueueId");class mc extends ic{_watchdogs=new Map;_watchdogConfig;_context=null;_contextProps=new Set;_actionQueues=new gc;_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(hc,(()=>(this._contextConfig=e,this._create())))}getItem(e){return this._getWatchdog(e)._item}getItemState(e){return this._getWatchdog(e).state}add(e){const t=pc(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 cc(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",((o,{error:i,causesRestart:n})=>{this._fire("itemError",{itemId:e.id,error:i}),n&&this._actionQueues.enqueue(e.id,(()=>new Promise((o=>{const i=()=>{t.off("restart",i),this._fire("itemRestart",{itemId:e.id}),o()};t.on("restart",i)}))))})),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=pc(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(hc,(()=>(this.state="destroyed",this._fire("stateChange"),super.destroy(),this._destroy())))}_restart(){return this._actionQueues.enqueue(hc,(()=>(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=nc(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 rc(this._context,e.context)}}class gc{_onEmptyCallbacks=[];_queues=new Map;_activeActions=0;onEmpty(e){this._onEmptyCallbacks.push(e)}enqueue(e,t){const o=e===hc;this._activeActions++,this._queues.get(e)||this._queues.set(e,Promise.resolve());const i=(o?Promise.all(this._queues.values()):Promise.all([this._queues.get(hc),this._queues.get(e)])).then(t),n=i.catch((()=>{}));return this._queues.set(e,n),i.finally((()=>{this._activeActions--,this._queues.get(e)===n&&0===this._activeActions&&this._onEmptyCallbacks.forEach((e=>e()))}))}}function pc(e){return Array.isArray(e)?e:[e]}class fc extends(Be()){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",bc,{priority:"highest"}),this.isEnabled=!1)}clearForceDisabled(e){this._disableStack.delete(e),0==this._disableStack.size&&(this.off("set:isEnabled",bc),this.isEnabled=!0)}destroy(){this.stopListening()}static get isContextPlugin(){return!1}static get isOfficialPlugin(){return!1}static get isPremiumPlugin(){return!1}}function bc(e){e.return=!1,e.stop()}class wc extends(Be()){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 o=e.model.document.selection,i=!("$graveyard"==o.getFirstPosition().root.rootName)&&e.model.canEditAt(o);(e.isReadOnly||this._isEnabledBasedOnSelection&&!i)&&(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",yc,{priority:"highest"}),this.isEnabled=!1)}clearForceDisabled(e){this._disableStack.delete(e),0==this._disableStack.size&&(this.off("set:isEnabled",yc),this.refresh())}execute(...e){}destroy(){this.stopListening()}}function yc(e){e.return=!1,e.stop()}class _c{_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 o=this.get(e);if(!o)throw new fe("commandcollection-command-not-found",this,{commandName:e});return o.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()}}class kc extends(xe()){_context;_plugins=new Map;_availablePlugins;_contextPlugins;constructor(e,t=[],o=[]){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 o)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=[],o=[]){const i=this,n=this._context;!function e(t,o=new Set){t.forEach((t=>{a(t)&&(o.has(t)||(o.add(t),t.pluginName&&!i._availablePlugins.has(t.pluginName)&&i._availablePlugins.set(t.pluginName,t),t.requires&&e(t.requires,o)))}))}(e),u(e);const s=[...function e(t,o=new Set){return t.map((e=>a(e)?e:i._availablePlugins.get(e))).reduce(((t,i)=>o.has(i)?t:(o.add(i),i.requires&&(u(i.requires,i),e(i.requires,o).forEach((e=>t.add(e)))),t.add(i))),new Set)}(e.filter((e=>!c(e,t))))];!function(e,t){for(const o of t){if("function"!=typeof o)throw new fe("plugincollection-replace-plugin-invalid-type",null,{pluginItem:o});const t=o.pluginName;if(!t)throw new fe("plugincollection-replace-plugin-missing-name",null,{pluginItem:o});if(o.requires&&o.requires.length)throw new fe("plugincollection-plugin-for-replacing-cannot-have-dependencies",null,{pluginName:t});const n=i._availablePlugins.get(t);if(!n)throw new fe("plugincollection-plugin-for-replacing-not-exist",null,{pluginName:t});const s=e.indexOf(n);if(-1===s){if(i._contextPlugins.has(n))return;throw new fe("plugincollection-plugin-for-replacing-not-loaded",null,{pluginName:t})}if(n.requires&&n.requires.length)throw new fe("plugincollection-replaced-plugin-cannot-have-dependencies",null,{pluginName:t});e.splice(s,1,o),i._availablePlugins.set(t,o)}}(s,o);const r=function(e){return e.map((e=>{let t=i._contextPlugins.get(e);return t=t||new e(n),i._add(e,t),t}))}(s);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,o=null){e.map((e=>a(e)?e:i._availablePlugins.get(e)||e)).forEach((e=>{!function(e){if("function"!=typeof e)return;if(e._throwErrorWhenUsedAsAPlugin)throw new fe("plugincollection-plugin-invalid-constructor",n,{name:e.name})}(e),function(e,t){if(a(e))return;if(t)throw new fe("plugincollection-soft-required",n,{missingPlugin:e,requiredBy:d(t)});throw new fe("plugincollection-plugin-not-found",n,{plugin:e})}(e,o),function(e,t){if(!l(t))return;if(l(e))return;throw new fe("plugincollection-context-required",n,{plugin:d(e),requiredBy:d(t)})}(e,o),function(e,o){if(!o)return;if(!c(e,t))return;throw new fe("plugincollection-required",n,{plugin:d(e),requiredBy:d(o)})}(e,o)}))}function h(e,t){return e.reduce(((e,o)=>o[t]?i._contextPlugins.has(o)?e:e.then(o[t].bind(o)):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 o=e.pluginName;if(o){if(this._plugins.has(o))throw new fe("plugincollection-plugin-name-conflict",null,{pluginName:o,plugin1:this._plugins.get(o).constructor,plugin2:e});this._plugins.set(o,t)}}}class vc{config;plugins;locale;t;editors;static defaultConfig;static builtinPlugins;_contextOwner=null;constructor(e){const{translations:t,...o}=e||{};this.config=new Ge(o,this.constructor.defaultConfig);const i=this.constructor.builtinPlugins;this.config.define("plugins",i),this.plugins=new kc(this,i);const n=this.config.get("language")||{};this.locale=new Xt({uiLanguage:"string"==typeof n?n:n.ui,contentLanguage:this.config.get("language.content"),translations:t}),this.t=this.locale.t,this.editors=new eo}initPlugins(){const e=this.config.get("plugins")||[],t=this.config.get("substitutePlugins")||[];for(const o of e.concat(t)){if("function"!=typeof o)throw new fe("context-initplugins-constructor-only",null,{Plugin:o});if(!0!==o.isContextPlugin)throw new fe("context-initplugins-invalid-plugin",null,{Plugin:o})}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 o=new this(e);t(o.initPlugins().then((()=>o)))}))}static get _throwErrorWhenUsedAsAPlugin(){return!0}}class Cc extends(Be()){context;constructor(e){super(),this.context=e}destroy(){this.stopListening()}static get isContextPlugin(){return!0}static get isOfficialPlugin(){return!1}static get isPremiumPlugin(){return!1}}class Ac extends ro{editor;constructor(e){super(),this.editor=e}set(e,t,o={}){if("string"==typeof t){const e=t;t=(t,o)=>{this.editor.execute(e),o()}}super.set(e,t,o)}}const xc="contentEditing",Ec="common";class Tc{keystrokeInfos=new Map;_editor;constructor(e){this._editor=e;const t=e.config.get("menuBar.isVisible"),o=e.locale.t;this.addKeystrokeInfoCategory({id:xc,label:o("Content editing keystrokes"),description:o("These keyboard shortcuts allow for quick access to content editing features.")});const i=[{label:o("Close contextual balloons, dropdowns, and dialogs"),keystroke:"Esc"},{label:o("Open the accessibility help dialog"),keystroke:"Alt+0"},{label:o("Move focus between form fields (inputs, buttons, etc.)"),keystroke:[["Tab"],["Shift+Tab"]]},{label:o("Move focus to the toolbar, navigate between toolbars"),keystroke:"Alt+F10",mayRequireFn:!0},{label:o("Navigate through the toolbar or menu bar"),keystroke:[["arrowup"],["arrowright"],["arrowdown"],["arrowleft"]]},{label:o("Execute the currently focused button. Executing buttons that interact with the editor content moves the focus back to the content."),keystroke:[["Enter"],["Space"]]}];t&&i.push({label:o("Move focus to the menu bar, navigate between menu bars"),keystroke:"Alt+F9",mayRequireFn:!0}),this.addKeystrokeInfoCategory({id:"navigation",label:o("User interface and content navigation keystrokes"),description:o("Use the following keystrokes for more efficient navigation in the CKEditor 5 user interface."),groups:[{id:"common",keystrokes:i}]})}addKeystrokeInfoCategory({id:e,label:t,description:o,groups:i}){this.keystrokeInfos.set(e,{id:e,label:t,description:o,groups:new Map}),this.addKeystrokeInfoGroup({categoryId:e,id:Ec}),i&&i.forEach((t=>{this.addKeystrokeInfoGroup({categoryId:e,...t})}))}addKeystrokeInfoGroup({categoryId:e=xc,id:t,label:o,keystrokes:i}){const n=this.keystrokeInfos.get(e);if(!n)throw new fe("accessibility-unknown-keystroke-info-category",this._editor,{groupId:t,categoryId:e});n.groups.set(t,{id:t,label:o,keystrokes:i||[]})}addKeystrokeInfos({categoryId:e=xc,groupId:t=Ec,keystrokes:o}){if(!this.keystrokeInfos.has(e))throw new fe("accessibility-unknown-keystroke-info-category",this._editor,{categoryId:e,keystrokes:o});const i=this.keystrokeInfos.get(e);if(!i.groups.has(t))throw new fe("accessibility-unknown-keystroke-info-group",this._editor,{groupId:t,categoryId:e,keystrokes:o});i.groups.get(t).keystrokes.push(...o)}}function Pc(e){return Object.getPrototypeOf(e).constructor.editorName}function Sc(e){if(!e)return;const t=Array.isArray(e)?{items:e}:e,o=function e(t){return t.flatMap((t=>"string"==typeof t?[t]:e(t.items)))}(t.items||[]);return{isMultiline:o.includes("-"),shouldNotGroupWhenFull:!!t.shouldNotGroupWhenFull,items:(i=o,i.filter((e=>"|"!==e&&"-"!==e)))};var i}function Ic(){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 Rc(){return localStorage.getItem("__ckeditor-session-id")||localStorage.setItem("__ckeditor-session-id",me()),localStorage.getItem("__ckeditor-session-id")}function Oc(){return J.window.CKEDITOR_PAGE_SESSION_ID=J.window.CKEDITOR_PAGE_SESSION_ID||me(),J.window.CKEDITOR_PAGE_SESSION_ID}class Vc extends(Be()){static get editorName(){return"Editor"}accessibility;commands;config;conversion;data;editing;locale;model;plugins;keystrokes;t;static defaultConfig;static builtinPlugins;_context;_readOnlyLocks;static get _throwErrorWhenUsedAsAPlugin(){return!0}constructor(e={}){if(super(),"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:o,...i}=t.defaultConfig||{},{translations:n=o,...s}=e,r=e.language||i.language;this._context=e.context||new vc({language:r,translations:n}),this._context._addEditor(this,!e.context);const a=Array.from(t.builtinPlugins||[]);this.config=new Ge(s,i),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 kc(this,a,this._context.plugins),this.locale=this._context.locale,this.t=this.locale.t,this._readOnlyLocks=new Set,this.commands=new _c,this.set("state","initializing"),this.once("ready",(()=>this.state="ready"),{priority:"high"}),this.once("destroy",(()=>this.state="destroyed"),{priority:"high"}),this.model=new el(this.config),this.on("change:isReadOnly",(()=>{this.model.document.isReadOnly=this.isReadOnly}));const l=new pi;this.data=new Rr(this.model,l),this.editing=new hr(this.model,l),this.editing.view.document.bind("isReadOnly").to(this),this.conversion=new Or([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 Ac(this),this.keystrokes.listenTo(this.editing.view.document),this.accessibility=new Tc(this),function(e){const t=e.config.get("licenseKey"),o=window[Symbol.for("cke distribution")]||"sh";function i(t,o){e.enableReadOnlyMode(Symbol("invalidLicense")),e._showLicenseError(t,o)}if("GPL"==t)return void("cloud"==o&&i("distributionChannel"));const n=bo(t);if(!n)return void i("invalid");if(!function(e){return["exp","jti","vc"].every((t=>t in e))}(n))return void i("invalid");if(n.distributionChannel&&!Qt(n.distributionChannel).includes(o))return void i("distributionChannel");if(function(e){const t=Array.isArray(e)?e:[e],o=function(){const e=[];for(let t=0;t<256;t++){let o=t;for(let e=0;e<8;e++)1&o?o=3988292384^o>>>1:o>>>=1;e[t]=o}return e}();let i=-1;const n=t.map((e=>Array.isArray(e)?e.join(""):String(e))).join("");for(let e=0;e>>8^o[255&(i^n.charCodeAt(e))];return i=~i>>>0,i.toString(16).padStart(8,"0")}(function(e){return Object.getOwnPropertyNames(e).sort().filter((t=>"vc"!=t&&null!=e[t])).map((t=>e[t]))}(n))!=n.vc.toLowerCase())return void i("invalid");if(new Date(1e3*n.exp)<_e)return void i("expired");const s=n.licensedHosts;if(s&&s.length>0&&!function(e){const{hostname:t}=new URL(window.location.href);if(e.includes(t))return!0;const o=t.split(".");return e.filter((e=>e.includes("*"))).map((e=>e.split("."))).filter((e=>e.length<=o.length)).map((e=>Array(o.length-e.length).fill("*"===e[0]?"*":"").concat(e))).some((e=>o.every(((t,o)=>e[o]===t||"*"===e[o]))))}(s))return void i("domainLimit");if(["evaluation","trial"].includes(n.licenseType)&&1e3*n.exp{i("evaluationLimit")}),6e5);e.on("destroy",(()=>{clearTimeout(t)}))}n.usageEndpoint&&e.once("ready",(()=>{const o={requestId:me(),requestTime:Math.round(Date.now()/1e3),license:t,editor:Dc(e)};e._sendUsageRequest(n.usageEndpoint,o).then((e=>{const{status:t,message:o}=e;o&&console.warn(o),"ok"!=t&&i("usageLimit")}),(()=>{var e,t;e="license-key-validation-endpoint-not-reachable",t={url:n.usageEndpoint},console.error(...ye(e,t))}))}),{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)}initPlugins(){const e=this.config,t=e.get("plugins"),o=e.get("removePlugins")||[],i=e.get("extraPlugins")||[],n=e.get("substitutePlugins")||[];return this.plugins.init(t.concat(i),o,n).then((e=>(function(e){const t=e.config.get("licenseKey");if("GPL"===t)return;const o=bo(t);if(!o)return;const i=[...e.plugins].map((([e])=>e)).find((e=>{return!!e.pluginName&&(!!e.licenseFeatureCode&&(t=o,i=e.licenseFeatureCode,(t.removeFeatures||[]).includes(i)));var t,i}));i&&(e.enableReadOnlyMode(Symbol("invalidLicense")),e._showLicenseError("pluginNotAllowed",i.pluginName))}(this),e)))}destroy(){let e=Promise.resolve();return"initializing"==this.state&&(e=new Promise((e=>this.once("ready",e)))),e.then((()=>{this.fire("destroy"),this.stopListening(),this.commands.destroy()})).then((()=>this.plugins.destroy())).then((()=>{this.model.destroy(),this.data.destroy(),this.editing.destroy(),this.keystrokes.destroy()})).then((()=>this._context._removeEditor(this)))}execute(e,...t){try{return this.commands.execute(e,...t)}catch(e){fe.rethrowUnexpectedError(e,this)}}focus(){this.editing.view.focus()}static create(...e){throw new Error("This is an abstract method.")}static Context=vc;static EditorWatchdog=cc;static ContextWatchdog=mc;_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)$/,""),o=this.plugins.has(e);throw new fe("license-key-plugin-not-allowed",null,{pluginName:o?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 o=new Headers({"Content-Type":"application/json"}),i=await fetch(new URL(e),{method:"POST",headers:o,body:JSON.stringify(t)});if(!i.ok)throw new Error(`HTTP Response: ${i.status}`);return i.json()}}function Dc(e){const t=function(e){return{sessionId:Rc(),pageSessionId:Oc(),hostname:window.location.hostname,version:globalThis.CKEDITOR_VERSION,type:Pc(e),plugins:(t=e.plugins,Array.from(t).filter((([e])=>!!e.pluginName)).map((([e])=>{const{pluginName:t,isContextPlugin:o,isOfficialPlugin:i,isPremiumPlugin:n}=e;return{isContext:!!o,isOfficial:!!i,isPremium:!!n,name:t}}))),distribution:{channel:window[Symbol.for("cke distribution")]||"sh"},env:Ic(),integration:Object.create(null),menuBar:{isVisible:!!e.config.get("menuBar.isVisible")},language:{ui:e.locale.uiLanguage,content:e.locale.contentLanguage},toolbar:{main:Sc(e.config.get("toolbar")),block:Sc(e.config.get("blockToolbar")),balloon:Sc(e.config.get("balloonToolbar"))}};var t}(e);return e.fire("collectUsageData",{setUsageData:function(e,o){if(void 0!==vo(t,e))throw new fe("editor-usage-data-path-already-set",{path:e});Ro(t,e,o)}}),t}function Fc(e){return class extends e{sourceElement;updateSourceElement(e){if(!this.sourceElement)throw new fe("editor-missing-sourceelement",this);const t=this.config.get("updateSourceElementOnDestroy"),o=this.sourceElement instanceof HTMLTextAreaElement;if(!t&&!o)return void wt(this.sourceElement,"");const i="string"==typeof e?e:this.data.get();wt(this.sourceElement,i)}}}function Mc(e,t,o="main",i=!1){const n=t.get("root"),s=t.get("roots")||Object.create(null);if(n){if(!o)throw new fe("editor-create-multi-root-with-main",null);if(o in s)throw new fe("editor-create-roots-with-main",null)}o&&!s[o]&&(s[o]=n||Object.create(null));const r=function(e){return!!e&&"object"==typeof e&&!Array.isArray(e)&&!Bc(e)}(e),a=function(e,t,o){return t||!o?e.get("initialData")||Object.create(null):{[o]:e.get("initialData")}}(t,r,o),l=Array.from(new Set([...r?Object.keys(e):[],...Object.keys(s),...Object.keys(a)]));for(const o of l){const n=s[o]||Object.create(null),l=r?e[o]:e;if(!i&&Bc(l)){if(n.element)throw new fe("editor-create-root-element-overspecified",null);n.element=l}if(i&&Bc(n.element)&&be("editor-create-root-element-not-supported"),void 0===n.initialData)if(void 0===a[o])n.initialData=Bc(d=l||n.element||i&&t.get("attachTo")||"")?(c=d)instanceof HTMLTextAreaElement?c.value:c.innerHTML:d;else{if(l&&!Bc(l))throw new fe("editor-create-initial-data-overspecified",null);n.initialData=a[o]}else{if(l&&!Bc(l))throw new fe("editor-create-root-initial-data-overspecified",null);if(void 0!==a[o])throw new fe("editor-create-legacy-initial-data-overspecified",null)}n.placeholder??=Nc(t,"placeholder",o),n.label??=Nc(t,"label",o),s[o]=n}var c,d;if(i&&Bc(e)){if(t.get("attachTo"))throw new fe("editor-create-attachto-overspecified",null);t.set("attachTo",e)}if(!i&&t.get("attachTo"))throw new fe("editor-create-attachto-ignored",null);t.set("roots",s)}function Nc(e,t,o){const i=e.get(t);if(i)return"string"==typeof i?i:i[o]}function Bc(e){return L(e)}class Lc extends Cc{_actions;static get pluginName(){return"PendingActions"}static get isOfficialPlugin(){return!0}init(){this.set("hasAny",!1),this._actions=new eo({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(Be());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]()}}var zc='',jc='',qc='',$c='',Hc='',Wc='',Uc='',Kc='',Gc='',Jc='',Zc='',Qc='',Yc='',Xc='',ed='',td='',od='',id='',nd='';const sd={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 sd)Object.freeze(sd[e]);const rd=Object.freeze(sd),ad=function(e){var t,o,i=[],n=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(),rd[e])i=rd[e].slice(),o="rgb";else if("transparent"===e)n=0,o="rgb",i=[0,0,0];else if("#"===e[0]){var s=e.slice(1),r=s.length;n=1,r<=4?(i=[parseInt(s[0]+s[0],16),parseInt(s[1]+s[1],16),parseInt(s[2]+s[2],16)],4===r&&(n=parseInt(s[3]+s[3],16)/255)):(i=[parseInt(s[0]+s[1],16),parseInt(s[2]+s[3],16),parseInt(s[4]+s[5],16)],8===r&&(n=parseInt(s[6]+s[7],16)/255)),i[0]||(i[0]=0),i[1]||(i[1]=0),i[2]||(i[2]=0),o="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"===(o=a.replace(/a$/,""))?4:"gray"===o?1:3;i=t[2].trim().split(/\s*[,\/]\s*|\s+/),"color"===o&&(o=i.shift()),n=(i=i.map((function(e,t){if("%"===e[e.length-1])return e=parseFloat(e)/100,3===t?e:"rgb"===o?255*e:"h"===o[0]?100*e:"l"!==o[0]||t?"lab"===o?125*e:"lch"===o?t<2?150*e:360*e:"o"!==o[0]||t?"oklab"===o?.4*e:"oklch"===o?t<2?.4*e:360*e:e:e:100*e;if("h"===o[t]||2===t&&"h"===o[o.length-1]){if(void 0!==ld[e])return ld[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)}))).length>l?i.pop():1}else/[0-9](?:\s|\/|,)/.test(e)&&(i=e.match(/([0-9]+)/g).map((function(e){return parseFloat(e)})),o=e.match(/([a-z])/gi)?.join("")?.toLowerCase()||"rgb");return{space:o,values:i,alpha:n}};var ld={red:0,orange:60,yellow:120,green:180,blue:240,purple:300};const cd={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 cd)Object.freeze(cd[e]);const dd=Object.freeze(cd),ud={};for(const e of Object.keys(dd))ud[dd[e]]=e;const hd={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"]}},md=hd,gd=(6/29)**3;function pd(e){const t=e>.0031308?1.055*e**(1/2.4)-.055:12.92*e;return Math.min(Math.max(0,t),1)}function fd(e){return e>.04045?((e+.055)/1.055)**2.4:e/12.92}for(const e of Object.keys(hd)){if(!("channels"in hd[e]))throw new Error("missing channels property: "+e);if(!("labels"in hd[e]))throw new Error("missing channel labels property: "+e);if(hd[e].labels.length!==hd[e].channels)throw new Error("channel and label counts mismatch: "+e);const{channels:t,labels:o}=hd[e];delete hd[e].channels,delete hd[e].labels,Object.defineProperty(hd[e],"channels",{value:t}),Object.defineProperty(hd[e],"labels",{value:o})}function bd(e){const t=function(){const e={},t=Object.keys(md);for(let{length:o}=t,i=0;i0;){const e=o.pop(),i=Object.keys(md[e]);for(let{length:n}=i,s=0;s1&&(n-=1)}return[360*n,100*s,100*c]},hd.rgb.hwb=function(e){const t=e[0],o=e[1];let i=e[2];const n=hd.rgb.hsl(e)[0],s=1/255*Math.min(t,Math.min(o,i));return i=1-1/255*Math.max(t,Math.max(o,i)),[n,100*s,100*i]},hd.rgb.oklab=function(e){const t=fd(e[0]/255),o=fd(e[1]/255),i=fd(e[2]/255),n=Math.cbrt(.4122214708*t+.5363325363*o+.0514459929*i),s=Math.cbrt(.2119034982*t+.6806995451*o+.1073969566*i),r=Math.cbrt(.0883024619*t+.2817188376*o+.6299787005*i);return[100*(.2104542553*n+.793617785*s-.0040720468*r),100*(1.9779984951*n-2.428592205*s+.4505937099*r),100*(.0259040371*n+.7827717662*s-.808675766*r)]},hd.rgb.cmyk=function(e){const t=e[0]/255,o=e[1]/255,i=e[2]/255,n=Math.min(1-t,1-o,1-i);return[100*((1-t-n)/(1-n)||0),100*((1-o-n)/(1-n)||0),100*((1-i-n)/(1-n)||0),100*n]},hd.rgb.keyword=function(e){const t=ud[e];if(t)return t;let o,i=Number.POSITIVE_INFINITY;for(const t of Object.keys(dd)){const r=dd[t],a=(s=r,((n=e)[0]-s[0])**2+(n[1]-s[1])**2+(n[2]-s[2])**2);agd?o**(1/3):7.787*o+16/116,i=i>gd?i**(1/3):7.787*i+16/116,n=n>gd?n**(1/3):7.787*n+16/116;return[116*i-16,500*(o-i),200*(i-n)]},hd.hsl.rgb=function(e){const t=e[0]/360,o=e[1]/100,i=e[2]/100;let n,s;if(0===o)return s=255*i,[s,s,s];const r=i<.5?i*(1+o):i+o-i*o,a=2*i-r,l=[0,0,0];for(let e=0;e<3;e++)n=t+1/3*-(e-1),n<0&&n++,n>1&&n--,s=6*n<1?a+6*(r-a)*n:2*n<1?r:3*n<2?a+(r-a)*(2/3-n)*6:a,l[e]=255*s;return l},hd.hsl.hsv=function(e){const t=e[0];let o=e[1]/100,i=e[2]/100,n=o;const s=Math.max(i,.01);i*=2,o*=i<=1?i:2-i,n*=s<=1?s:2-s;return[t,100*(0===i?2*n/(s+n):2*o/(i+o)),100*((i+o)/2)]},hd.hsv.rgb=function(e){const t=e[0]/60,o=e[1]/100;let i=e[2]/100;const n=Math.floor(t)%6,s=t-Math.floor(t),r=255*i*(1-o),a=255*i*(1-o*s),l=255*i*(1-o*(1-s));switch(i*=255,n){case 0:return[i,l,r];case 1:return[a,i,r];case 2:return[r,i,l];case 3:return[r,a,i];case 4:return[l,r,i];case 5:return[i,r,a]}},hd.hsv.hsl=function(e){const t=e[0],o=e[1]/100,i=e[2]/100,n=Math.max(i,.01);let s,r;r=(2-o)*i;const a=(2-o)*n;return s=o*n,s/=a<=1?a:2-a,s=s||0,r/=2,[t,100*s,100*r]},hd.hwb.rgb=function(e){const t=e[0]/360;let o=e[1]/100,i=e[2]/100;const n=o+i;let s;n>1&&(o/=n,i/=n);const r=Math.floor(6*t),a=1-i;s=6*t-r,1&r&&(s=1-s);const l=o+s*(a-o);let c,d,u;switch(r){default:case 6:case 0:c=a,d=l,u=o;break;case 1:c=l,d=a,u=o;break;case 2:c=o,d=a,u=l;break;case 3:c=o,d=l,u=a;break;case 4:c=l,d=o,u=a;break;case 5:c=a,d=o,u=l}return[255*c,255*d,255*u]},hd.cmyk.rgb=function(e){const t=e[0]/100,o=e[1]/100,i=e[2]/100,n=e[3]/100;return[255*(1-Math.min(1,t*(1-n)+n)),255*(1-Math.min(1,o*(1-n)+n)),255*(1-Math.min(1,i*(1-n)+n))]},hd.xyz.rgb=function(e){const t=e[0]/100,o=e[1]/100,i=e[2]/100;let n,s,r;return n=3.2404542*t+-1.5371385*o+-.4985314*i,s=-.969266*t+1.8760108*o+.041556*i,r=.0556434*t+-.2040259*o+1.0572252*i,n=pd(n),s=pd(s),r=pd(r),[255*n,255*s,255*r]},hd.xyz.lab=function(e){let t=e[0],o=e[1],i=e[2];t/=95.047,o/=100,i/=108.883,t=t>gd?t**(1/3):7.787*t+16/116,o=o>gd?o**(1/3):7.787*o+16/116,i=i>gd?i**(1/3):7.787*i+16/116;return[116*o-16,500*(t-o),200*(o-i)]},hd.xyz.oklab=function(e){const t=e[0]/100,o=e[1]/100,i=e[2]/100,n=Math.cbrt(.8189330101*t+.3618667424*o-.1288597137*i),s=Math.cbrt(.0329845436*t+.9293118715*o+.0361456387*i),r=Math.cbrt(.0482003018*t+.2643662691*o+.633851707*i);return[100*(.2104542553*n+.793617785*s-.0040720468*r),100*(1.9779984951*n-2.428592205*s+.4505937099*r),100*(.0259040371*n+.7827717662*s-.808675766*r)]},hd.oklab.oklch=function(e){return hd.lab.lch(e)},hd.oklab.xyz=function(e){const t=e[0]/100,o=e[1]/100,i=e[2]/100,n=(.999999998*t+.396337792*o+.215803758*i)**3,s=(1.000000008*t-.105561342*o-.063854175*i)**3,r=(1.000000055*t-.089484182*o-1.291485538*i)**3;return[100*(1.227013851*n-.55779998*s+.281256149*r),100*(-.040580178*n+1.11225687*s-.071676679*r),100*(-.076381285*n-.421481978*s+1.58616322*r)]},hd.oklab.rgb=function(e){const t=e[0]/100,o=e[1]/100,i=e[2]/100,n=(t+.3963377774*o+.2158037573*i)**3,s=(t-.1055613458*o-.0638541728*i)**3,r=(t-.0894841775*o-1.291485548*i)**3;return[255*pd(4.0767416621*n-3.3077115913*s+.2309699292*r),255*pd(-1.2684380046*n+2.6097574011*s-.3413193965*r),255*pd(-.0041960863*n-.7034186147*s+1.707614701*r)]},hd.oklch.oklab=function(e){return hd.lch.lab(e)},hd.lab.xyz=function(e){let t,o,i;o=(e[0]+16)/116,t=e[1]/500+o,i=o-e[2]/200;const n=o**3,s=t**3,r=i**3;return o=n>gd?n:(o-16/116)/7.787,t=s>gd?s:(t-16/116)/7.787,i=r>gd?r:(i-16/116)/7.787,t*=95.047,o*=100,i*=108.883,[t,o,i]},hd.lab.lch=function(e){const t=e[0],o=e[1],i=e[2];let n;n=360*Math.atan2(i,o)/2/Math.PI,n<0&&(n+=360);return[t,Math.sqrt(o*o+i*i),n]},hd.lch.lab=function(e){const t=e[0],o=e[1],i=e[2]/360*2*Math.PI;return[t,o*Math.cos(i),o*Math.sin(i)]},hd.rgb.ansi16=function(e,t=null){const[o,i,n]=e;let s=null===t?hd.rgb.hsv(e)[2]:t;if(s=Math.round(s/50),0===s)return 30;let r=30+(Math.round(n/255)<<2|Math.round(i/255)<<1|Math.round(o/255));return 2===s&&(r+=60),r},hd.hsv.ansi16=function(e){return hd.rgb.ansi16(hd.hsv.rgb(e),e[2])},hd.rgb.ansi256=function(e){const t=e[0],o=e[1],i=e[2];if(t>>4==o>>4&&o>>4==i>>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(o/255*5)+Math.round(i/255*5)},hd.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 o=.5*(Math.trunc(e>50)+1);return[(1&t)*o*255,(t>>1&1)*o*255,(t>>2&1)*o*255]},hd.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]},hd.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},hd.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 o=t[0];3===t[0].length&&(o=[...o].map((e=>e+e)).join(""));const i=Number.parseInt(o,16);return[i>>16&255,i>>8&255,255&i]},hd.rgb.hcg=function(e){const t=e[0]/255,o=e[1]/255,i=e[2]/255,n=Math.max(Math.max(t,o),i),s=Math.min(Math.min(t,o),i),r=n-s;let a;return a=r<=0?0:n===t?(o-i)/r%6:n===o?2+(i-t)/r:4+(t-o)/r,a/=6,a%=1,[360*a,100*r,100*(r<1?s/(1-r):0)]},hd.hsl.hcg=function(e){const t=e[1]/100,o=e[2]/100,i=o<.5?2*t*o:2*t*(1-o);let n=0;return i<1&&(n=(o-.5*i)/(1-i)),[e[0],100*i,100*n]},hd.hsv.hcg=function(e){const t=e[1]/100,o=e[2]/100,i=t*o;let n=0;return i<1&&(n=(o-i)/(1-i)),[e[0],100*i,100*n]},hd.hcg.rgb=function(e){const t=e[0]/360,o=e[1]/100,i=e[2]/100;if(0===o)return[255*i,255*i,255*i];const n=[0,0,0],s=t%1*6,r=s%1,a=1-r;let l=0;switch(Math.floor(s)){case 0:n[0]=1,n[1]=r,n[2]=0;break;case 1:n[0]=a,n[1]=1,n[2]=0;break;case 2:n[0]=0,n[1]=1,n[2]=r;break;case 3:n[0]=0,n[1]=a,n[2]=1;break;case 4:n[0]=r,n[1]=0,n[2]=1;break;default:n[0]=1,n[1]=0,n[2]=a}return l=(1-o)*i,[255*(o*n[0]+l),255*(o*n[1]+l),255*(o*n[2]+l)]},hd.hcg.hsv=function(e){const t=e[1]/100,o=t+e[2]/100*(1-t);let i=0;return o>0&&(i=t/o),[e[0],100*i,100*o]},hd.hcg.hsl=function(e){const t=e[1]/100,o=e[2]/100*(1-t)+.5*t;let i=0;return o>0&&o<.5?i=t/(2*o):o>=.5&&o<1&&(i=t/(2*(1-o))),[e[0],100*i,100*o]},hd.hcg.hwb=function(e){const t=e[1]/100,o=t+e[2]/100*(1-t);return[e[0],100*(o-t),100*(1-o)]},hd.hwb.hcg=function(e){const t=e[1]/100,o=1-e[2]/100,i=o-t;let n=0;return i<1&&(n=(o-i)/(1-i)),[e[0],100*i,100*n]},hd.apple.rgb=function(e){return[e[0]/65535*255,e[1]/65535*255,e[2]/65535*255]},hd.rgb.apple=function(e){return[e[0]/255*65535,e[1]/255*65535,e[2]/255*65535]},hd.gray.rgb=function(e){return[e[0]/100*255,e[0]/100*255,e[0]/100*255]},hd.gray.hsl=function(e){return[0,0,e[0]]},hd.gray.hsv=hd.gray.hsl,hd.gray.hwb=function(e){return[0,100,e[0]]},hd.gray.cmyk=function(e){return[0,0,0,e[0]]},hd.gray.lab=function(e){return[e[0],0,0]},hd.gray.hex=function(e){const t=255&Math.round(e[0]/100*255),o=((t<<16)+(t<<8)+t).toString(16).toUpperCase();return"000000".slice(o.length)+o},hd.rgb.gray=function(e){return[(e[0]+e[1]+e[2])/3/255*100]};const _d=function(e){const t=bd(e),o={},i=Object.keys(t);for(let{length:e}=i,n=0;n1&&(t=o),e(t))};return"conversion"in e&&(t.conversion=e.conversion),t}function Ad(e){const t=function(...t){const o=t[0];if(null==o)return o;o.length>1&&(t=o);const i=e(t);if("object"==typeof i)for(let{length:e}=i,t=0;te>o?o:eMath.round(o*e)/o,Pd=(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?Td(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?Td(parseInt(e.substring(6,8),16)/255,2):1})),Sd=({h:e,s:t,v:o,a:i})=>{const n=(200-t)*o/100;return{h:Td(e),s:Td(n>0&&n<200?t*o/100/(n<=100?n:200-n)*100:0),l:Td(n/2),a:Td(i,2)}},Id=e=>{const{h:t,s:o,l:i}=Sd(e);return`hsl(${t}, ${o}%, ${i}%)`},Rd=({h:e,s:t,v:o,a:i})=>{e=e/360*6,t/=100,o/=100;const n=Math.floor(e),s=o*(1-t),r=o*(1-(e-n)*t),a=o*(1-(1-e+n)*t),l=n%6;return{r:Td(255*[o,r,s,s,a,o][l]),g:Td(255*[a,o,o,r,s,s][l]),b:Td(255*[s,s,a,o,o,r][l]),a:Td(i,2)}},Od=e=>{const t=e.toString(16);return t.length<2?"0"+t:t},Vd=({r:e,g:t,b:o,a:i})=>{const n=i<1?Od(Td(255*i)):"";return"#"+Od(e)+Od(t)+Od(o)+n},Dd=({r:e,g:t,b:o,a:i})=>{const n=Math.max(e,t,o),s=n-Math.min(e,t,o),r=s?n===e?(t-o)/s:n===t?2+(o-e)/s:4+(e-t)/s:0;return{h:Td(60*(r<0?r+6:r)),s:Td(n?s/n*100:0),v:Td(n/255*100),a:i}},Fd=(e,t)=>{if(e===t)return!0;for(const o in e)if(e[o]!==t[o])return!1;return!0},Md={},Nd=e=>{let t=Md[e];return t||(t=document.createElement("template"),t.innerHTML=e,Md[e]=t),t},Bd=(e,t,o)=>{e.dispatchEvent(new CustomEvent(t,{bubbles:!0,detail:o}))};let Ld=!1;const zd=e=>"touches"in e,jd=(e,t)=>{const o=zd(t)?t.touches[0]:t,i=e.el.getBoundingClientRect();Bd(e.el,"move",e.getMove({x:Ed((o.pageX-(i.left+window.pageXOffset))/i.width),y:Ed((o.pageY-(i.top+window.pageYOffset))/i.height)}))};class qd{constructor(e,t,o,i){const n=Nd(``);e.appendChild(n.content.cloneNode(!0));const s=e.querySelector(`[part=${t}]`);s.addEventListener("mousedown",this),s.addEventListener("touchstart",this),s.addEventListener("keydown",this),this.el=s,this.xy=i,this.nodes=[s.firstChild,s]}set dragging(e){const t=e?document.addEventListener:document.removeEventListener;t(Ld?"touchmove":"mousemove",this),t(Ld?"touchend":"mouseup",this)}handleEvent(e){switch(e.type){case"mousedown":case"touchstart":if(e.preventDefault(),!(e=>!(Ld&&!zd(e)||(Ld||(Ld=zd(e)),0)))(e)||!Ld&&0!=e.button)return;this.el.focus(),jd(this,e),this.dragging=!0;break;case"mousemove":case"touchmove":e.preventDefault(),jd(this,e);break;case"mouseup":case"touchend":this.dragging=!1;break;case"keydown":((e,t)=>{const o=t.keyCode;o>40||e.xy&&o<37||o<33||(t.preventDefault(),Bd(e.el,"move",e.getMove({x:39===o?.01:37===o?-.01:34===o?.05:33===o?-.05:35===o?1:36===o?-1:0,y:40===o?.01:38===o?-.01:0},!0)))})(this,e)}}style(e){e.forEach(((e,t)=>{for(const o in e)this.nodes[t].style.setProperty(o,e[o])}))}}class $d extends qd{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:Id({h:e,s:100,v:100,a:1})}]),this.el.setAttribute("aria-valuenow",`${Td(e)}`)}getMove(e,t){return{h:t?Ed(this.h+360*e.x,0,360):360*e.x}}}class Hd extends qd{constructor(e){super(e,"saturation",'aria-label="Color"',!0)}update(e){this.hsva=e,this.style([{top:100-e.v+"%",left:`${e.s}%`,color:Id(e)},{"background-color":Id({h:e.h,s:100,v:100,a:1})}]),this.el.setAttribute("aria-valuetext",`Saturation ${Td(e.s)}%, Brightness ${Td(e.v)}%`)}getMove(e,t){return{s:t?Ed(this.hsva.s+100*e.x,0,100):100*e.x,v:t?Ed(this.hsva.v-100*e.y,0,100):Math.round(100-100*e.y)}}}const Wd=Symbol("same"),Ud=Symbol("color"),Kd=Symbol("hsva"),Gd=Symbol("update"),Jd=Symbol("parts"),Zd=Symbol("css"),Qd=Symbol("sliders");class Yd extends HTMLElement{static get observedAttributes(){return["color"]}get[Zd](){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[Qd](){return[Hd,$d]}get color(){return this[Ud]}set color(e){if(!this[Wd](e)){const t=this.colorModel.toHsva(e);this[Gd](t),this[Ud]=e}}constructor(){super();const e=Nd(``),t=this.attachShadow({mode:"open"});t.appendChild(e.content.cloneNode(!0)),t.addEventListener("move",this),this[Jd]=this[Qd].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,o){const i=this.colorModel.fromAttr(o);this[Wd](i)||(this.color=i)}handleEvent(e){const t=this[Kd],o={...t,...e.detail};let i;this[Gd](o),Fd(o,t)||this[Wd](i=this.colorModel.fromHsva(o))||(this[Ud]=i,Bd(this,"color-changed",{value:i}))}[Wd](e){return this.color&&this.colorModel.equal(e,this.color)}[Gd](e){this[Kd]=e,this[Jd].forEach((t=>t.update(e)))}}const Xd={defaultColor:"#000",toHsva:e=>Dd(Pd(e)),fromHsva:({h:e,s:t,v:o})=>Vd(Rd({h:e,s:t,v:o,a:1})),equal:(e,t)=>e.toLowerCase()===t.toLowerCase()||Fd(Pd(e),Pd(t)),fromAttr:e=>e};class eu extends Yd{get colorModel(){return Xd}}class tu extends eo{_parentElement;constructor(e=[]){super(e,{idProperty:"viewUid"}),this.on("add",((e,t,o)=>{this._renderViewIntoCollectionParent(t,o)})),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 o of this)for(const i of e)o.delegate(i).to(t);this.on("add",((o,i)=>{for(const o of e)i.delegate(o).to(t)})),this.on("remove",((o,i)=>{for(const o of e)i.stopDelegating(o,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)}}class ou extends(xe()){ns;tag;text;attributes;children;eventListeners;_isRendered;_revertData;constructor(e){super(),Object.assign(this,mu(hu(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 o of t.children)yu(o)?yield o:_u(o)&&(yield*e(o))}(this)}static bind(e,t){return{to:(o,i)=>new nu({eventNameOrFunction:o,attribute:o,observable:e,emitter:t,callback:i}),if:(o,i,n)=>new su({observable:e,emitter:t,attribute:o,valueIfTrue:i,callback:n})}}static extend(e,t){if(e._isRendered)throw new fe("template-extend-render",[this,e]);bu(e,mu(hu(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(""),ru(this.text)?this._bindToObservable({schema:this.text,updater:cu(t),data:e}):t.textContent=this.text.join(""),t}_renderAttributes(e){if(!this.attributes)return;const t=e.node,o=e.revertData;for(const i in this.attributes){const n=t.getAttribute(i),s=this.attributes[i];o&&(o.attributes[i]=n);const r=vu(s)?s[0].ns:null;if(ru(s)){const a=vu(s)?s[0].value:s;o&&Cu(i)&&a.unshift(n),this._bindToObservable({schema:a,updater:du(t,i,r),data:e})}else if("style"==i&&"string"!=typeof s[0])this._renderStyleAttribute(s[0],e);else{o&&n&&Cu(i)&&s.unshift(n);const e=s.map((e=>e&&e.value||e)).reduce(((e,t)=>e.concat(t)),[]).reduce(pu,"");wu(e)||t.setAttributeNS(r,i,e)}}}_renderStyleAttribute(e,t){const o=t.node;for(const i in e){const n=e[i];ru(n)?this._bindToObservable({schema:[n],updater:uu(o,i),data:t}):au(i)?o.style.setProperty(i,n):o.style[i]=n}}_renderElementChildren(e){const t=e.node,o=e.intoFragment?document.createDocumentFragment():t,i=e.isApplying;let n=0;for(const s of this.children)if(ku(s)){if(!i){s.setParent(t);for(const e of s)o.appendChild(e.element)}}else if(yu(s))i||(s.isRendered||s.render(),o.appendChild(s.element));else if(Qe(s))o.appendChild(s);else if(i){const t={children:[],bindings:[],attributes:{}};e.revertData.children.push(t),s._renderNode({intoFragment:!1,node:o.childNodes[n++],isApplying:!0,revertData:t})}else o.appendChild(s.render());e.intoFragment&&t.appendChild(o)}_setUpListeners(e){if(this.eventListeners)for(const t in this.eventListeners){const o=this.eventListeners[t].map((o=>{const[i,n]=t.split("@");return o.activateDomEventListener(i,n,e)}));e.revertData&&e.revertData.bindings.push(o)}}_bindToObservable({schema:e,updater:t,data:o}){const i=o.revertData;lu(e,t,o);const n=e.filter((e=>!wu(e))).filter((e=>e.observable)).map((i=>i.activateAttributeListener(e,t,o)));i&&i.bindings.push(n)}_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 o=e;for(const e in t.attributes){const i=t.attributes[e];null===i?o.removeAttribute(e):o.setAttribute(e,i)}for(let e=0;elu(e,t,o);return this.emitter.listenTo(this.observable,`change:${this.attribute}`,i),()=>{this.emitter.stopListening(this.observable,`change:${this.attribute}`,i)}}}class nu extends iu{eventNameOrFunction;constructor(e){super(e),this.eventNameOrFunction=e.eventNameOrFunction}activateDomEventListener(e,t,o){const i=(e,o)=>{t&&!o.target.matches(t)||("function"==typeof this.eventNameOrFunction?this.eventNameOrFunction(o):this.observable.fire(this.eventNameOrFunction,o))};return this.emitter.listenTo(o.node,e,i),()=>{this.emitter.stopListening(o.node,e,i)}}}class su extends iu{valueIfTrue;constructor(e){super(e),this.valueIfTrue=e.valueIfTrue}getValue(e){return!wu(super.getValue(e))&&(this.valueIfTrue||!0)}}function ru(e){return!!e&&(e.value&&(e=e.value),Array.isArray(e)?e.some(ru):e instanceof iu)}function au(e){return/^--[a-zA-Z_-][\w-]*$/.test(e)}function lu(e,t,{node:o}){const i=function(e,t){return e.map((e=>e instanceof iu?e.getValue(t):e))}(e,o);let n;n=1==e.length&&e[0]instanceof su?i[0]:i.reduce(pu,""),wu(n)?t.remove():t.set(n)}function cu(e){return{set(t){e.textContent=t},remove(){e.textContent=""}}}function du(e,t,o){return{set(i){e.setAttributeNS(o,t,i)},remove(){e.removeAttributeNS(o,t)}}}function uu(e,t){return{set(o){au(t)?e.style.setProperty(t,o):e.style[t]=o},remove(){au(t)?e.style.removeProperty(t):e.style[t]=null}}}function hu(e){return N(e,(e=>{if(e&&(e instanceof iu||_u(e)||yu(e)||ku(e)))return e}))}function mu(e){if("string"==typeof e?e=function(e){return{text:[e]}}(e):e.text&&function(e){e.text=Qt(e.text)}(e),e.on&&(e.eventListeners=function(e){for(const t in e)gu(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=Qt(e[t].value)),gu(e,t)}(e.attributes);const t=[];if(e.children)if(ku(e.children))t.push(e.children);else for(const o of e.children)_u(o)||yu(o)||Qe(o)?t.push(o):t.push(new ou(o));e.children=t}return e}function gu(e,t){e[t]=Qt(e[t])}function pu(e,t){return wu(t)?e:wu(e)?t:`${e} ${t}`}function fu(e,t){for(const o in t)e[o]?e[o].push(...t[o]):e[o]=t[o]}function bu(e,t){if(t.attributes&&(e.attributes||(e.attributes={}),fu(e.attributes,t.attributes)),t.eventListeners&&(e.eventListeners||(e.eventListeners={}),fu(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 o=0;for(const i of t.children)bu(e.children[o++],i)}}function wu(e){return!e&&0!==e}function yu(e){return e instanceof Au}function _u(e){return e instanceof ou}function ku(e){return e instanceof tu}function vu(e){return s(e[0])&&e[0].ns}function Cu(e){return"class"==e||"style"==e}class Au extends(et(Be())){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 eo,this._unboundChildren=this.createCollection(),this._viewCollections.on("add",((t,o)=>{o.locale=e,o.t=e&&e.t})),this.decorate("render")}get bindTemplate(){return this._bindTemplate?this._bindTemplate:this._bindTemplate=ou.bind(this,this)}createCollection(e){const t=new tu(e);return this._viewCollections.add(t),t}registerChild(e){Ue(e)||(e=[e]);for(const t of e)this._unboundChildren.add(t)}deregisterChild(e){Ue(e)||(e=[e]);for(const t of e)this._unboundChildren.remove(t)}setTemplate(e){this.template=new ou(e)}extendTemplate(e){ou.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 xu={POLITE:"polite",ASSERTIVE:"assertive"};class Eu{editor;view;constructor(e){this.editor=e,e.once("ready",(()=>{for(const e of Object.values(xu))this.announce("",e)}))}announce(e,t=xu.POLITE){const o=this.editor;if(!o.ui.view)return;this.view||(this.view=new Tu(o.locale),o.ui.view.body.add(this.view));const{politeness:i,isUnsafeHTML:n}="string"==typeof t?{politeness:t}:t;let s=this.view.regionViews.find((e=>e.politeness===i));s||(s=new Pu(o,i),this.view.regionViews.add(s)),s.announce({announcement:e,isUnsafeHTML:n})}}class Tu extends Au{regionViews;constructor(e){super(e),this.regionViews=this.createCollection(),this.setTemplate({tag:"div",attributes:{class:["ck","ck-aria-live-announcer"]},children:this.regionViews})}}class Pu extends Au{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 o=document.createElement("li");t?this._domConverter.setContentOf(o,e):o.innerText=e,this._listElement.appendChild(o)}get _listElement(){return this.element.querySelector("ul")}}function Su({emitter:e,activator:t,callback:o,contextElements:i,listenerOptions:n}){e.listenTo(document,"mousedown",((e,n)=>{if(!t())return;const s="function"==typeof n.composedPath?n.composedPath():[],r="function"==typeof i?i():i;for(const e of r)if(e.contains(n.target)||s.includes(e))return;o()}),n)}function Iu(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 Ru(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(J.document,"mouseup",this._onDragEndBound),this.listenTo(J.document,"touchend",this._onDragEndBound),this.listenTo(J.document,"mousemove",this._onDragBound),this.listenTo(J.document,"touchmove",this._onDragBound)}_detachDragListeners(){this.stopListening(J.document,"mouseup",this._onDragEndBound),this.stopListening(J.document,"touchend",this._onDragEndBound),this.stopListening(J.document,"mousemove",this._onDragBound),this.stopListening(J.document,"touchmove",this._onDragBound)}_onDragStart(e,t){if(!this._isHandleElementPressed(t))return;this._attachDragListeners();let o=0,i=0;t instanceof MouseEvent?(o=t.clientX,i=t.clientY):(o=t.touches[0].clientX,i=t.touches[0].clientY),this._lastDraggingCoordinates={x:o,y:i},this.isDragging=!0}_onDrag(e,t){if(!this.isDragging)return void this._detachDragListeners();let o=0,i=0;t instanceof MouseEvent?(o=t.clientX,i=t.clientY):(o=t.touches[0].clientX,i=t.touches[0].clientY),t.preventDefault(),this.fire("drag",{deltaX:Math.round(o-this._lastDraggingCoordinates.x),deltaY:Math.round(i-this._lastDraggingCoordinates.y)}),this._lastDraggingCoordinates={x:o,y:i}}_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 Ou({view:e}){e.listenTo(e.element,"submit",((t,o)=>{o.preventDefault(),e.fire("submit")}),{useCapture:!0})}function Vu({keystrokeHandler:e,focusTracker:t,gridItems:o,numberOfColumns:i,uiLanguageDirection:n}){const s="number"==typeof i?()=>i:i;function r(e){return i=>{const n=o.find((e=>e.element===t.focusedElement)),s=o.getIndex(n),r=e(s,o);o.get(r).focus(),i.stopPropagation(),i.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"===n?l(e,t.length):a(e,t.length)))),e.set("arrowleft",r(((e,t)=>"rtl"===n?a(e,t.length):l(e,t.length)))),e.set("arrowup",r(((e,t)=>{let o=e-s();return o<0&&(o=e+s()*Math.floor(t.length/s()),o>t.length-1&&(o-=s())),o}))),e.set("arrowdown",r(((e,t)=>{let o=e+s();return o>t.length-1&&(o=e%s()),o})))}class Du extends Au{id;constructor(e){super(e),this.set("text",void 0),this.set("for",void 0),this.id=`ck-editor__label_${me()}`;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")}]})}}class Fu extends Au{constructor(e,t){super(e);const o=e.t,i=new Du;i.text=o("Help Contents. To close this dialog press ESC."),this.setTemplate({tag:"div",attributes:{class:["ck","ck-accessibility-help-dialog__content"],"aria-labelledby":i.id,role:"document",tabindex:-1},children:[Ke(document,"p",{},o("Below, you can find a list of keyboard shortcuts that can be used in the editor.")),...this._createCategories(Array.from(t.values())),i]})}focus(){this.element.focus()}_createCategories(e){return e.map((e=>{const t=[Ke(document,"h3",{},e.label),...Array.from(e.groups.values()).map((e=>this._createGroup(e))).flat()];return e.description&&t.splice(1,0,Ke(document,"p",{},e.description)),Ke(document,"section",{},t)}))}_createGroup(e){const t=e.keystrokes.sort(((e,t)=>e.label.localeCompare(t.label))).map((e=>this._createGroupRow(e))).flat(),o=[Ke(document,"dl",{},t)];return e.label&&o.unshift(Ke(document,"h4",{},e.label)),o}_createGroupRow(e){const t=this.locale.t,o=Ke(document,"dt"),i=Ke(document,"dd"),n=function(e){if("string"==typeof e)return[[e]];if("string"==typeof e[0])return[e];return e}(e.keystroke),s=[];for(const e of n)s.push(e.map(Mu).join(""));return o.innerHTML=e.label,i.innerHTML=s.join(", ")+(e.mayRequireFn&&Y.isMac?` ${t("(may require Fn)")}`:""),[o,i]}}function Mu(e){return Ut(e).split("+").map((e=>`${e}`)).join("+")}class Nu extends Au{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 e=(new DOMParser).parseFromString(this.content.trim(),"image/svg+xml").querySelector("svg");if(!e)throw new fe("ui-iconview-invalid-svg",this);const t=e.getAttribute("viewBox");t&&(this.viewBox=t);for(const{name:t,value:o}of Array.from(e.attributes))Nu.presentationalAttributeNames.includes(t)&&this.element.setAttribute(t,o);for(;this.element.firstChild;)this.element.removeChild(this.element.firstChild);for(;e.childNodes.length>0;)this.element.appendChild(e.childNodes[0])}}_colorFillPaths(){this.fillColor&&this.element.querySelectorAll(".ck-icon__fill").forEach((e=>{e.style.fill=this.fillColor}))}}class Bu extends Au{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")}]})}}class Lu extends Au{children;labelView;iconView;keystrokeView;_focusDelayed=null;constructor(e,t=new Bu){super(e);const o=this.bindTemplate,i=me();this.set("_ariaPressed",!1),this.set("_ariaChecked",!1),this.set("ariaLabel",void 0),this.set("ariaLabelledBy",`ck-editor__aria-label_${i}`),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 Nu,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 n={tag:"button",attributes:{class:["ck","ck-button",o.to("class"),o.if("isEnabled","ck-disabled",(e=>!e)),o.if("isVisible","ck-hidden",(e=>!e)),o.to("isOn",(e=>e?"ck-on":"ck-off")),o.if("withText","ck-button_with-text"),o.if("withKeystroke","ck-button_with-keystroke")],role:o.to("role"),type:o.to("type",(e=>e||"button")),tabindex:o.to("tabindex"),"aria-checked":o.to("_ariaChecked"),"aria-pressed":o.to("_ariaPressed"),"aria-label":o.to("ariaLabel"),"aria-labelledby":o.to("ariaLabelledBy"),"aria-disabled":o.if("isEnabled",!0,(e=>!e)),"data-cke-tooltip-text":o.to("_tooltipString"),"data-cke-tooltip-position":o.to("tooltipPosition")},children:this.children,on:{click:o.to((e=>{this.isEnabled?this.fire("execute"):e.preventDefault()}))}};this.bind("_ariaPressed").to(this,"isOn",this,"isToggleable",this,"role",((e,t,o)=>!(!t||zu(o))&&String(!!e))),this.bind("_ariaChecked").to(this,"isOn",this,"isToggleable",this,"role",((e,t,o)=>!(!t||!zu(o))&&String(!!e))),Y.isSafari&&(this._focusDelayed||(this._focusDelayed=co((()=>this.focus()),0)),n.on.mousedown=o.to((()=>{this._focusDelayed()})),n.on.mouseup=o.to((()=>{this._focusDelayed.cancel()}))),this.setTemplate(n)}render(){super.render(),this.icon&&this.children.add(this.iconView),this.on("change:icon",((e,t,o,i)=>{o&&!i?this.children.add(this.iconView,0):!o&&i&&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 Au;return e.setTemplate({tag:"span",attributes:{class:["ck","ck-button__keystroke"]},children:[{text:this.bindTemplate.to("keystroke",(e=>Ut(e)))}]}),e}_getTooltipString(e,t,o){return e?"string"==typeof e?e:(o&&(o=Ut(o)),e instanceof Function?e(t,o):`${t}${o?` (${o})`:""}`):""}}function zu(e){switch(e){case"radio":case"checkbox":case"option":case"switch":case"menuitemcheckbox":case"menuitemradio":return!0;default:return!1}}class ju extends Au{children;iconView;constructor(e,t={}){super(e);const o=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",o.to("class")]},children:this.children}),t.icon&&(this.iconView=new Nu,this.iconView.content=t.icon,this.children.add(this.iconView));const i=new Au(e);i.setTemplate({tag:"h2",attributes:{class:["ck","ck-form__header__label"],role:"presentation"},children:[{text:o.to("label")}]}),this.children.add(i)}}class qu extends(xe()){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 o=e.actions[t];"string"==typeof o&&(o=[o]);for(const i of o)e.keystrokeHandler.set(i,((e,o)=>{this[t](),o()}),e.keystrokeHandlerOptions)}this.on("forwardCycle",(()=>this.focusFirst()),{priority:"low"}),this.on("backwardCycle",(()=>this.focusLast()),{priority:"low"})}get first(){return this.focusables.find($u)||null}get last(){return this.focusables.filter($u).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,o)=>{const i=t.element===this.focusTracker.focusedElement;return i&&(e=o),i})),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 o=t();this.focusNext(),o!==t()&&e.stop()}),{priority:"low"}),this.listenTo(e,"backwardCycle",(e=>{const o=t();this.focusPrevious(),o!==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 o=this.current;if(null===o)return this[1===e?"first":"last"];let i=this.focusables.get(o),n=(o+t+e)%t;do{const o=this.focusables.get(n);if($u(o)){i=o;break}n=(n+t+e)%t}while(n!==o);return i}}function $u(e){return Hu(e)&&Ct(e.element)}function Hu(e){return!(!("focus"in e)||"function"!=typeof e.focus)}class Wu extends Au{children;keystrokes;focusCycler;_focusTracker;_focusables;constructor(e){super(e),this.children=this.createCollection(),this.keystrokes=new ro,this._focusTracker=new oo,this._focusables=new tu,this.focusCycler=new qu({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 Lu(this.locale);let o;for(o in e.on("execute",(()=>t.onExecute())),t.onCreate&&t.onCreate(e),t)"onExecute"!=o&&"onCreate"!=o&&e.set(o,t[o]);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)}))}}class Uu extends Au{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 Ku="screen-center",Gu="editor-center",Ju="editor-top-side",Zu="editor-top-center",Qu="editor-bottom-center",Yu="editor-above-center",Xu="editor-below-center",eh=yt("px");class th extends(Ru(Au)){parts;headerView;closeButtonView;actionsView;static defaultOffset=15;contentView;keystrokes;focusTracker;wasMoved=!1;_getCurrentDomRoot;_getViewportOffset;_focusables;_focusCycler;constructor(e,{getCurrentDomRoot:t,getViewportOffset:o,keystrokeHandlerOptions:i}){super(e);const n=this.bindTemplate,s=e.t;this.set("className",""),this.set("ariaLabel",s("Editor dialog")),this.set("isModal",!1),this.set("position",Ku),this.set("_isVisible",!1),this.set("_isTransparent",!1),this.set("_top",0),this.set("_left",0),this._getCurrentDomRoot=t,this._getViewportOffset=o,this.decorate("moveTo"),this.parts=this.createCollection(),this.keystrokes=new ro,this.focusTracker=new oo,this._focusables=new tu,this._focusCycler=new qu({focusables:this._focusables,focusTracker:this.focusTracker,keystrokeHandler:this.keystrokes,actions:{focusPrevious:"shift + tab",focusNext:"tab"},keystrokeHandlerOptions:i}),this.setTemplate({tag:"div",attributes:{class:["ck","ck-dialog-overlay",n.if("isModal","ck-dialog-overlay__transparent",(e=>!e)),n.if("_isVisible","ck-hidden",(e=>!e))],tabindex:"-1"},children:[{tag:"div",attributes:{tabindex:"-1",class:["ck","ck-dialog",n.if("isModal","ck-dialog_modal"),n.to("className")],role:"dialog","aria-label":n.to("ariaLabel"),style:{top:n.to("_top",(e=>eh(e))),left:n.to("_left",(e=>eh(e))),visibility:n.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:o})=>{this.wasMoved=!0,this.moveBy(t,o)})),this.listenTo(J.window,"resize",(()=>{this._isVisible&&!this.wasMoved&&this.updatePosition()})),this.listenTo(J.document,"scroll",(()=>{this._isVisible&&!this.wasMoved&&this.updatePosition()})),this.on("change:_isVisible",((e,t,o)=>{o&&(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:o=!0,content:i,actionButtons:n}){t&&(this.headerView=new ju(this.locale,{icon:e}),o&&(this.closeButtonView=this._createCloseButton(),this.headerView.children.add(this.closeButtonView)),this.headerView.label=t,this.ariaLabel=t,this.parts.add(this.headerView,0)),i&&(i instanceof Au&&(i=[i]),this.contentView=new Uu(this.locale),this.contentView.children.addMany(i),this.parts.add(this.contentView)),n&&(this.actionsView=new Wu(this.locale),this.actionsView.setButtons(n),this.parts.add(this.actionsView)),this._updateFocusCyclableItems()}focus(){this._focusCycler.focusFirst()}moveTo(e,t){const o=this._getViewportRect(),i=this._getDialogRect();e+i.width>o.right&&(e=o.right-i.width),e{var t;this._focusables.add(e),this.focusTracker.add(e.element),Hu(t=e)&&"focusCycler"in t&&t.focusCycler instanceof qu&&this._focusCycler.chain(e.focusCycler)}))}_createCloseButton(){const e=new Lu(this.locale),t=this.locale.t;return e.set({label:t("Close"),tooltip:!0,icon:$c}),e.on("execute",(()=>this.fire("close",{source:"closeButton"}))),e}}class oh extends fc{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(),oh._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",(()=>{oh._visibleDialogPlugin&&oh._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,o)=>{this.isOpen&&!this.view.isModal&&(this.view.focusTracker.isFocused?e.editing.view.focus():this.view.focus(),o())}))}_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:e,icon:t,title:o,hasCloseButton:i=!0,content:n,actionButtons:s,className:r,isModal:a,position:l,onHide:c,keystrokeHandlerOptions:d}){const u=this.editor;this.view=new th(u.locale,{getCurrentDomRoot:()=>u.editing.view.getDomRoot(u.model.document.selection.anchor.root.rootName),getViewportOffset:()=>u.ui.viewportOffset,keystrokeHandlerOptions:d});const h=this.view;h.on("close",(()=>{this.hide()})),u.ui.view.body.add(h),u.keystrokes.listenTo(h.element),l||(l=a?Ku:Gu),a&&this._lockBodyScroll(),h.set({position:l,_isVisible:!0,className:r,isModal:a}),h.setupParts({icon:t,title:o,hasCloseButton:i,content:n,actionButtons:s}),this.id=e,c&&(this._onHide=c),this.isOpen=!0,oh._visibleDialogPlugin=this}hide(){oh._visibleDialogPlugin&&oh._visibleDialogPlugin.fire(`hide:${oh._visibleDialogPlugin.id}`)}_hide(){if(!this.view)return;const e=this.editor,t=this.view;t.isModal&&this._unlockBodyScroll(),t.contentView&&t.contentView.reset(),e.ui.view.body.remove(t),e.ui.focusTracker.remove(t.element),e.keystrokes.stopListening(t.element),t.destroy(),e.editing.view.focus(),this.id=null,this.isOpen=!1,oh._visibleDialogPlugin=null}_lockBodyScroll(){document.documentElement.classList.add("ck-dialog-scroll-locked")}_unlockBodyScroll(){document.documentElement.classList.remove("ck-dialog-scroll-locked")}}class ih extends Lu{_checkIconHolderView=new nh;constructor(e,t=new Bu){super(e,t),this.set({hasCheckSpace:!1,_hasCheck:this.isToggleable});const o=this.bindTemplate;this.extendTemplate({attributes:{class:["ck-list-item-button",o.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,o)=>{const{children:i,_checkIconHolderView:n}=this;o?i.add(n,0):i.remove(n)}))}}class nh extends Au{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,o)=>{const{children:i,_checkIconView:n}=this;o&&!i.has(n)?i.add(n):!o&&i.has(n)&&i.remove(n)}))}_createCheckIconView(){const e=new Nu;return e.content=Hc,e.extendTemplate({attributes:{class:"ck-list-item-button__check-icon"}}),e}}class sh extends ih{constructor(e){super(e),this.set({withText:!0,withKeystroke:!0,tooltip:!1,role:"menuitem"}),this.extendTemplate({attributes:{class:["ck-menu-bar__menu__item__button"]}})}}class rh extends fc{contentView=null;static get requires(){return[oh]}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(Lu);return e.set({tooltip:!0,withText:!1,label:t("Accessibility help")}),e})),e.ui.componentFactory.add("menuBar:accessibilityHelp",(()=>{const e=this._createButton(sh);return e.label=t("Accessibility"),e})),e.keystrokes.set("Alt+0",((e,t)=>{this._toggleDialog(),t()})),this._setupRootLabels()}_createButton(e){const t=this.editor,o=t.plugins.get("Dialog"),i=new e(t.locale);return i.set({keystroke:"Alt+0",icon:zc,isToggleable:!0}),i.on("execute",(()=>this._toggleDialog())),i.bind("isOn").to(o,"id",(e=>"accessibilityHelp"===e)),i}_setupRootLabels(){const e=this.editor,t=e.editing.view,o=e.t;function i(e,t){const i=[t.getAttribute("aria-label"),o("Press %0 for help.",[Ut("Alt+0")])].filter((e=>e)).join(". ");e.setAttribute("aria-label",i,t)}e.ui.on("ready",(()=>{t.change((e=>{for(const o of t.document.roots)i(e,o)})),e.on("addRoot",((o,n)=>{const s=e.editing.view.document.getRoot(n.rootName);t.change((e=>i(e,s)))}),{priority:"low"})}))}_toggleDialog(){const e=this.editor,t=e.plugins.get("Dialog"),o=e.locale.t;this.contentView||(this.contentView=new Fu(e.locale,e.accessibility.keystrokeInfos)),"accessibilityHelp"===t.id?t.hide():t.show({id:"accessibilityHelp",className:"ck-accessibility-help-dialog",title:o("Accessibility help"),icon:zc,hasCloseButton:!0,content:this.contentView})}}class ah extends tu{locale;_bodyCollectionContainer;static _bodyWrapper;constructor(e,t=[]){super(t),this.locale=e}get bodyCollectionContainer(){return this._bodyCollectionContainer}attachToDom(){this._bodyCollectionContainer=new ou({tag:"div",attributes:{class:["ck","ck-reset_all","ck-body","ck-rounded-corners"],dir:this.locale.uiLanguageDirection,role:"application"},children:this}).render(),ah._bodyWrapper&&ah._bodyWrapper.isConnected||(ah._bodyWrapper=Ke(document,"div",{class:"ck-body-wrapper"}),document.body.appendChild(ah._bodyWrapper)),ah._bodyWrapper.appendChild(this._bodyCollectionContainer)}detachFromDom(){super.destroy(),this._bodyCollectionContainer&&this._bodyCollectionContainer.remove(),ah._bodyWrapper&&!ah._bodyWrapper.childElementCount&&(ah._bodyWrapper.remove(),delete ah._bodyWrapper)}}const lh=yt("px"),ch={top:-99999,left:-99999,name:"arrowless",config:{withArrow:!1}};class dh extends Au{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",lh),left:t.to("left",lh)}},children:this.content})}destroy(){this.hide(),super.destroy()}show(){this.isVisible=!0}hide(){this.isVisible=!1}attachTo(e){const t=uh(e.target);if(t&&!Ct(t))return!1;this.show();const o=dh.defaultPositions,i=Object.assign({},{element:this.element,positions:[o.southArrowNorth,o.southArrowNorthMiddleWest,o.southArrowNorthMiddleEast,o.southArrowNorthWest,o.southArrowNorthEast,o.northArrowSouth,o.northArrowSouthMiddleWest,o.northArrowSouthMiddleEast,o.northArrowSouthWest,o.northArrowSouthEast,o.viewportStickyNorth],limiter:J.document.body,fitInViewport:!0},e),n=dh._getOptimalPosition(i)||ch,s=parseInt(n.left),r=parseInt(n.top),a=n.name,l=n.config||{},{withArrow:c=!0}=l;return this.top=r,this.left=s,this.position=a,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=uh(e.target);const o=e.limiter?uh(e.limiter):J.document.body;if(this.listenTo(J.document,"scroll",((i,n)=>{const s=n.target,r=t&&s.contains(t),a=o&&s.contains(o);!r&&!a&&t&&o||this.attachTo(e)}),{useCapture:!0}),this.listenTo(J.window,"resize",(()=>{this.attachTo(e)})),!this._resizeObserver&&(t&&at(t)&&(t=t.parentElement),t)){const e=()=>{Ct(t)||this.unpin()};this._resizeObserver=new bt(t,e)}return!0}_stopPinning(){this.stopListening(J.document,"scroll"),this.stopListening(J.window,"resize"),this._resizeObserver&&(this._resizeObserver.destroy(),this._resizeObserver=null)}static generatePositions(e={}){const{sideOffset:t=dh.arrowSideOffset,heightOffset:o=dh.arrowHeightOffset,stickyVerticalOffset:i=dh.stickyVerticalOffset,config:n}=e;return{northWestArrowSouthWest:(e,o)=>({top:s(e,o),left:e.left-t,name:"arrow_sw",...n&&{config:n}}),northWestArrowSouthMiddleWest:(e,o)=>({top:s(e,o),left:e.left-.25*o.width-t,name:"arrow_smw",...n&&{config:n}}),northWestArrowSouth:(e,t)=>({top:s(e,t),left:e.left-t.width/2,name:"arrow_s",...n&&{config:n}}),northWestArrowSouthMiddleEast:(e,o)=>({top:s(e,o),left:e.left-.75*o.width+t,name:"arrow_sme",...n&&{config:n}}),northWestArrowSouthEast:(e,o)=>({top:s(e,o),left:e.left-o.width+t,name:"arrow_se",...n&&{config:n}}),northArrowSouthWest:(e,o)=>({top:s(e,o),left:e.left+e.width/2-t,name:"arrow_sw",...n&&{config:n}}),northArrowSouthMiddleWest:(e,o)=>({top:s(e,o),left:e.left+e.width/2-.25*o.width-t,name:"arrow_smw",...n&&{config:n}}),northArrowSouth:(e,t)=>({top:s(e,t),left:e.left+e.width/2-t.width/2,name:"arrow_s",...n&&{config:n}}),northArrowSouthMiddleEast:(e,o)=>({top:s(e,o),left:e.left+e.width/2-.75*o.width+t,name:"arrow_sme",...n&&{config:n}}),northArrowSouthEast:(e,o)=>({top:s(e,o),left:e.left+e.width/2-o.width+t,name:"arrow_se",...n&&{config:n}}),northEastArrowSouthWest:(e,o)=>({top:s(e,o),left:e.right-t,name:"arrow_sw",...n&&{config:n}}),northEastArrowSouthMiddleWest:(e,o)=>({top:s(e,o),left:e.right-.25*o.width-t,name:"arrow_smw",...n&&{config:n}}),northEastArrowSouth:(e,t)=>({top:s(e,t),left:e.right-t.width/2,name:"arrow_s",...n&&{config:n}}),northEastArrowSouthMiddleEast:(e,o)=>({top:s(e,o),left:e.right-.75*o.width+t,name:"arrow_sme",...n&&{config:n}}),northEastArrowSouthEast:(e,o)=>({top:s(e,o),left:e.right-o.width+t,name:"arrow_se",...n&&{config:n}}),southWestArrowNorthWest:e=>({top:r(e),left:e.left-t,name:"arrow_nw",...n&&{config:n}}),southWestArrowNorthMiddleWest:(e,o)=>({top:r(e),left:e.left-.25*o.width-t,name:"arrow_nmw",...n&&{config:n}}),southWestArrowNorth:(e,t)=>({top:r(e),left:e.left-t.width/2,name:"arrow_n",...n&&{config:n}}),southWestArrowNorthMiddleEast:(e,o)=>({top:r(e),left:e.left-.75*o.width+t,name:"arrow_nme",...n&&{config:n}}),southWestArrowNorthEast:(e,o)=>({top:r(e),left:e.left-o.width+t,name:"arrow_ne",...n&&{config:n}}),southArrowNorthWest:e=>({top:r(e),left:e.left+e.width/2-t,name:"arrow_nw",...n&&{config:n}}),southArrowNorthMiddleWest:(e,o)=>({top:r(e),left:e.left+e.width/2-.25*o.width-t,name:"arrow_nmw",...n&&{config:n}}),southArrowNorth:(e,t)=>({top:r(e),left:e.left+e.width/2-t.width/2,name:"arrow_n",...n&&{config:n}}),southArrowNorthMiddleEast:(e,o)=>({top:r(e),left:e.left+e.width/2-.75*o.width+t,name:"arrow_nme",...n&&{config:n}}),southArrowNorthEast:(e,o)=>({top:r(e),left:e.left+e.width/2-o.width+t,name:"arrow_ne",...n&&{config:n}}),southEastArrowNorthWest:e=>({top:r(e),left:e.right-t,name:"arrow_nw",...n&&{config:n}}),southEastArrowNorthMiddleWest:(e,o)=>({top:r(e),left:e.right-.25*o.width-t,name:"arrow_nmw",...n&&{config:n}}),southEastArrowNorth:(e,t)=>({top:r(e),left:e.right-t.width/2,name:"arrow_n",...n&&{config:n}}),southEastArrowNorthMiddleEast:(e,o)=>({top:r(e),left:e.right-.75*o.width+t,name:"arrow_nme",...n&&{config:n}}),southEastArrowNorthEast:(e,o)=>({top:r(e),left:e.right-o.width+t,name:"arrow_ne",...n&&{config:n}}),westArrowEast:(e,t)=>({top:e.top+e.height/2-t.height/2,left:e.left-t.width-o,name:"arrow_e",...n&&{config:n}}),eastArrowWest:(e,t)=>({top:e.top+e.height/2-t.height/2,left:e.right+o,name:"arrow_w",...n&&{config:n}}),viewportStickyNorth:(e,t,o)=>{const s=new ut(J.document.body).getIntersection(o.getVisible());if(!s)return null;const r=s.getVisible();return e.getIntersection(r)&&r.top-e.top-ithis._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,o)=>{this._updateLastFocusedEditableElement(),o?this._showBalloon():this._hideBalloon()})),e.ui.focusTracker.on("change:focusedElement",((e,t,o)=>{this._updateLastFocusedEditableElement(),o&&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 dh,o=this._createBadgeContent();return t.content.add(o),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?function(e,t){return mh(e,t,((e,o)=>e.left+e.width-o.width-t.horizontalOffset))}(this._lastFocusedEditableElement,e):function(e,t){return mh(e,t,(e=>e.left+t.horizontalOffset))}(this._lastFocusedEditableElement,e);return{target:this._lastFocusedEditableElement,positions:[t]}}_updateLastFocusedEditableElement(){const e=this.editor,t=e.ui.focusTracker.isFocused,o=e.ui.focusTracker.focusedElement;if(!t||!o)return void(this._lastFocusedEditableElement=null);const i=Array.from(e.ui.getEditableElementsNames()).map((t=>e.ui.getEditableElement(t)));i.includes(o)?this._lastFocusedEditableElement=o:this._lastFocusedEditableElement=i[0]}}function mh(e,t,o){return(i,n)=>{const s=new ut(e);if(s.width<350||s.height<50)return null;let r;r="inside"===t.position?s.bottom-n.height:s.bottom-n.height/2,r-=t.verticalOffset;const a=o(s,n),l=i.clone().moveTo(a,r).getIntersection(n.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]}]:[],o],on:{dragstart:i.to((e=>e.preventDefault()))}}]})}}class fh extends Lu{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 Au;return e.setTemplate({tag:"span",attributes:{class:["ck","ck-button__toggle"]},children:[{tag:"span",attributes:{class:["ck","ck-button__toggle__inner"]}}]}),e}}class bh extends(yh(Lu)){}class wh extends(yh(ih)){}function yh(e){return class extends e{_fileInputView;constructor(...e){super(...e),this._fileInputView=new _h(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)}}}class _h extends Au{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()}}class kh extends Au{buttonView;children;constructor(e,t){super(e);const o=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",o.if("isCollapsed","ck-collapsible_collapsed")]},children:[this.buttonView,{tag:"div",attributes:{class:["ck","ck-collapsible__children"],role:"region",hidden:o.if("isCollapsed","hidden"),"aria-labelledby":o.to("_collapsibleAriaLabelUid")},children:this.children}]})}render(){super.render(),this._collapsibleAriaLabelUid=this.buttonView.labelView.element.id}focus(){this.buttonView.focus()}_createButtonView(){const e=new Lu(this.locale),t=e.bindTemplate;return e.set({withText:!0,icon:Uc}),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 vh(e,t){const o=e.t,i={Black:o("Black"),"Dim grey":o("Dim grey"),Grey:o("Grey"),"Light grey":o("Light grey"),White:o("White"),Red:o("Red"),Orange:o("Orange"),Yellow:o("Yellow"),"Light green":o("Light green"),Green:o("Green"),Aquamarine:o("Aquamarine"),Turquoise:o("Turquoise"),"Light blue":o("Light blue"),Blue:o("Blue"),Purple:o("Purple")};return t.map((e=>{const t=i[e.label];return t&&t!=e.label&&(e.label=t),e}))}function Ch(e){return e.map(Ah).filter((e=>!!e))}function Ah(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}`}}}}class xh extends Lu{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%)"}}class Eh extends Au{columns;items;focusTracker;keystrokes;constructor(e,t){super(e);const o=t&&t.colorDefinitions?t.colorDefinitions:[];this.columns=t?.columns||5;const i={gridTemplateColumns:`repeat( ${this.columns}, 1fr)`};this.set("selectedColor",void 0),this.items=this.createCollection(),this.focusTracker=new oo,this.keystrokes=new ro,this.items.on("add",((e,t)=>{t.isOn=t.color===this.selectedColor})),o.forEach((e=>{const t=new xh;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:i}}),this.on("change:selectedColor",((e,t,o)=>{for(const e of this.items)e.isOn=e.color===o}))}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),Vu({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 Th(e,t){if(!e)return"";const o=Ph(e);if(!o)return"";if(o.space===t)return e;if(i=o,!Object.keys(xd).includes(i.space))return"";var i;const n=xd[o.space][t];if(!n)return"";return 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""}}(n("hex"===o.space?o.hexValue:o.values),t)}function Ph(e){if(e.startsWith("#")){const t=ad(e);return{space:"hex",values:t.values,hexValue:e,alpha:t.alpha}}const t=ad(e);return t.space?t:null}class Sh extends Au{fieldView;labelView;statusView;fieldWrapperChildren;constructor(e,t){super(e);const o=`ck-labeled-field-view-${me()}`,i=`ck-labeled-field-view-status-${me()}`;this.fieldView=t(this,o,i),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(o),this.statusView=this._createStatusView(i),this.fieldWrapperChildren=this.createCollection([this.fieldView,this.labelView]),this.bind("_statusText").to(this,"errorText",this,"infoText",((e,t)=>e||t));const n=this.bindTemplate;this.setTemplate({tag:"div",attributes:{class:["ck","ck-labeled-field-view",n.to("class"),n.if("isEnabled","ck-disabled",(e=>!e)),n.if("isEmpty","ck-labeled-field-view_empty"),n.if("isFocused","ck-labeled-field-view_focused"),n.if("placeholder","ck-labeled-field-view_placeholder"),n.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 Du(this.locale);return t.for=e,t.bind("text").to(this,"label"),t}_createStatusView(e){const t=new Au(this.locale),o=this.bindTemplate;return t.setTemplate({tag:"div",attributes:{class:["ck","ck-labeled-field-view__status",o.if("errorText","ck-labeled-field-view__status_error"),o.if("_statusText","ck-hidden",(e=>!e))],id:e,role:o.if("errorText","alert")},children:[{text:o.to("_statusText")}]}),t}focus(e){this.fieldView.focus(e)}}class Ih extends Au{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 oo,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,o)=>{this._setDomElementValue(o),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:""}}class Rh extends Ih{constructor(e){super(e),this.set("inputMode","text");const t=this.bindTemplate;this.extendTemplate({attributes:{inputmode:t.to("inputMode")}})}}class Oh extends Rh{constructor(e){super(e),this.extendTemplate({attributes:{type:"text",class:["ck-input-text"]}})}}class Vh extends Rh{constructor(e,{min:t,max:o,step:i}={}){super(e);const n=this.bindTemplate;this.set("min",t),this.set("max",o),this.set("step",i),this.extendTemplate({attributes:{type:"number",class:["ck-input-number"],min:n.to("min"),max:n.to("max"),step:n.to("step")}})}}class Dh extends Au{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():be("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()}}}class Fh extends Au{buttonView;panelView;focusTracker;keystrokes;listView;toolbarView;menuView;constructor(e,t,o){super(e);const i=this.bindTemplate;this.buttonView=t,this.panelView=o,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 ro,this.focusTracker=new oo,this.setTemplate({tag:"div",attributes:{class:["ck","ck-dropdown",i.to("class"),i.if("isEnabled","ck-disabled",(e=>!e))],id:i.to("id"),"aria-describedby":i.to("ariaDescribedById")},children:[t,o]}),t.extendTemplate({attributes:{class:["ck-dropdown__button"],"data-cke-tooltip-disabled":i.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",((e,t,o)=>{if(o)if("auto"===this.panelPosition){const e=Fh._getOptimalPosition({element:this.panelView.element,target:this.buttonView.element,fitInViewport:!0,positions:this._panelPositions});this.panelView.position=e?e.name:this._defaultPanelPositionName}else this.panelView.position=this.panelPosition})),this.keystrokes.listenTo(this.element);const e=(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",e),this.keystrokes.set("esc",e)}focus(){this.buttonView.focus()}get _panelPositions(){const{south:e,north:t,southEast:o,southWest:i,northEast:n,northWest:s,southMiddleEast:r,southMiddleWest:a,northMiddleEast:l,northMiddleWest:c}=Fh.defaultPanelPositions;return"rtl"!==this.locale.uiLanguageDirection?[o,i,r,a,e,n,s,l,c,t]:[i,o,a,r,e,s,n,c,l,t]}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=At}class Mh extends Lu{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 Nu;return e.content=Uc,e.extendTemplate({attributes:{class:"ck-dropdown__arrow"}}),e}}class Nh extends Au{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()}}class Bh extends Au{constructor(e){super(e),this.setTemplate({tag:"li",attributes:{class:["ck","ck-list__separator"]}})}}class Lh extends Au{labelView;items;children;constructor(e,t=new Du){super(e);const o=this.bindTemplate,i=new zh(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,i]),i.set({role:"group",ariaLabelledBy:t.id}),i.focusTracker.destroy(),i.keystrokes.destroy(),this.items=i.items,this.setTemplate({tag:"li",attributes:{role:"presentation",class:["ck","ck-list__group",o.if("isVisible","ck-hidden",(e=>!e))]},children:this.children})}focus(){if(this.items){const e=this.items.find((e=>!(e instanceof Bh)));e&&e.focus()}}}class zh extends Au{focusables;items;focusTracker;keystrokes;_focusCycler;_listItemGroupToChangeListeners=new WeakMap;constructor(e){super(e);const t=this.bindTemplate;this.focusables=new tu,this.items=this.createCollection(),this.focusTracker=new oo,this.keystrokes=new ro,this._focusCycler=new qu({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 Lh?this._registerFocusableItemsGroup(e):e instanceof Nh&&this._registerFocusableListItem(e);this.items.on("change",((e,t)=>{for(const e of t.removed)e instanceof Lh?this._deregisterFocusableItemsGroup(e):e instanceof Nh&&this._deregisterFocusableListItem(e);for(const e of Array.from(t.added).reverse())e instanceof Lh?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,o)=>{for(const e of o.removed)this._deregisterFocusableListItem(e);for(const t of Array.from(o.added).reverse())this._registerFocusableListItem(t,this.items.getIndex(e)+o.index)}}_registerFocusableItemsGroup(e,t){Array.from(e.items).forEach(((e,o)=>{const i=void 0!==t?t+o:void 0;this._registerFocusableListItem(e,i)}));const o=this._getOnGroupItemsChangeCallback(e);this._listItemGroupToChangeListeners.set(e,o),e.items.on("change",o)}_deregisterFocusableItemsGroup(e){for(const t of e.items)this._deregisterFocusableListItem(t);e.items.off("change",this._listItemGroupToChangeListeners.get(e)),this._listItemGroupToChangeListeners.delete(e)}}class jh extends Au{constructor(e){super(e),this.setTemplate({tag:"span",attributes:{class:["ck","ck-toolbar__separator"]}})}}class qh extends Au{constructor(e){super(e),this.setTemplate({tag:"span",attributes:{class:["ck","ck-toolbar__line-break"]}})}}function $h(e){if(Array.isArray(e))return{items:e,removeItems:[]};const t={items:[],removeItems:[]};return e?{...t,...e}:t}const Hh=(()=>({alignLeft:jc,bold:qc,importExport:'',paragraph:'',plus:'',text:'',threeVerticalDots:id,pilcrow:'',dragIndicator:''}))();class Wh extends Au{options;items;focusTracker;keystrokes;itemsView;children;focusables;_focusCycler;_behavior;constructor(e,t){super(e);const o=this.bindTemplate,i=this.t;this.options=t||{},this.set("ariaLabel",i("Editor toolbar")),this.set("maxWidth","auto"),this.set("role","toolbar"),this.set("isGrouping",!!this.options.shouldGroupWhenFull),this.items=this.createCollection(),this.focusTracker=new oo,this.keystrokes=new ro,this.set("class",void 0),this.set("isCompact",!1),this.set("isVertical",!1),this.itemsView=new Uh(e),this.children=this.createCollection(),this.children.add(this.itemsView),this.focusables=this.createCollection();const n="rtl"===e.uiLanguageDirection;this._focusCycler=new qu({focusables:this.focusables,focusTracker:this.focusTracker,keystrokeHandler:this.keystrokes,actions:{focusPrevious:[n?"arrowright":"arrowleft","arrowup"],focusNext:[n?"arrowleft":"arrowright","arrowdown"]}});const s=["ck","ck-toolbar",o.to("class"),o.if("isCompact","ck-toolbar_compact"),o.if("isGrouping","ck-toolbar_grouping"),o.if("isVertical","ck-toolbar_vertical")];var r;this.options.shouldGroupWhenFull&&this.options.isFloating&&s.push("ck-toolbar_floating"),this.setTemplate({tag:"div",attributes:{class:s,role:o.to("role"),"aria-label":o.to("ariaLabel"),style:{maxWidth:o.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 Gh(this):new Kh(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,o){this.items.addMany(this._buildItemsFromConfig(e,t,o))}switchBehavior(e){this._behavior.type!==e&&(this._behavior.destroy(),this.itemsView.children.clear(),this.focusables.clear(),"dynamic"===e?(this._behavior=new Gh(this),this._behavior.render(this),this._behavior.refreshItems()):(this._behavior=new Kh(this),this._behavior.render(this)))}_buildItemsFromConfig(e,t,o){const i=$h(e),n=o||i.removeItems;return this._cleanItemsConfiguration(i.items,t,n).map((e=>s(e)?this._createNestedToolbarDropdown(e,t,n):"|"===e?new jh:"-"===e?new qh:t.create(e))).filter((e=>!!e))}_cleanItemsConfiguration(e,t,o){const i=e.filter(((e,i,n)=>"|"===e||-1===o.indexOf(e)&&("-"===e?!this.options.shouldGroupWhenFull||(be("toolbarview-line-break-ignored-when-grouping-items",n),!1):!(!s(e)&&!t.has(e))||(be("toolbarview-item-unavailable",{item:e}),!1))));return this._cleanSeparatorsAndLineBreaks(i)}_cleanSeparatorsAndLineBreaks(e){const t=e=>"-"!==e&&"|"!==e,o=e.length,i=e.findIndex(t);if(-1===i)return[];const n=o-e.slice().reverse().findIndex(t);return e.slice(i,n).filter(((e,o,i)=>{if(t(e))return!0;return!(o>0&&i[o-1]===e)}))}_createNestedToolbarDropdown(e,t,o){let{label:i,icon:n,items:s,tooltip:r=!0,withText:a=!1}=e;if(s=this._cleanItemsConfiguration(s,t,o),!s.length)return null;const l=Zh(this.locale);return i||be("toolbarview-nested-toolbar-dropdown-missing-label",e),l.class="ck-toolbar__nested-toolbar-dropdown",l.buttonView.set({label:i,tooltip:r,withText:!!a}),!1!==n?l.buttonView.icon=Hh[n]||n||id:l.buttonView.withText=!0,Qh(l,(()=>l.toolbarView._buildItemsFromConfig(s,t,o))),l}}class Uh extends Au{children;constructor(e){super(e),this.children=this.createCollection(),this.setTemplate({tag:"div",attributes:{class:["ck","ck-toolbar__items"]},children:this.children})}}class Kh{type="static";constructor(e){e.isGrouping=!1,e.itemsView.children.bindTo(e.items).using((e=>e)),e.focusables.bindTo(e.items).using((e=>Hu(e)?e:null))}render(){}destroy(){}}class Gh{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 o=t.index,i=Array.from(t.added);for(const e of t.removed)o>=this.ungroupedItems.length?this.groupedItems.remove(e):this.ungroupedItems.remove(e);for(let e=o;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;ti.right-this.cachedPadding:o.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 jh),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,o=Zh(e);return o.class="ck-toolbar__grouped-dropdown",o.panelPosition="ltr"===e.uiLanguageDirection?"sw":"se",Qh(o,this.groupedItems),o.buttonView.set({label:t("Show more items"),tooltip:!0,tooltipPosition:"rtl"===e.uiLanguageDirection?"se":"sw",icon:id}),o}_updateFocusCyclableItems(){this.viewFocusables.clear(),this.ungroupedItems.map((e=>{Hu(e)&&this.viewFocusables.add(e)})),this.groupedItems.length&&this.viewFocusables.add(this.groupedItemsDropdown)}}class Jh extends Au{children;actionView;arrowView;keystrokes;focusTracker;constructor(e,t){super(e);const o=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 ro,this.focusTracker=new oo,this.setTemplate({tag:"div",attributes:{class:["ck","ck-splitbutton",o.to("class"),o.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 Lu;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 Lu,t=e.bindTemplate;return e.icon=Uc,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 Zh(e,t=Mh){const o="function"==typeof t?new t(e):t,i=new Dh(e),n=new Fh(e,o,i);return o.bind("isEnabled").to(n),o instanceof Jh?o.arrowView.bind("isOn").to(n,"isOpen"):o.bind("isOn").to(n,"isOpen"),function(e){(function(e){Su({emitter:e,activator:()=>e.isRendered&&e.isOpen,callback:()=>{e.isOpen=!1},contextElements:()=>[e.element,...om(e.focusTracker).filter((t=>!e.element.contains(t)))]})})(e),function(e){e.on("execute",(t=>{t.source instanceof fh||(e.isOpen=!1)}))}(e),function(e){e.focusTracker.on("change:isFocused",((t,o,i)=>{!i&&e.isOpen&&(e.isOpen=!1)}))}(e),function(e){e.keystrokes.set("arrowdown",((t,o)=>{e.isOpen&&(e.panelView.focus(),o())})),e.keystrokes.set("arrowup",((t,o)=>{e.isOpen&&(e.panelView.focusLast(),o())}))}(e),function(e){e.on("change:isOpen",((t,o,i)=>{if(i)return;e.focusTracker.elements.some((e=>e.contains(J.document.activeElement)))&&e.buttonView.focus()}))}(e),function(e){e.on("change:isOpen",((t,o,i)=>{i&&e.panelView.focus()}),{priority:"low"})}(e)}(n),n}function Qh(e,t,o={}){e.extendTemplate({attributes:{class:["ck-toolbar-dropdown"]}}),e.isOpen?Yh(e,t,o):e.once("change:isOpen",(()=>Yh(e,t,o)),{priority:"highest"}),o.enableActiveItemFocusOnDropdownOpen&&tm(e,(()=>e.toolbarView.items.find((e=>e.isOn))))}function Yh(e,t,o){const i=e.locale,n=i.t,s=e.toolbarView=new Wh(i),r="function"==typeof t?t():t;s.ariaLabel=o.ariaLabel||n("Dropdown toolbar"),o.maxWidth&&(s.maxWidth=o.maxWidth),o.class&&(s.class=o.class),o.isCompact&&(s.isCompact=o.isCompact),o.isVertical&&(s.isVertical=!0),r instanceof tu?s.items.bindTo(r).using((e=>e)):s.items.addMany(r),e.panelView.children.add(s),e.focusTracker.add(s),s.items.delegate("execute").to(e)}function Xh(e,t,o={}){e.isOpen?em(e,t,o):e.once("change:isOpen",(()=>em(e,t,o)),{priority:"highest"}),tm(e,(()=>e.listView.items.find((e=>e instanceof Nh&&e.children.first.isOn))))}function em(e,t,o){const i=e.locale,n=e.listView=new zh(i),s="function"==typeof t?t():t;n.ariaLabel=o.ariaLabel,n.role=o.role,im(e,n.items,s,i),e.panelView.children.add(n),n.items.delegate("execute").to(e)}function tm(e,t){e.on("change:isOpen",(()=>{if(!e.isOpen)return;const o=t();o&&("function"==typeof o.focus?o.focus():be("ui-dropdown-focus-child-on-open-child-missing-focus",{view:o}))}),{priority:ge.low-10})}function om(e){return[...e.elements,...e.externalViews.flatMap((e=>om(e.focusTracker)))]}function im(e,t,o,i){!function(e){let t=0;const o=e=>e instanceof Nh&&e.children.first instanceof ih?e.children.first:null,i=e=>{const t=o(e);return t&&t.isToggleable?t:null},n=t=>{for(const i of e){const e=o(i);e&&(e.hasCheckSpace=t)}};e.on("change",((e,s)=>{const r=t>0;for(const e of s.removed)i(e)&&t--;for(const e of s.added){const i=o(e);i&&(i.isToggleable&&t++,i.hasCheckSpace=t>0)}const a=t>0;r!==a&&n(a)}))}(t),t.bindTo(o).using((t=>{if("separator"===t.type)return new Bh(i);if("group"===t.type){const o=new Lh(i);return o.set({label:t.label}),im(e,o.items,t.items,i),o.items.delegate("execute").to(e),o}if("button"===t.type||"switchbutton"===t.type){const e="menuitemcheckbox"===t.model.role||"menuitemradio"===t.model.role,o=new Nh(i);let n;return"button"===t.type?(n=new ih(i,t.labelView),n.set({isToggleable:e})):n=new fh(i),n.bind(...Object.keys(t.model)).to(t.model),n.delegate("execute").to(o),o.children.add(n),o}return null}))}const nm=(e,t,o)=>{const i=new Oh(e.locale);return i.set({id:t,ariaDescribedById:o}),i.bind("isReadOnly").to(e,"isEnabled",(e=>!e)),i.bind("hasError").to(e,"errorText",(e=>!!e)),i.on("input",(()=>{e.errorText=null})),e.bind("isEmpty","isFocused","placeholder").to(i),i},sm=(e,t,o)=>{const i=new Vh(e.locale);return i.set({id:t,ariaDescribedById:o,inputMode:"numeric"}),i.bind("isReadOnly").to(e,"isEnabled",(e=>!e)),i.bind("hasError").to(e,"errorText",(e=>!!e)),i.on("input",(()=>{e.errorText=null})),e.bind("isEmpty","isFocused","placeholder").to(i),i},rm=(e,t,o)=>{const i=Zh(e.locale);return i.set({id:t,ariaDescribedById:o}),i.bind("isEnabled").to(e),i};class am extends Au{hexInputRow;_debounceColorPickerEvent;_config;constructor(e,t={}){super(e),this.set({color:"",_hexColor:""}),this.hexInputRow=this._createInputRow();const o=this.createCollection();t.hideInput||o.add(this.hexInputRow),this.setTemplate({tag:"div",attributes:{class:["ck","ck-color-picker"],tabindex:-1},children:o}),this._config=t,this._debounceColorPickerEvent=zo((e=>{this.set("color",e),this.fire("colorSelected",{color:this.color})}),150,{leading:!0}),this.on("set:color",((e,t,o)=>{e.return=Th(o,this._config.format||"hsl")})),this.on("change:color",(()=>{this._hexColor=lm(this.color)})),this.on("change:_hexColor",(()=>{document.activeElement!==this.picker&&this.picker.setAttribute("color",this._hexColor),lm(this.color)!=lm(this._hexColor)&&(this.color=this._hexColor)}))}render(){var e,t;if(super.render(),e="hex-color-picker",t=eu,void 0===customElements.get(e)&&customElements.define(e,t),this.picker=J.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(){if(!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 cm(e)));this.slidersView=this.createCollection(),e.forEach((e=>{this.slidersView.add(e)}))}_createInputRow(){const e=this._createColorInput();return new um(this.locale,e)}_createColorInput(){const e=new Sh(this.locale,nm),{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=hm(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 lm(e){let t=function(e){if(!e)return"";const t=Ph(e);return t?"hex"===t.space?t.hexValue:Th(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()}class cm extends Au{constructor(e){super(),this.element=e}focus(){this.element.focus()}}class dm extends Au{constructor(e){super(e),this.setTemplate({tag:"div",attributes:{class:["ck","ck-color-picker__hash-view"]},children:"#"})}}class um extends Au{children;inputView;constructor(e,t){super(e),this.inputView=t,this.children=this.createCollection([new dm,this.inputView]),this.setTemplate({tag:"div",attributes:{class:["ck","ck-color-picker__row"]},children:this.children})}getParsedColor(){return hm(this.inputView.fieldView.element.value)}}function hm(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}class mm extends(Be(eo)){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))}}class gm extends Au{items;colorDefinitions;focusTracker;columns;documentColors;documentColorsCount;staticColorsGrid;documentColorsGrid;colorPickerButtonView;removeColorButtonView;_focusables;_documentColorsLabel;_removeButtonLabel;_colorPickerLabel;constructor(e,{colors:t,columns:o,removeButtonLabel:i,documentColorsLabel:n,documentColorsCount:s,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=o,this.documentColors=new mm,this.documentColorsCount=s,this._focusables=l,this._removeButtonLabel=i,this._colorPickerLabel=r,this._documentColorsLabel=n,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 o=e.document,i=this.documentColorsCount;this.documentColors.clear();for(const n of o.getRoots()){const o=e.createRangeIn(n);for(const e of o.getItems())if(e.is("$textProxy")&&e.hasAttribute(t)&&(this._addColorToDocumentColors(e.getAttribute(t)),this.documentColors.length>=i))return}}updateSelectedColors(){const e=this.documentColorsGrid,t=this.staticColorsGrid,o=this.selectedColor;t.selectedColor=o,e&&(e.selectedColor=o)}render(){if(super.render(),this.staticColorsGrid=this._createStaticColorsGrid(),this.items.add(this.staticColorsGrid),this.documentColorsCount){const e=ou.bind(this.documentColors,this.documentColors),t=new Au(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 Lu,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 Lu;return e.set({withText:!0,icon:'',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 Eh(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=ou.bind(this.documentColors,this.documentColors),t=new Eh(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 xh;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,o,i)=>{i&&(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}})}}class pm extends Au{items;colorPickerView;saveButtonView;cancelButtonView;actionBarView;focusTracker;keystrokes;_focusables;_colorPickerViewConfig;constructor(e,{focusTracker:t,focusables:o,keystrokes:i,colorPickerViewConfig:n}){super(e),this.items=this.createCollection(),this.focusTracker=t,this.keystrokes=i,this.set("isVisible",!1),this.set("selectedColor",void 0),this._focusables=o,this._colorPickerViewConfig=n;const s=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",s.if("isVisible","ck-hidden",(e=>!e))]},children:this.items})}render(){super.render();const e=new am(this.locale,{...this._colorPickerViewConfig});this.colorPickerView=e,this.colorPickerView.render(),this.selectedColor&&(e.color=this.selectedColor),this.listenTo(this,"change:selectedColor",((t,o,i)=>{e.color=i})),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 o=new Au,i=this.createCollection();return i.add(e),i.add(t),o.setTemplate({tag:"div",attributes:{class:["ck","ck-color-selector_action-bar"]},children:i}),o}_createActionButtons(){const e=this.locale,t=e.t,o=new Lu(e),i=new Lu(e);return o.set({icon:Hc,class:"ck-button-save",type:"button",withText:!1,label:t("Accept")}),i.set({icon:$c,class:"ck-button-cancel",type:"button",withText:!1,label:t("Cancel")}),o.on("execute",(()=>{this.colorPickerView.isValid()&&this.fire("execute",{source:"colorPickerSaveButton",value:this.selectedColor})})),i.on("execute",(()=>{this.fire("colorPicker:cancel")})),{saveButtonView:o,cancelButtonView:i}}_executeUponColorChange(){this.colorPickerView.on("colorSelected",((e,t)=>{this.fire("execute",{value:t.color,source:"colorPicker"}),this.set("selectedColor",t.color)}))}}class fm extends Au{focusTracker;keystrokes;items;colorGridsFragmentView;colorPickerFragmentView;_focusCycler;_focusables;_colorPickerViewConfig;constructor(e,{colors:t,columns:o,removeButtonLabel:i,documentColorsLabel:n,documentColorsCount:s,colorPickerLabel:r,colorPickerViewConfig:a}){super(e),this.items=this.createCollection(),this.focusTracker=new oo,this.keystrokes=new ro,this._focusables=new tu,this._colorPickerViewConfig=a,this._focusCycler=new qu({focusables:this._focusables,focusTracker:this.focusTracker,keystrokeHandler:this.keystrokes,actions:{focusPrevious:"shift + tab",focusNext:"tab"}}),this.colorGridsFragmentView=new gm(e,{colors:t,columns:o,removeButtonLabel:i,documentColorsLabel:n,documentColorsCount:s,colorPickerLabel:r,focusTracker:this.focusTracker,focusables:this._focusables}),this.colorPickerFragmentView=new pm(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,o)=>{this.colorGridsFragmentView.set("selectedColor",o),this.colorPickerFragmentView.set("selectedColor",o)})),this.colorGridsFragmentView.on("change:selectedColor",((e,t,o)=>{this.set("selectedColor",o)})),this.colorPickerFragmentView.on("change:selectedColor",((e,t,o)=>{this.set("selectedColor",o)})),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))}}class bm{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(wm(e),{callback:t,originalName:e})}create(e){if(!this.has(e))throw new fe("componentfactory-item-missing",this,{name:e});return this._components.get(wm(e)).callback(this.editor.locale)}has(e){return this._components.has(wm(e))}}function wm(e){return String(e).toLowerCase()}const ym="ck-tooltip";class _m extends(et()){tooltipTextView;balloonPanelView;static defaultBalloonPositions=dh.generatePositions({heightOffset:5,sideOffset:13});_currentElementWithTooltip=null;_currentTooltipPosition=null;_mutationObserver=null;_pinTooltipDebounced;_unpinTooltipDebounced;_watchdogExcluded;static _editors=new Set;static _instance=null;constructor(e){if(super(),_m._editors.add(e),_m._instance)return _m._instance;_m._instance=this,this.tooltipTextView=new Au(e.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 dh(e.locale),this.balloonPanelView.class=ym,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=zo(this._pinTooltip,600),this._unpinTooltipDebounced=zo(this._unpinTooltip,400),this.listenTo(J.document,"keydown",this._onKeyDown.bind(this),{useCapture:!0}),this.listenTo(J.document,"mouseenter",this._onEnterOrFocus.bind(this),{useCapture:!0}),this.listenTo(J.document,"mouseleave",this._onLeaveOrBlur.bind(this),{useCapture:!0}),this.listenTo(J.document,"focus",this._onEnterOrFocus.bind(this),{useCapture:!0}),this.listenTo(J.document,"blur",this._onLeaveOrBlur.bind(this),{useCapture:!0}),this.listenTo(J.document,"scroll",this._onScroll.bind(this),{useCapture:!0}),this._watchdogExcluded=!0}destroy(e){const t=e.ui.view&&e.ui.view.body;_m._editors.delete(e),this.stopListening(e.ui),t&&t.has(this.balloonPanelView)&&t.remove(this.balloonPanelView),_m._editors.size||(this._unpinTooltip(),this.balloonPanelView.destroy(),this.stopListening(),_m._instance=null)}static getPositioningFunctions(e){const t=_m.defaultBalloonPositions;return{s:[t.southArrowNorth,t.southArrowNorthEast,t.southArrowNorthWest],n:[t.northArrowSouth],e:[t.eastArrowWest],w:[t.westArrowEast],sw:[t.southArrowNorthEast],se:[t.southArrowNorthWest]}[e]}_onKeyDown(e,t){"Escape"===t.key&&this._currentElementWithTooltip&&(this._unpinTooltip(),t.stopPropagation())}_onEnterOrFocus(e,{target:t}){const o=km(t);o?o!==this._currentElementWithTooltip?(this._unpinTooltip(),"focus"===e.name&&!o.matches(":hover")||o.matches("[data-cke-tooltip-instant]")?this._pinTooltip(o,vm(o)):this._pinTooltipDebounced(o,vm(o))):this._unpinTooltipDebounced.cancel():"focus"===e.name&&this._unpinTooltip()}_onLeaveOrBlur(e,{target:t,relatedTarget:o}){if("mouseleave"===e.name){if(!L(t))return;const e=this.balloonPanelView.element,i=e&&(e===o||e.contains(o)),n=!i&&t===e;if(i)return void this._unpinTooltipDebounced.cancel();if(!n&&this._currentElementWithTooltip&&t!==this._currentElementWithTooltip)return;const s=km(t),r=km(o);(n||s&&s!==r)&&(this._pinTooltipDebounced.cancel(),this._currentElementWithTooltip&&this._currentElementWithTooltip.matches("[data-cke-tooltip-instant]")||s&&s.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(e,{text:t,position:o,cssClass:i}){this._unpinTooltip();const n=to(_m._editors.values()).ui.view.body;n.has(this.balloonPanelView)||n.add(this.balloonPanelView),this.tooltipTextView.text=t,this.balloonPanelView.class=[ym,i].filter((e=>e)).join(" "),this.balloonPanelView.pin({target:e,positions:_m.getPositioningFunctions(o)}),this._mutationObserver.attach(e);for(const e of _m._editors)this.listenTo(e.ui,"update",this._updateTooltipPosition.bind(this),{priority:"low"});this._currentElementWithTooltip=e,this._currentTooltipPosition=o}_unpinTooltip(){this._unpinTooltipDebounced.cancel(),this._pinTooltipDebounced.cancel(),this.balloonPanelView.unpin();for(const e of _m._editors)this.stopListening(e.ui,"update");this._currentElementWithTooltip=null,this._currentTooltipPosition=null,this.tooltipTextView.text="",this._mutationObserver.detach()}_updateTooltipPosition(){if(!this._currentElementWithTooltip)return;const e=vm(this._currentElementWithTooltip);Ct(this._currentElementWithTooltip)&&e.text?this.balloonPanelView.pin({target:this._currentElementWithTooltip,positions:_m.getPositioningFunctions(e.position)}):this._unpinTooltip()}}function km(e){return L(e)?e.closest("[data-cke-tooltip-text]:not([data-cke-tooltip-disabled])"):null}function vm(e){return{text:e.dataset.ckeTooltipText,position:e.dataset.ckeTooltipPosition||"s",cssClass:e.dataset.ckeTooltipClass||""}}class Cm extends hh{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=xm(this.editor.config.get("licenseKey"));return Boolean(e&&this.licenseTypeMessage[e])}_createBadgeContent(){const e=xm(this.editor.config.get("licenseKey"));return new Am(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}}}class Am extends Au{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 xm(e){if("GPL"==e)return"GPL";const t=uo(e.split(".")[1]);return t?t.licenseType||"production":null}class Em extends Nh{constructor(e,t){super(e);const o=this.bindTemplate;this.extendTemplate({attributes:{class:["ck-menu-bar__menu__item"]},on:{mouseenter:o.to("mouseenter")}}),this.delegate("mouseenter").to(t)}}const Tm={toggleMenusAndFocusItemsOnHover(e){e.on("menu:mouseenter",(t=>{if(e.isFocusBorderEnabled||e.isOpen){if(e.isOpen)for(const o of e.menus){const e=t.path[0],i=e instanceof Em&&e.children.first===o;o.isOpen=(t.path.includes(o)||i)&&o.isEnabled}t.source.focus()}}))},focusCycleMenusOnArrows(e){const t="rtl"===e.locale.uiLanguageDirection;function o(t,o){const i=e.children.getIndex(t),n=t.isOpen,s=e.children.length,r=e.children.get((i+s+o)%s);t.isOpen=!1,n&&(r.isOpen=!0),r.buttonView.focus()}e.on("menu:arrowright",(e=>{o(e.source,t?-1:1)})),e.on("menu:arrowleft",(e=>{o(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,o,i)=>{i&&e.menus.filter((e=>t.source.parentMenuView===e.parentMenuView&&t.source!==e&&e.isOpen)).forEach((e=>{e.isOpen=!1}))}))},closeOnClickOutside(e){Su({emitter:e,activator:()=>e.isOpen,callback:()=>e.close(),contextElements:()=>e.children.map((e=>e.element))})},enableFocusHighlightOnInteraction(e){let t=!1;e.on("change:isOpen",((o,i,n)=>{n||(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})}},Pm={openAndFocusPanelOnArrowDownKey(e){e.keystrokes.set("arrowdown",((t,o)=>{e.isEnabled&&e.focusTracker.focusedElement===e.buttonView.element&&(e.isOpen||(e.isOpen=!0),e.panelView.focus(),o())}))},openOnArrowRightKey(e){const t="rtl"===e.locale.uiLanguageDirection?"arrowleft":"arrowright";e.keystrokes.set(t,((t,o)=>{e.focusTracker.focusedElement===e.buttonView.element&&e.isEnabled&&(e.isOpen||(e.isOpen=!0),e.panelView.focus(),o())}))},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,o)=>{e.focusTracker.focusedElement===e.buttonView.element&&(e.isOpen=!0,e.panelView.focus(),o())}))},closeOnArrowLeftKey(e){const t="rtl"===e.locale.uiLanguageDirection?"arrowright":"arrowleft";e.keystrokes.set(t,((t,o)=>{e.isOpen&&(e.isOpen=!1,e.focus(),o())}))},closeOnEscKey(e){e.keystrokes.set("esc",((t,o)=>{e.isOpen&&(e.isOpen=!1,e.focus(),o())}))},closeOnParentClose(e){e.parentMenuView.on("change:isOpen",((t,o,i)=>{i||t.source!==e.parentMenuView||(e.isOpen=!1)}))}},Sm={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"})},Im=[{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 Rm({normalizedConfig:e,locale:t,componentFactory:o,extraItems:i}){const n=j(e);return Om(e,n,i),function(e,t){const o=t.removeItems,i=[];t.items=t.items.filter((({menuId:e})=>!o.includes(e)||(i.push(e),!1))),Mm(t.items,(e=>{e.groups=e.groups.filter((({groupId:e})=>!o.includes(e)||(i.push(e),!1)));for(const t of e.groups)t.items=t.items.filter((e=>{const t=zm(e);return!o.includes(t)||(i.push(t),!1)}))}));for(const t of o)i.includes(t)||be("menu-bar-item-could-not-be-removed",{menuBarConfig:e,itemName:t})}(e,n),Om(e,n,n.addItems),function(e,t,o){Mm(t.items,(i=>{for(const n of i.groups)n.items=n.items.filter((n=>{const s="string"==typeof n&&!o.has(n);return s&&!t.isUsingDefaultConfig&&be("menu-bar-item-unavailable",{menuBarConfig:e,parentMenuConfig:j(i),componentName:n}),!s}))}))}(e,n,o),Dm(e,n),function(e,t){const o=t.t,i={File:o({string:"File",id:"MENU_BAR_MENU_FILE"}),Edit:o({string:"Edit",id:"MENU_BAR_MENU_EDIT"}),View:o({string:"View",id:"MENU_BAR_MENU_VIEW"}),Insert:o({string:"Insert",id:"MENU_BAR_MENU_INSERT"}),Format:o({string:"Format",id:"MENU_BAR_MENU_FORMAT"}),Tools:o({string:"Tools",id:"MENU_BAR_MENU_TOOLS"}),Help:o({string:"Help",id:"MENU_BAR_MENU_HELP"}),Text:o({string:"Text",id:"MENU_BAR_MENU_TEXT"}),Font:o({string:"Font",id:"MENU_BAR_MENU_FONT"})};Mm(e.items,(e=>{e.label in i&&(e.label=i[e.label])}))}(n,t),n}function Om(e,t,o){const i=[];if(0!=o.length){for(const e of o){const o=Bm(e.position),s=Lm(e.position);if("object"==typeof(n=e)&&"menu"in n)if(s){const n=t.items.findIndex((e=>e.menuId===s));if(-1!=n)"before"===o?(t.items.splice(n,0,e.menu),i.push(e)):"after"===o&&(t.items.splice(n+1,0,e.menu),i.push(e));else{Vm(t,e.menu,s,o)&&i.push(e)}}else"start"===o?(t.items.unshift(e.menu),i.push(e)):"end"===o&&(t.items.push(e.menu),i.push(e));else if(Nm(e))Mm(t.items,(t=>{if(t.menuId===s)"start"===o?(t.groups.unshift(e.group),i.push(e)):"end"===o&&(t.groups.push(e.group),i.push(e));else{const n=t.groups.findIndex((e=>e.groupId===s));-1!==n&&("before"===o?(t.groups.splice(n,0,e.group),i.push(e)):"after"===o&&(t.groups.splice(n+1,0,e.group),i.push(e)))}}));else{Vm(t,e.item,s,o)&&i.push(e)}}var n;for(const t of o)i.includes(t)||be("menu-bar-item-could-not-be-added",{menuBarConfig:e,addedItemConfig:t})}}function Vm(e,t,o,i){let n=!1;return Mm(e.items,(e=>{for(const{groupId:s,items:r}of e.groups){if(n)return;if(s===o)"start"===i?(r.unshift(t),n=!0):"end"===i&&(r.push(t),n=!0);else{const e=r.findIndex((e=>zm(e)===o));-1!==e&&("before"===i?(r.splice(e,0,t),n=!0):"after"===i&&(r.splice(e+1,0,t),n=!0))}}})),n}function Dm(e,t){const o=t.isUsingDefaultConfig;let i=!1;t.items=t.items.filter((t=>!!t.groups.length||(Fm(e,t,o),!1))),t.items.length?(Mm(t.items,(t=>{t.groups=t.groups.filter((e=>!!e.items.length||(i=!0,!1)));for(const n of t.groups)n.items=n.items.filter((t=>!(jm(t)&&!t.groups.length)||(Fm(e,t,o),i=!0,!1)))})),i&&Dm(e,t)):Fm(e,e,o)}function Fm(e,t,o){o||be("menu-bar-menu-empty",{menuBarConfig:e,emptyMenuConfig:t})}function Mm(e,t){if(Array.isArray(e))for(const t of e)o(t);function o(e){t(e);for(const t of e.groups)for(const e of t.items)jm(e)&&o(e)}}function Nm(e){return"object"==typeof e&&"group"in e}function Bm(e){return e.startsWith("start")?"start":e.startsWith("end")?"end":e.startsWith("after")?"after":"before"}function Lm(e){const t=e.match(/^[^:]+:(.+)/);return t?t[1]:null}function zm(e){return"string"==typeof e?e:e.menuId}function jm(e){return"object"==typeof e&&"menuId"in e}class qm extends(Be()){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 bm(e),this.focusTracker=new oo,this.tooltipManager=new _m(e),this.poweredBy=new gh(e),this.evaluationBadge=new Cm(e),this.ariaLiveAnnouncer=new Eu(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 o=()=>{this.editor.editing.view.getDomRoot(e)||this.editor.keystrokes.listenTo(t)};this.isReady?o():this.once("ready",o)}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 o=function(e){let t;return t="items"in e&&e.items?{items:e.items,removeItems:[],addItems:[],isVisible:!0,isUsingDefaultConfig:!1,...e}:{items:j(Im),addItems:[],removeItems:[],isVisible:!0,isUsingDefaultConfig:!0,...e},t}(this.editor.config.get("menuBar")||{});e.fillFromConfig(o,this.componentFactory,this._extraMenuBarElements),this.editor.keystrokes.set("Esc",((e,o)=>{t.contains(this.editor.ui.focusTracker.focusedElement)&&(this._lastFocusedForeignElement?(this._lastFocusedForeignElement.focus(),this._lastFocusedForeignElement=null):this.editor.editing.view.focus(),o())})),this.editor.keystrokes.set("Alt+F9",((o,i)=>{t.contains(this.editor.ui.focusTracker.focusedElement)||(this._saveLastFocusedForeignElement(),e.isFocusBorderEnabled=!0,e.focus(),i())}))}_readViewportOffsetFromConfig(){const e=this.editor,t=e.config.get("ui.viewportOffset");if(t)return t;const o=e.config.get("toolbar.viewportTopOffset");return o?(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:o}):{top:0}}_initFocusTracking(){const e=this.editor;let t;e.keystrokes.set("Alt+F10",((e,o)=>{this._saveLastFocusedForeignElement();const i=this._getCurrentFocusedToolbarDefinition();i&&t||(t=this._getFocusableCandidateToolbarDefinitions());for(let e=0;e{const i=this._getCurrentFocusedToolbarDefinition();i&&(this._lastFocusedForeignElement?(this._lastFocusedForeignElement.focus(),this._lastFocusedForeignElement=null):e.editing.view.focus(),i.options.afterBlur&&i.options.afterBlur(),o())}))}_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:o,options:i}=t;(Ct(o.element)||i.beforeFocus)&&e.push(t)}return e.sort(((e,t)=>$m(e)-$m(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:o}}=e;return o&&o(),!!Ct(t.element)&&(t.focus(),!0)}_handleScrollToTheSelection(e,t){const o={top:0,bottom:0,left:0,right:0,...this.viewportOffset};t.viewportOffset.top+=o.top,t.viewportOffset.bottom+=o.bottom,t.viewportOffset.left+=o.left,t.viewportOffset.right+=o.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,o)=>{const i=this._getVisualViewportTopOffset(o);o.visualTop!==i&&(e.return={...o,visualTop:i})})),this.set("viewportOffset",e)}_initVisualViewportSupport(){if(!J.window.visualViewport)return;const e=()=>{const e=this._getVisualViewportTopOffset(this.viewportOffset);this.viewportOffset.visualTop!==e&&(this.viewportOffset={...this.viewportOffset,visualTop:e})};this._domEmitter=new(et()),this._domEmitter.listenTo(J.window.visualViewport,"scroll",e),this._domEmitter.listenTo(J.window.visualViewport,"resize",e)}_getVisualViewportTopOffset(e){const t=St().top,o=e.top||0;return t>o?0:o-t}}function $m(e){const{toolbarView:t,options:o}=e;let i=10;return Ct(t.element)&&i--,o.isContextual&&(i-=2),i}class Hm extends Au{body;menuBarView;toolbar;constructor(e){super(e),this.body=new ah(e)}render(){super.render(),this.body.attachToDom()}destroy(){return this.body.detachFromDom(),super.destroy()}}class Wm extends Au{name=null;_editingView;_editableElement;_hasExternalElement;constructor(e,t,o){super(e),this.setTemplate({tag:"div",attributes:{class:["ck","ck-content","ck-editor__editable","ck-rounded-corners"],lang:e.contentLanguage,dir:e.contentLanguageDirection}}),this.set("isFocused",!1),this._editableElement=o,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((o=>{const i=e.document.getRoot(t.name);o.addClass(t.isFocused?"ck-focused":"ck-blurred",i),o.removeClass(t.isFocused?"ck-blurred":"ck-focused",i)}))}e.isRenderingInProgress?function o(i){e.once("change:isRenderingInProgress",((e,n,s)=>{s?o(i):t(i)}))}(this):t(this)}}class Um extends Wm{_options;constructor(e,t,o,i={}){super(e,t,o),this._options=i,this.extendTemplate({attributes:{role:"textbox",class:"ck-editor__editable_inline"}})}render(){super.render();const e=this._editingView;e.change((t=>{const o=e.document.getRoot(this.name);t.setAttribute("aria-label",this.getEditableAriaLabel(),o)}))}getEditableAriaLabel(){const e=this.locale.t,t=this._options.label,o=this._editableElement,i=this.name;if("string"==typeof t)return t;if("object"==typeof t)return t[i];if("function"==typeof t)return t(this);if(o){const e=o.getAttribute("aria-label");if(e)return e}return e("Rich Text Editor. Editing area: %0",i)}}class Km extends Au{children;constructor(e,t={}){super(e);const o=this.bindTemplate;this.set("class",["ck","ck-form__row",...Qt(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:o.to("class",(e=>e.join(" "))),role:o.to("_role"),"aria-labelledby":o.to("_ariaLabelledBy")},children:this.children})}}class Gm extends Cc{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||""})}}class Jm extends(Be()){constructor(e,t){super(),t&&No(this,t),e&&this.set(e)}}const Zm=yt("px");class Qm extends fc{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 o=this._idToStack.get(t);e.singleViewMode&&this.showStack(t),o.set(e.view,e),this._viewToStack.set(e.view,o),o===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 dh(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 Ym(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,o)=>{if(o<2)return"";const i=Array.from(this._idToStack.values()).indexOf(this._visibleStack)+1;return t("%0 of %1",[i,o])})),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 Xm(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:o=!0,singleViewMode:i=!1}){this.view.class=t,this.view.withArrow=o,this._rotatorView.showView(e),this.visibleView=e,this.view.pin(this.getPositionOptions()),this._fakePanelsView.updatePosition(),i&&(this._singleViewMode=!0)}}class Ym extends Au{focusTracker;buttonPrevView;buttonNextView;content;constructor(e){super(e);const t=e.t,o=this.bindTemplate;this.set("isNavigationVisible",!0),this.focusTracker=new oo,this.buttonPrevView=this._createButtonView(t("Previous"),ed),this.buttonNextView=this._createButtonView(t("Next"),Kc),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",o.to("isNavigationVisible",(e=>e?"":"ck-hidden"))]},children:[this.buttonPrevView,{tag:"span",attributes:{class:["ck-balloon-rotator__counter"]},children:[{text:o.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 o=new Lu(this.locale);return o.set({label:e,icon:t,tooltip:!0}),o}}class Xm extends Au{content;_balloonPanelView;constructor(e,t){super(e);const o=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",o.to("numberOfPanels",(e=>e?"":"ck-hidden"))],style:{top:o.to("top",Zm),left:o.to("left",Zm),width:o.to("width",Zm),height:o.to("height",Zm)}},children:this.content}),this.on("change:numberOfPanels",((e,t,o,i)=>{o>i?this._addPanels(o-i):this._removePanels(i-o),this.updatePosition()}))}_addPanels(e){for(;e--;){const e=new Au;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:o,height:i}=new ut(this._balloonPanelView.element);Object.assign(this,{top:e,left:t,width:o,height:i})}}}class eg extends ih{arrowView;constructor(e){super(e);const t=this.bindTemplate;this.set({withText:!0,role:"menuitem"}),this.arrowView=this._createArrowView(),this.extendTemplate({attributes:{class:["ck-menu-bar__menu__button"],"aria-haspopup":!0,"aria-expanded":this.bindTemplate.to("isOn",(e=>String(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 Nu;return e.content=Uc,e.extendTemplate({attributes:{class:"ck-menu-bar__menu__button__arrow"}}),e}}class tg extends Au{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())}}class og extends Au{buttonView;panelView;focusTracker;keystrokes;constructor(e){super(e);const t=this.bindTemplate;this.buttonView=new eg(e),this.buttonView.delegate("mouseenter").to(this),this.buttonView.bind("isOn","isEnabled").to(this,"isOpen","isEnabled"),this.panelView=new tg(e),this.panelView.bind("isVisible").to(this,"isOpen"),this.keystrokes=new ro,this.focusTracker=new oo,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),Pm.closeOnEscKey(this),this._closeOnDisabled(),this._repositionPanelOnOpen()}_attachBehaviors(){this.parentMenuView?(Pm.openOnButtonClick(this),Pm.openOnArrowRightKey(this),Pm.closeOnArrowLeftKey(this),Pm.openAndFocusOnEnterKeyPress(this),Pm.closeOnParentClose(this)):(this._propagateArrowKeystrokeEvents(),Pm.openAndFocusPanelOnArrowDownKey(this),Pm.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,o)=>{o||(this.isOpen=!1)}))}_repositionPanelOnOpen(){this.on("change:isOpen",((e,t,o)=>{if(!o)return;const i=og._getOptimalPosition({element:this.panelView.element,target:this.buttonView.element,fitInViewport:!0,positions:this._panelPositions});this.panelView.position=i?i.name:this._defaultMenuPositionName}))}focus(){this.buttonView.focus()}get _panelPositions(){const{southEast:e,southWest:t,northEast:o,northWest:i,westSouth:n,eastSouth:s,westNorth:r,eastNorth:a}=Sm;return"ltr"===this.locale.uiLanguageDirection?this.parentMenuView?[s,a,n,r]:[e,t,o,i]:this.parentMenuView?[n,r,s,a]:[t,e,i,o]}get _defaultMenuPositionName(){return"ltr"===this.locale.uiLanguageDirection?this.parentMenuView?"es":"se":this.parentMenuView?"ws":"sw"}static _getOptimalPosition=At}class ig extends zh{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=ng(e);return t&&t.isToggleable}));this.items.forEach((t=>{const o=ng(t);o&&(o.hasCheckSpace=e)}))}}function ng(e){return e instanceof Nh?e.children.map((e=>function(e){return"object"==typeof e&&"buttonView"in e&&e.buttonView instanceof Lu}(e)?e.buttonView:e)).find((e=>e instanceof ih)):null}class sg extends wh{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 rg=["mouseenter","arrowleft","arrowright","change:isOpen"];class ag extends Au{children;menus=[];constructor(e){super(e);const t=e.t,o=this.bindTemplate;this.set({isOpen:!1,isFocusBorderEnabled:!1}),this._setupIsOpenUpdater(),this.children=this.createCollection(),this.setTemplate({tag:"div",attributes:{class:["ck","ck-menu-bar",o.if("isFocusBorderEnabled","ck-menu-bar_focus-border-enabled")],"aria-label":t("Editor menu bar"),role:"menubar"},children:this.children})}fillFromConfig(e,t,o=[]){const i=Rm({normalizedConfig:e,locale:this.locale,componentFactory:t,extraItems:o}).items.map((e=>this._createMenu({componentFactory:t,menuDefinition:e})));this.children.addMany(i)}render(){super.render(),Tm.toggleMenusAndFocusItemsOnHover(this),Tm.closeMenusWhenTheBarCloses(this),Tm.closeMenuWhenAnotherOnTheSameLevelOpens(this),Tm.focusCycleMenusOnArrows(this),Tm.closeOnClickOutside(this),Tm.enableFocusHighlightOnInteraction(this)}focus(){this.children.first&&this.children.first.focus()}close(){for(const e of this.children)e.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(...rg).to(t),e.parentMenuView=t):e.delegate(...rg).to(this,(e=>"menu:"+e)),e._attachBehaviors(),this.menus.push(e)}_createMenu({componentFactory:e,menuDefinition:t,parentMenuView:o}){const i=this.locale,n=new og(i);return this.registerMenu(n,o),n.buttonView.set({label:t.label}),n.once("change:isOpen",(()=>{const o=new ig(i);o.ariaLabel=t.label,n.panelView.children.add(o),o.items.addMany(this._createMenuItems({menuDefinition:t,parentMenuView:n,componentFactory:e}))})),n}_createMenuItems({menuDefinition:e,parentMenuView:t,componentFactory:o}){const i=this.locale,n=[];for(const r of e.groups){for(const e of r.items){const r=new Em(i,t);if(s(e))r.children.add(this._createMenu({componentFactory:o,menuDefinition:e,parentMenuView:t}));else{const i=this._createMenuItemContentFromFactory({componentName:e,componentFactory:o,parentMenuView:t});if(!i)continue;r.children.add(i)}n.push(r)}r!==e.groups[e.groups.length-1]&&n.push(new Bh(i))}return n}_createMenuItemContentFromFactory({componentName:e,parentMenuView:t,componentFactory:o}){const i=o.create(e);return i instanceof og||i instanceof sh||i instanceof sg?(this._registerMenuTree(i,t),i.on("execute",(()=>{this.close()})),i):(be("menu-bar-component-unsupported",{componentName:e,componentView:i}),null)}_registerMenuTree(e,t){if(!(e instanceof og))return void e.delegate("mouseenter").to(t);this.registerMenu(e,t);const o=e.panelView.children.filter((e=>e instanceof ig))[0];if(!o)return void e.delegate("mouseenter").to(t);const i=o.items.filter((e=>e instanceof Nh));for(const t of i)this._registerMenuTree(t.children.get(0),e)}_setupIsOpenUpdater(){let e;this.on("menu:change:isOpen",((t,o,i)=>{clearTimeout(e),i?this.isOpen=!0:e=setTimeout((()=>{this.isOpen=Array.from(this.children).some((e=>e.isOpen))}),0)}))}}class lg extends qm{view;constructor(e,t){super(e),this.view=t}init(){const e=this.editor,t=this.view,o=e.editing.view,i=t.editable,n=o.document.getRoot();i.name=n.rootName,t.render();const s=i.element;this.setEditableElement(i.name,s),t.editable.bind("isFocused").to(this.focusTracker),o.attachDomRoot(s),this._initPlaceholder(),this._initToolbar(),this.initMenuBar(this.view.menuBarView),this.fire("ready")}destroy(){super.destroy();const e=this.view,t=this.editor.editing.view;t.getDomRoot(e.editable.name)&&t.detachDomRoot(e.editable.name),e.destroy()}_initToolbar(){const e=this.editor,t=this.view;t.toolbar.fillFromConfig(e.config.get("toolbar"),this.componentFactory),this.addToolbar(t.toolbar)}_initPlaceholder(){const e=this.editor,t=e.editing.view,o=t.document.getRoot(),i=e.config.get("roots")[o.rootName].placeholder;i&&(o.placeholder=i),Yo({view:t,element:o,isDirectHost:!1,keepOnFocus:!0})}}class cg extends Hm{toolbar;editable;menuBarView;constructor(e,t,o={}){super(e),this.toolbar=new Wh(e,{shouldGroupWhenFull:o.shouldToolbarGroupWhenFull}),this.menuBarView=new ag(e),this.editable=new Um(e,t,o.editableElement,{label:o.label}),this.toolbar.extendTemplate({attributes:{class:["ck-reset_all","ck-rounded-corners"],dir:e.uiLanguageDirection}}),this.menuBarView.extendTemplate({attributes:{class:["ck-reset_all","ck-rounded-corners"],dir:e.uiLanguageDirection}})}render(){super.render(),this.registerChild([this.menuBarView,this.toolbar,this.editable])}}class dg extends(Fc(Vc)){static get editorName(){return"DecoupledEditor"}ui;constructor(e,t={}){const{sourceElementOrData:o,editorConfig:i}=function(e,t){return"string"==typeof e||Bc(e)||t&&Object.keys(t).length?{sourceElementOrData:e,editorConfig:t}:{sourceElementOrData:"",editorConfig:e}}(e,t);super(i),Mc(o,this.config);const n=this.config.get("roots").main.element;if(L(n)){if("TEXTAREA"===n.tagName)throw new fe("editor-wrong-element",null);this.sourceElement=n,function(e,t){if(t.ckeditorInstance)throw new fe("editor-source-element-already-used",e);t.ckeditorInstance=e,e.once("destroy",(()=>{delete t.ckeditorInstance}))}(this,n)}this.model.document.createRoot();const s=!this.config.get("toolbar.shouldNotGroupWhenFull"),r=new cg(this.locale,this.editing.view,{editableElement:this.sourceElement,shouldToolbarGroupWhenFull:s,label:this.config.get("roots").main.label});this.ui=new lg(this,r)}destroy(){const e=this.getData();return this.ui.destroy(),super.destroy().then((()=>{this.sourceElement&&this.updateSourceElement(e)}))}static create(e,t={}){return new Promise((o=>{const i=new this(e,t);o(i.initPlugins().then((()=>i.ui.init())).then((()=>i.data.init(i.config.get("roots").main.initialData))).then((()=>i.fire("ready"))).then((()=>i)))}))}}class ug{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)}}class hg extends wc{_buffer;constructor(e,t){super(e),this._buffer=new ug(e.model,t),this._isEnabledBasedOnSelection=!1}get buffer(){return this._buffer}destroy(){super.destroy(),this._buffer.destroy()}execute(e={}){const t=this.editor.model,o=t.document,i=e.text||"",n=i.length;let s=o.selection;if(e.selection?s=e.selection:e.range&&(s=t.createSelection(e.range)),!t.canEditAt(s))return;const r=e.resultRange;t.enqueueChange(this._buffer.batch,(e=>{this._buffer.lock();const a=Array.from(o.selection.getAttributes());t.deleteContent(s),i&&t.insertContent(e.createText(i,a),s),r?e.setSelection(r):s.is("documentSelection")||e.setSelection(s),this._buffer.unlock(),this._buffer.input(n)}))}}const mg=["insertText","insertReplacementText"],gg=[...mg,"insertCompositionText"];class pg extends Ln{focusObserver;constructor(e){super(e),this.focusObserver=e.getObserver(Un);const t=Y.isAndroid?gg:mg,o=e.document;o.on("beforeinput",((i,n)=>{if(!this.isEnabled)return;const{data:s,targetRanges:r,inputType:a,domEvent:l,isComposing:c}=n;if(!t.includes(a))return;this.focusObserver.flush();const d=new ue(o,"insertText");o.fire(d,new zn(e,l,{text:s,selection:e.createSelection(r),isComposing:c})),d.stop.called&&i.stop()})),Y.isAndroid||o.on("compositionend",((t,{data:i,domEvent:n})=>{this.isEnabled&&i&&o.fire("insertText",new zn(e,n,{text:i,isComposing:!0}))}),{priority:"low"})}observe(){}stopObserving(){}}class fg extends fc{_typingQueue;static get pluginName(){return"Input"}static get isOfficialPlugin(){return!0}init(){const e=this.editor,t=e.model,o=e.editing.view,i=e.editing.mapper,n=t.document.selection;this._typingQueue=new bg(e),o.addObserver(pg);const s=new hg(e,e.config.get("typing.undoStep")||20);e.commands.add("insertText",s),e.commands.add("input",s),this.listenTo(o.document,"beforeinput",(()=>{this._typingQueue.flush("next beforeinput")}),{priority:"high"}),this.listenTo(o.document,"insertText",((e,r)=>{const{text:a,selection:l}=r;if(o.document.selection.isFake&&l&&o.document.selection.isSimilar(l)&&r.preventDefault(),l&&Array.from(l.getRanges()).some((e=>!e.isCollapsed))&&r.preventDefault(),!s.isEnabled)return void r.preventDefault();let c;l&&(c=Array.from(l.getRanges()).filter((e=>e.root.is("rootElement"))).map((e=>i.toModelRange(e))).map((e=>Ba(e,t.schema)||e))),c&&c.length||(c=Array.from(n.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(o.document,"keydown",((e,i)=>{!n.isCollapsed&&229==i.keyCode&&o.document.isComposing&&wg(t,s)})):this.listenTo(o.document,"compositionstart",(()=>{n.isCollapsed||wg(t,s)}),{priority:"high"}),this.listenTo(o.document,"mutations",((e,{mutations:t})=>{if(this._typingQueue.hasAffectedElements())for(const{node:e}of t){const t=yg(e,i),o=i.toModelElement(t);if(this._typingQueue.isElementAffected(o))return void this._typingQueue.flush("mutations")}})),this.listenTo(o.document,"compositionend",(()=>{this._typingQueue.flush("before composition end")}),{priority:"high"}),this.listenTo(o.document,"compositionend",(()=>{this._typingQueue.flush("after composition end");const e=[];if(this._typingQueue.hasAffectedElements())for(const t of this._typingQueue.flushAffectedElements()){const o=i.toViewElement(t);o&&e.push({type:"children",node:o})}!e.length&&Y.isAndroid||o.document.fire("mutations",{mutations:e})}),{priority:"lowest"})}destroy(){super.destroy(),this._typingQueue.destroy()}}class bg{editor;flushDebounced=zo((()=>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 o={text:e.text};if(e.selection){o.selectionRanges=[];for(const t of e.selection.getRanges())o.selectionRanges.push(Ts.fromRange(t)),this._affectedElements.add(t.start.parent)}this._queue.push(o),this._isComposing||=t,this.flushDebounced()}shift(){const e=this._queue.shift(),t={text:e.text};if(e.selectionRanges){const o=e.selectionRanges.map((e=>function(e){const t=e.toRange();if(e.detach(),"$graveyard"==t.root.rootName)return null;return t}(e))).filter((e=>!!e));o.length&&(t.selection=this.editor.model.createSelection(o))}return t}flush(e){const t=this.editor,o=t.model,i=t.editing.view;if(this.flushDebounced.cancel(),!this._queue.length)return;const n=t.commands.get("insertText").buffer;o.enqueueChange(n.batch,(()=>{for(n.lock();this._queue.length;){const e=this.shift();t.execute("insertText",e)}n.unlock(),this._isComposing||this._affectedElements.clear(),this._isComposing=!1})),i.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 wg(e,t){if(!t.isEnabled)return;const o=t.buffer;o.lock(),e.enqueueChange(o.batch,(()=>{e.deleteContent(e.document.selection)})),o.unlock()}function yg(e,t){let o=e.is("$text")?e.parent:e;for(;!t.toModelElement(o);)o=o.parent;return o}class _g extends wc{direction;_buffer;constructor(e,t){super(e),this.direction=t,this._buffer=new ug(e.model,e.config.get("typing.undoStep")),this._isEnabledBasedOnSelection=!1}get buffer(){return this._buffer}execute(e={}){const t=this.editor.model,o=t.document;t.enqueueChange(this._buffer.batch,(i=>{this._buffer.lock();const n=i.createSelection(e.selection||o.selection);if(!t.canEditAt(n))return;const s=e.sequence||1,r=n.isCollapsed;if(n.isCollapsed&&t.modifySelection(n,{direction:this.direction,unit:e.unit,treatEmojiAsSingleUnit:!0}),this._shouldEntireContentBeReplacedWithParagraph(s))return void this._replaceEntireContentWithParagraph(i);if(this._shouldReplaceFirstBlockWithParagraph(n,s))return void this.editor.execute("paragraph",{selection:n});if(n.isCollapsed)return;let a=0;n.getFirstRange().getMinimalFlatRanges().forEach((e=>{a+=He(e.getWalker({singleCharacters:!0,ignoreElementEnd:!0,shallow:!0}))})),t.deleteContent(n,{doNotResetEntireContent:r,direction:this.direction}),this._buffer.input(a),i.setSelection(n),this._buffer.unlock()}))}_shouldEntireContentBeReplacedWithParagraph(e){if(e>1)return!1;const t=this.editor.model,o=t.document.selection,i=t.schema.getLimitElement(o);if(!(o.isCollapsed&&o.containsEntireContent(i)))return!1;if(!t.schema.checkChild(i,"paragraph"))return!1;const n=i.getChild(0);return!n||!n.is("element","paragraph")}_replaceEntireContentWithParagraph(e){const t=this.editor.model,o=t.document.selection,i=t.schema.getLimitElement(o),n=e.createElement("paragraph");e.remove(e.createRangeIn(i)),e.insert(n,i),e.setSelection(n,0)}_shouldReplaceFirstBlockWithParagraph(e,t){const o=this.editor.model;if(t>1||"backward"!=this.direction)return!1;if(!e.isCollapsed)return!1;const i=e.getFirstPosition(),n=o.schema.getLimitElement(i),s=n.getChild(0);return i.parent==s&&(!!e.containsEntireContent(s)&&(!!o.schema.checkChild(n,"paragraph")&&"paragraph"!=s.name))}}const kg="word",vg="selection",Cg="backward",Ag="forward",xg={deleteContent:{unit:vg,direction:Cg},deleteContentBackward:{unit:"codePoint",direction:Cg},deleteWordBackward:{unit:kg,direction:Cg},deleteHardLineBackward:{unit:vg,direction:Cg},deleteSoftLineBackward:{unit:vg,direction:Cg},deleteContentForward:{unit:"character",direction:Ag},deleteWordForward:{unit:kg,direction:Ag},deleteHardLineForward:{unit:vg,direction:Ag},deleteSoftLineForward:{unit:vg,direction:Ag}};class Eg extends Ln{constructor(e){super(e);const t=e.document;let o=0;t.on("keydown",(()=>{o++})),t.on("keyup",(()=>{o=0})),t.on("beforeinput",((i,n)=>{if(!this.isEnabled)return;const{targetRanges:s,domEvent:r,inputType:a}=n,l=xg[a];if(!l)return;const c={direction:l.direction,unit:l.unit,sequence:o};c.unit==vg&&(c.selectionToRemove=e.createSelection(s[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 o=0;for(const{nextPosition:e,item:i}of t){if(e.parent.is("$text")){const t=e.parent.data,i=e.offset;if(ho(t,i)||mo(t,i)||po(t,i))continue;o++}else(i.is("containerElement")||i.is("emptyElement"))&&o++;if(o>1)return!0}return!1}(s)&&(c.unit=vg,c.selectionToRemove=e.createSelection(s)));const d=new Di(t,"delete",s[0]);t.fire(d,new zn(e,r,c)),d.stop.called&&i.stop()})),Y.isBlink&&function(e){const t=e.view,o=t.document;let i=null,n=!1;function s(e){return e==qt.backspace||e==qt.delete}function r(e){return e==qt.backspace?Cg:Ag}o.on("keydown",((e,{keyCode:t})=>{i=t,n=!1})),o.on("keyup",((a,{keyCode:l,domEvent:c})=>{const d=o.selection,u=e.isEnabled&&l==i&&s(l)&&!d.isCollapsed&&!n;if(i=null,u){const e=d.getFirstRange(),i=new Di(o,"delete",e),n={unit:vg,direction:r(l),selectionToRemove:d};o.fire(i,new zn(t,c,n))}})),o.on("beforeinput",((e,{inputType:t})=>{const o=xg[t];s(i)&&o&&o.direction==r(i)&&(n=!0)}),{priority:"high"}),o.on("beforeinput",((e,{inputType:t,data:o})=>{i==qt.delete&&"insertText"==t&&""==o&&e.stop()}),{priority:"high"})}(this)}observe(){}stopObserving(){}}class Tg extends fc{_undoOnBackspace;static get pluginName(){return"Delete"}static get isOfficialPlugin(){return!0}init(){const e=this.editor,t=e.editing.view,o=t.document,i=e.model.document;t.addObserver(Eg),this._undoOnBackspace=!1;const n=new _g(e,"forward");e.commands.add("deleteForward",n),e.commands.add("forwardDelete",n),e.commands.add("delete",new _g(e,"backward")),this.listenTo(o,"delete",((i,n)=>{o.isComposing||n.preventDefault();const{direction:s,sequence:r,selectionToRemove:a,unit:l}=n,c="forward"===s?"deleteForward":"delete",d={sequence:r};if("selection"==l){const t=Array.from(a.getRanges()).map((t=>e.editing.mapper.toModelRange(t))).map((t=>Ba(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(o,"keydown",((n,s)=>{if(o.isComposing||s.keyCode!=qt.backspace||!i.selection.isCollapsed)return;const r=e.model.schema.getLimitElement(i.selection),a=e.model.createPositionAt(r,0);if(a.isTouching(i.selection.getFirstPosition())){s.preventDefault();const i=e.model.schema.getNearestSelectionRange(a,"forward");if(!i)return;const n=t.createSelection(e.editing.mapper.toViewRange(i)),r=n.getFirstRange(),l=new Di(document,"delete",r),c={unit:"selection",direction:"backward",selectionToRemove:n};o.fire(l,new zn(t,s.domEvent,c))}})),this.editor.plugins.has("UndoEditing")&&(this.listenTo(o,"delete",((t,o)=>{this._undoOnBackspace&&"backward"==o.direction&&1==o.sequence&&"codePoint"==o.unit&&(this._undoOnBackspace=!1,e.execute("undo"),o.preventDefault(),t.stop())}),{context:"$capture"}),this.listenTo(i,"change",(()=>{this._undoOnBackspace=!1})))}requestUndoOnBackspace(){this.editor.plugins.has("UndoEditing")&&(this._undoOnBackspace=!0)}}class Pg extends fc{static get requires(){return[fg,Tg]}static get pluginName(){return"Typing"}static get isOfficialPlugin(){return!0}}function Sg(e,t){let o=e.start;return{text:Array.from(e.getWalker({ignoreElementEnd:!1})).reduce(((e,{item:i})=>i.is("$text")||i.is("$textProxy")?e+i.data:(o=t.createPositionAfter(i),"")),""),range:t.createRange(o,e.end)}}class Ig extends(Be()){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:o})=>{o&&(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 o=this.model,i=o.document.selection,n=o.createRange(o.createPositionAt(i.focus.parent,0),i.focus),{text:s,range:r}=Sg(n,o),a=this.testCallback(s);if(!a&&this.hasMatch&&this.fire("unmatched"),this._hasMatch=!!a,a){const o=Object.assign(t,{text:s,range:r});"object"==typeof a&&Object.assign(o,a),this.fire(`matched:${e}`,o)}}}class Rg extends fc{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,o=e.editing.view,i=e.locale,n=t.document.selection;this.listenTo(o.document,"arrowKey",((e,t)=>{if(!n.isCollapsed)return;if(t.shiftKey||t.altKey||t.ctrlKey)return;const o=t.keyCode==qt.arrowright,s=t.keyCode==qt.arrowleft;if(!o&&!s)return;const r=i.contentLanguageDirection;let a=!1;a="ltr"===r&&o||"rtl"===r&&s?this._handleForwardMovement(t):this._handleBackwardMovement(t),!0===a&&e.stop()}),{context:"$text",priority:"highest"}),this.listenTo(n,"change:range",((e,t)=>{this._isNextGravityRestorationSkipped?this._isNextGravityRestorationSkipped=!1:this._isGravityOverridden&&(!t.directChange&&Ng(n.getFirstPosition(),this.attributes)||this._restoreGravity())})),this._enableClickingAfterNode(),this._enableInsertContentSelectionAttributesFixer(),this._handleDeleteContentAfterNode()}registerAttribute(e){this.attributes.add(e)}_handleForwardMovement(e){const t=this.attributes,o=this.editor.model,i=o.document.selection,n=i.getFirstPosition();return!this._isGravityOverridden&&((!n.isAtStart||!Og(i,t))&&(!!Ng(n,t)&&(e&&Fg(e),Og(i,t)&&Ng(n,t,!0)?Dg(o,t):this._overrideGravity(),!0)))}_handleBackwardMovement(e){const t=this.attributes,o=this.editor.model,i=o.document.selection,n=i.getFirstPosition();return this._isGravityOverridden?(e&&Fg(e),this._restoreGravity(),Ng(n,t,!0)?Dg(o,t):Vg(o,t,n),!0):n.isAtStart?!!Og(i,t)&&(e&&Fg(e),Vg(o,t,n),!0):!Og(i,t)&&Ng(n,t,!0)?(e&&Fg(e),Vg(o,t,n),!0):!!Mg(n,t)&&(n.isAtEnd&&!Og(i,t)&&Ng(n,t)?(e&&Fg(e),Vg(o,t,n),!0):(this._isNextGravityRestorationSkipped=!0,this._overrideGravity(),!1))}_enableClickingAfterNode(){const e=this.editor,t=e.model,o=t.document.selection,i=e.editing.view.document;e.editing.view.addObserver(il),e.editing.view.addObserver(nl);let n=!1,s=!1;this.listenTo(i,"touchstart",(()=>{s=!1,n=!0})),this.listenTo(i,"mousedown",(()=>{s=!0})),this.listenTo(i,"selectionChange",(()=>{const e=this.attributes;if(!s&&!n)return;if(s=!1,n=!1,!o.isCollapsed)return;if(!Og(o,e))return;const i=o.getFirstPosition();Ng(i,e)&&(i.isAtStart||Ng(i,e,!0)?Dg(t,e):this._isGravityOverridden||this._overrideGravity())}))}_enableInsertContentSelectionAttributesFixer(){const e=this.editor.model,t=e.document.selection,o=this.attributes;this.listenTo(e,"insertContent",(()=>{const i=t.getFirstPosition();Og(t,o)&&Ng(i,o)&&Dg(e,o)}),{priority:"low"})}_handleDeleteContentAfterNode(){const e=this.editor,t=e.model,o=t.document.selection,i=e.editing.view;let n=!1,s=!1;this.listenTo(i.document,"delete",((e,t)=>{n="backward"===t.direction}),{priority:"high"}),this.listenTo(t,"deleteContent",(()=>{if(!n)return;const e=o.getFirstPosition();s=Og(o,this.attributes)&&!Mg(e,this.attributes)}),{priority:"high"}),this.listenTo(t,"deleteContent",(()=>{n&&(n=!1,s||e.model.enqueueChange((()=>{const e=o.getFirstPosition();Og(o,this.attributes)&&Ng(e,this.attributes)&&(e.isAtStart||Ng(e,this.attributes,!0)?Dg(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 Og(e,t){for(const o of t)if(e.hasAttribute(o))return!0;return!1}function Vg(e,t,o){const i=o.nodeBefore;e.change((o=>{if(i){const t=[],n=e.schema.isObject(i)&&e.schema.isInline(i);for(const[o,s]of i.getAttributes())!e.schema.checkAttribute("$text",o)||n&&!1===e.schema.getAttributeProperties(o).copyFromObject||t.push([o,s]);o.setSelectionAttribute(t)}else o.removeSelectionAttribute(t)}))}function Dg(e,t){e.change((e=>{e.removeSelectionAttribute(t)}))}function Fg(e){e.preventDefault()}function Mg(e,t){return Ng(e.getShiftedBy(-1),t)}function Ng(e,t,o=!1){const{nodeBefore:i,nodeAfter:n}=e;for(const e of t){const t=i?i.getAttribute(e):void 0,s=n?n.getAttribute(e):void 0;if((!o||void 0!==t&&void 0!==s)&&s!==t)return!0}return!1}Bg('"'),Bg("'"),Bg("'"),Bg('"'),Bg('"'),Bg("'");function Bg(e){return new RegExp(`(^|\\s)(${e})([^${e}]*)(${e})$`)}function Lg(e,t,o,i){return i.createRange(zg(e,t,o,!0,i),zg(e,t,o,!1,i))}function zg(e,t,o,i,n){let s=e.textNode||(i?e.nodeBefore:e.nodeAfter),r=null;for(;s&&s.getAttribute(t)==o;)r=s,s=i?s.previousSibling:s.nextSibling;return r?n.createPositionAt(r,i?"before":"after"):e}function jg(e,t,o,i){const n=e.editing.view,s=new Set;n.document.registerPostFixer((n=>{const r=e.model.document.selection;let a=!1;if(r.hasAttribute(t)){const l=Lg(r.getFirstPosition(),t,r.getAttribute(t),e.model),c=e.editing.mapper.toViewRange(l);for(const e of c.getItems())e.is("element",o)&&!e.hasClass(i)&&(n.addClass(i,e),s.add(e),a=!0)}return a})),e.conversion.for("editingDowncast").add((e=>{function t(){n.change((e=>{for(const t of s.values())e.removeClass(i,t),s.delete(t)}))}e.on("insert",t,{priority:"highest"}),e.on("remove",t,{priority:"highest"}),e.on("attribute",t,{priority:"highest"}),e.on("selection",t,{priority:"highest"})}))}function*qg(e,t){for(const o of t)o&&e.getAttributeProperties(o[0]).copyOnEnter&&(yield o)}class $g extends wc{execute(){this.editor.model.change((e=>{this.enterBlock(e),this.fire("afterExecute",{writer:e})}))}enterBlock(e){const t=this.editor.model,o=t.document.selection,i=t.schema,n=o.isCollapsed,s=o.getFirstRange(),r=s.start.parent,a=s.end.parent;if(i.isLimit(r)||i.isLimit(a))return n||r!=a||t.deleteContent(o),!1;if(n){const t=qg(e.model.schema,o.getAttributes());return Hg(e,s.start),e.setSelectionAttribute(t),!0}{const i=!(s.start.isAtStart&&s.end.isAtEnd),n=r==a;if(t.deleteContent(o,{leaveUnmerged:i}),i){if(n)return Hg(e,o.focus),!0;e.setSelection(a,0)}}return!1}}function Hg(e,t){e.split(t),e.setSelection(t.parent.nextSibling,0)}const Wg={insertParagraph:{isSoft:!1},insertLineBreak:{isSoft:!0}};class Ug extends Ln{constructor(e){super(e);const t=this.document;let o=!1;t.on("keydown",((e,t)=>{o=t.shiftKey})),t.on("beforeinput",((i,n)=>{if(!this.isEnabled)return;let s=n.inputType;Y.isSafari&&o&&"insertParagraph"==s&&(s="insertLineBreak");const r=n.domEvent,a=Wg[s];if(!a)return;const l=new Di(t,"enter",n.targetRanges[0]);t.fire(l,new zn(e,r,{isSoft:a.isSoft})),l.stop.called&&i.stop()}))}observe(){}stopObserving(){}}class Kg extends fc{static get pluginName(){return"Enter"}static get isOfficialPlugin(){return!0}init(){const e=this.editor,t=e.editing.view,o=t.document,i=this.editor.t;t.addObserver(Ug),e.commands.add("enter",new $g(e)),this.listenTo(o,"enter",((i,n)=>{o.isComposing||n.preventDefault(),n.isSoft||(e.execute("enter"),t.scrollToTheSelection())}),{priority:"low"}),e.accessibility.addKeystrokeInfos({keystrokes:[{label:i("Insert a hard break (a new paragraph)"),keystroke:"Enter"}]})}}class Gg extends wc{execute(){const e=this.editor.model,t=e.document;e.change((o=>{!function(e,t,o){const i=o.isCollapsed,n=o.getFirstRange(),s=n.start.parent,r=n.end.parent,a=s==r;if(i){const i=qg(e.schema,o.getAttributes());Jg(e,t,n.end),t.removeSelectionAttribute(o.getAttributeKeys()),t.setSelectionAttribute(i)}else{const i=!(n.start.isAtStart&&n.end.isAtEnd);e.deleteContent(o,{leaveUnmerged:i}),a?Jg(e,t,o.focus):i&&t.setSelection(r,0)}}(e,o,t.selection),this.fire("afterExecute",{writer:o})}))}refresh(){const e=this.editor.model,t=e.document;this.isEnabled=function(e,t){if(t.rangeCount>1)return!1;const o=t.anchor;if(!o||!e.checkChild(o,"softBreak"))return!1;const i=t.getFirstRange(),n=i.start.parent,s=i.end.parent;if((Zg(n,e)||Zg(s,e))&&n!==s)return!1;return!0}(e.schema,t.selection)}}function Jg(e,t,o){const i=t.createElement("softBreak");e.insertContent(i,o),t.setSelection(i,"after")}function Zg(e,t){return!e.is("rootElement")&&(t.isLimit(e)||Zg(e.parent,t))}class Qg extends fc{static get pluginName(){return"ShiftEnter"}static get isOfficialPlugin(){return!0}init(){const e=this.editor,t=e.model.schema,o=e.conversion,i=e.editing.view,n=i.document,s=this.editor.t;t.register("softBreak",{allowWhere:"$text",isInline:!0}),o.for("upcast").elementToElement({model:"softBreak",view:"br"}),o.for("downcast").elementToElement({model:"softBreak",view:(e,{writer:t})=>t.createEmptyElement("br")}),i.addObserver(Ug),e.commands.add("shiftEnter",new Gg(e)),this.listenTo(n,"enter",((t,o)=>{n.isComposing||o.preventDefault(),o.isSoft&&(e.execute("shiftEnter"),i.scrollToTheSelection())}),{priority:"low"}),e.accessibility.addKeystrokeInfos({keystrokes:[{label:s("Insert a soft break (a <br> element)"),keystroke:"Shift+Enter"}]})}}class Yg extends(xe()){_stack=[];add(e,t){const o=this._stack,i=o[0];this._insertDescriptor(e);const n=o[0];i===n||Xg(i,n)||this.fire("change:top",{oldDescriptor:i,newDescriptor:n,writer:t})}remove(e,t){const o=this._stack,i=o[0];this._removeDescriptor(e);const n=o[0];i===n||Xg(i,n)||this.fire("change:top",{oldDescriptor:i,newDescriptor:n,writer:t})}_insertDescriptor(e){const t=this._stack,o=t.findIndex((t=>t.id===e.id));if(Xg(e,t[o]))return;o>-1&&t.splice(o,1);let i=0;for(;t[i]&&ep(t[i],e);)i++;t.splice(i,0,e)}_removeDescriptor(e){const t=this._stack,o=t.findIndex((t=>t.id===e));o>-1&&t.splice(o,1)}}function Xg(e,t){return e&&t&&e.priority==t.priority&&tp(e.classes)==tp(t.classes)}function ep(e,t){return e.priority>t.priority||!(e.prioritytp(t.classes)}function tp(e){return Array.isArray(e)?e.sort().join(","):e}const op="ck-widget_selected";function ip(e){return!!e.is("element")&&!!e.getCustomProperty("widget")}function np(e,t,o={}){if(!e.is("containerElement"))throw new fe("widget-to-widget-wrong-element-type",null,{element:e});return t.setAttribute("contenteditable","false",e),t.addClass("ck-widget",e),t.setCustomProperty("widget",!0,e),e.getFillerOffset=dp,t.setCustomProperty("widgetLabel",[],e),o.label&&function(e,t){const o=e.getCustomProperty("widgetLabel");o.push(t)}(e,o.label),o.hasSelectionHandle&&function(e,t){const o=t.createUIElement("div",{class:"ck ck-widget__selection-handle"},(function(e){const t=this.toDomElement(e),o=new Nu;return o.set("content",Wc),o.render(),t.appendChild(o.element),t}));t.insert(t.createPositionAt(e,0),o),t.addClass(["ck-widget_with-selection-handle"],e)}(e,t),ap(e,t),e}function sp(e,t,o){if(t.classes&&o.addClass(Qt(t.classes),e),t.attributes)for(const i in t.attributes)o.setAttribute(i,t.attributes[i],e)}function rp(e,t,o){if(t.classes&&o.removeClass(Qt(t.classes),e),t.attributes)for(const i in t.attributes)o.removeAttribute(i,e)}function ap(e,t,o=sp,i=rp){const n=new Yg;n.on("change:top",((t,n)=>{n.oldDescriptor&&i(e,n.oldDescriptor,n.writer),n.newDescriptor&&o(e,n.newDescriptor,n.writer)}));t.setCustomProperty("addHighlight",((e,t,o)=>n.add(t,o)),e),t.setCustomProperty("removeHighlight",((e,t,o)=>n.remove(t,o)),e)}function lp(e,t,o={}){return t.addClass(["ck-editor__editable","ck-editor__nested-editable"],e),!1!==o.withAriaRole&&t.setAttribute("role","textbox",e),e.isReadOnly||t.setAttribute("tabindex","-1",e),o.label&&t.setAttribute("aria-label",o.label,e),t.setAttribute("contenteditable",e.isReadOnly?"false":"true",e),e.on("change:isReadOnly",((o,i,n)=>{t.setAttribute("contenteditable",n?"false":"true",e),n?t.removeAttribute("tabindex",e):t.setAttribute("tabindex","-1",e)})),e.on("change:isFocused",((o,i,n)=>{n?t.addClass("ck-editor__nested-editable_focused",e):t.removeClass("ck-editor__nested-editable_focused",e)})),ap(e,t),e}function cp(e,t){const o=e.getSelectedElement();if(o){const i=gp(e);if(i)return t.createRange(t.createPositionAt(o,i))}return t.schema.findOptimalInsertionRange(e)}function dp(){return null}function up(e){const t=e=>{const{width:t,paddingLeft:o,paddingRight:i}=e.ownerDocument.defaultView.getComputedStyle(e);return parseFloat(t)-(parseFloat(o)||0)-(parseFloat(i)||0)},o=e.parentElement;if(!o)return 0;let i=t(o);let n=0,s=o;for(;isNaN(i);){if(s=s.parentElement,++n>5)return 0;i=t(s)}return i}const hp="widget-type-around";function mp(e,t,o){return!!e&&ip(e)&&!o.isInline(t)}function gp(e){return e.getAttribute(hp)}const pp=["before","after"],fp=(new DOMParser).parseFromString('',"image/svg+xml").firstChild,bp="ck-widget__type-around_disabled";class wp extends fc{_currentFakeCaretModelElement=null;static get pluginName(){return"WidgetTypeAround"}static get isOfficialPlugin(){return!0}static get requires(){return[Kg,Tg]}init(){const e=this.editor,t=e.editing.view;this.on("change:isEnabled",((o,i,n)=>{t.change((e=>{for(const o of t.document.roots)n?e.removeClass(bp,o):e.addClass(bp,o)})),n||e.model.change((e=>{e.removeSelectionAttribute(hp)}))})),this._enableTypeAroundUIInjection(),this._enableInsertingParagraphsOnButtonClick(),this._enableInsertingParagraphsOnEnterKeypress(),this._enableInsertingParagraphsOnTypingKeystroke(),this._enableTypeAroundFakeCaretActivationUsingKeyboardArrows(),this._enableDeleteIntegration(),this._enableInsertContentIntegration(),this._enableInsertObjectIntegration(),this._enableDeleteContentIntegration()}destroy(){super.destroy(),this._currentFakeCaretModelElement=null}_insertParagraph(e,t){const o=this.editor,i=o.editing.view,n=o.model.schema.getAttributesWithProperty(e,"copyOnReplace",!0);o.execute("insertParagraph",{position:o.model.createPositionAt(e,t),attributes:n}),i.focus(),i.scrollToTheSelection()}_listenToIfEnabled(e,t,o,i){this.listenTo(e,t,((...e)=>{this.isEnabled&&o(...e)}),i)}_insertParagraphAccordingToFakeCaretPosition(){const e=this.editor.model.document.selection,t=gp(e);if(!t)return!1;const o=e.getSelectedElement();return this._insertParagraph(o,t),!0}_enableTypeAroundUIInjection(){const e=this.editor,t=e.model.schema,o=e.locale.t,i={before:o("Insert paragraph before block"),after:o("Insert paragraph after block")};e.editing.downcastDispatcher.on("insert",((e,n,s)=>{const r=s.mapper.toViewElement(n.item);if(r&&mp(r,n.item,t)){!function(e,t,o){const i=e.createUIElement("div",{class:"ck ck-reset_all ck-widget__type-around"},(function(e){const o=this.toDomElement(e);return function(e,t){for(const o of pp){const i=new ou({tag:"div",attributes:{class:["ck","ck-widget__type-around__button",`ck-widget__type-around__button_${o}`],title:t[o],"aria-hidden":"true"},children:[e.ownerDocument.importNode(fp,!0)]});e.appendChild(i.render())}}(o,t),function(e){const t=new ou({tag:"div",attributes:{class:["ck","ck-widget__type-around__fake-caret"]}});e.appendChild(t.render())}(o),o}));e.insert(e.createPositionAt(o,"end"),i)}(s.writer,i,r);r.getCustomProperty("widgetLabel").push((()=>this.isEnabled?o("Press Enter to type after or press Shift + Enter to type before the widget"):""))}}),{priority:"low"})}_enableTypeAroundFakeCaretActivationUsingKeyboardArrows(){const e=this.editor,t=e.model,o=t.document.selection,i=t.schema,n=e.editing.view;function s(e){return`ck-widget_type-around_show-fake-caret_${e}`}this._listenToIfEnabled(n.document,"arrowKey",((e,t)=>{this._handleArrowKeyPress(e,t)}),{context:[ip,"$text"],priority:"high"}),this._listenToIfEnabled(o,"change:range",((t,o)=>{o.directChange&&e.model.change((e=>{e.removeSelectionAttribute(hp)}))})),this._listenToIfEnabled(t.document,"change:data",(()=>{const t=o.getSelectedElement();if(t){if(mp(e.editing.mapper.toViewElement(t),t,i))return}e.model.change((e=>{e.removeSelectionAttribute(hp)}))})),this._listenToIfEnabled(e.editing.downcastDispatcher,"selection",((e,t,o)=>{const n=o.writer;if(this._currentFakeCaretModelElement){const e=o.mapper.toViewElement(this._currentFakeCaretModelElement);e&&(n.removeClass(pp.map(s),e),this._currentFakeCaretModelElement=null)}const r=t.selection.getSelectedElement();if(!r)return;const a=o.mapper.toViewElement(r);if(!mp(a,r,i))return;const l=gp(t.selection);l&&(n.addClass(s(l),a),this._currentFakeCaretModelElement=r)})),this._listenToIfEnabled(e.ui.focusTracker,"change:isFocused",((t,o,i)=>{i||e.model.change((e=>{e.removeSelectionAttribute(hp)}))}))}_handleArrowKeyPress(e,t){const o=this.editor,i=o.model,n=i.document.selection,s=i.schema,r=o.editing.view;if(t.shiftKey)return;const a=function(e,t){const o=Kt(e,t);return"down"===o||"right"===o}(t.keyCode,o.locale.contentLanguageDirection),l=r.document.selection.getSelectedElement();let c;mp(l,o.editing.mapper.toModelElement(l),s)?c=this._handleArrowKeyPressOnSelectedWidget(a):n.isCollapsed?c=this._handleArrowKeyPressWhenSelectionNextToAWidget(a):t.shiftKey||(c=this._handleArrowKeyPressWhenNonCollapsedSelection(a)),c&&(t.preventDefault(),e.stop())}_handleArrowKeyPressOnSelectedWidget(e){const t=this.editor.model,o=gp(t.document.selection);return t.change((t=>{if(!o)return t.setSelectionAttribute(hp,e?"after":"before"),!0;if(!(o===(e?"after":"before")))return t.removeSelectionAttribute(hp),!0;return!1}))}_handleArrowKeyPressWhenSelectionNextToAWidget(e){const t=this.editor,o=t.model,i=o.schema,n=t.plugins.get("Widget"),s=n._getObjectElementNextToSelection(e);return!!mp(t.editing.mapper.toViewElement(s),s,i)&&(o.change((t=>{n._setSelectionOverElement(s),t.setSelectionAttribute(hp,e?"before":"after")})),!0)}_handleArrowKeyPressWhenNonCollapsedSelection(e){const t=this.editor,o=t.model,i=o.schema,n=t.editing.mapper,s=o.document.selection,r=e?s.getLastPosition().nodeBefore:s.getFirstPosition().nodeAfter;return!!mp(n.toViewElement(r),r,i)&&(o.change((t=>{t.setSelection(r,"on"),t.setSelectionAttribute(hp,e?"after":"before")})),!0)}_enableInsertingParagraphsOnButtonClick(){const e=this.editor,t=e.editing.view;this._listenToIfEnabled(t.document,"mousedown",((o,i)=>{const n=i.domTarget.closest(".ck-widget__type-around__button");if(!n)return;const s=function(e){return e.classList.contains("ck-widget__type-around__button_before")?"before":"after"}(n),r=function(e,t){const o=e.closest(".ck-widget");return t.mapDomToView(o)}(n,t.domConverter),a=e.editing.mapper.toModelElement(r);this._insertParagraph(a,s),i.preventDefault(),o.stop()}))}_enableInsertingParagraphsOnEnterKeypress(){const e=this.editor,t=e.model.document.selection,o=e.editing.view;this._listenToIfEnabled(o.document,"enter",((o,i)=>{if("atTarget"!=o.eventPhase)return;const n=t.getSelectedElement(),s=e.editing.mapper.toViewElement(n),r=e.model.schema;let a;this._insertParagraphAccordingToFakeCaretPosition()?a=!0:mp(s,n,r)&&(this._insertParagraph(n,i.isSoft?"before":"after"),a=!0),a&&(i.preventDefault(),o.stop())}),{context:ip})}_enableInsertingParagraphsOnTypingKeystroke(){const e=this.editor.editing.view.document;this._listenToIfEnabled(e,"insertText",((t,o)=>{this._insertParagraphAccordingToFakeCaretPosition()&&(o.selection=e.selection)}),{priority:"high"}),Y.isAndroid?this._listenToIfEnabled(e,"keydown",((e,t)=>{229==t.keyCode&&this._insertParagraphAccordingToFakeCaretPosition()})):this._listenToIfEnabled(e,"compositionstart",(()=>{this._insertParagraphAccordingToFakeCaretPosition()}),{priority:"highest"})}_enableDeleteIntegration(){const e=this.editor,t=e.editing.view,o=e.model,i=o.schema;this._listenToIfEnabled(t.document,"delete",((t,n)=>{if("atTarget"!=t.eventPhase)return;const s=gp(o.document.selection);if(!s)return;const r=n.direction,a=o.document.selection.getSelectedElement(),l="forward"==r;if("before"===s===l)e.execute("delete",{selection:o.createSelection(a,"on")});else{const t=i.getNearestSelectionRange(o.createPositionAt(a,s),r);if(t)if(t.isCollapsed){const n=o.createSelection(t.start);if(o.modifySelection(n,{direction:r}),n.focus.isEqual(t.start)){const e=function(e,t){let o=t;for(const i of t.getAncestors({parentFirst:!0})){if(i.childCount>1||e.isLimit(i))break;o=i}return o}(i,t.start.parent);o.deleteContent(o.createSelection(e,"on"),{doNotAutoparagraph:!0})}else o.change((o=>{o.setSelection(t),e.execute(l?"deleteForward":"delete")}))}else o.change((o=>{o.setSelection(t),e.execute(l?"deleteForward":"delete")}))}n.preventDefault(),t.stop()}),{context:ip})}_enableInsertContentIntegration(){const e=this.editor,t=this.editor.model,o=t.document.selection;this._listenToIfEnabled(e.model,"insertContent",((e,[i,n])=>{if(n&&!n.is("documentSelection"))return;const s=gp(o);return s?(e.stop(),t.change((e=>{const n=o.getSelectedElement(),r=t.createPositionAt(n,s),a=e.createSelection(r),l=t.insertContent(i,a);return e.setSelection(a),l}))):void 0}),{priority:"high"})}_enableInsertObjectIntegration(){const e=this.editor,t=this.editor.model.document.selection;this._listenToIfEnabled(e.model,"insertObject",((e,o)=>{const[,i,n={}]=o;if(i&&!i.is("documentSelection"))return;const s=gp(t);s&&(n.findOptimalPosition=s,o[3]=n)}),{priority:"high"})}_enableDeleteContentIntegration(){const e=this.editor,t=this.editor.model.document.selection;this._listenToIfEnabled(e.model,"deleteContent",((e,[o])=>{if(o&&!o.is("documentSelection"))return;gp(t)&&e.stop()}),{priority:"high"})}}function yp(e){const t=e.model;return(o,i)=>{const n=i.keyCode==qt.arrowup,s=i.keyCode==qt.arrowdown,r=i.shiftKey,a=t.document.selection;if(!n&&!s)return;const l=s,c=function(e,t,o){const i=e.model;if(o){const e=t.focus,o=_p(i,e,"forward");if(!o)return;const n=i.createRange(e,o),s=kp(i.schema,n,"backward");if(s)return i.createRange(e,s)}else{const e=t.focus,o=_p(i,e,"backward");if(!o)return;const n=i.createRange(o,e),s=kp(i.schema,n,"forward");if(s)return i.createRange(s,e)}}(e,a,l);if(c){if(c.isCollapsed){if(a.isCollapsed)return;if(r)return}(c.isCollapsed||function(e,t,o){const i=e.model,n=e.view.domConverter;if(o){const e=i.createSelection(t.start);i.modifySelection(e),e.focus.isAtEnd||t.start.isEqual(e.focus)||(t=i.createRange(e.focus,t.end))}const s=e.mapper.toViewRange(t),r=n.viewRangeToDom(s),a=ut.getDomRangeRects(r);let l;for(const e of a)if(void 0!==l){if(Math.round(e.top)>=l)return!1;l=Math.max(l,Math.round(e.bottom))}else l=Math.round(e.bottom);return!0}(e,c,l))&&(t.change((e=>{const o=l?c.end:c.start;if(r){const i=t.createSelection(a.anchor);i.setFocus(o),e.setSelection(i)}else e.setSelection(o)})),o.stop(),i.preventDefault(),i.stopPropagation())}}}function _p(e,t,o){const i=e.schema,n=e.createRangeIn(t.root),s="forward"==o?"elementStart":"elementEnd";for(const{previousPosition:e,item:r,type:a}of n.getWalker({startPosition:t,direction:o})){if(i.isLimit(r)&&!i.isInline(r))return e;if(a==s&&i.isBlock(r))return null}return null}function kp(e,t,o){const i="backward"==o?t.end:t.start;if(e.checkChild(i,"$text"))return i;for(const{nextPosition:i}of t.getWalker({direction:o}))if(e.checkChild(i,"$text"))return i}class vp extends fc{_previouslySelected=new Set;static get pluginName(){return"Widget"}static get isOfficialPlugin(){return!0}static get requires(){return[wp,Tg]}init(){const e=this.editor,t=e.editing.view,o=t.document,i=e.t;this.editor.editing.downcastDispatcher.on("selection",((t,o,i)=>{const n=i.writer,s=o.selection;if(s.isCollapsed)return;const r=s.getSelectedElement();if(!r)return;const a=e.editing.mapper.toViewElement(r);var l;ip(a)&&(i.consumable.consume(s,"selection")&&n.setSelection(n.createRangeOn(a),{fake:!0,label:(l=a,l.getCustomProperty("widgetLabel").reduce(((e,t)=>"function"==typeof t?e?e+". "+t():t():e?e+". "+t:t),""))}))})),this.editor.editing.downcastDispatcher.on("selection",((e,t,o)=>{this._clearPreviouslySelectedWidgets(o.writer);const i=o.writer,n=i.document.selection;let s=null;for(const e of n.getRanges())for(const t of e){const e=t.item;ip(e)&&!Cp(e,s)&&(i.addClass(op,e),this._previouslySelected.add(e),s=e)}}),{priority:"low"}),t.addObserver(il),t.addObserver(sl),this.listenTo(o,"mousedown",((...e)=>this._onMousedown(...e))),this.listenTo(o,"pointerdown",((...e)=>this._onPointerdown(...e))),this.listenTo(o,"arrowKey",((...e)=>{this._handleSelectionChangeOnArrowKeyPress(...e)}),{context:[ip,"$text"]}),this.listenTo(o,"arrowKey",((...e)=>{this._preventDefaultOnArrowKeyPress(...e)}),{context:"$root"}),this.listenTo(o,"arrowKey",yp(this.editor.editing),{context:"$text"}),this.listenTo(o,"delete",((e,t)=>{this._handleDelete("forward"==t.direction)&&(t.preventDefault(),e.stop())}),{context:"$root"}),this.listenTo(o,"tab",((e,o)=>{this._selectNextEditable(o.shiftKey?"backward":"forward")&&(t.scrollToTheSelection(),o.preventDefault(),e.stop())}),{context:e=>ip(e)||e.is("editableElement"),priority:"low"}),this.listenTo(o,"keydown",((e,t)=>{t.keystroke==qt.esc&&this._selectAncestorWidget()&&(t.preventDefault(),e.stop())}),{context:e=>e.is("editableElement"),priority:"low"}),e.accessibility.addKeystrokeInfoGroup({id:"widget",label:i("Keystrokes that can be used when a widget is selected (for example: image, table, etc.)"),keystrokes:[{label:i("Move focus from an editable area back to the parent widget"),keystroke:"Esc"},{label:i("Insert a new paragraph directly after a widget"),keystroke:"Enter"},{label:i("Insert a new paragraph directly before a widget"),keystroke:"Shift+Enter"},{label:i("Move the caret to allow typing directly before a widget"),keystroke:[["arrowup"],["arrowleft"]]},{label:i("Move the caret to allow typing directly after a widget"),keystroke:[["arrowdown"],["arrowright"]]}]})}_onMousedown(e,t){const o=t.target;o&&t.domEvent.detail>=3&&this._selectBlockContent(o)&&t.preventDefault()}_onPointerdown(e,t){if(!t.domEvent.isPrimary)return;const o=this.editor,i=o.editing.view,n=i.document;let s=t.target;if(!s)return;if(!ip(s)){const e=function(e){let t=e;for(;t;){if(t.is("editableElement")||ip(t))return t;t=t.parent}return null}(s);if(!e)return;if(ip(e))s=e;else{const e=function(e,t){const o=st(t.domEvent);let i=null;i=o?e.domConverter.domRangeToView(o):e.createRange(e.createPositionAt(t.target,0));if(!i)return null;const n=i.start;if(!n.parent)return null;let s=n.parent;n.parent.is("editableElement")&&(n.isAtEnd&&n.nodeBefore?s=n.nodeBefore:n.isAtStart&&n.nodeAfter&&(s=n.nodeAfter));if(s.is("$text"))return s.parent;return s}(i,t);if(!e||!ip(e))return;s=e}}(Y.isAndroid||Y.isiOS)&&t.preventDefault(),n.isFocused||i.focus();const r=o.editing.mapper.toModelElement(s);this._setSelectionOverElement(r)}_selectBlockContent(e){const t=this.editor,o=t.model,i=t.editing.mapper,n=o.schema,s=i.findMappedViewAncestor(this.editor.editing.view.createPositionAt(e,0)),r=function(e,t){for(const o of e.getAncestors({includeSelf:!0,parentFirst:!0})){if(t.checkChild(o,"$text"))return o;if(t.isLimit(o)&&!t.isObject(o))break}return null}(i.toModelElement(s),o.schema);return!!r&&(o.change((e=>{const t=n.isLimit(r)?null:function(e,t){const o=new is({startPosition:e});for(const{item:e}of o){if(t.isLimit(e)||!e.is("element"))return null;if(t.checkChild(e,"$text"))return e}return null}(e.createPositionAfter(r),n),o=e.createPositionAt(r,0),i=t?e.createPositionAt(t,0):e.createPositionAt(r,"end");e.setSelection(e.createRange(o,i))})),!0)}_handleSelectionChangeOnArrowKeyPress(e,t){const o=t.keyCode,i=this.editor.model,n=i.schema,s=i.document.selection,r=s.getSelectedElement(),a=Kt(o,this.editor.locale.contentLanguageDirection),l="down"==a||"right"==a,c="up"==a||"down"==a;if(!t.shiftKey&&!s.isCollapsed){if(function(e,t){const o=e.getFirstPosition(),i=e.getLastPosition(),n=o.nodeAfter,s=i.nodeBefore;return!!n&&t.isObject(n)||!!s&&t.isObject(s)}(s,n)){const o=l?s.getLastPosition():s.getFirstPosition(),r=n.getNearestSelectionRange(o,l?"forward":"backward");r&&(i.change((e=>{e.setSelection(r)})),t.preventDefault(),e.stop())}return}const d=function(e,t){const o=e.document.selection,i=o.getSelectedElement(),n=gp(o);if(i&&"before"==n)return e.createSelection(i,"before");if(i&&"after"==n)return e.createSelection(i,"after");return e.createSelection(o.getRanges(),{backward:i&&e.schema.isObject(i)?!t:o.isBackward})}(i,l),u=i.createSelection(d);if(i.modifySelection(u,{direction:l?"forward":"backward"}),u.isEqual(d))return;u.focus.isTouching(d.focus)&&n.checkChild(u.focus.parent,"$text")&&(l?!u.focus.isAtEnd:!u.focus.isAtStart)&&i.modifySelection(u,{direction:l?"forward":"backward"});const h=l?d.focus.nodeBefore:d.focus.nodeAfter,m=u.focus.nodeBefore,g=u.focus.nodeAfter,p=l?m:g;if(t.shiftKey)(r&&n.isObject(r)||p&&n.isObject(p)||h&&n.isObject(h))&&(i.change((e=>{e.setSelection(u)})),t.preventDefault(),e.stop());else if(p&&n.isObject(p)){if(n.isInline(p)&&c)return;i.change((e=>{e.setSelection(p,"on")})),t.preventDefault(),e.stop()}}_preventDefaultOnArrowKeyPress(e,t){const o=this.editor.model,i=o.schema,n=o.document.selection.getSelectedElement();n&&i.isObject(n)&&(t.preventDefault(),e.stop())}_handleDelete(e){const t=this.editor.model.document.selection;if(!this.editor.model.canEditAt(t))return;if(!t.isCollapsed)return;const o=this._getObjectElementNextToSelection(e);return o?(this.editor.model.change((e=>{let i=t.anchor.parent;for(;i.isEmpty;){const t=i;i=t.parent,e.remove(t)}this._setSelectionOverElement(o)})),!0):void 0}_setSelectionOverElement(e){this.editor.model.change((t=>{t.setSelection(t.createRangeOn(e))}))}_getObjectElementNextToSelection(e){const t=this.editor.model,o=t.schema,i=t.document.selection,n=t.createSelection(i);if(t.modifySelection(n,{direction:e?"forward":"backward"}),n.isEqual(i))return null;const s=e?n.focus.nodeBefore:n.focus.nodeAfter;return s&&o.isObject(s)?s:null}_clearPreviouslySelectedWidgets(e){for(const t of this._previouslySelected)e.removeClass(op,t);this._previouslySelected.clear()}_selectNextEditable(e){const t=this.editor.editing,o=t.view,i=this.editor.model,n=o.document.selection,s=i.document.selection;let r;if(s.rangeCount>1){const o=s.isBackward?s.getFirstRange():s.getLastRange();r=t.mapper.toViewPosition("forward"==e?o.end:o.start)}else r="forward"==e?n.getFirstPosition():n.getLastPosition();const a=this._findNextFocusRange(r,e);return!!a&&(i.change((e=>{e.setSelection(a)})),!0)}_findNextFocusRange(e,t){const o=this.editor.editing,i=o.view,n=this.editor.model,s=i.document.selection,r=s.editableElement,a=r.getPath();let l=s.getSelectedElement();l&&!ip(l)&&(l=null);const c="forward"==t?i.createRange(e,i.createPositionAt(e.root,"end")):i.createRange(i.createPositionAt(e.root,0),e);for(const{nextPosition:e}of c.getWalker({direction:t})){const i=e.parent;if(ip(i)&&i!=l){const e=o.mapper.toModelElement(i);if(!n.schema.isBlock(e))continue;if("extension"!=We(a,i.getPath()))return n.createRangeOn(e)}else if(i.is("editableElement")){if(i==r&&!l)continue;const s=o.mapper.toModelPosition(e),c=n.schema.getNearestSelectionRange(s,t);if(!c)continue;return i==r&&l?c:"extension"!=We(a,i.getPath())?n.createRangeIn(n.schema.getLimitElement(c)):c}}return null}_selectAncestorWidget(){const e=this.editor,t=e.editing.mapper,o=e.editing.view.document.selection.getFirstPosition().parent,i=(o.is("$text")?o.parent:o).findAncestor(ip);if(!i)return!1;const n=t.toModelElement(i);return!!n&&(e.model.change((e=>{e.setSelection(n,"on")})),!0)}}function Cp(e,t){return!!t&&Array.from(e.getAncestors()).includes(t)}class Ap extends fc{_toolbarDefinitions=new Map;_balloon;static get requires(){return[Qm]}static get pluginName(){return"WidgetToolbarRepository"}static get isOfficialPlugin(){return!0}init(){const e=this.editor;if(e.plugins.has("BalloonToolbar")){const t=e.plugins.get("BalloonToolbar");this.listenTo(t,"show",(t=>{(function(e){const t=e.getSelectedElement();return!(!t||!ip(t))})(e.editing.view.document.selection)&&t.stop()}),{priority:"high"})}this._balloon=this.editor.plugins.get("ContextualBalloon"),this.on("change:isEnabled",(()=>{this._updateToolbarsVisibility()})),this.listenTo(e.ui,"update",(()=>{this._updateToolbarsVisibility()})),this.listenTo(e.ui.focusTracker,"change:isFocused",(()=>{this._updateToolbarsVisibility()}),{priority:"low"})}destroy(){super.destroy();for(const e of this._toolbarDefinitions.values())e.view.destroy()}register(e,{ariaLabel:t,items:o,getRelatedElement:i,balloonClassName:n="ck-toolbar-container",positions:s}){if(!o.length)return void be("widget-toolbar-no-items",{toolbarId:e});const r=this.editor,a=r.t,l=new Wh(r.locale);if(l.ariaLabel=t||a("Widget toolbar"),this._toolbarDefinitions.has(e))throw new fe("widget-toolbar-duplicated",this,{toolbarId:e});const c={view:l,getRelatedElement:i,balloonClassName:n,itemsConfig:o,positions:s,initialized:!1};r.ui.addToolbar(l,{isContextual:!0,beforeFocus:()=>{const e=i(r.editing.view.document.selection);e&&this._showToolbar(c,e)},afterBlur:()=>{this._hideToolbar(c)}}),this._toolbarDefinitions.set(e,c)}_updateToolbarsVisibility(){let e=0,t=null,o=null;for(const i of this._toolbarDefinitions.values()){const n=i.getRelatedElement(this.editor.editing.view.document.selection);if(this.isEnabled&&n)if(this.editor.ui.focusTracker.isFocused){const s=n.getAncestors().length;s>e&&(e=s,t=n,o=i)}else this._isToolbarVisible(i)&&this._hideToolbar(i);else this._isToolbarInBalloon(i)&&this._hideToolbar(i)}o&&this._showToolbar(o,t)}_hideToolbar(e){this._balloon.remove(e.view),this.stopListening(this._balloon,"change:visibleView")}_showToolbar(e,t){this._isToolbarVisible(e)?xp(this.editor,t,e.positions):this._isToolbarInBalloon(e)||(e.initialized||(e.initialized=!0,e.view.fillFromConfig(e.itemsConfig,this.editor.ui.componentFactory)),this._balloon.add({view:e.view,position:Ep(this.editor,t,e.positions),balloonClassName:e.balloonClassName}),this.listenTo(this._balloon,"change:visibleView",(()=>{for(const t of this._toolbarDefinitions.values())if(this._isToolbarVisible(t)){const o=t.getRelatedElement(this.editor.editing.view.document.selection);xp(this.editor,o,e.positions)}})))}_isToolbarVisible(e){return this._balloon.visibleView===e.view}_isToolbarInBalloon(e){return this._balloon.hasView(e.view)}}function xp(e,t,o){const i=e.plugins.get("ContextualBalloon"),n=Ep(e,t,o);i.updatePosition(n)}function Ep(e,t,o){const i=e.editing.view,n=dh.defaultPositions;return{target:i.domConverter.mapViewToDom(t),positions:o||[n.northArrowSouth,n.northArrowSouthWest,n.northArrowSouthEast,n.southArrowNorth,n.southArrowNorthWest,n.southArrowNorthEast,n.viewportStickyNorth]}}class Tp extends(Be()){_referenceCoordinates;_options;_originalWidth;_originalHeight;_originalWidthPercents;_aspectRatio;constructor(e){super(),this.set("activeHandlePosition",null),this.set("proposedWidthPercents",null),this.set("proposedWidth",null),this.set("proposedHeight",null),this.set("proposedHandleHostWidth",null),this.set("proposedHandleHostHeight",null),this._options=e,this._referenceCoordinates=null}get originalWidth(){return this._originalWidth}get originalHeight(){return this._originalHeight}get originalWidthPercents(){return this._originalWidthPercents}get aspectRatio(){return this._aspectRatio}begin(e,t,o){const i=new ut(t);this.activeHandlePosition=function(e){const t=["top-left","top-right","bottom-right","bottom-left"];for(const o of t)if(e.classList.contains(Pp(o)))return o}(e),this._referenceCoordinates=function(e,t){const o=new ut(e),i=t.split("-"),n={x:"right"==i[1]?o.right:o.left,y:"bottom"==i[0]?o.bottom:o.top};return n.x+=e.ownerDocument.defaultView.scrollX,n.y+=e.ownerDocument.defaultView.scrollY,n}(t,function(e){const t=e.split("-"),o={top:"bottom",bottom:"top",left:"right",right:"left"};return`${o[t[0]]}-${o[t[1]]}`}(this.activeHandlePosition)),this._originalWidth=i.width,this._originalHeight=i.height,this._aspectRatio=i.width/i.height;const n=o.style.width;n&&n.match(/^\d+(\.\d*)?%$/)?this._originalWidthPercents=parseFloat(n):this._originalWidthPercents=function(e,t=new ut(e)){const o=up(e);return o?t.width/o*100:0}(o,i)}update(e){this.proposedWidth=e.width,this.proposedHeight=e.height,this.proposedWidthPercents=e.widthPercents,this.proposedHandleHostWidth=e.handleHostWidth,this.proposedHandleHostHeight=e.handleHostHeight}}function Pp(e){return`ck-widget__resizer__handle-${e}`}class Sp extends Au{constructor(){super();const e=this.bindTemplate;this.setTemplate({tag:"div",attributes:{class:["ck","ck-size-view",e.to("_viewPosition",(e=>e?`ck-orientation-${e}`:""))],style:{display:e.if("_isVisible","none",(e=>!e))}},children:[{text:e.to("_label")}]})}_bindToState(e,t){this.bind("_isVisible").to(t,"proposedWidth",t,"proposedHeight",((e,t)=>null!==e&&null!==t)),this.bind("_label").to(t,"proposedHandleHostWidth",t,"proposedHandleHostHeight",t,"proposedWidthPercents",((t,o,i)=>"px"===e.unit?`${t}×${o}`:`${i}%`)),this.bind("_viewPosition").to(t,"activeHandlePosition",t,"proposedHandleHostWidth",t,"proposedHandleHostHeight",((e,t,o)=>t<50||o<50?"above-center":e))}_dismiss(){this.unbind(),this._isVisible=!1}}class Ip extends(Be()){_state;_sizeView;_options;_viewResizerWrapper=null;_initialViewWidth;constructor(e){super(),this._options=e,this.set("isEnabled",!0),this.set("isSelected",!1),this.bind("isVisible").to(this,"isEnabled",this,"isSelected",((e,t)=>e&&t)),this.decorate("begin"),this.decorate("cancel"),this.decorate("commit"),this.decorate("updateSize"),this.on("commit",(e=>{this.state.proposedWidth||this.state.proposedWidthPercents||(this._cleanup(),e.stop())}),{priority:"high"})}get state(){return this._state}show(){this._options.editor.editing.view.change((e=>{e.removeClass("ck-hidden",this._viewResizerWrapper)}))}hide(){this._options.editor.editing.view.change((e=>{e.addClass("ck-hidden",this._viewResizerWrapper)}))}attach(){const e=this,t=this._options.viewElement;this._options.editor.editing.view.change((o=>{const i=o.createUIElement("div",{class:"ck ck-reset_all ck-widget__resizer"},(function(t){const o=this.toDomElement(t);return e._appendHandles(o),e._appendSizeUI(o),o}));o.insert(o.createPositionAt(t,"end"),i),o.addClass("ck-widget_with-resizer",t),this._viewResizerWrapper=i,this.isVisible||this.hide()})),this.on("change:isVisible",(()=>{this.isVisible?(this.show(),this.redraw()):this.hide()}))}begin(e){this._state=new Tp(this._options),this._sizeView._bindToState(this._options,this.state),this._initialViewWidth=this._options.viewElement.getStyle("width"),this.state.begin(e,this._getHandleHost(),this._getResizeHost())}updateSize(e){const t=this._proposeNewSize(e);this._options.editor.editing.view.change((e=>{const o=this._options.unit||"%",i=("%"===o?t.widthPercents:t.width)+o;e.setStyle("width",i,this._options.viewElement)}));const o=this._getHandleHost(),i=new ut(o),n=Math.round(i.width),s=Math.round(i.height),r=new ut(o);t.width=Math.round(r.width),t.height=Math.round(r.height),this.redraw(i),this.state.update({...t,handleHostWidth:n,handleHostHeight:s})}commit(){const e=this._options.unit||"%",t=("%"===e?this.state.proposedWidthPercents:this.state.proposedWidth)+e;this._options.editor.editing.view.change((()=>{this._cleanup(),this._options.onCommit(t)}))}cancel(){this._cleanup()}destroy(){this.cancel()}redraw(e){const t=this._domResizerWrapper;if(!((o=t)&&o.ownerDocument&&o.ownerDocument.contains(o)))return;var o;const i=t.parentElement,n=this._getHandleHost(),s=this._viewResizerWrapper,r=[s.getStyle("width"),s.getStyle("height"),s.getStyle("left"),s.getStyle("top")];let a;if(i.isSameNode(n)){const t=e||new ut(n);a=[t.width+"px",t.height+"px",void 0,void 0]}else a=[n.offsetWidth+"px",n.offsetHeight+"px",n.offsetLeft+"px",n.offsetTop+"px"];"same"!==We(r,a)&&this._options.editor.editing.view.change((e=>{e.setStyle({width:a[0],height:a[1],left:a[2],top:a[3]},s)}))}containsHandle(e){return this._domResizerWrapper.contains(e)}static isResizeHandle(e){return e.classList.contains("ck-widget__resizer__handle")}_cleanup(){this._sizeView._dismiss();this._options.editor.editing.view.change((e=>{e.setStyle("width",this._initialViewWidth,this._options.viewElement)}))}_proposeNewSize(e){const t=this.state,o={x:(i=e).pageX,y:i.pageY};var i;const n=!this._options.isCentered||this._options.isCentered(this),s={x:t._referenceCoordinates.x-(o.x+t.originalWidth),y:o.y-t.originalHeight-t._referenceCoordinates.y};n&&t.activeHandlePosition.endsWith("-right")&&(s.x=o.x-(t._referenceCoordinates.x+t.originalWidth)),n&&(s.x*=2);let r=Math.abs(t.originalWidth+s.x),a=Math.abs(t.originalHeight+s.y);return"width"==(r/t.aspectRatio>a?"width":"height")?a=r/t.aspectRatio:r=a*t.aspectRatio,{width:Math.round(r),height:Math.round(a),widthPercents:Math.min(Math.round(t.originalWidthPercents/t.originalWidth*r*100)/100,100)}}_getResizeHost(){const e=this._domResizerWrapper.parentElement;return this._options.getResizeHost(e)}_getHandleHost(){const e=this._domResizerWrapper.parentElement;return this._options.getHandleHost(e)}get _domResizerWrapper(){return this._options.editor.editing.view.domConverter.mapViewToDom(this._viewResizerWrapper)}_appendHandles(e){const t=["top-left","top-right","bottom-right","bottom-left"];for(const i of t)e.appendChild(new ou({tag:"div",attributes:{class:"ck-widget__resizer__handle "+(o=i,`ck-widget__resizer__handle-${o}`)}}).render());var o}_appendSizeUI(e){this._sizeView=new Sp,this._sizeView.render(),e.appendChild(this._sizeView.element)}}class Rp extends fc{_resizers=new Map;_observer;_redrawSelectedResizerThrottled;static get pluginName(){return"WidgetResize"}static get isOfficialPlugin(){return!0}init(){const e=this.editor.editing,t=J.window.document;this.set("selectedResizer",null),this.set("_activeResizer",null),e.view.addObserver(il),this._observer=new(et()),this.listenTo(e.view.document,"mousedown",this._mouseDownListener.bind(this),{priority:"high"}),this._observer.listenTo(t,"mousemove",this._mouseMoveListener.bind(this)),this._observer.listenTo(t,"mouseup",this._mouseUpListener.bind(this)),this._redrawSelectedResizerThrottled=oc((()=>this.redrawSelectedResizer()),200),this.editor.ui.on("update",this._redrawSelectedResizerThrottled),this.editor.model.document.on("change",(()=>{for(const[e,t]of this._resizers)e.isAttached()||(this._resizers.delete(e),t.destroy())}),{priority:"lowest"}),this._observer.listenTo(J.window,"resize",this._redrawSelectedResizerThrottled);const o=this.editor.editing.view.document.selection;o.on("change",(()=>{const e=o.getSelectedElement(),t=this.getResizerByViewElement(e)||null;t?this.select(t):this.deselect()}))}redrawSelectedResizer(){this.selectedResizer&&this.selectedResizer.isVisible&&this.selectedResizer.redraw()}destroy(){super.destroy(),this._observer.stopListening();for(const e of this._resizers.values())e.destroy();this._redrawSelectedResizerThrottled.cancel()}select(e){this.deselect(),this.selectedResizer=e,this.selectedResizer.isSelected=!0}deselect(){this.selectedResizer&&(this.selectedResizer.isSelected=!1),this.selectedResizer=null}attachTo(e){const t=new Ip(e),o=this.editor.plugins;if(t.attach(),o.has("WidgetToolbarRepository")){const e=o.get("WidgetToolbarRepository");t.on("begin",(()=>{e.forceDisabled("resize")}),{priority:"lowest"}),t.on("cancel",(()=>{e.clearForceDisabled("resize")}),{priority:"highest"}),t.on("commit",(()=>{e.clearForceDisabled("resize")}),{priority:"highest"})}this._resizers.set(e.viewElement,t);const i=this.editor.editing.view.document.selection.getSelectedElement();return this.getResizerByViewElement(i)==t&&this.select(t),t}getResizerByViewElement(e){return this._resizers.get(e)}_getResizerByHandle(e){for(const t of this._resizers.values())if(t.containsHandle(e))return t}_mouseDownListener(e,t){const o=t.domTarget;Ip.isResizeHandle(o)&&(this._activeResizer=this._getResizerByHandle(o)||null,this._activeResizer&&(this._activeResizer.begin(o),e.stop(),t.preventDefault()))}_mouseMoveListener(e,t){this._activeResizer&&this._activeResizer.updateSize(t)}_mouseUpListener(){this._activeResizer&&(this._activeResizer.commit(),this._activeResizer=null)}}class Op extends fc{static get pluginName(){return"OPMacroToc"}static get buttonName(){return"insertToc"}init(){const e=this.editor,t=e.model,o=e.conversion;t.schema.register("op-macro-toc",{allowWhere:"$block",isBlock:!0,isLimit:!0}),o.for("upcast").elementToElement({view:{name:"macro",classes:"toc"},model:"op-macro-toc"}),o.for("editingDowncast").elementToElement({model:"op-macro-toc",view:(e,{writer:t})=>np(this.createTocViewElement(t),t,{label:this.label})}),o.for("dataDowncast").elementToElement({model:"op-macro-toc",view:(e,{writer:t})=>this.createTocDataElement(t)}),e.ui.componentFactory.add(Op.buttonName,(t=>{const o=new Lu(t);return o.set({label:this.label,withText:!0}),o.on("execute",(()=>{e.model.change((t=>{const o=t.createElement("op-macro-toc",{});e.model.insertContent(o,e.model.document.selection)}))})),o}))}get label(){return window.I18n.t("js.editor.macro.toc")}createTocViewElement(e){const t=e.createText(this.label),o=e.createContainerElement("div");return e.insert(e.createPositionAt(o,0),t),o}createTocDataElement(e){return e.createContainerElement("macro",{class:"toc"})}}const Vp=Symbol("isOPEmbeddedTable");function Dp(e){const t=e.getSelectedElement();return!(!t||!function(e){return!!e.getCustomProperty(Vp)&&ip(e)}(t))}function Fp(e){return _.get(e.config,"_config.openProject.context.resource")}function Mp(e){return _.get(e.config,"_config.openProject.pluginContext")}function Np(e,t){return Mp(e).services[t]}function Bp(e){return Np(e,"pathHelperService")}function Lp(e){return Np(e,"i18n")}class zp extends fc{static get pluginName(){return"EmbeddedTableEditing"}static get buttonName(){return"insertEmbeddedTable"}init(){const e=this.editor,t=e.model,o=e.conversion,i=Mp(e);this.text={button:window.I18n.t("js.editor.macro.embedded_table.button"),macro_text:window.I18n.t("js.editor.macro.embedded_table.text")},t.schema.register("op-macro-embedded-table",{allowWhere:"$block",allowAttributes:["opEmbeddedTableQuery"],isBlock:!0,isObject:!0}),o.for("upcast").elementToElement({view:{name:"macro",classes:"embedded-table"},model:(e,{writer:t})=>{const o=e.getAttribute("data-query-props");return t.createElement("op-macro-embedded-table",{opEmbeddedTableQuery:o?JSON.parse(o):{}})}}),o.for("editingDowncast").elementToElement({model:"op-macro-embedded-table",view:(e,{writer:t})=>{return o=this.createEmbeddedTableView(t),i=t,this.label,i.setCustomProperty(Vp,!0,o),np(o,i,{label:"your label here"});var o,i}}),o.for("dataDowncast").elementToElement({model:"op-macro-embedded-table",view:(e,{writer:t})=>this.createEmbeddedTableDataElement(e,t)}),e.ui.componentFactory.add(zp.buttonName,(t=>{const o=new Lu(t);return o.set({label:this.text.button,withText:!0}),o.on("execute",(()=>i.runInZone((()=>{i.services.externalQueryConfiguration.show({currentQuery:{},callback:t=>e.model.change((o=>{const i=o.createElement("op-macro-embedded-table",{opEmbeddedTableQuery:t});e.model.insertContent(i,e.model.document.selection)}))})})))),o}))}createEmbeddedTableView(e){const t=e.createText(this.text.macro_text),o=e.createContainerElement("div");return e.insert(e.createPositionAt(o,0),t),o}createEmbeddedTableDataElement(e,t){const o=e.getAttribute("opEmbeddedTableQuery")||{};return t.createContainerElement("macro",{class:"embedded-table","data-query-props":JSON.stringify(o)})}}function jp(e,t,o){e.ui.componentFactory.add(t,(t=>{const i=new Lu(t);return i.set({label:I18n.t("js.button_edit"),icon:'\n',tooltip:!0}),i.on("execute",(()=>{const t=e.model.document.selection.getSelectedElement();t&&o(t)})),i}))}const qp="ck-toolbar-container";function $p(e,t,o,i){const n=t.config.get(o+".toolbar");if(!n||!n.length)return;const s=t.plugins.get("ContextualBalloon"),r=new Wh(t.locale);function a(){t.ui.focusTracker.isFocused&&i(t.editing.view.document.selection)?c()?function(e,t){const o=e.plugins.get("ContextualBalloon");if(t(e.editing.view.document.selection)){const t=Hp(e);o.updatePosition(t)}}(t,i):s.hasView(r)||s.add({view:r,position:Hp(t),balloonClassName:qp}):l()}function l(){c()&&s.remove(r)}function c(){return s.visibleView==r}r.fillFromConfig(n,t.ui.componentFactory),e.listenTo(t.editing.view,"render",a),e.listenTo(t.ui.focusTracker,"change:isFocused",a,{priority:"low"})}function Hp(e){const t=e.editing.view,o=dh.defaultPositions;return{target:t.domConverter.viewToDom(t.document.selection.getSelectedElement()),positions:[o.northArrowSouth,o.northArrowSouthWest,o.northArrowSouthEast,o.southArrowNorth,o.southArrowNorthWest,o.southArrowNorthEast]}}class Wp extends fc{static get requires(){return[Qm]}static get pluginName(){return"EmbeddedTableToolbar"}init(){const e=this.editor,t=this.editor.model,o=Mp(e);jp(e,"opEditEmbeddedTableQuery",(e=>{const i=o.services.externalQueryConfiguration,n=e.getAttribute("opEmbeddedTableQuery")||{};o.runInZone((()=>{i.show({currentQuery:n,callback:o=>t.change((t=>{t.setAttribute("opEmbeddedTableQuery",o,e)}))})}))}))}afterInit(){$p(this,this.editor,"OPMacroEmbeddedTable",Dp)}}const Up=Symbol("isWpButtonMacroSymbol");function Kp(e){const t=e.getSelectedElement();return!(!t||!function(e){return!!e.getCustomProperty(Up)&&ip(e)}(t))}class Gp extends fc{static get pluginName(){return"OPMacroWpButtonEditing"}static get buttonName(){return"insertWorkPackageButton"}init(){const e=this.editor,t=e.model,o=e.conversion,i=Mp(e);t.schema.register("op-macro-wp-button",{allowWhere:["$block"],allowAttributes:["type","classes"],isBlock:!0,isLimit:!0}),o.for("upcast").elementToElement({view:{name:"macro",classes:"create_work_package_link"},model:(e,{writer:t})=>{const o=e.getAttribute("data-type")||"",i=e.getAttribute("data-classes")||"";return t.createElement("op-macro-wp-button",{type:o,classes:i})}}),o.for("editingDowncast").elementToElement({model:"op-macro-wp-button",view:(e,{writer:t})=>this.createMacroViewElement(e,t)}),o.for("dataDowncast").elementToElement({model:"op-macro-wp-button",view:(e,{writer:t})=>t.createContainerElement("macro",{class:"create_work_package_link","data-type":e.getAttribute("type")||"","data-classes":e.getAttribute("classes")||""})}),e.ui.componentFactory.add(Gp.buttonName,(t=>{const o=new Lu(t);return o.set({label:window.I18n.t("js.editor.macro.work_package_button.button"),withText:!0}),o.on("execute",(()=>{i.services.macros.configureWorkPackageButton().then((t=>e.model.change((o=>{const i=o.createElement("op-macro-wp-button",{});o.setAttribute("type",t.type,i),o.setAttribute("classes",t.classes,i),e.model.insertContent(i,e.model.document.selection)}))))})),o}))}macroLabel(e){return e?window.I18n.t("js.editor.macro.work_package_button.with_type",{typename:e}):window.I18n.t("js.editor.macro.work_package_button.without_type")}createMacroViewElement(e,t){const o=e.getAttribute("classes")||"",i=this.macroLabel(),n=t.createText(i),s=t.createContainerElement("span",{class:o});return t.insert(t.createPositionAt(s,0),n),function(e,t,o){return t.setCustomProperty(Up,!0,e),np(e,t,{label:o})}(s,t,{label:i})}}class Jp extends fc{static get requires(){return[Qm]}static get pluginName(){return"OPMacroWpButtonToolbar"}init(){const e=this.editor,t=Mp(e);jp(e,"opEditWpMacroButton",(o=>{const i=t.services.macros,n=o.getAttribute("type"),s=o.getAttribute("classes");i.configureWorkPackageButton(n,s).then((t=>e.model.change((e=>{e.setAttribute("classes",t.classes,o),e.setAttribute("type",t.type,o)}))))}))}afterInit(){$p(this,this.editor,"OPMacroWpButton",Kp)}}class Zp extends(Be()){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(((o,i)=>{t.onload=()=>{const e=t.result;this._data=e,o(e)},t.onerror=()=>{i("error")},t.onabort=()=>{i("aborted")},this._reader.readAsDataURL(e)}))}abort(){this._reader.abort()}}class Qp extends fc{loaders=new eo;_loadersMap=new Map;_pendingAction=null;static get pluginName(){return"FileRepository"}static get isOfficialPlugin(){return!0}static get requires(){return[Lc]}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 be("filerepository-no-upload-adapter"),null;const t=new Yp(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 Yp?e:this.getLoader(e);t._destroy(),this.loaders.remove(t),this._loadersMap.forEach(((e,o)=>{e===t&&this._loadersMap.delete(o)}))}_updatePendingAction(){const e=this.editor.plugins.get(Lc);if(this.loaders.length){if(!this._pendingAction){const t=this.editor.t,o=e=>`${t("Upload in progress")} ${parseInt(e)}%.`;this._pendingAction=e.add(o(this.uploadedPercent)),this._pendingAction.bind("message").to(this,"uploadedPercent",o)}}else e.remove(this._pendingAction),this._pendingAction=null}}class Yp extends(Be()){id;_filePromiseWrapper;_adapter;_reader;constructor(e,t){super(),this.id=me(),this._filePromiseWrapper=this._createFilePromiseWrapper(e),this._adapter=t(this),this._reader=new Zp,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(((o,i)=>{t.rejecter=i,t.isFulfilled=!1,e.then((e=>{t.isFulfilled=!0,o(e)})).catch((e=>{t.isFulfilled=!0,i(e)}))})),t}}class Xp{constructor(e,t,o){this.loader=e,this.resource=t,this.editor=o}upload(){const e=this.resource,t=Np(this.editor,"attachmentsResourceService");return e?this.loader.file.then((o=>t.attachFiles(e,[o]).toPromise().then((e=>(this.editor.model.fire("op:attachment-added",e),this.buildResponse(e[0])))).catch((e=>{console.error("Failed upload %O",e)})))):(console.warn("resource not available in this CKEditor instance"),Promise.reject("Not possible to upload attachments without resource"))}buildResponse(e){return{default:e._links.staticDownloadLocation.href}}abort(){return!1}}function ef(e){return e}function tf(e,t,o){return"function"!=typeof o?tf(e,t,(()=>{})):of(e,t,(function e(t,i,n,s,r,a){const l=o(t,i,n,s,r,a);return void 0!==l?Boolean(l):of(t,i,e,a)}),new Map)}function of(e,t,o,i){if(t===e)return!0;switch(typeof t){case"object":return function(e,t,o,i){if(null==t)return!0;if(Array.isArray(t))return nf(e,t,o,i);if(t instanceof Map)return function(e,t,o,i){if(0===t.size)return!0;if(!(e instanceof Map))return!1;for(const[n,s]of t.entries()){if(!1===o(e.get(n),s,n,e,t,i))return!1}return!0}(e,t,o,i);if(t instanceof Set)return function(e,t,o,i){if(0===t.size)return!0;if(!(e instanceof Set))return!1;return nf([...e],[...t],o,i)}(e,t,o,i);const n=Object.keys(t);if(null==e||V(e))return 0===n.length;if(0===n.length)return!0;if(i?.has(t))return i.get(t)===e;i?.set(t,e);try{for(let s=0;s0?of(e,{...t},o,i):Co(e,t);default:return s(e)?"string"!=typeof t||""===t:Co(e,t)}}function nf(e,t,o,i){if(0===t.length)return!0;if(!Array.isArray(e))return!1;const n=new Set;for(let s=0;s{}))}function rf(e){var t;return e=F(t=e,void 0,t,new Map,void 0),t=>sf(t,e)}function af(e,t){let o;if(o=Array.isArray(t)?t:"string"==typeof t&&wo(t)&&null==e?.[t]?ko(t):[t],0===o.length)return!1;let i=e;for(let e=0;e{i.preventDefault();const n=i.dropRange?[i.dropRange]:null,s=new ue(t,e);t.fire(s,{dataTransfer:i.dataTransfer,method:o.name,targetRanges:n,target:i.target,domEvent:i.domEvent}),s.stop.called&&i.stopPropagation()}}this.listenTo(t,"paste",o("clipboardInput"),{priority:"low"}),this.listenTo(t,"drop",o("clipboardInput"),{priority:"low"}),this.listenTo(t,"dragover",o("dragging"),{priority:"low"})}onDomEvent(e){const t="clipboardData"in e?e.clipboardData:e.dataTransfer,o="drop"==e.type||"paste"==e.type,i={dataTransfer:new Jn(t,{cacheFiles:o})};if("drop"==e.type||"dragover"==e.type){const t=st(e);i.dropRange=t&&this.view.domConverter.domRangeToView(t)}this.fire(e.type,e,i)}}const uf=["figcaption","li"],hf=["ol","ul"];function mf(e,t){if(t.is("$text")||t.is("$textProxy"))return t.data;if(t.is("element","img")&&t.hasAttribute("alt"))return t.getAttribute("alt");if(t.is("element","br"))return"\n";let o="",i=null;for(const n of t.getChildren())o+=pf(n,i)+mf(e,n),i=n;if(t.is("rawElement")){const i=document.implementation.createHTMLDocument("").createElement("div");t.render(i,e),o+=gf(i)}return o}function gf(e){let t="";if(e.nodeType===Node.TEXT_NODE)return e.textContent;if("BR"===e.tagName)return"\n";for(const o of e.childNodes)t+=gf(o);return t}function pf(e,t){return t?e.is("element","li")&&!e.isEmpty&&e.getChild(0).is("containerElement")||hf.includes(e.name)&&hf.includes(t.name)?"\n\n":e.is("containerElement")||t.is("containerElement")?uf.includes(e.name)||uf.includes(t.name)?"\n":e.is("element")&&e.getCustomProperty("dataPipeline:transparentRendering")||t.is("element")&&t.getCustomProperty("dataPipeline:transparentRendering")?"":"\n\n":"":""}class ff extends fc{_markersToCopy=new Map;static get pluginName(){return"ClipboardMarkersUtils"}static get isOfficialPlugin(){return!0}_registerMarkerToCopy(e,t){this._markersToCopy.set(e,t)}_copySelectedFragmentWithMarkers(e,t,o=e=>e.model.getSelectedContent(e.model.document.selection)){return this.editor.model.change((i=>{const n=i.model.document.selection;i.setSelection(t);const s=this._insertFakeMarkersIntoSelection(i,i.model.document.selection,e),r=o(i),a=this._removeFakeMarkersInsideElement(i,r);for(const[e,t]of Object.entries(s)){a[e]||=i.createRangeIn(r);for(const e of t)i.remove(e)}r.markers.clear();for(const[e,t]of Object.entries(a))r.markers.set(e,t);return i.setSelection(n),r}))}_pasteMarkersIntoTransformedElement(e,t){const o=this._getPasteMarkersFromRangeMap(e);return this.editor.model.change((e=>{const i=this._insertFakeMarkersElements(e,o),n=t(e),s=this._removeFakeMarkersInsideElement(e,n);for(const t of Object.values(i).flat())e.remove(t);for(const[t,o]of Object.entries(s))e.model.markers.has(t)||e.addMarker(t,{usingOperation:!0,affectsData:!0,range:o});return n}))}_pasteFragmentWithMarkers(e){const t=this._getPasteMarkersFromRangeMap(e.markers);e.markers.clear();for(const o of t)e.markers.set(o.name,o.range);return this.editor.model.insertContent(e)}_forceMarkersCopy(e,t,o={allowedActions:"all",copyPartiallySelected:!0,duplicateOnPaste:!0}){const i=this._markersToCopy.get(e);this._markersToCopy.set(e,o),t(),i?this._markersToCopy.set(e,i):this._markersToCopy.delete(e)}_isMarkerCopyable(e,t){const o=this._getMarkerClipboardConfig(e);if(!o)return!1;if(!t)return!0;const{allowedActions:i}=o;return"all"===i||i.includes(t)}_hasMarkerConfiguration(e){return!!this._getMarkerClipboardConfig(e)}_getMarkerClipboardConfig(e){const[t]=e.split(":");return this._markersToCopy.get(t)||null}_insertFakeMarkersIntoSelection(e,t,o){const i=this._getCopyableMarkersFromSelection(e,t,o);return this._insertFakeMarkersElements(e,i)}_getCopyableMarkersFromSelection(e,t,o){const i=Array.from(t.getRanges()),n=new Set(i.flatMap((t=>Array.from(e.model.markers.getMarkersIntersectingRange(t)))));return Array.from(n).filter((e=>{if(!this._isMarkerCopyable(e.name,o))return!1;const{copyPartiallySelected:t}=this._getMarkerClipboardConfig(e.name);if(!t){const t=e.getRange();return i.some((e=>e.containsRange(t,!0)))}return!0})).map((e=>({name:"dragstart"===o?this._getUniqueMarkerName(e.name):e.name,range:e.getRange()})))}_getPasteMarkersFromRangeMap(e,t=null){const{model:o}=this.editor;return(e instanceof Map?Array.from(e.entries()):Object.entries(e)).flatMap((([e,i])=>{if(!this._hasMarkerConfiguration(e))return[{name:e,range:i}];if(this._isMarkerCopyable(e,t)){const t=this._getMarkerClipboardConfig(e),n=o.markers.has(e)&&"$graveyard"===o.markers.get(e).getRange().root.rootName;return(t.duplicateOnPaste||n)&&(e=this._getUniqueMarkerName(e)),[{name:e,range:i}]}return[]}))}_insertFakeMarkersElements(e,t){const o={},i=t.flatMap((e=>{const{start:t,end:o}=e.range;return[{position:t,marker:e,type:"start"},{position:o,marker:e,type:"end"}]})).sort((({position:e},{position:t})=>e.isBefore(t)?1:-1));for(const{position:t,marker:n,type:s}of i){const i=e.createElement("$marker",{"data-name":n.name,"data-type":s});o[n.name]||(o[n.name]=[]),o[n.name].push(i),e.insert(i,t)}return o}_removeFakeMarkersInsideElement(e,t){return cf(this._getAllFakeMarkersFromElement(e,t).reduce(((t,o)=>{const i=o.markerElement&&e.createPositionBefore(o.markerElement);let n=t[o.name],s=!1;if(n?.start&&n?.end){this._getMarkerClipboardConfig(o.name).duplicateOnPaste?t[this._getUniqueMarkerName(o.name)]=t[o.name]:s=!0,n=null}return s||(t[o.name]={...n,[o.type]:i}),o.markerElement&&e.remove(o.markerElement),t}),{}),(o=>new us(o.start||e.createPositionFromPath(t,[0]),o.end||e.createPositionAt(t,"end"))))}_getAllFakeMarkersFromElement(e,t){const o=Array.from(e.createRangeIn(t)).flatMap((({item:e})=>{if(!e.is("element","$marker"))return[];const t=e.getAttribute("data-name"),o=e.getAttribute("data-type");return[{markerElement:e,name:t,type:o}]})),i=[],n=[];for(const e of o){if("end"===e.type){o.some((t=>t.name===e.name&&"start"===t.type))||i.push({markerElement:null,name:e.name,type:"start"})}if("start"===e.type){o.some((t=>t.name===e.name&&"end"===t.type))||n.unshift({markerElement:null,name:e.name,type:"end"})}}return[...i,...o,...n]}_getUniqueMarkerName(e){const t=e.split(":"),o=me().substring(1,6);return 3===t.length?`${t.slice(0,2).join(":")}:${o}`:`${t.join(":")}:${o}`}}class bf extends fc{static get pluginName(){return"ClipboardPipeline"}static get isOfficialPlugin(){return!0}static get requires(){return[ff]}init(){this.editor.editing.view.addObserver(df),this._setupPasteDrop(),this._setupCopyCut()}_fireOutputTransformationEvent(e,t,o){const i=this.editor.plugins.get("ClipboardMarkersUtils");this.editor.model.enqueueChange({isUndoable:"cut"===o},(()=>{const n=i._copySelectedFragmentWithMarkers(o,t);this.fire("outputTransformation",{dataTransfer:e,content:n,method:o})}))}_setupPasteDrop(){const e=this.editor,t=e.model,o=e.editing.view,i=o.document,n=this.editor.plugins.get("ClipboardMarkersUtils");this.listenTo(i,"clipboardInput",((t,o)=>{"paste"!=o.method||e.model.canEditAt(e.model.document.selection)||t.stop()}),{priority:"highest"}),this.listenTo(i,"clipboardInput",((e,t)=>{const i=t.dataTransfer;let n;if(t.content)n=t.content;else{let e="";i.getData("text/html")?e=function(e){return e.replace(/(\s+)<\/span>/g,((e,t)=>1==t.length?" ":t)).replace(//g,"")}(i.getData("text/html")):i.getData("text/plain")&&(((s=(s=i.getData("text/plain")).replace(/&/g,"&").replace(//g,">").replace(/\r?\n\r?\n/g,"
").replace(/\r?\n/g,"
").replace(/\t/g," ").replace(/^\s/," ").replace(/\s$/," ").replace(/\s\s/g," ")).includes("
")||s.includes("
"))&&(s=`
${s}
`),e=s),n=this.editor.data.htmlProcessor.toView(e)}var s;const r=new ue(this,"inputTransformation"),a=i.getData("application/ckeditor5-editor-id")||null;this.fire(r,{content:n,dataTransfer:i,sourceEditorId:a,targetRanges:t.targetRanges,method:t.method}),r.stop.called&&e.stop(),o.scrollToTheSelection()}),{priority:"low"}),this.listenTo(this,"inputTransformation",((e,o)=>{if(o.content.isEmpty)return;const i=this.editor.data.toModel(o.content,"$clipboardHolder");0!=i.childCount&&(e.stop(),t.change((()=>{this.fire("contentInsertion",{content:i,method:o.method,sourceEditorId:o.sourceEditorId,dataTransfer:o.dataTransfer,targetRanges:o.targetRanges})})))}),{priority:"low"}),this.listenTo(this,"contentInsertion",((e,t)=>{t.resultRange=n._pasteFragmentWithMarkers(t.content)}),{priority:"low"})}_setupCopyCut(){const e=this.editor,t=e.model.document,o=e.editing.view.document,i=(e,o)=>{const i=o.dataTransfer;o.preventDefault(),this._fireOutputTransformationEvent(i,t.selection,e.name)};this.listenTo(o,"copy",i,{priority:"low"}),this.listenTo(o,"cut",((t,o)=>{e.model.canEditAt(e.model.document.selection)?i(t,o):o.preventDefault()}),{priority:"low"}),this.listenTo(this,"outputTransformation",((t,i)=>{const n=e.data.toView(i.content,{isClipboardPipeline:!0});o.fire("clipboardOutput",{dataTransfer:i.dataTransfer,content:n,method:i.method})}),{priority:"low"}),this.listenTo(o,"clipboardOutput",((o,i)=>{i.content.isEmpty||(i.dataTransfer.setData("text/html",this.editor.data.htmlProcessor.toData(i.content)),i.dataTransfer.setData("text/plain",mf(e.data.htmlProcessor.domConverter,i.content)),i.dataTransfer.setData("application/ckeditor5-editor-id",this.editor.id)),"cut"==i.method&&e.model.deleteContent(t.selection)}),{priority:"low"})}}const wf=yt("px");class yf extends Au{constructor(){super();const e=this.bindTemplate;this.set({isVisible:!1,left:null,top:null,width:null}),this.setTemplate({tag:"div",attributes:{class:["ck","ck-clipboard-drop-target-line",e.if("isVisible","ck-hidden",(e=>!e))],style:{left:e.to("left",(e=>wf(e))),top:e.to("top",(e=>wf(e))),width:e.to("width",(e=>wf(e)))}}})}}class _f extends fc{removeDropMarkerDelayed=co((()=>this.removeDropMarker()),40);_updateDropMarkerThrottled=oc((e=>this._updateDropMarker(e)),40);_reconvertMarkerThrottled=oc((()=>{this.editor.model.markers.has("drop-target")&&this.editor.editing.reconvertMarker("drop-target")}),0);_dropTargetLineView=new yf;_domEmitter=new(et());_scrollables=new Map;static get pluginName(){return"DragDropTarget"}static get isOfficialPlugin(){return!0}init(){this._setupDropMarker()}destroy(){this._domEmitter.stopListening();for(const{resizeObserver:e}of this._scrollables.values())e.destroy();return this._updateDropMarkerThrottled.cancel(),this.removeDropMarkerDelayed.cancel(),this._reconvertMarkerThrottled.cancel(),super.destroy()}updateDropMarker(e,t,o,i,n,s){this.removeDropMarkerDelayed.cancel();const r=kf(this.editor,e,t,o,i,n,s);return r?s&&s.containsRange(r)||r&&!this.editor.model.canEditAt(r)?(this.removeDropMarker(),null):(this._updateDropMarkerThrottled(r),r):null}getFinalDropRange(e,t,o,i,n,s){const r=kf(this.editor,e,t,o,i,n,s);return this.removeDropMarker(),r}removeDropMarker(){const e=this.editor.model;this.removeDropMarkerDelayed.cancel(),this._updateDropMarkerThrottled.cancel(),this._dropTargetLineView.isVisible=!1,e.markers.has("drop-target")&&e.change((e=>{e.removeMarker("drop-target")}))}_setupDropMarker(){const e=this.editor;e.ui.view.body.add(this._dropTargetLineView),e.conversion.for("editingDowncast").markerToHighlight({model:"drop-target",view:{classes:["ck-clipboard-drop-target-range"]}}),e.conversion.for("editingDowncast").markerToElement({model:"drop-target",view:(t,{writer:o})=>{if(e.model.schema.checkChild(t.markerRange.start,"$text"))return this._dropTargetLineView.isVisible=!1,this._createDropTargetPosition(o);t.markerRange.isCollapsed?this._updateDropTargetLine(t.markerRange):this._dropTargetLineView.isVisible=!1}})}_updateDropMarker(e){const t=this.editor,o=t.model.markers;t.model.change((t=>{o.has("drop-target")?o.get("drop-target").getRange().isEqual(e)||t.updateMarker("drop-target",{range:e}):t.addMarker("drop-target",{range:e,usingOperation:!1,affectsData:!1})}))}_createDropTargetPosition(e){return e.createUIElement("span",{class:"ck ck-clipboard-drop-target-position"},(function(e){const t=this.toDomElement(e);return t.append("",e.createElement("span"),""),t}))}_updateDropTargetLine(e){const t=this.editor.editing,o=e.start.nodeBefore,i=e.start.nodeAfter,n=e.start.parent,s=o?t.mapper.toViewElement(o):null,r=s?t.view.domConverter.mapViewToDom(s):null,a=i?t.mapper.toViewElement(i):null,l=a?t.view.domConverter.mapViewToDom(a):null,c=t.mapper.toViewElement(n);if(!c)return;const d=t.view.domConverter.mapViewToDom(c),u=this._getScrollableRect(c),{scrollX:h,scrollY:m}=J.window,g=r?new ut(r):null,p=l?new ut(l):null,f=new ut(d).excludeScrollbarsAndBorders(),b=g?g.bottom:f.top,w=p?p.top:f.bottom,y=J.window.getComputedStyle(d),_=b<=w?(b+w)/2:w;if(u.top<_&&_a.schema.checkChild(s,e)))){if(a.schema.checkChild(s,"$text"))return a.createRange(s);if(t)return Cf(e,xf(e,t.parent),i,n)}}}else if(a.schema.isInline(c))return Cf(e,c,i,n);if(a.schema.isBlock(c))return Cf(e,c,i,n);if(a.schema.checkChild(c,"$block")){const t=Array.from(c.getChildren()).filter((t=>t.is("element")&&!vf(e,t)));let o=0,s=t.length;if(0==s)return a.createRange(a.createPositionAt(c,"end"));for(;o{o?(this.forceDisabled("readOnlyMode"),this._isBlockDragging=!1):this.clearForceDisabled("readOnlyMode")})),Y.isAndroid&&this.forceDisabled("noAndroidSupport"),e.plugins.has("BlockToolbar")){const t=e.plugins.get("BlockToolbar").buttonView.element;this._domEmitter.listenTo(t,"dragstart",((e,t)=>this._handleBlockDragStart(t))),this._domEmitter.listenTo(J.document,"dragover",((e,t)=>this._handleBlockDragging(t))),this._domEmitter.listenTo(J.document,"drop",((e,t)=>this._handleBlockDragging(t))),this._domEmitter.listenTo(J.document,"dragend",(()=>this._handleBlockDragEnd()),{useCapture:!0}),this.isEnabled&&t.setAttribute("draggable","true"),this.on("change:isEnabled",((e,o,i)=>{t.setAttribute("draggable",i?"true":"false")}))}}destroy(){return this._domEmitter.stopListening(),super.destroy()}_handleBlockDragStart(e){if(!this.isEnabled)return;const t=this.editor.model,o=t.document.selection,i=this.editor.editing.view,n=Array.from(o.getSelectedBlocks()),s=t.createRange(t.createPositionBefore(n[0]),t.createPositionAfter(n[n.length-1]));t.change((e=>e.setSelection(s))),this._isBlockDragging=!0,i.focus(),i.getObserver(df).onDomEvent(e)}_handleBlockDragging(e){if(!this.isEnabled||!this._isBlockDragging)return;const t=e.clientX+("ltr"==this.editor.locale.contentLanguageDirection?100:-100),o=e.clientY,i=document.elementFromPoint(t,o),n=this.editor.editing.view;i&&i.closest(".ck-editor__editable")&&n.getObserver(df).onDomEvent({...e,type:e.type,dataTransfer:e.dataTransfer,target:i,clientX:t,clientY:o,preventDefault:()=>e.preventDefault(),stopPropagation:()=>e.stopPropagation()})}_handleBlockDragEnd(){this._isBlockDragging=!1}}class Tf extends fc{_draggedRange;_draggingUid;_draggableElement;_clearDraggableAttributesDelayed=co((()=>this._clearDraggableAttributes()),40);_blockMode=!1;_domEmitter=new(et());_previewContainer;static get pluginName(){return"DragDrop"}static get isOfficialPlugin(){return!0}static get requires(){return[bf,vp,_f,Ef]}init(){const e=this.editor,t=e.editing.view;this._draggedRange=null,this._draggingUid="",this._draggableElement=null,t.addObserver(df),t.addObserver(sl),this._setupDragging(),this._setupContentInsertionIntegration(),this._setupClipboardInputIntegration(),this._setupDraggableAttributeHandling(),this.listenTo(e,"change:isReadOnly",((e,t,o)=>{o?this.forceDisabled("readOnlyMode"):this.clearForceDisabled("readOnlyMode")})),this.on("change:isEnabled",((e,t,o)=>{o||this._finalizeDragging(!1)})),Y.isAndroid&&this.forceDisabled("noAndroidSupport")}destroy(){return this._draggedRange&&(this._draggedRange.detach(),this._draggedRange=null),this._previewContainer&&this._previewContainer.remove(),this._domEmitter.stopListening(),this._clearDraggableAttributesDelayed.cancel(),super.destroy()}_setupDragging(){const e=this.editor,t=e.model,o=e.editing.view,i=o.document,n=e.plugins.get(_f);this.listenTo(i,"dragstart",((o,i)=>{if(i.target?.is("editableElement"))return void i.preventDefault();if(this._prepareDraggedRange(i.target),!this._draggedRange)return void i.preventDefault();this._draggingUid=me();const n=this.isEnabled&&e.model.canEditAt(this._draggedRange);i.dataTransfer.effectAllowed=n?"copyMove":"copy",i.dataTransfer.setData("application/ckeditor5-dragging-uid",this._draggingUid);const s=t.createSelection(this._draggedRange.toRange());this.editor.plugins.get("ClipboardPipeline")._fireOutputTransformationEvent(i.dataTransfer,s,"dragstart");const{dataTransfer:r,domTarget:a,domEvent:l}=i,{clientX:c}=l;this._updatePreview({dataTransfer:r,domTarget:a,clientX:c}),i.stopPropagation(),n||(this._draggedRange.detach(),this._draggedRange=null,this._draggingUid="")}),{priority:"low"}),this.listenTo(i,"dragend",((e,t)=>{this._finalizeDragging(!t.dataTransfer.isCanceled&&"move"==t.dataTransfer.dropEffect)}),{priority:"low"}),this._domEmitter.listenTo(J.document,"dragend",(()=>{this._blockMode=!1}),{useCapture:!0}),this.listenTo(i,"dragenter",(()=>{this.isEnabled&&o.focus()})),this.listenTo(i,"dragleave",(()=>{n.removeDropMarkerDelayed()})),this.listenTo(i,"dragging",((e,t)=>{if(!this.isEnabled)return void(t.dataTransfer.dropEffect="none");const{clientX:o,clientY:i}=t.domEvent;n.updateDropMarker(t.target,t.targetRanges,o,i,this._blockMode,this._draggedRange)?(this._draggedRange||(t.dataTransfer.dropEffect="copy"),Y.isGecko||("copy"==t.dataTransfer.effectAllowed?t.dataTransfer.dropEffect="copy":["all","copyMove"].includes(t.dataTransfer.effectAllowed)&&(t.dataTransfer.dropEffect="move")),e.stop()):t.dataTransfer.dropEffect="none"}),{priority:"low"})}_setupClipboardInputIntegration(){const e=this.editor,t=e.editing.view.document,o=e.plugins.get(_f);this.listenTo(t,"clipboardInput",((t,i)=>{if("drop"!=i.method)return;const{clientX:n,clientY:s}=i.domEvent,r=o.getFinalDropRange(i.target,i.targetRanges,n,s,this._blockMode,this._draggedRange);if(!r)return this._finalizeDragging(!1),void t.stop();this._draggedRange&&this._draggingUid!=i.dataTransfer.getData("application/ckeditor5-dragging-uid")&&(this._draggedRange.detach(),this._draggedRange=null,this._draggingUid="");if("move"==Pf(i.dataTransfer)&&this._draggedRange&&this._draggedRange.containsRange(r,!0))return this._finalizeDragging(!1),void t.stop();i.targetRanges=[e.editing.mapper.toViewRange(r)]}),{priority:"high"})}_setupContentInsertionIntegration(){const e=this.editor.plugins.get(bf);e.on("contentInsertion",((e,t)=>{if(!this.isEnabled||"drop"!==t.method)return;const o=t.targetRanges.map((e=>this.editor.editing.mapper.toModelRange(e)));this.editor.model.change((e=>e.setSelection(o)))}),{priority:"high"}),e.on("contentInsertion",((e,t)=>{if(!this.isEnabled||"drop"!==t.method)return;const o="move"==Pf(t.dataTransfer),i=!t.resultRange||!t.resultRange.isCollapsed;this._finalizeDragging(i&&o)}),{priority:"lowest"})}_setupDraggableAttributeHandling(){const e=this.editor,t=e.editing.view,o=t.document;this.listenTo(o,"pointerdown",((i,n)=>{if(Y.isAndroid||!n)return;this._clearDraggableAttributesDelayed.cancel();let s=Sf(n.target);if(Y.isBlink&&!e.isReadOnly&&!s&&!o.selection.isCollapsed){const e=o.selection.getSelectedElement();e&&ip(e)||(s=o.selection.editableElement)}s&&(t.change((e=>{e.setAttribute("draggable","true",s)})),this._draggableElement=e.editing.mapper.toModelElement(s))})),this.listenTo(o,"pointerup",(()=>{Y.isAndroid||this._clearDraggableAttributesDelayed()}))}_clearDraggableAttributes(){const e=this.editor.editing;e.view.change((t=>{this._draggableElement&&"$graveyard"!=this._draggableElement.root.rootName&&t.removeAttribute("draggable",e.mapper.toViewElement(this._draggableElement)),this._draggableElement=null}))}_finalizeDragging(e){const t=this.editor,o=t.model;if(t.plugins.get(_f).removeDropMarker(),this._clearDraggableAttributes(),t.plugins.has("WidgetToolbarRepository")){t.plugins.get("WidgetToolbarRepository").clearForceDisabled("dragDrop")}this._draggingUid="",this._previewContainer&&(this._previewContainer.remove(),this._previewContainer=void 0),this._draggedRange&&(e&&this.isEnabled&&o.change((e=>{const t=o.createSelection(this._draggedRange);o.deleteContent(t,{doNotAutoparagraph:!0});const i=t.getFirstPosition().parent;i.isEmpty&&!o.schema.checkChild(i,"$text")&&o.schema.checkChild(i,"paragraph")&&e.insertElement("paragraph",i,0)})),this._draggedRange.detach(),this._draggedRange=null)}_prepareDraggedRange(e){const t=this.editor,o=t.model,i=o.document.selection,n=e?Sf(e):null;if(n){const e=t.editing.mapper.toModelElement(n);if(this._draggedRange=Ts.fromRange(o.createRangeOn(e)),this._blockMode=o.schema.isBlock(e),t.plugins.has("WidgetToolbarRepository")){t.plugins.get("WidgetToolbarRepository").forceDisabled("dragDrop")}return}if(i.isCollapsed&&!i.getFirstPosition().parent.isEmpty)return;const s=Array.from(i.getSelectedBlocks()),r=i.getFirstRange();if(0==s.length)return void(this._draggedRange=Ts.fromRange(r));const a=If(o,s);if(s.length>1)this._draggedRange=Ts.fromRange(a),this._blockMode=!0;else if(1==s.length){const e=r.start.isTouching(a.start)&&r.end.isTouching(a.end);this._draggedRange=Ts.fromRange(e?a:r),this._blockMode=e}o.change((e=>e.setSelection(this._draggedRange.toRange())))}_updatePreview({dataTransfer:e,domTarget:t,clientX:o}){const i=this.editor.editing.view,n=i.document.selection.editableElement,s=i.domConverter.mapViewToDom(n),r=J.window.getComputedStyle(s);this._previewContainer?this._previewContainer.firstElementChild&&this._previewContainer.removeChild(this._previewContainer.firstElementChild):(this._previewContainer=Ke(J.document,"div",{style:"position: fixed; left: -999999px;"}),J.document.body.appendChild(this._previewContainer));const a=Ke(J.document,"div");a.className="ck ck-content ck-clipboard-preview";const l=new ut(s),c=parseFloat(r.paddingLeft),d=parseFloat(r.paddingRight),u=parseFloat(r.width)-c-d;if(s.contains(t)){if(!Y.isiOS)return;a.style.maxWidth=`${u}px`,a.style.padding="10px",a.style.minWidth="200px",a.style.minHeight="20px",a.style.boxSizing="border-box",a.style.backgroundColor="var(--ck-color-base-background)"}else if(Y.isiOS)a.style.width=`${u}px`,a.style.backgroundColor="var(--ck-color-base-background)";else{const e=l.left-o+c;a.style.width=`${u+e}px`,a.style.paddingLeft=`${e}px`}i.domConverter.setContentOf(a,e.getData("text/html")),e.setDragImage(a,0,0),this._previewContainer.appendChild(a)}}function Pf(e){return Y.isGecko?e.dropEffect:["all","copyMove"].includes(e.effectAllowed)?"move":"copy"}function Sf(e){if(e.is("editableElement"))return null;if(e.hasClass("ck-widget__selection-handle"))return e.findAncestor(ip);if(ip(e))return e;const t=e.findAncestor((e=>ip(e)||e.is("editableElement")));return ip(t)?t:null}function If(e,t){const o=t[0],i=t[t.length-1],n=o.getCommonAncestor(i),s=e.createPositionBefore(o),r=e.createPositionAfter(i);if(n&&n.is("element")&&!e.schema.isLimit(n)){const t=e.createRangeOn(n),o=s.isTouching(t.start),i=r.isTouching(t.end);if(o&&i)return If(e,[n])}return e.createRange(s,r)}class Rf extends fc{static get pluginName(){return"PastePlainText"}static get isOfficialPlugin(){return!0}static get requires(){return[bf]}init(){const e=this.editor,t=e.model,o=e.editing.view,i=t.document.selection;o.addObserver(df),e.plugins.get(bf).on("contentInsertion",((e,o)=>{(function(e,t){let o=t.createRangeIn(e);if(1==e.childCount){const i=e.getChild(0);i.is("element")&&t.schema.isBlock(i)&&!t.schema.isObject(i)&&!t.schema.isLimit(i)&&(o=t.createRangeIn(i))}for(const e of o.getItems()){if(!t.schema.isInline(e))return!1;if(Array.from(e.getAttributeKeys()).find((e=>t.schema.getAttributeProperties(e).isFormatting)))return!1}return!0})(o.content,t)&&t.change((e=>{const n=Array.from(i.getAttributes()).filter((([e])=>t.schema.getAttributeProperties(e).isFormatting));i.isCollapsed||t.deleteContent(i,{doNotAutoparagraph:!0}),n.push(...i.getAttributes());const s=e.createRangeIn(o.content);for(const o of s.getItems())for(const i of n)t.schema.checkAttribute(o,i[0])&&e.setAttribute(i[0],i[1],o)}))}))}}class Of extends fc{static get pluginName(){return"Clipboard"}static get isOfficialPlugin(){return!0}static get requires(){return[ff,bf,Tf,Rf]}init(){const e=this.editor,t=this.editor.t;e.accessibility.addKeystrokeInfos({keystrokes:[{label:t("Copy selected content"),keystroke:"CTRL+C"},{label:t("Paste content"),keystroke:"CTRL+V"},{label:t("Paste content as plain text"),keystroke:"CTRL+SHIFT+V"}]})}}class Vf extends wc{_stack=[];_createdBatches=new WeakSet;constructor(e){super(e),this.refresh(),this._isEnabledBasedOnSelection=!1,this.listenTo(e.data,"set",((e,t)=>{t[1]={...t[1]};const o=t[1];o.batchType||(o.batchType={isUndoable:!1})}),{priority:"high"}),this.listenTo(e.data,"set",((e,t)=>{t[1].batchType.isUndoable||this.clearStack()}))}refresh(){this.isEnabled=this._stack.length>0}get createdBatches(){return this._createdBatches}addBatch(e){const t=this.editor.model.document.selection,o={ranges:t.hasOwnRange?Array.from(t.getRanges()):[],isBackward:t.isBackward};this._stack.push({batch:e,selection:o}),this.refresh()}clearStack(){this._stack=[],this.refresh()}_restoreSelection(e,t,o){const i=this.editor.model,n=i.document,s=[],r=e.map((e=>e.getTransformedByOperations(o))),a=r.flat();for(const e of r){const t=e.filter((e=>e.root!=n.graveyard)).filter((e=>!Ff(e,a)));t.length&&(Df(t),s.push(t[0]))}s.length&&i.change((e=>{e.setSelection(s,{backward:t})}))}_undo(e,t){const o=this.editor.model,i=o.document;this._createdBatches.add(t);const n=e.operations.slice().filter((e=>e.isDocumentOperation));n.reverse();for(const e of n){const n=e.baseVersion+1,s=Array.from(i.history.getOperations(n)),r=sa([e.getReversed()],s,{useRelations:!0,document:this.editor.model.document,padWithNoOps:!1,forceWeakRemove:!0}).operationsA;for(let n of r){const s=n.affectedSelectable;s&&!o.canEditAt(s)&&(n=new Jr(n.baseVersion)),t.addOperation(n),o.applyOperation(n),i.history.setOperationAsUndone(e,n)}}}}function Df(e){e.sort(((e,t)=>e.start.isBefore(t.start)?-1:1));for(let t=1;tt!==e&&t.containsRange(e,!0)))}class Mf extends Vf{execute(e=null){const t=e?this._stack.findIndex((t=>t.batch==e)):this._stack.length-1,o=this._stack.splice(t,1)[0],i=this.editor.model.createBatch({isUndo:!0});this.editor.model.enqueueChange(i,(()=>{this._undo(o.batch,i);const e=this.editor.model.document.history.getOperations(o.batch.baseVersion);this._restoreSelection(o.selection.ranges,o.selection.isBackward,e)})),this.fire("revert",o.batch,i),this.refresh()}}class Nf extends Vf{execute(){const e=this._stack.pop(),t=this.editor.model.createBatch({isUndo:!0});this.editor.model.enqueueChange(t,(()=>{const o=e.batch.operations[e.batch.operations.length-1].baseVersion+1,i=this.editor.model.document.history.getOperations(o);this._restoreSelection(e.selection.ranges,e.selection.isBackward,i),this._undo(e.batch,t)})),this.fire("revert",e.batch,t),this.refresh()}}class Bf extends fc{_undoCommand;_redoCommand;_batchRegistry=new WeakSet;static get pluginName(){return"UndoEditing"}static get isOfficialPlugin(){return!0}init(){const e=this.editor,t=e.t;this._undoCommand=new Mf(e),this._redoCommand=new Nf(e),e.commands.add("undo",this._undoCommand),e.commands.add("redo",this._redoCommand),this.listenTo(e.model,"applyOperation",((e,t)=>{const o=t[0];if(!o.isDocumentOperation)return;const i=o.batch,n=this._redoCommand.createdBatches.has(i),s=this._undoCommand.createdBatches.has(i);this._batchRegistry.has(i)||(this._batchRegistry.add(i),i.isUndoable&&(n?this._undoCommand.addBatch(i):s||(this._undoCommand.addBatch(i),this._redoCommand.clearStack())))}),{priority:"highest"}),this.listenTo(this._undoCommand,"revert",((e,t,o)=>{this._redoCommand.addBatch(o)})),e.keystrokes.set("CTRL+Z","undo"),e.keystrokes.set("CTRL+Y","redo"),e.keystrokes.set("CTRL+SHIFT+Z","redo"),e.accessibility.addKeystrokeInfos({keystrokes:[{label:t("Undo"),keystroke:"CTRL+Z"},{label:t("Redo"),keystroke:[["CTRL+Y"],["CTRL+SHIFT+Z"]]}]})}}class Lf extends fc{static get pluginName(){return"UndoUI"}static get isOfficialPlugin(){return!0}init(){const e=this.editor,t=e.locale,o=e.t,i="ltr"==t.uiLanguageDirection?nd:td,n="ltr"==t.uiLanguageDirection?td:nd;this._addButtonsToFactory("undo",o("Undo"),"CTRL+Z",i),this._addButtonsToFactory("redo",o("Redo"),"CTRL+Y",n)}_addButtonsToFactory(e,t,o,i){const n=this.editor;n.ui.componentFactory.add(e,(()=>{const n=this._createButton(Lu,e,t,o,i);return n.set({tooltip:!0}),n})),n.ui.componentFactory.add("menuBar:"+e,(()=>this._createButton(sh,e,t,o,i)))}_createButton(e,t,o,i,n){const s=this.editor,r=s.locale,a=s.commands.get(t),l=new e(r);return l.set({label:o,icon:n,keystroke:i}),l.bind("isEnabled").to(a,"isEnabled"),this.listenTo(l,"execute",(()=>{s.execute(t),s.editing.view.focus()})),l}}class zf extends fc{static get requires(){return[Bf,Lf]}static get pluginName(){return"Undo"}static get isOfficialPlugin(){return!0}}function jf(e){return e}function qf(e){return e.createContainerElement("figure",{class:"image"},[e.createEmptyElement("img"),e.createSlot("children")])}function $f(e,t){const o=e.plugins.get("ImageUtils"),i=e.plugins.has("ImageInlineEditing")&&e.plugins.has("ImageBlockEditing");return e=>{if(!o.isInlineImageView(e))return null;if(!i)return n(e);return("block"==e.getStyle("display")||e.findAncestor(o.isBlockImageView)?"imageBlock":"imageInline")!==t?null:n(e)};function n(e){const t={name:!0};return e.hasAttribute("src")&&(t.attributes=["src"]),t}}function Hf(e,t){const o=to(t.getSelectedBlocks());return!o||e.isObject(o)||o.isEmpty&&"listItem"!=o.name?"imageBlock":"imageInline"}function Wf(e){return e&&e.endsWith("px")?parseInt(e):null}function Uf(e){const t=Wf(e.getStyle("width")),o=Wf(e.getStyle("height"));return!(!t||!o)}const Kf=/^(image|image-inline)$/;class Gf extends fc{_domEmitter=new(et());static get pluginName(){return"ImageUtils"}static get isOfficialPlugin(){return!0}isImage(e){return this.isInlineImage(e)||this.isBlockImage(e)}isInlineImageView(e){return!!e&&e.is("element","img")}isBlockImageView(e){return!!e&&e.is("element","figure")&&e.hasClass("image")}insertImage(e={},t=null,o=null,i={}){const n=this.editor,s=n.model,r=s.document.selection,a=Jf(n,t||r,o);e={...Object.fromEntries(r.getAttributes()),...e};for(const t in e)s.schema.checkAttribute(a,t)||delete e[t];return s.change((o=>{const{setImageSizes:n=!0}=i,r=o.createElement(a,e);return s.insertObject(r,t,null,{setSelection:"on",findOptimalPosition:t||"imageInline"==a?void 0:"auto"}),r.parent?(n&&this.setImageNaturalSizeAttributes(r),r):null}))}setImageNaturalSizeAttributes(e){const t=e.getAttribute("src");t&&(e.getAttribute("width")||e.getAttribute("height")||this.editor.model.change((o=>{const i=new J.window.Image;this._domEmitter.listenTo(i,"load",(()=>{e.getAttribute("width")||e.getAttribute("height")||this.editor.model.enqueueChange(o.batch,(t=>{t.setAttribute("width",i.naturalWidth,e),t.setAttribute("height",i.naturalHeight,e)})),this._domEmitter.stopListening(i,"load")})),i.src=t})))}getClosestSelectedImageWidget(e){const t=e.getFirstPosition();if(!t)return null;const o=e.getSelectedElement();if(o&&this.isImageWidget(o))return o;let i=t.parent;for(;i;){if(i.is("element")&&this.isImageWidget(i))return i;i=i.parent}return null}getClosestSelectedImageElement(e){const t=e.getSelectedElement();return this.isImage(t)?t:e.getFirstPosition().findAncestor("imageBlock")}getImageWidgetFromImageView(e){return e.findAncestor({classes:Kf})}isImageAllowed(){const e=this.editor.model.document.selection;return function(e,t){const o=Jf(e,t,null);if("imageBlock"==o){const o=function(e,t){const o=cp(e,t),i=o.start.parent;if(i.isEmpty&&!i.is("element","$root"))return i.parent;return i}(t,e.model);if(e.model.schema.checkChild(o,"imageBlock"))return!0}else if(e.model.schema.checkChild(t.focus,"imageInline"))return!0;return!1}(this.editor,e)&&function(e){return[...e.focus.getAncestors()].every((e=>!e.is("element","imageBlock")))}(e)}toImageWidget(e,t,o){t.setCustomProperty("image",!0,e);return np(e,t,{label:()=>{const t=this.findViewImgElement(e).getAttribute("alt");return t?`${t} ${o}`:o}})}isImageWidget(e){return!!e.getCustomProperty("image")&&ip(e)}isBlockImage(e){return!!e&&e.is("element","imageBlock")}isInlineImage(e){return!!e&&e.is("element","imageInline")}findViewImgElement(e){if(this.isInlineImageView(e))return e;const t=this.editor.editing.view;for(const{item:o}of t.createRangeIn(e))if(this.isInlineImageView(o))return o}destroy(){return this._domEmitter.stopListening(),super.destroy()}}function Jf(e,t,o){const i=e.model.schema,n=e.config.get("image.insert.type");return e.plugins.has("ImageBlockEditing")?e.plugins.has("ImageInlineEditing")?o||("inline"===n?"imageInline":"auto"!==n?"imageBlock":t.is("selection")?Hf(i,t):i.checkChild(t,"imageInline")?"imageInline":"imageBlock"):"imageBlock":"imageInline"}new RegExp(String(/^(http(s)?:\/\/)?[\w-]+\.[\w.~:/[\]@!$&'()*+,;=%-]+/.source+/\.(jpg|jpeg|png|gif|ico|webp|JPG|JPEG|PNG|GIF|ICO|WEBP)/.source+/(\?[\w.~:/[\]@!$&'()*+,;=%-]*)?/.source+/(#[\w.~:/[\]@!$&'()*+,;=%-]*)?$/.source));class Zf extends wc{refresh(){const e=this.editor.plugins.get("ImageUtils").getClosestSelectedImageElement(this.editor.model.document.selection);this.isEnabled=!!e,this.isEnabled&&e.hasAttribute("alt")?this.value=e.getAttribute("alt"):this.value=!1}execute(e){const t=this.editor,o=t.plugins.get("ImageUtils"),i=t.model,n=o.getClosestSelectedImageElement(i.document.selection);i.change((t=>{t.setAttribute("alt",e.newValue,n)}))}}class Qf extends fc{static get requires(){return[Gf]}static get pluginName(){return"ImageTextAlternativeEditing"}static get isOfficialPlugin(){return!0}init(){this.editor.commands.add("imageTextAlternative",new Zf(this.editor))}}class Yf extends Au{focusTracker;keystrokes;labeledInput;backButtonView;saveButtonView;children;_focusables;_focusCycler;constructor(e){super(e),this.focusTracker=new oo,this.keystrokes=new ro,this.backButtonView=this._createBackButton(),this.saveButtonView=this._createSaveButton(),this.labeledInput=this._createLabeledInputView(),this.children=this.createCollection([this._createHeaderView()]),this.children.add(new Km(e,{children:[this.labeledInput,this.saveButtonView],class:["ck-form__row_with-submit","ck-form__row_large-top-padding"]})),this._focusables=new tu,this.keystrokes.set("Esc",((e,t)=>{this.fire("cancel"),t()})),this._focusCycler=new qu({focusables:this._focusables,focusTracker:this.focusTracker,keystrokeHandler:this.keystrokes,actions:{focusPrevious:"shift + tab",focusNext:"tab"}}),this.setTemplate({tag:"form",attributes:{class:["ck","ck-form","ck-text-alternative-form","ck-responsive-form"],tabindex:"-1"},children:this.children})}render(){super.render(),Ou({view:this});[this.backButtonView,this.labeledInput,this.saveButtonView].forEach((e=>{this._focusables.add(e),this.focusTracker.add(e.element)})),this.keystrokes.listenTo(this.element)}destroy(){super.destroy(),this.focusTracker.destroy(),this.keystrokes.destroy()}_createBackButton(){const e=this.locale.t,t=new Lu(this.locale);return t.set({class:"ck-button-back",label:e("Back"),icon:ed,tooltip:!0}),t.delegate("execute").to(this,"cancel"),t}_createSaveButton(){const e=this.locale.t,t=new Lu(this.locale);return t.set({label:e("Save"),withText:!0,type:"submit",class:"ck-button-action ck-button-bold"}),t}_createHeaderView(){const e=this.locale.t,t=new ju(this.locale,{label:e("Text Alternative")});return t.children.add(this.backButtonView,0),t}_createLabeledInputView(){const e=this.locale.t,t=new Sh(this.locale,nm);return t.label=e("Text alternative"),t.class="ck-labeled-field-view_full-width",t}}function Xf(e){const t=e.editing.view,o=dh.defaultPositions,i=e.plugins.get("ImageUtils");return{target:t.domConverter.mapViewToDom(i.getClosestSelectedImageWidget(t.document.selection)),positions:[o.northArrowSouth,o.northArrowSouthWest,o.northArrowSouthEast,o.southArrowNorth,o.southArrowNorthWest,o.southArrowNorthEast,o.viewportStickyNorth]}}class eb extends fc{_balloon;_form;static get requires(){return[Qm]}static get pluginName(){return"ImageTextAlternativeUI"}static get isOfficialPlugin(){return!0}init(){this._createButton()}destroy(){super.destroy(),this._form&&this._form.destroy()}_createButton(){const e=this.editor,t=e.t;e.ui.componentFactory.add("imageTextAlternative",(o=>{const i=e.commands.get("imageTextAlternative"),n=new Lu(o);return n.set({label:t("Change image text alternative"),icon:'',tooltip:!0}),n.bind("isEnabled").to(i,"isEnabled"),n.bind("isOn").to(i,"value",(e=>!!e)),this.listenTo(n,"execute",(()=>{this._showForm()})),n}))}_createForm(){const e=this.editor,t=e.editing.view.document,o=e.plugins.get("ImageUtils");this._balloon=this.editor.plugins.get("ContextualBalloon"),this._form=new(Iu(Yf))(e.locale),this._form.render(),this.listenTo(this._form,"submit",(()=>{e.execute("imageTextAlternative",{newValue:this._form.labeledInput.fieldView.element.value}),this._hideForm(!0)})),this.listenTo(this._form,"cancel",(()=>{this._hideForm(!0)})),this.listenTo(e.ui,"update",(()=>{o.getClosestSelectedImageWidget(t.selection)?this._isVisible&&function(e){const t=e.plugins.get("ContextualBalloon");if(e.plugins.get("ImageUtils").getClosestSelectedImageWidget(e.editing.view.document.selection)){const o=Xf(e);t.updatePosition(o)}}(e):this._hideForm(!0)})),Su({emitter:this._form,activator:()=>this._isVisible,contextElements:()=>[this._balloon.view.element],callback:()=>this._hideForm()})}_showForm(){if(this._isVisible)return;this._form||this._createForm();const e=this.editor,t=e.commands.get("imageTextAlternative"),o=this._form.labeledInput;this._form.disableCssTransitions(),this._isInBalloon||this._balloon.add({view:this._form,position:Xf(e)}),o.fieldView.value=o.fieldView.element.value=t.value||"",this._form.labeledInput.fieldView.select(),this._form.enableCssTransitions()}_hideForm(e=!1){this._isInBalloon&&(this._form.focusTracker.isFocused&&this._form.saveButtonView.focus(),this._balloon.remove(this._form),e&&this.editor.editing.view.focus())}get _isVisible(){return!!this._balloon&&this._balloon.visibleView===this._form}get _isInBalloon(){return!!this._balloon&&this._balloon.hasView(this._form)}}class tb extends fc{static get requires(){return[Qf,eb]}static get pluginName(){return"ImageTextAlternative"}static get isOfficialPlugin(){return!0}}function ob(e,t){const o=(t,o,i)=>{if(!i.consumable.consume(o.item,t.name))return;const n=i.writer,s=i.mapper.toViewElement(o.item),r=e.findViewImgElement(s);null===o.attributeNewValue?(n.removeAttribute("srcset",r),n.removeAttribute("sizes",r)):o.attributeNewValue&&(n.setAttribute("srcset",o.attributeNewValue,r),n.setAttribute("sizes","100vw",r))};return e=>{e.on(`attribute:srcset:${t}`,o)}}function ib(e,t,o){const i=(t,o,i)=>{if(!i.consumable.consume(o.item,t.name))return;const n=i.writer,s=i.mapper.toViewElement(o.item),r=e.findViewImgElement(s);n.setAttribute(o.attributeKey,o.attributeNewValue||"",r)};return e=>{e.on(`attribute:${o}:${t}`,i)}}class nb extends Ln{observe(e){this.listenTo(e,"load",((e,t)=>{const o=t.target;this.checkShouldIgnoreEventFromTarget(o)||"IMG"==o.tagName&&this._fireEvents(t)}),{useCapture:!0})}stopObserving(e){this.stopListening(e)}_fireEvents(e){this.isEnabled&&(this.document.fire("layoutChanged"),this.document.fire("imageLoaded",e))}}class sb extends wc{constructor(e){super(e);const t=e.config.get("image.insert.type");e.plugins.has("ImageBlockEditing")||"block"===t&&be("image-block-plugin-required"),e.plugins.has("ImageInlineEditing")||"inline"===t&&be("image-inline-plugin-required")}refresh(){const e=this.editor.plugins.get("ImageUtils");this.isEnabled=e.isImageAllowed()}execute(e){const t=Qt(e.source),o=this.editor.model.document.selection,i=this.editor.plugins.get("ImageUtils"),n=Object.fromEntries(o.getAttributes());t.forEach(((t,s)=>{const r=o.getSelectedElement();if("string"==typeof t&&(t={src:t}),s&&r&&i.isImage(r)){const o=this.editor.model.createPositionAfter(r);i.insertImage({...t,...n},o,e.imageType)}else e.breakBlock?i.insertImage({...t,...n},o.getFirstPosition(),e.imageType):i.insertImage({...t,...n},null,e.imageType)}))}}class rb extends wc{constructor(e){super(e),this.decorate("cleanupImage")}refresh(){const e=this.editor.plugins.get("ImageUtils"),t=this.editor.model.document.selection.getSelectedElement();this.isEnabled=e.isImage(t),this.value=this.isEnabled?t.getAttribute("src"):null}execute(e){const t=this.editor.model.document.selection.getSelectedElement(),o=this.editor.plugins.get("ImageUtils");this.editor.model.change((i=>{i.setAttribute("src",e.source,t),this.cleanupImage(i,t),o.setImageNaturalSizeAttributes(t)}))}cleanupImage(e,t){e.removeAttribute("srcset",t),e.removeAttribute("sizes",t),e.removeAttribute("sources",t),e.removeAttribute("width",t),e.removeAttribute("height",t),e.removeAttribute("alt",t)}}class ab extends fc{static get requires(){return[Gf]}static get pluginName(){return"ImageEditing"}static get isOfficialPlugin(){return!0}init(){const e=this.editor,t=e.conversion;e.editing.view.addObserver(nb),t.for("upcast").attributeToAttribute({view:{name:"img",key:"alt"},model:"alt"}).attributeToAttribute({view:{name:"img",key:"srcset"},model:"srcset"});const o=new sb(e),i=new rb(e);e.commands.add("insertImage",o),e.commands.add("replaceImageSource",i),e.commands.add("imageInsert",o)}}class lb extends fc{static get requires(){return[Gf]}static get pluginName(){return"ImageSizeAttributes"}static get isOfficialPlugin(){return!0}afterInit(){this._registerSchema(),this._registerConverters("imageBlock"),this._registerConverters("imageInline")}_registerSchema(){const e=this.editor.model.schema;this.editor.plugins.has("ImageBlockEditing")&&e.extend("imageBlock",{allowAttributes:["width","height"]}),this.editor.plugins.has("ImageInlineEditing")&&e.extend("imageInline",{allowAttributes:["width","height"]})}_registerConverters(e){const t=this.editor,o=t.plugins.get("ImageUtils"),i="imageBlock"===e?"figure":"img";function n(t,i,n,s,r=!1){t.on(`attribute:${i}:${e}`,((t,i,a)=>{if(!a.consumable.consume(i.item,t.name))return;const l=a.writer,c=a.mapper.toViewElement(i.item),d=o.findViewImgElement(c);null!==i.attributeNewValue?l.setAttribute(n,i.attributeNewValue,d):l.removeAttribute(n,d);const u=i.item.getAttribute("width"),h=i.item.getAttribute("height"),m=u&&h;if(m&&r&&l.setAttribute("loading","lazy",d),i.item.hasAttribute("sources"))return;const g=i.item.hasAttribute("resizedWidth");("imageInline"!==e||g||s)&&m&&l.setStyle("aspect-ratio",`${u}/${h}`,d)}))}t.conversion.for("upcast").attributeToAttribute({view:{name:i,styles:{width:/.+/}},model:{key:"width",value:e=>Uf(e)?Wf(e.getStyle("width")):null}}).attributeToAttribute({view:{name:i,key:"width"},model:"width"}).attributeToAttribute({view:{name:i,styles:{height:/.+/}},model:{key:"height",value:e=>Uf(e)?Wf(e.getStyle("height")):null}}).attributeToAttribute({view:{name:i,key:"height"},model:"height"}),t.conversion.for("editingDowncast").add((e=>{n(e,"width","width",!0,!0),n(e,"height","height",!0,!0)})),t.conversion.for("dataDowncast").add((e=>{n(e,"width","width",!1),n(e,"height","height",!1)})),t.conversion.for("upcast").add((e=>{e.on("element:img",((e,t,o)=>{const i=t.viewItem.getAttribute("width"),n=t.viewItem.getAttribute("height");i&&n&&o.consumable.consume(t.viewItem,{styles:["aspect-ratio"]})}))}))}}class cb extends wc{_modelElementName;constructor(e,t){super(e),this._modelElementName=t}refresh(){const e=this.editor.plugins.get("ImageUtils"),t=e.getClosestSelectedImageElement(this.editor.model.document.selection);"imageBlock"===this._modelElementName?this.isEnabled=e.isInlineImage(t):this.isEnabled=e.isBlockImage(t)}execute(e={}){const t=this.editor,o=this.editor.model,i=t.plugins.get("ImageUtils"),n=i.getClosestSelectedImageElement(o.document.selection),s=Object.fromEntries(n.getAttributes());return s.src||s.uploadId?o.change((t=>{const{setImageSizes:r=!0}=e,a=Array.from(o.markers).filter((e=>e.getRange().containsItem(n))),l=i.insertImage(s,o.createSelection(n,"on"),this._modelElementName,{setImageSizes:r});if(!l)return null;const c=t.createRangeOn(l);for(const e of a){const o=e.getRange(),i="$graveyard"!=o.root.rootName?o.getJoined(c,!0):c;t.updateMarker(e,{range:i})}return{oldElement:n,newElement:l}})):null}}class db extends fc{static get requires(){return[Gf]}static get pluginName(){return"ImagePlaceholder"}static get isOfficialPlugin(){return!0}afterInit(){this._setupSchema(),this._setupConversion(),this._setupLoadListener()}_setupSchema(){const e=this.editor.model.schema;e.isRegistered("imageBlock")&&e.extend("imageBlock",{allowAttributes:["placeholder"]}),e.isRegistered("imageInline")&&e.extend("imageInline",{allowAttributes:["placeholder"]})}_setupConversion(){const e=this.editor,t=e.conversion,o=e.plugins.get("ImageUtils");t.for("editingDowncast").add((e=>{e.on("attribute:placeholder",((e,t,i)=>{if(!i.consumable.test(t.item,e.name))return;if(!t.item.is("element","imageBlock")&&!t.item.is("element","imageInline"))return;i.consumable.consume(t.item,e.name);const n=i.writer,s=i.mapper.toViewElement(t.item),r=o.findViewImgElement(s);t.attributeNewValue?(n.addClass("image_placeholder",r),n.setStyle("background-image",`url(${t.attributeNewValue})`,r),n.setCustomProperty("editingPipeline:doNotReuseOnce",!0,r)):(n.removeClass("image_placeholder",r),n.removeStyle("background-image",r))}))}))}_setupLoadListener(){const e=this.editor,t=e.model,o=e.editing,i=o.view,n=e.plugins.get("ImageUtils");i.addObserver(nb),this.listenTo(i.document,"imageLoaded",((e,s)=>{const r=i.domConverter.mapDomToView(s.target);if(!r)return;const a=n.getImageWidgetFromImageView(r);if(!a)return;const l=o.mapper.toModelElement(a);l&&l.hasAttribute("placeholder")&&t.enqueueChange({isUndoable:!1},(e=>{e.removeAttribute("placeholder",l)}))}))}}class ub extends fc{static get requires(){return[ab,lb,Gf,db,bf]}static get pluginName(){return"ImageBlockEditing"}static get isOfficialPlugin(){return!0}init(){const e=this.editor;e.model.schema.register("imageBlock",{inheritAllFrom:"$blockObject",allowAttributes:["alt","src","srcset"]}),this._setupConversion(),e.plugins.has("ImageInlineEditing")&&(e.commands.add("imageTypeBlock",new cb(this.editor,"imageBlock")),this._setupClipboardIntegration())}_setupConversion(){const e=this.editor,t=e.t,o=e.conversion,i=e.plugins.get("ImageUtils");o.for("dataDowncast").elementToStructure({model:"imageBlock",view:(e,{writer:t})=>qf(t)}),o.for("editingDowncast").elementToStructure({model:"imageBlock",view:(e,{writer:o})=>i.toImageWidget(qf(o),o,t("image widget"))}),o.for("downcast").add(ib(i,"imageBlock","src")).add(ib(i,"imageBlock","alt")).add(ob(i,"imageBlock")),o.for("upcast").elementToElement({view:$f(e,"imageBlock"),model:(e,{writer:t})=>t.createElement("imageBlock",e.hasAttribute("src")?{src:e.getAttribute("src")}:void 0)}).add(function(e){const t=(t,o,i)=>{if(!i.consumable.test(o.viewItem,{name:!0,classes:"image"}))return;const n=e.findViewImgElement(o.viewItem);if(!n||!i.consumable.test(n,{name:!0}))return;i.consumable.consume(o.viewItem,{name:!0,classes:"image"});const s=to(i.convertItem(n,o.modelCursor).modelRange.getItems());s?(i.convertChildren(o.viewItem,s),i.updateConversionResult(s,o)):i.consumable.revert(o.viewItem,{name:!0,classes:"image"})};return e=>{e.on("element:figure",t)}}(i))}_setupClipboardIntegration(){const e=this.editor,t=e.model,o=e.editing.view,i=e.plugins.get("ImageUtils"),n=e.plugins.get("ClipboardPipeline");this.listenTo(n,"inputTransformation",((n,s)=>{const r=Array.from(s.content.getChildren());let a;if(!r.every(i.isInlineImageView))return;a=s.targetRanges?e.editing.mapper.toModelRange(s.targetRanges[0]):t.document.selection.getFirstRange();const l=t.createSelection(a);if("imageBlock"===Hf(t.schema,l)){const e=new rl(o.document),t=r.map((t=>e.createElement("figure",{class:"image"},t)));s.content=e.createDocumentFragment(t)}})),this.listenTo(n,"contentInsertion",((e,o)=>{"paste"===o.method&&t.change((e=>{const t=e.createRangeIn(o.content);for(const e of t.getItems())e.is("element","imageBlock")&&i.setImageNaturalSizeAttributes(e)}))}))}}class hb extends Au{focusTracker;keystrokes;_focusables;_focusCycler;children;constructor(e,t=[]){super(e),this.focusTracker=new oo,this.keystrokes=new ro,this._focusables=new tu,this.children=this.createCollection(),this._focusCycler=new qu({focusables:this._focusables,focusTracker:this.focusTracker,keystrokeHandler:this.keystrokes,actions:{focusPrevious:"shift + tab",focusNext:"tab"}});for(const e of t)this.children.add(e),this._focusables.add(e),e instanceof kh&&this._focusables.addMany(e.children);this.setTemplate({tag:"form",attributes:{class:["ck","ck-image-insert-form"],tabindex:-1},children:this.children})}render(){super.render(),Ou({view:this});for(const e of this._focusables)this.focusTracker.add(e.element);this.keystrokes.listenTo(this.element);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)}destroy(){super.destroy(),this.focusTracker.destroy(),this.keystrokes.destroy()}focus(){this._focusCycler.focusFirst()}}class mb extends fc{static get pluginName(){return"ImageInsertUI"}static get isOfficialPlugin(){return!0}static get requires(){return[Gf]}dropdownView;_integrations=new Map;constructor(e){super(e),e.config.define("image.insert.integrations",["upload","assetManager","url"])}init(){const e=this.editor,t=e.model.document.selection,o=e.plugins.get("ImageUtils");this.set("isImageSelected",!1),this.listenTo(e.model.document,"change",(()=>{this.isImageSelected=o.isImage(t.getSelectedElement())}));const i=e=>this._createToolbarComponent(e);e.ui.componentFactory.add("insertImage",i),e.ui.componentFactory.add("imageInsert",i),e.ui.componentFactory.add("menuBar:insertImage",(e=>this._createMenuBarComponent(e)))}registerIntegration({name:e,observable:t,buttonViewCreator:o,formViewCreator:i,menuBarButtonViewCreator:n,requiresForm:s=!1,override:r=!1}){this._integrations.has(e)&&!r&&be("image-insert-integration-exists",{name:e}),this._integrations.set(e,{observable:t,buttonViewCreator:o,menuBarButtonViewCreator:n,formViewCreator:i,requiresForm:s})}_createToolbarComponent(e){const t=this.editor,o=e.t,i=this._prepareIntegrations();if(!i.length)return null;let n;const s=i[0];if(1==i.length){if(!s.requiresForm)return s.buttonViewCreator(!0);n=s.buttonViewCreator(!0)}else{const t=s.buttonViewCreator(!1);n=new Jh(e,t),n.tooltip=!0,n.bind("label").to(this,"isImageSelected",(e=>o(e?"Replace image":"Insert image")))}const r=this.dropdownView=Zh(e,n),a=i.map((({observable:e})=>"function"==typeof e?e():e));return r.bind("isEnabled").toMany(a,"isEnabled",((...e)=>e.some((e=>e)))),r.once("change:isOpen",(()=>{const e=i.flatMap((({formViewCreator:e})=>e(1==i.length))),o=new hb(t.locale,e);r.panelView.children.add(o)})),r}_createMenuBarComponent(e){const t=e.t,o=this._prepareIntegrations();if(!o.length)return null;const i=o.flatMap((({menuBarButtonViewCreator:e})=>e(1==o.length))),n=new og(e),s=new ig(e);n.panelView.children.add(s),n.buttonView.set({icon:'',label:t("Image")});for(const t of i){const o=new Em(e,n);o.children.add(t),s.items.add(o),t.delegate("execute").to(n)}return n}_prepareIntegrations(){const e=this.editor.config.get("image.insert.integrations"),t=[];if(!e.length)return be("image-insert-integrations-not-specified"),t;for(const o of e)this._integrations.has(o)?t.push(this._integrations.get(o)):["upload","assetManager","url"].includes(o)||be("image-insert-unknown-integration",{item:o});return t.length||be("image-insert-integrations-not-registered"),t}}class gb extends fc{static get requires(){return[ub,vp,tb,mb]}static get pluginName(){return"ImageBlock"}static get isOfficialPlugin(){return!0}}class pb extends fc{static get requires(){return[ab,lb,Gf,db,bf]}static get pluginName(){return"ImageInlineEditing"}static get isOfficialPlugin(){return!0}init(){const e=this.editor;e.model.schema.register("imageInline",{inheritAllFrom:"$inlineObject",allowAttributes:["alt","src","srcset"],disallowIn:["caption"]}),this._setupConversion(),e.plugins.has("ImageBlockEditing")&&(e.commands.add("imageTypeInline",new cb(this.editor,"imageInline")),this._setupClipboardIntegration())}_setupConversion(){const e=this.editor,t=e.t,o=e.conversion,i=e.plugins.get("ImageUtils");o.for("dataDowncast").elementToElement({model:"imageInline",view:(e,{writer:t})=>t.createEmptyElement("img")}),o.for("editingDowncast").elementToStructure({model:"imageInline",view:(e,{writer:o})=>i.toImageWidget(function(e){return e.createContainerElement("span",{class:"image-inline"},e.createEmptyElement("img"))}(o),o,t("image widget"))}),o.for("downcast").add(ib(i,"imageInline","src")).add(ib(i,"imageInline","alt")).add(ob(i,"imageInline")),o.for("upcast").elementToElement({view:$f(e,"imageInline"),model:(e,{writer:t})=>t.createElement("imageInline",e.hasAttribute("src")?{src:e.getAttribute("src")}:void 0)})}_setupClipboardIntegration(){const e=this.editor,t=e.model,o=e.editing.view,i=e.plugins.get("ImageUtils"),n=e.plugins.get("ClipboardPipeline");this.listenTo(n,"inputTransformation",((n,s)=>{const r=Array.from(s.content.getChildren());let a;if(!r.every(i.isBlockImageView))return;a=s.targetRanges?e.editing.mapper.toModelRange(s.targetRanges[0]):t.document.selection.getFirstRange();const l=t.createSelection(a);if("imageInline"===Hf(t.schema,l)){const e=new rl(o.document),t=r.map((t=>1===t.childCount?(Array.from(t.getAttributes()).forEach((o=>e.setAttribute(...o,i.findViewImgElement(t)))),t.getChild(0)):t));s.content=e.createDocumentFragment(t)}})),this.listenTo(n,"contentInsertion",((e,o)=>{"paste"===o.method&&t.change((e=>{const t=e.createRangeIn(o.content);for(const e of t.getItems())e.is("element","imageInline")&&i.setImageNaturalSizeAttributes(e)}))}))}}class fb extends fc{static get requires(){return[pb,vp,tb,mb]}static get pluginName(){return"ImageInline"}static get isOfficialPlugin(){return!0}}class bb extends fc{static get pluginName(){return"ImageCaptionUtils"}static get isOfficialPlugin(){return!0}static get requires(){return[Gf]}getCaptionFromImageModelElement(e){for(const t of e.getChildren())if(t&&t.is("element","caption"))return t;return null}getCaptionFromModelSelection(e){const t=this.editor.plugins.get("ImageUtils"),o=e.getFirstPosition().findAncestor("caption");return o&&t.isBlockImage(o.parent)?o:null}matchImageCaptionViewElement(e){const t=this.editor.plugins.get("ImageUtils");return"figcaption"==e.name&&t.isBlockImageView(e.parent)?{name:!0}:null}}class wb extends wc{refresh(){const e=this.editor,t=e.plugins.get("ImageCaptionUtils"),o=e.plugins.get("ImageUtils");if(!e.plugins.has(ub))return this.isEnabled=!1,void(this.value=!1);const i=e.model.document.selection,n=i.getSelectedElement();if(!n){const e=t.getCaptionFromModelSelection(i);return this.isEnabled=!!e,void(this.value=!!e)}this.isEnabled=o.isImage(n),this.isEnabled?this.value=!!t.getCaptionFromImageModelElement(n):this.value=!1}execute(e={}){const{focusCaptionOnShow:t}=e;this.editor.model.change((e=>{this.value?this._hideImageCaption(e):this._showImageCaption(e,t)}))}_showImageCaption(e,t){const o=this.editor.model.document.selection,i=this.editor.plugins.get("ImageCaptionEditing"),n=this.editor.plugins.get("ImageUtils");let s=o.getSelectedElement();const r=i._getSavedCaption(s);n.isInlineImage(s)&&(this.editor.execute("imageTypeBlock"),s=o.getSelectedElement());const a=r||e.createElement("caption");e.append(a,s),t&&e.setSelection(a,"in")}_hideImageCaption(e){const t=this.editor,o=t.model.document.selection,i=t.plugins.get("ImageCaptionEditing"),n=t.plugins.get("ImageCaptionUtils");let s,r=o.getSelectedElement();r?s=n.getCaptionFromImageModelElement(r):(s=n.getCaptionFromModelSelection(o),r=s.parent),i._saveCaption(r,s),e.setSelection(r,"on"),e.remove(s)}}class yb extends fc{static get requires(){return[Gf,bb]}static get pluginName(){return"ImageCaptionEditing"}static get isOfficialPlugin(){return!0}_savedCaptionsMap;constructor(e){super(e),this._savedCaptionsMap=new WeakMap}init(){const e=this.editor,t=e.model.schema;t.isRegistered("caption")?t.extend("caption",{allowIn:"imageBlock"}):t.register("caption",{allowIn:"imageBlock",allowContentOf:"$block",isLimit:!0}),e.commands.add("toggleImageCaption",new wb(this.editor)),this._setupConversion(),this._setupImageTypeCommandsIntegration(),this._registerCaptionReconversion()}_setupConversion(){const e=this.editor,t=e.editing.view,o=e.plugins.get("ImageUtils"),i=e.plugins.get("ImageCaptionUtils"),n=e.t;e.conversion.for("upcast").elementToElement({view:e=>i.matchImageCaptionViewElement(e),model:"caption"}),e.conversion.for("dataDowncast").elementToElement({model:"caption",view:(e,{writer:t})=>o.isBlockImage(e.parent)?t.createContainerElement("figcaption"):null}),e.conversion.for("editingDowncast").elementToElement({model:"caption",view:(e,{writer:i})=>{if(!o.isBlockImage(e.parent))return null;const s=i.createEditableElement("figcaption");i.setCustomProperty("imageCaption",!0,s),s.placeholder=n("Enter image caption"),Yo({view:t,element:s,keepOnFocus:!0});const r=e.parent.getAttribute("alt");return lp(s,i,{label:r?n("Caption for image: %0",[r]):n("Caption for the image")})}})}_setupImageTypeCommandsIntegration(){const e=this.editor,t=e.plugins.get("ImageUtils"),o=e.plugins.get("ImageCaptionUtils"),i=e.commands.get("imageTypeInline"),n=e.commands.get("imageTypeBlock"),s=e=>{if(!e.return)return;const{oldElement:i,newElement:n}=e.return;if(!i)return;if(t.isBlockImage(i)){const e=o.getCaptionFromImageModelElement(i);if(e)return void this._saveCaption(n,e)}const s=this._getSavedCaption(i);s&&this._saveCaption(n,s)};i&&this.listenTo(i,"execute",s,{priority:"low"}),n&&this.listenTo(n,"execute",s,{priority:"low"})}_getSavedCaption(e){const t=this._savedCaptionsMap.get(e);return t?Ms.fromJSON(t):null}_saveCaption(e,t){this._savedCaptionsMap.set(e,t.toJSON())}_registerCaptionReconversion(){const e=this.editor,t=e.model,o=e.plugins.get("ImageUtils"),i=e.plugins.get("ImageCaptionUtils");t.document.on("change:data",(()=>{const n=t.document.differ.getChanges();for(const t of n){if("alt"!==t.attributeKey)continue;const n=t.range.start.nodeAfter;if(o.isBlockImage(n)){const t=i.getCaptionFromImageModelElement(n);if(!t)return;e.editing.reconvertItem(t)}}}))}}class _b extends fc{static get requires(){return[bb]}static get pluginName(){return"ImageCaptionUI"}static get isOfficialPlugin(){return!0}init(){const e=this.editor,t=e.editing.view,o=e.plugins.get("ImageCaptionUtils"),i=e.t;e.ui.componentFactory.add("toggleImageCaption",(n=>{const s=e.commands.get("toggleImageCaption"),r=new Lu(n);return r.set({icon:'',tooltip:!0,isToggleable:!0}),r.bind("isOn","isEnabled").to(s,"value","isEnabled"),r.bind("label").to(s,"value",(e=>i(e?"Toggle caption off":"Toggle caption on"))),this.listenTo(r,"execute",(()=>{e.execute("toggleImageCaption",{focusCaptionOnShow:!0});const i=o.getCaptionFromModelSelection(e.model.document.selection);if(i){const o=e.editing.mapper.toViewElement(i);t.scrollToTheSelection(),t.change((e=>{e.addClass("image__caption_highlighted",o)}))}e.editing.view.focus()})),r}))}}function kb(e){const t=e.map((e=>e.replace("+","\\+")));return new RegExp(`^image\\/(${t.join("|")})$`)}function vb(e){return new Promise(((t,o)=>{const i=e.getAttribute("src");fetch(i).then((e=>e.blob())).then((e=>{const o=Cb(e,i),n=o.replace("image/",""),s=new File([e],`image.${n}`,{type:o});t(s)})).catch((e=>e&&"TypeError"===e.name?function(e){return function(e){return new Promise(((t,o)=>{const i=J.document.createElement("img");i.addEventListener("load",(()=>{const e=J.document.createElement("canvas");e.width=i.width,e.height=i.height;e.getContext("2d").drawImage(i,0,0),e.toBlob((e=>e?t(e):o()))})),i.addEventListener("error",(()=>o())),i.src=e}))}(e).then((t=>{const o=Cb(t,e),i=o.replace("image/","");return new File([t],`image.${i}`,{type:o})}))}(i).then(t).catch(o):o(e)))}))}function Cb(e,t){return e.type?e.type:t.match(/data:(image\/\w+);base64/)?t.match(/data:(image\/\w+);base64/)[1].toLowerCase():"image/jpeg"}class Ab extends fc{static get pluginName(){return"ImageUploadUI"}static get isOfficialPlugin(){return!0}init(){const e=this.editor;e.ui.componentFactory.add("uploadImage",(()=>this._createToolbarButton())),e.ui.componentFactory.add("imageUpload",(()=>this._createToolbarButton())),e.ui.componentFactory.add("menuBar:uploadImage",(()=>this._createMenuBarButton("standalone"))),e.plugins.has("ImageInsertUI")&&e.plugins.get("ImageInsertUI").registerIntegration({name:"upload",observable:()=>e.commands.get("uploadImage"),buttonViewCreator:()=>this._createToolbarButton(),formViewCreator:()=>this._createDropdownButton(),menuBarButtonViewCreator:e=>this._createMenuBarButton(e?"insertOnly":"insertNested")})}_createButton(e){const t=this.editor,o=t.locale,i=t.commands.get("uploadImage"),n=t.config.get("image.upload.types"),s=kb(n),r=new e(t.locale),a=o.t;return r.set({acceptedType:n.map((e=>`image/${e}`)).join(","),allowMultipleFiles:!0,label:a("Upload from computer"),icon:''}),r.bind("isEnabled").to(i),r.on("done",((e,o)=>{const i=Array.from(o).filter((e=>s.test(e.type)));i.length&&(t.execute("uploadImage",{file:i}),t.editing.view.focus())})),r}_createToolbarButton(){const e=this.editor.locale.t,t=this.editor.plugins.get("ImageInsertUI"),o=this.editor.commands.get("uploadImage"),i=this._createButton(bh);return i.tooltip=!0,i.bind("label").to(t,"isImageSelected",o,"isAccessAllowed",((t,o)=>e(o?t?"Replace image from computer":"Upload image from computer":"You have no image upload permissions."))),i}_createDropdownButton(){const e=this.editor.locale.t,t=this.editor.plugins.get("ImageInsertUI"),o=this._createButton(bh);return o.withText=!0,o.bind("label").to(t,"isImageSelected",(t=>e(t?"Replace from computer":"Upload from computer"))),o.on("execute",(()=>{t.dropdownView.isOpen=!1})),o}_createMenuBarButton(e){const t=this.editor.locale.t,o=this._createButton(sg);switch(o.withText=!0,e){case"standalone":o.label=t("Image from computer");break;case"insertOnly":o.label=t("Image");break;case"insertNested":o.label=t("From computer")}return o}}class xb extends fc{static get pluginName(){return"ImageUploadProgress"}static get isOfficialPlugin(){return!0}placeholder;constructor(e){super(e),this.placeholder="data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw=="}init(){const e=this.editor;e.plugins.has("ImageBlockEditing")&&e.editing.downcastDispatcher.on("attribute:uploadStatus:imageBlock",this.uploadStatusChange),e.plugins.has("ImageInlineEditing")&&e.editing.downcastDispatcher.on("attribute:uploadStatus:imageInline",this.uploadStatusChange)}uploadStatusChange=(e,t,o)=>{const i=this.editor,n=t.item,s=n.getAttribute("uploadId");if(!o.consumable.consume(t.item,e.name))return;const r=i.plugins.get("ImageUtils"),a=i.plugins.get(Qp),l=s?t.attributeNewValue:null,c=this.placeholder,d=i.editing.mapper.toViewElement(n),u=o.writer;if("reading"==l)return Eb(d,u),void Tb(r,c,d,u);if("uploading"==l){const e=a.loaders.get(s);return Eb(d,u),void(e?(Pb(d,u),function(e,t,o,i){const n=function(e){const t=e.createUIElement("div",{class:"ck-progress-bar"});return e.setCustomProperty("progressBar",!0,t),t}(t);t.insert(t.createPositionAt(e,"end"),n),o.on("change:uploadedPercent",((e,t,o)=>{i.change((e=>{e.setStyle("width",o+"%",n)}))}))}(d,u,e,i.editing.view),function(e,t,o,i){if(i.data){const n=e.findViewImgElement(t);o.setAttribute("src",i.data,n)}}(r,d,u,e)):Tb(r,c,d,u))}"complete"==l&&a.loaders.get(s)&&function(e,t,o){const i=t.createUIElement("div",{class:"ck-image-upload-complete-icon"});t.insert(t.createPositionAt(e,"end"),i),setTimeout((()=>{o.change((e=>e.remove(e.createRangeOn(i))))}),3e3)}(d,u,i.editing.view),function(e,t){Ib(e,t,"progressBar")}(d,u),Pb(d,u),function(e,t){t.removeClass("ck-appear",e)}(d,u)}}function Eb(e,t){e.hasClass("ck-appear")||t.addClass("ck-appear",e)}function Tb(e,t,o,i){o.hasClass("ck-image-upload-placeholder")||i.addClass("ck-image-upload-placeholder",o);const n=e.findViewImgElement(o);n.getAttribute("src")!==t&&i.setAttribute("src",t,n),Sb(o,"placeholder")||i.insert(i.createPositionAfter(n),function(e){const t=e.createUIElement("div",{class:"ck-upload-placeholder-loader"});return e.setCustomProperty("placeholder",!0,t),t}(i))}function Pb(e,t){e.hasClass("ck-image-upload-placeholder")&&t.removeClass("ck-image-upload-placeholder",e),Ib(e,t,"placeholder")}function Sb(e,t){for(const o of e.getChildren())if(o.getCustomProperty(t))return o}function Ib(e,t,o){const i=Sb(e,o);i&&t.remove(t.createRangeOn(i))}class Rb extends wc{constructor(e){super(e),this.set("isAccessAllowed",!0)}refresh(){const e=this.editor,t=e.plugins.get("ImageUtils"),o=e.model.document.selection.getSelectedElement();this.isEnabled=t.isImageAllowed()||t.isImage(o)}execute(e){const t=Qt(e.file),o=this.editor.model.document.selection,i=this.editor.plugins.get("ImageUtils"),n=Object.fromEntries(o.getAttributes());t.forEach(((e,t)=>{const s=o.getSelectedElement();if(t&&s&&i.isImage(s)){const t=this.editor.model.createPositionAfter(s);this._uploadImage(e,n,t)}else this._uploadImage(e,n)}))}_uploadImage(e,t,o){const i=this.editor,n=i.plugins.get(Qp).createLoader(e),s=i.plugins.get("ImageUtils");n&&s.insertImage({...t,uploadId:n.id},o)}}class Ob extends fc{static get requires(){return[Qp,Gm,bf,Gf]}static get pluginName(){return"ImageUploadEditing"}static get isOfficialPlugin(){return!0}_uploadImageElements;_uploadedImages=new Map;constructor(e){super(e),e.config.define("image",{upload:{types:["jpeg","png","gif","bmp","webp","tiff"]}}),this._uploadImageElements=new Map}init(){const e=this.editor,t=e.model.document,o=e.conversion,i=e.plugins.get(Qp),n=e.plugins.get("ImageUtils"),s=e.plugins.get("ClipboardPipeline"),r=kb(e.config.get("image.upload.types")),a=new Rb(e);e.commands.add("uploadImage",a),e.commands.add("imageUpload",a),o.for("upcast").attributeToAttribute({view:{name:"img",key:"uploadId"},model:"uploadId"}).add((e=>e.on("element:img",((e,t,o)=>{if(!o.consumable.test(t.viewItem,{attributes:["data-ck-upload-id"]}))return;const n=t.viewItem.getAttribute("data-ck-upload-id");if(!n)return;const[s]=Array.from(t.modelRange.getItems({shallow:!0})),r=i.loaders.get(n);s&&(o.writer.setAttribute("uploadId",n,s),o.consumable.consume(t.viewItem,{attributes:["data-ck-upload-id"]}),r&&r.data&&o.writer.setAttribute("uploadStatus",r.status,s))}),{priority:"low"}))),this.listenTo(e.editing.view.document,"clipboardInput",((t,o)=>{if(i=o.dataTransfer,Array.from(i.types).includes("text/html")&&""!==i.getData("text/html"))return;var i;const n=Array.from(o.dataTransfer.files).filter((e=>!!e&&r.test(e.type)));if(!n.length)return;t.stop(),e.model.change((t=>{o.targetRanges&&t.setSelection(o.targetRanges.map((t=>e.editing.mapper.toModelRange(t)))),e.execute("uploadImage",{file:n})}));if(!e.commands.get("uploadImage").isAccessAllowed){const t=e.plugins.get("Notification"),o=e.locale.t;t.showWarning(o("You have no image upload permissions."),{namespace:"image"})}})),this.listenTo(s,"inputTransformation",((t,o)=>{const s=Array.from(e.editing.view.createRangeIn(o.content)).map((e=>e.item)).filter((e=>function(e,t){return!(!e.isInlineImageView(t)||!t.getAttribute("src")||!t.getAttribute("src").match(/^data:image\/\w+;base64,/g)&&!t.getAttribute("src").match(/^blob:/g))}(n,e)&&!e.getAttribute("uploadProcessed"))).map((e=>({promise:vb(e),imageElement:e})));if(!s.length)return;const r=new rl(e.editing.view.document);for(const e of s){r.setAttribute("uploadProcessed",!0,e.imageElement);const t=i.createLoader(e.promise);t&&(r.setAttribute("src","",e.imageElement),r.setAttribute("uploadId",t.id,e.imageElement))}})),e.editing.view.document.on("dragover",((e,t)=>{t.preventDefault()})),t.on("change",(()=>{const o=t.differ.getChanges({includeChangesInGraveyard:!0}).reverse(),n=new Set;for(const t of o)if("insert"==t.type&&"$text"!=t.name){const o=t.position.nodeAfter,s="$graveyard"==t.position.root.rootName;for(const t of Vb(e,o)){const o=t.getAttribute("uploadId"),r=t.getAttribute("uploadStatus");if(!o||"complete"==r)continue;const a=i.loaders.get(o);if(a)if(s){if(!n.has(o)){Array.from(this._uploadImageElements.get(o)).every((e=>"$graveyard"==e.root.rootName))&&a.abort()}}else n.add(o),this._uploadImageElements.has(o)?this._uploadImageElements.get(o).add(t):this._uploadImageElements.set(o,new Set([t])),"idle"==a.status&&this._readAndUpload(a);else!s&&this._uploadedImages.has(o)&&e.model.enqueueChange({isUndoable:!1},(e=>{e.setAttribute("uploadStatus","complete",t),this.fire("uploadComplete",{data:this._uploadedImages.get(o),imageElement:t})}))}}})),this.on("uploadComplete",((e,{imageElement:t,data:o})=>{const i=o.urls?o.urls:o;this.editor.model.change((e=>{e.setAttribute("src",i.default,t),this._parseAndSetSrcsetAttributeOnImage(i,t,e),n.setImageNaturalSizeAttributes(t)}))}),{priority:"low"})}afterInit(){const e=this.editor.model.schema;this.editor.plugins.has("ImageBlockEditing")&&(e.extend("imageBlock",{allowAttributes:["uploadId","uploadStatus"]}),this._registerConverters("imageBlock")),this.editor.plugins.has("ImageInlineEditing")&&(e.extend("imageInline",{allowAttributes:["uploadId","uploadStatus"]}),this._registerConverters("imageInline"))}_readAndUpload(e){const t=this.editor,o=t.model,i=t.locale.t,n=t.plugins.get(Qp),s=t.plugins.get(Gm),r=t.plugins.get("ImageUtils"),a=this._uploadImageElements;return o.enqueueChange({isUndoable:!1},(t=>{const o=a.get(e.id);for(const e of o)t.setAttribute("uploadStatus","reading",e)})),e.read().then((()=>{const n=e.upload();t.ui&&t.ui.ariaLiveAnnouncer.announce(i("Uploading image"));for(const i of a.get(e.id)){if(Y.isSafari){const e=t.editing.mapper.toViewElement(i),o=r.findViewImgElement(e);t.editing.view.once("render",(()=>{if(!o.parent)return;const e=t.editing.view.domConverter.mapViewToDom(o.parent);if(!e)return;const i=e.style.display;e.style.display="none",e._ckHack=e.offsetHeight,e.style.display=i}))}o.enqueueChange({isUndoable:!1},(e=>{e.setAttribute("uploadStatus","uploading",i)}))}return n})).then((n=>{o.enqueueChange({isUndoable:!1},(o=>{for(const t of a.get(e.id))o.setAttribute("uploadStatus","complete",t),this.fire("uploadComplete",{data:n,imageElement:t});t.ui&&t.ui.ariaLiveAnnouncer.announce(i("Image upload complete")),this._uploadedImages.set(e.id,n)})),l()})).catch((n=>{if(t.ui&&t.ui.ariaLiveAnnouncer.announce(i("Error during image upload")),"error"!==e.status&&"aborted"!==e.status)throw n;"error"==e.status&&n&&s.showWarning(n,{title:i("Upload failed"),namespace:"upload"}),o.enqueueChange({isUndoable:!1},(t=>{for(const o of a.get(e.id))"$graveyard"!==o.root.rootName&&t.remove(o)})),l()}));function l(){o.enqueueChange({isUndoable:!1},(t=>{for(const o of a.get(e.id))t.removeAttribute("uploadId",o),t.removeAttribute("uploadStatus",o);a.delete(e.id)})),n.destroyLoader(e)}}_parseAndSetSrcsetAttributeOnImage(e,t,o){let i=0;const n=Object.keys(e).filter((e=>{const t=parseInt(e,10);if(!isNaN(t))return i=Math.max(i,t),!0})).map((t=>`${e[t]} ${t}w`)).join(", ");if(""!=n){const e={srcset:n};t.hasAttribute("width")||t.hasAttribute("height")||(e.width=i),o.setAttributes(e,t)}}_registerConverters(e){const{conversion:t,plugins:o}=this.editor,i=o.get(Qp),n=o.get(Gf);t.for("dataDowncast").add((t=>{t.on(`attribute:uploadId:${e}`,((e,t,o)=>{if(!o.consumable.test(t.item,e.name))return;const s=i.loaders.get(t.attributeNewValue);if(!s||!s.data)return null;const r=o.mapper.toViewElement(t.item),a=n.findViewImgElement(r);a&&(o.consumable.consume(t.item,e.name),o.writer.setAttribute("data-ck-upload-id",s.id,a))}))}))}}function Vb(e,t){const o=e.plugins.get("ImageUtils");return Array.from(e.model.createRangeOn(t)).filter((e=>o.isImage(e.item))).map((e=>e.item))}class Db extends fc{static get pluginName(){return"ImageUpload"}static get isOfficialPlugin(){return!0}static get requires(){return[Ob,Ab,xb]}}class Fb extends wc{refresh(){const e=this.editor,t=e.plugins.get("ImageUtils").getClosestSelectedImageElement(e.model.document.selection);this.isEnabled=!!t,t&&t.hasAttribute("resizedWidth")?this.value={width:t.getAttribute("resizedWidth"),height:null}:this.value=null}execute(e){const t=this.editor,o=t.model,i=t.plugins.get("ImageUtils"),n=i.getClosestSelectedImageElement(o.document.selection);this.value={width:e.width,height:null},n&&o.change((t=>{t.setAttribute("resizedWidth",e.width,n),t.removeAttribute("resizedHeight",n),i.setImageNaturalSizeAttributes(n)}))}}class Mb extends fc{static get requires(){return[Gf]}static get pluginName(){return"ImageResizeEditing"}static get licenseFeatureCode(){return"IR"}static get isOfficialPlugin(){return!0}static get isPremiumPlugin(){return!0}constructor(e){super(e),e.config.define("image",{resizeUnit:"%",resizeOptions:[{name:"resizeImage:original",value:null,icon:"original"},{name:"resizeImage:custom",value:"custom",icon:"custom"},{name:"resizeImage:25",value:"25",icon:"small"},{name:"resizeImage:50",value:"50",icon:"medium"},{name:"resizeImage:75",value:"75",icon:"large"}]})}init(){const e=this.editor,t=new Fb(e);this._registerConverters("imageBlock"),this._registerConverters("imageInline"),e.commands.add("resizeImage",t),e.commands.add("imageResize",t)}afterInit(){this._registerSchema()}_registerSchema(){const e=this.editor.model.schema;this.editor.plugins.has("ImageBlockEditing")&&(e.extend("imageBlock",{allowAttributes:["resizedWidth","resizedHeight"]}),e.setAttributeProperties("resizedWidth",{isFormatting:!0}),e.setAttributeProperties("resizedHeight",{isFormatting:!0})),this.editor.plugins.has("ImageInlineEditing")&&(e.extend("imageInline",{allowAttributes:["resizedWidth","resizedHeight"]}),e.setAttributeProperties("resizedWidth",{isFormatting:!0}),e.setAttributeProperties("resizedHeight",{isFormatting:!0}))}_registerConverters(e){const t=this.editor,o=t.plugins.get("ImageUtils");t.conversion.for("downcast").add((t=>t.on(`attribute:resizedWidth:${e}`,((e,t,o)=>{if(!o.consumable.consume(t.item,e.name))return;const i=o.writer,n=o.mapper.toViewElement(t.item);null!==t.attributeNewValue?(i.setStyle("width",t.attributeNewValue,n),i.addClass("image_resized",n)):(i.removeStyle("width",n),i.removeClass("image_resized",n))})))),t.conversion.for("dataDowncast").attributeToAttribute({model:{name:e,key:"resizedHeight"},view:e=>({key:"style",value:{height:e}})}),t.conversion.for("editingDowncast").add((t=>t.on(`attribute:resizedHeight:${e}`,((t,i,n)=>{if(!n.consumable.consume(i.item,t.name))return;const s=n.writer,r=n.mapper.toViewElement(i.item),a="imageInline"===e?o.findViewImgElement(r):r;null!==i.attributeNewValue?s.setStyle("height",i.attributeNewValue,a):s.removeStyle("height",a)})))),t.conversion.for("upcast").attributeToAttribute({view:{name:"imageBlock"===e?"figure":"img",styles:{width:/.+/}},model:{key:"resizedWidth",value:e=>Uf(e)?null:e.getStyle("width")}}),t.conversion.for("upcast").attributeToAttribute({view:{name:"imageBlock"===e?"figure":"img",styles:{height:/.+/}},model:{key:"resizedHeight",value:e=>Uf(e)?null:e.getStyle("height")}}),t.conversion.for("upcast").add((t=>{t.on("element:"+("imageBlock"===e?"figure":"img"),((e,t,o)=>{o.consumable.consume(t.viewItem,{classes:["image_resized"]})}))}))}}const Nb=(()=>({small:'',medium:'',large:'',custom:'',original:''}))();class Bb extends fc{static get requires(){return[Mb]}static get pluginName(){return"ImageResizeButtons"}static get isOfficialPlugin(){return!0}_resizeUnit;constructor(e){super(e),this._resizeUnit=e.config.get("image.resizeUnit")}init(){const e=this.editor,t=e.config.get("image.resizeOptions"),o=e.commands.get("resizeImage");this.bind("isEnabled").to(o);for(const e of t)this._registerImageResizeButton(e);this._registerImageResizeDropdown(t)}_registerImageResizeButton(e){const t=this.editor,{name:o,value:i,icon:n}=e;t.ui.componentFactory.add(o,(o=>{const s=new Lu(o),r=t.commands.get("resizeImage"),a=this._getOptionLabelValue(e,!0);if(!Nb[n])throw new fe("imageresizebuttons-missing-icon",t,e);if(s.set({label:a,icon:Nb[n],tooltip:a,isToggleable:!0}),s.bind("isEnabled").to(this),t.plugins.has("ImageCustomResizeUI")&&Lb(e)){const e=t.plugins.get("ImageCustomResizeUI");this.listenTo(s,"execute",(()=>{e._showForm(this._resizeUnit)}))}else{const e=i?i+this._resizeUnit:null;s.bind("isOn").to(r,"value",r,"isEnabled",zb(e)),this.listenTo(s,"execute",(()=>{t.execute("resizeImage",{width:e})}))}return s}))}_registerImageResizeDropdown(e){const t=this.editor,o=t.t,i=e.find((e=>!e.value)),n=n=>{const s=t.commands.get("resizeImage"),r=Zh(n,Mh),a=r.buttonView,l=o("Resize image");return a.set({tooltip:l,commandValue:i.value,icon:Nb.medium,isToggleable:!0,label:this._getOptionLabelValue(i),withText:!0,class:"ck-resize-image-button",ariaLabel:l,ariaLabelledBy:void 0}),a.bind("label").to(s,"value",(e=>e&&e.width?e.width:this._getOptionLabelValue(i))),r.bind("isEnabled").to(this),Xh(r,(()=>this._getResizeDropdownListItemDefinitions(e,s)),{ariaLabel:o("Image resize list"),role:"menu"}),this.listenTo(r,"execute",(e=>{"onClick"in e.source?e.source.onClick():(t.execute(e.source.commandName,{width:e.source.commandValue}),t.editing.view.focus())})),r};t.ui.componentFactory.add("resizeImage",n),t.ui.componentFactory.add("imageResize",n)}_getOptionLabelValue(e,t=!1){const o=this.editor.t;return e.label?e.label:t?Lb(e)?o("Custom image size"):e.value?o("Resize image to %0",e.value+this._resizeUnit):o("Resize image to the original size"):Lb(e)?o("Custom"):e.value?e.value+this._resizeUnit:o("Original")}_getResizeDropdownListItemDefinitions(e,t){const{editor:o}=this,i=new eo,n=e.map((e=>Lb(e)?{...e,valueWithUnits:"custom"}:e.value?{...e,valueWithUnits:`${e.value}${this._resizeUnit}`}:{...e,valueWithUnits:null}));for(const e of n){let s=null;if(o.plugins.has("ImageCustomResizeUI")&&Lb(e)){const i=o.plugins.get("ImageCustomResizeUI");s={type:"button",model:new Jm({label:this._getOptionLabelValue(e),role:"menuitemradio",withText:!0,icon:null,onClick:()=>{i._showForm(this._resizeUnit)}})};const r=Object.values(n).map((e=>e.valueWithUnits));s.model.bind("isOn").to(t,"value",t,"isEnabled",jb(r))}else s={type:"button",model:new Jm({commandName:"resizeImage",commandValue:e.valueWithUnits,label:this._getOptionLabelValue(e),role:"menuitemradio",withText:!0,icon:null})},s.model.bind("isOn").to(t,"value",t,"isEnabled",zb(e.valueWithUnits));s.model.bind("isEnabled").to(t,"isEnabled"),i.add(s)}return i}}function Lb(e){return"custom"===e.value}function zb(e){return(t,o)=>!(void 0===t||!o)&&(null===e&&t===e||null!==t&&t.width===e)}function jb(e){return(t,o)=>!e.some((e=>zb(e)(t,o)))}const qb="image_resized";class $b extends fc{static get requires(){return[Rp,Gf]}static get pluginName(){return"ImageResizeHandles"}static get isOfficialPlugin(){return!0}init(){const e=this.editor.commands.get("resizeImage");this.bind("isEnabled").to(e),this._setupResizerCreator()}_setupResizerCreator(){const e=this.editor,t=e.editing.view,o=e.plugins.get("ImageUtils");t.addObserver(nb),this.listenTo(t.document,"imageLoaded",((i,n)=>{if(!n.target.matches("figure.image.ck-widget > img,figure.image.ck-widget > picture > img,figure.image.ck-widget > a > img,figure.image.ck-widget > a > picture > img,span.image-inline.ck-widget > img,span.image-inline.ck-widget > picture > img"))return;const s=e.editing.view.domConverter,r=s.domToView(n.target),a=o.getImageWidgetFromImageView(r);let l=this.editor.plugins.get(Rp).getResizerByViewElement(a);if(l)return void l.redraw();const c=e.editing.mapper,d=c.toModelElement(a);l=e.plugins.get(Rp).attachTo({unit:e.config.get("image.resizeUnit"),modelElement:d,viewElement:a,editor:e,getHandleHost:e=>e.querySelector("img"),getResizeHost:()=>s.mapViewToDom(c.toViewElement(d)),isCentered:()=>"alignCenter"==d.getAttribute("imageStyle"),onCommit(o){t.change((e=>{e.removeClass(qb,a)})),e.execute("resizeImage",{width:o})}}),l.on("updateSize",(()=>{a.hasClass(qb)||t.change((e=>{e.addClass(qb,a)}));const e="imageInline"===d.name?r:a;e.getStyle("height")&&t.change((t=>{t.removeStyle("height",e)}))})),l.bind("isEnabled").to(this)}))}}function Hb(e){if(!e)return null;const[,t,o]=e.trim().match(/([.,\d]+)(%|px)$/)||[],i=Number.parseFloat(t);return Number.isNaN(i)?null:{value:i,unit:o}}function Wb(e,t,o){return"px"===o?{value:t.value,unit:"px"}:{value:t.value/e*100,unit:"%"}}function Ub(e){const{editing:t}=e,o=e.plugins.get("ImageUtils").getClosestSelectedImageElement(e.model.document.selection);if(!o)return null;const i=t.mapper.toViewElement(o);return{model:o,view:i,dom:t.view.domConverter.mapViewToDom(i)}}class Kb extends Au{focusTracker;keystrokes;unit;backButtonView;saveButtonView;labeledInput;children;_focusables;_focusCycler;_validators;constructor(e,t,o){super(e),this.focusTracker=new oo,this.keystrokes=new ro,this.unit=t,this.backButtonView=this._createBackButton(),this.saveButtonView=this._createSaveButton(),this.labeledInput=this._createLabeledInputView(),this.children=this.createCollection([this._createHeaderView()]),this.children.add(new Km(e,{children:[this.labeledInput,this.saveButtonView],class:["ck-form__row_with-submit","ck-form__row_large-top-padding"]})),this._focusables=new tu,this._validators=o,this.keystrokes.set("Esc",((e,t)=>{this.fire("cancel"),t()})),this._focusCycler=new qu({focusables:this._focusables,focusTracker:this.focusTracker,keystrokeHandler:this.keystrokes,actions:{focusPrevious:"shift + tab",focusNext:"tab"}}),this.setTemplate({tag:"form",attributes:{class:["ck","ck-form","ck-image-custom-resize-form","ck-responsive-form"],tabindex:"-1"},children:this.children})}render(){super.render(),Ou({view:this});[this.backButtonView,this.labeledInput,this.saveButtonView].forEach((e=>{this._focusables.add(e),this.focusTracker.add(e.element)})),this.keystrokes.listenTo(this.element)}destroy(){super.destroy(),this.focusTracker.destroy(),this.keystrokes.destroy()}_createBackButton(){const e=this.locale.t,t=new Lu(this.locale);return t.set({class:"ck-button-back",label:e("Back"),icon:ed,tooltip:!0}),t.delegate("execute").to(this,"cancel"),t}_createSaveButton(){const e=this.locale.t,t=new Lu(this.locale);return t.set({label:e("Save"),withText:!0,type:"submit",class:"ck-button-action ck-button-bold"}),t}_createHeaderView(){const e=this.locale.t,t=new ju(this.locale,{label:e("Image Resize")});return t.children.add(this.backButtonView,0),t}_createLabeledInputView(){const e=this.locale.t,t=new Sh(this.locale,sm);return t.label=e("Resize image (in %0)",this.unit),t.class="ck-labeled-field-view_full-width",t.fieldView.set({step:.1}),t}isValid(){this.resetFormStatus();for(const e of this._validators){const t=e(this);if(t)return this.labeledInput.errorText=t,!1}return!0}resetFormStatus(){this.labeledInput.errorText=null}get rawSize(){const{element:e}=this.labeledInput.fieldView;return e?e.value:null}get parsedSize(){const{rawSize:e}=this;if(null===e)return null;const t=Number.parseFloat(e);return Number.isNaN(t)?null:t}get sizeWithUnits(){const{parsedSize:e,unit:t}=this;return null===e?null:`${e}${t}`}}class Gb extends fc{_balloon;_form;static get requires(){return[Qm]}static get pluginName(){return"ImageCustomResizeUI"}static get isOfficialPlugin(){return!0}destroy(){super.destroy(),this._form&&this._form.destroy()}_createForm(e){const t=this.editor;this._balloon=this.editor.plugins.get("ContextualBalloon"),this._form=new(Iu(Kb))(t.locale,e,function(e){const t=e.t;return[e=>""===e.rawSize.trim()?t("The value must not be empty."):null===e.parsedSize?t("The value should be a plain number."):void 0]}(t)),this._form.render(),this.listenTo(this._form,"submit",(()=>{this._form.isValid()&&(t.execute("resizeImage",{width:this._form.sizeWithUnits}),this._hideForm(!0))})),this.listenTo(this._form.labeledInput,"change:errorText",(()=>{t.ui.update()})),this.listenTo(this._form,"cancel",(()=>{this._hideForm(!0)})),Su({emitter:this._form,activator:()=>this._isVisible,contextElements:()=>[this._balloon.view.element],callback:()=>this._hideForm()})}_showForm(e){if(this._isVisible)return;this._form||this._createForm(e);const t=this.editor,o=this._form.labeledInput;this._form.disableCssTransitions(),this._form.resetFormStatus(),this._isInBalloon||this._balloon.add({view:this._form,position:Xf(t)});const i=function(e,t){const o=Ub(e);if(!o)return null;const i=Hb(o.model.getAttribute("resizedWidth")||null);return i?i.unit===t?i:Wb(up(o.dom),{value:new ut(o.dom).width},t):null}(t,e),n=i?i.value.toFixed(1):"",s=function(e,t){const o=Ub(e);if(!o)return null;const i=up(o.dom),n=Hb(window.getComputedStyle(o.dom).minWidth)||{value:1};return{unit:t,lower:Math.max(.1,Wb(i,n,t).value),upper:"px"===t?i:100}}(t,e);o.fieldView.value=o.fieldView.element.value=n,s&&Object.assign(o.fieldView,{min:s.lower.toFixed(1),max:Math.ceil(s.upper).toFixed(1)}),this._form.labeledInput.fieldView.select(),this._form.enableCssTransitions()}_hideForm(e=!1){this._isInBalloon&&(this._form.focusTracker.isFocused&&this._form.saveButtonView.focus(),this._balloon.remove(this._form),e&&this.editor.editing.view.focus())}get _isVisible(){return!!this._balloon&&this._balloon.visibleView===this._form}get _isInBalloon(){return!!this._balloon&&this._balloon.hasView(this._form)}}class Jb extends wc{_defaultStyles;_styles;constructor(e,t){super(e),this._defaultStyles={imageBlock:!1,imageInline:!1},this._styles=new Map(t.map((e=>{if(e.isDefault)for(const t of e.modelElements)this._defaultStyles[t]=e.name;return[e.name,e]})))}refresh(){const e=this.editor.plugins.get("ImageUtils").getClosestSelectedImageElement(this.editor.model.document.selection);this.isEnabled=!!e,this.isEnabled?e.hasAttribute("imageStyle")?this.value=e.getAttribute("imageStyle"):this.value=this._defaultStyles[e.name]:this.value=!1}execute(e={}){const t=this.editor,o=t.model,i=t.plugins.get("ImageUtils");o.change((t=>{const n=e.value,{setImageSizes:s=!0}=e;let r=i.getClosestSelectedImageElement(o.document.selection);n&&this.shouldConvertImageType(n,r)&&(this.editor.execute(i.isBlockImage(r)?"imageTypeInline":"imageTypeBlock",{setImageSizes:s}),r=i.getClosestSelectedImageElement(o.document.selection)),!n||this._styles.get(n).isDefault?t.removeAttribute("imageStyle",r):t.setAttribute("imageStyle",n,r),s&&i.setImageNaturalSizeAttributes(r)}))}shouldConvertImageType(e,t){return!this._styles.get(e).modelElements.includes(t.name)}}const Zb={get inline(){return{name:"inline",title:"In line",icon:Qc,modelElements:["imageInline"],isDefault:!0}},get alignLeft(){return{name:"alignLeft",title:"Left aligned image",icon:Jc,modelElements:["imageBlock","imageInline"],className:"image-style-align-left"}},get alignBlockLeft(){return{name:"alignBlockLeft",title:"Left aligned image",icon:Yc,modelElements:["imageBlock"],className:"image-style-block-align-left"}},get alignCenter(){return{name:"alignCenter",title:"Centered image",icon:Gc,modelElements:["imageBlock"],className:"image-style-align-center"}},get alignRight(){return{name:"alignRight",title:"Right aligned image",icon:Zc,modelElements:["imageBlock","imageInline"],className:"image-style-align-right"}},get alignBlockRight(){return{name:"alignBlockRight",title:"Right aligned image",icon:Xc,modelElements:["imageBlock"],className:"image-style-block-align-right"}},get block(){return{name:"block",title:"Centered image",icon:Gc,modelElements:["imageBlock"],isDefault:!0}},get side(){return{name:"side",title:"Side image",icon:Zc,modelElements:["imageBlock"],className:"image-style-side"}}},Qb=(()=>({full:'',left:Yc,right:Xc,center:Gc,inlineLeft:Jc,inlineRight:Zc,inline:Qc}))(),Yb=[{name:"imageStyle:wrapText",title:"Wrap text",defaultItem:"imageStyle:alignLeft",items:["imageStyle:alignLeft","imageStyle:alignRight"]},{name:"imageStyle:breakText",title:"Break text",defaultItem:"imageStyle:block",items:["imageStyle:alignBlockLeft","imageStyle:block","imageStyle:alignBlockRight"]}];function Xb(e){be("image-style-configuration-definition-invalid",e)}const ew={normalizeStyles:function(e){const t=(e.configuredStyles.options||[]).map((e=>function(e){e="string"==typeof e?Zb[e]?{...Zb[e]}:{name:e}:function(e,t){const o={...t};for(const i in e)Object.prototype.hasOwnProperty.call(t,i)||(o[i]=e[i]);return o}(Zb[e.name],e);"string"==typeof e.icon&&(e.icon=Qb[e.icon]||e.icon);return e}(e))).filter((t=>function(e,{isBlockPluginLoaded:t,isInlinePluginLoaded:o}){const{modelElements:i,name:n}=e;if(!(i&&i.length&&n))return Xb({style:e}),!1;{const n=[t?"imageBlock":null,o?"imageInline":null];if(!i.some((e=>n.includes(e))))return be("image-style-missing-dependency",{style:e,missingPlugins:i.map((e=>"imageBlock"===e?"ImageBlockEditing":"ImageInlineEditing"))}),!1}return!0}(t,e)));return t},getDefaultStylesConfiguration:function(e,t){return e&&t?{options:["inline","alignLeft","alignRight","alignCenter","alignBlockLeft","alignBlockRight","block","side"]}:e?{options:["block","side"]}:t?{options:["inline","alignLeft","alignRight"]}:{}},getDefaultDropdownDefinitions:function(e){return e.has("ImageBlockEditing")&&e.has("ImageInlineEditing")?[...Yb]:[]},warnInvalidStyle:Xb};function tw(e){const t={imageInline:e.filter((e=>!e.isDefault&&e.modelElements.includes("imageInline"))),imageBlock:e.filter((e=>!e.isDefault&&e.modelElements.includes("imageBlock")))};return(o,i,n)=>{if(!i.modelRange)return;const s=i.viewItem,r=to(i.modelRange.getItems());if(r&&n.schema.checkAttribute(r,"imageStyle")){for(const e of t[r.name])n.consumable.consume(s,{classes:e.className})&&n.writer.setAttribute("imageStyle",e.name,r);!function(e,t,o,i){if(!e.consumable.test(t,{styles:["float"]}))return;let n=null;switch(t.getStyle("float")){case"left":n="alignLeft";break;case"right":n="alignRight"}if(!n)return;const s=ow(n,i);if(!s)return;const r=Zb[s.name];if(!Ko(s,r))return;e.writer.setAttribute("imageStyle",n,o),e.consumable.consume(t,{styles:["float"]})}(n,s,r,e)}}}function ow(e,t){for(const o of t)if(o.name===e)return o}class iw extends fc{static get pluginName(){return"ImageStyleEditing"}static get isOfficialPlugin(){return!0}static get requires(){return[Gf]}normalizedStyles;init(){const e=this.editor,t=e.plugins.has("ImageBlockEditing"),o=e.plugins.has("ImageInlineEditing");e.config.define("image.styles",ew.getDefaultStylesConfiguration(t,o)),this.normalizedStyles=ew.normalizeStyles({configuredStyles:e.config.get("image.styles"),isBlockPluginLoaded:t,isInlinePluginLoaded:o}),this._setupConversion(t,o),this._setupPostFixer(),e.commands.add("imageStyle",new Jb(e,this.normalizedStyles))}_setupConversion(e,t){const o=this.editor,i=o.model.schema,n=(s=this.normalizedStyles,(e,t,o)=>{if(!o.consumable.consume(t.item,e.name))return;const i=ow(t.attributeNewValue,s),n=ow(t.attributeOldValue,s),r=o.mapper.toViewElement(t.item),a=o.writer;n&&a.removeClass(n.className,r),i&&a.addClass(i.className,r)});var s;const r=tw(this.normalizedStyles);o.editing.downcastDispatcher.on("attribute:imageStyle",n),o.data.downcastDispatcher.on("attribute:imageStyle",n),e&&(i.extend("imageBlock",{allowAttributes:"imageStyle"}),i.setAttributeProperties("imageStyle",{isFormatting:!0}),o.data.upcastDispatcher.on("element:figure",r,{priority:"low"})),t&&(i.extend("imageInline",{allowAttributes:"imageStyle"}),i.setAttributeProperties("imageStyle",{isFormatting:!0}),o.data.upcastDispatcher.on("element:img",r,{priority:"low"}))}_setupPostFixer(){const e=this.editor,t=e.model.document,o=e.plugins.get(Gf),i=new Map(this.normalizedStyles.map((e=>[e.name,e])));t.registerPostFixer((e=>{let n=!1;for(const s of t.differ.getChanges())if("insert"==s.type||"attribute"==s.type&&"imageStyle"==s.attributeKey){let t="insert"==s.type?s.position.nodeAfter:s.range.start.nodeAfter;if(t&&t.is("element","paragraph")&&t.childCount>0&&(t=t.getChild(0)),!o.isImage(t))continue;const r=t.getAttribute("imageStyle");if(!r)continue;const a=i.get(r);a&&a.modelElements.includes(t.name)||(e.removeAttribute("imageStyle",t),n=!0)}return n}))}}class nw extends fc{static get requires(){return[iw]}static get pluginName(){return"ImageStyleUI"}static get isOfficialPlugin(){return!0}get localizedDefaultStylesTitles(){const e=this.editor.t;return{"Wrap text":e("Wrap text"),"Break text":e("Break text"),"In line":e("In line"),"Full size image":e("Full size image"),"Side image":e("Side image"),"Left aligned image":e("Left aligned image"),"Centered image":e("Centered image"),"Right aligned image":e("Right aligned image")}}init(){const e=this.editor.plugins,t=this.editor.config.get("image.toolbar")||[],o=sw(e.get("ImageStyleEditing").normalizedStyles,this.localizedDefaultStylesTitles);for(const e of o)this._createButton(e);const i=sw([...t.filter(s),...ew.getDefaultDropdownDefinitions(e)],this.localizedDefaultStylesTitles);for(const e of i)this._createDropdown(e,o)}_createDropdown(e,t){const o=this.editor.ui.componentFactory;o.add(e.name,(i=>{let n;const{defaultItem:s,items:r,title:a}=e,l=r.filter((e=>t.find((({name:t})=>rw(t)===e)))).map((e=>{const t=o.create(e);return e===s&&(n=t),t}));r.length!==l.length&&ew.warnInvalidStyle({dropdown:e});const c=Zh(i,Jh),d=c.buttonView,u=d.arrowView;return Qh(c,l,{enableActiveItemFocusOnDropdownOpen:!0}),d.set({label:aw(a,n.label),class:null,tooltip:!0}),u.unbind("label"),u.set({label:a}),d.bind("icon").toMany(l,"isOn",((...e)=>{const t=e.findIndex(jf);return t<0?n.icon:l[t].icon})),d.bind("label").toMany(l,"isOn",((...e)=>{const t=e.findIndex(jf);return aw(a,t<0?n.label:l[t].label)})),d.bind("isOn").toMany(l,"isOn",((...e)=>e.some(jf))),d.bind("class").toMany(l,"isOn",((...e)=>e.some(jf)?"ck-splitbutton_flatten":void 0)),d.on("execute",(()=>{l.some((({isOn:e})=>e))?c.isOpen=!c.isOpen:n.fire("execute")})),c.bind("isEnabled").toMany(l,"isEnabled",((...e)=>e.some(jf))),this.listenTo(c,"execute",(()=>{this.editor.editing.view.focus()})),c}))}_createButton(e){const t=e.name;this.editor.ui.componentFactory.add(rw(t),(o=>{const i=this.editor.commands.get("imageStyle"),n=new Lu(o);return n.set({label:e.title,icon:e.icon,tooltip:!0,isToggleable:!0}),n.bind("isEnabled").to(i,"isEnabled"),n.bind("isOn").to(i,"value",(e=>e===t)),n.on("execute",this._executeCommand.bind(this,t)),n}))}_executeCommand(e){this.editor.execute("imageStyle",{value:e}),this.editor.editing.view.focus()}}function sw(e,t){for(const o of e)t[o.title]&&(o.title=t[o.title]);return e}function rw(e){return`imageStyle:${e}`}function aw(e,t){return(e?e+": ":"")+t}function lw(e){return e.map((e=>s(e)?e.name:e))}const cw=Symbol("isWpButtonMacroSymbol");function dw(e){const t=e.getSelectedElement();return!(!t||!function(e){return!!e.getCustomProperty(cw)&&ip(e)}(t))}class uw extends fc{static get pluginName(){return"OPChildPagesEditing"}static get buttonName(){return"insertChildPages"}init(){const e=this.editor,t=e.model,o=e.conversion;t.schema.register("op-macro-child-pages",{allowWhere:["$block"],allowAttributes:["page"],isBlock:!0,isLimit:!0}),o.for("upcast").elementToElement({view:{name:"macro",classes:"child_pages"},model:(e,{writer:t})=>{const o=e.getAttribute("data-page")||"",i="true"==e.getAttribute("data-include-parent");return t.createElement("op-macro-child-pages",{page:o,includeParent:i})}}),o.for("editingDowncast").elementToElement({model:"op-macro-child-pages",view:(e,{writer:t})=>this.createMacroViewElement(e,t)}).add((e=>e.on("attribute:page",this.modelAttributeToView.bind(this)))).add((e=>e.on("attribute:includeParent",this.modelAttributeToView.bind(this)))),o.for("dataDowncast").elementToElement({model:"op-macro-child-pages",view:(e,{writer:t})=>t.createContainerElement("macro",{class:"child_pages","data-page":e.getAttribute("page")||"","data-include-parent":e.getAttribute("includeParent")||""})}),e.ui.componentFactory.add(uw.buttonName,(t=>{const o=new Lu(t);return o.set({label:window.I18n.t("js.editor.macro.child_pages.button"),withText:!0}),o.on("execute",(()=>{e.model.change((t=>{const o=t.createElement("op-macro-child-pages",{});e.model.insertContent(o,e.model.document.selection)}))})),o}))}modelAttributeToView(e,t,o){const i=t.item;if(!i.is("element","op-macro-child-pages"))return;o.consumable.consume(t.item,e.name);const n=o.mapper.toViewElement(i);o.writer.remove(o.writer.createRangeIn(n)),this.setPlaceholderContent(o.writer,i,n)}macroLabel(){return window.I18n.t("js.editor.macro.child_pages.text")}pageLabel(e){return e&&e.length>0?e:window.I18n.t("js.editor.macro.child_pages.this_page")}includeParentText(e){return e?` (${window.I18n.t("js.editor.macro.child_pages.include_parent")})`:""}createMacroViewElement(e,t){const o=t.createContainerElement("div");return this.setPlaceholderContent(t,e,o),function(e,t,o){return t.setCustomProperty(cw,!0,e),np(e,t,{label:o})}(o,t,{label:this.macroLabel()})}setPlaceholderContent(e,t,o){const i=t.getAttribute("page"),n=t.getAttribute("includeParent"),s=this.macroLabel(),r=this.pageLabel(i),a=e.createContainerElement("span",{class:"macro-value"});let l=[e.createText(`${s} `)];e.insert(e.createPositionAt(a,0),e.createText(`${r}`)),l.push(a),l.push(e.createText(this.includeParentText(n))),e.insert(e.createPositionAt(o,0),l)}}class hw extends fc{static get requires(){return[Qm]}static get pluginName(){return"OPChildPagesToolbar"}init(){const e=this.editor,t=this.editor.model,o=Mp(e);jp(e,"opEditChildPagesMacroButton",(e=>{const i=o.services.macros,n=e.getAttribute("page"),s=e.getAttribute("includeParent"),r=n&&n.length>0?n:"";i.configureChildPages(r,s).then((o=>t.change((t=>{t.setAttribute("page",o.page,e),t.setAttribute("includeParent",o.includeParent,e)}))))}))}afterInit(){$p(this,this.editor,"OPChildPages",dw)}}class mw extends wc{constructor(e){super(e),this.affectsData=!1}execute(){const e=this.editor.model,t=e.document.selection;let o=e.schema.getLimitElement(t);if(t.containsEntireContent(o)||!gw(e.schema,o))do{if(o=o.parent,!o)return}while(!gw(e.schema,o));e.change((e=>{e.setSelection(o,"in")}))}}function gw(e,t){return e.isLimit(t)&&(e.checkChild(t,"$text")||e.checkChild(t,"paragraph"))}const pw=Wt("Ctrl+A");class fw extends fc{static get pluginName(){return"SelectAllEditing"}static get isOfficialPlugin(){return!0}init(){const e=this.editor,t=e.t,o=e.editing.view.document;e.commands.add("selectAll",new mw(e)),this.listenTo(o,"keydown",((t,o)=>{Ht(o)===pw&&(e.execute("selectAll"),o.preventDefault())})),e.accessibility.addKeystrokeInfos({keystrokes:[{label:t("Select all"),keystroke:"CTRL+A"}]})}}class bw extends fc{static get pluginName(){return"SelectAllUI"}static get isOfficialPlugin(){return!0}init(){const e=this.editor;e.ui.componentFactory.add("selectAll",(()=>{const e=this._createButton(Lu);return e.set({tooltip:!0}),e})),e.ui.componentFactory.add("menuBar:selectAll",(()=>this._createButton(sh)))}_createButton(e){const t=this.editor,o=t.locale,i=t.commands.get("selectAll"),n=new e(t.locale),s=o.t;return n.set({label:s("Select all"),icon:'',keystroke:"Ctrl+A"}),n.bind("isEnabled").to(i,"isEnabled"),this.listenTo(n,"execute",(()=>{t.execute("selectAll"),t.editing.view.focus()})),n}}class ww extends fc{static get requires(){return[fw,bw]}static get pluginName(){return"SelectAll"}static get isOfficialPlugin(){return!0}}const yw="ckCsrfToken",_w="abcdefghijklmnopqrstuvwxyz0123456789";function kw(){let e=function(e){e=e.toLowerCase();const t=document.cookie.split(";");for(const o of t){const t=o.split("=");if(decodeURIComponent(t[0].trim().toLowerCase())===e)return decodeURIComponent(t[1])}return null}(yw);var t,o;return e&&40==e.length||(e=function(e){let t="";const o=new Uint8Array(e);window.crypto.getRandomValues(o);for(let e=0;e.5?i.toUpperCase():i}return t}(40),t=yw,o=e,document.cookie=encodeURIComponent(t)+"="+encodeURIComponent(o)+";path=/"),e}class vw{loader;url;t;xhr;constructor(e,t,o){this.loader=e,this.url=t,this.t=o}upload(){return this.loader.file.then((e=>new Promise(((t,o)=>{this._initRequest(),this._initListeners(t,o,e),this._sendRequest(e)}))))}abort(){this.xhr&&this.xhr.abort()}_initRequest(){const e=this.xhr=new XMLHttpRequest;e.open("POST",this.url,!0),e.responseType="json"}_initListeners(e,t,o){const i=this.xhr,n=this.loader,s=(0,this.t)("Cannot upload file:")+` ${o.name}.`;i.addEventListener("error",(()=>t(s))),i.addEventListener("abort",(()=>t())),i.addEventListener("load",(()=>{const o=i.response;if(!o||!o.uploaded)return t(o&&o.error&&o.error.message?o.error.message:s);e({default:o.url})})),i.upload&&i.upload.addEventListener("progress",(e=>{e.lengthComputable&&(n.uploadTotal=e.total,n.uploaded=e.loaded)}))}_sendRequest(e){const t=new FormData;t.append("upload",e),t.append("ckCsrfToken",kw()),this.xhr.send(t)}}function Cw(e,t,o,i){let n,s=null;"function"==typeof i?n=i:(s=e.commands.get(i),n=()=>{e.execute(i)}),e.model.document.on("change:data",((r,a)=>{if(s&&!s.isEnabled||!t.isEnabled)return;const l=to(e.model.document.selection.getRanges());if(!l.isCollapsed)return;if(a.isUndo||!a.isLocal)return;const c=Array.from(e.model.document.differ.getChanges()),d=c[0];if(1!=c.length||"insert"!==d.type||"$text"!=d.name||1!=d.length)return;const u=d.position.parent;if(u.is("element","codeBlock"))return;if(u.is("element","listItem")&&"function"!=typeof i&&!["numberedList","bulletedList","todoList"].includes(i))return;if(s&&!0===s.value)return;const h=u.getChild(0),m=e.model.createRangeOn(h);if(!m.containsRange(l)&&!l.end.isEqual(m.end))return;const g=o.exec(h.data.substr(0,l.end.offset));g&&e.model.enqueueChange((t=>{const o=e.model.document.selection,i=t.createPositionAt(u,0),s=t.createPositionAt(u,g[0].length),r=new Ts(i,s);if(!1!==n({match:g})){const e=Array.from(o.getAttributes());t.remove(r);const i=o.getFirstRange(),n=t.createRangeIn(u);!u.isEmpty||n.isEqual(i)||n.containsRange(i,!0)||t.remove(u),function(e,t,o){const i=e.model.schema,n=t.getFirstPosition();let s=new gr(n);i.checkChild(s,"$text")&&(s=s.push("$text"));for(const[t,n]of o)i.checkAttribute(s,t)&&e.setSelectionAttribute(t,n)}(t,o,e)}r.detach(),e.model.enqueueChange((()=>{e.plugins.get("Delete").requestUndoOnBackspace()}))}))}))}function Aw(e,t,o,i){let n,s;o instanceof RegExp?n=o:s=o,s=s||(e=>{let t;const o=[],i=[];for(;null!==(t=n.exec(e))&&!(t&&t.length<4);){let{index:e,1:n,2:s,3:r}=t;const a=n+s+r;e+=t[0].length-a.length;const l=[e,e+n.length],c=[e+n.length+s.length,e+n.length+s.length+r.length];o.push(l),o.push(c),i.push([e+n.length,e+n.length+s.length])}return{remove:o,format:i}}),e.model.document.on("change:data",((o,n)=>{if(n.isUndo||!n.isLocal||!t.isEnabled)return;const r=e.model,a=r.document.selection;if(!a.isCollapsed)return;const l=Array.from(r.document.differ.getChanges()),c=l[0];if(1!=l.length||"insert"!==c.type||"$text"!=c.name||1!=c.length)return;const d=a.focus,u=d.parent,{text:h,range:m}=function(e,t){let o=e.start;const i=Array.from(e.getItems()).reduce(((e,i)=>!i.is("$text")&&!i.is("$textProxy")||i.getAttribute("code")?(o=t.createPositionAfter(i),""):e+i.data),"");return{text:i,range:t.createRange(o,e.end)}}(r.createRange(r.createPositionAt(u,0),d),r),g=s(h),p=xw(m.start,g.format,r),f=xw(m.start,g.remove,r);p.length&&f.length&&r.enqueueChange((t=>{if(!1!==i(t,p)){for(const e of f.reverse())t.remove(e);r.enqueueChange((()=>{e.plugins.get("Delete").requestUndoOnBackspace()}))}}))}))}function xw(e,t,o){return t.filter((e=>void 0!==e[0]&&void 0!==e[1])).map((t=>o.createRange(e.getShiftedBy(t[0]),e.getShiftedBy(t[1]))))}function Ew(e,t){return(o,i)=>{if(!e.commands.get(t).isEnabled)return!1;const n=e.model.schema.getValidRanges(i,t);for(const e of n)o.setAttribute(t,!0,e);o.removeSelectionAttribute(t)}}class Tw extends wc{attributeKey;constructor(e,t){super(e),this.attributeKey=t}refresh(){const e=this.editor.model,t=e.document;this.value=this._getValueFromFirstAllowedNode(),this.isEnabled=e.schema.checkAttributeInSelection(t.selection,this.attributeKey)}execute(e={}){const t=this.editor.model,o=t.document.selection,i=void 0===e.forceValue?!this.value:e.forceValue;t.change((e=>{if(o.isCollapsed)i?e.setSelectionAttribute(this.attributeKey,!0):e.removeSelectionAttribute(this.attributeKey);else{const n=t.schema.getValidRanges(o.getRanges(),this.attributeKey,{includeEmptyRanges:!0});for(const t of n){let o=t,n=this.attributeKey;t.isCollapsed&&(o=t.start.parent,n=Os._getStoreAttributeKey(this.attributeKey)),i?e.setAttribute(n,i,o):e.removeAttribute(n,o)}}}))}_getValueFromFirstAllowedNode(){const e=this.editor.model,t=e.schema,o=e.document.selection;if(o.isCollapsed)return o.hasAttribute(this.attributeKey);for(const e of o.getRanges())for(const o of e.getItems())if(t.checkAttribute(o,this.attributeKey))return o.hasAttribute(this.attributeKey);return!1}}const Pw="bold";class Sw extends fc{static get pluginName(){return"BoldEditing"}static get isOfficialPlugin(){return!0}init(){const e=this.editor,t=this.editor.t;e.model.schema.extend("$text",{allowAttributes:Pw}),e.model.schema.setAttributeProperties(Pw,{isFormatting:!0,copyOnEnter:!0}),e.conversion.attributeToElement({model:Pw,view:"strong",upcastAlso:["b",e=>{const t=e.getStyle("font-weight");return t&&("bold"==t||Number(t)>=600)?{name:!0,styles:["font-weight"]}:null}]}),e.commands.add(Pw,new Tw(e,Pw)),e.keystrokes.set("CTRL+B",Pw),e.accessibility.addKeystrokeInfos({keystrokes:[{label:t("Bold text"),keystroke:"CTRL+B"}]})}}function Iw({editor:e,commandName:t,plugin:o,icon:i,label:n,keystroke:s}){return r=>{const a=e.commands.get(t),l=new r(e.locale);return l.set({label:n,icon:i,keystroke:s,isToggleable:!0}),l.bind("isEnabled").to(a,"isEnabled"),l.bind("isOn").to(a,"value"),l instanceof sh?l.set({role:"menuitemcheckbox"}):l.set({tooltip:!0}),o.listenTo(l,"execute",(()=>{e.execute(t),e.editing.view.focus()})),l}}const Rw="bold";class Ow extends fc{static get pluginName(){return"BoldUI"}static get isOfficialPlugin(){return!0}init(){const e=this.editor,t=e.locale.t,o=Iw({editor:e,commandName:Rw,plugin:this,icon:qc,label:t("Bold"),keystroke:"CTRL+B"});e.ui.componentFactory.add(Rw,(()=>o(Lu))),e.ui.componentFactory.add("menuBar:"+Rw,(()=>o(sh)))}}const Vw="code";class Dw extends fc{static get pluginName(){return"CodeEditing"}static get isOfficialPlugin(){return!0}static get requires(){return[Rg]}init(){const e=this.editor,t=this.editor.t;e.model.schema.extend("$text",{allowAttributes:Vw}),e.model.schema.setAttributeProperties(Vw,{isFormatting:!0,copyOnEnter:!1}),e.conversion.attributeToElement({model:Vw,view:"code"}),e.commands.add(Vw,new Tw(e,Vw)),e.plugins.get(Rg).registerAttribute(Vw),jg(e,Vw,"code","ck-code_selected"),e.accessibility.addKeystrokeInfos({keystrokes:[{label:t("Move out of an inline code style"),keystroke:[["arrowleft","arrowleft"],["arrowright","arrowright"]]}]})}}const Fw="code";class Mw extends fc{static get pluginName(){return"CodeUI"}static get isOfficialPlugin(){return!0}init(){const e=this.editor,t=e.locale.t,o=Iw({editor:e,commandName:Fw,plugin:this,icon:'',label:t("Code")});e.ui.componentFactory.add(Fw,(()=>o(Lu))),e.ui.componentFactory.add("menuBar:"+Fw,(()=>o(sh)))}}const Nw="italic";class Bw extends fc{static get pluginName(){return"ItalicEditing"}static get isOfficialPlugin(){return!0}init(){const e=this.editor,t=this.editor.t;e.model.schema.extend("$text",{allowAttributes:Nw}),e.model.schema.setAttributeProperties(Nw,{isFormatting:!0,copyOnEnter:!0}),e.conversion.attributeToElement({model:Nw,view:"i",upcastAlso:["em",{styles:{"font-style":"italic"}}]}),e.commands.add(Nw,new Tw(e,Nw)),e.keystrokes.set("CTRL+I",Nw),e.accessibility.addKeystrokeInfos({keystrokes:[{label:t("Italic text"),keystroke:"CTRL+I"}]})}}const Lw="italic";class zw extends fc{static get pluginName(){return"ItalicUI"}static get isOfficialPlugin(){return!0}init(){const e=this.editor,t=e.locale.t,o=Iw({editor:e,commandName:Lw,plugin:this,icon:'',keystroke:"CTRL+I",label:t("Italic")});e.ui.componentFactory.add(Lw,(()=>o(Lu))),e.ui.componentFactory.add("menuBar:"+Lw,(()=>o(sh)))}}const jw="strikethrough";class qw extends fc{static get pluginName(){return"StrikethroughEditing"}static get isOfficialPlugin(){return!0}init(){const e=this.editor,t=this.editor.t;e.model.schema.extend("$text",{allowAttributes:jw}),e.model.schema.setAttributeProperties(jw,{isFormatting:!0,copyOnEnter:!0}),e.conversion.attributeToElement({model:jw,view:"s",upcastAlso:["del","strike",{styles:{"text-decoration":"line-through"}}]}),e.commands.add(jw,new Tw(e,jw)),e.keystrokes.set("CTRL+SHIFT+X","strikethrough"),e.accessibility.addKeystrokeInfos({keystrokes:[{label:t("Strikethrough text"),keystroke:"CTRL+SHIFT+X"}]})}}const $w="strikethrough";class Hw extends fc{static get pluginName(){return"StrikethroughUI"}static get isOfficialPlugin(){return!0}init(){const e=this.editor,t=e.locale.t,o=Iw({editor:e,commandName:$w,plugin:this,icon:'',keystroke:"CTRL+SHIFT+X",label:t("Strikethrough")});e.ui.componentFactory.add($w,(()=>o(Lu))),e.ui.componentFactory.add("menuBar:"+$w,(()=>o(sh)))}}class Ww extends wc{refresh(){this.value=this._getValue(),this.isEnabled=this._checkEnabled()}execute(e={}){const t=this.editor.model,o=t.schema,i=t.document.selection,n=Array.from(i.getSelectedBlocks()),s=void 0===e.forceValue?!this.value:e.forceValue;t.change((e=>{if(s){const t=n.filter((e=>Uw(e)||Gw(o,e)));this._applyQuote(e,t)}else this._removeQuote(e,n.filter(Uw))}))}_getValue(){const e=to(this.editor.model.document.selection.getSelectedBlocks());return!(!e||!Uw(e))}_checkEnabled(){if(this.value)return!0;const e=this.editor.model.document.selection,t=this.editor.model.schema,o=to(e.getSelectedBlocks());return!!o&&Gw(t,o)}_removeQuote(e,t){Kw(e,t).reverse().forEach((t=>{if(t.start.isAtStart&&t.end.isAtEnd)return void e.unwrap(t.start.parent);if(t.start.isAtStart){const o=e.createPositionBefore(t.start.parent);return void e.move(t,o)}t.end.isAtEnd||e.split(t.end);const o=e.createPositionAfter(t.end.parent);e.move(t,o)}))}_applyQuote(e,t){const o=[];Kw(e,t).reverse().forEach((t=>{let i=Uw(t.start);i||(i=e.createElement("blockQuote"),e.wrap(t,i)),o.push(i)})),o.reverse().reduce(((t,o)=>t.nextSibling==o?(e.merge(e.createPositionAfter(t)),t):o))}}function Uw(e){return"blockQuote"==e.parent.name?e.parent:null}function Kw(e,t){let o,i=0;const n=[];for(;i{const i=e.model.document.differ.getChanges();for(const e of i)if("insert"==e.type){const i=e.position.nodeAfter;if(!i)continue;if(i.is("element","blockQuote")&&i.isEmpty)return o.remove(i),!0;if(i.is("element","blockQuote")&&!t.checkChild(e.position,i))return o.unwrap(i),!0;if(i.is("element")){const e=o.createRangeIn(i);for(const i of e.getItems())if(i.is("element","blockQuote")&&!t.checkChild(o.createPositionBefore(i),i))return o.unwrap(i),!0}}else if("remove"==e.type){const t=e.position.parent;if(t.is("element","blockQuote")&&t.isEmpty)return o.remove(t),!0}return!1}));const o=this.editor.editing.view.document,i=e.model.document.selection,n=e.commands.get("blockQuote");this.listenTo(o,"enter",((t,o)=>{if(!i.isCollapsed||!n.value)return;i.getLastPosition().parent.isEmpty&&(e.execute("blockQuote"),e.editing.view.scrollToTheSelection(),o.preventDefault(),t.stop())}),{context:"blockquote"}),this.listenTo(o,"delete",((t,o)=>{if("backward"!=o.direction||!i.isCollapsed||!n.value)return;const s=i.getLastPosition().parent;s.isEmpty&&!s.previousSibling&&(e.execute("blockQuote"),e.editing.view.scrollToTheSelection(),o.preventDefault(),t.stop())}),{context:"blockquote"})}}class Zw extends fc{static get pluginName(){return"BlockQuoteUI"}static get isOfficialPlugin(){return!0}init(){const e=this.editor;e.ui.componentFactory.add("blockQuote",(()=>{const e=this._createButton(Lu);return e.set({tooltip:!0}),e})),e.ui.componentFactory.add("menuBar:blockQuote",(()=>{const e=this._createButton(sh);return e.set({role:"menuitemcheckbox"}),e}))}_createButton(e){const t=this.editor,o=t.locale,i=t.commands.get("blockQuote"),n=new e(t.locale),s=o.t;return n.set({label:s("Block quote"),icon:'',isToggleable:!0}),n.bind("isEnabled").to(i,"isEnabled"),n.bind("isOn").to(i,"value"),this.listenTo(n,"execute",(()=>{t.execute("blockQuote"),t.editing.view.focus()})),n}}class Qw extends wc{constructor(e){super(e),this._isEnabledBasedOnSelection=!1}refresh(){const e=this.editor.model,t=to(e.document.selection.getSelectedBlocks());this.value=!!t&&t.is("element","paragraph"),this.isEnabled=!!t&&Yw(t,e.schema)}execute(e={}){const t=this.editor.model,o=t.document,i=e.selection||o.selection;t.canEditAt(i)&&t.change((e=>{const o=i.getSelectedBlocks();for(const i of o)!i.is("element","paragraph")&&Yw(i,t.schema)&&e.rename(i,"paragraph")}))}}function Yw(e,t){return t.checkChild(e.parent,"paragraph")&&!t.isObject(e)}class Xw extends wc{constructor(e){super(e),this._isEnabledBasedOnSelection=!1}execute(e){const t=this.editor.model,o=e.attributes;let i=e.position;return t.canEditAt(i)?t.change((e=>{if(i=this._findPositionToInsertParagraph(i,e),!i)return null;const n=e.createElement("paragraph");return o&&t.schema.setAllowedAttributes(n,o,e),t.insertContent(n,i),e.setSelection(n,"in"),e.createPositionAt(n,0)})):null}_findPositionToInsertParagraph(e,t){const o=this.editor.model;if(o.schema.checkChild(e,"paragraph"))return e;const i=o.schema.findAllowedParent(e,"paragraph");if(!i)return null;const n=e.parent,s=o.schema.checkChild(n,"$text");return n.isEmpty||s&&e.isAtEnd?o.createPositionAfter(n):!n.isEmpty&&s&&e.isAtStart?o.createPositionBefore(n):t.split(e,i).position}}class ey extends fc{static get pluginName(){return"Paragraph"}static get isOfficialPlugin(){return!0}init(){const e=this.editor,t=e.model;e.commands.add("paragraph",new Qw(e)),e.commands.add("insertParagraph",new Xw(e)),t.schema.register("paragraph",{inheritAllFrom:"$block"}),e.conversion.elementToElement({model:"paragraph",view:"p"}),e.conversion.for("upcast").elementToElement({model:(e,{writer:t})=>ey.paragraphLikeElements.has(e.name)?e.isEmpty?null:t.createElement("paragraph"):null,view:/.+/,converterPriority:"low"})}static paragraphLikeElements=new Set(["blockquote","dd","div","dt","h1","h2","h3","h4","h5","h6","li","p","td","th"])}class ty extends wc{modelElements;constructor(e,t){super(e),this.modelElements=t}refresh(){const e=to(this.editor.model.document.selection.getSelectedBlocks());this.value=!!e&&this.modelElements.includes(e.name)&&e.name,this.isEnabled=!!e&&this.modelElements.some((t=>oy(e,t,this.editor.model.schema)))}execute(e){const t=this.editor.model,o=t.document,i=e.value;t.change((e=>{const n=Array.from(o.selection.getSelectedBlocks()).filter((e=>oy(e,i,t.schema)));for(const t of n)t.is("element",i)||e.rename(t,i)}))}}function oy(e,t,o){return o.checkChild(e.parent,t)&&!o.isObject(e)}const iy="paragraph";class ny extends fc{static get pluginName(){return"HeadingEditing"}static get isOfficialPlugin(){return!0}constructor(e){super(e),e.config.define("heading",{options:[{model:"paragraph",title:"Paragraph",class:"ck-heading_paragraph"},{model:"heading1",view:"h2",title:"Heading 1",class:"ck-heading_heading1"},{model:"heading2",view:"h3",title:"Heading 2",class:"ck-heading_heading2"},{model:"heading3",view:"h4",title:"Heading 3",class:"ck-heading_heading3"}]})}static get requires(){return[ey]}init(){const e=this.editor,t=e.config.get("heading.options"),o=[];for(const i of t)"paragraph"!==i.model&&(e.model.schema.register(i.model,{inheritAllFrom:"$block"}),e.conversion.elementToElement(i),o.push(i.model));this._addDefaultH1Conversion(e),e.commands.add("heading",new ty(e,o))}afterInit(){const e=this.editor,t=e.commands.get("enter"),o=e.config.get("heading.options");t&&this.listenTo(t,"afterExecute",((t,i)=>{const n=e.model.document.selection.getFirstPosition().parent;o.some((e=>n.is("element",e.model)))&&!n.is("element",iy)&&0===n.childCount&&i.writer.rename(n,iy)}))}_addDefaultH1Conversion(e){e.conversion.for("upcast").elementToElement({model:"heading1",view:"h1",converterPriority:ge.low+1})}}function sy(e){const t=e.t,o={Paragraph:t("Paragraph"),"Heading 1":t("Heading 1"),"Heading 2":t("Heading 2"),"Heading 3":t("Heading 3"),"Heading 4":t("Heading 4"),"Heading 5":t("Heading 5"),"Heading 6":t("Heading 6")};return e.config.get("heading.options").map((e=>{const t=o[e.title];return t&&t!=e.title&&(e.title=t),e}))}class ry extends fc{static get pluginName(){return"HeadingUI"}static get isOfficialPlugin(){return!0}init(){const e=this.editor,t=e.t,o=sy(e),i=t("Choose heading"),n=t("Heading");e.ui.componentFactory.add("heading",(t=>{const s={},r=new eo,a=e.commands.get("heading"),l=e.commands.get("paragraph"),c=[a];for(const e of o){const t={type:"button",model:new Jm({label:e.title,class:e.class,role:"menuitemradio",withText:!0})};"paragraph"===e.model?(t.model.bind("isOn").to(l,"value"),t.model.set("commandName","paragraph"),c.push(l)):(t.model.bind("isOn").to(a,"value",(t=>t===e.model)),t.model.set({commandName:"heading",commandValue:e.model})),r.add(t),s[e.model]=e.title}const d=Zh(t);return Xh(d,r,{ariaLabel:n,role:"menu"}),d.buttonView.set({ariaLabel:n,ariaLabelledBy:void 0,isOn:!1,withText:!0,tooltip:n}),d.extendTemplate({attributes:{class:["ck-heading-dropdown"]}}),d.bind("isEnabled").toMany(c,"isEnabled",((...e)=>e.some((e=>e)))),d.buttonView.bind("label").to(a,"value",l,"value",((e,t)=>{const o=t?"paragraph":e;return"boolean"==typeof o?i:s[o]?s[o]:i})),d.buttonView.bind("ariaLabel").to(a,"value",l,"value",((e,t)=>{const o=t?"paragraph":e;return"boolean"==typeof o?n:s[o]?`${s[o]}, ${n}`:n})),this.listenTo(d,"execute",(t=>{const{commandName:o,commandValue:i}=t.source;e.execute(o,i?{value:i}:void 0),e.editing.view.focus()})),d})),e.ui.componentFactory.add("menuBar:heading",(i=>{const n=new og(i),s=e.commands.get("heading"),r=e.commands.get("paragraph"),a=[s],l=new ig(i);n.set({class:"ck-heading-dropdown"}),l.set({ariaLabel:t("Heading"),role:"menu"}),n.buttonView.set({label:t("Heading")}),n.panelView.children.add(l);for(const t of o){const o=new Em(i,n),c=new sh(i);o.children.add(c),l.items.add(o),c.set({isToggleable:!0,label:t.title,role:"menuitemradio",class:t.class}),c.delegate("execute").to(n),c.on("execute",(()=>{const o="paragraph"===t.model?"paragraph":"heading";e.execute(o,{value:t.model}),e.editing.view.focus()})),"paragraph"===t.model?(c.bind("isOn").to(r,"value"),a.push(r)):c.bind("isOn").to(s,"value",(e=>e===t.model))}return n.bind("isEnabled").toMany(a,"isEnabled",((...e)=>e.some((e=>e)))),n}))}}new Set(["paragraph","heading1","heading2","heading3","heading4","heading5","heading6"]);class ay{_definitions=new Set;_conflictChecker;get length(){return this._definitions.size}setConflictChecker(e){this._conflictChecker=e}add(e){Array.isArray(e)?e.forEach((e=>this._definitions.add(e))):this._definitions.add(e)}getDispatcher(){return e=>{const t=(e,t)=>{const o=t.createAttributeElement("a",e.attributes,{priority:5});e.classes&&t.addClass(e.classes,o);for(const i in e.styles)t.setStyle(i,e.styles[i],o);return t.setCustomProperty("link",!0,o),o},o=e=>(o,i,n)=>{if(i.attributeKey.startsWith("link")&&("linkHref"!=i.attributeKey||n.consumable.test(i.item,"attribute:linkHref"))&&(i.item.is("selection")||n.schema.isInline(i.item)))for(const o of this._definitions)o.callback(i.item.getAttribute("linkHref"))&&!this._conflictChecker?.(o,i.item)&&e?i.item.is("selection")?n.writer.wrap(n.writer.document.selection.getFirstRange(),t(o,n.writer)):n.writer.wrap(n.mapper.toViewRange(i.range),t(o,n.writer)):n.writer.unwrap(n.mapper.toViewRange(i.range),t(o,n.writer))};e.on("attribute",o(!1),{priority:ge.high-1}),e.on("attribute",o(!0),{priority:ge.high-2})}}getDispatcherForLinkedImage(){return e=>{const t=e=>(t,o,{writer:i,mapper:n})=>{if(!o.item.is("element","imageBlock")||!o.attributeKey.startsWith("link"))return;const s=n.toViewElement(o.item),r=Array.from(s.getChildren()).find((e=>e.is("element","a")));if(r)for(const t of this._definitions){const n=ao(t.attributes);if(t.callback(o.item.getAttribute("linkHref"))&&!this._conflictChecker?.(t,o.item)&&e){for(const[e,t]of n)"class"===e?i.addClass(t,r):i.setAttribute(e,t,!1,r);t.classes&&i.addClass(t.classes,r);for(const e in t.styles)i.setStyle(e,t.styles[e],r)}else{for(const[e,t]of n)"class"===e?i.removeClass(t,r):i.removeAttribute(e,t,r);t.classes&&i.removeClass(t.classes,r);for(const e in t.styles)i.removeStyle(e,r)}}};e.on("attribute",t(!1),{priority:ge.high-1}),e.on("attribute",t(!0),{priority:ge.high-2})}}}const ly=/[\u0000-\u0020\u00A0\u1680\u180E\u2000-\u2029\u205f\u3000]/g,cy=/^[\S]+@((?![-_])(?:[-\w\u00a1-\uffff]{0,63}[^-_]\.))+(?:[a-z\u00a1-\uffff]{2,})$/i,dy=/^((\w+:(\/{2,})?)|(\W))/i,uy=["https?","ftps?","mailto"],hy="Ctrl+K";function my(e,{writer:t}){const o=t.createAttributeElement("a",{href:e},{priority:5});return t.setCustomProperty("link",!0,o),o}function gy(e,t=uy){const o=String(e),i=t.join("|");return function(e,t){const o=e.replace(ly,"");return!!o.match(t)}(o,new RegExp(`${"^(?:(?:):|[^a-z]|[a-z+.-]+(?:[^a-z+.:-]|$))".replace("",i)}`,"i"))?o:"#"}function py(e,t){return!!e&&t.checkAttribute(e.name,"linkHref")}function fy(e,t){const o=(i=e,cy.test(i)?"mailto:":t);var i;const n=!!o&&!by(e);return e&&n?o+e:e}function by(e){return dy.test(e)}function wy(e){let t="";for(const o of e.getItems()){if(!o.is("$text")&&!o.is("$textProxy"))return;t+=o.data}return t}function yy(e,t){if(e.attributes&&t.attributes){if(Object.keys(e.attributes).some((e=>!function(e){return"class"===e||"style"===e||"rel"===e}(e)&&e in t.attributes)))return!0}if(e.styles&&t.styles){if(Object.keys(e.styles).some((e=>e in t.styles)))return!0}return!1}function _y(e,t){const o=t.find((t=>t.id===e));return o?t.filter((t=>t.id!==e&&yy(o,t))).map((e=>e.id)):[]}class ky extends wc{manualDecorators=new eo;automaticDecorators=new ay;restoreManualDecoratorStates(){for(const e of this.manualDecorators)e.value=this._getDecoratorStateFromModel(e.id)}refresh(){const e=this.editor.model,t=e.document.selection,o=t.getSelectedElement()||to(t.getSelectedBlocks());py(o,e.schema)?(this.value=o.getAttribute("linkHref"),this.isEnabled=e.schema.checkAttribute(o,"linkHref")):(this.value=t.getAttribute("linkHref"),this.isEnabled=e.schema.checkAttributeInSelection(t,"linkHref"));for(const e of this.manualDecorators)e.value=this._getDecoratorStateFromModel(e.id)}execute(e,t={},o){const i=this.editor.model,n=i.document.selection,s=function({decoratorStates:e,allDecorators:t}){const o={...e};for(const n in e)if(e[n]&&i(n)){const e=_y(n,t);for(const t of e)o[t]=!1}function i(e){return t.some((t=>t.id===e&&!t.value))}return o}({allDecorators:Array.from(this.manualDecorators),decoratorStates:t}),r=[],a=[];for(const e in s)s[e]?r.push(e):a.push(e);i.change((t=>{const s=o=>{t.setAttribute("linkHref",e,o),r.forEach((e=>t.setAttribute(e,!0,o))),a.forEach((e=>t.removeAttribute(e,o)))},l=(n,r)=>{const a=wy(n);if(!a)return n;let l=o;if(l||(l=r&&r==a?e:a),l!=a){const e=t.createDocumentFragment();for(const o of n.getItems()){const i=o;t.append(t.createText(i.data,i.getAttributes()),e)}const o=t.createRangeIn(e),r=function(e,t){const o=de(e,t),i={equal:0,insert:0,delete:0},n=[];let s="",r="";for(const a of[...o,null])"insert"==a?r+=t[i.equal+i.insert]:"delete"==a?s+=e[i.equal+i.delete]:(s.length||r.length)&&(n.push({offset:i.equal,actual:s,expected:r}),s="",r=""),a&&i[a]++;return n}(a,l);let c=0;for(const{offset:e,actual:n,expected:a}of r){const r=e+c,l=t.createRange(o.start.getShiftedBy(r),o.start.getShiftedBy(r+n.length)),d=vy(l,o).getAttributes(),u=Array.from(d).filter((([e])=>i.schema.getAttributeProperties(e).isFormatting)),h=t.createText(a,u);s(h),t.remove(l),t.insert(h,l.start),c+=a.length}return i.insertContent(e,n),t.createRange(n.start,n.start.getShiftedBy(l.length))}},c=e=>{const{plugins:o}=this.editor;if(t.setSelection(e.end),o.has("TwoStepCaretMovement"))o.get("TwoStepCaretMovement")._handleForwardMovement();else for(const e of["linkHref",...r,...a])t.removeSelectionAttribute(e)};if(n.isCollapsed){const a=n.getFirstPosition();if(n.hasAttribute("linkHref")){const e=n.getAttribute("linkHref"),t=Lg(a,"linkHref",e,i),o=l(t,e);s(o||t),o&&c(o)}else if(""!==e){const s=ao(n.getAttributes());s.set("linkHref",e),r.forEach((e=>{s.set(e,!0)}));c(i.insertContent(t.createText(o||e,s),a))}}else{const e=Array.from(n.getRanges()),o=i.schema.getValidRanges(e,"linkHref"),r=[];for(const e of n.getSelectedBlocks())i.schema.checkAttribute(e,"linkHref")&&r.push(t.createRangeOn(e));const a=r.slice();for(const e of o)this._isRangeToUpdate(e,r)&&a.push(e);const c=e.map((e=>({start:ma.fromPosition(e.start,"toPrevious"),end:ma.fromPosition(e.end,"toNext")})));for(let e of a){e=l(e,(e.start.textNode||e.start.nodeAfter).getAttribute("linkHref"))||e,s(e)}t.setSelection(c.map((e=>{const t=e.start.toPosition(),o=e.end.toPosition();return e.start.detach(),e.end.detach(),i.createRange(t,o)})))}})),this.restoreManualDecoratorStates()}_getDecoratorStateFromModel(e){const t=this.editor.model,o=t.document.selection,i=o.getSelectedElement();return py(i,t.schema)?i.getAttribute(e):o.getAttribute(e)}_isRangeToUpdate(e,t){for(const o of t)if(o.containsRange(e))return!1;return!0}}function vy(e,t){if(!e.isCollapsed)return to(e.getItems());const o=e.start;return o.textNode?o.textNode:!o.nodeBefore||o.isEqual(t.start)?o.nodeAfter:o.nodeBefore}class Cy extends wc{refresh(){const e=this.editor.model,t=e.document.selection,o=t.getSelectedElement();py(o,e.schema)?this.isEnabled=e.schema.checkAttribute(o,"linkHref"):this.isEnabled=e.schema.checkAttributeInSelection(t,"linkHref")}execute(){const e=this.editor,t=this.editor.model,o=t.document.selection,i=e.commands.get("link");t.change((e=>{const n=o.isCollapsed?[Lg(o.getFirstPosition(),"linkHref",o.getAttribute("linkHref"),t)]:t.schema.getValidRanges(o.getRanges(),"linkHref");for(const t of n)if(e.removeAttribute("linkHref",t),i)for(const o of i.manualDecorators)e.removeAttribute(o.id,t)}))}}class Ay extends(Be()){id;defaultValue;label;attributes;classes;styles;constructor({id:e,label:t,attributes:o,classes:i,styles:n,defaultValue:s}){super(),this.id=e,this.set("value",void 0),this.defaultValue=s,this.label=t,this.attributes=o,this.classes=i,this.styles=n}_createPattern(){return{attributes:this.attributes,classes:this.classes,styles:this.styles}}}const xy="automatic",Ey=/^(https?:)?\/\//;class Ty extends fc{_linkOpeners=[];static get pluginName(){return"LinkEditing"}static get isOfficialPlugin(){return!0}static get requires(){return[Rg,fg,bf]}constructor(e){super(e),e.config.define("link",{allowCreatingEmptyLinks:!1,addTargetToExternalLinks:!1,toolbar:["linkPreview","|","editLink","linkProperties","unlink"]})}init(){const e=this.editor,t=this.editor.config.get("link.allowedProtocols");e.model.schema.extend("$text",{allowAttributes:"linkHref"}),e.conversion.for("dataDowncast").attributeToElement({model:"linkHref",view:my}),e.conversion.for("editingDowncast").attributeToElement({model:"linkHref",view:(e,o)=>my(gy(e,t),o)}),e.conversion.for("upcast").elementToAttribute({view:{name:"a",attributes:{href:!0}},model:{key:"linkHref",value:e=>e.getAttribute("href")}}),e.commands.add("link",new ky(e)),e.commands.add("unlink",new Cy(e));const o=function(e,t){const o={"Open in a new tab":e("Open in a new tab"),Downloadable:e("Downloadable")};return t.forEach((e=>("label"in e&&o[e.label]&&(e.label=o[e.label]),e))),t}(e.t,function(e){const t=[];if(e)for(const[i,n]of Object.entries(e)){const e=Object.assign({},n,{id:`link${o=i,function(e){return e.substring(0,1).toUpperCase()+e.substring(1)}(_o(o))}`});t.push(e)}var o;return t}(e.config.get("link.decorators")));this._enableAutomaticDecorators(o.filter((e=>e.mode===xy))),this._enableManualDecorators(o.filter((e=>"manual"===e.mode)));e.plugins.get(Rg).registerAttribute("linkHref"),jg(e,"linkHref","a","ck-link_selected"),this._enableLinkOpen(),this._enableSelectionAttributesFixer(),this._enableClipboardIntegration(),this._enableDecoratorConflictPostfixer()}_registerLinkOpener(e){this._linkOpeners.push(e)}_enableAutomaticDecorators(e){const t=this.editor,o=t.commands.get("link"),i=o.automaticDecorators;t.config.get("link.addTargetToExternalLinks")&&i.add({id:"linkIsExternal",mode:xy,callback:e=>!!e&&Ey.test(e),attributes:{target:"_blank",rel:"noopener noreferrer"}}),i.add(e),i.setConflictChecker(((e,t)=>{for(const i of o.manualDecorators)if(t.hasAttribute(i.id)&&yy(e,i))return!0})),i.length&&t.conversion.for("downcast").add(i.getDispatcher())}_enableManualDecorators(e){if(!e.length)return;const t=this.editor,o=t.commands.get("link").manualDecorators;e.forEach((e=>{t.model.schema.extend("$text",{allowAttributes:e.id});const i=new Ay(e);o.add(i),t.conversion.for("downcast").add((e=>{const t=e=>{const t=e.createAttributeElement("a",i.attributes,{priority:5});i.classes&&e.addClass(i.classes,t);for(const o in i.styles)e.setStyle(o,i.styles[o],t);return e.setCustomProperty("link",!0,t),t},o=e=>(o,i,n)=>{if(i.item.is("selection")||n.schema.isInline(i.item)){if(!e&&i.attributeOldValue){if(!n.consumable.test(i.item,o.name))return;n.writer.unwrap(n.mapper.toViewRange(i.range),t(n.writer))}if(e&&i.attributeNewValue){if(!n.consumable.consume(i.item,o.name))return;i.item.is("selection")?n.writer.wrap(n.writer.document.selection.getFirstRange(),t(n.writer)):n.writer.wrap(n.mapper.toViewRange(i.range),t(n.writer))}}};e.on(`attribute:${i.id}`,o(!1),{priority:ge.high-1}),e.on(`attribute:${i.id}`,o(!0),{priority:ge.high-2})})),t.conversion.for("upcast").elementToAttribute({view:{name:"a",...i._createPattern()},model:{key:i.id}})}))}_enableLinkOpen(){const e=this.editor,t=e.editing.view.document,o=e=>{var t;this._linkOpeners.some((t=>t(e)))||(t=e,window.open(t,"_blank","noopener"))};this.listenTo(t,"click",((e,t)=>{if(!(Y.isMac?t.domEvent.metaKey:t.domEvent.ctrlKey))return;let i=t.domTarget;if("a"!=i.tagName.toLowerCase()&&(i=i.closest("a")),!i)return;const n=i.getAttribute("href");n&&(e.stop(),t.preventDefault(),o(n))}),{context:"$capture"}),this.listenTo(t,"keydown",((t,i)=>{const n=e.commands.get("link").value;!!n&&i.keyCode===qt.enter&&i.altKey&&(t.stop(),o(n))}))}_enableSelectionAttributesFixer(){const e=this.editor.model,t=e.document.selection;this.listenTo(t,"change:attribute",((o,{attributeKeys:i})=>{i.includes("linkHref")&&!t.hasAttribute("linkHref")&&e.change((t=>{var o;!function(e,t){e.removeSelectionAttribute("linkHref");for(const o of t)e.removeSelectionAttribute(o)}(t,(o=e.schema,o.getDefinition("$text").allowAttributes.filter((e=>e.startsWith("link")))))}))}))}_enableClipboardIntegration(){const e=this.editor,t=e.model,o=this.editor.config.get("link.defaultProtocol");o&&this.listenTo(e.plugins.get("ClipboardPipeline"),"contentInsertion",((e,i)=>{t.change((e=>{const t=e.createRangeIn(i.content);for(const i of t.getItems())if(i.hasAttribute("linkHref")){const t=fy(i.getAttribute("linkHref"),o);e.setAttribute("linkHref",t,i)}}))}))}_enableDecoratorConflictPostfixer(){const e=this.editor,t=e.model,o=e.commands.get("link");t.document.registerPostFixer((e=>{let i=!1;const n=t.document.differ.getChanges(),s=new Set,r=new Set(o.manualDecorators.map((e=>e.id)));for(const e of n){if("attribute"===e.type){if("linkHref"!==e.attributeKey&&!r.has(e.attributeKey))continue;for(const t of e.range.getItems())t.hasAttribute("linkHref")&&s.add(t)}"insert"===e.type&&e.attributes.has("linkHref")&&e.position.nodeAfter&&s.add(e.position.nodeAfter)}for(const t of s){const n=[];for(const s of o.manualDecorators)if(t.hasAttribute(s.id)){for(let o=n.length-1;o>=0;o--){const r=n[o];yy(r,s)&&(e.removeAttribute(r.id,t),n.splice(o,1),i=!0)}n.push(s)}}return i}))}}class Py extends Lu{constructor(e){super(e);const t=this.bindTemplate;this.set({href:void 0,withText:!0}),this.extendTemplate({attributes:{class:["ck-link-toolbar__preview"],href:t.to("href"),target:"_blank",rel:"noopener noreferrer"},on:{click:t.to((e=>{if(this.href){const t=()=>e.preventDefault();this.fire("navigate",this.href,t)}}))}}),this.template.tag="a"}}class Sy extends Au{focusTracker=new oo;keystrokes=new ro;backButtonView;saveButtonView;displayedTextInputView;urlInputView;children;providersListChildren;_validators;_focusables=new tu;_focusCycler;constructor(e,t){super(e),this._validators=t,this.backButtonView=this._createBackButton(),this.saveButtonView=this._createSaveButton(),this.displayedTextInputView=this._createDisplayedTextInput(),this.urlInputView=this._createUrlInput(),this.providersListChildren=this.createCollection(),this.children=this.createCollection([this._createHeaderView()]),this._createFormChildren(),this.listenTo(this.providersListChildren,"add",(()=>{this.stopListening(this.providersListChildren,"add"),this.children.add(this._createProvidersListView())})),this._focusCycler=new qu({focusables:this._focusables,focusTracker:this.focusTracker,keystrokeHandler:this.keystrokes,actions:{focusPrevious:"shift + tab",focusNext:"tab"}}),this.setTemplate({tag:"form",attributes:{class:["ck","ck-form","ck-link-form","ck-responsive-form"],tabindex:"-1"},children:this.children})}render(){super.render(),Ou({view:this});[this.urlInputView,this.saveButtonView,...this.providersListChildren,this.backButtonView,this.displayedTextInputView].forEach((e=>{this._focusables.add(e),this.focusTracker.add(e.element)})),this.keystrokes.listenTo(this.element)}destroy(){super.destroy(),this.focusTracker.destroy(),this.keystrokes.destroy()}focus(){this._focusCycler.focusFirst()}isValid(){this.resetFormStatus();for(const e of this._validators){const t=e(this);if(t)return this.urlInputView.errorText=t,!1}return!0}resetFormStatus(){this.urlInputView.errorText=null}_createBackButton(){const e=this.locale.t,t=new Lu(this.locale);return t.set({class:"ck-button-back",label:e("Back"),icon:ed,tooltip:!0}),t.delegate("execute").to(this,"cancel"),t}_createSaveButton(){const e=this.locale.t,t=new Lu(this.locale);return t.set({label:e("Insert"),tooltip:!1,withText:!0,type:"submit",class:"ck-button-action ck-button-bold"}),t}_createHeaderView(){const e=this.locale.t,t=new ju(this.locale,{label:e("Link")});return t.children.add(this.backButtonView,0),t}_createProvidersListView(){const e=new zh(this.locale);return e.extendTemplate({attributes:{class:["ck-link-form__providers-list"]}}),e.items.bindTo(this.providersListChildren).using((e=>{const t=new Nh(this.locale);return t.children.add(e),t})),e}_createDisplayedTextInput(){const e=this.locale.t,t=new Sh(this.locale,nm);return t.label=e("Displayed text"),t.class="ck-labeled-field-view_full-width",t}_createUrlInput(){const e=this.locale.t,t=new Sh(this.locale,nm);return t.fieldView.inputMode="url",t.label=e("Link URL"),t.class="ck-labeled-field-view_full-width",t}_createFormChildren(){this.children.add(new Km(this.locale,{children:[this.displayedTextInputView],class:["ck-form__row_large-top-padding"]})),this.children.add(new Km(this.locale,{children:[this.urlInputView,this.saveButtonView],class:["ck-form__row_with-submit","ck-form__row_large-top-padding","ck-form__row_large-bottom-padding"]}))}get url(){const{element:e}=this.urlInputView.fieldView;return e?e.value.trim():null}}class Iy extends Au{focusTracker=new oo;keystrokes=new ro;backButtonView;listView;listChildren;emptyListInformation;children;_focusables=new tu;_focusCycler;constructor(e){super(e),this.listChildren=this.createCollection(),this.backButtonView=this._createBackButton(),this.listView=this._createListView(),this.emptyListInformation=this._createEmptyLinksListItemView(),this.children=this.createCollection([this._createHeaderView(),this.emptyListInformation]),this.set("title",""),this.set("emptyListPlaceholder",""),this.set("hasItems",!1),this.listenTo(this.listChildren,"change",(()=>{this.hasItems=this.listChildren.length>0})),this.on("change:hasItems",((e,t,o)=>{o?(this.children.remove(this.emptyListInformation),this.children.add(this.listView)):(this.children.remove(this.listView),this.children.add(this.emptyListInformation))})),this.keystrokes.set("Esc",((e,t)=>{this.fire("cancel"),t()})),this._focusCycler=new qu({focusables:this._focusables,focusTracker:this.focusTracker,keystrokeHandler:this.keystrokes,actions:{focusPrevious:"shift + tab",focusNext:"tab"}}),this.setTemplate({tag:"div",attributes:{class:["ck","ck-link-providers"],tabindex:"-1"},children:this.children})}render(){super.render();[this.listView,this.backButtonView].forEach((e=>{this._focusables.add(e),this.focusTracker.add(e.element)})),this.keystrokes.listenTo(this.element)}destroy(){super.destroy(),this.focusTracker.destroy(),this.keystrokes.destroy()}focus(){this._focusCycler.focusFirst()}_createListView(){const e=new zh(this.locale);return e.extendTemplate({attributes:{class:["ck-link-providers__list"]}}),e.items.bindTo(this.listChildren).using((e=>{const t=new Nh(this.locale);return t.children.add(e),t})),e}_createBackButton(){const e=this.locale.t,t=new Lu(this.locale);return t.set({class:"ck-button-back",label:e("Back"),icon:ed,tooltip:!0}),t.delegate("execute").to(this,"cancel"),t}_createHeaderView(){const e=new ju(this.locale);return e.bind("label").to(this,"title"),e.children.add(this.backButtonView,0),e}_createEmptyLinksListItemView(){const e=new Au(this.locale);return e.setTemplate({tag:"p",attributes:{class:["ck","ck-link__empty-list-info"]},children:[{text:this.bindTemplate.to("emptyListPlaceholder")}]}),e}}class Ry extends Au{focusTracker=new oo;keystrokes=new ro;backButtonView;children;listChildren;_focusables=new tu;_focusCycler;constructor(e){super(e),this.backButtonView=this._createBackButton(),this.listChildren=this.createCollection(),this.children=this.createCollection([this._createHeaderView(),this._createListView()]),this._focusCycler=new qu({focusables:this._focusables,focusTracker:this.focusTracker,keystrokeHandler:this.keystrokes,actions:{focusPrevious:"shift + tab",focusNext:"tab"}}),this.setTemplate({tag:"div",attributes:{class:["ck","ck-link-properties"],tabindex:"-1"},children:this.children}),this.keystrokes.set("Esc",((e,t)=>{this.fire("back"),t()}))}render(){super.render();[...this.listChildren,this.backButtonView].forEach((e=>{this._focusables.add(e),this.focusTracker.add(e.element)})),this.keystrokes.listenTo(this.element)}destroy(){super.destroy(),this.focusTracker.destroy(),this.keystrokes.destroy()}focus(){this._focusCycler.focusFirst()}_createBackButton(){const e=this.locale.t,t=new Lu(this.locale);return t.set({class:"ck-button-back",label:e("Back"),icon:ed,tooltip:!0}),t.delegate("execute").to(this,"back"),t}_createHeaderView(){const e=this.locale.t,t=new ju(this.locale,{label:e("Link properties")});return t.children.add(this.backButtonView,0),t}_createListView(){const e=new zh(this.locale);return e.extendTemplate({attributes:{class:["ck-link__list"]}}),e.items.bindTo(this.listChildren).using((e=>{const t=new Nh(this.locale);return t.children.add(e),t})),e}}class Oy extends Lu{arrowView;constructor(e){super(e),this.set({withText:!0}),this.arrowView=this._createArrowView(),this.extendTemplate({attributes:{class:["ck-link__button"]}})}render(){super.render(),this.children.add(this.arrowView)}_createArrowView(){const e=new Nu;return e.content=Kc,e}}const Vy="link-ui";class Dy extends fc{toolbarView=null;formView=null;linkProviderItemsView=null;propertiesView=null;_balloon;_linksProviders=new eo;static get requires(){return[Qm,Ty]}static get pluginName(){return"LinkUI"}static get isOfficialPlugin(){return!0}init(){const e=this.editor,t=this.editor.t;this.set("selectedLinkableText",void 0),e.editing.view.addObserver(ol),this._balloon=e.plugins.get(Qm),this._registerComponents(),this._registerEditingOpeners(),this._enableBalloonActivators(),e.conversion.for("editingDowncast").markerToHighlight({model:Vy,view:{classes:["ck-fake-link-selection"]}}),e.conversion.for("editingDowncast").markerToElement({model:Vy,view:(e,{writer:t})=>{if(!e.markerRange.isCollapsed)return null;const o=t.createUIElement("span");return t.addClass(["ck-fake-link-selection","ck-fake-link-selection_collapsed"],o),o}}),e.accessibility.addKeystrokeInfos({keystrokes:[{label:t("Create link"),keystroke:hy},{label:t("Move out of a link"),keystroke:[["arrowleft","arrowleft"],["arrowright","arrowright"]]}]})}destroy(){super.destroy(),this.propertiesView&&this.propertiesView.destroy(),this.formView&&this.formView.destroy(),this.toolbarView&&this.toolbarView.destroy(),this.linkProviderItemsView&&this.linkProviderItemsView.destroy()}registerLinksListProvider(e){const t=this._linksProviders.filter((t=>(t.order||0)<=(e.order||0))).length;this._linksProviders.add(e,t)}_createViews(){const e=this.editor.commands.get("link");this.toolbarView=this._createToolbarView(),this.formView=this._createFormView(),e.manualDecorators.length&&(this.propertiesView=this._createPropertiesView()),this._enableUserBalloonInteractions()}_createToolbarView(){const e=this.editor,t=new Wh(e.locale),o=e.commands.get("link");t.class="ck-link-toolbar";let i=e.config.get("link.toolbar");return o.manualDecorators.length||(i=i.filter((e=>"linkProperties"!==e))),t.fillFromConfig(i,e.ui.componentFactory),t.keystrokes.set("Esc",((e,t)=>{this._hideUI(),t()})),t.keystrokes.set(hy,((e,t)=>{this._addFormView(),t()})),e.ui.addToolbar(t,{isContextual:!0,beforeFocus:()=>{this._getSelectedLinkElement()&&!this._isToolbarVisible&&this._showUI(!0)},afterBlur:()=>{this._hideUI(!1)}}),t}_createFormView(){const e=this.editor,t=e.locale.t,o=e.commands.get("link"),i=e.config.get("link.defaultProtocol"),n=new(Iu(Sy))(e.locale,function(e){const t=e.t,o=e.config.get("link.allowCreatingEmptyLinks");return[e=>{if(!o&&!e.url.length)return t("Link URL must not be empty.")}]}(e));return n.displayedTextInputView.bind("isEnabled").to(this,"selectedLinkableText",(e=>void 0!==e)),n.urlInputView.bind("isEnabled").to(o,"isEnabled"),n.saveButtonView.bind("isEnabled").to(o,"isEnabled"),n.saveButtonView.bind("label").to(o,"value",(e=>t(e?"Update":"Insert"))),this.listenTo(n,"submit",(()=>{if(n.isValid()){const t=fy(n.urlInputView.fieldView.element.value,i),o=n.displayedTextInputView.fieldView.element.value;e.execute("link",t,this._getDecoratorSwitchesState(),o!==this.selectedLinkableText?o:void 0),this._closeFormView()}})),this.listenTo(n.urlInputView,"change:errorText",(()=>{e.ui.update()})),this.listenTo(n,"cancel",(()=>{this._closeFormView()})),n.keystrokes.set("Esc",((e,t)=>{this._closeFormView(),t()})),n.providersListChildren.bindTo(this._linksProviders).using((e=>this._createLinksListProviderButton(e))),n}_createLinkProviderListView(e){return e.getListItems().map((({href:e,label:t,icon:o})=>{const i=new Lu;return i.set({label:t,icon:o,tooltip:!1,withText:!0}),i.on("execute",(()=>{this.formView.resetFormStatus(),this.formView.urlInputView.fieldView.value=e,this.editor.editing.view.focus(),this._removeLinksProviderView(),this.formView.focus()})),i}))}_createLinkProviderItemsView(e){const t=this.editor,o=t.locale.t,i=new Iy(t.locale),{emptyListPlaceholder:n,label:s}=e;return i.emptyListPlaceholder=n||o("No links available"),i.title=s,this.listenTo(i,"cancel",(()=>{t.editing.view.focus(),this._removeLinksProviderView(),this.formView.focus()})),i}_createPropertiesView(){const e=this.editor,t=this.editor.commands.get("link"),o=new(Iu(Ry))(e.locale);return this.listenTo(o,"back",(()=>{e.editing.view.focus(),this._removePropertiesView()})),o.listChildren.bindTo(t.manualDecorators).using((o=>{const i=new fh(e.locale);return i.set({label:o.label,withText:!0}),i.bind("isOn").toMany([o,t],"value",((e,t)=>void 0===t&&void 0===e?!!o.defaultValue:!!e)),i.on("execute",(()=>{e.execute("link",t.value,{...this._getDecoratorSwitchesState(),[o.id]:!i.isOn})})),i})),o}_getDecoratorSwitchesState(){const e=this.editor.commands.get("link");return Array.from(e.manualDecorators).reduce(((t,o)=>{const i=void 0===e.value&&void 0===o.value?o.defaultValue:o.value;return{...t,[o.id]:!!i}}),{})}_registerEditingOpeners(){this.editor.plugins.get(Ty)._registerLinkOpener((e=>{const t=this._getLinkProviderLinkByHref(e);if(!t)return!1;const{item:o,provider:i}=t;return!!i.navigate&&i.navigate(o)}))}_registerComponents(){const e=this.editor;e.ui.componentFactory.add("link",(()=>{const e=this._createButton(Lu);return e.set({tooltip:!0}),e})),e.ui.componentFactory.add("menuBar:link",(()=>{const e=this._createButton(sh);return e.set({role:"menuitemcheckbox"}),e})),e.ui.componentFactory.add("linkPreview",(t=>{const o=new Py(t),i=e.config.get("link.allowedProtocols"),n=e.commands.get("link"),s=t.t;o.bind("isEnabled").to(n,"value",(e=>!!e)),o.bind("href").to(n,"value",(e=>e&&gy(e,i)));const r=e=>{if(!e)return o.label=void 0,o.icon=void 0,void(o.tooltip=s("Open link in new tab"));const t=this._getLinkProviderLinkByHref(e);if(t){const{label:e,tooltip:i,icon:n}=t.item;o.label=e,o.tooltip=i||!1,o.icon=n}else o.label=e,o.icon=void 0,o.tooltip=s("Open link in new tab")};return r(n.value),this.listenTo(n,"change:value",((e,t,o)=>{r(o)})),this.listenTo(o,"navigate",((e,t,o)=>{const i=this._getLinkProviderLinkByHref(t);if(!i)return;const{provider:n,item:s}=i,{navigate:r}=n;r&&r(s)&&(e.stop(),o())})),o})),e.ui.componentFactory.add("unlink",(t=>{const o=e.commands.get("unlink"),i=new Lu(t),n=t.t;return i.set({label:n("Unlink"),icon:'',tooltip:!0}),i.bind("isEnabled").to(o),this.listenTo(i,"execute",(()=>{e.execute("unlink"),this._hideUI()})),i})),e.ui.componentFactory.add("editLink",(t=>{const o=e.commands.get("link"),i=new Lu(t),n=t.t;return i.set({label:n("Edit link"),icon:'',tooltip:!0}),i.bind("isEnabled").to(o),this.listenTo(i,"execute",(()=>{this._addFormView()})),i})),e.ui.componentFactory.add("linkProperties",(t=>{const o=e.commands.get("link"),i=new Lu(t),n=t.t;return i.set({label:n("Link properties"),icon:'\n',tooltip:!0}),i.bind("isEnabled").to(o,"isEnabled",o,"value",o,"manualDecorators",((e,t,o)=>e&&!!t&&o.length>0)),this.listenTo(i,"execute",(()=>{this._addPropertiesView()})),i}))}_createLinksListProviderButton(e){const t=this.editor.locale,o=new Oy(t);return o.set({label:e.label}),this.listenTo(o,"execute",(()=>{this._showLinksProviderView(e)})),o}_createButton(e){const t=this.editor,o=t.locale,i=t.commands.get("link"),n=new e(t.locale),s=o.t;return n.set({label:s("Link"),icon:'',keystroke:hy,isToggleable:!0}),n.bind("isEnabled").to(i,"isEnabled"),n.bind("isOn").to(i,"value",(e=>!!e)),this.listenTo(n,"execute",(()=>{t.editing.view.scrollToTheSelection(),this._showUI(!0),this._getSelectedLinkElement()&&this._addFormView()})),n}_enableBalloonActivators(){const e=this.editor,t=e.editing.view.document;this.listenTo(t,"click",(()=>{this._getSelectedLinkElement()&&this._showUI()})),e.keystrokes.set(hy,((t,o)=>{o(),e.commands.get("link").isEnabled&&(e.editing.view.scrollToTheSelection(),this._showUI(!0))}))}_enableUserBalloonInteractions(){this.editor.keystrokes.set("Tab",((e,t)=>{this._isToolbarVisible&&!this.toolbarView.focusTracker.isFocused&&(this.toolbarView.focus(),t())}),{priority:"high"}),this.editor.keystrokes.set("Esc",((e,t)=>{this._isUIVisible&&(this._hideUI(),t())})),Su({emitter:this.formView,activator:()=>this._isUIInPanel,contextElements:()=>[this._balloon.view.element],callback:()=>{this._hideUI(!1)}})}_addToolbarView(){this.toolbarView||this._createViews(),this._isToolbarInPanel||this._balloon.add({view:this.toolbarView,position:this._getBalloonPositionData(),balloonClassName:"ck-toolbar-container"})}_addFormView(){if(this.formView||this._createViews(),this._isFormInPanel)return;const e=this.editor.commands.get("link");this.formView.disableCssTransitions(),this.formView.resetFormStatus(),this.formView.backButtonView.isVisible=e.isEnabled&&!!e.value,this._balloon.add({view:this.formView,position:this._getBalloonPositionData()}),this.selectedLinkableText=this._getSelectedLinkableText(),this.formView.displayedTextInputView.fieldView.value=this.selectedLinkableText||"",this.formView.urlInputView.fieldView.value=e.value||"",this._balloon.visibleView===this.formView&&this.formView.urlInputView.fieldView.select(),this.formView.enableCssTransitions()}_addPropertiesView(){this.propertiesView||this._createViews(),this._arePropertiesInPanel||(this.propertiesView.disableCssTransitions(),this._balloon.add({view:this.propertiesView,position:this._getBalloonPositionData()}),this.propertiesView.enableCssTransitions(),this.propertiesView.focus())}_showLinksProviderView(e){this.linkProviderItemsView&&this._removeLinksProviderView(),this.linkProviderItemsView=this._createLinkProviderItemsView(e),this._addLinkProviderItemsView(e)}_addLinkProviderItemsView(e){this.linkProviderItemsView.listChildren.clear(),this.linkProviderItemsView.listChildren.addMany(this._createLinkProviderListView(e)),this._balloon.add({view:this.linkProviderItemsView,position:this._getBalloonPositionData()}),this.linkProviderItemsView.focus()}_closeFormView(){const e=this.editor.commands.get("link");this.selectedLinkableText=void 0,void 0!==e.value?this._removeFormView():this._hideUI()}_removePropertiesView(){this._arePropertiesInPanel&&this._balloon.remove(this.propertiesView)}_removeLinksProviderView(){this._isLinksListInPanel&&this._balloon.remove(this.linkProviderItemsView)}_removeFormView(e=!0){this._isFormInPanel&&(this.formView.saveButtonView.focus(),this.formView.displayedTextInputView.fieldView.reset(),this.formView.urlInputView.fieldView.reset(),this._balloon.remove(this.formView),e&&this.editor.editing.view.focus(),this._hideFakeVisualSelection())}_showUI(e=!1){this.formView||this._createViews(),this._getSelectedLinkElement()?(this._isToolbarVisible?this._addFormView():this._addToolbarView(),e&&this._balloon.showStack("main")):(this._showFakeVisualSelection(),this._addToolbarView(),e&&this._balloon.showStack("main"),this._addFormView()),this._startUpdatingUI()}_hideUI(e=!0){const t=this.editor;this._isUIInPanel&&(this.stopListening(t.ui,"update"),this.stopListening(this._balloon,"change:visibleView"),e&&t.editing.view.focus(),this._removeLinksProviderView(),this._removePropertiesView(),this._removeFormView(e),this._isToolbarInPanel&&this._balloon.remove(this.toolbarView),this._hideFakeVisualSelection())}_startUpdatingUI(){const e=this.editor,t=e.editing.view.document;let o=this._getSelectedLinkElement(),i=s();const n=()=>{const e=this._getSelectedLinkElement(),t=s();o&&!e||!o&&t!==i?this._hideUI():this._isUIVisible&&this._balloon.updatePosition(this._getBalloonPositionData()),o=e,i=t};function s(){return t.selection.focus.getAncestors().reverse().find((e=>e.is("element")))}this.listenTo(e.ui,"update",n),this.listenTo(this._balloon,"change:visibleView",n)}get _arePropertiesInPanel(){return!!this.propertiesView&&this._balloon.hasView(this.propertiesView)}get _isLinksListInPanel(){return!!this.linkProviderItemsView&&this._balloon.hasView(this.linkProviderItemsView)}get _isFormInPanel(){return!!this.formView&&this._balloon.hasView(this.formView)}get _isToolbarInPanel(){return!!this.toolbarView&&this._balloon.hasView(this.toolbarView)}get _isPropertiesVisible(){return!!this.propertiesView&&this._balloon.visibleView===this.propertiesView}get _isFormVisible(){return!!this.formView&&this._balloon.visibleView==this.formView}get _isToolbarVisible(){return!!this.toolbarView&&this._balloon.visibleView===this.toolbarView}get _isUIInPanel(){return this._arePropertiesInPanel||this._isLinksListInPanel||this._isFormInPanel||this._isToolbarInPanel}get _isUIVisible(){return this._isPropertiesVisible||this._isLinksListInPanel||this._isFormVisible||this._isToolbarVisible}_getBalloonPositionData(){const e=this.editor.editing.view,t=e.document;if(this.editor.model.markers.has(Vy)){const t=this.editor.editing.mapper.markerNameToElements(Vy);if(t){const o=Array.from(t),i=e.createRange(e.createPositionBefore(o[0]),e.createPositionAfter(o[o.length-1]));return{target:e.domConverter.viewRangeToDom(i)}}}return{target:()=>{const o=this._getSelectedLinkElement();return o?e.domConverter.mapViewToDom(o):e.domConverter.viewRangeToDom(t.selection.getFirstRange())}}}_getSelectedLinkElement(){const e=this.editor.editing.view,t=e.document.selection,o=t.getSelectedElement();if(t.isCollapsed||o&&ip(o))return Fy(t.getFirstPosition());{const o=t.getFirstRange().getTrimmed(),i=Fy(o.start),n=Fy(o.end);return i&&i==n&&e.createRangeIn(i).getTrimmed().isEqual(o)?i:null}}_getSelectedLinkableText(){const e=this.editor.model,t=this.editor.editing,o=this._getSelectedLinkElement();if(!o)return wy(e.document.selection.getFirstRange());const i=t.view.createRangeOn(o);return wy(t.mapper.toModelRange(i))}_getLinkProviderLinkByHref(e){if(!e)return null;for(const t of this._linksProviders){const o=t.getItem?t.getItem(e):t.getListItems().find((t=>t.href===e));if(o)return{provider:t,item:o}}return null}_showFakeVisualSelection(){const e=this.editor.model;e.change((t=>{const o=e.document.selection.getFirstRange();if(e.markers.has(Vy))t.updateMarker(Vy,{range:o});else if(o.start.isAtEnd){const i=o.start.getLastMatchingPosition((({item:t})=>!e.schema.isContent(t)),{boundaries:o});t.addMarker(Vy,{usingOperation:!1,affectsData:!1,range:t.createRange(i,o.end)})}else t.addMarker(Vy,{usingOperation:!1,affectsData:!1,range:o})}))}_hideFakeVisualSelection(){const e=this.editor.model;e.markers.has(Vy)&&e.change((e=>{e.removeMarker(Vy)}))}}function Fy(e){return e.getAncestors().find((e=>{return(t=e).is("attributeElement")&&!!t.getCustomProperty("link");var t}))||null}const My=new RegExp("(^|\\s)(((?:(?:(?:https?|ftp):)?\\/\\/)(?:\\S+(?::\\S*)?@)?(?:(?:[1-9]\\d?|1\\d\\d|2[01]\\d|22[0-3])(?:\\.(?:1?\\d{1,2}|2[0-4]\\d|25[0-5])){2}(?:\\.(?:[1-9]\\d?|1\\d\\d|2[0-4]\\d|25[0-4]))|(((?!www\\.)|(www\\.))(?![-_])(?:[-_a-z0-9\\u00a1-\\uffff]{1,63}\\.)+(?:[a-z\\u00a1-\\uffff]{2,63}))|localhost)(?::\\d{2,5})?(?:[/?#]\\S*)?)|((www.|(\\S+@))((?![-_])(?:[-_a-z0-9\\u00a1-\\uffff]{1,63}\\.))+(?:[a-z\\u00a1-\\uffff]{2,63})))$","i");class Ny extends fc{static get requires(){return[Tg,Ty]}static get pluginName(){return"AutoLink"}static get isOfficialPlugin(){return!0}init(){const e=this.editor.model.document.selection;e.on("change:range",(()=>{this.isEnabled=!e.anchor.parent.is("element","codeBlock")})),this._enableTypingHandling()}afterInit(){this._enableEnterHandling(),this._enableShiftEnterHandling(),this._enablePasteLinking()}_expandLinkRange(e,t){return t.textNode&&t.textNode.hasAttribute("linkHref")?Lg(t,"linkHref",t.textNode.getAttribute("linkHref"),e):null}_selectEntireLinks(e,t){const o=this.editor.model,i=o.document.selection,n=i.getFirstPosition(),s=i.getLastPosition();let r=t.getJoined(this._expandLinkRange(o,n)||t);r&&(r=r.getJoined(this._expandLinkRange(o,s)||t)),r&&(r.start.isBefore(n)||r.end.isAfter(s))&&e.setSelection(r)}_enablePasteLinking(){const e=this.editor,t=e.model,o=t.document.selection,i=e.plugins.get("ClipboardPipeline"),n=e.commands.get("link");i.on("inputTransformation",((e,i)=>{if(!this.isEnabled||!n.isEnabled||o.isCollapsed||"paste"!==i.method)return;if(o.rangeCount>1)return;const s=o.getFirstRange(),r=i.dataTransfer.getData("text/plain");if(!r)return;const a=r.match(My);a&&a[2]===r&&(t.change((e=>{this._selectEntireLinks(e,s),n.execute(r)})),e.stop())}),{priority:"high"})}_enableTypingHandling(){const e=this.editor,t=new Ig(e.model,(e=>{let t=e;if(!function(e){return e.length>4&&" "===e[e.length-1]&&" "!==e[e.length-2]}(t))return;t=t.slice(0,-1),"!.:,;?".includes(t[t.length-1])&&(t=t.slice(0,-1));const o=By(t);return o?{url:o,removedTrailingCharacters:e.length-t.length}:void 0}));t.on("matched:data",((t,o)=>{const{batch:i,range:n,url:s,removedTrailingCharacters:r}=o;if(!i.isTyping)return;const a=n.end.getShiftedBy(-r),l=a.getShiftedBy(-s.length),c=e.model.createRange(l,a);this._applyAutoLink(s,c)})),t.bind("isEnabled").to(this)}_enableEnterHandling(){const e=this.editor,t=e.model,o=e.commands.get("enter");o&&o.on("execute",(()=>{const e=t.document.selection.getFirstPosition();let o;o=e.parent.previousSibling?.is("element")?t.createRangeIn(e.parent.previousSibling):t.createRange(t.createPositionAt(e.parent,0),e),this._checkAndApplyAutoLinkOnRange(o)}))}_enableShiftEnterHandling(){const e=this.editor,t=e.model,o=e.commands.get("shiftEnter");o&&o.on("execute",(()=>{const e=t.document.selection.getFirstPosition(),o=t.createRange(t.createPositionAt(e.parent,0),e.getShiftedBy(-1));this._checkAndApplyAutoLinkOnRange(o)}))}_checkAndApplyAutoLinkOnRange(e){const t=this.editor.model,{text:o,range:i}=Sg(e,t),n=By(o);if(n){const e=t.createRange(i.end.getShiftedBy(-n.length),i.end);this._applyAutoLink(n,e)}}_applyAutoLink(e,t){const o=this.editor.model,i=fy(e,this.editor.config.get("link.defaultProtocol"));this.isEnabled&&function(e,t){return t.schema.checkAttributeInSelection(t.createSelection(e),"linkHref")}(t,o)&&by(i)&&!function(e){const t=e.start.nodeAfter;return!!t&&t.hasAttribute("linkHref")}(t)&&this._persistAutoLink(i,t)}_persistAutoLink(e,t){const o=this.editor.model,i=this.editor.plugins.get("Delete");o.enqueueChange((n=>{n.setAttribute("linkHref",e,t),o.enqueueChange((()=>{i.requestUndoOnBackspace()}))}))}}function By(e){const t=My.exec(e);return t?t[2]:null}function Ly(e){return e.map((e=>function(e){"number"==typeof e&&(e=String(e));if("object"==typeof e&&(t=e,t.title&&t.model&&t.view))return jy(e);var t;const o=function(e){return"string"==typeof e?zy[e]:zy[e.model]}(e);if(o)return jy(o);if("default"===e)return{model:void 0,title:"Default"};if(function(e){let t;if("object"==typeof e){if(!e.model)throw new fe("font-size-invalid-definition",null,e);t=parseFloat(e.model)}else t=parseFloat(e);return isNaN(t)}(e))return;return function(e){"string"==typeof e&&(e={title:e,model:`${parseFloat(e)}px`});return e.view={name:"span",styles:{"font-size":e.model}},jy(e)}(e)}(e))).filter((e=>void 0!==e))}const zy={get tiny(){return{title:"Tiny",model:"tiny",view:{name:"span",classes:"text-tiny",priority:7}}},get small(){return{title:"Small",model:"small",view:{name:"span",classes:"text-small",priority:7}}},get big(){return{title:"Big",model:"big",view:{name:"span",classes:"text-big",priority:7}}},get huge(){return{title:"Huge",model:"huge",view:{name:"span",classes:"text-huge",priority:7}}}};function jy(e){return e.view&&"string"!=typeof e.view&&!e.view.priority&&(e.view.priority=7),e}class qy{_startElement;_referenceIndent;_isForward;_includeSelf;_sameAttributes;_sameIndent;_lowerIndent;_higherIndent;constructor(e,t){this._startElement=e,this._referenceIndent=e.getAttribute("listIndent"),this._isForward="forward"==t.direction,this._includeSelf=!!t.includeSelf,this._sameAttributes=Qt(t.sameAttributes||[]),this._sameIndent=!!t.sameIndent,this._lowerIndent=!!t.lowerIndent,this._higherIndent=!!t.higherIndent}static first(e,t){return to(new this(e,t)[Symbol.iterator]())}*[Symbol.iterator](){const e=[];for(const{node:t}of new $y(this._getStartNode(),this._isForward?"forward":"backward")){const o=t.getAttribute("listIndent");if(othis._referenceIndent){if(!this._higherIndent)continue;if(!this._isForward){e.push(t);continue}}else{if(!this._sameIndent){if(this._higherIndent){e.length&&(yield*e,e.length=0);break}continue}if(this._sameAttributes.some((e=>t.getAttribute(e)!==this._startElement.getAttribute(e))))break}e.length&&(yield*e,e.length=0),yield t}}_getStartNode(){return this._includeSelf?this._startElement:this._isForward?this._startElement.nextSibling:this._startElement.previousSibling}}class $y{_node;_isForward;_previousNodesByIndent=[];_previous=null;_previousNodeIndent=null;constructor(e,t="forward"){this._node=e,this._isForward="forward"===t}[Symbol.iterator](){return this}next(){if(!Uy(this._node))return{done:!0,value:void 0};const e=this._node.getAttribute("listIndent");let t=null;if(this._previous){const o=this._previousNodeIndent;e>o?this._previousNodesByIndent[o]=this._previous:ee.getAttribute("listItemId")!=t))}function s_(e){return Array.from(e).filter((e=>"$graveyard"!==e.root.rootName)).sort(((e,t)=>e.index-t.index))}function r_(e){const t=e.document.selection.getSelectedElement();return t&&e.schema.isObject(t)&&e.schema.isBlock(t)?t:null}function a_(e,t){return t.checkChild(e.parent,"listItem")&&t.checkChild(e,"$text")&&!t.isObject(e)}function l_(e){return"numbered"==e||"customNumbered"==e}function c_(e,t,o){return Gy(t,{direction:"forward"}).pop().index>e.index?t_(e,t,o):[]}class d_ extends wc{_direction;constructor(e,t){super(e),this._direction=t}refresh(){this.isEnabled=this._checkEnabled()}execute(){const e=this.editor,t=e.model,o=u_(t.document.selection),i=e.plugins.get("ListEditing").getListAttributeNames();t.change((e=>{const t=[];n_(o)&&!Zy(o[0])?("forward"==this._direction&&t.push(...o_(o,e,{attributeNames:i})),t.push(...e_(o[0],e))):"forward"==this._direction?t.push(...o_(o,e,{expand:!0,attributeNames:i})):t.push(...function(e,t,{attributeNames:o}){const i=Yy(e=Qt(e)),n=new Set,s=Math.min(...i.map((e=>e.getAttribute("listIndent")))),r=new Map;for(const e of i)r.set(e,qy.first(e,{lowerIndent:!0}));for(const e of i){if(n.has(e))continue;n.add(e);const i=e.getAttribute("listIndent")-1;if(i<0)i_(e,t,o);else{if(e.getAttribute("listIndent")==s){const o=c_(e,r.get(e),t);for(const e of o)n.add(e);if(o.length)continue}t.setAttribute("listIndent",i,e)}}return s_(n)}(o,e,{attributeNames:i}));for(const o of t){if(!o.hasAttribute("listType"))continue;const t=qy.first(o,{sameIndent:!0});t&&e.setAttribute("listType",t.getAttribute("listType"),o)}this._fireAfterExecute(t)}))}_fireAfterExecute(e){this.fire("afterExecute",s_(new Set(e)))}_checkEnabled(){let e=u_(this.editor.model.document.selection),t=e[0];if(!t)return!1;if("backward"==this._direction)return!0;if(n_(e)&&!Zy(e[0]))return!0;e=Yy(e),t=e[0];const o=qy.first(t,{sameIndent:!0});return!!o&&o.getAttribute("listType")==t.getAttribute("listType")}}function u_(e){const t=Array.from(e.getSelectedBlocks()),o=t.findIndex((e=>!Uy(e)));return-1!=o&&(t.length=o),t}class h_ extends wc{type;_listWalkerOptions;constructor(e,t,o={}){super(e),this.type=t,this._listWalkerOptions=o.multiLevel?{higherIndent:!0,lowerIndent:!0,sameAttributes:[]}:void 0}refresh(){this.value=this._getValue(),this.isEnabled=this._checkEnabled()}execute(e={}){const t=this.editor.model,o=t.document,i=r_(t),n=Array.from(o.selection.getSelectedBlocks()).filter((e=>t.schema.checkAttribute(e,"listType")||a_(e,t.schema))),s=void 0!==e.forceValue?!e.forceValue:this.value;t.change((r=>{if(s){const e=n[n.length-1],t=this.editor.plugins.get("ListEditing").getListAttributeNames(),o=Gy(e,{direction:"forward"}),i=[];o.length>1&&i.push(...e_(o[1],r)),i.push(...i_(n,r,t)),i.push(...function(e,t){const o=[];let i=Number.POSITIVE_INFINITY;for(const{node:n}of new $y(e.nextSibling)){const e=n.getAttribute("listIndent");if(0==e)break;e{const{firstElement:r,lastElement:a}=this._getMergeSubjectElements(i,e),l=r.getAttribute("listIndent")||0,c=a.getAttribute("listIndent"),d=a.getAttribute("listItemId");if(l!=c){const e=(u=a,Array.from(new qy(u,{direction:"forward",higherIndent:!0})));n.push(...o_([a,...e],t,{indentBy:l-c,expand:l{const t=e_(this._getStartBlock(),e);this._fireAfterExecute(t)}))}_fireAfterExecute(e){this.fire("afterExecute",s_(new Set(e)))}_checkEnabled(){const e=this.editor.model.document.selection,t=this._getStartBlock();return e.isCollapsed&&Uy(t)&&!Zy(t)}_getStartBlock(){const e=this.editor.model.document.selection.getFirstPosition().parent;return"before"==this._direction?e:e.nextSibling}}class p_ extends fc{static get pluginName(){return"ListItemBoldIntegration"}static get isOfficialPlugin(){return!0}static get requires(){return[z_]}init(){const e=this.editor,t=e.plugins.get("ListFormatting"),o=e.plugins.get(z_);e.plugins.has("BoldEditing")&&this.editor.config.get("list.enableListItemMarkerFormatting")&&(t.registerFormatAttribute("bold","listItemBold"),o.registerDowncastStrategy({scope:"item",attributeName:"listItemBold",setAttributeOnDowncast(e,t,o,i){t&&(e.addClass("ck-list-marker-bold",o),!Y.isSafari||i&&i.dataPipeline||e.setStyle("--ck-content-list-marker-dummy-bold","0",o))}}))}afterInit(){const e=this.editor,t=e.model;e.plugins.has("BoldEditing")&&this.editor.config.get("list.enableListItemMarkerFormatting")&&(t.schema.extend("$listItem",{allowAttributes:"listItemBold"}),t.schema.setAttributeProperties("listItemBold",{isFormatting:!0}),t.schema.addAttributeCheck((e=>{if(!e.last.getAttribute("listItemId"))return!1}),"listItemBold"),e.conversion.for("upcast").attributeToAttribute({model:"listItemBold",view:{name:"li",classes:"ck-list-marker-bold"}}))}}class f_ extends fc{static get pluginName(){return"ListItemItalicIntegration"}static get isOfficialPlugin(){return!0}static get requires(){return[z_]}init(){const e=this.editor,t=e.plugins.get("ListFormatting"),o=e.plugins.get(z_);e.plugins.has("ItalicEditing")&&this.editor.config.get("list.enableListItemMarkerFormatting")&&(t.registerFormatAttribute("italic","listItemItalic"),o.registerDowncastStrategy({scope:"item",attributeName:"listItemItalic",setAttributeOnDowncast(e,t,o,i){t&&(e.addClass("ck-list-marker-italic",o),!Y.isSafari||i&&i.dataPipeline||e.setStyle("--ck-content-list-marker-dummy-italic","0",o))}}))}afterInit(){const e=this.editor,t=e.model;e.plugins.has("ItalicEditing")&&this.editor.config.get("list.enableListItemMarkerFormatting")&&(t.schema.extend("$listItem",{allowAttributes:"listItemItalic"}),t.schema.setAttributeProperties("listItemItalic",{isFormatting:!0}),t.schema.addAttributeCheck((e=>{if(!e.last.getAttribute("listItemId"))return!1}),"listItemItalic"),e.conversion.for("upcast").attributeToAttribute({model:"listItemItalic",view:{name:"li",classes:"ck-list-marker-italic"}}))}}class b_ extends fc{static get pluginName(){return"ListItemFontSizeIntegration"}static get isOfficialPlugin(){return!0}static get requires(){return[z_]}init(){const e=this.editor,t=e.plugins.get("ListFormatting"),o=e.plugins.get(z_);if(!e.plugins.has("FontSizeEditing")||!this.editor.config.get("list.enableListItemMarkerFormatting"))return;const i=Ly(e.config.get("fontSize.options"));t.registerFormatAttribute("fontSize","listItemFontSize"),o.registerDowncastStrategy({scope:"item",attributeName:"listItemFontSize",setAttributeOnDowncast(e,t,o,n){if(t){const s=i.find((e=>e.model==t));s&&s.view&&"string"!=typeof s.view?s.view.styles?(e.addClass("ck-list-marker-font-size",o),e.setStyle("--ck-content-list-marker-font-size",s.view.styles["font-size"],o)):s.view.classes&&(e.addClass(`ck-list-marker-font-size-${t}`,o),!Y.isSafari||n&&n.dataPipeline||e.setStyle("--ck-content-list-marker-dummy-font-size","0",o)):(e.addClass("ck-list-marker-font-size",o),e.setStyle("--ck-content-list-marker-font-size",t,o))}}})}afterInit(){const e=this.editor,t=e.model;if(!e.plugins.has("FontSizeEditing")||!this.editor.config.get("list.enableListItemMarkerFormatting"))return;t.schema.extend("$listItem",{allowAttributes:"listItemFontSize"}),t.schema.setAttributeProperties("listItemFontSize",{isFormatting:!0}),t.schema.addAttributeCheck((e=>{if(!e.last.getAttribute("listItemId"))return!1}),"listItemFontSize"),e.conversion.for("upcast").elementToAttribute({model:{key:"listItemFontSize",value:e=>e.getStyle("--ck-content-list-marker-font-size")},view:{name:"li",classes:"ck-list-marker-font-size",styles:{"--ck-content-list-marker-font-size":/.*/}}});const o=Ly(e.config.get("fontSize.options"));for(const t of o)t.model&&t.view&&e.conversion.for("upcast").elementToAttribute({model:{key:"listItemFontSize",value:t.model},view:{name:"li",classes:`ck-list-marker-font-size-${t.model}`}})}}class w_ extends fc{static get pluginName(){return"ListItemFontColorIntegration"}static get isOfficialPlugin(){return!0}static get requires(){return[z_]}init(){const e=this.editor,t=e.plugins.get("ListFormatting"),o=e.plugins.get(z_);e.plugins.has("FontColorEditing")&&this.editor.config.get("list.enableListItemMarkerFormatting")&&(t.registerFormatAttribute("fontColor","listItemFontColor"),o.registerDowncastStrategy({scope:"item",attributeName:"listItemFontColor",setAttributeOnDowncast(e,t,o){t&&(e.addClass("ck-list-marker-color",o),e.setStyle("--ck-content-list-marker-color",t,o))}}))}afterInit(){const e=this.editor,t=e.model;e.plugins.has("FontColorEditing")&&this.editor.config.get("list.enableListItemMarkerFormatting")&&(t.schema.extend("$listItem",{allowAttributes:"listItemFontColor"}),t.schema.setAttributeProperties("listItemFontColor",{isFormatting:!0}),t.schema.addAttributeCheck((e=>{if(!e.last.getAttribute("listItemId"))return!1}),"listItemFontColor"),e.conversion.for("upcast").attributeToAttribute({model:{key:"listItemFontColor",value:e=>e.getStyle("--ck-content-list-marker-color")},view:{name:"li",classes:"ck-list-marker-color",styles:{"--ck-content-list-marker-color":/.*/}}}))}}class y_ extends fc{static get pluginName(){return"ListItemFontFamilyIntegration"}static get isOfficialPlugin(){return!0}static get requires(){return[z_]}init(){const e=this.editor,t=e.plugins.get("ListFormatting"),o=e.plugins.get(z_);e.plugins.has("FontFamilyEditing")&&this.editor.config.get("list.enableListItemMarkerFormatting")&&(t.registerFormatAttribute("fontFamily","listItemFontFamily"),o.registerDowncastStrategy({scope:"item",attributeName:"listItemFontFamily",setAttributeOnDowncast(e,t,o){t&&(e.addClass("ck-list-marker-font-family",o),e.setStyle("--ck-content-list-marker-font-family",t,o))}}))}afterInit(){const e=this.editor,t=e.model;e.plugins.has("FontFamilyEditing")&&this.editor.config.get("list.enableListItemMarkerFormatting")&&(t.schema.extend("$listItem",{allowAttributes:"listItemFontFamily"}),t.schema.setAttributeProperties("listItemFontFamily",{isFormatting:!0}),t.schema.addAttributeCheck((e=>{if(!e.last.getAttribute("listItemId"))return!1}),"listItemFontFamily"),e.conversion.for("upcast").attributeToAttribute({model:{key:"listItemFontFamily",value:e=>e.getStyle("--ck-content-list-marker-font-family")},view:{name:"li",classes:"ck-list-marker-font-family",styles:{"--ck-content-list-marker-font-family":/.*/}}}))}}class __ extends fc{_loadedFormatting={};static get pluginName(){return"ListFormatting"}static get isOfficialPlugin(){return!0}static get requires(){return[p_,f_,b_,w_,y_]}constructor(e){super(e),e.config.define("list.enableListItemMarkerFormatting",!0)}afterInit(){this.editor.config.get("list.enableListItemMarkerFormatting")&&this._registerPostfixerForListItemFormatting()}_registerPostfixerForListItemFormatting(){const e=this.editor.model;e.document.registerPostFixer((t=>{const o=e.document.differ.getChanges(),i=new Set;let n=!1;for(const e of o)if("attribute"===e.type)("listItemId"==e.attributeKey||"listType"==e.attributeKey||this._isInlineOrSelectionFormatting(e.attributeKey)||Object.values(this._loadedFormatting).includes(e.attributeKey))&&(Uy(e.range.start.nodeAfter)?i.add(e.range.start.nodeAfter):Uy(e.range.start.parent)&&i.add(e.range.start.parent));else if(Uy(e.position.nodeAfter)&&i.add(e.position.nodeAfter),Uy(e.position.nodeBefore)&&i.add(e.position.nodeBefore),Uy(e.position.parent)&&i.add(e.position.parent),"insert"==e.type&&"$text"!=e.name){const o=t.createRangeIn(e.position.nodeAfter);for(const e of o.getItems())Uy(e)&&i.add(e)}for(const o of i){const i=k_(e,o,Object.keys(this._loadedFormatting));for(const[e,s]of Object.entries(i)){const i=this._loadedFormatting[e];(s&&C_(t,o,i,s)||!s&&A_(t,o,i))&&(n=!0)}}return n}))}registerFormatAttribute(e,t){this._loadedFormatting[e]=t}_isInlineOrSelectionFormatting(e){return e.replace(/^selection:/,"")in this._loadedFormatting}}function k_(e,t,o){if(Zy(t))return v_(e,t,o);return v_(e,Ky(t)[0],o)}function v_(e,t,o){if(!function(e){return["numbered","bulleted","customNumbered","customBulleted"].includes(e.getAttribute("listType"))}(t)||e.schema.isLimit(t))return Object.fromEntries(o.map((e=>[e])));if(t.isEmpty)return Object.fromEntries(o.map((e=>[e,t.getAttribute(`selection:${e}`)])));const i=new Set(o),n={},s=e.createRangeIn(t).getWalker({ignoreElementEnd:!0});for(const{item:t}of s){for(const o of i)if(e.schema.checkAttribute(t,o)){const e=t.getAttribute(o);void 0===e?(i.delete(o),n[o]=void 0):void 0===n[o]?n[o]=e:n[o]!==e&&(i.delete(o),n[o]=void 0)}else o in n||(n[o]=void 0);if(!i.size)break;e.schema.isLimit(t)&&s.jumpTo(e.createPositionAfter(t))}return n}function C_(e,t,o,i){const n=Ky(t);let s=!1;for(const t of n)t.hasAttribute(o)&&t.getAttribute(o)===i||(e.setAttribute(o,i,t),s=!0);return s}function A_(e,t,o){const i=Ky(t);let n=!1;for(const t of i)t.hasAttribute(o)&&(e.removeAttribute(o,t),n=!0);return n}class x_ extends fc{static get pluginName(){return"ListUtils"}static get isOfficialPlugin(){return!0}expandListBlocksToCompleteList(e){return Xy(e)}isFirstBlockOfListItem(e){return Zy(e)}isListItemBlock(e){return Uy(e)}expandListBlocksToCompleteItems(e,t={}){return Yy(e,t)}isNumberedListType(e){return l_(e)}isFirstListItemInList(e){return function(e){return!qy.first(e,{sameIndent:!0,sameAttributes:"listType"})}(e)}}function E_(e){return e.is("element","ol")||e.is("element","ul")}function T_(e){return e.is("element","li")}function P_(e,t,o,i=R_(o,t)){return e.createAttributeElement(I_(o),null,{priority:2*t/100-100,id:i})}function S_(e,t,o){return e.createAttributeElement("li",null,{priority:(2*t+1)/100-100,id:o})}function I_(e){return"numbered"==e||"customNumbered"==e?"ol":"ul"}function R_(e,t){return`list-${e}-${t}`}function O_(e,t,o){const i=e.nodeBefore;if(Uy(i)){let e=i;for(const{node:n}of new $y(e,"backward")){if(e=n,o.has(e))return;if(o.add(e),t.has(i))return}t.add(e)}else{const o=e.nodeAfter;Uy(o)&&t.add(o)}}function V_(){return(e,t,o)=>{const{writer:i,schema:n}=o;if(!t.modelRange)return;const s=Array.from(t.modelRange.getItems({shallow:!0})).filter((e=>n.checkAttribute(e,"listItemId")));if(!s.length)return;const r=t.viewItem.getAttribute("data-list-item-id")||Wy.next();o.consumable.consume(t.viewItem,{attributes:"data-list-item-id"});const a=function(e){let t=0,o=e.parent;for(;o;){if(T_(o))t++;else{const e=o.previousSibling;e&&T_(e)&&t++}o=o.parent}return t}(t.viewItem);let l=t.viewItem.parent&&t.viewItem.parent.is("element","ol")?"numbered":"bulleted";const c=s[0].getAttribute("listType");c&&(l=c);const d={listItemId:r,listIndent:a,listType:l};for(const e of s)e.hasAttribute("listItemId")||i.setAttributes(d,e);s.length>1&&s[1].getAttribute("listItemId")!=d.listItemId&&o.keepEmptyElement(s[0])}}function D_(e,t,o,i){return()=>{const i=e.document.differ.getChanges(),r=[],a=new Set,l=new Set,c=new Set;for(const e of i)if("insert"==e.type&&"$text"!=e.name)O_(e.position,a,c),e.attributes.has("listItemId")?l.add(e.position.nodeAfter):O_(e.position.getShiftedBy(e.length),a,c);else if("remove"==e.type&&e.attributes.has("listItemId"))O_(e.position,a,c);else if("attribute"==e.type){const t=e.range.start.nodeAfter;o.includes(e.attributeKey)?(O_(e.range.start,a,c),null===e.attributeNewValue?(O_(e.range.start.getShiftedBy(1),a,c),s(t)&&r.push(t)):l.add(t)):Uy(t)&&s(t)&&r.push(t)}for(const e of a.values())r.push(...n(e,l));for(const e of new Set(r))t.reconvertItem(e)};function n(e,t){const i=[],n=new Set,a=[];for(const{node:l,previous:c}of new $y(e)){if(n.has(l))continue;const e=l.getAttribute("listIndent");c&&eo.includes(e)))),modelElement:l};const d=Gy(l,{direction:"forward"});for(const e of d)n.add(e),(s(e,d)||r(e,a,t))&&i.push(e)}return i}function s(e,n){const s=t.mapper.toViewElement(e);if(!s)return!1;if(function(e){e=e.parent;for(;e.is("attributeElement")&&["ol","ul","li"].includes(e.name);)e=e.parent;if(e.getCustomProperty("$structureSlotParent")&&!t.mapper.toModelElement(e))return!0;return!1}(s))return!0;if(i.fire("checkElement",{modelElement:e,viewElement:s}))return!0;if(!e.is("element","paragraph")&&!e.is("element","listItem"))return!1;const r=B_(e,o,n);return!(!r||!s.is("element","p"))||!(r||!s.is("element","span"))}function r(e,o,n){if(n.has(e))return!1;const s=t.mapper.toViewElement(e);let r=o.length-1;for(let e=s.parent;!e.is("editableElement");e=e.parent){const t=T_(e),n=E_(e);if(!n&&!t)continue;const s="checkAttributes:"+(t?"item":"list");if(i.fire(s,{viewElement:e,modelAttributes:o[r].modelAttributes,modelReferenceElement:o[r].modelElement}))break;if(n&&(r--,r<0))return!1}return!0}}function F_(e,t,o,{dataPipeline:i}={}){const n=function(e,t){const o=t.filter((e=>!1===e.consume)).map((e=>e.attributeName));return(t,i)=>{const n=[];for(const i of e)t.hasAttribute(i)&&!o.includes(i)&&n.push(`attribute:${i}`);return!!n.every((e=>!1!==i.test(t,e)))&&(n.forEach((e=>i.consume(t,e))),!0)}}(e,t);return(s,r,a)=>{const{writer:l,mapper:c,consumable:d}=a,u=r.item;if(!e.includes(r.attributeKey))return;if(!n(u,d))return;const h={...a.options,dataPipeline:i},m=function(e,t,o,i){const n=o.createRangeOn(e),s=t.toViewRange(n).getTrimmed(),r=s.getWalker();for(const{item:e}of r)if(e.is("element")&&e.getCustomProperty("listItemMarker"))r.jumpTo(i.createPositionAfter(e));else if(e.is("element")&&!e.getCustomProperty("listItemWrapper"))return e}(u,c,o,l);N_(m,l,c),function(e,t){let o=e.parent;for(;o.is("attributeElement")&&["ul","ol","li"].includes(o.name);){const i=o.parent;t.unwrap(t.createRangeOn(e),o),o=i}}(m,l);const g=function(e,t,o,i,{dataPipeline:n}){let s=i.createRangeOn(t);if(!Zy(e))return s;for(const r of o){if("itemMarker"!=r.scope)continue;const o=r.createElement(i,e,{dataPipeline:n});if(!o)continue;if(i.setCustomProperty("listItemMarker",!0,o),r.canInjectMarkerIntoElement&&r.canInjectMarkerIntoElement(e)?i.insert(i.createPositionAt(t,0),o):(i.insert(s.start,o),s=i.createRange(i.createPositionBefore(o),i.createPositionAfter(t))),!r.createWrapperElement||!r.canWrapElement)continue;const a=r.createWrapperElement(i,e,{dataPipeline:n});i.setCustomProperty("listItemWrapper",!0,a),r.canWrapElement(e)?s=i.wrap(s,a):(s=i.wrap(i.createRangeOn(o),a),s=i.createRange(s.start,i.createPositionAfter(t)))}return s}(u,m,t,l,h);!function(e,t,o,i,n){if(!e.hasAttribute("listIndent"))return;const s=e.getAttribute("listIndent");let r=e;for(let e=s;e>=0;e--){const s=S_(i,e,r.getAttribute("listItemId")),a=P_(i,e,r.getAttribute("listType"));for(const e of o)"list"!=e.scope&&"item"!=e.scope||!r.hasAttribute(e.attributeName)||e.setAttributeOnDowncast(i,r.getAttribute(e.attributeName),"list"==e.scope?a:s,n,r);if(t=i.wrap(t,s),t=i.wrap(t,a),0==e)break;if(r=qy.first(r,{lowerIndent:!0}),!r)break}}(u,g,t,l,h)}}function M_(e,{dataPipeline:t}={}){return(o,{writer:i})=>{if(!B_(o,e))return null;if(!t)return i.createContainerElement("span",{class:"ck-list-bogus-paragraph"});const n=i.createContainerElement("p");return i.setCustomProperty("dataPipeline:transparentRendering",!0,n),n}}function N_(e,t,o){for(;e.parent.is("attributeElement")&&e.parent.getCustomProperty("listItemWrapper");)t.unwrap(t.createRangeOn(e),e.parent);const i=[];n(t.createPositionBefore(e).getWalker({direction:"backward"})),n(t.createRangeIn(e).getWalker());for(const e of i)t.remove(e);function n(e){for(const{item:t}of e){if(t.is("element")&&o.toModelElement(t))break;t.is("element")&&t.getCustomProperty("listItemMarker")&&i.push(t)}}}function B_(e,t,o=Ky(e)){if(!Uy(e))return!1;for(const o of e.getAttributeKeys())if(!o.startsWith("selection:")&&"htmlEmptyBlock"!=o&&!t.includes(o))return!1;return o.length<2}const L_=["listType","listIndent","listItemId"];class z_ extends fc{_downcastStrategies=[];static get pluginName(){return"ListEditing"}static get isOfficialPlugin(){return!0}static get requires(){return[Kg,Tg,x_,bf,__]}constructor(e){super(e),e.config.define("list.multiBlock",!0)}init(){const e=this.editor,t=e.model,o=e.config.get("list.multiBlock");if(e.plugins.has("LegacyListEditing"))throw new fe("list-feature-conflict",this,{conflictPlugin:"LegacyListEditing"});t.schema.register("$listItem",{allowAttributes:L_}),o?(t.schema.extend("$container",{allowAttributesOf:"$listItem"}),t.schema.extend("$block",{allowAttributesOf:"$listItem"}),t.schema.extend("$blockObject",{allowAttributesOf:"$listItem"})):t.schema.register("listItem",{inheritAllFrom:"$block",allowAttributesOf:"$listItem"});for(const e of L_)t.schema.setAttributeProperties(e,{copyOnReplace:!0});e.commands.add("numberedList",new h_(e,"numbered")),e.commands.add("bulletedList",new h_(e,"bulleted")),e.commands.add("customNumberedList",new h_(e,"customNumbered",{multiLevel:!0})),e.commands.add("customBulletedList",new h_(e,"customBulleted",{multiLevel:!0})),e.commands.add("indentList",new d_(e,"forward")),e.commands.add("outdentList",new d_(e,"backward")),e.commands.add("splitListItemBefore",new g_(e,"before")),e.commands.add("splitListItemAfter",new g_(e,"after")),o&&(e.commands.add("mergeListItemBackward",new m_(e,"backward")),e.commands.add("mergeListItemForward",new m_(e,"forward"))),this._setupDeleteIntegration(),this._setupEnterIntegration(),this._setupTabIntegration(),this._setupClipboardIntegration(),this._setupAccessibilityIntegration(),this._setupListItemIdConversionStrategy()}afterInit(){const e=this.editor.commands,t=e.get("indent"),o=e.get("outdent");t&&t.registerChildCommand(e.get("indentList"),{priority:"high"}),o&&o.registerChildCommand(e.get("outdentList"),{priority:"lowest"}),this._setupModelPostFixing(),this._setupConversion()}registerDowncastStrategy(e){this._downcastStrategies.push(e)}getListAttributeNames(){return[...L_,...this._downcastStrategies.map((e=>e.attributeName))]}_setupDeleteIntegration(){const e=this.editor,t=e.commands.get("mergeListItemBackward"),o=e.commands.get("mergeListItemForward");this.listenTo(e.editing.view.document,"delete",((i,n)=>{const s=e.model.document.selection;r_(e.model)||e.model.change((()=>{const r=s.getFirstPosition();if(s.isCollapsed&&"backward"==n.direction){if(!r.isAtStart)return;const o=r.parent;if(!Uy(o))return;if(qy.first(o,{sameAttributes:"listType",sameIndent:!0})||0!==o.getAttribute("listIndent")){if(!t||!t.isEnabled)return;t.execute({shouldMergeOnBlocksContentLevel:j_(e.model,"backward")})}else Qy(o)||e.execute("splitListItemAfter"),e.execute("outdentList");n.preventDefault(),i.stop()}else{if(s.isCollapsed&&!s.getLastPosition().isAtEnd)return;if(!o||!o.isEnabled)return;o.execute({shouldMergeOnBlocksContentLevel:j_(e.model,"forward")}),n.preventDefault(),i.stop()}}))}),{context:"li"})}_setupEnterIntegration(){const e=this.editor,t=e.model,o=e.commands,i=o.get("enter");this.listenTo(e.editing.view.document,"enter",((o,i)=>{const n=t.document,s=n.selection.getFirstPosition().parent;if(n.selection.isCollapsed&&Uy(s)&&s.isEmpty&&!i.isSoft){const t=Zy(s),n=Qy(s);t&&n?(e.execute("outdentList"),i.preventDefault(),o.stop()):t&&!n?(e.execute("splitListItemAfter"),i.preventDefault(),o.stop()):n&&(e.execute("splitListItemBefore"),i.preventDefault(),o.stop())}}),{context:"li"}),this.listenTo(i,"afterExecute",(()=>{const t=o.get("splitListItemBefore");if(t.refresh(),!t.isEnabled)return;2===Ky(e.model.document.selection.getLastPosition().parent).length&&t.execute()}))}_setupTabIntegration(){const e=this.editor;this.listenTo(e.editing.view.document,"tab",((t,o)=>{const i=o.shiftKey?"outdentList":"indentList";this.editor.commands.get(i).isEnabled&&(e.execute(i),o.stopPropagation(),o.preventDefault(),t.stop())}),{context:"li"})}_setupConversion(){const e=this.editor,t=e.model,o=this.getListAttributeNames(),i=e.config.get("list.multiBlock"),n=i?"paragraph":"listItem";e.conversion.for("upcast").elementToElement({view:"li",model:(e,{writer:t})=>t.createElement(n,{listType:""})}).elementToElement({view:"p",model:(e,{writer:t})=>e.parent&&e.parent.is("element","li")?t.createElement(n,{listType:""}):null,converterPriority:"high"}).add((e=>{e.on("element:li",V_())})),i||e.conversion.for("downcast").elementToElement({model:"listItem",view:"p"}),e.conversion.for("editingDowncast").elementToElement({model:n,view:M_(o),converterPriority:"high"}).add((e=>{var i;e.on("attribute",F_(o,this._downcastStrategies,t)),e.on("remove",(i=t.schema,(e,t,o)=>{const{writer:n,mapper:s}=o,r=e.name.split(":")[1];if(!i.checkAttribute(r,"listItemId"))return;const a=s.toViewPosition(t.position),l=t.position.getShiftedBy(t.length),c=s.toViewPosition(l,{isPhantom:!0}),d=n.createRange(a,c).getTrimmed().end.nodeBefore;d&&N_(d,n,s)}))})),e.conversion.for("dataDowncast").elementToElement({model:n,view:M_(o,{dataPipeline:!0}),converterPriority:"high"}).add((e=>{e.on("attribute",F_(o,this._downcastStrategies,t,{dataPipeline:!0}))}));const s=(r=this._downcastStrategies,a=e.editing.view,(e,t)=>{if(t.modelPosition.offset>0)return;const o=t.modelPosition.parent;if(!Uy(o))return;if(!r.some((e=>"itemMarker"==e.scope&&e.canInjectMarkerIntoElement&&e.canInjectMarkerIntoElement(o))))return;const i=t.mapper.toViewElement(o),n=a.createRangeIn(i),s=n.getWalker();let l=n.start;for(const{item:e}of s){if(e.is("element")&&t.mapper.toModelElement(e)||e.is("$textProxy"))break;e.is("element")&&e.getCustomProperty("listItemMarker")&&(l=a.createPositionAfter(e),s.skip((({previousPosition:e})=>!e.isEqual(l))))}t.viewPosition=l});var r,a;e.editing.mapper.on("modelToViewPosition",s),e.data.mapper.on("modelToViewPosition",s),this.listenTo(t.document,"change:data",D_(t,e.editing,o,this),{priority:"high"}),this.on("checkAttributes:item",((e,{viewElement:t,modelAttributes:o})=>{t.id!=o.listItemId&&(e.return=!0,e.stop())})),this.on("checkAttributes:list",((e,{viewElement:t,modelAttributes:o})=>{t.name==I_(o.listType)&&t.id==R_(o.listType,o.listIndent)||(e.return=!0,e.stop())}))}_setupModelPostFixing(){const e=this.editor.model,t=this.getListAttributeNames();e.document.registerPostFixer((o=>function(e,t,o,i){const n=e.document.differ.getChanges(),s=new Set,r=new Set,a=i.editor.config.get("list.multiBlock");let l=!1;for(const i of n){if("insert"==i.type&&"$text"!=i.name){const n=i.position.nodeAfter;if(!e.schema.checkAttribute(n,"listItemId"))for(const e of Array.from(n.getAttributeKeys()))o.includes(e)&&(t.removeAttribute(e,n),l=!0);O_(i.position,r,s),i.attributes.has("listItemId")||O_(i.position.getShiftedBy(i.length),r,s);for(const{item:t,previousPosition:o}of e.createRangeIn(n))Uy(t)&&O_(o,r,s)}else"remove"==i.type?O_(i.position,r,s):"attribute"==i.type&&o.includes(i.attributeKey)&&(O_(i.range.start,r,s),null===i.attributeNewValue&&O_(i.range.start.getShiftedBy(1),r,s));if(!a&&"attribute"==i.type&&L_.includes(i.attributeKey)){const e=i.range.start.nodeAfter;null===i.attributeNewValue&&e&&e.is("element","listItem")?(t.rename(e,"paragraph"),l=!0):null===i.attributeOldValue&&e&&e.is("element")&&"listItem"!=e.name&&(t.rename(e,"listItem"),l=!0)}}const c=new Set;for(const e of r.values())l=i.fire("postFixer",{listNodes:new Hy(e),listHead:e,writer:t,seenIds:c})||l;return l}(e,o,t,this))),this.on("postFixer",((e,{listNodes:t,writer:o})=>{e.return=function(e,t){let o=0,i=-1,n=null,s=!1;for(const{node:r}of e){const e=r.getAttribute("listIndent");if(e>o){let a;null===n?(n=e-o,a=o):(n>e&&(n=e),a=e-n),a>i+1&&(a=i+1),t.setAttribute("listIndent",a,r),s=!0,i=a}else n=null,o=e+1,i=e}return s}(t,o)||e.return}),{priority:"high"}),this.on("postFixer",((e,{listNodes:t,writer:o,seenIds:i})=>{e.return=function(e,t,o){const i=new Set;let n=!1;for(const{node:s}of e){if(i.has(s))continue;let e=s.getAttribute("listType"),r=s.getAttribute("listItemId");if(t.has(r)&&(r=Wy.next()),t.add(r),s.is("element","listItem"))s.getAttribute("listItemId")!=r&&(o.setAttribute("listItemId",r,s),n=!0);else for(const t of Gy(s,{direction:"forward"}))i.add(t),t.getAttribute("listType")!=e&&(r=Wy.next(),e=t.getAttribute("listType")),t.getAttribute("listItemId")!=r&&(o.setAttribute("listItemId",r,t),n=!0)}return n}(t,i,o)||e.return}),{priority:"high"})}_setupClipboardIntegration(){const e=this.editor.model,t=this.editor.plugins.get("ClipboardPipeline");this.listenTo(e,"insertContent",function(e){return(t,[o,i])=>{const n=o.is("documentFragment")?Array.from(o.getChildren()):[o];if(!n.length)return;const s=(i?e.createSelection(i):e.document.selection).getFirstPosition();let r;if(Uy(s.parent))r=s.parent;else{if(!Uy(s.nodeBefore)||!Uy(s.nodeAfter))return;r=s.nodeBefore}e.change((e=>{const t=r.getAttribute("listType"),o=r.getAttribute("listIndent"),i=n[0].getAttribute("listIndent")||0,s=Math.max(o-i,0);for(const o of n){const i=Uy(o);r.is("element","listItem")&&o.is("element","paragraph")&&e.rename(o,"listItem"),e.setAttributes({listIndent:(i?o.getAttribute("listIndent"):0)+s,listItemId:i?o.getAttribute("listItemId"):Wy.next(),listType:t},o)}}))}}(e),{priority:"high"}),this.listenTo(t,"outputTransformation",((t,o)=>{e.change((e=>{const t=Array.from(o.content.getChildren()),i=t[t.length-1];if(t.length>1&&i.is("element")&&i.isEmpty){t.slice(0,-1).every(Uy)&&e.remove(i)}if("copy"==o.method||"cut"==o.method){const t=Array.from(o.content.getChildren());n_(t)&&i_(t,e,this.getListAttributeNames())}}))}))}_setupAccessibilityIntegration(){const e=this.editor,t=e.t;e.accessibility.addKeystrokeInfoGroup({id:"list",label:t("Keystrokes that can be used in a list"),keystrokes:[{label:t("Increase list item indent"),keystroke:"Tab"},{label:t("Decrease list item indent"),keystroke:"Shift+Tab"}]})}_setupListItemIdConversionStrategy(){this.registerDowncastStrategy({scope:"item",attributeName:"listItemId",setAttributeOnDowncast(e,t,o,i){i&&(i.skipListItemIds||i.isClipboardPipeline)||e.setAttribute("data-list-item-id",t,o)}})}}function j_(e,t){const o=e.document.selection;if(!o.isCollapsed)return!r_(e);if("forward"===t)return!0;const i=o.getFirstPosition().parent,n=i.previousSibling;return!e.schema.isObject(n)&&(!!n.isEmpty||n_([i,n]))}function q_(e,t,o,i){e.ui.componentFactory.add(t,(()=>{const n=$_(Lu,e,t,o,i);return n.set({tooltip:!0,isToggleable:!0}),n})),e.ui.componentFactory.add(`menuBar:${t}`,(()=>{const n=$_(sh,e,t,o,i);return n.set({role:"menuitemcheckbox",isToggleable:!0}),n}))}function $_(e,t,o,i,n){const s=t.commands.get(o),r=new e(t.locale);return r.set({label:i,icon:n}),r.bind("isOn","isEnabled").to(s,"value","isEnabled"),r.on("execute",(()=>{t.execute(o),t.editing.view.focus()})),r}class H_ extends fc{static get pluginName(){return"ListUI"}static get isOfficialPlugin(){return!0}init(){const e=this.editor.t;this.editor.ui.componentFactory.has("numberedList")||q_(this.editor,"numberedList",e("Numbered List"),''),this.editor.ui.componentFactory.has("bulletedList")||q_(this.editor,"bulletedList",e("Bulleted List"),'')}}const W_={},U_={},K_={},G_=[{listStyle:"disc",typeAttribute:"disc",listType:"bulleted"},{listStyle:"circle",typeAttribute:"circle",listType:"bulleted"},{listStyle:"square",typeAttribute:"square",listType:"bulleted"},{listStyle:"decimal",typeAttribute:"1",listType:"numbered"},{listStyle:"decimal-leading-zero",typeAttribute:null,listType:"numbered"},{listStyle:"lower-roman",typeAttribute:"i",listType:"numbered"},{listStyle:"upper-roman",typeAttribute:"I",listType:"numbered"},{listStyle:"lower-alpha",typeAttribute:"a",listType:"numbered"},{listStyle:"upper-alpha",typeAttribute:"A",listType:"numbered"},{listStyle:"lower-latin",typeAttribute:"a",listType:"numbered"},{listStyle:"upper-latin",typeAttribute:"A",listType:"numbered"},{listStyle:"arabic-indic",typeAttribute:null,listType:"numbered"}];for(const{listStyle:e,typeAttribute:t,listType:o}of G_)W_[e]=o,U_[e]=t,t&&(K_[t]=e);class J_ extends wc{constructor(e){super(e),this.on("execute",(()=>{this.refresh()}),{priority:"highest"})}refresh(){const e=this._getSelectedItems();this.value=this._getValue(e),this.isEnabled=!!e.length}execute(e={}){this.editor.model.change((t=>{const o=this._getSelectedItems(),i=void 0===e.forceValue?!this._getValue(o):e.forceValue;for(const e of o)i?t.setAttribute("todoListChecked",!0,e):t.removeAttribute("todoListChecked",e)}))}_getValue(e){return e.every((e=>e.getAttribute("todoListChecked")))}_getSelectedItems(){const e=this.editor.model,t=e.schema,o=e.document.selection.getFirstRange(),i=o.start.parent,n=[];t.checkAttribute(i,"todoListChecked")&&n.push(...Ky(i));for(const e of o.getItems({shallow:!0}))t.checkAttribute(e,"todoListChecked")&&!n.includes(e)&&n.push(...Ky(e));return n}}class Z_ extends jn{domEventType=["change"];onDomEvent(e){if(e.target){const t=this.view.domConverter.mapDomToView(e.target);t&&t.is("element","input")&&"checkbox"==t.getAttribute("type")&&t.findAncestor({classes:"todo-list__label"})&&this.fire("todoCheckboxChange",e)}}}const Q_=Wt("Ctrl+Enter");class Y_ extends fc{static get pluginName(){return"TodoListEditing"}static get isOfficialPlugin(){return!0}static get requires(){return[z_]}init(){const e=this.editor,t=e.model,o=e.editing,i=e.plugins.get(z_),n=e.config.get("list.multiBlock")?"paragraph":"listItem";e.commands.add("todoList",new h_(e,"todo")),e.commands.add("checkTodoList",new J_(e)),o.view.addObserver(Z_),t.schema.extend("$listItem",{allowAttributes:"todoListChecked"}),t.schema.addAttributeCheck((e=>{const t=e.last;if(!t.getAttribute("listItemId")||"todo"!=t.getAttribute("listType"))return!1}),"todoListChecked"),e.conversion.for("upcast").add((e=>{e.on("element:input",((e,t,o)=>{const i=t.modelCursor,n=i.parent,s=t.viewItem;if(!o.consumable.test(s,{name:!0}))return;if("checkbox"!=s.getAttribute("type")||!i.isAtStart||!n.hasAttribute("listType"))return;o.consumable.consume(s,{name:!0});const r=o.writer;r.setAttribute("listType","todo",n),t.viewItem.hasAttribute("checked")&&r.setAttribute("todoListChecked",!0,n),t.modelRange=r.createRange(i)})),e.on("element:li",((e,t,o)=>{const{writer:i,schema:n}=o;if(!t.modelRange)return;const s=Array.from(t.modelRange.getItems({shallow:!0})).filter((e=>"todo"===e.getAttribute("listType")&&n.checkAttribute(e,"listItemId"))).reduce(((e,t)=>{const o=t.getAttribute("listItemId");return e.has(o)||e.set(o,Ky(t)),e}),new Map);for(const[,e]of s.entries())if(e.some((e=>e.getAttribute("todoListChecked"))))for(const t of e)i.setAttribute("todoListChecked",!0,t)}),{priority:"low"}),e.on("element:label",X_({name:"label",classes:"todo-list__label"})),e.on("element:label",X_({name:"label",classes:["todo-list__label","todo-list__label_without-description"]})),e.on("element:span",X_({name:"span",classes:"todo-list__label__description"})),e.on("element:ul",function(e){const t=new ui(e);return(e,o,i)=>{const n=t.match(o.viewItem);if(!n)return;const s=n.match;s.name=!1,i.consumable.consume(o.viewItem,s)}}({name:"ul",classes:"todo-list"}))})),e.conversion.for("downcast").elementToElement({model:n,view:(e,{writer:t})=>{if(ek(e,i.getListAttributeNames()))return t.createContainerElement("span",{class:"todo-list__label__description"})},converterPriority:"highest"}),i.registerDowncastStrategy({scope:"list",attributeName:"listType",setAttributeOnDowncast(e,t,o){"todo"==t?e.addClass("todo-list",o):e.removeClass("todo-list",o)}}),i.registerDowncastStrategy({scope:"itemMarker",attributeName:"todoListChecked",createElement(e,t,{dataPipeline:o}){if("todo"!=t.getAttribute("listType"))return null;const i=e.createUIElement("input",{type:"checkbox",...t.getAttribute("todoListChecked")?{checked:"checked"}:null,...o?{disabled:"disabled"}:{tabindex:"-1"}});if(o)return i;const n=e.createContainerElement("span",{contenteditable:"false"},i);return n.getFillerOffset=()=>null,n},canWrapElement:e=>ek(e,i.getListAttributeNames()),createWrapperElement(e,t,{dataPipeline:o}){const n=["todo-list__label"];return ek(t,i.getListAttributeNames())||n.push("todo-list__label_without-description"),e.createAttributeElement(o?"label":"span",{class:n.join(" ")})}}),i.on("checkElement",((e,{modelElement:t,viewElement:o})=>{const n=ek(t,i.getListAttributeNames());o.hasClass("todo-list__label__description")!=n&&(e.return=!0,e.stop())})),i.on("checkElement",((t,{modelElement:o,viewElement:i})=>{const n="todo"==o.getAttribute("listType")&&Zy(o);let s=!1;const r=e.editing.view.createPositionBefore(i).getWalker({direction:"backward"});for(const{item:t}of r){if(t.is("element")&&e.editing.mapper.toModelElement(t))break;t.is("element","input")&&"checkbox"==t.getAttribute("type")&&(s=!0)}s!=n&&(t.return=!0,t.stop())})),i.on("postFixer",((e,{listNodes:t,writer:o})=>{for(const{node:i,previousNodeInList:n}of t){if(!n)continue;if(n.getAttribute("listItemId")!=i.getAttribute("listItemId"))continue;const t=n.hasAttribute("todoListChecked"),s=i.hasAttribute("todoListChecked");s&&!t?(o.removeAttribute("todoListChecked",i),e.return=!0):!s&&t&&(o.setAttribute("todoListChecked",!0,i),e.return=!0)}})),t.document.registerPostFixer((e=>{const o=t.document.differ.getChanges();let i=!1;for(const t of o)if("attribute"==t.type&&"listType"==t.attributeKey){const o=t.range.start.nodeAfter;"todo"==t.attributeOldValue&&o.hasAttribute("todoListChecked")&&(e.removeAttribute("todoListChecked",o),i=!0)}else if("insert"==t.type&&"$text"!=t.name)for(const{item:o}of e.createRangeOn(t.position.nodeAfter))o.is("element")&&"todo"!=o.getAttribute("listType")&&o.hasAttribute("todoListChecked")&&(e.removeAttribute("todoListChecked",o),i=!0);return i})),this.listenTo(o.view.document,"keydown",((t,o)=>{Ht(o)===Q_&&(e.execute("checkTodoList"),t.stop())}),{priority:"high"}),this.listenTo(o.view.document,"todoCheckboxChange",((e,t)=>{const i=t.target;if(!i||!i.is("element","input"))return;const n=o.view.createPositionAfter(i),s=o.mapper.toModelPosition(n).parent;s&&Uy(s)&&"todo"==s.getAttribute("listType")&&this._handleCheckmarkChange(s)})),this.listenTo(o.view.document,"arrowKey",function(e,t){return(o,i)=>{const n=Kt(i.keyCode,t.contentLanguageDirection),s=e.schema,r=e.document.selection;if(!r.isCollapsed)return;const a=r.getFirstPosition(),l=a.parent;if("right"==n&&a.isAtEnd){const t=s.getNearestSelectionRange(e.createPositionAfter(l),"forward");if(!t)return;const n=t.start.parent;n&&Uy(n)&&"todo"==n.getAttribute("listType")&&(e.change((e=>e.setSelection(t))),i.preventDefault(),i.stopPropagation(),o.stop())}else if("left"==n&&a.isAtStart&&Uy(l)&&"todo"==l.getAttribute("listType")){const t=s.getNearestSelectionRange(e.createPositionBefore(l),"backward");if(!t)return;e.change((e=>e.setSelection(t))),i.preventDefault(),i.stopPropagation(),o.stop()}}}(t,e.locale),{context:"$text"}),this.listenTo(o.mapper,"viewToModelPosition",((e,o)=>{const i=o.viewPosition.parent,n=i.is("attributeElement","li")&&0==o.viewPosition.offset,s=tk(i)&&o.viewPosition.offset<=1,r=i.is("element","span")&&"false"==i.getAttribute("contenteditable")&&tk(i.parent);if(!n&&!s&&!r)return;const a=o.modelPosition.nodeAfter;a&&"todo"==a.getAttribute("listType")&&(o.modelPosition=t.createPositionAt(a,0))}),{priority:"low"}),this._initAriaAnnouncements()}_handleCheckmarkChange(e){const t=this.editor,o=t.model,i=Array.from(o.document.selection.getRanges());o.change((o=>{o.setSelection(e,"end"),t.execute("checkTodoList"),o.setSelection(i)}))}_initAriaAnnouncements(){const{model:e,ui:t,t:o}=this.editor;let i=null;t&&e.document.selection.on("change:range",(()=>{const n=e.document.selection.focus.parent,s=ok(i),r=ok(n);s&&!r?t.ariaLiveAnnouncer.announce(o("Leaving a to-do list")):!s&&r&&t.ariaLiveAnnouncer.announce(o("Entering a to-do list")),i=n}))}}function X_(e){const t=new ui(e);return(e,o,i)=>{const n=t.match(o.viewItem);n&&i.consumable.consume(o.viewItem,n.match)&&Object.assign(o,i.convertChildren(o.viewItem,o.modelCursor))}}function ek(e,t){return(e.is("element","paragraph")||e.is("element","listItem"))&&"todo"==e.getAttribute("listType")&&Zy(e)&&function(e,t){for(const o of e.getAttributeKeys())if(!o.startsWith("selection:")&&!t.includes(o))return!1;return!0}(e,t)}function tk(e){return!!e&&e.is("attributeElement")&&e.hasClass("todo-list__label")}function ok(e){return!!e&&(!(!e.is("element","paragraph")&&!e.is("element","listItem"))&&"todo"==e.getAttribute("listType"))}class ik extends fc{static get pluginName(){return"TodoListUI"}static get isOfficialPlugin(){return!0}init(){const e=this.editor.t;q_(this.editor,"todoList",e("To-do List"),'')}}const nk=Symbol("isOPCodeBlock");function sk(e){return!!e.getCustomProperty(nk)&&ip(e)}function rk(e){const t=e.getSelectedElement();return!(!t||!sk(t))}function ak(e,t,o){const i=t.createContainerElement("pre",{title:window.I18n.t("js.editor.macro.toolbar_help")});return lk(t,e,i),function(e,t,o){return t.setCustomProperty(nk,!0,e),np(e,t,{label:o})}(i,t,o)}function lk(e,t,o){const i=(t.getAttribute("opCodeblockLanguage")||"language-text").replace(/^language-/,""),n=e.createContainerElement("div",{class:"op-uc-code-block--language"});ck(e,i,n,"text"),e.insert(e.createPositionAt(o,0),n);ck(e,t.getAttribute("opCodeblockContent"),o,"(empty)")}function ck(e,t,o,i){const n=e.createText(t||i);e.insert(e.createPositionAt(o,0),n)}class dk extends jn{constructor(e){super(e),this.domEventType="dblclick"}onDomEvent(e){this.fire(e.type,e)}}class uk extends fc{static get pluginName(){return"CodeBlockEditing"}init(){const e=this.editor,t=e.model.schema,o=e.conversion,i=e.editing.view,n=i.document,s=Mp(e);var r,a;t.register("codeblock",{isObject:!0,isBlock:!0,allowContentOf:"$block",allowWhere:["$root","$block"],allowIn:["$root"],allowAttributes:["opCodeblockLanguage","opCodeblockContent"]}),o.for("upcast").add(function(){return t=>{t.on("element:pre",e,{priority:"high"})};function e(e,t,o){if(!o.consumable.test(t.viewItem,{name:!0}))return;const i=Array.from(t.viewItem.getChildren()).find((e=>e.is("element","code")));if(!i||!o.consumable.consume(i,{name:!0}))return;const n=o.writer.createElement("codeblock");o.writer.setAttribute("opCodeblockLanguage",i.getAttribute("class"),n);const s=o.splitToAllowedParent(n,t.modelCursor);if(s){o.writer.insert(n,s.position);const e=i.getChild(0);if(e){o.consumable.consume(e,{name:!0});const t=e.data.replace(/\n$/,"");o.writer.setAttribute("opCodeblockContent",t,n)}t.modelRange=o.writer.createRange(o.writer.createPositionBefore(n),o.writer.createPositionAfter(n)),t.modelCursor=t.modelRange.end}}}()),o.for("editingDowncast").elementToElement({model:"codeblock",view:(e,{writer:t})=>ak(e,t,"Code block")}).add(function(){return t=>{t.on("attribute:opCodeblockContent",e),t.on("attribute:opCodeblockLanguage",e)};function e(e,t,o){const i=t.item;o.consumable.consume(t.item,e.name);const n=o.mapper.toViewElement(i);o.writer.remove(o.writer.createRangeOn(n.getChild(1))),o.writer.remove(o.writer.createRangeOn(n.getChild(0))),lk(o.writer,i,n)}}()),o.for("dataDowncast").add(function(){return t=>{t.on("insert:codeblock",e,{priority:"high"})};function e(e,t,o){const i=t.item,n=i.getAttribute("opCodeblockLanguage")||"language-text",s=i.getAttribute("opCodeblockContent");o.consumable.consume(i,"insert");const r=o.writer,a=r.createContainerElement("pre"),l=r.createContainerElement("div",{class:"op-uc-code-block--language"}),c=r.createContainerElement("code",{class:n}),d=r.createText(n),u=r.createText(s);r.insert(r.createPositionAt(c,0),u),r.insert(r.createPositionAt(l,0),d),r.insert(r.createPositionAt(a,0),l),r.insert(r.createPositionAt(a,0),c),o.mapper.bindElements(i,c),o.mapper.bindElements(i,a),o.mapper.bindElements(i,l);const h=o.mapper.toViewPosition(t.range.start);r.insert(h,a),e.stop()}}()),this.editor.editing.mapper.on("viewToModelPosition",(r=this.editor.model,a=e=>e.hasClass("op-uc-code-block"),(e,t)=>{const{mapper:o,viewPosition:i}=t,n=o.findMappedViewAncestor(i);if(!a(n))return;const s=o.toModelElement(n);t.modelPosition=r.createPositionAt(s,i.isAtStart?"before":"after")})),i.addObserver(dk),this.listenTo(n,"dblclick",((t,o)=>{let i=o.target,n=o.domEvent;if(n.shiftKey||n.altKey||n.metaKey)return;if(!sk(i)&&(i=i.findAncestor(sk),!i))return;o.preventDefault(),o.stopPropagation();const r=e.editing.mapper.toModelElement(i),a=s.services.macros,l=r.getAttribute("opCodeblockLanguage"),c=r.getAttribute("opCodeblockContent");a.editCodeBlock(c,l).then((t=>e.model.change((e=>{e.setAttribute("opCodeblockLanguage",t.languageClass,r),e.setAttribute("opCodeblockContent",t.content,r)}))))})),e.ui.componentFactory.add("insertCodeBlock",(t=>{const o=new Lu(t);return o.set({label:window.I18n.t("js.editor.macro.code_block.button"),icon:'\n\n',tooltip:!0}),o.on("execute",(()=>{s.services.macros.editCodeBlock().then((t=>e.model.change((o=>{const i=o.createElement("codeblock");o.setAttribute("opCodeblockLanguage",t.languageClass,i),o.setAttribute("opCodeblockContent",t.content,i),e.model.insertContent(i,e.model.document.selection)}))))})),o}))}}class hk extends fc{static get requires(){return[Qm]}static get pluginName(){return"CodeBlockToolbar"}init(){const e=this.editor,t=this.editor.model,o=Mp(e);jp(e,"opEditCodeBlock",(e=>{const i=o.services.macros,n=e.getAttribute("opCodeblockLanguage"),s=e.getAttribute("opCodeblockContent");i.editCodeBlock(s,n).then((o=>t.change((t=>{t.setAttribute("opCodeblockLanguage",o.languageClass,e),t.setAttribute("opCodeblockContent",o.content,e)}))))}))}afterInit(){$p(this,this.editor,"OPCodeBlock",rk)}}function mk(e){return e.__currentlyDisabled=e.__currentlyDisabled||[],e.ui.view.toolbar?e.ui.view.toolbar.items._items:[]}function gk(e,t){mk(e).forEach((o=>{let i=o;o instanceof bh?i=o.buttonView:o!==t&&Object.prototype.hasOwnProperty.call(o,"isEnabled")||(i=null),i&&(i.isEnabled?i.isEnabled=!1:e.__currentlyDisabled.push(i))}))}function pk(e){mk(e).forEach((t=>{let o=t;t instanceof bh&&(o=t.buttonView),e.__currentlyDisabled.indexOf(o)<0&&(o.isEnabled=!0)})),e.__currentlyDisabled=[]}class fk{constructor(e){this.response=e}get statusCode(){return this.response.status}get redirected(){return this.response.redirected}get ok(){return this.response.ok}get unauthenticated(){return 401===this.statusCode}get unprocessableEntity(){return 422===this.statusCode}get authenticationURL(){return this.response.headers.get("WWW-Authenticate")}get contentType(){return(this.response.headers.get("Content-Type")||"").replace(/;.*$/,"")}get headers(){return this.response.headers}get html(){return this.contentType.match(/^(application|text)\/(html|xhtml\+xml)$/)?this.text:Promise.reject(new Error(`Expected an HTML response but got "${this.contentType}" instead`))}get json(){return this.contentType.match(/^application\/.*json$/)?this.responseJson||(this.responseJson=this.response.json()):Promise.reject(new Error(`Expected a JSON response but got "${this.contentType}" instead`))}get text(){return this.responseText||(this.responseText=this.response.text())}get isTurboStream(){return this.contentType.match(/^text\/vnd\.turbo-stream\.html/)}get isScript(){return this.contentType.match(/\b(?:java|ecma)script\b/)}async renderTurboStream(){if(!this.isTurboStream)return Promise.reject(new Error(`Expected a Turbo Stream response but got "${this.contentType}" instead`));window.Turbo?await window.Turbo.renderStreamMessage(await this.text):console.warn("You must set `window.Turbo = Turbo` to automatically process Turbo Stream events with request.js")}async activeScript(){if(!this.isScript)return Promise.reject(new Error(`Expected a Script response but got "${this.contentType}" instead`));{const e=document.createElement("script"),t=document.querySelector("meta[name=csp-nonce]");if(t){const o=""===t.nonce?t.content:t.nonce;o&&e.setAttribute("nonce",o)}e.innerHTML=await this.text,document.body.appendChild(e)}}}class bk{static register(e){this.interceptor=e}static get(){return this.interceptor}static reset(){this.interceptor=void 0}}function wk(e){const t=document.head.querySelector(`meta[name="${e}"]`);return t&&t.content}class yk{constructor(e,t,o={}){this.method=e,this.options=o,this.originalUrl=t.toString()}async perform(){try{const e=bk.get();e&&await e(this)}catch(e){console.error(e)}const e=window.Turbo?window.Turbo.fetch:window.fetch,t=new fk(await e(this.url,this.fetchOptions));if(t.unauthenticated&&t.authenticationURL)return Promise.reject(window.location.href=t.authenticationURL);t.isScript&&await t.activeScript();return(t.ok||t.unprocessableEntity)&&t.isTurboStream&&await t.renderTurboStream(),t}addHeader(e,t){const o=this.additionalHeaders;o[e]=t,this.options.headers=o}sameHostname(){if(!this.originalUrl.startsWith("http:")&&!this.originalUrl.startsWith("https:"))return!0;try{return new URL(this.originalUrl).hostname===window.location.hostname}catch(e){return!0}}get fetchOptions(){return{method:this.method.toUpperCase(),headers:this.headers,body:this.formattedBody,signal:this.signal,credentials:this.credentials,redirect:this.redirect,keepalive:this.keepalive}}get headers(){const e={"X-Requested-With":"XMLHttpRequest","Content-Type":this.contentType,Accept:this.accept};return this.sameHostname()&&(e["X-CSRF-Token"]=this.csrfToken),function(e){const t={};for(const o in e){const i=e[o];void 0!==i&&(t[o]=i)}return t}(Object.assign(e,this.additionalHeaders))}get csrfToken(){return function(e){const t=document.cookie?document.cookie.split("; "):[],o=`${encodeURIComponent(e)}=`,i=t.find((e=>e.startsWith(o)));if(i){const e=i.split("=").slice(1).join("=");if(e)return decodeURIComponent(e)}}(wk("csrf-param"))||wk("csrf-token")}get contentType(){return this.options.contentType?this.options.contentType:null==this.body||this.body instanceof window.FormData?void 0:this.body instanceof window.File?this.body.type:"application/json"}get accept(){switch(this.responseKind){case"html":return"text/html, application/xhtml+xml";case"turbo-stream":return"text/vnd.turbo-stream.html, text/html, application/xhtml+xml";case"json":return"application/json, application/vnd.api+json";case"script":return"text/javascript, application/javascript";default:return"*/*"}}get body(){return this.options.body}get query(){const e=(this.originalUrl.split("?")[1]||"").split("#")[0],t=new URLSearchParams(e);let o=this.options.query;var i;o instanceof window.FormData?(i=o,o=[...i].reduce(((e,[t,o])=>e.concat("string"==typeof o?[[t,o]]:[])),[])):o=o instanceof window.URLSearchParams?o.entries():Object.entries(o||{}),function(e,t){for(const[o,i]of t)i instanceof window.File||(e.has(o)&&!o.includes("[]")?(e.delete(o),e.set(o,i)):e.append(o,i))}(t,o);const n=t.toString();return n.length>0?`?${n}`:""}get url(){return this.originalUrl.split("?")[0].split("#")[0]+this.query}get responseKind(){return this.options.responseKind||"html"}get signal(){return this.options.signal}get redirect(){return this.options.redirect||"follow"}get credentials(){return this.options.credentials||"same-origin"}get keepalive(){return this.options.keepalive||!1}get additionalHeaders(){return this.options.headers||{}}get formattedBody(){const e="[object String]"===Object.prototype.toString.call(this.body);return"application/json"===this.headers["Content-Type"]&&!e?JSON.stringify(this.body):this.body}}async function _k(e,t){return new yk("get",e,t).perform()}function kk(e,t){const{modelAttribute:o,styleName:i,attributeName:n,attributeType:s,viewElement:r,defaultValue:a,shouldUpcast:l=()=>!0,reduceBoxSides:c=!1}=t;e.for("upcast").attributeToAttribute({view:{name:r,styles:{[i]:/[\s\S]+/}},model:{key:o,value:(e,t,o)=>{if(!l(e))return;const n=xk(a,"",o),s=e.getNormalizedStyle(i),r=c?Ek(s):s;if(n!==r)return r;t.consumable.consume(e,{styles:i})}}}),n&&e.for("upcast").attributeToAttribute({view:{name:r,attributes:{[n]:/.+/}},model:{key:o,value:(e,t,o)=>{if("figure"==e.name||e.hasStyle(i)||"table"==e.name&&"figure"==e.parent.name&&e.parent.hasStyle(i))return;const r=xk(a,"",o);let l=e.getAttribute(n);if(l&&"length"==s){const e=parseFloat(l);l=isNaN(e)?r:e+(l.includes("%")?"%":"px")}if(r!==l)return l;t.consumable.consume(e,{attributes:n})}}})}function vk(e,t,o,i){const{conversion:n}=e;n.for("upcast").add((e=>{e.on(`element:${t}`,((e,t,n)=>{const{modelRange:s,viewItem:r}=t;if(!s)return;const a=["border-top-width","border-top-color","border-top-style","border-bottom-width","border-bottom-color","border-bottom-style","border-right-width","border-right-color","border-right-style","border-left-width","border-left-color","border-left-style"].filter((e=>r.hasStyle(e))),l=r.is("element","table")?r:r.findAncestor("table"),c=l.hasAttribute("border");if(!a.length&&!c)return;const d={styles:a};if(!n.consumable.test(r,d))return;const u=to(s.getItems({shallow:!0})),h=u.findAncestor("table",{includeSelf:!0});let m=i;h&&"layout"==h.getAttribute("tableType")&&(m={style:"none",color:"",width:""}),n.consumable.consume(r,d);const g={style:r.getNormalizedStyle("border-style"),color:r.getNormalizedStyle("border-color"),width:r.getNormalizedStyle("border-width")};if(c&&n.consumable.test(l,{attributes:"border"})){const e=parseFloat(l.getAttribute("border")||"1"),t=Number.isNaN(e)||!Number.isFinite(e)||e<0||"table"!=r.name&&e>1?"1px":`${e}px`;g.width={top:t,bottom:t,right:t,left:t,...g.width||{}},r.is("element","table")&&n.consumable.consume(l,{attributes:"border"})}const p={style:Ek(g.style),color:Ek(g.color),width:Ek(g.width)};p.style!==m.style&&n.writer.setAttribute(o.style,p.style,u),p.color!==m.color&&n.writer.setAttribute(o.color,p.color,u),p.width!==m.width&&n.writer.setAttribute(o.width,p.width,u)}))}))}function Ck(e,t){const{modelElement:o,modelAttribute:i,styleName:n}=t;e.for("downcast").attributeToAttribute({model:{name:o,key:i},view:e=>({key:"style",value:{[n]:e}})})}function Ak(e,t){const{modelAttribute:o,styleName:i}=t;e.for("downcast").add((e=>{e.on(`attribute:${o}:table`,((e,t,o)=>{const{item:n,attributeNewValue:s}=t,{mapper:r,writer:a}=o;if(!o.consumable.consume(t.item,e.name))return;const l=Array.from(r.toViewElement(n).getChildren()).find((e=>e.is("element","table")));s?a.setStyle(i,s,l):a.removeStyle(i,l)}))}))}function xk(e,t,o){const i=o.modelRange&&to(o.modelRange.getItems({shallow:!0})),n=i&&i.is("element")&&i.findAncestor("table",{includeSelf:!0});return n&&"layout"===n.getAttribute("tableType")?t:e}function Ek(e){if(!e)return;const t=["top","right","bottom","left"];if(!t.every((t=>e[t])))return e;const o=e.top;return t.every((t=>e[t]===o))?o:e}function Tk(e,t,o){const{conversion:i}=e;i.for("upcast").add((e=>{e.on(`element:${t}`,((e,t,i)=>{const{modelRange:n,viewItem:s}=t;if(!n)return;if(s.is("element","table"))return void i.consumable.consume(s,{attributes:"cellpadding"});const r=s.findAncestor("table");if(!r.hasAttribute("cellpadding")||!i.consumable.test(r,{attributes:"cellpadding"}))return;const a=n?.start?.nodeAfter,l=parseFloat(r.getAttribute("cellpadding")||"1"),c=Number.isNaN(l)||!Number.isFinite(l)||l<0?"0px":`${l}px`,d=a.getAttribute("tableCellPadding");if(d){if("object"==typeof d){const e={...o!==c&&{top:c},...o!==c&&{right:c},...o!==c&&{bottom:c},...o!==c&&{left:c},...d};i.writer.setAttribute("tableCellPadding",e,a)}}else o!==c&&i.writer.setAttribute("tableCellPadding",c,a)}),{priority:"low"})}))}const Pk={className:"table-style-align-left"},Sk={className:"table-style-align-center"},Ik={className:"table-style-align-right"},Rk={className:"table-style-block-align-left"},Ok={className:"table-style-block-align-right"},Vk=[{view:{name:/^(table|figure)$/,styles:{float:/^(left|none|right)$/}},getAlign:e=>{let t=e.getStyle("float");return"none"===t&&(t="center"),t},getConsumables(e){const t=e.getStyle("float"),o=["float"];return"left"===t&&e.hasStyle("margin-right")?o.push("margin-right"):"right"===t&&e.hasStyle("margin-left")&&o.push("margin-left"),{styles:o}}},{view:{name:/^(table|figure)$/,styles:{"margin-left":"auto","margin-right":"auto"}},getAlign:()=>"center",getConsumables:()=>({styles:["margin-left","margin-right"]})},{view:{name:/^(table|figure)$/,key:"class",value:"table-style-align-left"},getAlign:()=>"left",getConsumables:()=>({classes:Pk.className})},{view:{name:/^(table|figure)$/,key:"class",value:Ik.className},getAlign:()=>"right",getConsumables:()=>({classes:Ik.className})},{view:{name:/^(table|figure)$/,key:"class",value:Sk.className},getAlign:()=>"center",getConsumables:()=>({classes:Sk.className})},{view:{name:/^(table|figure)$/,key:"class",value:Rk.className},getAlign:()=>"blockLeft",getConsumables:()=>({classes:Rk.className})},{view:{name:/^(table|figure)$/,key:"class",value:Ok.className},getAlign:()=>"blockRight",getConsumables:()=>({classes:Ok.className})},{view:{name:/^(table|figure)$/,styles:{"margin-left":"0","margin-right":"auto"}},getAlign:()=>"blockLeft",getConsumables:()=>({styles:["margin-left","margin-right"]})},{view:{name:/^(table|figure)$/,styles:{"margin-left":"auto","margin-right":"0"}},getAlign:()=>"blockRight",getConsumables:()=>({styles:["margin-left","margin-right"]})},{view:{name:"table",attributes:{align:/^(left|center|right)$/}},getAlign:e=>e.getAttribute("align"),getConsumables:()=>({attributes:"align"})}],Dk={center:{align:"center",style:"margin-left: auto; margin-right: auto;",className:"table-style-align-center"},left:{align:"left",style:"float: left;",className:"table-style-align-left"},right:{align:"right",style:"float: right;",className:"table-style-align-right"},blockLeft:{align:void 0,style:"margin-left: 0; margin-right: auto;",className:Rk.className},blockRight:{align:void 0,style:"margin-left: auto; margin-right: 0;",className:Ok.className}};class Fk{_table;_startRow;_endRow;_startColumn;_endColumn;_includeAllSlots;_skipRows;_row;_rowIndex;_column;_cellIndex;_spannedCells;_nextCellAtColumn;_jumpedToStartRow=!1;constructor(e,t={}){this._table=e,this._startRow=void 0!==t.row?t.row:t.startRow||0,this._endRow=void 0!==t.row?t.row:t.endRow,this._startColumn=void 0!==t.column?t.column:t.startColumn||0,this._endColumn=void 0!==t.column?t.column:t.endColumn,this._includeAllSlots=!!t.includeAllSlots,this._skipRows=new Set,this._row=0,this._rowIndex=0,this._column=0,this._cellIndex=0,this._spannedCells=new Map,this._nextCellAtColumn=-1}[Symbol.iterator](){return this}next(){this._canJumpToStartRow()&&this._jumpToNonSpannedRowClosestToStartRow();const e=this._table.getChild(this._rowIndex);if(!e||this._isOverEndRow())return{done:!0,value:void 0};if(!e.is("element","tableRow"))return this._rowIndex++,this.next();if(this._isOverEndColumn())return this._advanceToNextRow();let t=null;const o=this._getSpanned();if(o)this._includeAllSlots&&!this._shouldSkipSlot()&&(t=this._formatOutValue(o.cell,o.row,o.column));else{const o=e.getChild(this._cellIndex);if(!o)return this._advanceToNextRow();const i=parseInt(o.getAttribute("colspan")||"1"),n=parseInt(o.getAttribute("rowspan")||"1");(i>1||n>1)&&this._recordSpans(o,n,i),this._shouldSkipSlot()||(t=this._formatOutValue(o)),this._nextCellAtColumn=this._column+i}return this._column++,this._column==this._nextCellAtColumn&&this._cellIndex++,t||this.next()}skipRow(e){this._skipRows.add(e)}_advanceToNextRow(){return this._row++,this._rowIndex++,this._column=0,this._cellIndex=0,this._nextCellAtColumn=-1,this.next()}_isOverEndRow(){return void 0!==this._endRow&&this._row>this._endRow}_isOverEndColumn(){return void 0!==this._endColumn&&this._column>this._endColumn}_formatOutValue(e,t=this._row,o=this._column){return{done:!1,value:new Mk(this,e,t,o)}}_shouldSkipSlot(){const e=this._skipRows.has(this._row),t=this._rowthis._endColumn;return e||t||o||i}_getSpanned(){const e=this._spannedCells.get(this._row);return e&&e.get(this._column)||null}_recordSpans(e,t,o){const i={cell:e,row:this._row,column:this._column};for(let e=this._row;e0&&!this._jumpedToStartRow}_jumpToNonSpannedRowClosestToStartRow(){const e=this._getRowLength(0);for(let t=this._startRow;!this._jumpedToStartRow;t--)e===this._getRowLength(t)&&(this._row=t,this._rowIndex=t,this._jumpedToStartRow=!0)}_getRowLength(e){return[...this._table.getChild(e).getChildren()].reduce(((e,t)=>e+parseInt(t.getAttribute("colspan")||"1")),0)}}class Mk{cell;row;column;cellAnchorRow;cellAnchorColumn;_cellIndex;_rowIndex;_table;constructor(e,t,o,i){this.cell=t,this.row=e._row,this.column=e._column,this.cellAnchorRow=o,this.cellAnchorColumn=i,this._cellIndex=e._cellIndex,this._rowIndex=e._rowIndex,this._table=e._table}get isAnchor(){return this.row===this.cellAnchorRow&&this.column===this.cellAnchorColumn}get cellWidth(){return parseInt(this.cell.getAttribute("colspan")||"1")}get cellHeight(){return parseInt(this.cell.getAttribute("rowspan")||"1")}get rowIndex(){return this._rowIndex}getPositionBefore(){return this._table.root.document.model.createPositionAt(this._table.getChild(this.row),this._cellIndex)}}function Nk(e){return"header"===e||"header-row"===e||"header-column"===e}function Bk(e,t,o,i,n=1){null!=t&&null!=n&&t>n?i.setAttribute(e,t,o):i.removeAttribute(e,o)}function Lk(e,t,o={}){const i=e.createElement("tableCell",o);return e.insertElement("paragraph",i),e.insert(i,t),i}function zk(e,t){const o=t.parent.parent,i=parseInt(o.getAttribute("headingColumns")||"0"),{column:n}=e.getCellLocation(t);return!!i&&n0){Bk("headingRows",s-o,e,n,0)}const r=parseInt(t.getAttribute("headingColumns")||"0");if(r>0){Bk("headingColumns",r-i,e,n,0)}}(a,e,i,n,o),function(e,t,o,i,n){const s=Array.from(t.getChildren()).reduce(((e,t)=>t.is("element","tableRow")?e+1:e),0),r=parseInt(t.getAttribute("footerRows")||"0"),a=s-r;if(r<1)return;let l=0;i>=a&&(l=i-Math.max(a,o)+1);Bk("footerRows",l,e,n,0)}(a,e,i,s,o),a}function Uk(e,t,o=0){const i=[],n=new Fk(e,{startRow:o,endRow:t-1});for(const e of n){const{row:o,cellHeight:n}=e;o1&&(a.rowspan=l);const c=parseInt(e.getAttribute("colspan")||"1");c>1&&(a.colspan=c);const d=s+r,u=[...new Fk(n,{startRow:s,endRow:d,includeAllSlots:!0})];let h,m=null;for(const t of u){const{row:i,column:n,cell:s}=t;s===e&&void 0===h&&(h=n),void 0!==h&&h===n&&i===d&&(m=Lk(o,t.getPositionBefore(),a))}return Bk("rowspan",r,e,o),m}function Gk(e,t){const o=[],i=new Fk(e);for(const e of i){const{column:i,cellWidth:n}=e;i1&&(s.colspan=r);const a=parseInt(e.getAttribute("rowspan")||"1");a>1&&(s.rowspan=a);const l=Lk(i,i.createPositionAfter(e),s);return Bk("colspan",n,e,i),l}function Zk(e,t,o,i,n,s){const r=parseInt(e.getAttribute("colspan")||"1"),a=parseInt(e.getAttribute("rowspan")||"1");if(o+r-1>n){Bk("colspan",n-o+1,e,s,1)}if(t+a-1>i){Bk("rowspan",i-t+1,e,s,1)}}function Qk(e,t){const o=t.getColumns(e),i=new Array(o).fill(0);for(const{column:t}of new Fk(e))i[t]++;const n=i.reduce(((e,t,o)=>t?e:[...e,o]),[]);if(n.length>0){const o=n[n.length-1];return t.removeColumns(e,{at:o}),!0}return!1}function Yk(e,t){const o=[],i=t.getRows(e);for(let t=0;t0){const i=o[o.length-1];return t.removeRows(e,{at:i}),!0}return!1}function Xk(e,t){Qk(e,t)||Yk(e,t)}function ev(e,t){const o=Array.from(new Fk(e,{startColumn:t.firstColumn,endColumn:t.lastColumn,row:t.lastRow}));if(o.every((({cellHeight:e})=>1===e)))return t.lastRow;const i=o[0].cellHeight-1;return t.lastRow+i}function tv(e,t){const o=Array.from(new Fk(e,{startRow:t.firstRow,endRow:t.lastRow,column:t.lastColumn}));if(o.every((({cellWidth:e})=>1===e)))return t.lastColumn;const i=o[0].cellWidth-1;return t.lastColumn+i}function ov(e){for(const t of e.getChildren())if(t.is("element","table"))return t}function iv(e){return t=>{t.on("element:table",((t,o,i)=>{const n=o.viewItem;if(!i.consumable.test(n,{name:!0}))return;const{rows:s,headingRows:r,headingColumns:a,footerRows:l}=function(e){let t,o=!0;const i=[],n=[],s=[];let r=null,a=null;const l=Array.from(e.getChildren());for(let e=0;ee.is("element","tr")));let d=null,u=null;for(const h of c){const m=Array.from(h.getChildren()).filter((e=>e.is("element","td")||e.is("element","th")));if("tfoot"===t.name){a||={element:t,rows:c},o=!1;const i=a.element===t;if(!i&&null===u)for(let t=e;t0&&(null===d||m.length===d)&&m.every((e=>e.is("element","th")))&&o?(i.push(h),o=!0):(n.push(h),o=!1),d=Math.max(d||0,m.length)}}const c=function(e){let t=new Map,o=0;const i=e.map((e=>{const i=[],n=Array.from(e.getChildren()).filter((e=>"th"===e.name||"td"===e.name)),s=new Map;for(;n.length||i.length0)i.push(e.cell);else{const e=n.shift();if(!e){i.push(null);continue}{const t=parseInt(e.getAttribute("colspan")||"1"),o=parseInt(e.getAttribute("rowspan")||"1");for(let n=0;n1&&s.set(i.length,{cell:e,remaining:o-1}),i.push(e)}}}for(const[e,o]of t.entries())o.remaining-=1,o.remaining>0&&!s.has(e)&&s.set(e,o);return t=s,o=Math.max(o,i.length),i}));for(const e of i)for(;e.lengthi.convertItem(e,i.writer.createPositionAt(d,"end")))),i.convertChildren(n,i.writer.createPositionAt(d,"end")),d.isEmpty){const e=i.writer.createElement("tableRow");i.writer.insert(e,i.writer.createPositionAt(d,"end")),Lk(i.writer,i.writer.createPositionAt(e,"end"))}i.updateConversionResult(d,o)}}))}}function nv(e){return t=>{t.on(`element:${e}`,((e,t,{writer:o})=>{if(!t.modelRange)return;const i=t.modelRange.start.nodeAfter,n=o.createPositionAt(i,0);if(t.viewItem.isEmpty)return void o.insertElement("paragraph",n);const s=Array.from(i.getChildren());if(s.every((e=>e.is("element","$marker")))){const e=o.createElement("paragraph");o.insert(e,o.createPositionAt(i,0));for(const t of s)o.move(o.createRangeOn(t),o.createPositionAt(e,"end"))}}),{priority:"low"})}}function sv(e){if(e.is("element","tableColumnGroup"))return e;const t=e.getChildren();return Array.from(t).find((e=>e.is("element","tableColumnGroup")))}function rv(e){const t=sv(e);return t?Array.from(t.getChildren()):[]}class av extends fc{static get pluginName(){return"TableUtils"}static get isOfficialPlugin(){return!0}init(){this.decorate("insertColumns"),this.decorate("insertRows")}getCellLocation(e){const t=e.parent,o=t.parent,i=o.getChildIndex(t),n=new Fk(o,{row:i});for(const{cell:t,row:o,column:i}of n)if(t===e)return{row:o,column:i}}createTable(e,t){const o=e.createElement("table");return lv(e,o,0,t.rows||2,t.columns||2),t.footerRows&&this.setFooterRowsCount(e,o,t.footerRows),t.headingRows&&this.setHeadingRowsCount(e,o,t.headingRows),t.headingColumns&&this.setHeadingColumnsCount(e,o,t.headingColumns),o}insertRows(e,t={}){const o=this.editor.model,i=t.at||0,n=t.rows||1,s=void 0!==t.copyStructureFromAbove,r=t.copyStructureFromAbove?i-1:i,a=Hk(this.editor),l=!!this.editor.config.get("table.tableCellProperties.scopedHeaders"),c=this.getRows(e),d=this.getColumns(e);if(i>c)throw new fe("tableutils-insertrows-insert-out-of-range",this,{options:t});o.change((t=>{let o=e.getAttribute("headingRows")||0,u=e.getAttribute("footerRows")||0;if(o>i&&(o+=n),u&&i>c-u&&(u+=n),s||0!==i&&i!==c){const o=s?Math.max(i,r):i,c=new Fk(e,{endRow:o}),u=new Array(d).fill(1);for(const{row:e,column:o,cellHeight:a,cellWidth:l,cell:d}of c){const c=e+a-1,h=e<=r&&r<=c;e0){const n=Lk(t,c,r>1?{colspan:r}:void 0);a&&hv({table:e,writer:t,cell:n,row:i+o,column:s,scopedHeaders:l})}s+=Math.abs(r)-1}}}else{const o=lv(t,e,i,n,d);if(a)for(let n=0;n{let o=e.getAttribute("headingColumns");in-1)throw new fe("tableutils-removerows-row-index-out-of-range",this,{table:e,options:t});o.change((t=>{const o={first:s,last:r},{cellsToMove:i,cellsToTrim:a}=function(e,{first:t,last:o}){const i=new Map,n=[];for(const{row:s,column:r,cellHeight:a,cell:l}of new Fk(e,{endRow:o})){const e=s+a-1;if(s>=t&&s<=o&&e>o){const e=a-(o-s+1);i.set(r,{cell:l,rowspan:e})}if(s=t){let i;i=e>=o?o-t+1:e-t+1,n.push({cell:l,rowspan:a-i})}}return{cellsToMove:i,cellsToTrim:n}}(e,o);if(i.size){!function(e,t,o,i){const n=new Fk(e,{includeAllSlots:!0,row:t}),s=[...n],r=e.getChild(t);let a;for(const{column:e,cell:t,isAnchor:n}of s)if(o.has(e)){const{cell:t,rowspan:n}=o.get(e),s=a?i.createPositionAfter(a):i.createPositionAt(r,0);i.move(i.createRangeOn(t),s),Bk("rowspan",n,t,i),a=t}else n&&(a=t)}(e,r+1,i,t)}for(let o=r;o>=s;o--)t.remove(e.getChild(o));for(const{rowspan:e,cell:o}of a)Bk("rowspan",e,o,t);if(function(e,{first:t,last:o},i){const n=e.getAttribute("headingRows")||0;if(t=r){Bk("footerRows",o>=r?s-(i-o+1):t-1-i,e,n,0)}}(e,n,o,t),Qk(e,this)||Yk(e,this),Hk(this.editor)){let o=e.getAttribute("headingRows")||0;const i=this.getRows(e);for(;o{!function(e,t,o){const i=e.getAttribute("headingColumns")||0;if(i&&t.first=i;n--){for(const{cell:o,column:i,cellWidth:s}of[...new Fk(e)])i<=n&&s>1&&i+s>n?Bk("colspan",s-1,o,t):i===n&&t.remove(o);if(o[n]){const e=0===n?o[1]:o[n-1],i=parseFloat(o[n].getAttribute("columnWidth")),s=parseFloat(e.getAttribute("columnWidth"));t.remove(o[n]),t.setAttribute("columnWidth",i+s+"%",e)}}if(Yk(e,this)||Qk(e,this),Hk(this.editor)){let o=e.getAttribute("headingColumns")||0;const i=this.getColumns(e);for(;o{if(s>1){const{newCellsSpan:i,updatedSpan:r}=dv(s,t);Bk("colspan",r,e,o);const a={};i>1&&(a.colspan=i),n>1&&(a.rowspan=n);cv(s>t?t-1:s-1,o,o.createPositionAfter(e),a)}if(st===e)),c=a.filter((({cell:t,cellWidth:o,column:i})=>t!==e&&i===l||il));for(const{cell:e,cellWidth:t}of c)o.setAttribute("colspan",t+r,e);const d={};n>1&&(d.rowspan=n),cv(r,o,o.createPositionAfter(e),d);const u=i.getAttribute("headingColumns")||0;u>l&&Bk("headingColumns",u+r,i,o)}}))}splitCellHorizontally(e,t=2){const o=this.editor.model,i=e.parent,n=i.parent,s=n.getChildIndex(i),r=parseInt(e.getAttribute("rowspan")||"1"),a=parseInt(e.getAttribute("colspan")||"1");o.change((o=>{if(r>1){const i=[...new Fk(n,{startRow:s,endRow:s+r-1,includeAllSlots:!0})],{newCellsSpan:l,updatedSpan:c}=dv(r,t);Bk("rowspan",c,e,o);const{column:d}=i.find((({cell:t})=>t===e)),u={};l>1&&(u.rowspan=l),a>1&&(u.colspan=a);let h=0;for(const e of i){const{column:t,row:i}=e,n=t===d;h>=l&&n&&(h=0),i>=s+c&&n&&(h||cv(1,o,e.getPositionBefore(),u),h++)}}if(rs){const e=n+i;o.setAttribute("rowspan",e,t)}const d={};a>1&&(d.colspan=a),lv(o,n,s+1,i,1,d);const u=n.getAttribute("headingRows")||0;u>s&&Bk("headingRows",u+i,n,o);const h=n.getAttribute("footerRows")||0;l-h<=s&&Bk("footerRows",h+i,n,o)}}))}getColumns(e){return[...e.getChild(0).getChildren()].filter((e=>e.is("element","tableCell"))).reduce(((e,t)=>e+parseInt(t.getAttribute("colspan")||"1")),0)}getRows(e){return Array.from(e.getChildren()).reduce(((e,t)=>t.is("element","tableRow")?e+1:e),0)}createTableWalker(e,t={}){return new Fk(e,t)}getSelectedTableCells(e){const t=[];for(const o of this.sortRanges(e.getRanges())){const e=o.getContainedElement();e&&e.is("element","tableCell")&&t.push(e)}return t}setFooterRowsCount(e,t,o){if(!this.editor.config.get("table.enableFooters"))return;const i=t.getAttribute("headingRows")||0,n=this.getRows(t),s=Math.min(o,n);if(Bk("footerRows",s,t,e,0),i+s>n){const o=n-s;this.setHeadingRowsCount(e,t,o)}}setHeadingRowsCount(e,t,o,i={}){const{updateCellType:n=!0,resetFormerHeadingCells:s=!0,autoExpand:r=!0}=i,a=this.getRows(t),l=!!this.editor.config.get("table.tableCellProperties.scopedHeaders"),c=t.getAttribute("headingRows")||0;let d=Math.min(o,a);if(d===c)return;Bk("headingRows",d,t,e,0);if(d+(t.getAttribute("footerRows")||0)>a){const o=a-d;this.setFooterRowsCount(e,t,o)}if(Hk(this.editor)){if(n){for(const{cell:o,row:i,column:n}of new Fk(t,{endRow:d-1}))hv({table:t,writer:e,cell:o,row:i,column:n,scopedHeaders:l});if(s&&dc){for(;dl){for(;de.parent.index));return this._getFirstLastIndexesObject(t)}getColumnIndexes(e){const t=e[0].findAncestor("table"),o=[...new Fk(t)].filter((t=>e.includes(t.cell))).map((e=>e.column));return this._getFirstLastIndexesObject(o)}isSelectionRectangular(e){if(e.length<2||!this._areCellInTheSameTableSection(e))return!1;const t=new Set,o=new Set;let i=0;for(const n of e){const{row:e,column:s}=this.getCellLocation(n),r=parseInt(n.getAttribute("rowspan"))||1,a=parseInt(n.getAttribute("colspan"))||1;t.add(e),o.add(s),r>1&&t.add(e+r-1),a>1&&o.add(s+a-1),i+=r*a}const n=function(e,t){const o=Array.from(e.values()),i=Array.from(t.values()),n=Math.max(...o),s=Math.min(...o),r=Math.max(...i),a=Math.min(...i);return(n-s+1)*(r-a+1)}(t,o);return n==i}sortRanges(e){return Array.from(e).sort(uv)}_getFirstLastIndexesObject(e){const t=e.sort(((e,t)=>e-t));return{first:t[0],last:t[t.length-1]}}_areCellInTheSameTableSection(e){const t=e[0].findAncestor("table"),o=this.getRows(t),i=this.getRowIndexes(e),n=parseInt(t.getAttribute("headingRows"))||0,s=parseInt(t.getAttribute("footerRows"))||0;if(!this._areIndexesInSameHeadingSection(i,n)||!this._areIndexesInSameFooterSection(i,o,s))return!1;const r=this.getColumnIndexes(e),a=parseInt(t.getAttribute("headingColumns"))||0;return this._areIndexesInSameHeadingSection(r,a)}_areIndexesInSameHeadingSection({first:e,last:t},o){return e=n===t>=n}}function lv(e,t,o,i,n,s={}){const r=[];for(let a=0;a=r&&i>=a)return void e.removeAttribute("tableCellType",n);let l="header";s&&(l=o{const n=o.getAttribute("headingRows")||0,s=o.getAttribute("footerRows")||0,r=i.createContainerElement("table",null,[]),a=i.createContainerElement("figure",{class:"table"},r),l=e.getRows(o);n>0&&i.insert(i.createPositionAt(r,"end"),i.createContainerElement("thead",null,i.createSlot((e=>e.is("element","tableRow")&&e.indexe.is("element","tableRow")&&e.index>=n&&e.index0&&i.insert(i.createPositionAt(r,"end"),i.createContainerElement("tfoot",null,i.createSlot((e=>e.is("element","tableRow")&&e.index>=l-s))));for(const{positionOffset:e,filter:o}of t.additionalSlots)i.insert(i.createPositionAt(r,e),i.createSlot(o));return i.insert(i.createPositionAt(r,"after"),i.createSlot((e=>!e.is("element","tableRow")&&!t.additionalSlots.some((({filter:t})=>t(e)))))),t.asWidget?function(e,t){return t.setCustomProperty("table",!0,e),np(e,t,{hasSelectionHandle:!0})}(a,i):a}}function yv(e){return(o,{writer:i})=>{if(e.cellTypeEnabled?.()){return t(i,Nk(o.getAttribute("tableCellType"))?"th":"td")}const n=o.parent,s=n.parent,r=s.getChildIndex(n),a=new Fk(s,{row:r}),l=s.getAttribute("headingRows")||0,c=s.getAttribute("headingColumns")||0;let d=null;for(const e of a)if(e.cell==o){d=t(i,e.row{if(!t.parent.is("element","tableCell"))return null;if(!kv(t))return null;if(e.asWidget)return o.createContainerElement("span",{class:"ck-table-bogus-paragraph"});{const e=o.createContainerElement("p");return o.setCustomProperty("dataPipeline:transparentRendering",!0,e),e}}}function kv(e){return 1==e.parent.childCount&&!function(e){for(const t of e.getAttributeKeys())if(!t.startsWith("selection:")&&"htmlEmptyBlock"!=t)return!0;return!1}(e)}function vv(e){return(t,o)=>{const i=e.plugins.has("PlainTableOutput"),n=o.options.isClipboardPipeline,s=Av(e,t);return i||s||n?function(e,t,o){const i=o.plugins.get(av),n=t.writer,s=i.getRows(e),r=e.getAttribute("headingRows")||0,a=e.getAttribute("footerRows")||0,l=s-a,c=n.createSlot((e=>e.is("element","tableRow")&&e.indexe.is("element","tableRow")&&e.index>=r&&e.indexe.is("element","tableRow")&&e.index>=l)),h=n.createSlot((e=>!e.is("element","tableRow"))),m=n.createContainerElement("thead",null,c),g=n.createContainerElement("tbody",null,d),p=n.createContainerElement("tfoot",null,u),f=[];r&&f.push(m);r+a{const n=e.plugins.has("PlainTableOutput"),s=i.isClipboardPipeline,r=Av(e,t);return(n||r||s)&&"table"===t.parent.name?o.createContainerElement("caption"):null}}function Av(e,t){const o=e.plugins.has("TableLayoutEditing"),i=e.config.get("table.tableLayout.stripFigureFromContentTable")??!1,n=t.findAncestor("table",{includeSelf:!0}),s=n?.getAttribute("tableType");return o&&(i||"layout"===s)}class xv extends wc{refresh(){const e=this.editor.model,t=e.document.selection,o=e.schema;this.isEnabled=function(e,t){const o=e.getFirstPosition().parent,i=o===o.root?o:o.parent;return t.checkChild(i,"table")}(t,o)}execute(e={}){const t=this.editor,o=t.model,i=t.plugins.get("TableUtils"),n=!!t.config.get("table.enableFooters"),s=t.config.get("table.defaultHeadings.rows"),r=t.config.get("table.defaultHeadings.columns"),a=t.config.get("table.defaultFooters");void 0===e.headingRows&&s&&(e.headingRows=s),void 0===e.headingColumns&&r&&(e.headingColumns=r),n&&void 0===e.footerRows&&a&&(e.footerRows=a),!n&&"footerRows"in e&&delete e.footerRows,o.change((t=>{const n=i.createTable(t,e);o.insertObject(n,null,null,{findOptimalPosition:"auto"}),t.setSelection(t.createPositionAt(n.getNodeByPath([0,0,0]),0))}))}}class Ev extends wc{order;constructor(e,t={}){super(e),this.order=t.order||"below"}refresh(){const e=this.editor.model.document.selection,t=!!this.editor.plugins.get("TableUtils").getSelectionAffectedTableCells(e).length;this.isEnabled=t}execute(){const e=this.editor,t=e.model.document.selection,o=e.plugins.get("TableUtils"),i="above"===this.order,n=o.getSelectionAffectedTableCells(t),s=o.getRowIndexes(n),r=i?s.first:s.last,a=n[0].findAncestor("table");o.insertRows(a,{at:i?r:r+1,copyStructureFromAbove:!i})}}class Tv extends wc{order;constructor(e,t={}){super(e),this.order=t.order||"right"}refresh(){const e=this.editor.model.document.selection,t=!!this.editor.plugins.get("TableUtils").getSelectionAffectedTableCells(e).length;this.isEnabled=t}execute(){const e=this.editor,t=e.model.document.selection,o=e.plugins.get("TableUtils"),i="left"===this.order,n=o.getSelectionAffectedTableCells(t),s=o.getColumnIndexes(n),r=i?s.first:s.last,a=n[0].findAncestor("table");o.insertColumns(a,{columns:1,at:i?r:r+1})}}class Pv extends wc{direction;constructor(e,t={}){super(e),this.direction=t.direction||"horizontally"}refresh(){const e=this.editor.plugins.get("TableUtils").getSelectionAffectedTableCells(this.editor.model.document.selection);this.isEnabled=1===e.length}execute(){const e=this.editor.plugins.get("TableUtils"),t=e.getSelectionAffectedTableCells(this.editor.model.document.selection)[0];"horizontally"===this.direction?e.splitCellHorizontally(t,2):e.splitCellVertically(t,2)}}class Sv extends wc{direction;isHorizontal;constructor(e,t){super(e),this.direction=t.direction,this.isHorizontal="right"==this.direction||"left"==this.direction}refresh(){const e=this._getMergeableCell();this.value=e,this.isEnabled=!!e}execute(){const e=this.editor.model,t=e.document,o=this.editor.plugins.get("TableUtils").getTableCellsContainingSelection(t.selection)[0],i=this.value,n=this.direction;e.change((e=>{const t="right"==n||"down"==n,s=t?o:i,r=t?i:o,a=r.parent;!function(e,t,o){Iv(e)||(Iv(t)&&o.remove(o.createRangeIn(t)),o.move(o.createRangeIn(e),o.createPositionAt(t,"end")));o.remove(e)}(r,s,e);const l=this.isHorizontal?"colspan":"rowspan",c=parseInt(o.getAttribute(l)||"1"),d=parseInt(i.getAttribute(l)||"1");e.setAttribute(l,c+d,s),e.setSelection(e.createRangeIn(s));const u=this.editor.plugins.get("TableUtils");Xk(a.findAncestor("table"),u)}))}_getMergeableCell(){const e=this.editor.model.document,t=this.editor.plugins.get("TableUtils"),o=t.getTableCellsContainingSelection(e.selection)[0];if(!o)return;const i=this.isHorizontal?function(e,t,o){const i=e.parent,n=i.parent,s="right"==t?e.nextSibling:e.previousSibling,r=(n.getAttribute("headingColumns")||0)>0;if(!s)return;const a="right"==t?e:s,l="right"==t?s:e,{column:c}=o.getCellLocation(a),{column:d}=o.getCellLocation(l),u=parseInt(a.getAttribute("colspan")||"1"),h=zk(o,a),m=zk(o,l);if(r&&h!=m)return;return c+u===d?s:void 0}(o,this.direction,t):function(e,t,o){const i=e.parent,n=i.parent,s=n.getChildIndex(i),r=o.getRows(n);if("down"==t&&s===r-1||"up"==t&&0===s)return null;const a=parseInt(e.getAttribute("rowspan")||"1"),l=n.getAttribute("headingRows")||0,c=n.getAttribute("footerRows")||0,d=r-c,u="up"==t&&s===d,h="up"==t&&s===l,m="down"==t&&s+a===l,g="down"==t&&s+a===d;if(l&&(m||h))return null;if(c&&(u||g))return null;const p=parseInt(e.getAttribute("rowspan")||"1"),f="down"==t?s+p:s,b=[...new Fk(n,{endRow:f})],w=b.find((t=>t.cell===e)),y=w.column,_=b.find((({row:e,cellHeight:o,column:i})=>i===y&&("down"==t?e===f:f===e+o)));return _&&_.cell?_.cell:null}(o,this.direction,t);if(!i)return;const n=this.isHorizontal?"rowspan":"colspan",s=parseInt(o.getAttribute(n)||"1");return parseInt(i.getAttribute(n)||"1")===s?i:void 0}}function Iv(e){const t=e.getChild(0);return 1==e.childCount&&t.is("element","paragraph")&&t.isEmpty}class Rv extends wc{refresh(){const e=this.editor.plugins.get("TableUtils"),t=e.getSelectionAffectedTableCells(this.editor.model.document.selection),o=t[0];if(o){const i=o.findAncestor("table"),n=e.getRows(i)-1,s=e.getRowIndexes(t),r=0===s.first&&s.last===n;this.isEnabled=!r}else this.isEnabled=!1}execute(){const e=this.editor.model,t=this.editor.plugins.get("TableUtils"),o=t.getSelectionAffectedTableCells(e.document.selection),i=t.getRowIndexes(o),n=o[0],s=n.findAncestor("table"),r=t.getCellLocation(n).column;e.change((e=>{const o=i.last-i.first+1;t.removeRows(s,{at:i.first,rows:o});const n=function(e,t,o,i){const n=e.getChild(Math.min(t,i-1));let s=n.getChild(0),r=0;for(const e of n.getChildren()){if(r>o)return s;s=e,r+=parseInt(e.getAttribute("colspan")||"1")}return s}(s,i.first,r,t.getRows(s));e.setSelection(e.createPositionAt(n,0))}))}}class Ov extends wc{refresh(){const e=this.editor.plugins.get("TableUtils"),t=e.getSelectionAffectedTableCells(this.editor.model.document.selection),o=t[0];if(o){const i=o.findAncestor("table"),n=e.getColumns(i),{first:s,last:r}=e.getColumnIndexes(t);this.isEnabled=r-se.cell===t)).column,last:n.find((e=>e.cell===o)).column},r=function(e,t,o,i){const n=parseInt(o.getAttribute("colspan")||"1");return n>1?o:t.previousSibling||o.nextSibling?o.nextSibling||t.previousSibling:i.first?e.reverse().find((({column:e})=>ee>i.last)).cell}(n,t,o,s);this.editor.model.change((t=>{const o=s.last-s.first+1;e.removeColumns(i,{at:s.first,columns:o}),t.setSelection(t.createPositionAt(r,0))}))}}class Vv extends wc{refresh(){const e=this.editor.plugins.get("TableUtils"),t=this.editor.model,o=e.getSelectionAffectedTableCells(t.document.selection);if(0===o.length)return this.isEnabled=!1,void(this.value=!1);const i=o[0].findAncestor("table");this.isEnabled=t.schema.checkAttribute(i,"headingRows"),this.value=o.every((e=>this._isInHeading(e,e.parent.parent)))}execute(e={}){if(e.forceValue===this.value)return;const t=this.editor.plugins.get("TableUtils"),o=this.editor.model,i=t.getSelectionAffectedTableCells(o.document.selection),n=i[0].findAncestor("table"),{first:s,last:r}=t.getRowIndexes(i),a=this.value?s:r+1,l=n.getAttribute("headingRows")||0;o.change((e=>{if(a){const t=Uk(n,a,a>l?l:0);for(const{cell:o}of t)Kk(o,a,e)}t.setHeadingRowsCount(e,n,a)}))}_isInHeading(e,t){const o=parseInt(t.getAttribute("headingRows")||"0");return!!o&&e.parent.indexthis._isInFooter(e,i)))}execute(e={}){if(e.forceValue===this.value)return;const t=this.editor.plugins.get("TableUtils"),o=this.editor.model,i=t.getSelectionAffectedTableCells(o.document.selection),n=i[0].findAncestor("table"),{first:s,last:r}=t.getRowIndexes(i),a=t.getRows(n),l=this.value?a-(r+1):a-s,c=n.getAttribute("footerRows")||0;o.change((e=>{if(l){const t=a-l,o=a-c,i=Uk(n,t,t>o?o:0);for(const{cell:o}of i)Kk(o,t,e)}t.setFooterRowsCount(e,n,l)}))}_isInFooter(e,t){const o=parseInt(t.getAttribute("footerRows")||"0"),i=this.editor.plugins.get("TableUtils").getRows(t),n=e.parent.index;return!!o&&n>=i-o}}class Fv extends wc{refresh(){const e=this.editor.plugins.get("TableUtils"),t=this.editor.model,o=e.getSelectionAffectedTableCells(t.document.selection);if(0===o.length)return this.isEnabled=!1,void(this.value=!1);const i=o[0].findAncestor("table");this.isEnabled=t.schema.checkAttribute(i,"headingColumns"),this.value=o.every((t=>zk(e,t)))}execute(e={}){if(e.forceValue===this.value)return;const t=this.editor.plugins.get("TableUtils"),o=this.editor.model,i=t.getSelectionAffectedTableCells(o.document.selection),n=i[0].findAncestor("table"),{first:s,last:r}=t.getColumnIndexes(i),a=this.value?s:r+1;o.change((e=>{if(a){const t=Gk(n,a);for(const{cell:o,column:i}of t)Jk(o,i,a,e)}t.setHeadingColumnsCount(e,n,a)}))}}class Mv extends wc{refresh(){const e=this.editor.plugins.get(av),t=e.getSelectedTableCells(this.editor.model.document.selection);this.isEnabled=e.isSelectionRectangular(t)}execute(){const e=this.editor.model,t=this.editor.plugins.get(av);e.change((o=>{const i=t.getSelectedTableCells(e.document.selection),n=i.shift(),{mergeWidth:s,mergeHeight:r}=function(e,t,o){let i=0,n=0;for(const e of t){const{row:t,column:s}=o.getCellLocation(e);i=Lv(e,s,i,"colspan"),n=Lv(e,t,n,"rowspan")}const{row:s,column:r}=o.getCellLocation(e),a=i-r,l=n-s;return{mergeWidth:a,mergeHeight:l}}(n,i,t);Bk("colspan",s,n,o),Bk("rowspan",r,n,o);for(const e of i)Nv(e,n,o);Xk(n.findAncestor("table"),t),o.setSelection(n,"in")}))}}function Nv(e,t,o){Bv(e)||(Bv(t)&&o.remove(o.createRangeIn(t)),o.move(o.createRangeIn(e),o.createPositionAt(t,"end"))),o.remove(e)}function Bv(e){const t=e.getChild(0);return 1==e.childCount&&t.is("element","paragraph")&&t.isEmpty}function Lv(e,t,o,i){const n=parseInt(e.getAttribute(i)||"1");return Math.max(o,t+n)}class zv extends wc{constructor(e){super(e),this.affectsData=!1}refresh(){const e=this.editor.plugins.get("TableUtils").getSelectionAffectedTableCells(this.editor.model.document.selection);this.isEnabled=e.length>0}execute(){const e=this.editor.model,t=this.editor.plugins.get("TableUtils"),o=t.getSelectionAffectedTableCells(e.document.selection),i=t.getRowIndexes(o),n=o[0].findAncestor("table"),s=[];for(let t=i.first;t<=i.last;t++)for(const o of n.getChild(t).getChildren())s.push(e.createRangeOn(o));e.change((e=>{e.setSelection(s)}))}}class jv extends wc{constructor(e){super(e),this.affectsData=!1}refresh(){const e=this.editor.plugins.get("TableUtils").getSelectionAffectedTableCells(this.editor.model.document.selection);this.isEnabled=e.length>0}execute(){const e=this.editor.plugins.get("TableUtils"),t=this.editor.model,o=e.getSelectionAffectedTableCells(t.document.selection),i=o[0],n=o.pop(),s=i.findAncestor("table"),r=e.getCellLocation(i),a=e.getCellLocation(n),l=Math.min(r.column,a.column),c=Math.max(r.column,a.column),d=[];for(const e of new Fk(s,{startColumn:l,endColumn:c}))d.push(t.createRangeOn(e.cell));t.change((e=>{e.setSelection(d)}))}}function qv(e){e.document.registerPostFixer((t=>function(e,t){const o=t.document.differ.getChanges();let i=!1;const n=new Set;for(const t of o){let o=null;"insert"==t.type&&"table"==t.name&&(o=t.position.nodeAfter),"insert"!=t.type&&"remove"!=t.type||"tableRow"!=t.name&&"tableCell"!=t.name||(o=t.position.findAncestor("table")),Wv(t)&&(o=t.range.start.findAncestor("table")),o&&!n.has(o)&&(i=$v(o,e)||i,i=Hv(o,e)||i,n.add(o))}return i}(t,e)))}function $v(e,t){let o=!1;const i=function(e){const t=parseInt(e.getAttribute("headingRows")||"0"),o=parseInt(e.getAttribute("footerRows")||"0"),i=Array.from(e.getChildren()).reduce(((e,t)=>t.is("element","tableRow")?e+1:e),0),n=i-o,s=[];for(const{row:o,cell:r,cellHeight:a}of new Fk(e)){if(a<2)continue;let e;if(e=o=n?i:n,o+a>e){const t=e-o;s.push({cell:r,rowspan:t})}}return s}(e);if(i.length){o=!0;for(const e of i)Bk("rowspan",e.rowspan,e.cell,t,1)}return o}function Hv(e,t){let o=!1;const i=function(e){const t=new Array(e.childCount).fill(0);for(const{rowIndex:o}of new Fk(e,{includeAllSlots:!0}))t[o]++;return t}(e),n=[];for(const[t,o]of i.entries())!o&&e.getChild(t).is("element","tableRow")&&n.push(t);if(n.length){o=!0;for(const o of n.reverse())t.remove(e.getChild(o)),i.splice(o,1)}const s=i.filter(((t,o)=>e.getChild(o).is("element","tableRow"))),r=s[0];if(!s.every((e=>e===r))){const i=s.reduce(((e,t)=>t>e?t:e),0);for(const[n,r]of s.entries()){const s=i-r;if(s){for(let o=0;ofunction(e,t){const o=t.document.differ.getChanges();let i=!1;for(const t of o)"insert"==t.type&&"table"==t.name&&(i=Kv(t.position.nodeAfter,e)||i),"insert"==t.type&&"tableRow"==t.name&&(i=Gv(t.position.nodeAfter,e)||i),"insert"==t.type&&"tableCell"==t.name&&(i=Jv(t.position.nodeAfter,e)||i),"remove"!=t.type&&"insert"!=t.type||!Zv(t)||(i=Jv(t.position.parent,e)||i);return i}(t,e)))}function Kv(e,t){let o=!1;for(const i of e.getChildren())i.is("element","tableRow")&&(o=Gv(i,t)||o);return o}function Gv(e,t){let o=!1;for(const i of e.getChildren())o=Jv(i,t)||o;return o}function Jv(e,t){if(0==e.childCount)return t.insertElement("paragraph",e),!0;const o=Array.from(e.getChildren()).filter((e=>e.is("$text")));for(const e of o)t.wrap(t.createRangeOn(e),"paragraph");return!!o.length}function Zv(e){return!!e.position.parent.is("element","tableCell")&&("insert"==e.type&&"$text"==e.name||"remove"==e.type)}function Qv(e,t,o){const i=o.getAttribute("headingRows")||0,n=o.getAttribute("footerRows")||0,s=e.getRows(o);if(i+n>s){return Bk("footerRows",Math.max(0,s-i),o,t,0),!0}return!1}function Yv(e,t){if(!e.is("element","paragraph"))return!1;const o=t.toViewElement(e);return!!o&&kv(e)!==o.is("element","span")}class Xv extends fc{_additionalSlots;static get pluginName(){return"TableEditing"}static get isOfficialPlugin(){return!0}static get requires(){return[av]}constructor(e){super(e),this._additionalSlots=[]}init(){const e=this.editor,t=e.model,o=t.schema,i=e.conversion,n=e.plugins.get(av);e.config.define("table.enableFooters",!1);const s=!!e.config.get("table.enableFooters");o.register("table",{inheritAllFrom:"$blockObject",allowAttributes:["headingRows","headingColumns",...s?["footerRows"]:[]]}),o.register("tableRow",{allowIn:"table",isLimit:!0}),o.register("tableCell",{allowContentOf:"$container",allowIn:"tableRow",allowAttributes:["colspan","rowspan"],isLimit:!0,isSelectable:!0}),i.for("upcast").add((e=>{e.on("element:figure",((e,t,o)=>{if(!o.consumable.test(t.viewItem,{name:!0,classes:"table"}))return;const i=ov(t.viewItem);if(!i||!o.consumable.test(i,{name:!0}))return;o.consumable.consume(t.viewItem,{name:!0,classes:"table"});const n=o.convertItem(i,t.modelCursor),s=to(n.modelRange.getItems());if(!s||!s.is("element","table"))return o.consumable.revert(t.viewItem,{name:!0,classes:"table"}),void(n.modelRange&&!n.modelRange.isCollapsed&&(t.modelRange=n.modelRange,t.modelCursor=n.modelCursor));o.convertChildren(t.viewItem,o.writer.createPositionAt(s,"end")),o.updateConversionResult(s,t)}))})),i.for("upcast").add(iv({enableFooters:s})),i.for("editingDowncast").elementToStructure({model:{name:"table",attributes:["headingRows",...s?["footerRows"]:[]]},view:wv(n,{asWidget:!0,additionalSlots:this._additionalSlots})}),i.for("dataDowncast").elementToStructure({model:{name:"table",attributes:["headingRows",...s?["footerRows"]:[]]},view:wv(n,{additionalSlots:this._additionalSlots})}),i.for("upcast").elementToElement({model:"tableRow",view:"tr"}),i.for("upcast").add((e=>{e.on("element:tr",((e,t)=>{t.viewItem.isEmpty&&0==t.modelCursor.index&&e.stop()}),{priority:"high"})})),i.for("downcast").elementToElement({model:"tableRow",view:(e,{writer:t})=>e.isEmpty?t.createEmptyElement("tr"):t.createContainerElement("tr")}),i.for("upcast").elementToElement({model:"tableCell",view:"td"}),i.for("upcast").elementToElement({model:"tableCell",view:"th"}),i.for("upcast").add(nv("td")),i.for("upcast").add(nv("th")),i.for("editingDowncast").elementToElement({model:"tableCell",view:yv({asWidget:!0,cellTypeEnabled:()=>Hk(this.editor)})}),i.for("dataDowncast").elementToElement({model:"tableCell",view:yv({cellTypeEnabled:()=>Hk(this.editor)})}),i.for("editingDowncast").elementToElement({model:"paragraph",view:_v({asWidget:!0}),converterPriority:"high"}),i.for("dataDowncast").elementToElement({model:"paragraph",view:_v(),converterPriority:"high"}),i.for("downcast").attributeToAttribute({model:"colspan",view:"colspan"}),i.for("upcast").attributeToAttribute({model:{key:"colspan",value:eC("colspan")},view:"colspan"}),i.for("downcast").attributeToAttribute({model:"rowspan",view:"rowspan"}),i.for("upcast").attributeToAttribute({model:{key:"rowspan",value:eC("rowspan")},view:"rowspan"}),this._addPlainTableOutputConverters(),e.config.define("table.defaultHeadings.rows",0),e.config.define("table.defaultHeadings.columns",0),e.config.define("table.defaultFooters",0),e.config.define("table.showHiddenBorders",!0),e.config.get("table.showHiddenBorders")&&e.editing.view.change((t=>{for(const o of e.editing.view.document.roots)t.addClass("ck-table-show-hidden-borders",o)})),e.commands.add("insertTable",new xv(e)),e.commands.add("insertTableRowAbove",new Ev(e,{order:"above"})),e.commands.add("insertTableRowBelow",new Ev(e,{order:"below"})),e.commands.add("insertTableColumnLeft",new Tv(e,{order:"left"})),e.commands.add("insertTableColumnRight",new Tv(e,{order:"right"})),e.commands.add("removeTableRow",new Rv(e)),e.commands.add("removeTableColumn",new Ov(e)),e.commands.add("splitTableCellVertically",new Pv(e,{direction:"vertically"})),e.commands.add("splitTableCellHorizontally",new Pv(e,{direction:"horizontally"})),e.commands.add("mergeTableCells",new Mv(e)),e.commands.add("mergeTableCellRight",new Sv(e,{direction:"right"})),e.commands.add("mergeTableCellLeft",new Sv(e,{direction:"left"})),e.commands.add("mergeTableCellDown",new Sv(e,{direction:"down"})),e.commands.add("mergeTableCellUp",new Sv(e,{direction:"up"})),e.commands.add("setTableColumnHeader",new Fv(e)),e.commands.add("setTableRowHeader",new Vv(e)),s&&e.commands.add("setTableFooterRow",new Dv(e)),e.commands.add("selectTableRow",new zv(e)),e.commands.add("selectTableColumn",new jv(e)),qv(t),Uv(t),s&&function(e){const{model:t}=e,o=e.plugins.get(av);t.document.registerPostFixer((e=>{let i=!1;const n=t.document.differ.getChanges(),s=new Set;for(const e of n){let t=null;"attribute"!=e.type||"headingRows"!=e.attributeKey&&"footerRows"!=e.attributeKey?("insert"==e.type&&"tableRow"==e.name||"remove"==e.type&&"tableRow"==e.name)&&(t=e.position.parent):t=e.range.start.nodeAfter,t&&t.is("element","table")&&s.add(t)}for(const t of s)Qv(o,e,t)&&(i=!0);return i}))}(e),this.listenTo(t.document,"change:data",(()=>{Hk(e)||function(e,t){const o=e.document.differ,i=new Set,n=new Set,s=new Set;for(const e of o.getChanges()){let o;if("attribute"==e.type){const t=e.range.start.nodeAfter;if(!t||!t.is("element","table"))continue;if("headingRows"!=e.attributeKey&&"headingColumns"!=e.attributeKey&&"footerRows"!=e.attributeKey)continue;o=t}else"tableRow"!=e.name&&"tableCell"!=e.name||(o=e.position.findAncestor("table"));if(!o)continue;"insert"==e.type&&"tableRow"==e.name&&t.mapper.toViewElement(e.position.nodeAfter)&&i.add(e.position.nodeAfter);const r=o.getAttribute("headingRows")||0,a=o.getAttribute("headingColumns")||0,l=new Fk(o);for(const e of l){const o=t.mapper.toViewElement(e.cell);if(!o||!o.is("element"))continue;const l=e.rowYv(e,t.mapper)));for(const e of o)t.reconvertItem(e)}}(t,e.editing)}))}registerAdditionalSlot(e){this._additionalSlots.push(e)}_addPlainTableOutputConverters(){const e=this.editor;e.conversion.for("dataDowncast").elementToStructure({model:"table",view:vv(e),converterPriority:"high"}),e.plugins.has("TableCaptionEditing")&&e.conversion.for("dataDowncast").elementToElement({model:"caption",view:Cv(e),converterPriority:"high"}),e.plugins.has("TablePropertiesEditing")&&function(e){const t={"border-width":"tableBorderWidth","border-color":"tableBorderColor","border-style":"tableBorderStyle","background-color":"tableBackgroundColor"};for(const[o,i]of Object.entries(t))e.conversion.for("dataDowncast").add((t=>t.on(`attribute:${i}:table`,((t,i,n)=>{const{item:s,attributeNewValue:r}=i,{mapper:a,writer:l}=n,c=e.plugins.has("PlainTableOutput"),d=n.options.isClipboardPipeline,u=Av(e,s);if(!(c||u||d))return;if(!n.consumable.consume(s,t.name))return;const h=a.toViewElement(s);r?l.setStyle(o,r,h):l.removeStyle(o,h)}),{priority:"high"})))}(e)}}function eC(e){return t=>{const o=parseInt(t.getAttribute(e));return Number.isNaN(o)||o<=0?null:o}}class tC extends Au{items;keystrokes;focusTracker;constructor(e){super(e);const t=this.bindTemplate;this.items=this._createGridCollection(),this.keystrokes=new ro,this.focusTracker=new oo,this.set("rows",0),this.set("columns",0),this.bind("label").to(this,"columns",this,"rows",((e,t)=>`${t} × ${e}`)),this.setTemplate({tag:"div",attributes:{class:["ck"]},children:[{tag:"div",attributes:{class:["ck-insert-table-dropdown__grid"]},on:{"mouseover@.ck-insert-table-dropdown-grid-box":t.to("boxover")},children:this.items},{tag:"div",attributes:{class:["ck","ck-insert-table-dropdown__label"],"aria-hidden":!0},children:[{text:t.to("label")}]}],on:{mousedown:t.to((e=>{e.preventDefault()})),click:t.to((()=>{this.fire("execute")}))}}),this.on("boxover",((e,t)=>{const{row:o,column:i}=t.target.dataset;this.items.get(10*(parseInt(o,10)-1)+(parseInt(i,10)-1)).focus()})),this.focusTracker.on("change:focusedElement",((e,t,o)=>{if(!o)return;const{row:i,column:n}=o.dataset;this.set({rows:parseInt(i),columns:parseInt(n)})})),this.on("change:columns",(()=>this._highlightGridBoxes())),this.on("change:rows",(()=>this._highlightGridBoxes()))}render(){super.render(),Vu({keystrokeHandler:this.keystrokes,focusTracker:this.focusTracker,gridItems:this.items,numberOfColumns:10,uiLanguageDirection:this.locale&&this.locale.uiLanguageDirection});for(const e of this.items)this.focusTracker.add(e.element);this.keystrokes.listenTo(this.element)}reset(){this.set({rows:1,columns:1})}focus(){this.items.get(0).focus()}focusLast(){this.items.get(0).focus()}_highlightGridBoxes(){const e=this.rows,t=this.columns;this.items.map(((o,i)=>{const n=Math.floor(i/10){const i=e.commands.get("insertTable"),n=Zh(o);let s;return n.bind("isEnabled").to(i),n.buttonView.set({icon:od,label:t("Insert table"),tooltip:!0}),n.on("change:isOpen",(()=>{s||(s=new tC(o),n.panelView.children.add(s),s.delegate("execute").to(n),n.on("execute",(()=>{e.execute("insertTable",{rows:s.rows,columns:s.columns}),e.editing.view.focus()})))})),n})),e.ui.componentFactory.add("menuBar:insertTable",(o=>{const i=e.commands.get("insertTable"),n=new og(o),s=new tC(o);return s.delegate("execute").to(n),n.on("change:isOpen",((e,t,o)=>{o||s.reset()})),s.on("execute",(()=>{e.execute("insertTable",{rows:s.rows,columns:s.columns}),e.editing.view.focus()})),n.buttonView.set({label:t("Table"),icon:od}),n.panelView.children.add(s),n.bind("isEnabled").to(i),n})),e.ui.componentFactory.add("tableColumn",(e=>{const i=[{type:"switchbutton",model:{commandName:"setTableColumnHeader",label:t("Header column"),bindIsOn:!0}},{type:"separator"},{type:"button",model:{commandName:o?"insertTableColumnLeft":"insertTableColumnRight",label:t("Insert column left")}},{type:"button",model:{commandName:o?"insertTableColumnRight":"insertTableColumnLeft",label:t("Insert column right")}},{type:"button",model:{commandName:"removeTableColumn",label:t("Delete column")}},{type:"button",model:{commandName:"selectTableColumn",label:t("Select column")}}];return this._prepareDropdown(t("Column"),'',i,e)})),e.ui.componentFactory.add("tableRow",(e=>{const o=[{type:"switchbutton",model:{commandName:"setTableRowHeader",label:t("Header row"),bindIsOn:!0}},i&&{type:"switchbutton",model:{commandName:"setTableFooterRow",label:t("Footer row"),bindIsOn:!0}},{type:"separator"},{type:"button",model:{commandName:"insertTableRowAbove",label:t("Insert row above")}},{type:"button",model:{commandName:"insertTableRowBelow",label:t("Insert row below")}},{type:"button",model:{commandName:"removeTableRow",label:t("Delete row")}},{type:"button",model:{commandName:"selectTableRow",label:t("Select row")}}].filter(Boolean);return this._prepareDropdown(t("Row"),'',o,e)})),e.ui.componentFactory.add("mergeTableCells",(e=>{const i=[{type:"button",model:{commandName:"mergeTableCellUp",label:t("Merge cell up")}},{type:"button",model:{commandName:o?"mergeTableCellRight":"mergeTableCellLeft",label:t("Merge cell right")}},{type:"button",model:{commandName:"mergeTableCellDown",label:t("Merge cell down")}},{type:"button",model:{commandName:o?"mergeTableCellLeft":"mergeTableCellRight",label:t("Merge cell left")}},{type:"separator"},{type:"button",model:{commandName:"splitTableCellVertically",label:t("Split cell vertically")}},{type:"button",model:{commandName:"splitTableCellHorizontally",label:t("Split cell horizontally")}}];return this._prepareMergeSplitButtonDropdown(t("Merge cells"),'',i,e)}))}_prepareDropdown(e,t,o,i){const n=this.editor,s=Zh(i),r=this._fillDropdownWithListOptions(s,o);return s.buttonView.set({label:e,icon:t,tooltip:!0}),s.bind("isEnabled").toMany(r,"isEnabled",((...e)=>e.some((e=>e)))),this.listenTo(s,"execute",(e=>{n.execute(e.source.commandName),e.source instanceof fh||n.editing.view.focus()})),s}_prepareMergeSplitButtonDropdown(e,t,o,i){const n=this.editor,s=Zh(i,Jh),r="mergeTableCells",a=n.commands.get(r),l=this._fillDropdownWithListOptions(s,o);return s.buttonView.set({label:e,icon:t,tooltip:!0,isEnabled:!0}),s.bind("isEnabled").toMany([a,...l],"isEnabled",((...e)=>e.some((e=>e)))),this.listenTo(s.buttonView,"execute",(()=>{n.execute(r),n.editing.view.focus()})),this.listenTo(s,"execute",(e=>{n.execute(e.source.commandName),n.editing.view.focus()})),s}_fillDropdownWithListOptions(e,t){const o=this.editor,i=[],n=new eo;for(const e of t)iC(e,o,i,n);return Xh(e,n),i}}function iC(e,t,o,i){if("button"===e.type||"switchbutton"===e.type){const i=e.model=new Jm(e.model),{commandName:n,bindIsOn:s}=e.model,r=t.commands.get(n);o.push(r),i.set({commandName:n}),i.bind("isEnabled").to(r),s&&i.bind("isOn").to(r,"value"),i.set({withText:!0})}i.add(e)}class nC extends fc{static get pluginName(){return"TableSelection"}static get isOfficialPlugin(){return!0}static get requires(){return[av,av]}init(){const e=this.editor,t=e.model,o=e.editing.view;this.listenTo(t,"deleteContent",((e,t)=>this._handleDeleteContent(e,t)),{priority:"high"}),this.listenTo(o.document,"insertText",((e,t)=>this._handleInsertTextEvent(e,t)),{priority:"high"}),this._defineSelectionConverter(),this._enablePluginDisabling()}getSelectedTableCells(){const e=this.editor.plugins.get(av),t=this.editor.model.document.selection,o=e.getSelectedTableCells(t);return 0==o.length?null:o}getSelectionAsFragment(){const e=this.editor.plugins.get(av),t=this.getSelectedTableCells();return t?this.editor.model.change((o=>{const i=o.createDocumentFragment(),{first:n,last:s}=e.getColumnIndexes(t),{first:r,last:a}=e.getRowIndexes(t),l=t[0].findAncestor("table");let c=a,d=s;if(e.isSelectionRectangular(t)){const e={firstColumn:n,lastColumn:s,firstRow:r,lastRow:a};c=ev(l,e),d=tv(l,e)}const u=Wk(l,{startRow:r,startColumn:n,endRow:c,endColumn:d},o);return o.insert(u,i,0),i})):null}setCellSelection(e,t){const o=this._getCellsToSelect(e,t);this.editor.model.change((e=>{e.setSelection(o.cells.map((t=>e.createRangeOn(t))),{backward:o.backward})}))}getFocusCell(){const e=[...this.editor.model.document.selection.getRanges()].pop().getContainedElement();return e&&e.is("element","tableCell")?e:null}getAnchorCell(){const e=to(this.editor.model.document.selection.getRanges()).getContainedElement();return e&&e.is("element","tableCell")?e:null}_defineSelectionConverter(){const e=this.editor,t=new Set;e.conversion.for("editingDowncast").add((e=>e.on("selection",((e,o,i)=>{const n=i.writer;!function(e){for(const o of t)e.removeClass("ck-editor__editable_selected",o);t.clear()}(n);const s=this.getSelectedTableCells();if(!s)return;for(const e of s){const o=i.mapper.toViewElement(e);n.addClass("ck-editor__editable_selected",o),t.add(o)}const r=i.mapper.toViewElement(s[s.length-1]);n.setSelection(r,0)}),{priority:"lowest"})))}_enablePluginDisabling(){const e=this.editor;this.on("change:isEnabled",(()=>{if(!this.isEnabled){const t=this.getSelectedTableCells();if(!t)return;e.model.change((o=>{const i=o.createPositionAt(t[0],0),n=e.model.schema.getNearestSelectionRange(i);o.setSelection(n)}))}}))}_handleDeleteContent(e,t){const o=this.editor.plugins.get(av),i=t[0],n=t[1],s=this.editor.model,r=!n||"backward"==n.direction,a=o.getSelectedTableCells(i);a.length&&(e.stop(),s.change((e=>{const t=a[r?a.length-1:0];s.change((e=>{for(const t of a)s.deleteContent(e.createSelection(t,"in"))}));const o=s.schema.getNearestSelectionRange(e.createPositionAt(t,0));i.is("documentSelection")?e.setSelection(o):i.setTo(o)})))}_handleInsertTextEvent(e,t){const o=this.editor,i=this.getSelectedTableCells();if(!i)return;const n=o.editing.view,s=o.editing.mapper,r=i.map((e=>n.createRangeOn(s.toViewElement(e))));t.selection=n.createSelection(r),t.preventDefault()}_getCellsToSelect(e,t){const o=this.editor.plugins.get("TableUtils"),i=o.getCellLocation(e),n=o.getCellLocation(t),s=Math.min(i.row,n.row),r=Math.max(i.row,n.row),a=Math.min(i.column,n.column),l=parseInt(t.getAttribute("colspan")||"1")-1,c=Math.max(i.column,n.column+l),d=new Array(r-s+1).fill(null).map((()=>[])),u={startRow:s,endRow:r,startColumn:a,endColumn:c};for(const{row:t,cell:o}of new Fk(e.findAncestor("table"),u))d[t-s].push(o);const h=n.rowe.reverse())),{cells:d.flat(),backward:h||m}}}class sC extends fc{static get pluginName(){return"TableClipboard"}static get isOfficialPlugin(){return!0}static get requires(){return[ff,bf,nC,av]}init(){const e=this.editor.editing.view.document;this.listenTo(e,"copy",((e,t)=>this._onCopyCut(e,t))),this.listenTo(e,"cut",((e,t)=>this._onCopyCut(e,t))),this._listenToContentInsertion(),this.decorate("_replaceTableSlotCell")}_listenToContentInsertion(){const{editor:e}=this,t=e.plugins.get(bf),o=e.plugins.get(nC);let i=!1;t.on("contentInsertion",((e,t)=>{i="paste"===t.method})),this.listenTo(e.model,"insertContent",((e,[t,n])=>{(i||null!==o.getSelectedTableCells())&&this._onInsertContent(e,t,n)}),{priority:"high"}),t.on("contentInsertion",(()=>{i=!1}),{priority:"lowest"})}_onCopyCut(e,t){const o=this.editor.editing.view,i=this.editor.plugins.get(nC),n=this.editor.plugins.get(ff);i.getSelectedTableCells()&&("cut"!=e.name||this.editor.model.canEditAt(this.editor.model.document.selection))&&(t.preventDefault(),e.stop(),this.editor.model.enqueueChange({isUndoable:"cut"===e.name},(()=>{const s=n._copySelectedFragmentWithMarkers(e.name,this.editor.model.document.selection,(()=>i.getSelectionAsFragment()));o.document.fire("clipboardOutput",{dataTransfer:t.dataTransfer,content:this.editor.data.toView(s),method:e.name})})))}_onInsertContent(e,t,o){if(o&&!o.is("documentSelection"))return;const i=this.editor.model,n=this.editor.plugins.get(av),s=this.editor.plugins.get(ff),r=this.getTableIfOnlyTableInContent(t,i);if(!r)return;const a=n.getSelectionAffectedTableCells(i.document.selection);a.length?(e.stop(),t.is("documentFragment")?s._pasteMarkersIntoTransformedElement(t.markers,(e=>this._replaceSelectedCells(r,a,e))):this.editor.model.change((e=>{this._replaceSelectedCells(r,a,e)}))):Xk(r,n)}_replaceSelectedCells(e,t,o){const i=this.editor.plugins.get(av),n={width:i.getColumns(e),height:i.getRows(e)},s=function(e,t,o,i){const n=e[0].findAncestor("table"),s=i.getColumnIndexes(e),r=i.getRowIndexes(e),a={firstColumn:s.first,lastColumn:s.last,firstRow:r.first,lastRow:r.last},l=1===e.length;l&&(a.lastRow+=t.height-1,a.lastColumn+=t.width-1,function(e,t,o,i){const n=i.getColumns(e),s=i.getRows(e);o>n&&i.insertColumns(e,{at:n,columns:o-n});t>s&&i.insertRows(e,{at:s,rows:t-s})}(n,a.lastRow+1,a.lastColumn+1,i));l||!i.isSelectionRectangular(e)?function(e,t,o){const{firstRow:i,lastRow:n,firstColumn:s,lastColumn:r}=t,a={first:i,last:n},l={first:s,last:r};aC(e,s,a,o),aC(e,r+1,a,o),rC(e,i,l,o),rC(e,n+1,l,o,i)}(n,a,o):(a.lastRow=ev(n,a),a.lastColumn=tv(n,a));return a}(t,n,o,i),r=s.lastRow-s.firstRow+1,a=s.lastColumn-s.firstColumn+1;e=Wk(e,{startRow:0,startColumn:0,endRow:Math.min(r,n.height)-1,endColumn:Math.min(a,n.width)-1},o);const l=t[0].findAncestor("table"),c=this._replaceSelectedCellsWithPasted(e,n,l,s,o,i);if(this.editor.plugins.get("TableSelection").isEnabled){const e=i.sortRanges(c.map((e=>o.createRangeOn(e))));o.setSelection(e)}else o.setSelection(c[0],0);return l}_replaceSelectedCellsWithPasted(e,t,o,i,n,s){const{width:r,height:a}=t,l=function(e,t,o){const i=new Array(o).fill(null).map((()=>new Array(t).fill(null)));for(const{column:t,row:o,cell:n}of new Fk(e))i[o][t]=n;return i}(e,r,a),c=[...new Fk(o,{startRow:i.firstRow,endRow:i.lastRow,startColumn:i.firstColumn,endColumn:i.lastColumn,includeAllSlots:!0})],d=[];let u;for(const e of c){const{row:t,column:o}=e;o===i.firstColumn&&(u=e.getPositionBefore());const s=t-i.firstRow,c=o-i.firstColumn,h=l[s%a][c%r],m=h?n.cloneElement(h):null,g=this._replaceTableSlotCell(e,m,u,n);g&&(Zk(g,t,o,i.lastRow,i.lastColumn,n),d.push(g),u=n.createPositionAfter(g))}const h=parseInt(o.getAttribute("headingRows")||"0"),m=parseInt(o.getAttribute("headingColumns")||"0"),g=parseInt(o.getAttribute("footerRows")||"0"),p=s.getRows(o)-g,f=i.firstRowlC(e,t,o))).map((({cell:e})=>Kk(e,t,i)))}function aC(e,t,o,i){if(t<1)return;return Gk(e,t).filter((({row:e,cellHeight:t})=>lC(e,t,o))).map((({cell:e,column:o})=>Jk(e,o,t,i)))}function lC(e,t,o){const i=e+t-1,{first:n,last:s}=o;return e>=n&&e<=s||e=n}class cC extends fc{static get pluginName(){return"TableKeyboard"}static get isOfficialPlugin(){return!0}static get requires(){return[nC,av]}init(){const e=this.editor,t=e.editing.view.document,o=e.t;this.listenTo(t,"arrowKey",((...e)=>this._onArrowKey(...e)),{context:"table"}),this.listenTo(t,"tab",((...e)=>this._handleTabOnSelectedTable(...e)),{context:"figure"}),this.listenTo(t,"tab",((...e)=>this._handleTab(...e)),{context:["th","td"]}),e.accessibility.addKeystrokeInfoGroup({id:"table",label:o("Keystrokes that can be used in a table cell"),keystrokes:[{label:o("Move the selection to the next cell"),keystroke:"Tab"},{label:o("Move the selection to the previous cell"),keystroke:"Shift+Tab"},{label:o("Insert a new table row (when in the last cell of a table)"),keystroke:"Tab"},{label:o("Navigate through the table"),keystroke:[["arrowup"],["arrowright"],["arrowdown"],["arrowleft"]]}]})}_handleTabOnSelectedTable(e,t){const o=this.editor.model.document.selection.getSelectedElement();o&&o.is("element","table")&&t.stopPropagation()}_handleTab(e,t){const o=this.editor,i=this.editor.plugins.get(av),n=this.editor.plugins.get("TableSelection"),s=o.model.document.selection,r=!t.shiftKey;let a=i.getTableCellsContainingSelection(s)[0];if(a||(a=n.getFocusCell()),!a)return;t.stopPropagation();const l=a.parent,c=l.parent,d=c.getChildIndex(l),u=l.getChildIndex(a)===l.childCount-1,h=d===i.getRows(c)-1;r&&h&&u&&o.execute("insertTableRowBelow")}_onArrowKey(e,t){const o=this.editor,i=Kt(t.keyCode,o.locale.contentLanguageDirection);this._handleArrowKeys(i,t.shiftKey)&&(t.preventDefault(),t.stopPropagation(),e.stop())}_handleArrowKeys(e,t){const o=this.editor.plugins.get(av),i=this.editor.plugins.get("TableSelection"),n=this.editor.model,s=n.document.selection,r=["right","down"].includes(e),a=o.getSelectedTableCells(s);if(a.length){let o;return o=t?i.getFocusCell():r?a[a.length-1]:a[0],this._navigateFromCellInDirection(o,e,t),!0}const l=s.focus.findAncestor("tableCell");if(!l)return!1;if(!s.isCollapsed)if(t){if(s.isBackward==r&&!s.containsEntireContent(l))return!1}else{const e=s.getSelectedElement();if(!e||!n.schema.isObject(e))return!1}return!!this._isSelectionAtCellEdge(s,l,r)&&(this._navigateFromCellInDirection(l,e,t),!0)}_isSelectionAtCellEdge(e,t,o){const i=this.editor.model,n=this.editor.model.schema,s=o?e.getLastPosition():e.getFirstPosition();if(!n.getLimitElement(s).is("element","tableCell")){return i.createPositionAt(t,o?"end":0).isTouching(s)}const r=i.createSelection(s);return i.modifySelection(r,{direction:o?"forward":"backward"}),s.isEqual(r.focus)}_navigateFromCellInDirection(e,t,o=!1){const i=this.editor.model,n=e.findAncestor("table"),s=[...new Fk(n,{includeAllSlots:!0})],{row:r,column:a}=s[s.length-1],l=s.find((({cell:t})=>t==e));let{row:c,column:d}=l;switch(t){case"left":d--;break;case"up":c--;break;case"right":d+=l.cellWidth;break;case"down":c+=l.cellHeight}if(c<0||c>r||d<0&&c<=0||d>a&&c>=r)return void i.change((e=>{e.setSelection(e.createRangeOn(n))}));d<0?(d=o?0:a,c--):d>a&&(d=o?a:0,c++);const u=s.find((e=>e.row==c&&e.column==d)).cell,h=["right","down"].includes(t),m=this.editor.plugins.get("TableSelection");if(o&&m.isEnabled){const t=m.getAnchorCell()||e;m.setCellSelection(t,u)}else{const e=i.createPositionAt(u,h?0:"end");i.change((t=>{t.setSelection(e)}))}}}class dC extends jn{domEventType=["mousemove","mouseleave"];onDomEvent(e){this.fire(e.type,e)}}class uC extends fc{static get pluginName(){return"TableMouse"}static get isOfficialPlugin(){return!0}static get requires(){return[nC,av]}init(){this.editor.editing.view.addObserver(dC),this._enableShiftClickSelection(),this._enableMouseDragSelection()}_enableShiftClickSelection(){const e=this.editor,t=e.plugins.get(av);let o=!1;const i=e.plugins.get(nC);this.listenTo(e.editing.view.document,"mousedown",((n,s)=>{const r=e.model.document.selection;if(!this.isEnabled||!i.isEnabled)return;if(!s.domEvent.shiftKey)return;const a=i.getAnchorCell()||t.getTableCellsContainingSelection(r)[0];if(!a)return;const l=this._getModelTableCellFromDomEvent(s);l&&hC(a,l)&&(o=!0,i.setCellSelection(a,l),s.preventDefault())})),this.listenTo(e.editing.view.document,"mouseup",(()=>{o=!1})),this.listenTo(e.editing.view.document,"selectionChange",(e=>{o&&e.stop()}),{priority:"highest"})}_enableMouseDragSelection(){const e=this.editor;let t,o,i=!1,n=!1;const s=e.plugins.get(nC);this.listenTo(e.editing.view.document,"mousedown",((e,o)=>{this.isEnabled&&s.isEnabled&&(o.domEvent.shiftKey||o.domEvent.ctrlKey||o.domEvent.altKey||(t=this._getModelTableCellFromDomEvent(o)))})),this.listenTo(e.editing.view.document,"mousemove",((e,r)=>{if(!r.domEvent.buttons)return;if(!t)return;const a=this._getModelTableCellFromDomEvent(r);a&&hC(t,a)&&(o=a,i||o==t||(i=!0)),i&&(n=!0,s.setCellSelection(t,o),r.preventDefault())})),this.listenTo(e.editing.view.document,"mouseup",(()=>{i=!1,n=!1,t=null,o=null})),this.listenTo(e.editing.view.document,"selectionChange",(e=>{n&&e.stop()}),{priority:"highest"})}_getModelTableCellFromDomEvent(e){const t=e.target,o=this.editor.editing.view.createPositionAt(t,0);return this.editor.editing.mapper.toModelPosition(o).parent.findAncestor("tableCell",{includeSelf:!0})}}function hC(e,t){return e.parent.parent==t.parent.parent}class mC extends fc{static get requires(){return[Xv,oC,nC,uC,cC,sC,vp]}static get pluginName(){return"Table"}static get isOfficialPlugin(){return!0}}function gC(e){const t=pC(e);return t||fC(e)}function pC(e){const t=e.getSelectedElement();return t&&bC(t)?t:null}function fC(e){const t=e.getFirstPosition();if(!t)return null;let o=t.parent;for(;o;){if(o.is("element")&&bC(o))return o;o=o.parent}return null}function bC(e){return e.is("element")&&!!e.getCustomProperty("table")&&ip(e)}class wC extends Au{options;focusTracker;focusCycler;_focusables;dropdownView;inputView;keystrokes;_stillTyping;constructor(e,t){super(e),this.set("value",""),this.set("isReadOnly",!1),this.set("isFocused",!1),this.set("isEmpty",!0),this.options=t,this.focusTracker=new oo,this._focusables=new tu,this.dropdownView=this._createDropdownView(),this.inputView=this._createInputTextView(),this.keystrokes=new ro,this._stillTyping=!1,this.focusCycler=new qu({focusables:this._focusables,focusTracker:this.focusTracker,keystrokeHandler:this.keystrokes,actions:{focusPrevious:"shift + tab",focusNext:"tab"}}),this.setTemplate({tag:"div",attributes:{class:["ck","ck-input-color"]},children:[this.dropdownView,this.inputView]}),this.on("change:value",((e,t,o)=>this._setInputValue(o)))}render(){super.render(),[this.inputView,this.dropdownView.buttonView].forEach((e=>{this.focusTracker.add(e.element),this._focusables.add(e)})),this.keystrokes.listenTo(this.element)}focus(e){-1===e?this.focusCycler.focusLast():this.focusCycler.focusFirst()}destroy(){super.destroy(),this.focusTracker.destroy(),this.keystrokes.destroy()}_createDropdownView(){const e=this.locale,t=e.t,o=this.bindTemplate,i=this._createColorSelector(e),n=Zh(e),s=new Au;return s.setTemplate({tag:"span",attributes:{class:["ck","ck-input-color__button__preview"],style:{backgroundColor:o.to("value")}},children:[{tag:"span",attributes:{class:["ck","ck-input-color__button__preview__no-color-indicator",o.if("value","ck-hidden",(e=>""!=e))]}}]}),n.buttonView.extendTemplate({attributes:{class:"ck-input-color__button"}}),n.buttonView.children.add(s),n.buttonView.label=t("Color picker"),n.buttonView.tooltip=!0,n.panelPosition="rtl"===e.uiLanguageDirection?"se":"sw",n.panelView.children.add(i),n.bind("isEnabled").to(this,"isReadOnly",(e=>!e)),n.on("change:isOpen",((e,t,o)=>{o&&(i.updateSelectedColors(),i.showColorGridsFragment())})),n}_createInputTextView(){const e=this.locale,t=new Oh(e);return t.extendTemplate({on:{blur:t.bindTemplate.to("blur")}}),t.value=this.value,t.bind("isReadOnly","hasError").to(this),this.bind("isFocused","isEmpty").to(t),t.on("input",(()=>{const e=t.element.value,o=this.options.colorDefinitions.find((t=>e===t.label));this._stillTyping=!0,this.value=o&&o.color||e})),t.on("blur",(()=>{this._stillTyping=!1,this._setInputValue(t.element.value)})),t.delegate("input").to(this),t}_createColorSelector(e){const t=e.t,o=this.options.defaultColorValue||"",i=t(o?"Restore default":"Remove color"),n=new fm(e,{colors:this.options.colorDefinitions,columns:this.options.columns,removeButtonLabel:i,colorPickerLabel:t("Color picker"),colorPickerViewConfig:!1!==this.options.colorPickerConfig&&{...this.options.colorPickerConfig,hideInput:!0}});n.appendUI(),n.on("execute",((e,t)=>{"colorPickerSaveButton"!==t.source?(this.value=t.value||o,this.fire("input"),"colorPicker"!==t.source&&(this.dropdownView.isOpen=!1)):this.dropdownView.isOpen=!1}));let s=this.value;return n.on("colorPicker:cancel",(()=>{this.value=s,this.fire("input"),this.dropdownView.isOpen=!1})),n.colorGridsFragmentView.colorPickerButtonView.on("execute",(()=>{s=this.value})),n.bind("selectedColor").to(this,"value"),n}_setInputValue(e){if(!this._stillTyping){const t=yC(e),o=this.options.colorDefinitions.find((e=>t===yC(e.color)));this.inputView.value=o?o.label:e||""}}}function yC(e){return e.replace(/([(,])\s+/g,"$1").replace(/^\s+|\s+(?=[),\s]|$)/g,"").replace(/,|\s/g," ")}const _C=e=>""===e;function kC(e){return{none:e("None"),solid:e("Solid"),dotted:e("Dotted"),dashed:e("Dashed"),double:e("Double"),groove:e("Groove"),ridge:e("Ridge"),inset:e("Inset"),outset:e("Outset")}}function vC(e){return e('The color is invalid. Try "#FF0000" or "rgb(255,0,0)" or "red".')}function CC(e){return e('The value is invalid. Try "10px" or "2em" or simply "2".')}function AC(e){return e=e.trim().toLowerCase(),_C(e)||gl(e)}function xC(e){return e=e.trim(),_C(e)||RC(e)||wl(e)||_l(e)}function EC(e){return e=e.trim(),_C(e)||RC(e)||wl(e)}function TC(e,t){const o=new eo,i=kC(e.t);for(const n in i){const s={type:"button",model:new Jm({_borderStyleValue:n,label:i[n],role:"menuitemradio",withText:!0})};"none"===n?s.model.bind("isOn").to(e,"borderStyle",(e=>"none"===t?!e:e===n)):s.model.bind("isOn").to(e,"borderStyle",(e=>e===n)),o.add(s)}return o}function PC(e){const{view:t,icons:o,toolbar:i,labels:n,propertyName:s,nameToValue:r,defaultValue:a}=e;for(const e in n){const l=new Lu(t.locale);l.set({role:"radio",isToggleable:!0,label:n[e],icon:o[e],tooltip:n[e]});const c=r?r(e):e;l.bind("isOn").to(t,s,(e=>{let t=e;return""===e&&a&&(t=a),c===t})),l.on("execute",(()=>{!a&&c&&t[s]===c?t[s]=void 0:t[s]=c})),i.items.add(l)}}const SC=[{color:"hsl(0, 0%, 0%)",label:"Black"},{color:"hsl(0, 0%, 30%)",label:"Dim grey"},{color:"hsl(0, 0%, 60%)",label:"Grey"},{color:"hsl(0, 0%, 90%)",label:"Light grey"},{color:"hsl(0, 0%, 100%)",label:"White",hasBorder:!0},{color:"hsl(0, 75%, 60%)",label:"Red"},{color:"hsl(30, 75%, 60%)",label:"Orange"},{color:"hsl(60, 75%, 60%)",label:"Yellow"},{color:"hsl(90, 75%, 60%)",label:"Light green"},{color:"hsl(120, 75%, 60%)",label:"Green"},{color:"hsl(150, 75%, 60%)",label:"Aquamarine"},{color:"hsl(180, 75%, 60%)",label:"Turquoise"},{color:"hsl(210, 75%, 60%)",label:"Light blue"},{color:"hsl(240, 75%, 60%)",label:"Blue"},{color:"hsl(270, 75%, 60%)",label:"Purple"}];function IC(e){return(t,o,i)=>{const n=new wC(t.locale,{colorDefinitions:(s=e.colorConfig,s.map((e=>({color:e.model,label:e.label,options:{hasBorder:e.hasBorder}})))),columns:e.columns,defaultColorValue:e.defaultColorValue,colorPickerConfig:e.colorPickerConfig});var s;return n.inputView.set({id:o,ariaDescribedById:i}),n.bind("isReadOnly").to(t,"isEnabled",(e=>!e)),n.bind("hasError").to(t,"errorText",(e=>!!e)),n.on("input",(()=>{t.errorText=null})),t.bind("isEmpty","isFocused").to(n),n}}function RC(e){const t=parseFloat(e);return!Number.isNaN(t)&&e===String(t)}class OC extends Au{options;focusTracker;keystrokes;children;borderStyleDropdown;borderWidthInput;borderColorInput;backgroundInput;cellTypeDropdown;paddingInput;widthInput;heightInput;horizontalAlignmentToolbar;verticalAlignmentToolbar;saveButtonView;cancelButtonView;backButtonView;_focusables;_focusCycler;constructor(e,t){super(e),this.set({borderStyle:"",borderWidth:"",borderColor:"",padding:"",backgroundColor:"",width:"",height:"",horizontalAlignment:"",verticalAlignment:"",cellType:""}),this.options=t;const{borderStyleDropdown:o,borderWidthInput:i,borderColorInput:n,borderRowLabel:s}=this._createBorderFields(),{backgroundRowLabel:r,backgroundInput:a}=this._createBackgroundFields(),{cellTypeRowLabel:l,cellTypeDropdown:c}=this._createCellTypeField(),{widthInput:d,operatorLabel:u,heightInput:h,dimensionsLabel:m}=this._createDimensionFields(),{horizontalAlignmentToolbar:g,verticalAlignmentToolbar:p,alignmentLabel:f}=this._createAlignmentFields();this.focusTracker=new oo,this.keystrokes=new ro,this.children=this.createCollection(),this.borderStyleDropdown=o,this.borderWidthInput=i,this.borderColorInput=n,this.backgroundInput=a,this.cellTypeDropdown=c,this.paddingInput=this._createPaddingField(),this.widthInput=d,this.heightInput=h,this.horizontalAlignmentToolbar=g,this.verticalAlignmentToolbar=p;const{saveButtonView:b,cancelButtonView:w}=this._createActionButtons();this.saveButtonView=b,this.cancelButtonView=w,this.backButtonView=this._createBackButton(),this._focusables=new tu,this._focusCycler=new qu({focusables:this._focusables,focusTracker:this.focusTracker,keystrokeHandler:this.keystrokes,actions:{focusPrevious:"shift + tab",focusNext:"tab"}});const y=new ju(e,{label:this.t("Cell properties")});y.children.add(this.backButtonView,0),this.children.add(y),this.children.add(new Km(e,{labelView:s,children:[s,o,i,n],class:"ck-table-form__border-row"})),this.children.add(new Km(e,{children:[new Km(e,{labelView:l,children:[l,c],class:"ck-table-form__cell-type-row"}),new Km(e,{labelView:r,children:[r,a],class:"ck-table-form__background-row"})]})),this.children.add(new Km(e,{children:[new Km(e,{labelView:m,children:[m,d,u,h],class:"ck-table-form__dimensions-row"}),new Km(e,{children:[this.paddingInput],class:"ck-table-cell-properties-form__padding-row"})]})),this.children.add(new Km(e,{labelView:f,children:[f,g,p],class:"ck-table-cell-properties-form__alignment-row"})),this.children.add(new Km(e,{children:[this.cancelButtonView,this.saveButtonView],class:"ck-table-form__action-row"})),this.setTemplate({tag:"form",attributes:{class:["ck","ck-form","ck-table-form","ck-table-cell-properties-form"],tabindex:"-1"},children:this.children})}render(){super.render(),Ou({view:this}),[this.borderColorInput,this.backgroundInput].forEach((e=>{this._focusCycler.chain(e.fieldView.focusCycler)})),[this.borderStyleDropdown,this.borderColorInput,this.borderWidthInput,this.cellTypeDropdown,this.backgroundInput,this.widthInput,this.heightInput,this.paddingInput,this.horizontalAlignmentToolbar,this.verticalAlignmentToolbar,this.cancelButtonView,this.saveButtonView,this.backButtonView].forEach((e=>{this._focusables.add(e),this.focusTracker.add(e.element)})),this.keystrokes.listenTo(this.element)}destroy(){super.destroy(),this.focusTracker.destroy(),this.keystrokes.destroy()}focus(){this._focusCycler.focusFirst()}_createBorderFields(){const e=this.options.defaultTableCellProperties,t={style:e.borderStyle,width:e.borderWidth,color:e.borderColor},o=IC({colorConfig:this.options.borderColors,columns:5,defaultColorValue:t.color,colorPickerConfig:this.options.colorPickerConfig}),i=this.locale,n=this.t,s=n("Style"),r=new Du(i);r.text=n("Border");const a=kC(n),l=new Sh(i,rm);l.set({label:s,class:"ck-table-form__border-style"}),l.fieldView.buttonView.set({ariaLabel:s,ariaLabelledBy:void 0,isOn:!1,withText:!0,tooltip:s}),l.fieldView.buttonView.bind("label").to(this,"borderStyle",(e=>a[e||"none"])),l.fieldView.on("execute",(e=>{this.borderStyle=e.source._borderStyleValue})),l.bind("isEmpty").to(this,"borderStyle",(e=>!e)),Xh(l.fieldView,TC(this,t.style),{role:"menu",ariaLabel:s});const c=new Sh(i,nm);c.set({label:n("Width"),class:"ck-table-form__border-width"}),c.fieldView.bind("value").to(this,"borderWidth"),c.bind("isEnabled").to(this,"borderStyle",VC),c.fieldView.on("input",(()=>{this.borderWidth=c.fieldView.element.value}));const d=new Sh(i,o);return d.set({label:n("Color"),class:"ck-table-form__border-color"}),d.fieldView.bind("value").to(this,"borderColor"),d.bind("isEnabled").to(this,"borderStyle",VC),d.fieldView.on("input",(()=>{this.borderColor=d.fieldView.value})),this.on("change:borderStyle",((e,o,i,n)=>{VC(i)||(this.borderColor="",this.borderWidth=""),VC(n)||(this.borderColor=t.color,this.borderWidth=t.width)})),{borderRowLabel:r,borderStyleDropdown:l,borderColorInput:d,borderWidthInput:c}}_createBackgroundFields(){const e=this.locale,t=this.t,o=new Du(e);o.text=t("Background");const i=IC({colorConfig:this.options.backgroundColors,columns:5,defaultColorValue:this.options.defaultTableCellProperties.backgroundColor,colorPickerConfig:this.options.colorPickerConfig}),n=new Sh(e,i);return n.set({label:t("Color"),class:"ck-table-cell-properties-form__background"}),n.fieldView.bind("value").to(this,"backgroundColor"),n.fieldView.on("input",(()=>{this.backgroundColor=n.fieldView.value})),{backgroundRowLabel:o,backgroundInput:n}}_createCellTypeField(){const e=this.locale,t=this.t,o=new Du(e);o.text=t("Cell type");const i=this._cellTypeLabels,n=new Sh(e,rm);return n.set({label:t("Cell type"),class:"ck-table-cell-properties-form__cell-type"}),n.fieldView.buttonView.set({ariaLabel:t("Cell type"),ariaLabelledBy:void 0,isOn:!1,withText:!0,tooltip:t("Cell type")}),n.fieldView.buttonView.bind("label").to(this,"cellType",(e=>i[e||"data"])),n.fieldView.on("execute",(e=>{this.cellType=e.source._cellTypeValue})),n.bind("isEmpty").to(this,"cellType",(e=>!e)),Xh(n.fieldView,this._getCellTypeDefinitions(),{role:"menu",ariaLabel:t("Cell type")}),{cellTypeRowLabel:o,cellTypeDropdown:n}}_createDimensionFields(){const e=this.locale,t=this.t,o=new Du(e);o.text=t("Dimensions");const i=new Sh(e,nm);i.set({label:t("Width"),class:"ck-table-form__dimensions-row__width"}),i.fieldView.bind("value").to(this,"width"),i.fieldView.on("input",(()=>{this.width=i.fieldView.element.value}));const n=new Au(e);n.setTemplate({tag:"span",attributes:{class:["ck-table-form__dimension-operator"]},children:[{text:"×"}]});const s=new Sh(e,nm);return s.set({label:t("Height"),class:"ck-table-form__dimensions-row__height"}),s.fieldView.bind("value").to(this,"height"),s.fieldView.on("input",(()=>{this.height=s.fieldView.element.value})),{dimensionsLabel:o,widthInput:i,operatorLabel:n,heightInput:s}}_createPaddingField(){const e=this.locale,t=this.t,o=new Sh(e,nm);return o.set({label:t("Padding"),class:"ck-table-cell-properties-form__padding"}),o.fieldView.bind("value").to(this,"padding"),o.fieldView.on("input",(()=>{this.padding=o.fieldView.element.value})),o}_createAlignmentFields(){const e=this.locale,t=this.t,o=new Du(e),i={left:jc,center:'',right:'',justify:'',top:'',middle:'',bottom:''};o.text=t("Table cell text alignment");const n=new Wh(e),s="rtl"===e.contentLanguageDirection;n.set({isCompact:!0,role:"radiogroup",ariaLabel:t("Horizontal text alignment toolbar"),class:"ck-table-cell-properties-form__horizontal-alignment-toolbar"}),PC({view:this,icons:i,toolbar:n,labels:this._horizontalAlignmentLabels,propertyName:"horizontalAlignment",nameToValue:e=>{if(s){if("left"===e)return"right";if("right"===e)return"left"}return e},defaultValue:this.options.defaultTableCellProperties.horizontalAlignment});const r=new Wh(e);return r.set({isCompact:!0,role:"radiogroup",ariaLabel:t("Vertical text alignment toolbar"),class:"ck-table-cell-properties-form__vertical-alignment-toolbar"}),PC({view:this,icons:i,toolbar:r,labels:this._verticalAlignmentLabels,propertyName:"verticalAlignment",defaultValue:this.options.defaultTableCellProperties.verticalAlignment}),{horizontalAlignmentToolbar:n,verticalAlignmentToolbar:r,alignmentLabel:o}}_createActionButtons(){const e=this.locale,t=this.t,o=new Lu(e),i=new Lu(e),n=[this.borderWidthInput,this.borderColorInput,this.backgroundInput,this.paddingInput];return o.set({label:t("Save"),class:"ck-button-action",type:"submit",withText:!0}),o.bind("isEnabled").toMany(n,"errorText",((...e)=>e.every((e=>!e)))),i.set({label:t("Cancel"),withText:!0}),i.delegate("execute").to(this,"cancel"),{saveButtonView:o,cancelButtonView:i}}_createBackButton(){const e=this.locale.t,t=new Lu(this.locale);return t.set({class:"ck-button-back",label:e("Back"),icon:ed,tooltip:!0}),t.delegate("execute").to(this,"cancel"),t}_getCellTypeDefinitions(){const e=new eo,t=this._cellTypeLabels,o=["data","header"];this.options.showScopedHeaderOptions&&o.push("header-column","header-row");for(const i of o){const o={type:"button",model:new Jm({_cellTypeValue:i,label:t[i],role:"menuitemradio",withText:!0})};o.model.bind("isOn").to(this,"cellType",(e=>e===i)),e.add(o)}return e}get _horizontalAlignmentLabels(){const e=this.locale,t=this.t,o=t("Align cell text to the left"),i=t("Align cell text to the center"),n=t("Align cell text to the right"),s=t("Justify cell text");return"rtl"===e.uiLanguageDirection?{right:n,center:i,left:o,justify:s}:{left:o,center:i,right:n,justify:s}}get _verticalAlignmentLabels(){const e=this.t;return{top:e("Align cell text to the top"),middle:e("Align cell text to the middle"),bottom:e("Align cell text to the bottom")}}get _cellTypeLabels(){const e=this.t;return{data:e("Data cell"),header:e("Header cell"),"header-column":e("Column header"),"header-row":e("Row header")}}}function VC(e){return"none"!==e}const DC=(()=>[dh.defaultPositions.northArrowSouth,dh.defaultPositions.northArrowSouthWest,dh.defaultPositions.northArrowSouthEast,dh.defaultPositions.southArrowNorth,dh.defaultPositions.southArrowNorthWest,dh.defaultPositions.southArrowNorthEast,dh.defaultPositions.viewportStickyNorth])();function FC(e,t){const o=e.plugins.get("ContextualBalloon"),i=e.editing.view.document.selection;let n;"cell"===t?fC(i)&&(n=NC(e)):gC(i)&&(n=MC(e)),n&&o.updatePosition(n)}function MC(e){const t=qk(e.model.document.selection),o=e.editing.mapper.toViewElement(t);return{target:e.editing.view.domConverter.mapViewToDom(o),positions:DC}}function NC(e){const t=e.editing.mapper,o=e.editing.view.domConverter,i=e.model.document.selection;if(i.rangeCount>1)return{target:()=>function(e,t){const o=t.editing.mapper,i=t.editing.view.domConverter,n=Array.from(e).map((e=>{const t=BC(e.start),n=o.toViewElement(t);return new ut(i.mapViewToDom(n))}));return ut.getBoundingRect(n)}(i.getRanges(),e),positions:DC};const n=BC(i.getFirstPosition()),s=t.toViewElement(n);return{target:o.mapViewToDom(s),positions:DC}}function BC(e){return e.nodeAfter&&e.nodeAfter.is("element","tableCell")?e.nodeAfter:e.findAncestor("tableCell")}const LC={borderStyle:"tableCellBorderStyle",borderColor:"tableCellBorderColor",borderWidth:"tableCellBorderWidth",height:"tableCellHeight",width:"tableCellWidth",padding:"tableCellPadding",backgroundColor:"tableCellBackgroundColor",horizontalAlignment:"tableCellHorizontalAlignment",verticalAlignment:"tableCellVerticalAlignment",cellType:"tableCellType"};class zC extends fc{_defaultContentTableCellProperties;_defaultLayoutTableCellProperties;_balloon;view;_viewWithContentTableDefaults;_viewWithLayoutTableDefaults;_undoStepBatch;_isReady;static get requires(){return[Qm]}static get pluginName(){return"TableCellPropertiesUI"}static get isOfficialPlugin(){return!0}constructor(e){super(e),e.config.define("table.tableCellProperties",{borderColors:SC,backgroundColors:SC})}init(){const e=this.editor,t=e.t;this._defaultContentTableCellProperties=bv(e.config.get("table.tableCellProperties.defaultProperties"),{includeVerticalAlignmentProperty:!0,includeHorizontalAlignmentProperty:!0,includePaddingProperty:!0,isRightToLeftContent:"rtl"===e.locale.contentLanguageDirection}),this._defaultLayoutTableCellProperties=pv(void 0,{includeVerticalAlignmentProperty:!0,includeHorizontalAlignmentProperty:!0,isRightToLeftContent:"rtl"===e.locale.contentLanguageDirection}),this._balloon=e.plugins.get(Qm),this.view=null,this._isReady=!1,e.ui.componentFactory.add("tableCellProperties",(o=>{const i=new Lu(o);i.set({label:t("Cell properties"),icon:'',tooltip:!0}),this.listenTo(i,"execute",(()=>this._showView()));const n=Object.values(LC).map((t=>e.commands.get(t))).filter((e=>!!e));return i.bind("isEnabled").toMany(n,"isEnabled",((...e)=>e.some((e=>e)))),i}))}destroy(){super.destroy(),this.view&&this.view.destroy()}_createPropertiesView(e){const t=this.editor,o=t.config.get("table.tableCellProperties"),i=!!t.config.get("table.tableCellProperties.scopedHeaders"),n=Ch(o.borderColors),s=vh(t.locale,n),r=Ch(o.backgroundColors),a=vh(t.locale,r),l=!1!==o.colorPicker,c=new OC(t.locale,{borderColors:s,backgroundColors:a,defaultTableCellProperties:e,colorPickerConfig:!!l&&(o.colorPicker||{}),showScopedHeaderOptions:i}),d=t.t;c.render(),this.listenTo(c,"submit",(()=>{this._hideView()})),this.listenTo(c,"cancel",(()=>{this._undoStepBatch.operations.length&&t.execute("undo",this._undoStepBatch),this._hideView()})),c.keystrokes.set("Esc",((e,t)=>{this._hideView(),t()})),Su({emitter:c,activator:()=>this._isViewInBalloon,contextElements:[this._balloon.view.element],callback:()=>this._hideView()});const u=vC(d),h=CC(d);c.on("change:borderStyle",this._getPropertyChangeCallback("tableCellBorderStyle")),c.on("change:borderColor",this._getValidatedPropertyChangeCallback({viewField:c.borderColorInput,commandName:"tableCellBorderColor",errorText:u,validator:AC})),c.on("change:borderWidth",this._getValidatedPropertyChangeCallback({viewField:c.borderWidthInput,commandName:"tableCellBorderWidth",errorText:h,validator:EC})),c.on("change:padding",this._getValidatedPropertyChangeCallback({viewField:c.paddingInput,commandName:"tableCellPadding",errorText:h,validator:xC})),c.on("change:width",this._getValidatedPropertyChangeCallback({viewField:c.widthInput,commandName:"tableCellWidth",errorText:h,validator:xC})),c.on("change:height",this._getValidatedPropertyChangeCallback({viewField:c.heightInput,commandName:"tableCellHeight",errorText:h,validator:xC})),c.on("change:backgroundColor",this._getValidatedPropertyChangeCallback({viewField:c.backgroundInput,commandName:"tableCellBackgroundColor",errorText:u,validator:AC})),c.on("change:horizontalAlignment",this._getPropertyChangeCallback("tableCellHorizontalAlignment")),c.on("change:verticalAlignment",this._getPropertyChangeCallback("tableCellVerticalAlignment"));const m=t.commands.get("tableCellType");return m&&(c.cellTypeDropdown.bind("isEnabled").to(m,"isEnabled"),c.on("change:cellType",this._getPropertyChangeCallback("tableCellType"))),c}_fillViewFormFromCommandValues(){const e=this.editor.commands,t=e.get("tableCellBorderStyle");Object.entries(LC).flatMap((([t,o])=>{const i=e.get(o);if(!i)return[];const n=t;let s;s="cellType"===n?"":this.view===this._viewWithContentTableDefaults?this._defaultContentTableCellProperties[n]||"":this._defaultLayoutTableCellProperties[n]||"";return[[t,i.value||s]]})).forEach((([e,o])=>{("borderColor"!==e&&"borderWidth"!==e||"none"!==t.value)&&this.view.set(e,o)})),this._isReady=!0}_showView(){const e=this.editor,t=gC(e.editing.view.document.selection),o=t&&e.editing.mapper.toModelElement(t),i=!o||"layout"!==o.getAttribute("tableType");i&&!this._viewWithContentTableDefaults?this._viewWithContentTableDefaults=this._createPropertiesView(this._defaultContentTableCellProperties):i||this._viewWithLayoutTableDefaults||(this._viewWithLayoutTableDefaults=this._createPropertiesView(this._defaultLayoutTableCellProperties)),this.view=i?this._viewWithContentTableDefaults:this._viewWithLayoutTableDefaults,this.listenTo(e.ui,"update",(()=>{this._updateView()})),this._fillViewFormFromCommandValues(),this._balloon.add({view:this.view,position:NC(e)}),this._undoStepBatch=e.model.createBatch(),this.view.focus()}_hideView(){const e=this.editor;this.stopListening(e.ui,"update"),this._isReady=!1,this.view.saveButtonView.focus(),this._balloon.remove(this.view),this.editor.editing.view.focus()}_updateView(){const e=this.editor;fC(e.editing.view.document.selection)?this._isViewVisible&&FC(e,"cell"):this._hideView()}get _isViewVisible(){return!!this.view&&this._balloon.visibleView===this.view}get _isViewInBalloon(){return!!this.view&&this._balloon.hasView(this.view)}_getPropertyChangeCallback(e){return(t,o,i)=>{this._isReady&&this.editor.execute(e,{value:i,batch:this._undoStepBatch})}}_getValidatedPropertyChangeCallback(e){const{commandName:t,viewField:o,validator:i,errorText:n}=e,s=zo((()=>{o.errorText=n}),500);return(e,n,r)=>{s.cancel(),this._isReady&&(i(r)?(this.editor.execute(t,{value:r,batch:this._undoStepBatch}),o.errorText=null):s())}}}class jC extends wc{attributeName;_defaultValue;_defaultContentTableValue;_defaultLayoutTableValue;constructor(e,t,o){switch(super(e),this.attributeName=t,this._defaultContentTableValue=o,t){case"tableCellType":this._defaultLayoutTableValue="data";break;case"tableCellBorderStyle":this._defaultLayoutTableValue="none";break;case"tableCellHorizontalAlignment":this._defaultLayoutTableValue="left";break;case"tableCellVerticalAlignment":this._defaultLayoutTableValue="middle";break;default:this._defaultLayoutTableValue=void 0}}refresh(){const e=this.editor.model.document.selection,t=this.editor.plugins.get("TableUtils").getSelectionAffectedTableCells(e),o=qk(e);this._defaultValue=o&&"layout"===o.getAttribute("tableType")?this._defaultLayoutTableValue:this._defaultContentTableValue,this.isEnabled=!!t.length,this.value=this._getSingleValue(t)}execute(e={}){const{value:t,batch:o}=e,i=this.editor.model,n=this.editor.plugins.get("TableUtils").getSelectionAffectedTableCells(i.document.selection),s=this._getValueToSet(t);i.enqueueChange(o,(e=>{s?n.forEach((t=>e.setAttribute(this.attributeName,s,t))):n.forEach((t=>e.removeAttribute(this.attributeName,t))),this.fire("afterExecute",{writer:e,tableCells:n,valueToSet:s})}))}_getAttribute(e){if(!e)return;const t=e.getAttribute(this.attributeName);return t!==this._defaultValue?t:void 0}_getValueToSet(e){if(e!==this._defaultValue)return e}_getSingleValue(e){const t=this._getAttribute(e[0]);return e.every((e=>this._getAttribute(e)===t))?t:void 0}}class qC extends jC{constructor(e,t){super(e,"tableCellWidth",t)}_getValueToSet(e){if((e=gv(e,"px"))!==this._defaultValue)return e}}class $C extends fc{static get pluginName(){return"TableCellWidthEditing"}static get isOfficialPlugin(){return!0}static get requires(){return[Xv]}init(){const e=this.editor,t=bv(e.config.get("table.tableCellProperties.defaultProperties"));jk(e.model.schema,e.conversion,{modelAttribute:"tableCellWidth",styleName:"width",attributeName:"width",attributeType:"length",defaultValue:t.width}),e.commands.add("tableCellWidth",new qC(e,t.width))}}class HC extends jC{constructor(e,t){super(e,"tableCellPadding",t)}_getAttribute(e){if(!e)return;const t=mv(e.getAttribute(this.attributeName));return t!==this._defaultValue?t:void 0}_getValueToSet(e){const t=gv(e,"px");if(t!==this._defaultValue)return t}}class WC extends jC{constructor(e,t){super(e,"tableCellHeight",t)}_getValueToSet(e){const t=gv(e,"px");if(t!==this._defaultValue)return t}}class UC extends jC{constructor(e,t){super(e,"tableCellBackgroundColor",t)}}class KC extends jC{constructor(e,t){super(e,"tableCellVerticalAlignment",t)}}class GC extends jC{constructor(e,t){super(e,"tableCellHorizontalAlignment",t)}}class JC extends jC{constructor(e,t){super(e,"tableCellBorderStyle",t)}_getAttribute(e){if(!e)return;const t=mv(e.getAttribute(this.attributeName));return t!==this._defaultValue?t:void 0}}class ZC extends jC{constructor(e,t){super(e,"tableCellBorderColor",t)}_getAttribute(e){if(!e)return;const t=mv(e.getAttribute(this.attributeName));return t!==this._defaultValue?t:void 0}}class QC extends jC{constructor(e,t){super(e,"tableCellBorderWidth",t)}_getAttribute(e){if(!e)return;const t=mv(e.getAttribute(this.attributeName));return t!==this._defaultValue?t:void 0}_getValueToSet(e){const t=gv(e,"px");if(t!==this._defaultValue)return t}}class YC extends jC{constructor(e){super(e,"tableCellType","data"),this.on("afterExecute",((e,t)=>{const{writer:o,tableCells:i}=t,n=this.editor.plugins.get(av),s=function(e){const t=new Map;for(const o of e){const e=o.findAncestor("table");t.has(e)||t.set(e,[]),t.get(e).push(o)}return t}(i);XC(n,o,s.keys())}))}refresh(){super.refresh();const e=qk(this.editor.model.document.selection);this.isEnabled&&e&&"layout"===e.getAttribute("tableType")&&(this.isEnabled=!1)}_getAttribute(e){return e?.getAttribute(this.attributeName)||"data"}}function XC(e,t,o){let i=!1;for(const n of o){let o=n.getAttribute("headingRows")||0,s=n.getAttribute("headingColumns")||0;const r=n.getAttribute("footerRows")||0,a=e.getRows(n)-r,l=s>o;if(l){const r=eA(e,n,"column",s,o);r!==s&&(e.setHeadingColumnsCount(t,n,r,{updateCellType:!1}),s=r,i=!0)}let c=eA(e,n,"row",o,s);if(r>0&&(c=Math.min(c,a)),c!==o&&(e.setHeadingRowsCount(t,n,c,{updateCellType:!1}),o=c,i=!0),!l){const r=eA(e,n,"column",s,o);r!==s&&(e.setHeadingColumnsCount(t,n,r,{updateCellType:!1}),i=!0)}}return i}function eA(e,t,o,i,n){const s="row"===o?e.getRows(t):e.getColumns(t);let r=i;for(let e=0;e=n&&(a=!0)}if(!s)return Math.min(r,e);a&&(r=Math.max(r,e+1))}return Math.min(r,s)}const tA=/^(top|middle|bottom)$/,oA=/^(left|center|right|justify)$/;class iA extends fc{static get pluginName(){return"TableCellPropertiesEditing"}static get licenseFeatureCode(){return"TCP"}static get isOfficialPlugin(){return!0}static get isPremiumPlugin(){return!0}static get requires(){return[Xv,$C]}init(){const e=this.editor,t=e.model.schema,o=e.conversion;e.config.define("table.tableCellProperties.defaultProperties",{});const i=bv(e.config.get("table.tableCellProperties.defaultProperties"),{includeVerticalAlignmentProperty:!0,includeHorizontalAlignmentProperty:!0,includePaddingProperty:!0,isRightToLeftContent:"rtl"===e.locale.contentLanguageDirection});e.data.addStyleProcessorRules(Hl),function(e,t){const{conversion:o}=e,{schema:i}=e.model,n={width:"tableCellBorderWidth",color:"tableCellBorderColor",style:"tableCellBorderStyle"};i.extend("tableCell",{allowAttributes:Object.values(n)});for(const e of Object.values(n))i.setAttributeProperties(e,{isFormatting:!0});vk(e,"td",n,t),vk(e,"th",n,t),Ck(o,{modelElement:"tableCell",modelAttribute:n.style,styleName:"border-style"}),Ck(o,{modelElement:"tableCell",modelAttribute:n.color,styleName:"border-color"}),Ck(o,{modelElement:"tableCell",modelAttribute:n.width,styleName:"border-width"})}(e,{color:i.borderColor,style:i.borderStyle,width:i.borderWidth}),e.commands.add("tableCellBorderStyle",new JC(e,i.borderStyle)),e.commands.add("tableCellBorderColor",new ZC(e,i.borderColor)),e.commands.add("tableCellBorderWidth",new QC(e,i.borderWidth)),jk(t,o,{modelAttribute:"tableCellHeight",styleName:"height",attributeName:"height",attributeType:"length",defaultValue:i.height}),e.commands.add("tableCellHeight",new WC(e,i.height)),e.data.addStyleProcessorRules(tc),jk(t,o,{modelAttribute:"tableCellPadding",styleName:"padding",reduceBoxSides:!0,defaultValue:i.padding}),function(e,t){Tk(e,"td",t),Tk(e,"th",t)}(e,i.padding),e.commands.add("tableCellPadding",new HC(e,i.padding)),e.data.addStyleProcessorRules(Bl),jk(t,o,{modelAttribute:"tableCellBackgroundColor",styleName:"background-color",attributeName:"bgcolor",attributeType:"color",defaultValue:i.backgroundColor}),e.commands.add("tableCellBackgroundColor",new UC(e,i.backgroundColor)),function(e,t,o){e.extend("tableCell",{allowAttributes:["tableCellHorizontalAlignment"]}),e.setAttributeProperties("tableCellHorizontalAlignment",{isFormatting:!0}),t.for("downcast").attributeToAttribute({model:{name:"tableCell",key:"tableCellHorizontalAlignment"},view:e=>({key:"style",value:{"text-align":e}})}),t.for("upcast").attributeToAttribute({view:{name:/^(td|th)$/,styles:{"text-align":oA}},model:{key:"tableCellHorizontalAlignment",value:(e,t,i)=>{const n=xk(o,"left",i),s=e.getStyle("text-align");if(s!==n)return s;t.consumable.consume(e,{styles:"text-align"})}}}).attributeToAttribute({view:{name:/^(td|th)$/,attributes:{align:oA}},model:{key:"tableCellHorizontalAlignment",value:(e,t,i)=>{const n=xk(o,"left",i),s=e.getAttribute("align");if(s!==n)return s;t.consumable.consume(e,{attributes:"align"})}}})}(t,o,i.horizontalAlignment),e.commands.add("tableCellHorizontalAlignment",new GC(e,i.horizontalAlignment)),function(e,t,o){e.extend("tableCell",{allowAttributes:["tableCellVerticalAlignment"]}),e.setAttributeProperties("tableCellVerticalAlignment",{isFormatting:!0}),t.for("downcast").attributeToAttribute({model:{name:"tableCell",key:"tableCellVerticalAlignment"},view:e=>({key:"style",value:{"vertical-align":e}})}),t.for("upcast").attributeToAttribute({view:{name:/^(td|th)$/,styles:{"vertical-align":tA}},model:{key:"tableCellVerticalAlignment",value:(e,t,i)=>{const n=xk(o,"middle",i),s=e.getStyle("vertical-align");if(s!==n)return s;t.consumable.consume(e,{styles:"vertical-align"})}}}).attributeToAttribute({view:{name:/^(td|th)$/,attributes:{valign:tA}},model:{key:"tableCellVerticalAlignment",value:(e,t,i)=>{const n=xk(o,"middle",i),s=e.getAttribute("valign");if(s!==n)return s;t.consumable.consume(e,{attributes:"valign"})}}})}(t,o,i.verticalAlignment),e.commands.add("tableCellVerticalAlignment",new KC(e,i.verticalAlignment)),function(e){const{model:t,conversion:o,editing:i,config:n}=e,{schema:s}=t;n.define("table.tableCellProperties.scopedHeaders",!0);const r=!!n.get("table.tableCellProperties.scopedHeaders"),a=e.plugins.get(av);s.extend("tableCell",{allowAttributes:["tableCellType"]}),s.setAttributeProperties("tableCellType",{isFormatting:!0}),s.addAttributeCheck((e=>{const t=Array.from(e).reverse().find((e=>"table"===e.name));if("layout"===t?.getAttribute("tableType"))return!1}),"tableCellType"),o.for("upcast").add((e=>{e.on("element:th",((e,t,o)=>{const{writer:i}=o,{modelRange:n}=t,s=n?.start.nodeAfter;s?.is("element","tableCell")&&!s.hasAttribute("tableCellType")&&i.setAttribute("tableCellType","header",s)})),e.on("element:table",((e,t,o)=>{const{writer:i}=o,{modelRange:n}=t,s=n?.start.nodeAfter;if(s?.is("element","table")&&"layout"===s.getAttribute("tableType"))for(const{cell:e}of new Fk(s)){if(Nk(e.getAttribute("tableCellType"))){i.setAttribute("tableType","content",s);break}}}),{priority:ge.low-1})})),r&&(o.for("downcast").attributeToAttribute({model:{name:"tableCell",key:"tableCellType"},view:e=>{switch(e){case"header-row":return{key:"scope",value:"row"};case"header-column":return{key:"scope",value:"col"}}}}),o.for("upcast").add((e=>{e.on("element:th",((e,t,o)=>{const{writer:i,consumable:n}=o,{viewItem:s,modelRange:r}=t,a=r.start.nodeAfter,l=a?.getAttribute("tableCellType");if("header"===l&&n.consume(s,{attributes:["scope"]})){switch(s.getAttribute("scope")){case"row":i.setAttribute("tableCellType","header-row",a);break;case"col":i.setAttribute("tableCellType","header-column",a)}}}))})));t.document.registerPostFixer((e=>{const o=t.document.differ.getChanges(),i=new Set;for(const e of o){if("attribute"===e.type&&("headingRows"===e.attributeKey||"headingColumns"===e.attributeKey)){const t=e.range.start.nodeAfter;t?.is("element","table")&&"$graveyard"!==t.root.rootName&&i.add(t)}if("attribute"===e.type&&"tableCellType"===e.attributeKey){const t=e.range.start.nodeAfter;if(t?.is("element","tableCell")&&"$graveyard"!==t.root.rootName){const e=t.findAncestor("table");e&&i.add(e)}}if("insert"===e.type&&e.position.nodeAfter)for(const{item:o}of t.createRangeOn(e.position.nodeAfter))if(o.is("element","tableCell")&&o.getAttribute("tableCellType")&&"$graveyard"!==o.root.rootName){const e=o.findAncestor("table");e&&i.add(e)}}return XC(a,e,i)})),t.document.on("change:data",(()=>{const{differ:e}=t.document,o=new Set;for(const t of e.getChanges())if("attribute"===t.type&&"tableCellType"===t.attributeKey){const e=t.range.start.nodeAfter;e.is("element","tableCell")&&o.add(e)}for(const e of o){const t=i.mapper.toViewElement(e),o=Nk(e.getAttribute("tableCellType"))?"th":"td";t?.name!==o&&i.reconvertItem(e)}}))}(e),e.commands.add("tableCellType",new YC(e))}}class nA extends wc{attributeName;_defaultValue;_defaultContentTableValue;_defaultLayoutTableValue;constructor(e,t,o){super(e),this.attributeName=t,this._defaultContentTableValue=o,this._defaultLayoutTableValue="tableBorderStyle"===t?"none":void 0}refresh(){const e=qk(this.editor.model.document.selection);this._defaultValue=e&&"layout"===e.getAttribute("tableType")?this._defaultLayoutTableValue:this._defaultContentTableValue,this.isEnabled=!!e,this.value=this._getValue(e)}execute(e={}){const t=this.editor.model,o=t.document.selection,{value:i,batch:n}=e,s=qk(o),r=this._getValueToSet(i);t.enqueueChange(n,(e=>{r?e.setAttribute(this.attributeName,r,s):e.removeAttribute(this.attributeName,s)}))}_getValue(e){if(!e)return;const t=e.getAttribute(this.attributeName);return t!==this._defaultValue?t:void 0}_getValueToSet(e){if(e!==this._defaultValue)return e}}class sA extends nA{constructor(e,t){super(e,"tableBackgroundColor",t)}}class rA extends nA{constructor(e,t){super(e,"tableBorderColor",t)}_getValue(e){if(!e)return;const t=mv(e.getAttribute(this.attributeName));return t!==this._defaultValue?t:void 0}}class aA extends nA{constructor(e,t){super(e,"tableBorderStyle",t)}_getValue(e){if(!e)return;const t=mv(e.getAttribute(this.attributeName));return t!==this._defaultValue?t:void 0}}class lA extends nA{constructor(e,t){super(e,"tableBorderWidth",t)}_getValue(e){if(!e)return;const t=mv(e.getAttribute(this.attributeName));return t!==this._defaultValue?t:void 0}_getValueToSet(e){const t=gv(e,"px");if(t!==this._defaultValue)return t}}class cA extends nA{constructor(e,t){super(e,"tableWidth",t)}_getValueToSet(e){if((e=gv(e,"px"))!==this._defaultValue)return e}}class dA extends nA{constructor(e,t){super(e,"tableHeight",t)}_getValueToSet(e){if((e=gv(e,"px"))!==this._defaultValue)return e}}class uA extends nA{constructor(e,t){super(e,"tableAlignment",t)}}class hA extends fc{static get pluginName(){return"TablePropertiesEditing"}static get licenseFeatureCode(){return"TCP"}static get isOfficialPlugin(){return!0}static get isPremiumPlugin(){return!0}static get requires(){return[Xv]}init(){const e=this.editor,t=e.model.schema,o=e.conversion;e.config.define("table.tableProperties.defaultProperties",{});const i=fv(e.config.get("table.tableProperties.defaultProperties"),{includeAlignmentProperty:!0}),n=!0===e.config.get("table.tableProperties.alignment.useInlineStyles");e.data.addStyleProcessorRules(ec),e.data.addStyleProcessorRules(Hl),function(e,t){const{conversion:o}=e,{schema:i}=e.model,n={width:"tableBorderWidth",color:"tableBorderColor",style:"tableBorderStyle"};i.extend("table",{allowAttributes:Object.values(n)});for(const e of Object.values(n))i.setAttributeProperties(e,{isFormatting:!0});vk(e,"table",n,t),Ak(o,{modelAttribute:n.color,styleName:"border-color"}),Ak(o,{modelAttribute:n.style,styleName:"border-style"}),Ak(o,{modelAttribute:n.width,styleName:"border-width"})}(e,{color:i.borderColor,style:i.borderStyle,width:i.borderWidth}),e.commands.add("tableBorderColor",new rA(e,i.borderColor)),e.commands.add("tableBorderStyle",new aA(e,i.borderStyle)),e.commands.add("tableBorderWidth",new lA(e,i.borderWidth)),function(e,t,o,i){e.extend("table",{allowAttributes:["tableAlignment"]}),e.setAttributeProperties("tableAlignment",{isFormatting:!0}),t.for("downcast").attributeToAttribute({model:{name:"table",key:"tableAlignment",values:["left","center","right","blockLeft","blockRight"]},view:{left:i?{key:"style",value:{float:"left","margin-right":"var(--ck-content-table-style-spacing, 1.5em)"}}:{key:"class",value:Pk.className},right:i?{key:"style",value:{float:"right","margin-left":"var(--ck-content-table-style-spacing, 1.5em)"}}:{key:"class",value:Ik.className},center:i?{key:"style",value:{"margin-left":"auto","margin-right":"auto"}}:{key:"class",value:Sk.className},blockLeft:i?{key:"style",value:{"margin-left":"0","margin-right":"auto"}}:{key:"class",value:Rk.className},blockRight:i?{key:"style",value:{"margin-left":"auto","margin-right":"0"}}:{key:"class",value:Ok.className}},converterPriority:"high"}),Vk.forEach((e=>{t.for("upcast").attributeToAttribute({view:e.view,model:{key:"tableAlignment",value:(t,i,n)=>{if(function(e){return"figure"==e.name&&!e.hasClass("table")}(t))return;const s=xk(o,"",n),r=e.getAlign(t),a=e.getConsumables(t);return i.consumable.consume(t,a),r!==s?r:void 0}}})})),t.for("upcast").add(function(e){return t=>{t.on("element:div",((t,o,i)=>{if(!i.consumable.test(o.viewItem,{name:!0,attributes:"align"}))return;const n=ov(o.viewItem);if(!n||!i.consumable.test(n,{name:!0}))return;i.consumable.consume(o.viewItem,{name:!0,attributes:"align"});const s=i.convertItem(n,o.modelCursor),r=to(s.modelRange.getItems());if(!r||!r.is("element","table"))return i.consumable.revert(o.viewItem,{name:!0,attributes:"align"}),void(s.modelRange&&!s.modelRange.isCollapsed&&(o.modelRange=s.modelRange,o.modelCursor=s.modelCursor));const a=function(e,t,o){if(e)switch(e){case"right":return"right"===t?"right":"left"===t?"left":"blockRight";case"center":return"center";case"left":return void 0===t?"blockLeft":"left";default:return o}return}(o.viewItem.getAttribute("align"),n.getAttribute("align"),xk(e,"",o));a&&i.writer.setAttribute("tableAlignment",a,r),i.convertChildren(o.viewItem,i.writer.createPositionAt(r,"end")),i.updateConversionResult(r,o)}))}}(o))}(t,o,i.alignment,n),e.commands.add("tableAlignment",new uA(e,i.alignment)),pA(t,o,{modelAttribute:"tableWidth",styleName:"width",attributeName:"width",attributeType:"length",defaultValue:i.width}),e.commands.add("tableWidth",new cA(e,i.width)),pA(t,o,{modelAttribute:"tableHeight",styleName:"height",attributeName:"height",attributeType:"length",defaultValue:i.height}),e.commands.add("tableHeight",new dA(e,i.height)),e.data.addStyleProcessorRules(Bl),function(e,t,o){const{modelAttribute:i}=o;e.extend("table",{allowAttributes:[i]}),e.setAttributeProperties(i,{isFormatting:!0}),kk(t,{viewElement:"table",...o}),Ak(t,o)}(t,o,{modelAttribute:"tableBackgroundColor",styleName:"background-color",attributeName:"bgcolor",attributeType:"color",defaultValue:i.backgroundColor}),e.commands.add("tableBackgroundColor",new sA(e,i.backgroundColor)),Tk(e,"table");const s=e.editing.view.document;this.listenTo(s,"clipboardOutput",((t,o)=>{e.editing.view.change((e=>{for(const{item:t}of e.createRangeIn(o.content))mA(t,e);o.dataTransfer.setData("text/html",this.editor.data.htmlProcessor.toData(o.content))}))}),{priority:"lowest"})}}function mA(e,t){if(!e.is("element","table"))return;const o=e.getAttribute("align"),i=e.getStyle("float"),n=e.getStyle("margin-left"),s=e.getStyle("margin-right");o&&"center"===o||i&&"right"===i&&o&&"right"===o?gA(t,o,e):void 0===i&&"auto"===n&&"0"===s&&gA(t,"right",e)}function gA(e,t,o){const i=e.createPositionBefore(o),n=e.createContainerElement("div",{align:t},o);e.insert(i,n)}function pA(e,t,o){const{modelAttribute:i}=o;e.extend("table",{allowAttributes:[i]}),e.setAttributeProperties(i,{isFormatting:!0}),kk(t,{viewElement:/^(table|figure)$/,shouldUpcast:e=>!("table"==e.name&&"figure"==e.parent.name||"figure"==e.name&&!e.hasClass("table")),...o}),Ck(t,{modelElement:"table",...o})}class fA extends Au{options;focusTracker;keystrokes;children;borderStyleDropdown;borderWidthInput;borderColorInput;backgroundInput;widthInput;heightInput;alignmentToolbar;saveButtonView;cancelButtonView;backButtonView;_focusables;_focusCycler;constructor(e,t){super(e),this.set({borderStyle:"",borderWidth:"",borderColor:"",backgroundColor:"",width:"",height:"",alignment:""}),this.options=t;const{borderStyleDropdown:o,borderWidthInput:i,borderColorInput:n,borderRowLabel:s}=this._createBorderFields(),{backgroundRowLabel:r,backgroundInput:a}=this._createBackgroundFields(),{widthInput:l,operatorLabel:c,heightInput:d,dimensionsLabel:u}=this._createDimensionFields(),{alignmentToolbar:h,alignmentLabel:m}=this._createAlignmentFields();this.focusTracker=new oo,this.keystrokes=new ro,this.children=this.createCollection(),this.borderStyleDropdown=o,this.borderWidthInput=i,this.borderColorInput=n,this.backgroundInput=a,this.widthInput=l,this.heightInput=d,this.alignmentToolbar=h;const{saveButtonView:g,cancelButtonView:p}=this._createActionButtons();this.saveButtonView=g,this.cancelButtonView=p,this.backButtonView=this._createBackButton(),this._focusables=new tu,this._focusCycler=new qu({focusables:this._focusables,focusTracker:this.focusTracker,keystrokeHandler:this.keystrokes,actions:{focusPrevious:"shift + tab",focusNext:"tab"}});const f=new ju(e,{label:this.t("Table properties")});f.children.add(this.backButtonView,0),this.children.add(f),this.children.add(new Km(e,{labelView:s,children:[s,o,i,n],class:"ck-table-form__border-row"})),this.children.add(new Km(e,{children:[new Km(e,{labelView:u,children:[u,l,c,d],class:"ck-table-form__dimensions-row"}),new Km(e,{labelView:r,children:[r,a],class:"ck-table-form__background-row"})]})),this.children.add(new Km(e,{labelView:m,children:[m,h],class:"ck-table-properties-form__alignment-row"})),this.children.add(new Km(e,{children:[this.cancelButtonView,this.saveButtonView],class:"ck-table-form__action-row"})),this.setTemplate({tag:"form",attributes:{class:["ck","ck-form","ck-table-form","ck-table-properties-form"],tabindex:"-1"},children:this.children})}render(){super.render(),Ou({view:this}),[this.borderColorInput,this.backgroundInput].forEach((e=>{this._focusCycler.chain(e.fieldView.focusCycler)})),[this.borderStyleDropdown,this.borderWidthInput,this.borderColorInput,this.widthInput,this.heightInput,this.backgroundInput,this.alignmentToolbar,this.cancelButtonView,this.saveButtonView,this.backButtonView].forEach((e=>{this._focusables.add(e),this.focusTracker.add(e.element)})),this.keystrokes.listenTo(this.element)}destroy(){super.destroy(),this.focusTracker.destroy(),this.keystrokes.destroy()}focus(){this._focusCycler.focusFirst()}_createBorderFields(){const e=this.options.defaultTableProperties,t={style:e.borderStyle,width:e.borderWidth,color:e.borderColor},o=IC({colorConfig:this.options.borderColors,columns:5,defaultColorValue:t.color,colorPickerConfig:this.options.colorPickerConfig}),i=this.locale,n=this.t,s=n("Style"),r=new Du(i);r.text=n("Border");const a=kC(n),l=new Sh(i,rm);l.set({label:s,class:"ck-table-form__border-style"}),l.fieldView.buttonView.set({ariaLabel:s,ariaLabelledBy:void 0,isOn:!1,withText:!0,tooltip:s}),l.fieldView.buttonView.bind("label").to(this,"borderStyle",(e=>a[e||"none"])),l.fieldView.on("execute",(e=>{this.borderStyle=e.source._borderStyleValue})),l.bind("isEmpty").to(this,"borderStyle",(e=>!e)),Xh(l.fieldView,TC(this,t.style),{role:"menu",ariaLabel:s});const c=new Sh(i,nm);c.set({label:n("Width"),class:"ck-table-form__border-width"}),c.fieldView.bind("value").to(this,"borderWidth"),c.bind("isEnabled").to(this,"borderStyle",bA),c.fieldView.on("input",(()=>{this.borderWidth=c.fieldView.element.value}));const d=new Sh(i,o);return d.set({label:n("Color"),class:"ck-table-form__border-color"}),d.fieldView.bind("value").to(this,"borderColor"),d.bind("isEnabled").to(this,"borderStyle",bA),d.fieldView.on("input",(()=>{this.borderColor=d.fieldView.value})),this.on("change:borderStyle",((e,o,i,n)=>{bA(i)||(this.borderColor="",this.borderWidth=""),bA(n)||(this.borderColor=t.color,this.borderWidth=t.width)})),{borderRowLabel:r,borderStyleDropdown:l,borderColorInput:d,borderWidthInput:c}}_createBackgroundFields(){const e=this.locale,t=this.t,o=new Du(e);o.text=t("Background");const i=IC({colorConfig:this.options.backgroundColors,columns:5,defaultColorValue:this.options.defaultTableProperties.backgroundColor,colorPickerConfig:this.options.colorPickerConfig}),n=new Sh(e,i);return n.set({label:t("Color"),class:"ck-table-properties-form__background"}),n.fieldView.bind("value").to(this,"backgroundColor"),n.fieldView.on("input",(()=>{this.backgroundColor=n.fieldView.value})),{backgroundRowLabel:o,backgroundInput:n}}_createDimensionFields(){const e=this.locale,t=this.t,o=new Du(e);o.text=t("Dimensions");const i=new Sh(e,nm);i.set({label:t("Width"),class:"ck-table-form__dimensions-row__width"}),i.fieldView.bind("value").to(this,"width"),i.fieldView.on("input",(()=>{this.width=i.fieldView.element.value}));const n=new Au(e);n.setTemplate({tag:"span",attributes:{class:["ck-table-form__dimension-operator"]},children:[{text:"×"}]});const s=new Sh(e,nm);return s.set({label:t("Height"),class:"ck-table-form__dimensions-row__height"}),s.fieldView.bind("value").to(this,"height"),s.fieldView.on("input",(()=>{this.height=s.fieldView.element.value})),{dimensionsLabel:o,widthInput:i,operatorLabel:n,heightInput:s}}_createAlignmentFields(){const e=this.locale,t=this.t,o=new Du(e);o.text=t("Table Alignment");const i=new Wh(e);return i.set({role:"radiogroup",isCompact:!0,ariaLabel:t("Table alignment toolbar")}),PC({view:this,icons:{left:Jc,center:Gc,right:Zc,blockLeft:Yc,blockRight:Xc},toolbar:i,labels:this._alignmentLabels,propertyName:"alignment",defaultValue:this.options.defaultTableProperties.alignment}),{alignmentLabel:o,alignmentToolbar:i}}_createActionButtons(){const e=this.locale,t=this.t,o=new Lu(e),i=new Lu(e),n=[this.borderWidthInput,this.borderColorInput,this.backgroundInput,this.widthInput,this.heightInput];return o.set({label:t("Save"),class:"ck-button-action",type:"submit",withText:!0}),o.bind("isEnabled").toMany(n,"errorText",((...e)=>e.every((e=>!e)))),i.set({label:t("Cancel"),withText:!0}),i.delegate("execute").to(this,"cancel"),{saveButtonView:o,cancelButtonView:i}}_createBackButton(){const e=this.locale.t,t=new Lu(this.locale);return t.set({class:"ck-button-back",label:e("Back"),icon:ed,tooltip:!0}),t.delegate("execute").to(this,"cancel"),t}get _alignmentLabels(){const e=this.locale,t=this.t,o=t("Align table to the left with no text wrapping"),i=t("Align table to the right with no text wrapping"),n=t("Align table to the left with text wrapping"),s=t("Center table with no text wrapping"),r=t("Align table to the right with text wrapping");return"rtl"===e.uiLanguageDirection?{right:r,left:n,blockRight:i,center:s,blockLeft:o}:{blockLeft:o,center:s,blockRight:i,left:n,right:r}}}function bA(e){return"none"!==e}const wA={borderStyle:"tableBorderStyle",borderColor:"tableBorderColor",borderWidth:"tableBorderWidth",backgroundColor:"tableBackgroundColor",width:"tableWidth",height:"tableHeight",alignment:"tableAlignment"};class yA extends fc{_defaultContentTableProperties;_defaultLayoutTableProperties;_balloon;view=null;_viewWithContentTableDefaults=null;_viewWithLayoutTableDefaults=null;_undoStepBatch;_isReady;static get requires(){return[Qm]}static get pluginName(){return"TablePropertiesUI"}static get isOfficialPlugin(){return!0}constructor(e){super(e),e.config.define("table.tableProperties",{borderColors:SC,backgroundColors:SC})}init(){const e=this.editor;this._defaultContentTableProperties=fv(e.config.get("table.tableProperties.defaultProperties"),{includeAlignmentProperty:!0}),this._defaultLayoutTableProperties=pv(),this._balloon=e.plugins.get(Qm),e.ui.componentFactory.add("tableProperties",(()=>this._createTablePropertiesButton()))}_createTablePropertiesButton(){const e=this.editor,t=e.t,o=new Lu(e.locale);o.set({label:t("Table properties"),icon:'',tooltip:!0}),this.listenTo(o,"execute",(()=>this._showView()));const i=Object.values(wA).map((t=>e.commands.get(t)));return o.bind("isEnabled").toMany(i,"isEnabled",((...e)=>e.some((e=>e)))),o}destroy(){super.destroy(),this.view&&this.view.destroy()}_createPropertiesView(e){const t=this.editor,o=t.config.get("table.tableProperties"),i=Ch(o.borderColors),n=vh(t.locale,i),s=Ch(o.backgroundColors),r=vh(t.locale,s),a=!1!==o.colorPicker,l=new fA(t.locale,{borderColors:n,backgroundColors:r,defaultTableProperties:e,colorPickerConfig:!!a&&(o.colorPicker||{})}),c=t.t;l.render(),this.listenTo(l,"submit",(()=>{this._hideView()})),this.listenTo(l,"cancel",(()=>{this._undoStepBatch.operations.length&&t.execute("undo",this._undoStepBatch),this._hideView()})),l.keystrokes.set("Esc",((e,t)=>{this._hideView(),t()})),Su({emitter:l,activator:()=>this._isViewInBalloon,contextElements:[this._balloon.view.element],callback:()=>this._hideView()});const d=vC(c),u=CC(c);return l.on("change:borderStyle",this._getPropertyChangeCallback("tableBorderStyle")),l.on("change:borderColor",this._getValidatedPropertyChangeCallback({viewField:l.borderColorInput,commandName:"tableBorderColor",errorText:d,validator:AC})),l.on("change:borderWidth",this._getValidatedPropertyChangeCallback({viewField:l.borderWidthInput,commandName:"tableBorderWidth",errorText:u,validator:EC})),l.on("change:backgroundColor",this._getValidatedPropertyChangeCallback({viewField:l.backgroundInput,commandName:"tableBackgroundColor",errorText:d,validator:AC})),l.on("change:width",this._getValidatedPropertyChangeCallback({viewField:l.widthInput,commandName:"tableWidth",errorText:u,validator:xC})),l.on("change:height",this._getValidatedPropertyChangeCallback({viewField:l.heightInput,commandName:"tableHeight",errorText:u,validator:xC})),l.on("change:alignment",this._getPropertyChangeCallback("tableAlignment")),l}_fillViewFormFromCommandValues(){const e=this.editor.commands,t=e.get("tableBorderStyle");Object.entries(wA).map((([t,o])=>{const i=t,n=this.view===this._viewWithContentTableDefaults?this._defaultContentTableProperties[i]||"":this._defaultLayoutTableProperties[i]||"";return[i,e.get(o).value||n]})).forEach((([e,o])=>{("borderColor"!==e&&"borderWidth"!==e||"none"!==t.value)&&this.view.set(e,o)})),this._isReady=!0}_showView(){const e=this.editor,t=gC(e.editing.view.document.selection),o=t&&e.editing.mapper.toModelElement(t),i=!o||"layout"!==o.getAttribute("tableType");i&&!this._viewWithContentTableDefaults?this._viewWithContentTableDefaults=this._createPropertiesView(this._defaultContentTableProperties):i||this._viewWithLayoutTableDefaults||(this._viewWithLayoutTableDefaults=this._createPropertiesView(this._defaultLayoutTableProperties)),this.view=i?this._viewWithContentTableDefaults:this._viewWithLayoutTableDefaults,this.listenTo(e.ui,"update",(()=>{this._updateView()})),this._fillViewFormFromCommandValues(),this._balloon.add({view:this.view,position:MC(e)}),this._undoStepBatch=e.model.createBatch(),this.view.focus()}_hideView(){const e=this.editor;this.stopListening(e.ui,"update"),this._isReady=!1,this.view.saveButtonView.focus(),this._balloon.remove(this.view),this.editor.editing.view.focus()}_updateView(){const e=this.editor;gC(e.editing.view.document.selection)?this._isViewVisible&&FC(e,"table"):this._hideView()}get _isViewVisible(){return!!this.view&&this._balloon.visibleView===this.view}get _isViewInBalloon(){return!!this.view&&this._balloon.hasView(this.view)}_getPropertyChangeCallback(e){return(t,o,i)=>{this._isReady&&this.editor.execute(e,{value:i,batch:this._undoStepBatch})}}_getValidatedPropertyChangeCallback(e){const{commandName:t,viewField:o,validator:i,errorText:n}=e,s=zo((()=>{o.errorText=n}),500);return(e,n,r)=>{s.cancel(),this._isReady&&(i(r)?(this.editor.execute(t,{value:r,batch:this._undoStepBatch}),o.errorText=null):s())}}}function _A(e){const t=parseFloat(e);return e.endsWith("pt")?kA(96*t/72):e.endsWith("pc")?kA(12*t*96/72):e.endsWith("in")?kA(96*t):e.endsWith("cm")?kA(96*t/2.54):e.endsWith("mm")?kA(t/10*96/2.54):e}function kA(e){return Math.round(e)+"px"}function vA(e,t,o){if(!e.childCount)return;const i=new rl(e.document),n=function(e,t){const o=t.createRangeIn(e),i=[],n=new Set;for(const e of o.getItems()){if(!e.is("element")||!e.name.match(/^(p|h\d+|li|div)$/))continue;let t=VA(e);if(void 0===t||0!=parseFloat(t)||Array.from(e.getClassNames()).find((e=>e.startsWith("MsoList")))||(t=void 0),e.hasStyle("mso-list")&&"none"!==e.getStyle("mso-list")||void 0!==t&&n.has(t)){const o=RA(e);i.push({element:e,id:o.id,order:o.order,indent:o.indent,marginLeft:t}),void 0!==t&&n.add(t)}else n.clear()}return i}(e,i);if(!n.length)return;const s={},r=[];let a=AA();for(const e of n)if(void 0!==e.indent){EA(e)||(xA(i,r,a),a=AA(),r.length=0);const n=`${e.id}:${e.indent}`,l=Math.min(e.indent-1,r.length);if(lr.length-1||r[l].listElement.name!=a.type){0==l&&"ol"==a.type&&void 0!==e.id&&s[n]&&(a.startIndex=s[n]);const t=IA(a,i,o);if(0==r.length){const o=e.element.parent,n=o.getChildIndex(e.element)+1;i.insertChild(n,t,o)}else{const e=r[l-1].listItemElements;i.appendChild(t,e[e.length-1])}r[l]={...e,listElement:t,listItemElements:[]},0==l&&void 0!==e.id&&(s[n]=a.startIndex||1)}}const c="li"==e.element.name?e.element:i.createElement("li");CA(i,r,a,e,c,l),i.appendChild(c,r[l].listElement),r[l].listItemElements.push(c),0==l&&void 0!==e.id&&s[n]++,e.element!=c&&i.appendChild(e.element,c),OA(e.element,i),i.removeStyle("text-indent",e.element),i.removeStyle("margin-left",e.element)}else{const t=r.find((t=>t.marginLeft==e.marginLeft));if(t){const o=t.listItemElements;i.appendChild(e.element,o[o.length-1]),i.removeStyle("margin-left",e.element)}else r.length=0}xA(i,r,a)}function CA(e,t,o,i,n,s){if(void 0===i.marginLeft)return void(0==s&&(o.canApplyMarginOnList=!1));const r=parseFloat(i.marginLeft);let a=0;if(t.length>1){const e=t[t.length-2].listItemElements;if(e.length>0){const t=e[e.length-1].getStyle("margin-left");void 0!==t&&(a+=parseFloat(t))}}a+=40*t.length;const l=r-a,c=0!==l?kA(l):void 0;c&&(e.setStyle("margin-left",c,n),0==s&&o.canApplyMarginOnList&&(void 0===o.marginLeft&&(o.marginLeft=c),c!==o.marginLeft&&(o.canApplyMarginOnList=!1),o.topLevelListItemElements.push(n)))}function AA(){return{marginLeft:void 0,canApplyMarginOnList:!0,topLevelListItemElements:[]}}function xA(e,t,o){if(o.canApplyMarginOnList&&o.marginLeft&&o.topLevelListItemElements.length>0){e.setStyle("margin-left",o.marginLeft,t[0].listElement);for(const t of o.topLevelListItemElements)e.removeStyle("margin-left",t)}}function EA(e){const t=e.element.previousSibling;if(!t){const t=e.element.parent;return TA(t)&&(!t.previousSibling||TA(t.previousSibling))}return TA(t)}function TA(e){return e.is("element","ol")||e.is("element","ul")}function PA(e,t){const o=new RegExp(`@list l${e.id}:level${e.indent}\\s*({[^}]*)`,"gi"),i=/mso-level-number-format:([^;]{0,100});/gi,n=/mso-level-start-at:\s{0,100}([0-9]{0,10})\s{0,100};/gi,s=new RegExp(`@list\\s+l${e.id}:level\\d\\s*{[^{]*mso-level-text:"%\\d\\\\.`,"gi"),r=new RegExp(`@list l${e.id}:level\\d\\s*{[^{]*mso-level-number-format:`,"gi"),a=s.exec(t),l=r.exec(t),c=a&&!l,d=o.exec(t);let u="decimal",h="ol",m=null;if(d&&d[1]){const t=i.exec(d[1]);if(t&&t[1]&&(u=t[1].trim(),h="bullet"!==u&&"image"!==u?"ol":"ul"),"bullet"===u){const t=function(e){if("li"==e.name&&"ul"==e.parent.name&&e.parent.hasAttribute("type"))return e.parent.getAttribute("type");const t=function(e){if(e.getChild(0).is("$text"))return null;for(const t of e.getChildren()){if(!t.is("element","span"))continue;const e=t.getChild(0);if(e)return e.is("$text")?e:e.getChild(0)}return null}(e);if(!t)return null;const o=t._data;if("o"===o)return"circle";if("·"===o)return"disc";if("§"===o)return"square";return null}(e.element);t&&(u=t)}else{const e=n.exec(d[1]);e&&e[1]&&(m=parseInt(e[1]))}c&&(h="ol")}return{type:h,startIndex:m,style:SA(u),isLegalStyleList:c}}function SA(e){if(e.startsWith("arabic-leading-zero"))return"decimal-leading-zero";switch(e){case"alpha-upper":return"upper-alpha";case"alpha-lower":return"lower-alpha";case"roman-upper":return"upper-roman";case"roman-lower":return"lower-roman";case"circle":case"disc":case"square":return e;default:return null}}function IA(e,t,o){const i=t.createElement(e.type);return e.style&&t.setStyle("list-style-type",e.style,i),e.startIndex&&e.startIndex>1&&t.setAttribute("start",e.startIndex,i),e.isLegalStyleList&&o&&t.addClass("legal-list",i),i}function RA(e){const t=e.getStyle("mso-list");if(void 0===t)return{};const o=t.match(/(^|\s{1,100})l(\d+)/i),i=t.match(/\s{0,100}lfo(\d+)/i),n=t.match(/\s{0,100}level(\d+)/i);return o&&i&&n?{id:o[2],order:i[1],indent:parseInt(n[1])}:{indent:1}}function OA(e,t){const o=new ui({name:"span",styles:{"mso-list":"Ignore"}}),i=t.createRangeIn(e);for(const e of i)"elementStart"===e.type&&o.match(e.item)&&t.remove(e.item)}function VA(e){const t=e.getStyle("margin-left");return void 0===t||t.endsWith("px")?t:_A(t)}function DA(e,t){if(!e.childCount)return;const o=new rl(e.document),i=function(e,t){const o=t.createRangeIn(e),i=new ui({name:/v:(.+)/}),n=[];for(const e of o){if("elementStart"!=e.type)continue;const t=e.item,o=t.previousSibling,s=o&&o.is("element")?o.name:null,r=["Chart"],a=i.match(t),l=t.getAttribute("o:gfxdata"),c="v:shapetype"===s,d=l&&r.some((e=>t.getAttribute("id").includes(e)));a&&l&&!c&&!d&&n.push(e.item.getAttribute("id"))}return n}(e,o);!function(e,t,o){const i=o.createRangeIn(t),n=new ui({name:"img"}),s=[];for(const t of i)if(t.item.is("element")&&n.match(t.item)){const o=t.item,i=o.getAttribute("v:shapes")?o.getAttribute("v:shapes").split(" "):[];i.length&&i.every((t=>e.indexOf(t)>-1))?s.push(o):o.getAttribute("src")||s.push(o)}for(const e of s)o.remove(e)}(i,e,o),function(e,t,o){const i=o.createRangeIn(t),n=[];for(const t of i)if("elementStart"==t.type&&t.item.is("element","v:shape")){const o=t.item.getAttribute("id");if(e.includes(o))continue;s(t.item.parent.getChildren(),o)||n.push(t.item)}for(const e of n){const t={src:r(e)};e.hasAttribute("alt")&&(t.alt=e.getAttribute("alt"));const i=o.createElement("img",t);o.insertChild(e.index+1,i,e.parent)}function s(e,t){for(const o of e)if(o.is("element")){if("img"==o.name&&o.getAttribute("v:shapes")==t)return!0;if(s(o.getChildren(),t))return!0}return!1}function r(e){for(const t of e.getChildren())if(t.is("element")&&t.getAttribute("src"))return t.getAttribute("src")}}(i,e,o),function(e,t){const o=t.createRangeIn(e),i=new ui({name:/v:(.+)/}),n=[];for(const e of o)"elementStart"==e.type&&i.match(e.item)&&n.push(e.item);for(const e of n)t.remove(e)}(e,o);const n=function(e,t){const o=t.createRangeIn(e),i=new ui({name:"img"}),n=[];let s=0;for(const e of o)e.item.is("element")&&i.match(e.item)&&(e.item.getAttribute("src").startsWith("file://")&&n.push({element:e.item,imageIndex:s}),s++);return n}(e,o);n.length&&function(e,t,o){for(let i=0;iString.fromCharCode(parseInt(e,16)))).join(""))}function MA(e,t){for(const o of t.createRangeIn(e).getItems())o.is("element","table")&&("0px"===o.getStyle("width")&&t.removeStyle("width",o),"0"===o.getAttribute("width")&&t.removeAttribute("width",o))}function NA(e,t){const o=[],i=[];for(const{item:n}of e.createRangeIn(t))if(n.is("element")&&n.getStyle("mso-footnote-id")){o.unshift(n);const{nextSibling:e}=n;e?.is("$text")&&e.data.startsWith(" ")&&i.unshift(e)}for(const t of o)e.remove(t);for(const t of i){const o=t.data.substring(1);if(o.length>0){const i=t.parent,n=i.getChildIndex(t),s=e.createText(o);e.remove(t),e.insertChild(n,s,i)}else e.remove(t)}return t}function BA(e,t){const o=e.createElement("sup",{class:"footnote"}),i=e.createElement("a",{id:`ref-${t}`,href:`#${t}`});return e.appendChild(i,o),o}function LA(e,t){const o=e.createElement("li",{id:t,class:"footnote-definition"}),i=e.createElement("a",{href:`#ref-${t}`,class:"footnote-backlink"}),n=e.createElement("div",{class:"footnote-content"});return e.appendChild(e.createText("^"),i),e.appendChild(i,o),e.appendChild(n,o),{listItem:o,content:n}}const zA=//i,jA=/xmlns:o="urn:schemas-microsoft-com/i;class qA{document;hasMultiLevelListPlugin;hasTablePropertiesPlugin;constructor(e,t=!1,o=!1){this.document=e,this.hasMultiLevelListPlugin=t,this.hasTablePropertiesPlugin=o}isActive(e){return zA.test(e)||jA.test(e)}execute(e){const t=new rl(this.document),{body:o,stylesString:i}=e._parsedData;!function(e,t){const o=[];for(const i of t.createRangeIn(e)){const e=i.item;e.is("element","a")&&!e.hasAttribute("href")&&(e.hasAttribute("id")||e.hasAttribute("name"))&&o.push(e)}for(const e of o){const o=e.parent.getChildIndex(e)+1,i=e.getChildren();t.insertChild(o,i,e.parent)}}(o,t),vA(o,i,this.hasMultiLevelListPlugin),DA(o,e.dataTransfer.getData("text/rtf")),function(e,t,o=!1){for(const i of t.createRangeIn(e).getItems()){if(!i.is("element","table")&&!i.is("element","td")&&!i.is("element","th"))continue;if(o&&i.is("element","table")){const e=i.parent?.is("element","div")?i.parent:null,o=i.parent?.parent?.is("element","div")?i.parent.parent:null,n=e??o;n&&"center"===n.getAttribute("align")&&!i.getAttribute("align")?(t.setStyle("margin-left","auto",i),t.setStyle("margin-right","auto",i)):n&&"right"===n.getAttribute("align")&&!i.getAttribute("align")?(t.setStyle("margin-left","auto",i),t.setStyle("margin-right","0",i)):n||i.getAttribute("align")||(t.setStyle("margin-left","0",i),t.setStyle("margin-right","auto",i))}const e=["left","top","right","bottom"];if(e.every((e=>!i.hasStyle(`border-${e}-style`))))t.setStyle("border-style","none",i);else for(const o of e)i.hasStyle(`border-${o}-style`)||t.setStyle(`border-${o}-style`,"none",i);const n=["width","height",...e.map((e=>`border-${e}-width`)),...e.map((e=>`padding-${e}`))];for(const e of n)i.hasStyle(e)&&t.setStyle(e,_A(i.getStyle(e)),i)}}(o,t,this.hasTablePropertiesPlugin),MA(o,t),function(e,t){const o=new Map,i=new Map;let n=null;for(const{item:s}of t.createRangeIn(e))if(s.is("element"))if("footnote-list"!==s.getStyle("mso-element")){if(s.hasStyle("mso-footnote-id")){const e=s.findAncestor("element",(e=>"footnote"===e.getStyle("mso-element")));if(e){const t=e.getAttribute("id");i.set(t,e)}else{const e=s.getStyle("mso-footnote-id");o.set(e,s)}}}else n=s;if(!o.size||!n)return;const s=function(e){return e.createElement("ol",{class:"footnotes"})}(t);t.replace(n,s);for(const[e,n]of o){const o=i.get(e);if(!o)continue;t.replace(n,BA(t,e));const r=LA(t,e);NA(t,o);for(const e of o.getChildren()){let o=e;e.is("element")&&(o=t.clone(e,!0)),t.appendChild(o,r.content)}t.appendChild(r.listItem,s)}}(o,t),function(e){const t=[],o=new rl(e.document);for(const{item:i}of o.createRangeIn(e))if(i.is("element")){for(const e of i.getClassNames())/\bmso/gi.exec(e)&&o.removeClass(e,i);for(const e of i.getStyleNames())/\bmso/gi.exec(e)&&o.removeStyle(e,i);(i.is("element","w:sdt")||i.is("element","w:sdtpr")&&i.isEmpty||i.is("element","o:p")&&i.isEmpty)&&t.push(i)}for(const e of t){const t=e.parent,i=t.getChildIndex(e);o.insertChild(i,e.getChildren(),t),o.remove(e)}}(o),e.content=o}}function $A(e,t,o,{blockElements:i,inlineObjectElements:n}){let s=o.createPositionAt(e,"forward"==t?"after":"before");return s=s.getLastMatchingPosition((({item:e})=>e.is("element")&&!i.includes(e.name)&&!n.includes(e.name)),{direction:t}),"forward"==t?s.nodeAfter:s.nodeBefore}function HA(e,t){return!!e&&e.is("element")&&t.includes(e.name)}function WA(e){let t=e;for(;t;){if(t.is("element")){const e=t.getStyle?.("white-space");if("pre-wrap"===e)return!0}t=t.parent}return!1}function UA(e,t,o){const{parent:i,data:n}=e,s=n.replaceAll("\t"," ".repeat(o)),r=i.getChildIndex(e);t.remove(e),t.insertChild(r,t.createText(s),i)}const KA=/id=("|')docs-internal-guid-[-0-9a-f]+("|')/i;class GA{document;constructor(e){this.document=e}isActive(e){return KA.test(e)}execute(e){const t=new rl(this.document),{body:o}=e._parsedData;!function(e,t){for(const o of e.getChildren())if(o.is("element","b")&&"normal"===o.getStyle("font-weight")){const i=e.getChildIndex(o);t.remove(o),t.insertChild(i,o.getChildren(),e)}}(o,t),function(e,t){for(const o of t.createRangeIn(e)){const e=o.item;if(e.is("element","li")){const o=e.getChild(0);o&&o.is("element","p")&&t.unwrapElement(o)}}}(o,t),function(e,t){const o=new Hi(t.document.stylesProcessor),i=new Rn(o,{renderingMode:"data"}),n=i.blockElements,s=i.inlineObjectElements,r=[];for(const o of t.createRangeIn(e)){const e=o.item;if(e.is("element","br")){const o=$A(e,"forward",t,{blockElements:n,inlineObjectElements:s}),i=$A(e,"backward",t,{blockElements:n,inlineObjectElements:s}),a=HA(o,n);(HA(i,n)||a)&&r.push(e)}}for(const e of r)e.hasClass("Apple-interchange-newline")?t.remove(e):t.replace(e,t.createElement("p"))}(o,t),function(e,t,o){const i=new Set;for(const o of t.createRangeIn(e).getItems())o.is("view:$textProxy")&&o.data.includes("\t")&&WA(o.parent)&&i.add(o.textNode);for(const e of i)UA(e,t,o)}(o,t,8),e.content=o}}const JA=/(\s+)<\/span>/g,((e,t)=>1===t.length?" ":Array(t.length+1).join(" ").substr(0,t.length)))}function YA(e,t){const o=new DOMParser,i=function(e){return QA(QA(e)).replace(/([^\S\r\n]*?)[\r\n]+([^\S\r\n]*<\/span>)/g,"$1$2").replace(/<\/span>/g,"").replace(/()[\r\n]+(<\/span>)/g,"$1 $2").replace(/ <\//g," ").replace(/ <\/o:p>/g," ").replace(/( |\u00A0)<\/o:p>/g,"").replace(/>([^\S\r\n]*[\r\n]\s*)<")}(function(e){const t="