@eigenpal/docx-js-editor 0.0.7 → 0.0.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +52 -14
- package/dist/{chunk-FOU7PS3K.cjs → chunk-A7VY2V4X.cjs} +1 -1
- package/dist/chunk-GQ4JYQWC.js +58 -0
- package/dist/{chunk-ZRXLWSRP.cjs → chunk-H3JNHCD7.cjs} +4 -4
- package/dist/{chunk-VFBM3YKJ.js → chunk-L2UUZRZI.js} +4 -4
- package/dist/{chunk-AQ35GWDV.js → chunk-MMJD2DLL.js} +1 -1
- package/dist/chunk-PM4Y7OFN.js +12 -0
- package/dist/{chunk-PYAIJMEG.cjs → chunk-QOIY4Y6N.cjs} +2 -2
- package/dist/chunk-QYKJKSKZ.cjs +58 -0
- package/dist/{chunk-NZ7XUW4I.cjs → chunk-S6FZ7HL6.js} +1 -1
- package/dist/{chunk-AEANV5BR.js → chunk-TPUJJJWA.js} +1 -1
- package/dist/chunk-TRAQI6RX.cjs +12 -0
- package/dist/chunk-Y37VT37I.cjs +1 -0
- package/dist/{colorResolver-CQcFBxHC.d.ts → colorResolver-BNj-uZ58.d.ts} +1 -1
- package/dist/{colorResolver-Di-JRsr9.d.cts → colorResolver-DiMquGWR.d.cts} +1 -1
- package/dist/core-plugins.cjs +1 -1
- package/dist/core-plugins.d.cts +3 -3
- package/dist/core-plugins.d.ts +3 -3
- package/dist/core-plugins.js +1 -1
- package/dist/executor-44OB3DFD.js +1 -0
- package/dist/executor-U3BZPPGN.cjs +1 -0
- package/dist/headless.cjs +2 -2
- package/dist/headless.d.cts +4 -4
- package/dist/headless.d.ts +4 -4
- package/dist/headless.js +2 -2
- package/dist/index.cjs +26 -27
- package/dist/index.css +1 -1
- package/dist/index.d.cts +90 -152
- package/dist/index.d.ts +90 -152
- package/dist/index.js +26 -27
- package/dist/mcp-cli.js +21 -20
- package/dist/mcp.cjs +12 -12
- package/dist/mcp.d.cts +2 -2
- package/dist/mcp.d.ts +2 -2
- package/dist/mcp.js +12 -12
- package/dist/{registry-CrAzNdUO.d.cts → registry-BUTMLqSj.d.cts} +1 -1
- package/dist/{registry-aux2uuQs.d.ts → registry-CzqAPdui.d.ts} +1 -1
- package/dist/selectionRects-I5JVL73G.cjs +1 -0
- package/dist/selectionRects-LO3FJT47.js +1 -0
- package/dist/styles.css +1 -1
- package/dist/{types-BnShY2aQ.d.ts → types-BALm1KBi.d.cts} +3 -1
- package/dist/{types-BnShY2aQ.d.cts → types-BALm1KBi.d.ts} +3 -1
- package/package.json +10 -5
- package/dist/chunk-2CFVFSUH.js +0 -57
- package/dist/chunk-CDSUWDYP.cjs +0 -11
- package/dist/chunk-TL3YTVN2.cjs +0 -57
- package/dist/chunk-W2TDS3UO.js +0 -1
- package/dist/chunk-ZZNWTYMW.js +0 -11
- package/dist/executor-7DZMHPUF.js +0 -1
- package/dist/executor-FSMRGT73.cjs +0 -1
- package/dist/selectionRects-5TGQE33Q.cjs +0 -1
- package/dist/selectionRects-JSPKYXPU.js +0 -1
package/README.md
CHANGED
|
@@ -21,6 +21,17 @@ Open-source WYSIWYG DOCX editor for React. Open, edit, and save `.docx` files en
|
|
|
21
21
|
</a>
|
|
22
22
|
</p>
|
|
23
23
|
|
|
24
|
+
We built it for ourselves in [eigenpal.com](https://eigenpal.com) in order to have an editor for `.docx` files, which serve as AI document workflow output templates for our clients.
|
|
25
|
+
|
|
26
|
+
### Framework Examples
|
|
27
|
+
|
|
28
|
+
| Framework | Example |
|
|
29
|
+
| ------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------- |
|
|
30
|
+
| <img src="https://vite.dev/logo.svg" width="14" /> Vite + React | [`examples/vite`](examples/vite) ([demo](https://docx-js-editor.vercel.app/)) |
|
|
31
|
+
| <img src="https://assets.vercel.com/image/upload/v1662130559/nextjs/Icon_dark_background.png" width="14" /> Next.js | [`examples/nextjs`](examples/nextjs) |
|
|
32
|
+
| <img src="https://remix.run/favicon-192.png" width="14" /> Remix | [`examples/remix`](examples/remix) |
|
|
33
|
+
| <img src="https://astro.build/favicon.svg" width="14" /> Astro | [`examples/astro`](examples/astro) |
|
|
34
|
+
|
|
24
35
|
## Installation
|
|
25
36
|
|
|
26
37
|
```bash
|
|
@@ -57,19 +68,41 @@ function Editor({ file }: { file: ArrayBuffer }) {
|
|
|
57
68
|
|
|
58
69
|
## Props
|
|
59
70
|
|
|
60
|
-
| Prop
|
|
61
|
-
|
|
|
62
|
-
| `documentBuffer`
|
|
63
|
-
| `document`
|
|
64
|
-
| `readOnly`
|
|
65
|
-
| `showToolbar`
|
|
66
|
-
| `showRuler`
|
|
67
|
-
| `
|
|
68
|
-
| `
|
|
69
|
-
| `
|
|
70
|
-
| `
|
|
71
|
-
| `
|
|
72
|
-
| `
|
|
71
|
+
| Prop | Type | Default | Description |
|
|
72
|
+
| ----------------------- | ------------------------------------------- | ----------------- | ------------------------------------------------- |
|
|
73
|
+
| `documentBuffer` | `ArrayBuffer \| Uint8Array \| Blob \| File` | — | `.docx` file contents to load |
|
|
74
|
+
| `document` | `Document` | — | Pre-parsed document (alternative to buffer) |
|
|
75
|
+
| `readOnly` | `boolean` | `false` | Read-only preview (hides toolbar, rulers, panel) |
|
|
76
|
+
| `showToolbar` | `boolean` | `true` | Show formatting toolbar |
|
|
77
|
+
| `showRuler` | `boolean` | `false` | Show horizontal & vertical rulers |
|
|
78
|
+
| `rulerUnit` | `'inch' \| 'cm'` | `'inch'` | Unit for ruler display |
|
|
79
|
+
| `showZoomControl` | `boolean` | `true` | Show zoom controls in toolbar |
|
|
80
|
+
| `showVariablePanel` | `boolean` | `true` | Show template variable panel |
|
|
81
|
+
| `variablePanelPosition` | `'left' \| 'right'` | `'right'` | Variable panel position |
|
|
82
|
+
| `variableDescriptions` | `Record<string, string>` | — | Descriptions for template variables |
|
|
83
|
+
| `showPrintButton` | `boolean` | `true` | Show print button in toolbar |
|
|
84
|
+
| `showPageNumbers` | `boolean` | `true` | Show page number indicator |
|
|
85
|
+
| `enablePageNavigation` | `boolean` | `true` | Enable interactive page navigation |
|
|
86
|
+
| `pageNumberPosition` | `string` | `'bottom-center'` | Position of page number indicator |
|
|
87
|
+
| `showOutline` | `boolean` | `false` | Show document outline sidebar (table of contents) |
|
|
88
|
+
| `showMarginGuides` | `boolean` | `false` | Show page margin guide boundaries |
|
|
89
|
+
| `marginGuideColor` | `string` | `'#c0c0c0'` | Color for margin guides |
|
|
90
|
+
| `initialZoom` | `number` | `1.0` | Initial zoom level |
|
|
91
|
+
| `theme` | `Theme \| null` | — | Theme for styling |
|
|
92
|
+
| `toolbarExtra` | `ReactNode` | — | Custom toolbar items appended to the toolbar |
|
|
93
|
+
| `placeholder` | `ReactNode` | — | Placeholder when no document is loaded |
|
|
94
|
+
| `loadingIndicator` | `ReactNode` | — | Custom loading indicator |
|
|
95
|
+
| `className` | `string` | — | Additional CSS class name |
|
|
96
|
+
| `style` | `CSSProperties` | — | Additional inline styles |
|
|
97
|
+
| `onChange` | `(doc: Document) => void` | — | Called on document change |
|
|
98
|
+
| `onSave` | `(buffer: ArrayBuffer) => void` | — | Called on save |
|
|
99
|
+
| `onError` | `(error: Error) => void` | — | Called on error |
|
|
100
|
+
| `onSelectionChange` | `(state: SelectionState \| null) => void` | — | Called on selection change |
|
|
101
|
+
| `onFontsLoaded` | `() => void` | — | Called when fonts finish loading |
|
|
102
|
+
| `onPrint` | `() => void` | — | Called when print is triggered |
|
|
103
|
+
| `onCopy` | `() => void` | — | Called when content is copied |
|
|
104
|
+
| `onCut` | `() => void` | — | Called when content is cut |
|
|
105
|
+
| `onPaste` | `() => void` | — | Called when content is pasted |
|
|
73
106
|
|
|
74
107
|
## Ref Methods
|
|
75
108
|
|
|
@@ -128,9 +161,14 @@ See [docs/PLUGINS.md](docs/PLUGINS.md) for the full plugin API, including how to
|
|
|
128
161
|
|
|
129
162
|
```bash
|
|
130
163
|
bun install
|
|
131
|
-
bun run dev
|
|
164
|
+
bun run dev # Vite example on localhost:5173
|
|
165
|
+
bun run dev:nextjs # Next.js example on localhost:3000
|
|
166
|
+
bun run dev:remix # Remix example on localhost:3001
|
|
167
|
+
bun run dev:astro # Astro example on localhost:4321
|
|
132
168
|
```
|
|
133
169
|
|
|
170
|
+
Each example is independently deployable. Copy any `examples/<framework>/` directory to start your own project — just `npm install` and go.
|
|
171
|
+
|
|
134
172
|
## License
|
|
135
173
|
|
|
136
174
|
MIT
|
|
@@ -1 +1 @@
|
|
|
1
|
-
'use strict';var chunkXVFMG77A_cjs=require('./chunk-XVFMG77A.cjs');function
|
|
1
|
+
'use strict';var chunkXVFMG77A_cjs=require('./chunk-XVFMG77A.cjs');function v(s,t){let a=chunkXVFMG77A_cjs.b.getCommandHandler(t.type);if(a)return a(s,t);switch(t.type){case "insertText":return R(s,t);case "replaceText":return E(s,t);case "deleteText":return B(s,t);case "formatText":return S(s,t);case "formatParagraph":return V(s,t);case "applyStyle":return $(s,t);case "insertTable":return H(s,t);case "insertImage":return A(s,t);case "insertHyperlink":return F(s,t);case "removeHyperlink":return j(s,t);case "insertParagraphBreak":return T(s,t);case "mergeParagraphs":return N(s,t);case "splitParagraph":return M(s,t);case "setVariable":return O(s,t);case "applyVariables":return _(s,t);default:let r=t;throw new Error(`Unknown command type: ${r.type}`)}}function z(s,t){return t.reduce((a,r)=>v(a,r),s)}function h(s){return JSON.parse(JSON.stringify(s))}function g(s,t){let a=0;for(let r=0;r<s.content.length;r++)if(s.content[r].type==="paragraph"){if(a===t)return r;a++;}return -1}function I(s){let t="";for(let a of s.content)if(a.type==="run")for(let r of a.content)r.type==="text"&&(t+=r.text);else if(a.type==="hyperlink"){for(let r of a.children)if(r.type==="run")for(let e of r.content)e.type==="text"&&(t+=e.text);}return t}function b(s,t){return {type:"run",formatting:t,content:[{type:"text",text:s}]}}function C(s,t,a,r){let e=[],o=0,p=false;for(let n of s.content)if(n.type==="run"){let c=n.content.filter(l=>l.type==="text").map(l=>l.text).join(""),i=o,u=o+c.length;if(!p&&t>=i&&t<=u){let l=t-i;l>0&&e.push({...n,content:[{type:"text",text:c.slice(0,l)}]}),e.push(b(a,r||n.formatting)),l<c.length&&e.push({...n,content:[{type:"text",text:c.slice(l)}]}),p=true;}else e.push(n);o=u;}else e.push(n);return p||e.push(b(a,r)),e}function y(s,t,a){let r=[],e=0;for(let o of s.content)if(o.type==="run"){let p=o.content.filter(i=>i.type==="text").map(i=>i.text).join(""),n=e,c=e+p.length;if(c<=t||n>=a)r.push(o);else {let i="";n<t&&(i+=p.slice(0,t-n)),c>a&&(i+=p.slice(a-n)),i.length>0&&r.push({...o,content:[{type:"text",text:i}]});}e=c;}else r.push(o);return r}function D(s,t,a,r){let e=[],o=0;for(let p of s.content)if(p.type==="run"){let n=p.content.filter(u=>u.type==="text").map(u=>u.text).join(""),c=o,i=o+n.length;if(i<=t||c>=a)e.push(p);else if(c>=t&&i<=a)e.push({...p,formatting:{...p.formatting,...r}});else {let u=Math.max(t,c),l=Math.min(a,i);c<u&&e.push({...p,content:[{type:"text",text:n.slice(0,u-c)}]}),e.push({...p,formatting:{...p.formatting,...r},content:[{type:"text",text:n.slice(u-c,l-c)}]}),i>l&&e.push({...p,content:[{type:"text",text:n.slice(l-c)}]});}o=i;}else e.push(p);return e}function R(s,t){let a=h(s),r=a.package.document,e=g(r,t.position.paragraphIndex);if(e===-1)throw new Error(`Paragraph index ${t.position.paragraphIndex} not found`);let o=r.content[e];return o.content=C(o,t.position.offset,t.text,t.formatting),a}function E(s,t){let a=h(s),r=a.package.document,{start:e,end:o}=t.range;if(e.paragraphIndex===o.paragraphIndex){let p=g(r,e.paragraphIndex);if(p===-1)throw new Error(`Paragraph index ${e.paragraphIndex} not found`);let n=r.content[p];n.content=y(n,e.offset,o.offset),n.content=C(n,e.offset,t.text,t.formatting);}else {let p=g(r,e.paragraphIndex),n=r.content[p],c=I(n);n.content=y(n,e.offset,c.length),n.content=C(n,e.offset,t.text,t.formatting);let i=[];for(let u=e.paragraphIndex+1;u<=o.paragraphIndex;u++)i.push(g(r,u));for(let u=i.length-1;u>=0;u--)i[u]!==-1&&r.content.splice(i[u],1);}return a}function B(s,t){let a=h(s),r=a.package.document,{start:e,end:o}=t.range;if(e.paragraphIndex===o.paragraphIndex){let p=g(r,e.paragraphIndex);if(p===-1)throw new Error(`Paragraph index ${e.paragraphIndex} not found`);let n=r.content[p];n.content=y(n,e.offset,o.offset);}else {let p=g(r,e.paragraphIndex),n=r.content[p],c=I(n);n.content=y(n,e.offset,c.length);let i=g(r,o.paragraphIndex),u=r.content[i];u.content=y(u,0,o.offset),n.content.push(...u.content);let l=[];for(let f=e.paragraphIndex+1;f<=o.paragraphIndex;f++)l.push(g(r,f));for(let f=l.length-1;f>=0;f--)l[f]!==-1&&r.content.splice(l[f],1);}return a}function S(s,t){let a=h(s),r=a.package.document,{start:e,end:o}=t.range;if(e.paragraphIndex===o.paragraphIndex){let p=g(r,e.paragraphIndex);if(p===-1)throw new Error(`Paragraph index ${e.paragraphIndex} not found`);let n=r.content[p];n.content=D(n,e.offset,o.offset,t.formatting);}else for(let p=e.paragraphIndex;p<=o.paragraphIndex;p++){let n=g(r,p);if(n===-1)continue;let c=r.content[n],i=I(c),u=0,l=i.length;p===e.paragraphIndex&&(u=e.offset),p===o.paragraphIndex&&(l=o.offset),c.content=D(c,u,l,t.formatting);}return a}function V(s,t){let a=h(s),r=a.package.document,e=g(r,t.paragraphIndex);if(e===-1)throw new Error(`Paragraph index ${t.paragraphIndex} not found`);let o=r.content[e];if(o.formatting={...o.formatting,...t.formatting},"numPr"in t.formatting){let p=t.formatting.numPr;if(p&&p.numId!==void 0&&p.numId!==0){let n=p.ilvl??0,c=p.numId===1,i=c?"\u2022":"1.";if(a.package.numbering){let u=a.package.numbering.nums.find(l=>l.numId===p.numId);if(u){let l=a.package.numbering.abstractNums.find(f=>f.abstractNumId===u.abstractNumId);if(l){let f=l.levels.find(x=>x.ilvl===n);f&&(i=f.lvlText||i);}}}o.listRendering={level:n,numId:p.numId,marker:i,isBullet:c};}else delete o.listRendering;}return a}function $(s,t){let a=h(s),r=a.package.document,e=g(r,t.paragraphIndex);if(e===-1)throw new Error(`Paragraph index ${t.paragraphIndex} not found`);let o=r.content[e];return o.formatting={...o.formatting,styleId:t.styleId},a}function H(s,t){let a=h(s),r=a.package.document,e=[];for(let n=0;n<t.rows;n++){let c=[];for(let i=0;i<t.columns;i++){let u=t.data?.[n]?.[i]||"";c.push({type:"tableCell",content:[{type:"paragraph",content:u?[b(u)]:[]}]});}e.push({type:"tableRow",formatting:n===0&&t.hasHeader?{header:true}:void 0,cells:c});}let o={type:"table",rows:e},p=g(r,t.position.paragraphIndex);return p===-1?r.content.push(o):r.content.splice(p+1,0,o),a}function A(s,t){let a=h(s),r=a.package.document,e=g(r,t.position.paragraphIndex);if(e===-1)throw new Error(`Paragraph index ${t.position.paragraphIndex} not found`);let o=r.content[e],n={type:"run",content:[{type:"drawing",image:{type:"image",rId:`rId_img_${Date.now()}`,src:t.src,alt:t.alt,size:{width:(t.width||100)*914400,height:(t.height||100)*914400},wrap:{type:"inline"}}}]},c=C(o,t.position.offset,"",void 0),i=false,u=0;for(let l=0;l<c.length;l++){let f=c[l];if(f.type==="run"){let x=f.content.filter(d=>d.type==="text").map(d=>d.text).join("");if(u+=x.length,!i&&u>=t.position.offset){c.splice(l+1,0,n),i=true;break}}}return i||c.push(n),o.content=c,a}function F(s,t){let a=h(s),r=a.package.document,{start:e,end:o}=t.range;if(e.paragraphIndex!==o.paragraphIndex)throw new Error("Hyperlinks cannot span multiple paragraphs");let p=g(r,e.paragraphIndex);if(p===-1)throw new Error(`Paragraph index ${e.paragraphIndex} not found`);let n=r.content[p],c=I(n),i=t.displayText||c.slice(e.offset,o.offset);n.content=y(n,e.offset,o.offset);let u={type:"hyperlink",href:t.url,tooltip:t.tooltip,children:[b(i)]},l=false,f=0,x=[];for(let d of n.content)if(d.type==="run"){let P=d.content.filter(m=>m.type==="text").map(m=>m.text).join(""),w=f+P.length;if(!l&&f<=e.offset&&e.offset<=w){let m=e.offset-f;m>0&&x.push({...d,content:[{type:"text",text:P.slice(0,m)}]}),x.push(u),m<P.length&&x.push({...d,content:[{type:"text",text:P.slice(m)}]}),l=true;}else x.push(d);f=w;}else x.push(d);return l||x.push(u),n.content=x,a}function j(s,t){let a=h(s),r=a.package.document,{start:e}=t.range,o=g(r,e.paragraphIndex);if(o===-1)throw new Error(`Paragraph index ${e.paragraphIndex} not found`);let p=r.content[o],n=[];for(let c of p.content)if(c.type==="hyperlink")for(let i of c.children)i.type==="run"&&n.push(i);else n.push(c);return p.content=n,a}function T(s,t){let a=h(s),r=a.package.document,e=g(r,t.position.paragraphIndex);if(e===-1)throw new Error(`Paragraph index ${t.position.paragraphIndex} not found`);let o=r.content[e],p=I(o),n=y({...o,content:[...o.content]},t.position.offset,p.length),c=y({...o,content:[...o.content]},0,t.position.offset);o.content=n;let i={type:"paragraph",formatting:o.formatting,content:c};return r.content.splice(e+1,0,i),a}function N(s,t){let a=h(s),r=a.package.document,e=g(r,t.paragraphIndex);if(e===-1)throw new Error(`Paragraph index ${t.paragraphIndex} not found`);let o=r.content[e],p=[];for(let n=1;n<=t.count;n++){let c=g(r,t.paragraphIndex+n);if(c!==-1){let i=r.content[c];o.content.push(...i.content),p.push(c);}}for(let n=p.length-1;n>=0;n--)r.content.splice(p[n],1);return a}function M(s,t){return T(s,{position:t.position})}function O(s,t){let a=h(s);return a.templateVariables||(a.templateVariables=[]),a.templateVariables.includes(t.name)||a.templateVariables.push(t.name),a}function _(s,t){let a=h(s),r=a.package.document;function e(n){for(let c of n.content)if(c.type==="text")for(let[i,u]of Object.entries(t.values)){let l=new RegExp(`\\{${i}\\}`,"g");c.text=c.text.replace(l,u);}}function o(n){for(let c of n.content)if(c.type==="run")e(c);else if(c.type==="hyperlink")for(let i of c.children)i.type==="run"&&e(i);}function p(n){if(n.type==="paragraph")o(n);else if(n.type==="table")for(let c of n.rows)for(let i of c.cells)for(let u of i.content)p(u);}for(let n of r.content)p(n);return a}exports.a=v;exports.b=z;
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import {b as b$1}from'./chunk-PM4Y7OFN.js';import R from'jszip';function u(e){return e.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'")}function Z(e){if(!e)return "";let t=[];return e.auto?t.push('w:val="auto"'):e.rgb&&t.push(`w:val="${e.rgb}"`),e.themeColor&&t.push(`w:themeColor="${e.themeColor}"`),e.themeTint&&t.push(`w:themeTint="${e.themeTint}"`),e.themeShade&&t.push(`w:themeShade="${e.themeShade}"`),t.length===0?"":`<w:color ${t.join(" ")}/>`}function Y(e){if(!e)return "";let t=[];return e.pattern?t.push(`w:val="${e.pattern}"`):t.push('w:val="clear"'),e.color?.rgb?t.push(`w:color="${e.color.rgb}"`):e.color?.auto&&t.push('w:color="auto"'),e.fill?.rgb?t.push(`w:fill="${e.fill.rgb}"`):e.fill?.auto&&t.push('w:fill="auto"'),e.fill?.themeColor&&t.push(`w:themeFill="${e.fill.themeColor}"`),e.fill?.themeTint&&t.push(`w:themeFillTint="${e.fill.themeTint}"`),e.fill?.themeShade&&t.push(`w:themeFillShade="${e.fill.themeShade}"`),t.length===0?"":`<w:shd ${t.join(" ")}/>`}function C(e){if(!e)return "";let t=[];if(e.styleId&&t.push(`<w:rStyle w:val="${u(e.styleId)}"/>`),e.fontFamily){let i=[];e.fontFamily.ascii&&i.push(`w:ascii="${u(e.fontFamily.ascii)}"`),e.fontFamily.hAnsi&&i.push(`w:hAnsi="${u(e.fontFamily.hAnsi)}"`),e.fontFamily.eastAsia&&i.push(`w:eastAsia="${u(e.fontFamily.eastAsia)}"`),e.fontFamily.cs&&i.push(`w:cs="${u(e.fontFamily.cs)}"`),e.fontFamily.asciiTheme&&i.push(`w:asciiTheme="${e.fontFamily.asciiTheme}"`),e.fontFamily.hAnsiTheme&&i.push(`w:hAnsiTheme="${e.fontFamily.hAnsiTheme}"`),e.fontFamily.eastAsiaTheme&&i.push(`w:eastAsiaTheme="${e.fontFamily.eastAsiaTheme}"`),e.fontFamily.csTheme&&i.push(`w:csTheme="${e.fontFamily.csTheme}"`),i.length>0&&t.push(`<w:rFonts ${i.join(" ")}/>`);}e.bold===true?t.push("<w:b/>"):e.bold===false&&t.push('<w:b w:val="0"/>'),e.boldCs===true?t.push("<w:bCs/>"):e.boldCs===false&&t.push('<w:bCs w:val="0"/>'),e.italic===true?t.push("<w:i/>"):e.italic===false&&t.push('<w:i w:val="0"/>'),e.italicCs===true?t.push("<w:iCs/>"):e.italicCs===false&&t.push('<w:iCs w:val="0"/>'),e.allCaps&&t.push("<w:caps/>"),e.smallCaps&&t.push("<w:smallCaps/>"),e.strike&&t.push("<w:strike/>"),e.doubleStrike&&t.push("<w:dstrike/>"),e.outline&&t.push("<w:outline/>"),e.shadow&&t.push("<w:shadow/>"),e.emboss&&t.push("<w:emboss/>"),e.imprint&&t.push("<w:imprint/>"),e.hidden&&t.push("<w:vanish/>");let n=Z(e.color);if(n&&t.push(n),e.spacing!==void 0&&t.push(`<w:spacing w:val="${e.spacing}"/>`),e.scale!==void 0&&t.push(`<w:w w:val="${e.scale}"/>`),e.kerning!==void 0&&t.push(`<w:kern w:val="${e.kerning}"/>`),e.position!==void 0&&t.push(`<w:position w:val="${e.position}"/>`),e.fontSize!==void 0&&t.push(`<w:sz w:val="${e.fontSize}"/>`),e.fontSizeCs!==void 0&&t.push(`<w:szCs w:val="${e.fontSizeCs}"/>`),e.highlight&&e.highlight!=="none"&&new Set(["black","blue","cyan","darkBlue","darkCyan","darkGray","darkGreen","darkMagenta","darkRed","darkYellow","green","lightGray","magenta","red","white","yellow"]).has(e.highlight)&&t.push(`<w:highlight w:val="${e.highlight}"/>`),e.underline){let i=[`w:val="${e.underline.style}"`];e.underline.color&&(e.underline.color.rgb&&i.push(`w:color="${e.underline.color.rgb}"`),e.underline.color.themeColor&&i.push(`w:themeColor="${e.underline.color.themeColor}"`)),t.push(`<w:u ${i.join(" ")}/>`);}e.effect&&e.effect!=="none"&&t.push(`<w:effect w:val="${e.effect}"/>`),e.emphasisMark&&e.emphasisMark!=="none"&&t.push(`<w:em w:val="${e.emphasisMark}"/>`);let r=Y(e.shading);return r&&t.push(r),e.vertAlign&&e.vertAlign!=="baseline"&&t.push(`<w:vertAlign w:val="${e.vertAlign}"/>`),e.rtl&&t.push("<w:rtl/>"),e.cs&&t.push("<w:cs/>"),t.length===0?"":`<w:rPr>${t.join("")}</w:rPr>`}function J(e){return `<w:t${e.preserveSpace||e.text.startsWith(" ")||e.text.endsWith(" ")||e.text.includes(" ")?' xml:space="preserve"':""}>${u(e.text)}</w:t>`}function K(e){return "<w:tab/>"}function Q(e){let t=[];return e.breakType==="page"?t.push('w:type="page"'):e.breakType==="column"?t.push('w:type="column"'):e.breakType==="textWrapping"&&(t.push('w:type="textWrapping"'),e.clear&&e.clear!=="none"&&t.push(`w:clear="${e.clear}"`)),t.length===0?"<w:br/>":`<w:br ${t.join(" ")}/>`}function ee(e){return `<w:sym w:font="${u(e.font)}" w:char="${u(e.char)}"/>`}function te(e){return e.type==="footnoteRef"?`<w:footnoteReference w:id="${e.id}"/>`:`<w:endnoteReference w:id="${e.id}"/>`}function ne(e){let t=[`w:fldCharType="${e.charType}"`];return e.fldLock&&t.push('w:fldLock="true"'),e.dirty&&t.push('w:dirty="true"'),`<w:fldChar ${t.join(" ")}/>`}function re(e){return `<w:instrText${e.text.startsWith(" ")||e.text.endsWith(" ")||e.text.includes(" ")?' xml:space="preserve"':""}>${u(e.text)}</w:instrText>`}function ie(e){return "<w:softHyphen/>"}function se(e){return "<w:noBreakHyphen/>"}function B(e){if(!e)return "";if(e.rgb)return `<a:srgbClr val="${e.rgb.replace("#","")}"/>`;if(e.themeColor){let t=`<a:schemeClr val="${e.themeColor}"`;return e.themeTint?t+=`><a:tint val="${e.themeTint}"/></a:schemeClr>`:e.themeShade?t+=`><a:shade val="${e.themeShade}"/></a:schemeClr>`:t+="/>",t}return ""}function oe(e){if(!e||e.type==="none")return "<a:noFill/>";if(e.type==="solid"&&e.color)return `<a:solidFill>${B(e.color)}</a:solidFill>`;if(e.type==="gradient"&&e.gradient){let t=e.gradient,n=t.stops.map(i=>`<a:gs pos="${i.position}">${B(i.color)}</a:gs>`).join(""),r=t.type==="linear"?`<a:lin ang="${(t.angle||0)*6e4}" scaled="1"/>`:"";return `<a:gradFill><a:gsLst>${n}</a:gsLst>${r}</a:gradFill>`}return ""}function j(e){if(!e)return "";let t=[];e.width!=null&&t.push(`w="${e.width}"`),e.cap&&t.push(`cap="${e.cap}"`);let n=[];return e.color&&n.push(`<a:solidFill>${B(e.color)}</a:solidFill>`),e.style&&e.style!=="solid"&&n.push(`<a:prstDash val="${e.style}"/>`),e.headEnd&&n.push(`<a:headEnd type="${e.headEnd.type}"${e.headEnd.width?` w="${e.headEnd.width}"`:""}${e.headEnd.length?` len="${e.headEnd.length}"`:""}/>`),e.tailEnd&&n.push(`<a:tailEnd type="${e.tailEnd.type}"${e.tailEnd.width?` w="${e.tailEnd.width}"`:""}${e.tailEnd.length?` len="${e.tailEnd.length}"`:""}/>`),n.length===0&&t.length===0?"":`<a:ln${t.length?" "+t.join(" "):""}>${n.join("")}</a:ln>`}function E(e){let t=[],n=e.horizontal;t.push(`<wp:positionH relativeFrom="${n.relativeTo}">`),n.alignment?t.push(`<wp:align>${n.alignment}</wp:align>`):t.push(`<wp:posOffset>${n.posOffset||0}</wp:posOffset>`),t.push("</wp:positionH>");let r=e.vertical;return t.push(`<wp:positionV relativeFrom="${r.relativeTo}">`),r.alignment?t.push(`<wp:align>${r.alignment}</wp:align>`):t.push(`<wp:posOffset>${r.posOffset||0}</wp:posOffset>`),t.push("</wp:positionV>"),t.join("")}function I(e){let t=e.wrapText?` wrapText="${e.wrapText}"`:' wrapText="bothSides"';switch(e.type){case "square":return `<wp:wrapSquare${t}/>`;case "tight":return `<wp:wrapTight${t}><wp:wrapPolygon edited="0"><wp:start x="0" y="0"/><wp:lineTo x="0" y="21600"/><wp:lineTo x="21600" y="21600"/><wp:lineTo x="21600" y="0"/><wp:lineTo x="0" y="0"/></wp:wrapPolygon></wp:wrapTight>`;case "through":return `<wp:wrapThrough${t}><wp:wrapPolygon edited="0"><wp:start x="0" y="0"/><wp:lineTo x="0" y="21600"/><wp:lineTo x="21600" y="21600"/><wp:lineTo x="21600" y="0"/><wp:lineTo x="0" y="0"/></wp:wrapPolygon></wp:wrapThrough>`;case "topAndBottom":return "<wp:wrapTopAndBottom/>";case "behind":case "inFront":return "<wp:wrapNone/>";default:return "<wp:wrapNone/>"}}function ae(e){let t=e.size.width,n=e.size.height,r=e.rId||"rId1",i=e.id||"0",s=e.filename||`image${i}`,o="";return e.transform?.rotation&&(o+=` rot="${Math.round(e.transform.rotation*6e4)}"`),e.transform?.flipH&&(o+=' flipH="1"'),e.transform?.flipV&&(o+=' flipV="1"'),['<a:graphic xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main">','<a:graphicData uri="http://schemas.openxmlformats.org/drawingml/2006/picture">','<pic:pic xmlns:pic="http://schemas.openxmlformats.org/drawingml/2006/picture">',"<pic:nvPicPr>",`<pic:cNvPr id="${i}" name="${u(s)}"${e.alt?` descr="${u(e.alt)}"`:""}/>`,"<pic:cNvPicPr/>","</pic:nvPicPr>","<pic:blipFill>",`<a:blip r:embed="${r}"/>`,"<a:stretch><a:fillRect/></a:stretch>","</pic:blipFill>","<pic:spPr>",`<a:xfrm${o}>`,'<a:off x="0" y="0"/>',`<a:ext cx="${t}" cy="${n}"/>`,"</a:xfrm>",'<a:prstGeom prst="rect"><a:avLst/></a:prstGeom>',e.outline?j(e.outline):"","</pic:spPr>","</pic:pic>","</a:graphicData>","</a:graphic>"].join("")}function ce(e){let t=e.image,n=t.wrap.type!=="inline",r=t.size.width,i=t.size.height,s=t.padding?.top??t.wrap.distT??0,o=t.padding?.bottom??t.wrap.distB??0,a=t.padding?.left??t.wrap.distL??0,l=t.padding?.right??t.wrap.distR??0,c=t.id||"1",p=t.title||t.filename||`Picture ${c}`,m=ae(t);if(!n)return ["<w:drawing>",`<wp:inline distT="${s}" distB="${o}" distL="${a}" distR="${l}">`,`<wp:extent cx="${r}" cy="${i}"/>`,'<wp:effectExtent l="0" t="0" r="0" b="0"/>',`<wp:docPr id="${c}" name="${u(p)}"${t.alt?` descr="${u(t.alt)}"`:""}${t.decorative?' hidden="1"':""}/>`,'<wp:cNvGraphicFramePr><a:graphicFrameLocks xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main" noChangeAspect="1"/></wp:cNvGraphicFramePr>',m,"</wp:inline>","</w:drawing>"].join("");let w=t.wrap.type==="behind"?"1":"0",S=t.position?E(t.position):'<wp:positionH relativeFrom="column"><wp:posOffset>0</wp:posOffset></wp:positionH><wp:positionV relativeFrom="paragraph"><wp:posOffset>0</wp:posOffset></wp:positionV>',P=I(t.wrap);return ["<w:drawing>",`<wp:anchor distT="${s}" distB="${o}" distL="${a}" distR="${l}" simplePos="0" relativeHeight="251658240" behindDoc="${w}" locked="0" layoutInCell="1" allowOverlap="1">`,'<wp:simplePos x="0" y="0"/>',S,`<wp:extent cx="${r}" cy="${i}"/>`,'<wp:effectExtent l="0" t="0" r="0" b="0"/>',P,`<wp:docPr id="${c}" name="${u(p)}"${t.alt?` descr="${u(t.alt)}"`:""}/>`,'<wp:cNvGraphicFramePr><a:graphicFrameLocks xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main" noChangeAspect="1"/></wp:cNvGraphicFramePr>',m,"</wp:anchor>","</w:drawing>"].join("")}function pe(e){return e.map(t=>y(t)).join("")}function le(e){let t=e.shape,n=t.size.width,r=t.size.height,i=t.shapeType==="textBox",s=t.wrap&&t.wrap.type!=="inline",o=t.wrap?.distT??0,a=t.wrap?.distB??0,l=t.wrap?.distL??0,c=t.wrap?.distR??0,p=t.id||"1",m=t.name||(i?`TextBox ${p}`:`Shape ${p}`),w="";t.transform?.rotation&&(w+=` rot="${Math.round(t.transform.rotation*6e4)}"`),t.transform?.flipH&&(w+=' flipH="1"'),t.transform?.flipV&&(w+=' flipV="1"');let S=["<wps:spPr>",`<a:xfrm${w}>`,'<a:off x="0" y="0"/>',`<a:ext cx="${n}" cy="${r}"/>`,"</a:xfrm>",`<a:prstGeom prst="${t.shapeType==="textBox"?"rect":t.shapeType}"><a:avLst/></a:prstGeom>`,oe(t.fill),j(t.outline),"</wps:spPr>"].join(""),P="";if(t.textBody){let h=t.textBody,g=['rot="0"','vert="horz"'];h.anchor&&g.push(`anchor="${h.anchor==="middle"?"ctr":h.anchor}"`),h.anchorCenter&&g.push('anchorCtr="1"'),h.margins&&(h.margins.left!=null&&g.push(`lIns="${h.margins.left}"`),h.margins.top!=null&&g.push(`tIns="${h.margins.top}"`),h.margins.right!=null&&g.push(`rIns="${h.margins.right}"`),h.margins.bottom!=null&&g.push(`bIns="${h.margins.bottom}"`)),i?P=["<wps:txbx><w:txbxContent>",pe(h.content),"</w:txbxContent></wps:txbx>",`<wps:bodyPr ${g.join(" ")}/>`].join(""):P=[`<wps:bodyPr ${g.join(" ")}/>`].join("");}let k=['<a:graphic xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main">','<a:graphicData uri="http://schemas.microsoft.com/office/word/2010/wordprocessingShape">',["<wps:wsp>",`<wps:cNvSpPr${i?' txBox="1"':""}/>`,S,P,"</wps:wsp>"].join(""),"</a:graphicData>","</a:graphic>"].join("");if(!s)return ["<w:drawing>",`<wp:inline distT="${o}" distB="${a}" distL="${l}" distR="${c}">`,`<wp:extent cx="${n}" cy="${r}"/>`,'<wp:effectExtent l="0" t="0" r="0" b="0"/>',`<wp:docPr id="${p}" name="${u(m)}"/>`,"<wp:cNvGraphicFramePr/>",k,"</wp:inline>","</w:drawing>"].join("");let _=t.wrap?.type==="behind"?"1":"0",q=t.position?E(t.position):'<wp:positionH relativeFrom="column"><wp:posOffset>0</wp:posOffset></wp:positionH><wp:positionV relativeFrom="paragraph"><wp:posOffset>0</wp:posOffset></wp:positionV>',U=I(t.wrap);return ["<w:drawing>",`<wp:anchor distT="${o}" distB="${a}" distL="${l}" distR="${c}" simplePos="0" relativeHeight="251658240" behindDoc="${_}" locked="0" layoutInCell="1" allowOverlap="1">`,'<wp:simplePos x="0" y="0"/>',q,`<wp:extent cx="${n}" cy="${r}"/>`,'<wp:effectExtent l="0" t="0" r="0" b="0"/>',U,`<wp:docPr id="${p}" name="${u(m)}"/>`,"<wp:cNvGraphicFramePr/>",k,"</wp:anchor>","</w:drawing>"].join("")}function ue(e){switch(e.type){case "text":return J(e);case "tab":return K();case "break":return Q(e);case "symbol":return ee(e);case "footnoteRef":case "endnoteRef":return te(e);case "fieldChar":return ne(e);case "instrText":return re(e);case "softHyphen":return ie();case "noBreakHyphen":return se();case "drawing":return ce(e);case "shape":return le(e);default:return ""}}function x(e){let t=[],n=C(e.formatting);n&&t.push(n);for(let r of e.content){let i=ue(r);i&&t.push(i);}return `<w:r>${t.join("")}</w:r>`}function f(e){return e.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'")}function T(e,t){if(!e||e.style==="none"||e.style==="nil")return "";let n=[`w:val="${e.style}"`];return e.size!==void 0&&n.push(`w:sz="${e.size}"`),e.space!==void 0&&n.push(`w:space="${e.space}"`),e.color&&(e.color.auto?n.push('w:color="auto"'):e.color.rgb&&n.push(`w:color="${e.color.rgb}"`),e.color.themeColor&&n.push(`w:themeColor="${e.color.themeColor}"`),e.color.themeTint&&n.push(`w:themeTint="${e.color.themeTint}"`),e.color.themeShade&&n.push(`w:themeShade="${e.color.themeShade}"`)),e.shadow&&n.push('w:shadow="true"'),e.frame&&n.push('w:frame="true"'),`<w:${t} ${n.join(" ")}/>`}function fe(e){if(!e)return "";let t=[];if(e.top){let n=T(e.top,"top");n&&t.push(n);}if(e.left){let n=T(e.left,"left");n&&t.push(n);}if(e.bottom){let n=T(e.bottom,"bottom");n&&t.push(n);}if(e.right){let n=T(e.right,"right");n&&t.push(n);}if(e.between){let n=T(e.between,"between");n&&t.push(n);}if(e.bar){let n=T(e.bar,"bar");n&&t.push(n);}return t.length===0?"":`<w:pBdr>${t.join("")}</w:pBdr>`}function he(e){if(!e)return "";let t=[];return e.pattern?t.push(`w:val="${e.pattern}"`):t.push('w:val="clear"'),e.color?.rgb?t.push(`w:color="${e.color.rgb}"`):e.color?.auto&&t.push('w:color="auto"'),e.fill?.rgb?t.push(`w:fill="${e.fill.rgb}"`):e.fill?.auto&&t.push('w:fill="auto"'),e.fill?.themeColor&&t.push(`w:themeFill="${e.fill.themeColor}"`),e.fill?.themeTint&&t.push(`w:themeFillTint="${e.fill.themeTint}"`),e.fill?.themeShade&&t.push(`w:themeFillShade="${e.fill.themeShade}"`),t.length===0?"":`<w:shd ${t.join(" ")}/>`}function de(e){return !e||e.length===0?"":`<w:tabs>${e.map(n=>{let r=[`w:val="${n.alignment}"`,`w:pos="${n.position}"`];return n.leader&&n.leader!=="none"&&r.push(`w:leader="${n.leader}"`),`<w:tab ${r.join(" ")}/>`}).join("")}</w:tabs>`}function me(e){let t=[];return e.spaceBefore!==void 0&&t.push(`w:before="${e.spaceBefore}"`),e.spaceAfter!==void 0&&t.push(`w:after="${e.spaceAfter}"`),e.lineSpacing!==void 0&&t.push(`w:line="${e.lineSpacing}"`),e.lineSpacingRule&&t.push(`w:lineRule="${e.lineSpacingRule}"`),e.beforeAutospacing&&t.push('w:beforeAutospacing="1"'),e.afterAutospacing&&t.push('w:afterAutospacing="1"'),t.length===0?"":`<w:spacing ${t.join(" ")}/>`}function we(e){let t=[];return e.indentLeft!==void 0&&t.push(`w:left="${e.indentLeft}"`),e.indentRight!==void 0&&t.push(`w:right="${e.indentRight}"`),e.indentFirstLine!==void 0&&(e.hangingIndent?t.push(`w:hanging="${Math.abs(e.indentFirstLine)}"`):e.indentFirstLine!==0&&t.push(`w:firstLine="${e.indentFirstLine}"`)),t.length===0?"":`<w:ind ${t.join(" ")}/>`}function ge(e){if(!e)return "";let t=[];return e.ilvl!==void 0&&t.push(`<w:ilvl w:val="${e.ilvl}"/>`),e.numId!==void 0&&t.push(`<w:numId w:val="${e.numId}"/>`),t.length===0?"":`<w:numPr>${t.join("")}</w:numPr>`}function xe(e){if(!e)return "";let t=[];return e.width!==void 0&&t.push(`w:w="${e.width}"`),e.height!==void 0&&t.push(`w:h="${e.height}"`),e.hAnchor&&t.push(`w:hAnchor="${e.hAnchor}"`),e.vAnchor&&t.push(`w:vAnchor="${e.vAnchor}"`),e.x!==void 0&&t.push(`w:x="${e.x}"`),e.y!==void 0&&t.push(`w:y="${e.y}"`),e.xAlign&&t.push(`w:xAlign="${e.xAlign}"`),e.yAlign&&t.push(`w:yAlign="${e.yAlign}"`),e.wrap&&t.push(`w:wrap="${e.wrap}"`),t.length===0?"":`<w:framePr ${t.join(" ")}/>`}function ye(e){if(!e)return "";let t=[];e.styleId&&t.push(`<w:pStyle w:val="${f(e.styleId)}"/>`),e.keepNext&&t.push("<w:keepNext/>"),e.keepLines&&t.push("<w:keepLines/>"),e.contextualSpacing&&t.push("<w:contextualSpacing/>"),e.pageBreakBefore&&t.push("<w:pageBreakBefore/>");let n=xe(e.frame);n&&t.push(n),e.widowControl===false?t.push('<w:widowControl w:val="0"/>'):e.widowControl===true&&t.push("<w:widowControl/>");let r=ge(e.numPr);r&&t.push(r);let i=fe(e.borders);i&&t.push(i);let s=he(e.shading);s&&t.push(s);let o=de(e.tabs);o&&t.push(o),e.suppressLineNumbers&&t.push("<w:suppressLineNumbers/>"),e.suppressAutoHyphens&&t.push("<w:suppressAutoHyphens/>");let a=me(e);a&&t.push(a);let l=we(e);if(l&&t.push(l),e.bidi&&t.push("<w:bidi/>"),e.alignment&&t.push(`<w:jc w:val="${e.alignment}"/>`),e.outlineLevel!==void 0&&t.push(`<w:outlineLvl w:val="${e.outlineLevel}"/>`),e.runProperties){let c=C(e.runProperties);c&&t.push(c);}return t.length===0?"":`<w:pPr>${t.join("")}</w:pPr>`}function z(e){let t=[];e.rId&&t.push(`r:id="${e.rId}"`),e.anchor&&t.push(`w:anchor="${f(e.anchor)}"`),e.tooltip&&t.push(`w:tooltip="${f(e.tooltip)}"`),e.target&&t.push(`w:tgtFrame="${f(e.target)}"`),e.history===false&&t.push('w:history="0"'),e.docLocation&&t.push(`w:docLocation="${f(e.docLocation)}"`);let n=e.children.map(i=>i.type==="run"?x(i):i.type==="bookmarkStart"?L(i):i.type==="bookmarkEnd"?O(i):"").join("");return `<w:hyperlink${t.length>0?" "+t.join(" "):""}>${n}</w:hyperlink>`}function L(e){let t=[`w:id="${e.id}"`,`w:name="${f(e.name)}"`];return e.colFirst!==void 0&&t.push(`w:colFirst="${e.colFirst}"`),e.colLast!==void 0&&t.push(`w:colLast="${e.colLast}"`),`<w:bookmarkStart ${t.join(" ")}/>`}function O(e){return `<w:bookmarkEnd w:id="${e.id}"/>`}function $e(e){let t=[],n=e.content.find(a=>a.type==="run"),r=n?.formatting?C(n.formatting):"",i=['w:fldCharType="begin"'];e.fldLock&&i.push('w:fldLock="true"'),t.push(`<w:r>${r}<w:fldChar ${i.join(" ")}/></w:r>`);let o=e.instruction.startsWith(" ")||e.instruction.endsWith(" ")||e.instruction.includes(" ")?' xml:space="preserve"':"";t.push(`<w:r>${r}<w:instrText${o}>${f(e.instruction)}</w:instrText></w:r>`),t.push(`<w:r>${r}<w:fldChar w:fldCharType="separate"/></w:r>`);for(let a of e.content)a.type==="run"&&t.push(x(a));return t.push(`<w:r>${r}<w:fldChar w:fldCharType="end"/></w:r>`),t.join("")}function Te(e){let t=[],n=e.fieldResult?.[0]?.formatting,r=n?C(n):"",i=['w:fldCharType="begin"'];if(e.fldLock&&i.push('w:fldLock="true"'),t.push(`<w:r>${r}<w:fldChar ${i.join(" ")}/></w:r>`),e.fieldCode.length>0)t.push(...e.fieldCode.map(s=>x(s)));else {let o=e.instruction.startsWith(" ")||e.instruction.endsWith(" ")||e.instruction.includes(" ")?' xml:space="preserve"':"";t.push(`<w:r>${r}<w:instrText${o}>${f(e.instruction)}</w:instrText></w:r>`);}return t.push(`<w:r>${r}<w:fldChar w:fldCharType="separate"/></w:r>`),t.push(...e.fieldResult.map(s=>x(s))),t.push(`<w:r>${r}<w:fldChar w:fldCharType="end"/></w:r>`),t.join("")}function be(e){let t=e.properties,n=[];switch(t.alias&&n.push(`<w:alias w:val="${f(t.alias)}"/>`),t.tag&&n.push(`<w:tag w:val="${f(t.tag)}"/>`),t.lock&&t.lock!=="unlocked"&&n.push(`<w:lock w:val="${t.lock}"/>`),t.showingPlaceholder&&n.push("<w:showingPlcHdr/>"),t.sdtType){case "plainText":n.push("<w:text/>");break;case "date":t.dateFormat?n.push(`<w:date w:fullDate="${f(t.dateFormat)}"/>`):n.push("<w:date/>");break;case "dropdown":{let i=(t.listItems??[]).map(s=>`<w:listItem w:displayText="${f(s.displayText)}" w:value="${f(s.value)}"/>`).join("");n.push(`<w:dropDownList>${i}</w:dropDownList>`);break}case "comboBox":{let i=(t.listItems??[]).map(s=>`<w:listItem w:displayText="${f(s.displayText)}" w:value="${f(s.value)}"/>`).join("");n.push(`<w:comboBox>${i}</w:comboBox>`);break}case "checkbox":n.push(`<w14:checkbox><w14:checked w14:val="${t.checked?"1":"0"}"/></w14:checkbox>`);break;case "picture":n.push("<w:picture/>");break}let r=e.content.map(i=>i.type==="run"?x(i):i.type==="hyperlink"?z(i):"").join("");return `<w:sdt><w:sdtPr>${n.join("")}</w:sdtPr><w:sdtContent>${r}</w:sdtContent></w:sdt>`}function X(e,t){let n=t.info,r=[`w:id="${n.id}"`,`w:author="${f(n.author)}"`];n.date&&r.push(`w:date="${f(n.date)}"`);let i=t.content.map(s=>s.type==="run"?x(s):s.type==="hyperlink"?z(s):"").join("");return `<w:${e} ${r.join(" ")}>${i}</w:${e}>`}function Pe(e){switch(e.type){case "run":return x(e);case "hyperlink":return z(e);case "bookmarkStart":return L(e);case "bookmarkEnd":return O(e);case "simpleField":return $e(e);case "complexField":return Te(e);case "inlineSdt":return be(e);case "commentRangeStart":return `<w:commentRangeStart w:id="${e.id}"/>`;case "commentRangeEnd":return `<w:commentRangeEnd w:id="${e.id}"/>`;case "insertion":return X("ins",e);case "deletion":return X("del",e);case "mathEquation":return e.ommlXml||"";default:return ""}}function y(e){let t=[],n=[];e.paraId&&n.push(`w14:paraId="${e.paraId}"`),e.textId&&n.push(`w14:textId="${e.textId}"`);let r=n.length>0?" "+n.join(" "):"",i=ye(e.formatting);i&&t.push(i);for(let s of e.content){let o=Pe(s);o&&t.push(o);}return `<w:p${r}>${t.join("")}</w:p>`}function Ce(e){return e.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'")}function $(e,t){if(!e)return "";let n=[`w:w="${e.value}"`,`w:type="${e.type}"`];return `<w:${t} ${n.join(" ")}/>`}function b(e,t){if(!e||e.style==="none"||e.style==="nil")return "";let n=[`w:val="${e.style}"`];return e.size!==void 0&&n.push(`w:sz="${e.size}"`),e.space!==void 0&&n.push(`w:space="${e.space}"`),e.color&&(e.color.auto?n.push('w:color="auto"'):e.color.rgb&&n.push(`w:color="${e.color.rgb}"`),e.color.themeColor&&n.push(`w:themeColor="${e.color.themeColor}"`),e.color.themeTint&&n.push(`w:themeTint="${e.color.themeTint}"`),e.color.themeShade&&n.push(`w:themeShade="${e.color.themeShade}"`)),e.shadow&&n.push('w:shadow="true"'),e.frame&&n.push('w:frame="true"'),`<w:${t} ${n.join(" ")}/>`}function H(e,t){if(!e)return "";let n=[];if(e.top){let r=b(e.top,"top");r&&n.push(r);}if(e.left){let r=b(e.left,"left");r&&n.push(r);}if(e.bottom){let r=b(e.bottom,"bottom");r&&n.push(r);}if(e.right){let r=b(e.right,"right");r&&n.push(r);}if(e.insideH){let r=b(e.insideH,"insideH");r&&n.push(r);}if(e.insideV){let r=b(e.insideV,"insideV");r&&n.push(r);}return n.length===0?"":`<w:${t}>${n.join("")}</w:${t}>`}function M(e,t){if(!e)return "";let n=[];return e.top&&n.push($(e.top,"top")),e.left&&n.push($(e.left,"left")),e.bottom&&n.push($(e.bottom,"bottom")),e.right&&n.push($(e.right,"right")),n.length===0?"":`<w:${t}>${n.join("")}</w:${t}>`}function N(e){if(!e)return "";let t=[];return e.pattern?t.push(`w:val="${e.pattern}"`):t.push('w:val="clear"'),e.color?.rgb?t.push(`w:color="${e.color.rgb}"`):e.color?.auto&&t.push('w:color="auto"'),e.fill?.rgb?t.push(`w:fill="${e.fill.rgb}"`):e.fill?.auto&&t.push('w:fill="auto"'),e.fill?.themeColor&&t.push(`w:themeFill="${e.fill.themeColor}"`),e.fill?.themeTint&&t.push(`w:themeFillTint="${e.fill.themeTint}"`),e.fill?.themeShade&&t.push(`w:themeFillShade="${e.fill.themeShade}"`),t.length===0?"":`<w:shd ${t.join(" ")}/>`}function ve(e){if(!e)return "";let t=[];return e.firstRow&&t.push('w:firstRow="1"'),e.lastRow&&t.push('w:lastRow="1"'),e.firstColumn&&t.push('w:firstColumn="1"'),e.lastColumn&&t.push('w:lastColumn="1"'),e.noHBand&&t.push('w:noHBand="1"'),e.noVBand&&t.push('w:noVBand="1"'),t.length===0?"":`<w:tblLook ${t.join(" ")}/>`}function Fe(e){if(!e)return "";let t=[];return e.horzAnchor&&t.push(`w:horzAnchor="${e.horzAnchor}"`),e.vertAnchor&&t.push(`w:vertAnchor="${e.vertAnchor}"`),e.tblpX!==void 0&&t.push(`w:tblpX="${e.tblpX}"`),e.tblpXSpec&&t.push(`w:tblpXSpec="${e.tblpXSpec}"`),e.tblpY!==void 0&&t.push(`w:tblpY="${e.tblpY}"`),e.tblpYSpec&&t.push(`w:tblpYSpec="${e.tblpYSpec}"`),e.topFromText!==void 0&&t.push(`w:topFromText="${e.topFromText}"`),e.bottomFromText!==void 0&&t.push(`w:bottomFromText="${e.bottomFromText}"`),e.leftFromText!==void 0&&t.push(`w:leftFromText="${e.leftFromText}"`),e.rightFromText!==void 0&&t.push(`w:rightFromText="${e.rightFromText}"`),t.length===0?"":`<w:tblpPr ${t.join(" ")}/>`}function Se(e){if(!e)return "";let t=[];e.styleId&&t.push(`<w:tblStyle w:val="${Ce(e.styleId)}"/>`);let n=Fe(e.floating);n&&t.push(n),e.bidi&&t.push("<w:bidiVisual/>");let r=$(e.width,"tblW");r&&t.push(r),e.justification&&t.push(`<w:jc w:val="${e.justification}"/>`);let i=$(e.cellSpacing,"tblCellSpacing");i&&t.push(i);let s=$(e.indent,"tblInd");s&&t.push(s);let o=H(e.borders,"tblBorders");o&&t.push(o);let a=M(e.cellMargins,"tblCellMar");a&&t.push(a),e.layout&&t.push(`<w:tblLayout w:type="${e.layout}"/>`);let l=N(e.shading);l&&t.push(l);let c=ve(e.look);return c&&t.push(c),e.overlap&&t.push(`<w:tblOverlap w:val="${e.overlap}"/>`),t.length===0?"":`<w:tblPr>${t.join("")}</w:tblPr>`}function Ae(e){if(!e)return "";let t=[];if(e.cantSplit&&t.push("<w:cantSplit/>"),e.header&&t.push("<w:tblHeader/>"),e.height){let n=[`w:val="${e.height.value}"`];e.heightRule&&n.push(`w:hRule="${e.heightRule}"`),t.push(`<w:trHeight ${n.join(" ")}/>`);}return e.justification&&t.push(`<w:jc w:val="${e.justification}"/>`),e.hidden&&t.push("<w:hidden/>"),t.length===0?"":`<w:trPr>${t.join("")}</w:trPr>`}function Be(e){if(!e)return "";let n=[e.firstRow?"1":"0",e.lastRow?"1":"0",e.firstColumn?"1":"0",e.lastColumn?"1":"0",e.oddVBand?"1":"0",e.evenVBand?"1":"0",e.oddHBand?"1":"0",e.evenHBand?"1":"0",e.nwCell?"1":"0",e.neCell?"1":"0",e.swCell?"1":"0",e.seCell?"1":"0"].join("");return n==="000000000000"?"":`<w:cnfStyle w:val="${n}"/>`}function ze(e){if(!e)return "";let t=[],n=Be(e.conditionalFormat);n&&t.push(n);let r=$(e.width,"tcW");r&&t.push(r),e.gridSpan&&e.gridSpan>1&&t.push(`<w:gridSpan w:val="${e.gridSpan}"/>`),e.vMerge&&(e.vMerge==="restart"?t.push('<w:vMerge w:val="restart"/>'):t.push("<w:vMerge/>"));let i=H(e.borders,"tcBorders");i&&t.push(i);let s=N(e.shading);s&&t.push(s),e.noWrap&&t.push("<w:noWrap/>");let o=M(e.margins,"tcMar");return o&&t.push(o),e.textDirection&&t.push(`<w:textDirection w:val="${e.textDirection}"/>`),e.fitText&&t.push("<w:tcFitText/>"),e.verticalAlign&&t.push(`<w:vAlign w:val="${e.verticalAlign}"/>`),e.hideMark&&t.push("<w:hideMark/>"),t.length===0?"":`<w:tcPr>${t.join("")}</w:tcPr>`}function De(e){return !e||e.length===0?"":`<w:tblGrid>${e.map(n=>`<w:gridCol w:w="${n}"/>`).join("")}</w:tblGrid>`}function Re(e){let t=[];for(let n of e)n.type==="paragraph"?t.push(y(n)):n.type==="table"&&t.push(v(n));return t.length===0&&t.push("<w:p/>"),t.join("")}function ke(e){let t=[],n=ze(e.formatting);return n&&t.push(n),t.push(Re(e.content)),`<w:tc>${t.join("")}</w:tc>`}function je(e){let t=[],n=Ae(e.formatting);n&&t.push(n);for(let r of e.cells)t.push(ke(r));return `<w:tr>${t.join("")}</w:tr>`}function v(e){let t=[],n=Se(e.formatting);n&&t.push(n);let r=De(e.columnWidths);r&&t.push(r);for(let i of e.rows)t.push(je(i));return `<w:tbl>${t.join("")}</w:tbl>`}var d={wpc:"http://schemas.microsoft.com/office/word/2010/wordprocessingCanvas",mc:"http://schemas.openxmlformats.org/markup-compatibility/2006",o:"urn:schemas-microsoft-com:office:office",r:"http://schemas.openxmlformats.org/officeDocument/2006/relationships",m:"http://schemas.openxmlformats.org/officeDocument/2006/math",v:"urn:schemas-microsoft-com:vml",wp14:"http://schemas.microsoft.com/office/word/2010/wordprocessingDrawing",wp:"http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing",w10:"urn:schemas-microsoft-com:office:word",w:"http://schemas.openxmlformats.org/wordprocessingml/2006/main",w14:"http://schemas.microsoft.com/office/word/2010/wordml",w15:"http://schemas.microsoft.com/office/word/2012/wordml",wpg:"http://schemas.microsoft.com/office/word/2010/wordprocessingGroup",wps:"http://schemas.microsoft.com/office/word/2010/wordprocessingShape"};function Ee(){let e={wpc:d.wpc,mc:d.mc,o:d.o,r:d.r,m:d.m,v:d.v,wp14:d.wp14,wp:d.wp,w10:d.w10,w:d.w,w14:d.w14,w15:d.w15,wpg:d.wpg,wps:d.wps};return Object.entries(e).map(([t,n])=>`xmlns:${t}="${n}"`).join(" ")}function F(e,t){if(!e||e.style==="none"||e.style==="nil")return "";let n=[`w:val="${e.style}"`];return e.size!==void 0&&n.push(`w:sz="${e.size}"`),e.space!==void 0&&n.push(`w:space="${e.space}"`),e.color&&(e.color.auto?n.push('w:color="auto"'):e.color.rgb&&n.push(`w:color="${e.color.rgb}"`),e.color.themeColor&&n.push(`w:themeColor="${e.color.themeColor}"`),e.color.themeTint&&n.push(`w:themeTint="${e.color.themeTint}"`),e.color.themeShade&&n.push(`w:themeShade="${e.color.themeShade}"`)),e.shadow&&n.push('w:shadow="true"'),e.frame&&n.push('w:frame="true"'),`<w:${t} ${n.join(" ")}/>`}function Ie(e){return `<w:headerReference ${[`w:type="${e.type}"`,`r:id="${e.rId}"`].join(" ")}/>`}function Xe(e){return `<w:footerReference ${[`w:type="${e.type}"`,`r:id="${e.rId}"`].join(" ")}/>`}function Le(e){if(!e)return "";let t=[];return e.position&&t.push(`<w:pos w:val="${e.position}"/>`),e.numFmt&&t.push(`<w:numFmt w:val="${e.numFmt}"/>`),e.numStart!==void 0&&t.push(`<w:numStart w:val="${e.numStart}"/>`),e.numRestart&&t.push(`<w:numRestart w:val="${e.numRestart}"/>`),t.length===0?"":`<w:footnotePr>${t.join("")}</w:footnotePr>`}function Oe(e){if(!e)return "";let t=[];return e.position&&t.push(`<w:pos w:val="${e.position}"/>`),e.numFmt&&t.push(`<w:numFmt w:val="${e.numFmt}"/>`),e.numStart!==void 0&&t.push(`<w:numStart w:val="${e.numStart}"/>`),e.numRestart&&t.push(`<w:numRestart w:val="${e.numRestart}"/>`),t.length===0?"":`<w:endnotePr>${t.join("")}</w:endnotePr>`}function He(e){let t=[];return e.pageWidth!==void 0&&t.push(`w:w="${e.pageWidth}"`),e.pageHeight!==void 0&&t.push(`w:h="${e.pageHeight}"`),e.orientation==="landscape"&&t.push('w:orient="landscape"'),t.length===0?"":`<w:pgSz ${t.join(" ")}/>`}function Me(e){let t=[];return e.marginTop!==void 0&&t.push(`w:top="${e.marginTop}"`),e.marginRight!==void 0&&t.push(`w:right="${e.marginRight}"`),e.marginBottom!==void 0&&t.push(`w:bottom="${e.marginBottom}"`),e.marginLeft!==void 0&&t.push(`w:left="${e.marginLeft}"`),e.headerDistance!==void 0&&t.push(`w:header="${e.headerDistance}"`),e.footerDistance!==void 0&&t.push(`w:footer="${e.footerDistance}"`),e.gutter!==void 0&&t.push(`w:gutter="${e.gutter}"`),t.length===0?"":`<w:pgMar ${t.join(" ")}/>`}function Ne(e){if(!e.columnCount&&!e.columns?.length)return "";let t=[];e.columnCount!==void 0&&e.columnCount>1&&t.push(`w:num="${e.columnCount}"`),e.columnSpace!==void 0&&t.push(`w:space="${e.columnSpace}"`),e.equalWidth!==void 0&&t.push(`w:equalWidth="${e.equalWidth?"1":"0"}"`),e.separator&&t.push('w:sep="1"');let n="";return e.columns&&e.columns.length>0&&(n=e.columns.map(i=>{let s=[];return i.width!==void 0&&s.push(`w:w="${i.width}"`),i.space!==void 0&&s.push(`w:space="${i.space}"`),`<w:col ${s.join(" ")}/>`}).join("")),t.length===0&&!n?"":`<w:cols${t.length>0?" "+t.join(" "):""}>${n}</w:cols>`}function We(e){if(!e.lineNumbers)return "";let t=e.lineNumbers,n=[];return t.countBy!==void 0&&n.push(`w:countBy="${t.countBy}"`),t.start!==void 0&&n.push(`w:start="${t.start}"`),t.distance!==void 0&&n.push(`w:distance="${t.distance}"`),t.restart&&n.push(`w:restart="${t.restart}"`),n.length===0?"":`<w:lnNumType ${n.join(" ")}/>`}function Ge(e){if(!e.pageBorders)return "";let t=e.pageBorders,n=[],r=[];if(t.display&&n.push(`w:display="${t.display}"`),t.offsetFrom&&n.push(`w:offsetFrom="${t.offsetFrom}"`),t.zOrder&&n.push(`w:zOrder="${t.zOrder}"`),t.top){let s=F(t.top,"top");s&&r.push(s);}if(t.left){let s=F(t.left,"left");s&&r.push(s);}if(t.bottom){let s=F(t.bottom,"bottom");s&&r.push(s);}if(t.right){let s=F(t.right,"right");s&&r.push(s);}return r.length===0?"":`<w:pgBorders${n.length>0?" "+n.join(" "):""}>${r.join("")}</w:pgBorders>`}function Ve(e){if(!e.docGrid)return "";let t=e.docGrid,n=[];return t.type&&n.push(`w:type="${t.type}"`),t.linePitch!==void 0&&n.push(`w:linePitch="${t.linePitch}"`),t.charSpace!==void 0&&n.push(`w:charSpace="${t.charSpace}"`),n.length===0?"":`<w:docGrid ${n.join(" ")}/>`}function _e(e){if(!e)return "";let t=[];if(e.headerReferences)for(let p of e.headerReferences)t.push(Ie(p));if(e.footerReferences)for(let p of e.footerReferences)t.push(Xe(p));let n=Le(e.footnotePr);n&&t.push(n);let r=Oe(e.endnotePr);r&&t.push(r),e.sectionStart&&t.push(`<w:type w:val="${e.sectionStart}"/>`);let i=He(e);i&&t.push(i);let s=Me(e);if(s&&t.push(s),e.paperSrcFirst!==void 0||e.paperSrcOther!==void 0){let p=[];e.paperSrcFirst!==void 0&&p.push(`w:first="${e.paperSrcFirst}"`),e.paperSrcOther!==void 0&&p.push(`w:other="${e.paperSrcOther}"`),t.push(`<w:paperSrc ${p.join(" ")}/>`);}let o=Ge(e);o&&t.push(o);let a=We(e);a&&t.push(a);let l=Ne(e);l&&t.push(l);let c=Ve(e);return c&&t.push(c),e.verticalAlign&&t.push(`<w:vAlign w:val="${e.verticalAlign}"/>`),e.bidi&&t.push("<w:bidi/>"),e.titlePg&&t.push("<w:titlePg/>"),e.evenAndOddHeaders&&t.push("<w:evenAndOddHeaders/>"),t.length===0?"":`<w:sectPr>${t.join("")}</w:sectPr>`}function W(e){if(e.type==="paragraph")return y(e);if(e.type==="table")return v(e);if(e.type==="blockSdt"){let t=e.content.map(i=>W(i)).join(""),n=e.properties,r=[];return n.alias&&r.push(`<w:alias w:val="${n.alias}"/>`),n.tag&&r.push(`<w:tag w:val="${n.tag}"/>`),`<w:sdt><w:sdtPr>${r.join("")}</w:sdtPr><w:sdtContent>${t}</w:sdtContent></w:sdt>`}return ""}function qe(e){return e.map(t=>W(t)).join("")}function Ue(e){let t=[];return t.push(qe(e.content)),e.finalSectionProperties&&t.push(_e(e.finalSectionProperties)),t.join("")}function G(e){let t=[];t.push('<?xml version="1.0" encoding="UTF-8" standalone="yes"?>');let n=Ee();return t.push(`<w:document ${n} mc:Ignorable="w14 w15 wp14">`),t.push("<w:body>"),t.push(Ue(e.package.document)),t.push("</w:body>"),t.push("</w:document>"),t.join("")}var Ze={wpc:"http://schemas.microsoft.com/office/word/2010/wordprocessingCanvas",mc:"http://schemas.openxmlformats.org/markup-compatibility/2006",o:"urn:schemas-microsoft-com:office:office",r:"http://schemas.openxmlformats.org/officeDocument/2006/relationships",m:"http://schemas.openxmlformats.org/officeDocument/2006/math",v:"urn:schemas-microsoft-com:vml",wp14:"http://schemas.microsoft.com/office/word/2010/wordprocessingDrawing",wp:"http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing",w10:"urn:schemas-microsoft-com:office:word",w:"http://schemas.openxmlformats.org/wordprocessingml/2006/main",w14:"http://schemas.microsoft.com/office/word/2010/wordml",w15:"http://schemas.microsoft.com/office/word/2012/wordml",wpg:"http://schemas.microsoft.com/office/word/2010/wordprocessingGroup",wps:"http://schemas.microsoft.com/office/word/2010/wordprocessingShape"};function Ye(){return Object.entries(Ze).map(([e,t])=>`xmlns:${e}="${t}"`).join(" ")}function Je(e){return e.type==="paragraph"?y(e):e.type==="table"?v(e):""}function D(e){let t=e.type==="header"?"w:hdr":"w:ftr",n=Ye(),r=e.content.map(i=>Je(i)).join("");return r||(r="<w:p><w:pPr/></w:p>"),`<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
|
2
|
+
<${t} ${n}>${r}</${t}>`}async function Ke(e,t={}){if(!e.originalBuffer)throw new Error("Cannot repack document: no original buffer for round-trip. Use createDocx() for new documents.");let{compressionLevel:n=6,updateModifiedDate:r=true,modifiedBy:i}=t,s=await R.loadAsync(e.originalBuffer),o=new R;for(let[c,p]of Object.entries(s.files)){if(p.dir){o.folder(c.replace(/\/$/,""));continue}let m=await p.async("arraybuffer");o.file(c,m,{compression:"DEFLATE",compressionOptions:{level:n}});}let a=G(e);if(o.file("word/document.xml",a,{compression:"DEFLATE",compressionOptions:{level:n}}),Qe(e,o,n),r){let c="docProps/core.xml",p=s.file(c);if(p){let m=await p.async("text"),w=et(m,{updateModifiedDate:r,modifiedBy:i});o.file(c,w,{compression:"DEFLATE",compressionOptions:{level:n}});}}return await o.generateAsync({type:"arraybuffer",compression:"DEFLATE",compressionOptions:{level:n}})}function Qe(e,t,n){let r=e.package.relationships;if(!r)return;let i={level:n};if(e.package.headers)for(let[s,o]of e.package.headers.entries()){let a=r.get(s);if(a&&a.type===b$1.header&&a.target){let l=a.target.startsWith("/")?a.target.slice(1):`word/${a.target}`,c=D(o);t.file(l,c,{compression:"DEFLATE",compressionOptions:i});}}if(e.package.footers)for(let[s,o]of e.package.footers.entries()){let a=r.get(s);if(a&&a.type===b$1.footer&&a.target){let l=a.target.startsWith("/")?a.target.slice(1):`word/${a.target}`,c=D(o);t.file(l,c,{compression:"DEFLATE",compressionOptions:i});}}}function et(e,t){let n=e;if(t.updateModifiedDate){let r=new Date().toISOString();n.includes("<dcterms:modified")?n=n.replace(/<dcterms:modified[^>]*>[^<]*<\/dcterms:modified>/,`<dcterms:modified xsi:type="dcterms:W3CDTF">${r}</dcterms:modified>`):n=n.replace("</cp:coreProperties>",`<dcterms:modified xsi:type="dcterms:W3CDTF">${r}</dcterms:modified></cp:coreProperties>`);}return t.modifiedBy&&(n.includes("<cp:lastModifiedBy")?n=n.replace(/<cp:lastModifiedBy>[^<]*<\/cp:lastModifiedBy>/,`<cp:lastModifiedBy>${V(t.modifiedBy)}</cp:lastModifiedBy>`):n=n.replace("</cp:coreProperties>",`<cp:lastModifiedBy>${V(t.modifiedBy)}</cp:lastModifiedBy></cp:coreProperties>`)),n}function V(e){return e.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">")}async function tt(){let e=new R;e.file("[Content_Types].xml",`<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
|
3
|
+
<Types xmlns="http://schemas.openxmlformats.org/package/2006/content-types">
|
|
4
|
+
<Default Extension="rels" ContentType="application/vnd.openxmlformats-package.relationships+xml"/>
|
|
5
|
+
<Default Extension="xml" ContentType="application/xml"/>
|
|
6
|
+
<Override PartName="/word/document.xml" ContentType="application/vnd.openxmlformats-officedocument.wordprocessingml.document.main+xml"/>
|
|
7
|
+
<Override PartName="/word/styles.xml" ContentType="application/vnd.openxmlformats-officedocument.wordprocessingml.styles+xml"/>
|
|
8
|
+
<Override PartName="/docProps/core.xml" ContentType="application/vnd.openxmlformats-package.core-properties+xml"/>
|
|
9
|
+
<Override PartName="/docProps/app.xml" ContentType="application/vnd.openxmlformats-officedocument.extended-properties+xml"/>
|
|
10
|
+
</Types>`),e.file("_rels/.rels",`<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
|
11
|
+
<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">
|
|
12
|
+
<Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument" Target="word/document.xml"/>
|
|
13
|
+
<Relationship Id="rId2" Type="http://schemas.openxmlformats.org/package/2006/relationships/metadata/core-properties" Target="docProps/core.xml"/>
|
|
14
|
+
<Relationship Id="rId3" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/extended-properties" Target="docProps/app.xml"/>
|
|
15
|
+
</Relationships>`),e.file("word/_rels/document.xml.rels",`<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
|
16
|
+
<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">
|
|
17
|
+
<Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles" Target="styles.xml"/>
|
|
18
|
+
</Relationships>`),e.file("word/document.xml",`<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
|
19
|
+
<w:document xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships">
|
|
20
|
+
<w:body>
|
|
21
|
+
<w:p>
|
|
22
|
+
<w:r>
|
|
23
|
+
<w:t></w:t>
|
|
24
|
+
</w:r>
|
|
25
|
+
</w:p>
|
|
26
|
+
<w:sectPr>
|
|
27
|
+
<w:pgSz w:w="12240" w:h="15840"/>
|
|
28
|
+
<w:pgMar w:top="1440" w:right="1440" w:bottom="1440" w:left="1440" w:header="720" w:footer="720" w:gutter="0"/>
|
|
29
|
+
</w:sectPr>
|
|
30
|
+
</w:body>
|
|
31
|
+
</w:document>`),e.file("word/styles.xml",`<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
|
32
|
+
<w:styles xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main">
|
|
33
|
+
<w:docDefaults>
|
|
34
|
+
<w:rPrDefault>
|
|
35
|
+
<w:rPr>
|
|
36
|
+
<w:rFonts w:ascii="Calibri" w:hAnsi="Calibri"/>
|
|
37
|
+
<w:sz w:val="22"/>
|
|
38
|
+
</w:rPr>
|
|
39
|
+
</w:rPrDefault>
|
|
40
|
+
<w:pPrDefault>
|
|
41
|
+
<w:pPr>
|
|
42
|
+
<w:spacing w:after="200" w:line="276" w:lineRule="auto"/>
|
|
43
|
+
</w:pPr>
|
|
44
|
+
</w:pPrDefault>
|
|
45
|
+
</w:docDefaults>
|
|
46
|
+
<w:style w:type="paragraph" w:default="1" w:styleId="Normal">
|
|
47
|
+
<w:name w:val="Normal"/>
|
|
48
|
+
</w:style>
|
|
49
|
+
</w:styles>`);let t=new Date().toISOString();return e.file("docProps/core.xml",`<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
|
50
|
+
<cp:coreProperties xmlns:cp="http://schemas.openxmlformats.org/package/2006/metadata/core-properties" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:dcterms="http://purl.org/dc/terms/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
|
|
51
|
+
<dc:creator>EigenPal DOCX Editor</dc:creator>
|
|
52
|
+
<dcterms:created xsi:type="dcterms:W3CDTF">${t}</dcterms:created>
|
|
53
|
+
<dcterms:modified xsi:type="dcterms:W3CDTF">${t}</dcterms:modified>
|
|
54
|
+
</cp:coreProperties>`),e.file("docProps/app.xml",`<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
|
55
|
+
<Properties xmlns="http://schemas.openxmlformats.org/officeDocument/2006/extended-properties">
|
|
56
|
+
<Application>EigenPal DOCX Editor</Application>
|
|
57
|
+
<AppVersion>1.0.0</AppVersion>
|
|
58
|
+
</Properties>`),e.generateAsync({type:"arraybuffer",compression:"DEFLATE",compressionOptions:{level:6}})}async function yt(e){let t=await tt(),n={...e,originalBuffer:t};return Ke(n)}export{_e as a,Ue as b,G as c,Ke as d,yt as e};
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
'use strict';var
|
|
1
|
+
'use strict';var chunkTRAQI6RX_cjs=require('./chunk-TRAQI6RX.cjs'),chunkRTESADL3_cjs=require('./chunk-RTESADL3.cjs'),g=require('pizzip'),b=require('docxtemplater');function _interopDefault(e){return e&&e.__esModule?e:{default:e}}var g__default=/*#__PURE__*/_interopDefault(g);var b__default=/*#__PURE__*/_interopDefault(b);function J(e){return typeof e=="object"&&e!==null&&("_def"in e||"parse"in e||"safeParse"in e)}function v(e,t){let r=t,{position:o,variableName:n}=r,a=JSON.parse(JSON.stringify(e)),s=a.package.document.content.filter(u=>u.type==="paragraph");if(o.paragraphIndex>=s.length)throw new Error(`Paragraph index ${o.paragraphIndex} out of bounds`);let c=s[o.paragraphIndex],l=`{{${n}}}`;return k(c,o.offset,l),a.templateVariables||(a.templateVariables=[]),a.templateVariables.includes(n)||a.templateVariables.push(n),a}function w(e,t){let r=t,{range:o,variableName:n}=r,a=JSON.parse(JSON.stringify(e)),s=a.package.document.content.filter(u=>u.type==="paragraph");if(o.start.paragraphIndex!==o.end.paragraphIndex)throw new Error("Template variable replacement cannot span multiple paragraphs");if(o.start.paragraphIndex>=s.length)throw new Error(`Paragraph index ${o.start.paragraphIndex} out of bounds`);let c=s[o.start.paragraphIndex];Z(c,o.start.offset,o.end.offset);let l=`{{${n}}}`;return k(c,o.start.offset,l),a.templateVariables||(a.templateVariables=[]),a.templateVariables.includes(n)||a.templateVariables.push(n),a}function k(e,t,r){let o=0,n=false;for(let a=0;a<e.content.length;a++){let i=e.content[a];if(i.type==="run"){let s=T(i),c=o,l=o+s.length;if(!n&&t>=c&&t<=l){let u=t-c,y=s.slice(0,u),m=s.slice(u),p=[];for(let d=0;d<a;d++)p.push(e.content[d]);y&&p.push({type:"run",formatting:i.formatting,content:[{type:"text",text:y}]}),p.push({type:"run",formatting:i.formatting,content:[{type:"text",text:r}]}),m&&p.push({type:"run",formatting:i.formatting,content:[{type:"text",text:m}]});for(let d=a+1;d<e.content.length;d++)p.push(e.content[d]);e.content=p,n=true;break}o=l;}else if(i.type==="hyperlink")for(let s of i.children)s.type==="run"&&(o+=T(s).length);}n||e.content.push({type:"run",content:[{type:"text",text:r}]});}function Z(e,t,r){let o=[],n=0;for(let a of e.content)if(a.type==="run"){let i=T(a),s=n,c=n+i.length;if(c<=t||s>=r)o.push(a);else {let l="";s<t&&(l+=i.slice(0,t-s)),c>r&&(l+=i.slice(r-s)),l.length>0&&o.push({type:"run",formatting:a.formatting,content:[{type:"text",text:l}]});}n=c;}else o.push(a);e.content=o;}function T(e){return e.content.filter(t=>t.type==="text").map(t=>t.text).join("")}function U(e){return V(e).variables}function V(e){let t=[],r={body:[],headers:[],footers:[],footnotes:[],endnotes:[],textBoxes:[]};if(e.package?.document){let n=j(e.package.document);n.forEach(a=>{t.push({name:a,location:"body"});}),r.body=Array.from(new Set(n)).sort();}if(e.package?.document?.sections&&e.package.document.sections.forEach((n,a)=>{n.properties.headerReferences&&n.properties.headerReferences.forEach(i=>{});}),e.package?.footnotes){let n=A(e.package.footnotes);n.forEach(a=>{t.push({name:a,location:"footnote"});}),r.footnotes=Array.from(new Set(n)).sort();}if(e.package?.endnotes){let n=A(e.package.endnotes);n.forEach(a=>{t.push({name:a,location:"endnote"});}),r.endnotes=Array.from(new Set(n)).sort();}e.templateVariables&&e.templateVariables.forEach(n=>{t.some(a=>a.name===n)||t.push({name:n,location:"body"});});let o=new Set;return t.forEach(n=>o.add(n.name)),{variables:Array.from(o).sort(),totalOccurrences:t.length,byLocation:r,occurrences:t}}function j(e){let t=[];if(e.content&&t.push(...I(e.content)),e.sections)for(let r of e.sections)r.content&&t.push(...I(r.content));return t}function I(e){let t=[];for(let r of e)r.type==="paragraph"?t.push(...R(r)):r.type==="table"&&t.push(...M(r));return t}function R(e){let t=[];if(!e.content)return t;for(let r of e.content)r.type==="run"?t.push(...f(r)):r.type==="hyperlink"?t.push(...q(r)):r.type==="simpleField"?t.push(...W(r)):r.type==="complexField"&&t.push(...G(r));return t}function f(e){let t=[];if(!e.content)return t;for(let r of e.content)r.type==="text"&&r.text&&t.push(...B(r.text));return t}function q(e){let t=[];if(!e.children)return t;for(let r of e.children)r.type==="run"&&t.push(...f(r));return t}function W(e){let t=[];if(e.instruction&&t.push(...B(e.instruction)),e.content)for(let r of e.content)r.type==="run"&&t.push(...f(r));return t}function G(e){let t=[];if(e.fieldCode)for(let r of e.fieldCode)r.type==="run"&&t.push(...f(r));if(e.fieldResult)for(let r of e.fieldResult)r.type==="run"&&t.push(...f(r));return t}function M(e){let t=[];if(!e.rows)return t;for(let r of e.rows)if(r.cells)for(let o of r.cells)t.push(...X(o));return t}function X(e){let t=[];if(!e.content)return t;for(let r of e.content)r.type==="paragraph"?t.push(...R(r)):r.type==="table"&&t.push(...M(r));return t}function A(e){let t=[];for(let r of e)if(r.content)for(let o of r.content)t.push(...R(o));return t}var S=/\{([a-zA-Z_][a-zA-Z0-9_\-\.]*)\}/g,_=/\{(.+?)\}/g;function B(e){if(!e)return [];let t=[],r=new RegExp(S),o;for(;(o=r.exec(e))!==null;)t.push(o[1]);return t}function ne(e){return S.test(e)}function oe(e){return !(!e||typeof e!="string"||e.length===0||e.length>100||!/^[a-zA-Z_]/.test(e)||!/^[a-zA-Z_][a-zA-Z0-9_\-\.]*$/.test(e))}function ae(e){if(!e)return "";let t=e.replace(/\s+/g,"_");return t=t.replace(/[^a-zA-Z0-9_\-\.]/g,""),t&&!/^[a-zA-Z_]/.test(t)&&(t="_"+t),t.substring(0,100)}function ie(e){return `{${e}}`}function se(e){let t=e.match(/^\{(.+?)\}$/);return t?t[1]:null}function ce(e,t){return e&&e.replace(_,(r,o)=>{let n=o.trim();return n in t?t[n]:r})}function le(e,t=""){return e&&e.replace(_,t)}function pe(e){return U(e).length>0}function O(e,t,r={}){return E(e,t,r).buffer}function E(e,t,r={}){let{nullGetter:o="keep",linebreaks:n=true,delimiters:a}=r,i=[],s=[],c=[];try{let l=new g__default.default(e),u=new b__default.default(l,{paragraphLoop:!0,linebreaks:n,nullGetter:m=>{let p=m.value||"";if(o==="error")throw new Error(`Undefined variable: ${p}`);return o==="empty"?(c.push(p),""):(c.push(p),`{${p}}`)},delimiters:a?{start:a.start||"{",end:a.end||"}"}:void 0});return Object.keys(t).forEach(m=>{t[m]!==void 0&&t[m]!==null&&s.push(m);}),u.setData(t),u.render(),{buffer:u.getZip().generate({type:"arraybuffer",compression:"DEFLATE",compressionOptions:{level:6}}),replacedVariables:s,unreplacedVariables:c,warnings:i}}catch(l){throw x(l)}}function fe(e,t,r={}){let o=O(e,t,r);return new Blob([o],{type:"application/vnd.openxmlformats-officedocument.wordprocessingml.document"})}function ge(e){try{let t=new g__default.default(e),o=new b__default.default(t,{paragraphLoop:!0,linebreaks:!0}).getFullText();return $(o)}catch(t){throw x(t)}}function L(e){let t=[],r=[];try{let o=new g__default.default(e),a=new b__default.default(o,{paragraphLoop:!0,linebreaks:!0}).getFullText();r=$(a);let i=K(a);for(let s of i)t.push({message:`Unclosed tag: ${s}`,variable:s,type:"parse"});return {valid:t.length===0,errors:t,tags:r}}catch(o){return t.push(x(o)),{valid:false,errors:t,tags:r}}}function be(e,t){return e.filter(r=>!(r in t)||t[r]===void 0||t[r]===null)}function xe(e,t){try{let r=new g__default.default(e),o=new b__default.default(r,{paragraphLoop:!0,linebreaks:!0,nullGetter:n=>`[${n.value||""}]`});return o.setData(t),o.render(),o.getFullText()}catch(r){throw x(r)}}function $(e){let t=[],r=/\{([^{}]+)\}/g,o;for(;(o=r.exec(e))!==null;){let n=o[1].trim();n&&!t.includes(n)&&t.push(n);}return t.sort()}function K(e){let t=[],r=0,o="";for(let n of e)n==="{"?(r++,o=""):n==="}"?(r--,r<0&&(r=0)):r>0&&(o+=n);return r>0&&o.trim()&&t.push(o.trim()),t}function Q(e){return "properties"in e&&typeof e.properties=="object"}function x(e){if(e instanceof Error){if(Q(e)&&e.properties?.errors){let t=e.properties.errors[0];return {message:t?.message||"Template processing error",variable:t?.properties?.tag,type:"render",originalError:e}}if(e.message.includes("undefined")){let t=e.message.match(/undefined (?:variable|tag):\s*(\S+)/i);return {message:e.message,variable:t?t[1]:void 0,type:"undefined",originalError:e}}return e.message.includes("parse")||e.message.includes("unclosed")||e.message.includes("syntax")?{message:e.message,type:"parse",originalError:e}:{message:e.message,type:"unknown",originalError:e}}return {message:String(e),type:"unknown"}}function he(e,t,r={}){let{linebreaks:o=true,delimiters:n}=r;try{let a=new g__default.default(e),i=new b__default.default(a,{paragraphLoop:!0,linebreaks:o,delimiters:n?{start:n.start||"{",end:n.end||"}"}:void 0});return i.setData(t),i.render(),i.getZip().generate({type:"arraybuffer",compression:"DEFLATE"})}catch(a){throw x(a)}}function ye(e={}){return (t,r)=>O(t,r,e)}var h={type:"string",description:"Document ID from a previous docx_load call"},Y={type:"object",properties:{paragraphIndex:{type:"number",description:"Index of the paragraph (0-indexed)"},offset:{type:"number",description:"Character offset within the paragraph"}},required:["paragraphIndex","offset"]},N={name:"docx_get_variables",description:`List all template variables ({{name}} format) found in the document.
|
|
2
2
|
Returns variable names without braces, along with their locations (body, headers, footers, etc.).
|
|
3
3
|
Use this to discover what data fields a template document expects.`,inputSchema:{type:"object",properties:{documentId:h},required:["documentId"]},handler:async(e,t)=>{let{documentId:r}=e,o=t.session.documents.get(r);if(!o)return {isError:true,content:[{type:"text",text:`Document not found: ${r}`}]};try{let n=V(o.document);return {content:[{type:"text",text:JSON.stringify({variables:n.variables,count:n.variables.length,totalOccurrences:n.totalOccurrences,byLocation:n.byLocation},null,2)}]}}catch(n){return {isError:true,content:[{type:"text",text:`Failed to detect variables: ${n.message}`}]}}},annotations:{category:"template",readOnly:true,complexity:"low",examples:[{description:"Get all variables from a loaded document",input:{documentId:"doc_123"},output:'{"variables": ["customer_name", "invoice_date"], "count": 2}'}]}},F={name:"docx_insert_variable",description:`Insert a template variable placeholder ({{name}}) at a specific position in the document.
|
|
4
4
|
The variable can later be substituted with actual values using docx_apply_template.
|
|
5
|
-
Variable names should follow the pattern: letters, numbers, underscores, starting with a letter.`,inputSchema:{type:"object",properties:{documentId:h,position:Y,variableName:{type:"string",description:'Variable name without braces (e.g., "customer_name"). Will be inserted as {{customer_name}}',pattern:"^[a-zA-Z_][a-zA-Z0-9_]*$"}},required:["documentId","position","variableName"]},handler:async(e,t)=>{let{documentId:r,position:o,variableName:n}=e,a=t.session.documents.get(r);if(!a)return {isError:true,content:[{type:"text",text:`Document not found: ${r}`}]};if(!/^[a-zA-Z_][a-zA-Z0-9_\-.]*$/.test(n))return {isError:true,content:[{type:"text",text:`Invalid variable name: ${n}. Must start with letter/underscore and contain only alphanumeric, underscore, hyphen, or dot.`}]};try{let{executeCommand:i}=await import('./executor-
|
|
5
|
+
Variable names should follow the pattern: letters, numbers, underscores, starting with a letter.`,inputSchema:{type:"object",properties:{documentId:h,position:Y,variableName:{type:"string",description:'Variable name without braces (e.g., "customer_name"). Will be inserted as {{customer_name}}',pattern:"^[a-zA-Z_][a-zA-Z0-9_]*$"}},required:["documentId","position","variableName"]},handler:async(e,t)=>{let{documentId:r,position:o,variableName:n}=e,a=t.session.documents.get(r);if(!a)return {isError:true,content:[{type:"text",text:`Document not found: ${r}`}]};if(!/^[a-zA-Z_][a-zA-Z0-9_\-.]*$/.test(n))return {isError:true,content:[{type:"text",text:`Invalid variable name: ${n}. Must start with letter/underscore and contain only alphanumeric, underscore, hyphen, or dot.`}]};try{let{executeCommand:i}=await import('./executor-U3BZPPGN.cjs'),s=i(a.document,{type:"insertText",position:o,text:`{{${n}}}`});return a.document=s,a.lastModified=Date.now(),s.templateVariables||(s.templateVariables=[]),s.templateVariables.includes(n)||s.templateVariables.push(n),{content:[{type:"text",text:JSON.stringify({success:!0,variable:n,insertedAs:`{{${n}}}`,position:o})}]}}catch(i){return {isError:true,content:[{type:"text",text:`Failed to insert variable: ${i.message}`}]}}},annotations:{category:"template",readOnly:false,complexity:"low",examples:[{description:"Insert customer name variable at start of first paragraph",input:{documentId:"doc_123",position:{paragraphIndex:0,offset:0},variableName:"customer_name"}}]}},z={name:"docx_apply_template",description:`Substitute template variables with actual values in the document.
|
|
6
6
|
Replaces all {variable} placeholders with the corresponding values provided.
|
|
7
7
|
Preserves all formatting (fonts, styles, colors, tables).
|
|
8
|
-
Use docx_get_variables first to discover what variables exist in the document.`,inputSchema:{type:"object",properties:{documentId:h,variables:{type:"object",description:'Map of variable names to values (e.g., {"customer_name": "John Doe", "date": "2024-01-15"})',additionalProperties:{type:"string"}},keepUnmatchedVariables:{type:"boolean",description:"If true, keep {variable} placeholders for variables not in the map. If false, replace with empty string. Default: true",default:true}},required:["documentId","variables"]},handler:async(e,t)=>{let{documentId:r,variables:o,keepUnmatchedVariables:n=true}=e,a=t.session.documents.get(r);if(!a)return {isError:true,content:[{type:"text",text:`Document not found: ${r}`}]};if(!a.buffer)return {isError:true,content:[{type:"text",text:"Cannot apply template: document was not loaded from a DOCX buffer"}]};try{let i=E(a.buffer,o,{nullGetter:n?"keep":"empty"}),s=await
|
|
8
|
+
Use docx_get_variables first to discover what variables exist in the document.`,inputSchema:{type:"object",properties:{documentId:h,variables:{type:"object",description:'Map of variable names to values (e.g., {"customer_name": "John Doe", "date": "2024-01-15"})',additionalProperties:{type:"string"}},keepUnmatchedVariables:{type:"boolean",description:"If true, keep {variable} placeholders for variables not in the map. If false, replace with empty string. Default: true",default:true}},required:["documentId","variables"]},handler:async(e,t)=>{let{documentId:r,variables:o,keepUnmatchedVariables:n=true}=e,a=t.session.documents.get(r);if(!a)return {isError:true,content:[{type:"text",text:`Document not found: ${r}`}]};if(!a.buffer)return {isError:true,content:[{type:"text",text:"Cannot apply template: document was not loaded from a DOCX buffer"}]};try{let i=E(a.buffer,o,{nullGetter:n?"keep":"empty"}),s=await chunkTRAQI6RX_cjs.o(i.buffer);return a.document=s,a.buffer=i.buffer,a.lastModified=Date.now(),{content:[{type:"text",text:JSON.stringify({success:!0,replacedVariables:i.replacedVariables,unreplacedVariables:i.unreplacedVariables,warnings:i.warnings})}]}}catch(i){return {isError:true,content:[{type:"text",text:`Failed to apply template: ${i.message}`}]}}},annotations:{category:"template",readOnly:false,complexity:"medium",examples:[{description:"Fill in customer and date values",input:{documentId:"doc_123",variables:{customer_name:"Jane Smith",invoice_date:"2024-02-15",amount:"$1,234.56"}}}]}},H={name:"docx_validate_template",description:`Validate that a document is a valid docxtemplater template.
|
|
9
9
|
Checks for syntax errors like unclosed braces, invalid tag names, etc.
|
|
10
|
-
Returns validation result with any errors found and list of valid tags.`,inputSchema:{type:"object",properties:{documentId:h},required:["documentId"]},handler:async(e,t)=>{let{documentId:r}=e,o=t.session.documents.get(r);if(!o)return {isError:true,content:[{type:"text",text:`Document not found: ${r}`}]};if(!o.buffer)return {isError:true,content:[{type:"text",text:"Cannot validate template: document was not loaded from a DOCX buffer"}]};try{let n=L(o.buffer);return {content:[{type:"text",text:JSON.stringify({valid:n.valid,tags:n.tags,errors:n.errors.map(a=>({message:a.message,variable:a.variable,type:a.type}))},null,2)}]}}catch(n){return {isError:true,content:[{type:"text",text:`Failed to validate template: ${n.message}`}]}}},annotations:{category:"template",readOnly:true,complexity:"low"}},D=[N,F,z,H];var ee={id:"docxtemplater",name:"Docxtemplater",version:"1.0.0",description:"Template variable support using standard docxtemplater syntax ({variable})",commandHandlers:{insertTemplateVariable:v,replaceWithTemplateVariable:w},mcpTools:D,initialize:()=>{try{chunkRTESADL3_cjs.a("docxtemplater"),chunkRTESADL3_cjs.a("pizzip");}catch{console.warn("[docxtemplater-plugin] Warning: docxtemplater or pizzip not installed. Template features may not work. Install with: npm install docxtemplater pizzip");}}};exports.a=U;exports.b=V;exports.c=j;exports.d=R;exports.e=B;exports.f=
|
|
10
|
+
Returns validation result with any errors found and list of valid tags.`,inputSchema:{type:"object",properties:{documentId:h},required:["documentId"]},handler:async(e,t)=>{let{documentId:r}=e,o=t.session.documents.get(r);if(!o)return {isError:true,content:[{type:"text",text:`Document not found: ${r}`}]};if(!o.buffer)return {isError:true,content:[{type:"text",text:"Cannot validate template: document was not loaded from a DOCX buffer"}]};try{let n=L(o.buffer);return {content:[{type:"text",text:JSON.stringify({valid:n.valid,tags:n.tags,errors:n.errors.map(a=>({message:a.message,variable:a.variable,type:a.type}))},null,2)}]}}catch(n){return {isError:true,content:[{type:"text",text:`Failed to validate template: ${n.message}`}]}}},annotations:{category:"template",readOnly:true,complexity:"low"}},D=[N,F,z,H];var ee={id:"docxtemplater",name:"Docxtemplater",version:"1.0.0",description:"Template variable support using standard docxtemplater syntax ({variable})",commandHandlers:{insertTemplateVariable:v,replaceWithTemplateVariable:w},mcpTools:D,initialize:()=>{try{chunkRTESADL3_cjs.a("docxtemplater"),chunkRTESADL3_cjs.a("pizzip");}catch{console.warn("[docxtemplater-plugin] Warning: docxtemplater or pizzip not installed. Template features may not work. Install with: npm install docxtemplater pizzip");}}};exports.a=U;exports.b=V;exports.c=j;exports.d=R;exports.e=B;exports.f=ne;exports.g=oe;exports.h=ae;exports.i=ie;exports.j=se;exports.k=ce;exports.l=le;exports.m=pe;exports.n=O;exports.o=E;exports.p=fe;exports.q=ge;exports.r=L;exports.s=be;exports.t=xe;exports.u=he;exports.v=ye;exports.w=J;exports.x=ee;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {o}from'./chunk-PM4Y7OFN.js';import {a}from'./chunk-3IYNTJO5.js';import g from'pizzip';import b from'docxtemplater';function J(e){return typeof e=="object"&&e!==null&&("_def"in e||"parse"in e||"safeParse"in e)}function v(e,t){let r=t,{position:o,variableName:n}=r,a=JSON.parse(JSON.stringify(e)),s=a.package.document.content.filter(u=>u.type==="paragraph");if(o.paragraphIndex>=s.length)throw new Error(`Paragraph index ${o.paragraphIndex} out of bounds`);let c=s[o.paragraphIndex],l=`{{${n}}}`;return k(c,o.offset,l),a.templateVariables||(a.templateVariables=[]),a.templateVariables.includes(n)||a.templateVariables.push(n),a}function w(e,t){let r=t,{range:o,variableName:n}=r,a=JSON.parse(JSON.stringify(e)),s=a.package.document.content.filter(u=>u.type==="paragraph");if(o.start.paragraphIndex!==o.end.paragraphIndex)throw new Error("Template variable replacement cannot span multiple paragraphs");if(o.start.paragraphIndex>=s.length)throw new Error(`Paragraph index ${o.start.paragraphIndex} out of bounds`);let c=s[o.start.paragraphIndex];Z(c,o.start.offset,o.end.offset);let l=`{{${n}}}`;return k(c,o.start.offset,l),a.templateVariables||(a.templateVariables=[]),a.templateVariables.includes(n)||a.templateVariables.push(n),a}function k(e,t,r){let o=0,n=false;for(let a=0;a<e.content.length;a++){let i=e.content[a];if(i.type==="run"){let s=T(i),c=o,l=o+s.length;if(!n&&t>=c&&t<=l){let u=t-c,y=s.slice(0,u),m=s.slice(u),p=[];for(let d=0;d<a;d++)p.push(e.content[d]);y&&p.push({type:"run",formatting:i.formatting,content:[{type:"text",text:y}]}),p.push({type:"run",formatting:i.formatting,content:[{type:"text",text:r}]}),m&&p.push({type:"run",formatting:i.formatting,content:[{type:"text",text:m}]});for(let d=a+1;d<e.content.length;d++)p.push(e.content[d]);e.content=p,n=true;break}o=l;}else if(i.type==="hyperlink")for(let s of i.children)s.type==="run"&&(o+=T(s).length);}n||e.content.push({type:"run",content:[{type:"text",text:r}]});}function Z(e,t,r){let o=[],n=0;for(let a of e.content)if(a.type==="run"){let i=T(a),s=n,c=n+i.length;if(c<=t||s>=r)o.push(a);else {let l="";s<t&&(l+=i.slice(0,t-s)),c>r&&(l+=i.slice(r-s)),l.length>0&&o.push({type:"run",formatting:a.formatting,content:[{type:"text",text:l}]});}n=c;}else o.push(a);e.content=o;}function T(e){return e.content.filter(t=>t.type==="text").map(t=>t.text).join("")}function U(e){return V(e).variables}function V(e){let t=[],r={body:[],headers:[],footers:[],footnotes:[],endnotes:[],textBoxes:[]};if(e.package?.document){let n=j(e.package.document);n.forEach(a=>{t.push({name:a,location:"body"});}),r.body=Array.from(new Set(n)).sort();}if(e.package?.document?.sections&&e.package.document.sections.forEach((n,a)=>{n.properties.headerReferences&&n.properties.headerReferences.forEach(i=>{});}),e.package?.footnotes){let n=A(e.package.footnotes);n.forEach(a=>{t.push({name:a,location:"footnote"});}),r.footnotes=Array.from(new Set(n)).sort();}if(e.package?.endnotes){let n=A(e.package.endnotes);n.forEach(a=>{t.push({name:a,location:"endnote"});}),r.endnotes=Array.from(new Set(n)).sort();}e.templateVariables&&e.templateVariables.forEach(n=>{t.some(a=>a.name===n)||t.push({name:n,location:"body"});});let o=new Set;return t.forEach(n=>o.add(n.name)),{variables:Array.from(o).sort(),totalOccurrences:t.length,byLocation:r,occurrences:t}}function j(e){let t=[];if(e.content&&t.push(...I(e.content)),e.sections)for(let r of e.sections)r.content&&t.push(...I(r.content));return t}function I(e){let t=[];for(let r of e)r.type==="paragraph"?t.push(...R(r)):r.type==="table"&&t.push(...M(r));return t}function R(e){let t=[];if(!e.content)return t;for(let r of e.content)r.type==="run"?t.push(...f(r)):r.type==="hyperlink"?t.push(...q(r)):r.type==="simpleField"?t.push(...W(r)):r.type==="complexField"&&t.push(...G(r));return t}function f(e){let t=[];if(!e.content)return t;for(let r of e.content)r.type==="text"&&r.text&&t.push(...B(r.text));return t}function q(e){let t=[];if(!e.children)return t;for(let r of e.children)r.type==="run"&&t.push(...f(r));return t}function W(e){let t=[];if(e.instruction&&t.push(...B(e.instruction)),e.content)for(let r of e.content)r.type==="run"&&t.push(...f(r));return t}function G(e){let t=[];if(e.fieldCode)for(let r of e.fieldCode)r.type==="run"&&t.push(...f(r));if(e.fieldResult)for(let r of e.fieldResult)r.type==="run"&&t.push(...f(r));return t}function M(e){let t=[];if(!e.rows)return t;for(let r of e.rows)if(r.cells)for(let o of r.cells)t.push(...X(o));return t}function X(e){let t=[];if(!e.content)return t;for(let r of e.content)r.type==="paragraph"?t.push(...R(r)):r.type==="table"&&t.push(...M(r));return t}function A(e){let t=[];for(let r of e)if(r.content)for(let o of r.content)t.push(...R(o));return t}var S=/\{([a-zA-Z_][a-zA-Z0-9_\-\.]*)\}/g,_=/\{(.+?)\}/g;function B(e){if(!e)return [];let t=[],r=new RegExp(S),o;for(;(o=r.exec(e))!==null;)t.push(o[1]);return t}function ne(e){return S.test(e)}function oe(e){return !(!e||typeof e!="string"||e.length===0||e.length>100||!/^[a-zA-Z_]/.test(e)||!/^[a-zA-Z_][a-zA-Z0-9_\-\.]*$/.test(e))}function ae(e){if(!e)return "";let t=e.replace(/\s+/g,"_");return t=t.replace(/[^a-zA-Z0-9_\-\.]/g,""),t&&!/^[a-zA-Z_]/.test(t)&&(t="_"+t),t.substring(0,100)}function ie(e){return `{${e}}`}function se(e){let t=e.match(/^\{(.+?)\}$/);return t?t[1]:null}function ce(e,t){return e&&e.replace(_,(r,o)=>{let n=o.trim();return n in t?t[n]:r})}function le(e,t=""){return e&&e.replace(_,t)}function pe(e){return U(e).length>0}function O(e,t,r={}){return E(e,t,r).buffer}function E(e,t,r={}){let{nullGetter:o="keep",linebreaks:n=true,delimiters:a}=r,i=[],s=[],c=[];try{let l=new g(e),u=new b(l,{paragraphLoop:!0,linebreaks:n,nullGetter:m=>{let p=m.value||"";if(o==="error")throw new Error(`Undefined variable: ${p}`);return o==="empty"?(c.push(p),""):(c.push(p),`{${p}}`)},delimiters:a?{start:a.start||"{",end:a.end||"}"}:void 0});return Object.keys(t).forEach(m=>{t[m]!==void 0&&t[m]!==null&&s.push(m);}),u.setData(t),u.render(),{buffer:u.getZip().generate({type:"arraybuffer",compression:"DEFLATE",compressionOptions:{level:6}}),replacedVariables:s,unreplacedVariables:c,warnings:i}}catch(l){throw x(l)}}function fe(e,t,r={}){let o=O(e,t,r);return new Blob([o],{type:"application/vnd.openxmlformats-officedocument.wordprocessingml.document"})}function ge(e){try{let t=new g(e),o=new b(t,{paragraphLoop:!0,linebreaks:!0}).getFullText();return $(o)}catch(t){throw x(t)}}function L(e){let t=[],r=[];try{let o=new g(e),a=new b(o,{paragraphLoop:!0,linebreaks:!0}).getFullText();r=$(a);let i=K(a);for(let s of i)t.push({message:`Unclosed tag: ${s}`,variable:s,type:"parse"});return {valid:t.length===0,errors:t,tags:r}}catch(o){return t.push(x(o)),{valid:false,errors:t,tags:r}}}function be(e,t){return e.filter(r=>!(r in t)||t[r]===void 0||t[r]===null)}function xe(e,t){try{let r=new g(e),o=new b(r,{paragraphLoop:!0,linebreaks:!0,nullGetter:n=>`[${n.value||""}]`});return o.setData(t),o.render(),o.getFullText()}catch(r){throw x(r)}}function $(e){let t=[],r=/\{([^{}]+)\}/g,o;for(;(o=r.exec(e))!==null;){let n=o[1].trim();n&&!t.includes(n)&&t.push(n);}return t.sort()}function K(e){let t=[],r=0,o="";for(let n of e)n==="{"?(r++,o=""):n==="}"?(r--,r<0&&(r=0)):r>0&&(o+=n);return r>0&&o.trim()&&t.push(o.trim()),t}function Q(e){return "properties"in e&&typeof e.properties=="object"}function x(e){if(e instanceof Error){if(Q(e)&&e.properties?.errors){let t=e.properties.errors[0];return {message:t?.message||"Template processing error",variable:t?.properties?.tag,type:"render",originalError:e}}if(e.message.includes("undefined")){let t=e.message.match(/undefined (?:variable|tag):\s*(\S+)/i);return {message:e.message,variable:t?t[1]:void 0,type:"undefined",originalError:e}}return e.message.includes("parse")||e.message.includes("unclosed")||e.message.includes("syntax")?{message:e.message,type:"parse",originalError:e}:{message:e.message,type:"unknown",originalError:e}}return {message:String(e),type:"unknown"}}function he(e,t,r={}){let{linebreaks:o=true,delimiters:n}=r;try{let a=new g(e),i=new b(a,{paragraphLoop:!0,linebreaks:o,delimiters:n?{start:n.start||"{",end:n.end||"}"}:void 0});return i.setData(t),i.render(),i.getZip().generate({type:"arraybuffer",compression:"DEFLATE"})}catch(a){throw x(a)}}function ye(e={}){return (t,r)=>O(t,r,e)}var h={type:"string",description:"Document ID from a previous docx_load call"},Y={type:"object",properties:{paragraphIndex:{type:"number",description:"Index of the paragraph (0-indexed)"},offset:{type:"number",description:"Character offset within the paragraph"}},required:["paragraphIndex","offset"]},N={name:"docx_get_variables",description:`List all template variables ({{name}} format) found in the document.
|
|
2
2
|
Returns variable names without braces, along with their locations (body, headers, footers, etc.).
|
|
3
3
|
Use this to discover what data fields a template document expects.`,inputSchema:{type:"object",properties:{documentId:h},required:["documentId"]},handler:async(e,t)=>{let{documentId:r}=e,o=t.session.documents.get(r);if(!o)return {isError:true,content:[{type:"text",text:`Document not found: ${r}`}]};try{let n=V(o.document);return {content:[{type:"text",text:JSON.stringify({variables:n.variables,count:n.variables.length,totalOccurrences:n.totalOccurrences,byLocation:n.byLocation},null,2)}]}}catch(n){return {isError:true,content:[{type:"text",text:`Failed to detect variables: ${n.message}`}]}}},annotations:{category:"template",readOnly:true,complexity:"low",examples:[{description:"Get all variables from a loaded document",input:{documentId:"doc_123"},output:'{"variables": ["customer_name", "invoice_date"], "count": 2}'}]}},F={name:"docx_insert_variable",description:`Insert a template variable placeholder ({{name}}) at a specific position in the document.
|
|
4
4
|
The variable can later be substituted with actual values using docx_apply_template.
|
|
5
|
-
Variable names should follow the pattern: letters, numbers, underscores, starting with a letter.`,inputSchema:{type:"object",properties:{documentId:h,position:Y,variableName:{type:"string",description:'Variable name without braces (e.g., "customer_name"). Will be inserted as {{customer_name}}',pattern:"^[a-zA-Z_][a-zA-Z0-9_]*$"}},required:["documentId","position","variableName"]},handler:async(e,t)=>{let{documentId:r,position:o,variableName:n}=e,a=t.session.documents.get(r);if(!a)return {isError:true,content:[{type:"text",text:`Document not found: ${r}`}]};if(!/^[a-zA-Z_][a-zA-Z0-9_\-.]*$/.test(n))return {isError:true,content:[{type:"text",text:`Invalid variable name: ${n}. Must start with letter/underscore and contain only alphanumeric, underscore, hyphen, or dot.`}]};try{let{executeCommand:i}=await import('./executor-
|
|
5
|
+
Variable names should follow the pattern: letters, numbers, underscores, starting with a letter.`,inputSchema:{type:"object",properties:{documentId:h,position:Y,variableName:{type:"string",description:'Variable name without braces (e.g., "customer_name"). Will be inserted as {{customer_name}}',pattern:"^[a-zA-Z_][a-zA-Z0-9_]*$"}},required:["documentId","position","variableName"]},handler:async(e,t)=>{let{documentId:r,position:o,variableName:n}=e,a=t.session.documents.get(r);if(!a)return {isError:true,content:[{type:"text",text:`Document not found: ${r}`}]};if(!/^[a-zA-Z_][a-zA-Z0-9_\-.]*$/.test(n))return {isError:true,content:[{type:"text",text:`Invalid variable name: ${n}. Must start with letter/underscore and contain only alphanumeric, underscore, hyphen, or dot.`}]};try{let{executeCommand:i}=await import('./executor-44OB3DFD.js'),s=i(a.document,{type:"insertText",position:o,text:`{{${n}}}`});return a.document=s,a.lastModified=Date.now(),s.templateVariables||(s.templateVariables=[]),s.templateVariables.includes(n)||s.templateVariables.push(n),{content:[{type:"text",text:JSON.stringify({success:!0,variable:n,insertedAs:`{{${n}}}`,position:o})}]}}catch(i){return {isError:true,content:[{type:"text",text:`Failed to insert variable: ${i.message}`}]}}},annotations:{category:"template",readOnly:false,complexity:"low",examples:[{description:"Insert customer name variable at start of first paragraph",input:{documentId:"doc_123",position:{paragraphIndex:0,offset:0},variableName:"customer_name"}}]}},z={name:"docx_apply_template",description:`Substitute template variables with actual values in the document.
|
|
6
6
|
Replaces all {variable} placeholders with the corresponding values provided.
|
|
7
7
|
Preserves all formatting (fonts, styles, colors, tables).
|
|
8
|
-
Use docx_get_variables first to discover what variables exist in the document.`,inputSchema:{type:"object",properties:{documentId:h,variables:{type:"object",description:'Map of variable names to values (e.g., {"customer_name": "John Doe", "date": "2024-01-15"})',additionalProperties:{type:"string"}},keepUnmatchedVariables:{type:"boolean",description:"If true, keep {variable} placeholders for variables not in the map. If false, replace with empty string. Default: true",default:true}},required:["documentId","variables"]},handler:async(e,t)=>{let{documentId:r,variables:o,keepUnmatchedVariables:n=true}=e,a=t.session.documents.get(r);if(!a)return {isError:true,content:[{type:"text",text:`Document not found: ${r}`}]};if(!a.buffer)return {isError:true,content:[{type:"text",text:"Cannot apply template: document was not loaded from a DOCX buffer"}]};try{let i=E(a.buffer,o,{nullGetter:n?"keep":"empty"}),s=await
|
|
8
|
+
Use docx_get_variables first to discover what variables exist in the document.`,inputSchema:{type:"object",properties:{documentId:h,variables:{type:"object",description:'Map of variable names to values (e.g., {"customer_name": "John Doe", "date": "2024-01-15"})',additionalProperties:{type:"string"}},keepUnmatchedVariables:{type:"boolean",description:"If true, keep {variable} placeholders for variables not in the map. If false, replace with empty string. Default: true",default:true}},required:["documentId","variables"]},handler:async(e,t)=>{let{documentId:r,variables:o$1,keepUnmatchedVariables:n=true}=e,a=t.session.documents.get(r);if(!a)return {isError:true,content:[{type:"text",text:`Document not found: ${r}`}]};if(!a.buffer)return {isError:true,content:[{type:"text",text:"Cannot apply template: document was not loaded from a DOCX buffer"}]};try{let i=E(a.buffer,o$1,{nullGetter:n?"keep":"empty"}),s=await o(i.buffer);return a.document=s,a.buffer=i.buffer,a.lastModified=Date.now(),{content:[{type:"text",text:JSON.stringify({success:!0,replacedVariables:i.replacedVariables,unreplacedVariables:i.unreplacedVariables,warnings:i.warnings})}]}}catch(i){return {isError:true,content:[{type:"text",text:`Failed to apply template: ${i.message}`}]}}},annotations:{category:"template",readOnly:false,complexity:"medium",examples:[{description:"Fill in customer and date values",input:{documentId:"doc_123",variables:{customer_name:"Jane Smith",invoice_date:"2024-02-15",amount:"$1,234.56"}}}]}},H={name:"docx_validate_template",description:`Validate that a document is a valid docxtemplater template.
|
|
9
9
|
Checks for syntax errors like unclosed braces, invalid tag names, etc.
|
|
10
|
-
Returns validation result with any errors found and list of valid tags.`,inputSchema:{type:"object",properties:{documentId:h},required:["documentId"]},handler:async(e,t)=>{let{documentId:r}=e,o=t.session.documents.get(r);if(!o)return {isError:true,content:[{type:"text",text:`Document not found: ${r}`}]};if(!o.buffer)return {isError:true,content:[{type:"text",text:"Cannot validate template: document was not loaded from a DOCX buffer"}]};try{let n=L(o.buffer);return {content:[{type:"text",text:JSON.stringify({valid:n.valid,tags:n.tags,errors:n.errors.map(a=>({message:a.message,variable:a.variable,type:a.type}))},null,2)}]}}catch(n){return {isError:true,content:[{type:"text",text:`Failed to validate template: ${n.message}`}]}}},annotations:{category:"template",readOnly:true,complexity:"low"}},D=[N,F,z,H];var ee={id:"docxtemplater",name:"Docxtemplater",version:"1.0.0",description:"Template variable support using standard docxtemplater syntax ({variable})",commandHandlers:{insertTemplateVariable:v,replaceWithTemplateVariable:w},mcpTools:D,initialize:()=>{try{a("docxtemplater"),a("pizzip");}catch{console.warn("[docxtemplater-plugin] Warning: docxtemplater or pizzip not installed. Template features may not work. Install with: npm install docxtemplater pizzip");}}};export{U as a,V as b,j as c,R as d,B as e,
|
|
10
|
+
Returns validation result with any errors found and list of valid tags.`,inputSchema:{type:"object",properties:{documentId:h},required:["documentId"]},handler:async(e,t)=>{let{documentId:r}=e,o=t.session.documents.get(r);if(!o)return {isError:true,content:[{type:"text",text:`Document not found: ${r}`}]};if(!o.buffer)return {isError:true,content:[{type:"text",text:"Cannot validate template: document was not loaded from a DOCX buffer"}]};try{let n=L(o.buffer);return {content:[{type:"text",text:JSON.stringify({valid:n.valid,tags:n.tags,errors:n.errors.map(a=>({message:a.message,variable:a.variable,type:a.type}))},null,2)}]}}catch(n){return {isError:true,content:[{type:"text",text:`Failed to validate template: ${n.message}`}]}}},annotations:{category:"template",readOnly:true,complexity:"low"}},D=[N,F,z,H];var ee={id:"docxtemplater",name:"Docxtemplater",version:"1.0.0",description:"Template variable support using standard docxtemplater syntax ({variable})",commandHandlers:{insertTemplateVariable:v,replaceWithTemplateVariable:w},mcpTools:D,initialize:()=>{try{a("docxtemplater"),a("pizzip");}catch{console.warn("[docxtemplater-plugin] Warning: docxtemplater or pizzip not installed. Template features may not work. Install with: npm install docxtemplater pizzip");}}};export{U as a,V as b,j as c,R as d,B as e,ne as f,oe as g,ae as h,ie as i,se as j,ce as k,le as l,pe as m,O as n,E as o,fe as p,ge as q,L as r,be as s,xe as t,he as u,ye as v,J as w,ee as x};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import {b as b$1}from'./chunk-QHWHCIUW.js';function
|
|
1
|
+
import {b as b$1}from'./chunk-QHWHCIUW.js';function v(s,t){let a=b$1.getCommandHandler(t.type);if(a)return a(s,t);switch(t.type){case "insertText":return R(s,t);case "replaceText":return E(s,t);case "deleteText":return B(s,t);case "formatText":return S(s,t);case "formatParagraph":return V(s,t);case "applyStyle":return $(s,t);case "insertTable":return H(s,t);case "insertImage":return A(s,t);case "insertHyperlink":return F(s,t);case "removeHyperlink":return j(s,t);case "insertParagraphBreak":return T(s,t);case "mergeParagraphs":return N(s,t);case "splitParagraph":return M(s,t);case "setVariable":return O(s,t);case "applyVariables":return _(s,t);default:let r=t;throw new Error(`Unknown command type: ${r.type}`)}}function z(s,t){return t.reduce((a,r)=>v(a,r),s)}function h(s){return JSON.parse(JSON.stringify(s))}function g(s,t){let a=0;for(let r=0;r<s.content.length;r++)if(s.content[r].type==="paragraph"){if(a===t)return r;a++;}return -1}function I(s){let t="";for(let a of s.content)if(a.type==="run")for(let r of a.content)r.type==="text"&&(t+=r.text);else if(a.type==="hyperlink"){for(let r of a.children)if(r.type==="run")for(let e of r.content)e.type==="text"&&(t+=e.text);}return t}function b(s,t){return {type:"run",formatting:t,content:[{type:"text",text:s}]}}function C(s,t,a,r){let e=[],o=0,p=false;for(let n of s.content)if(n.type==="run"){let c=n.content.filter(l=>l.type==="text").map(l=>l.text).join(""),i=o,u=o+c.length;if(!p&&t>=i&&t<=u){let l=t-i;l>0&&e.push({...n,content:[{type:"text",text:c.slice(0,l)}]}),e.push(b(a,r||n.formatting)),l<c.length&&e.push({...n,content:[{type:"text",text:c.slice(l)}]}),p=true;}else e.push(n);o=u;}else e.push(n);return p||e.push(b(a,r)),e}function y(s,t,a){let r=[],e=0;for(let o of s.content)if(o.type==="run"){let p=o.content.filter(i=>i.type==="text").map(i=>i.text).join(""),n=e,c=e+p.length;if(c<=t||n>=a)r.push(o);else {let i="";n<t&&(i+=p.slice(0,t-n)),c>a&&(i+=p.slice(a-n)),i.length>0&&r.push({...o,content:[{type:"text",text:i}]});}e=c;}else r.push(o);return r}function D(s,t,a,r){let e=[],o=0;for(let p of s.content)if(p.type==="run"){let n=p.content.filter(u=>u.type==="text").map(u=>u.text).join(""),c=o,i=o+n.length;if(i<=t||c>=a)e.push(p);else if(c>=t&&i<=a)e.push({...p,formatting:{...p.formatting,...r}});else {let u=Math.max(t,c),l=Math.min(a,i);c<u&&e.push({...p,content:[{type:"text",text:n.slice(0,u-c)}]}),e.push({...p,formatting:{...p.formatting,...r},content:[{type:"text",text:n.slice(u-c,l-c)}]}),i>l&&e.push({...p,content:[{type:"text",text:n.slice(l-c)}]});}o=i;}else e.push(p);return e}function R(s,t){let a=h(s),r=a.package.document,e=g(r,t.position.paragraphIndex);if(e===-1)throw new Error(`Paragraph index ${t.position.paragraphIndex} not found`);let o=r.content[e];return o.content=C(o,t.position.offset,t.text,t.formatting),a}function E(s,t){let a=h(s),r=a.package.document,{start:e,end:o}=t.range;if(e.paragraphIndex===o.paragraphIndex){let p=g(r,e.paragraphIndex);if(p===-1)throw new Error(`Paragraph index ${e.paragraphIndex} not found`);let n=r.content[p];n.content=y(n,e.offset,o.offset),n.content=C(n,e.offset,t.text,t.formatting);}else {let p=g(r,e.paragraphIndex),n=r.content[p],c=I(n);n.content=y(n,e.offset,c.length),n.content=C(n,e.offset,t.text,t.formatting);let i=[];for(let u=e.paragraphIndex+1;u<=o.paragraphIndex;u++)i.push(g(r,u));for(let u=i.length-1;u>=0;u--)i[u]!==-1&&r.content.splice(i[u],1);}return a}function B(s,t){let a=h(s),r=a.package.document,{start:e,end:o}=t.range;if(e.paragraphIndex===o.paragraphIndex){let p=g(r,e.paragraphIndex);if(p===-1)throw new Error(`Paragraph index ${e.paragraphIndex} not found`);let n=r.content[p];n.content=y(n,e.offset,o.offset);}else {let p=g(r,e.paragraphIndex),n=r.content[p],c=I(n);n.content=y(n,e.offset,c.length);let i=g(r,o.paragraphIndex),u=r.content[i];u.content=y(u,0,o.offset),n.content.push(...u.content);let l=[];for(let f=e.paragraphIndex+1;f<=o.paragraphIndex;f++)l.push(g(r,f));for(let f=l.length-1;f>=0;f--)l[f]!==-1&&r.content.splice(l[f],1);}return a}function S(s,t){let a=h(s),r=a.package.document,{start:e,end:o}=t.range;if(e.paragraphIndex===o.paragraphIndex){let p=g(r,e.paragraphIndex);if(p===-1)throw new Error(`Paragraph index ${e.paragraphIndex} not found`);let n=r.content[p];n.content=D(n,e.offset,o.offset,t.formatting);}else for(let p=e.paragraphIndex;p<=o.paragraphIndex;p++){let n=g(r,p);if(n===-1)continue;let c=r.content[n],i=I(c),u=0,l=i.length;p===e.paragraphIndex&&(u=e.offset),p===o.paragraphIndex&&(l=o.offset),c.content=D(c,u,l,t.formatting);}return a}function V(s,t){let a=h(s),r=a.package.document,e=g(r,t.paragraphIndex);if(e===-1)throw new Error(`Paragraph index ${t.paragraphIndex} not found`);let o=r.content[e];if(o.formatting={...o.formatting,...t.formatting},"numPr"in t.formatting){let p=t.formatting.numPr;if(p&&p.numId!==void 0&&p.numId!==0){let n=p.ilvl??0,c=p.numId===1,i=c?"\u2022":"1.";if(a.package.numbering){let u=a.package.numbering.nums.find(l=>l.numId===p.numId);if(u){let l=a.package.numbering.abstractNums.find(f=>f.abstractNumId===u.abstractNumId);if(l){let f=l.levels.find(x=>x.ilvl===n);f&&(i=f.lvlText||i);}}}o.listRendering={level:n,numId:p.numId,marker:i,isBullet:c};}else delete o.listRendering;}return a}function $(s,t){let a=h(s),r=a.package.document,e=g(r,t.paragraphIndex);if(e===-1)throw new Error(`Paragraph index ${t.paragraphIndex} not found`);let o=r.content[e];return o.formatting={...o.formatting,styleId:t.styleId},a}function H(s,t){let a=h(s),r=a.package.document,e=[];for(let n=0;n<t.rows;n++){let c=[];for(let i=0;i<t.columns;i++){let u=t.data?.[n]?.[i]||"";c.push({type:"tableCell",content:[{type:"paragraph",content:u?[b(u)]:[]}]});}e.push({type:"tableRow",formatting:n===0&&t.hasHeader?{header:true}:void 0,cells:c});}let o={type:"table",rows:e},p=g(r,t.position.paragraphIndex);return p===-1?r.content.push(o):r.content.splice(p+1,0,o),a}function A(s,t){let a=h(s),r=a.package.document,e=g(r,t.position.paragraphIndex);if(e===-1)throw new Error(`Paragraph index ${t.position.paragraphIndex} not found`);let o=r.content[e],n={type:"run",content:[{type:"drawing",image:{type:"image",rId:`rId_img_${Date.now()}`,src:t.src,alt:t.alt,size:{width:(t.width||100)*914400,height:(t.height||100)*914400},wrap:{type:"inline"}}}]},c=C(o,t.position.offset,"",void 0),i=false,u=0;for(let l=0;l<c.length;l++){let f=c[l];if(f.type==="run"){let x=f.content.filter(d=>d.type==="text").map(d=>d.text).join("");if(u+=x.length,!i&&u>=t.position.offset){c.splice(l+1,0,n),i=true;break}}}return i||c.push(n),o.content=c,a}function F(s,t){let a=h(s),r=a.package.document,{start:e,end:o}=t.range;if(e.paragraphIndex!==o.paragraphIndex)throw new Error("Hyperlinks cannot span multiple paragraphs");let p=g(r,e.paragraphIndex);if(p===-1)throw new Error(`Paragraph index ${e.paragraphIndex} not found`);let n=r.content[p],c=I(n),i=t.displayText||c.slice(e.offset,o.offset);n.content=y(n,e.offset,o.offset);let u={type:"hyperlink",href:t.url,tooltip:t.tooltip,children:[b(i)]},l=false,f=0,x=[];for(let d of n.content)if(d.type==="run"){let P=d.content.filter(m=>m.type==="text").map(m=>m.text).join(""),w=f+P.length;if(!l&&f<=e.offset&&e.offset<=w){let m=e.offset-f;m>0&&x.push({...d,content:[{type:"text",text:P.slice(0,m)}]}),x.push(u),m<P.length&&x.push({...d,content:[{type:"text",text:P.slice(m)}]}),l=true;}else x.push(d);f=w;}else x.push(d);return l||x.push(u),n.content=x,a}function j(s,t){let a=h(s),r=a.package.document,{start:e}=t.range,o=g(r,e.paragraphIndex);if(o===-1)throw new Error(`Paragraph index ${e.paragraphIndex} not found`);let p=r.content[o],n=[];for(let c of p.content)if(c.type==="hyperlink")for(let i of c.children)i.type==="run"&&n.push(i);else n.push(c);return p.content=n,a}function T(s,t){let a=h(s),r=a.package.document,e=g(r,t.position.paragraphIndex);if(e===-1)throw new Error(`Paragraph index ${t.position.paragraphIndex} not found`);let o=r.content[e],p=I(o),n=y({...o,content:[...o.content]},t.position.offset,p.length),c=y({...o,content:[...o.content]},0,t.position.offset);o.content=n;let i={type:"paragraph",formatting:o.formatting,content:c};return r.content.splice(e+1,0,i),a}function N(s,t){let a=h(s),r=a.package.document,e=g(r,t.paragraphIndex);if(e===-1)throw new Error(`Paragraph index ${t.paragraphIndex} not found`);let o=r.content[e],p=[];for(let n=1;n<=t.count;n++){let c=g(r,t.paragraphIndex+n);if(c!==-1){let i=r.content[c];o.content.push(...i.content),p.push(c);}}for(let n=p.length-1;n>=0;n--)r.content.splice(p[n],1);return a}function M(s,t){return T(s,{position:t.position})}function O(s,t){let a=h(s);return a.templateVariables||(a.templateVariables=[]),a.templateVariables.includes(t.name)||a.templateVariables.push(t.name),a}function _(s,t){let a=h(s),r=a.package.document;function e(n){for(let c of n.content)if(c.type==="text")for(let[i,u]of Object.entries(t.values)){let l=new RegExp(`\\{${i}\\}`,"g");c.text=c.text.replace(l,u);}}function o(n){for(let c of n.content)if(c.type==="run")e(c);else if(c.type==="hyperlink")for(let i of c.children)i.type==="run"&&e(i);}function p(n){if(n.type==="paragraph")o(n);else if(n.type==="table")for(let c of n.rows)for(let i of c.cells)for(let u of i.content)p(u);}for(let n of r.content)p(n);return a}export{v as a,z as b};
|