@eigenpal/docx-editor-agents 0.0.35 → 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.
@@ -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-QU2KZVKE.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';
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 chunkT3PAPI4X_js=require('./chunk-T3PAPI4X.js');function d(r){return r.type==="insertion"||r.type==="deletion"||r.type==="moveFrom"||r.type==="moveTo"}function y(r){let e=[];for(let t of r)t.type==="run"?e.push(chunkT3PAPI4X_js.Q(t)):t.type==="hyperlink"&&e.push(chunkT3PAPI4X_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 i of n.content)if(i.type==="paragraph"){if(t===e)return i;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 i of n.content)if(i.type==="paragraph"){if(e(i,t)===false)return;t++;}}else t++;}function O(r,e={}){let{fromIndex:t,toIndex:o,includeTrackedChanges:s=true,includeCommentAnchors:n=true}=e,i=[],a=0;for(let p of r.content)if(p.type==="paragraph")S(a,t,o)&&i.push(oe(p,a,s,n)),a++;else if(p.type==="table"){S(a,t,o)&&i.push(re(p,a,s,n));for(let u of p.rows)for(let c of u.cells)for(let m of c.content)m.type==="paragraph"&&a++;}else a++;return i}function S(r,e,t){return (e===void 0||r>=e)&&(t===void 0||r<=t)}function oe(r,e,t,o){let s=L(r,t,o),n=r.formatting?.styleId;return chunkT3PAPI4X_js.ba(n)?{type:"heading",index:e,level:chunkT3PAPI4X_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 re(r,e,t,o){let s=[];for(let n of r.rows){let i=[];for(let a of n.cells){let p=[];for(let u of a.content)u.type==="paragraph"&&p.push(L(u,t,o));i.push(p.join(`
2
- `));}s.push(i);}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 a=t.rows[s][n].split(`
3
- `);for(let p of a)e.push(`[${o}] (table, row ${s+1}, col ${n+1}) ${p}`),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(chunkT3PAPI4X_js.Q(n));else if(n.type==="hyperlink")o.push(chunkT3PAPI4X_js.R(n));else if(d(n)){let i=y(n.content);n.type==="insertion"||n.type==="moveTo"?e?o.push(`[+${i}+]{by:${n.info.author}}`):o.push(i):e&&o.push(`[-${i}-]{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";}},C=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=chunkT3PAPI4X_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 i=s.children[n];if(i.type==="run"){let a=chunkT3PAPI4X_js.Q(i);e.push({contentIndex:o,run:i,text:a,startPos:t}),t+=a.length;}}else if(d(s))for(let n=0;n<s.content.length;n++){let i=s.content[n];if(i.type==="run"){let a=chunkT3PAPI4X_js.Q(i);e.push({contentIndex:o,run:i,text:a,startPos:t}),t+=a.length;}else if(i.type==="hyperlink"){for(let a of i.children)if(a.type==="run"){let p=chunkT3PAPI4X_js.Q(a);e.push({contentIndex:o,run:a,text:p,startPos:t}),t+=p.length;}}}}return e}function F(r){return U(r).map(e=>e.text).join("")}function j(r,e,t){let o=U(r),s=o.map(c=>c.text).join(""),n=se(s,e);if(!n)throw new g(e,t);let i=-1,a=0;for(let c=0;c<o.length;c++)if(n.start<o[c].startPos+o[c].text.length){i=c,a=n.start-o[c].startPos;break}let p=-1,u=0;for(let c=o.length-1;c>=0;c--)if(n.end>o[c].startPos){p=c,u=n.end-o[c].startPos;break}if(i===-1||p===-1)throw new g(e,t);return {startRunIndex:o[i].contentIndex,startOffset:a,endRunIndex:o[p].contentIndex,endOffset:u}}function I(r,e,t){let o=j(r,e,t),{startRunIndex:s,endRunIndex:n}=o,{startOffset:i,endOffset:a}=o,p=r.content[n];if(p.type==="run"){let c=chunkT3PAPI4X_js.Q(p);if(a<c.length){let m=G(c.slice(a),p);N(p,c.slice(0,a)),r.content.splice(n+1,0,m);}}let u=r.content[s];if(u.type==="run"&&i>0){let c=chunkT3PAPI4X_js.Q(u),m=G(c.slice(0,i),u);N(u,c.slice(i)),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 se(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 i=s.text.split(" ");if(i.length>=3)for(let a=1;a<=Math.min(2,i.length-2);a++){let p=i.slice(0,-a).join(" "),u=o.text.indexOf(p);if(u!==-1)return z(o,u,p.length,r)}return null}function q(r,e){let t=new Map;return f(r,(s,n)=>{let i=null;for(let a of s.content)if(d(a)){i===null&&(i=F(s));let p=y(a.content),u=a.info.id,c=t.get(u);c&&c.paragraphIndex===n?c.text+=p:t.set(u,{id:u,type:a.type,author:a.info.author,date:a.info.date??null,text:p,context:i,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=ae(r),s=[],n=new Map;for(let a of t)if(a.parentId!==void 0){let p=n.get(a.parentId)??[];p.push(a),n.set(a.parentId,p);}else s.push(a);return s.map(a=>{let p=o.get(a.id),u=(n.get(a.id)??[]).map(c=>({id:c.id,author:c.author,date:c.date??null,text:X(c)}));return {id:a.id,author:a.author,date:a.date??null,text:X(a),anchoredText:p?.text??"",paragraphIndex:p?.paragraphIndex??-1,replies:u,done:a.done??false}}).filter(a=>!(e?.author&&a.author!==e.author||e?.done!==void 0&&a.done!==e.done))}function X(r){return r.content.map(e=>F(e)).join(`
5
- `)}function ae(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 i=t.get(n.id);i&&(e.set(n.id,{text:i.parts.join(""),paragraphIndex:i.paragraphIndex}),t.delete(n.id));}else if(n.type==="run"){let i=chunkT3PAPI4X_js.Q(n);for(let a of t.values())a.parts.push(i);}else if(n.type==="hyperlink"){let i=n.children.filter(a=>a.type==="run").map(chunkT3PAPI4X_js.Q).join("");for(let a of t.values())a.parts.push(i);}else if(d(n)){let i=y(n.content);for(let a of t.values())a.parts.push(i);}}),e}function R(r,e){let{paragraphIndex:t,author:o="AI",text:s,search:n}=e,i=h(r,t),a=(r.comments??[]).map(c=>c.id),p=a.length>0?Math.max(...a)+1:1,u={id:p,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 c=j(i,n,t);i.content.splice(c.endRunIndex+1,0,{type:"commentRangeEnd",id:p}),i.content.splice(c.startRunIndex,0,{type:"commentRangeStart",id:p});}else i.content.unshift({type:"commentRangeStart",id:p}),i.content.push({type:"commentRangeEnd",id:p});return p}function v(r,e,t){let o=r.comments??[];if(!o.find(p=>p.id===e))throw new C(e);let n=o.map(p=>p.id),i=Math.max(...n)+1,a={id:i,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(a),i}function w(r,e){if(!Z(r,e,"accept"))throw new x(e)}function B(r,e){if(!Z(r,e,"reject"))throw new x(e)}function Q(r){return Y(r,"accept")}function V(r){return Y(r,"reject")}function Y(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)&&(_(o,s,n,e),t++);}}),t}function Z(r,e,t){let o=false;return f(r,s=>{for(let n=s.content.length-1;n>=0;n--){let i=s.content[n];d(i)&&i.info.id===e&&(_(s,n,i,t),o=true);}if(o)return false}),o}function _(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,i=h(r,t),{startIndex:a,endIndex:p}=I(i,o,t),u=new Date().toISOString(),c=E(r),m=i.content.slice(a,p+1),D={type:"deletion",info:{id:c,author:s,date:u},content:m},P={type:"insertion",info:{id:c+1,author:s,date:u},content:[{type:"run",content:[{type:"text",text:n}]}]};i.content.splice(a,p-a+1,D,P);}function ee(r,e){let{paragraphIndex:t,author:o="AI",insertText:s,position:n="after",search:i}=e,a=h(r,t),p=new Date().toISOString(),c={type:"insertion",info:{id:E(r),author:o,date:p},content:[{type:"run",content:[{type:"text",text:s}]}]};if(i){let{startIndex:m,endIndex:D}=I(a,i,t),P=n==="after"?D+1:m;a.content.splice(P,0,c);}else n==="before"?a.content.unshift(c):a.content.push(c);}function te(r,e){let{paragraphIndex:t,search:o,author:s="AI"}=e,n=h(r,t),{startIndex:i,endIndex:a}=I(n,o,t),p=new Date().toISOString(),u=E(r),c=n.content.slice(i,a+1),m={type:"deletion",info:{id:u,author:s,date:p},content:c};n.content.splice(i,a-i+1,m);}var K=new WeakMap;function E(r){let e=K.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 K.set(r,t+1),t}function ne(r,e,t="AI"){let o=[],s=0,n=0,i=0,a=0,p=0;for(let u of e.accept??[])try{w(r,u),s++;}catch(c){o.push({operation:"accept",id:u,error:c.message});}for(let u of e.reject??[])try{B(r,u),n++;}catch(c){o.push({operation:"reject",id:u,error:c.message});}for(let u of e.comments??[])try{R(r,{...u,author:u.author??t}),i++;}catch(c){o.push({operation:"comment",search:u.search,error:c.message});}for(let u of e.replies??[])try{v(r,u.commentId,{author:u.author??t,text:u.text}),a++;}catch(c){o.push({operation:"reply",id:u.commentId,error:c.message});}for(let u of e.proposals??[])try{T(r,{...u,author:u.author??t}),p++;}catch(c){o.push({operation:"proposal",search:u.search,error:c.message});}return {accepted:s,rejected:n,commentsAdded:i,repliesAdded:a,proposalsAdded:p,errors:o}}var M=class r{constructor(e,t="AI",o){let s=o??e.originalBuffer,{originalBuffer:n,...i}=e;this.doc=structuredClone(i),s&&(this.doc.originalBuffer=s),this.author=t;}static async fromBuffer(e,t="AI"){let o=await chunkT3PAPI4X_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)}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){ee(this.body,{...e,author:this.resolveAuthor(e.author)});}proposeDeletion(e){te(this.body,{...e,author:this.resolveAuthor(e.author)});}acceptChange(e){w(this.body,e);}rejectChange(e){B(this.body,e);}acceptAll(){return Q(this.body)}rejectAll(){return V(this.body)}applyReview(e){return ne(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-SJ66VOJQ.js');return e(this.doc)}};exports.ChangeNotFoundError=x;exports.CommentNotFoundError=C;exports.DocxReviewer=M;exports.TextNotFoundError=g;
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-QU2KZVKE.mjs';function d(r){return r.type==="insertion"||r.type==="deletion"||r.type==="moveFrom"||r.type==="moveTo"}function y(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 i of n.content)if(i.type==="paragraph"){if(t===e)return i;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 i of n.content)if(i.type==="paragraph"){if(e(i,t)===false)return;t++;}}else t++;}function O(r,e={}){let{fromIndex:t,toIndex:o,includeTrackedChanges:s=true,includeCommentAnchors:n=true}=e,i=[],a=0;for(let p of r.content)if(p.type==="paragraph")S(a,t,o)&&i.push(oe(p,a,s,n)),a++;else if(p.type==="table"){S(a,t,o)&&i.push(re(p,a,s,n));for(let u of p.rows)for(let c of u.cells)for(let m of c.content)m.type==="paragraph"&&a++;}else a++;return i}function S(r,e,t){return (e===void 0||r>=e)&&(t===void 0||r<=t)}function oe(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 re(r,e,t,o){let s=[];for(let n of r.rows){let i=[];for(let a of n.cells){let p=[];for(let u of a.content)u.type==="paragraph"&&p.push(L(u,t,o));i.push(p.join(`
2
- `));}s.push(i);}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 a=t.rows[s][n].split(`
3
- `);for(let p of a)e.push(`[${o}] (table, row ${s+1}, col ${n+1}) ${p}`),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 i=y(n.content);n.type==="insertion"||n.type==="moveTo"?e?o.push(`[+${i}+]{by:${n.info.author}}`):o.push(i):e&&o.push(`[-${i}-]{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";}},C=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 i=s.children[n];if(i.type==="run"){let a=Q$1(i);e.push({contentIndex:o,run:i,text:a,startPos:t}),t+=a.length;}}else if(d(s))for(let n=0;n<s.content.length;n++){let i=s.content[n];if(i.type==="run"){let a=Q$1(i);e.push({contentIndex:o,run:i,text:a,startPos:t}),t+=a.length;}else if(i.type==="hyperlink"){for(let a of i.children)if(a.type==="run"){let p=Q$1(a);e.push({contentIndex:o,run:a,text:p,startPos:t}),t+=p.length;}}}}return e}function F(r){return U(r).map(e=>e.text).join("")}function j(r,e,t){let o=U(r),s=o.map(c=>c.text).join(""),n=se(s,e);if(!n)throw new g(e,t);let i=-1,a=0;for(let c=0;c<o.length;c++)if(n.start<o[c].startPos+o[c].text.length){i=c,a=n.start-o[c].startPos;break}let p=-1,u=0;for(let c=o.length-1;c>=0;c--)if(n.end>o[c].startPos){p=c,u=n.end-o[c].startPos;break}if(i===-1||p===-1)throw new g(e,t);return {startRunIndex:o[i].contentIndex,startOffset:a,endRunIndex:o[p].contentIndex,endOffset:u}}function I(r,e,t){let o=j(r,e,t),{startRunIndex:s,endRunIndex:n}=o,{startOffset:i,endOffset:a}=o,p=r.content[n];if(p.type==="run"){let c=Q$1(p);if(a<c.length){let m=G(c.slice(a),p);N(p,c.slice(0,a)),r.content.splice(n+1,0,m);}}let u=r.content[s];if(u.type==="run"&&i>0){let c=Q$1(u),m=G(c.slice(0,i),u);N(u,c.slice(i)),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 se(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 i=s.text.split(" ");if(i.length>=3)for(let a=1;a<=Math.min(2,i.length-2);a++){let p=i.slice(0,-a).join(" "),u=o.text.indexOf(p);if(u!==-1)return z(o,u,p.length,r)}return null}function q(r,e){let t=new Map;return f(r,(s,n)=>{let i=null;for(let a of s.content)if(d(a)){i===null&&(i=F(s));let p=y(a.content),u=a.info.id,c=t.get(u);c&&c.paragraphIndex===n?c.text+=p:t.set(u,{id:u,type:a.type,author:a.info.author,date:a.info.date??null,text:p,context:i,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=ae(r),s=[],n=new Map;for(let a of t)if(a.parentId!==void 0){let p=n.get(a.parentId)??[];p.push(a),n.set(a.parentId,p);}else s.push(a);return s.map(a=>{let p=o.get(a.id),u=(n.get(a.id)??[]).map(c=>({id:c.id,author:c.author,date:c.date??null,text:X(c)}));return {id:a.id,author:a.author,date:a.date??null,text:X(a),anchoredText:p?.text??"",paragraphIndex:p?.paragraphIndex??-1,replies:u,done:a.done??false}}).filter(a=>!(e?.author&&a.author!==e.author||e?.done!==void 0&&a.done!==e.done))}function X(r){return r.content.map(e=>F(e)).join(`
5
- `)}function ae(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 i=t.get(n.id);i&&(e.set(n.id,{text:i.parts.join(""),paragraphIndex:i.paragraphIndex}),t.delete(n.id));}else if(n.type==="run"){let i=Q$1(n);for(let a of t.values())a.parts.push(i);}else if(n.type==="hyperlink"){let i=n.children.filter(a=>a.type==="run").map(Q$1).join("");for(let a of t.values())a.parts.push(i);}else if(d(n)){let i=y(n.content);for(let a of t.values())a.parts.push(i);}}),e}function R(r,e){let{paragraphIndex:t,author:o="AI",text:s,search:n}=e,i=h(r,t),a=(r.comments??[]).map(c=>c.id),p=a.length>0?Math.max(...a)+1:1,u={id:p,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 c=j(i,n,t);i.content.splice(c.endRunIndex+1,0,{type:"commentRangeEnd",id:p}),i.content.splice(c.startRunIndex,0,{type:"commentRangeStart",id:p});}else i.content.unshift({type:"commentRangeStart",id:p}),i.content.push({type:"commentRangeEnd",id:p});return p}function v(r,e,t){let o=r.comments??[];if(!o.find(p=>p.id===e))throw new C(e);let n=o.map(p=>p.id),i=Math.max(...n)+1,a={id:i,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(a),i}function w(r,e){if(!Z(r,e,"accept"))throw new x(e)}function B(r,e){if(!Z(r,e,"reject"))throw new x(e)}function Q(r){return Y(r,"accept")}function V(r){return Y(r,"reject")}function Y(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)&&(_(o,s,n,e),t++);}}),t}function Z(r,e,t){let o=false;return f(r,s=>{for(let n=s.content.length-1;n>=0;n--){let i=s.content[n];d(i)&&i.info.id===e&&(_(s,n,i,t),o=true);}if(o)return false}),o}function _(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,i=h(r,t),{startIndex:a,endIndex:p}=I(i,o,t),u=new Date().toISOString(),c=E(r),m=i.content.slice(a,p+1),D={type:"deletion",info:{id:c,author:s,date:u},content:m},P={type:"insertion",info:{id:c+1,author:s,date:u},content:[{type:"run",content:[{type:"text",text:n}]}]};i.content.splice(a,p-a+1,D,P);}function ee(r,e){let{paragraphIndex:t,author:o="AI",insertText:s,position:n="after",search:i}=e,a=h(r,t),p=new Date().toISOString(),c={type:"insertion",info:{id:E(r),author:o,date:p},content:[{type:"run",content:[{type:"text",text:s}]}]};if(i){let{startIndex:m,endIndex:D}=I(a,i,t),P=n==="after"?D+1:m;a.content.splice(P,0,c);}else n==="before"?a.content.unshift(c):a.content.push(c);}function te(r,e){let{paragraphIndex:t,search:o,author:s="AI"}=e,n=h(r,t),{startIndex:i,endIndex:a}=I(n,o,t),p=new Date().toISOString(),u=E(r),c=n.content.slice(i,a+1),m={type:"deletion",info:{id:u,author:s,date:p},content:c};n.content.splice(i,a-i+1,m);}var K=new WeakMap;function E(r){let e=K.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 K.set(r,t+1),t}function ne(r,e,t="AI"){let o=[],s=0,n=0,i=0,a=0,p=0;for(let u of e.accept??[])try{w(r,u),s++;}catch(c){o.push({operation:"accept",id:u,error:c.message});}for(let u of e.reject??[])try{B(r,u),n++;}catch(c){o.push({operation:"reject",id:u,error:c.message});}for(let u of e.comments??[])try{R(r,{...u,author:u.author??t}),i++;}catch(c){o.push({operation:"comment",search:u.search,error:c.message});}for(let u of e.replies??[])try{v(r,u.commentId,{author:u.author??t,text:u.text}),a++;}catch(c){o.push({operation:"reply",id:u.commentId,error:c.message});}for(let u of e.proposals??[])try{T(r,{...u,author:u.author??t}),p++;}catch(c){o.push({operation:"proposal",search:u.search,error:c.message});}return {accepted:s,rejected:n,commentsAdded:i,repliesAdded:a,proposalsAdded:p,errors:o}}var M=class r{constructor(e,t="AI",o){let s=o??e.originalBuffer,{originalBuffer:n,...i}=e;this.doc=structuredClone(i),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)}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){ee(this.body,{...e,author:this.resolveAuthor(e.author)});}proposeDeletion(e){te(this.body,{...e,author:this.resolveAuthor(e.author)});}acceptChange(e){w(this.body,e);}rejectChange(e){B(this.body,e);}acceptAll(){return Q(this.body)}rejectAll(){return V(this.body)}applyReview(e){return ne(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-BWFR2RRX.mjs');return e(this.doc)}};export{x as ChangeNotFoundError,C as CommentNotFoundError,M as DocxReviewer,g as TextNotFoundError};
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.35",
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-js-editor.git",
55
+ "url": "https://github.com/eigenpal/docx-editor.git",
56
56
  "directory": "packages/agent-use"
57
57
  },
58
58
  "publishConfig": {