@eigenpal/docx-js-editor 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/chunk-3IYNTJO5.js +1 -0
- package/dist/chunk-7KNRIGGW.cjs +1 -0
- package/dist/chunk-AQ35GWDV.js +1 -0
- package/dist/chunk-CDT2SOKB.cjs +9 -0
- package/dist/chunk-CM5WP7HZ.cjs +10 -0
- package/dist/chunk-EU5LN2WS.js +11 -0
- package/dist/chunk-FOU7PS3K.cjs +1 -0
- package/dist/chunk-G4AXMTQY.cjs +11 -0
- package/dist/chunk-HRPNPUU4.js +1 -0
- package/dist/chunk-NI5OFVY2.js +57 -0
- package/dist/chunk-QHWHCIUW.js +1 -0
- package/dist/chunk-RGYAPHXT.cjs +57 -0
- package/dist/chunk-RTESADL3.cjs +1 -0
- package/dist/chunk-T3I3VSJ3.js +9 -0
- package/dist/chunk-XVFMG77A.cjs +1 -0
- package/dist/chunk-YJJ7HRPG.js +10 -0
- package/dist/core-plugins.cjs +1 -7131
- package/dist/core-plugins.js +1 -7102
- package/dist/executor-7DZMHPUF.js +1 -0
- package/dist/executor-FSMRGT73.cjs +1 -0
- package/dist/headless.cjs +4 -10984
- package/dist/headless.d.cts +4 -3
- package/dist/headless.d.ts +4 -3
- package/dist/headless.js +4 -10852
- package/dist/index.cjs +210 -44710
- package/dist/index.css +1 -369
- package/dist/index.d.cts +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.js +210 -44385
- package/dist/mcp-cli.js +35 -9557
- package/dist/mcp.cjs +14 -8713
- package/dist/mcp.js +14 -8665
- package/dist/selectionRects-3PJ6FGHQ.js +1 -0
- package/dist/selectionRects-6QL5E7CE.cjs +1 -0
- package/package.json +3 -4
- package/dist/core-plugins.cjs.map +0 -1
- package/dist/core-plugins.js.map +0 -1
- package/dist/headless.cjs.map +0 -1
- package/dist/headless.js.map +0 -1
- package/dist/index.cjs.map +0 -1
- package/dist/index.css.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/mcp-cli.js.map +0 -1
- package/dist/mcp.cjs.map +0 -1
- package/dist/mcp.js.map +0 -1
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import {a,n}from'./chunk-YJJ7HRPG.js';import {d,e as e$1}from'./chunk-NI5OFVY2.js';import {l}from'./chunk-EU5LN2WS.js';import {b,a as a$1}from'./chunk-AQ35GWDV.js';import {e}from'./chunk-3IYNTJO5.js';var W={dk1:"000000",lt1:"FFFFFF",dk2:"44546A",lt2:"E7E6E6",accent1:"4472C4",accent2:"ED7D31",accent3:"A5A5A5",accent4:"FFC000",accent5:"5B9BD5",accent6:"70AD47",hlink:"0563C1",folHlink:"954F72"},Y={black:"000000",blue:"0000FF",cyan:"00FFFF",darkBlue:"00008B",darkCyan:"008B8B",darkGray:"A9A9A9",darkGreen:"006400",darkMagenta:"8B008B",darkRed:"8B0000",darkYellow:"808000",green:"00FF00",lightGray:"D3D3D3",magenta:"FF00FF",red:"FF0000",white:"FFFFFF",yellow:"FFFF00",none:""},w={dk1:"dk1",lt1:"lt1",dk2:"dk2",lt2:"lt2",accent1:"accent1",accent2:"accent2",accent3:"accent3",accent4:"accent4",accent5:"accent5",accent6:"accent6",hlink:"hlink",folHlink:"folHlink",dark1:"dk1",light1:"lt1",dark2:"dk2",light2:"lt2",hyperlink:"hlink",followedHyperlink:"folHlink",background1:"lt1",text1:"dk1",background2:"lt2",text2:"dk2",tx1:"dk1",tx2:"dk2",bg1:"lt1",bg2:"lt2"};function U(n){if(!n)return 1;let e=parseInt(n,16);return isNaN(e)?1:e/255}function C(n){let e=n.padStart(6,"0").slice(0,6),t=parseInt(e.slice(0,2),16),r=parseInt(e.slice(2,4),16),o=parseInt(e.slice(4,6),16);return {r:isNaN(t)?0:t,g:isNaN(r)?0:r,b:isNaN(o)?0:o}}function D(n,e,t){let r=o=>Math.max(0,Math.min(255,Math.round(o))).toString(16).padStart(2,"0");return `${r(n)}${r(e)}${r(t)}`.toUpperCase()}function $(n,e,t){n/=255,e/=255,t/=255;let r=Math.max(n,e,t),o=Math.min(n,e,t),a=(r+o)/2;if(r===o)return {h:0,s:0,l:a};let i=r-o,s=a>.5?i/(2-r-o):i/(r+o),u;switch(r){case n:u=((e-t)/i+(e<t?6:0))/6;break;case e:u=((t-n)/i+2)/6;break;case t:u=((n-e)/i+4)/6;break;default:u=0;}return {h:u*360,s,l:a}}function G(n,e,t){if(n=n/360,e===0){let i=Math.round(t*255);return {r:i,g:i,b:i}}let r=(i,s,u)=>(u<0&&(u+=1),u>1&&(u-=1),u<1/6?i+(s-i)*6*u:u<1/2?s:u<2/3?i+(s-i)*(2/3-u)*6:i),o=t<.5?t*(1+e):t+e-t*e,a=2*t-o;return {r:Math.round(r(a,o,n+1/3)*255),g:Math.round(r(a,o,n)*255),b:Math.round(r(a,o,n-1/3)*255)}}function q(n,e){if(e<=0||e>=1)return e>=1?"FFFFFF":n;let t=C(n),r=$(t.r,t.g,t.b);r.l=r.l+(1-r.l)*e;let o=G(r.h,r.s,r.l);return D(o.r,o.g,o.b)}function X(n,e){if(e<=0||e>=1)return e<=0?"000000":n;let t=C(n),r=$(t.r,t.g,t.b);r.l=r.l*e;let o=G(r.h,r.s,r.l);return D(o.r,o.g,o.b)}function J(n,e){let t=w[e]??e,r=["dk1","lt1","dk2","lt2","accent1","accent2","accent3","accent4","accent5","accent6","hlink","folHlink"],o=a=>r.includes(a);return n?.colorScheme?o(t)?n.colorScheme[t]??W[t]??"000000":"000000":o(t)?W[t]??"000000":"000000"}function K(n){if(!n)return null;let e=n.toLowerCase();return w[n]??w[e]??null}function g(n,e,t="000000"){if(!n)return `#${t}`;if(n.auto)return `#${t}`;let r;if(n.themeColor){let o=K(n.themeColor);if(o?r=J(e,o):r=n.rgb??t,n.themeTint){let a=U(n.themeTint);r=q(r,a);}else if(n.themeShade){let a=U(n.themeShade);r=X(r,a);}}else n.rgb?r=n.rgb:r=t;return `#${r.toUpperCase().replace(/^#/,"")}`}function De(n){if(!n||n==="none")return "";let e=Y[n];return e?`#${e}`:""}function Be(n,e){return n?n.auto?"transparent":g(n,e):""}function ve(n,e){if(!n)return false;if(n.auto)return true;let r=g(n,e).replace(/^#/,"").toLowerCase(),o=C(r);return (o.r+o.g+o.b)/3<20}function Oe(n,e){if(!n)return false;let r=g(n,e).replace(/^#/,"").toLowerCase(),o=C(r);return (o.r+o.g+o.b)/3>235}function Ne(n,e){if(!n)return "#000000";let r=g(n,e).replace(/^#/,""),o=C(r);return (.299*o.r+.587*o.g+.114*o.b)/255>.5?"#000000":"#FFFFFF"}function Le(n){if(!n)return;let e=n.trim();if(e.toLowerCase()==="auto")return {auto:true};let t=K(e);if(t)return {themeColor:t};let r=e.replace(/^#/,"").toUpperCase();return /^[0-9A-F]{6}$/i.test(r)?{rgb:r}:/^[0-9A-F]{3}$/i.test(r)?{rgb:r.split("").map(a=>a+a).join("")}:{rgb:r.padStart(6,"0").slice(0,6)}}function Me(n,e,t){let r={themeColor:n};return e!==void 0&&e>0&&e<1&&(r.themeTint=Math.round(e*255).toString(16).toUpperCase().padStart(2,"0")),t!==void 0&&t>0&&t<1&&(r.themeShade=Math.round(t*255).toString(16).toUpperCase().padStart(2,"0")),r}function Ve(n){return {rgb:n.replace(/^#/,"").toUpperCase()}}function ze(n,e,t){let o=g(n,e).replace(/^#/,""),a=1-t/100;return `#${X(o,a)}`}function je(n,e,t){let o=g(n,e).replace(/^#/,""),a=t/100;return `#${q(o,a)}`}function We(n,e,t,r){let o=g(n,r).replace(/^#/,""),a=g(e,r).replace(/^#/,""),i=C(o),s=C(a),u={r:Math.round(i.r*(1-t)+s.r*t),g:Math.round(i.g*(1-t)+s.g*t),b:Math.round(i.b*(1-t)+s.b*t)};return `#${D(u.r,u.g,u.b)}`}function Ue(n,e,t){if(!n&&!e)return true;if(!n||!e)return false;let r=g(n,t).toUpperCase(),o=g(e,t).toUpperCase();return r===o}function Ge(n){return n/1440*96}function qe(n){return n/96*1440}function Xe(n){return n/914400*96}function Ke(n){return n/96*914400}function Ze(n){return n/914400*1440}function Ye(n){return n/1440*914400}function Je(n){return n/72*96}function Qe(n){return n/144*96}function et(n){return n/2}function tt(n){return n/576*96}function Q(n,e=2){let t=Math.pow(10,e);return Math.round(n*t)/t}function nt(n){return `${Q(n)}px`}var S=class n$1{constructor(e$1){e(this,"_document");e(this,"_pendingVariables");e$1 instanceof ArrayBuffer||ArrayBuffer.isView(e$1)?this._document={package:{document:{content:[]}},originalBuffer:e$1 instanceof ArrayBuffer?e$1:e$1.buffer}:this._document=e$1,this._pendingVariables={};}static async fromBuffer(e){let t=await l(e);return new n$1(t)}static fromDocument(e){return new n$1(e)}getDocument(){return this._document}getText(){let e=this._document.package.document;return this._getBodyText(e)}getFormattedText(){let e=[],t=this._document.package.document;for(let r of t.content)r.type==="paragraph"&&this._extractParagraphSegments(r,e);return e}getVariables(){return a(this._document)}getStyles(){let e=this._document.package.styles;if(!e?.styles)return [];let t=[];for(let[r,o]of Object.entries(e.styles))if(typeof o=="object"&&o!==null){let a=o;t.push({id:r,name:a.name||r,type:a.type==="numbering"?"paragraph":a.type||"paragraph",builtIn:a.default});}return t}getPageCount(){let e=this.getWordCount();return Math.max(1,Math.ceil(e/500))}getWordCount(){return this.getText().split(/\s+/).filter(r=>r.length>0).length}getCharacterCount(e=true){let t=this.getText();return e?t.length:t.replace(/\s/g,"").length}getParagraphCount(){return this._document.package.document.content.filter(e=>e.type==="paragraph").length}getTableCount(){return this._document.package.document.content.filter(e=>e.type==="table").length}getAgentContext(e=100){let t=this._document.package.document,r=t.content.filter(i=>i.type==="paragraph"),o=r.map((i,s)=>{let u=this._getParagraphText(i),c=i.formatting?.styleId;return {index:s,preview:u.slice(0,e),style:c,isHeading:c?.toLowerCase().includes("heading")||false,headingLevel:this._parseHeadingLevel(c),isListItem:!!i.listRendering,isEmpty:u.trim().length===0}}),a=(t.sections||[]).map((i,s)=>({index:s,paragraphCount:i.content?.length||0,pageSize:i.properties?.pageWidth&&i.properties?.pageHeight?{width:i.properties.pageWidth,height:i.properties.pageHeight}:void 0,isLandscape:i.properties?.orientation==="landscape",hasHeader:!!i.properties?.headerReferences?.length,hasFooter:!!i.properties?.footerReferences?.length}));return {paragraphCount:r.length,wordCount:this.getWordCount(),characterCount:this.getCharacterCount(),variables:this.getVariables(),variableCount:this.getVariables().length,availableStyles:this.getStyles(),outline:o,sections:a,hasTables:this.getTableCount()>0,hasImages:this._hasImages(),hasHyperlinks:this._hasHyperlinks()}}insertText(e,t,r={}){let o={type:"insertText",position:e,text:t,formatting:r.formatting};return this._executeCommand(o)}replaceRange(e,t,r={}){let o={type:"replaceText",range:e,text:t,formatting:r.formatting};return this._executeCommand(o)}deleteRange(e){let t={type:"deleteText",range:e};return this._executeCommand(t)}applyFormatting(e,t){let r={type:"formatText",range:e,formatting:t};return this._executeCommand(r)}applyStyle(e,t){let r={type:"applyStyle",paragraphIndex:e,styleId:t};return this._executeCommand(r)}applyParagraphFormatting(e,t){let r={type:"formatParagraph",paragraphIndex:e,formatting:t};return this._executeCommand(r)}insertTable(e,t,r,o={}){let a={type:"insertTable",position:e,rows:t,columns:r,data:o.data,hasHeader:o.hasHeader};return this._executeCommand(a)}insertImage(e,t,r={}){let o={type:"insertImage",position:e,src:t,width:r.width,height:r.height,alt:r.alt};return this._executeCommand(o)}insertHyperlink(e,t,r={}){let o={type:"insertHyperlink",range:e,url:t,displayText:r.displayText,tooltip:r.tooltip};return this._executeCommand(o)}removeHyperlink(e){let t={type:"removeHyperlink",range:e};return this._executeCommand(t)}insertParagraphBreak(e){let t={type:"insertParagraphBreak",position:e};return this._executeCommand(t)}mergeParagraphs(e,t){let r={type:"mergeParagraphs",paragraphIndex:e,count:t};return this._executeCommand(r)}setVariable(e,t){return this._pendingVariables[e]=t,this}setVariables(e){for(let[t,r]of Object.entries(e))this._pendingVariables[t]=r;return this}getPendingVariables(){return {...this._pendingVariables}}clearPendingVariables(){return this._pendingVariables={},this}async applyVariables(e){let t={...this._pendingVariables,...e};if(Object.keys(t).length===0)return this;let r=this._document.originalBuffer;if(!r)throw new Error("Cannot apply variables: no original buffer for processing");let o=n(r,t),a=await l(o),i=new n$1(a);return i._pendingVariables={},i}async toBuffer(){return this._document.originalBuffer?d(this._document):e$1(this._document)}async toBlob(e="application/vnd.openxmlformats-officedocument.wordprocessingml.document"){let t=await this.toBuffer();return new Blob([t],{type:e})}executeCommands(e){let t=b(this._document,e);return new n$1(t)}_executeCommand(e){let t=a$1(this._document,e),r=new n$1(t);return r._pendingVariables={...this._pendingVariables},r}_getBodyText(e){let t=[];for(let r of e.content)r.type==="paragraph"?t.push(this._getParagraphText(r)):r.type==="table"&&t.push(this._getTableText(r));return t.join(`
|
|
2
|
+
`)}_getParagraphText(e){let t=[];for(let r of e.content)r.type==="run"?t.push(this._getRunText(r)):r.type==="hyperlink"&&t.push(this._getHyperlinkText(r));return t.join("")}_getRunText(e){return e.content.filter(t=>t.type==="text").map(t=>t.text).join("")}_getHyperlinkText(e){let t=[];for(let r of e.children)r.type==="run"&&t.push(this._getRunText(r));return t.join("")}_getTableText(e){let t=[];for(let r of e.rows)for(let o of r.cells)for(let a of o.content)a.type==="paragraph"&&t.push(this._getParagraphText(a));return t.join(" ")}_extractParagraphSegments(e,t){for(let r of e.content)if(r.type==="run"){let o=this._getRunText(r);o&&t.push({text:o,formatting:r.formatting});}else if(r.type==="hyperlink"){let o=r.href||"";for(let a of r.children)if(a.type==="run"){let i=this._getRunText(a);i&&t.push({text:i,formatting:a.formatting,isHyperlink:true,hyperlinkUrl:o});}}}_parseHeadingLevel(e){if(!e)return;let t=e.match(/heading\s*(\d)/i);if(t)return parseInt(t[1],10)}_hasImages(){let e=this._document.package.document;for(let t of e.content)if(t.type==="paragraph"){for(let r of t.content)if(r.type==="run"){for(let o of r.content)if(o.type==="drawing")return true}}return false}_hasHyperlinks(){let e=this._document.package.document;for(let t of e.content)if(t.type==="paragraph"){for(let r of t.content)if(r.type==="hyperlink")return true}return false}};async function ct(n){return S.fromBuffer(n)}function pt(n){return S.fromDocument(n)}function ee(n,e={}){let{outlineMaxChars:t=100,maxOutlineParagraphs:r=50}=e,o=n.package.document,a$1=o.content.filter(y=>y.type==="paragraph"),i=te(a$1,t,r),s=a(n),u=ne(n),c=re(o),p=oe(o),x=ae(o),d=o.content.some(y=>y.type==="table"),b=ue(o),l=ce(o);return {paragraphCount:a$1.length,wordCount:p,characterCount:x,variables:s,variableCount:s.length,availableStyles:u,outline:i,sections:c,hasTables:d,hasImages:b,hasHyperlinks:l}}function dt(n,e,t={}){let{contextChars:r=200,includeSuggestions:o=true}=t,i=n.package.document.content.filter(f=>f.type==="paragraph"),s=i[e.start.paragraphIndex];if(!s)throw new Error(`Paragraph not found at index ${e.start.paragraphIndex}`);let u=m(s),c="";if(e.start.paragraphIndex===e.end.paragraphIndex)c=u.slice(e.start.offset,e.end.offset);else {let f=[];for(let P=e.start.paragraphIndex;P<=e.end.paragraphIndex;P++){let N=i[P];if(!N)continue;let R=m(N);P===e.start.paragraphIndex?f.push(R.slice(e.start.offset)):P===e.end.paragraphIndex?f.push(R.slice(0,e.end.offset)):f.push(R);}c=f.join(`
|
|
3
|
+
`);}let p=me(i,e.start.paragraphIndex,e.start.offset,r),x=ge(i,e.end.paragraphIndex,e.end.offset,r),d=de(s,e.start.offset),b=s.formatting||{},l={index:e.start.paragraphIndex,fullText:u,style:s.formatting?.styleId,wordCount:B(u)},y=false,_=fe(s,e.start.offset),F=o?he(c):[];return {selectedText:c,range:e,formatting:d,paragraphFormatting:b,textBefore:p,textAfter:x,paragraph:l,inTable:y,inHyperlink:_,suggestedActions:F}}function Z(n){let e=ee(n,{outlineMaxChars:50,maxOutlineParagraphs:10}),t=[`Document with ${e.paragraphCount} paragraphs, ${e.wordCount} words.`];e.hasTables&&t.push("Contains tables."),e.hasImages&&t.push("Contains images."),e.hasHyperlinks&&t.push("Contains hyperlinks."),e.variableCount>0&&t.push(`Has ${e.variableCount} template variables: ${e.variables.join(", ")}`);let r=e.outline.filter(o=>o.isHeading);if(r.length>0){t.push(`
|
|
4
|
+
Headings:`);for(let o of r.slice(0,5)){let a=o.headingLevel||1;t.push(`${" ".repeat(a-1)}- ${o.preview}`);}r.length>5&&t.push(` ... and ${r.length-5} more headings`);}return t.join(" ")}function te(n,e,t){let r=[];for(let o=0;o<Math.min(n.length,t);o++){let a=n[o],i=m(a),s=a.formatting?.styleId;r.push({index:o,preview:i.slice(0,e),style:s,isHeading:pe(s),headingLevel:le(s),isListItem:!!a.listRendering,isEmpty:i.trim().length===0});}return r}function ne(n){let e=n.package.styles;if(!e?.styles)return [];let t=[];for(let[r,o]of Object.entries(e.styles))if(typeof o=="object"&&o!==null){let a=o;t.push({id:r,name:a.name||r,type:a.type==="numbering"?"paragraph":a.type||"paragraph",builtIn:a.default});}return t}function re(n){return n.sections?n.sections.map((e,t)=>({index:t,paragraphCount:e.content?.length||0,pageSize:e.properties?.pageWidth&&e.properties?.pageHeight?{width:e.properties.pageWidth,height:e.properties.pageHeight}:void 0,isLandscape:e.properties?.orientation==="landscape",hasHeader:!!e.properties?.headerReferences?.length,hasFooter:!!e.properties?.footerReferences?.length})):[]}function oe(n){let e=0;for(let t of n.content)if(t.type==="paragraph"){let r=m(t);e+=B(r);}else t.type==="table"&&(e+=ie(t));return e}function B(n){return n.split(/\s+/).filter(t=>t.length>0).length}function ae(n){let e=0;for(let t of n.content)if(t.type==="paragraph"){let r=m(t);e+=r.length;}else t.type==="table"&&(e+=se(t));return e}function ie(n){let e=0;for(let t of n.rows)for(let r of t.cells)for(let o of r.content)if(o.type==="paragraph"){let a=m(o);e+=B(a);}return e}function se(n){let e=0;for(let t of n.rows)for(let r of t.cells)for(let o of r.content)if(o.type==="paragraph"){let a=m(o);e+=a.length;}return e}function m(n){let e=[];for(let t of n.content)t.type==="run"?e.push(A(t)):t.type==="hyperlink"&&e.push(v(t));return e.join("")}function A(n){return n.content.filter(e=>e.type==="text").map(e=>e.text).join("")}function v(n){let e=[];for(let t of n.children)t.type==="run"&&e.push(A(t));return e.join("")}function ue(n){for(let e of n.content)if(e.type==="paragraph"){for(let t of e.content)if(t.type==="run"){for(let r of t.content)if(r.type==="drawing")return true}}return false}function ce(n){for(let e of n.content)if(e.type==="paragraph"){for(let t of e.content)if(t.type==="hyperlink")return true}return false}function pe(n){return n?n.toLowerCase().includes("heading"):false}function le(n){if(!n)return;let e=n.match(/heading\s*(\d)/i);if(e)return parseInt(e[1],10)}function me(n,e,t,r){let o=[],a=0,i=n[e];if(i){let c=m(i).slice(0,t);o.unshift(c),a+=c.length;}for(let u=e-1;u>=0&&a<r;u--){let c=n[u];if(!c)continue;let p=m(c);o.unshift(p),a+=p.length;}let s=o.join(`
|
|
5
|
+
`);return s.length>r?"..."+s.slice(-r):s}function ge(n,e,t,r){let o=[],a=0,i=n[e];if(i){let c=m(i).slice(t);o.push(c),a+=c.length;}for(let u=e+1;u<n.length&&a<r;u++){let c=n[u];if(!c)continue;let p=m(c);o.push(p),a+=p.length;}let s=o.join(`
|
|
6
|
+
`);return s.length>r?s.slice(0,r)+"...":s}function de(n,e){let t=0;for(let r of n.content)if(r.type==="run"){let o=A(r),a=t,i=t+o.length;if(e>=a&&e<i)return r.formatting||{};t=i;}else if(r.type==="hyperlink"){let o=v(r),a=t,i=t+o.length;if(e>=a&&e<i){for(let s of r.children)if(s.type==="run")return s.formatting||{}}t=i;}return {}}function fe(n,e){let t=0;for(let r of n.content)if(r.type==="run"){let o=A(r);t+=o.length;}else if(r.type==="hyperlink"){let o=v(r),a=t,i=t+o.length;if(e>=a&&e<i)return true;t=i;}return false}function he(n,e,t){let r=[];return n.length>0&&(r.push({id:"rewrite",label:"Rewrite",description:"Rewrite this text",priority:10},{id:"summarize",label:"Summarize",description:"Summarize this text",priority:9}),n.length>200&&r.push({id:"summarize",label:"Summarize",description:"Create a shorter version",priority:8}),n.length<50&&n.split(/\s+/).length<10&&r.push({id:"expand",label:"Expand",description:"Add more details",priority:8}),r.push({id:"fixGrammar",label:"Fix Grammar",description:"Fix grammar and spelling",priority:7}),r.push({id:"translate",label:"Translate",description:"Translate to another language",priority:6}),r.push({id:"makeFormal",label:"Make Formal",description:"Use formal tone",priority:5},{id:"makeCasual",label:"Make Casual",description:"Use casual tone",priority:4})),r.sort((o,a)=>(a.priority||0)-(o.priority||0)),r}function xe(n,e,t={}){let{contextCharsBefore:r=200,contextCharsAfter:o=200,includeSuggestions:a=true}=t,i=n.package.document,s=i.content.filter(f=>f.type==="paragraph");if(e.start.paragraphIndex>=s.length)throw new Error(`Invalid start paragraph index: ${e.start.paragraphIndex}`);let u=s[e.start.paragraphIndex],c=be(s,e),p=ye(s,e.start,r),x=Ce(s,e.end,o),d=Pe(u,e.start.offset),b=u.formatting||{},l={index:e.start.paragraphIndex,fullText:h(u),style:u.formatting?.styleId,wordCount:O(h(u))},y=Ie(i,e.start),_=Se(u,e.start.offset),F=a?Ae(c):[];return {selectedText:c,range:e,formatting:d,paragraphFormatting:b,textBefore:p,textAfter:x,paragraph:l,inTable:y,inHyperlink:_,suggestedActions:F}}function xt(n,e,t={}){let r=xe(n,e,t),{includeDocumentSummary:o=true}=t,i=n.package.document.content.filter(l=>l.type==="paragraph"),s=O(r.selectedText),u=r.selectedText.length,c=e.start.paragraphIndex!==e.end.paragraphIndex,p=[];for(let l=e.start.paragraphIndex;l<=e.end.paragraphIndex;l++)p.push(l);let x=ke(i,e),d=o?Z(n):void 0,b=_e(r.selectedText);return {...r,documentSummary:d,wordCount:s,characterCount:u,isMultiParagraph:c,paragraphIndices:p,detectedLanguage:b,contentType:x}}function bt(n,e){let r=n.package.document.content.filter(s=>s.type==="paragraph"),o=[];for(let s=e.start.paragraphIndex;s<=e.end.paragraphIndex;s++){let u=r[s];if(!u)continue;let c=s===e.start.paragraphIndex?e.start.offset:0,p=s===e.end.paragraphIndex?e.end.offset:1/0;Te(u,c,p,o);}let a=o.length<=1||o.every(s=>Fe(s,o[0]));return {predominant:o.length>0?o[0]:{},isConsistent:a,allFormatting:o}}function be(n,e){if(e.start.paragraphIndex===e.end.paragraphIndex){let r=n[e.start.paragraphIndex];return r?h(r).slice(e.start.offset,e.end.offset):""}let t=[];for(let r=e.start.paragraphIndex;r<=e.end.paragraphIndex;r++){let o=n[r];if(!o)continue;let a=h(o);r===e.start.paragraphIndex?t.push(a.slice(e.start.offset)):r===e.end.paragraphIndex?t.push(a.slice(0,e.end.offset)):t.push(a);}return t.join(`
|
|
7
|
+
`)}function ye(n,e,t){let r=[],o=0,a=n[e.paragraphIndex];if(a){let u=h(a).slice(0,e.offset);r.unshift(u),o+=u.length;}for(let s=e.paragraphIndex-1;s>=0&&o<t;s--){let u=n[s];if(!u)continue;let c=h(u);r.unshift(c),o+=c.length;}let i=r.join(`
|
|
8
|
+
`);return i.length>t?"..."+i.slice(-t):i}function Ce(n,e,t){let r=[],o=0,a=n[e.paragraphIndex];if(a){let u=h(a).slice(e.offset);r.push(u),o+=u.length;}for(let s=e.paragraphIndex+1;s<n.length&&o<t;s++){let u=n[s];if(!u)continue;let c=h(u);r.push(c),o+=c.length;}let i=r.join(`
|
|
9
|
+
`);return i.length>t?i.slice(0,t)+"...":i}function Pe(n,e){let t=0;for(let r of n.content)if(r.type==="run"){let o=T(r),a=t+o.length;if(e>=t&&e<a)return r.formatting||{};t=a;}else if(r.type==="hyperlink"){let o=k(r),a=t+o.length;if(e>=t&&e<a){for(let i of r.children)if(i.type==="run")return i.formatting||{}}t=a;}return {}}function Te(n,e,t,r){let o=0;for(let a of n.content)if(a.type==="run"){let i=T(a),s=o,u=o+i.length;u>e&&s<t&&a.formatting&&r.push({...a.formatting}),o=u;}else if(a.type==="hyperlink"){let i=k(a),s=o,u=o+i.length;if(u>e&&s<t)for(let c of a.children)c.type==="run"&&c.formatting&&r.push({...c.formatting});o=u;}}function Ie(n,e){return false}function Se(n,e){let t=0;for(let r of n.content)if(r.type==="run"){let o=T(r);t+=o.length;}else if(r.type==="hyperlink"){let o=k(r),a=t,i=t+o.length;if(e>=a&&e<i)return true;t=i;}return false}function Ae(n,e,t){let r=[];if(!n||n.trim().length===0)return r;r.push({id:"askAI",label:"Ask AI",description:"Ask AI about this text",priority:11},{id:"rewrite",label:"Rewrite",description:"Rewrite this text differently",priority:10});let o=O(n);return o>50&&r.push({id:"summarize",label:"Summarize",description:"Create a shorter version",priority:9}),o<20&&r.push({id:"expand",label:"Expand",description:"Add more details",priority:9}),r.push({id:"fixGrammar",label:"Fix Grammar",description:"Fix grammar and spelling",priority:7},{id:"translate",label:"Translate",description:"Translate to another language",priority:6},{id:"explain",label:"Explain",description:"Explain what this means",priority:5}),r.push({id:"makeFormal",label:"Make Formal",description:"Use formal tone",priority:4},{id:"makeCasual",label:"Make Casual",description:"Use casual tone",priority:3}),r.sort((a,i)=>(i.priority||0)-(a.priority||0)),r}function ke(n,e){let t=new Set;for(let r=e.start.paragraphIndex;r<=e.end.paragraphIndex;r++){let o=n[r];o&&(o.listRendering?t.add("list"):o.formatting?.styleId?.toLowerCase().includes("heading")?t.add("heading"):t.add("prose"));}return t.size>1?"mixed":t.has("list")?"list":t.has("heading")?"heading":"prose"}function _e(n){return /[а-яА-ЯёЁ]/.test(n)?"ru":/[一-龯]/.test(n)?"zh":/[ひらがなカタカナ]/.test(n)||/[\u3040-\u309F\u30A0-\u30FF]/.test(n)?"ja":/[가-힣]/.test(n)?"ko":/[àâäéèêëïîôùûüç]/i.test(n)?"fr":/[äöüß]/i.test(n)?"de":/[áéíóúñ]/i.test(n)?"es":"en"}function h(n){let e=[];for(let t of n.content)t.type==="run"?e.push(T(t)):t.type==="hyperlink"&&e.push(k(t));return e.join("")}function T(n){return n.content.filter(e=>e.type==="text").map(e=>e.text).join("")}function k(n){let e=[];for(let t of n.children)t.type==="run"&&e.push(T(t));return e.join("")}function O(n){return n.split(/\s+/).filter(e=>e.length>0).length}function Fe(n,e){let t=Object.keys(n),r=Object.keys(e);return t.length!==r.length?false:t.every(o=>{let a=n[o],i=e[o];return a===i})}function Re(){return [{styleId:"Normal",type:"paragraph",name:"Normal",default:true,qFormat:true,uiPriority:0,rPr:{fontSize:22,fontFamily:{ascii:"Arial",hAnsi:"Arial"}},pPr:{lineSpacing:276}},{styleId:"Title",type:"paragraph",name:"Title",basedOn:"Normal",next:"Normal",qFormat:true,uiPriority:10,rPr:{fontSize:52,bold:true,fontFamily:{ascii:"Arial",hAnsi:"Arial"}},pPr:{lineSpacing:240}},{styleId:"Subtitle",type:"paragraph",name:"Subtitle",basedOn:"Normal",next:"Normal",qFormat:true,uiPriority:11,rPr:{fontSize:30,color:{rgb:"666666"},fontFamily:{ascii:"Arial",hAnsi:"Arial"}},pPr:{lineSpacing:240}},{styleId:"Heading1",type:"paragraph",name:"Heading 1",basedOn:"Normal",next:"Normal",qFormat:true,uiPriority:9,rPr:{fontSize:40,bold:true,fontFamily:{ascii:"Arial",hAnsi:"Arial"}},pPr:{spaceBefore:400,spaceAfter:120,lineSpacing:240}},{styleId:"Heading2",type:"paragraph",name:"Heading 2",basedOn:"Normal",next:"Normal",qFormat:true,uiPriority:9,rPr:{fontSize:32,bold:true,fontFamily:{ascii:"Arial",hAnsi:"Arial"}},pPr:{spaceBefore:360,spaceAfter:80,lineSpacing:240}},{styleId:"Heading3",type:"paragraph",name:"Heading 3",basedOn:"Normal",next:"Normal",qFormat:true,uiPriority:9,rPr:{fontSize:28,bold:true,fontFamily:{ascii:"Arial",hAnsi:"Arial"}},pPr:{spaceBefore:320,spaceAfter:80,lineSpacing:240}},{styleId:"Heading4",type:"paragraph",name:"Heading 4",basedOn:"Normal",next:"Normal",qFormat:true,uiPriority:9,rPr:{fontSize:24,bold:true,fontFamily:{ascii:"Arial",hAnsi:"Arial"}},pPr:{spaceBefore:280,spaceAfter:80,lineSpacing:240}}]}function He(){return {pageWidth:12240,pageHeight:15840,orientation:"portrait",marginTop:1440,marginBottom:1440,marginLeft:1440,marginRight:1440,headerDistance:720,footerDistance:720,gutter:0,columnCount:1,columnSpace:720,equalWidth:true,sectionStart:"nextPage",verticalAlign:"top"}}function Ee(n={}){let e=He();n.pageWidth!==void 0&&(e.pageWidth=n.pageWidth),n.pageHeight!==void 0&&(e.pageHeight=n.pageHeight),n.orientation!==void 0&&(e.orientation=n.orientation),n.marginTop!==void 0&&(e.marginTop=n.marginTop),n.marginBottom!==void 0&&(e.marginBottom=n.marginBottom),n.marginLeft!==void 0&&(e.marginLeft=n.marginLeft),n.marginRight!==void 0&&(e.marginRight=n.marginRight);let t={type:"text",text:n.initialText||""};return {package:{document:{content:[{type:"paragraph",content:[{type:"run",content:n.initialText?[t]:[],formatting:{fontSize:22,fontFamily:{ascii:"Arial",hAnsi:"Arial"}}}],formatting:{lineSpacing:276}}],finalSectionProperties:e},styles:{docDefaults:{rPr:{fontSize:22,fontFamily:{ascii:"Arial",hAnsi:"Arial"}},pPr:{lineSpacing:276}},styles:Re()}},templateVariables:[],warnings:[]}}function Ct(n,e={}){return Ee({...e,initialText:n})}function Tt(n){return {start:n,end:n,collapsed:true}}function It(n,e){return {start:n,end:e,collapsed:n.paragraphIndex===e.paragraphIndex&&n.offset===e.offset}}function St(n,e){return !(n.paragraphIndex<e.start.paragraphIndex||n.paragraphIndex===e.start.paragraphIndex&&n.offset<e.start.offset||n.paragraphIndex>e.end.paragraphIndex||n.paragraphIndex===e.end.paragraphIndex&&n.offset>e.end.offset)}function At(n,e){return n.paragraphIndex<e.paragraphIndex?-1:n.paragraphIndex>e.paragraphIndex?1:n.offset<e.offset?-1:n.offset>e.offset?1:0}function kt(n){return {askAI:"Ask AI",rewrite:"Rewrite",expand:"Expand",summarize:"Summarize",translate:"Translate",explain:"Explain",fixGrammar:"Fix Grammar",makeFormal:"Make Formal",makeCasual:"Make Casual",custom:"Custom Prompt"}[n]}function _t(n){return {askAI:"Ask AI a question about this text",rewrite:"Rewrite this text in a different way",expand:"Expand this text with more details",summarize:"Summarize this text to be shorter",translate:"Translate this text to another language",explain:"Explain what this text means",fixGrammar:"Fix grammar and spelling errors",makeFormal:"Make the tone more formal",makeCasual:"Make the tone more casual",custom:"Enter a custom prompt"}[n]}var Ft=["askAI","rewrite","expand","summarize","translate","explain"];function Rt(n){return {...n,id:we()}}function we(){return `cmd_${Date.now()}_${Math.random().toString(36).substr(2,9)}`}export{pt as A,ee as B,dt as C,Z as D,xe as E,xt as F,bt as G,Ee as H,Ct as I,Tt as J,It as K,St as L,At as M,kt as N,_t as O,Ft as P,Rt as Q,g as a,De as b,Be as c,ve as d,Oe as e,Ne as f,Le as g,Me as h,Ve as i,ze as j,je as k,We as l,Ue as m,Ge as n,qe as o,Xe as p,Ke as q,Ze as r,Ye as s,Je as t,Qe as u,et as v,tt as w,nt as x,S as y,ct as z};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
'use strict';var chunkRTESADL3_cjs=require('./chunk-RTESADL3.cjs');var a=class{constructor(){chunkRTESADL3_cjs.e(this,"plugins",new Map);chunkRTESADL3_cjs.e(this,"commandHandlers",new Map);chunkRTESADL3_cjs.e(this,"eventListeners",new Set);chunkRTESADL3_cjs.e(this,"initialized",new Set);}register(e,r){let t=[];if(!e.id)return {success:false,error:"Plugin must have an id"};if(this.plugins.has(e.id))return {success:false,error:`Plugin '${e.id}' is already registered`};if(e.dependencies){for(let i of e.dependencies)if(!this.plugins.has(i))return {success:false,error:`Plugin '${e.id}' requires '${i}' which is not registered`}}if(e.commandHandlers)for(let[i,o]of Object.entries(e.commandHandlers)){if(this.commandHandlers.has(i)){let d=this.commandHandlers.get(i);t.push(`Command '${i}' from '${e.id}' overrides handler from '${d.pluginId}'`);}this.commandHandlers.set(i,{pluginId:e.id,handler:o});}if(this.plugins.set(e.id,e),e.initialize&&!this.initialized.has(e.id))try{let i=e.initialize();i instanceof Promise?i.then(()=>{this.initialized.add(e.id);}).catch(o=>{this.emit({type:"error",pluginId:e.id,error:o});}):this.initialized.add(e.id);}catch(i){this.emit({type:"error",pluginId:e.id,error:i});}return r?.debug&&console.log(`[PluginRegistry] Registered plugin: ${e.id}`),this.emit({type:"registered",plugin:e}),{success:true,plugin:e,warnings:t.length>0?t:void 0}}unregister(e){let r=this.plugins.get(e);if(!r)return false;for(let[t,i]of this.plugins)if(i.dependencies?.includes(e))return console.warn(`Cannot unregister '${e}': '${t}' depends on it`),false;for(let[t,{pluginId:i}]of this.commandHandlers)i===e&&this.commandHandlers.delete(t);if(r.destroy)try{let t=r.destroy();t instanceof Promise&&t.catch(i=>{this.emit({type:"error",pluginId:e,error:i});});}catch(t){this.emit({type:"error",pluginId:e,error:t});}return this.plugins.delete(e),this.initialized.delete(e),this.emit({type:"unregistered",pluginId:e}),true}get(e){return this.plugins.get(e)}getAll(){return Array.from(this.plugins.values())}has(e){return this.plugins.has(e)}get size(){return this.plugins.size}getCommandHandler(e){return this.commandHandlers.get(e)?.handler}getCommandTypes(){return Array.from(this.commandHandlers.keys())}hasCommandHandler(e){return this.commandHandlers.has(e)}getMcpTools(){let e=[];for(let r of this.plugins.values())r.mcpTools&&e.push(...r.mcpTools);return e}getMcpToolsForPlugin(e){return this.plugins.get(e)?.mcpTools||[]}getMcpTool(e){for(let r of this.plugins.values())if(r.mcpTools){let t=r.mcpTools.find(i=>i.name===e);if(t)return t}}addEventListener(e){this.eventListeners.add(e);}removeEventListener(e){this.eventListeners.delete(e);}emit(e){for(let r of this.eventListeners)try{r(e);}catch(t){console.error("[PluginRegistry] Event listener error:",t);}}clear(){for(let e of this.plugins.values())if(e.destroy)try{e.destroy();}catch{}this.plugins.clear(),this.commandHandlers.clear(),this.initialized.clear();}getDebugInfo(){return {plugins:Array.from(this.plugins.keys()),commandTypes:Array.from(this.commandHandlers.keys()),mcpTools:this.getMcpTools().map(e=>e.name),initialized:Array.from(this.initialized)}}},l=new a;function c(s,e){return s.map(r=>l.register(r,e))}function g(s){return e=>l.register(e,s)}exports.a=a;exports.b=l;exports.c=c;exports.d=g;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import {l}from'./chunk-EU5LN2WS.js';import {a}from'./chunk-3IYNTJO5.js';import g from'pizzip';import b from'docxtemplater';function J(e){return typeof e=="object"&&e!==null&&("_def"in e||"parse"in e||"safeParse"in e)}function v(e,t){let r=t,{position:o,variableName:n}=r,a=JSON.parse(JSON.stringify(e)),s=a.package.document.content.filter(u=>u.type==="paragraph");if(o.paragraphIndex>=s.length)throw new Error(`Paragraph index ${o.paragraphIndex} out of bounds`);let c=s[o.paragraphIndex],l=`{{${n}}}`;return k(c,o.offset,l),a.templateVariables||(a.templateVariables=[]),a.templateVariables.includes(n)||a.templateVariables.push(n),a}function w(e,t){let r=t,{range:o,variableName:n}=r,a=JSON.parse(JSON.stringify(e)),s=a.package.document.content.filter(u=>u.type==="paragraph");if(o.start.paragraphIndex!==o.end.paragraphIndex)throw new Error("Template variable replacement cannot span multiple paragraphs");if(o.start.paragraphIndex>=s.length)throw new Error(`Paragraph index ${o.start.paragraphIndex} out of bounds`);let c=s[o.start.paragraphIndex];Z(c,o.start.offset,o.end.offset);let l=`{{${n}}}`;return k(c,o.start.offset,l),a.templateVariables||(a.templateVariables=[]),a.templateVariables.includes(n)||a.templateVariables.push(n),a}function k(e,t,r){let o=0,n=false;for(let a=0;a<e.content.length;a++){let i=e.content[a];if(i.type==="run"){let s=T(i),c=o,l=o+s.length;if(!n&&t>=c&&t<=l){let u=t-c,y=s.slice(0,u),m=s.slice(u),p=[];for(let d=0;d<a;d++)p.push(e.content[d]);y&&p.push({type:"run",formatting:i.formatting,content:[{type:"text",text:y}]}),p.push({type:"run",formatting:i.formatting,content:[{type:"text",text:r}]}),m&&p.push({type:"run",formatting:i.formatting,content:[{type:"text",text:m}]});for(let d=a+1;d<e.content.length;d++)p.push(e.content[d]);e.content=p,n=true;break}o=l;}else if(i.type==="hyperlink")for(let s of i.children)s.type==="run"&&(o+=T(s).length);}n||e.content.push({type:"run",content:[{type:"text",text:r}]});}function Z(e,t,r){let o=[],n=0;for(let a of e.content)if(a.type==="run"){let i=T(a),s=n,c=n+i.length;if(c<=t||s>=r)o.push(a);else {let l="";s<t&&(l+=i.slice(0,t-s)),c>r&&(l+=i.slice(r-s)),l.length>0&&o.push({type:"run",formatting:a.formatting,content:[{type:"text",text:l}]});}n=c;}else o.push(a);e.content=o;}function T(e){return e.content.filter(t=>t.type==="text").map(t=>t.text).join("")}function U(e){return V(e).variables}function V(e){let t=[],r={body:[],headers:[],footers:[],footnotes:[],endnotes:[],textBoxes:[]};if(e.package?.document){let n=j(e.package.document);n.forEach(a=>{t.push({name:a,location:"body"});}),r.body=Array.from(new Set(n)).sort();}if(e.package?.document?.sections&&e.package.document.sections.forEach((n,a)=>{n.properties.headerReferences&&n.properties.headerReferences.forEach(i=>{});}),e.package?.footnotes){let n=A(e.package.footnotes);n.forEach(a=>{t.push({name:a,location:"footnote"});}),r.footnotes=Array.from(new Set(n)).sort();}if(e.package?.endnotes){let n=A(e.package.endnotes);n.forEach(a=>{t.push({name:a,location:"endnote"});}),r.endnotes=Array.from(new Set(n)).sort();}e.templateVariables&&e.templateVariables.forEach(n=>{t.some(a=>a.name===n)||t.push({name:n,location:"body"});});let o=new Set;return t.forEach(n=>o.add(n.name)),{variables:Array.from(o).sort(),totalOccurrences:t.length,byLocation:r,occurrences:t}}function j(e){let t=[];if(e.content&&t.push(...I(e.content)),e.sections)for(let r of e.sections)r.content&&t.push(...I(r.content));return t}function I(e){let t=[];for(let r of e)r.type==="paragraph"?t.push(...R(r)):r.type==="table"&&t.push(...M(r));return t}function R(e){let t=[];if(!e.content)return t;for(let r of e.content)r.type==="run"?t.push(...f(r)):r.type==="hyperlink"?t.push(...q(r)):r.type==="simpleField"?t.push(...W(r)):r.type==="complexField"&&t.push(...G(r));return t}function f(e){let t=[];if(!e.content)return t;for(let r of e.content)r.type==="text"&&r.text&&t.push(...B(r.text));return t}function q(e){let t=[];if(!e.children)return t;for(let r of e.children)r.type==="run"&&t.push(...f(r));return t}function W(e){let t=[];if(e.instruction&&t.push(...B(e.instruction)),e.content)for(let r of e.content)r.type==="run"&&t.push(...f(r));return t}function G(e){let t=[];if(e.fieldCode)for(let r of e.fieldCode)r.type==="run"&&t.push(...f(r));if(e.fieldResult)for(let r of e.fieldResult)r.type==="run"&&t.push(...f(r));return t}function M(e){let t=[];if(!e.rows)return t;for(let r of e.rows)if(r.cells)for(let o of r.cells)t.push(...X(o));return t}function X(e){let t=[];if(!e.content)return t;for(let r of e.content)r.type==="paragraph"?t.push(...R(r)):r.type==="table"&&t.push(...M(r));return t}function A(e){let t=[];for(let r of e)if(r.content)for(let o of r.content)t.push(...R(o));return t}var S=/\{([a-zA-Z_][a-zA-Z0-9_\-\.]*)\}/g,_=/\{(.+?)\}/g;function B(e){if(!e)return [];let t=[],r=new RegExp(S),o;for(;(o=r.exec(e))!==null;)t.push(o[1]);return t}function oe(e){return S.test(e)}function ae(e){return !(!e||typeof e!="string"||e.length===0||e.length>100||!/^[a-zA-Z_]/.test(e)||!/^[a-zA-Z_][a-zA-Z0-9_\-\.]*$/.test(e))}function ie(e){if(!e)return "";let t=e.replace(/\s+/g,"_");return t=t.replace(/[^a-zA-Z0-9_\-\.]/g,""),t&&!/^[a-zA-Z_]/.test(t)&&(t="_"+t),t.substring(0,100)}function se(e){return `{${e}}`}function ce(e){let t=e.match(/^\{(.+?)\}$/);return t?t[1]:null}function le(e,t){return e&&e.replace(_,(r,o)=>{let n=o.trim();return n in t?t[n]:r})}function pe(e,t=""){return e&&e.replace(_,t)}function ue(e){return U(e).length>0}function O(e,t,r={}){return E(e,t,r).buffer}function E(e,t,r={}){let{nullGetter:o="keep",linebreaks:n=true,delimiters:a}=r,i=[],s=[],c=[];try{let l=new g(e),u=new b(l,{paragraphLoop:!0,linebreaks:n,nullGetter:m=>{let p=m.value||"";if(o==="error")throw new Error(`Undefined variable: ${p}`);return o==="empty"?(c.push(p),""):(c.push(p),`{${p}}`)},delimiters:a?{start:a.start||"{",end:a.end||"}"}:void 0});return Object.keys(t).forEach(m=>{t[m]!==void 0&&t[m]!==null&&s.push(m);}),u.setData(t),u.render(),{buffer:u.getZip().generate({type:"arraybuffer",compression:"DEFLATE",compressionOptions:{level:6}}),replacedVariables:s,unreplacedVariables:c,warnings:i}}catch(l){throw x(l)}}function ge(e,t,r={}){let o=O(e,t,r);return new Blob([o],{type:"application/vnd.openxmlformats-officedocument.wordprocessingml.document"})}function be(e){try{let t=new g(e),o=new b(t,{paragraphLoop:!0,linebreaks:!0}).getFullText();return $(o)}catch(t){throw x(t)}}function L(e){let t=[],r=[];try{let o=new g(e),a=new b(o,{paragraphLoop:!0,linebreaks:!0}).getFullText();r=$(a);let i=K(a);for(let s of i)t.push({message:`Unclosed tag: ${s}`,variable:s,type:"parse"});return {valid:t.length===0,errors:t,tags:r}}catch(o){return t.push(x(o)),{valid:false,errors:t,tags:r}}}function xe(e,t){return e.filter(r=>!(r in t)||t[r]===void 0||t[r]===null)}function he(e,t){try{let r=new g(e),o=new b(r,{paragraphLoop:!0,linebreaks:!0,nullGetter:n=>`[${n.value||""}]`});return o.setData(t),o.render(),o.getFullText()}catch(r){throw x(r)}}function $(e){let t=[],r=/\{([^{}]+)\}/g,o;for(;(o=r.exec(e))!==null;){let n=o[1].trim();n&&!t.includes(n)&&t.push(n);}return t.sort()}function K(e){let t=[],r=0,o="";for(let n of e)n==="{"?(r++,o=""):n==="}"?(r--,r<0&&(r=0)):r>0&&(o+=n);return r>0&&o.trim()&&t.push(o.trim()),t}function Q(e){return "properties"in e&&typeof e.properties=="object"}function x(e){if(e instanceof Error){if(Q(e)&&e.properties?.errors){let t=e.properties.errors[0];return {message:t?.message||"Template processing error",variable:t?.properties?.tag,type:"render",originalError:e}}if(e.message.includes("undefined")){let t=e.message.match(/undefined (?:variable|tag):\s*(\S+)/i);return {message:e.message,variable:t?t[1]:void 0,type:"undefined",originalError:e}}return e.message.includes("parse")||e.message.includes("unclosed")||e.message.includes("syntax")?{message:e.message,type:"parse",originalError:e}:{message:e.message,type:"unknown",originalError:e}}return {message:String(e),type:"unknown"}}function ye(e,t,r={}){let{linebreaks:o=true,delimiters:n}=r;try{let a=new g(e),i=new b(a,{paragraphLoop:!0,linebreaks:o,delimiters:n?{start:n.start||"{",end:n.end||"}"}:void 0});return i.setData(t),i.render(),i.getZip().generate({type:"arraybuffer",compression:"DEFLATE"})}catch(a){throw x(a)}}function Te(e={}){return (t,r)=>O(t,r,e)}var h={type:"string",description:"Document ID from a previous docx_load call"},Y={type:"object",properties:{paragraphIndex:{type:"number",description:"Index of the paragraph (0-indexed)"},offset:{type:"number",description:"Character offset within the paragraph"}},required:["paragraphIndex","offset"]},N={name:"docx_get_variables",description:`List all template variables ({{name}} format) found in the document.
|
|
2
|
+
Returns variable names without braces, along with their locations (body, headers, footers, etc.).
|
|
3
|
+
Use this to discover what data fields a template document expects.`,inputSchema:{type:"object",properties:{documentId:h},required:["documentId"]},handler:async(e,t)=>{let{documentId:r}=e,o=t.session.documents.get(r);if(!o)return {isError:true,content:[{type:"text",text:`Document not found: ${r}`}]};try{let n=V(o.document);return {content:[{type:"text",text:JSON.stringify({variables:n.variables,count:n.variables.length,totalOccurrences:n.totalOccurrences,byLocation:n.byLocation},null,2)}]}}catch(n){return {isError:true,content:[{type:"text",text:`Failed to detect variables: ${n.message}`}]}}},annotations:{category:"template",readOnly:true,complexity:"low",examples:[{description:"Get all variables from a loaded document",input:{documentId:"doc_123"},output:'{"variables": ["customer_name", "invoice_date"], "count": 2}'}]}},F={name:"docx_insert_variable",description:`Insert a template variable placeholder ({{name}}) at a specific position in the document.
|
|
4
|
+
The variable can later be substituted with actual values using docx_apply_template.
|
|
5
|
+
Variable names should follow the pattern: letters, numbers, underscores, starting with a letter.`,inputSchema:{type:"object",properties:{documentId:h,position:Y,variableName:{type:"string",description:'Variable name without braces (e.g., "customer_name"). Will be inserted as {{customer_name}}',pattern:"^[a-zA-Z_][a-zA-Z0-9_]*$"}},required:["documentId","position","variableName"]},handler:async(e,t)=>{let{documentId:r,position:o,variableName:n}=e,a=t.session.documents.get(r);if(!a)return {isError:true,content:[{type:"text",text:`Document not found: ${r}`}]};if(!/^[a-zA-Z_][a-zA-Z0-9_\-.]*$/.test(n))return {isError:true,content:[{type:"text",text:`Invalid variable name: ${n}. Must start with letter/underscore and contain only alphanumeric, underscore, hyphen, or dot.`}]};try{let{executeCommand:i}=await import('./executor-7DZMHPUF.js'),s=i(a.document,{type:"insertText",position:o,text:`{{${n}}}`});return a.document=s,a.lastModified=Date.now(),s.templateVariables||(s.templateVariables=[]),s.templateVariables.includes(n)||s.templateVariables.push(n),{content:[{type:"text",text:JSON.stringify({success:!0,variable:n,insertedAs:`{{${n}}}`,position:o})}]}}catch(i){return {isError:true,content:[{type:"text",text:`Failed to insert variable: ${i.message}`}]}}},annotations:{category:"template",readOnly:false,complexity:"low",examples:[{description:"Insert customer name variable at start of first paragraph",input:{documentId:"doc_123",position:{paragraphIndex:0,offset:0},variableName:"customer_name"}}]}},z={name:"docx_apply_template",description:`Substitute template variables with actual values in the document.
|
|
6
|
+
Replaces all {variable} placeholders with the corresponding values provided.
|
|
7
|
+
Preserves all formatting (fonts, styles, colors, tables).
|
|
8
|
+
Use docx_get_variables first to discover what variables exist in the document.`,inputSchema:{type:"object",properties:{documentId:h,variables:{type:"object",description:'Map of variable names to values (e.g., {"customer_name": "John Doe", "date": "2024-01-15"})',additionalProperties:{type:"string"}},keepUnmatchedVariables:{type:"boolean",description:"If true, keep {variable} placeholders for variables not in the map. If false, replace with empty string. Default: true",default:true}},required:["documentId","variables"]},handler:async(e,t)=>{let{documentId:r,variables:o,keepUnmatchedVariables:n=true}=e,a=t.session.documents.get(r);if(!a)return {isError:true,content:[{type:"text",text:`Document not found: ${r}`}]};if(!a.buffer)return {isError:true,content:[{type:"text",text:"Cannot apply template: document was not loaded from a DOCX buffer"}]};try{let i=E(a.buffer,o,{nullGetter:n?"keep":"empty"}),s=await l(i.buffer);return a.document=s,a.buffer=i.buffer,a.lastModified=Date.now(),{content:[{type:"text",text:JSON.stringify({success:!0,replacedVariables:i.replacedVariables,unreplacedVariables:i.unreplacedVariables,warnings:i.warnings})}]}}catch(i){return {isError:true,content:[{type:"text",text:`Failed to apply template: ${i.message}`}]}}},annotations:{category:"template",readOnly:false,complexity:"medium",examples:[{description:"Fill in customer and date values",input:{documentId:"doc_123",variables:{customer_name:"Jane Smith",invoice_date:"2024-02-15",amount:"$1,234.56"}}}]}},H={name:"docx_validate_template",description:`Validate that a document is a valid docxtemplater template.
|
|
9
|
+
Checks for syntax errors like unclosed braces, invalid tag names, etc.
|
|
10
|
+
Returns validation result with any errors found and list of valid tags.`,inputSchema:{type:"object",properties:{documentId:h},required:["documentId"]},handler:async(e,t)=>{let{documentId:r}=e,o=t.session.documents.get(r);if(!o)return {isError:true,content:[{type:"text",text:`Document not found: ${r}`}]};if(!o.buffer)return {isError:true,content:[{type:"text",text:"Cannot validate template: document was not loaded from a DOCX buffer"}]};try{let n=L(o.buffer);return {content:[{type:"text",text:JSON.stringify({valid:n.valid,tags:n.tags,errors:n.errors.map(a=>({message:a.message,variable:a.variable,type:a.type}))},null,2)}]}}catch(n){return {isError:true,content:[{type:"text",text:`Failed to validate template: ${n.message}`}]}}},annotations:{category:"template",readOnly:true,complexity:"low"}},D=[N,F,z,H];var ee={id:"docxtemplater",name:"Docxtemplater",version:"1.0.0",description:"Template variable support using standard docxtemplater syntax ({variable})",commandHandlers:{insertTemplateVariable:v,replaceWithTemplateVariable:w},mcpTools:D,initialize:()=>{try{a("docxtemplater"),a("pizzip");}catch{console.warn("[docxtemplater-plugin] Warning: docxtemplater or pizzip not installed. Template features may not work. Install with: npm install docxtemplater pizzip");}}};export{U as a,V as b,j as c,R as d,B as e,oe as f,ae as g,ie as h,se as i,ce as j,le as k,pe as l,ue as m,O as n,E as o,ge as p,be as q,L as r,xe as s,he as t,ye as u,Te as v,J as w,ee as x};
|