`),t}(i.getData("text/plain"))),n=this._htmlDataProcessor.toView(n),this.fire("inputTransformation",{content:n,dataTransfer:i}),o.scrollToTheSelection()},{priority:"low"}),this.listenTo(this,"inputTransformation",(t,e)=>{if(!e.content.isEmpty){const t=this.editor.data,o=this.editor.model,i=t.toModel(e.content,"$clipboardHolder");if(0==i.childCount)return;o.insertContent(i)}},{priority:"low"}),this.listenTo(i,"copy",n,{priority:"low"}),this.listenTo(i,"cut",(e,o)=>{t.isReadOnly?o.preventDefault():n(e,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 t(e){let o="";if(e.is("text")||e.is("textProxy"))o=e.data;else if(e.is("img")&&e.hasAttribute("alt"))o=e.getAttribute("alt");else{let i=null;for(const n of e.getChildren()){const e=t(n);i&&(i.is("containerElement")||n.is("containerElement"))&&(Fh.includes(i.name)||Fh.includes(n.name)?o+="\n":o+="\n\n"),o+=e,i=n}}return o}(i.content))),"cut"==i.method&&t.model.deleteContent(e.selection)},{priority:"low"})}}class Lh{constructor(t){this.editor=t,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",t=>{this.isEnabled||t.stop()},{priority:"high"}),this.listenTo(t,"change:isReadOnly",(t,e,o)=>{o?this.forceDisabled("readOnlyMode"):this.clearForceDisabled("readOnlyMode")})}refresh(){this.isEnabled=!0}forceDisabled(t){this._disableStack.add(t),1==this._disableStack.size&&(this.on("set:isEnabled",jh,{priority:"highest"}),this.isEnabled=!1)}clearForceDisabled(t){this._disableStack.delete(t),0==this._disableStack.size&&(this.off("set:isEnabled",jh),this.refresh())}execute(){}destroy(){this.stopListening()}}function jh(t){t.return=!1,t.stop()}function*Hh(t,e){for(const o of e)o&&t.getAttributeProperties(o[0]).copyOnEnter&&(yield o)}ui(Lh,jn);class qh extends Lh{execute(){const t=this.editor.model,e=t.document;t.change(o=>{!function(t,e,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||t.deleteContent(o));if(n){const t=Hh(e.model.schema,o.getAttributes());Wh(e,r.start),e.setSelectionAttribute(t)}else{const i=!(r.start.isAtStart&&r.end.isAtEnd),n=s==a;t.deleteContent(o,{leaveUnmerged:i}),i&&(n?Wh(e,o.focus):e.setSelection(a,0))}}(this.editor.model,o,e.selection,t.schema),this.fire("afterExecute",{writer:o})})}}function Wh(t,e){t.split(e),t.setSelection(e.parent.nextSibling,0)}class Uh extends hs{constructor(t){super(t);const e=this.document;e.on("keydown",(t,o)=>{if(this.isEnabled&&o.keyCode==gr.enter){let i;e.once("enter",t=>i=t,{priority:"highest"}),e.fire("enter",new Xs(e,o.domEvent,{isSoft:o.shiftKey})),i&&i.stop.called&&t.stop()}})}observe(){}}class $h extends ed{static get pluginName(){return"Enter"}init(){const t=this.editor,e=t.editing.view,o=e.document;e.addObserver(Uh),t.commands.add("enter",new qh(t)),this.listenTo(o,"enter",(o,i)=>{i.preventDefault(),i.isSoft||(t.execute("enter"),e.scrollToTheSelection())},{priority:"low"})}}class Gh extends Lh{execute(){const t=this.editor.model,e=t.document;t.change(o=>{!function(t,e,o){const i=o.isCollapsed,n=o.getFirstRange(),r=n.start.parent,s=n.end.parent,a=r==s;if(i){const i=Hh(t.schema,o.getAttributes());Kh(t,e,n.end),e.removeSelectionAttribute(o.getAttributeKeys()),e.setSelectionAttribute(i)}else{const i=!(n.start.isAtStart&&n.end.isAtEnd);t.deleteContent(o,{leaveUnmerged:i}),a?Kh(t,e,o.focus):i&&e.setSelection(s,0)}}(t,o,e.selection),this.fire("afterExecute",{writer:o})})}refresh(){const t=this.editor.model,e=t.document;this.isEnabled=function(t,e){if(e.rangeCount>1)return!1;const o=e.anchor;if(!o||!t.checkChild(o,"softBreak"))return!1;const i=e.getFirstRange(),n=i.start.parent,r=i.end.parent;if((Jh(n,t)||Jh(r,t))&&n!==r)return!1;return!0}(t.schema,e.selection)}}function Kh(t,e,o){const i=e.createElement("softBreak");t.insertContent(i,o),e.setSelection(i,"after")}function Jh(t,e){return!t.is("rootElement")&&(e.isLimit(t)||Jh(t.parent,e))}class Yh extends ed{static get pluginName(){return"ShiftEnter"}init(){const t=this.editor,e=t.model.schema,o=t.conversion,i=t.editing.view,n=i.document;e.register("softBreak",{allowWhere:"$text",isInline:!0}),o.for("upcast").elementToElement({model:"softBreak",view:"br"}),o.for("downcast").elementToElement({model:"softBreak",view:(t,e)=>e.createEmptyElement("br")}),i.addObserver(Uh),t.commands.add("shiftEnter",new Gh(t)),this.listenTo(n,"enter",(e,o)=>{o.preventDefault(),o.isSoft&&(t.execute("shiftEnter"),i.scrollToTheSelection())},{priority:"low"})}}class Qh{constructor(t,e=20){this.model=t,this.size=0,this.limit=e,this.isLocked=!1,this._changeCallback=(t,e)=>{"transparent"!=e.type&&e!==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(t){this.size+=t,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(t){this.isLocked&&!t||(this._batch=null,this.size=0)}}class Xh extends Lh{constructor(t,e){super(t),this._buffer=new Qh(t.model,e),this._batches=new WeakSet}get buffer(){return this._buffer}destroy(){super.destroy(),this._buffer.destroy()}execute(t={}){const e=this.editor.model,o=e.document,i=t.text||"",n=i.length,r=t.range?e.createSelection(t.range):o.selection,s=t.resultRange;e.enqueueChange(this._buffer.batch,t=>{this._buffer.lock(),e.deleteContent(r),i&&e.insertContent(t.createText(i,o.selection.getAttributes()),r),s?t.setSelection(s):r.is("documentSelection")||t.setSelection(r),this._buffer.unlock(),this._buffer.input(n),this._batches.add(this._buffer.batch)})}}function Zh(t){let e=null;const o=t.model,i=t.editing.view,n=t.commands.get("input");function r(t){const r=o.document,a=i.document.isComposing,c=e&&e.isEqual(r.selection);e=null,n.isEnabled&&(function(t){if(t.ctrlKey)return!0;return tu.includes(t.keyCode)}(t)||r.selection.isCollapsed||a&&229===t.keyCode||!a&&229===t.keyCode&&c||s())}function s(){const t=n.buffer;t.lock(),o.enqueueChange(t.batch,()=>{o.deleteContent(o.document.selection)}),t.unlock()}hr.isAndroid?i.document.on("beforeinput",(t,e)=>r(e),{priority:"lowest"}):i.document.on("keydown",(t,e)=>r(e),{priority:"lowest"}),i.document.on("compositionstart",(function(){const t=o.document,e=1!==t.selection.rangeCount||t.selection.getFirstRange().isFlat;if(t.selection.isCollapsed||e)return;s()}),{priority:"lowest"}),i.document.on("compositionend",()=>{e=o.createSelection(o.document.selection)},{priority:"lowest"})}const tu=[fr("arrowUp"),fr("arrowRight"),fr("arrowDown"),fr("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 t=112;t<=135;t++)tu.push(t);function eu(t){if(t.newChildren.length-t.oldChildren.length!=1)return;const e=function(t,e){const o=[];let i,n=0;return t.forEach(t=>{"equal"==t?(r(),n++):"insert"==t?(s("insert")?i.values.push(e[n]):(r(),i={type:"insert",index:n,values:[e[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(t){return i&&i.type==t}}(Ur(t.oldChildren,t.newChildren,ou),t.newChildren);if(e.length>1)return;const o=e[0];return o.values[0]&&o.values[0].is("text")?o:void 0}function ou(t,e){return t&&t.is("text")&&e&&e.is("text")?t.data===e.data:t===e}class iu{constructor(t){this.editor=t,this.editing=this.editor.editing}handle(t,e){if(function(t){if(0==t.length)return!1;for(const e of t)if("children"===e.type&&!eu(e))return!0;return!1}(t))this._handleContainerChildrenMutations(t,e);else for(const o of t)this._handleTextMutation(o,e),this._handleTextNodeInsertion(o)}_handleContainerChildrenMutations(t,e){const o=function(t){const e=t.map(t=>t.node).reduce((t,e)=>t.getCommonAncestor(e,{includeSelf:!0}));if(!e)return;return e.getAncestors({includeSelf:!0,parentFirst:!0}).find(t=>t.is("containerElement")||t.is("rootElement"))}(t);if(!o)return;const i=this.editor.editing.view.domConverter.mapViewToDom(o),n=new is(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()),c=Array.from(s.getChildren()),l=a[a.length-1],d=c[c.length-1];l&&l.is("softBreak")&&d&&!d.is("softBreak")&&a.pop();const h=this.editor.model.schema;if(!nu(a,h)||!nu(c,h))return;const u=a.map(t=>t.is("text")?t.data:"@").join("").replace(/\u00A0/g," "),m=c.map(t=>t.is("text")?t.data:"@").join("").replace(/\u00A0/g," ");if(m===u)return;const g=Ur(m,u),{firstChangeAt:f,insertions:p,deletions:b}=ru(g);let w=null;e&&(w=this.editing.mapper.toModelRange(e.getFirstRange()));const k=u.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(t,e){if("text"!=t.type)return;const o=t.newText.replace(/\u00A0/g," "),i=t.oldText.replace(/\u00A0/g," ");if(i===o)return;const n=Ur(i,o),{firstChangeAt:r,insertions:s,deletions:a}=ru(n);let c=null;e&&(c=this.editing.mapper.toModelRange(e.getFirstRange()));const l=this.editing.view.createPositionAt(t.node,r),d=this.editing.mapper.toModelPosition(l),h=this.editor.model.createRange(d,d.getShiftedBy(a)),u=o.substr(r,s);this.editor.execute("input",{text:u,range:h,resultRange:c})}_handleTextNodeInsertion(t){if("children"!=t.type)return;const e=eu(t),o=this.editing.view.createPositionAt(t.node,e.index),i=this.editing.mapper.toModelPosition(o),n=e.values[0].data;this.editor.execute("input",{text:n.replace(/\u00A0/g," "),range:this.editor.model.createRange(i)})}}function nu(t,e){return t.every(t=>e.isInline(t))}function ru(t){let e=null,o=null;for(let i=0;i{new iu(t).handle(o,i)})}(t)}isInput(t){return this.editor.commands.get("input")._batches.has(t)}}class au extends Lh{constructor(t,e){super(t),this.direction=e,this._buffer=new Qh(t.model,t.config.get("typing.undoStep"))}get buffer(){return this._buffer}execute(t={}){const e=this.editor.model,o=e.document;e.enqueueChange(this._buffer.batch,i=>{this._buffer.lock();const n=i.createSelection(t.selection||o.selection),r=n.isCollapsed;if(n.isCollapsed&&e.modifySelection(n,{direction:this.direction,unit:t.unit}),this._shouldEntireContentBeReplacedWithParagraph(t.sequence||1))return void this._replaceEntireContentWithParagraph(i);if(n.isCollapsed)return;let s=0;n.getFirstRange().getMinimalFlatRanges().forEach(t=>{s+=tr(t.getWalker({singleCharacters:!0,ignoreElementEnd:!0,shallow:!0}))}),e.deleteContent(n,{doNotResetEntireContent:r,direction:this.direction}),this._buffer.input(s),i.setSelection(n),this._buffer.unlock()})}_shouldEntireContentBeReplacedWithParagraph(t){if(t>1)return!1;const e=this.editor.model,o=e.document.selection,i=e.schema.getLimitElement(o);if(!(o.isCollapsed&&o.containsEntireContent(i)))return!1;if(!e.schema.checkChild(i,"paragraph"))return!1;const n=i.getChild(0);return!n||"paragraph"!==n.name}_replaceEntireContentWithParagraph(t){const e=this.editor.model,o=e.document.selection,i=e.schema.getLimitElement(o),n=t.createElement("paragraph");t.remove(t.createRangeIn(i)),t.insert(n,i),t.setSelection(n,0)}}class cu extends hs{constructor(t){super(t);const e=t.document;let o=0;function i(t,o,i){let n;e.once("delete",t=>n=t,{priority:Number.POSITIVE_INFINITY}),e.fire("delete",new Xs(e,o,i)),n&&n.stop.called&&t.stop()}e.on("keyup",(t,e)=>{e.keyCode!=gr.delete&&e.keyCode!=gr.backspace||(o=0)}),e.on("keydown",(t,e)=>{const n={};if(e.keyCode==gr.delete)n.direction="forward",n.unit="character";else{if(e.keyCode!=gr.backspace)return;n.direction="backward",n.unit="codePoint"}const r=hr.isMac?e.altKey:e.ctrlKey;n.unit=r?"word":n.unit,n.sequence=++o,i(t,e.domEvent,n)}),hr.isAndroid&&e.on("beforeinput",(e,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=t.domConverter.domSelectionToView(r)),i(e,o.domEvent,n)})}observe(){}}class lu extends ed{static get pluginName(){return"Delete"}init(){const t=this.editor,e=t.editing.view,o=e.document;if(e.addObserver(cu),t.commands.add("forwardDelete",new au(t,"forward")),t.commands.add("delete",new au(t,"backward")),this.listenTo(o,"delete",(o,i)=>{const n={unit:i.unit,sequence:i.sequence};if(i.selectionToRemove){const e=t.model.createSelection(),o=[];for(const e of i.selectionToRemove.getRanges())o.push(t.editing.mapper.toModelRange(e));e.setTo(o),n.selection=e}t.execute("forward"==i.direction?"forwardDelete":"delete",n),i.preventDefault(),e.scrollToTheSelection()}),hr.isAndroid){let t=null;this.listenTo(o,"delete",(e,o)=>{const i=o.domTarget.ownerDocument.defaultView.getSelection();t={anchorNode:i.anchorNode,anchorOffset:i.anchorOffset,focusNode:i.focusNode,focusOffset:i.focusOffset}},{priority:"lowest"}),this.listenTo(o,"keyup",(e,o)=>{if(t){const e=o.domTarget.ownerDocument.defaultView.getSelection();e.collapse(t.anchorNode,t.anchorOffset),e.extend(t.focusNode,t.focusOffset),t=null}})}}}class du extends ed{static get requires(){return[su,lu]}static get pluginName(){return"Typing"}}const hu=new Map;function uu(t,e,o){let i=hu.get(t);i||(i=new Map,hu.set(t,i)),i.set(e,o)}function mu(t){return[t]}function gu(t,e,o={}){const i=function(t,e){const o=hu.get(t);return o&&o.has(e)?o.get(e):mu}(t.constructor,e.constructor);try{return i(t=t.clone(),e,o)}catch(t){throw t}}function fu(t,e,o){t=t.slice(),e=e.slice();const i=new pu(o.document,o.useRelations,o.forceWeakRemove);i.setOriginalOperations(t),i.setOriginalOperations(e);const n=i.originalOperations;if(0==t.length||0==e.length)return{operationsA:t,operationsB:e,originalOperations:n};const r=new WeakMap;for(const e of t)r.set(e,0);const s={nextBaseVersionA:t[t.length-1].baseVersion+1,nextBaseVersionB:e[e.length-1].baseVersion+1,originalOperationsACount:t.length,originalOperationsBCount:e.length};let a=0;for(;a{if(t.key===e.key){const i=t.range.getDifference(e.range).map(e=>new el(e,t.key,t.oldValue,t.newValue,0)),n=t.range.getIntersection(e.range);return n&&o.aIsStrong&&i.push(new el(n,e.key,e.newValue,t.newValue,0)),0==i.length?[new El(0)]:i}return[t]}),uu(el,nl,(t,e)=>{if(t.range.start.hasSameParentAs(e.position)&&t.range.containsPosition(e.position)){const o=t.range._getTransformedByInsertion(e.position,e.howMany,!e.shouldReceiveAttributes).map(e=>new el(e,t.key,t.oldValue,t.newValue,t.baseVersion));if(e.shouldReceiveAttributes){const i=ku(e,t.key,t.oldValue);i&&o.unshift(i)}return o}return t.range=t.range._getTransformedByInsertion(e.position,e.howMany,!1)[0],[t]}),uu(el,cl,(t,e)=>{const o=[];t.range.start.hasSameParentAs(e.deletionPosition)&&(t.range.containsPosition(e.deletionPosition)||t.range.start.isEqual(e.deletionPosition))&&o.push(qa._createFromPositionAndShift(e.graveyardPosition,1));const i=t.range._getTransformedByMergeOperation(e);return i.isCollapsed||o.push(i),o.map(e=>new el(e,t.key,t.oldValue,t.newValue,t.baseVersion))}),uu(el,il,(t,e)=>{return function(t,e){const o=qa._createFromPositionAndShift(e.sourcePosition,e.howMany);let i=null,n=[];o.containsRange(t,!0)?i=t:t.start.hasSameParentAs(o.start)?(n=t.getDifference(o),i=t.getIntersection(o)):n=[t];const r=[];for(let t of n){t=t._getTransformedByDeletion(e.sourcePosition,e.howMany);const o=e.getMovedRangeStart(),i=t.start.hasSameParentAs(o);t=t._getTransformedByInsertion(o,e.howMany,i),r.push(...t)}i&&r.push(i._getTransformedByMove(e.sourcePosition,e.targetPosition,e.howMany,!1)[0]);return r}(t.range,e).map(e=>new el(e,t.key,t.oldValue,t.newValue,t.baseVersion))}),uu(el,ll,(t,e)=>{if(t.range.end.isEqual(e.insertionPosition))return e.graveyardPosition||t.range.end.offset++,[t];if(t.range.start.hasSameParentAs(e.splitPosition)&&t.range.containsPosition(e.splitPosition)){const o=t.clone();return o.range=new qa(e.moveTargetPosition.clone(),t.range.end._getCombined(e.splitPosition,e.moveTargetPosition)),t.range.end=e.splitPosition.clone(),t.range.end.stickiness="toPrevious",[t,o]}return t.range=t.range._getTransformedBySplitOperation(e),[t]}),uu(nl,el,(t,e)=>{const o=[t];if(t.shouldReceiveAttributes&&t.position.hasSameParentAs(e.range.start)&&e.range.containsPosition(t.position)){const i=ku(t,e.key,e.newValue);i&&o.push(i)}return o}),uu(nl,nl,(t,e,o)=>t.position.isEqual(e.position)&&o.aIsStrong?[t]:(t.position=t.position._getTransformedByInsertOperation(e),[t])),uu(nl,il,(t,e)=>(t.position=t.position._getTransformedByMoveOperation(e),[t])),uu(nl,ll,(t,e)=>(t.position=t.position._getTransformedBySplitOperation(e),[t])),uu(nl,cl,(t,e)=>(t.position=t.position._getTransformedByMergeOperation(e),[t])),uu(rl,nl,(t,e)=>(t.oldRange&&(t.oldRange=t.oldRange._getTransformedByInsertOperation(e)[0]),t.newRange&&(t.newRange=t.newRange._getTransformedByInsertOperation(e)[0]),[t])),uu(rl,rl,(t,e,o)=>{if(t.name==e.name){if(!o.aIsStrong)return[new El(0)];t.oldRange=e.newRange?e.newRange.clone():null}return[t]}),uu(rl,cl,(t,e)=>(t.oldRange&&(t.oldRange=t.oldRange._getTransformedByMergeOperation(e)),t.newRange&&(t.newRange=t.newRange._getTransformedByMergeOperation(e)),[t])),uu(rl,il,(t,e,o)=>{if(t.oldRange&&(t.oldRange=qa._createFromRanges(t.oldRange._getTransformedByMoveOperation(e))),t.newRange){if(o.abRelation){const i=qa._createFromRanges(t.newRange._getTransformedByMoveOperation(e));if("left"==o.abRelation.side&&e.targetPosition.isEqual(t.newRange.start))return t.newRange.start.path=o.abRelation.path,t.newRange.end=i.end,[t];if("right"==o.abRelation.side&&e.targetPosition.isEqual(t.newRange.end))return t.newRange.start=i.start,t.newRange.end.path=o.abRelation.path,[t]}t.newRange=qa._createFromRanges(t.newRange._getTransformedByMoveOperation(e))}return[t]}),uu(rl,ll,(t,e,o)=>{if(t.oldRange&&(t.oldRange=t.oldRange._getTransformedBySplitOperation(e)),t.newRange){if(o.abRelation){const i=t.newRange._getTransformedBySplitOperation(e);return t.newRange.start.isEqual(e.splitPosition)&&o.abRelation.wasStartBeforeMergedElement?t.newRange.start=Ha._createAt(e.insertionPosition):t.newRange.start.isEqual(e.splitPosition)&&!o.abRelation.wasInLeftElement&&(t.newRange.start=Ha._createAt(e.moveTargetPosition)),t.newRange.end.isEqual(e.splitPosition)&&o.abRelation.wasInRightElement?t.newRange.end=Ha._createAt(e.moveTargetPosition):t.newRange.end.isEqual(e.splitPosition)&&o.abRelation.wasEndBeforeMergedElement?t.newRange.end=Ha._createAt(e.insertionPosition):t.newRange.end=i.end,[t]}t.newRange=t.newRange._getTransformedBySplitOperation(e)}return[t]}),uu(cl,nl,(t,e)=>(t.sourcePosition.hasSameParentAs(e.position)&&(t.howMany+=e.howMany),t.sourcePosition=t.sourcePosition._getTransformedByInsertOperation(e),t.targetPosition=t.targetPosition._getTransformedByInsertOperation(e),[t])),uu(cl,cl,(t,e,o)=>{if(t.sourcePosition.isEqual(e.sourcePosition)&&t.targetPosition.isEqual(e.targetPosition)){if(o.bWasUndone){const o=e.graveyardPosition.path.slice();return o.push(0),t.sourcePosition=new Ha(e.graveyardPosition.root,o),t.howMany=0,[t]}return[new El(0)]}if(t.sourcePosition.isEqual(e.sourcePosition)&&!t.targetPosition.isEqual(e.targetPosition)&&!o.bWasUndone&&"splitAtSource"!=o.abRelation){const i="$graveyard"==t.targetPosition.root.rootName,n="$graveyard"==e.targetPosition.root.rootName,r=i&&!n;if(n&&!i||!r&&o.aIsStrong){const o=e.targetPosition._getTransformedByMergeOperation(e),i=t.targetPosition._getTransformedByMergeOperation(e);return[new il(o,t.howMany,i,0)]}return[new El(0)]}return t.sourcePosition.hasSameParentAs(e.targetPosition)&&(t.howMany+=e.howMany),t.sourcePosition=t.sourcePosition._getTransformedByMergeOperation(e),t.targetPosition=t.targetPosition._getTransformedByMergeOperation(e),t.graveyardPosition.isEqual(e.graveyardPosition)&&o.aIsStrong||(t.graveyardPosition=t.graveyardPosition._getTransformedByMergeOperation(e)),[t]}),uu(cl,il,(t,e,o)=>{const i=qa._createFromPositionAndShift(e.sourcePosition,e.howMany);return"remove"==e.type&&!o.bWasUndone&&!o.forceWeakRemove&&t.deletionPosition.hasSameParentAs(e.sourcePosition)&&i.containsPosition(t.sourcePosition)?[new El(0)]:(t.sourcePosition.hasSameParentAs(e.targetPosition)&&(t.howMany+=e.howMany),t.sourcePosition.hasSameParentAs(e.sourcePosition)&&(t.howMany-=e.howMany),t.sourcePosition=t.sourcePosition._getTransformedByMoveOperation(e),t.targetPosition=t.targetPosition._getTransformedByMoveOperation(e),t.graveyardPosition.isEqual(e.targetPosition)||(t.graveyardPosition=t.graveyardPosition._getTransformedByMoveOperation(e)),[t])}),uu(cl,ll,(t,e,o)=>{if(e.graveyardPosition&&(t.graveyardPosition=t.graveyardPosition._getTransformedByDeletion(e.graveyardPosition,1),t.deletionPosition.isEqual(e.graveyardPosition)&&(t.howMany=e.howMany)),t.targetPosition.isEqual(e.splitPosition)){const i=0!=e.howMany,n=e.graveyardPosition&&t.deletionPosition.isEqual(e.graveyardPosition);if(i||n||"mergeTargetNotMoved"==o.abRelation)return t.sourcePosition=t.sourcePosition._getTransformedBySplitOperation(e),[t]}if(t.sourcePosition.isEqual(e.splitPosition)){if("mergeSourceNotMoved"==o.abRelation)return t.howMany=0,t.targetPosition=t.targetPosition._getTransformedBySplitOperation(e),[t];if("mergeSameElement"==o.abRelation||t.sourcePosition.offset>0)return t.sourcePosition=e.moveTargetPosition.clone(),t.targetPosition=t.targetPosition._getTransformedBySplitOperation(e),[t]}return t.sourcePosition.hasSameParentAs(e.splitPosition)&&(t.howMany=e.splitPosition.offset),t.sourcePosition=t.sourcePosition._getTransformedBySplitOperation(e),t.targetPosition=t.targetPosition._getTransformedBySplitOperation(e),[t]}),uu(il,nl,(t,e)=>{const o=qa._createFromPositionAndShift(t.sourcePosition,t.howMany)._getTransformedByInsertOperation(e,!1)[0];return t.sourcePosition=o.start,t.howMany=o.end.offset-o.start.offset,t.targetPosition.isEqual(e.position)||(t.targetPosition=t.targetPosition._getTransformedByInsertOperation(e)),[t]}),uu(il,il,(t,e,o)=>{const i=qa._createFromPositionAndShift(t.sourcePosition,t.howMany),n=qa._createFromPositionAndShift(e.sourcePosition,e.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=t.targetPosition.isEqual(e.targetPosition)&&a?t.targetPosition._getTransformedByDeletion(e.sourcePosition,e.howMany):t.targetPosition._getTransformedByMove(e.sourcePosition,e.targetPosition,e.howMany),_u(t,e)&&_u(e,t))return[e.getReversed()];if(i.containsPosition(e.targetPosition)&&i.containsRange(n,!0))return i.start=i.start._getTransformedByMove(e.sourcePosition,e.targetPosition,e.howMany),i.end=i.end._getTransformedByMove(e.sourcePosition,e.targetPosition,e.howMany),vu([i],r);if(n.containsPosition(t.targetPosition)&&n.containsRange(i,!0))return i.start=i.start._getCombined(e.sourcePosition,e.getMovedRangeStart()),i.end=i.end._getCombined(e.sourcePosition,e.getMovedRangeStart()),vu([i],r);const c=_i(t.sourcePosition.getParentPath(),e.sourcePosition.getParentPath());if("prefix"==c||"extension"==c)return i.start=i.start._getTransformedByMove(e.sourcePosition,e.targetPosition,e.howMany),i.end=i.end._getTransformedByMove(e.sourcePosition,e.targetPosition,e.howMany),vu([i],r);"remove"!=t.type||"remove"==e.type||o.aWasUndone||o.forceWeakRemove?"remove"==t.type||"remove"!=e.type||o.bWasUndone||o.forceWeakRemove||(s=!1):s=!0;const l=[],d=i.getDifference(n);for(const t of d){t.start=t.start._getTransformedByDeletion(e.sourcePosition,e.howMany),t.end=t.end._getTransformedByDeletion(e.sourcePosition,e.howMany);const o="same"==_i(t.start.getParentPath(),e.getMovedRangeStart().getParentPath()),i=t._getTransformedByInsertion(e.getMovedRangeStart(),e.howMany,o);l.push(...i)}const h=i.getIntersection(n);return null!==h&&s&&(h.start=h.start._getCombined(e.sourcePosition,e.getMovedRangeStart()),h.end=h.end._getCombined(e.sourcePosition,e.getMovedRangeStart()),0===l.length?l.push(h):1==l.length?n.start.isBefore(i.start)||n.start.isEqual(i.start)?l.unshift(h):l.push(h):l.splice(1,0,h)),0===l.length?[new El(t.baseVersion)]:vu(l,r)}),uu(il,ll,(t,e,o)=>{let i=t.targetPosition.clone();t.targetPosition.isEqual(e.insertionPosition)&&e.graveyardPosition&&"moveTargetAfter"!=o.abRelation||(i=t.targetPosition._getTransformedBySplitOperation(e));const n=qa._createFromPositionAndShift(t.sourcePosition,t.howMany);if(n.end.isEqual(e.insertionPosition))return e.graveyardPosition||t.howMany++,t.targetPosition=i,[t];if(n.start.hasSameParentAs(e.splitPosition)&&n.containsPosition(e.splitPosition)){let t=new qa(e.splitPosition,n.end);return t=t._getTransformedBySplitOperation(e),vu([new qa(n.start,e.splitPosition),t],i)}t.targetPosition.isEqual(e.splitPosition)&&"insertAtSource"==o.abRelation&&(i=e.moveTargetPosition),t.targetPosition.isEqual(e.insertionPosition)&&"insertBetween"==o.abRelation&&(i=t.targetPosition);const r=[n._getTransformedBySplitOperation(e)];if(e.graveyardPosition){const i=n.start.isEqual(e.graveyardPosition)||n.containsPosition(e.graveyardPosition);t.howMany>1&&i&&!o.aWasUndone&&r.push(qa._createFromPositionAndShift(e.insertionPosition,1))}return vu(r,i)}),uu(il,cl,(t,e,o)=>{const i=qa._createFromPositionAndShift(t.sourcePosition,t.howMany);if(e.deletionPosition.hasSameParentAs(t.sourcePosition)&&i.containsPosition(e.sourcePosition))if("remove"!=t.type||o.forceWeakRemove){if(1==t.howMany)return o.bWasUndone?(t.sourcePosition=e.graveyardPosition.clone(),t.targetPosition=t.targetPosition._getTransformedByMergeOperation(e),[t]):[new El(0)]}else if(!o.aWasUndone){const o=[];let i=e.graveyardPosition.clone(),n=e.targetPosition._getTransformedByMergeOperation(e);t.howMany>1&&(o.push(new il(t.sourcePosition,t.howMany-1,t.targetPosition,0)),i=i._getTransformedByMove(t.sourcePosition,t.targetPosition,t.howMany-1),n=n._getTransformedByMove(t.sourcePosition,t.targetPosition,t.howMany-1));const r=e.deletionPosition._getCombined(t.sourcePosition,t.targetPosition),s=new il(i,1,r,0),a=s.getMovedRangeStart().path.slice();a.push(0);const c=new Ha(s.targetPosition.root,a);n=n._getTransformedByMove(i,r,1);const l=new il(n,e.howMany,c,0);return o.push(s),o.push(l),o}const n=qa._createFromPositionAndShift(t.sourcePosition,t.howMany)._getTransformedByMergeOperation(e);return t.sourcePosition=n.start,t.howMany=n.end.offset-n.start.offset,t.targetPosition=t.targetPosition._getTransformedByMergeOperation(e),[t]}),uu(sl,nl,(t,e)=>(t.position=t.position._getTransformedByInsertOperation(e),[t])),uu(sl,cl,(t,e)=>t.position.isEqual(e.deletionPosition)?(t.position=e.graveyardPosition.clone(),t.position.stickiness="toNext",[t]):(t.position=t.position._getTransformedByMergeOperation(e),[t])),uu(sl,il,(t,e)=>(t.position=t.position._getTransformedByMoveOperation(e),[t])),uu(sl,sl,(t,e,o)=>{if(t.position.isEqual(e.position)){if(!o.aIsStrong)return[new El(0)];t.oldName=e.newName}return[t]}),uu(sl,ll,(t,e)=>{if("same"==_i(t.position.path,e.splitPosition.getParentPath())&&!e.graveyardPosition){const e=new sl(t.position.getShiftedBy(1),t.oldName,t.newName,0);return[t,e]}return t.position=t.position._getTransformedBySplitOperation(e),[t]}),uu(al,al,(t,e,o)=>{if(t.root===e.root&&t.key===e.key){if(!o.aIsStrong||t.newValue===e.newValue)return[new El(0)];t.oldValue=e.newValue}return[t]}),uu(ll,nl,(t,e)=>(t.splitPosition.hasSameParentAs(e.position)&&t.splitPosition.offset{if(!t.graveyardPosition&&!o.bWasUndone&&t.splitPosition.hasSameParentAs(e.sourcePosition)){const o=e.graveyardPosition.path.slice();o.push(0);const i=new Ha(e.graveyardPosition.root,o),n=ll.getInsertionPosition(new Ha(e.graveyardPosition.root,o)),r=new ll(i,0,null,0);return r.insertionPosition=n,t.splitPosition=t.splitPosition._getTransformedByMergeOperation(e),t.insertionPosition=ll.getInsertionPosition(t.splitPosition),t.graveyardPosition=r.insertionPosition.clone(),t.graveyardPosition.stickiness="toNext",[r,t]}return t.splitPosition.hasSameParentAs(e.deletionPosition)&&!t.splitPosition.isAfter(e.deletionPosition)&&t.howMany--,t.splitPosition.hasSameParentAs(e.targetPosition)&&(t.howMany+=e.howMany),t.splitPosition=t.splitPosition._getTransformedByMergeOperation(e),t.insertionPosition=ll.getInsertionPosition(t.splitPosition),t.graveyardPosition&&(t.graveyardPosition=t.graveyardPosition._getTransformedByMergeOperation(e)),[t]}),uu(ll,il,(t,e,o)=>{const i=qa._createFromPositionAndShift(e.sourcePosition,e.howMany);if(t.graveyardPosition){const n=i.start.isEqual(t.graveyardPosition)||i.containsPosition(t.graveyardPosition);if(!o.bWasUndone&&n){const o=t.splitPosition._getTransformedByMoveOperation(e),i=t.graveyardPosition._getTransformedByMoveOperation(e),n=i.path.slice();n.push(0);const r=new Ha(i.root,n);return[new il(o,t.howMany,r,0)]}t.graveyardPosition=t.graveyardPosition._getTransformedByMoveOperation(e)}if(t.splitPosition.hasSameParentAs(e.sourcePosition)&&i.containsPosition(t.splitPosition)){const o=e.howMany-(t.splitPosition.offset-e.sourcePosition.offset);return t.howMany-=o,t.splitPosition.hasSameParentAs(e.targetPosition)&&t.splitPosition.offset{if(t.splitPosition.isEqual(e.splitPosition)){if(!t.graveyardPosition&&!e.graveyardPosition)return[new El(0)];if(t.graveyardPosition&&e.graveyardPosition&&t.graveyardPosition.isEqual(e.graveyardPosition))return[new El(0)];if("splitBefore"==o.abRelation)return t.howMany=0,t.graveyardPosition=t.graveyardPosition._getTransformedBySplitOperation(e),[t]}if(t.graveyardPosition&&e.graveyardPosition&&t.graveyardPosition.isEqual(e.graveyardPosition)){const i="$graveyard"==t.splitPosition.root.rootName,n="$graveyard"==e.splitPosition.root.rootName,r=i&&!n;if(n&&!i||!r&&o.aIsStrong){const o=[];return e.howMany&&o.push(new il(e.moveTargetPosition,e.howMany,e.splitPosition,0)),t.howMany&&o.push(new il(t.splitPosition,t.howMany,t.moveTargetPosition,0)),o}return[new El(0)]}if(t.graveyardPosition&&(t.graveyardPosition=t.graveyardPosition._getTransformedBySplitOperation(e)),t.splitPosition.isEqual(e.insertionPosition)&&"splitBefore"==o.abRelation)return t.howMany++,[t];if(e.splitPosition.isEqual(t.insertionPosition)&&"splitBefore"==o.baRelation){const o=e.insertionPosition.path.slice();o.push(0);const i=new Ha(e.insertionPosition.root,o);return[t,new il(t.insertionPosition,1,i,0)]}return t.splitPosition.hasSameParentAs(e.splitPosition)&&t.splitPosition.offset0}addBatch(t){const e=this.editor.model.document.selection,o={ranges:e.hasOwnRange?Array.from(e.getRanges()):[],isBackward:e.isBackward};this._stack.push({batch:t,selection:o}),this.refresh()}clearStack(){this._stack=[],this.refresh()}_restoreSelection(t,e,o){const i=this.editor.model,n=i.document,r=[];for(const e of t){const t=xu(e,o).find(t=>t.start.root!=n.graveyard);t&&r.push(t)}r.length&&i.change(t=>{t.setSelection(r,{backward:e})})}_undo(t,e){const o=this.editor.model,i=o.document;this._createdBatches.add(e);const n=t.operations.slice().filter(t=>t.isDocumentOperation);n.reverse();for(const t of n){const n=t.baseVersion+1,r=Array.from(i.history.getOperations(n)),s=fu([t.getReversed()],r,{useRelations:!0,document:this.editor.model.document,padWithNoOps:!1,forceWeakRemove:!0}).operationsA;for(const n of s)e.addOperation(n),o.applyOperation(n),i.history.setOperationAsUndone(t,n)}}}function xu(t,e){const o=t.getTransformedByOperations(e);o.sort((t,e)=>t.start.isBefore(e.start)?-1:1);for(let t=1;te.batch==t):this._stack.length-1,o=this._stack.splice(e,1)[0],i=this.editor.model.createBatch("transparent");this.editor.model.enqueueChange(i,()=>{this._undo(o.batch,i);const t=this.editor.model.document.history.getOperations(o.batch.baseVersion);this._restoreSelection(o.selection.ranges,o.selection.isBackward,t),this.fire("revert",o.batch,i)}),this.refresh()}}class Au extends yu{execute(){const t=this._stack.pop(),e=this.editor.model.createBatch("transparent");this.editor.model.enqueueChange(e,()=>{const o=t.batch.operations[t.batch.operations.length-1].baseVersion+1,i=this.editor.model.document.history.getOperations(o);this._restoreSelection(t.selection.ranges,t.selection.isBackward,i),this._undo(t.batch,e)}),this.refresh()}}class Tu extends ed{static get pluginName(){return"UndoEditing"}constructor(t){super(t),this._batchRegistry=new WeakSet}init(){const t=this.editor;this._undoCommand=new Cu(t),this._redoCommand=new Au(t),t.commands.add("undo",this._undoCommand),t.commands.add("redo",this._redoCommand),this.listenTo(t.model,"applyOperation",(t,e)=>{const o=e[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",(t,e,o)=>{this._redoCommand.addBatch(o)}),t.keystrokes.set("CTRL+Z","undo"),t.keystrokes.set("CTRL+Y","redo"),t.keystrokes.set("CTRL+SHIFT+Z","redo")}}var Pu='',Su='';class Eu extends ed{init(){const t=this.editor,e=t.locale,o=t.t,i="ltr"==e.uiLanguageDirection?Pu:Su,n="ltr"==e.uiLanguageDirection?Su:Pu;this._addButton("undo",o("de"),"CTRL+Z",i),this._addButton("redo",o("df"),"CTRL+Y",n)}_addButton(t,e,o,i){const n=this.editor;n.ui.componentFactory.add(t,r=>{const s=n.commands.get(t),a=new zd(r);return a.set({label:e,icon:i,keystroke:o,tooltip:!0}),a.bind("isEnabled").to(s,"isEnabled"),this.listenTo(a,"execute",()=>{n.execute(t),n.editing.view.focus()}),a})}}class Ru extends ed{static get requires(){return[Tu,Eu]}static get pluginName(){return"Undo"}}class Iu{constructor(t){this.context=t}destroy(){this.stopListening()}static get isContextPlugin(){return!0}}ui(Iu,jn);class Vu extends Iu{static get pluginName(){return"PendingActions"}init(){this.set("hasAny",!1),this._actions=new mi({idProperty:"_id"}),this._actions.delegate("add","remove").to(this)}add(t){if("string"!=typeof t)throw new oi.b("pendingactions-add-invalid-message: The message must be a string.",this);const e=Object.create(jn);return e.set("message",t),this._actions.add(e),this.hasAny=!0,e}remove(t){this._actions.remove(t),this.hasAny=!!this._actions.length}get first(){return this._actions.get(0)}[Symbol.iterator](){return this._actions[Symbol.iterator]()}}class Ou{constructor(){const t=new window.FileReader;this._reader=t,this._data=void 0,this.set("loaded",0),t.onprogress=t=>{this.loaded=t.loaded}}get error(){return this._reader.error}get data(){return this._data}read(t){const e=this._reader;return this.total=t.size,new Promise((o,i)=>{e.onload=()=>{const t=e.result;this._data=t,o(t)},e.onerror=()=>{i("error")},e.onabort=()=>{i("aborted")},this._reader.readAsDataURL(t)})}abort(){this._reader.abort()}}ui(Ou,jn);class Nu extends ed{static get pluginName(){return"FileRepository"}static get requires(){return[Vu]}init(){this.loaders=new mi,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",(t,e)=>e?t/e*100:0)}getLoader(t){return this._loadersMap.get(t)||null}createLoader(t){if(!this.createUploadAdapter)return console.warn(Object(oi.a)("filerepository-no-upload-adapter: Upload adapter is not defined.")),null;const e=new Mu(Promise.resolve(t),this.createUploadAdapter);return this.loaders.add(e),this._loadersMap.set(t,e),t instanceof Promise&&e.file.then(t=>{this._loadersMap.set(t,e)}).catch(()=>{}),e.on("change:uploaded",()=>{let t=0;for(const e of this.loaders)t+=e.uploaded;this.uploaded=t}),e.on("change:uploadTotal",()=>{let t=0;for(const e of this.loaders)e.uploadTotal&&(t+=e.uploadTotal);this.uploadTotal=t}),e}destroyLoader(t){const e=t instanceof Mu?t:this.getLoader(t);e._destroy(),this.loaders.remove(e),this._loadersMap.forEach((t,o)=>{t===e&&this._loadersMap.delete(o)})}_updatePendingAction(){const t=this.editor.plugins.get(Vu);if(this.loaders.length){if(!this._pendingAction){const e=this.editor.t,o=t=>`${e("f")} ${parseInt(t)}%.`;this._pendingAction=t.add(o(this.uploadedPercent)),this._pendingAction.bind("message").to(this,"uploadedPercent",o)}}else t.remove(this._pendingAction),this._pendingAction=null}}ui(Nu,jn);class Mu{constructor(t,e){this.id=ti(),this._filePromiseWrapper=this._createFilePromiseWrapper(t),this._adapter=e(this),this._reader=new Ou,this.set("status","idle"),this.set("uploaded",0),this.set("uploadTotal",null),this.bind("uploadedPercent").to(this,"uploaded",this,"uploadTotal",(t,e)=>e?t/e*100:0),this.set("uploadResponse",null)}get file(){return this._filePromiseWrapper?this._filePromiseWrapper.promise.then(t=>this._filePromiseWrapper?t:null):Promise.resolve(null)}get data(){return this._reader.data}read(){if("idle"!=this.status)throw new oi.b("filerepository-read-wrong-status: You cannot call read if the status is different than idle.",this);return this.status="reading",this.file.then(t=>this._reader.read(t)).then(t=>(this.status="idle",t)).catch(t=>{if("aborted"===t)throw this.status="aborted","aborted";throw this.status="error",this._reader.error?this._reader.error:t})}upload(){if("idle"!=this.status)throw new oi.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(t=>(this.uploadResponse=t,this.status="idle",t)).catch(t=>{if("aborted"===this.status)throw"aborted";throw this.status="error",t})}abort(){const t=this.status;this.status="aborted",this._filePromiseWrapper.isFulfilled?"reading"==t?this._reader.abort():"uploading"==t&&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(t){const e={};return e.promise=new Promise((o,i)=>{e.rejecter=i,e.isFulfilled=!1,t.then(t=>{e.isFulfilled=!0,o(t)}).catch(t=>{e.isFulfilled=!0,i(t)})}),e}}ui(Mu,jn);const Bu="ckCsrfToken",zu=40,Fu="abcdefghijklmnopqrstuvwxyz0123456789";function Du(){let t=function(t){t=t.toLowerCase();const e=document.cookie.split(";");for(const o of e){const e=o.split("=");if(decodeURIComponent(e[0].trim().toLowerCase())===t)return decodeURIComponent(e[1])}return null}(Bu);var e,o;return t&&t.length==zu||(t=function(t){let e="";const o=new Uint8Array(t);window.crypto.getRandomValues(o);for(let t=0;t.5?i.toUpperCase():i}return e}(zu),e=Bu,o=t,document.cookie=encodeURIComponent(e)+"="+encodeURIComponent(o)+";path=/"),t}class Lu{constructor(t,e,o){this.loader=t,this.url=e,this.t=o}upload(){return this.loader.file.then(t=>new Promise((e,o)=>{this._initRequest(),this._initListeners(e,o,t),this._sendRequest(t)}))}abort(){this.xhr&&this.xhr.abort()}_initRequest(){const t=this.xhr=new XMLHttpRequest;t.open("POST",this.url,!0),t.responseType="json"}_initListeners(t,e,o){const i=this.xhr,n=this.loader,r=(0,this.t)("a")+` ${o.name}.`;i.addEventListener("error",()=>e(r)),i.addEventListener("abort",()=>e()),i.addEventListener("load",()=>{const o=i.response;if(!o||!o.uploaded)return e(o&&o.error&&o.error.message?o.error.message:r);t({default:o.url})}),i.upload&&i.upload.addEventListener("progress",t=>{t.lengthComputable&&(n.uploadTotal=t.total,n.uploaded=t.loaded)})}_sendRequest(t){const e=new FormData;e.append("upload",t),e.append("ckCsrfToken",Du()),this.xhr.send(e)}}class ju{static get pluginName(){return"BlockAutoformatEditing"}constructor(t,e,o){let i,n=null;"function"==typeof o?i=o:(n=t.commands.get(o),i=()=>{t.execute(o)}),t.model.document.on("change",(o,r)=>{if(n&&!n.isEnabled)return;if("transparent"==r.type)return;const s=Array.from(t.model.document.differ.getChanges()),a=s[0];if(1!=s.length||"insert"!==a.type||"$text"!=a.name||1!=a.length)return;const c=a.position.parent;if(!c.is("paragraph")||1!==c.childCount)return;const l=e.exec(c.getChild(0).data);l&&t.model.enqueueChange(t=>{const e=t.createPositionAt(c,0),o=t.createPositionAt(c,l[0].length),n=new tc(e,o);!1!==i({match:l})&&t.remove(n),n.detach()})})}}function Hu(t,e){let o=t.start;return{text:Array.from(t.getItems()).reduce((t,i)=>i.is("text")||i.is("textProxy")?t+i.data:(o=e.createPositionAfter(i),""),""),range:e.createRange(o,t.end)}}class qu{static get pluginName(){return"InlineAutoformatEditing"}constructor(t,e,o){let i,n,r,s;e instanceof RegExp?i=e:r=e,"string"==typeof o?n=o:s=o,r=r||(t=>{let e;const o=[],n=[];for(;null!==(e=i.exec(t))&&!(e&&e.length<4);){let{index:t,1:i,2:r,3:s}=e;const a=i+r+s;t+=e[0].length-a.length;const c=[t,t+i.length],l=[t+i.length+r.length,t+i.length+r.length+s.length];o.push(c),o.push(l),n.push([t+i.length,t+i.length+r.length])}return{remove:o,format:n}}),s=s||((e,o)=>{const i=t.model.schema.getValidRanges(o,n);for(const t of i)e.setAttribute(n,!0,t);e.removeSelectionAttribute(n)}),t.model.document.on("change",(e,o)=>{if("transparent"==o.type)return;const i=t.model,n=i.document.selection;if(!n.isCollapsed)return;const a=Array.from(i.document.differ.getChanges()),c=a[0];if(1!=a.length||"insert"!==c.type||"$text"!=c.name||1!=c.length)return;const l=n.focus,d=l.parent,{text:h,range:u}=Hu(i.createRange(i.createPositionAt(d,0),l),i),m=r(h),g=Wu(u.start,m.format,i),f=Wu(u.start,m.remove,i);g.length&&f.length&&i.enqueueChange(t=>{if(!1!==s(t,g))for(const e of f.reverse())t.remove(e)})})}}function Wu(t,e,o){return e.filter(t=>void 0!==t[0]&&void 0!==t[1]).map(e=>o.createRange(t.getShiftedBy(e[0]),t.getShiftedBy(e[1])))}function Uu(t,e){return(o,i)=>{if(!t.commands.get(e).isEnabled)return!1;const n=t.model.schema.getValidRanges(i,e);for(const t of n)o.setAttribute(e,!0,t);o.removeSelectionAttribute(e)}}class $u extends Lh{constructor(t,e){super(t),this.attributeKey=e}refresh(){const t=this.editor.model,e=t.document;this.value=this._getValueFromFirstAllowedNode(),this.isEnabled=t.schema.checkAttributeInSelection(e.selection,this.attributeKey)}execute(t={}){const e=this.editor.model,o=e.document.selection,i=void 0===t.forceValue?!this.value:t.forceValue;e.change(t=>{if(o.isCollapsed)i?t.setSelectionAttribute(this.attributeKey,!0):t.removeSelectionAttribute(this.attributeKey);else{const n=e.schema.getValidRanges(o.getRanges(),this.attributeKey);for(const e of n)i?t.setAttribute(this.attributeKey,i,e):t.removeAttribute(this.attributeKey,e)}})}_getValueFromFirstAllowedNode(){const t=this.editor.model,e=t.schema,o=t.document.selection;if(o.isCollapsed)return o.hasAttribute(this.attributeKey);for(const t of o.getRanges())for(const o of t.getItems())if(e.checkAttribute(o,this.attributeKey))return o.hasAttribute(this.attributeKey);return!1}}const Gu="bold";class Ku extends ed{static get pluginName(){return"BoldEditing"}init(){const t=this.editor;t.model.schema.extend("$text",{allowAttributes:Gu}),t.model.schema.setAttributeProperties(Gu,{isFormatting:!0,copyOnEnter:!0}),t.conversion.attributeToElement({model:Gu,view:"strong",upcastAlso:["b",t=>{const e=t.getStyle("font-weight");return e?"bold"==e||Number(e)>=600?{name:!0,styles:["font-weight"]}:void 0:null}]}),t.commands.add(Gu,new $u(t,Gu)),t.keystrokes.set("CTRL+B",Gu)}}var Ju='';const Yu="bold";class Qu extends ed{init(){const t=this.editor,e=t.t;t.ui.componentFactory.add(Yu,o=>{const i=t.commands.get(Yu),n=new zd(o);return n.set({label:e("g"),icon:Ju,keystroke:"CTRL+B",tooltip:!0,isToggleable:!0}),n.bind("isOn","isEnabled").to(i,"value","isEnabled"),this.listenTo(n,"execute",()=>{t.execute(Yu),t.editing.view.focus()}),n})}}const Xu="italic";class Zu extends ed{static get pluginName(){return"ItalicEditing"}init(){const t=this.editor;t.model.schema.extend("$text",{allowAttributes:Xu}),t.model.schema.setAttributeProperties(Xu,{isFormatting:!0,copyOnEnter:!0}),t.conversion.attributeToElement({model:Xu,view:"i",upcastAlso:["em",{styles:{"font-style":"italic"}}]}),t.commands.add(Xu,new $u(t,Xu)),t.keystrokes.set("CTRL+I",Xu)}}var tm='';const em="italic";class om extends ed{init(){const t=this.editor,e=t.t;t.ui.componentFactory.add(em,o=>{const i=t.commands.get(em),n=new zd(o);return n.set({label:e("i"),icon:tm,keystroke:"CTRL+I",tooltip:!0,isToggleable:!0}),n.bind("isOn","isEnabled").to(i,"value","isEnabled"),this.listenTo(n,"execute",()=>{t.execute(em),t.editing.view.focus()}),n})}}const im="superscript";class nm extends ed{static get pluginName(){return"SuperscriptEditing"}init(){const t=this.editor;t.model.schema.extend("$text",{allowAttributes:im}),t.model.schema.setAttributeProperties(im,{isFormatting:!0,copyOnEnter:!0}),t.conversion.attributeToElement({model:im,view:"sup",upcastAlso:[{styles:{"vertical-align":"super"}}]}),t.commands.add(im,new $u(t,im))}}var rm='';const sm="superscript";class am extends ed{init(){const t=this.editor,e=t.t;t.ui.componentFactory.add(sm,o=>{const i=t.commands.get(sm),n=new zd(o);return n.set({label:e("h"),icon:rm,tooltip:!0,isToggleable:!0}),n.bind("isOn","isEnabled").to(i,"value","isEnabled"),this.listenTo(n,"execute",()=>{t.execute(sm),t.editing.view.focus()}),n})}}const cm="subscript";class lm extends ed{static get pluginName(){return"SubscriptEditing"}init(){const t=this.editor;t.model.schema.extend("$text",{allowAttributes:cm}),t.model.schema.setAttributeProperties(cm,{isFormatting:!0,copyOnEnter:!0}),t.conversion.attributeToElement({model:cm,view:"sub",upcastAlso:[{styles:{"vertical-align":"sub"}}]}),t.commands.add(cm,new $u(t,cm))}}var dm='';const hm="subscript";class um extends ed{init(){const t=this.editor,e=t.t;t.ui.componentFactory.add(hm,o=>{const i=t.commands.get(hm),n=new zd(o);return n.set({label:e("j"),icon:dm,tooltip:!0,isToggleable:!0}),n.bind("isOn","isEnabled").to(i,"value","isEnabled"),this.listenTo(n,"execute",()=>{t.execute(hm),t.editing.view.focus()}),n})}}const mm="underline";class gm extends ed{static get pluginName(){return"UnderlineEditing"}init(){const t=this.editor;t.model.schema.extend("$text",{allowAttributes:mm}),t.model.schema.setAttributeProperties(mm,{isFormatting:!0,copyOnEnter:!0}),t.conversion.attributeToElement({model:mm,view:"u",upcastAlso:{styles:{"text-decoration":"underline"}}}),t.commands.add(mm,new $u(t,mm)),t.keystrokes.set("CTRL+U","underline")}}var fm='';const pm="underline";class bm extends ed{init(){const t=this.editor,e=t.t;t.ui.componentFactory.add(pm,o=>{const i=t.commands.get(pm),n=new zd(o);return n.set({label:e("m"),icon:fm,keystroke:"CTRL+U",tooltip:!0,isToggleable:!0}),n.bind("isOn","isEnabled").to(i,"value","isEnabled"),this.listenTo(n,"execute",()=>{t.execute(pm),t.editing.view.focus()}),n})}}const wm="strikethrough";class km extends ed{static get pluginName(){return"StrikethroughEditing"}init(){const t=this.editor;t.model.schema.extend("$text",{allowAttributes:wm}),t.model.schema.setAttributeProperties(wm,{isFormatting:!0,copyOnEnter:!0}),t.conversion.attributeToElement({model:wm,view:"s",upcastAlso:["del","strike",{styles:{"text-decoration":"line-through"}}]}),t.commands.add(wm,new $u(t,wm)),t.keystrokes.set("CTRL+SHIFT+X","strikethrough")}}var _m='';const vm="strikethrough";class ym extends ed{init(){const t=this.editor,e=t.t;t.ui.componentFactory.add(vm,o=>{const i=t.commands.get(vm),n=new zd(o);return n.set({label:e("l"),icon:_m,keystroke:"CTRL+SHIFT+X",tooltip:!0,isToggleable:!0}),n.bind("isOn","isEnabled").to(i,"value","isEnabled"),this.listenTo(n,"execute",()=>{t.execute(vm),t.editing.view.focus()}),n})}}const xm="code";class Cm extends ed{static get pluginName(){return"CodeEditing"}init(){const t=this.editor;t.model.schema.extend("$text",{allowAttributes:xm}),t.model.schema.setAttributeProperties(xm,{isFormatting:!0,copyOnEnter:!0}),t.conversion.attributeToElement({model:xm,view:"code",upcastAlso:{styles:{"word-wrap":"break-word"}}}),t.commands.add(xm,new $u(t,xm))}}var Am='';o(11);const Tm="code";class Pm extends ed{init(){const t=this.editor,e=t.t;t.ui.componentFactory.add(Tm,o=>{const i=t.commands.get(Tm),n=new zd(o);return n.set({label:e("k"),icon:Am,tooltip:!0,isToggleable:!0}),n.bind("isOn","isEnabled").to(i,"value","isEnabled"),this.listenTo(n,"execute",()=>{t.execute(Tm),t.editing.view.focus()}),n})}}function Sm(t){const e=t.next();return e.done?null:e.value}class Em extends Lh{refresh(){this.value=this._getValue(),this.isEnabled=this._checkEnabled()}execute(t={}){const e=this.editor.model,o=e.schema,i=e.document.selection,n=Array.from(i.getSelectedBlocks()),r=void 0===t.forceValue?!this.value:t.forceValue;e.change(t=>{if(r){const e=n.filter(t=>Rm(t)||Vm(o,t));this._applyQuote(t,e)}else this._removeQuote(t,n.filter(Rm))})}_getValue(){const t=Sm(this.editor.model.document.selection.getSelectedBlocks());return!(!t||!Rm(t))}_checkEnabled(){if(this.value)return!0;const t=this.editor.model.document.selection,e=this.editor.model.schema,o=Sm(t.getSelectedBlocks());return!!o&&Vm(e,o)}_removeQuote(t,e){Im(t,e).reverse().forEach(e=>{if(e.start.isAtStart&&e.end.isAtEnd)return void t.unwrap(e.start.parent);if(e.start.isAtStart){const o=t.createPositionBefore(e.start.parent);return void t.move(e,o)}e.end.isAtEnd||t.split(e.end);const o=t.createPositionAfter(e.end.parent);t.move(e,o)})}_applyQuote(t,e){const o=[];Im(t,e).reverse().forEach(e=>{let i=Rm(e.start);i||(i=t.createElement("blockQuote"),t.wrap(e,i)),o.push(i)}),o.reverse().reduce((e,o)=>e.nextSibling==o?(t.merge(t.createPositionAfter(e)),e):o)}}function Rm(t){return"blockQuote"==t.parent.name?t.parent:null}function Im(t,e){let o,i=0;const n=[];for(;i{if(t.endsWith("blockQuote")&&"blockQuote"==e.name)return!1}),t.conversion.elementToElement({model:"blockQuote",view:"blockquote"}),t.model.document.registerPostFixer(o=>{const i=t.model.document.differ.getChanges();for(const t of i)if("insert"==t.type){const i=t.position.nodeAfter;if(!i)continue;if(i.is("blockQuote")&&i.isEmpty)return o.remove(i),!0;if(i.is("blockQuote")&&!e.checkChild(t.position,i))return o.unwrap(i),!0;if(i.is("element")){const t=o.createRangeIn(i);for(const i of t.getItems())if(i.is("blockQuote")&&!e.checkChild(o.createPositionBefore(i),i))return o.unwrap(i),!0}}else if("remove"==t.type){const e=t.position.parent;if(e.is("blockQuote")&&e.isEmpty)return o.remove(e),!0}return!1})}afterInit(){const t=this.editor.commands.get("blockQuote");this.listenTo(this.editor.editing.view.document,"enter",(e,o)=>{const i=this.editor.model.document,n=i.selection.getLastPosition().parent;i.selection.isCollapsed&&n.isEmpty&&t.value&&(this.editor.execute("blockQuote"),this.editor.editing.view.scrollToTheSelection(),o.preventDefault(),e.stop())})}}var Nm='';o(47);class Mm extends ed{init(){const t=this.editor,e=t.t;t.ui.componentFactory.add("blockQuote",o=>{const i=t.commands.get("blockQuote"),n=new zd(o);return n.set({label:e("n"),icon:Nm,tooltip:!0,isToggleable:!0}),n.bind("isOn","isEnabled").to(i,"value","isEnabled"),this.listenTo(n,"execute",()=>{t.execute("blockQuote"),t.editing.view.focus()}),n})}}class Bm extends Lh{refresh(){const t=this.editor.model,e=Sm(t.document.selection.getSelectedBlocks());this.value=!!e&&e.is("paragraph"),this.isEnabled=!!e&&zm(e,t.schema)}execute(t={}){const e=this.editor.model,o=e.document;e.change(i=>{const n=(t.selection||o.selection).getSelectedBlocks();for(const t of n)!t.is("paragraph")&&zm(t,e.schema)&&i.rename(t,"paragraph")})}}function zm(t,e){return e.checkChild(t.parent,"paragraph")&&!e.isObject(t)}class Fm extends ed{static get pluginName(){return"Paragraph"}init(){const t=this.editor,e=t.model,o=t.data;t.commands.add("paragraph",new Bm(t)),e.schema.register("paragraph",{inheritAllFrom:"$block"}),t.conversion.elementToElement({model:"paragraph",view:"p"}),t.conversion.for("upcast").elementToElement({model:(t,e)=>Fm.paragraphLikeElements.has(t.name)?t.isEmpty?null:e.createElement("paragraph"):null,converterPriority:"low"}),o.upcastDispatcher.on("element",(t,e,o)=>{o.consumable.test(e.viewItem,{name:e.viewItem.name})&&Lm(e.viewItem,e.modelCursor,o.schema)&&Object.assign(e,Dm(e.viewItem,e.modelCursor,o))},{priority:"low"}),o.upcastDispatcher.on("text",(t,e,o)=>{e.modelRange||Lm(e.viewItem,e.modelCursor,o.schema)&&Object.assign(e,Dm(e.viewItem,e.modelCursor,o))},{priority:"lowest"}),e.document.registerPostFixer(t=>this._autoparagraphEmptyRoots(t)),t.data.on("ready",()=>{e.enqueueChange("transparent",t=>this._autoparagraphEmptyRoots(t))},{priority:"lowest"})}_autoparagraphEmptyRoots(t){const e=this.editor.model;for(const o of e.document.getRootNames()){const i=e.document.getRoot(o);if(i.isEmpty&&"$graveyard"!=i.rootName&&e.schema.checkChild(i,"paragraph"))return t.insertElement("paragraph",i),!0}}}function Dm(t,e,o){const i=o.writer.createElement("paragraph");return o.writer.insert(i,e),o.convertItem(t,o.writer.createPositionAt(i,0))}function Lm(t,e,o){const i=o.createContext(e);return!!o.checkChild(i,"paragraph")&&!!o.checkChild(i.push("paragraph"),t)}Fm.paragraphLikeElements=new Set(["blockquote","dd","div","dt","h1","h2","h3","h4","h5","h6","li","p","td"]);class jm extends Lh{constructor(t,e){super(t),this.modelElements=e}refresh(){const t=Sm(this.editor.model.document.selection.getSelectedBlocks());this.value=!!t&&this.modelElements.includes(t.name)&&t.name,this.isEnabled=!!t&&this.modelElements.some(e=>Hm(t,e,this.editor.model.schema))}execute(t){const e=this.editor.model,o=e.document,i=t.value;e.change(t=>{const n=Array.from(o.selection.getSelectedBlocks()).filter(t=>Hm(t,i,e.schema));for(const e of n)e.is(i)||t.rename(e,i)})}}function Hm(t,e,o){return o.checkChild(t.parent,e)&&!o.isObject(t)}const qm="paragraph";class Wm extends ed{static get pluginName(){return"HeadingEditing"}constructor(t){super(t),t.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[Fm]}init(){const t=this.editor,e=t.config.get("heading.options"),o=[];for(const i of e)i.model!==qm&&(t.model.schema.register(i.model,{inheritAllFrom:"$block"}),t.conversion.elementToElement(i),o.push(i.model));this._addDefaultH1Conversion(t),t.commands.add("heading",new jm(t,o))}afterInit(){const t=this.editor,e=t.commands.get("enter"),o=t.config.get("heading.options");e&&this.listenTo(e,"afterExecute",(e,i)=>{const n=t.model.document.selection.getFirstPosition().parent;o.some(t=>n.is(t.model))&&!n.is(qm)&&0===n.childCount&&i.writer.rename(n,qm)})}_addDefaultH1Conversion(t){t.conversion.for("upcast").elementToElement({model:"heading1",view:"h1",converterPriority:ei.get("low")+1})}}class Um{constructor(t,e){e&&Bn(this,e),t&&this.set(t)}}function $m(t){const e=t.t,o={Paragraph:e("c"),"Heading 1":e("o"),"Heading 2":e("p"),"Heading 3":e("q"),"Heading 4":e("r"),"Heading 5":e("s"),"Heading 6":e("t")};return t.config.get("heading.options").map(t=>{const e=o[t.title];return e&&e!=t.title&&(t.title=e),t})}ui(Um,jn);o(12);class Gm extends ed{init(){const t=this.editor,e=t.t,o=$m(t),i=e("dy"),n=e("dz");t.ui.componentFactory.add("heading",e=>{const r={},s=new mi,a=t.commands.get("heading"),c=t.commands.get("paragraph"),l=[a];for(const t of o){const e={type:"button",model:new Um({label:t.title,class:t.class,withText:!0})};"paragraph"===t.model?(e.model.bind("isOn").to(c,"value"),e.model.set("commandName","paragraph"),l.push(c)):(e.model.bind("isOn").to(a,"value",e=>e===t.model),e.model.set({commandName:"heading",commandValue:t.model})),s.add(e),r[t.model]=t.title}const d=sh(e);return ah(d,s),d.buttonView.set({isOn:!1,withText:!0,tooltip:n}),d.extendTemplate({attributes:{class:["ck-heading-dropdown"]}}),d.bind("isEnabled").toMany(l,"isEnabled",(...t)=>t.some(t=>t)),d.buttonView.bind("label").to(a,"value",c,"value",(t,e)=>{const o=t||e&&"paragraph";return r[o]?r[o]:i}),this.listenTo(d,"execute",e=>{t.execute(e.source.commandName,e.source.commandValue?{value:e.source.commandValue}:void 0),t.editing.view.focus()}),d})}}class Km extends hs{observe(t){this.listenTo(t,"load",(t,e)=>{"IMG"==e.target.tagName&&this._fireEvents(e)},{useCapture:!0})}_fireEvents(t){this.isEnabled&&(this.document.fire("layoutChanged"),this.document.fire("imageLoaded",t))}}class Jm{constructor(){this._stack=[]}add(t,e){const o=this._stack,i=o[0];this._insertDescriptor(t);const n=o[0];i===n||Ym(i,n)||this.fire("change:top",{oldDescriptor:i,newDescriptor:n,writer:e})}remove(t,e){const o=this._stack,i=o[0];this._removeDescriptor(t);const n=o[0];i===n||Ym(i,n)||this.fire("change:top",{oldDescriptor:i,newDescriptor:n,writer:e})}_insertDescriptor(t){const e=this._stack,o=e.findIndex(e=>e.id===t.id);if(Ym(t,e[o]))return;o>-1&&e.splice(o,1);let i=0;for(;e[i]&&Qm(e[i],t);)i++;e.splice(i,0,t)}_removeDescriptor(t){const e=this._stack,o=e.findIndex(e=>e.id===t);o>-1&&e.splice(o,1)}}function Ym(t,e){return t&&e&&t.priority==e.priority&&Xm(t.classes)==Xm(e.classes)}function Qm(t,e){return t.priority>e.priority||!(t.priorityXm(e.classes)}function Xm(t){return Array.isArray(t)?t.sort().join(","):t}ui(Jm,ri);var Zm='';const tg="ck-widget",eg="ck-widget_selected";function og(t){return!!t.is("element")&&!!t.getCustomProperty("widget")}function ig(t,e,o={}){return hr.isEdge||e.setAttribute("contenteditable","false",t),e.addClass(tg,t),e.setCustomProperty("widget",!0,t),t.getFillerOffset=ag,o.label&&function(t,e,o){o.setCustomProperty("widgetLabel",e,t)}(t,o.label,e),o.hasSelectionHandle&&function(t,e){const o=e.createUIElement("div",{class:"ck ck-widget__selection-handle"},(function(t){const e=this.toDomElement(t),o=new Md;return o.set("content",Zm),o.render(),e.appendChild(o.element),e}));e.insert(e.createPositionAt(t,0),o),e.addClass(["ck-widget_with-selection-handle"],t)}(t,e),function(t,e,o,i){const n=new Jm;n.on("change:top",(e,n)=>{n.oldDescriptor&&i(t,n.oldDescriptor,n.writer),n.newDescriptor&&o(t,n.newDescriptor,n.writer)}),e.setCustomProperty("addHighlight",(t,e,o)=>n.add(e,o),t),e.setCustomProperty("removeHighlight",(t,e,o)=>n.remove(e,o),t)}(t,e,(t,e,o)=>o.addClass(i(e.classes),t),(t,e,o)=>o.removeClass(i(e.classes),t)),t;function i(t){return Array.isArray(t)?t:[t]}}function ng(t){const e=t.getCustomProperty("widgetLabel");return e?"function"==typeof e?e():e:""}function rg(t,e){return e.addClass(["ck-editor__editable","ck-editor__nested-editable"],t),hr.isEdge||(e.setAttribute("contenteditable",t.isReadOnly?"false":"true",t),t.on("change:isReadOnly",(o,i,n)=>{e.setAttribute("contenteditable",n?"false":"true",t)})),t.on("change:isFocused",(o,i,n)=>{n?e.addClass("ck-editor__nested-editable_focused",t):e.removeClass("ck-editor__nested-editable_focused",t)}),t}function sg(t,e){const o=t.getSelectedElement();if(o&&e.schema.isBlock(o))return e.createPositionAfter(o);const i=t.getSelectedBlocks().next().value;if(i){if(i.isEmpty)return e.createPositionAt(i,0);const o=e.createPositionAfter(i);return t.focus.isTouching(o)?o:e.createPositionBefore(i)}return t.focus}function ag(){return null}function cg(t){const e=t.getSelectedElement();return e&&function(t){return!!t.getCustomProperty("image")&&og(t)}(e)?e:null}function lg(t){return!!t&&t.is("image")}function dg(t,e,o={}){const i=t.createElement("image",o),n=sg(e.document.selection,e);e.insertContent(i,n),i.parent&&t.setSelection(i,"on")}function hg(t){const e=t.schema,o=t.document.selection;return function(t,e,o){const i=function(t,e){const o=sg(t,e).parent;if(o.isEmpty&&!o.is("$root"))return o.parent;return o}(t,o);return e.checkChild(i,"image")}(o,e,t)&&!function(t,e){const o=t.getSelectedElement();return o&&e.isObject(o)}(o,e)&&function(t){return[...t.focus.getAncestors()].every(t=>!t.is("image"))}(o)}function ug(t){return Array.from(t.getChildren()).find(t=>t.is("img"))}function mg(t){return o=>{o.on(`attribute:${t}:image`,e)};function e(t,e,o){if(!o.consumable.consume(e.item,t.name))return;const i=o.writer,n=ug(o.mapper.toViewElement(e.item));null!==e.attributeNewValue?i.setAttribute(e.attributeKey,e.attributeNewValue,n):i.removeAttribute(e.attributeKey,n)}}class gg extends Lh{refresh(){this.isEnabled=hg(this.editor.model)}execute(t){const e=this.editor.model;e.change(o=>{const i=Array.isArray(t.source)?t.source:[t.source];for(const t of i)dg(o,e,{src:t})})}}class fg extends ed{static get pluginName(){return"ImageEditing"}init(){const t=this.editor,e=t.model.schema,o=t.t,i=t.conversion;t.editing.view.addObserver(Km),e.register("image",{isObject:!0,isBlock:!0,allowWhere:"$block",allowAttributes:["alt","src","srcset"]}),i.for("dataDowncast").elementToElement({model:"image",view:(t,e)=>pg(e)}),i.for("editingDowncast").elementToElement({model:"image",view:(t,e)=>(function(t,e,o){return e.setCustomProperty("image",!0,t),ig(t,e,{label:function(){const e=ug(t).getAttribute("alt");return e?`${e} ${o}`:o}})})(pg(e),e,o("dx"))}),i.for("downcast").add(mg("src")).add(mg("alt")).add(function(){return e=>{e.on("attribute:srcset:image",t)};function t(t,e,o){if(!o.consumable.consume(e.item,t.name))return;const i=o.writer,n=ug(o.mapper.toViewElement(e.item));if(null===e.attributeNewValue){const t=e.attributeOldValue;t.data&&(i.removeAttribute("srcset",n),i.removeAttribute("sizes",n),t.width&&i.removeAttribute("width",n))}else{const t=e.attributeNewValue;t.data&&(i.setAttribute("srcset",t.data,n),i.setAttribute("sizes","100vw",n),t.width&&i.setAttribute("width",t.width,n))}}}()),i.for("upcast").elementToElement({view:{name:"img",attributes:{src:!0}},model:(t,e)=>e.createElement("image",{src:t.getAttribute("src")})}).attributeToAttribute({view:{name:"img",key:"alt"},model:"alt"}).attributeToAttribute({view:{name:"img",key:"srcset"},model:{key:"srcset",value:t=>{const e={data:t.getAttribute("srcset")};return t.hasAttribute("width")&&(e.width=t.getAttribute("width")),e}}}).add(function(){return e=>{e.on("element:figure",t)};function t(t,e,o){if(!o.consumable.test(e.viewItem,{name:!0,classes:"image"}))return;const i=ug(e.viewItem);if(!i||!i.hasAttribute("src")||!o.consumable.test(i,{name:!0}))return;const n=o.convertItem(i,e.modelCursor),r=Sm(n.modelRange.getItems());r&&(o.convertChildren(e.viewItem,o.writer.createPositionAt(r,0)),e.modelRange=n.modelRange,e.modelCursor=n.modelCursor)}}()),t.commands.add("imageInsert",new gg(t))}}function pg(t){const e=t.createEmptyElement("img"),o=t.createContainerElement("figure",{class:"image"});return t.insert(t.createPositionAt(o,0),e),o}class bg extends Zs{constructor(t){super(t),this.domEventType="mousedown"}onDomEvent(t){this.fire(t.type,t)}}o(50);const wg=pr("Ctrl+A");class kg extends ed{static get pluginName(){return"Widget"}init(){const t=this.editor.editing.view,e=t.document;this._previouslySelected=new Set,this.editor.editing.downcastDispatcher.on("selection",(t,e,o)=>{this._clearPreviouslySelectedWidgets(o.writer);const i=o.writer,n=i.document.selection,r=n.getSelectedElement();let s=null;for(const t of n.getRanges())for(const e of t){const t=e.item;og(t)&&!_g(t,s)&&(i.addClass(eg,t),this._previouslySelected.add(t),s=t,t==r&&i.setSelection(n.getRanges(),{fake:!0,label:ng(r)}))}},{priority:"low"}),t.addObserver(bg),this.listenTo(e,"mousedown",(...t)=>this._onMousedown(...t)),this.listenTo(e,"keydown",(...t)=>this._onKeydown(...t),{priority:"high"}),this.listenTo(e,"delete",(t,e)=>{this._handleDelete("forward"==e.direction)&&(e.preventDefault(),t.stop())},{priority:"high"})}_onMousedown(t,e){const o=this.editor,i=o.editing.view,n=i.document;let r=e.target;if(function(t){for(;t;){if(t.is("editableElement")&&!t.is("rootElement"))return!0;if(og(t))return!1;t=t.parent}return!1}(r)){if(hr.isSafari&&e.domEvent.detail>=3){const t=o.editing.mapper.toModelElement(r);this.editor.model.change(o=>{e.preventDefault(),o.setSelection(t,"in")})}return}if(!og(r)&&(r=r.findAncestor(og),!r))return;e.preventDefault(),n.isFocused||i.focus();const s=o.editing.mapper.toModelElement(r);this._setSelectionOverElement(s)}_onKeydown(t,e){const o=e.keyCode,i="ltr"===this.editor.locale.contentLanguageDirection,n=o==gr.arrowdown||o==gr[i?"arrowright":"arrowleft"];let r=!1;!function(t){return t==gr.arrowright||t==gr.arrowleft||t==gr.arrowup||t==gr.arrowdown}(o)?!function(t){return fr(t)==wg}(e)?o===gr.enter&&(r=this._handleEnterKey(e.shiftKey)):r=this._selectAllNestedEditableContent()||this._selectAllContent():r=this._handleArrowKeys(n),r&&(e.preventDefault(),t.stop())}_handleDelete(t){if(this.editor.isReadOnly)return;const e=this.editor.model.document.selection;if(!e.isCollapsed)return;const o=this._getObjectElementNextToSelection(t);return o?(this.editor.model.change(t=>{let i=e.anchor.parent;for(;i.isEmpty;){const e=i;i=e.parent,t.remove(e)}this._setSelectionOverElement(o)}),!0):void 0}_handleArrowKeys(t){const e=this.editor.model,o=e.schema,i=e.document.selection,n=i.getSelectedElement();if(n&&o.isObject(n)){const n=t?i.getLastPosition():i.getFirstPosition(),r=o.getNearestSelectionRange(n,t?"forward":"backward");return r&&e.change(t=>{t.setSelection(r)}),!0}if(!i.isCollapsed)return;const r=this._getObjectElementNextToSelection(t);return r&&o.isObject(r)?(this._setSelectionOverElement(r),!0):void 0}_handleEnterKey(t){const e=this.editor.model,o=e.document.selection.getSelectedElement();if(i=o,n=e.schema,i&&n.isObject(i)&&!n.isInline(i))return e.change(i=>{let n=i.createPositionAt(o,t?"before":"after");const r=i.createElement("paragraph");if(e.schema.isBlock(o.parent)){const t=e.schema.findAllowedParent(n,r);n=i.split(n,t).position}i.insert(r,n),i.setSelection(r,"in")}),!0;var i,n}_selectAllNestedEditableContent(){const t=this.editor.model,e=t.document.selection,o=t.schema.getLimitElement(e);return e.getFirstRange().root!=o&&(t.change(t=>{t.setSelection(t.createRangeIn(o))}),!0)}_selectAllContent(){const t=this.editor.model,e=this.editor.editing,o=e.view.document.selection.getSelectedElement();if(o&&og(o)){const i=e.mapper.toModelElement(o.parent);return t.change(t=>{t.setSelection(t.createRangeIn(i))}),!0}return!1}_setSelectionOverElement(t){this.editor.model.change(e=>{e.setSelection(e.createRangeOn(t))})}_getObjectElementNextToSelection(t){const e=this.editor.model,o=e.schema,i=e.document.selection,n=e.createSelection(i);e.modifySelection(n,{direction:t?"forward":"backward"});const r=t?n.focus.nodeBefore:n.focus.nodeAfter;return r&&o.isObject(r)?r:null}_clearPreviouslySelectedWidgets(t){for(const e of this._previouslySelected)t.removeClass(eg,e);this._previouslySelected.clear()}}function _g(t,e){return!!e&&Array.from(t.getAncestors()).includes(e)}class vg extends Lh{refresh(){const t=this.editor.model.document.selection.getSelectedElement();this.isEnabled=lg(t),lg(t)&&t.hasAttribute("alt")?this.value=t.getAttribute("alt"):this.value=!1}execute(t){const e=this.editor.model,o=e.document.selection.getSelectedElement();e.change(e=>{e.setAttribute("alt",t.newValue,o)})}}class yg extends ed{static get pluginName(){return"ImageTextAlternativeEditing"}init(){this.editor.commands.add("imageTextAlternative",new vg(this.editor))}}o(52);class xg extends Cd{constructor(t){super(t),this.set("text"),this.set("for"),this.id=`ck-editor__label_${ti()}`;const e=this.bindTemplate;this.setTemplate({tag:"label",attributes:{class:["ck","ck-label"],id:this.id,for:e.to("for")},children:[{text:e.to("text")}]})}}o(54);class Cg extends Cd{constructor(t,e){super(t);const o=`ck-input-${ti()}`,i=`ck-status-${ti()}`;this.set("label"),this.set("value"),this.set("isReadOnly",!1),this.set("errorText",null),this.set("infoText",null),this.labelView=this._createLabelView(o),this.inputView=this._createInputView(e,o,i),this.statusView=this._createStatusView(i),this.bind("_statusText").to(this,"errorText",this,"infoText",(t,e)=>t||e);const n=this.bindTemplate;this.setTemplate({tag:"div",attributes:{class:["ck","ck-labeled-input",n.if("isReadOnly","ck-disabled")]},children:[this.labelView,this.inputView,this.statusView]})}_createLabelView(t){const e=new xg(this.locale);return e.for=t,e.bind("text").to(this,"label"),e}_createInputView(t,e,o){const i=new t(this.locale,o);return i.id=e,i.ariaDescribedById=o,i.bind("value").to(this),i.bind("isReadOnly").to(this),i.bind("hasError").to(this,"errorText",t=>!!t),i.on("input",()=>{this.errorText=null}),i}_createStatusView(t){const e=new Cd(this.locale),o=this.bindTemplate;return e.setTemplate({tag:"div",attributes:{class:["ck","ck-labeled-input__status",o.if("errorText","ck-labeled-input__status_error"),o.if("_statusText","ck-hidden",t=>!t)],id:t,role:o.if("errorText","alert")},children:[{text:o.to("_statusText")}]}),e}select(){this.inputView.select()}focus(){this.inputView.focus()}}o(56);class Ag extends Cd{constructor(t){super(t),this.set("value"),this.set("id"),this.set("placeholder"),this.set("isReadOnly",!1),this.set("hasError",!1),this.set("ariaDescribedById");const e=this.bindTemplate;this.setTemplate({tag:"input",attributes:{type:"text",class:["ck","ck-input","ck-input-text",e.if("hasError","ck-error")],id:e.to("id"),placeholder:e.to("placeholder"),readonly:e.to("isReadOnly"),"aria-invalid":e.if("hasError",!0),"aria-describedby":e.to("ariaDescribedById")},on:{input:e.to("input")}})}render(){super.render();const t=t=>{this.element.value=t||0===t?t:""};t(this.value),this.on("change:value",(e,o,i)=>{t(i)})}select(){this.element.select()}focus(){this.element.focus()}}function Tg({view:t}){t.listenTo(t.element,"submit",(e,o)=>{o.preventDefault(),t.fire("submit")},{useCapture:!0})}var Pg='',Sg='';o(58);class Eg extends Cd{constructor(t){super(t);const e=this.locale.t;this.focusTracker=new Fd,this.keystrokes=new Yl,this.labeledInput=this._createLabeledInputView(),this.saveButtonView=this._createButton(e("cv"),Pg,"ck-button-save"),this.saveButtonView.type="submit",this.cancelButtonView=this._createButton(e("cw"),Sg,"ck-button-cancel","cancel"),this._focusables=new id,this._focusCycler=new Ud({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),Tg({view:this}),[this.labeledInput,this.saveButtonView,this.cancelButtonView].forEach(t=>{this._focusables.add(t),this.focusTracker.add(t.element)})}_createButton(t,e,o,i){const n=new zd(this.locale);return n.set({label:t,icon:e,tooltip:!0}),n.extendTemplate({attributes:{class:o}}),i&&n.delegate("execute").to(this,i),n}_createLabeledInputView(){const t=this.locale.t,e=new Cg(this.locale,Ag);return e.label=t("ej"),e.inputView.placeholder=t("ej"),e}}var Rg='';function Ig(t){const e=t.editing.view,o=Id.defaultPositions;return{target:e.domConverter.viewToDom(e.document.selection.getSelectedElement()),positions:[o.northArrowSouth,o.northArrowSouthWest,o.northArrowSouthEast,o.southArrowNorth,o.southArrowNorthWest,o.southArrowNorthEast]}}class Vg extends ed{static get requires(){return[Hd]}static get pluginName(){return"ImageTextAlternativeUI"}init(){this._createButton(),this._createForm()}destroy(){super.destroy(),this._form.destroy()}_createButton(){const t=this.editor,e=t.t;t.ui.componentFactory.add("imageTextAlternative",o=>{const i=t.commands.get("imageTextAlternative"),n=new zd(o);return n.set({label:e("ei"),icon:Rg,tooltip:!0}),n.bind("isEnabled").to(i,"isEnabled"),this.listenTo(n,"execute",()=>{this._showForm()}),n})}_createForm(){const t=this.editor,e=t.editing.view.document;this._balloon=this.editor.plugins.get("ContextualBalloon"),this._form=new Eg(t.locale),this._form.render(),this.listenTo(this._form,"submit",()=>{t.execute("imageTextAlternative",{newValue:this._form.labeledInput.inputView.element.value}),this._hideForm(!0)}),this.listenTo(this._form,"cancel",()=>{this._hideForm(!0)}),this._form.keystrokes.set("Esc",(t,e)=>{this._hideForm(!0),e()}),this.listenTo(t.ui,"update",()=>{cg(e.selection)?this._isVisible&&function(t){const e=t.plugins.get("ContextualBalloon");if(cg(t.editing.view.document.selection)){const o=Ig(t);e.updatePosition(o)}}(t):this._hideForm(!0)}),rh({emitter:this._form,activator:()=>this._isVisible,contextElements:[this._balloon.view.element],callback:()=>this._hideForm()})}_showForm(){if(this._isVisible)return;const t=this.editor,e=t.commands.get("imageTextAlternative"),o=this._form.labeledInput;this._isInBalloon||this._balloon.add({view:this._form,position:Ig(t)}),o.value=o.inputView.element.value=e.value||"",this._form.labeledInput.select()}_hideForm(t){this._isInBalloon&&(this._form.focusTracker.isFocused&&this._form.saveButtonView.focus(),this._balloon.remove(this._form),t&&this.editor.editing.view.focus())}get _isVisible(){return this._balloon.visibleView===this._form}get _isInBalloon(){return this._balloon.hasView(this._form)}}class Og extends ed{static get requires(){return[yg,Vg]}static get pluginName(){return"ImageTextAlternative"}}o(60);function Ng(t){for(const e of t.getChildren())if(e&&e.is("caption"))return e;return null}function Mg(t){const e=t.parent;return"figcaption"==t.name&&e&&"figure"==e.name&&e.hasClass("image")?{name:!0}:null}class Bg extends ed{static get pluginName(){return"ImageCaptionEditing"}init(){const t=this.editor,e=t.editing.view,o=t.model.schema,i=t.data,n=t.editing,r=t.t;o.register("caption",{allowIn:"image",allowContentOf:"$block",isLimit:!0}),t.model.document.registerPostFixer(t=>this._insertMissingModelCaptionElement(t)),t.conversion.for("upcast").elementToElement({view:Mg,model:"caption"});i.downcastDispatcher.on("insert:caption",zg(t=>t.createContainerElement("figcaption"),!1));const s=function(t,e){return o=>{const i=o.createEditableElement("figcaption");return o.setCustomProperty("imageCaption",!0,i),_h({view:t,element:i,text:e}),rg(i,o)}}(e,r("dw"));n.downcastDispatcher.on("insert:caption",zg(s)),n.downcastDispatcher.on("insert",this._fixCaptionVisibility(t=>t.item),{priority:"high"}),n.downcastDispatcher.on("remove",this._fixCaptionVisibility(t=>t.position.parent),{priority:"high"}),e.document.registerPostFixer(t=>this._updateCaptionVisibility(t))}_updateCaptionVisibility(t){const e=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 t=Ng(r);i=e.toViewElement(t)}const s=Fg(n.getFirstPosition().parent);if(s&&(i=e.toViewElement(s)),i)return o?o===i?Lg(i,t):(Dg(o,t),this._lastSelectedCaption=i,Lg(i,t)):(this._lastSelectedCaption=i,Lg(i,t));if(o){const e=Dg(o,t);return this._lastSelectedCaption=null,e}return!1}_fixCaptionVisibility(t){return(e,o,i)=>{const n=Fg(t(o)),r=this.editor.editing.mapper,s=i.writer;if(n){const t=r.toViewElement(n);t&&(n.childCount?s.removeClass("ck-hidden",t):s.addClass("ck-hidden",t))}}}_insertMissingModelCaptionElement(t){const e=this.editor.model,o=e.document.differ.getChanges(),i=[];for(const t of o)if("insert"==t.type&&"$text"!=t.name){const o=t.position.nodeAfter;if(o.is("image")&&!Ng(o)&&i.push(o),!o.is("image")&&o.childCount)for(const t of e.createRangeIn(o).getItems())t.is("image")&&!Ng(t)&&i.push(t)}for(const e of i)t.appendElement("caption",e);return!!i.length}}function zg(t,e=!0){return(o,i,n)=>{const r=i.item;if((r.childCount||e)&&lg(r.parent)){if(!n.consumable.consume(i.item,"insert"))return;const e=n.mapper.toViewElement(i.range.start.parent),o=t(n.writer),s=n.writer;r.childCount||s.addClass("ck-hidden",o),function(t,e,o,i){const n=i.writer.createPositionAt(o,"end");i.writer.insert(n,t),i.mapper.bindElements(e,t)}(o,i.item,e,n)}}}function Fg(t){const e=t.getAncestors({includeSelf:!0}).find(t=>"caption"==t.name);return e&&e.parent&&"image"==e.parent.name?e:null}function Dg(t,e){return!t.childCount&&!t.hasClass("ck-hidden")&&(e.addClass("ck-hidden",t),!0)}function Lg(t,e){return!!t.hasClass("ck-hidden")&&(e.removeClass("ck-hidden",t),!0)}o(62);class jg extends Lh{constructor(t,e){super(t),this.defaultStyle=!1,this.styles=e.reduce((t,e)=>(t[e.name]=e,e.isDefault&&(this.defaultStyle=e.name),t),{})}refresh(){const t=this.editor.model.document.selection.getSelectedElement();if(this.isEnabled=lg(t),t)if(t.hasAttribute("imageStyle")){const e=t.getAttribute("imageStyle");this.value=!!this.styles[e]&&e}else this.value=this.defaultStyle;else this.value=!1}execute(t){const e=t.value,o=this.editor.model,i=o.document.selection.getSelectedElement();o.change(t=>{this.styles[e].isDefault?t.removeAttribute("imageStyle",i):t.setAttribute("imageStyle",e,i)})}}function Hg(t,e){for(const o of e)if(o.name===t)return o}var qg='',Wg='',Ug='',$g='';const Gg={full:{name:"full",title:"Full size image",icon:qg,isDefault:!0},side:{name:"side",title:"Side image",icon:$g,className:"image-style-side"},alignLeft:{name:"alignLeft",title:"Left aligned image",icon:Wg,className:"image-style-align-left"},alignCenter:{name:"alignCenter",title:"Centered image",icon:Ug,className:"image-style-align-center"},alignRight:{name:"alignRight",title:"Right aligned image",icon:$g,className:"image-style-align-right"}},Kg={full:qg,left:Wg,right:$g,center:Ug};function Jg(t=[]){return t.map(Yg)}function Yg(t){if("string"==typeof t){const e=t;Gg[e]?t=Object.assign({},Gg[e]):(console.warn(Object(oi.a)("image-style-not-found: There is no such image style of given name."),{name:e}),t={name:e})}else if(Gg[t.name]){const e=Gg[t.name],o=Object.assign({},t);for(const i in e)t.hasOwnProperty(i)||(o[i]=e[i]);t=o}return"string"==typeof t.icon&&Kg[t.icon]&&(t.icon=Kg[t.icon]),t}class Qg extends ed{static get pluginName(){return"ImageStyleEditing"}init(){const t=this.editor,e=t.model.schema,o=t.data,i=t.editing;t.config.define("image.styles",["full","side"]);const n=Jg(t.config.get("image.styles"));e.extend("image",{allowAttributes:"imageStyle"});const r=function(t){return(e,o,i)=>{if(!i.consumable.consume(o.item,e.name))return;const n=Hg(o.attributeNewValue,t),r=Hg(o.attributeOldValue,t),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(t){const e=t.filter(t=>!t.isDefault);return(t,o,i)=>{if(!o.modelRange)return;const n=o.viewItem,r=Sm(o.modelRange.getItems());if(i.schema.checkAttribute(r,"imageStyle"))for(const t of e)i.consumable.consume(n,{classes:t.className})&&i.writer.setAttribute("imageStyle",t.name,r)}}(n),{priority:"low"}),t.commands.add("imageStyle",new jg(t,n))}}o(64);class Xg extends ed{static get pluginName(){return"ImageStyleUI"}get localizedDefaultStylesTitles(){const t=this.editor.t;return{"Full size image":t("dr"),"Side image":t("ds"),"Left aligned image":t("dt"),"Centered image":t("du"),"Right aligned image":t("dv")}}init(){const t=function(t,e){for(const o of t)e[o.title]&&(o.title=e[o.title]);return t}(Jg(this.editor.config.get("image.styles")),this.localizedDefaultStylesTitles);for(const e of t)this._createButton(e)}_createButton(t){const e=this.editor,o=`imageStyle:${t.name}`;e.ui.componentFactory.add(o,o=>{const i=e.commands.get("imageStyle"),n=new zd(o);return n.set({label:t.title,icon:t.icon,tooltip:!0,isToggleable:!0}),n.bind("isEnabled").to(i,"isEnabled"),n.bind("isOn").to(i,"value",e=>e===t.name),this.listenTo(n,"execute",()=>{e.execute("imageStyle",{value:t.name}),e.editing.view.focus()}),n})}}class Zg extends ed{static get requires(){return[Hd]}static get pluginName(){return"WidgetToolbarRepository"}init(){const t=this.editor;if(t.plugins.has("BalloonToolbar")){const e=t.plugins.get("BalloonToolbar");this.listenTo(e,"show",e=>{(function(t){const e=t.getSelectedElement();return!(!e||!og(e))})(t.editing.view.document.selection)&&e.stop()},{priority:"high"})}this._toolbarDefinitions=new Map,this._balloon=this.editor.plugins.get("ContextualBalloon"),this.on("change:isEnabled",()=>{this._updateToolbarsVisibility()}),this.listenTo(t.ui,"update",()=>{this._updateToolbarsVisibility()}),this.listenTo(t.ui.focusTracker,"change:isFocused",()=>{this._updateToolbarsVisibility()},{priority:"low"})}destroy(){super.destroy();for(const t of this._toolbarDefinitions.values())t.view.destroy()}register(t,{ariaLabel:e,items:o,getRelatedElement:i,balloonClassName:n="ck-toolbar-container"}){const r=this.editor,s=r.t,a=new lh(r.locale);if(a.ariaLabel=e||s("y"),this._toolbarDefinitions.has(t))throw new oi.b("widget-toolbar-duplicated: Toolbar with the given id was already added.",this,{toolbarId:t});a.fillFromConfig(o,r.ui.componentFactory),this._toolbarDefinitions.set(t,{view:a,getRelatedElement:i,balloonClassName:n})}_updateToolbarsVisibility(){let t=0,e=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>t&&(t=r,e=n,o=i)}else this._isToolbarVisible(i)&&this._hideToolbar(i);else this._isToolbarInBalloon(i)&&this._hideToolbar(i)}o&&this._showToolbar(o,e)}_hideToolbar(t){this._balloon.remove(t.view),this.stopListening(this._balloon,"change:visibleView")}_showToolbar(t,e){this._isToolbarVisible(t)?tf(this.editor,e):this._isToolbarInBalloon(t)||(this._balloon.add({view:t.view,position:ef(this.editor,e),balloonClassName:t.balloonClassName}),this.listenTo(this._balloon,"change:visibleView",()=>{for(const t of this._toolbarDefinitions.values())if(this._isToolbarVisible(t)){const e=t.getRelatedElement(this.editor.editing.view.document.selection);tf(this.editor,e)}}))}_isToolbarVisible(t){return this._balloon.visibleView===t.view}_isToolbarInBalloon(t){return this._balloon.hasView(t.view)}}function tf(t,e){const o=t.plugins.get("ContextualBalloon"),i=ef(t,e);o.updatePosition(i)}function ef(t,e){const o=t.editing.view,i=Id.defaultPositions;return{target:o.domConverter.mapViewToDom(e),positions:[i.northArrowSouth,i.northArrowSouthWest,i.northArrowSouthEast,i.southArrowNorth,i.southArrowNorthWest,i.southArrowNorthEast]}}class of extends Cd{constructor(t){super(t),this.buttonView=new zd(t),this._fileInputView=new nf(t),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 nf extends Cd{constructor(t){super(t),this.set("acceptedType"),this.set("allowMultipleFiles",!1);const e=this.bindTemplate;this.setTemplate({tag:"input",attributes:{class:["ck-hidden"],type:"file",tabindex:"-1",accept:e.to("acceptedType"),multiple:e.to("allowMultipleFiles")},on:{change:e.to(()=>{this.element&&this.element.files&&this.element.files.length&&this.fire("done",this.element.files),this.element.value=""})}})}open(){this.element.click()}}var rf='';function sf(t){const e=t.map(t=>t.replace("+","\\+"));return new RegExp(`^image\\/(${e.join("|")})$`)}function af(t){return new Promise((e,o)=>{const i=t.getAttribute("src");fetch(i).then(t=>t.blob()).then(t=>{const n=function(t,e){return t.type?t.type:e.match(/data:(image\/\w+);base64/)?e.match(/data:(image\/\w+);base64/)[1].toLowerCase():"image/jpeg"}(t,i),r=function(t,e,o){try{return new File([t],e,{type:o})}catch(t){return null}}(t,`image.${n.replace("image/","")}`,n);r?e(r):o()}).catch(o)})}class cf extends ed{init(){const t=this.editor,e=t.t;t.ui.componentFactory.add("imageUpload",o=>{const i=new of(o),n=t.commands.get("imageUpload"),r=t.config.get("image.upload.types"),s=sf(r);return i.set({acceptedType:r.map(t=>`image/${t}`).join(","),allowMultipleFiles:!0}),i.buttonView.set({label:e("dq"),icon:rf,tooltip:!0}),i.buttonView.bind("isEnabled").to(n),i.on("done",(e,o)=>{const i=Array.from(o).filter(t=>s.test(t.type));i.length&&t.execute("imageUpload",{file:i})}),i})}}var lf='';o(66),o(68),o(70);class df extends ed{constructor(t){super(t),this.placeholder="data:image/svg+xml;utf8,"+encodeURIComponent(lf)}init(){this.editor.editing.downcastDispatcher.on("attribute:uploadStatus:image",(...t)=>this.uploadStatusChange(...t))}uploadStatusChange(t,e,o){const i=this.editor,n=e.item,r=n.getAttribute("uploadId");if(!o.consumable.consume(e.item,t.name))return;const s=i.plugins.get(Nu),a=r?e.attributeNewValue:null,c=this.placeholder,l=i.editing.mapper.toViewElement(n),d=o.writer;if("reading"==a)return hf(l,d),void uf(c,l,d);if("uploading"==a){const t=s.loaders.get(r);return hf(l,d),void(t?(mf(l,d),function(t,e,o,i){const n=function(t){const e=t.createUIElement("div",{class:"ck-progress-bar"});return t.setCustomProperty("progressBar",!0,e),e}(e);e.insert(e.createPositionAt(t,"end"),n),o.on("change:uploadedPercent",(t,e,o)=>{i.change(t=>{t.setStyle("width",o+"%",n)})})}(l,d,t,i.editing.view),function(t,e,o){if(o.data){const i=ug(t);e.setAttribute("src",o.data,i)}}(l,d,t)):uf(c,l,d))}"complete"==a&&s.loaders.get(r)&&!hr.isEdge&&function(t,e,o){const i=e.createUIElement("div",{class:"ck-image-upload-complete-icon"});e.insert(e.createPositionAt(t,"end"),i),setTimeout(()=>{o.change(t=>t.remove(t.createRangeOn(i)))},3e3)}(l,d,i.editing.view),function(t,e){ff(t,e,"progressBar")}(l,d),mf(l,d),function(t,e){e.removeClass("ck-appear",t)}(l,d)}}function hf(t,e){t.hasClass("ck-appear")||e.addClass("ck-appear",t)}function uf(t,e,o){e.hasClass("ck-image-upload-placeholder")||o.addClass("ck-image-upload-placeholder",e);const i=ug(e);i.getAttribute("src")!==t&&o.setAttribute("src",t,i),gf(e,"placeholder")||o.insert(o.createPositionAfter(i),function(t){const e=t.createUIElement("div",{class:"ck-upload-placeholder-loader"});return t.setCustomProperty("placeholder",!0,e),e}(o))}function mf(t,e){t.hasClass("ck-image-upload-placeholder")&&e.removeClass("ck-image-upload-placeholder",t),ff(t,e,"placeholder")}function gf(t,e){for(const o of t.getChildren())if(o.getCustomProperty(e))return o}function ff(t,e,o){const i=gf(t,o);i&&e.remove(e.createRangeOn(i))}class pf extends Iu{static get pluginName(){return"Notification"}init(){this.on("show:warning",(t,e)=>{window.alert(e.message)},{priority:"lowest"})}showSuccess(t,e={}){this._showNotification({message:t,type:"success",namespace:e.namespace,title:e.title})}showInfo(t,e={}){this._showNotification({message:t,type:"info",namespace:e.namespace,title:e.title})}showWarning(t,e={}){this._showNotification({message:t,type:"warning",namespace:e.namespace,title:e.title})}_showNotification(t){const e=`show:${t.type}`+(t.namespace?`:${t.namespace}`:"");this.fire(e,{message:t.message,type:t.type,title:t.title||""})}}class bf{constructor(t){this.document=t}createDocumentFragment(t){return new yr(this.document,t)}createElement(t,e,o){return new Vn(this.document,t,e,o)}createText(t){return new Ci(this.document,t)}clone(t,e=!1){return t._clone(e)}appendChild(t,e){return e._appendChild(t)}insertChild(t,e,o){return o._insertChild(t,e)}removeChildren(t,e,o){return o._removeChildren(t,e)}remove(t){const e=t.parent;return e?this.removeChildren(e.getChildIndex(t),1,e):[]}replace(t,e){const o=t.parent;if(o){const i=o.getChildIndex(t);return this.removeChildren(i,1,o),this.insertChild(i,e,o),!0}return!1}unwrapElement(t){const e=t.parent;if(e){const o=e.getChildIndex(t);this.remove(t),this.insertChild(o,t.getChildren(),e)}}rename(t,e){const o=new Vn(this.document,t,e.getAttributes(),e.getChildren());return this.replace(e,o)?o:null}setAttribute(t,e,o){o._setAttribute(t,e)}removeAttribute(t,e){e._removeAttribute(t)}addClass(t,e){e._addClass(t)}removeClass(t,e){e._removeClass(t)}setStyle(t,e,o){A(t)&&void 0===o&&(o=e),o._setStyle(t,e)}removeStyle(t,e){e._removeStyle(t)}setCustomProperty(t,e,o){o._setCustomProperty(t,e)}removeCustomProperty(t,e){return e._removeCustomProperty(t)}createPositionAt(t,e){return Qn._createAt(t,e)}createPositionAfter(t){return Qn._createAfter(t)}createPositionBefore(t){return Qn._createBefore(t)}createRange(t,e){return new Xn(t,e)}createRangeOn(t){return Xn._createOn(t)}createRangeIn(t){return Xn._createIn(t)}createSelection(t,e,o){return new er(t,e,o)}}class wf extends Lh{refresh(){this.isEnabled=hg(this.editor.model)}execute(t){const e=this.editor,o=e.model,i=e.plugins.get(Nu);o.change(e=>{const n=Array.isArray(t.file)?t.file:[t.file];for(const t of n)kf(e,o,i,t)})}}function kf(t,e,o,i){const n=o.createLoader(i);n&&dg(t,e,{uploadId:n.id})}class _f extends ed{static get requires(){return[Nu,pf,Dh]}static get pluginName(){return"ImageUploadEditing"}constructor(t){super(t),t.config.define("image",{upload:{types:["jpeg","png","gif","bmp","webp","tiff"]}})}init(){const t=this.editor,e=t.model.document,o=t.model.schema,i=t.conversion,n=t.plugins.get(Nu),r=sf(t.config.get("image.upload.types"));o.extend("image",{allowAttributes:["uploadId","uploadStatus"]}),t.commands.add("imageUpload",new wf(t)),i.for("upcast").attributeToAttribute({view:{name:"img",key:"uploadId"},model:"uploadId"}),this.listenTo(t.editing.view.document,"clipboardInput",(e,o)=>{if(function(t){return Array.from(t.types).includes("text/html")&&""!==t.getData("text/html")}(o.dataTransfer))return;const i=Array.from(o.dataTransfer.files).filter(t=>!!t&&r.test(t.type)),n=o.targetRanges.map(e=>t.editing.mapper.toModelRange(e));t.model.change(o=>{o.setSelection(n),i.length&&(e.stop(),t.model.enqueueChange("default",()=>{t.execute("imageUpload",{file:i})}))})}),this.listenTo(t.plugins.get(Dh),"inputTransformation",(e,o)=>{const i=Array.from(t.editing.view.createRangeIn(o.content)).filter(t=>(function(t){return!(!t.is("element","img")||!t.getAttribute("src"))&&(t.getAttribute("src").match(/^data:image\/\w+;base64,/g)||t.getAttribute("src").match(/^blob:/g))})(t.item)&&!t.item.getAttribute("uploadProcessed")).map(t=>({promise:af(t.item),imageElement:t.item}));if(!i.length)return;const r=new bf(t.editing.view.document);for(const t of i){r.setAttribute("uploadProcessed",!0,t.imageElement);const e=n.createLoader(t.promise);e&&(r.setAttribute("src","",t.imageElement),r.setAttribute("uploadId",e.id,t.imageElement))}}),t.editing.view.document.on("dragover",(t,e)=>{e.preventDefault()}),e.on("change",()=>{const o=e.differ.getChanges({includeChangesInGraveyard:!0});for(const e of o)if("insert"==e.type&&"$text"!=e.name){const o=e.position.nodeAfter,i="$graveyard"==e.position.root.rootName;for(const e of vf(t,o)){const t=e.getAttribute("uploadId");if(!t)continue;const o=n.loaders.get(t);o&&(i?o.abort():"idle"==o.status&&this._readAndUpload(o,e))}}})}_readAndUpload(t,e){const o=this.editor,i=o.model,n=o.locale.t,r=o.plugins.get(Nu),s=o.plugins.get(pf);return i.enqueueChange("transparent",t=>{t.setAttribute("uploadStatus","reading",e)}),t.read().then(()=>{const n=t.upload();if(hr.isSafari){const t=ug(o.editing.mapper.toViewElement(e));o.editing.view.once("render",()=>{if(!t.parent)return;const e=o.editing.view.domConverter.mapViewToDom(t.parent);if(!e)return;const i=e.style.display;e.style.display="none",e._ckHack=e.offsetHeight,e.style.display=i})}return i.enqueueChange("transparent",t=>{t.setAttribute("uploadStatus","uploading",e)}),n}).then(t=>{i.enqueueChange("transparent",o=>{o.setAttributes({uploadStatus:"complete",src:t.default},e),this._parseAndSetSrcsetAttributeOnImage(t,e,o)}),a()}).catch(o=>{if("error"!==t.status&&"aborted"!==t.status)throw o;"error"==t.status&&o&&s.showWarning(o,{title:n("dp"),namespace:"upload"}),a(),i.enqueueChange("transparent",t=>{t.remove(e)})});function a(){i.enqueueChange("transparent",t=>{t.removeAttribute("uploadId",e),t.removeAttribute("uploadStatus",e)}),r.destroyLoader(t)}}_parseAndSetSrcsetAttributeOnImage(t,e,o){let i=0;const n=Object.keys(t).filter(t=>{const e=parseInt(t,10);if(!isNaN(e))return i=Math.max(i,e),!0}).map(e=>`${t[e]} ${e}w`).join(", ");""!=n&&o.setAttribute("srcset",{data:n,width:i},e)}}function vf(t,e){return Array.from(t.model.createRangeOn(e)).filter(t=>t.item.is("image")).map(t=>t.item)}class yf{constructor(t){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=t,this._referenceCoordinates=null}begin(t,e,o){const i=new va(e);this.activeHandlePosition=function(t){const e=["top-left","top-right","bottom-right","bottom-left"];for(const o of e)if(t.classList.contains(`ck-widget__resizer__handle-${o}`))return o}(t),this._referenceCoordinates=function(t,e){const o=new va(t),i=e.split("-"),n={x:"right"==i[1]?o.right:o.left,y:"bottom"==i[0]?o.bottom:o.top};return n.x+=t.ownerDocument.defaultView.scrollX,n.y+=t.ownerDocument.defaultView.scrollY,n}(e,function(t){const e=t.split("-"),o={top:"bottom",bottom:"top",left:"right",right:"left"};return`${o[e[0]]}-${o[e[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(t,e){const o=t.parentElement,i=parseFloat(o.ownerDocument.defaultView.getComputedStyle(o).width);return e.width/i*100}(o,i)}update(t){this.proposedWidth=t.width,this.proposedHeight=t.height,this.proposedWidthPercents=t.widthPercents,this.proposedHandleHostWidth=t.handleHostWidth,this.proposedHandleHostHeight=t.handleHostHeight}}ui(yf,jn);class xf{constructor(t){this._options=t,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",t=>{this.state.proposedWidth||this.state.proposedWidthPercents||(this._cleanup(),t.stop())},{priority:"high"})}attach(){const t=this,e=this._options.viewElement;this._options.editor.editing.view.change(o=>{const i=o.createUIElement("div",{class:"ck ck-reset_all ck-widget__resizer"},(function(e){const o=this.toDomElement(e);return t._appendHandles(o),t._appendSizeUI(o),t._domResizerWrapper=o,t.on("change:isEnabled",(t,e,i)=>{o.style.display=i?"":"none"}),o.style.display=t.isEnabled?"":"none",o}));o.insert(o.createPositionAt(e,"end"),i),o.addClass("ck-widget_with-resizer",e),this._viewResizerWrapper=i})}begin(t){this.state=new yf(this._options),this._sizeUI.bindToState(this._options,this.state),this.state.begin(t,this._getHandleHost(),this._getResizeHost())}updateSize(t){const e=this._proposeNewSize(t);this._options.editor.editing.view.change(t=>{const o=this._options.unit||"%",i=("%"===o?e.widthPercents:e.width)+o;t.setStyle("width",i,this._options.viewElement)});const o=this._getHandleHost(),i=new va(o);e.handleHostWidth=Math.round(i.width),e.handleHostHeight=Math.round(i.height);const n=new va(o);e.width=Math.round(n.width),e.height=Math.round(n.height),this.redraw(i),this.state.update(e)}commit(){const t=this._options.unit||"%",e=("%"===t?this.state.proposedWidthPercents:this.state.proposedWidth)+t;this._options.onCommit(e),this._cleanup()}cancel(){this._cleanup()}destroy(){this.cancel()}redraw(t){const e=this._domResizerWrapper;var o;(o=e)&&o.ownerDocument&&o.ownerDocument.contains(o)&&this._options.editor.editing.view.change(o=>{const i=e.parentElement,n=this._getHandleHost(),r=t||new va(n);o.setStyle("width",r.width+"px",this._viewResizerWrapper),o.setStyle("height",r.height+"px",this._viewResizerWrapper);const s=n.offsetLeft,a=n.offsetTop,c=n.offsetHeight,l=n.offsetWidth;i.isSameNode(n)||(o.setStyle("left",s+"px",this._viewResizerWrapper),o.setStyle("top",a+"px",this._viewResizerWrapper),o.setStyle("height",c+"px",this._viewResizerWrapper),o.setStyle("width",l+"px",this._viewResizerWrapper))})}containsHandle(t){return this._domResizerWrapper.contains(t)}static isResizeHandle(t){return t.classList.contains("ck-widget__resizer__handle")}_cleanup(){this._sizeUI.dismiss(),this._sizeUI.isVisible=!1}_proposeNewSize(t){const e=this.state,o={x:(i=t).pageX,y:i.pageY};var i;const n=!this._options.isCentered||this._options.isCentered(this),r={x:e._referenceCoordinates.x-(o.x+e.originalWidth),y:o.y-e.originalHeight-e._referenceCoordinates.y};n&&e.activeHandlePosition.endsWith("-right")&&(r.x=o.x-(e._referenceCoordinates.x+e.originalWidth)),n&&(r.x*=2);const s={width:Math.abs(e.originalWidth+r.x),height:Math.abs(e.originalHeight+r.y)};s.dominant=s.width/e.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/e.aspectRatio:a.width=a.height*e.aspectRatio,{width:Math.round(a.width),height:Math.round(a.height),widthPercents:Math.min(Math.round(e.originalWidthPercents/e.originalWidth*a.width*100)/100,100)}}_getResizeHost(){const t=this._domResizerWrapper.parentElement;return this._options.getResizeHost(t)}_getHandleHost(){const t=this._domResizerWrapper.parentElement;return this._options.getHandleHost(t)}_appendHandles(t){const e=["top-left","top-right","bottom-right","bottom-left"];for(const i of e)t.appendChild(new rd({tag:"div",attributes:{class:`ck-widget__resizer__handle ${o=i,`ck-widget__resizer__handle-${o}`}`}}).render());var o}_appendSizeUI(t){const e=new Cf;e.render(),this._sizeUI=e,t.appendChild(e.element)}}ui(xf,jn);class Cf extends Cd{constructor(){super();const t=this.bindTemplate;this.setTemplate({tag:"div",attributes:{class:["ck","ck-size-view",t.to("activeHandlePosition",t=>t?`ck-orientation-${t}`:"")],style:{display:t.if("isVisible","none",t=>!t)}},children:[{text:t.to("label")}]})}bindToState(t,e){this.bind("isVisible").to(e,"proposedWidth",e,"proposedHeight",(t,e)=>null!==t&&null!==e),this.bind("label").to(e,"proposedHandleHostWidth",e,"proposedHandleHostHeight",e,"proposedWidthPercents",(e,o,i)=>"px"===t.unit?`${e}×${o}`:`${i}%`),this.bind("activeHandlePosition").to(e)}dismiss(){this.unbind(),this.isVisible=!1}}var Af="Expected a function";var Tf=function(t,e,o){var i=!0,n=!0;if("function"!=typeof t)throw new TypeError(Af);return L(o)&&(i="leading"in o?!!o.leading:i,n="trailing"in o?!!o.trailing:n),ua(t,e,{leading:i,maxWait:e,trailing:n})};o(72);class Pf extends ed{static get pluginName(){return"WidgetResize"}init(){this.set("_visibleResizer",null),this.set("_activeResizer",null),this._resizers=new Map;const t=Zr.window.document;this.editor.model.schema.setAttributeProperties("width",{isFormatting:!0}),this._observer=Object.create(cs),this._observer.listenTo(t,"mousedown",this._mouseDownListener.bind(this)),this._observer.listenTo(t,"mousemove",this._mouseMoveListener.bind(this)),this._observer.listenTo(t,"mouseup",this._mouseUpListener.bind(this));const e=()=>{this._visibleResizer&&this._visibleResizer.redraw()},o=Tf(e,200);this.on("change:_visibleResizer",e),this.editor.ui.on("update",o),this._observer.listenTo(Zr.window,"resize",o);const i=this.editor.editing.view.document.selection;i.on("change",()=>{const t=i.getSelectedElement();this._visibleResizer=this._getResizerByViewElement(t)||null})}destroy(){this._observer.stopListening();for(const t of this._resizers.values())t.destroy()}attachTo(t){const e=new xf(t),o=this.editor.plugins;if(e.attach(),o.has("WidgetToolbarRepository")){const t=o.get("WidgetToolbarRepository");e.on("begin",()=>{t.forceDisabled("resize")},{priority:"lowest"}),e.on("cancel",()=>{t.clearForceDisabled("resize")},{priority:"highest"}),e.on("commit",()=>{t.clearForceDisabled("resize")},{priority:"highest"})}return this._resizers.set(t.viewElement,e),e}_getResizerByHandle(t){for(const e of this._resizers.values())if(e.containsHandle(t))return e}_getResizerByViewElement(t){return this._resizers.get(t)}_mouseDownListener(t,e){if(!xf.isResizeHandle(e.target))return;const o=e.target;this._activeResizer=this._getResizerByHandle(o),this._activeResizer&&this._activeResizer.begin(o)}_mouseMoveListener(t,e){this._activeResizer&&this._activeResizer.updateSize(e)}_mouseUpListener(){this._activeResizer&&(this._activeResizer.commit(),this._activeResizer=null)}}ui(Pf,jn);class Sf extends Lh{refresh(){const t=this.editor.model.document.selection.getSelectedElement();this.isEnabled=lg(t),t&&t.hasAttribute("width")?this.value={width:t.getAttribute("width"),height:null}:this.value=null}execute(t){const e=this.editor.model,o=e.document.selection.getSelectedElement();e.change(e=>{e.setAttribute("width",t.width,o)})}}o(74);function Ef(t,e,o){return o.createRange(Rf(t,e,!0,o),Rf(t,e,!1,o))}function Rf(t,e,o,i){let n=t.textNode||(o?t.nodeBefore:t.nodeAfter),r=null;for(;n&&n.getAttribute("linkHref")==e;)r=n,n=o?n.previousSibling:n.nextSibling;return r?i.createPositionAt(r,o?"before":"after"):t}class If extends Lh{constructor(t){super(t),this.manualDecorators=new mi}restoreManualDecoratorStates(){for(const t of this.manualDecorators)t.value=this._getDecoratorStateFromModel(t.id)}refresh(){const t=this.editor.model,e=t.document;this.value=e.selection.getAttribute("linkHref");for(const t of this.manualDecorators)t.value=this._getDecoratorStateFromModel(t.id);this.isEnabled=t.schema.checkAttributeInSelection(e.selection,"linkHref")}execute(t,e={}){const o=this.editor.model,i=o.document.selection,n=[],r=[];for(const t in e)e[t]?n.push(t):r.push(t);o.change(e=>{if(i.isCollapsed){const s=i.getFirstPosition();if(i.hasAttribute("linkHref")){const a=Ef(s,i.getAttribute("linkHref"),o);e.setAttribute("linkHref",t,a),n.forEach(t=>{e.setAttribute(t,!0,a)}),r.forEach(t=>{e.removeAttribute(t,a)}),e.setSelection(a)}else if(""!==t){const r=Pi(i.getAttributes());r.set("linkHref",t),n.forEach(t=>{r.set(t,!0)});const a=e.createText(t,r);o.insertContent(a,s),e.setSelection(e.createRangeOn(a))}}else{const s=o.schema.getValidRanges(i.getRanges(),"linkHref");for(const o of s)e.setAttribute("linkHref",t,o),n.forEach(t=>{e.setAttribute(t,!0,o)}),r.forEach(t=>{e.removeAttribute(t,o)})}})}_getDecoratorStateFromModel(t){return this.editor.model.document.selection.getAttribute(t)||!1}}class Vf extends Lh{refresh(){this.isEnabled=this.editor.model.document.selection.hasAttribute("linkHref")}execute(){const t=this.editor,e=this.editor.model,o=e.document.selection,i=t.commands.get("link");e.change(t=>{const n=o.isCollapsed?[Ef(o.getFirstPosition(),o.getAttribute("linkHref"),e)]:o.getRanges();for(const e of n)if(t.removeAttribute("linkHref",e),i)for(const o of i.manualDecorators)t.removeAttribute(o.id,e)})}}var Of=function(t,e,o){var i=t.length;return o=void 0===o?i:o,!e&&o>=i?t:Zi(t,e,o)},Nf=RegExp("[\\u200d\\ud800-\\udfff\\u0300-\\u036f\\ufe20-\\ufe2f\\u20d0-\\u20ff\\ufe0e\\ufe0f]");var Mf=function(t){return Nf.test(t)};var Bf=function(t){return t.split("")},zf="[\\ud800-\\udfff]",Ff="[\\u0300-\\u036f\\ufe20-\\ufe2f\\u20d0-\\u20ff]",Df="\\ud83c[\\udffb-\\udfff]",Lf="[^\\ud800-\\udfff]",jf="(?:\\ud83c[\\udde6-\\uddff]){2}",Hf="[\\ud800-\\udbff][\\udc00-\\udfff]",qf="(?:"+Ff+"|"+Df+")"+"?",Wf="[\\ufe0e\\ufe0f]?"+qf+("(?:\\u200d(?:"+[Lf,jf,Hf].join("|")+")[\\ufe0e\\ufe0f]?"+qf+")*"),Uf="(?:"+[Lf+Ff+"?",Ff,jf,Hf,zf].join("|")+")",$f=RegExp(Df+"(?="+Df+")|"+Uf+Wf,"g");var Gf=function(t){return t.match($f)||[]};var Kf=function(t){return Mf(t)?Gf(t):Bf(t)};var Jf=function(t){return function(e){e=Gi(e);var o=Mf(e)?Kf(e):void 0,i=o?o[0]:e.charAt(0),n=o?Of(o,1).join(""):e.slice(1);return i[t]()+n}}("toUpperCase");const Yf=/[\u0000-\u0020\u00A0\u1680\u180E\u2000-\u2029\u205f\u3000]/g,Qf=/^(?:(?:https?|ftps?|mailto):|[^a-z]|[a-z+.-]+(?:[^a-z+.:-]|$))/i;function Xf(t,e){const o=e.createAttributeElement("a",{href:t},{priority:5});return e.setCustomProperty("link",!0,o),o}function Zf(t){return function(t){return t.replace(Yf,"").match(Qf)}(t=String(t))?t:"#"}class tp{constructor(){this._definitions=new Set}get length(){return this._definitions.size}add(t){Array.isArray(t)?t.forEach(t=>this._definitions.add(t)):this._definitions.add(t)}getDispatcher(){return t=>{t.on("attribute:linkHref",(t,e,o)=>{if(!o.consumable.test(e.item,"attribute:linkHref"))return;const i=o.writer,n=i.document.selection;for(const t of this._definitions){const r=i.createAttributeElement("a",t.attributes,{priority:5});i.setCustomProperty("link",!0,r),t.callback(e.attributeNewValue)?e.item.is("selection")?i.wrap(n.getFirstRange(),r):i.wrap(o.mapper.toViewRange(e.range),r):i.unwrap(o.mapper.toViewRange(e.range),r)}},{priority:"high"})}}}class ep{constructor({id:t,label:e,attributes:o}){this.id=t,this.set("value"),this.label=e,this.attributes=o}}ui(ep,jn);class op{constructor(t,e,o){this.model=t,this.attribute=o,this._modelSelection=t.document.selection,this._overrideUid=null,this._isNextGravityRestorationSkipped=!1,e.listenTo(this._modelSelection,"change:range",(t,e)=>{this._isNextGravityRestorationSkipped?this._isNextGravityRestorationSkipped=!1:this._isGravityOverridden&&(!e.directChange&&ip(this._modelSelection.getFirstPosition(),o)||this._restoreGravity())})}handleForwardMovement(t,e){const o=this.attribute;if(!(this._isGravityOverridden||t.isAtStart&&this._hasSelectionAttribute))return sp(t,o)&&this._hasSelectionAttribute?(this._preventCaretMovement(e),this._removeSelectionAttribute(),!0):np(t,o)?(this._preventCaretMovement(e),this._overrideGravity(),!0):rp(t,o)&&this._hasSelectionAttribute?(this._preventCaretMovement(e),this._overrideGravity(),!0):void 0}handleBackwardMovement(t,e){const o=this.attribute;return this._isGravityOverridden?sp(t,o)&&this._hasSelectionAttribute?(this._preventCaretMovement(e),this._restoreGravity(),this._removeSelectionAttribute(),!0):(this._preventCaretMovement(e),this._restoreGravity(),t.isAtStart&&this._removeSelectionAttribute(),!0):sp(t,o)&&!this._hasSelectionAttribute?(this._preventCaretMovement(e),this._setSelectionAttributeFromTheNodeBefore(t),!0):t.isAtEnd&&rp(t,o)?this._hasSelectionAttribute?void(ap(t,o)&&(this._skipNextAutomaticGravityRestoration(),this._overrideGravity())):(this._preventCaretMovement(e),this._setSelectionAttributeFromTheNodeBefore(t),!0):t.isAtStart?this._hasSelectionAttribute?(this._removeSelectionAttribute(),this._preventCaretMovement(e),!0):void 0:void(ap(t,o)&&(this._skipNextAutomaticGravityRestoration(),this._overrideGravity()))}get _isGravityOverridden(){return!!this._overrideUid}get _hasSelectionAttribute(){return this._modelSelection.hasAttribute(this.attribute)}_overrideGravity(){this._overrideUid=this.model.change(t=>t.overrideSelectionGravity())}_restoreGravity(){this.model.change(t=>{t.restoreSelectionGravity(this._overrideUid),this._overrideUid=null})}_preventCaretMovement(t){t.preventDefault()}_removeSelectionAttribute(){this.model.change(t=>{t.removeSelectionAttribute(this.attribute)})}_setSelectionAttributeFromTheNodeBefore(t){const e=this.attribute;this.model.change(o=>{o.setSelectionAttribute(this.attribute,t.nodeBefore.getAttribute(e))})}_skipNextAutomaticGravityRestoration(){this._isNextGravityRestorationSkipped=!0}}function ip(t,e){return np(t,e)||rp(t,e)}function np(t,e){const{nodeBefore:o,nodeAfter:i}=t,n=!!o&&o.hasAttribute(e);return!!i&&i.hasAttribute(e)&&(!n||o.getAttribute(e)!==i.getAttribute(e))}function rp(t,e){const{nodeBefore:o,nodeAfter:i}=t,n=!!o&&o.hasAttribute(e),r=!!i&&i.hasAttribute(e);return n&&(!r||o.getAttribute(e)!==i.getAttribute(e))}function sp(t,e){const{nodeBefore:o,nodeAfter:i}=t,n=!!o&&o.hasAttribute(e);if(!!i&&i.hasAttribute(e)&&n)return i.getAttribute(e)!==o.getAttribute(e)}function ap(t,e){return ip(t.getShiftedBy(-1),e)}o(76);const cp="ck-link_selected",lp="automatic",dp="manual",hp=/^(https?:)?\/\//;class up extends ed{static get pluginName(){return"LinkEditing"}constructor(t){super(t),t.config.define("link",{addTargetToExternalLinks:!1})}init(){const t=this.editor,e=t.locale;t.model.schema.extend("$text",{allowAttributes:"linkHref"}),t.conversion.for("dataDowncast").attributeToElement({model:"linkHref",view:Xf}),t.conversion.for("editingDowncast").attributeToElement({model:"linkHref",view:(t,e)=>Xf(Zf(t),e)}),t.conversion.for("upcast").elementToAttribute({view:{name:"a",attributes:{href:!0}},model:{key:"linkHref",value:t=>t.getAttribute("href")}}),t.commands.add("link",new If(t)),t.commands.add("unlink",new Vf(t));const o=function(t,e){const o={"Open in a new tab":t("eb"),Downloadable:t("ec")};return e.forEach(t=>(t.label&&o[t.label]&&(t.label=o[t.label]),t)),e}(t.t,function(t){const e=[];if(t)for(const[o,i]of Object.entries(t)){const t=Object.assign({},i,{id:`link${Jf(o)}`});e.push(t)}return e}(t.config.get("link.decorators")));this._enableAutomaticDecorators(o.filter(t=>t.mode===lp)),this._enableManualDecorators(o.filter(t=>t.mode===dp)),function({view:t,model:e,emitter:o,attribute:i,locale:n}){const r=new op(e,o,i),s=e.document.selection;o.listenTo(t.document,"keydown",(t,e)=>{if(!s.isCollapsed)return;if(e.shiftKey||e.altKey||e.ctrlKey)return;const o=e.keyCode==gr.arrowright,i=e.keyCode==gr.arrowleft;if(!o&&!i)return;const a=s.getFirstPosition(),c=n.contentLanguageDirection;let l;l="ltr"===c&&o||"rtl"===c&&i?r.handleForwardMovement(a,e):r.handleBackwardMovement(a,e),l&&t.stop()},{priority:ei.get("high")+1})}({view:t.editing.view,model:t.model,emitter:this,attribute:"linkHref",locale:e}),this._setupLinkHighlight()}_enableAutomaticDecorators(t){const e=this.editor,o=new tp;e.config.get("link.addTargetToExternalLinks")&&o.add({id:"linkIsExternal",mode:lp,callback:t=>hp.test(t),attributes:{target:"_blank",rel:"noopener noreferrer"}}),o.add(t),o.length&&e.conversion.for("downcast").add(o.getDispatcher())}_enableManualDecorators(t){if(!t.length)return;const e=this.editor,o=e.commands.get("link").manualDecorators;t.forEach(t=>{e.model.schema.extend("$text",{allowAttributes:t.id}),o.add(new ep(t)),e.conversion.for("downcast").attributeToElement({model:t.id,view:(e,i)=>{if(e){const e=o.get(t.id).attributes,n=i.createAttributeElement("a",e,{priority:5});return i.setCustomProperty("link",!0,n),n}}}),e.conversion.for("upcast").elementToAttribute({view:{name:"a",attributes:o.get(t.id).attributes},model:{key:t.id}})})}_setupLinkHighlight(){const t=this.editor,e=t.editing.view,o=new Set;e.document.registerPostFixer(e=>{const i=t.model.document.selection;let n=!1;if(i.hasAttribute("linkHref")){const r=Ef(i.getFirstPosition(),i.getAttribute("linkHref"),t.model),s=t.editing.mapper.toViewRange(r);for(const t of s.getItems())t.is("a")&&!t.hasClass(cp)&&(e.addClass(cp,t),o.add(t),n=!0)}return n}),t.conversion.for("editingDowncast").add(t=>{function i(){e.change(t=>{for(const e of o.values())t.removeClass(cp,e),o.delete(e)})}t.on("insert",i,{priority:"highest"}),t.on("remove",i,{priority:"highest"}),t.on("attribute",i,{priority:"highest"}),t.on("selection",i,{priority:"highest"})})}}class mp extends Zs{constructor(t){super(t),this.domEventType="click"}onDomEvent(t){this.fire(t.type,t)}}o(78);class gp extends Cd{constructor(t,e=[]){super(t);const o=t.t;this.focusTracker=new Fd,this.keystrokes=new Yl,this.urlInputView=this._createUrlInput(),this.saveButtonView=this._createButton(o("cv"),Pg,"ck-button-save"),this.saveButtonView.type="submit",this.cancelButtonView=this._createButton(o("cw"),Sg,"ck-button-cancel","cancel"),this._manualDecoratorSwitches=this._createManualDecoratorSwitches(e),this.children=this._createFormChildren(e),this._focusables=new id,this._focusCycler=new Ud({focusables:this._focusables,focusTracker:this.focusTracker,keystrokeHandler:this.keystrokes,actions:{focusPrevious:"shift + tab",focusNext:"tab"}});const i=["ck","ck-link-form"];e.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((t,e)=>(t[e.name]=e.isOn,t),{})}render(){super.render(),Tg({view:this}),[this.urlInputView,...this._manualDecoratorSwitches,this.saveButtonView,this.cancelButtonView].forEach(t=>{this._focusables.add(t),this.focusTracker.add(t.element)}),this.keystrokes.listenTo(this.element)}focus(){this._focusCycler.focusFirst()}_createUrlInput(){const t=this.locale.t,e=new Cg(this.locale,Ag);return e.label=t("ed"),e.inputView.placeholder="https://example.com",e}_createButton(t,e,o,i){const n=new zd(this.locale);return n.set({label:t,icon:e,tooltip:!0}),n.extendTemplate({attributes:{class:o}}),i&&n.delegate("execute").to(this,i),n}_createManualDecoratorSwitches(t){const e=this.createCollection();for(const o of t){const t=new nh(this.locale);t.set({name:o.id,label:o.label,withText:!0}),t.bind("isOn").to(o,"value"),t.on("execute",()=>{o.set("value",!t.isOn)}),e.add(t)}return e}_createFormChildren(t){const e=this.createCollection();if(e.add(this.urlInputView),t.length){const t=new Cd;t.setTemplate({tag:"ul",children:this._manualDecoratorSwitches.map(t=>({tag:"li",children:[t],attributes:{class:["ck","ck-list__item"]}})),attributes:{class:["ck","ck-reset","ck-list"]}}),e.add(t)}return e.add(this.saveButtonView),e.add(this.cancelButtonView),e}}var fp='',pp='';o(80);class bp extends Cd{constructor(t){super(t);const e=t.t;this.focusTracker=new Fd,this.keystrokes=new Yl,this.previewButtonView=this._createPreviewButton(),this.unlinkButtonView=this._createButton(e("ee"),fp,"unlink"),this.editButtonView=this._createButton(e("ef"),pp,"edit"),this.set("href"),this._focusables=new id,this._focusCycler=new Ud({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(t=>{this._focusables.add(t),this.focusTracker.add(t.element)}),this.keystrokes.listenTo(this.element)}focus(){this._focusCycler.focusFirst()}_createButton(t,e,o){const i=new zd(this.locale);return i.set({label:t,icon:e,tooltip:!0}),i.delegate("execute").to(this,o),i}_createPreviewButton(){const t=new zd(this.locale),e=this.bindTemplate,o=this.t;return t.set({withText:!0,tooltip:o("eg")}),t.extendTemplate({attributes:{class:["ck","ck-link-actions__preview"],href:e.to("href",t=>t&&Zf(t)),target:"_blank",rel:"noopener noreferrer"}}),t.bind("label").to(this,"href",t=>t||o("eh")),t.bind("isEnabled").to(this,"href",t=>!!t),t.template.tag="a",t.template.eventListeners={},t}}var wp='';const kp="Ctrl+K";class _p extends ed{static get requires(){return[Hd]}static get pluginName(){return"LinkUI"}init(){const t=this.editor;t.editing.view.addObserver(mp),this.actionsView=this._createActionsView(),this.formView=this._createFormView(),this._balloon=t.plugins.get(Hd),this._createToolbarLinkButton(),this._enableUserBalloonInteractions()}destroy(){super.destroy(),this.formView.destroy()}_createActionsView(){const t=this.editor,e=new bp(t.locale),o=t.commands.get("link"),i=t.commands.get("unlink");return e.bind("href").to(o,"value"),e.editButtonView.bind("isEnabled").to(o),e.unlinkButtonView.bind("isEnabled").to(i),this.listenTo(e,"edit",()=>{this._addFormView()}),this.listenTo(e,"unlink",()=>{t.execute("unlink"),this._hideUI()}),e.keystrokes.set("Esc",(t,e)=>{this._hideUI(),e()}),e.keystrokes.set(kp,(t,e)=>{this._addFormView(),e()}),e}_createFormView(){const t=this.editor,e=t.commands.get("link"),o=new gp(t.locale,e.manualDecorators);return o.urlInputView.bind("value").to(e,"value"),o.urlInputView.bind("isReadOnly").to(e,"isEnabled",t=>!t),o.saveButtonView.bind("isEnabled").to(e),this.listenTo(o,"submit",()=>{t.execute("link",o.urlInputView.inputView.element.value,o.getDecoratorSwitchesState()),this._closeFormView()}),this.listenTo(o,"cancel",()=>{this._closeFormView()}),o.keystrokes.set("Esc",(t,e)=>{this._closeFormView(),e()}),o}_createToolbarLinkButton(){const t=this.editor,e=t.commands.get("link"),o=t.t;t.keystrokes.set(kp,(t,e)=>{e(),this._showUI(!0)}),t.ui.componentFactory.add("link",t=>{const i=new zd(t);return i.isEnabled=!0,i.label=o("do"),i.icon=wp,i.keystroke=kp,i.tooltip=!0,i.isToggleable=!0,i.bind("isEnabled").to(e,"isEnabled"),i.bind("isOn").to(e,"value",t=>!!t),this.listenTo(i,"execute",()=>this._showUI(!0)),i})}_enableUserBalloonInteractions(){const t=this.editor.editing.view.document;this.listenTo(t,"click",()=>{this._getSelectedLinkElement()&&this._showUI()}),this.editor.keystrokes.set("Tab",(t,e)=>{this._areActionsVisible&&!this.actionsView.focusTracker.isFocused&&(this.actionsView.focus(),e())},{priority:"high"}),this.editor.keystrokes.set("Esc",(t,e)=>{this._isUIVisible&&(this._hideUI(),e())}),rh({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 t=this.editor.commands.get("link");this._balloon.add({view:this.formView,position:this._getBalloonPositionData()}),this._balloon.visibleView===this.formView&&this.formView.urlInputView.select(),this.formView.urlInputView.inputView.element.value=t.value||""}_closeFormView(){const t=this.editor.commands.get("link");t.restoreManualDecoratorStates(),void 0!==t.value?this._removeFormView():this._hideUI()}_removeFormView(){this._isFormInPanel&&(this.formView.saveButtonView.focus(),this._balloon.remove(this.formView),this.editor.editing.view.focus())}_showUI(t=!1){this._getSelectedLinkElement()?(this._areActionsVisible?this._addFormView():this._addActionsView(),t&&this._balloon.showStack("main")):(this._addActionsView(),t&&this._balloon.showStack("main"),this._addFormView()),this._startUpdatingUI()}_hideUI(){if(!this._isUIInPanel)return;const t=this.editor;this.stopListening(t.ui,"update"),this.stopListening(this._balloon,"change:visibleView"),t.editing.view.focus(),this._removeFormView(),this._balloon.remove(this.actionsView)}_startUpdatingUI(){const t=this.editor,e=t.editing.view.document;let o=this._getSelectedLinkElement(),i=r();const n=()=>{const t=this._getSelectedLinkElement(),e=r();o&&!t||!o&&e!==i?this._hideUI():this._isUIVisible&&this._balloon.updatePosition(this._getBalloonPositionData()),o=t,i=e};function r(){return e.selection.focus.getAncestors().reverse().find(t=>t.is("element"))}this.listenTo(t.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 t=this.editor.editing.view,e=t.document,o=this._getSelectedLinkElement();return{target:o?t.domConverter.mapViewToDom(o):t.domConverter.viewRangeToDom(e.selection.getFirstRange())}}_getSelectedLinkElement(){const t=this.editor.editing.view,e=t.document.selection;if(e.isCollapsed)return vp(e.getFirstPosition());{const o=e.getFirstRange().getTrimmed(),i=vp(o.start),n=vp(o.end);return i&&i==n&&t.createRangeIn(i).getTrimmed().isEqual(o)?i:null}}}function vp(t){return t.getAncestors().find(t=>(function(t){return t.is("attributeElement")&&!!t.getCustomProperty("link")})(t))}class yp extends Lh{constructor(t,e){super(t),this.type=e}refresh(){this.value=this._getValue(),this.isEnabled=this._checkEnabled()}execute(){const t=this.editor.model,e=t.document,o=Array.from(e.selection.getSelectedBlocks()).filter(e=>Cp(e,t.schema)),i=!0===this.value;t.change(t=>{if(i){let e=o[o.length-1].nextSibling,i=Number.POSITIVE_INFINITY,n=[];for(;e&&"listItem"==e.name&&0!==e.getAttribute("listIndent");){const t=e.getAttribute("listIndent");t=o;)r>n.getAttribute("listIndent")&&(r=n.getAttribute("listIndent")),n.getAttribute("listIndent")==r&&t[e?"unshift":"push"](n),n=n[e?"previousSibling":"nextSibling"]}}function Cp(t,e){return e.checkChild(t.parent,"listItem")&&!e.isObject(t)}class Ap extends Lh{constructor(t,e){super(t),this._indentBy="forward"==e?1:-1}refresh(){this.isEnabled=this._checkEnabled()}execute(){const t=this.editor.model,e=t.document;let o=Array.from(e.selection.getSelectedBlocks());t.change(t=>{const e=o[o.length-1];let i=e.nextSibling;for(;i&&"listItem"==i.name&&i.getAttribute("listIndent")>e.getAttribute("listIndent");)o.push(i),i=i.nextSibling;this._indentBy<0&&(o=o.reverse());for(const e of o){const o=e.getAttribute("listIndent")+this._indentBy;o<0?t.rename(e,"paragraph"):t.setAttribute("listIndent",o,e)}})}_checkEnabled(){const t=Sm(this.editor.model.document.selection.getSelectedBlocks());if(!t||!t.is("listItem"))return!1;if(this._indentBy>0){const e=t.getAttribute("listIndent"),o=t.getAttribute("listType");let i=t.previousSibling;for(;i&&i.is("listItem")&&i.getAttribute("listIndent")>=e;){if(i.getAttribute("listIndent")==e)return i.getAttribute("listType")==o;i=i.previousSibling}return!1}return!0}}function Tp(t,e){const o=e.mapper,i=e.writer,n="numbered"==t.getAttribute("listType")?"ol":"ul",r=function(t){const e=t.createContainerElement("li");return e.getFillerOffset=Vp,e}(i),s=i.createContainerElement(n,null);return i.insert(i.createPositionAt(s,0),r),o.bindElements(t,r),r}function Pp(t,e,o,i){const n=e.parent,r=o.mapper,s=o.writer;let a=r.toViewPosition(i.createPositionBefore(t));const c=Rp(t.previousSibling,{sameIndent:!0,smallerIndent:!0,listIndent:t.getAttribute("listIndent")}),l=t.previousSibling;if(c&&c.getAttribute("listIndent")==t.getAttribute("listIndent")){const t=r.toViewElement(c);a=s.breakContainer(s.createPositionAfter(t))}else a=l&&"listItem"==l.name?r.toViewPosition(i.createPositionAt(l,"end")):r.toViewPosition(i.createPositionBefore(t));if(a=Ep(a),s.insert(a,n),l&&"listItem"==l.name){const t=r.toViewElement(l),o=s.createRange(s.createPositionAt(t,0),a).getWalker({ignoreElementEnd:!0});for(const t of o)if(t.item.is("li")){const i=s.breakContainer(s.createPositionBefore(t.item)),n=t.item.parent,r=s.createPositionAt(e,"end");Sp(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 e of o.getChildren()){const o=r.toModelElement(e);if(!(o&&o.getAttribute("listIndent")>t.getAttribute("listIndent")))break;i=e}i&&(s.breakContainer(s.createPositionAfter(i)),s.move(s.createRangeOn(i.parent),s.createPositionAt(e,"end")))}}Sp(s,n,n.nextSibling),Sp(s,n.previousSibling,n)}function Sp(t,e,o){return!e||!o||"ul"!=e.name&&"ol"!=e.name?null:e.name!=o.name||e.getAttribute("class")!==o.getAttribute("class")?null:t.mergeContainers(t.createPositionAfter(e))}function Ep(t){return t.getLastMatchingPosition(t=>t.item.is("uiElement"))}function Rp(t,e){const o=!!e.sameIndent,i=!!e.smallerIndent,n=e.listIndent;let r=t;for(;r&&"listItem"==r.name;){const t=r.getAttribute("listIndent");if(o&&n==t||i&&n>t)return r;r=r.previousSibling}return null}function Ip(t,e,o,i){t.ui.componentFactory.add(e,n=>{const r=t.commands.get(e),s=new zd(n);return s.set({label:o,icon:i,tooltip:!0,isToggleable:!0}),s.bind("isOn","isEnabled").to(r,"value","isEnabled"),s.on("execute",()=>{t.execute(e),t.editing.view.focus()}),s})}function Vp(){const t=!this.isEmpty&&("ul"==this.getChild(0).name||"ol"==this.getChild(0).name);return this.isEmpty||t?0:Mn.call(this)}function Op(t){return(e,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;Pp(r,Tp(r,i),i,t)}}function Np(t,e,o){if(!o.consumable.consume(e.item,"attribute:listType"))return;const i=o.mapper.toViewElement(e.item),n=o.writer;n.breakContainer(n.createPositionBefore(i)),n.breakContainer(n.createPositionAfter(i));const r=i.parent,s="numbered"==e.attributeNewValue?"ol":"ul";n.rename(s,r)}function Mp(t,e,o){const i=o.mapper.toViewElement(e.item).parent,n=o.writer;Sp(n,i,i.nextSibling),Sp(n,i.previousSibling,i);for(const t of e.item.getChildren())o.consumable.consume(t,"insert")}function Bp(t,e,o){if("listItem"!=e.item.name){let t=o.mapper.toViewPosition(e.range.start);const i=o.writer,n=[];for(;("ul"==t.parent.name||"ol"==t.parent.name)&&(t=i.breakContainer(t),"li"==t.parent.name);){const e=t,o=i.createPositionAt(t.parent,"end");if(!e.isEqual(o)){const t=i.remove(i.createRange(e,o));n.push(t)}t=i.createPositionAfter(t.parent)}if(n.length>0){for(let e=0;e0){const e=Sp(i,o,o.nextSibling);e&&e.parent==o&&t.offset--}}Sp(i,t.nodeBefore,t.nodeAfter)}}}function zp(t,e,o){const i=o.mapper.toViewPosition(e.position),n=i.nodeBefore,r=i.nodeAfter;Sp(o.writer,n,r)}function Fp(t,e,o){if(o.consumable.consume(e.viewItem,{name:!0})){const t=o.writer,i=t.createElement("listItem"),n=function(t){let e=0,o=t.parent;for(;o;){if(o.is("li"))e++;else{const t=o.previousSibling;t&&t.is("li")&&e++}o=o.parent}return e}(e.viewItem);t.setAttribute("listIndent",n,i);const r=e.viewItem.parent&&"ol"==e.viewItem.parent.name?"numbered":"bulleted";t.setAttribute("listType",r,i);const s=o.splitToAllowedParent(i,e.modelCursor);if(!s)return;t.insert(i,s.position);const a=function(t,e,o){const{writer:i,schema:n}=o;let r=i.createPositionAfter(t);for(const s of e)if("ul"==s.name||"ol"==s.name)r=o.convertItem(s,r).modelCursor;else{const e=o.convertItem(s,i.createPositionAt(t,"end")),a=e.modelRange.start.nodeAfter;a&&a.is("element")&&!n.checkChild(t,a.name)&&(t=e.modelCursor.parent.is("listItem")?e.modelCursor.parent:qp(e.modelCursor),r=i.createPositionAfter(t))}return r}(i,e.viewItem.getChildren(),o);e.modelRange=t.createRange(e.modelCursor,a),s.cursorParent?e.modelCursor=t.createPositionAt(s.cursorParent,0):e.modelCursor=e.modelRange.end}}function Dp(t,e,o){if(o.consumable.test(e.viewItem,{name:!0})){const t=Array.from(e.viewItem.getChildren());for(const e of t){!(e.is("li")||Up(e))&&e._remove()}}}function Lp(t,e,o){if(o.consumable.test(e.viewItem,{name:!0})){if(0===e.viewItem.childCount)return;const t=[...e.viewItem.getChildren()];let o=!1,i=!0;for(const e of t)o&&!Up(e)&&e._remove(),e.is("text")?(i&&(e._data=e.data.replace(/^\s+/,"")),e.nextSibling&&!Up(e.nextSibling)||(e._data=e.data.replace(/\s+$/,""))):Up(e)&&(o=!0),i=!1}}function jp(t){return(e,o)=>{if(o.isPhantom)return;const i=o.modelPosition.nodeBefore;if(i&&i.is("listItem")){const e=o.mapper.toViewElement(i),n=e.getAncestors().find(Up),r=t.createPositionAt(e,0).getWalker();for(const t of r){if("elementStart"==t.type&&t.item.is("li")){o.viewPosition=t.previousPosition;break}if("elementEnd"==t.type&&t.item==n){o.viewPosition=t.nextPosition;break}}}}}function Hp(t,[e,o]){let i,n=e.is("documentFragment")?e.getChild(0):e;if(i=o?this.createSelection(o):this.document.selection,n&&n.is("listItem")){const t=i.getFirstPosition();let e=null;if(t.parent.is("listItem")?e=t.parent:t.nodeBefore&&t.nodeBefore.is("listItem")&&(e=t.nodeBefore),e){const t=e.getAttribute("listIndent");if(t>0)for(;n&&n.is("listItem");)n._setAttribute("listIndent",n.getAttribute("listIndent")+t),n=n.nextSibling}}}function qp(t){const e=new La({startPosition:t});let o;do{o=e.next()}while(!o.value.item.is("listItem"));return o.value.item}function Wp(t,e,o,i,n,r){const s=Rp(e.nodeBefore,{sameIndent:!0,smallerIndent:!0,listIndent:t,foo:"b"}),a=n.mapper,c=n.writer,l=s?s.getAttribute("listIndent"):null;let d;if(s)if(l==t){const t=a.toViewElement(s).parent;d=c.createPositionAfter(t)}else{const t=r.createPositionAt(s,"end");d=a.toViewPosition(t)}else d=o;d=Ep(d);for(const t of[...i.getChildren()])Up(t)&&(d=c.move(c.createRangeOn(t),d).end,Sp(c,t,t.nextSibling),Sp(c,t.previousSibling,t))}function Up(t){return t.is("ol")||t.is("ul")}class $p extends ed{static get pluginName(){return"ListEditing"}static get requires(){return[Fm]}init(){const t=this.editor;t.model.schema.register("listItem",{inheritAllFrom:"$block",allowAttributes:["listType","listIndent"]});const e=t.data,o=t.editing;var i;t.model.document.registerPostFixer(e=>(function(t,e){const o=t.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")&&(e.removeAttribute("listIndent",o),n=!0),o.hasAttribute("listType")&&(e.removeAttribute("listType",o),n=!0);for(const e of Array.from(t.createRangeIn(o)).filter(t=>t.item.is("listItem")))r(e.previousPosition)}r(i.position.getShiftedBy(i.length))}else"remove"==i.type&&"listItem"==i.name?r(i.position):"attribute"==i.type&&"listIndent"==i.attributeKey?r(i.range.start):"attribute"==i.type&&"listType"==i.attributeKey&&r(i.range.start);for(const t of i.values())s(t),a(t);return n;function r(t){const e=t.nodeBefore;if(e&&e.is("listItem")){let o=e;if(i.has(o))return;for(;o.previousSibling&&o.previousSibling.is("listItem");)if(o=o.previousSibling,i.has(o))return;i.set(t.nodeBefore,o)}else{const e=t.nodeAfter;e&&e.is("listItem")&&i.set(e,e)}}function s(t){let o=0,i=null;for(;t&&t.is("listItem");){const r=t.getAttribute("listIndent");if(r>o){let s;null===i?(i=r-o,s=o):(i>r&&(i=r),s=r-i),e.setAttribute("listIndent",s,t),n=!0}else i=null,o=t.getAttribute("listIndent")+1;t=t.nextSibling}}function a(t){let o=[],i=null;for(;t&&t.is("listItem");){const r=t.getAttribute("listIndent");if(i&&i.getAttribute("listIndent")>r&&(o=o.slice(0,r+1)),0!=r)if(o[r]){const i=o[r];t.getAttribute("listType")!=i&&(e.setAttribute("listType",i,t),n=!0)}else o[r]=t.getAttribute("listType");i=t,t=t.nextSibling}}})(t.model,e)),o.mapper.registerViewToModelLength("li",Gp),e.mapper.registerViewToModelLength("li",Gp),o.mapper.on("modelToViewPosition",jp(o.view)),o.mapper.on("viewToModelPosition",(i=t.model,(t,e)=>{const o=e.viewPosition,n=o.parent,r=e.mapper;if("ul"==n.name||"ol"==n.name){if(o.isAtEnd){const t=r.toModelElement(o.nodeBefore),n=r.getModelLength(o.nodeBefore);e.modelPosition=i.createPositionBefore(t).getShiftedBy(n)}else{const t=r.toModelElement(o.nodeAfter);e.modelPosition=i.createPositionBefore(t)}t.stop()}else if("li"==n.name&&o.nodeBefore&&("ul"==o.nodeBefore.name||"ol"==o.nodeBefore.name)){const s=r.toModelElement(n);let a=1,c=o.nodeBefore;for(;c&&Up(c);)a+=r.getModelLength(c),c=c.previousSibling;e.modelPosition=i.createPositionBefore(s).getShiftedBy(a),t.stop()}})),e.mapper.on("modelToViewPosition",jp(o.view)),t.conversion.for("editingDowncast").add(e=>{e.on("insert",Bp,{priority:"high"}),e.on("insert:listItem",Op(t.model)),e.on("attribute:listType:listItem",Np,{priority:"high"}),e.on("attribute:listType:listItem",Mp,{priority:"low"}),e.on("attribute:listIndent:listItem",function(t){return(e,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,c=r.createRangeOn(s);r.remove(c),a&&a.nextSibling&&Sp(r,a,a.nextSibling),Wp(o.attributeOldValue+1,o.range.start,c.start,n,i,t),Pp(o.item,n,i,t);for(const t of o.item.getChildren())i.consumable.consume(t,"insert")}}(t.model)),e.on("remove:listItem",function(t){return(e,o,i)=>{const n=i.mapper.toViewPosition(o.position).getLastMatchingPosition(t=>!t.item.is("li")).nodeAfter,r=i.writer;r.breakContainer(r.createPositionBefore(n)),r.breakContainer(r.createPositionAfter(n));const s=n.parent,a=s.previousSibling,c=r.createRangeOn(s),l=r.remove(c);a&&a.nextSibling&&Sp(r,a,a.nextSibling),Wp(i.mapper.toModelElement(n).getAttribute("listIndent")+1,o.position,c.start,n,i,t);for(const t of r.createRangeIn(l).getItems())i.mapper.unbindViewElement(t);e.stop()}}(t.model)),e.on("remove",zp,{priority:"low"})}),t.conversion.for("dataDowncast").add(e=>{e.on("insert",Bp,{priority:"high"}),e.on("insert:listItem",Op(t.model))}),t.conversion.for("upcast").add(t=>{t.on("element:ul",Dp,{priority:"high"}),t.on("element:ol",Dp,{priority:"high"}),t.on("element:li",Lp,{priority:"high"}),t.on("element:li",Fp)}),t.model.on("insertContent",Hp,{priority:"high"}),t.commands.add("numberedList",new yp(t,"numbered")),t.commands.add("bulletedList",new yp(t,"bulleted")),t.commands.add("indentList",new Ap(t,"forward")),t.commands.add("outdentList",new Ap(t,"backward"));const n=o.view.document;this.listenTo(n,"enter",(t,e)=>{const o=this.editor.model.document,i=o.selection.getLastPosition().parent;o.selection.isCollapsed&&"listItem"==i.name&&i.isEmpty&&(this.editor.execute("outdentList"),e.preventDefault(),t.stop())}),this.listenTo(n,"delete",(t,e)=>{if("backward"!==e.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;"listItem"===n.name&&(n.previousSibling&&"listItem"===n.previousSibling.name||(this.editor.execute("outdentList"),e.preventDefault(),t.stop()))},{priority:"high"});const r=t=>(e,o)=>{this.editor.commands.get(t).isEnabled&&(this.editor.execute(t),o())};t.keystrokes.set("Tab",r("indentList")),t.keystrokes.set("Shift+Tab",r("outdentList"))}afterInit(){const t=this.editor.commands,e=t.get("indent"),o=t.get("outdent");e&&e.registerChildCommand(t.get("indentList")),o&&o.registerChildCommand(t.get("outdentList"))}}function Gp(t){let e=1;for(const o of t.getChildren())if("ul"==o.name||"ol"==o.name)for(const t of o.getChildren())e+=Gp(t);return e}var Kp='',Jp='';class Yp extends ed{init(){const t=this.editor.t;Ip(this.editor,"numberedList",t("ar"),Kp),Ip(this.editor,"bulletedList",t("as"),Jp)}}const Qp="todoListChecked";class Xp extends Lh{constructor(t){super(t),this._selectedElements=[],this.on("execute",()=>{this.refresh()},{priority:"highest"})}refresh(){this._selectedElements=this._getSelectedItems(),this.value=this._selectedElements.every(t=>!!t.getAttribute("todoListChecked")),this.isEnabled=!!this._selectedElements.length}_getSelectedItems(){const t=this.editor.model,e=t.schema,o=t.document.selection.getFirstRange(),i=o.start.parent,n=[];e.checkAttribute(i,Qp)&&n.push(i);for(const t of o.getItems())e.checkAttribute(t,Qp)&&!n.includes(t)&&n.push(t);return n}execute(t={}){this.editor.model.change(e=>{for(const o of this._selectedElements){(void 0===t.forceValue?!this.value:t.forceValue)?e.setAttribute(Qp,!0,o):e.removeAttribute(Qp,o)}})}}function Zp(t,e,o){const i=e.range.start.parent;if("listItem"!=i.name||"todo"!=i.getAttribute("listType"))return;if(!o.consumable.consume(e.item,"insert"))return;const n=o.writer,r=o.mapper.toViewPosition(e.range.start),s=n.createText(e.item.data),a=n.createAttributeElement("span",{class:"todo-list__label__description"}),c=r.parent.getChild(0);n.insert(n.createPositionAt(r.parent,"end"),s),n.wrap(n.createRangeOn(s),a),n.wrap(n.createRangeOn(s.parent),c)}function tb(t,e,o){const i=e.modelCursor,n=i.parent,r=e.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),e.viewItem.hasAttribute("checked")&&s.setAttribute("todoListChecked",!0,n),e.modelRange=s.createRange(i)}function eb(t,e,o,i){return e.createUIElement("label",{class:"todo-list__label",contenteditable:!1},(function(e){const n=Ph(document,"input",{type:"checkbox"});o&&n.setAttribute("checked","checked"),n.addEventListener("change",()=>i(t));const r=this.toDomElement(e);return r.appendChild(n),r}))}function ob(t,e){const o=e.createRangeIn(t);for(const t of o)if(t.item.is("uiElement","label"))return t.item}class ib extends ed{static get pluginName(){return"TodoListEditing"}static get requires(){return[$p]}init(){const t=this.editor,{editing:e,data:o,model:i}=t;var n,r;i.schema.extend("listItem",{allowAttributes:["todoListChecked"]}),i.schema.addAttributeCheck((t,e)=>{const o=t.last;if("todoListChecked"==e&&"listItem"==o.name&&"todo"!=o.getAttribute("listType"))return!1}),t.commands.add("todoList",new yp(t,"todo")),t.commands.add("todoListCheck",new Xp(t)),o.downcastDispatcher.on("insert:listItem",function(t){return(e,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=Tp(s,i);r.addClass("todo-list",a.parent);const c=r.createAttributeElement("label",{class:"todo-list__label"}),l=r.createEmptyElement("input",{type:"checkbox",disabled:"disabled"});o.item.getAttribute("todoListChecked")&&(r.setAttribute("checked","checked",l),r.addClass("todo-list__label",c)),r.insert(r.createPositionAt(a,0),l),r.wrap(r.createRangeOn(l),c),Pp(s,a,i,t)}}(i),{priority:"high"}),o.downcastDispatcher.on("insert:$text",Zp,{priority:"high"}),e.downcastDispatcher.on("insert:listItem",function(t,e){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,c=Tp(s,n),l=!!s.getAttribute("todoListChecked"),d=eb(s,a,l,e);a.addClass("todo-list",c.parent),a.insert(a.createPositionAt(c,0),d),Pp(s,c,n,t)}}(i,t=>this._handleCheckmarkChange(t)),{priority:"high"}),e.downcastDispatcher.on("attribute:listType:listItem",(n=t=>this._handleCheckmarkChange(t),r=e.view,(t,e,o)=>{const i=o.mapper.toViewElement(e.item),s=o.writer;if("todo"==e.attributeNewValue){const t=!!e.item.getAttribute("todoListChecked"),o=eb(e.item,s,t,n);s.addClass("todo-list",i.parent),s.insert(s.createPositionAt(i,0),o)}else"todo"==e.attributeOldValue&&(s.removeClass("todo-list",i.parent),s.remove(ob(i,r)))})),e.downcastDispatcher.on("attribute:todoListChecked:listItem",function(t){return(e,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),c=eb(o.item,r,s,t);r.insert(r.createPositionAfter(a),c),r.remove(a)}}(t=>this._handleCheckmarkChange(t))),e.mapper.on("modelToViewPosition",function(t,e){return(o,i)=>{const n=i.modelPosition,r=n.parent;if(!r.is("listItem")||"todo"!=r.getAttribute("listType")||0!==n.offset)return;const s=ob(e.toViewElement(r),t);s&&(s.nextSibling&&!s.nextSibling.is("uiElement")?i.viewPosition=t.createPositionAt(s.nextSibling,0):i.viewPosition=t.createPositionAfter(s))}}(e.view,e.mapper)),o.upcastDispatcher.on("element:input",tb,{priority:"high"});const s="ltr"===t.locale.contentLanguageDirection?"arrowleft":"arrowright";t.keystrokes.set(s,(t,e)=>(function(t,e){const o=e.schema,i=e.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(e.createPositionBefore(r),"backward");i&&(t(),e.change(t=>t.setSelection(i)))}})(e,i)),t.keystrokes.set("Ctrl+space",()=>t.execute("todoListCheck"));const a=new Set;this.listenTo(i,"applyOperation",(t,e)=>{const o=e[0];if("rename"==o.type&&"listItem"==o.oldName){const t=o.position.nodeAfter;t.hasAttribute("todoListChecked")&&a.add(t)}else if("changeAttribute"==o.type&&"listType"==o.key&&"todo"===o.oldValue)for(const t of o.range.getItems())t.hasAttribute("todoListChecked")&&"todo"!==t.getAttribute("listType")&&a.add(t)}),i.document.registerPostFixer(t=>{let e=!1;for(const o of a)t.removeAttribute("todoListChecked",o),e=!0;return a.clear(),e})}_handleCheckmarkChange(t){const e=this.editor,o=e.model,i=Array.from(o.document.selection.getRanges());o.change(o=>{o.setSelection(t,"end"),e.execute("todoListCheck"),o.setSelection(i)})}}var nb='';class rb extends ed{init(){const t=this.editor.t;Ip(this.editor,"todoList",t("at"),nb)}}o(82);function sb(t,e){if(!t.childCount)return;const o=new bf(t.document),i=function(t,e){const o=e.createRangeIn(t),i=new Si({name:/^p|h\d+$/,styles:{"mso-list":/.*/}}),n=[];for(const t of o)if("elementStart"===t.type&&i.match(t.item)){const e=cb(t.item);n.push({element:t.item,id:e.id,order:e.order,indent:e.indent})}return n}(t,o);if(!i.length)return;let n=null,r=1;i.forEach((t,s)=>{const a=function(t,e){if(!t)return!0;if(t.id!==e.id)return!0;const o=e.element.previousSibling;if(!o)return!0;return i=o,!(i.is("ol")||i.is("ul"));var i}(i[s-1],t),c=function(t,e){return t?e.indent-t.indent:e.indent-1}(a?null:i[s-1],t);if(a&&(n=null,r=1),!n||0!==c){const i=function(t,e){const o=new RegExp(`@list l${t.id}:level${t.indent}\\s*({[^}]*)`,"gi"),i=/mso-level-number-format:([^;]*);/gi,n=o.exec(e);let r="decimal";if(n&&n[1]){const t=i.exec(n[1]);t&&t[1]&&(r=t[1].trim())}return{type:"bullet"!==r&&"image"!==r?"ol":"ul",style:r}}(t,e);if(n){if(t.indent>r){const t=n.getChild(n.childCount-1),e=t.getChild(t.childCount-1);n=ab(i,e,o),r+=1}else if(t.indent(\s+)<\/span>/g,(t,e)=>1===e.length?" ":Array(e.length+1).join(" ").substr(0,e.length))}function ub(t){const e=new DOMParser,o=function(t){return hb(hb(t)).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(t){const e=t.match(/<\/body>(.*?)(<\/html>|$)/);e&&e[1]&&(t=t.slice(0,e.index)+t.slice(e.index).replace(e[1],""));return t}(t=t.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// Transform text or any iterable into arrays for easier, consistent processing.\n\tif ( !Array.isArray( a ) ) {\n\t\ta = Array.from( a );\n\t}\n\n\tif ( !Array.isArray( b ) ) {\n\t\tb = Array.from( 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.