@eigenpal/docx-editor-agents 1.6.0 → 1.6.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/bridge.js CHANGED
@@ -1 +1 @@
1
- 'use strict';var chunkB56JZP3K_js=require('./chunk-B56JZP3K.js'),chunkYU3OJ2DE_js=require('./chunk-YU3OJ2DE.js'),chunkAO5SO6ZS_js=require('./chunk-AO5SO6ZS.js');Object.defineProperty(exports,"createEditorBridge",{enumerable:true,get:function(){return chunkB56JZP3K_js.a}});Object.defineProperty(exports,"createReviewerBridge",{enumerable:true,get:function(){return chunkYU3OJ2DE_js.n}});Object.defineProperty(exports,"agentTools",{enumerable:true,get:function(){return chunkAO5SO6ZS_js.a}});Object.defineProperty(exports,"executeToolCall",{enumerable:true,get:function(){return chunkAO5SO6ZS_js.b}});Object.defineProperty(exports,"getToolSchemas",{enumerable:true,get:function(){return chunkAO5SO6ZS_js.d}});
1
+ 'use strict';var chunkYIZV6SSD_js=require('./chunk-YIZV6SSD.js'),chunkEX4NO3JP_js=require('./chunk-EX4NO3JP.js'),chunkAO5SO6ZS_js=require('./chunk-AO5SO6ZS.js');Object.defineProperty(exports,"createEditorBridge",{enumerable:true,get:function(){return chunkYIZV6SSD_js.a}});Object.defineProperty(exports,"createReviewerBridge",{enumerable:true,get:function(){return chunkEX4NO3JP_js.n}});Object.defineProperty(exports,"agentTools",{enumerable:true,get:function(){return chunkAO5SO6ZS_js.a}});Object.defineProperty(exports,"executeToolCall",{enumerable:true,get:function(){return chunkAO5SO6ZS_js.b}});Object.defineProperty(exports,"getToolSchemas",{enumerable:true,get:function(){return chunkAO5SO6ZS_js.d}});
package/dist/bridge.mjs CHANGED
@@ -1 +1 @@
1
- export{a as createEditorBridge}from'./chunk-WDPSOX2B.mjs';export{n as createReviewerBridge}from'./chunk-J773ZJGL.mjs';export{a as agentTools,b as executeToolCall,d as getToolSchemas}from'./chunk-MSKW7E36.mjs';
1
+ export{a as createEditorBridge}from'./chunk-3RLSV2EA.mjs';export{n as createReviewerBridge}from'./chunk-5THPDZLF.mjs';export{a as agentTools,b as executeToolCall,d as getToolSchemas}from'./chunk-MSKW7E36.mjs';
@@ -1,2 +1,2 @@
1
- import {m,l,e,f}from'./chunk-J773ZJGL.mjs';function y(n){return !n||n.length===0?"":n.map(l=>{let s=l;return s?.content?s.content.map(e=>e.content?.map(t=>t.text||"").join("")||"").join(""):""}).join(`
1
+ import {m,l,e,f}from'./chunk-5THPDZLF.mjs';function y(n){return !n||n.length===0?"":n.map(l=>{let s=l;return s?.content?s.content.map(e=>e.content?.map(t=>t.text||"").join("")||"").join(""):""}).join(`
2
2
  `)}function u(n){let l=n.getEditorRef();if(l){let e=l.getDocument();if(e?.package?.document)return e.package.document}return n.getDocument()?.package?.document??null}function k(n,l$1="AI"){function s(e){return e??l$1}return {getContentAsText(e$1){let t=u(n);return t?f(e(t,e$1)):""},getContent(e$1){let t=u(n);return t?e(t,e$1):[]},getComments(e){let t=u(n);if(!t)return [];let r=m(t,e);if(r.length>0)return r;let i=n.getComments();if(i.length===0)return [];let a=new Map,g=[];for(let o of i)if(o.parentId){let p=a.get(o.parentId);p?p.push(o):a.set(o.parentId,[o]);}else g.push(o);let m$1=[];for(let o of g){if(e?.author&&o.author!==e.author||e?.done!==void 0&&(o.done??false)!==e.done)continue;let p=a.get(o.id)??[];m$1.push({id:o.id,author:o.author,date:o.date??null,text:y(o.content),anchoredText:"",paragraphIndex:-1,replies:p.map(c=>({id:c.id,author:c.author,date:c.date??null,text:y(c.content)})),done:o.done??false});}return m$1},getChanges(e){let t=u(n);return t?l(t,e):[]},findText(e,t){return n.findInDocument(e,t)},getSelection(){return n.getSelectionInfo()},addComment(e){return n.addComment({paraId:e.paraId,text:e.text,author:s(e.author),search:e.search})},replyTo(e,t){return n.replyToComment(e,t.text,s(t.author))},resolveComment(e){n.resolveComment(e);},proposeChange(e){return n.proposeChange({paraId:e.paraId,search:e.search,replaceWith:e.replaceWith,author:s(e.author)})},applyFormatting(e){return n.applyFormatting({paraId:e.paraId,search:e.search,marks:e.marks})},setParagraphStyle(e){return n.setParagraphStyle({paraId:e.paraId,styleId:e.styleId})},insertBreak(e){return n.insertBreak({paraId:e.paraId,type:e.type})},getPage(e){return n.getPageContent(e)},getPages(e){let t=n.getTotalPages(),r=Math.max(1,Math.min(e.from,t)),i=Math.max(r,Math.min(e.to,t)),a=[];for(let g=r;g<=i;g++){let m=n.getPageContent(g);m&&a.push(m);}return a},getTotalPages(){return n.getTotalPages()},getCurrentPage(){return n.getCurrentPage()},scrollTo(e){return n.scrollToParaId(e)},onContentChange(e){return n.onContentChange(()=>{let t=u(n),r=t?m(t):[],i=t?l(t):[];try{e({commentCount:r.length,changeCount:i.length,comments:r,changes:i});}catch(a){console.error("onContentChange listener threw:",a);}})},onSelectionChange(e){return n.onSelectionChange(()=>{try{e(n.getSelectionInfo());}catch(t){console.error("onSelectionChange listener threw:",t);}})}}}export{k as a};
@@ -0,0 +1,5 @@
1
+ import {U as U$1,V as V$1,H as H$1,I as I$1,va}from'./chunk-X5FXVERG.mjs';import {m as m$1}from'./chunk-6RMDMHUK.mjs';function h(o){return o.type==="insertion"||o.type==="deletion"||o.type==="moveFrom"||o.type==="moveTo"}function C(o){let t=[];for(let r of o)r.type==="run"?t.push(H$1(r)):r.type==="hyperlink"&&t.push(I$1(r));return t.join("")}function R(o,t){let r=0;for(let n of o.content)if(n.type==="paragraph"){if(r===t)return n;r++;}else if(n.type==="table"){for(let a of n.rows)for(let e of a.cells)for(let i of e.content)if(i.type==="paragraph"){if(r===t)return i;r++;}}else r++;throw new Error(`Paragraph index ${t} out of bounds (max: ${r-1})`)}function A(o,t,r){let n=0;for(let a of o)if(a.type==="paragraph"){if(r(a,n)===false)return;n++;}else if(a.type==="table"){for(let e of a.rows)for(let i of e.cells)for(let s of i.content)if(s.type==="paragraph"){if(r(s,n)===false)return;n++;}}else t&&n++;}function m(o,t){A(o.content,true,t);}function k(o,t){A(o.content,false,t);}function fe(o,t={}){let{fromIndex:r,toIndex:n,includeTrackedChanges:a=true,includeCommentAnchors:e=true}=t,i=[],s=0;for(let u of o.content)if(u.type==="paragraph")L(s,r,n)&&i.push(Q(u,s,a,e)),s++;else if(u.type==="table"){L(s,r,n)&&i.push(V(u,s,a,e));for(let l of u.rows)for(let c of l.cells)for(let f of c.content)f.type==="paragraph"&&s++;}else s++;return i}function L(o,t,r){return (t===void 0||o>=t)&&(r===void 0||o<=r)}function Q(o,t,r,n){let a=j(o,r,n),e=o.formatting?.styleId,i=o.paraId;return U$1(e)?{type:"heading",index:t,paraId:i,level:V$1(e)??1,text:a}:o.listRendering?{type:"list-item",index:t,paraId:i,text:a,listLevel:o.listRendering.level??0,listType:o.listRendering.isBullet?"bullet":"number"}:{type:"paragraph",index:t,paraId:i,text:a}}function V(o,t,r,n){let a=[],e=[];for(let i of o.rows){let s=[],u=[];for(let l of i.cells){let c=[],f;for(let d of l.content)d.type==="paragraph"&&(f===void 0&&(f=d.paraId),c.push(j(d,r,n)));s.push(c.join(`
2
+ `)),u.push(f);}a.push(s),e.push(u);}return {type:"table",index:t,rows:a,cellParaIds:e}}function pe(o){let t=[],r=n=>n.paraId?n.paraId:String(n.index);for(let n of o)switch(n.type){case "heading":t.push(`[${r(n)}] (h${n.level}) ${n.text}`);break;case "paragraph":t.push(`[${r(n)}] ${n.text}`);break;case "list-item":{let a=" ".repeat(n.listLevel),e=n.listType==="bullet"?"\u2022":"-";t.push(`[${r(n)}] ${a}${e} ${n.text}`);break}case "table":{let a=n.index;for(let e=0;e<n.rows.length;e++)for(let i=0;i<n.rows[e].length;i++){let u=n.rows[e][i].split(`
3
+ `),l=n.cellParaIds?.[e]?.[i];for(let c=0;c<u.length;c++){let f=c===0&&l?l:String(a);t.push(`[${f}] (table, row ${e+1}, col ${i+1}) ${u[c]}`),a++;}}break}}return t.join(`
4
+ `)}function j(o,t,r){let n=[],a=new Set;for(let e of o.content){if(e.type==="commentRangeStart"&&r){a.add(e.id),n.push(`[comment:${e.id}]`);continue}if(e.type==="commentRangeEnd"&&r){a.has(e.id)&&(a.delete(e.id),n.push("[/comment]"));continue}if(e.type==="run")n.push(H$1(e));else if(e.type==="hyperlink")n.push(I$1(e));else if(h(e)){let i=C(e.content);e.type==="insertion"||e.type==="moveTo"?t&&n.push(`[+${i}+]{by:${e.info.author}}`):t?n.push(`[-${i}-]{by:${e.info.author}}`):n.push(i);}}return n.join("")}var T=class extends Error{constructor(t,r){let n=r!==void 0?` in paragraph ${r}`:" in document";super(`Text not found${n}: "${t}"`),this.name="TextNotFoundError";}},H=class extends Error{constructor(t){super(`Tracked change not found: id=${t}`),this.name="ChangeNotFoundError";}},I=class extends Error{constructor(t){super(`Comment not found: id=${t}`),this.name="CommentNotFoundError";}};function U(o){let t=[],r=0;for(let n=0;n<o.content.length;n++){let a=o.content[n];if(a.type==="run"){let e=H$1(a);t.push({contentIndex:n,run:a,text:e,startPos:r}),r+=e.length;}else if(a.type==="hyperlink")for(let e=0;e<a.children.length;e++){let i=a.children[e];if(i.type==="run"){let s=H$1(i);t.push({contentIndex:n,run:i,text:s,startPos:r}),r+=s.length;}}else if(h(a)){if(a.type==="insertion"||a.type==="moveTo")continue;for(let e=0;e<a.content.length;e++){let i=a.content[e];if(i.type==="run"){let s=H$1(i);t.push({contentIndex:n,run:i,text:s,startPos:r}),r+=s.length;}else if(i.type==="hyperlink"){for(let s of i.children)if(s.type==="run"){let u=H$1(s);t.push({contentIndex:n,run:s,text:u,startPos:r}),r+=u.length;}}}}}return t}function w(o){return U(o).map(t=>t.text).join("")}function Y(o,t,r){let n=U(o),a=n.map(c=>c.text).join(""),e=Z(a,t);if(!e)throw new T(t,r);let i=-1,s=0;for(let c=0;c<n.length;c++)if(e.start<n[c].startPos+n[c].text.length){i=c,s=e.start-n[c].startPos;break}let u=-1,l=0;for(let c=n.length-1;c>=0;c--)if(e.end>n[c].startPos){u=c,l=e.end-n[c].startPos;break}if(i===-1||u===-1)throw new T(t,r);return {startRunIndex:n[i].contentIndex,startOffset:s,endRunIndex:n[u].contentIndex,endOffset:l}}function xe(o,t,r){let n=Y(o,t,r),{startRunIndex:a,endRunIndex:e}=n,{startOffset:i,endOffset:s}=n,u=o.content[e];if(u.type==="run"){let c=H$1(u);if(s<c.length){let f=N(c.slice(s),u);z(u,c.slice(0,s)),o.content.splice(e+1,0,f);}}let l=o.content[a];if(l.type==="run"&&i>0){let c=H$1(l),f=N(c.slice(0,i),l);z(l,c.slice(i)),o.content.splice(a,0,f),a++,e++;}return {startIndex:a,endIndex:e}}function N(o,t){return {type:"run",content:[{type:"text",text:o}],formatting:t.formatting?{...t.formatting}:void 0}}function z(o,t){let r=o.content.find(n=>n.type==="text");r&&(r.text=t);}function W(o){let t=[],r=[],n=true;for(let a=0;a<o.length;a++){let e=o[a];if(!"\u200B\u200C\u200D\uFEFF\xAD".includes(e)){if("\u201C\u201D\u201E\u201F".includes(e)&&(e='"'),"\u2018\u2019\u201A\u201B".includes(e)&&(e="'"),"\u2013\u2014\u2012\u2015".includes(e)&&(e="-"),e==="\u2026"){t.push(".",".","."),r.push(a,a,a),n=false;continue}if(/\s/.test(e)||e==="\xA0"){n||(t.push(" "),r.push(a),n=true);continue}t.push(e.toLowerCase()),r.push(a),n=false;}}return t.length>0&&t[t.length-1]===" "&&(t.pop(),r.pop()),{text:t.join(""),posMap:r}}function G(o,t,r,n){let a=o.posMap[t],e=o.posMap[t+r-1]+1;for(;e<n.length&&"\u200B\u200C\u200D\uFEFF\xAD".includes(n[e]);)e++;return {start:a,end:e}}function Z(o,t){if(!t||!o)return null;let r=o.indexOf(t);if(r!==-1)return {start:r,end:r+t.length};let n=W(o),a=W(t);if(!a.text)return null;let e=n.text.indexOf(a.text);if(e!==-1)return G(n,e,a.text.length,o);let i=a.text.split(" ");if(i.length>=3)for(let s=1;s<=Math.min(2,i.length-2);s++){let u=i.slice(0,-s).join(" "),l=n.text.indexOf(u);if(l!==-1)return G(n,l,u.length,o)}return null}function Te(o,t,r){let n=new Map,a=(i,s,u)=>{let l=null;for(let c of i.content)if(h(c)){l===null&&(l=w(i));let f=C(c.content),d=c.info.id,x=`${u.noteType??"body"}:${u.noteId??""}:${d}`,y=n.get(x);y&&y.paragraphIndex===s?y.text+=f:n.set(x,{id:d,type:c.type,author:c.info.author,date:c.info.date??null,text:f,context:l,paragraphIndex:s,...u.noteId!==void 0?{noteId:u.noteId}:{},...u.noteType!==void 0?{noteType:u.noteType}:{}});}};if(m(o,(i,s)=>a(i,s,{})),t?.includeFootnotes&&r?.footnotes)for(let i of r.footnotes)k(i,(s,u)=>a(s,u,{noteId:i.id,noteType:"footnote"}));if(t?.includeEndnotes&&r?.endnotes)for(let i of r.endnotes)k(i,(s,u)=>a(s,u,{noteId:i.id,noteType:"endnote"}));return Array.from(n.values()).filter(i=>!(t?.author&&i.author!==t.author||t?.type&&i.type!==t.type))}function Pe(o,t){let r=o.comments??[];if(r.length===0)return [];let n=_(o),a=[],e=new Map;for(let s of r)if(s.parentId!==void 0){let u=e.get(s.parentId)??[];u.push(s),e.set(s.parentId,u);}else a.push(s);return a.map(s=>{let u=n.get(s.id),l=(e.get(s.id)??[]).map(c=>({id:c.id,author:c.author,date:c.date??null,text:X(c)}));return {id:s.id,author:s.author,date:s.date??null,text:X(s),anchoredText:u?.text??"",paragraphIndex:u?.paragraphIndex??-1,replies:l,done:s.done??false}}).filter(s=>!(t?.author&&s.author!==t.author||t?.done!==void 0&&s.done!==t.done))}function X(o){return o.content.map(t=>w(t)).join(`
5
+ `)}function _(o){let t=new Map,r=new Map;return m(o,(n,a)=>{for(let e of n.content)if(e.type==="commentRangeStart")r.set(e.id,{paragraphIndex:a,parts:[]});else if(e.type==="commentRangeEnd"){let i=r.get(e.id);i&&(t.set(e.id,{text:i.parts.join(""),paragraphIndex:i.paragraphIndex}),r.delete(e.id));}else if(e.type==="run"){let i=H$1(e);for(let s of r.values())s.parts.push(i);}else if(e.type==="hyperlink"){let i=e.children.filter(s=>s.type==="run").map(H$1).join("");for(let s of r.values())s.parts.push(i);}else if(h(e)){if(e.type==="insertion"||e.type==="moveTo")continue;let i=C(e.content);for(let s of r.values())s.parts.push(i);}}),t}function q(o){let t=o.toDocument().package?.document;if(!t)return new Map;let r=new Map;return m(t,(n,a)=>{r.set(n.paraId??String(a),a),r.set(String(a),a);}),r}function ee(o){let t=[],r=n=>{for(let a of n.content)a.type==="text"&&t.push(a.text??"");};for(let n of o.content)if(n.type==="run")r(n);else if(n.type==="hyperlink")for(let a of n.children)a.type==="run"&&r(a);else if(n.type==="deletion"||n.type==="moveFrom"){for(let a of n.content)if(a.type==="run")r(a);else if(a.type==="hyperlink")for(let e of a.children)e.type==="run"&&r(e);}return t.join("")}function B(o,t){let n={type:"run",content:[{type:"text",text:t,preserveSpace:/^\s|\s$/.test(t)}]};return o.formatting&&(n.formatting={...o.formatting}),o.propertyChanges&&(n.propertyChanges=[...o.propertyChanges]),n}function te(o){return o.content.map(t=>t.type==="text"?t.text:"").join("")}function M(o,t,r,n,a){let e=te(o);if(!e)return;let i=a.value,s=i+e.length;n.push({run:o,parent:t,index:r,text:e,start:i,end:s}),a.value=s;}function J(o,t,r){o.children.forEach((n,a)=>{n.type==="run"&&M(n,o.children,a,t,r);});}function D(o,t){let r=[],n={value:0};return o.content.forEach((a,e)=>{a.type==="run"?M(a,o.content,e,r,n):a.type==="hyperlink"?J(a,r,n):(a.type==="deletion"||a.type==="moveFrom"||t&&(a.type==="insertion"||a.type==="moveTo"))&&a.content.forEach((i,s)=>{i.type==="run"?M(i,a.content,s,r,n):i.type==="hyperlink"&&J(i,r,n);});}),r}function ne(o,t){let r={...o??{}};t.bold!==void 0&&(r.bold=t.bold||void 0),t.italic!==void 0&&(r.italic=t.italic||void 0),t.underline!==void 0&&(t.underline?r.underline={style:typeof t.underline=="object"&&t.underline.style?t.underline.style:"single"}:delete r.underline),t.strike!==void 0&&(r.strike=t.strike||void 0),t.color!==void 0&&(t.color&&(t.color.rgb||t.color.themeColor)?r.color={rgb:t.color.rgb,themeColor:t.color.themeColor}:delete r.color),t.highlight!==void 0&&(t.highlight?r.highlight=va(t.highlight)||t.highlight:delete r.highlight),t.fontSize!==void 0&&(t.fontSize>0?r.fontSize=m$1(t.fontSize):delete r.fontSize),t.fontFamily!==void 0&&(t.fontFamily&&(t.fontFamily.ascii||t.fontFamily.hAnsi)?r.fontFamily={ascii:t.fontFamily.ascii,hAnsi:t.fontFamily.hAnsi??t.fontFamily.ascii}:delete r.fontFamily);for(let n of Object.keys(r))r[n]===void 0&&delete r[n];return Object.keys(r).length>0?r:void 0}function S(o,t){o.formatting=ne(o.formatting,t);}function oe(o,t,r,n){let a=o.run.content.every(s=>s.type==="text");if(t<=0&&r>=o.text.length||!a){S(o.run,n);return}let e=[];t>0&&e.push(B(o.run,o.text.slice(0,t)));let i=B(o.run,o.text.slice(t,r));S(i,n),e.push(i),r<o.text.length&&e.push(B(o.run,o.text.slice(r))),o.parent.splice(o.index,1,...e);}function re(o,t,r,n){let e=D(o,false).filter(i=>i.start<r&&i.end>t);if(e.length===0)return true;for(let i=e.length-1;i>=0;i--){let s=e[i];oe(s,Math.max(0,t-s.start),Math.min(s.text.length,r-s.start),n);}return true}function ae(o,t){let r=D(o,true);for(let n of r)S(n.run,t);return true}function ie(o,t){if(!t)return null;let n=D(o,false).map(e=>e.text).join(""),a=n.indexOf(t);return a===-1||n.indexOf(t,a+1)!==-1?null:{from:a,to:a+t.length}}function se(o,t){return o?!!o.styles?.some(r=>r.styleId===t&&r.type==="paragraph"):true}function ke(o){let t=new Set,r=null;function n(){return r===null&&(r=q(o)),r}function a(){if(t.size===0)return;let e=o.getComments(),i=o.getChanges(),s={commentCount:e.length,changeCount:i.length,comments:e,changes:i};for(let u of t)try{u(s);}catch(l){console.error("reviewerBridge content listener threw:",l);}}return {getContentAsText(e){return o.getContentAsText(e)},getContent(e){return o.getContent(e)},getComments(e){return o.getComments(e)},getChanges(e){return o.getChanges(e)},findText(e,i){if(!e)return [];let s=i?.caseSensitive??false,u=i?.limit??20,l=s?e:e.toLowerCase(),c=o.toDocument().package?.document;if(!c)return [];let f=[],d=40;return m(c,(x,y)=>{let b=ee(x),E=s?b:b.toLowerCase(),g=E.indexOf(l);if(g===-1||E.indexOf(l,g+1)!==-1)return;let K=b.slice(g,g+e.length);if(f.push({paraId:x.paraId??String(y),match:K,before:b.slice(Math.max(0,g-d),g),after:b.slice(g+e.length,g+e.length+d)}),f.length>=u)return false}),f},getSelection(){return null},addComment(e){let i=n().get(e.paraId);if(i===void 0)return null;try{let s=o.addComment({paragraphIndex:i,text:e.text,author:e.author,search:e.search});return a(),s}catch{return null}},replyTo(e,i){try{let s=o.replyTo(e,i);return a(),s}catch{return null}},resolveComment(e){let s=o.toDocument().package?.document?.comments?.find(u=>u.id===e);if(!s)throw new I(e);s.done=true,a();},proposeChange(e){let i=n().get(e.paraId);if(i===void 0)return false;let s=e.search==="",u=e.replaceWith==="";if(s&&u)return false;try{return s?o.proposeInsertion({paragraphIndex:i,insertText:e.replaceWith,author:e.author}):u?o.proposeDeletion({paragraphIndex:i,search:e.search,author:e.author}):o.replace({paragraphIndex:i,search:e.search,replaceWith:e.replaceWith,author:e.author}),a(),true}catch{return false}},scrollTo(e){return n().has(e)},applyFormatting(e){let i=n().get(e.paraId);if(i===void 0)return false;let s=o.toDocument().package?.document;if(!s)return false;try{let u=s?R(s,i):null;if(!u)return false;if(e.search){let l=ie(u,e.search);if(!l)return false;re(u,l.from,l.to,e.marks);}else ae(u,e.marks);return a(),true}catch{return false}},setParagraphStyle(e){let i=n().get(e.paraId);if(i===void 0)return false;let s=o.toDocument(),u=s.package?.document;if(!u||!se(s.package?.styles,e.styleId))return false;try{let l=R(u,i);return l.formatting={...l.formatting??{},styleId:e.styleId},a(),true}catch{return false}},insertBreak(e){let i=n().get(e.paraId);if(i===void 0)return false;let s=o.toDocument().package?.document;if(!s)return false;try{let u=R(s,i);if(!u)return false;if(e.type==="sectionNextPage"||e.type==="sectionContinuous"){let f=e.type==="sectionNextPage"?"nextPage":"continuous";return u.sectionProperties={...u.sectionProperties??{},sectionStart:f},a(),true}let l=s.content.indexOf(u);if(l===-1)return false;let c={type:"paragraph",content:[{type:"run",content:[{type:"break",breakType:"page"}]}]};return s.content.splice(l+1,0,c),r=null,a(),true}catch{return false}},getPage(){return null},getPages(){return []},getTotalPages(){return 0},getCurrentPage(){return 0},onContentChange(e){return t.add(e),()=>{t.delete(e);}},onSelectionChange(){return ()=>{}}}}export{h as a,R as b,m as c,k as d,fe as e,pe as f,T as g,H as h,I as i,Y as j,xe as k,Te as l,Pe as m,ke as n};
@@ -0,0 +1,5 @@
1
+ 'use strict';var chunkRTU2ZS7R_js=require('./chunk-RTU2ZS7R.js'),chunkMMJQ47Q7_js=require('./chunk-MMJQ47Q7.js');function h(o){return o.type==="insertion"||o.type==="deletion"||o.type==="moveFrom"||o.type==="moveTo"}function C(o){let t=[];for(let r of o)r.type==="run"?t.push(chunkRTU2ZS7R_js.H(r)):r.type==="hyperlink"&&t.push(chunkRTU2ZS7R_js.I(r));return t.join("")}function R(o,t){let r=0;for(let n of o.content)if(n.type==="paragraph"){if(r===t)return n;r++;}else if(n.type==="table"){for(let a of n.rows)for(let e of a.cells)for(let i of e.content)if(i.type==="paragraph"){if(r===t)return i;r++;}}else r++;throw new Error(`Paragraph index ${t} out of bounds (max: ${r-1})`)}function A(o,t,r){let n=0;for(let a of o)if(a.type==="paragraph"){if(r(a,n)===false)return;n++;}else if(a.type==="table"){for(let e of a.rows)for(let i of e.cells)for(let s of i.content)if(s.type==="paragraph"){if(r(s,n)===false)return;n++;}}else t&&n++;}function m(o,t){A(o.content,true,t);}function k(o,t){A(o.content,false,t);}function fe(o,t={}){let{fromIndex:r,toIndex:n,includeTrackedChanges:a=true,includeCommentAnchors:e=true}=t,i=[],s=0;for(let u of o.content)if(u.type==="paragraph")L(s,r,n)&&i.push(Q(u,s,a,e)),s++;else if(u.type==="table"){L(s,r,n)&&i.push(V(u,s,a,e));for(let l of u.rows)for(let c of l.cells)for(let f of c.content)f.type==="paragraph"&&s++;}else s++;return i}function L(o,t,r){return (t===void 0||o>=t)&&(r===void 0||o<=r)}function Q(o,t,r,n){let a=j(o,r,n),e=o.formatting?.styleId,i=o.paraId;return chunkRTU2ZS7R_js.U(e)?{type:"heading",index:t,paraId:i,level:chunkRTU2ZS7R_js.V(e)??1,text:a}:o.listRendering?{type:"list-item",index:t,paraId:i,text:a,listLevel:o.listRendering.level??0,listType:o.listRendering.isBullet?"bullet":"number"}:{type:"paragraph",index:t,paraId:i,text:a}}function V(o,t,r,n){let a=[],e=[];for(let i of o.rows){let s=[],u=[];for(let l of i.cells){let c=[],f;for(let d of l.content)d.type==="paragraph"&&(f===void 0&&(f=d.paraId),c.push(j(d,r,n)));s.push(c.join(`
2
+ `)),u.push(f);}a.push(s),e.push(u);}return {type:"table",index:t,rows:a,cellParaIds:e}}function pe(o){let t=[],r=n=>n.paraId?n.paraId:String(n.index);for(let n of o)switch(n.type){case "heading":t.push(`[${r(n)}] (h${n.level}) ${n.text}`);break;case "paragraph":t.push(`[${r(n)}] ${n.text}`);break;case "list-item":{let a=" ".repeat(n.listLevel),e=n.listType==="bullet"?"\u2022":"-";t.push(`[${r(n)}] ${a}${e} ${n.text}`);break}case "table":{let a=n.index;for(let e=0;e<n.rows.length;e++)for(let i=0;i<n.rows[e].length;i++){let u=n.rows[e][i].split(`
3
+ `),l=n.cellParaIds?.[e]?.[i];for(let c=0;c<u.length;c++){let f=c===0&&l?l:String(a);t.push(`[${f}] (table, row ${e+1}, col ${i+1}) ${u[c]}`),a++;}}break}}return t.join(`
4
+ `)}function j(o,t,r){let n=[],a=new Set;for(let e of o.content){if(e.type==="commentRangeStart"&&r){a.add(e.id),n.push(`[comment:${e.id}]`);continue}if(e.type==="commentRangeEnd"&&r){a.has(e.id)&&(a.delete(e.id),n.push("[/comment]"));continue}if(e.type==="run")n.push(chunkRTU2ZS7R_js.H(e));else if(e.type==="hyperlink")n.push(chunkRTU2ZS7R_js.I(e));else if(h(e)){let i=C(e.content);e.type==="insertion"||e.type==="moveTo"?t&&n.push(`[+${i}+]{by:${e.info.author}}`):t?n.push(`[-${i}-]{by:${e.info.author}}`):n.push(i);}}return n.join("")}var T=class extends Error{constructor(t,r){let n=r!==void 0?` in paragraph ${r}`:" in document";super(`Text not found${n}: "${t}"`),this.name="TextNotFoundError";}},H=class extends Error{constructor(t){super(`Tracked change not found: id=${t}`),this.name="ChangeNotFoundError";}},I=class extends Error{constructor(t){super(`Comment not found: id=${t}`),this.name="CommentNotFoundError";}};function U(o){let t=[],r=0;for(let n=0;n<o.content.length;n++){let a=o.content[n];if(a.type==="run"){let e=chunkRTU2ZS7R_js.H(a);t.push({contentIndex:n,run:a,text:e,startPos:r}),r+=e.length;}else if(a.type==="hyperlink")for(let e=0;e<a.children.length;e++){let i=a.children[e];if(i.type==="run"){let s=chunkRTU2ZS7R_js.H(i);t.push({contentIndex:n,run:i,text:s,startPos:r}),r+=s.length;}}else if(h(a)){if(a.type==="insertion"||a.type==="moveTo")continue;for(let e=0;e<a.content.length;e++){let i=a.content[e];if(i.type==="run"){let s=chunkRTU2ZS7R_js.H(i);t.push({contentIndex:n,run:i,text:s,startPos:r}),r+=s.length;}else if(i.type==="hyperlink"){for(let s of i.children)if(s.type==="run"){let u=chunkRTU2ZS7R_js.H(s);t.push({contentIndex:n,run:s,text:u,startPos:r}),r+=u.length;}}}}}return t}function w(o){return U(o).map(t=>t.text).join("")}function Y(o,t,r){let n=U(o),a=n.map(c=>c.text).join(""),e=Z(a,t);if(!e)throw new T(t,r);let i=-1,s=0;for(let c=0;c<n.length;c++)if(e.start<n[c].startPos+n[c].text.length){i=c,s=e.start-n[c].startPos;break}let u=-1,l=0;for(let c=n.length-1;c>=0;c--)if(e.end>n[c].startPos){u=c,l=e.end-n[c].startPos;break}if(i===-1||u===-1)throw new T(t,r);return {startRunIndex:n[i].contentIndex,startOffset:s,endRunIndex:n[u].contentIndex,endOffset:l}}function xe(o,t,r){let n=Y(o,t,r),{startRunIndex:a,endRunIndex:e}=n,{startOffset:i,endOffset:s}=n,u=o.content[e];if(u.type==="run"){let c=chunkRTU2ZS7R_js.H(u);if(s<c.length){let f=N(c.slice(s),u);z(u,c.slice(0,s)),o.content.splice(e+1,0,f);}}let l=o.content[a];if(l.type==="run"&&i>0){let c=chunkRTU2ZS7R_js.H(l),f=N(c.slice(0,i),l);z(l,c.slice(i)),o.content.splice(a,0,f),a++,e++;}return {startIndex:a,endIndex:e}}function N(o,t){return {type:"run",content:[{type:"text",text:o}],formatting:t.formatting?{...t.formatting}:void 0}}function z(o,t){let r=o.content.find(n=>n.type==="text");r&&(r.text=t);}function W(o){let t=[],r=[],n=true;for(let a=0;a<o.length;a++){let e=o[a];if(!"\u200B\u200C\u200D\uFEFF\xAD".includes(e)){if("\u201C\u201D\u201E\u201F".includes(e)&&(e='"'),"\u2018\u2019\u201A\u201B".includes(e)&&(e="'"),"\u2013\u2014\u2012\u2015".includes(e)&&(e="-"),e==="\u2026"){t.push(".",".","."),r.push(a,a,a),n=false;continue}if(/\s/.test(e)||e==="\xA0"){n||(t.push(" "),r.push(a),n=true);continue}t.push(e.toLowerCase()),r.push(a),n=false;}}return t.length>0&&t[t.length-1]===" "&&(t.pop(),r.pop()),{text:t.join(""),posMap:r}}function G(o,t,r,n){let a=o.posMap[t],e=o.posMap[t+r-1]+1;for(;e<n.length&&"\u200B\u200C\u200D\uFEFF\xAD".includes(n[e]);)e++;return {start:a,end:e}}function Z(o,t){if(!t||!o)return null;let r=o.indexOf(t);if(r!==-1)return {start:r,end:r+t.length};let n=W(o),a=W(t);if(!a.text)return null;let e=n.text.indexOf(a.text);if(e!==-1)return G(n,e,a.text.length,o);let i=a.text.split(" ");if(i.length>=3)for(let s=1;s<=Math.min(2,i.length-2);s++){let u=i.slice(0,-s).join(" "),l=n.text.indexOf(u);if(l!==-1)return G(n,l,u.length,o)}return null}function Te(o,t,r){let n=new Map,a=(i,s,u)=>{let l=null;for(let c of i.content)if(h(c)){l===null&&(l=w(i));let f=C(c.content),d=c.info.id,x=`${u.noteType??"body"}:${u.noteId??""}:${d}`,y=n.get(x);y&&y.paragraphIndex===s?y.text+=f:n.set(x,{id:d,type:c.type,author:c.info.author,date:c.info.date??null,text:f,context:l,paragraphIndex:s,...u.noteId!==void 0?{noteId:u.noteId}:{},...u.noteType!==void 0?{noteType:u.noteType}:{}});}};if(m(o,(i,s)=>a(i,s,{})),t?.includeFootnotes&&r?.footnotes)for(let i of r.footnotes)k(i,(s,u)=>a(s,u,{noteId:i.id,noteType:"footnote"}));if(t?.includeEndnotes&&r?.endnotes)for(let i of r.endnotes)k(i,(s,u)=>a(s,u,{noteId:i.id,noteType:"endnote"}));return Array.from(n.values()).filter(i=>!(t?.author&&i.author!==t.author||t?.type&&i.type!==t.type))}function Pe(o,t){let r=o.comments??[];if(r.length===0)return [];let n=_(o),a=[],e=new Map;for(let s of r)if(s.parentId!==void 0){let u=e.get(s.parentId)??[];u.push(s),e.set(s.parentId,u);}else a.push(s);return a.map(s=>{let u=n.get(s.id),l=(e.get(s.id)??[]).map(c=>({id:c.id,author:c.author,date:c.date??null,text:X(c)}));return {id:s.id,author:s.author,date:s.date??null,text:X(s),anchoredText:u?.text??"",paragraphIndex:u?.paragraphIndex??-1,replies:l,done:s.done??false}}).filter(s=>!(t?.author&&s.author!==t.author||t?.done!==void 0&&s.done!==t.done))}function X(o){return o.content.map(t=>w(t)).join(`
5
+ `)}function _(o){let t=new Map,r=new Map;return m(o,(n,a)=>{for(let e of n.content)if(e.type==="commentRangeStart")r.set(e.id,{paragraphIndex:a,parts:[]});else if(e.type==="commentRangeEnd"){let i=r.get(e.id);i&&(t.set(e.id,{text:i.parts.join(""),paragraphIndex:i.paragraphIndex}),r.delete(e.id));}else if(e.type==="run"){let i=chunkRTU2ZS7R_js.H(e);for(let s of r.values())s.parts.push(i);}else if(e.type==="hyperlink"){let i=e.children.filter(s=>s.type==="run").map(chunkRTU2ZS7R_js.H).join("");for(let s of r.values())s.parts.push(i);}else if(h(e)){if(e.type==="insertion"||e.type==="moveTo")continue;let i=C(e.content);for(let s of r.values())s.parts.push(i);}}),t}function q(o){let t=o.toDocument().package?.document;if(!t)return new Map;let r=new Map;return m(t,(n,a)=>{r.set(n.paraId??String(a),a),r.set(String(a),a);}),r}function ee(o){let t=[],r=n=>{for(let a of n.content)a.type==="text"&&t.push(a.text??"");};for(let n of o.content)if(n.type==="run")r(n);else if(n.type==="hyperlink")for(let a of n.children)a.type==="run"&&r(a);else if(n.type==="deletion"||n.type==="moveFrom"){for(let a of n.content)if(a.type==="run")r(a);else if(a.type==="hyperlink")for(let e of a.children)e.type==="run"&&r(e);}return t.join("")}function B(o,t){let n={type:"run",content:[{type:"text",text:t,preserveSpace:/^\s|\s$/.test(t)}]};return o.formatting&&(n.formatting={...o.formatting}),o.propertyChanges&&(n.propertyChanges=[...o.propertyChanges]),n}function te(o){return o.content.map(t=>t.type==="text"?t.text:"").join("")}function M(o,t,r,n,a){let e=te(o);if(!e)return;let i=a.value,s=i+e.length;n.push({run:o,parent:t,index:r,text:e,start:i,end:s}),a.value=s;}function J(o,t,r){o.children.forEach((n,a)=>{n.type==="run"&&M(n,o.children,a,t,r);});}function D(o,t){let r=[],n={value:0};return o.content.forEach((a,e)=>{a.type==="run"?M(a,o.content,e,r,n):a.type==="hyperlink"?J(a,r,n):(a.type==="deletion"||a.type==="moveFrom"||t&&(a.type==="insertion"||a.type==="moveTo"))&&a.content.forEach((i,s)=>{i.type==="run"?M(i,a.content,s,r,n):i.type==="hyperlink"&&J(i,r,n);});}),r}function ne(o,t){let r={...o??{}};t.bold!==void 0&&(r.bold=t.bold||void 0),t.italic!==void 0&&(r.italic=t.italic||void 0),t.underline!==void 0&&(t.underline?r.underline={style:typeof t.underline=="object"&&t.underline.style?t.underline.style:"single"}:delete r.underline),t.strike!==void 0&&(r.strike=t.strike||void 0),t.color!==void 0&&(t.color&&(t.color.rgb||t.color.themeColor)?r.color={rgb:t.color.rgb,themeColor:t.color.themeColor}:delete r.color),t.highlight!==void 0&&(t.highlight?r.highlight=chunkRTU2ZS7R_js.va(t.highlight)||t.highlight:delete r.highlight),t.fontSize!==void 0&&(t.fontSize>0?r.fontSize=chunkMMJQ47Q7_js.m(t.fontSize):delete r.fontSize),t.fontFamily!==void 0&&(t.fontFamily&&(t.fontFamily.ascii||t.fontFamily.hAnsi)?r.fontFamily={ascii:t.fontFamily.ascii,hAnsi:t.fontFamily.hAnsi??t.fontFamily.ascii}:delete r.fontFamily);for(let n of Object.keys(r))r[n]===void 0&&delete r[n];return Object.keys(r).length>0?r:void 0}function S(o,t){o.formatting=ne(o.formatting,t);}function oe(o,t,r,n){let a=o.run.content.every(s=>s.type==="text");if(t<=0&&r>=o.text.length||!a){S(o.run,n);return}let e=[];t>0&&e.push(B(o.run,o.text.slice(0,t)));let i=B(o.run,o.text.slice(t,r));S(i,n),e.push(i),r<o.text.length&&e.push(B(o.run,o.text.slice(r))),o.parent.splice(o.index,1,...e);}function re(o,t,r,n){let e=D(o,false).filter(i=>i.start<r&&i.end>t);if(e.length===0)return true;for(let i=e.length-1;i>=0;i--){let s=e[i];oe(s,Math.max(0,t-s.start),Math.min(s.text.length,r-s.start),n);}return true}function ae(o,t){let r=D(o,true);for(let n of r)S(n.run,t);return true}function ie(o,t){if(!t)return null;let n=D(o,false).map(e=>e.text).join(""),a=n.indexOf(t);return a===-1||n.indexOf(t,a+1)!==-1?null:{from:a,to:a+t.length}}function se(o,t){return o?!!o.styles?.some(r=>r.styleId===t&&r.type==="paragraph"):true}function ke(o){let t=new Set,r=null;function n(){return r===null&&(r=q(o)),r}function a(){if(t.size===0)return;let e=o.getComments(),i=o.getChanges(),s={commentCount:e.length,changeCount:i.length,comments:e,changes:i};for(let u of t)try{u(s);}catch(l){console.error("reviewerBridge content listener threw:",l);}}return {getContentAsText(e){return o.getContentAsText(e)},getContent(e){return o.getContent(e)},getComments(e){return o.getComments(e)},getChanges(e){return o.getChanges(e)},findText(e,i){if(!e)return [];let s=i?.caseSensitive??false,u=i?.limit??20,l=s?e:e.toLowerCase(),c=o.toDocument().package?.document;if(!c)return [];let f=[],d=40;return m(c,(x,y)=>{let b=ee(x),E=s?b:b.toLowerCase(),g=E.indexOf(l);if(g===-1||E.indexOf(l,g+1)!==-1)return;let K=b.slice(g,g+e.length);if(f.push({paraId:x.paraId??String(y),match:K,before:b.slice(Math.max(0,g-d),g),after:b.slice(g+e.length,g+e.length+d)}),f.length>=u)return false}),f},getSelection(){return null},addComment(e){let i=n().get(e.paraId);if(i===void 0)return null;try{let s=o.addComment({paragraphIndex:i,text:e.text,author:e.author,search:e.search});return a(),s}catch{return null}},replyTo(e,i){try{let s=o.replyTo(e,i);return a(),s}catch{return null}},resolveComment(e){let s=o.toDocument().package?.document?.comments?.find(u=>u.id===e);if(!s)throw new I(e);s.done=true,a();},proposeChange(e){let i=n().get(e.paraId);if(i===void 0)return false;let s=e.search==="",u=e.replaceWith==="";if(s&&u)return false;try{return s?o.proposeInsertion({paragraphIndex:i,insertText:e.replaceWith,author:e.author}):u?o.proposeDeletion({paragraphIndex:i,search:e.search,author:e.author}):o.replace({paragraphIndex:i,search:e.search,replaceWith:e.replaceWith,author:e.author}),a(),true}catch{return false}},scrollTo(e){return n().has(e)},applyFormatting(e){let i=n().get(e.paraId);if(i===void 0)return false;let s=o.toDocument().package?.document;if(!s)return false;try{let u=s?R(s,i):null;if(!u)return false;if(e.search){let l=ie(u,e.search);if(!l)return false;re(u,l.from,l.to,e.marks);}else ae(u,e.marks);return a(),true}catch{return false}},setParagraphStyle(e){let i=n().get(e.paraId);if(i===void 0)return false;let s=o.toDocument(),u=s.package?.document;if(!u||!se(s.package?.styles,e.styleId))return false;try{let l=R(u,i);return l.formatting={...l.formatting??{},styleId:e.styleId},a(),true}catch{return false}},insertBreak(e){let i=n().get(e.paraId);if(i===void 0)return false;let s=o.toDocument().package?.document;if(!s)return false;try{let u=R(s,i);if(!u)return false;if(e.type==="sectionNextPage"||e.type==="sectionContinuous"){let f=e.type==="sectionNextPage"?"nextPage":"continuous";return u.sectionProperties={...u.sectionProperties??{},sectionStart:f},a(),true}let l=s.content.indexOf(u);if(l===-1)return false;let c={type:"paragraph",content:[{type:"run",content:[{type:"break",breakType:"page"}]}]};return s.content.splice(l+1,0,c),r=null,a(),true}catch{return false}},getPage(){return null},getPages(){return []},getTotalPages(){return 0},getCurrentPage(){return 0},onContentChange(e){return t.add(e),()=>{t.delete(e);}},onSelectionChange(){return ()=>{}}}}exports.a=h;exports.b=R;exports.c=m;exports.d=k;exports.e=fe;exports.f=pe;exports.g=T;exports.h=H;exports.i=I;exports.j=Y;exports.k=xe;exports.l=Te;exports.m=Pe;exports.n=ke;
@@ -1 +1 @@
1
- 'use strict';var chunkYU3OJ2DE_js=require('./chunk-YU3OJ2DE.js'),chunk4C2IJ7OV_js=require('./chunk-4C2IJ7OV.js');function y(n,e){let{paragraphIndex:t,author:o="AI",text:s,search:a}=e,r=chunkYU3OJ2DE_js.b(n,t),c=(n.comments??[]).map(m=>m.id),p=c.length>0?Math.max(...c)+1:1,i={id:p,author:o,date:new Date().toISOString(),content:[{type:"paragraph",content:[{type:"run",content:[{type:"text",text:s}]}],formatting:{}}]};if(n.comments||(n.comments=[]),n.comments.push(i),a){let m=chunkYU3OJ2DE_js.j(r,a,t);r.content.splice(m.endRunIndex+1,0,{type:"commentRangeEnd",id:p}),r.content.splice(m.startRunIndex,0,{type:"commentRangeStart",id:p});}else r.content.unshift({type:"commentRangeStart",id:p}),r.content.push({type:"commentRangeEnd",id:p});return p}function C(n,e,t){let o=n.comments??[];if(!o.find(p=>p.id===e))throw new chunkYU3OJ2DE_js.i(e);let a=o.map(p=>p.id),r=Math.max(...a)+1,c={id:r,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(c),r}function N(n,e){let t=n.comments??[],o=t.find(r=>r.id===e);if(!o)throw new chunkYU3OJ2DE_js.i(e);let s=o.parentId!==void 0,a=new Set([e]);if(!s)for(let r of t)r.parentId===e&&a.add(r.id);n.comments=t.filter(r=>!a.has(r.id)),!s&&chunkYU3OJ2DE_js.c(n,r=>{for(let c=r.content.length-1;c>=0;c--){let p=r.content[c];(p.type==="commentRangeStart"||p.type==="commentRangeEnd")&&p.id===e&&r.content.splice(c,1);}});}function I(n,e,t){if(!W(n,e,"accept",t))throw new chunkYU3OJ2DE_js.h(typeof e=="number"?e:e.id)}function R(n,e,t){if(!W(n,e,"reject",t))throw new chunkYU3OJ2DE_js.h(typeof e=="number"?e:e.id)}function F(n,e,t){return G(n,"accept",e,t)}function M(n,e,t){return G(n,"reject",e,t)}function l(n,e,t){let o=0;for(let s=n.content.length-1;s>=0;s--){let a=n.content[s];chunkYU3OJ2DE_js.a(a)&&t(a)&&(J(n,s,a,e),o++);}return o}function W(n,e,t,o){if(typeof e!="number"&&e.noteType){let a=e.noteType==="footnote"?o?.footnotes:o?.endnotes,r=e.noteId!==void 0?a?.find(c=>c.id===e.noteId):void 0;return r?z(r,e.id,t):false}let s=typeof e=="number"?e:e.id;return q(n,s,t)}function G(n,e,t,o){let s=0;if(chunkYU3OJ2DE_js.c(n,a=>{s+=l(a,e,()=>true);}),t?.includeFootnotes&&o?.footnotes)for(let a of o.footnotes)chunkYU3OJ2DE_js.d(a,r=>{s+=l(r,e,()=>true);});if(t?.includeEndnotes&&o?.endnotes)for(let a of o.endnotes)chunkYU3OJ2DE_js.d(a,r=>{s+=l(r,e,()=>true);});return s}function q(n,e,t){let o=false;return chunkYU3OJ2DE_js.c(n,s=>{if(l(s,t,a=>a.info.id===e)>0&&(o=true),o)return false}),o}function z(n,e,t){let o=false;return chunkYU3OJ2DE_js.d(n,s=>{l(s,t,a=>a.info.id===e)>0&&(o=true);}),o}function J(n,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 a=t.content;n.content.splice(e,1,...a);}else n.content.splice(e,1);}function x(n,e){let{paragraphIndex:t,search:o,author:s="AI",replaceWith:a}=e,r=chunkYU3OJ2DE_js.b(n,t),{startIndex:c,endIndex:p}=chunkYU3OJ2DE_js.k(r,o,t),i=new Date().toISOString(),m=P(n),d=r.content.slice(c,p+1),v={type:"deletion",info:{id:m,author:s,date:i},content:d},b={type:"insertion",info:{id:m+1,author:s,date:i},content:[{type:"run",content:[{type:"text",text:a}]}]};r.content.splice(c,p-c+1,v,b);}function H(n,e){let{paragraphIndex:t,author:o="AI",insertText:s,position:a="after",search:r}=e,c=chunkYU3OJ2DE_js.b(n,t),p=new Date().toISOString(),m={type:"insertion",info:{id:P(n),author:o,date:p},content:[{type:"run",content:[{type:"text",text:s}]}]};if(r){let{startIndex:d,endIndex:v}=chunkYU3OJ2DE_js.k(c,r,t),b=a==="after"?v+1:d;c.content.splice(b,0,m);}else a==="before"?c.content.unshift(m):c.content.push(m);}function L(n,e){let{paragraphIndex:t,search:o,author:s="AI"}=e,a=chunkYU3OJ2DE_js.b(n,t),{startIndex:r,endIndex:c}=chunkYU3OJ2DE_js.k(a,o,t),p=new Date().toISOString(),i=P(n),m=a.content.slice(r,c+1),d={type:"deletion",info:{id:i,author:s,date:p},content:m};a.content.splice(r,c-r+1,d);}var S=new WeakMap;function P(n){let e=S.get(n);e===void 0&&(e=0,chunkYU3OJ2DE_js.c(n,o=>{for(let s of o.content)chunkYU3OJ2DE_js.a(s)&&(e=Math.max(e,s.info.id));}));let t=e+1;return S.set(n,t+1),t}function U(n,e,t="AI"){let o=[],s=0,a=0,r=0,c=0,p=0;for(let i of e.accept??[])try{I(n,i),s++;}catch(m){o.push({operation:"accept",id:i,error:m.message});}for(let i of e.reject??[])try{R(n,i),a++;}catch(m){o.push({operation:"reject",id:i,error:m.message});}for(let i of e.comments??[])try{y(n,{...i,author:i.author??t}),r++;}catch(m){o.push({operation:"comment",search:i.search,error:m.message});}for(let i of e.replies??[])try{C(n,i.commentId,{author:i.author??t,text:i.text}),c++;}catch(m){o.push({operation:"reply",id:i.commentId,error:m.message});}for(let i of e.proposals??[])try{x(n,{...i,author:i.author??t}),p++;}catch(m){o.push({operation:"proposal",search:i.search,error:m.message});}return {accepted:s,rejected:a,commentsAdded:r,repliesAdded:c,proposalsAdded:p,errors:o}}var X=class n{constructor(e,t="AI",o){let s=o??e.originalBuffer,{originalBuffer:a,...r}=e;this.doc=structuredClone(r),s&&(this.doc.originalBuffer=s),this.author=t;}static async fromBuffer(e,t="AI"){let o=await chunk4C2IJ7OV_js.w(e,{preloadFonts:false});return new n(o,t,e)}get body(){return this.doc.package.document}resolveAuthor(e){return e??this.author}getContent(e){return chunkYU3OJ2DE_js.e(this.body,e)}getContentAsText(e){return chunkYU3OJ2DE_js.f(chunkYU3OJ2DE_js.e(this.body,e))}getChanges(e){return chunkYU3OJ2DE_js.l(this.body,e,{footnotes:this.doc.package.footnotes,endnotes:this.doc.package.endnotes})}getComments(e){return chunkYU3OJ2DE_js.m(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 y(this.body,o)}replyTo(e,t){let o=typeof t=="string"?{text:t,author:this.author}:{...t,author:this.resolveAuthor(t.author)};return C(this.body,e,o)}removeComment(e){N(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)};x(this.body,s);}proposeReplacement(e){this.replace(e);}proposeInsertion(e){H(this.body,{...e,author:this.resolveAuthor(e.author)});}proposeDeletion(e){L(this.body,{...e,author:this.resolveAuthor(e.author)});}acceptChange(e){I(this.body,e,this.changeNotes());}rejectChange(e){R(this.body,e,this.changeNotes());}acceptAll(e){return F(this.body,e,this.changeNotes())}rejectAll(e){return M(this.body,e,this.changeNotes())}changeNotes(){return {footnotes:this.doc.package.footnotes,endnotes:this.doc.package.endnotes}}applyReview(e){return U(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-BS5JJGVC.js');return e(this.doc)}};exports.a=X;
1
+ 'use strict';var chunkEX4NO3JP_js=require('./chunk-EX4NO3JP.js'),chunkRTU2ZS7R_js=require('./chunk-RTU2ZS7R.js');function y(n,e){let{paragraphIndex:t,author:o="AI",text:s,search:a}=e,r=chunkEX4NO3JP_js.b(n,t),c=(n.comments??[]).map(m=>m.id),p=c.length>0?Math.max(...c)+1:1,i={id:p,author:o,date:new Date().toISOString(),content:[{type:"paragraph",content:[{type:"run",content:[{type:"text",text:s}]}],formatting:{}}]};if(n.comments||(n.comments=[]),n.comments.push(i),a){let m=chunkEX4NO3JP_js.j(r,a,t);r.content.splice(m.endRunIndex+1,0,{type:"commentRangeEnd",id:p}),r.content.splice(m.startRunIndex,0,{type:"commentRangeStart",id:p});}else r.content.unshift({type:"commentRangeStart",id:p}),r.content.push({type:"commentRangeEnd",id:p});return p}function C(n,e,t){let o=n.comments??[];if(!o.find(p=>p.id===e))throw new chunkEX4NO3JP_js.i(e);let a=o.map(p=>p.id),r=Math.max(...a)+1,c={id:r,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(c),r}function N(n,e){let t=n.comments??[],o=t.find(r=>r.id===e);if(!o)throw new chunkEX4NO3JP_js.i(e);let s=o.parentId!==void 0,a=new Set([e]);if(!s)for(let r of t)r.parentId===e&&a.add(r.id);n.comments=t.filter(r=>!a.has(r.id)),!s&&chunkEX4NO3JP_js.c(n,r=>{for(let c=r.content.length-1;c>=0;c--){let p=r.content[c];(p.type==="commentRangeStart"||p.type==="commentRangeEnd")&&p.id===e&&r.content.splice(c,1);}});}function I(n,e,t){if(!W(n,e,"accept",t))throw new chunkEX4NO3JP_js.h(typeof e=="number"?e:e.id)}function R(n,e,t){if(!W(n,e,"reject",t))throw new chunkEX4NO3JP_js.h(typeof e=="number"?e:e.id)}function F(n,e,t){return G(n,"accept",e,t)}function M(n,e,t){return G(n,"reject",e,t)}function l(n,e,t){let o=0;for(let s=n.content.length-1;s>=0;s--){let a=n.content[s];chunkEX4NO3JP_js.a(a)&&t(a)&&(J(n,s,a,e),o++);}return o}function W(n,e,t,o){if(typeof e!="number"&&e.noteType){let a=e.noteType==="footnote"?o?.footnotes:o?.endnotes,r=e.noteId!==void 0?a?.find(c=>c.id===e.noteId):void 0;return r?z(r,e.id,t):false}let s=typeof e=="number"?e:e.id;return q(n,s,t)}function G(n,e,t,o){let s=0;if(chunkEX4NO3JP_js.c(n,a=>{s+=l(a,e,()=>true);}),t?.includeFootnotes&&o?.footnotes)for(let a of o.footnotes)chunkEX4NO3JP_js.d(a,r=>{s+=l(r,e,()=>true);});if(t?.includeEndnotes&&o?.endnotes)for(let a of o.endnotes)chunkEX4NO3JP_js.d(a,r=>{s+=l(r,e,()=>true);});return s}function q(n,e,t){let o=false;return chunkEX4NO3JP_js.c(n,s=>{if(l(s,t,a=>a.info.id===e)>0&&(o=true),o)return false}),o}function z(n,e,t){let o=false;return chunkEX4NO3JP_js.d(n,s=>{l(s,t,a=>a.info.id===e)>0&&(o=true);}),o}function J(n,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 a=t.content;n.content.splice(e,1,...a);}else n.content.splice(e,1);}function x(n,e){let{paragraphIndex:t,search:o,author:s="AI",replaceWith:a}=e,r=chunkEX4NO3JP_js.b(n,t),{startIndex:c,endIndex:p}=chunkEX4NO3JP_js.k(r,o,t),i=new Date().toISOString(),m=P(n),d=r.content.slice(c,p+1),v={type:"deletion",info:{id:m,author:s,date:i},content:d},b={type:"insertion",info:{id:m+1,author:s,date:i},content:[{type:"run",content:[{type:"text",text:a}]}]};r.content.splice(c,p-c+1,v,b);}function H(n,e){let{paragraphIndex:t,author:o="AI",insertText:s,position:a="after",search:r}=e,c=chunkEX4NO3JP_js.b(n,t),p=new Date().toISOString(),m={type:"insertion",info:{id:P(n),author:o,date:p},content:[{type:"run",content:[{type:"text",text:s}]}]};if(r){let{startIndex:d,endIndex:v}=chunkEX4NO3JP_js.k(c,r,t),b=a==="after"?v+1:d;c.content.splice(b,0,m);}else a==="before"?c.content.unshift(m):c.content.push(m);}function L(n,e){let{paragraphIndex:t,search:o,author:s="AI"}=e,a=chunkEX4NO3JP_js.b(n,t),{startIndex:r,endIndex:c}=chunkEX4NO3JP_js.k(a,o,t),p=new Date().toISOString(),i=P(n),m=a.content.slice(r,c+1),d={type:"deletion",info:{id:i,author:s,date:p},content:m};a.content.splice(r,c-r+1,d);}var S=new WeakMap;function P(n){let e=S.get(n);e===void 0&&(e=0,chunkEX4NO3JP_js.c(n,o=>{for(let s of o.content)chunkEX4NO3JP_js.a(s)&&(e=Math.max(e,s.info.id));}));let t=e+1;return S.set(n,t+1),t}function U(n,e,t="AI"){let o=[],s=0,a=0,r=0,c=0,p=0;for(let i of e.accept??[])try{I(n,i),s++;}catch(m){o.push({operation:"accept",id:i,error:m.message});}for(let i of e.reject??[])try{R(n,i),a++;}catch(m){o.push({operation:"reject",id:i,error:m.message});}for(let i of e.comments??[])try{y(n,{...i,author:i.author??t}),r++;}catch(m){o.push({operation:"comment",search:i.search,error:m.message});}for(let i of e.replies??[])try{C(n,i.commentId,{author:i.author??t,text:i.text}),c++;}catch(m){o.push({operation:"reply",id:i.commentId,error:m.message});}for(let i of e.proposals??[])try{x(n,{...i,author:i.author??t}),p++;}catch(m){o.push({operation:"proposal",search:i.search,error:m.message});}return {accepted:s,rejected:a,commentsAdded:r,repliesAdded:c,proposalsAdded:p,errors:o}}var X=class n{constructor(e,t="AI",o){let s=o??e.originalBuffer,{originalBuffer:a,...r}=e;this.doc=structuredClone(r),s&&(this.doc.originalBuffer=s),this.author=t;}static async fromBuffer(e,t="AI"){let o=await chunkRTU2ZS7R_js.w(e,{preloadFonts:false});return new n(o,t,e)}get body(){return this.doc.package.document}resolveAuthor(e){return e??this.author}getContent(e){return chunkEX4NO3JP_js.e(this.body,e)}getContentAsText(e){return chunkEX4NO3JP_js.f(chunkEX4NO3JP_js.e(this.body,e))}getChanges(e){return chunkEX4NO3JP_js.l(this.body,e,{footnotes:this.doc.package.footnotes,endnotes:this.doc.package.endnotes})}getComments(e){return chunkEX4NO3JP_js.m(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 y(this.body,o)}replyTo(e,t){let o=typeof t=="string"?{text:t,author:this.author}:{...t,author:this.resolveAuthor(t.author)};return C(this.body,e,o)}removeComment(e){N(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)};x(this.body,s);}proposeReplacement(e){this.replace(e);}proposeInsertion(e){H(this.body,{...e,author:this.resolveAuthor(e.author)});}proposeDeletion(e){L(this.body,{...e,author:this.resolveAuthor(e.author)});}acceptChange(e){I(this.body,e,this.changeNotes());}rejectChange(e){R(this.body,e,this.changeNotes());}acceptAll(e){return F(this.body,e,this.changeNotes())}rejectAll(e){return M(this.body,e,this.changeNotes())}changeNotes(){return {footnotes:this.doc.package.footnotes,endnotes:this.doc.package.endnotes}}applyReview(e){return U(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-6GD55ATM.js');return e(this.doc)}};exports.a=X;