import{d as r,e as P,g as S,W as y,f as g,b as k,a as A,c as B}from"./applyTemplate-BnHIDwqK.js";const D=[{key:"正文",value:"Main"},{key:"标题 1",value:"P1"},{key:"标题 2",value:"P2"},{key:"标题 3",value:"P3"},{key:"标题 4",value:"P4"},{key:"标题 5",value:"P5"},{key:"标题 6",value:"P6"},{key:"标题 7",value:"P7"},{key:"标题 8",value:"P8"},{key:"标题 9",value:"P9"}],h=(o,e)=>{o.LineSpacingRule=e},N=(o,e)=>{o.CharacterUnitFirstLineIndent=e},z=(o,e)=>{o.SpaceBefore=e},v=(o,e)=>{o.Alignment=e},U=(o,e)=>{if(!o)return;let a=o.Range.Font;a.Name=e.Name,a.NameAscii=e.NameAscii,a.NameBi=e.NameBi,a.NameFarEast=e.NameFarEast,a.NameOther=e.NameOther,a.Size=e.Size,a.SizeBi=e.SizeBi,a.Bold=e.Bold,a.BoldBi=e.BoldBi,a.Italic=e.Italic,a.ItalicBi=e.ItalicBi};function W(o={}){const e=o.wpsDoc;return new Promise((a,t)=>{if(window.wps){const n=(e?r(e):r(window.Application.ActiveDocument)).map(s=>({id:s.ParaID,text:s.Range.Text.trim(),_self:s}));a({paragraphs:n})}else if(window.YozoDocUtil){const i=JSON.parse(YozoDocUtil.getAllParagraphs());if(i.code===200){const n=i.data.map(s=>({id:s.index,text:s.text,_self:s}));a({paragraphs:n})}else t(i.msg||"未知异常")}else t("未检测到word环境")})}function Y(o,e){return new Promise((a,t)=>{if(window.wps){const s=r(window.Application.ActiveDocument)[o].Range;s.Text=e+"\r",s.Select(),a({msg:"操作成功"})}else if(window.YozoDocUtil){const i={paragraphIndex:o,newText:e},n=JSON.parse(YozoDocUtil.replaceParagraph(JSON.stringify(i)));n.code===200?a({msg:"操作成功"}):t(n.msg||"未知异常")}else t("未检测到word环境")})}function L(o){return new Promise((e,a)=>{if(window.wps){const t=Application.Selection;t.WholeStory(),t.TypeText(o),e({msg:"操作成功"})}else if(window.YozoDocUtil){const t=JSON.parse(YozoDocUtil.replaceAllText(o));t.code===200?e({msg:"操作成功"}):a(t.msg||"未知异常")}else a("未检测到word环境")})}const O=(o,e)=>new Promise((a,t)=>{setTimeout(()=>{h(o,e.LineSpacingRule),U(o,e.Font),N(o,e.CharacterUnitFirstLineIndent),z(o,e.SpaceBefore),v(o,e.Alignment),a()},200)});function R(o){return new Promise(async(e,a)=>{if(window.wps){const t=S(),i=y(o),n=t.Bookmarks,s=[g(n,"Header",0),g(n,"Footer",100)];await Promise.all(s);const w=await k(t,i),p=A();for(let l=0;l<p.length;l++){const c=p[l];let m=D.find(u=>u.key==c.Style.NameLocal),d=m?m.value:"Main";const f=w[d];c.Range.Select(),await O(c,f)}await B(t,i),i.Close(),wps.FileSystem.Remove(o),e({msg:"模板应用成功"})}else window.YozoDocUtil?(console.log("模板应用"),e({msg:"模板应用成功"})):a("未检测到word环境")})}function x(o){return new Promise(async(e,a)=>{if(window.wps){const t=P(o,null,!1);t?e({data:t,msg:"操作成功"}):a("打开失败")}else if(window.YozoDocUtil){const t=await YozoDocUtil.openFileByAbsoluteFilePath(o),i=JSON.parse(t);i.code===200?e({msg:"操作成功"}):a(i.msg||"未知异常")}else a("未检测到word环境")})}export{R as a,Y as b,W as g,x as o,L as r};
