import{Command as B,Plugin as b}from"@ckeditor/ckeditor5-core";import{ModelDocumentSelection as E}from"@ckeditor/ckeditor5-engine";import{IconEraser as f,IconMarker as H,IconPen as M}from"@ckeditor/ckeditor5-icons";import{ButtonView as T,createDropdown as A,SplitButtonView as C,addToolbarToDropdown as I,MenuBarMenuView as S,MenuBarMenuListView as O,MenuBarMenuListItemView as w,MenuBarMenuListItemButtonView as v,ListSeparatorView as P,ToolbarSeparatorView as R}from"@ckeditor/ckeditor5-ui";/**
* @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 V extends B{refresh(){const e=this.editor.model,t=e.document;this.value=t.selection.getAttribute("highlight"),this.isEnabled=e.schema.checkAttributeInSelection(t.selection,"highlight")}execute(e={}){const t=this.editor.model,h=t.document.selection,o=e.value;t.change(i=>{if(h.isCollapsed){const a=h.getFirstPosition();if(h.hasAttribute("highlight")){const r=d=>d.item.hasAttribute("highlight")&&d.item.getAttribute("highlight")===this.value,l=a.getLastMatchingPosition(r,{direction:"backward"}),n=a.getLastMatchingPosition(r),u=i.createRange(l,n);!o||this.value===o?(a.isEqual(n)||i.removeAttribute("highlight",u),i.removeSelectionAttribute("highlight")):(a.isEqual(n)||i.setAttribute("highlight",o,u),i.setSelectionAttribute("highlight",o))}else o&&i.setSelectionAttribute("highlight",o)}else{const a=t.schema.getValidRanges(h.getRanges(),"highlight",{includeEmptyRanges:!0});for(const r of a){let l=r,n="highlight";r.isCollapsed&&(l=r.start.parent,n=E._getStoreAttributeKey("highlight")),o?i.setAttribute(n,o,l):i.removeAttribute(n,l)}}})}}/**
* @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 b{static get pluginName(){return"HighlightEditing"}static get isOfficialPlugin(){return!0}constructor(e){super(e),e.config.define("highlight",{options:[{model:"yellowMarker",class:"marker-yellow",title:"Yellow marker",color:"var(--ck-content-highlight-marker-yellow)",type:"marker"},{model:"greenMarker",class:"marker-green",title:"Green marker",color:"var(--ck-content-highlight-marker-green)",type:"marker"},{model:"pinkMarker",class:"marker-pink",title:"Pink marker",color:"var(--ck-content-highlight-marker-pink)",type:"marker"},{model:"blueMarker",class:"marker-blue",title:"Blue marker",color:"var(--ck-content-highlight-marker-blue)",type:"marker"},{model:"redPen",class:"pen-red",title:"Red pen",color:"var(--ck-content-highlight-pen-red)",type:"pen"},{model:"greenPen",class:"pen-green",title:"Green pen",color:"var(--ck-content-highlight-pen-green)",type:"pen"}]})}init(){const e=this.editor;e.model.schema.extend("$text",{allowAttributes:"highlight"});const t=e.config.get("highlight.options");e.conversion.attributeToElement(_(t)),e.commands.add("highlight",new V(e))}}function _(g){const e={model:{key:"highlight",values:[]},view:{}};for(const t of g)e.model.values.push(t.model),e.view[t.model]={name:"mark",classes:t.class};return e}function D(g,{insertAt:e}={}){if(typeof document>"u")return;const t=document.head||document.getElementsByTagName("head")[0],c=document.createElement("style");c.type="text/css",window.litNonce&&c.setAttribute("nonce",window.litNonce),e==="top"&&t.firstChild?t.insertBefore(c,t.firstChild):t.appendChild(c),c.styleSheet?c.styleSheet.cssText=g:c.appendChild(document.createTextNode(g))}D(":root{--ck-content-highlight-marker-yellow:#fdfd77;--ck-content-highlight-marker-green:#62f962;--ck-content-highlight-marker-pink:#fc7899;--ck-content-highlight-marker-blue:#72ccfd;--ck-content-highlight-pen-red:#e71313;--ck-content-highlight-pen-green:#128a00}.ck-content .marker-yellow{background-color:var(--ck-content-highlight-marker-yellow)}.ck-content .marker-green{background-color:var(--ck-content-highlight-marker-green)}.ck-content .marker-pink{background-color:var(--ck-content-highlight-marker-pink)}.ck-content .marker-blue{background-color:var(--ck-content-highlight-marker-blue)}.ck-content .pen-red{background-color:transparent;color:var(--ck-content-highlight-pen-red)}.ck-content .pen-green{background-color:transparent;color:var(--ck-content-highlight-pen-green)}");/**
* @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 x extends b{get localizedOptionTitles(){const e=this.editor.t;return{"Yellow marker":e("Yellow marker"),"Green marker":e("Green marker"),"Pink marker":e("Pink marker"),"Blue marker":e("Blue marker"),"Red pen":e("Red pen"),"Green pen":e("Green pen")}}static get pluginName(){return"HighlightUI"}static get isOfficialPlugin(){return!0}init(){const e=this.editor.config.get("highlight.options");for(const t of e)this._addHighlighterButton(t);this._addRemoveHighlightButton(),this._addDropdown(e),this._addMenuBarButton(e)}_addRemoveHighlightButton(){const e=this.editor.t,t=this.editor.commands.get("highlight");this._addButton("removeHighlight",e("Remove highlight"),f,null,c=>{c.bind("isEnabled").to(t,"isEnabled")})}_addHighlighterButton(e){const t=this.editor.commands.get("highlight");this._addButton("highlight:"+e.model,e.title,p(e.type),e.model,c);function c(h){h.bind("isEnabled").to(t,"isEnabled"),h.bind("isOn").to(t,"value",o=>o===e.model),h.iconView.fillColor=e.color,h.isToggleable=!0}}_addButton(e,t,c,h,o){const i=this.editor;i.ui.componentFactory.add(e,a=>{const r=new T(a),l=this.localizedOptionTitles[t]?this.localizedOptionTitles[t]:t;return r.set({label:l,icon:c,tooltip:!0}),r.on("execute",()=>{i.execute("highlight",{value:h}),i.editing.view.focus()}),o(r),r})}_addDropdown(e){const t=this.editor,c=t.t,h=t.ui.componentFactory,o=e[0],i=e.reduce((a,r)=>(a[r.model]=r,a),{});h.add("highlight",a=>{const r=t.commands.get("highlight"),l=A(a,C),n=l.buttonView;n.set({label:c("Highlight"),tooltip:!0,lastExecuted:o.model,commandValue:o.model,isToggleable:!0}),n.bind("icon").to(r,"value",s=>p(d(s,"type"))),n.bind("color").to(r,"value",s=>d(s,"color")),n.bind("commandValue").to(r,"value",s=>d(s,"model")),n.bind("isOn").to(r,"value",s=>!!s),n.delegate("execute").to(l);const u=()=>{const s=e.map(m=>{const k=h.create("highlight:"+m.model);return this.listenTo(k,"execute",()=>{l.buttonView.set({lastExecuted:m.model})}),k});return s.push(new R),s.push(h.create("removeHighlight")),s};l.bind("isEnabled").to(r,"isEnabled"),I(l,u,{enableActiveItemFocusOnDropdownOpen:!0,ariaLabel:c("Text highlight toolbar")}),F(l),n.on("execute",()=>{t.execute("highlight",{value:n.commandValue})}),this.listenTo(l,"execute",()=>{t.editing.view.focus()});function d(s,m){const k=!s||s===n.lastExecuted?n.lastExecuted:s;return i[k][m]}return l})}_addMenuBarButton(e){const t=this.editor,c=t.t,h=t.commands.get("highlight");t.ui.componentFactory.add("menuBar:highlight",o=>{const i=new S(o);i.buttonView.set({label:c("Highlight"),icon:p("marker")}),i.bind("isEnabled").to(h),i.buttonView.iconView.fillColor="transparent";const a=new O(o);for(const n of e){const u=new w(o,i),d=new v(o);d.set({label:n.title,icon:p(n.type),role:"menuitemradio",isToggleable:!0}),d.iconView.fillColor=n.color,d.delegate("execute").to(i),d.bind("isOn").to(h,"value",s=>s===n.model),d.on("execute",()=>{t.execute("highlight",{value:n.model}),t.editing.view.focus()}),u.children.add(d),a.items.add(u)}a.items.add(new P(o));const r=new w(o,i),l=new v(o);return l.set({label:c("Remove highlight"),icon:f}),l.delegate("execute").to(i),l.on("execute",()=>{t.execute("highlight",{value:null}),t.editing.view.focus()}),r.children.add(l),a.items.add(r),i.panelView.children.add(a),i})}}function F(g){g.buttonView.actionView.iconView.bind("fillColor").to(g.buttonView,"color")}function p(g){return g==="marker"?H:M}/**
* @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 L extends b{static get requires(){return[y,x]}static get pluginName(){return"Highlight"}static get isOfficialPlugin(){return!0}}export{L as Highlight,V as HighlightCommand,y as HighlightEditing,x as HighlightUI};
