/*!
Copyright (c) 2026 Lenovo SSG BASD. All rights reserved.
@license Proprietary

This software is the confidential and proprietary property of Lenovo SSG BASD.
You shall not disclose such Confidential Information and shall use it only in
accordance with the terms of the license agreement.

--- Build Info ---
Version: 1.1.1
Build Time: 2026/2/26 17:21:00
Build Commit: 81e556ed827e2f043668506dae6fae8dbb9ef395
*/
import{Mark as t,mergeAttributes as e,Extension as o}from"../../core/dist/index.js";var n=(t,e=0)=>{const o=[];return!t.children.length||e>20||Array.from(t.children).forEach(t=>{"SPAN"===t.tagName?o.push(t):t.children.length&&o.push(...n(t,e+1))}),o},r=t.create({name:"textStyle",priority:101,addOptions:()=>({HTMLAttributes:{},mergeNestedSpanStyles:!0}),parseHTML(){return[{tag:"span",consuming:!1,getAttrs:t=>!!t.hasAttribute("style")&&(this.options.mergeNestedSpanStyles&&(t=>{if(!t.children.length)return;const e=n(t);e&&e.forEach(t=>{var e,o;const n=t.getAttribute("style"),r=null==(o=null==(e=t.parentElement)?void 0:e.closest("span"))?void 0:o.getAttribute("style");t.setAttribute("style",`${r};${n}`)})})(t),{})}]},renderHTML({HTMLAttributes:t}){return["span",e(this.options.HTMLAttributes,t),0]},addCommands(){return{toggleTextStyle:t=>({commands:e})=>e.toggleMark(this.name,t),removeEmptyTextStyle:()=>({tr:t})=>{const{selection:e}=t;return t.doc.nodesBetween(e.from,e.to,(e,o)=>{if(e.isTextblock)return!0;e.marks.filter(t=>t.type===this.type).some(t=>Object.values(t.attrs).some(t=>!!t))||t.removeMark(o,o+e.nodeSize,this.type)}),!0}}}}),s=o.create({name:"backgroundColor",addOptions:()=>({types:["textStyle"]}),addGlobalAttributes(){return[{types:this.options.types,attributes:{backgroundColor:{default:null,parseHTML:t=>{var e;const o=t.getAttribute("style");if(o){const t=o.split(";").map(t=>t.trim()).filter(Boolean);for(let e=t.length-1;e>=0;e-=1){const o=t[e].split(":");if(o.length>=2){const t=o[0].trim().toLowerCase(),e=o.slice(1).join(":").trim();if("background-color"===t)return e.replace(/['"]+/g,"")}}}return null==(e=t.style.backgroundColor)?void 0:e.replace(/['"]+/g,"")},renderHTML:t=>t.backgroundColor?{style:`background-color: ${t.backgroundColor}`}:{}}}}]},addCommands:()=>({setBackgroundColor:t=>({chain:e})=>e().setMark("textStyle",{backgroundColor:t}).run(),unsetBackgroundColor:()=>({chain:t})=>t().setMark("textStyle",{backgroundColor:null}).removeEmptyTextStyle().run()})}),i=o.create({name:"color",addOptions:()=>({types:["textStyle"]}),addGlobalAttributes(){return[{types:this.options.types,attributes:{color:{default:null,parseHTML:t=>{var e;const o=t.getAttribute("style");if(o){const t=o.split(";").map(t=>t.trim()).filter(Boolean);for(let e=t.length-1;e>=0;e-=1){const o=t[e].split(":");if(o.length>=2){const t=o[0].trim().toLowerCase(),e=o.slice(1).join(":").trim();if("color"===t)return e.replace(/['"]+/g,"")}}}return null==(e=t.style.color)?void 0:e.replace(/['"]+/g,"")},renderHTML:t=>t.color?{style:`color: ${t.color}`}:{}}}}]},addCommands:()=>({setColor:t=>({chain:e})=>e().setMark("textStyle",{color:t}).run(),unsetColor:()=>({chain:t})=>t().setMark("textStyle",{color:null}).removeEmptyTextStyle().run()})}),l=o.create({name:"fontFamily",addOptions:()=>({types:["textStyle"]}),addGlobalAttributes(){return[{types:this.options.types,attributes:{fontFamily:{default:null,parseHTML:t=>t.style.fontFamily,renderHTML:t=>t.fontFamily?{style:`font-family: ${t.fontFamily}`}:{}}}}]},addCommands:()=>({setFontFamily:t=>({chain:e})=>e().setMark("textStyle",{fontFamily:t}).run(),unsetFontFamily:()=>({chain:t})=>t().setMark("textStyle",{fontFamily:null}).removeEmptyTextStyle().run()})}),a=o.create({name:"fontSize",addOptions:()=>({types:["textStyle"]}),addGlobalAttributes(){return[{types:this.options.types,attributes:{fontSize:{default:null,parseHTML:t=>t.style.fontSize,renderHTML:t=>t.fontSize?{style:`font-size: ${t.fontSize}`}:{}}}}]},addCommands:()=>({setFontSize:t=>({chain:e})=>e().setMark("textStyle",{fontSize:t}).run(),unsetFontSize:()=>({chain:t})=>t().setMark("textStyle",{fontSize:null}).removeEmptyTextStyle().run()})}),u=o.create({name:"lineHeight",addOptions:()=>({types:["textStyle"]}),addGlobalAttributes(){return[{types:this.options.types,attributes:{lineHeight:{default:null,parseHTML:t=>t.style.lineHeight,renderHTML:t=>t.lineHeight?{style:`line-height: ${t.lineHeight}`}:{}}}}]},addCommands:()=>({setLineHeight:t=>({chain:e})=>e().setMark("textStyle",{lineHeight:t}).run(),unsetLineHeight:()=>({chain:t})=>t().setMark("textStyle",{lineHeight:null}).removeEmptyTextStyle().run()})});o.create({name:"textStyleKit",addExtensions(){const t=[];return!1!==this.options.backgroundColor&&t.push(s.configure(this.options.backgroundColor)),!1!==this.options.color&&t.push(i.configure(this.options.color)),!1!==this.options.fontFamily&&t.push(l.configure(this.options.fontFamily)),!1!==this.options.fontSize&&t.push(a.configure(this.options.fontSize)),!1!==this.options.lineHeight&&t.push(u.configure(this.options.lineHeight)),!1!==this.options.textStyle&&t.push(r.configure(this.options.textStyle)),t}});export{s as BackgroundColor,i as Color,l as FontFamily,a as FontSize,u as LineHeight,r as TextStyle};