import{Plugin as l,MultiCommand as h,Command as w}from"@ckeditor/ckeditor5-core";import{ButtonView as b,MenuBarMenuListItemButtonView as p}from"@ckeditor/ckeditor5-ui";import{IconIndent as g,IconOutdent as m}from"@ckeditor/ckeditor5-icons";import{addMarginStylesRules as B}from"@ckeditor/ckeditor5-engine";import{first as v}from"@ckeditor/ckeditor5-utils";/**
* @license Copyright (c) 2003-2025, CKSource Holding sp. z o.o. All rights reserved.
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options
*/class I extends l{static get pluginName(){return"IndentEditing"}static get isOfficialPlugin(){return!0}init(){const t=this.editor;t.commands.add("indent",new h(t)),t.commands.add("outdent",new h(t))}}/**
* @license Copyright (c) 2003-2025, 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 l{static get pluginName(){return"IndentUI"}static get isOfficialPlugin(){return!0}init(){const t=this.editor,e=t.locale,n=t.t,s=e.uiLanguageDirection=="ltr"?g:m,i=e.uiLanguageDirection=="ltr"?m:g;this._defineButton("indent",n("Increase indent"),s),this._defineButton("outdent",n("Decrease indent"),i)}_defineButton(t,e,n){const s=this.editor;s.ui.componentFactory.add(t,()=>{const i=this._createButton(b,t,e,n);return i.set({tooltip:!0}),i}),s.ui.componentFactory.add("menuBar:"+t,()=>this._createButton(p,t,e,n))}_createButton(t,e,n,s){const i=this.editor,r=i.commands.get(e),d=new t(i.locale);return d.set({label:n,icon:s}),d.bind("isEnabled").to(r,"isEnabled"),this.listenTo(d,"execute",()=>{i.execute(e),i.editing.view.focus()}),d}}/**
* @license Copyright (c) 2003-2025, CKSource Holding sp. z o.o. All rights reserved.
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options
*/class C extends l{static get pluginName(){return"Indent"}static get isOfficialPlugin(){return!0}static get requires(){return[I,k]}}/**
* @license Copyright (c) 2003-2025, CKSource Holding sp. z o.o. All rights reserved.
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options
*/class c extends w{_indentBehavior;constructor(t,e){super(t),this._indentBehavior=e}refresh(){const e=this.editor.model,n=v(e.document.selection.getSelectedBlocks());if(!n||!this._isIndentationChangeAllowed(n)){this.isEnabled=!1;return}this.isEnabled=this._indentBehavior.checkEnabled(n.getAttribute("blockIndent"))}execute(){const t=this.editor.model,e=this._getBlocksToChange();t.change(n=>{for(const s of e){const i=s.getAttribute("blockIndent"),r=this._indentBehavior.getNextIndent(i);r?n.setAttribute("blockIndent",r,s):n.removeAttribute("blockIndent",s)}})}_getBlocksToChange(){const e=this.editor.model.document.selection;return Array.from(e.getSelectedBlocks()).filter(s=>this._isIndentationChangeAllowed(s))}_isIndentationChangeAllowed(t){const e=this.editor;return e.model.schema.checkAttribute(t,"blockIndent")?!e.plugins.has("ListUtils")||!this._indentBehavior.isForward?!0:!e.plugins.get("ListUtils").isListItemBlock(t):!1}}/**
* @license Copyright (c) 2003-2025, CKSource Holding sp. z o.o. All rights reserved.
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options
*/class u{isForward;offset;unit;constructor(t){this.isForward=t.direction==="forward",this.offset=t.offset,this.unit=t.unit}checkEnabled(t){const e=parseFloat(t||"0");return this.isForward||e>0}getNextIndent(t){const e=parseFloat(t||"0");if(!(!t||t.endsWith(this.unit)))return this.isForward?this.offset+this.unit:void 0;const s=this.isForward?this.offset:-this.offset,i=e+s;return i>0?i+this.unit:void 0}}/**
* @license Copyright (c) 2003-2025, CKSource Holding sp. z o.o. All rights reserved.
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options
*/class f{isForward;classes;constructor(t){this.isForward=t.direction==="forward",this.classes=t.classes}checkEnabled(t){const e=this.classes.indexOf(t);return this.isForward?e<this.classes.length-1:e>=0}getNextIndent(t){const e=this.classes.indexOf(t),n=this.isForward?1:-1;return this.classes[e+n]}}/**
* @license Copyright (c) 2003-2025, CKSource Holding sp. z o.o. All rights reserved.
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options
*/const _=["paragraph","heading1","heading2","heading3","heading4","heading5","heading6"];class x extends l{constructor(t){super(t),t.config.define("indentBlock",{offset:40,unit:"px"})}static get pluginName(){return"IndentBlock"}static get isOfficialPlugin(){return!0}init(){const t=this.editor,e=t.config.get("indentBlock");e.classes&&e.classes.length?(this._setupConversionUsingClasses(e.classes),t.commands.add("indentBlock",new c(t,new f({direction:"forward",classes:e.classes}))),t.commands.add("outdentBlock",new c(t,new f({direction:"backward",classes:e.classes})))):(t.data.addStyleProcessorRules(B),this._setupConversionUsingOffset(),t.commands.add("indentBlock",new c(t,new u({direction:"forward",offset:e.offset,unit:e.unit}))),t.commands.add("outdentBlock",new c(t,new u({direction:"backward",offset:e.offset,unit:e.unit}))))}afterInit(){const t=this.editor,e=t.model.schema,n=t.commands.get("indent"),s=t.commands.get("outdent"),i=t.config.get("heading.options");(i&&i.map(a=>a.model)||_).forEach(a=>{e.isRegistered(a)&&e.extend(a,{allowAttributes:"blockIndent"})}),e.setAttributeProperties("blockIndent",{isFormatting:!0}),n.registerChildCommand(t.commands.get("indentBlock")),s.registerChildCommand(t.commands.get("outdentBlock"))}_setupConversionUsingOffset(){const t=this.editor.conversion,n=this.editor.locale.contentLanguageDirection==="rtl"?"margin-right":"margin-left";t.for("upcast").attributeToAttribute({view:{styles:{[n]:/[\s\S]+/}},model:{key:"blockIndent",value:s=>{if(!s.is("element","li"))return s.getStyle(n)}}}),t.for("downcast").attributeToAttribute({model:"blockIndent",view:s=>({key:"style",value:{[n]:s}})})}_setupConversionUsingClasses(t){const e={model:{key:"blockIndent",values:[]},view:{}};for(const n of t)e.model.values.push(n),e.view[n]={key:"class",value:[n]};this.editor.conversion.attributeToAttribute(e)}}export{C as Indent,x as IndentBlock,c as IndentBlockCommand,I as IndentEditing,k as IndentUI,f as _IndentUsingClasses,u as _IndentUsingOffset};
