import{Command as q,Plugin as x}from"@ckeditor/ckeditor5-core";import{env as v,EventInfo as ie,count as se,isInsideSurrogatePair as oe,isInsideCombinedSymbol as re,isInsideEmojiSequence as ce,keyCodes as E,ObservableMixin as le}from"@ckeditor/ckeditor5-utils";import{Observer as N,FocusObserver as ae,ViewDocumentDomEventData as A,_tryFixingModelRange as M,ModelLiveRange as ue,BubblingEventInfo as B,MouseObserver as de,TouchObserver as fe}from"@ckeditor/ckeditor5-engine";/**
* @license Copyright (c) 2003-2026, CKSource Holding sp. z o.o. All rights reserved.
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options
*/class I{model;limit;_isLocked;_size;_batch=null;_changeCallback;_selectionChangeCallback;constructor(e,t=20){this.model=e,this._size=0,this.limit=t,this._isLocked=!1,this._changeCallback=(n,s)=>{s.isLocal&&s.isUndoable&&s!==this._batch&&this._reset(!0)},this._selectionChangeCallback=()=>{this._reset()},this.model.document.on("change",this._changeCallback),this.model.document.selection.on("change:range",this._selectionChangeCallback),this.model.document.selection.on("change:attribute",this._selectionChangeCallback)}get batch(){return this._batch||(this._batch=this.model.createBatch({isTyping:!0})),this._batch}get size(){return this._size}input(e){this._size+=e,this._size>=this.limit&&this._reset(!0)}get isLocked(){return this._isLocked}lock(){this._isLocked=!0}unlock(){this._isLocked=!1}destroy(){this.model.document.off("change",this._changeCallback),this.model.document.selection.off("change:range",this._selectionChangeCallback),this.model.document.selection.off("change:attribute",this._selectionChangeCallback)}_reset(e=!1){(!this.isLocked||e)&&(this._batch=null,this._size=0)}}/**
* @license Copyright (c) 2003-2026, CKSource Holding sp. z o.o. All rights reserved.
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options
*/class G extends q{_buffer;constructor(e,t){super(e),this._buffer=new I(e.model,t),this._isEnabledBasedOnSelection=!1}get buffer(){return this._buffer}destroy(){super.destroy(),this._buffer.destroy()}execute(e={}){const t=this.editor.model,n=t.document,s=e.text||"",i=s.length;let c=n.selection;if(e.selection?c=e.selection:e.range&&(c=t.createSelection(e.range)),!t.canEditAt(c))return;const r=e.resultRange;t.enqueueChange(this._buffer.batch,l=>{this._buffer.lock();const a=Array.from(n.selection.getAttributes());t.deleteContent(c),s&&t.insertContent(l.createText(s,a),c),r?l.setSelection(r):c.is("documentSelection")||l.setSelection(c),this._buffer.unlock(),this._buffer.input(i)})}}/**
* @license Copyright (c) 2003-2026, CKSource Holding sp. z o.o. All rights reserved.
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options
*/const $=["insertText","insertReplacementText"],he=[...$,"insertCompositionText"];class me extends N{focusObserver;constructor(e){super(e),this.focusObserver=e.getObserver(ae);const t=v.isAndroid?he:$,n=e.document;n.on("beforeinput",(s,i)=>{if(!this.isEnabled)return;const{data:c,targetRanges:r,inputType:l,domEvent:a,isComposing:u}=i;if(!t.includes(l))return;this.focusObserver.flush();const d=new ie(n,"insertText");n.fire(d,new A(e,a,{text:c,selection:e.createSelection(r),isComposing:u})),d.stop.called&&s.stop()}),v.isAndroid||n.on("compositionend",(s,{data:i,domEvent:c})=>{this.isEnabled&&i&&n.fire("insertText",new A(e,c,{text:i,isComposing:!0}))},{priority:"low"})}observe(){}stopObserving(){}}function ge(o,e,{signal:t,edges:n}={}){let s,i=null;const c=n!=null&&n.includes("leading"),r=n==null||n.includes("trailing"),l=()=>{i!==null&&(o.apply(s,i),s=void 0,i=null)},a=()=>{r&&l(),m()};let u=null;const d=()=>{u!=null&&clearTimeout(u),u=setTimeout(()=>{u=null,a()},e)},h=()=>{u!==null&&(clearTimeout(u),u=null)},m=()=>{h(),s=void 0,i=null},f=()=>{h(),l()},g=function(...b){if(t?.aborted)return;s=this,i=b;const R=u==null;d(),c&&R&&l()};return g.schedule=d,g.cancel=m,g.flush=f,t?.addEventListener("abort",m,{once:!0}),g}function pe(o,e=0,t={}){typeof t!="object"&&(t={});const{leading:n=!1,trailing:s=!0,maxWait:i}=t,c=Array(2);n&&(c[0]="leading"),s&&(c[1]="trailing");let r,l=null;const a=ge(function(...h){r=o.apply(this,h),l=null},e,{edges:c}),u=function(...h){return i!=null&&(l===null&&(l=Date.now()),Date.now()-l>=i)?(r=o.apply(this,h),l=Date.now(),a.cancel(),a.schedule(),r):(a.apply(this,h),r)},d=()=>(a.flush(),r);return u.cancel=a.cancel,u.flush=d,u}function z(o){if(o==null)return"";if(typeof o=="string")return o;if(Array.isArray(o))return o.map(z).join(",");const e=String(o);return e==="0"&&Object.is(Number(o),-0)?"-0":e}function be(o){return o.replace(/[\\^$.*+?()[\]{}|]/g,"\\$&")}function _e(o){return be(z(o))}/**
* @license Copyright (c) 2003-2026, CKSource Holding sp. z o.o. All rights reserved.
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options
*/class W extends x{_typingQueue;static get pluginName(){return"Input"}static get isOfficialPlugin(){return!0}init(){const e=this.editor,t=e.model,n=e.editing.view,s=e.editing.mapper,i=t.document.selection;this._typingQueue=new ye(e),n.addObserver(me);const c=new G(e,e.config.get("typing.undoStep")||20);e.commands.add("insertText",c),e.commands.add("input",c),this.listenTo(n.document,"beforeinput",()=>{this._typingQueue.flush("next beforeinput")},{priority:"high"}),this.listenTo(n.document,"insertText",(r,l)=>{const{text:a,selection:u}=l;if(n.document.selection.isFake&&u&&n.document.selection.isSimilar(u)&&l.preventDefault(),u&&Array.from(u.getRanges()).some(f=>!f.isCollapsed)&&l.preventDefault(),!c.isEnabled){l.preventDefault();return}let d;u&&(d=Array.from(u.getRanges()).filter(f=>f.root.is("rootElement")).map(f=>s.toModelRange(f)).map(f=>M(f,t.schema)||f)),(!d||!d.length)&&(d=Array.from(i.getRanges()));let h=a;if(v.isAndroid){const f=Array.from(d[0].getItems()).reduce((g,b)=>g+(b.is("$textProxy")?b.data:""),"");if(f&&(f.length<=h.length?h.startsWith(f)&&(h=h.substring(f.length),d[0].start=d[0].start.getShiftedBy(f.length)):f.startsWith(h)&&(d[0].start=d[0].start.getShiftedBy(h.length),h="")),h.length==0&&d[0].isCollapsed)return}const m={text:h,selection:t.createSelection(d)};this._typingQueue.push(m,!!l.isComposing),l.domEvent.defaultPrevented&&this._typingQueue.flush("beforeinput default prevented")}),v.isAndroid?this.listenTo(n.document,"keydown",(r,l)=>{i.isCollapsed||l.keyCode!=229||!n.document.isComposing||U(t,c)}):this.listenTo(n.document,"compositionstart",()=>{i.isCollapsed||U(t,c)},{priority:"high"}),this.listenTo(n.document,"mutations",(r,{mutations:l})=>{if(this._typingQueue.hasAffectedElements())for(const{node:a}of l){const u=Ee(a,s),d=s.toModelElement(u);if(this._typingQueue.isElementAffected(d)){this._typingQueue.flush("mutations");return}}}),this.listenTo(n.document,"compositionend",()=>{this._typingQueue.flush("before composition end")},{priority:"high"}),this.listenTo(n.document,"compositionend",()=>{this._typingQueue.flush("after composition end");const r=[];if(this._typingQueue.hasAffectedElements())for(const l of this._typingQueue.flushAffectedElements()){const a=s.toViewElement(l);a&&r.push({type:"children",node:a})}(r.length||!v.isAndroid)&&n.document.fire("mutations",{mutations:r})},{priority:"lowest"})}destroy(){super.destroy(),this._typingQueue.destroy()}}class ye{editor;flushDebounced=pe(()=>this.flush("timeout"),50);_queue=[];_isComposing=!1;_affectedElements=new Set;constructor(e){this.editor=e}destroy(){for(this.flushDebounced.cancel(),this._affectedElements.clear();this._queue.length;)this.shift()}get length(){return this._queue.length}push(e,t){const n={text:e.text};if(e.selection){n.selectionRanges=[];for(const s of e.selection.getRanges())n.selectionRanges.push(ue.fromRange(s)),this._affectedElements.add(s.start.parent)}this._queue.push(n),this._isComposing||=t,this.flushDebounced()}shift(){const e=this._queue.shift(),t={text:e.text};if(e.selectionRanges){const n=e.selectionRanges.map(s=>ve(s)).filter(s=>!!s);n.length&&(t.selection=this.editor.model.createSelection(n))}return t}flush(e){const t=this.editor,n=t.model,s=t.editing.view;if(this.flushDebounced.cancel(),!this._queue.length)return;const c=t.commands.get("insertText").buffer;n.enqueueChange(c.batch,()=>{for(c.lock();this._queue.length;){const r=this.shift();t.execute("insertText",r)}c.unlock(),this._isComposing||this._affectedElements.clear(),this._isComposing=!1}),s.scrollToTheSelection()}isElementAffected(e){return this._affectedElements.has(e)}hasAffectedElements(){return this._affectedElements.size>0}flushAffectedElements(){const e=Array.from(this._affectedElements);return this._affectedElements.clear(),e}}function U(o,e){if(!e.isEnabled)return;const t=e.buffer;t.lock(),o.enqueueChange(t.batch,()=>{o.deleteContent(o.document.selection)}),t.unlock()}function ve(o){const e=o.toRange();return o.detach(),e.root.rootName=="$graveyard"?null:e}function Ee(o,e){let t=o.is("$text")?o.parent:o;for(;!e.toModelElement(t);)t=t.parent;return t}/**
* @license Copyright (c) 2003-2026, CKSource Holding sp. z o.o. All rights reserved.
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options
*/class F extends q{direction;_buffer;constructor(e,t){super(e),this.direction=t,this._buffer=new I(e.model,e.config.get("typing.undoStep")),this._isEnabledBasedOnSelection=!1}get buffer(){return this._buffer}execute(e={}){const t=this.editor.model,n=t.document;t.enqueueChange(this._buffer.batch,s=>{this._buffer.lock();const i=s.createSelection(e.selection||n.selection);if(!t.canEditAt(i))return;const c=e.sequence||1,r=i.isCollapsed;if(i.isCollapsed&&t.modifySelection(i,{direction:this.direction,unit:e.unit,treatEmojiAsSingleUnit:!0}),this._shouldEntireContentBeReplacedWithParagraph(c)){this._replaceEntireContentWithParagraph(s);return}if(this._shouldReplaceFirstBlockWithParagraph(i,c)){this.editor.execute("paragraph",{selection:i});return}if(i.isCollapsed)return;let l=0;i.getFirstRange().getMinimalFlatRanges().forEach(a=>{l+=se(a.getWalker({singleCharacters:!0,ignoreElementEnd:!0,shallow:!0}))}),t.deleteContent(i,{doNotResetEntireContent:r,direction:this.direction}),this._buffer.input(l),s.setSelection(i),this._buffer.unlock()})}_shouldEntireContentBeReplacedWithParagraph(e){if(e>1)return!1;const t=this.editor.model,s=t.document.selection,i=t.schema.getLimitElement(s);if(!(s.isCollapsed&&s.containsEntireContent(i))||!t.schema.checkChild(i,"paragraph"))return!1;const r=i.getChild(0);return!(r&&r.is("element","paragraph"))}_replaceEntireContentWithParagraph(e){const t=this.editor.model,s=t.document.selection,i=t.schema.getLimitElement(s),c=e.createElement("paragraph");e.remove(e.createRangeIn(i)),e.insert(c,i),e.setSelection(c,0)}_shouldReplaceFirstBlockWithParagraph(e,t){const n=this.editor.model;if(t>1||this.direction!="backward"||!e.isCollapsed)return!1;const s=e.getFirstPosition(),i=n.schema.getLimitElement(s),c=i.getChild(0);return!(s.parent!=c||!e.containsEntireContent(c)||!n.schema.checkChild(i,"paragraph")||c.name=="paragraph")}}/**
* @license Copyright (c) 2003-2026, CKSource Holding sp. z o.o. All rights reserved.
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options
*/const Te="character",Q="word",Ce="codePoint",y="selection",T="backward",w="forward",j={deleteContent:{unit:y,direction:T},deleteContentBackward:{unit:Ce,direction:T},deleteWordBackward:{unit:Q,direction:T},deleteHardLineBackward:{unit:y,direction:T},deleteSoftLineBackward:{unit:y,direction:T},deleteContentForward:{unit:Te,direction:w},deleteWordForward:{unit:Q,direction:w},deleteHardLineForward:{unit:y,direction:w},deleteSoftLineForward:{unit:y,direction:w}};class H extends N{constructor(e){super(e);const t=e.document;let n=0;t.on("keydown",()=>{n++}),t.on("keyup",()=>{n=0}),t.on("beforeinput",(s,i)=>{if(!this.isEnabled)return;const{targetRanges:c,domEvent:r,inputType:l}=i,a=j[l];if(!a)return;const u={direction:a.direction,unit:a.unit,sequence:n};u.unit==y&&(u.selectionToRemove=e.createSelection(c[0])),l==="deleteContentBackward"&&(v.isAndroid&&(u.sequence=1),Ae(c)&&(u.unit=y,u.selectionToRemove=e.createSelection(c)));const d=new B(t,"delete",c[0]);t.fire(d,new A(e,r,u)),d.stop.called&&s.stop()}),v.isBlink&&xe(this)}observe(){}stopObserving(){}}function xe(o){const e=o.view,t=e.document;let n=null,s=!1;t.on("keydown",(r,{keyCode:l})=>{n=l,s=!1}),t.on("keyup",(r,{keyCode:l,domEvent:a})=>{const u=t.selection,d=o.isEnabled&&l==n&&i(l)&&!u.isCollapsed&&!s;if(n=null,d){const h=u.getFirstRange(),m=new B(t,"delete",h),f={unit:y,direction:c(l),selectionToRemove:u};t.fire(m,new A(e,a,f))}}),t.on("beforeinput",(r,{inputType:l})=>{const a=j[l];i(n)&&a&&a.direction==c(n)&&(s=!0)},{priority:"high"}),t.on("beforeinput",(r,{inputType:l,data:a})=>{n==E.delete&&l=="insertText"&&a=="\x7F"&&r.stop()},{priority:"high"});function i(r){return r==E.backspace||r==E.delete}function c(r){return r==E.backspace?T:w}}function Ae(o){if(o.length!=1||o[0].isCollapsed)return!1;const e=o[0].getWalker({direction:"backward",singleCharacters:!0,ignoreElementEnd:!0});let t=0;for(const{nextPosition:n,item:s}of e){if(n.parent.is("$text")){const i=n.parent.data,c=n.offset;if(oe(i,c)||re(i,c)||ce(i,c))continue;t++}else(s.is("containerElement")||s.is("emptyElement"))&&t++;if(t>1)return!0}return!1}/**
* @license Copyright (c) 2003-2026, CKSource Holding sp. z o.o. All rights reserved.
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options
*/class K extends x{_undoOnBackspace;static get pluginName(){return"Delete"}static get isOfficialPlugin(){return!0}init(){const e=this.editor,t=e.editing.view,n=t.document,s=e.model.document;t.addObserver(H),this._undoOnBackspace=!1;const i=new F(e,"forward");e.commands.add("deleteForward",i),e.commands.add("forwardDelete",i),e.commands.add("delete",new F(e,"backward")),this.listenTo(n,"delete",(c,r)=>{n.isComposing||r.preventDefault();const{direction:l,sequence:a,selectionToRemove:u,unit:d}=r,h=l==="forward"?"deleteForward":"delete",m={sequence:a};if(d=="selection"){const f=Array.from(u.getRanges()).map(g=>e.editing.mapper.toModelRange(g)).map(g=>M(g,e.model.schema)||g);m.selection=e.model.createSelection(f)}else m.unit=d;e.execute(h,m),t.scrollToTheSelection()},{priority:"low"}),this.listenTo(n,"keydown",(c,r)=>{if(n.isComposing||r.keyCode!=E.backspace||!s.selection.isCollapsed)return;const l=e.model.schema.getLimitElement(s.selection),a=e.model.createPositionAt(l,0);if(a.isTouching(s.selection.getFirstPosition())){r.preventDefault();const u=e.model.schema.getNearestSelectionRange(a,"forward");if(!u)return;const d=t.createSelection(e.editing.mapper.toViewRange(u)),h=d.getFirstRange(),m=new B(document,"delete",h),f={unit:"selection",direction:"backward",selectionToRemove:d};n.fire(m,new A(t,r.domEvent,f))}}),this.editor.plugins.has("UndoEditing")&&(this.listenTo(n,"delete",(c,r)=>{this._undoOnBackspace&&r.direction=="backward"&&r.sequence==1&&r.unit=="codePoint"&&(this._undoOnBackspace=!1,e.execute("undo"),r.preventDefault(),c.stop())},{context:"$capture"}),this.listenTo(s,"change",()=>{this._undoOnBackspace=!1}))}requestUndoOnBackspace(){this.editor.plugins.has("UndoEditing")&&(this._undoOnBackspace=!0)}}/**
* @license Copyright (c) 2003-2026, CKSource Holding sp. z o.o. All rights reserved.
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options
*/class we extends x{static get requires(){return[W,K]}static get pluginName(){return"Typing"}static get isOfficialPlugin(){return!0}}/**
* @license Copyright (c) 2003-2026, CKSource Holding sp. z o.o. All rights reserved.
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options
*/function V(o,e){let t=o.start;return{text:Array.from(o.getWalker({ignoreElementEnd:!1})).reduce((s,{item:i})=>i.is("$text")||i.is("$textProxy")?s+i.data:(t=e.createPositionAfter(i),""),""),range:e.createRange(t,o.end)}}/**
* @license Copyright (c) 2003-2026, CKSource Holding sp. z o.o. All rights reserved.
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options
*/class Y extends le(){model;testCallback;_hasMatch;constructor(e,t){super(),this.model=e,this.testCallback=t,this._hasMatch=!1,this.set("isEnabled",!0),this.on("change:isEnabled",()=>{this.isEnabled?this._startListening():(this.stopListening(e.document.selection),this.stopListening(e.document))}),this._startListening()}get hasMatch(){return this._hasMatch}_startListening(){const t=this.model.document;this.listenTo(t.selection,"change:range",(n,{directChange:s})=>{if(s){if(!t.selection.isCollapsed){this.hasMatch&&(this.fire("unmatched"),this._hasMatch=!1);return}this._evaluateTextBeforeSelection("selection")}}),this.listenTo(t,"change:data",(n,s)=>{s.isUndo||!s.isLocal||this._evaluateTextBeforeSelection("data",{batch:s})})}_evaluateTextBeforeSelection(e,t={}){const n=this.model,i=n.document.selection,c=n.createRange(n.createPositionAt(i.focus.parent,0),i.focus),{text:r,range:l}=V(c,n),a=this.testCallback(r);if(!a&&this.hasMatch&&this.fire("unmatched"),this._hasMatch=!!a,a){const u=Object.assign(t,{text:r,range:l});typeof a=="object"&&Object.assign(u,a),this.fire(`matched:${e}`,u)}}}/**
* @license Copyright (c) 2003-2026, CKSource Holding sp. z o.o. All rights reserved.
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options
*/class Se extends x{attributes;_overrideUid;_isNextGravityRestorationSkipped=!1;static get pluginName(){return"TwoStepCaretMovement"}static get isOfficialPlugin(){return!0}constructor(e){super(e),this.attributes=new Set,this._overrideUid=null}init(){const e=this.editor,t=e.model,n=e.editing.view,s=e.locale,i=t.document.selection;this.listenTo(n.document,"arrowKey",(c,r)=>{if(!i.isCollapsed||r.shiftKey||r.altKey||r.ctrlKey)return;const l=r.keyCode==E.arrowright,a=r.keyCode==E.arrowleft;if(!l&&!a)return;const u=s.contentLanguageDirection;let d=!1;u==="ltr"&&l||u==="rtl"&&a?d=this._handleForwardMovement(r):d=this._handleBackwardMovement(r),d===!0&&c.stop()},{context:"$text",priority:"highest"}),this.listenTo(i,"change:range",(c,r)=>{if(this._isNextGravityRestorationSkipped){this._isNextGravityRestorationSkipped=!1;return}this._isGravityOverridden&&(!r.directChange&&p(i.getFirstPosition(),this.attributes)||this._restoreGravity())}),this._enableClickingAfterNode(),this._enableInsertContentSelectionAttributesFixer(),this._handleDeleteContentAfterNode()}registerAttribute(e){this.attributes.add(e)}_handleForwardMovement(e){const t=this.attributes,n=this.editor.model,s=n.document.selection,i=s.getFirstPosition();return this._isGravityOverridden||i.isAtStart&&_(s,t)?!1:p(i,t)?(e&&k(e),_(s,t)&&p(i,t,!0)?S(n,t):this._overrideGravity(),!0):!1}_handleBackwardMovement(e){const t=this.attributes,n=this.editor.model,s=n.document.selection,i=s.getFirstPosition();return this._isGravityOverridden?(e&&k(e),this._restoreGravity(),p(i,t,!0)?S(n,t):O(n,t,i),!0):i.isAtStart?_(s,t)?(e&&k(e),O(n,t,i),!0):!1:!_(s,t)&&p(i,t,!0)?(e&&k(e),O(n,t,i),!0):J(i,t)?i.isAtEnd&&!_(s,t)&&p(i,t)?(e&&k(e),O(n,t,i),!0):(this._isNextGravityRestorationSkipped=!0,this._overrideGravity(),!1):!1}_enableClickingAfterNode(){const e=this.editor,t=e.model,n=t.document.selection,s=e.editing.view.document;e.editing.view.addObserver(de),e.editing.view.addObserver(fe);let i=!1,c=!1;this.listenTo(s,"touchstart",()=>{c=!1,i=!0}),this.listenTo(s,"mousedown",()=>{c=!0}),this.listenTo(s,"selectionChange",()=>{const r=this.attributes;if(!c&&!i||(c=!1,i=!1,!n.isCollapsed)||!_(n,r))return;const l=n.getFirstPosition();p(l,r)&&(l.isAtStart||p(l,r,!0)?S(t,r):this._isGravityOverridden||this._overrideGravity())})}_enableInsertContentSelectionAttributesFixer(){const t=this.editor.model,n=t.document.selection,s=this.attributes;this.listenTo(t,"insertContent",()=>{const i=n.getFirstPosition();_(n,s)&&p(i,s)&&S(t,s)},{priority:"low"})}_handleDeleteContentAfterNode(){const e=this.editor,t=e.model,n=t.document.selection,s=e.editing.view;let i=!1,c=!1;this.listenTo(s.document,"delete",(r,l)=>{i=l.direction==="backward"},{priority:"high"}),this.listenTo(t,"deleteContent",()=>{if(!i)return;const r=n.getFirstPosition();c=_(n,this.attributes)&&!J(r,this.attributes)},{priority:"high"}),this.listenTo(t,"deleteContent",()=>{i&&(i=!1,!c&&e.model.enqueueChange(()=>{const r=n.getFirstPosition();_(n,this.attributes)&&p(r,this.attributes)&&(r.isAtStart||p(r,this.attributes,!0)?S(t,this.attributes):this._isGravityOverridden||this._overrideGravity())}))},{priority:"low"})}get _isGravityOverridden(){return!!this._overrideUid}_overrideGravity(){this._overrideUid=this.editor.model.change(e=>e.overrideSelectionGravity())}_restoreGravity(){this.editor.model.change(e=>{e.restoreSelectionGravity(this._overrideUid),this._overrideUid=null})}}function _(o,e){for(const t of e)if(o.hasAttribute(t))return!0;return!1}function O(o,e,t){const n=t.nodeBefore;o.change(s=>{if(n){const i=[],c=o.schema.isObject(n)&&o.schema.isInline(n);for(const[r,l]of n.getAttributes())o.schema.checkAttribute("$text",r)&&(!c||o.schema.getAttributeProperties(r).copyFromObject!==!1)&&i.push([r,l]);s.setSelectionAttribute(i)}else s.removeSelectionAttribute(e)})}function S(o,e){o.change(t=>{t.removeSelectionAttribute(e)})}function k(o){o.preventDefault()}function J(o,e){const t=o.getShiftedBy(-1);return p(t,e)}function p(o,e,t=!1){const{nodeBefore:n,nodeAfter:s}=o;for(const i of e){const c=n?n.getAttribute(i):void 0,r=s?s.getAttribute(i):void 0;if(!(t&&(c===void 0||r===void 0))&&r!==c)return!0}return!1}/**
* @license Copyright (c) 2003-2026, CKSource Holding sp. z o.o. All rights reserved.
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options
*/const X={copyright:{from:"(c)",to:"\xA9"},registeredTrademark:{from:"(r)",to:"\xAE"},trademark:{from:"(tm)",to:"\u2122"},oneHalf:{from:/(^|[^/a-z0-9])(1\/2)([^/a-z0-9])$/i,to:[null,"\xBD",null]},oneThird:{from:/(^|[^/a-z0-9])(1\/3)([^/a-z0-9])$/i,to:[null,"\u2153",null]},twoThirds:{from:/(^|[^/a-z0-9])(2\/3)([^/a-z0-9])$/i,to:[null,"\u2154",null]},oneForth:{from:/(^|[^/a-z0-9])(1\/4)([^/a-z0-9])$/i,to:[null,"\xBC",null]},threeQuarters:{from:/(^|[^/a-z0-9])(3\/4)([^/a-z0-9])$/i,to:[null,"\xBE",null]},lessThanOrEqual:{from:"<=",to:"\u2264"},greaterThanOrEqual:{from:">=",to:"\u2265"},notEqual:{from:"!=",to:"\u2260"},arrowLeft:{from:"<-",to:"\u2190"},arrowRight:{from:"->",to:"\u2192"},horizontalEllipsis:{from:"...",to:"\u2026"},enDash:{from:/(^| )(--)( )$/,to:[null,"\u2013",null]},emDash:{from:/(^| )(---)( )$/,to:[null,"\u2014",null]},quotesPrimary:{from:C('"'),to:[null,"\u201C",null,"\u201D"]},quotesSecondary:{from:C("'"),to:[null,"\u2018",null,"\u2019"]},quotesPrimaryEnGb:{from:C("'"),to:[null,"\u2018",null,"\u2019"]},quotesSecondaryEnGb:{from:C('"'),to:[null,"\u201C",null,"\u201D"]},quotesPrimaryPl:{from:C('"'),to:[null,"\u201E",null,"\u201D"]},quotesSecondaryPl:{from:C("'"),to:[null,"\u201A",null,"\u2019"]}},Z={symbols:["copyright","registeredTrademark","trademark"],mathematical:["oneHalf","oneThird","twoThirds","oneForth","threeQuarters","lessThanOrEqual","greaterThanOrEqual","notEqual","arrowLeft","arrowRight"],typography:["horizontalEllipsis","enDash","emDash"],quotes:["quotesPrimary","quotesSecondary"]},ke=["symbols","mathematical","typography","quotes"];class Re extends x{static get requires(){return["Delete","Input"]}static get pluginName(){return"TextTransformation"}static get isOfficialPlugin(){return!0}constructor(e){super(e),e.config.define("typing",{transformations:{include:ke}})}init(){const t=this.editor.model.document.selection;t.on("change:range",()=>{const n=t.anchor,s=!!n&&n.parent.is("element","codeBlock"),i=t.hasAttribute("code");this.isEnabled=!(s||i)}),this._enableTransformationWatchers()}_enableTransformationWatchers(){const e=this.editor,t=e.model,n=e.plugins.get("Delete"),s=Be(e.config.get("typing.transformations")),i=r=>{for(const l of s)if(l.from.test(r))return{normalizedTransformation:l}},c=new Y(e.model,i);c.on("matched:data",(r,l)=>{if(!l.batch.isTyping)return;const{from:a,to:u}=l.normalizedTransformation,d=a.exec(l.text),h=u(d.slice(1)),m=l.range;let f=d.index;t.enqueueChange(g=>{for(let b=1;b<d.length;b++){const R=d[b],D=h[b-1];if(D==null){f+=R.length;continue}const P=m.start.getShiftedBy(f),te=t.createRange(P,P.getShiftedBy(R.length)),ne=Pe(P);t.insertContent(g.createText(D,ne),te),f+=D.length}t.enqueueChange(()=>{n.requestUndoOnBackspace()})})}),c.bind("isEnabled").to(this)}}function Oe(o){return typeof o=="string"?new RegExp(`(${_e(o)})$`):o}function De(o){return typeof o=="string"?()=>[o]:o instanceof Array?()=>o:o}function Pe(o){return(o.textNode?o.textNode:o.nodeAfter).getAttributes()}function C(o){return new RegExp(`(^|\\s)(${o})([^${o}]*)(${o})$`)}function Be(o){const e=o.extra||[],t=o.remove||[],n=i=>!t.includes(i),s=o.include.concat(e).filter(n);return Ie(s).filter(n).map(i=>typeof i=="string"&&X[i]?X[i]:i).filter(i=>typeof i=="object").map(i=>({from:Oe(i.from),to:De(i.to)}))}function Ie(o){const e=new Set;for(const t of o)if(typeof t=="string"&&Z[t])for(const n of Z[t])e.add(n);else e.add(t);return Array.from(e)}/**
* @license Copyright (c) 2003-2026, CKSource Holding sp. z o.o. All rights reserved.
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options
*/function ee(o,e,t,n){return n.createRange(L(o,e,t,!0,n),L(o,e,t,!1,n))}function L(o,e,t,n,s){let i=o.textNode||(n?o.nodeBefore:o.nodeAfter),c=null;for(;i&&i.getAttribute(e)==t;)c=i,i=n?i.previousSibling:i.nextSibling;return c?s.createPositionAt(c,n?"before":"after"):o}/**
* @license Copyright (c) 2003-2026, CKSource Holding sp. z o.o. All rights reserved.
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options
*/function Fe(o,e,t,n){const s=o.editing.view,i=new Set;s.document.registerPostFixer(c=>{const r=o.model.document.selection;let l=!1;if(r.hasAttribute(e)){const a=ee(r.getFirstPosition(),e,r.getAttribute(e),o.model),u=o.editing.mapper.toViewRange(a);for(const d of u.getItems())d.is("element",t)&&!d.hasClass(n)&&(c.addClass(n,d),i.add(d),l=!0)}return l}),o.conversion.for("editingDowncast").add(c=>{c.on("insert",r,{priority:"highest"}),c.on("remove",r,{priority:"highest"}),c.on("attribute",r,{priority:"highest"}),c.on("selection",r,{priority:"highest"});function r(){s.change(l=>{for(const a of i.values())l.removeClass(n,a),i.delete(a)})}})}export{K as Delete,F as DeleteCommand,W as Input,G as InsertTextCommand,Re as TextTransformation,Y as TextWatcher,Se as TwoStepCaretMovement,we as Typing,I as TypingChangeBuffer,H as _DeleteObserver,ee as findAttributeRange,L as findAttributeRangeBound,V as getLastTextLine,Fe as inlineHighlight};
