@eigenpal/docx-editor-agents 0.0.34 → 0.1.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/chunk-G5XAABHF.js +71 -0
- package/dist/chunk-W2QSJSB7.mjs +71 -0
- package/dist/headless-DGAHMYIU.js +1 -0
- package/dist/{headless-BWFR2RRX.mjs → headless-I5CZ42MD.mjs} +1 -1
- package/dist/index.d.mts +13 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.js +5 -5
- package/dist/index.mjs +5 -5
- package/package.json +2 -2
- package/dist/chunk-QU2KZVKE.mjs +0 -71
- package/dist/chunk-T3PAPI4X.js +0 -71
- package/dist/headless-SJ66VOJQ.js +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
'use strict';var chunkG5XAABHF_js=require('./chunk-G5XAABHF.js'),chunk2AF2FRMM_js=require('./chunk-2AF2FRMM.js'),chunk4QRVKNI4_js=require('./chunk-4QRVKNI4.js');Object.defineProperty(exports,"DEFAULT_AI_ACTIONS",{enumerable:true,get:function(){return chunkG5XAABHF_js.Fa}});Object.defineProperty(exports,"DocumentAgent",{enumerable:true,get:function(){return chunkG5XAABHF_js.G}});Object.defineProperty(exports,"VERSION",{enumerable:true,get:function(){return chunkG5XAABHF_js.Ha}});Object.defineProperty(exports,"attemptSelectiveSave",{enumerable:true,get:function(){return chunkG5XAABHF_js.i}});Object.defineProperty(exports,"blendColors",{enumerable:true,get:function(){return chunkG5XAABHF_js.wa}});Object.defineProperty(exports,"buildExtendedSelectionContext",{enumerable:true,get:function(){return chunkG5XAABHF_js.N}});Object.defineProperty(exports,"buildPatchedDocumentXml",{enumerable:true,get:function(){return chunkG5XAABHF_js.h}});Object.defineProperty(exports,"buildSelectionContext",{enumerable:true,get:function(){return chunkG5XAABHF_js.M}});Object.defineProperty(exports,"buildSelectionContextFromContext",{enumerable:true,get:function(){return chunkG5XAABHF_js.K}});Object.defineProperty(exports,"colorsEqual",{enumerable:true,get:function(){return chunkG5XAABHF_js.xa}});Object.defineProperty(exports,"comparePositions",{enumerable:true,get:function(){return chunkG5XAABHF_js.Ca}});Object.defineProperty(exports,"countCharacters",{enumerable:true,get:function(){return chunkG5XAABHF_js.V}});Object.defineProperty(exports,"countWords",{enumerable:true,get:function(){return chunkG5XAABHF_js.U}});Object.defineProperty(exports,"createAgent",{enumerable:true,get:function(){return chunkG5XAABHF_js.H}});Object.defineProperty(exports,"createAgentFromDocument",{enumerable:true,get:function(){return chunkG5XAABHF_js.I}});Object.defineProperty(exports,"createCollapsedRange",{enumerable:true,get:function(){return chunkG5XAABHF_js.za}});Object.defineProperty(exports,"createCommand",{enumerable:true,get:function(){return chunkG5XAABHF_js.Ga}});Object.defineProperty(exports,"createDocumentWithText",{enumerable:true,get:function(){return chunkG5XAABHF_js.ka}});Object.defineProperty(exports,"createDocx",{enumerable:true,get:function(){return chunkG5XAABHF_js.f}});Object.defineProperty(exports,"createEmptyDocument",{enumerable:true,get:function(){return chunkG5XAABHF_js.ja}});Object.defineProperty(exports,"createRange",{enumerable:true,get:function(){return chunkG5XAABHF_js.Aa}});Object.defineProperty(exports,"createRgbColor",{enumerable:true,get:function(){return chunkG5XAABHF_js.ta}});Object.defineProperty(exports,"createThemeColor",{enumerable:true,get:function(){return chunkG5XAABHF_js.sa}});Object.defineProperty(exports,"darkenColor",{enumerable:true,get:function(){return chunkG5XAABHF_js.ua}});Object.defineProperty(exports,"detectVariables",{enumerable:true,get:function(){return chunkG5XAABHF_js.j}});Object.defineProperty(exports,"detectVariablesDetailed",{enumerable:true,get:function(){return chunkG5XAABHF_js.k}});Object.defineProperty(exports,"detectVariablesInBody",{enumerable:true,get:function(){return chunkG5XAABHF_js.l}});Object.defineProperty(exports,"detectVariablesInParagraph",{enumerable:true,get:function(){return chunkG5XAABHF_js.m}});Object.defineProperty(exports,"documentHasVariables",{enumerable:true,get:function(){return chunkG5XAABHF_js.v}});Object.defineProperty(exports,"emuToPixels",{enumerable:true,get:function(){return chunkG5XAABHF_js.y}});Object.defineProperty(exports,"emuToTwips",{enumerable:true,get:function(){return chunkG5XAABHF_js.A}});Object.defineProperty(exports,"extractVariablesFromText",{enumerable:true,get:function(){return chunkG5XAABHF_js.n}});Object.defineProperty(exports,"formatPx",{enumerable:true,get:function(){return chunkG5XAABHF_js.E}});Object.defineProperty(exports,"formatVariable",{enumerable:true,get:function(){return chunkG5XAABHF_js.r}});Object.defineProperty(exports,"getActionDescription",{enumerable:true,get:function(){return chunkG5XAABHF_js.Ea}});Object.defineProperty(exports,"getActionLabel",{enumerable:true,get:function(){return chunkG5XAABHF_js.Da}});Object.defineProperty(exports,"getAgentContext",{enumerable:true,get:function(){return chunkG5XAABHF_js.J}});Object.defineProperty(exports,"getBlockIndexForParagraph",{enumerable:true,get:function(){return chunkG5XAABHF_js.ia}});Object.defineProperty(exports,"getBodyCharacterCount",{enumerable:true,get:function(){return chunkG5XAABHF_js.X}});Object.defineProperty(exports,"getBodyText",{enumerable:true,get:function(){return chunkG5XAABHF_js.T}});Object.defineProperty(exports,"getBodyWordCount",{enumerable:true,get:function(){return chunkG5XAABHF_js.W}});Object.defineProperty(exports,"getContrastingColor",{enumerable:true,get:function(){return chunkG5XAABHF_js.qa}});Object.defineProperty(exports,"getDocumentSummary",{enumerable:true,get:function(){return chunkG5XAABHF_js.L}});Object.defineProperty(exports,"getFormattingAtPosition",{enumerable:true,get:function(){return chunkG5XAABHF_js._}});Object.defineProperty(exports,"getHyperlinkAtPosition",{enumerable:true,get:function(){return chunkG5XAABHF_js.aa}});Object.defineProperty(exports,"getHyperlinkText",{enumerable:true,get:function(){return chunkG5XAABHF_js.R}});Object.defineProperty(exports,"getParagraphAtIndex",{enumerable:true,get:function(){return chunkG5XAABHF_js.ha}});Object.defineProperty(exports,"getParagraphText",{enumerable:true,get:function(){return chunkG5XAABHF_js.P}});Object.defineProperty(exports,"getParagraphs",{enumerable:true,get:function(){return chunkG5XAABHF_js.ga}});Object.defineProperty(exports,"getRunText",{enumerable:true,get:function(){return chunkG5XAABHF_js.Q}});Object.defineProperty(exports,"getSelectionFormattingSummary",{enumerable:true,get:function(){return chunkG5XAABHF_js.O}});Object.defineProperty(exports,"getTableText",{enumerable:true,get:function(){return chunkG5XAABHF_js.S}});Object.defineProperty(exports,"getTextAfter",{enumerable:true,get:function(){return chunkG5XAABHF_js.Z}});Object.defineProperty(exports,"getTextBefore",{enumerable:true,get:function(){return chunkG5XAABHF_js.Y}});Object.defineProperty(exports,"halfPointsToPixels",{enumerable:true,get:function(){return chunkG5XAABHF_js.D}});Object.defineProperty(exports,"hasHyperlinks",{enumerable:true,get:function(){return chunkG5XAABHF_js.ea}});Object.defineProperty(exports,"hasImages",{enumerable:true,get:function(){return chunkG5XAABHF_js.da}});Object.defineProperty(exports,"hasTables",{enumerable:true,get:function(){return chunkG5XAABHF_js.fa}});Object.defineProperty(exports,"hasTemplateVariables",{enumerable:true,get:function(){return chunkG5XAABHF_js.o}});Object.defineProperty(exports,"isBlack",{enumerable:true,get:function(){return chunkG5XAABHF_js.oa}});Object.defineProperty(exports,"isHeadingStyle",{enumerable:true,get:function(){return chunkG5XAABHF_js.ba}});Object.defineProperty(exports,"isPositionInHyperlink",{enumerable:true,get:function(){return chunkG5XAABHF_js.$}});Object.defineProperty(exports,"isPositionInRange",{enumerable:true,get:function(){return chunkG5XAABHF_js.Ba}});Object.defineProperty(exports,"isValidVariableName",{enumerable:true,get:function(){return chunkG5XAABHF_js.p}});Object.defineProperty(exports,"isWhite",{enumerable:true,get:function(){return chunkG5XAABHF_js.pa}});Object.defineProperty(exports,"isZodSchema",{enumerable:true,get:function(){return chunkG5XAABHF_js.ya}});Object.defineProperty(exports,"lightenColor",{enumerable:true,get:function(){return chunkG5XAABHF_js.va}});Object.defineProperty(exports,"parseColorString",{enumerable:true,get:function(){return chunkG5XAABHF_js.ra}});Object.defineProperty(exports,"parseDocx",{enumerable:true,get:function(){return chunkG5XAABHF_js.F}});Object.defineProperty(exports,"parseHeadingLevel",{enumerable:true,get:function(){return chunkG5XAABHF_js.ca}});Object.defineProperty(exports,"parseVariable",{enumerable:true,get:function(){return chunkG5XAABHF_js.s}});Object.defineProperty(exports,"pixelsToEmu",{enumerable:true,get:function(){return chunkG5XAABHF_js.z}});Object.defineProperty(exports,"pixelsToTwips",{enumerable:true,get:function(){return chunkG5XAABHF_js.x}});Object.defineProperty(exports,"pointsToPixels",{enumerable:true,get:function(){return chunkG5XAABHF_js.C}});Object.defineProperty(exports,"removeVariables",{enumerable:true,get:function(){return chunkG5XAABHF_js.u}});Object.defineProperty(exports,"repackDocx",{enumerable:true,get:function(){return chunkG5XAABHF_js.d}});Object.defineProperty(exports,"replaceVariables",{enumerable:true,get:function(){return chunkG5XAABHF_js.t}});Object.defineProperty(exports,"resolveColor",{enumerable:true,get:function(){return chunkG5XAABHF_js.la}});Object.defineProperty(exports,"resolveHighlightColor",{enumerable:true,get:function(){return chunkG5XAABHF_js.ma}});Object.defineProperty(exports,"resolveShadingColor",{enumerable:true,get:function(){return chunkG5XAABHF_js.na}});Object.defineProperty(exports,"sanitizeVariableName",{enumerable:true,get:function(){return chunkG5XAABHF_js.q}});Object.defineProperty(exports,"serializeDocumentBody",{enumerable:true,get:function(){return chunkG5XAABHF_js.b}});Object.defineProperty(exports,"serializeDocx",{enumerable:true,get:function(){return chunkG5XAABHF_js.c}});Object.defineProperty(exports,"serializeSectionProperties",{enumerable:true,get:function(){return chunkG5XAABHF_js.a}});Object.defineProperty(exports,"twipsToEmu",{enumerable:true,get:function(){return chunkG5XAABHF_js.B}});Object.defineProperty(exports,"twipsToPixels",{enumerable:true,get:function(){return chunkG5XAABHF_js.w}});Object.defineProperty(exports,"updateMultipleFiles",{enumerable:true,get:function(){return chunkG5XAABHF_js.e}});Object.defineProperty(exports,"validatePatchSafety",{enumerable:true,get:function(){return chunkG5XAABHF_js.g}});Object.defineProperty(exports,"PluginRegistry",{enumerable:true,get:function(){return chunk2AF2FRMM_js.a}});Object.defineProperty(exports,"createPluginRegistrar",{enumerable:true,get:function(){return chunk2AF2FRMM_js.d}});Object.defineProperty(exports,"executeCommand",{enumerable:true,get:function(){return chunk2AF2FRMM_js.e}});Object.defineProperty(exports,"executeCommands",{enumerable:true,get:function(){return chunk2AF2FRMM_js.f}});Object.defineProperty(exports,"pluginRegistry",{enumerable:true,get:function(){return chunk2AF2FRMM_js.b}});Object.defineProperty(exports,"registerPlugins",{enumerable:true,get:function(){return chunk2AF2FRMM_js.c}});Object.defineProperty(exports,"createTemplateProcessor",{enumerable:true,get:function(){return chunk4QRVKNI4_js.j}});Object.defineProperty(exports,"getMissingVariables",{enumerable:true,get:function(){return chunk4QRVKNI4_js.g}});Object.defineProperty(exports,"getTemplateTags",{enumerable:true,get:function(){return chunk4QRVKNI4_js.e}});Object.defineProperty(exports,"previewTemplate",{enumerable:true,get:function(){return chunk4QRVKNI4_js.h}});Object.defineProperty(exports,"processTemplate",{enumerable:true,get:function(){return chunk4QRVKNI4_js.a}});Object.defineProperty(exports,"processTemplateAdvanced",{enumerable:true,get:function(){return chunk4QRVKNI4_js.i}});Object.defineProperty(exports,"processTemplateAsBlob",{enumerable:true,get:function(){return chunk4QRVKNI4_js.c}});Object.defineProperty(exports,"processTemplateDetailed",{enumerable:true,get:function(){return chunk4QRVKNI4_js.b}});Object.defineProperty(exports,"validateTemplate",{enumerable:true,get:function(){return chunk4QRVKNI4_js.f}});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export{Fa as DEFAULT_AI_ACTIONS,G as DocumentAgent,Ha as VERSION,i as attemptSelectiveSave,wa as blendColors,N as buildExtendedSelectionContext,h as buildPatchedDocumentXml,M as buildSelectionContext,K as buildSelectionContextFromContext,xa as colorsEqual,Ca as comparePositions,V as countCharacters,U as countWords,H as createAgent,I as createAgentFromDocument,za as createCollapsedRange,Ga as createCommand,ka as createDocumentWithText,f as createDocx,ja as createEmptyDocument,Aa as createRange,ta as createRgbColor,sa as createThemeColor,ua as darkenColor,j as detectVariables,k as detectVariablesDetailed,l as detectVariablesInBody,m as detectVariablesInParagraph,v as documentHasVariables,y as emuToPixels,A as emuToTwips,n as extractVariablesFromText,E as formatPx,r as formatVariable,Ea as getActionDescription,Da as getActionLabel,J as getAgentContext,ia as getBlockIndexForParagraph,X as getBodyCharacterCount,T as getBodyText,W as getBodyWordCount,qa as getContrastingColor,L as getDocumentSummary,_ as getFormattingAtPosition,aa as getHyperlinkAtPosition,R as getHyperlinkText,ha as getParagraphAtIndex,P as getParagraphText,ga as getParagraphs,Q as getRunText,O as getSelectionFormattingSummary,S as getTableText,Z as getTextAfter,Y as getTextBefore,D as halfPointsToPixels,ea as hasHyperlinks,da as hasImages,fa as hasTables,o as hasTemplateVariables,oa as isBlack,ba as isHeadingStyle,$ as isPositionInHyperlink,Ba as isPositionInRange,p as isValidVariableName,pa as isWhite,ya as isZodSchema,va as lightenColor,ra as parseColorString,F as parseDocx,ca as parseHeadingLevel,s as parseVariable,z as pixelsToEmu,x as pixelsToTwips,C as pointsToPixels,u as removeVariables,d as repackDocx,t as replaceVariables,la as resolveColor,ma as resolveHighlightColor,na as resolveShadingColor,q as sanitizeVariableName,b as serializeDocumentBody,c as serializeDocx,a as serializeSectionProperties,B as twipsToEmu,w as twipsToPixels,e as updateMultipleFiles,g as validatePatchSafety}from'./chunk-
|
|
1
|
+
export{Fa as DEFAULT_AI_ACTIONS,G as DocumentAgent,Ha as VERSION,i as attemptSelectiveSave,wa as blendColors,N as buildExtendedSelectionContext,h as buildPatchedDocumentXml,M as buildSelectionContext,K as buildSelectionContextFromContext,xa as colorsEqual,Ca as comparePositions,V as countCharacters,U as countWords,H as createAgent,I as createAgentFromDocument,za as createCollapsedRange,Ga as createCommand,ka as createDocumentWithText,f as createDocx,ja as createEmptyDocument,Aa as createRange,ta as createRgbColor,sa as createThemeColor,ua as darkenColor,j as detectVariables,k as detectVariablesDetailed,l as detectVariablesInBody,m as detectVariablesInParagraph,v as documentHasVariables,y as emuToPixels,A as emuToTwips,n as extractVariablesFromText,E as formatPx,r as formatVariable,Ea as getActionDescription,Da as getActionLabel,J as getAgentContext,ia as getBlockIndexForParagraph,X as getBodyCharacterCount,T as getBodyText,W as getBodyWordCount,qa as getContrastingColor,L as getDocumentSummary,_ as getFormattingAtPosition,aa as getHyperlinkAtPosition,R as getHyperlinkText,ha as getParagraphAtIndex,P as getParagraphText,ga as getParagraphs,Q as getRunText,O as getSelectionFormattingSummary,S as getTableText,Z as getTextAfter,Y as getTextBefore,D as halfPointsToPixels,ea as hasHyperlinks,da as hasImages,fa as hasTables,o as hasTemplateVariables,oa as isBlack,ba as isHeadingStyle,$ as isPositionInHyperlink,Ba as isPositionInRange,p as isValidVariableName,pa as isWhite,ya as isZodSchema,va as lightenColor,ra as parseColorString,F as parseDocx,ca as parseHeadingLevel,s as parseVariable,z as pixelsToEmu,x as pixelsToTwips,C as pointsToPixels,u as removeVariables,d as repackDocx,t as replaceVariables,la as resolveColor,ma as resolveHighlightColor,na as resolveShadingColor,q as sanitizeVariableName,b as serializeDocumentBody,c as serializeDocx,a as serializeSectionProperties,B as twipsToEmu,w as twipsToPixels,e as updateMultipleFiles,g as validatePatchSafety}from'./chunk-W2QSJSB7.mjs';export{a as PluginRegistry,d as createPluginRegistrar,e as executeCommand,f as executeCommands,b as pluginRegistry,c as registerPlugins}from'./chunk-X57U3ESM.mjs';export{j as createTemplateProcessor,g as getMissingVariables,e as getTemplateTags,h as previewTemplate,a as processTemplate,i as processTemplateAdvanced,c as processTemplateAsBlob,b as processTemplateDetailed,f as validateTemplate}from'./chunk-UILTIEBD.mjs';
|
package/dist/index.d.mts
CHANGED
|
@@ -526,6 +526,12 @@ interface ListRendering {
|
|
|
526
526
|
markerFontFamily?: string;
|
|
527
527
|
/** Marker font size from numbering level rPr, in points */
|
|
528
528
|
markerFontSize?: number;
|
|
529
|
+
/**
|
|
530
|
+
* NumberFormat for each level from 0..ilvl (inclusive).
|
|
531
|
+
* Used to resolve multi-level templates like "%1.%2." where each %N
|
|
532
|
+
* may need a different format (e.g., upperRoman parent + decimal child).
|
|
533
|
+
*/
|
|
534
|
+
levelNumFmts?: NumberFormat[];
|
|
529
535
|
}
|
|
530
536
|
/**
|
|
531
537
|
* Complete numbering definitions
|
|
@@ -1963,6 +1969,13 @@ declare class DocxReviewer {
|
|
|
1963
1969
|
replyTo(commentId: number, text: string): number;
|
|
1964
1970
|
/** Reply to an existing comment with full options. */
|
|
1965
1971
|
replyTo(commentId: number, options: ReplyOptions): number;
|
|
1972
|
+
/**
|
|
1973
|
+
* Remove a comment by ID. Removing a top-level comment also removes its
|
|
1974
|
+
* replies and the anchored range markers. Removing a reply only removes
|
|
1975
|
+
* that reply.
|
|
1976
|
+
* @param commentId - ID of the comment to remove
|
|
1977
|
+
*/
|
|
1978
|
+
removeComment(commentId: number): void;
|
|
1966
1979
|
/**
|
|
1967
1980
|
* Replace text in a paragraph. Creates a tracked change (deletion + insertion).
|
|
1968
1981
|
* @param paragraphIndex - Index of the paragraph
|
package/dist/index.d.ts
CHANGED
|
@@ -526,6 +526,12 @@ interface ListRendering {
|
|
|
526
526
|
markerFontFamily?: string;
|
|
527
527
|
/** Marker font size from numbering level rPr, in points */
|
|
528
528
|
markerFontSize?: number;
|
|
529
|
+
/**
|
|
530
|
+
* NumberFormat for each level from 0..ilvl (inclusive).
|
|
531
|
+
* Used to resolve multi-level templates like "%1.%2." where each %N
|
|
532
|
+
* may need a different format (e.g., upperRoman parent + decimal child).
|
|
533
|
+
*/
|
|
534
|
+
levelNumFmts?: NumberFormat[];
|
|
529
535
|
}
|
|
530
536
|
/**
|
|
531
537
|
* Complete numbering definitions
|
|
@@ -1963,6 +1969,13 @@ declare class DocxReviewer {
|
|
|
1963
1969
|
replyTo(commentId: number, text: string): number;
|
|
1964
1970
|
/** Reply to an existing comment with full options. */
|
|
1965
1971
|
replyTo(commentId: number, options: ReplyOptions): number;
|
|
1972
|
+
/**
|
|
1973
|
+
* Remove a comment by ID. Removing a top-level comment also removes its
|
|
1974
|
+
* replies and the anchored range markers. Removing a reply only removes
|
|
1975
|
+
* that reply.
|
|
1976
|
+
* @param commentId - ID of the comment to remove
|
|
1977
|
+
*/
|
|
1978
|
+
removeComment(commentId: number): void;
|
|
1966
1979
|
/**
|
|
1967
1980
|
* Replace text in a paragraph. Creates a tracked change (deletion + insertion).
|
|
1968
1981
|
* @param paragraphIndex - Index of the paragraph
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
'use strict';var
|
|
2
|
-
`));}s.push(
|
|
3
|
-
`);for(let
|
|
4
|
-
`)}function L(r,e,t){let o=[],s=new Set;for(let n of r.content){if(n.type==="commentRangeStart"&&t){s.add(n.id),o.push(`[comment:${n.id}]`);continue}if(n.type==="commentRangeEnd"&&t){s.has(n.id)&&(s.delete(n.id),o.push("[/comment]"));continue}if(n.type==="run")o.push(
|
|
5
|
-
`)}function
|
|
1
|
+
'use strict';var chunkG5XAABHF_js=require('./chunk-G5XAABHF.js');function d(r){return r.type==="insertion"||r.type==="deletion"||r.type==="moveFrom"||r.type==="moveTo"}function C(r){let e=[];for(let t of r)t.type==="run"?e.push(chunkG5XAABHF_js.Q(t)):t.type==="hyperlink"&&e.push(chunkG5XAABHF_js.R(t));return e.join("")}function h(r,e){let t=0;for(let o of r.content)if(o.type==="paragraph"){if(t===e)return o;t++;}else if(o.type==="table"){for(let s of o.rows)for(let n of s.cells)for(let a of n.content)if(a.type==="paragraph"){if(t===e)return a;t++;}}else t++;throw new Error(`Paragraph index ${e} out of bounds (max: ${t-1})`)}function f(r,e){let t=0;for(let o of r.content)if(o.type==="paragraph"){if(e(o,t)===false)return;t++;}else if(o.type==="table"){for(let s of o.rows)for(let n of s.cells)for(let a of n.content)if(a.type==="paragraph"){if(e(a,t)===false)return;t++;}}else t++;}function O(r,e={}){let{fromIndex:t,toIndex:o,includeTrackedChanges:s=true,includeCommentAnchors:n=true}=e,a=[],i=0;for(let c of r.content)if(c.type==="paragraph")S(i,t,o)&&a.push(re(c,i,s,n)),i++;else if(c.type==="table"){S(i,t,o)&&a.push(se(c,i,s,n));for(let u of c.rows)for(let p of u.cells)for(let m of p.content)m.type==="paragraph"&&i++;}else i++;return a}function S(r,e,t){return (e===void 0||r>=e)&&(t===void 0||r<=t)}function re(r,e,t,o){let s=L(r,t,o),n=r.formatting?.styleId;return chunkG5XAABHF_js.ba(n)?{type:"heading",index:e,level:chunkG5XAABHF_js.ca(n)??1,text:s}:r.listRendering?{type:"list-item",index:e,text:s,listLevel:r.listRendering.level??0,listType:r.listRendering.isBullet?"bullet":"number"}:{type:"paragraph",index:e,text:s}}function se(r,e,t,o){let s=[];for(let n of r.rows){let a=[];for(let i of n.cells){let c=[];for(let u of i.content)u.type==="paragraph"&&c.push(L(u,t,o));a.push(c.join(`
|
|
2
|
+
`));}s.push(a);}return {type:"table",index:e,rows:s}}function H(r){let e=[];for(let t of r)switch(t.type){case "heading":e.push(`[${t.index}] (h${t.level}) ${t.text}`);break;case "paragraph":e.push(`[${t.index}] ${t.text}`);break;case "list-item":{let o=" ".repeat(t.listLevel),s=t.listType==="bullet"?"\u2022":"-";e.push(`[${t.index}] ${o}${s} ${t.text}`);break}case "table":{let o=t.index;for(let s=0;s<t.rows.length;s++)for(let n=0;n<t.rows[s].length;n++){let i=t.rows[s][n].split(`
|
|
3
|
+
`);for(let c of i)e.push(`[${o}] (table, row ${s+1}, col ${n+1}) ${c}`),o++;}break}}return e.join(`
|
|
4
|
+
`)}function L(r,e,t){let o=[],s=new Set;for(let n of r.content){if(n.type==="commentRangeStart"&&t){s.add(n.id),o.push(`[comment:${n.id}]`);continue}if(n.type==="commentRangeEnd"&&t){s.has(n.id)&&(s.delete(n.id),o.push("[/comment]"));continue}if(n.type==="run")o.push(chunkG5XAABHF_js.Q(n));else if(n.type==="hyperlink")o.push(chunkG5XAABHF_js.R(n));else if(d(n)){let a=C(n.content);n.type==="insertion"||n.type==="moveTo"?e?o.push(`[+${a}+]{by:${n.info.author}}`):o.push(a):e&&o.push(`[-${a}-]{by:${n.info.author}}`);}}return o.join("")}var g=class extends Error{constructor(e,t){let o=t!==void 0?` in paragraph ${t}`:" in document";super(`Text not found${o}: "${e}"`),this.name="TextNotFoundError";}},x=class extends Error{constructor(e){super(`Tracked change not found: id=${e}`),this.name="ChangeNotFoundError";}},y=class extends Error{constructor(e){super(`Comment not found: id=${e}`),this.name="CommentNotFoundError";}};function U(r){let e=[],t=0;for(let o=0;o<r.content.length;o++){let s=r.content[o];if(s.type==="run"){let n=chunkG5XAABHF_js.Q(s);e.push({contentIndex:o,run:s,text:n,startPos:t}),t+=n.length;}else if(s.type==="hyperlink")for(let n=0;n<s.children.length;n++){let a=s.children[n];if(a.type==="run"){let i=chunkG5XAABHF_js.Q(a);e.push({contentIndex:o,run:a,text:i,startPos:t}),t+=i.length;}}else if(d(s))for(let n=0;n<s.content.length;n++){let a=s.content[n];if(a.type==="run"){let i=chunkG5XAABHF_js.Q(a);e.push({contentIndex:o,run:a,text:i,startPos:t}),t+=i.length;}else if(a.type==="hyperlink"){for(let i of a.children)if(i.type==="run"){let c=chunkG5XAABHF_js.Q(i);e.push({contentIndex:o,run:i,text:c,startPos:t}),t+=c.length;}}}}return e}function E(r){return U(r).map(e=>e.text).join("")}function F(r,e,t){let o=U(r),s=o.map(p=>p.text).join(""),n=ae(s,e);if(!n)throw new g(e,t);let a=-1,i=0;for(let p=0;p<o.length;p++)if(n.start<o[p].startPos+o[p].text.length){a=p,i=n.start-o[p].startPos;break}let c=-1,u=0;for(let p=o.length-1;p>=0;p--)if(n.end>o[p].startPos){c=p,u=n.end-o[p].startPos;break}if(a===-1||c===-1)throw new g(e,t);return {startRunIndex:o[a].contentIndex,startOffset:i,endRunIndex:o[c].contentIndex,endOffset:u}}function I(r,e,t){let o=F(r,e,t),{startRunIndex:s,endRunIndex:n}=o,{startOffset:a,endOffset:i}=o,c=r.content[n];if(c.type==="run"){let p=chunkG5XAABHF_js.Q(c);if(i<p.length){let m=G(p.slice(i),c);N(c,p.slice(0,i)),r.content.splice(n+1,0,m);}}let u=r.content[s];if(u.type==="run"&&a>0){let p=chunkG5XAABHF_js.Q(u),m=G(p.slice(0,a),u);N(u,p.slice(a)),r.content.splice(s,0,m),s++,n++;}return {startIndex:s,endIndex:n}}function G(r,e){return {type:"run",content:[{type:"text",text:r}],formatting:e.formatting?{...e.formatting}:void 0}}function N(r,e){let t=r.content.find(o=>o.type==="text");t&&(t.text=e);}function W(r){let e=[],t=[],o=true;for(let s=0;s<r.length;s++){let n=r[s];if(!"\u200B\u200C\u200D\uFEFF\xAD".includes(n)){if("\u201C\u201D\u201E\u201F".includes(n)&&(n='"'),"\u2018\u2019\u201A\u201B".includes(n)&&(n="'"),"\u2013\u2014\u2012\u2015".includes(n)&&(n="-"),n==="\u2026"){e.push(".",".","."),t.push(s,s,s),o=false;continue}if(/\s/.test(n)||n==="\xA0"){o||(e.push(" "),t.push(s),o=true);continue}e.push(n.toLowerCase()),t.push(s),o=false;}}return e.length>0&&e[e.length-1]===" "&&(e.pop(),t.pop()),{text:e.join(""),posMap:t}}function z(r,e,t,o){let s=r.posMap[e],n=r.posMap[e+t-1]+1;for(;n<o.length&&"\u200B\u200C\u200D\uFEFF\xAD".includes(o[n]);)n++;return {start:s,end:n}}function ae(r,e){if(!e||!r)return null;let t=r.indexOf(e);if(t!==-1)return {start:t,end:t+e.length};let o=W(r),s=W(e);if(!s.text)return null;let n=o.text.indexOf(s.text);if(n!==-1)return z(o,n,s.text.length,r);let a=s.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(" "),u=o.text.indexOf(c);if(u!==-1)return z(o,u,c.length,r)}return null}function q(r,e){let t=new Map;return f(r,(s,n)=>{let a=null;for(let i of s.content)if(d(i)){a===null&&(a=E(s));let c=C(i.content),u=i.info.id,p=t.get(u);p&&p.paragraphIndex===n?p.text+=c:t.set(u,{id:u,type:i.type,author:i.info.author,date:i.info.date??null,text:c,context:a,paragraphIndex:n});}}),Array.from(t.values()).filter(s=>!(e?.author&&s.author!==e.author||e?.type&&s.type!==e.type))}function J(r,e){let t=r.comments??[];if(t.length===0)return [];let o=ie(r),s=[],n=new Map;for(let i of t)if(i.parentId!==void 0){let c=n.get(i.parentId)??[];c.push(i),n.set(i.parentId,c);}else s.push(i);return s.map(i=>{let c=o.get(i.id),u=(n.get(i.id)??[]).map(p=>({id:p.id,author:p.author,date:p.date??null,text:X(p)}));return {id:i.id,author:i.author,date:i.date??null,text:X(i),anchoredText:c?.text??"",paragraphIndex:c?.paragraphIndex??-1,replies:u,done:i.done??false}}).filter(i=>!(e?.author&&i.author!==e.author||e?.done!==void 0&&i.done!==e.done))}function X(r){return r.content.map(e=>E(e)).join(`
|
|
5
|
+
`)}function ie(r){let e=new Map,t=new Map;return f(r,(o,s)=>{for(let n of o.content)if(n.type==="commentRangeStart")t.set(n.id,{paragraphIndex:s,parts:[]});else if(n.type==="commentRangeEnd"){let a=t.get(n.id);a&&(e.set(n.id,{text:a.parts.join(""),paragraphIndex:a.paragraphIndex}),t.delete(n.id));}else if(n.type==="run"){let a=chunkG5XAABHF_js.Q(n);for(let i of t.values())i.parts.push(a);}else if(n.type==="hyperlink"){let a=n.children.filter(i=>i.type==="run").map(chunkG5XAABHF_js.Q).join("");for(let i of t.values())i.parts.push(a);}else if(d(n)){let a=C(n.content);for(let i of t.values())i.parts.push(a);}}),e}function R(r,e){let{paragraphIndex:t,author:o="AI",text:s,search:n}=e,a=h(r,t),i=(r.comments??[]).map(p=>p.id),c=i.length>0?Math.max(...i)+1:1,u={id:c,author:o,date:new Date().toISOString(),content:[{type:"paragraph",content:[{type:"run",content:[{type:"text",text:s}]}],formatting:{}}]};if(r.comments||(r.comments=[]),r.comments.push(u),n){let p=F(a,n,t);a.content.splice(p.endRunIndex+1,0,{type:"commentRangeEnd",id:c}),a.content.splice(p.startRunIndex,0,{type:"commentRangeStart",id:c});}else a.content.unshift({type:"commentRangeStart",id:c}),a.content.push({type:"commentRangeEnd",id:c});return c}function v(r,e,t){let o=r.comments??[];if(!o.find(c=>c.id===e))throw new y(e);let n=o.map(c=>c.id),a=Math.max(...n)+1,i={id:a,author:t.author??"AI",date:new Date().toISOString(),parentId:e,content:[{type:"paragraph",content:[{type:"run",content:[{type:"text",text:t.text}]}],formatting:{}}]};return o.push(i),a}function K(r,e){let t=r.comments??[],o=t.find(a=>a.id===e);if(!o)throw new y(e);let s=o.parentId!==void 0,n=new Set([e]);if(!s)for(let a of t)a.parentId===e&&n.add(a.id);r.comments=t.filter(a=>!n.has(a.id)),!s&&f(r,a=>{for(let i=a.content.length-1;i>=0;i--){let c=a.content[i];(c.type==="commentRangeStart"||c.type==="commentRangeEnd")&&c.id===e&&a.content.splice(i,1);}});}function w(r,e){if(!_(r,e,"accept"))throw new x(e)}function B(r,e){if(!_(r,e,"reject"))throw new x(e)}function V(r){return Z(r,"accept")}function Y(r){return Z(r,"reject")}function Z(r,e){let t=0;return f(r,o=>{for(let s=o.content.length-1;s>=0;s--){let n=o.content[s];d(n)&&(ee(o,s,n,e),t++);}}),t}function _(r,e,t){let o=false;return f(r,s=>{for(let n=s.content.length-1;n>=0;n--){let a=s.content[n];d(a)&&a.info.id===e&&(ee(s,n,a,t),o=true);}if(o)return false}),o}function ee(r,e,t,o){if(t.type==="insertion"&&o==="accept"||t.type==="deletion"&&o==="reject"||t.type==="moveTo"&&o==="accept"||t.type==="moveFrom"&&o==="reject"){let n=t.content;r.content.splice(e,1,...n);}else r.content.splice(e,1);}function T(r,e){let{paragraphIndex:t,search:o,author:s="AI",replaceWith:n}=e,a=h(r,t),{startIndex:i,endIndex:c}=I(a,o,t),u=new Date().toISOString(),p=j(r),m=a.content.slice(i,c+1),D={type:"deletion",info:{id:p,author:s,date:u},content:m},P={type:"insertion",info:{id:p+1,author:s,date:u},content:[{type:"run",content:[{type:"text",text:n}]}]};a.content.splice(i,c-i+1,D,P);}function te(r,e){let{paragraphIndex:t,author:o="AI",insertText:s,position:n="after",search:a}=e,i=h(r,t),c=new Date().toISOString(),p={type:"insertion",info:{id:j(r),author:o,date:c},content:[{type:"run",content:[{type:"text",text:s}]}]};if(a){let{startIndex:m,endIndex:D}=I(i,a,t),P=n==="after"?D+1:m;i.content.splice(P,0,p);}else n==="before"?i.content.unshift(p):i.content.push(p);}function ne(r,e){let{paragraphIndex:t,search:o,author:s="AI"}=e,n=h(r,t),{startIndex:a,endIndex:i}=I(n,o,t),c=new Date().toISOString(),u=j(r),p=n.content.slice(a,i+1),m={type:"deletion",info:{id:u,author:s,date:c},content:p};n.content.splice(a,i-a+1,m);}var Q=new WeakMap;function j(r){let e=Q.get(r);e===void 0&&(e=0,f(r,o=>{for(let s of o.content)d(s)&&(e=Math.max(e,s.info.id));}));let t=e+1;return Q.set(r,t+1),t}function oe(r,e,t="AI"){let o=[],s=0,n=0,a=0,i=0,c=0;for(let u of e.accept??[])try{w(r,u),s++;}catch(p){o.push({operation:"accept",id:u,error:p.message});}for(let u of e.reject??[])try{B(r,u),n++;}catch(p){o.push({operation:"reject",id:u,error:p.message});}for(let u of e.comments??[])try{R(r,{...u,author:u.author??t}),a++;}catch(p){o.push({operation:"comment",search:u.search,error:p.message});}for(let u of e.replies??[])try{v(r,u.commentId,{author:u.author??t,text:u.text}),i++;}catch(p){o.push({operation:"reply",id:u.commentId,error:p.message});}for(let u of e.proposals??[])try{T(r,{...u,author:u.author??t}),c++;}catch(p){o.push({operation:"proposal",search:u.search,error:p.message});}return {accepted:s,rejected:n,commentsAdded:a,repliesAdded:i,proposalsAdded:c,errors:o}}var M=class r{constructor(e,t="AI",o){let s=o??e.originalBuffer,{originalBuffer:n,...a}=e;this.doc=structuredClone(a),s&&(this.doc.originalBuffer=s),this.author=t;}static async fromBuffer(e,t="AI"){let o=await chunkG5XAABHF_js.F(e,{preloadFonts:false});return new r(o,t,e)}get body(){return this.doc.package.document}resolveAuthor(e){return e??this.author}getContent(e){return O(this.body,e)}getContentAsText(e){return H(O(this.body,e))}getChanges(e){return q(this.body,e)}getComments(e){return J(this.body,e)}addComment(e,t){let o=typeof e=="number"?{paragraphIndex:e,text:t,author:this.author}:{...e,author:this.resolveAuthor(e.author)};return R(this.body,o)}replyTo(e,t){let o=typeof t=="string"?{text:t,author:this.author}:{...t,author:this.resolveAuthor(t.author)};return v(this.body,e,o)}removeComment(e){K(this.body,e);}replace(e,t,o){let s=typeof e=="number"?{paragraphIndex:e,search:t,replaceWith:o,author:this.author}:{...e,author:this.resolveAuthor(e.author)};T(this.body,s);}proposeReplacement(e){this.replace(e);}proposeInsertion(e){te(this.body,{...e,author:this.resolveAuthor(e.author)});}proposeDeletion(e){ne(this.body,{...e,author:this.resolveAuthor(e.author)});}acceptChange(e){w(this.body,e);}rejectChange(e){B(this.body,e);}acceptAll(){return V(this.body)}rejectAll(){return Y(this.body)}applyReview(e){return oe(this.body,e,this.author)}toDocument(){return this.doc}async toBuffer(){if(!this.doc.originalBuffer)throw new Error("Cannot create buffer: no original DOCX buffer was provided. Use DocxReviewer.fromBuffer() or pass originalBuffer to the constructor.");let{repackDocx:e}=await import('./headless-DGAHMYIU.js');return e(this.doc)}};exports.ChangeNotFoundError=x;exports.CommentNotFoundError=y;exports.DocxReviewer=M;exports.TextNotFoundError=g;
|
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {F as F$1,ba,ca,Q as Q$1,R as R$1}from'./chunk-
|
|
2
|
-
`));}s.push(
|
|
3
|
-
`);for(let
|
|
4
|
-
`)}function L(r,e,t){let o=[],s=new Set;for(let n of r.content){if(n.type==="commentRangeStart"&&t){s.add(n.id),o.push(`[comment:${n.id}]`);continue}if(n.type==="commentRangeEnd"&&t){s.has(n.id)&&(s.delete(n.id),o.push("[/comment]"));continue}if(n.type==="run")o.push(Q$1(n));else if(n.type==="hyperlink")o.push(R$1(n));else if(d(n)){let
|
|
5
|
-
`)}function
|
|
1
|
+
import {F as F$1,ba,ca,Q as Q$1,R as R$1}from'./chunk-W2QSJSB7.mjs';function d(r){return r.type==="insertion"||r.type==="deletion"||r.type==="moveFrom"||r.type==="moveTo"}function C(r){let e=[];for(let t of r)t.type==="run"?e.push(Q$1(t)):t.type==="hyperlink"&&e.push(R$1(t));return e.join("")}function h(r,e){let t=0;for(let o of r.content)if(o.type==="paragraph"){if(t===e)return o;t++;}else if(o.type==="table"){for(let s of o.rows)for(let n of s.cells)for(let a of n.content)if(a.type==="paragraph"){if(t===e)return a;t++;}}else t++;throw new Error(`Paragraph index ${e} out of bounds (max: ${t-1})`)}function f(r,e){let t=0;for(let o of r.content)if(o.type==="paragraph"){if(e(o,t)===false)return;t++;}else if(o.type==="table"){for(let s of o.rows)for(let n of s.cells)for(let a of n.content)if(a.type==="paragraph"){if(e(a,t)===false)return;t++;}}else t++;}function O(r,e={}){let{fromIndex:t,toIndex:o,includeTrackedChanges:s=true,includeCommentAnchors:n=true}=e,a=[],i=0;for(let c of r.content)if(c.type==="paragraph")S(i,t,o)&&a.push(re(c,i,s,n)),i++;else if(c.type==="table"){S(i,t,o)&&a.push(se(c,i,s,n));for(let u of c.rows)for(let p of u.cells)for(let m of p.content)m.type==="paragraph"&&i++;}else i++;return a}function S(r,e,t){return (e===void 0||r>=e)&&(t===void 0||r<=t)}function re(r,e,t,o){let s=L(r,t,o),n=r.formatting?.styleId;return ba(n)?{type:"heading",index:e,level:ca(n)??1,text:s}:r.listRendering?{type:"list-item",index:e,text:s,listLevel:r.listRendering.level??0,listType:r.listRendering.isBullet?"bullet":"number"}:{type:"paragraph",index:e,text:s}}function se(r,e,t,o){let s=[];for(let n of r.rows){let a=[];for(let i of n.cells){let c=[];for(let u of i.content)u.type==="paragraph"&&c.push(L(u,t,o));a.push(c.join(`
|
|
2
|
+
`));}s.push(a);}return {type:"table",index:e,rows:s}}function H(r){let e=[];for(let t of r)switch(t.type){case "heading":e.push(`[${t.index}] (h${t.level}) ${t.text}`);break;case "paragraph":e.push(`[${t.index}] ${t.text}`);break;case "list-item":{let o=" ".repeat(t.listLevel),s=t.listType==="bullet"?"\u2022":"-";e.push(`[${t.index}] ${o}${s} ${t.text}`);break}case "table":{let o=t.index;for(let s=0;s<t.rows.length;s++)for(let n=0;n<t.rows[s].length;n++){let i=t.rows[s][n].split(`
|
|
3
|
+
`);for(let c of i)e.push(`[${o}] (table, row ${s+1}, col ${n+1}) ${c}`),o++;}break}}return e.join(`
|
|
4
|
+
`)}function L(r,e,t){let o=[],s=new Set;for(let n of r.content){if(n.type==="commentRangeStart"&&t){s.add(n.id),o.push(`[comment:${n.id}]`);continue}if(n.type==="commentRangeEnd"&&t){s.has(n.id)&&(s.delete(n.id),o.push("[/comment]"));continue}if(n.type==="run")o.push(Q$1(n));else if(n.type==="hyperlink")o.push(R$1(n));else if(d(n)){let a=C(n.content);n.type==="insertion"||n.type==="moveTo"?e?o.push(`[+${a}+]{by:${n.info.author}}`):o.push(a):e&&o.push(`[-${a}-]{by:${n.info.author}}`);}}return o.join("")}var g=class extends Error{constructor(e,t){let o=t!==void 0?` in paragraph ${t}`:" in document";super(`Text not found${o}: "${e}"`),this.name="TextNotFoundError";}},x=class extends Error{constructor(e){super(`Tracked change not found: id=${e}`),this.name="ChangeNotFoundError";}},y=class extends Error{constructor(e){super(`Comment not found: id=${e}`),this.name="CommentNotFoundError";}};function U(r){let e=[],t=0;for(let o=0;o<r.content.length;o++){let s=r.content[o];if(s.type==="run"){let n=Q$1(s);e.push({contentIndex:o,run:s,text:n,startPos:t}),t+=n.length;}else if(s.type==="hyperlink")for(let n=0;n<s.children.length;n++){let a=s.children[n];if(a.type==="run"){let i=Q$1(a);e.push({contentIndex:o,run:a,text:i,startPos:t}),t+=i.length;}}else if(d(s))for(let n=0;n<s.content.length;n++){let a=s.content[n];if(a.type==="run"){let i=Q$1(a);e.push({contentIndex:o,run:a,text:i,startPos:t}),t+=i.length;}else if(a.type==="hyperlink"){for(let i of a.children)if(i.type==="run"){let c=Q$1(i);e.push({contentIndex:o,run:i,text:c,startPos:t}),t+=c.length;}}}}return e}function E(r){return U(r).map(e=>e.text).join("")}function F(r,e,t){let o=U(r),s=o.map(p=>p.text).join(""),n=ae(s,e);if(!n)throw new g(e,t);let a=-1,i=0;for(let p=0;p<o.length;p++)if(n.start<o[p].startPos+o[p].text.length){a=p,i=n.start-o[p].startPos;break}let c=-1,u=0;for(let p=o.length-1;p>=0;p--)if(n.end>o[p].startPos){c=p,u=n.end-o[p].startPos;break}if(a===-1||c===-1)throw new g(e,t);return {startRunIndex:o[a].contentIndex,startOffset:i,endRunIndex:o[c].contentIndex,endOffset:u}}function I(r,e,t){let o=F(r,e,t),{startRunIndex:s,endRunIndex:n}=o,{startOffset:a,endOffset:i}=o,c=r.content[n];if(c.type==="run"){let p=Q$1(c);if(i<p.length){let m=G(p.slice(i),c);N(c,p.slice(0,i)),r.content.splice(n+1,0,m);}}let u=r.content[s];if(u.type==="run"&&a>0){let p=Q$1(u),m=G(p.slice(0,a),u);N(u,p.slice(a)),r.content.splice(s,0,m),s++,n++;}return {startIndex:s,endIndex:n}}function G(r,e){return {type:"run",content:[{type:"text",text:r}],formatting:e.formatting?{...e.formatting}:void 0}}function N(r,e){let t=r.content.find(o=>o.type==="text");t&&(t.text=e);}function W(r){let e=[],t=[],o=true;for(let s=0;s<r.length;s++){let n=r[s];if(!"\u200B\u200C\u200D\uFEFF\xAD".includes(n)){if("\u201C\u201D\u201E\u201F".includes(n)&&(n='"'),"\u2018\u2019\u201A\u201B".includes(n)&&(n="'"),"\u2013\u2014\u2012\u2015".includes(n)&&(n="-"),n==="\u2026"){e.push(".",".","."),t.push(s,s,s),o=false;continue}if(/\s/.test(n)||n==="\xA0"){o||(e.push(" "),t.push(s),o=true);continue}e.push(n.toLowerCase()),t.push(s),o=false;}}return e.length>0&&e[e.length-1]===" "&&(e.pop(),t.pop()),{text:e.join(""),posMap:t}}function z(r,e,t,o){let s=r.posMap[e],n=r.posMap[e+t-1]+1;for(;n<o.length&&"\u200B\u200C\u200D\uFEFF\xAD".includes(o[n]);)n++;return {start:s,end:n}}function ae(r,e){if(!e||!r)return null;let t=r.indexOf(e);if(t!==-1)return {start:t,end:t+e.length};let o=W(r),s=W(e);if(!s.text)return null;let n=o.text.indexOf(s.text);if(n!==-1)return z(o,n,s.text.length,r);let a=s.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(" "),u=o.text.indexOf(c);if(u!==-1)return z(o,u,c.length,r)}return null}function q(r,e){let t=new Map;return f(r,(s,n)=>{let a=null;for(let i of s.content)if(d(i)){a===null&&(a=E(s));let c=C(i.content),u=i.info.id,p=t.get(u);p&&p.paragraphIndex===n?p.text+=c:t.set(u,{id:u,type:i.type,author:i.info.author,date:i.info.date??null,text:c,context:a,paragraphIndex:n});}}),Array.from(t.values()).filter(s=>!(e?.author&&s.author!==e.author||e?.type&&s.type!==e.type))}function J(r,e){let t=r.comments??[];if(t.length===0)return [];let o=ie(r),s=[],n=new Map;for(let i of t)if(i.parentId!==void 0){let c=n.get(i.parentId)??[];c.push(i),n.set(i.parentId,c);}else s.push(i);return s.map(i=>{let c=o.get(i.id),u=(n.get(i.id)??[]).map(p=>({id:p.id,author:p.author,date:p.date??null,text:X(p)}));return {id:i.id,author:i.author,date:i.date??null,text:X(i),anchoredText:c?.text??"",paragraphIndex:c?.paragraphIndex??-1,replies:u,done:i.done??false}}).filter(i=>!(e?.author&&i.author!==e.author||e?.done!==void 0&&i.done!==e.done))}function X(r){return r.content.map(e=>E(e)).join(`
|
|
5
|
+
`)}function ie(r){let e=new Map,t=new Map;return f(r,(o,s)=>{for(let n of o.content)if(n.type==="commentRangeStart")t.set(n.id,{paragraphIndex:s,parts:[]});else if(n.type==="commentRangeEnd"){let a=t.get(n.id);a&&(e.set(n.id,{text:a.parts.join(""),paragraphIndex:a.paragraphIndex}),t.delete(n.id));}else if(n.type==="run"){let a=Q$1(n);for(let i of t.values())i.parts.push(a);}else if(n.type==="hyperlink"){let a=n.children.filter(i=>i.type==="run").map(Q$1).join("");for(let i of t.values())i.parts.push(a);}else if(d(n)){let a=C(n.content);for(let i of t.values())i.parts.push(a);}}),e}function R(r,e){let{paragraphIndex:t,author:o="AI",text:s,search:n}=e,a=h(r,t),i=(r.comments??[]).map(p=>p.id),c=i.length>0?Math.max(...i)+1:1,u={id:c,author:o,date:new Date().toISOString(),content:[{type:"paragraph",content:[{type:"run",content:[{type:"text",text:s}]}],formatting:{}}]};if(r.comments||(r.comments=[]),r.comments.push(u),n){let p=F(a,n,t);a.content.splice(p.endRunIndex+1,0,{type:"commentRangeEnd",id:c}),a.content.splice(p.startRunIndex,0,{type:"commentRangeStart",id:c});}else a.content.unshift({type:"commentRangeStart",id:c}),a.content.push({type:"commentRangeEnd",id:c});return c}function v(r,e,t){let o=r.comments??[];if(!o.find(c=>c.id===e))throw new y(e);let n=o.map(c=>c.id),a=Math.max(...n)+1,i={id:a,author:t.author??"AI",date:new Date().toISOString(),parentId:e,content:[{type:"paragraph",content:[{type:"run",content:[{type:"text",text:t.text}]}],formatting:{}}]};return o.push(i),a}function K(r,e){let t=r.comments??[],o=t.find(a=>a.id===e);if(!o)throw new y(e);let s=o.parentId!==void 0,n=new Set([e]);if(!s)for(let a of t)a.parentId===e&&n.add(a.id);r.comments=t.filter(a=>!n.has(a.id)),!s&&f(r,a=>{for(let i=a.content.length-1;i>=0;i--){let c=a.content[i];(c.type==="commentRangeStart"||c.type==="commentRangeEnd")&&c.id===e&&a.content.splice(i,1);}});}function w(r,e){if(!_(r,e,"accept"))throw new x(e)}function B(r,e){if(!_(r,e,"reject"))throw new x(e)}function V(r){return Z(r,"accept")}function Y(r){return Z(r,"reject")}function Z(r,e){let t=0;return f(r,o=>{for(let s=o.content.length-1;s>=0;s--){let n=o.content[s];d(n)&&(ee(o,s,n,e),t++);}}),t}function _(r,e,t){let o=false;return f(r,s=>{for(let n=s.content.length-1;n>=0;n--){let a=s.content[n];d(a)&&a.info.id===e&&(ee(s,n,a,t),o=true);}if(o)return false}),o}function ee(r,e,t,o){if(t.type==="insertion"&&o==="accept"||t.type==="deletion"&&o==="reject"||t.type==="moveTo"&&o==="accept"||t.type==="moveFrom"&&o==="reject"){let n=t.content;r.content.splice(e,1,...n);}else r.content.splice(e,1);}function T(r,e){let{paragraphIndex:t,search:o,author:s="AI",replaceWith:n}=e,a=h(r,t),{startIndex:i,endIndex:c}=I(a,o,t),u=new Date().toISOString(),p=j(r),m=a.content.slice(i,c+1),D={type:"deletion",info:{id:p,author:s,date:u},content:m},P={type:"insertion",info:{id:p+1,author:s,date:u},content:[{type:"run",content:[{type:"text",text:n}]}]};a.content.splice(i,c-i+1,D,P);}function te(r,e){let{paragraphIndex:t,author:o="AI",insertText:s,position:n="after",search:a}=e,i=h(r,t),c=new Date().toISOString(),p={type:"insertion",info:{id:j(r),author:o,date:c},content:[{type:"run",content:[{type:"text",text:s}]}]};if(a){let{startIndex:m,endIndex:D}=I(i,a,t),P=n==="after"?D+1:m;i.content.splice(P,0,p);}else n==="before"?i.content.unshift(p):i.content.push(p);}function ne(r,e){let{paragraphIndex:t,search:o,author:s="AI"}=e,n=h(r,t),{startIndex:a,endIndex:i}=I(n,o,t),c=new Date().toISOString(),u=j(r),p=n.content.slice(a,i+1),m={type:"deletion",info:{id:u,author:s,date:c},content:p};n.content.splice(a,i-a+1,m);}var Q=new WeakMap;function j(r){let e=Q.get(r);e===void 0&&(e=0,f(r,o=>{for(let s of o.content)d(s)&&(e=Math.max(e,s.info.id));}));let t=e+1;return Q.set(r,t+1),t}function oe(r,e,t="AI"){let o=[],s=0,n=0,a=0,i=0,c=0;for(let u of e.accept??[])try{w(r,u),s++;}catch(p){o.push({operation:"accept",id:u,error:p.message});}for(let u of e.reject??[])try{B(r,u),n++;}catch(p){o.push({operation:"reject",id:u,error:p.message});}for(let u of e.comments??[])try{R(r,{...u,author:u.author??t}),a++;}catch(p){o.push({operation:"comment",search:u.search,error:p.message});}for(let u of e.replies??[])try{v(r,u.commentId,{author:u.author??t,text:u.text}),i++;}catch(p){o.push({operation:"reply",id:u.commentId,error:p.message});}for(let u of e.proposals??[])try{T(r,{...u,author:u.author??t}),c++;}catch(p){o.push({operation:"proposal",search:u.search,error:p.message});}return {accepted:s,rejected:n,commentsAdded:a,repliesAdded:i,proposalsAdded:c,errors:o}}var M=class r{constructor(e,t="AI",o){let s=o??e.originalBuffer,{originalBuffer:n,...a}=e;this.doc=structuredClone(a),s&&(this.doc.originalBuffer=s),this.author=t;}static async fromBuffer(e,t="AI"){let o=await F$1(e,{preloadFonts:false});return new r(o,t,e)}get body(){return this.doc.package.document}resolveAuthor(e){return e??this.author}getContent(e){return O(this.body,e)}getContentAsText(e){return H(O(this.body,e))}getChanges(e){return q(this.body,e)}getComments(e){return J(this.body,e)}addComment(e,t){let o=typeof e=="number"?{paragraphIndex:e,text:t,author:this.author}:{...e,author:this.resolveAuthor(e.author)};return R(this.body,o)}replyTo(e,t){let o=typeof t=="string"?{text:t,author:this.author}:{...t,author:this.resolveAuthor(t.author)};return v(this.body,e,o)}removeComment(e){K(this.body,e);}replace(e,t,o){let s=typeof e=="number"?{paragraphIndex:e,search:t,replaceWith:o,author:this.author}:{...e,author:this.resolveAuthor(e.author)};T(this.body,s);}proposeReplacement(e){this.replace(e);}proposeInsertion(e){te(this.body,{...e,author:this.resolveAuthor(e.author)});}proposeDeletion(e){ne(this.body,{...e,author:this.resolveAuthor(e.author)});}acceptChange(e){w(this.body,e);}rejectChange(e){B(this.body,e);}acceptAll(){return V(this.body)}rejectAll(){return Y(this.body)}applyReview(e){return oe(this.body,e,this.author)}toDocument(){return this.doc}async toBuffer(){if(!this.doc.originalBuffer)throw new Error("Cannot create buffer: no original DOCX buffer was provided. Use DocxReviewer.fromBuffer() or pass originalBuffer to the constructor.");let{repackDocx:e}=await import('./headless-I5CZ42MD.mjs');return e(this.doc)}};export{x as ChangeNotFoundError,y as CommentNotFoundError,M as DocxReviewer,g as TextNotFoundError};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@eigenpal/docx-editor-agents",
|
|
3
|
-
"version": "0.0
|
|
3
|
+
"version": "0.1.0",
|
|
4
4
|
"description": "Agent-friendly API for DOCX document review — read, comment, propose changes, accept/reject tracked changes",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.mjs",
|
|
@@ -52,7 +52,7 @@
|
|
|
52
52
|
"license": "AGPL-3.0-or-later",
|
|
53
53
|
"repository": {
|
|
54
54
|
"type": "git",
|
|
55
|
-
"url": "https://github.com/eigenpal/docx-
|
|
55
|
+
"url": "https://github.com/eigenpal/docx-editor.git",
|
|
56
56
|
"directory": "packages/agent-use"
|
|
57
57
|
},
|
|
58
58
|
"publishConfig": {
|