`),n=r),n=this._htmlDataProcessor.toView(n);const s=new lo(this,"inputTransformation");this.fire(s,{content:n,dataTransfer:i}),s.stop.called&&e.stop(),o.scrollToTheSelection()},{priority:"low"}),this.listenTo(this,"inputTransformation",(e,t)=>{if(!t.content.isEmpty){const o=this.editor.data,i=this.editor.model,n=o.toModel(t.content,"$clipboardHolder");if(0==n.childCount)return;i.insertContent(n),e.stop()}},{priority:"low"}),this.listenTo(i,"copy",n,{priority:"low"}),this.listenTo(i,"cut",(t,o)=>{e.isReadOnly?o.preventDefault():n(t,o)},{priority:"low"}),this.listenTo(i,"clipboardOutput",(o,i)=>{i.content.isEmpty||(i.dataTransfer.setData("text/html",this._htmlDataProcessor.toData(i.content)),i.dataTransfer.setData("text/plain",function e(t){let o="";if(t.is("text")||t.is("textProxy"))o=t.data;else if(t.is("img")&&t.hasAttribute("alt"))o=t.getAttribute("alt");else{let i=null;for(const n of t.getChildren()){const t=e(n);i&&(i.is("containerElement")||n.is("containerElement"))&&(dd.includes(i.name)||dd.includes(n.name)?o+="\n":o+="\n\n"),o+=t,i=n}}return o}(i.content))),"cut"==i.method&&e.model.deleteContent(t.selection)},{priority:"low"})}}class hd{constructor(e){this.editor=e,this.set("value",void 0),this.set("isEnabled",!1),this._disableStack=new Set,this.decorate("execute"),this.listenTo(this.editor.model.document,"change",()=>{this.refresh()}),this.on("execute",e=>{this.isEnabled||e.stop()},{priority:"high"}),this.listenTo(e,"change:isReadOnly",(e,t,o)=>{o?this.forceDisabled("readOnlyMode"):this.clearForceDisabled("readOnlyMode")})}refresh(){this.isEnabled=!0}forceDisabled(e){this._disableStack.add(e),1==this._disableStack.size&&(this.on("set:isEnabled",gd,{priority:"highest"}),this.isEnabled=!1)}clearForceDisabled(e){this._disableStack.delete(e),0==this._disableStack.size&&(this.off("set:isEnabled",gd),this.refresh())}execute(){}destroy(){this.stopListening()}}function gd(e){e.return=!1,e.stop()}function*md(e,t){for(const o of t)o&&e.getAttributeProperties(o[0]).copyOnEnter&&(yield o)}Co(hd,Wi);class fd extends hd{execute(){const e=this.editor.model,t=e.document;e.change(o=>{!function(e,t,o,i){const n=o.isCollapsed,r=o.getFirstRange(),s=r.start.parent,a=r.end.parent;if(i.isLimit(s)||i.isLimit(a))return void(n||s!=a||e.deleteContent(o));if(n){const e=md(t.model.schema,o.getAttributes());pd(t,r.start),t.setSelectionAttribute(e)}else{const i=!(r.start.isAtStart&&r.end.isAtEnd),n=s==a;e.deleteContent(o,{leaveUnmerged:i}),i&&(n?pd(t,o.focus):t.setSelection(a,0))}}(this.editor.model,o,t.selection,e.schema),this.fire("afterExecute",{writer:o})})}}function pd(e,t){e.split(t),e.setSelection(t.parent.nextSibling,0)}class bd extends hr{constructor(e){super(e);const t=this.document;t.on("keydown",(e,o)=>{if(this.isEnabled&&o.keyCode==pn.enter){let i;t.once("enter",e=>i=e,{priority:"highest"}),t.fire("enter",new Nr(t,o.domEvent,{isSoft:o.shiftKey})),i&&i.stop.called&&e.stop()}})}observe(){}}class wd extends Ml{static get pluginName(){return"Enter"}init(){const e=this.editor,t=e.editing.view,o=t.document;t.addObserver(bd),e.commands.add("enter",new fd(e)),this.listenTo(o,"enter",(o,i)=>{i.preventDefault(),i.isSoft||(e.execute("enter"),t.scrollToTheSelection())},{priority:"low"})}}class kd extends hd{execute(){const e=this.editor.model,t=e.document;e.change(o=>{!function(e,t,o){const i=o.isCollapsed,n=o.getFirstRange(),r=n.start.parent,s=n.end.parent,a=r==s;if(i){const i=md(e.schema,o.getAttributes());_d(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?_d(e,t,o.focus):i&&t.setSelection(s,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,r=i.end.parent;if((vd(n,e)||vd(r,e))&&n!==r)return!1;return!0}(e.schema,t.selection)}}function _d(e,t,o){const i=t.createElement("softBreak");e.insertContent(i,o),t.setSelection(i,"after")}function vd(e,t){return!e.is("rootElement")&&(t.isLimit(e)||vd(e.parent,t))}class yd extends Ml{static get pluginName(){return"ShiftEnter"}init(){const e=this.editor,t=e.model.schema,o=e.conversion,i=e.editing.view,n=i.document;t.register("softBreak",{allowWhere:"$text",isInline:!0}),o.for("upcast").elementToElement({model:"softBreak",view:"br"}),o.for("downcast").elementToElement({model:"softBreak",view:(e,t)=>t.createEmptyElement("br")}),i.addObserver(bd),e.commands.add("shiftEnter",new kd(e)),this.listenTo(n,"enter",(t,o)=>{o.preventDefault(),o.isSoft&&(e.execute("shiftEnter"),i.scrollToTheSelection())},{priority:"low"})}}class xd extends hd{execute(){const e=this.editor.model,t=e.schema.getLimitElement(e.document.selection);e.change(e=>{e.setSelection(t,"in")})}}const Cd=wn("Ctrl+A");class Ad extends Ml{static get pluginName(){return"SelectAllEditing"}init(){const e=this.editor,t=e.editing.view.document;e.commands.add("selectAll",new xd(e)),this.listenTo(t,"keydown",(t,o)=>{bn(o)===Cd&&(e.execute("selectAll"),o.preventDefault())})}}class Td extends Ml{static get pluginName(){return"SelectAllUI"}init(){const e=this.editor;e.ui.componentFactory.add("selectAll",t=>{const o=e.commands.get("selectAll"),i=new hc(t),n=t.t;return i.set({label:n("Select all"),icon:'',keystroke:"Ctrl+A",tooltip:!0}),i.bind("isOn","isEnabled").to(o,"value","isEnabled"),this.listenTo(i,"execute",()=>{e.execute("selectAll"),e.editing.view.focus()}),i})}}class Sd extends Ml{static get requires(){return[Ad,Td]}static get pluginName(){return"SelectAll"}}class Pd{constructor(e,t=20){this.model=e,this.size=0,this.limit=t,this.isLocked=!1,this._changeCallback=(e,t)=>{"transparent"!=t.type&&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()),this._batch}input(e){this.size+=e,this.size>=this.limit&&this._reset(!0)}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){this.isLocked&&!e||(this._batch=null,this.size=0)}}class Ed extends hd{constructor(e,t){super(e),this._buffer=new Pd(e.model,t),this._batches=new WeakSet}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,r=e.range?t.createSelection(e.range):o.selection,s=e.resultRange;t.enqueueChange(this._buffer.batch,e=>{this._buffer.lock(),t.deleteContent(r),i&&t.insertContent(e.createText(i,o.selection.getAttributes()),r),s?e.setSelection(s):r.is("documentSelection")||e.setSelection(r),this._buffer.unlock(),this._buffer.input(n),this._batches.add(this._buffer.batch)})}}function Md(e){let t=null;const o=e.model,i=e.editing.view,n=e.commands.get("input");function r(e){const r=o.document,a=i.document.isComposing,l=t&&t.isEqual(r.selection);t=null,n.isEnabled&&(function(e){if(e.ctrlKey)return!0;return Id.includes(e.keyCode)}(e)||r.selection.isCollapsed||a&&229===e.keyCode||!a&&229===e.keyCode&&l||s())}function s(){const e=n.buffer;e.lock(),o.enqueueChange(e.batch,()=>{o.deleteContent(o.document.selection)}),e.unlock()}gn.isAndroid?i.document.on("beforeinput",(e,t)=>r(t),{priority:"lowest"}):i.document.on("keydown",(e,t)=>r(t),{priority:"lowest"}),i.document.on("compositionstart",(function(){const e=o.document,t=1!==e.selection.rangeCount||e.selection.getFirstRange().isFlat;if(e.selection.isCollapsed||t)return;s()}),{priority:"lowest"}),i.document.on("compositionend",()=>{t=o.createSelection(o.document.selection)},{priority:"lowest"})}const Id=[bn("arrowUp"),bn("arrowRight"),bn("arrowDown"),bn("arrowLeft"),9,16,17,18,19,20,27,33,34,35,36,45,91,93,144,145,173,174,175,176,177,178,179,255];for(let e=112;e<=135;e++)Id.push(e);function Nd(e){if(e.newChildren.length-e.oldChildren.length!=1)return;const t=function(e,t){const o=[];let i,n=0;return e.forEach(e=>{"equal"==e?(r(),n++):"insert"==e?(s("insert")?i.values.push(t[n]):(r(),i={type:"insert",index:n,values:[t[n]]}),n++):s("delete")?i.howMany++:(r(),i={type:"delete",index:n,howMany:1})}),r(),o;function r(){i&&(o.push(i),i=null)}function s(e){return i&&i.type==e}}(Gn(e.oldChildren,e.newChildren,Rd),e.newChildren);if(t.length>1)return;const o=t[0];return o.values[0]&&o.values[0].is("text")?o:void 0}function Rd(e,t){return e&&e.is("text")&&t&&t.is("text")?e.data===t.data:e===t}class Od{constructor(e){this.editor=e,this.editing=this.editor.editing}handle(e,t){if(function(e){if(0==e.length)return!1;for(const t of e)if("children"===t.type&&!Nd(t))return!0;return!1}(e))this._handleContainerChildrenMutations(e,t);else for(const o of e)this._handleTextMutation(o,t),this._handleTextNodeInsertion(o)}_handleContainerChildrenMutations(e,t){const o=function(e){const t=e.map(e=>e.node).reduce((e,t)=>e.getCommonAncestor(t,{includeSelf:!0}));if(!t)return;return t.getAncestors({includeSelf:!0,parentFirst:!0}).find(e=>e.is("containerElement")||e.is("rootElement"))}(e);if(!o)return;const i=this.editor.editing.view.domConverter.mapViewToDom(o),n=new nr(this.editor.editing.view.document),r=this.editor.data.toModel(n.domToView(i)).getChild(0),s=this.editor.editing.mapper.toModelElement(o);if(!s)return;const a=Array.from(r.getChildren()),l=Array.from(s.getChildren()),c=a[a.length-1],d=l[l.length-1];c&&c.is("softBreak")&&d&&!d.is("softBreak")&&a.pop();const u=this.editor.model.schema;if(!Vd(a,u)||!Vd(l,u))return;const h=a.map(e=>e.is("text")?e.data:"@").join("").replace(/\u00A0/g," "),g=l.map(e=>e.is("text")?e.data:"@").join("").replace(/\u00A0/g," ");if(g===h)return;const m=Gn(g,h),{firstChangeAt:f,insertions:p,deletions:b}=Dd(m);let w=null;t&&(w=this.editing.mapper.toModelRange(t.getFirstRange()));const k=h.substr(f,p),_=this.editor.model.createRange(this.editor.model.createPositionAt(s,f),this.editor.model.createPositionAt(s,f+b));this.editor.execute("input",{text:k,range:_,resultRange:w})}_handleTextMutation(e,t){if("text"!=e.type)return;const o=e.newText.replace(/\u00A0/g," "),i=e.oldText.replace(/\u00A0/g," ");if(i===o)return;const n=Gn(i,o),{firstChangeAt:r,insertions:s,deletions:a}=Dd(n);let l=null;t&&(l=this.editing.mapper.toModelRange(t.getFirstRange()));const c=this.editing.view.createPositionAt(e.node,r),d=this.editing.mapper.toModelPosition(c),u=this.editor.model.createRange(d,d.getShiftedBy(a)),h=o.substr(r,s);this.editor.execute("input",{text:h,range:u,resultRange:l})}_handleTextNodeInsertion(e){if("children"!=e.type)return;const t=Nd(e),o=this.editing.view.createPositionAt(e.node,t.index),i=this.editing.mapper.toModelPosition(o),n=t.values[0].data;this.editor.execute("input",{text:n.replace(/\u00A0/g," "),range:this.editor.model.createRange(i)})}}function Vd(e,t){return e.every(e=>t.isInline(e))}function Dd(e){let t=null,o=null;for(let i=0;i{new Od(e).handle(o,i)})}(e)}isInput(e){return this.editor.commands.get("input")._batches.has(e)}}class zd extends hd{constructor(e,t){super(e),this.direction=t,this._buffer=new Pd(e.model,e.config.get("typing.undoStep"))}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),r=n.isCollapsed;if(n.isCollapsed&&t.modifySelection(n,{direction:this.direction,unit:e.unit}),this._shouldEntireContentBeReplacedWithParagraph(e.sequence||1))return void this._replaceEntireContentWithParagraph(i);if(n.isCollapsed)return;let s=0;n.getFirstRange().getMinimalFlatRanges().forEach(e=>{s+=on(e.getWalker({singleCharacters:!0,ignoreElementEnd:!0,shallow:!0}))}),t.deleteContent(n,{doNotResetEntireContent:r,direction:this.direction}),this._buffer.input(s),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||"paragraph"!==n.name}_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)}}class Bd extends hr{constructor(e){super(e);const t=e.document;let o=0;function i(e,o,i){let n;t.once("delete",e=>n=e,{priority:Number.POSITIVE_INFINITY}),t.fire("delete",new Nr(t,o,i)),n&&n.stop.called&&e.stop()}t.on("keyup",(e,t)=>{t.keyCode!=pn.delete&&t.keyCode!=pn.backspace||(o=0)}),t.on("keydown",(e,t)=>{const n={};if(t.keyCode==pn.delete)n.direction="forward",n.unit="character";else{if(t.keyCode!=pn.backspace)return;n.direction="backward",n.unit="codePoint"}const r=gn.isMac?t.altKey:t.ctrlKey;n.unit=r?"word":n.unit,n.sequence=++o,i(e,t.domEvent,n)}),gn.isAndroid&&t.on("beforeinput",(t,o)=>{if("deleteContentBackward"!=o.domEvent.inputType)return;const n={unit:"codepoint",direction:"backward",sequence:1},r=o.domTarget.ownerDocument.defaultView.getSelection();r.anchorNode==r.focusNode&&r.anchorOffset+1!=r.focusOffset&&(n.selectionToRemove=e.domConverter.domSelectionToView(r)),i(t,o.domEvent,n)})}observe(){}}class jd extends Ml{static get pluginName(){return"Delete"}init(){const e=this.editor,t=e.editing.view,o=t.document;if(t.addObserver(Bd),e.commands.add("forwardDelete",new zd(e,"forward")),e.commands.add("delete",new zd(e,"backward")),this.listenTo(o,"delete",(o,i)=>{const n={unit:i.unit,sequence:i.sequence};if(i.selectionToRemove){const t=e.model.createSelection(),o=[];for(const t of i.selectionToRemove.getRanges())o.push(e.editing.mapper.toModelRange(t));t.setTo(o),n.selection=t}e.execute("forward"==i.direction?"forwardDelete":"delete",n),i.preventDefault(),t.scrollToTheSelection()}),gn.isAndroid){let e=null;this.listenTo(o,"delete",(t,o)=>{const i=o.domTarget.ownerDocument.defaultView.getSelection();e={anchorNode:i.anchorNode,anchorOffset:i.anchorOffset,focusNode:i.focusNode,focusOffset:i.focusOffset}},{priority:"lowest"}),this.listenTo(o,"keyup",(t,o)=>{if(e){const t=o.domTarget.ownerDocument.defaultView.getSelection();t.collapse(e.anchorNode,e.anchorOffset),t.extend(e.focusNode,e.focusOffset),e=null}})}}}class Fd extends Ml{static get requires(){return[Ld,jd]}static get pluginName(){return"Typing"}}const Hd=new Map;function Wd(e,t,o){let i=Hd.get(e);i||(i=new Map,Hd.set(e,i)),i.set(t,o)}function Ud(e){return[e]}function qd(e,t,o={}){const i=function(e,t){const o=Hd.get(e);return o&&o.has(t)?o.get(t):Ud}(e.constructor,t.constructor);try{return i(e=e.clone(),t,o)}catch(e){throw e}}function Gd(e,t,o){e=e.slice(),t=t.slice();const i=new $d(o.document,o.useRelations,o.forceWeakRemove);i.setOriginalOperations(e),i.setOriginalOperations(t);const n=i.originalOperations;if(0==e.length||0==t.length)return{operationsA:e,operationsB:t,originalOperations:n};const r=new WeakMap;for(const t of e)r.set(t,0);const s={nextBaseVersionA:e[e.length-1].baseVersion+1,nextBaseVersionB:t[t.length-1].baseVersion+1,originalOperationsACount:e.length,originalOperationsBCount:t.length};let a=0;for(;a{if(e.key===t.key&&e.range.start.hasSameParentAs(t.range.start)){const i=e.range.getDifference(t.range).map(t=>new Ra(t,e.key,e.oldValue,e.newValue,0)),n=e.range.getIntersection(t.range);return n&&o.aIsStrong&&i.push(new Ra(n,t.key,t.newValue,e.newValue,0)),0==i.length?[new sl(0)]:i}return[e]}),Wd(Ra,Da,(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 Ra(t,e.key,e.oldValue,e.newValue,e.baseVersion));if(t.shouldReceiveAttributes){const i=Qd(t,e.key,e.oldValue);i&&o.unshift(i)}return o}return e.range=e.range._getTransformedByInsertion(t.position,t.howMany,!1)[0],[e]}),Wd(Ra,ja,(e,t)=>{const o=[];e.range.start.hasSameParentAs(t.deletionPosition)&&(e.range.containsPosition(t.deletionPosition)||e.range.start.isEqual(t.deletionPosition))&&o.push(Cs._createFromPositionAndShift(t.graveyardPosition,1));const i=e.range._getTransformedByMergeOperation(t);return i.isCollapsed||o.push(i),o.map(t=>new Ra(t,e.key,e.oldValue,e.newValue,e.baseVersion))}),Wd(Ra,Va,(e,t)=>function(e,t){const o=Cs._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 r=[];for(let e of n){e=e._getTransformedByDeletion(t.sourcePosition,t.howMany);const o=t.getMovedRangeStart(),i=e.start.hasSameParentAs(o);e=e._getTransformedByInsertion(o,t.howMany,i),r.push(...e)}i&&r.push(i._getTransformedByMove(t.sourcePosition,t.targetPosition,t.howMany,!1)[0]);return r}(e.range,t).map(t=>new Ra(t,e.key,e.oldValue,e.newValue,e.baseVersion))),Wd(Ra,Fa,(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 Cs(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]}),Wd(Da,Ra,(e,t)=>{const o=[e];if(e.shouldReceiveAttributes&&e.position.hasSameParentAs(t.range.start)&&t.range.containsPosition(e.position)){const i=Qd(e,t.key,t.newValue);i&&o.push(i)}return o}),Wd(Da,Da,(e,t,o)=>(e.position.isEqual(t.position)&&o.aIsStrong||(e.position=e.position._getTransformedByInsertOperation(t)),[e])),Wd(Da,Va,(e,t)=>(e.position=e.position._getTransformedByMoveOperation(t),[e])),Wd(Da,Fa,(e,t)=>(e.position=e.position._getTransformedBySplitOperation(t),[e])),Wd(Da,ja,(e,t)=>(e.position=e.position._getTransformedByMergeOperation(t),[e])),Wd(La,Da,(e,t)=>(e.oldRange&&(e.oldRange=e.oldRange._getTransformedByInsertOperation(t)[0]),e.newRange&&(e.newRange=e.newRange._getTransformedByInsertOperation(t)[0]),[e])),Wd(La,La,(e,t,o)=>{if(e.name==t.name){if(!o.aIsStrong)return[new sl(0)];e.oldRange=t.newRange?t.newRange.clone():null}return[e]}),Wd(La,ja,(e,t)=>(e.oldRange&&(e.oldRange=e.oldRange._getTransformedByMergeOperation(t)),e.newRange&&(e.newRange=e.newRange._getTransformedByMergeOperation(t)),[e])),Wd(La,Va,(e,t,o)=>{if(e.oldRange&&(e.oldRange=Cs._createFromRanges(e.oldRange._getTransformedByMoveOperation(t))),e.newRange){if(o.abRelation){const i=Cs._createFromRanges(e.newRange._getTransformedByMoveOperation(t));if("left"==o.abRelation.side&&t.targetPosition.isEqual(e.newRange.start))return e.newRange.start.path=o.abRelation.path,e.newRange.end=i.end,[e];if("right"==o.abRelation.side&&t.targetPosition.isEqual(e.newRange.end))return e.newRange.start=i.start,e.newRange.end.path=o.abRelation.path,[e]}e.newRange=Cs._createFromRanges(e.newRange._getTransformedByMoveOperation(t))}return[e]}),Wd(La,Fa,(e,t,o)=>{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=_s._createAt(t.insertionPosition):e.newRange.start.isEqual(t.splitPosition)&&!o.abRelation.wasInLeftElement&&(e.newRange.start=_s._createAt(t.moveTargetPosition)),e.newRange.end.isEqual(t.splitPosition)&&o.abRelation.wasInRightElement?e.newRange.end=_s._createAt(t.moveTargetPosition):e.newRange.end.isEqual(t.splitPosition)&&o.abRelation.wasEndBeforeMergedElement?e.newRange.end=_s._createAt(t.insertionPosition):e.newRange.end=i.end,[e]}e.newRange=e.newRange._getTransformedBySplitOperation(t)}return[e]}),Wd(ja,Da,(e,t)=>(e.sourcePosition.hasSameParentAs(t.position)&&(e.howMany+=t.howMany),e.sourcePosition=e.sourcePosition._getTransformedByInsertOperation(t),e.targetPosition=e.targetPosition._getTransformedByInsertOperation(t),[e])),Wd(ja,ja,(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 _s(t.graveyardPosition.root,o),e.howMany=0,[e]}return[new sl(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,r=i&&!n;if(n&&!i||!r&&o.aIsStrong){const o=t.targetPosition._getTransformedByMergeOperation(t),i=e.targetPosition._getTransformedByMergeOperation(t);return[new Va(o,e.howMany,i,0)]}return[new sl(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]}),Wd(ja,Va,(e,t,o)=>{const i=Cs._createFromPositionAndShift(t.sourcePosition,t.howMany);return"remove"==t.type&&!o.bWasUndone&&!o.forceWeakRemove&&e.deletionPosition.hasSameParentAs(t.sourcePosition)&&i.containsPosition(e.sourcePosition)?[new sl(0)]:(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.graveyardPosition.isEqual(t.targetPosition)||(e.graveyardPosition=e.graveyardPosition._getTransformedByMoveOperation(t)),[e])}),Wd(ja,Fa,(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)){const i=0!=t.howMany,n=t.graveyardPosition&&e.deletionPosition.isEqual(t.graveyardPosition);if(i||n||"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]}),Wd(Va,Da,(e,t)=>{const o=Cs._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]}),Wd(Va,Va,(e,t,o)=>{const i=Cs._createFromPositionAndShift(e.sourcePosition,e.howMany),n=Cs._createFromPositionAndShift(t.sourcePosition,t.howMany);let r,s=o.aIsStrong,a=!o.aIsStrong;if("insertBefore"==o.abRelation||"insertAfter"==o.baRelation?a=!0:"insertAfter"!=o.abRelation&&"insertBefore"!=o.baRelation||(a=!1),r=e.targetPosition.isEqual(t.targetPosition)&&a?e.targetPosition._getTransformedByDeletion(t.sourcePosition,t.howMany):e.targetPosition._getTransformedByMove(t.sourcePosition,t.targetPosition,t.howMany),Jd(e,t)&&Jd(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),Zd([i],r);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()),Zd([i],r);const l=No(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),Zd([i],r);"remove"!=e.type||"remove"==t.type||o.aWasUndone||o.forceWeakRemove?"remove"==e.type||"remove"!=t.type||o.bWasUndone||o.forceWeakRemove||(s=!1):s=!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"==No(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&&s&&(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 sl(e.baseVersion)]:Zd(c,r)}),Wd(Va,Fa,(e,t,o)=>{let i=e.targetPosition.clone();e.targetPosition.isEqual(t.insertionPosition)&&t.graveyardPosition&&"moveTargetAfter"!=o.abRelation||(i=e.targetPosition._getTransformedBySplitOperation(t));const n=Cs._createFromPositionAndShift(e.sourcePosition,e.howMany);if(n.end.isEqual(t.insertionPosition))return t.graveyardPosition||e.howMany++,e.targetPosition=i,[e];if(n.start.hasSameParentAs(t.splitPosition)&&n.containsPosition(t.splitPosition)){let e=new Cs(t.splitPosition,n.end);e=e._getTransformedBySplitOperation(t);return Zd([new Cs(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 r=[n._getTransformedBySplitOperation(t)];if(t.graveyardPosition){const i=n.start.isEqual(t.graveyardPosition)||n.containsPosition(t.graveyardPosition);e.howMany>1&&i&&!o.aWasUndone&&r.push(Cs._createFromPositionAndShift(t.insertionPosition,1))}return Zd(r,i)}),Wd(Va,ja,(e,t,o)=>{const i=Cs._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 sl(0)]}else if(!o.aWasUndone){const o=[];let i=t.graveyardPosition.clone(),n=t.targetPosition._getTransformedByMergeOperation(t);e.howMany>1&&(o.push(new Va(e.sourcePosition,e.howMany-1,e.targetPosition,0)),i=i._getTransformedByMove(e.sourcePosition,e.targetPosition,e.howMany-1),n=n._getTransformedByMove(e.sourcePosition,e.targetPosition,e.howMany-1));const r=t.deletionPosition._getCombined(e.sourcePosition,e.targetPosition),s=new Va(i,1,r,0),a=s.getMovedRangeStart().path.slice();a.push(0);const l=new _s(s.targetPosition.root,a);n=n._getTransformedByMove(i,r,1);const c=new Va(n,t.howMany,l,0);return o.push(s),o.push(c),o}const n=Cs._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]}),Wd(za,Da,(e,t)=>(e.position=e.position._getTransformedByInsertOperation(t),[e])),Wd(za,ja,(e,t)=>e.position.isEqual(t.deletionPosition)?(e.position=t.graveyardPosition.clone(),e.position.stickiness="toNext",[e]):(e.position=e.position._getTransformedByMergeOperation(t),[e])),Wd(za,Va,(e,t)=>(e.position=e.position._getTransformedByMoveOperation(t),[e])),Wd(za,za,(e,t,o)=>{if(e.position.isEqual(t.position)){if(!o.aIsStrong)return[new sl(0)];e.oldName=t.newName}return[e]}),Wd(za,Fa,(e,t)=>{if("same"==No(e.position.path,t.splitPosition.getParentPath())&&!t.graveyardPosition){const t=new za(e.position.getShiftedBy(1),e.oldName,e.newName,0);return[e,t]}return e.position=e.position._getTransformedBySplitOperation(t),[e]}),Wd(Ba,Ba,(e,t,o)=>{if(e.root===t.root&&e.key===t.key){if(!o.aIsStrong||e.newValue===t.newValue)return[new sl(0)];e.oldValue=t.newValue}return[e]}),Wd(Fa,Da,(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 _s(t.graveyardPosition.root,o),n=Fa.getInsertionPosition(new _s(t.graveyardPosition.root,o)),r=new Fa(i,0,null,0);return r.insertionPosition=n,e.splitPosition=e.splitPosition._getTransformedByMergeOperation(t),e.insertionPosition=Fa.getInsertionPosition(e.splitPosition),e.graveyardPosition=r.insertionPosition.clone(),e.graveyardPosition.stickiness="toNext",[r,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=Fa.getInsertionPosition(e.splitPosition),e.graveyardPosition&&(e.graveyardPosition=e.graveyardPosition._getTransformedByMergeOperation(t)),[e]}),Wd(Fa,Va,(e,t,o)=>{const i=Cs._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 r=new _s(i.root,n);return[new Va(o,e.howMany,r,0)]}e.graveyardPosition=e.graveyardPosition._getTransformedByMoveOperation(t)}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 sl(0)];if(e.graveyardPosition&&t.graveyardPosition&&e.graveyardPosition.isEqual(t.graveyardPosition))return[new sl(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,r=i&&!n;if(n&&!i||!r&&o.aIsStrong){const o=[];return t.howMany&&o.push(new Va(t.moveTargetPosition,t.howMany,t.splitPosition,0)),e.howMany&&o.push(new Va(e.splitPosition,e.howMany,e.moveTargetPosition,0)),o}return[new sl(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 _s(t.insertionPosition.root,o);return[e,new Va(e.insertionPosition,1,i,0)]}return e.splitPosition.hasSameParentAs(t.splitPosition)&&e.splitPosition.offset0}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,r=[];for(const t of e){const e=eu(t,o).find(e=>e.start.root!=n.graveyard);e&&r.push(e)}r.length&&i.change(e=>{e.setSelection(r,{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,r=Array.from(i.history.getOperations(n)),s=Gd([e.getReversed()],r,{useRelations:!0,document:this.editor.model.document,padWithNoOps:!1,forceWeakRemove:!0}).operationsA;for(const n of s)t.addOperation(n),o.applyOperation(n),i.history.setOperationAsUndone(e,n)}}}function eu(e,t){const o=e.getTransformedByOperations(t);o.sort((e,t)=>e.start.isBefore(t.start)?-1:1);for(let e=1;et.batch==e):this._stack.length-1,o=this._stack.splice(t,1)[0],i=this.editor.model.createBatch("transparent");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 ou extends Xd{execute(){const e=this._stack.pop(),t=this.editor.model.createBatch("transparent");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.refresh()}}class iu extends Ml{static get pluginName(){return"UndoEditing"}constructor(e){super(e),this._batchRegistry=new WeakSet}init(){const e=this.editor;this._undoCommand=new tu(e),this._redoCommand=new ou(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),r=this._undoCommand._createdBatches.has(i);this._batchRegistry.has(i)||"transparent"==i.type&&!n&&!r||(n?this._undoCommand.addBatch(i):r||(this._undoCommand.addBatch(i),this._redoCommand.clearStack()),this._batchRegistry.add(i))},{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")}}var nu='',ru='';class su extends Ml{init(){const e=this.editor,t=e.locale,o=e.t,i="ltr"==t.uiLanguageDirection?nu:ru,n="ltr"==t.uiLanguageDirection?ru:nu;this._addButton("undo",o("Undo"),"CTRL+Z",i),this._addButton("redo",o("Redo"),"CTRL+Y",n)}_addButton(e,t,o,i){const n=this.editor;n.ui.componentFactory.add(e,r=>{const s=n.commands.get(e),a=new hc(r);return a.set({label:t,icon:i,keystroke:o,tooltip:!0}),a.bind("isEnabled").to(s,"isEnabled"),this.listenTo(a,"execute",()=>{n.execute(e),n.editing.view.focus()}),a})}}class au extends Ml{static get requires(){return[iu,su]}static get pluginName(){return"Undo"}}class lu{constructor(e){this.context=e}destroy(){this.stopListening()}static get isContextPlugin(){return!0}}Co(lu,Wi);class cu extends lu{static get pluginName(){return"PendingActions"}init(){this.set("hasAny",!1),this._actions=new Ao({idProperty:"_id"}),this._actions.delegate("add","remove").to(this)}add(e){if("string"!=typeof e)throw new go.b("pendingactions-add-invalid-message: The message must be a string.",this);const t=Object.create(Wi);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]()}}class du{constructor(){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()}}Co(du,Wi);class uu extends Ml{static get pluginName(){return"FileRepository"}static get requires(){return[cu]}init(){this.loaders=new Ao,this.loaders.on("add",()=>this._updatePendingAction()),this.loaders.on("remove",()=>this._updatePendingAction()),this._loadersMap=new Map,this._pendingAction=null,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 console.warn(Object(go.a)("filerepository-no-upload-adapter: Upload adapter is not defined.")),null;const t=new hu(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 hu?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(cu);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}}Co(uu,Wi);class hu{constructor(e,t){this.id=uo(),this._filePromiseWrapper=this._createFilePromiseWrapper(e),this._adapter=t(this),this._reader=new du,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 go.b("filerepository-read-wrong-status: You cannot call read if the status is different than idle.",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 go.b("filerepository-upload-wrong-status: You cannot call upload if the status is different than idle.",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}}Co(hu,Wi);function gu(){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}("ckCsrfToken");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="ckCsrfToken",o=e,document.cookie=encodeURIComponent(t)+"="+encodeURIComponent(o)+";path=/"),e}class mu{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,r=(0,this.t)("Cannot upload file:")+` ${o.name}.`;i.addEventListener("error",()=>t(r)),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:r);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",gu()),this.xhr.send(t)}}class fu{static get pluginName(){return"BlockAutoformatEditing"}constructor(e,t,o){let i,n=null;"function"==typeof o?i=o:(n=e.commands.get(o),i=()=>{e.execute(o)}),e.model.document.on("change",(o,r)=>{if(n&&!n.isEnabled)return;if("transparent"==r.type)return;const s=Array.from(e.model.document.differ.getChanges()),a=s[0];if(1!=s.length||"insert"!==a.type||"$text"!=a.name||1!=a.length)return;const l=a.position.parent;if(!l.is("paragraph")||1!==l.childCount)return;const c=t.exec(l.getChild(0).data);c&&e.model.enqueueChange(e=>{const t=e.createPositionAt(l,0),o=e.createPositionAt(l,c[0].length),n=new Vs(t,o);!1!==i({match:c})&&e.remove(n),n.detach()})})}}function pu(e,t){let o=e.start;return{text:Array.from(e.getItems()).reduce((e,i)=>i.is("text")||i.is("textProxy")?e+i.data:(o=t.createPositionAfter(i),""),""),range:t.createRange(o,e.end)}}class bu{static get pluginName(){return"InlineAutoformatEditing"}constructor(e,t,o){let i,n,r,s;t instanceof RegExp?i=t:r=t,"string"==typeof o?n=o:s=o,r=r||(e=>{let t;const o=[],n=[];for(;null!==(t=i.exec(e))&&!(t&&t.length<4);){let{index:e,1:i,2:r,3:s}=t;const a=i+r+s;e+=t[0].length-a.length;const l=[e,e+i.length],c=[e+i.length+r.length,e+i.length+r.length+s.length];o.push(l),o.push(c),n.push([e+i.length,e+i.length+r.length])}return{remove:o,format:n}}),s=s||((t,o)=>{const i=e.model.schema.getValidRanges(o,n);for(const e of i)t.setAttribute(n,!0,e);t.removeSelectionAttribute(n)}),e.model.document.on("change",(t,o)=>{if("transparent"==o.type)return;const i=e.model,n=i.document.selection;if(!n.isCollapsed)return;const a=Array.from(i.document.differ.getChanges()),l=a[0];if(1!=a.length||"insert"!==l.type||"$text"!=l.name||1!=l.length)return;const c=n.focus,d=c.parent,{text:u,range:h}=pu(i.createRange(i.createPositionAt(d,0),c),i),g=r(u),m=wu(h.start,g.format,i),f=wu(h.start,g.remove,i);m.length&&f.length&&i.enqueueChange(e=>{if(!1!==s(e,m))for(const t of f.reverse())e.remove(t)})})}}function wu(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 ku(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 _u extends hd{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);for(const t of n)i?e.setAttribute(this.attributeKey,i,t):e.removeAttribute(this.attributeKey,t)}})}_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}}class vu extends Ml{static get pluginName(){return"BoldEditing"}init(){const e=this.editor;e.model.schema.extend("$text",{allowAttributes:"bold"}),e.model.schema.setAttributeProperties("bold",{isFormatting:!0,copyOnEnter:!0}),e.conversion.attributeToElement({model:"bold",view:"strong",upcastAlso:["b",e=>{const t=e.getStyle("font-weight");return t?"bold"==t||Number(t)>=600?{name:!0,styles:["font-weight"]}:void 0:null}]}),e.commands.add("bold",new _u(e,"bold")),e.keystrokes.set("CTRL+B","bold")}}class yu extends Ml{init(){const e=this.editor,t=e.t;e.ui.componentFactory.add("bold",o=>{const i=e.commands.get("bold"),n=new hc(o);return n.set({label:t("Bold"),icon:'',keystroke:"CTRL+B",tooltip:!0,isToggleable:!0}),n.bind("isOn","isEnabled").to(i,"value","isEnabled"),this.listenTo(n,"execute",()=>{e.execute("bold"),e.editing.view.focus()}),n})}}class xu extends Ml{static get pluginName(){return"ItalicEditing"}init(){const e=this.editor;e.model.schema.extend("$text",{allowAttributes:"italic"}),e.model.schema.setAttributeProperties("italic",{isFormatting:!0,copyOnEnter:!0}),e.conversion.attributeToElement({model:"italic",view:"i",upcastAlso:["em",{styles:{"font-style":"italic"}}]}),e.commands.add("italic",new _u(e,"italic")),e.keystrokes.set("CTRL+I","italic")}}class Cu extends Ml{init(){const e=this.editor,t=e.t;e.ui.componentFactory.add("italic",o=>{const i=e.commands.get("italic"),n=new hc(o);return n.set({label:t("Italic"),icon:'',keystroke:"CTRL+I",tooltip:!0,isToggleable:!0}),n.bind("isOn","isEnabled").to(i,"value","isEnabled"),this.listenTo(n,"execute",()=>{e.execute("italic"),e.editing.view.focus()}),n})}}class Au extends Ml{static get pluginName(){return"SuperscriptEditing"}init(){const e=this.editor;e.model.schema.extend("$text",{allowAttributes:"superscript"}),e.model.schema.setAttributeProperties("superscript",{isFormatting:!0,copyOnEnter:!0}),e.conversion.attributeToElement({model:"superscript",view:"sup",upcastAlso:[{styles:{"vertical-align":"super"}}]}),e.commands.add("superscript",new _u(e,"superscript"))}}class Tu extends Ml{init(){const e=this.editor,t=e.t;e.ui.componentFactory.add("superscript",o=>{const i=e.commands.get("superscript"),n=new hc(o);return n.set({label:t("Superscript"),icon:'',tooltip:!0,isToggleable:!0}),n.bind("isOn","isEnabled").to(i,"value","isEnabled"),this.listenTo(n,"execute",()=>{e.execute("superscript"),e.editing.view.focus()}),n})}}class Su extends Ml{static get pluginName(){return"SubscriptEditing"}init(){const e=this.editor;e.model.schema.extend("$text",{allowAttributes:"subscript"}),e.model.schema.setAttributeProperties("subscript",{isFormatting:!0,copyOnEnter:!0}),e.conversion.attributeToElement({model:"subscript",view:"sub",upcastAlso:[{styles:{"vertical-align":"sub"}}]}),e.commands.add("subscript",new _u(e,"subscript"))}}class Pu extends Ml{init(){const e=this.editor,t=e.t;e.ui.componentFactory.add("subscript",o=>{const i=e.commands.get("subscript"),n=new hc(o);return n.set({label:t("Subscript"),icon:'',tooltip:!0,isToggleable:!0}),n.bind("isOn","isEnabled").to(i,"value","isEnabled"),this.listenTo(n,"execute",()=>{e.execute("subscript"),e.editing.view.focus()}),n})}}class Eu extends Ml{static get pluginName(){return"UnderlineEditing"}init(){const e=this.editor;e.model.schema.extend("$text",{allowAttributes:"underline"}),e.model.schema.setAttributeProperties("underline",{isFormatting:!0,copyOnEnter:!0}),e.conversion.attributeToElement({model:"underline",view:"u",upcastAlso:{styles:{"text-decoration":"underline"}}}),e.commands.add("underline",new _u(e,"underline")),e.keystrokes.set("CTRL+U","underline")}}class Mu extends Ml{init(){const e=this.editor,t=e.t;e.ui.componentFactory.add("underline",o=>{const i=e.commands.get("underline"),n=new hc(o);return n.set({label:t("Underline"),icon:'',keystroke:"CTRL+U",tooltip:!0,isToggleable:!0}),n.bind("isOn","isEnabled").to(i,"value","isEnabled"),this.listenTo(n,"execute",()=>{e.execute("underline"),e.editing.view.focus()}),n})}}class Iu extends Ml{static get pluginName(){return"StrikethroughEditing"}init(){const e=this.editor;e.model.schema.extend("$text",{allowAttributes:"strikethrough"}),e.model.schema.setAttributeProperties("strikethrough",{isFormatting:!0,copyOnEnter:!0}),e.conversion.attributeToElement({model:"strikethrough",view:"s",upcastAlso:["del","strike",{styles:{"text-decoration":"line-through"}}]}),e.commands.add("strikethrough",new _u(e,"strikethrough")),e.keystrokes.set("CTRL+SHIFT+X","strikethrough")}}class Nu extends Ml{init(){const e=this.editor,t=e.t;e.ui.componentFactory.add("strikethrough",o=>{const i=e.commands.get("strikethrough"),n=new hc(o);return n.set({label:t("Strikethrough"),icon:'',keystroke:"CTRL+SHIFT+X",tooltip:!0,isToggleable:!0}),n.bind("isOn","isEnabled").to(i,"value","isEnabled"),this.listenTo(n,"execute",()=>{e.execute("strikethrough"),e.editing.view.focus()}),n})}}class Ru extends Ml{static get pluginName(){return"CodeEditing"}init(){const e=this.editor;e.model.schema.extend("$text",{allowAttributes:"code"}),e.model.schema.setAttributeProperties("code",{isFormatting:!0,copyOnEnter:!0}),e.conversion.attributeToElement({model:"code",view:"code",upcastAlso:{styles:{"word-wrap":"break-word"}}}),e.commands.add("code",new _u(e,"code"))}}o(11);class Ou extends Ml{init(){const e=this.editor,t=e.t;e.ui.componentFactory.add("code",o=>{const i=e.commands.get("code"),n=new hc(o);return n.set({label:t("Code"),icon:'',tooltip:!0,isToggleable:!0}),n.bind("isOn","isEnabled").to(i,"value","isEnabled"),this.listenTo(n,"execute",()=>{e.execute("code"),e.editing.view.focus()}),n})}}function Vu(e){const t=e.next();return t.done?null:t.value}class Du extends hd{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()),r=void 0===e.forceValue?!this.value:e.forceValue;t.change(e=>{if(r){const t=n.filter(e=>Lu(e)||Bu(o,e));this._applyQuote(e,t)}else this._removeQuote(e,n.filter(Lu))})}_getValue(){const e=Vu(this.editor.model.document.selection.getSelectedBlocks());return!(!e||!Lu(e))}_checkEnabled(){if(this.value)return!0;const e=this.editor.model.document.selection,t=this.editor.model.schema,o=Vu(e.getSelectedBlocks());return!!o&&Bu(t,o)}_removeQuote(e,t){zu(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=[];zu(e,t).reverse().forEach(t=>{let i=Lu(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 Lu(e){return"blockQuote"==e.parent.name?e.parent:null}function zu(e,t){let o,i=0;const n=[];for(;i{if(e.endsWith("blockQuote")&&"blockQuote"==t.name)return!1}),e.conversion.elementToElement({model:"blockQuote",view:"blockquote"}),e.model.document.registerPostFixer(o=>{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("blockQuote")&&i.isEmpty)return o.remove(i),!0;if(i.is("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("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("blockQuote")&&t.isEmpty)return o.remove(t),!0}return!1})}afterInit(){const e=this.editor.commands.get("blockQuote");this.listenTo(this.editor.editing.view.document,"enter",(t,o)=>{const i=this.editor.model.document,n=i.selection.getLastPosition().parent;i.selection.isCollapsed&&n.isEmpty&&e.value&&(this.editor.execute("blockQuote"),this.editor.editing.view.scrollToTheSelection(),o.preventDefault(),t.stop())})}}o(47);class Fu extends Ml{init(){const e=this.editor,t=e.t;e.ui.componentFactory.add("blockQuote",o=>{const i=e.commands.get("blockQuote"),n=new hc(o);return n.set({label:t("Block quote"),icon:'',tooltip:!0,isToggleable:!0}),n.bind("isOn","isEnabled").to(i,"value","isEnabled"),this.listenTo(n,"execute",()=>{e.execute("blockQuote"),e.editing.view.focus()}),n})}}class Hu extends hd{refresh(){const e=this.editor.model,t=Vu(e.document.selection.getSelectedBlocks());this.value=!!t&&t.is("paragraph"),this.isEnabled=!!t&&Wu(t,e.schema)}execute(e={}){const t=this.editor.model,o=t.document;t.change(i=>{const n=(e.selection||o.selection).getSelectedBlocks();for(const e of n)!e.is("paragraph")&&Wu(e,t.schema)&&i.rename(e,"paragraph")})}}function Wu(e,t){return t.checkChild(e.parent,"paragraph")&&!t.isObject(e)}class Uu extends hd{execute(e){const t=this.editor.model;t.schema.checkChild(e.position,"paragraph")&&t.change(o=>{const i=o.createElement("paragraph");t.insertContent(i,e.position),o.setSelection(i,"in")})}}class qu extends Ml{static get pluginName(){return"Paragraph"}init(){const e=this.editor,t=e.model,o=e.data;e.commands.add("paragraph",new Hu(e)),e.commands.add("insertParagraph",new Uu(e)),t.schema.register("paragraph",{inheritAllFrom:"$block"}),e.conversion.elementToElement({model:"paragraph",view:"p"}),e.conversion.for("upcast").elementToElement({model:(e,t)=>qu.paragraphLikeElements.has(e.name)?e.isEmpty?null:t.createElement("paragraph"):null,converterPriority:"low"}),o.upcastDispatcher.on("element",(e,t,o)=>{o.consumable.test(t.viewItem,{name:t.viewItem.name})&&$u(t.viewItem,t.modelCursor,o.schema)&&Object.assign(t,Gu(t.viewItem,t.modelCursor,o))},{priority:"low"}),o.upcastDispatcher.on("text",(e,t,o)=>{t.modelRange||$u(t.viewItem,t.modelCursor,o.schema)&&Object.assign(t,Gu(t.viewItem,t.modelCursor,o))},{priority:"lowest"}),t.document.registerPostFixer(e=>this._autoparagraphEmptyRoots(e)),e.data.on("ready",()=>{t.enqueueChange("transparent",e=>this._autoparagraphEmptyRoots(e))},{priority:"lowest"})}_autoparagraphEmptyRoots(e){const t=this.editor.model;for(const o of t.document.getRootNames()){const i=t.document.getRoot(o);if(i.isEmpty&&"$graveyard"!=i.rootName&&t.schema.checkChild(i,"paragraph"))return e.insertElement("paragraph",i),!0}}}function Gu(e,t,o){const i=o.writer.createElement("paragraph");return o.writer.insert(i,t),o.convertItem(e,o.writer.createPositionAt(i,0))}function $u(e,t,o){const i=o.createContext(t);return!!o.checkChild(i,"paragraph")&&!!o.checkChild(i.push("paragraph"),e)}qu.paragraphLikeElements=new Set(["blockquote","dd","div","dt","h1","h2","h3","h4","h5","h6","li","p","td"]);class Yu extends hd{constructor(e,t){super(e),this.modelElements=t}refresh(){const e=Vu(this.editor.model.document.selection.getSelectedBlocks());this.value=!!e&&this.modelElements.includes(e.name)&&e.name,this.isEnabled=!!e&&this.modelElements.some(t=>Ku(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=>Ku(e,i,t.schema));for(const t of n)t.is(i)||e.rename(t,i)})}}function Ku(e,t,o){return o.checkChild(e.parent,t)&&!o.isObject(e)}class Qu extends Ml{static get pluginName(){return"HeadingEditing"}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[qu]}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 Yu(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(e.model))&&!n.is("paragraph")&&0===n.childCount&&i.writer.rename(n,"paragraph")})}_addDefaultH1Conversion(e){e.conversion.for("upcast").elementToElement({model:"heading1",view:"h1",converterPriority:ho.get("low")+1})}}class Ju{constructor(e,t){t&&zi(this,t),e&&this.set(e)}}function Zu(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})}Co(Ju,Wi);o(12);class Xu extends Ml{init(){const e=this.editor,t=e.t,o=Zu(e),i=t("Choose heading"),n=t("Heading");e.ui.componentFactory.add("heading",t=>{const r={},s=new Ao,a=e.commands.get("heading"),l=e.commands.get("paragraph"),c=[a];for(const e of o){const t={type:"button",model:new Ju({label:e.title,class:e.class,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})),s.add(t),r[e.model]=e.title}const d=Nc(t);return Rc(d,s),d.buttonView.set({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=e||t&&"paragraph";return r[o]?r[o]:i}),this.listenTo(d,"execute",t=>{e.execute(t.source.commandName,t.source.commandValue?{value:t.source.commandValue}:void 0),e.editing.view.focus()}),d})}}class eh extends hr{observe(e){this.listenTo(e,"load",(e,t)=>{"IMG"==t.target.tagName&&this._fireEvents(t)},{useCapture:!0})}_fireEvents(e){this.isEnabled&&(this.document.fire("layoutChanged"),this.document.fire("imageLoaded",e))}}class th{constructor(){this._stack=[]}add(e,t){const o=this._stack,i=o[0];this._insertDescriptor(e);const n=o[0];i===n||oh(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||oh(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(oh(e,t[o]))return;o>-1&&t.splice(o,1);let i=0;for(;t[i]&&ih(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 oh(e,t){return e&&t&&e.priority==t.priority&&nh(e.classes)==nh(t.classes)}function ih(e,t){return e.priority>t.priority||!(e.prioritynh(t.classes)}function nh(e){return Array.isArray(e)?e.sort().join(","):e}Co(th,po);function rh(e){return!!e.is("element")&&!!e.getCustomProperty("widget")}function sh(e,t,o={}){return t.setAttribute("contenteditable","false",e),t.addClass("ck-widget",e),t.setCustomProperty("widget",!0,e),e.getFillerOffset=uh,o.label&&function(e,t,o){o.setCustomProperty("widgetLabel",t,e)}(e,o.label,t),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 dc;return o.set("content",''),o.render(),t.appendChild(o.element),t}));t.insert(t.createPositionAt(e,0),o),t.addClass(["ck-widget_with-selection-handle"],e)}(e,t),function(e,t,o,i){const n=new th;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)}(e,t,(e,t,o)=>o.addClass(i(t.classes),e),(e,t,o)=>o.removeClass(i(t.classes),e)),e;function i(e){return Array.isArray(e)?e:[e]}}function ah(e){const t=e.getCustomProperty("widgetLabel");return t?"function"==typeof t?t():t:""}function lh(e,t){return t.addClass(["ck-editor__editable","ck-editor__nested-editable"],e),t.setAttribute("contenteditable",e.isReadOnly?"false":"true",e),e.on("change:isReadOnly",(o,i,n)=>{t.setAttribute("contenteditable",n?"false":"true",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)}),e}function ch(e,t){const o=e.getSelectedElement();if(o&&t.schema.isBlock(o))return t.createPositionAfter(o);const i=e.getSelectedBlocks().next().value;if(i){if(i.isEmpty)return t.createPositionAt(i,0);const o=t.createPositionAfter(i);return e.focus.isTouching(o)?o:t.createPositionBefore(i)}return e.focus}function dh(e,t){const o=new Xr(er.window),i=o.getIntersection(e),n=t.height+sc.arrowVerticalOffset;if(e.top-n>o.top||e.bottom+n!e.is("image"))}(o)}function ph(e){return Array.from(e.getChildren()).find(e=>e.is("img"))}function bh(e){return o=>{o.on(`attribute:${e}:image`,t)};function t(e,t,o){if(!o.consumable.consume(t.item,e.name))return;const i=o.writer,n=ph(o.mapper.toViewElement(t.item));null!==t.attributeNewValue?i.setAttribute(t.attributeKey,t.attributeNewValue,n):i.removeAttribute(t.attributeKey,n)}}class wh extends hd{refresh(){this.isEnabled=fh(this.editor.model)}execute(e){const t=this.editor.model;t.change(o=>{const i=Array.isArray(e.source)?e.source:[e.source];for(const e of i)mh(o,t,{src:e})})}}class kh extends Ml{static get pluginName(){return"ImageEditing"}init(){const e=this.editor,t=e.model.schema,o=e.t,i=e.conversion;e.editing.view.addObserver(eh),t.register("image",{isObject:!0,isBlock:!0,allowWhere:"$block",allowAttributes:["alt","src","srcset"]}),i.for("dataDowncast").elementToElement({model:"image",view:(e,t)=>_h(t)}),i.for("editingDowncast").elementToElement({model:"image",view:(e,t)=>{return i=_h(t),n=t,r=o("image widget"),n.setCustomProperty("image",!0,i),sh(i,n,{label:function(){const e=ph(i).getAttribute("alt");return e?`${e} ${r}`:r}});var i,n,r}}),i.for("downcast").add(bh("src")).add(bh("alt")).add(function(){return t=>{t.on("attribute:srcset:image",e)};function e(e,t,o){if(!o.consumable.consume(t.item,e.name))return;const i=o.writer,n=ph(o.mapper.toViewElement(t.item));if(null===t.attributeNewValue){const e=t.attributeOldValue;e.data&&(i.removeAttribute("srcset",n),i.removeAttribute("sizes",n),e.width&&i.removeAttribute("width",n))}else{const e=t.attributeNewValue;e.data&&(i.setAttribute("srcset",e.data,n),i.setAttribute("sizes","100vw",n),e.width&&i.setAttribute("width",e.width,n))}}}()),i.for("upcast").elementToElement({view:{name:"img",attributes:{src:!0}},model:(e,t)=>t.createElement("image",{src:e.getAttribute("src")})}).attributeToAttribute({view:{name:"img",key:"alt"},model:"alt"}).attributeToAttribute({view:{name:"img",key:"srcset"},model:{key:"srcset",value:e=>{const t={data:e.getAttribute("srcset")};return e.hasAttribute("width")&&(t.width=e.getAttribute("width")),t}}}).add(function(){return t=>{t.on("element:figure",e)};function e(e,t,o){if(!o.consumable.test(t.viewItem,{name:!0,classes:"image"}))return;const i=ph(t.viewItem);if(!i||!i.hasAttribute("src")||!o.consumable.test(i,{name:!0}))return;const n=o.convertItem(i,t.modelCursor),r=Vu(n.modelRange.getItems());r&&(o.convertChildren(t.viewItem,o.writer.createPositionAt(r,0)),t.modelRange=n.modelRange,t.modelCursor=n.modelCursor)}}()),e.commands.add("imageInsert",new wh(e))}}function _h(e){const t=e.createEmptyElement("img"),o=e.createContainerElement("figure",{class:"image"});return e.insert(e.createPositionAt(o,0),t),o}class vh extends Rr{constructor(e){super(e),this.domEventType="mousedown"}onDomEvent(e){this.fire(e.type,e)}}function yh(e){const t=[];return(!e.previousSibling||function(e){return e.previousSibling&&rh(e.previousSibling)}(e))&&t.push("before"),(function(e){return!e.nextSibling}(e)||function(e){return e.nextSibling&&rh(e.nextSibling)}(e))&&t.push("after"),t}o(50);const xh=["before","after"],Ch=(new DOMParser).parseFromString('\n',"image/svg+xml").firstChild;class Ah extends Ml{static get requires(){return[qu]}static get pluginName(){return"WidgetTypeAround"}constructor(e){super(e),this._widgetsWithTypeAroundUI=new Set}destroy(){this._widgetsWithTypeAroundUI.clear()}init(){this._enableTypeAroundUIInjection(),this._enableDetectionOfTypeAroundWidgets(),this._enableInsertingParagraphsOnButtonClick()}_insertParagraph(e,t){const o=this.editor,i=o.editing.view,n=o.editing.mapper.toModelElement(e);let r;r="before"===t?o.model.createPositionBefore(n):o.model.createPositionAfter(n),o.execute("insertParagraph",{position:r}),i.focus(),i.scrollToTheSelection()}_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,o,n)=>{const r=n.mapper.toViewElement(o.item);(function(e,t,o){return e&&rh(e)&&!o.isInline(t)})(r,o.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 xh){const i=new Rl({tag:"div",attributes:{class:["ck","ck-widget__type-around__button","ck-widget__type-around__button_"+o],title:t[o]},children:[e.ownerDocument.importNode(Ch,!0)]});e.appendChild(i.render())}}(o,t),o}));e.insert(e.createPositionAt(o,"end"),i)}(n.writer,i,r),this._widgetsWithTypeAroundUI.add(r))},{priority:"low"})}_enableDetectionOfTypeAroundWidgets(){function e(e){return"ck-widget_can-type-around_"+e}this.editor.editing.view.document.registerPostFixer(t=>{for(const o of this._widgetsWithTypeAroundUI)if(o.isAttached()){const i=yh(o);t.removeClass(xh.map(e),o),t.addClass(i.map(e),o)}else this._widgetsWithTypeAroundUI.delete(o)})}_enableInsertingParagraphsOnButtonClick(){const e=this.editor.editing.view;e.document.on("mousedown",(t,o)=>{const i=o.domTarget.closest(".ck-widget__type-around__button");if(!i)return;const n=function(e){return e.classList.contains("ck-widget__type-around__button_before")?"before":"after"}(i),r=function(e,t){const o=e.closest(".ck-widget");return t.mapDomToView(o)}(i,e.domConverter);this._insertParagraph(r,n),o.preventDefault(),t.stop()})}}o(52);class Th extends Ml{static get pluginName(){return"Widget"}static get requires(){return[Ah]}init(){const e=this.editor.editing.view,t=e.document;this._previouslySelected=new Set,this.editor.editing.downcastDispatcher.on("selection",(e,t,o)=>{this._clearPreviouslySelectedWidgets(o.writer);const i=o.writer,n=i.document.selection,r=n.getSelectedElement();let s=null;for(const e of n.getRanges())for(const t of e){const e=t.item;rh(e)&&!Sh(e,s)&&(i.addClass("ck-widget_selected",e),this._previouslySelected.add(e),s=e,e==r&&i.setSelection(n.getRanges(),{fake:!0,label:ah(r)}))}},{priority:"low"}),e.addObserver(vh),this.listenTo(t,"mousedown",(...e)=>this._onMousedown(...e)),this.listenTo(t,"keydown",(...e)=>this._onKeydown(...e),{priority:"high"}),this.listenTo(t,"delete",(e,t)=>{this._handleDelete("forward"==t.direction)&&(t.preventDefault(),e.stop())},{priority:"high"})}_onMousedown(e,t){const o=this.editor,i=o.editing.view,n=i.document;let r=t.target;if(function(e){for(;e;){if(e.is("editableElement")&&!e.is("rootElement"))return!0;if(rh(e))return!1;e=e.parent}return!1}(r)){if(gn.isSafari&&t.domEvent.detail>=3){const e=o.editing.mapper.toModelElement(r);this.editor.model.change(o=>{t.preventDefault(),o.setSelection(e,"in")})}return}if(!rh(r)&&(r=r.findAncestor(rh),!r))return;t.preventDefault(),n.isFocused||i.focus();const s=o.editing.mapper.toModelElement(r);this._setSelectionOverElement(s)}_onKeydown(e,t){const o=t.keyCode,i="ltr"===this.editor.locale.contentLanguageDirection,n=o==pn.arrowdown||o==pn[i?"arrowright":"arrowleft"];let r=!1;!function(e){return e==pn.arrowright||e==pn.arrowleft||e==pn.arrowup||e==pn.arrowdown}(o)?o===pn.enter&&(r=this._handleEnterKey(t.shiftKey)):r=this._handleArrowKeys(n),r&&(t.preventDefault(),e.stop())}_handleDelete(e){if(this.editor.isReadOnly)return;const t=this.editor.model.document.selection;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}_handleArrowKeys(e){const t=this.editor.model,o=t.schema,i=t.document.selection,n=i.getSelectedElement();if(n&&o.isObject(n)){const n=e?i.getLastPosition():i.getFirstPosition(),r=o.getNearestSelectionRange(n,e?"forward":"backward");return r&&t.change(e=>{e.setSelection(r)}),!0}if(!i.isCollapsed)return;const r=this._getObjectElementNextToSelection(e);return r&&o.isObject(r)?(this._setSelectionOverElement(r),!0):void 0}_handleEnterKey(e){const t=this.editor.model,o=t.document.selection.getSelectedElement();if(i=o,n=t.schema,i&&n.isObject(i)&&!n.isInline(i))return t.change(i=>{let n=i.createPositionAt(o,e?"before":"after");const r=i.createElement("paragraph");if(t.schema.isBlock(o.parent)){const e=t.schema.findAllowedParent(n,r);n=i.split(n,e).position}i.insert(r,n),i.setSelection(r,"in")}),!0;var i,n}_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);t.modifySelection(n,{direction:e?"forward":"backward"});const r=e?n.focus.nodeBefore:n.focus.nodeAfter;return r&&o.isObject(r)?r:null}_clearPreviouslySelectedWidgets(e){for(const t of this._previouslySelected)e.removeClass("ck-widget_selected",t);this._previouslySelected.clear()}}function Sh(e,t){return!!t&&Array.from(e.getAncestors()).includes(t)}class Ph extends hd{refresh(){const e=this.editor.model.document.selection.getSelectedElement();this.isEnabled=gh(e),gh(e)&&e.hasAttribute("alt")?this.value=e.getAttribute("alt"):this.value=!1}execute(e){const t=this.editor.model,o=t.document.selection.getSelectedElement();t.change(t=>{t.setAttribute("alt",e.newValue,o)})}}class Eh extends Ml{static get pluginName(){return"ImageTextAlternativeEditing"}init(){this.editor.commands.add("imageTextAlternative",new Ph(this.editor))}}o(54);class Mh extends Zl{constructor(e){super(e),this.set("text"),this.set("for"),this.id="ck-editor__label_"+uo();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")}]})}}o(56);class Ih extends Zl{constructor(e,t){super(e);const o="ck-labeled-field-view-"+uo(),i="ck-labeled-field-view-status-"+uo();this.fieldView=t(this,o,i),this.set("label"),this.set("isEnabled",!0),this.set("errorText",null),this.set("infoText",null),this.set("class"),this.labelView=this._createLabelView(o),this.statusView=this._createStatusView(i),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)]},children:[this.labelView,this.fieldView,this.statusView]})}_createLabelView(e){const t=new Mh(this.locale);return t.for=e,t.bind("text").to(this,"label"),t}_createStatusView(e){const t=new Zl(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(){this.fieldView.focus()}}o(58);class Nh extends Zl{constructor(e){super(e),this.set("value"),this.set("id"),this.set("placeholder"),this.set("isReadOnly",!1),this.set("hasError",!1),this.set("ariaDescribedById");const t=this.bindTemplate;this.setTemplate({tag:"input",attributes:{type:"text",class:["ck","ck-input","ck-input-text",t.if("hasError","ck-error")],id:t.to("id"),placeholder:t.to("placeholder"),readonly:t.to("isReadOnly"),"aria-invalid":t.if("hasError",!0),"aria-describedby":t.to("ariaDescribedById")},on:{input:t.to("input")}})}render(){super.render();const e=e=>{this.element.value=e||0===e?e:""};e(this.value),this.on("change:value",(t,o,i)=>{e(i)})}select(){this.element.select()}focus(){this.element.focus()}}function Rh(e,t,o){const i=new Nh(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}),i}function Oh(e,t,o){const i=Nc(e.locale);return i.set({id:t,ariaDescribedById:o}),i.bind("isEnabled").to(e),i}function Vh({view:e}){e.listenTo(e.element,"submit",(t,o)=>{o.preventDefault(),e.fire("submit")},{useCapture:!0})}var Dh='',Lh='';o(60);class zh extends Zl{constructor(e){super(e);const t=this.locale.t;this.focusTracker=new gc,this.keystrokes=new Al,this.labeledInput=this._createLabeledInputView(),this.saveButtonView=this._createButton(t("Save"),Dh,"ck-button-save"),this.saveButtonView.type="submit",this.cancelButtonView=this._createButton(t("Cancel"),Lh,"ck-button-cancel","cancel"),this._focusables=new Nl,this._focusCycler=new wc({focusables:this._focusables,focusTracker:this.focusTracker,keystrokeHandler:this.keystrokes,actions:{focusPrevious:"shift + tab",focusNext:"tab"}}),this.setTemplate({tag:"form",attributes:{class:["ck","ck-text-alternative-form"],tabindex:"-1"},children:[this.labeledInput,this.saveButtonView,this.cancelButtonView]})}render(){super.render(),this.keystrokes.listenTo(this.element),Vh({view:this}),[this.labeledInput,this.saveButtonView,this.cancelButtonView].forEach(e=>{this._focusables.add(e),this.focusTracker.add(e.element)})}_createButton(e,t,o,i){const n=new hc(this.locale);return n.set({label:e,icon:t,tooltip:!0}),n.extendTemplate({attributes:{class:o}}),i&&n.delegate("execute").to(this,i),n}_createLabeledInputView(){const e=this.locale.t,t=new Ih(this.locale,Rh);return t.label=e("Text alternative"),t.fieldView.placeholder=e("Text alternative"),t}}function Bh(e){const t=e.editing.view,o=sc.defaultPositions;return{target:t.domConverter.viewToDom(t.document.selection.getSelectedElement()),positions:[o.northArrowSouth,o.northArrowSouthWest,o.northArrowSouthEast,o.southArrowNorth,o.southArrowNorthWest,o.southArrowNorthEast]}}class jh extends Ml{static get requires(){return[fc]}static get pluginName(){return"ImageTextAlternativeUI"}init(){this._createButton(),this._createForm()}destroy(){super.destroy(),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 hc(o);return n.set({label:t("Change image text alternative"),icon:'',tooltip:!0}),n.bind("isEnabled").to(i,"isEnabled"),this.listenTo(n,"execute",()=>{this._showForm()}),n})}_createForm(){const e=this.editor,t=e.editing.view.document;this._balloon=this.editor.plugins.get("ContextualBalloon"),this._form=new zh(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._form.keystrokes.set("Esc",(e,t)=>{this._hideForm(!0),t()}),this.listenTo(e.ui,"update",()=>{hh(t.selection)?this._isVisible&&function(e){const t=e.plugins.get("ContextualBalloon");if(hh(e.editing.view.document.selection)){const o=Bh(e);t.updatePosition(o)}}(e):this._hideForm(!0)}),Ic({emitter:this._form,activator:()=>this._isVisible,contextElements:[this._balloon.view.element],callback:()=>this._hideForm()})}_showForm(){if(this._isVisible)return;const e=this.editor,t=e.commands.get("imageTextAlternative"),o=this._form.labeledInput;this._isInBalloon||this._balloon.add({view:this._form,position:Bh(e)}),o.fieldView.value=o.fieldView.element.value=t.value||"",this._form.labeledInput.fieldView.select()}_hideForm(e){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.visibleView===this._form}get _isInBalloon(){return this._balloon.hasView(this._form)}}class Fh extends Ml{static get requires(){return[Eh,jh]}static get pluginName(){return"ImageTextAlternative"}}o(62);function Hh(e){for(const t of e.getChildren())if(t&&t.is("caption"))return t;return null}function Wh(e){const t=e.parent;return"figcaption"==e.name&&t&&"figure"==t.name&&t.hasClass("image")?{name:!0}:null}class Uh extends Ml{static get pluginName(){return"ImageCaptionEditing"}init(){const e=this.editor,t=e.editing.view,o=e.model.schema,i=e.data,n=e.editing,r=e.t;o.register("caption",{allowIn:"image",allowContentOf:"$block",isLimit:!0}),e.model.document.registerPostFixer(e=>this._insertMissingModelCaptionElement(e)),e.conversion.for("upcast").elementToElement({view:Wh,model:"caption"});i.downcastDispatcher.on("insert:caption",qh(e=>e.createContainerElement("figcaption"),!1));const s=function(e,t){return o=>{const i=o.createEditableElement("figcaption");return o.setCustomProperty("imageCaption",!0,i),Gc({view:e,element:i,text:t}),lh(i,o)}}(t,r("Enter image caption"));n.downcastDispatcher.on("insert:caption",qh(s)),n.downcastDispatcher.on("insert",this._fixCaptionVisibility(e=>e.item),{priority:"high"}),n.downcastDispatcher.on("remove",this._fixCaptionVisibility(e=>e.position.parent),{priority:"high"}),t.document.registerPostFixer(e=>this._updateCaptionVisibility(e))}_updateCaptionVisibility(e){const t=this.editor.editing.mapper,o=this._lastSelectedCaption;let i;const n=this.editor.model.document.selection,r=n.getSelectedElement();if(r&&r.is("image")){const e=Hh(r);i=t.toViewElement(e)}const s=Gh(n.getFirstPosition().parent);if(s&&(i=t.toViewElement(s)),i)return o?(o===i||($h(o,e),this._lastSelectedCaption=i),Yh(i,e)):(this._lastSelectedCaption=i,Yh(i,e));if(o){const t=$h(o,e);return this._lastSelectedCaption=null,t}return!1}_fixCaptionVisibility(e){return(t,o,i)=>{const n=Gh(e(o)),r=this.editor.editing.mapper,s=i.writer;if(n){const e=r.toViewElement(n);e&&(n.childCount?s.removeClass("ck-hidden",e):s.addClass("ck-hidden",e))}}}_insertMissingModelCaptionElement(e){const t=this.editor.model,o=t.document.differ.getChanges(),i=[];for(const e of o)if("insert"==e.type&&"$text"!=e.name){const o=e.position.nodeAfter;if(o.is("image")&&!Hh(o)&&i.push(o),!o.is("image")&&o.childCount)for(const e of t.createRangeIn(o).getItems())e.is("image")&&!Hh(e)&&i.push(e)}for(const t of i)e.appendElement("caption",t);return!!i.length}}function qh(e,t=!0){return(o,i,n)=>{const r=i.item;if((r.childCount||t)&&gh(r.parent)){if(!n.consumable.consume(i.item,"insert"))return;const t=n.mapper.toViewElement(i.range.start.parent),o=e(n.writer),s=n.writer;r.childCount||s.addClass("ck-hidden",o),function(e,t,o,i){const n=i.writer.createPositionAt(o,"end");i.writer.insert(n,e),i.mapper.bindElements(t,e)}(o,i.item,t,n)}}}function Gh(e){const t=e.getAncestors({includeSelf:!0}).find(e=>"caption"==e.name);return t&&t.parent&&"image"==t.parent.name?t:null}function $h(e,t){return!e.childCount&&!e.hasClass("ck-hidden")&&(t.addClass("ck-hidden",e),!0)}function Yh(e,t){return!!e.hasClass("ck-hidden")&&(t.removeClass("ck-hidden",e),!0)}o(64);class Kh extends hd{constructor(e,t){super(e),this.defaultStyle=!1,this.styles=t.reduce((e,t)=>(e[t.name]=t,t.isDefault&&(this.defaultStyle=t.name),e),{})}refresh(){const e=this.editor.model.document.selection.getSelectedElement();if(this.isEnabled=gh(e),e)if(e.hasAttribute("imageStyle")){const t=e.getAttribute("imageStyle");this.value=!!this.styles[t]&&t}else this.value=this.defaultStyle;else this.value=!1}execute(e){const t=e.value,o=this.editor.model,i=o.document.selection.getSelectedElement();o.change(e=>{this.styles[t].isDefault?e.removeAttribute("imageStyle",i):e.setAttribute("imageStyle",t,i)})}}function Qh(e,t){for(const o of t)if(o.name===e)return o}var Jh='',Zh='',Xh='',eg='';const tg={full:{name:"full",title:"Full size image",icon:Jh,isDefault:!0},side:{name:"side",title:"Side image",icon:eg,className:"image-style-side"},alignLeft:{name:"alignLeft",title:"Left aligned image",icon:Zh,className:"image-style-align-left"},alignCenter:{name:"alignCenter",title:"Centered image",icon:Xh,className:"image-style-align-center"},alignRight:{name:"alignRight",title:"Right aligned image",icon:eg,className:"image-style-align-right"}},og={full:Jh,left:Zh,right:eg,center:Xh};function ig(e=[]){return e.map(ng)}function ng(e){if("string"==typeof e){const t=e;tg[t]?e=Object.assign({},tg[t]):(console.warn(Object(go.a)("image-style-not-found: There is no such image style of given name."),{name:t}),e={name:t})}else if(tg[e.name]){const t=tg[e.name],o=Object.assign({},e);for(const i in t)e.hasOwnProperty(i)||(o[i]=t[i]);e=o}return"string"==typeof e.icon&&og[e.icon]&&(e.icon=og[e.icon]),e}class rg extends Ml{static get pluginName(){return"ImageStyleEditing"}init(){const e=this.editor,t=e.model.schema,o=e.data,i=e.editing;e.config.define("image.styles",["full","side"]);const n=ig(e.config.get("image.styles"));t.extend("image",{allowAttributes:"imageStyle"});const r=function(e){return(t,o,i)=>{if(!i.consumable.consume(o.item,t.name))return;const n=Qh(o.attributeNewValue,e),r=Qh(o.attributeOldValue,e),s=i.mapper.toViewElement(o.item),a=i.writer;r&&a.removeClass(r.className,s),n&&a.addClass(n.className,s)}}(n);i.downcastDispatcher.on("attribute:imageStyle:image",r),o.downcastDispatcher.on("attribute:imageStyle:image",r),o.upcastDispatcher.on("element:figure",function(e){const t=e.filter(e=>!e.isDefault);return(e,o,i)=>{if(!o.modelRange)return;const n=o.viewItem,r=Vu(o.modelRange.getItems());if(i.schema.checkAttribute(r,"imageStyle"))for(const e of t)i.consumable.consume(n,{classes:e.className})&&i.writer.setAttribute("imageStyle",e.name,r)}}(n),{priority:"low"}),e.commands.add("imageStyle",new Kh(e,n))}}o(66);class sg extends Ml{static get pluginName(){return"ImageStyleUI"}get localizedDefaultStylesTitles(){const e=this.editor.t;return{"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=function(e,t){for(const o of e)t[o.title]&&(o.title=t[o.title]);return e}(ig(this.editor.config.get("image.styles")),this.localizedDefaultStylesTitles);for(const t of e)this._createButton(t)}_createButton(e){const t=this.editor,o="imageStyle:"+e.name;t.ui.componentFactory.add(o,o=>{const i=t.commands.get("imageStyle"),n=new hc(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",t=>t===e.name),this.listenTo(n,"execute",()=>{t.execute("imageStyle",{value:e.name}),t.editing.view.focus()}),n})}}class ag extends Ml{static get requires(){return[fc]}static get pluginName(){return"WidgetToolbarRepository"}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||!rh(t))})(e.editing.view.document.selection)&&t.stop()},{priority:"high"})}this._toolbarDefinitions=new Map,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"}){const r=this.editor,s=r.t,a=new Oc(r.locale);if(a.ariaLabel=t||s("Widget toolbar"),this._toolbarDefinitions.has(e))throw new go.b("widget-toolbar-duplicated: Toolbar with the given id was already added.",this,{toolbarId:e});a.fillFromConfig(o,r.ui.componentFactory),this._toolbarDefinitions.set(e,{view:a,getRelatedElement:i,balloonClassName:n})}_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 r=n.getAncestors().length;r>e&&(e=r,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)?lg(this.editor,t):this._isToolbarInBalloon(e)||(this._balloon.add({view:e.view,position:cg(this.editor,t),balloonClassName:e.balloonClassName}),this.listenTo(this._balloon,"change:visibleView",()=>{for(const e of this._toolbarDefinitions.values())if(this._isToolbarVisible(e)){const t=e.getRelatedElement(this.editor.editing.view.document.selection);lg(this.editor,t)}}))}_isToolbarVisible(e){return this._balloon.visibleView===e.view}_isToolbarInBalloon(e){return this._balloon.hasView(e.view)}}function lg(e,t){const o=e.plugins.get("ContextualBalloon"),i=cg(e,t);o.updatePosition(i)}function cg(e,t){const o=e.editing.view,i=sc.defaultPositions;return{target:o.domConverter.mapViewToDom(t),positions:[i.northArrowSouth,i.northArrowSouthWest,i.northArrowSouthEast,i.southArrowNorth,i.southArrowNorthWest,i.southArrowNorthEast,dh]}}class dg extends Zl{constructor(e){super(e),this.buttonView=new hc(e),this._fileInputView=new ug(e),this._fileInputView.bind("acceptedType").to(this),this._fileInputView.bind("allowMultipleFiles").to(this),this._fileInputView.delegate("done").to(this),this.setTemplate({tag:"span",attributes:{class:"ck-file-dialog-button"},children:[this.buttonView,this._fileInputView]}),this.buttonView.on("execute",()=>{this._fileInputView.open()})}focus(){this.buttonView.focus()}}class ug extends Zl{constructor(e){super(e),this.set("acceptedType"),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&&this.element.files&&this.element.files.length&&this.fire("done",this.element.files),this.element.value=""})}})}open(){this.element.click()}}function hg(e){const t=e.map(e=>e.replace("+","\\+"));return new RegExp(`^image\\/(${t.join("|")})$`)}class gg extends Ml{init(){const e=this.editor,t=e.t;e.ui.componentFactory.add("imageUpload",o=>{const i=new dg(o),n=e.commands.get("imageUpload"),r=e.config.get("image.upload.types"),s=hg(r);return i.set({acceptedType:r.map(e=>"image/"+e).join(","),allowMultipleFiles:!0}),i.buttonView.set({label:t("Insert image"),icon:'',tooltip:!0}),i.buttonView.bind("isEnabled").to(n),i.on("done",(t,o)=>{const i=Array.from(o).filter(e=>s.test(e.type));i.length&&e.execute("imageUpload",{file:i})}),i})}}o(68),o(70),o(72);class mg extends Ml{constructor(e){super(e),this.placeholder="data:image/svg+xml;utf8,"+encodeURIComponent('')}init(){this.editor.editing.downcastDispatcher.on("attribute:uploadStatus:image",(...e)=>this.uploadStatusChange(...e))}uploadStatusChange(e,t,o){const i=this.editor,n=t.item,r=n.getAttribute("uploadId");if(!o.consumable.consume(t.item,e.name))return;const s=i.plugins.get(uu),a=r?t.attributeNewValue:null,l=this.placeholder,c=i.editing.mapper.toViewElement(n),d=o.writer;if("reading"==a)return fg(c,d),void pg(l,c,d);if("uploading"==a){const e=s.loaders.get(r);return fg(c,d),void(e?(bg(c,d),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)})})}(c,d,e,i.editing.view),function(e,t,o){if(o.data){const i=ph(e);t.setAttribute("src",o.data,i)}}(c,d,e)):pg(l,c,d))}"complete"==a&&s.loaders.get(r)&&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)}(c,d,i.editing.view),function(e,t){kg(e,t,"progressBar")}(c,d),bg(c,d),function(e,t){t.removeClass("ck-appear",e)}(c,d)}}function fg(e,t){e.hasClass("ck-appear")||t.addClass("ck-appear",e)}function pg(e,t,o){t.hasClass("ck-image-upload-placeholder")||o.addClass("ck-image-upload-placeholder",t);const i=ph(t);i.getAttribute("src")!==e&&o.setAttribute("src",e,i),wg(t,"placeholder")||o.insert(o.createPositionAfter(i),function(e){const t=e.createUIElement("div",{class:"ck-upload-placeholder-loader"});return e.setCustomProperty("placeholder",!0,t),t}(o))}function bg(e,t){e.hasClass("ck-image-upload-placeholder")&&t.removeClass("ck-image-upload-placeholder",e),kg(e,t,"placeholder")}function wg(e,t){for(const o of e.getChildren())if(o.getCustomProperty(t))return o}function kg(e,t,o){const i=wg(e,o);i&&t.remove(t.createRangeOn(i))}class _g extends lu{static get pluginName(){return"Notification"}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="show:"+e.type+(e.namespace?":"+e.namespace:"");this.fire(t,{message:e.message,type:e.type,title:e.title||""})}}class vg{constructor(e){this.document=e}createDocumentFragment(e){return new Cn(this.document,e)}createElement(e,t,o){return new Oi(this.document,e,t,o)}createText(e){return new Vo(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 Oi(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){y(e)&&void 0===o&&(o=t),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 Xi._createAt(e,t)}createPositionAfter(e){return Xi._createAfter(e)}createPositionBefore(e){return Xi._createBefore(e)}createRange(e,t){return new en(e,t)}createRangeOn(e){return en._createOn(e)}createRangeIn(e){return en._createIn(e)}createSelection(e,t,o){return new nn(e,t,o)}}class yg extends hd{refresh(){this.isEnabled=fh(this.editor.model)}execute(e){const t=this.editor,o=t.model,i=t.plugins.get(uu);o.change(t=>{const n=Array.isArray(e.file)?e.file:[e.file];for(const e of n)xg(t,o,i,e)})}}function xg(e,t,o,i){const n=o.createLoader(i);n&&mh(e,t,{uploadId:n.id})}class Cg extends Ml{static get requires(){return[uu,_g,ud]}static get pluginName(){return"ImageUploadEditing"}constructor(e){super(e),e.config.define("image",{upload:{types:["jpeg","png","gif","bmp","webp","tiff"]}})}init(){const e=this.editor,t=e.model.document,o=e.model.schema,i=e.conversion,n=e.plugins.get(uu),r=hg(e.config.get("image.upload.types"));o.extend("image",{allowAttributes:["uploadId","uploadStatus"]}),e.commands.add("imageUpload",new yg(e)),i.for("upcast").attributeToAttribute({view:{name:"img",key:"uploadId"},model:"uploadId"}),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)),s=o.targetRanges.map(t=>e.editing.mapper.toModelRange(t));e.model.change(o=>{o.setSelection(s),n.length&&(t.stop(),e.model.enqueueChange("default",()=>{e.execute("imageUpload",{file:n})}))})}),this.listenTo(e.plugins.get(ud),"inputTransformation",(t,o)=>{const i=Array.from(e.editing.view.createRangeIn(o.content)).filter(e=>{return!(!(t=e.item).is("element","img")||!t.getAttribute("src"))&&(t.getAttribute("src").match(/^data:image\/\w+;base64,/g)||t.getAttribute("src").match(/^blob:/g))&&!e.item.getAttribute("uploadProcessed");var t}).map(e=>{return{promise:(t=e.item,new Promise((e,o)=>{const i=t.getAttribute("src");fetch(i).then(e=>e.blob()).then(t=>{const o=function(e,t){return e.type?e.type:t.match(/data:(image\/\w+);base64/)?t.match(/data:(image\/\w+);base64/)[1].toLowerCase():"image/jpeg"}(t,i),n=o.replace("image/",""),r=new File([t],"image."+n,{type:o});e(r)}).catch(o)})),imageElement:e.item};var t});if(!i.length)return;const r=new vg(e.editing.view.document);for(const e of i){r.setAttribute("uploadProcessed",!0,e.imageElement);const t=n.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});for(const t of o)if("insert"==t.type&&"$text"!=t.name){const o=t.position.nodeAfter,i="$graveyard"==t.position.root.rootName;for(const t of Ag(e,o)){const e=t.getAttribute("uploadId");if(!e)continue;const o=n.loaders.get(e);o&&(i?o.abort():"idle"==o.status&&this._readAndUpload(o,t))}}})}_readAndUpload(e,t){const o=this.editor,i=o.model,n=o.locale.t,r=o.plugins.get(uu),s=o.plugins.get(_g);return i.enqueueChange("transparent",e=>{e.setAttribute("uploadStatus","reading",t)}),e.read().then(()=>{const n=e.upload();if(gn.isSafari){const e=ph(o.editing.mapper.toViewElement(t));o.editing.view.once("render",()=>{if(!e.parent)return;const t=o.editing.view.domConverter.mapViewToDom(e.parent);if(!t)return;const i=t.style.display;t.style.display="none",t._ckHack=t.offsetHeight,t.style.display=i})}return i.enqueueChange("transparent",e=>{e.setAttribute("uploadStatus","uploading",t)}),n}).then(e=>{i.enqueueChange("transparent",o=>{o.setAttributes({uploadStatus:"complete",src:e.default},t),this._parseAndSetSrcsetAttributeOnImage(e,t,o)}),a()}).catch(o=>{if("error"!==e.status&&"aborted"!==e.status)throw o;"error"==e.status&&o&&s.showWarning(o,{title:n("Upload failed"),namespace:"upload"}),a(),i.enqueueChange("transparent",e=>{e.remove(t)})});function a(){i.enqueueChange("transparent",e=>{e.removeAttribute("uploadId",t),e.removeAttribute("uploadStatus",t)}),r.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(", ");""!=n&&o.setAttribute("srcset",{data:n,width:i},t)}}function Ag(e,t){return Array.from(e.model.createRangeOn(t)).filter(e=>e.item.is("image")).map(e=>e.item)}class Tg{constructor(e){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}begin(e,t,o){const i=new Xr(t);this.activeHandlePosition=function(e){const t=["top-left","top-right","bottom-right","bottom-left"];for(const o of t)if(e.classList.contains("ck-widget__resizer__handle-"+o))return o}(e),this._referenceCoordinates=function(e,t){const o=new Xr(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){const o=e.parentElement,i=parseFloat(o.ownerDocument.defaultView.getComputedStyle(o).width);return t.width/i*100}(o,i)}update(e){this.proposedWidth=e.width,this.proposedHeight=e.height,this.proposedWidthPercents=e.widthPercents,this.proposedHandleHostWidth=e.handleHostWidth,this.proposedHandleHostHeight=e.handleHostHeight}}Co(Tg,Wi);class Sg{constructor(e){this._options=e,this._domResizerWrapper=null,this._viewResizerWrapper=null,this.set("isEnabled",!0),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"})}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),e._domResizerWrapper=o,e.on("change:isEnabled",(e,t,i)=>{o.style.display=i?"":"none"}),o.style.display=e.isEnabled?"":"none",o}));o.insert(o.createPositionAt(t,"end"),i),o.addClass("ck-widget_with-resizer",t),this._viewResizerWrapper=i})}begin(e){this.state=new Tg(this._options),this._sizeUI.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 Xr(o);t.handleHostWidth=Math.round(i.width),t.handleHostHeight=Math.round(i.height);const n=new Xr(o);t.width=Math.round(n.width),t.height=Math.round(n.height),this.redraw(i),this.state.update(t)}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;var o;(o=t)&&o.ownerDocument&&o.ownerDocument.contains(o)&&this._options.editor.editing.view.change(o=>{const i=t.parentElement,n=this._getHandleHost(),r=e||new Xr(n);o.setStyle("width",r.width+"px",this._viewResizerWrapper),o.setStyle("height",r.height+"px",this._viewResizerWrapper);const s=n.offsetLeft,a=n.offsetTop,l=n.offsetHeight,c=n.offsetWidth;i.isSameNode(n)||(o.setStyle("left",s+"px",this._viewResizerWrapper),o.setStyle("top",a+"px",this._viewResizerWrapper),o.setStyle("height",l+"px",this._viewResizerWrapper),o.setStyle("width",c+"px",this._viewResizerWrapper))})}containsHandle(e){return this._domResizerWrapper.contains(e)}static isResizeHandle(e){return e.classList.contains("ck-widget__resizer__handle")}_cleanup(){this._sizeUI.dismiss(),this._sizeUI.isVisible=!1;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),r={x:t._referenceCoordinates.x-(o.x+t.originalWidth),y:o.y-t.originalHeight-t._referenceCoordinates.y};n&&t.activeHandlePosition.endsWith("-right")&&(r.x=o.x-(t._referenceCoordinates.x+t.originalWidth)),n&&(r.x*=2);const s={width:Math.abs(t.originalWidth+r.x),height:Math.abs(t.originalHeight+r.y)};s.dominant=s.width/t.aspectRatio>s.height?"width":"height",s.max=s[s.dominant];const a={width:s.width,height:s.height};return"width"==s.dominant?a.height=a.width/t.aspectRatio:a.width=a.height*t.aspectRatio,{width:Math.round(a.width),height:Math.round(a.height),widthPercents:Math.min(Math.round(t.originalWidthPercents/t.originalWidth*a.width*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)}_appendHandles(e){const t=["top-left","top-right","bottom-right","bottom-left"];for(const i of t)e.appendChild(new Rl({tag:"div",attributes:{class:"ck-widget__resizer__handle "+(o=i,"ck-widget__resizer__handle-"+o)}}).render());var o}_appendSizeUI(e){const t=new Pg;t.render(),this._sizeUI=t,e.appendChild(t.element)}}Co(Sg,Wi);class Pg extends Zl{constructor(){super();const e=this.bindTemplate;this.setTemplate({tag:"div",attributes:{class:["ck","ck-size-view",e.to("activeHandlePosition",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("activeHandlePosition").to(t)}dismiss(){this.unbind(),this.isVisible=!1}}var Eg=function(e,t,o){var i=!0,n=!0;if("function"!=typeof e)throw new TypeError("Expected a function");return L(o)&&(i="leading"in o?!!o.leading:i,n="trailing"in o?!!o.trailing:n),Ur(e,t,{leading:i,maxWait:t,trailing:n})};o(74);class Mg extends Ml{static get pluginName(){return"WidgetResize"}init(){this.set("_visibleResizer",null),this.set("_activeResizer",null),this._resizers=new Map;const e=er.window.document;this.editor.model.schema.setAttributeProperties("width",{isFormatting:!0}),this._observer=Object.create(cr),this._observer.listenTo(e,"mousedown",this._mouseDownListener.bind(this)),this._observer.listenTo(e,"mousemove",this._mouseMoveListener.bind(this)),this._observer.listenTo(e,"mouseup",this._mouseUpListener.bind(this));const t=()=>{this._visibleResizer&&this._visibleResizer.redraw()},o=Eg(t,200);this.on("change:_visibleResizer",t),this.editor.ui.on("update",o),this._observer.listenTo(er.window,"resize",o);const i=this.editor.editing.view.document.selection;i.on("change",()=>{const e=i.getSelectedElement();this._visibleResizer=this._getResizerByViewElement(e)||null})}destroy(){this._observer.stopListening();for(const e of this._resizers.values())e.destroy()}attachTo(e){const t=new Sg(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"})}return this._resizers.set(e.viewElement,t),t}_getResizerByHandle(e){for(const t of this._resizers.values())if(t.containsHandle(e))return t}_getResizerByViewElement(e){return this._resizers.get(e)}_mouseDownListener(e,t){if(!Sg.isResizeHandle(t.target))return;const o=t.target;this._activeResizer=this._getResizerByHandle(o),this._activeResizer&&this._activeResizer.begin(o)}_mouseMoveListener(e,t){this._activeResizer&&this._activeResizer.updateSize(t)}_mouseUpListener(){this._activeResizer&&(this._activeResizer.commit(),this._activeResizer=null)}}Co(Mg,Wi);class Ig extends hd{refresh(){const e=this.editor.model.document.selection.getSelectedElement();this.isEnabled=gh(e),e&&e.hasAttribute("width")?this.value={width:e.getAttribute("width"),height:null}:this.value=null}execute(e){const t=this.editor.model,o=t.document.selection.getSelectedElement();t.change(t=>{t.setAttribute("width",e.width,o)})}}o(76);function Ng(e,t,o){return o.createRange(Rg(e,t,!0,o),Rg(e,t,!1,o))}function Rg(e,t,o,i){let n=e.textNode||(o?e.nodeBefore:e.nodeAfter),r=null;for(;n&&n.getAttribute("linkHref")==t;)r=n,n=o?n.previousSibling:n.nextSibling;return r?i.createPositionAt(r,o?"before":"after"):e}class Og extends hd{constructor(e){super(e),this.manualDecorators=new Ao}restoreManualDecoratorStates(){for(const e of this.manualDecorators)e.value=this._getDecoratorStateFromModel(e.id)}refresh(){const e=this.editor.model,t=e.document;this.value=t.selection.getAttribute("linkHref");for(const e of this.manualDecorators)e.value=this._getDecoratorStateFromModel(e.id);this.isEnabled=e.schema.checkAttributeInSelection(t.selection,"linkHref")}execute(e,t={}){const o=this.editor.model,i=o.document.selection,n=[],r=[];for(const e in t)t[e]?n.push(e):r.push(e);o.change(t=>{if(i.isCollapsed){const s=i.getFirstPosition();if(i.hasAttribute("linkHref")){const a=Ng(s,i.getAttribute("linkHref"),o);t.setAttribute("linkHref",e,a),n.forEach(e=>{t.setAttribute(e,!0,a)}),r.forEach(e=>{t.removeAttribute(e,a)}),t.setSelection(a)}else if(""!==e){const r=Lo(i.getAttributes());r.set("linkHref",e),n.forEach(e=>{r.set(e,!0)});const a=t.createText(e,r);o.insertContent(a,s),t.setSelection(t.createRangeOn(a))}}else{const s=o.schema.getValidRanges(i.getRanges(),"linkHref");for(const o of s)t.setAttribute("linkHref",e,o),n.forEach(e=>{t.setAttribute(e,!0,o)}),r.forEach(e=>{t.removeAttribute(e,o)})}})}_getDecoratorStateFromModel(e){return this.editor.model.document.selection.getAttribute(e)}}class Vg extends hd{refresh(){this.isEnabled=this.editor.model.document.selection.hasAttribute("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?[Ng(o.getFirstPosition(),o.getAttribute("linkHref"),t)]:o.getRanges();for(const t of n)if(e.removeAttribute("linkHref",t),i)for(const o of i.manualDecorators)e.removeAttribute(o.id,t)})}}var Dg=function(e,t,o){var i=e.length;return o=void 0===o?i:o,!t&&o>=i?e:ni(e,t,o)},Lg=RegExp("[\\u200d\\ud800-\\udfff\\u0300-\\u036f\\ufe20-\\ufe2f\\u20d0-\\u20ff\\ufe0e\\ufe0f]");var zg=function(e){return Lg.test(e)};var Bg=function(e){return e.split("")},jg="[\\ud800-\\udfff]",Fg="[\\u0300-\\u036f\\ufe20-\\ufe2f\\u20d0-\\u20ff]",Hg="\\ud83c[\\udffb-\\udfff]",Wg="[^\\ud800-\\udfff]",Ug="(?:\\ud83c[\\udde6-\\uddff]){2}",qg="[\\ud800-\\udbff][\\udc00-\\udfff]",Gg="(?:"+Fg+"|"+Hg+")"+"?",$g="[\\ufe0e\\ufe0f]?"+Gg+("(?:\\u200d(?:"+[Wg,Ug,qg].join("|")+")[\\ufe0e\\ufe0f]?"+Gg+")*"),Yg="(?:"+[Wg+Fg+"?",Fg,Ug,qg,jg].join("|")+")",Kg=RegExp(Hg+"(?="+Hg+")|"+Yg+$g,"g");var Qg=function(e){return e.match(Kg)||[]};var Jg=function(e){return zg(e)?Qg(e):Bg(e)};var Zg=function(e){return function(t){t=Xo(t);var o=zg(t)?Jg(t):void 0,i=o?o[0]:t.charAt(0),n=o?Dg(o,1).join(""):t.slice(1);return i[e]()+n}}("toUpperCase");const Xg=/[\u0000-\u0020\u00A0\u1680\u180E\u2000-\u2029\u205f\u3000]/g,em=/^(?:(?:https?|ftps?|mailto):|[^a-z]|[a-z+.-]+(?:[^a-z+.:-]|$))/i;function tm(e,t){const o=t.createAttributeElement("a",{href:e},{priority:5});return t.setCustomProperty("link",!0,o),o}function om(e){return function(e){return e.replace(Xg,"").match(em)}(e=String(e))?e:"#"}class im{constructor(){this._definitions=new Set}get length(){return this._definitions.size}add(e){Array.isArray(e)?e.forEach(e=>this._definitions.add(e)):this._definitions.add(e)}getDispatcher(){return e=>{e.on("attribute:linkHref",(e,t,o)=>{if(!o.consumable.test(t.item,"attribute:linkHref"))return;const i=o.writer,n=i.document.selection;for(const e of this._definitions){const r=i.createAttributeElement("a",e.attributes,{priority:5});i.setCustomProperty("link",!0,r),e.callback(t.attributeNewValue)?t.item.is("selection")?i.wrap(n.getFirstRange(),r):i.wrap(o.mapper.toViewRange(t.range),r):i.unwrap(o.mapper.toViewRange(t.range),r)}},{priority:"high"})}}}class nm{constructor({id:e,label:t,attributes:o,defaultValue:i}){this.id=e,this.set("value"),this.defaultValue=i,this.label=t,this.attributes=o}}Co(nm,Wi);class rm{constructor(e,t,o){this.model=e,this.attribute=o,this._modelSelection=e.document.selection,this._overrideUid=null,this._isNextGravityRestorationSkipped=!1,t.listenTo(this._modelSelection,"change:range",(e,t)=>{this._isNextGravityRestorationSkipped?this._isNextGravityRestorationSkipped=!1:this._isGravityOverridden&&(!t.directChange&&sm(this._modelSelection.getFirstPosition(),o)||this._restoreGravity())})}handleForwardMovement(e,t){const o=this.attribute;if(!(this._isGravityOverridden||e.isAtStart&&this._hasSelectionAttribute))return cm(e,o)&&this._hasSelectionAttribute?(this._preventCaretMovement(t),this._removeSelectionAttribute(),!0):am(e,o)||lm(e,o)&&this._hasSelectionAttribute?(this._preventCaretMovement(t),this._overrideGravity(),!0):void 0}handleBackwardMovement(e,t){const o=this.attribute;return this._isGravityOverridden?cm(e,o)&&this._hasSelectionAttribute?(this._preventCaretMovement(t),this._restoreGravity(),this._removeSelectionAttribute(),!0):(this._preventCaretMovement(t),this._restoreGravity(),e.isAtStart&&this._removeSelectionAttribute(),!0):cm(e,o)&&!this._hasSelectionAttribute?(this._preventCaretMovement(t),this._setSelectionAttributeFromTheNodeBefore(e),!0):e.isAtEnd&&lm(e,o)?this._hasSelectionAttribute?void(dm(e,o)&&(this._skipNextAutomaticGravityRestoration(),this._overrideGravity())):(this._preventCaretMovement(t),this._setSelectionAttributeFromTheNodeBefore(e),!0):e.isAtStart?this._hasSelectionAttribute?(this._removeSelectionAttribute(),this._preventCaretMovement(t),!0):void 0:void(dm(e,o)&&(this._skipNextAutomaticGravityRestoration(),this._overrideGravity()))}get _isGravityOverridden(){return!!this._overrideUid}get _hasSelectionAttribute(){return this._modelSelection.hasAttribute(this.attribute)}_overrideGravity(){this._overrideUid=this.model.change(e=>e.overrideSelectionGravity())}_restoreGravity(){this.model.change(e=>{e.restoreSelectionGravity(this._overrideUid),this._overrideUid=null})}_preventCaretMovement(e){e.preventDefault()}_removeSelectionAttribute(){this.model.change(e=>{e.removeSelectionAttribute(this.attribute)})}_setSelectionAttributeFromTheNodeBefore(e){const t=this.attribute;this.model.change(o=>{o.setSelectionAttribute(this.attribute,e.nodeBefore.getAttribute(t))})}_skipNextAutomaticGravityRestoration(){this._isNextGravityRestorationSkipped=!0}}function sm(e,t){return am(e,t)||lm(e,t)}function am(e,t){const{nodeBefore:o,nodeAfter:i}=e,n=!!o&&o.hasAttribute(t);return!!i&&i.hasAttribute(t)&&(!n||o.getAttribute(t)!==i.getAttribute(t))}function lm(e,t){const{nodeBefore:o,nodeAfter:i}=e,n=!!o&&o.hasAttribute(t),r=!!i&&i.hasAttribute(t);return n&&(!r||o.getAttribute(t)!==i.getAttribute(t))}function cm(e,t){const{nodeBefore:o,nodeAfter:i}=e,n=!!o&&o.hasAttribute(t);if(!!i&&i.hasAttribute(t)&&n)return i.getAttribute(t)!==o.getAttribute(t)}function dm(e,t){return sm(e.getShiftedBy(-1),t)}o(78);const um=/^(https?:)?\/\//;class hm extends Ml{static get pluginName(){return"LinkEditing"}constructor(e){super(e),e.config.define("link",{addTargetToExternalLinks:!1})}init(){const e=this.editor,t=e.locale;e.model.schema.extend("$text",{allowAttributes:"linkHref"}),e.conversion.for("dataDowncast").attributeToElement({model:"linkHref",view:tm}),e.conversion.for("editingDowncast").attributeToElement({model:"linkHref",view:(e,t)=>tm(om(e),t)}),e.conversion.for("upcast").elementToAttribute({view:{name:"a",attributes:{href:!0}},model:{key:"linkHref",value:e=>e.getAttribute("href")}}),e.commands.add("link",new Og(e)),e.commands.add("unlink",new Vg(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=>(e.label&&o[e.label]&&(e.label=o[e.label]),e)),t}(e.t,function(e){const t=[];if(e)for(const[o,i]of Object.entries(e)){const e=Object.assign({},i,{id:"link"+Zg(o)});t.push(e)}return t}(e.config.get("link.decorators")));this._enableAutomaticDecorators(o.filter(e=>"automatic"===e.mode)),this._enableManualDecorators(o.filter(e=>"manual"===e.mode)),function({view:e,model:t,emitter:o,attribute:i,locale:n}){const r=new rm(t,o,i),s=t.document.selection;o.listenTo(e.document,"keydown",(e,t)=>{if(!s.isCollapsed)return;if(t.shiftKey||t.altKey||t.ctrlKey)return;const o=t.keyCode==pn.arrowright,i=t.keyCode==pn.arrowleft;if(!o&&!i)return;const a=s.getFirstPosition(),l=n.contentLanguageDirection;let c;c="ltr"===l&&o||"rtl"===l&&i?r.handleForwardMovement(a,t):r.handleBackwardMovement(a,t),c&&e.stop()},{priority:ho.get("high")+1})}({view:e.editing.view,model:e.model,emitter:this,attribute:"linkHref",locale:t}),this._setupLinkHighlight(),this._enableInsertContentSelectionAttributesFixer()}_enableAutomaticDecorators(e){const t=this.editor,o=new im;t.config.get("link.addTargetToExternalLinks")&&o.add({id:"linkIsExternal",mode:"automatic",callback:e=>um.test(e),attributes:{target:"_blank",rel:"noopener noreferrer"}}),o.add(e),o.length&&t.conversion.for("downcast").add(o.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}),o.add(new nm(e)),t.conversion.for("downcast").attributeToElement({model:e.id,view:(t,i)=>{if(t){const t=o.get(e.id).attributes,n=i.createAttributeElement("a",t,{priority:5});return i.setCustomProperty("link",!0,n),n}}}),t.conversion.for("upcast").elementToAttribute({view:{name:"a",attributes:o.get(e.id).attributes},model:{key:e.id}})})}_setupLinkHighlight(){const e=this.editor,t=e.editing.view,o=new Set;t.document.registerPostFixer(t=>{const i=e.model.document.selection;let n=!1;if(i.hasAttribute("linkHref")){const r=Ng(i.getFirstPosition(),i.getAttribute("linkHref"),e.model),s=e.editing.mapper.toViewRange(r);for(const e of s.getItems())e.is("a")&&!e.hasClass("ck-link_selected")&&(t.addClass("ck-link_selected",e),o.add(e),n=!0)}return n}),e.conversion.for("editingDowncast").add(e=>{function i(){t.change(e=>{for(const t of o.values())e.removeClass("ck-link_selected",t),o.delete(t)})}e.on("insert",i,{priority:"highest"}),e.on("remove",i,{priority:"highest"}),e.on("attribute",i,{priority:"highest"}),e.on("selection",i,{priority:"highest"})})}_enableInsertContentSelectionAttributesFixer(){const e=this.editor.model,t=e.document.selection;e.on("insertContent",()=>{const o=t.anchor.nodeBefore,i=t.anchor.nodeAfter;t.hasAttribute("linkHref")&&o&&o.hasAttribute("linkHref")&&(i&&i.hasAttribute("linkHref")||e.change(t=>{[...e.document.selection.getAttributeKeys()].filter(e=>e.startsWith("link")).forEach(e=>t.removeSelectionAttribute(e))}))},{priority:"low"})}}class gm extends Rr{constructor(e){super(e),this.domEventType="click"}onDomEvent(e){this.fire(e.type,e)}}o(80);class mm extends Zl{constructor(e,t){super(e);const o=e.t;this.focusTracker=new gc,this.keystrokes=new Al,this.urlInputView=this._createUrlInput(),this.saveButtonView=this._createButton(o("Save"),Dh,"ck-button-save"),this.saveButtonView.type="submit",this.cancelButtonView=this._createButton(o("Cancel"),Lh,"ck-button-cancel","cancel"),this._manualDecoratorSwitches=this._createManualDecoratorSwitches(t),this.children=this._createFormChildren(t.manualDecorators),this._focusables=new Nl,this._focusCycler=new wc({focusables:this._focusables,focusTracker:this.focusTracker,keystrokeHandler:this.keystrokes,actions:{focusPrevious:"shift + tab",focusNext:"tab"}});const i=["ck","ck-link-form"];t.manualDecorators.length&&i.push("ck-link-form_layout-vertical"),this.setTemplate({tag:"form",attributes:{class:i,tabindex:"-1"},children:this.children})}getDecoratorSwitchesState(){return Array.from(this._manualDecoratorSwitches).reduce((e,t)=>(e[t.name]=t.isOn,e),{})}render(){super.render(),Vh({view:this});[this.urlInputView,...this._manualDecoratorSwitches,this.saveButtonView,this.cancelButtonView].forEach(e=>{this._focusables.add(e),this.focusTracker.add(e.element)}),this.keystrokes.listenTo(this.element)}focus(){this._focusCycler.focusFirst()}_createUrlInput(){const e=this.locale.t,t=new Ih(this.locale,Rh);return t.label=e("Link URL"),t.fieldView.placeholder="https://example.com",t}_createButton(e,t,o,i){const n=new hc(this.locale);return n.set({label:e,icon:t,tooltip:!0}),n.extendTemplate({attributes:{class:o}}),i&&n.delegate("execute").to(this,i),n}_createManualDecoratorSwitches(e){const t=this.createCollection();for(const o of e.manualDecorators){const i=new Mc(this.locale);i.set({name:o.id,label:o.label,withText:!0}),i.bind("isOn").toMany([o,e],"value",(e,t)=>void 0===t&&void 0===e?o.defaultValue:e),i.on("execute",()=>{o.set("value",!i.isOn)}),t.add(i)}return t}_createFormChildren(e){const t=this.createCollection();if(t.add(this.urlInputView),e.length){const e=new Zl;e.setTemplate({tag:"ul",children:this._manualDecoratorSwitches.map(e=>({tag:"li",children:[e],attributes:{class:["ck","ck-list__item"]}})),attributes:{class:["ck","ck-reset","ck-list"]}}),t.add(e)}return t.add(this.saveButtonView),t.add(this.cancelButtonView),t}}o(82);class fm extends Zl{constructor(e){super(e);const t=e.t;this.focusTracker=new gc,this.keystrokes=new Al,this.previewButtonView=this._createPreviewButton(),this.unlinkButtonView=this._createButton(t("Unlink"),'',"unlink"),this.editButtonView=this._createButton(t("Edit link"),'',"edit"),this.set("href"),this._focusables=new Nl,this._focusCycler=new wc({focusables:this._focusables,focusTracker:this.focusTracker,keystrokeHandler:this.keystrokes,actions:{focusPrevious:"shift + tab",focusNext:"tab"}}),this.setTemplate({tag:"div",attributes:{class:["ck","ck-link-actions"],tabindex:"-1"},children:[this.previewButtonView,this.editButtonView,this.unlinkButtonView]})}render(){super.render();[this.previewButtonView,this.editButtonView,this.unlinkButtonView].forEach(e=>{this._focusables.add(e),this.focusTracker.add(e.element)}),this.keystrokes.listenTo(this.element)}focus(){this._focusCycler.focusFirst()}_createButton(e,t,o){const i=new hc(this.locale);return i.set({label:e,icon:t,tooltip:!0}),i.delegate("execute").to(this,o),i}_createPreviewButton(){const e=new hc(this.locale),t=this.bindTemplate,o=this.t;return e.set({withText:!0,tooltip:o("Open link in new tab")}),e.extendTemplate({attributes:{class:["ck","ck-link-actions__preview"],href:t.to("href",e=>e&&om(e)),target:"_blank",rel:"noopener noreferrer"}}),e.bind("label").to(this,"href",e=>e||o("This link has no URL")),e.bind("isEnabled").to(this,"href",e=>!!e),e.template.tag="a",e.template.eventListeners={},e}}class pm extends Ml{static get requires(){return[fc]}static get pluginName(){return"LinkUI"}init(){const e=this.editor;e.editing.view.addObserver(gm),this.actionsView=this._createActionsView(),this.formView=this._createFormView(),this._balloon=e.plugins.get(fc),this._createToolbarLinkButton(),this._enableUserBalloonInteractions()}destroy(){super.destroy(),this.formView.destroy()}_createActionsView(){const e=this.editor,t=new fm(e.locale),o=e.commands.get("link"),i=e.commands.get("unlink");return t.bind("href").to(o,"value"),t.editButtonView.bind("isEnabled").to(o),t.unlinkButtonView.bind("isEnabled").to(i),this.listenTo(t,"edit",()=>{this._addFormView()}),this.listenTo(t,"unlink",()=>{e.execute("unlink"),this._hideUI()}),t.keystrokes.set("Esc",(e,t)=>{this._hideUI(),t()}),t.keystrokes.set("Ctrl+K",(e,t)=>{this._addFormView(),t()}),t}_createFormView(){const e=this.editor,t=e.commands.get("link"),o=new mm(e.locale,t);return o.urlInputView.fieldView.bind("value").to(t,"value"),o.urlInputView.bind("isReadOnly").to(t,"isEnabled",e=>!e),o.saveButtonView.bind("isEnabled").to(t),this.listenTo(o,"submit",()=>{e.execute("link",o.urlInputView.fieldView.element.value,o.getDecoratorSwitchesState()),this._closeFormView()}),this.listenTo(o,"cancel",()=>{this._closeFormView()}),o.keystrokes.set("Esc",(e,t)=>{this._closeFormView(),t()}),o}_createToolbarLinkButton(){const e=this.editor,t=e.commands.get("link"),o=e.t;e.keystrokes.set("Ctrl+K",(e,t)=>{t(),this._showUI(!0)}),e.ui.componentFactory.add("link",e=>{const i=new hc(e);return i.isEnabled=!0,i.label=o("Link"),i.icon='',i.keystroke="Ctrl+K",i.tooltip=!0,i.isToggleable=!0,i.bind("isEnabled").to(t,"isEnabled"),i.bind("isOn").to(t,"value",e=>!!e),this.listenTo(i,"execute",()=>this._showUI(!0)),i})}_enableUserBalloonInteractions(){const e=this.editor.editing.view.document;this.listenTo(e,"click",()=>{this._getSelectedLinkElement()&&this._showUI()}),this.editor.keystrokes.set("Tab",(e,t)=>{this._areActionsVisible&&!this.actionsView.focusTracker.isFocused&&(this.actionsView.focus(),t())},{priority:"high"}),this.editor.keystrokes.set("Esc",(e,t)=>{this._isUIVisible&&(this._hideUI(),t())}),Ic({emitter:this.formView,activator:()=>this._isUIInPanel,contextElements:[this._balloon.view.element],callback:()=>this._hideUI()})}_addActionsView(){this._areActionsInPanel||this._balloon.add({view:this.actionsView,position:this._getBalloonPositionData()})}_addFormView(){if(this._isFormInPanel)return;const e=this.editor.commands.get("link");this._balloon.add({view:this.formView,position:this._getBalloonPositionData()}),this._balloon.visibleView===this.formView&&this.formView.urlInputView.fieldView.select(),this.formView.urlInputView.fieldView.element.value=e.value||""}_closeFormView(){const e=this.editor.commands.get("link");e.restoreManualDecoratorStates(),void 0!==e.value?this._removeFormView():this._hideUI()}_removeFormView(){this._isFormInPanel&&(this.formView.saveButtonView.focus(),this._balloon.remove(this.formView),this.editor.editing.view.focus())}_showUI(e=!1){this._getSelectedLinkElement()?(this._areActionsVisible?this._addFormView():this._addActionsView(),e&&this._balloon.showStack("main")):(this._addActionsView(),e&&this._balloon.showStack("main"),this._addFormView()),this._startUpdatingUI()}_hideUI(){if(!this._isUIInPanel)return;const e=this.editor;this.stopListening(e.ui,"update"),this.stopListening(this._balloon,"change:visibleView"),e.editing.view.focus(),this._removeFormView(),this._balloon.remove(this.actionsView)}_startUpdatingUI(){const e=this.editor,t=e.editing.view.document;let o=this._getSelectedLinkElement(),i=r();const n=()=>{const e=this._getSelectedLinkElement(),t=r();o&&!e||!o&&t!==i?this._hideUI():this._isUIVisible&&this._balloon.updatePosition(this._getBalloonPositionData()),o=e,i=t};function r(){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 _isFormInPanel(){return this._balloon.hasView(this.formView)}get _areActionsInPanel(){return this._balloon.hasView(this.actionsView)}get _areActionsVisible(){return this._balloon.visibleView===this.actionsView}get _isUIInPanel(){return this._isFormInPanel||this._areActionsInPanel}get _isUIVisible(){return this._balloon.visibleView==this.formView||this._areActionsVisible}_getBalloonPositionData(){const e=this.editor.editing.view,t=e.document,o=this._getSelectedLinkElement();return{target:o?e.domConverter.mapViewToDom(o):e.domConverter.viewRangeToDom(t.selection.getFirstRange())}}_getSelectedLinkElement(){const e=this.editor.editing.view,t=e.document.selection;if(t.isCollapsed)return bm(t.getFirstPosition());{const o=t.getFirstRange().getTrimmed(),i=bm(o.start),n=bm(o.end);return i&&i==n&&e.createRangeIn(i).getTrimmed().isEqual(o)?i:null}}}function bm(e){return e.getAncestors().find(e=>{return(t=e).is("attributeElement")&&!!t.getCustomProperty("link");var t})}class wm extends hd{constructor(e,t){super(e),this.type=t}refresh(){this.value=this._getValue(),this.isEnabled=this._checkEnabled()}execute(){const e=this.editor.model,t=e.document,o=Array.from(t.selection.getSelectedBlocks()).filter(t=>_m(t,e.schema)),i=!0===this.value;e.change(e=>{if(i){let t=o[o.length-1].nextSibling,i=Number.POSITIVE_INFINITY,n=[];for(;t&&"listItem"==t.name&&0!==t.getAttribute("listIndent");){const e=t.getAttribute("listIndent");e=o;)r>n.getAttribute("listIndent")&&(r=n.getAttribute("listIndent")),n.getAttribute("listIndent")==r&&e[t?"unshift":"push"](n),n=n[t?"previousSibling":"nextSibling"]}}function _m(e,t){return t.checkChild(e.parent,"listItem")&&!t.isObject(e)}class vm extends hd{constructor(e,t){super(e),this._indentBy="forward"==t?1:-1}refresh(){this.isEnabled=this._checkEnabled()}execute(){const e=this.editor.model,t=e.document;let o=Array.from(t.selection.getSelectedBlocks());e.change(e=>{const t=o[o.length-1];let i=t.nextSibling;for(;i&&"listItem"==i.name&&i.getAttribute("listIndent")>t.getAttribute("listIndent");)o.push(i),i=i.nextSibling;this._indentBy<0&&(o=o.reverse());for(const t of o){const o=t.getAttribute("listIndent")+this._indentBy;o<0?e.rename(t,"paragraph"):e.setAttribute("listIndent",o,t)}})}_checkEnabled(){const e=Vu(this.editor.model.document.selection.getSelectedBlocks());if(!e||!e.is("listItem"))return!1;if(this._indentBy>0){const t=e.getAttribute("listIndent"),o=e.getAttribute("listType");let i=e.previousSibling;for(;i&&i.is("listItem")&&i.getAttribute("listIndent")>=t;){if(i.getAttribute("listIndent")==t)return i.getAttribute("listType")==o;i=i.previousSibling}return!1}return!0}}function ym(e,t){const o=t.mapper,i=t.writer,n="numbered"==e.getAttribute("listType")?"ol":"ul",r=function(e){const t=e.createContainerElement("li");return t.getFillerOffset=Pm,t}(i),s=i.createContainerElement(n,null);return i.insert(i.createPositionAt(s,0),r),o.bindElements(e,r),r}function xm(e,t,o,i){const n=t.parent,r=o.mapper,s=o.writer;let a=r.toViewPosition(i.createPositionBefore(e));const l=Tm(e.previousSibling,{sameIndent:!0,smallerIndent:!0,listIndent:e.getAttribute("listIndent")}),c=e.previousSibling;if(l&&l.getAttribute("listIndent")==e.getAttribute("listIndent")){const e=r.toViewElement(l);a=s.breakContainer(s.createPositionAfter(e))}else a=c&&"listItem"==c.name?r.toViewPosition(i.createPositionAt(c,"end")):r.toViewPosition(i.createPositionBefore(e));if(a=Am(a),s.insert(a,n),c&&"listItem"==c.name){const e=r.toViewElement(c),o=s.createRange(s.createPositionAt(e,0),a).getWalker({ignoreElementEnd:!0});for(const e of o)if(e.item.is("li")){const i=s.breakContainer(s.createPositionBefore(e.item)),n=e.item.parent,r=s.createPositionAt(t,"end");Cm(s,r.nodeBefore,r.nodeAfter),s.move(s.createRangeOn(n),r),o.position=i}}else{const o=n.nextSibling;if(o&&(o.is("ul")||o.is("ol"))){let i=null;for(const t of o.getChildren()){const o=r.toModelElement(t);if(!(o&&o.getAttribute("listIndent")>e.getAttribute("listIndent")))break;i=t}i&&(s.breakContainer(s.createPositionAfter(i)),s.move(s.createRangeOn(i.parent),s.createPositionAt(t,"end")))}}Cm(s,n,n.nextSibling),Cm(s,n.previousSibling,n)}function Cm(e,t,o){return!t||!o||"ul"!=t.name&&"ol"!=t.name||t.name!=o.name||t.getAttribute("class")!==o.getAttribute("class")?null:e.mergeContainers(e.createPositionAfter(t))}function Am(e){return e.getLastMatchingPosition(e=>e.item.is("uiElement"))}function Tm(e,t){const o=!!t.sameIndent,i=!!t.smallerIndent,n=t.listIndent;let r=e;for(;r&&"listItem"==r.name;){const e=r.getAttribute("listIndent");if(o&&n==e||i&&n>e)return r;r=r.previousSibling}return null}function Sm(e,t,o,i){e.ui.componentFactory.add(t,n=>{const r=e.commands.get(t),s=new hc(n);return s.set({label:o,icon:i,tooltip:!0,isToggleable:!0}),s.bind("isOn","isEnabled").to(r,"value","isEnabled"),s.on("execute",()=>{e.execute(t),e.editing.view.focus()}),s})}function Pm(){const e=!this.isEmpty&&("ul"==this.getChild(0).name||"ol"==this.getChild(0).name);return this.isEmpty||e?0:Li.call(this)}function Em(e){return(t,o,i)=>{const n=i.consumable;if(!n.test(o.item,"insert")||!n.test(o.item,"attribute:listType")||!n.test(o.item,"attribute:listIndent"))return;n.consume(o.item,"insert"),n.consume(o.item,"attribute:listType"),n.consume(o.item,"attribute:listIndent");const r=o.item;xm(r,ym(r,i),i,e)}}function Mm(e,t,o){if(!o.consumable.consume(t.item,"attribute:listType"))return;const i=o.mapper.toViewElement(t.item),n=o.writer;n.breakContainer(n.createPositionBefore(i)),n.breakContainer(n.createPositionAfter(i));const r=i.parent,s="numbered"==t.attributeNewValue?"ol":"ul";n.rename(s,r)}function Im(e,t,o){const i=o.mapper.toViewElement(t.item).parent,n=o.writer;Cm(n,i,i.nextSibling),Cm(n,i.previousSibling,i);for(const e of t.item.getChildren())o.consumable.consume(e,"insert")}function Nm(e,t,o){if("listItem"!=t.item.name){let e=o.mapper.toViewPosition(t.range.start);const i=o.writer,n=[];for(;("ul"==e.parent.name||"ol"==e.parent.name)&&(e=i.breakContainer(e),"li"==e.parent.name);){const t=e,o=i.createPositionAt(e.parent,"end");if(!t.isEqual(o)){const e=i.remove(i.createRange(t,o));n.push(e)}e=i.createPositionAfter(e.parent)}if(n.length>0){for(let t=0;t0){const t=Cm(i,o,o.nextSibling);t&&t.parent==o&&e.offset--}}Cm(i,e.nodeBefore,e.nodeAfter)}}}function Rm(e,t,o){const i=o.mapper.toViewPosition(t.position),n=i.nodeBefore,r=i.nodeAfter;Cm(o.writer,n,r)}function Om(e,t,o){if(o.consumable.consume(t.viewItem,{name:!0})){const e=o.writer,i=e.createElement("listItem"),n=function(e){let t=0,o=e.parent;for(;o;){if(o.is("li"))t++;else{const e=o.previousSibling;e&&e.is("li")&&t++}o=o.parent}return t}(t.viewItem);e.setAttribute("listIndent",n,i);const r=t.viewItem.parent&&"ol"==t.viewItem.parent.name?"numbered":"bulleted";e.setAttribute("listType",r,i);const s=o.splitToAllowedParent(i,t.modelCursor);if(!s)return;e.insert(i,s.position);const a=function(e,t,o){const{writer:i,schema:n}=o;let r=i.createPositionAfter(e);for(const s of t)if("ul"==s.name||"ol"==s.name)r=o.convertItem(s,r).modelCursor;else{const t=o.convertItem(s,i.createPositionAt(e,"end")),a=t.modelRange.start.nodeAfter;a&&a.is("element")&&!n.checkChild(e,a.name)&&(e=t.modelCursor.parent.is("listItem")?t.modelCursor.parent:Bm(t.modelCursor),r=i.createPositionAfter(e))}return r}(i,t.viewItem.getChildren(),o);t.modelRange=e.createRange(t.modelCursor,a),s.cursorParent?t.modelCursor=e.createPositionAt(s.cursorParent,0):t.modelCursor=t.modelRange.end}}function Vm(e,t,o){if(o.consumable.test(t.viewItem,{name:!0})){const e=Array.from(t.viewItem.getChildren());for(const t of e){!(t.is("li")||Fm(t))&&t._remove()}}}function Dm(e,t,o){if(o.consumable.test(t.viewItem,{name:!0})){if(0===t.viewItem.childCount)return;const e=[...t.viewItem.getChildren()];let o=!1,i=!0;for(const t of e)o&&!Fm(t)&&t._remove(),t.is("text")?(i&&(t._data=t.data.replace(/^\s+/,"")),t.nextSibling&&!Fm(t.nextSibling)||(t._data=t.data.replace(/\s+$/,""))):Fm(t)&&(o=!0),i=!1}}function Lm(e){return(t,o)=>{if(o.isPhantom)return;const i=o.modelPosition.nodeBefore;if(i&&i.is("listItem")){const t=o.mapper.toViewElement(i),n=t.getAncestors().find(Fm),r=e.createPositionAt(t,0).getWalker();for(const e of r){if("elementStart"==e.type&&e.item.is("li")){o.viewPosition=e.previousPosition;break}if("elementEnd"==e.type&&e.item==n){o.viewPosition=e.nextPosition;break}}}}}function zm(e,[t,o]){let i,n=t.is("documentFragment")?t.getChild(0):t;if(i=o?this.createSelection(o):this.document.selection,n&&n.is("listItem")){const e=i.getFirstPosition();let t=null;if(e.parent.is("listItem")?t=e.parent:e.nodeBefore&&e.nodeBefore.is("listItem")&&(t=e.nodeBefore),t){const e=t.getAttribute("listIndent");if(e>0)for(;n&&n.is("listItem");)n._setAttribute("listIndent",n.getAttribute("listIndent")+e),n=n.nextSibling}}}function Bm(e){const t=new ws({startPosition:e});let o;do{o=t.next()}while(!o.value.item.is("listItem"));return o.value.item}function jm(e,t,o,i,n,r){const s=Tm(t.nodeBefore,{sameIndent:!0,smallerIndent:!0,listIndent:e,foo:"b"}),a=n.mapper,l=n.writer,c=s?s.getAttribute("listIndent"):null;let d;if(s)if(c==e){const e=a.toViewElement(s).parent;d=l.createPositionAfter(e)}else{const e=r.createPositionAt(s,"end");d=a.toViewPosition(e)}else d=o;d=Am(d);for(const e of[...i.getChildren()])Fm(e)&&(d=l.move(l.createRangeOn(e),d).end,Cm(l,e,e.nextSibling),Cm(l,e.previousSibling,e))}function Fm(e){return e.is("ol")||e.is("ul")}class Hm extends Ml{static get pluginName(){return"ListEditing"}static get requires(){return[qu]}init(){const e=this.editor;e.model.schema.register("listItem",{inheritAllFrom:"$block",allowAttributes:["listType","listIndent"]});const t=e.data,o=e.editing;var i;e.model.document.registerPostFixer(t=>function(e,t){const o=e.document.differ.getChanges(),i=new Map;let n=!1;for(const i of o)if("insert"==i.type&&"listItem"==i.name)r(i.position);else if("insert"==i.type&&"listItem"!=i.name){if("$text"!=i.name){const o=i.position.nodeAfter;o.hasAttribute("listIndent")&&(t.removeAttribute("listIndent",o),n=!0),o.hasAttribute("listType")&&(t.removeAttribute("listType",o),n=!0);for(const t of Array.from(e.createRangeIn(o)).filter(e=>e.item.is("listItem")))r(t.previousPosition)}r(i.position.getShiftedBy(i.length))}else"remove"==i.type&&"listItem"==i.name?r(i.position):("attribute"==i.type&&"listIndent"==i.attributeKey||"attribute"==i.type&&"listType"==i.attributeKey)&&r(i.range.start);for(const e of i.values())s(e),a(e);return n;function r(e){const t=e.nodeBefore;if(t&&t.is("listItem")){let e=t;if(i.has(e))return;for(let t=e.previousSibling;t&&t.is("listItem");t=e.previousSibling)if(e=t,i.has(e))return;i.set(t,e)}else{const t=e.nodeAfter;t&&t.is("listItem")&&i.set(t,t)}}function s(e){let o=0,i=null;for(;e&&e.is("listItem");){const r=e.getAttribute("listIndent");if(r>o){let s;null===i?(i=r-o,s=o):(i>r&&(i=r),s=r-i),t.setAttribute("listIndent",s,e),n=!0}else i=null,o=e.getAttribute("listIndent")+1;e=e.nextSibling}}function a(e){let o=[],i=null;for(;e&&e.is("listItem");){const r=e.getAttribute("listIndent");if(i&&i.getAttribute("listIndent")>r&&(o=o.slice(0,r+1)),0!=r)if(o[r]){const i=o[r];e.getAttribute("listType")!=i&&(t.setAttribute("listType",i,e),n=!0)}else o[r]=e.getAttribute("listType");i=e,e=e.nextSibling}}}(e.model,t)),o.mapper.registerViewToModelLength("li",Wm),t.mapper.registerViewToModelLength("li",Wm),o.mapper.on("modelToViewPosition",Lm(o.view)),o.mapper.on("viewToModelPosition",(i=e.model,(e,t)=>{const o=t.viewPosition,n=o.parent,r=t.mapper;if("ul"==n.name||"ol"==n.name){if(o.isAtEnd){const e=r.toModelElement(o.nodeBefore),n=r.getModelLength(o.nodeBefore);t.modelPosition=i.createPositionBefore(e).getShiftedBy(n)}else{const e=r.toModelElement(o.nodeAfter);t.modelPosition=i.createPositionBefore(e)}e.stop()}else if("li"==n.name&&o.nodeBefore&&("ul"==o.nodeBefore.name||"ol"==o.nodeBefore.name)){const s=r.toModelElement(n);let a=1,l=o.nodeBefore;for(;l&&Fm(l);)a+=r.getModelLength(l),l=l.previousSibling;t.modelPosition=i.createPositionBefore(s).getShiftedBy(a),e.stop()}})),t.mapper.on("modelToViewPosition",Lm(o.view)),e.conversion.for("editingDowncast").add(t=>{t.on("insert",Nm,{priority:"high"}),t.on("insert:listItem",Em(e.model)),t.on("attribute:listType:listItem",Mm,{priority:"high"}),t.on("attribute:listType:listItem",Im,{priority:"low"}),t.on("attribute:listIndent:listItem",function(e){return(t,o,i)=>{if(!i.consumable.consume(o.item,"attribute:listIndent"))return;const n=i.mapper.toViewElement(o.item),r=i.writer;r.breakContainer(r.createPositionBefore(n)),r.breakContainer(r.createPositionAfter(n));const s=n.parent,a=s.previousSibling,l=r.createRangeOn(s);r.remove(l),a&&a.nextSibling&&Cm(r,a,a.nextSibling),jm(o.attributeOldValue+1,o.range.start,l.start,n,i,e),xm(o.item,n,i,e);for(const e of o.item.getChildren())i.consumable.consume(e,"insert")}}(e.model)),t.on("remove:listItem",function(e){return(t,o,i)=>{const n=i.mapper.toViewPosition(o.position).getLastMatchingPosition(e=>!e.item.is("li")).nodeAfter,r=i.writer;r.breakContainer(r.createPositionBefore(n)),r.breakContainer(r.createPositionAfter(n));const s=n.parent,a=s.previousSibling,l=r.createRangeOn(s),c=r.remove(l);a&&a.nextSibling&&Cm(r,a,a.nextSibling);jm(i.mapper.toModelElement(n).getAttribute("listIndent")+1,o.position,l.start,n,i,e);for(const e of r.createRangeIn(c).getItems())i.mapper.unbindViewElement(e);t.stop()}}(e.model)),t.on("remove",Rm,{priority:"low"})}),e.conversion.for("dataDowncast").add(t=>{t.on("insert",Nm,{priority:"high"}),t.on("insert:listItem",Em(e.model))}),e.conversion.for("upcast").add(e=>{e.on("element:ul",Vm,{priority:"high"}),e.on("element:ol",Vm,{priority:"high"}),e.on("element:li",Dm,{priority:"high"}),e.on("element:li",Om)}),e.model.on("insertContent",zm,{priority:"high"}),e.commands.add("numberedList",new wm(e,"numbered")),e.commands.add("bulletedList",new wm(e,"bulleted")),e.commands.add("indentList",new vm(e,"forward")),e.commands.add("outdentList",new vm(e,"backward"));const n=o.view.document;this.listenTo(n,"enter",(e,t)=>{const o=this.editor.model.document,i=o.selection.getLastPosition().parent;o.selection.isCollapsed&&"listItem"==i.name&&i.isEmpty&&(this.editor.execute("outdentList"),t.preventDefault(),e.stop())}),this.listenTo(n,"delete",(e,t)=>{if("backward"!==t.direction)return;const o=this.editor.model.document.selection;if(!o.isCollapsed)return;const i=o.getFirstPosition();if(!i.isAtStart)return;const n=i.parent;if("listItem"!==n.name)return;n.previousSibling&&"listItem"===n.previousSibling.name||(this.editor.execute("outdentList"),t.preventDefault(),e.stop())},{priority:"high"});const r=e=>(t,o)=>{this.editor.commands.get(e).isEnabled&&(this.editor.execute(e),o())};e.keystrokes.set("Tab",r("indentList")),e.keystrokes.set("Shift+Tab",r("outdentList"))}afterInit(){const e=this.editor.commands,t=e.get("indent"),o=e.get("outdent");t&&t.registerChildCommand(e.get("indentList")),o&&o.registerChildCommand(e.get("outdentList"))}}function Wm(e){let t=1;for(const o of e.getChildren())if("ul"==o.name||"ol"==o.name)for(const e of o.getChildren())t+=Wm(e);return t}class Um extends Ml{init(){const e=this.editor.t;Sm(this.editor,"numberedList",e("Numbered List"),''),Sm(this.editor,"bulletedList",e("Bulleted List"),'')}}class qm extends hd{constructor(e){super(e),this._selectedElements=[],this.on("execute",()=>{this.refresh()},{priority:"highest"})}refresh(){this._selectedElements=this._getSelectedItems(),this.value=this._selectedElements.every(e=>!!e.getAttribute("todoListChecked")),this.isEnabled=!!this._selectedElements.length}_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(i);for(const e of o.getItems())t.checkAttribute(e,"todoListChecked")&&!n.includes(e)&&n.push(e);return n}execute(e={}){this.editor.model.change(t=>{for(const o of this._selectedElements){(void 0===e.forceValue?!this.value:e.forceValue)?t.setAttribute("todoListChecked",!0,o):t.removeAttribute("todoListChecked",o)}})}}function Gm(e,t,o){const i=t.range.start.parent;if("listItem"!=i.name||"todo"!=i.getAttribute("listType"))return;if(!o.consumable.consume(t.item,"insert"))return;const n=o.writer,r=o.mapper.toViewPosition(t.range.start),s=n.createText(t.item.data),a=n.createAttributeElement("span",{class:"todo-list__label__description"}),l=r.parent.getChild(0);n.insert(n.createPositionAt(r.parent,"end"),s),n.wrap(n.createRangeOn(s),a),n.wrap(n.createRangeOn(s.parent),l)}function $m(e,t,o){const i=t.modelCursor,n=i.parent,r=t.viewItem;if("checkbox"!=r.getAttribute("type")||"listItem"!=n.name||!i.isAtStart)return;if(!o.consumable.consume(r,{name:!0}))return;const s=o.writer;s.setAttribute("listType","todo",n),t.viewItem.hasAttribute("checked")&&s.setAttribute("todoListChecked",!0,n),t.modelRange=s.createRange(i)}function Ym(e,t,o,i){return t.createUIElement("label",{class:"todo-list__label",contenteditable:!1},(function(t){const n=Zc(document,"input",{type:"checkbox"});o&&n.setAttribute("checked","checked"),n.addEventListener("change",()=>i(e));const r=this.toDomElement(t);return r.appendChild(n),r}))}function Km(e,t){const o=t.createRangeIn(e);for(const e of o)if(e.item.is("uiElement","label"))return e.item}class Qm extends Ml{static get pluginName(){return"TodoListEditing"}static get requires(){return[Hm]}init(){const e=this.editor,{editing:t,data:o,model:i}=e;var n,r;i.schema.extend("listItem",{allowAttributes:["todoListChecked"]}),i.schema.addAttributeCheck((e,t)=>{const o=e.last;if("todoListChecked"==t&&"listItem"==o.name&&"todo"!=o.getAttribute("listType"))return!1}),e.commands.add("todoList",new wm(e,"todo")),e.commands.add("todoListCheck",new qm(e)),o.downcastDispatcher.on("insert:listItem",function(e){return(t,o,i)=>{const n=i.consumable;if(!n.test(o.item,"insert")||!n.test(o.item,"attribute:listType")||!n.test(o.item,"attribute:listIndent"))return;if("todo"!=o.item.getAttribute("listType"))return;n.consume(o.item,"insert"),n.consume(o.item,"attribute:listType"),n.consume(o.item,"attribute:listIndent");const r=i.writer,s=o.item,a=ym(s,i);r.addClass("todo-list",a.parent);const l=r.createAttributeElement("label",{class:"todo-list__label"}),c=r.createEmptyElement("input",{type:"checkbox",disabled:"disabled"});o.item.getAttribute("todoListChecked")&&(r.setAttribute("checked","checked",c),r.addClass("todo-list__label",l)),r.insert(r.createPositionAt(a,0),c),r.wrap(r.createRangeOn(c),l),xm(s,a,i,e)}}(i),{priority:"high"}),o.downcastDispatcher.on("insert:$text",Gm,{priority:"high"}),t.downcastDispatcher.on("insert:listItem",function(e,t){return(o,i,n)=>{const r=n.consumable;if(!r.test(i.item,"insert")||!r.test(i.item,"attribute:listType")||!r.test(i.item,"attribute:listIndent"))return;if("todo"!=i.item.getAttribute("listType"))return;const s=i.item;r.consume(s,"insert"),r.consume(s,"attribute:listType"),r.consume(s,"attribute:listIndent"),r.consume(s,"attribute:todoListChecked");const a=n.writer,l=ym(s,n),c=!!s.getAttribute("todoListChecked"),d=Ym(s,a,c,t);a.addClass("todo-list",l.parent),a.insert(a.createPositionAt(l,0),d),xm(s,l,n,e)}}(i,e=>this._handleCheckmarkChange(e)),{priority:"high"}),t.downcastDispatcher.on("attribute:listType:listItem",(n=e=>this._handleCheckmarkChange(e),r=t.view,(e,t,o)=>{const i=o.mapper.toViewElement(t.item),s=o.writer;if("todo"==t.attributeNewValue){const e=!!t.item.getAttribute("todoListChecked"),o=Ym(t.item,s,e,n);s.addClass("todo-list",i.parent),s.insert(s.createPositionAt(i,0),o)}else"todo"==t.attributeOldValue&&(s.removeClass("todo-list",i.parent),s.remove(Km(i,r)))})),t.downcastDispatcher.on("attribute:todoListChecked:listItem",function(e){return(t,o,i)=>{if("todo"!=o.item.getAttribute("listType"))return;if(!i.consumable.consume(o.item,"attribute:todoListChecked"))return;const{mapper:n,writer:r}=i,s=!!o.item.getAttribute("todoListChecked"),a=n.toViewElement(o.item).getChild(0),l=Ym(o.item,r,s,e);r.insert(r.createPositionAfter(a),l),r.remove(a)}}(e=>this._handleCheckmarkChange(e))),t.mapper.on("modelToViewPosition",function(e,t){return(o,i)=>{const n=i.modelPosition,r=n.parent;if(!r.is("listItem")||"todo"!=r.getAttribute("listType")||0!==n.offset)return;const s=Km(t.toViewElement(r),e);s&&(s.nextSibling&&!s.nextSibling.is("uiElement")?i.viewPosition=e.createPositionAt(s.nextSibling,0):i.viewPosition=e.createPositionAfter(s))}}(t.view,t.mapper)),o.upcastDispatcher.on("element:input",$m,{priority:"high"});const s="ltr"===e.locale.contentLanguageDirection?"arrowleft":"arrowright";e.keystrokes.set(s,(e,t)=>function(e,t){const o=t.schema,i=t.document.selection;if(!i.isCollapsed)return;const n=i.getFirstPosition(),r=n.parent;if("listItem"===r.name&&"todo"==r.getAttribute("listType")&&n.isAtStart){const i=o.getNearestSelectionRange(t.createPositionBefore(r),"backward");i&&(e(),t.change(e=>e.setSelection(i)))}}(t,i)),e.keystrokes.set("Ctrl+space",()=>e.execute("todoListCheck"));const a=new Set;this.listenTo(i,"applyOperation",(e,t)=>{const o=t[0];if("rename"==o.type&&"listItem"==o.oldName){const e=o.position.nodeAfter;e.hasAttribute("todoListChecked")&&a.add(e)}else if("changeAttribute"==o.type&&"listType"==o.key&&"todo"===o.oldValue)for(const e of o.range.getItems())e.hasAttribute("todoListChecked")&&"todo"!==e.getAttribute("listType")&&a.add(e)}),i.document.registerPostFixer(e=>{let t=!1;for(const o of a)e.removeAttribute("todoListChecked",o),t=!0;return a.clear(),t})}_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("todoListCheck"),o.setSelection(i)})}}class Jm extends Ml{init(){const e=this.editor.t;Sm(this.editor,"todoList",e("To-do List"),'')}}o(84);function Zm(e,t){if(!e.childCount)return;const o=new vg(e.document),i=function(e,t){const o=t.createRangeIn(e),i=new zo({name:/^p|h\d+$/,styles:{"mso-list":/.*/}}),n=[];for(const e of o)if("elementStart"===e.type&&i.match(e.item)){const t=ef(e.item);n.push({element:e.item,id:t.id,order:t.order,indent:t.indent})}return n}(e,o);if(!i.length)return;let n=null,r=1;i.forEach((e,s)=>{const a=function(e,t){if(!e)return!0;if(e.id!==t.id)return!0;const o=t.element.previousSibling;if(!o)return!0;return i=o,!(i.is("ol")||i.is("ul"));var i}(i[s-1],e),l=a?null:i[s-1],c=(u=e,(d=l)?u.indent-d.indent:u.indent-1);var d,u;if(a&&(n=null,r=1),!n||0!==c){const i=function(e,t){const o=new RegExp(`@list l${e.id}:level${e.indent}\\s*({[^}]*)`,"gi"),i=/mso-level-number-format:([^;]*);/gi,n=o.exec(t);let r="decimal";if(n&&n[1]){const e=i.exec(n[1]);e&&e[1]&&(r=e[1].trim())}return{type:"bullet"!==r&&"image"!==r?"ol":"ul",style:r}}(e,t);if(n){if(e.indent>r){const e=n.getChild(n.childCount-1),t=e.getChild(e.childCount-1);n=Xm(i,t,o),r+=1}else if(e.indent(\s+)<\/span>/g,(e,t)=>1===t.length?" ":Array(t.length+1).join(" ").substr(0,t.length))}function rf(e){const t=new DOMParser,o=function(e){return nf(nf(e)).replace(/([\s]*?)[\r\n]+(\s*<\/span>)/g,"$1$2").replace(/<\/span>/g,"").replace(/ <\//g," ").replace(/ <\/o:p>/g," ").replace(/( |\u00A0)<\/o:p>/g,"").replace(/>(\s*[\r\n]\s*)<")}(function(e){const t=e.match(/<\/body>(.*?)(<\/html>|$)/);t&&t[1]&&(e=e.slice(0,t.index)+e.slice(t.index).replace(t[1],""));return e}(e=e.replace(/
abc
\n\t\t\t//\n\t\t\tif ( isAttribute && this._wrapAttributeElement( wrapElement, child ) ) {\n\t\t\t\twrapPositions.push( new Position( parent, i ) );\n\t\t\t}\n\t\t\t//\n\t\t\t// Wrap the child if it is not an attribute element or if it is an attribute element that should be inside\n\t\t\t// `wrapElement` (due to priority).\n\t\t\t//\n\t\t\t//
abc
-->
abc
\n\t\t\t//
abc
-->
abc
\n\t\t\t//\n\t\t\telse if ( isText || isEmpty || isUI || ( isAttribute && shouldABeOutsideB( wrapElement, child ) ) ) {\n\t\t\t\t// Clone attribute.\n\t\t\t\tconst newAttribute = wrapElement._clone();\n\n\t\t\t\t// Wrap current node with new attribute.\n\t\t\t\tchild._remove();\n\t\t\t\tnewAttribute._appendChild( child );\n\n\t\t\t\tparent._insertChild( i, newAttribute );\n\t\t\t\tthis._addToClonedElementsGroup( newAttribute );\n\n\t\t\t\twrapPositions.push( new Position( parent, i ) );\n\t\t\t}\n\t\t\t//\n\t\t\t// If other nested attribute is found and it wasn't wrapped (see above), continue wrapping inside it.\n\t\t\t//\n\t\t\t//
\n\t\t\t//\n\t\t\telse if ( isAttribute ) {\n\t\t\t\tthis._wrapChildren( child, 0, child.childCount, wrapElement );\n\t\t\t}\n\n\t\t\ti++;\n\t\t}\n\n\t\t// Merge at each wrap.\n\t\tlet offsetChange = 0;\n\n\t\tfor ( const position of wrapPositions ) {\n\t\t\tposition.offset -= offsetChange;\n\n\t\t\t// Do not merge with elements outside selected children.\n\t\t\tif ( position.offset == startOffset ) {\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tconst newPosition = this.mergeAttributes( position );\n\n\t\t\t// If nodes were merged - other merge offsets will change.\n\t\t\tif ( !newPosition.isEqual( position ) ) {\n\t\t\t\toffsetChange++;\n\t\t\t\tendOffset--;\n\t\t\t}\n\t\t}\n\n\t\treturn Range._createFromParentsAndOffsets( parent, startOffset, parent, endOffset );\n\t}\n\n\t/**\n\t * Unwraps children from provided `unwrapElement`. Only children contained in `parent` element between\n\t * `startOffset` and `endOffset` will be unwrapped.\n\t *\n\t * @private\n\t * @param {module:engine/view/element~Element} parent\n\t * @param {Number} startOffset\n\t * @param {Number} endOffset\n\t * @param {module:engine/view/element~Element} unwrapElement\n\t */\n\t_unwrapChildren( parent, startOffset, endOffset, unwrapElement ) {\n\t\tlet i = startOffset;\n\t\tconst unwrapPositions = [];\n\n\t\t// Iterate over each element between provided offsets inside parent.\n\t\t// We don't use tree walker or range iterator because we will be removing and merging potentially multiple nodes,\n\t\t// so it could get messy. It is safer to it manually in this case.\n\t\twhile ( i < endOffset ) {\n\t\t\tconst child = parent.getChild( i );\n\n\t\t\t// Skip all text nodes. There should be no container element's here either.\n\t\t\tif ( !child.is( 'attributeElement' ) ) {\n\t\t\t\ti++;\n\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\t//\n\t\t\t// (In all examples, assume that `unwrapElement` is `` element.)\n\t\t\t//\n\t\t\t// If the child is similar to the given attribute element, unwrap it - it will be completely removed.\n\t\t\t//\n\t\t\t//
abcxyz
-->
abcxyz
\n\t\t\t//\n\t\t\tif ( child.isSimilar( unwrapElement ) ) {\n\t\t\t\tconst unwrapped = child.getChildren();\n\t\t\t\tconst count = child.childCount;\n\n\t\t\t\t// Replace wrapper element with its children\n\t\t\t\tchild._remove();\n\t\t\t\tparent._insertChild( i, unwrapped );\n\n\t\t\t\tthis._removeFromClonedElementsGroup( child );\n\n\t\t\t\t// Save start and end position of moved items.\n\t\t\t\tunwrapPositions.push(\n\t\t\t\t\tnew Position( parent, i ),\n\t\t\t\t\tnew Position( parent, i + count )\n\t\t\t\t);\n\n\t\t\t\t// Skip elements that were unwrapped. Assuming there won't be another element to unwrap in child elements.\n\t\t\t\ti += count;\n\t\t\t\tendOffset += count - 1;\n\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\t//\n\t\t\t// If the child is not similar but is an attribute element, try partial unwrapping - remove the same attributes/styles/classes.\n\t\t\t// Partial unwrapping will happen only if the elements have the same name.\n\t\t\t//\n\t\t\t//
abcxyz
-->
abcxyz
\n\t\t\t//
abcxyz
-->
abcxyz
\n\t\t\t//\n\t\t\tif ( this._unwrapAttributeElement( unwrapElement, child ) ) {\n\t\t\t\tunwrapPositions.push(\n\t\t\t\t\tnew Position( parent, i ),\n\t\t\t\t\tnew Position( parent, i + 1 )\n\t\t\t\t);\n\n\t\t\t\ti++;\n\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\t//\n\t\t\t// If other nested attribute is found, look through it's children for elements to unwrap.\n\t\t\t//\n\t\t\t//
abc
-->
abc
\n\t\t\t//\n\t\t\tthis._unwrapChildren( child, 0, child.childCount, unwrapElement );\n\n\t\t\ti++;\n\t\t}\n\n\t\t// Merge at each unwrap.\n\t\tlet offsetChange = 0;\n\n\t\tfor ( const position of unwrapPositions ) {\n\t\t\tposition.offset -= offsetChange;\n\n\t\t\t// Do not merge with elements outside selected children.\n\t\t\tif ( position.offset == startOffset || position.offset == endOffset ) {\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tconst newPosition = this.mergeAttributes( position );\n\n\t\t\t// If nodes were merged - other merge offsets will change.\n\t\t\tif ( !newPosition.isEqual( position ) ) {\n\t\t\t\toffsetChange++;\n\t\t\t\tendOffset--;\n\t\t\t}\n\t\t}\n\n\t\treturn Range._createFromParentsAndOffsets( parent, startOffset, parent, endOffset );\n\t}\n\n\t/**\n\t * Helper function for `view.writer.wrap`. Wraps range with provided attribute element.\n\t * This method will also merge newly added attribute element with its siblings whenever possible.\n\t *\n\t * Throws {@link module:utils/ckeditorerror~CKEditorError} `view-writer-wrap-invalid-attribute` when passed attribute element is not\n\t * an instance of {@link module:engine/view/attributeelement~AttributeElement AttributeElement}.\n\t *\n\t * @private\n\t * @param {module:engine/view/range~Range} range\n\t * @param {module:engine/view/attributeelement~AttributeElement} attribute\n\t * @returns {module:engine/view/range~Range} New range after wrapping, spanning over wrapping attribute element.\n\t */\n\t_wrapRange( range, attribute ) {\n\t\t// Break attributes at range start and end.\n\t\tconst { start: breakStart, end: breakEnd } = this._breakAttributesRange( range, true );\n\t\tconst parentContainer = breakStart.parent;\n\n\t\t// Wrap all children with attribute.\n\t\tconst newRange = this._wrapChildren( parentContainer, breakStart.offset, breakEnd.offset, attribute );\n\n\t\t// Merge attributes at the both ends and return a new range.\n\t\tconst start = this.mergeAttributes( newRange.start );\n\n\t\t// If start position was merged - move end position back.\n\t\tif ( !start.isEqual( newRange.start ) ) {\n\t\t\tnewRange.end.offset--;\n\t\t}\n\t\tconst end = this.mergeAttributes( newRange.end );\n\n\t\treturn new Range( start, end );\n\t}\n\n\t/**\n\t * Helper function for {@link #wrap}. Wraps position with provided attribute element.\n\t * This method will also merge newly added attribute element with its siblings whenever possible.\n\t *\n\t * Throws {@link module:utils/ckeditorerror~CKEditorError} `view-writer-wrap-invalid-attribute` when passed attribute element is not\n\t * an instance of {@link module:engine/view/attributeelement~AttributeElement AttributeElement}.\n\t *\n\t * @private\n\t * @param {module:engine/view/position~Position} position\n\t * @param {module:engine/view/attributeelement~AttributeElement} attribute\n\t * @returns {module:engine/view/position~Position} New position after wrapping.\n\t */\n\t_wrapPosition( position, attribute ) {\n\t\t// Return same position when trying to wrap with attribute similar to position parent.\n\t\tif ( attribute.isSimilar( position.parent ) ) {\n\t\t\treturn movePositionToTextNode( position.clone() );\n\t\t}\n\n\t\t// When position is inside text node - break it and place new position between two text nodes.\n\t\tif ( position.parent.is( 'text' ) ) {\n\t\t\tposition = breakTextNode( position );\n\t\t}\n\n\t\t// Create fake element that will represent position, and will not be merged with other attributes.\n\t\tconst fakePosition = this.createAttributeElement();\n\t\tfakePosition._priority = Number.POSITIVE_INFINITY;\n\t\tfakePosition.isSimilar = () => false;\n\n\t\t// Insert fake element in position location.\n\t\tposition.parent._insertChild( position.offset, fakePosition );\n\n\t\t// Range around inserted fake attribute element.\n\t\tconst wrapRange = new Range( position, position.getShiftedBy( 1 ) );\n\n\t\t// Wrap fake element with attribute (it will also merge if possible).\n\t\tthis.wrap( wrapRange, attribute );\n\n\t\t// Remove fake element and place new position there.\n\t\tconst newPosition = new Position( fakePosition.parent, fakePosition.index );\n\t\tfakePosition._remove();\n\n\t\t// If position is placed between text nodes - merge them and return position inside.\n\t\tconst nodeBefore = newPosition.nodeBefore;\n\t\tconst nodeAfter = newPosition.nodeAfter;\n\n\t\tif ( nodeBefore instanceof Text && nodeAfter instanceof Text ) {\n\t\t\treturn mergeTextNodes( nodeBefore, nodeAfter );\n\t\t}\n\n\t\t// If position is next to text node - move position inside.\n\t\treturn movePositionToTextNode( newPosition );\n\t}\n\n\t/**\n\t * \tWraps one {@link module:engine/view/attributeelement~AttributeElement AttributeElement} into another by\n\t * \tmerging them if possible. When merging is possible - all attributes, styles and classes are moved from wrapper\n\t * \telement to element being wrapped.\n\t *\n\t * \t@private\n\t * \t@param {module:engine/view/attributeelement~AttributeElement} wrapper Wrapper AttributeElement.\n\t * \t@param {module:engine/view/attributeelement~AttributeElement} toWrap AttributeElement to wrap using wrapper element.\n\t * \t@returns {Boolean} Returns `true` if elements are merged.\n\t */\n\t_wrapAttributeElement( wrapper, toWrap ) {\n\t\tif ( !canBeJoined( wrapper, toWrap ) ) {\n\t\t\treturn false;\n\t\t}\n\n\t\t// Can't merge if name or priority differs.\n\t\tif ( wrapper.name !== toWrap.name || wrapper.priority !== toWrap.priority ) {\n\t\t\treturn false;\n\t\t}\n\n\t\t// Check if attributes can be merged.\n\t\tfor ( const key of wrapper.getAttributeKeys() ) {\n\t\t\t// Classes and styles should be checked separately.\n\t\t\tif ( key === 'class' || key === 'style' ) {\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\t// If some attributes are different we cannot wrap.\n\t\t\tif ( toWrap.hasAttribute( key ) && toWrap.getAttribute( key ) !== wrapper.getAttribute( key ) ) {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t}\n\n\t\t// Check if styles can be merged.\n\t\tfor ( const key of wrapper.getStyleNames() ) {\n\t\t\tif ( toWrap.hasStyle( key ) && toWrap.getStyle( key ) !== wrapper.getStyle( key ) ) {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t}\n\n\t\t// Move all attributes/classes/styles from wrapper to wrapped AttributeElement.\n\t\tfor ( const key of wrapper.getAttributeKeys() ) {\n\t\t\t// Classes and styles should be checked separately.\n\t\t\tif ( key === 'class' || key === 'style' ) {\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\t// Move only these attributes that are not present - other are similar.\n\t\t\tif ( !toWrap.hasAttribute( key ) ) {\n\t\t\t\tthis.setAttribute( key, wrapper.getAttribute( key ), toWrap );\n\t\t\t}\n\t\t}\n\n\t\tfor ( const key of wrapper.getStyleNames() ) {\n\t\t\tif ( !toWrap.hasStyle( key ) ) {\n\t\t\t\tthis.setStyle( key, wrapper.getStyle( key ), toWrap );\n\t\t\t}\n\t\t}\n\n\t\tfor ( const key of wrapper.getClassNames() ) {\n\t\t\tif ( !toWrap.hasClass( key ) ) {\n\t\t\t\tthis.addClass( key, toWrap );\n\t\t\t}\n\t\t}\n\n\t\treturn true;\n\t}\n\n\t/**\n\t * Unwraps {@link module:engine/view/attributeelement~AttributeElement AttributeElement} from another by removing\n\t * corresponding attributes, classes and styles. All attributes, classes and styles from wrapper should be present\n\t * inside element being unwrapped.\n\t *\n\t * @private\n\t * @param {module:engine/view/attributeelement~AttributeElement} wrapper Wrapper AttributeElement.\n\t * @param {module:engine/view/attributeelement~AttributeElement} toUnwrap AttributeElement to unwrap using wrapper element.\n\t * @returns {Boolean} Returns `true` if elements are unwrapped.\n\t **/\n\t_unwrapAttributeElement( wrapper, toUnwrap ) {\n\t\tif ( !canBeJoined( wrapper, toUnwrap ) ) {\n\t\t\treturn false;\n\t\t}\n\n\t\t// Can't unwrap if name or priority differs.\n\t\tif ( wrapper.name !== toUnwrap.name || wrapper.priority !== toUnwrap.priority ) {\n\t\t\treturn false;\n\t\t}\n\n\t\t// Check if AttributeElement has all wrapper attributes.\n\t\tfor ( const key of wrapper.getAttributeKeys() ) {\n\t\t\t// Classes and styles should be checked separately.\n\t\t\tif ( key === 'class' || key === 'style' ) {\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\t// If some attributes are missing or different we cannot unwrap.\n\t\t\tif ( !toUnwrap.hasAttribute( key ) || toUnwrap.getAttribute( key ) !== wrapper.getAttribute( key ) ) {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t}\n\n\t\t// Check if AttributeElement has all wrapper classes.\n\t\tif ( !toUnwrap.hasClass( ...wrapper.getClassNames() ) ) {\n\t\t\treturn false;\n\t\t}\n\n\t\t// Check if AttributeElement has all wrapper styles.\n\t\tfor ( const key of wrapper.getStyleNames() ) {\n\t\t\t// If some styles are missing or different we cannot unwrap.\n\t\t\tif ( !toUnwrap.hasStyle( key ) || toUnwrap.getStyle( key ) !== wrapper.getStyle( key ) ) {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t}\n\n\t\t// Remove all wrapper's attributes from unwrapped element.\n\t\tfor ( const key of wrapper.getAttributeKeys() ) {\n\t\t\t// Classes and styles should be checked separately.\n\t\t\tif ( key === 'class' || key === 'style' ) {\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tthis.removeAttribute( key, toUnwrap );\n\t\t}\n\n\t\t// Remove all wrapper's classes from unwrapped element.\n\t\tthis.removeClass( Array.from( wrapper.getClassNames() ), toUnwrap );\n\n\t\t// Remove all wrapper's styles from unwrapped element.\n\t\tthis.removeStyle( Array.from( wrapper.getStyleNames() ), toUnwrap );\n\n\t\treturn true;\n\t}\n\n\t/**\n\t * Helper function used by other `DowncastWriter` methods. Breaks attribute elements at the boundaries of given range.\n\t *\n\t * @private\n\t * @param {module:engine/view/range~Range} range Range which `start` and `end` positions will be used to break attributes.\n\t * @param {Boolean} [forceSplitText=false] If set to `true`, will break text nodes even if they are directly in container element.\n\t * This behavior will result in incorrect view state, but is needed by other view writing methods which then fixes view state.\n\t * @returns {module:engine/view/range~Range} New range with located at break positions.\n\t */\n\t_breakAttributesRange( range, forceSplitText = false ) {\n\t\tconst rangeStart = range.start;\n\t\tconst rangeEnd = range.end;\n\n\t\tvalidateRangeContainer( range, this.document );\n\n\t\t// Break at the collapsed position. Return new collapsed range.\n\t\tif ( range.isCollapsed ) {\n\t\t\tconst position = this._breakAttributes( range.start, forceSplitText );\n\n\t\t\treturn new Range( position, position );\n\t\t}\n\n\t\tconst breakEnd = this._breakAttributes( rangeEnd, forceSplitText );\n\t\tconst count = breakEnd.parent.childCount;\n\t\tconst breakStart = this._breakAttributes( rangeStart, forceSplitText );\n\n\t\t// Calculate new break end offset.\n\t\tbreakEnd.offset += breakEnd.parent.childCount - count;\n\n\t\treturn new Range( breakStart, breakEnd );\n\t}\n\n\t/**\n\t * Helper function used by other `DowncastWriter` methods. Breaks attribute elements at given position.\n\t *\n\t * Throws {@link module:utils/ckeditorerror~CKEditorError CKEditorError} `view-writer-cannot-break-empty-element` when break position\n\t * is placed inside {@link module:engine/view/emptyelement~EmptyElement EmptyElement}.\n\t *\n\t * Throws {@link module:utils/ckeditorerror~CKEditorError CKEditorError} `view-writer-cannot-break-ui-element` when break position\n\t * is placed inside {@link module:engine/view/uielement~UIElement UIElement}.\n\t *\n\t * @private\n\t * @param {module:engine/view/position~Position} position Position where to break attributes.\n\t * @param {Boolean} [forceSplitText=false] If set to `true`, will break text nodes even if they are directly in container element.\n\t * This behavior will result in incorrect view state, but is needed by other view writing methods which then fixes view state.\n\t * @returns {module:engine/view/position~Position} New position after breaking the attributes.\n\t */\n\t_breakAttributes( position, forceSplitText = false ) {\n\t\tconst positionOffset = position.offset;\n\t\tconst positionParent = position.parent;\n\n\t\t// If position is placed inside EmptyElement - throw an exception as we cannot break inside.\n\t\tif ( position.parent.is( 'emptyElement' ) ) {\n\t\t\t/**\n\t\t\t * Cannot break inside EmptyElement instance.\n\t\t\t *\n\t\t\t * @error view-writer-cannot-break-empty-element\n\t\t\t */\n\t\t\tthrow new CKEditorError( 'view-writer-cannot-break-empty-element', this.document );\n\t\t}\n\n\t\t// If position is placed inside UIElement - throw an exception as we cannot break inside.\n\t\tif ( position.parent.is( 'uiElement' ) ) {\n\t\t\t/**\n\t\t\t * Cannot break inside UIElement instance.\n\t\t\t *\n\t\t\t * @error view-writer-cannot-break-ui-element\n\t\t\t */\n\t\t\tthrow new CKEditorError( 'view-writer-cannot-break-ui-element', this.document );\n\t\t}\n\n\t\t// There are no attributes to break and text nodes breaking is not forced.\n\t\tif ( !forceSplitText && positionParent.is( 'text' ) && isContainerOrFragment( positionParent.parent ) ) {\n\t\t\treturn position.clone();\n\t\t}\n\n\t\t// Position's parent is container, so no attributes to break.\n\t\tif ( isContainerOrFragment( positionParent ) ) {\n\t\t\treturn position.clone();\n\t\t}\n\n\t\t// Break text and start again in new position.\n\t\tif ( positionParent.is( 'text' ) ) {\n\t\t\treturn this._breakAttributes( breakTextNode( position ), forceSplitText );\n\t\t}\n\n\t\tconst length = positionParent.childCount;\n\n\t\t//
\n\t\t\telse {\n\t\t\t\tconst offsetAfter = positionParent.index + 1;\n\n\t\t\t\t// Break element.\n\t\t\t\tconst clonedNode = positionParent._clone();\n\n\t\t\t\t// Insert cloned node to position's parent node.\n\t\t\t\tpositionParent.parent._insertChild( offsetAfter, clonedNode );\n\t\t\t\tthis._addToClonedElementsGroup( clonedNode );\n\n\t\t\t\t// Get nodes to move.\n\t\t\t\tconst count = positionParent.childCount - positionOffset;\n\t\t\t\tconst nodesToMove = positionParent._removeChildren( positionOffset, count );\n\n\t\t\t\t// Move nodes to cloned node.\n\t\t\t\tclonedNode._appendChild( nodesToMove );\n\n\t\t\t\t// Create new position to work on.\n\t\t\t\tconst newPosition = new Position( positionParent.parent, offsetAfter );\n\n\t\t\t\treturn this._breakAttributes( newPosition, forceSplitText );\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Stores the information that an {@link module:engine/view/attributeelement~AttributeElement attribute element} was\n\t * added to the tree. Saves the reference to the group in the given element and updates the group, so other elements\n\t * from the group now keep a reference to the given attribute element.\n\t *\n\t * The clones group can be obtained using {@link module:engine/view/attributeelement~AttributeElement#getElementsWithSameId}.\n\t *\n\t * Does nothing if added element has no {@link module:engine/view/attributeelement~AttributeElement#id id}.\n\t *\n\t * @private\n\t * @param {module:engine/view/attributeelement~AttributeElement} element Attribute element to save.\n\t */\n\t_addToClonedElementsGroup( element ) {\n\t\t// Add only if the element is in document tree.\n\t\tif ( !element.root.is( 'rootElement' ) ) {\n\t\t\treturn;\n\t\t}\n\n\t\t// Traverse the element's children recursively to find other attribute elements that also might got inserted.\n\t\t// The loop is at the beginning so we can make fast returns later in the code.\n\t\tif ( element.is( 'element' ) ) {\n\t\t\tfor ( const child of element.getChildren() ) {\n\t\t\t\tthis._addToClonedElementsGroup( child );\n\t\t\t}\n\t\t}\n\n\t\tconst id = element.id;\n\n\t\tif ( !id ) {\n\t\t\treturn;\n\t\t}\n\n\t\tlet group = this._cloneGroups.get( id );\n\n\t\tif ( !group ) {\n\t\t\tgroup = new Set();\n\t\t\tthis._cloneGroups.set( id, group );\n\t\t}\n\n\t\tgroup.add( element );\n\t\telement._clonesGroup = group;\n\t}\n\n\t/**\n\t * Removes all the information about the given {@link module:engine/view/attributeelement~AttributeElement attribute element}\n\t * from its clones group.\n\t *\n\t * Keep in mind, that the element will still keep a reference to the group (but the group will not keep a reference to it).\n\t * This allows to reference the whole group even if the element was already removed from the tree.\n\t *\n\t * Does nothing if the element has no {@link module:engine/view/attributeelement~AttributeElement#id id}.\n\t *\n\t * @private\n\t * @param {module:engine/view/attributeelement~AttributeElement} element Attribute element to remove.\n\t */\n\t_removeFromClonedElementsGroup( element ) {\n\t\t// Traverse the element's children recursively to find other attribute elements that also got removed.\n\t\t// The loop is at the beginning so we can make fast returns later in the code.\n\t\tif ( element.is( 'element' ) ) {\n\t\t\tfor ( const child of element.getChildren() ) {\n\t\t\t\tthis._removeFromClonedElementsGroup( child );\n\t\t\t}\n\t\t}\n\n\t\tconst id = element.id;\n\n\t\tif ( !id ) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst group = this._cloneGroups.get( id );\n\n\t\tif ( !group ) {\n\t\t\treturn;\n\t\t}\n\n\t\tgroup.delete( element );\n\t\t// Not removing group from element on purpose!\n\t\t// If other parts of code have reference to this element, they will be able to get references to other elements from the group.\n\t}\n}\n\n// Helper function for `view.writer.wrap`. Checks if given element has any children that are not ui elements.\nfunction _hasNonUiChildren( parent ) {\n\treturn Array.from( parent.getChildren() ).some( child => !child.is( 'uiElement' ) );\n}\n\n/**\n * Attribute element need to be instance of attribute element.\n *\n * @error view-writer-wrap-invalid-attribute\n */\n\n// Returns first parent container of specified {@link module:engine/view/position~Position Position}.\n// Position's parent node is checked as first, then next parents are checked.\n// Note that {@link module:engine/view/documentfragment~DocumentFragment DocumentFragment} is treated like a container.\n//\n// @param {module:engine/view/position~Position} position Position used as a start point to locate parent container.\n// @returns {module:engine/view/containerelement~ContainerElement|module:engine/view/documentfragment~DocumentFragment|undefined}\n// Parent container element or `undefined` if container is not found.\nfunction getParentContainer( position ) {\n\tlet parent = position.parent;\n\n\twhile ( !isContainerOrFragment( parent ) ) {\n\t\tif ( !parent ) {\n\t\t\treturn undefined;\n\t\t}\n\t\tparent = parent.parent;\n\t}\n\n\treturn parent;\n}\n\n// Checks if first {@link module:engine/view/attributeelement~AttributeElement AttributeElement} provided to the function\n// can be wrapped otuside second element. It is done by comparing elements'\n// {@link module:engine/view/attributeelement~AttributeElement#priority priorities}, if both have same priority\n// {@link module:engine/view/element~Element#getIdentity identities} are compared.\n//\n// @param {module:engine/view/attributeelement~AttributeElement} a\n// @param {module:engine/view/attributeelement~AttributeElement} b\n// @returns {Boolean}\nfunction shouldABeOutsideB( a, b ) {\n\tif ( a.priority < b.priority ) {\n\t\treturn true;\n\t} else if ( a.priority > b.priority ) {\n\t\treturn false;\n\t}\n\n\t// When priorities are equal and names are different - use identities.\n\treturn a.getIdentity() < b.getIdentity();\n}\n\n// Returns new position that is moved to near text node. Returns same position if there is no text node before of after\n// specified position.\n//\n//\t\t
foo[]
->
foo{}
\n//\t\t
[]foo
->
{}foo
\n//\n// @param {module:engine/view/position~Position} position\n// @returns {module:engine/view/position~Position} Position located inside text node or same position if there is no text nodes\n// before or after position location.\nfunction movePositionToTextNode( position ) {\n\tconst nodeBefore = position.nodeBefore;\n\n\tif ( nodeBefore && nodeBefore.is( 'text' ) ) {\n\t\treturn new Position( nodeBefore, nodeBefore.data.length );\n\t}\n\n\tconst nodeAfter = position.nodeAfter;\n\n\tif ( nodeAfter && nodeAfter.is( 'text' ) ) {\n\t\treturn new Position( nodeAfter, 0 );\n\t}\n\n\treturn position;\n}\n\n// Breaks text node into two text nodes when possible.\n//\n//\t\t
foo{}bar
->
foo[]bar
\n//\t\t
{}foobar
->
[]foobar
\n//\t\t
foobar{}
->
foobar[]
\n//\n// @param {module:engine/view/position~Position} position Position that need to be placed inside text node.\n// @returns {module:engine/view/position~Position} New position after breaking text node.\nfunction breakTextNode( position ) {\n\tif ( position.offset == position.parent.data.length ) {\n\t\treturn new Position( position.parent.parent, position.parent.index + 1 );\n\t}\n\n\tif ( position.offset === 0 ) {\n\t\treturn new Position( position.parent.parent, position.parent.index );\n\t}\n\n\t// Get part of the text that need to be moved.\n\tconst textToMove = position.parent.data.slice( position.offset );\n\n\t// Leave rest of the text in position's parent.\n\tposition.parent._data = position.parent.data.slice( 0, position.offset );\n\n\t// Insert new text node after position's parent text node.\n\tposition.parent.parent._insertChild( position.parent.index + 1, new Text( position.root.document, textToMove ) );\n\n\t// Return new position between two newly created text nodes.\n\treturn new Position( position.parent.parent, position.parent.index + 1 );\n}\n\n// Merges two text nodes into first node. Removes second node and returns merge position.\n//\n// @param {module:engine/view/text~Text} t1 First text node to merge. Data from second text node will be moved at the end of\n// this text node.\n// @param {module:engine/view/text~Text} t2 Second text node to merge. This node will be removed after merging.\n// @returns {module:engine/view/position~Position} Position after merging text nodes.\nfunction mergeTextNodes( t1, t2 ) {\n\t// Merge text data into first text node and remove second one.\n\tconst nodeBeforeLength = t1.data.length;\n\tt1._data += t2.data;\n\tt2._remove();\n\n\treturn new Position( t1, nodeBeforeLength );\n}\n\n// Checks if provided nodes are valid to insert. Checks if each node is an instance of\n// {@link module:engine/view/text~Text Text} or {@link module:engine/view/attributeelement~AttributeElement AttributeElement},\n// {@link module:engine/view/containerelement~ContainerElement ContainerElement},\n// {@link module:engine/view/emptyelement~EmptyElement EmptyElement} or\n// {@link module:engine/view/uielement~UIElement UIElement}.\n//\n// Throws {@link module:utils/ckeditorerror~CKEditorError CKEditorError} `view-writer-insert-invalid-node` when nodes to insert\n// contains instances that are not {@link module:engine/view/text~Text Texts},\n// {@link module:engine/view/emptyelement~EmptyElement EmptyElements},\n// {@link module:engine/view/uielement~UIElement UIElements},\n// {@link module:engine/view/attributeelement~AttributeElement AttributeElements} or\n// {@link module:engine/view/containerelement~ContainerElement ContainerElements}.\n//\n// @param Iterable. nodes\n// @param {Object} errorContext\nfunction validateNodesToInsert( nodes, errorContext ) {\n\tfor ( const node of nodes ) {\n\t\tif ( !validNodesToInsert.some( ( validNode => node instanceof validNode ) ) ) { // eslint-disable-line no-use-before-define\n\t\t\t/**\n\t\t\t * Inserted nodes should be valid to insert. of {@link module:engine/view/attributeelement~AttributeElement AttributeElement},\n\t\t\t * {@link module:engine/view/containerelement~ContainerElement ContainerElement},\n\t\t\t * {@link module:engine/view/emptyelement~EmptyElement EmptyElement},\n\t\t\t * {@link module:engine/view/uielement~UIElement UIElement}, {@link module:engine/view/text~Text Text}.\n\t\t\t *\n\t\t\t * @error view-writer-insert-invalid-node\n\t\t\t */\n\t\t\tthrow new CKEditorError( 'view-writer-insert-invalid-node', errorContext );\n\t\t}\n\n\t\tif ( !node.is( 'text' ) ) {\n\t\t\tvalidateNodesToInsert( node.getChildren(), errorContext );\n\t\t}\n\t}\n}\n\nconst validNodesToInsert = [ Text, AttributeElement, ContainerElement, EmptyElement, UIElement ];\n\n// Checks if node is ContainerElement or DocumentFragment, because in most cases they should be treated the same way.\n//\n// @param {module:engine/view/node~Node} node\n// @returns {Boolean} Returns `true` if node is instance of ContainerElement or DocumentFragment.\nfunction isContainerOrFragment( node ) {\n\treturn node && ( node.is( 'containerElement' ) || node.is( 'documentFragment' ) );\n}\n\n// Checks if {@link module:engine/view/range~Range#start range start} and {@link module:engine/view/range~Range#end range end} are placed\n// inside same {@link module:engine/view/containerelement~ContainerElement container element}.\n// Throws {@link module:utils/ckeditorerror~CKEditorError CKEditorError} `view-writer-invalid-range-container` when validation fails.\n//\n// @param {module:engine/view/range~Range} range\n// @param {Object} errorContext\nfunction validateRangeContainer( range, errorContext ) {\n\tconst startContainer = getParentContainer( range.start );\n\tconst endContainer = getParentContainer( range.end );\n\n\tif ( !startContainer || !endContainer || startContainer !== endContainer ) {\n\t\t/**\n\t\t * Range container is invalid. This can happen if {@link module:engine/view/range~Range#start range start} and\n\t\t * {@link module:engine/view/range~Range#end range end} positions are not placed inside same container or\n\t\t * parent container for these positions cannot be found.\n\t\t *\n\t\t * @error view-writer-invalid-range-container\n\t\t */\n\n\t\tthrow new CKEditorError( 'view-writer-invalid-range-container', errorContext );\n\t}\n}\n\n// Checks if two attribute elements can be joined together. Elements can be joined together if, and only if\n// they do not have ids specified.\n//\n// @private\n// @param {module:engine/view/element~Element} a\n// @param {module:engine/view/element~Element} b\n// @returns {Boolean}\nfunction canBeJoined( a, b ) {\n\treturn a.id === null && b.id === null;\n}\n","/**\n * @license Copyright (c) 2003-2020, CKSource - Frederico Knabben. All rights reserved.\n * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license\n */\n\n/**\n * @module utils/dom/istext\n */\n\n/**\n * Checks if the object is a native DOM Text node.\n *\n * @param {*} obj\n * @returns {Boolean}\n */\nexport default function isText( obj ) {\n\treturn Object.prototype.toString.call( obj ) == '[object Text]';\n}\n","/**\n * @license Copyright (c) 2003-2020, CKSource - Frederico Knabben. All rights reserved.\n * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license\n */\n\nimport { keyCodes } from '@ckeditor/ckeditor5-utils/src/keyboard';\nimport isText from '@ckeditor/ckeditor5-utils/src/dom/istext';\n\n/**\n * Set of utils related to block and inline fillers handling.\n *\n * Browsers do not allow to put caret in elements which does not have height. Because of it, we need to fill all\n * empty elements which should be selectable with elements or characters called \"fillers\". Unfortunately there is no one\n * universal filler, this is why two types are uses:\n *\n * * Block filler is an element which fill block elements, like `
`. CKEditor uses ` ` as a block filler during the editing,\n * as browsers do natively. So instead of an empty `
` there will be `
`. The advantage of block filler is that\n * it is transparent for the selection, so when the caret is before the ` ` and user presses right arrow he will be\n * moved to the next paragraph, not after the ` `. The disadvantage is that it breaks a block, so it can not be used\n * in the middle of a line of text. The {@link module:engine/view/filler~BR_FILLER ` ` filler} can be replaced with any other\n * character in the data output, for instance {@link module:engine/view/filler~NBSP_FILLER non-breaking space}.\n *\n * * Inline filler is a filler which does not break a line of text, so it can be used inside the text, for instance in the empty\n * `` surrendered by text: `foobar`, if we want to put the caret there. CKEditor uses a sequence of the zero-width\n * spaces as an {@link module:engine/view/filler~INLINE_FILLER inline filler} having the predetermined\n * {@link module:engine/view/filler~INLINE_FILLER_LENGTH length}. A sequence is used, instead of a single character to\n * avoid treating random zero-width spaces as the inline filler. Disadvantage of the inline filler is that it is not\n * transparent for the selection. The arrow key moves the caret between zero-width spaces characters, so the additional\n * code is needed to handle the caret.\n *\n * Both inline and block fillers are handled by the {@link module:engine/view/renderer~Renderer renderer} and are not present in the\n * view.\n *\n * @module engine/view/filler\n */\n\n/**\n * Non-breaking space filler creator. This is a function which creates ` ` text node.\n * It defines how the filler is created.\n *\n * @see module:engine/view/filler~BR_FILLER\n * @function\n */\nexport const NBSP_FILLER = domDocument => domDocument.createTextNode( '\\u00A0' );\n\n/**\n * ` ` filler creator. This is a function which creates ` ` element.\n * It defines how the filler is created.\n *\n * @see module:engine/view/filler~NBSP_FILLER\n * @function\n */\nexport const BR_FILLER = domDocument => {\n\tconst fillerBr = domDocument.createElement( 'br' );\n\tfillerBr.dataset.ckeFiller = true;\n\n\treturn fillerBr;\n};\n\n/**\n * Length of the {@link module:engine/view/filler~INLINE_FILLER INLINE_FILLER}.\n */\nexport const INLINE_FILLER_LENGTH = 7;\n\n/**\n * Inline filler which is a sequence of the zero width spaces.\n */\nexport const INLINE_FILLER = ( () => {\n\tlet inlineFiller = '';\n\n\tfor ( let i = 0; i < INLINE_FILLER_LENGTH; i++ ) {\n\t\tinlineFiller += '\\u200b';\n\t}\n\n\treturn inlineFiller;\n} )(); // Usu IIF so the INLINE_FILLER appears as a constant in the docs.\n\n/**\n * Checks if the node is a text node which starts with the {@link module:engine/view/filler~INLINE_FILLER inline filler}.\n *\n *\t\tstartsWithFiller( document.createTextNode( INLINE_FILLER ) ); // true\n *\t\tstartsWithFiller( document.createTextNode( INLINE_FILLER + 'foo' ) ); // true\n *\t\tstartsWithFiller( document.createTextNode( 'foo' ) ); // false\n *\t\tstartsWithFiller( document.createElement( 'p' ) ); // false\n *\n * @param {Node} domNode DOM node.\n * @returns {Boolean} True if the text node starts with the {@link module:engine/view/filler~INLINE_FILLER inline filler}.\n */\nexport function startsWithFiller( domNode ) {\n\treturn isText( domNode ) && ( domNode.data.substr( 0, INLINE_FILLER_LENGTH ) === INLINE_FILLER );\n}\n\n/**\n * Checks if the text node contains only the {@link module:engine/view/filler~INLINE_FILLER inline filler}.\n *\n *\t\tisInlineFiller( document.createTextNode( INLINE_FILLER ) ); // true\n *\t\tisInlineFiller( document.createTextNode( INLINE_FILLER + 'foo' ) ); // false\n *\n * @param {Text} domText DOM text node.\n * @returns {Boolean} True if the text node contains only the {@link module:engine/view/filler~INLINE_FILLER inline filler}.\n */\nexport function isInlineFiller( domText ) {\n\treturn domText.data.length == INLINE_FILLER_LENGTH && startsWithFiller( domText );\n}\n\n/**\n * Get string data from the text node, removing an {@link module:engine/view/filler~INLINE_FILLER inline filler} from it,\n * if text node contains it.\n *\n *\t\tgetDataWithoutFiller( document.createTextNode( INLINE_FILLER + 'foo' ) ) == 'foo' // true\n *\t\tgetDataWithoutFiller( document.createTextNode( 'foo' ) ) == 'foo' // true\n *\n * @param {Text} domText DOM text node, possible with inline filler.\n * @returns {String} Data without filler.\n */\nexport function getDataWithoutFiller( domText ) {\n\tif ( startsWithFiller( domText ) ) {\n\t\treturn domText.data.slice( INLINE_FILLER_LENGTH );\n\t} else {\n\t\treturn domText.data;\n\t}\n}\n\n/**\n * Assign key observer which move cursor from the end of the inline filler to the beginning of it when\n * the left arrow is pressed, so the filler does not break navigation.\n *\n * @param {module:engine/view/view~View} view View controller instance we should inject quirks handling on.\n */\nexport function injectQuirksHandling( view ) {\n\tview.document.on( 'keydown', jumpOverInlineFiller );\n}\n\n// Move cursor from the end of the inline filler to the beginning of it when, so the filler does not break navigation.\nfunction jumpOverInlineFiller( evt, data ) {\n\tif ( data.keyCode == keyCodes.arrowleft ) {\n\t\tconst domSelection = data.domTarget.ownerDocument.defaultView.getSelection();\n\n\t\tif ( domSelection.rangeCount == 1 && domSelection.getRangeAt( 0 ).collapsed ) {\n\t\t\tconst domParent = domSelection.getRangeAt( 0 ).startContainer;\n\t\t\tconst domOffset = domSelection.getRangeAt( 0 ).startOffset;\n\n\t\t\tif ( startsWithFiller( domParent ) && domOffset <= INLINE_FILLER_LENGTH ) {\n\t\t\t\tdomSelection.collapse( domParent, 0 );\n\t\t\t}\n\t\t}\n\t}\n}\n","/**\n * @license Copyright (c) 2003-2020, CKSource - Frederico Knabben. All rights reserved.\n * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license\n */\n\n/**\n * @module utils/fastdiff\n */\n\n/**\n * Finds positions of the first and last change in the given string/array and generates a set of changes:\n *\n *\t\tfastDiff( '12a', '12xyza' );\n *\t\t// [ { index: 2, type: 'insert', values: [ 'x', 'y', 'z' ] } ]\n *\n *\t\tfastDiff( '12a', '12aa' );\n *\t\t// [ { index: 3, type: 'insert', values: [ 'a' ] } ]\n *\n *\t\tfastDiff( '12xyza', '12a' );\n *\t\t// [ { index: 2, type: 'delete', howMany: 3 } ]\n *\n *\t\tfastDiff( [ '1', '2', 'a', 'a' ], [ '1', '2', 'a' ] );\n *\t\t// [ { index: 3, type: 'delete', howMany: 1 } ]\n *\n *\t\tfastDiff( [ '1', '2', 'a', 'b', 'c', '3' ], [ '2', 'a', 'b' ] );\n *\t\t// [ { index: 0, type: 'insert', values: [ '2', 'a', 'b' ] }, { index: 3, type: 'delete', howMany: 6 } ]\n *\n * Passed arrays can contain any type of data, however to compare them correctly custom comparator function\n * should be passed as a third parameter:\n *\n *\t\tfastDiff( [ { value: 1 }, { value: 2 } ], [ { value: 1 }, { value: 3 } ], ( a, b ) => {\n *\t\t\treturn a.value === b.value;\n *\t\t} );\n *\t\t// [ { index: 1, type: 'insert', values: [ { value: 3 } ] }, { index: 2, type: 'delete', howMany: 1 } ]\n *\n * The resulted set of changes can be applied to the input in order to transform it into the output, for example:\n *\n *\t\tlet input = '12abc3';\n *\t\tconst output = '2ab';\n *\t\tconst changes = fastDiff( input, output );\n *\n *\t\tchanges.forEach( change => {\n *\t\t\tif ( change.type == 'insert' ) {\n *\t\t\t\tinput = input.substring( 0, change.index ) + change.values.join( '' ) + input.substring( change.index );\n *\t\t\t} else if ( change.type == 'delete' ) {\n *\t\t\t\tinput = input.substring( 0, change.index ) + input.substring( change.index + change.howMany );\n *\t\t\t}\n *\t\t} );\n *\n *\t\t// input equals output now\n *\n * or in case of arrays:\n *\n *\t\tlet input = [ '1', '2', 'a', 'b', 'c', '3' ];\n *\t\tconst output = [ '2', 'a', 'b' ];\n *\t\tconst changes = fastDiff( input, output );\n *\n *\t\tchanges.forEach( change => {\n *\t\t\tif ( change.type == 'insert' ) {\n *\t\t\t\tinput = input.slice( 0, change.index ).concat( change.values, input.slice( change.index ) );\n *\t\t\t} else if ( change.type == 'delete' ) {\n *\t\t\t\tinput = input.slice( 0, change.index ).concat( input.slice( change.index + change.howMany ) );\n *\t\t\t}\n *\t\t} );\n *\n *\t\t// input equals output now\n *\n * By passing `true` as the fourth parameter (`atomicChanges`) the output of this function will become compatible with\n * the {@link module:utils/diff~diff `diff()`} function:\n *\n *\t\tfastDiff( '12a', '12xyza' );\n *\t\t// [ 'equal', 'equal', 'insert', 'insert', 'insert', 'equal' ]\n *\n * The default output format of this function is compatible with the output format of\n * {@link module:utils/difftochanges~diffToChanges `diffToChanges()`}. The `diffToChanges()` input format is, in turn,\n * compatible with the output of {@link module:utils/diff~diff `diff()`}:\n *\n *\t\tconst a = '1234';\n *\t\tconst b = '12xyz34';\n *\n *\t\t// Both calls will return the same results (grouped changes format).\n *\t\tfastDiff( a, b );\n *\t\tdiffToChanges( diff( a, b ) );\n *\n *\t\t// Again, both calls will return the same results (atomic changes format).\n *\t\tfastDiff( a, b, null, true );\n *\t\tdiff( a, b );\n *\n *\n * @param {Array|String} a Input array or string.\n * @param {Array|String} b Input array or string.\n * @param {Function} [cmp] Optional function used to compare array values, by default `===` (strict equal operator) is used.\n * @param {Boolean} [atomicChanges=false] Whether an array of `inset|delete|equal` operations should\n * be returned instead of changes set. This makes this function compatible with {@link module:utils/diff~diff `diff()`}.\n * @returns {Array} Array of changes.\n */\nexport default function fastDiff( a, b, cmp, atomicChanges = false ) {\n\t// Set the comparator function.\n\tcmp = cmp || function( a, b ) {\n\t\treturn a === b;\n\t};\n\n\t// Convert the string (or any array-like object - eg. NodeList) to an array by using the slice() method because,\n\t// unlike Array.from(), it returns array of UTF-16 code units instead of the code points of a string.\n\t// One code point might be a surrogate pair of two code units. All text offsets are expected to be in code units.\n\t// See ckeditor/ckeditor5#3147.\n\t//\n\t// We need to make sure here that fastDiff() works identical to diff().\n\tif ( !Array.isArray( a ) ) {\n\t\ta = Array.prototype.slice.call( a );\n\t}\n\n\tif ( !Array.isArray( b ) ) {\n\t\tb = Array.prototype.slice.call( b );\n\t}\n\n\t// Find first and last change.\n\tconst changeIndexes = findChangeBoundaryIndexes( a, b, cmp );\n\n\t// Transform into changes array.\n\treturn atomicChanges ? changeIndexesToAtomicChanges( changeIndexes, b.length ) : changeIndexesToChanges( b, changeIndexes );\n}\n\n// Finds position of the first and last change in the given arrays. For example:\n//\n//\t\tconst indexes = findChangeBoundaryIndexes( [ '1', '2', '3', '4' ], [ '1', '3', '4', '2', '4' ] );\n//\t\tconsole.log( indexes ); // { firstIndex: 1, lastIndexOld: 3, lastIndexNew: 4 }\n//\n// The above indexes means that in the first array the modified part is `1[23]4` and in the second array it is `1[342]4`.\n// Based on such indexes, array with `insert`/`delete` operations which allows transforming first value into the second one\n// can be generated.\n//\n// @param {Array} arr1\n// @param {Array} arr2\n// @param {Function} cmp Comparator function.\n// @returns {Object}\n// @returns {Number} return.firstIndex Index of the first change in both values (always the same for both).\n// @returns {Number} result.lastIndexOld Index of the last common value in `arr1`.\n// @returns {Number} result.lastIndexNew Index of the last common value in `arr2`.\nfunction findChangeBoundaryIndexes( arr1, arr2, cmp ) {\n\t// Find the first difference between passed values.\n\tconst firstIndex = findFirstDifferenceIndex( arr1, arr2, cmp );\n\n\t// If arrays are equal return -1 indexes object.\n\tif ( firstIndex === -1 ) {\n\t\treturn { firstIndex: -1, lastIndexOld: -1, lastIndexNew: -1 };\n\t}\n\n\t// Remove the common part of each value and reverse them to make it simpler to find the last difference between them.\n\tconst oldArrayReversed = cutAndReverse( arr1, firstIndex );\n\tconst newArrayReversed = cutAndReverse( arr2, firstIndex );\n\n\t// Find the first difference between reversed values.\n\t// It should be treated as \"how many elements from the end the last difference occurred\".\n\t//\n\t// For example:\n\t//\n\t// \t\t\t\tinitial\t->\tafter cut\t-> reversed:\n\t// oldValue:\t'321ba'\t->\t'21ba'\t\t-> 'ab12'\n\t// newValue:\t'31xba'\t->\t'1xba'\t\t-> 'abx1'\n\t// lastIndex:\t\t\t\t\t\t\t-> 2\n\t//\n\t// So the last change occurred two characters from the end of the arrays.\n\tconst lastIndex = findFirstDifferenceIndex( oldArrayReversed, newArrayReversed, cmp );\n\n\t// Use `lastIndex` to calculate proper offset, starting from the beginning (`lastIndex` kind of starts from the end).\n\tconst lastIndexOld = arr1.length - lastIndex;\n\tconst lastIndexNew = arr2.length - lastIndex;\n\n\treturn { firstIndex, lastIndexOld, lastIndexNew };\n}\n\n// Returns a first index on which given arrays differ. If both arrays are the same, -1 is returned.\n//\n// @param {Array} arr1\n// @param {Array} arr2\n// @param {Function} cmp Comparator function.\n// @returns {Number}\nfunction findFirstDifferenceIndex( arr1, arr2, cmp ) {\n\tfor ( let i = 0; i < Math.max( arr1.length, arr2.length ); i++ ) {\n\t\tif ( arr1[ i ] === undefined || arr2[ i ] === undefined || !cmp( arr1[ i ], arr2[ i ] ) ) {\n\t\t\treturn i;\n\t\t}\n\t}\n\n\treturn -1; // Return -1 if arrays are equal.\n}\n\n// Returns a copy of the given array with `howMany` elements removed starting from the beginning and in reversed order.\n//\n// @param {Array} arr Array to be processed.\n// @param {Number} howMany How many elements from array beginning to remove.\n// @returns {Array} Shortened and reversed array.\nfunction cutAndReverse( arr, howMany ) {\n\treturn arr.slice( howMany ).reverse();\n}\n\n// Generates changes array based on change indexes from `findChangeBoundaryIndexes` function. This function will\n// generate array with 0 (no changes), 1 (deletion or insertion) or 2 records (insertion and deletion).\n//\n// @param {Array} newArray New array for which change indexes were calculated.\n// @param {Object} changeIndexes Change indexes object from `findChangeBoundaryIndexes` function.\n// @returns {Array.