@eigenpal/docx-editor-agents 0.4.3 → 0.5.0
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/dist/bridge.d.mts +1 -1
- package/dist/bridge.d.ts +1 -1
- package/dist/bridge.js +1 -1
- package/dist/bridge.mjs +1 -1
- package/dist/chunk-6NWAUIGY.js +1 -0
- package/dist/{chunk-MREPAMXX.js → chunk-A6ANAWKH.js} +1 -1
- package/dist/{chunk-H7HNGCMH.mjs → chunk-BDHS4WRJ.mjs} +1 -1
- package/dist/chunk-CPJV53R6.mjs +5 -0
- package/dist/chunk-G46D3GDJ.js +71 -0
- package/dist/{chunk-YCUXBRD7.js → chunk-LVRKZUG4.js} +3 -3
- package/dist/{chunk-NLYXACTI.js → chunk-N2TKFYHU.js} +2 -2
- package/dist/{chunk-74RQEWM7.mjs → chunk-QALBLABE.mjs} +1 -1
- package/dist/chunk-U7BWZ7DG.mjs +1 -0
- package/dist/chunk-XZHZXQO5.mjs +71 -0
- package/dist/executor-OYRPTNBR.mjs +1 -0
- package/dist/executor-SJAFSXKL.js +1 -0
- package/dist/headless-FE3K7ABO.js +1 -0
- package/dist/headless-JRF2KBID.mjs +1 -0
- package/dist/index.d.mts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +1 -1
- package/dist/index.mjs +1 -1
- package/dist/mcp.d.mts +1 -1
- package/dist/mcp.d.ts +1 -1
- package/dist/react.d.mts +2 -2
- package/dist/react.d.ts +2 -2
- package/dist/react.js +1 -1
- package/dist/react.mjs +1 -1
- package/dist/{server-CLaXsEC8.d.mts → server-DH5eszkm.d.mts} +41 -1
- package/dist/{server-CLaXsEC8.d.ts → server-DH5eszkm.d.ts} +41 -1
- package/dist/server.d.mts +1 -1
- package/dist/server.d.ts +1 -1
- package/dist/server.js +1 -1
- package/dist/server.mjs +1 -1
- package/package.json +1 -1
- package/dist/chunk-2AF2FRMM.js +0 -1
- package/dist/chunk-HSAYNLBS.mjs +0 -5
- package/dist/chunk-OVPN5UGH.js +0 -71
- package/dist/chunk-PNONETA3.mjs +0 -71
- package/dist/chunk-X57U3ESM.mjs +0 -1
- package/dist/executor-O3426NM3.mjs +0 -1
- package/dist/executor-WY7D4C5O.js +0 -1
- package/dist/headless-ASQ6WVGY.mjs +0 -1
- package/dist/headless-VE2YU7ZB.js +0 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
'use strict';var
|
|
1
|
+
'use strict';var chunkG46D3GDJ_js=require('./chunk-G46D3GDJ.js');function h(s){return s.type==="insertion"||s.type==="deletion"||s.type==="moveFrom"||s.type==="moveTo"}function x(s){let n=[];for(let o of s)o.type==="run"?n.push(chunkG46D3GDJ_js.H(o)):o.type==="hyperlink"&&n.push(chunkG46D3GDJ_js.I(o));return n.join("")}function K(s,n){let o=0;for(let t of s.content)if(t.type==="paragraph"){if(o===n)return t;o++;}else if(t.type==="table"){for(let r of t.rows)for(let e of r.cells)for(let a of e.content)if(a.type==="paragraph"){if(o===n)return a;o++;}}else o++;throw new Error(`Paragraph index ${n} out of bounds (max: ${o-1})`)}function R(s,n){let o=0;for(let t of s.content)if(t.type==="paragraph"){if(n(t,o)===false)return;o++;}else if(t.type==="table"){for(let r of t.rows)for(let e of r.cells)for(let a of e.content)if(a.type==="paragraph"){if(n(a,o)===false)return;o++;}}else o++;}function V(s,n={}){let{fromIndex:o,toIndex:t,includeTrackedChanges:r=true,includeCommentAnchors:e=true}=n,a=[],i=0;for(let c of s.content)if(c.type==="paragraph")w(i,o,t)&&a.push(L(c,i,r,e)),i++;else if(c.type==="table"){w(i,o,t)&&a.push(H(c,i,r,e));for(let l of c.rows)for(let u of l.cells)for(let p of u.content)p.type==="paragraph"&&i++;}else i++;return a}function w(s,n,o){return (n===void 0||s>=n)&&(o===void 0||s<=o)}function L(s,n,o,t){let r=B(s,o,t),e=s.formatting?.styleId,a=s.paraId;return chunkG46D3GDJ_js.U(e)?{type:"heading",index:n,paraId:a,level:chunkG46D3GDJ_js.V(e)??1,text:r}:s.listRendering?{type:"list-item",index:n,paraId:a,text:r,listLevel:s.listRendering.level??0,listType:s.listRendering.isBullet?"bullet":"number"}:{type:"paragraph",index:n,paraId:a,text:r}}function H(s,n,o,t){let r=[],e=[];for(let a of s.rows){let i=[],c=[];for(let l of a.cells){let u=[],p;for(let g of l.content)g.type==="paragraph"&&(p===void 0&&(p=g.paraId),u.push(B(g,o,t)));i.push(u.join(`
|
|
2
2
|
`)),c.push(p);}r.push(i),e.push(c);}return {type:"table",index:n,rows:r,cellParaIds:e}}function Y(s){let n=[],o=t=>t.paraId?t.paraId:String(t.index);for(let t of s)switch(t.type){case "heading":n.push(`[${o(t)}] (h${t.level}) ${t.text}`);break;case "paragraph":n.push(`[${o(t)}] ${t.text}`);break;case "list-item":{let r=" ".repeat(t.listLevel),e=t.listType==="bullet"?"\u2022":"-";n.push(`[${o(t)}] ${r}${e} ${t.text}`);break}case "table":{let r=t.index;for(let e=0;e<t.rows.length;e++)for(let a=0;a<t.rows[e].length;a++){let c=t.rows[e][a].split(`
|
|
3
3
|
`),l=t.cellParaIds?.[e]?.[a];for(let u=0;u<c.length;u++){let p=u===0&&l?l:String(r);n.push(`[${p}] (table, row ${e+1}, col ${a+1}) ${c[u]}`),r++;}}break}}return n.join(`
|
|
4
|
-
`)}function B(s,n,o){let t=[],r=new Set;for(let e of s.content){if(e.type==="commentRangeStart"&&o){r.add(e.id),t.push(`[comment:${e.id}]`);continue}if(e.type==="commentRangeEnd"&&o){r.has(e.id)&&(r.delete(e.id),t.push("[/comment]"));continue}if(e.type==="run")t.push(
|
|
5
|
-
`)}function z(s){let n=new Map,o=new Map;return R(s,(t,r)=>{for(let e of t.content)if(e.type==="commentRangeStart")o.set(e.id,{paragraphIndex:r,parts:[]});else if(e.type==="commentRangeEnd"){let a=o.get(e.id);a&&(n.set(e.id,{text:a.parts.join(""),paragraphIndex:a.paragraphIndex}),o.delete(e.id));}else if(e.type==="run"){let a=
|
|
4
|
+
`)}function B(s,n,o){let t=[],r=new Set;for(let e of s.content){if(e.type==="commentRangeStart"&&o){r.add(e.id),t.push(`[comment:${e.id}]`);continue}if(e.type==="commentRangeEnd"&&o){r.has(e.id)&&(r.delete(e.id),t.push("[/comment]"));continue}if(e.type==="run")t.push(chunkG46D3GDJ_js.H(e));else if(e.type==="hyperlink")t.push(chunkG46D3GDJ_js.I(e));else if(h(e)){let a=x(e.content);e.type==="insertion"||e.type==="moveTo"?n&&t.push(`[+${a}+]{by:${e.info.author}}`):n?t.push(`[-${a}-]{by:${e.info.author}}`):t.push(a);}}return t.join("")}var y=class extends Error{constructor(n,o){let t=o!==void 0?` in paragraph ${o}`:" in document";super(`Text not found${t}: "${n}"`),this.name="TextNotFoundError";}},M=class extends Error{constructor(n){super(`Tracked change not found: id=${n}`),this.name="ChangeNotFoundError";}},F=class extends Error{constructor(n){super(`Comment not found: id=${n}`),this.name="CommentNotFoundError";}};function E(s){let n=[],o=0;for(let t=0;t<s.content.length;t++){let r=s.content[t];if(r.type==="run"){let e=chunkG46D3GDJ_js.H(r);n.push({contentIndex:t,run:r,text:e,startPos:o}),o+=e.length;}else if(r.type==="hyperlink")for(let e=0;e<r.children.length;e++){let a=r.children[e];if(a.type==="run"){let i=chunkG46D3GDJ_js.H(a);n.push({contentIndex:t,run:a,text:i,startPos:o}),o+=i.length;}}else if(h(r)){if(r.type==="insertion"||r.type==="moveTo")continue;for(let e=0;e<r.content.length;e++){let a=r.content[e];if(a.type==="run"){let i=chunkG46D3GDJ_js.H(a);n.push({contentIndex:t,run:a,text:i,startPos:o}),o+=i.length;}else if(a.type==="hyperlink"){for(let i of a.children)if(i.type==="run"){let c=chunkG46D3GDJ_js.H(i);n.push({contentIndex:t,run:i,text:c,startPos:o}),o+=c.length;}}}}}return n}function k(s){return E(s).map(n=>n.text).join("")}function G(s,n,o){let t=E(s),r=t.map(u=>u.text).join(""),e=W(r,n);if(!e)throw new y(n,o);let a=-1,i=0;for(let u=0;u<t.length;u++)if(e.start<t[u].startPos+t[u].text.length){a=u,i=e.start-t[u].startPos;break}let c=-1,l=0;for(let u=t.length-1;u>=0;u--)if(e.end>t[u].startPos){c=u,l=e.end-t[u].startPos;break}if(a===-1||c===-1)throw new y(n,o);return {startRunIndex:t[a].contentIndex,startOffset:i,endRunIndex:t[c].contentIndex,endOffset:l}}function te(s,n,o){let t=G(s,n,o),{startRunIndex:r,endRunIndex:e}=t,{startOffset:a,endOffset:i}=t,c=s.content[e];if(c.type==="run"){let u=chunkG46D3GDJ_js.H(c);if(i<u.length){let p=D(u.slice(i),c);$(c,u.slice(0,i)),s.content.splice(e+1,0,p);}}let l=s.content[r];if(l.type==="run"&&a>0){let u=chunkG46D3GDJ_js.H(l),p=D(u.slice(0,a),l);$(l,u.slice(a)),s.content.splice(r,0,p),r++,e++;}return {startIndex:r,endIndex:e}}function D(s,n){return {type:"run",content:[{type:"text",text:s}],formatting:n.formatting?{...n.formatting}:void 0}}function $(s,n){let o=s.content.find(t=>t.type==="text");o&&(o.text=n);}function O(s){let n=[],o=[],t=true;for(let r=0;r<s.length;r++){let e=s[r];if(!"\u200B\u200C\u200D\uFEFF\xAD".includes(e)){if("\u201C\u201D\u201E\u201F".includes(e)&&(e='"'),"\u2018\u2019\u201A\u201B".includes(e)&&(e="'"),"\u2013\u2014\u2012\u2015".includes(e)&&(e="-"),e==="\u2026"){n.push(".",".","."),o.push(r,r,r),t=false;continue}if(/\s/.test(e)||e==="\xA0"){t||(n.push(" "),o.push(r),t=true);continue}n.push(e.toLowerCase()),o.push(r),t=false;}}return n.length>0&&n[n.length-1]===" "&&(n.pop(),o.pop()),{text:n.join(""),posMap:o}}function S(s,n,o,t){let r=s.posMap[n],e=s.posMap[n+o-1]+1;for(;e<t.length&&"\u200B\u200C\u200D\uFEFF\xAD".includes(t[e]);)e++;return {start:r,end:e}}function W(s,n){if(!n||!s)return null;let o=s.indexOf(n);if(o!==-1)return {start:o,end:o+n.length};let t=O(s),r=O(n);if(!r.text)return null;let e=t.text.indexOf(r.text);if(e!==-1)return S(t,e,r.text.length,s);let a=r.text.split(" ");if(a.length>=3)for(let i=1;i<=Math.min(2,a.length-2);i++){let c=a.slice(0,-i).join(" "),l=t.text.indexOf(c);if(l!==-1)return S(t,l,c.length,s)}return null}function se(s,n){let o=new Map;return R(s,(r,e)=>{let a=null;for(let i of r.content)if(h(i)){a===null&&(a=k(r));let c=x(i.content),l=i.info.id,u=o.get(l);u&&u.paragraphIndex===e?u.text+=c:o.set(l,{id:l,type:i.type,author:i.info.author,date:i.info.date??null,text:c,context:a,paragraphIndex:e});}}),Array.from(o.values()).filter(r=>!(n?.author&&r.author!==n.author||n?.type&&r.type!==n.type))}function ae(s,n){let o=s.comments??[];if(o.length===0)return [];let t=z(s),r=[],e=new Map;for(let i of o)if(i.parentId!==void 0){let c=e.get(i.parentId)??[];c.push(i),e.set(i.parentId,c);}else r.push(i);return r.map(i=>{let c=t.get(i.id),l=(e.get(i.id)??[]).map(u=>({id:u.id,author:u.author,date:u.date??null,text:A(u)}));return {id:i.id,author:i.author,date:i.date??null,text:A(i),anchoredText:c?.text??"",paragraphIndex:c?.paragraphIndex??-1,replies:l,done:i.done??false}}).filter(i=>!(n?.author&&i.author!==n.author||n?.done!==void 0&&i.done!==n.done))}function A(s){return s.content.map(n=>k(n)).join(`
|
|
5
|
+
`)}function z(s){let n=new Map,o=new Map;return R(s,(t,r)=>{for(let e of t.content)if(e.type==="commentRangeStart")o.set(e.id,{paragraphIndex:r,parts:[]});else if(e.type==="commentRangeEnd"){let a=o.get(e.id);a&&(n.set(e.id,{text:a.parts.join(""),paragraphIndex:a.paragraphIndex}),o.delete(e.id));}else if(e.type==="run"){let a=chunkG46D3GDJ_js.H(e);for(let i of o.values())i.parts.push(a);}else if(e.type==="hyperlink"){let a=e.children.filter(i=>i.type==="run").map(chunkG46D3GDJ_js.H).join("");for(let i of o.values())i.parts.push(a);}else if(h(e)){if(e.type==="insertion"||e.type==="moveTo")continue;let a=x(e.content);for(let i of o.values())i.parts.push(a);}}),n}function N(s){let n=s.toDocument().package?.document;if(!n)return new Map;let o=new Map,t=0;for(let r of n.content)if(r.type==="paragraph"){let e=r.paraId;e&&o.set(e,t),t++;}else if(r.type==="table")for(let e of r.rows)for(let a of e.cells)for(let i of a.content)i.type==="paragraph"&&t++;else t++;return o}function X(s){let n=[],o=t=>{for(let r of t.content)r.type==="text"&&n.push(r.text??"");};for(let t of s.content)if(t.type==="run")o(t);else if(t.type==="hyperlink")for(let r of t.children)r.type==="run"&&o(r);else if(t.type==="deletion"||t.type==="moveFrom"){for(let r of t.content)if(r.type==="run")o(r);else if(r.type==="hyperlink")for(let e of r.children)e.type==="run"&&o(e);}return n.join("")}function ce(s){let n=new Set,o=null;function t(){return o===null&&(o=N(s)),o}function r(){if(n.size===0)return;let e=s.getComments(),a=s.getChanges(),i={commentCount:e.length,changeCount:a.length,comments:e,changes:a};for(let c of n)try{c(i);}catch(l){console.error("reviewerBridge content listener threw:",l);}}return {getContentAsText(e){return s.getContentAsText(e)},getContent(e){return s.getContent(e)},getComments(e){return s.getComments(e)},getChanges(e){return s.getChanges(e)},findText(e,a){if(!e)return [];let i=a?.caseSensitive??false,c=a?.limit??20,l=i?e:e.toLowerCase(),u=s.toDocument().package?.document;if(!u)return [];let p=[],g=40;for(let P of u.content){if(p.length>=c)break;if(P.type!=="paragraph")continue;let C=P;if(!C.paraId)continue;let m=X(C),v=i?m:m.toLowerCase(),d=v.indexOf(l);if(d===-1||v.indexOf(l,d+1)!==-1)continue;let j=m.slice(d,d+e.length);p.push({paraId:C.paraId,match:j,before:m.slice(Math.max(0,d-g),d),after:m.slice(d+e.length,d+e.length+g)});}return p},getSelection(){return null},addComment(e){let a=t().get(e.paraId);if(a===void 0)return null;try{let i=s.addComment({paragraphIndex:a,text:e.text,author:e.author,search:e.search});return r(),i}catch{return null}},replyTo(e,a){try{let i=s.replyTo(e,a);return r(),i}catch{return null}},resolveComment(e){let i=s.toDocument().package?.document?.comments?.find(c=>c.id===e);i&&(i.done=true,r());},proposeChange(e){let a=t().get(e.paraId);if(a===void 0)return false;let i=e.search==="",c=e.replaceWith==="";if(i&&c)return false;try{return i?s.proposeInsertion({paragraphIndex:a,insertText:e.replaceWith,author:e.author}):c?s.proposeDeletion({paragraphIndex:a,search:e.search,author:e.author}):s.replace({paragraphIndex:a,search:e.search,replaceWith:e.replaceWith,author:e.author}),r(),true}catch{return false}},scrollTo(e){return t().has(e)},applyFormatting(){return false},setParagraphStyle(){return false},getPage(){return null},getPages(){return []},getTotalPages(){return 0},getCurrentPage(){return 0},onContentChange(e){return n.add(e),()=>{n.delete(e);}},onSelectionChange(){return ()=>{}}}}exports.a=h;exports.b=K;exports.c=R;exports.d=V;exports.e=Y;exports.f=y;exports.g=M;exports.h=F;exports.i=G;exports.j=te;exports.k=se;exports.l=ae;exports.m=ce;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
'use strict';var
|
|
2
|
-
`)}function m(t){let a=t.getEditorRef();if(a){let e=a.getDocument();if(e?.package?.document)return e.package.document}return t.getDocument()?.package?.document??null}function I(t,a="AI"){function s(e){return e??a}return {getContentAsText(e){let n=m(t);return n?
|
|
1
|
+
'use strict';var chunkLVRKZUG4_js=require('./chunk-LVRKZUG4.js'),chunkRI5S75JY_js=require('./chunk-RI5S75JY.js'),react=require('react');var S=chunkRI5S75JY_js.d();function T(t){let{editorRef:a,author:s="AI"}=t,e=react.useMemo(()=>({get:()=>a.current?I(a.current,s):null}),[a,s]);return {executeToolCall:react.useCallback((l,i)=>{let r=e.get();return r?chunkRI5S75JY_js.b(l,i,r):{success:false,error:"Editor not ready"}},[e]),toolSchemas:S}}function x(t){return !t||t.length===0?"":t.map(a=>{let s=a;return s?.content?s.content.map(e=>e.content?.map(n=>n.text||"").join("")||"").join(""):""}).join(`
|
|
2
|
+
`)}function m(t){let a=t.getEditorRef();if(a){let e=a.getDocument();if(e?.package?.document)return e.package.document}return t.getDocument()?.package?.document??null}function I(t,a="AI"){function s(e){return e??a}return {getContentAsText(e){let n=m(t);return n?chunkLVRKZUG4_js.e(chunkLVRKZUG4_js.d(n,e)):""},getContent(e){let n=m(t);return n?chunkLVRKZUG4_js.d(n,e):[]},getComments(e){let n=m(t);if(!n)return [];let l=chunkLVRKZUG4_js.l(n,e);if(l.length>0)return l;let i=t.getComments();if(i.length===0)return [];let r=new Map,g=[];for(let o of i)if(o.parentId){let c=r.get(o.parentId);c?c.push(o):r.set(o.parentId,[o]);}else g.push(o);let u=[];for(let o of g){if(e?.author&&o.author!==e.author||e?.done!==void 0&&(o.done??false)!==e.done)continue;let c=r.get(o.id)??[];u.push({id:o.id,author:o.author,date:o.date??null,text:x(o.content),anchoredText:"",paragraphIndex:-1,replies:c.map(p=>({id:p.id,author:p.author,date:p.date??null,text:x(p.content)})),done:o.done??false});}return u},getChanges(e){let n=m(t);return n?chunkLVRKZUG4_js.k(n,e):[]},findText(e,n){return t.findInDocument(e,n)},getSelection(){return t.getSelectionInfo()},addComment(e){return t.addComment({paraId:e.paraId,text:e.text,author:s(e.author),search:e.search})},replyTo(e,n){return t.replyToComment(e,n.text,s(n.author))},resolveComment(e){t.resolveComment(e);},proposeChange(e){return t.proposeChange({paraId:e.paraId,search:e.search,replaceWith:e.replaceWith,author:s(e.author)})},applyFormatting(e){return t.applyFormatting({paraId:e.paraId,search:e.search,marks:e.marks})},setParagraphStyle(e){return t.setParagraphStyle({paraId:e.paraId,styleId:e.styleId})},getPage(e){return t.getPageContent(e)},getPages(e){let n=t.getTotalPages(),l=Math.max(1,Math.min(e.from,n)),i=Math.max(l,Math.min(e.to,n)),r=[];for(let g=l;g<=i;g++){let u=t.getPageContent(g);u&&r.push(u);}return r},getTotalPages(){return t.getTotalPages()},getCurrentPage(){return t.getCurrentPage()},scrollTo(e){return t.scrollToParaId(e)},onContentChange(e){return t.onContentChange(()=>{let n=m(t),l=n?chunkLVRKZUG4_js.l(n):[],i=n?chunkLVRKZUG4_js.k(n):[];try{e({commentCount:l.length,changeCount:i.length,comments:l,changes:i});}catch(r){console.error("onContentChange listener threw:",r);}})},onSelectionChange(e){return t.onSelectionChange(()=>{try{e(t.getSelectionInfo());}catch(n){console.error("onSelectionChange listener threw:",n);}})}}}exports.a=T;exports.b=I;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {l,k,d as d$1,e}from'./chunk-
|
|
1
|
+
import {l,k,d as d$1,e}from'./chunk-CPJV53R6.mjs';import {d,b}from'./chunk-24MVJKCP.mjs';import {useMemo,useCallback}from'react';var S=d();function T(t){let{editorRef:a,author:s="AI"}=t,e=useMemo(()=>({get:()=>a.current?I(a.current,s):null}),[a,s]);return {executeToolCall:useCallback((l,i)=>{let r=e.get();return r?b(l,i,r):{success:false,error:"Editor not ready"}},[e]),toolSchemas:S}}function x(t){return !t||t.length===0?"":t.map(a=>{let s=a;return s?.content?s.content.map(e=>e.content?.map(n=>n.text||"").join("")||"").join(""):""}).join(`
|
|
2
2
|
`)}function m(t){let a=t.getEditorRef();if(a){let e=a.getDocument();if(e?.package?.document)return e.package.document}return t.getDocument()?.package?.document??null}function I(t,a="AI"){function s(e){return e??a}return {getContentAsText(e$1){let n=m(t);return n?e(d$1(n,e$1)):""},getContent(e){let n=m(t);return n?d$1(n,e):[]},getComments(e){let n=m(t);if(!n)return [];let l$1=l(n,e);if(l$1.length>0)return l$1;let i=t.getComments();if(i.length===0)return [];let r=new Map,g=[];for(let o of i)if(o.parentId){let c=r.get(o.parentId);c?c.push(o):r.set(o.parentId,[o]);}else g.push(o);let u=[];for(let o of g){if(e?.author&&o.author!==e.author||e?.done!==void 0&&(o.done??false)!==e.done)continue;let c=r.get(o.id)??[];u.push({id:o.id,author:o.author,date:o.date??null,text:x(o.content),anchoredText:"",paragraphIndex:-1,replies:c.map(p=>({id:p.id,author:p.author,date:p.date??null,text:x(p.content)})),done:o.done??false});}return u},getChanges(e){let n=m(t);return n?k(n,e):[]},findText(e,n){return t.findInDocument(e,n)},getSelection(){return t.getSelectionInfo()},addComment(e){return t.addComment({paraId:e.paraId,text:e.text,author:s(e.author),search:e.search})},replyTo(e,n){return t.replyToComment(e,n.text,s(n.author))},resolveComment(e){t.resolveComment(e);},proposeChange(e){return t.proposeChange({paraId:e.paraId,search:e.search,replaceWith:e.replaceWith,author:s(e.author)})},applyFormatting(e){return t.applyFormatting({paraId:e.paraId,search:e.search,marks:e.marks})},setParagraphStyle(e){return t.setParagraphStyle({paraId:e.paraId,styleId:e.styleId})},getPage(e){return t.getPageContent(e)},getPages(e){let n=t.getTotalPages(),l=Math.max(1,Math.min(e.from,n)),i=Math.max(l,Math.min(e.to,n)),r=[];for(let g=l;g<=i;g++){let u=t.getPageContent(g);u&&r.push(u);}return r},getTotalPages(){return t.getTotalPages()},getCurrentPage(){return t.getCurrentPage()},scrollTo(e){return t.scrollToParaId(e)},onContentChange(e){return t.onContentChange(()=>{let n=m(t),l$1=n?l(n):[],i=n?k(n):[];try{e({commentCount:l$1.length,changeCount:i.length,comments:l$1,changes:i});}catch(r){console.error("onContentChange listener threw:",r);}})},onSelectionChange(e){return t.onSelectionChange(()=>{try{e(t.getSelectionInfo());}catch(n){console.error("onSelectionChange listener threw:",n);}})}}}export{T as a,I as b};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var w=class{constructor(){this.plugins=new Map;this.commandHandlers=new Map;this.eventListeners=new Set;this.initialized=new Set;}register(e,r){let n=[];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 t of e.dependencies)if(!this.plugins.has(t))return {success:false,error:`Plugin '${e.id}' requires '${t}' which is not registered`}}if(e.commandHandlers)for(let[t,s]of Object.entries(e.commandHandlers)){if(this.commandHandlers.has(t)){let i=this.commandHandlers.get(t);n.push(`Command '${t}' from '${e.id}' overrides handler from '${i.pluginId}'`);}this.commandHandlers.set(t,{pluginId:e.id,handler:s});}if(this.plugins.set(e.id,e),e.initialize&&!this.initialized.has(e.id))try{let t=e.initialize();t instanceof Promise?t.then(()=>{this.initialized.add(e.id);}).catch(s=>{this.emit({type:"error",pluginId:e.id,error:s});}):this.initialized.add(e.id);}catch(t){this.emit({type:"error",pluginId:e.id,error:t});}return r?.debug&&console.log(`[PluginRegistry] Registered plugin: ${e.id}`),this.emit({type:"registered",plugin:e}),{success:true,plugin:e,warnings:n.length>0?n:void 0}}unregister(e){let r=this.plugins.get(e);if(!r)return false;for(let[n,t]of this.plugins)if(t.dependencies?.includes(e))return console.warn(`Cannot unregister '${e}': '${n}' depends on it`),false;for(let[n,{pluginId:t}]of this.commandHandlers)t===e&&this.commandHandlers.delete(n);if(r.destroy)try{let n=r.destroy();n instanceof Promise&&n.catch(t=>{this.emit({type:"error",pluginId:e,error:t});});}catch(n){this.emit({type:"error",pluginId:e,error:n});}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 n=r.mcpTools.find(t=>t.name===e);if(n)return n}}addEventListener(e){this.eventListeners.add(e);}removeEventListener(e){this.eventListeners.delete(e);}emit(e){for(let r of this.eventListeners)try{r(e);}catch(n){console.error("[PluginRegistry] Event listener error:",n);}}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)}}},b=new w;function U(o,e){return o.map(r=>b.register(r,e))}function W(o){return e=>b.register(e,o)}function J(o){return o/1440*96}function q(o){return o/96*1440}function K(o){return o==null||isNaN(o)?0:Math.round(o*96/914400)}function E(o){return Math.round(o/96*914400)}function Q(o){return Math.round(o/914400*1440)}function Y(o){return Math.round(o/1440*914400)}function Z(o){return o/72*96}function ee(o){return o/144*96}function R(o,e=2){let r=Math.pow(10,e);return Math.round(o*r)/r}function te(o){return `${R(o)}px`}function _(o,e){let r=b.getCommandHandler(e.type);if(r)return r(o,e);switch(e.type){case "insertText":return v(o,e);case "replaceText":return S(o,e);case "deleteText":return N(o,e);case "formatText":return M(o,e);case "formatParagraph":return $(o,e);case "applyStyle":return A(o,e);case "insertTable":return L(o,e);case "insertImage":return B(o,e);case "insertHyperlink":return F(o,e);case "removeHyperlink":return V(o,e);case "insertParagraphBreak":return H(o,e);case "mergeParagraphs":return z(o,e);case "splitParagraph":return O(o,e);case "setVariable":return X(o,e);case "applyVariables":return j(o,e);default:let n=e;throw new Error(`Unknown command type: ${n.type}`)}}function ae(o,e){return e.reduce((r,n)=>_(r,n),o)}function h(o){return JSON.parse(JSON.stringify(o))}function g(o,e){let r=0;for(let n=0;n<o.content.length;n++)if(o.content[n].type==="paragraph"){if(r===e)return n;r++;}return -1}function I(o){let e="";for(let r of o.content)if(r.type==="run")for(let n of r.content)n.type==="text"&&(e+=n.text);else if(r.type==="hyperlink"){for(let n of r.children)if(n.type==="run")for(let t of n.content)t.type==="text"&&(e+=t.text);}return e}function T(o,e){return {type:"run",formatting:e,content:[{type:"text",text:o}]}}function C(o,e,r,n){let t=[],s=0,i=false;for(let a of o.content)if(a.type==="run"){let c=a.content.filter(l=>l.type==="text").map(l=>l.text).join(""),p=s,u=s+c.length;if(!i&&e>=p&&e<=u){let l=e-p;l>0&&t.push({...a,content:[{type:"text",text:c.slice(0,l)}]}),t.push(T(r,n||a.formatting)),l<c.length&&t.push({...a,content:[{type:"text",text:c.slice(l)}]}),i=true;}else t.push(a);s=u;}else t.push(a);return i||t.push(T(r,n)),t}function P(o,e,r){let n=[],t=0;for(let s of o.content)if(s.type==="run"){let i=s.content.filter(p=>p.type==="text").map(p=>p.text).join(""),a=t,c=t+i.length;if(c<=e||a>=r)n.push(s);else {let p="";a<e&&(p+=i.slice(0,e-a)),c>r&&(p+=i.slice(r-a)),p.length>0&&n.push({...s,content:[{type:"text",text:p}]});}t=c;}else n.push(s);return n}function k(o,e,r,n){let t=[],s=0;for(let i of o.content)if(i.type==="run"){let a=i.content.filter(u=>u.type==="text").map(u=>u.text).join(""),c=s,p=s+a.length;if(p<=e||c>=r)t.push(i);else if(c>=e&&p<=r)t.push({...i,formatting:{...i.formatting,...n}});else {let u=Math.max(e,c),l=Math.min(r,p);c<u&&t.push({...i,content:[{type:"text",text:a.slice(0,u-c)}]}),t.push({...i,formatting:{...i.formatting,...n},content:[{type:"text",text:a.slice(u-c,l-c)}]}),p>l&&t.push({...i,content:[{type:"text",text:a.slice(l-c)}]});}s=p;}else t.push(i);return t}function v(o,e){let r=h(o),n=r.package.document,t=g(n,e.position.paragraphIndex);if(t===-1)throw new Error(`Paragraph index ${e.position.paragraphIndex} not found`);let s=n.content[t];return s.content=C(s,e.position.offset,e.text,e.formatting),r}function S(o,e){let r=h(o),n=r.package.document,{start:t,end:s}=e.range;if(t.paragraphIndex===s.paragraphIndex){let i=g(n,t.paragraphIndex);if(i===-1)throw new Error(`Paragraph index ${t.paragraphIndex} not found`);let a=n.content[i];a.content=P(a,t.offset,s.offset),a.content=C(a,t.offset,e.text,e.formatting);}else {let i=g(n,t.paragraphIndex),a=n.content[i],c=I(a);a.content=P(a,t.offset,c.length),a.content=C(a,t.offset,e.text,e.formatting);let p=[];for(let u=t.paragraphIndex+1;u<=s.paragraphIndex;u++)p.push(g(n,u));for(let u=p.length-1;u>=0;u--)p[u]!==-1&&n.content.splice(p[u],1);}return r}function N(o,e){let r=h(o),n=r.package.document,{start:t,end:s}=e.range;if(t.paragraphIndex===s.paragraphIndex){let i=g(n,t.paragraphIndex);if(i===-1)throw new Error(`Paragraph index ${t.paragraphIndex} not found`);let a=n.content[i];a.content=P(a,t.offset,s.offset);}else {let i=g(n,t.paragraphIndex),a=n.content[i],c=I(a);a.content=P(a,t.offset,c.length);let p=g(n,s.paragraphIndex),u=n.content[p];u.content=P(u,0,s.offset),a.content.push(...u.content);let l=[];for(let f=t.paragraphIndex+1;f<=s.paragraphIndex;f++)l.push(g(n,f));for(let f=l.length-1;f>=0;f--)l[f]!==-1&&n.content.splice(l[f],1);}return r}function M(o,e){let r=h(o),n=r.package.document,{start:t,end:s}=e.range;if(t.paragraphIndex===s.paragraphIndex){let i=g(n,t.paragraphIndex);if(i===-1)throw new Error(`Paragraph index ${t.paragraphIndex} not found`);let a=n.content[i];a.content=k(a,t.offset,s.offset,e.formatting);}else for(let i=t.paragraphIndex;i<=s.paragraphIndex;i++){let a=g(n,i);if(a===-1)continue;let c=n.content[a],p=I(c),u=0,l=p.length;i===t.paragraphIndex&&(u=t.offset),i===s.paragraphIndex&&(l=s.offset),c.content=k(c,u,l,e.formatting);}return r}function $(o,e){let r=h(o),n=r.package.document,t=g(n,e.paragraphIndex);if(t===-1)throw new Error(`Paragraph index ${e.paragraphIndex} not found`);let s=n.content[t];if(s.formatting={...s.formatting,...e.formatting},"numPr"in e.formatting){let i=e.formatting.numPr;if(i&&i.numId!==void 0&&i.numId!==0){let a=i.ilvl??0,c=i.numId===1,p=c?"\u2022":"1.";if(r.package.numbering){let u=r.package.numbering.nums.find(l=>l.numId===i.numId);if(u){let l=r.package.numbering.abstractNums.find(f=>f.abstractNumId===u.abstractNumId);if(l){let f=l.levels.find(d=>d.ilvl===a);f&&(p=f.lvlText||p);}}}s.listRendering={level:a,numId:i.numId,marker:p,isBullet:c};}else delete s.listRendering;}return r}function A(o,e){let r=h(o),n=r.package.document,t=g(n,e.paragraphIndex);if(t===-1)throw new Error(`Paragraph index ${e.paragraphIndex} not found`);let s=n.content[t];return s.formatting={...s.formatting,styleId:e.styleId},r}function L(o,e){let r=h(o),n=r.package.document,t=[];for(let a=0;a<e.rows;a++){let c=[];for(let p=0;p<e.columns;p++){let u=e.data?.[a]?.[p]||"";c.push({type:"tableCell",content:[{type:"paragraph",content:u?[T(u)]:[]}]});}t.push({type:"tableRow",formatting:a===0&&e.hasHeader?{header:true}:void 0,cells:c});}let s={type:"table",rows:t},i=g(n,e.position.paragraphIndex);return i===-1?n.content.push(s):n.content.splice(i+1,0,s),r}function B(o,e){let r=h(o),n=r.package.document,t=g(n,e.position.paragraphIndex);if(t===-1)throw new Error(`Paragraph index ${e.position.paragraphIndex} not found`);let s=n.content[t],a={type:"run",content:[{type:"drawing",image:{type:"image",rId:`rId_img_${Date.now()}`,src:e.src,alt:e.alt,size:{width:E(e.width||100),height:E(e.height||100)},wrap:{type:"inline"}}}]},c=C(s,e.position.offset,"",void 0),p=false,u=0;for(let l=0;l<c.length;l++){let f=c[l];if(f.type==="run"){let d=f.content.filter(m=>m.type==="text").map(m=>m.text).join("");if(u+=d.length,!p&&u>=e.position.offset){c.splice(l+1,0,a),p=true;break}}}return p||c.push(a),s.content=c,r}function F(o,e){let r=h(o),n=r.package.document,{start:t,end:s}=e.range;if(t.paragraphIndex!==s.paragraphIndex)throw new Error("Hyperlinks cannot span multiple paragraphs");let i=g(n,t.paragraphIndex);if(i===-1)throw new Error(`Paragraph index ${t.paragraphIndex} not found`);let a=n.content[i],c=I(a),p=e.displayText||c.slice(t.offset,s.offset);a.content=P(a,t.offset,s.offset);let u={type:"hyperlink",href:e.url,tooltip:e.tooltip,children:[T(p)]},l=false,f=0,d=[];for(let m of a.content)if(m.type==="run"){let y=m.content.filter(x=>x.type==="text").map(x=>x.text).join(""),D=f+y.length;if(!l&&f<=t.offset&&t.offset<=D){let x=t.offset-f;x>0&&d.push({...m,content:[{type:"text",text:y.slice(0,x)}]}),d.push(u),x<y.length&&d.push({...m,content:[{type:"text",text:y.slice(x)}]}),l=true;}else d.push(m);f=D;}else d.push(m);return l||d.push(u),a.content=d,r}function V(o,e){let r=h(o),n=r.package.document,{start:t}=e.range,s=g(n,t.paragraphIndex);if(s===-1)throw new Error(`Paragraph index ${t.paragraphIndex} not found`);let i=n.content[s],a=[];for(let c of i.content)if(c.type==="hyperlink")for(let p of c.children)p.type==="run"&&a.push(p);else a.push(c);return i.content=a,r}function H(o,e){let r=h(o),n=r.package.document,t=g(n,e.position.paragraphIndex);if(t===-1)throw new Error(`Paragraph index ${e.position.paragraphIndex} not found`);let s=n.content[t],i=I(s),a=P({content:[...s.content]},e.position.offset,i.length),c=P({content:[...s.content]},0,e.position.offset);s.content=a;let p={type:"paragraph",formatting:s.formatting,content:c};return n.content.splice(t+1,0,p),r}function z(o,e){let r=h(o),n=r.package.document,t=g(n,e.paragraphIndex);if(t===-1)throw new Error(`Paragraph index ${e.paragraphIndex} not found`);let s=n.content[t],i=[];for(let a=1;a<=e.count;a++){let c=g(n,e.paragraphIndex+a);if(c!==-1){let p=n.content[c];s.content.push(...p.content),i.push(c);}}for(let a=i.length-1;a>=0;a--)n.content.splice(i[a],1);return r}function O(o,e){return H(o,{position:e.position})}function X(o,e){let r=h(o);return r.templateVariables||(r.templateVariables=[]),r.templateVariables.includes(e.name)||r.templateVariables.push(e.name),r}function j(o,e){let r=h(o),n=r.package.document;function t(a){for(let c of a.content)if(c.type==="text")for(let[p,u]of Object.entries(e.values)){let l=new RegExp(`\\{${p}\\}`,"g");c.text=c.text.replace(l,u);}}function s(a){for(let c of a.content)if(c.type==="run")t(c);else if(c.type==="hyperlink")for(let p of c.children)p.type==="run"&&t(p);}function i(a){if(a.type==="paragraph")s(a);else if(a.type==="table")for(let c of a.rows)for(let p of c.cells)for(let u of p.content)i(u);}for(let a of n.content)i(a);return r}export{w as a,b,U as c,W as d,J as e,q as f,K as g,E as h,Q as i,Y as j,Z as k,ee as l,te as m,_ as n,ae as o};
|