@eigenpal/docx-js-editor 0.0.3 → 0.0.5
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 +69 -132
- package/dist/chunk-2CFVFSUH.js +57 -0
- package/dist/{chunk-YJJ7HRPG.js → chunk-AOL255XD.js} +1 -1
- package/dist/chunk-BBGDBZJY.cjs +1 -0
- package/dist/{chunk-CM5WP7HZ.cjs → chunk-D2GERZ7M.cjs} +2 -2
- package/dist/chunk-DQHQWQHL.cjs +11 -0
- package/dist/chunk-FXILBPZI.cjs +9 -0
- package/dist/chunk-H2UMX5CK.js +9 -0
- package/dist/chunk-HGOIKOKZ.js +1 -0
- package/dist/chunk-I2C6ENCR.js +11 -0
- package/dist/chunk-TL3YTVN2.cjs +57 -0
- package/dist/{colorResolver-Yakhydrt.d.ts → colorResolver-DrNkos_H.d.ts} +1 -32
- package/dist/{colorResolver-C-tITrbI.d.cts → colorResolver-WsUxFs5p.d.cts} +1 -32
- 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/headless.cjs +2 -2
- package/dist/headless.d.cts +4 -4
- package/dist/headless.d.ts +4 -4
- package/dist/headless.js +1 -1
- package/dist/index.cjs +43 -43
- package/dist/index.css +1 -1
- package/dist/index.d.cts +174 -363
- package/dist/index.d.ts +174 -363
- package/dist/index.js +43 -43
- package/dist/mcp-cli.js +21 -21
- package/dist/mcp.cjs +3 -3
- package/dist/mcp.d.cts +1 -1
- package/dist/mcp.d.ts +1 -1
- package/dist/mcp.js +1 -1
- package/dist/{registry-DeeU0bQB.d.cts → registry-BWDZlJx6.d.cts} +1 -1
- package/dist/{registry-D3zhko7n.d.ts → registry-DifIQR1O.d.ts} +1 -1
- package/dist/selectionRects-M7QY6HKR.cjs +1 -0
- package/dist/selectionRects-O6YQMMCP.js +1 -0
- package/dist/styles.css +1 -1
- package/dist/{types-BJXChtaM.d.cts → types-XVRXTi4o.d.cts} +509 -336
- package/dist/{types-BJXChtaM.d.ts → types-XVRXTi4o.d.ts} +509 -336
- package/package.json +10 -10
- package/dist/chunk-7KNRIGGW.cjs +0 -1
- package/dist/chunk-CDT2SOKB.cjs +0 -9
- package/dist/chunk-EU5LN2WS.js +0 -11
- package/dist/chunk-G4AXMTQY.cjs +0 -11
- package/dist/chunk-HRPNPUU4.js +0 -1
- package/dist/chunk-NI5OFVY2.js +0 -57
- package/dist/chunk-RGYAPHXT.cjs +0 -57
- package/dist/chunk-T3I3VSJ3.js +0 -9
- package/dist/selectionRects-3PJ6FGHQ.js +0 -1
- package/dist/selectionRects-6QL5E7CE.cjs +0 -1
package/README.md
CHANGED
|
@@ -1,10 +1,25 @@
|
|
|
1
|
-
|
|
1
|
+
<p align="center">
|
|
2
|
+
<a href="https://github.com/eigenpal/docx-js-editor">
|
|
3
|
+
<img src="./assets/logo.png" alt="DOCX JS Editor" width="600" />
|
|
4
|
+
</a>
|
|
5
|
+
</p>
|
|
6
|
+
|
|
7
|
+
<p align="center">
|
|
8
|
+
<a href="https://www.npmjs.com/package/@eigenpal/docx-js-editor"><img src="https://img.shields.io/npm/v/@eigenpal/docx-js-editor.svg?style=flat-square&color=00C853" alt="npm version" /></a>
|
|
9
|
+
<a href="https://www.npmjs.com/package/@eigenpal/docx-js-editor"><img src="https://img.shields.io/npm/dm/@eigenpal/docx-js-editor.svg?style=flat-square&color=00C853" alt="npm downloads" /></a>
|
|
10
|
+
<a href="https://github.com/eigenpal/docx-js-editor/blob/main/LICENSE"><img src="https://img.shields.io/badge/license-MIT-blue.svg?style=flat-square&color=00C853" alt="license" /></a>
|
|
11
|
+
<a href="https://docx-js-editor.vercel.app/"><img src="https://img.shields.io/badge/Live_Demo-00C853?style=flat-square&logo=vercel&logoColor=white" alt="Live Demo" /></a>
|
|
12
|
+
</p>
|
|
2
13
|
|
|
3
|
-
|
|
14
|
+
# @eigenpal/docx-js-editor
|
|
4
15
|
|
|
5
|
-
|
|
16
|
+
Open-source WYSIWYG DOCX editor for React. Open, edit, and save `.docx` files entirely in the browser — no server required. [Try the live demo.](https://docx-js-editor.vercel.app/)
|
|
6
17
|
|
|
7
|
-
|
|
18
|
+
<p align="center">
|
|
19
|
+
<a href="https://docx-js-editor.vercel.app/">
|
|
20
|
+
<img src="./assets/editor.png" alt="DOCX JS Editor screenshot" width="500" />
|
|
21
|
+
</a>
|
|
22
|
+
</p>
|
|
8
23
|
|
|
9
24
|
## Installation
|
|
10
25
|
|
|
@@ -12,164 +27,93 @@ An open-source, extendable WYSIWYG DOCX editor for JavaScript.
|
|
|
12
27
|
npm install @eigenpal/docx-js-editor
|
|
13
28
|
```
|
|
14
29
|
|
|
15
|
-
##
|
|
16
|
-
|
|
17
|
-
### Basic
|
|
18
|
-
|
|
19
|
-
```tsx
|
|
20
|
-
import DocxEditor from '@eigenpal/docx-js-editor';
|
|
21
|
-
import '@eigenpal/docx-js-editor/styles.css';
|
|
22
|
-
|
|
23
|
-
function App() {
|
|
24
|
-
return <DocxEditor onChange={(doc) => console.log(doc)} />;
|
|
25
|
-
}
|
|
26
|
-
```
|
|
27
|
-
|
|
28
|
-
### Load from backend
|
|
29
|
-
|
|
30
|
-
```tsx
|
|
31
|
-
import { useState, useEffect } from 'react';
|
|
32
|
-
import DocxEditor, { parseDocx, type Document } from '@eigenpal/docx-js-editor';
|
|
33
|
-
|
|
34
|
-
function App() {
|
|
35
|
-
const [document, setDocument] = useState<Document | null>(null);
|
|
36
|
-
|
|
37
|
-
useEffect(() => {
|
|
38
|
-
async function loadDocument() {
|
|
39
|
-
const response = await fetch('/api/documents/123');
|
|
40
|
-
const buffer = await response.arrayBuffer();
|
|
41
|
-
const doc = await parseDocx(buffer);
|
|
42
|
-
setDocument(doc);
|
|
43
|
-
}
|
|
44
|
-
loadDocument();
|
|
45
|
-
}, []);
|
|
46
|
-
|
|
47
|
-
if (!document) return <div>Loading...</div>;
|
|
48
|
-
|
|
49
|
-
return <DocxEditor document={document} />;
|
|
50
|
-
}
|
|
51
|
-
```
|
|
52
|
-
|
|
53
|
-
### Save to backend
|
|
30
|
+
## Quick Start
|
|
54
31
|
|
|
55
32
|
```tsx
|
|
56
33
|
import { useRef } from 'react';
|
|
57
|
-
import DocxEditor,
|
|
58
|
-
|
|
59
|
-
function App() {
|
|
60
|
-
const editorRef = useRef<DocxEditorRef>(null);
|
|
61
|
-
|
|
62
|
-
const handleSave = async () => {
|
|
63
|
-
const buffer = await editorRef.current?.save();
|
|
64
|
-
if (buffer) {
|
|
65
|
-
await fetch('/api/documents/123', {
|
|
66
|
-
method: 'PUT',
|
|
67
|
-
body: buffer,
|
|
68
|
-
});
|
|
69
|
-
}
|
|
70
|
-
};
|
|
71
|
-
|
|
72
|
-
return (
|
|
73
|
-
<>
|
|
74
|
-
<button onClick={handleSave}>Save</button>
|
|
75
|
-
<DocxEditor ref={editorRef} />
|
|
76
|
-
</>
|
|
77
|
-
);
|
|
78
|
-
}
|
|
79
|
-
```
|
|
80
|
-
|
|
81
|
-
### Full example (load + save)
|
|
82
|
-
|
|
83
|
-
```tsx
|
|
84
|
-
import { useState, useEffect, useRef } from 'react';
|
|
85
|
-
import DocxEditor, { parseDocx, type Document, type DocxEditorRef } from '@eigenpal/docx-js-editor';
|
|
34
|
+
import { DocxEditor, type DocxEditorRef } from '@eigenpal/docx-js-editor';
|
|
86
35
|
import '@eigenpal/docx-js-editor/styles.css';
|
|
87
36
|
|
|
88
|
-
function
|
|
37
|
+
function Editor({ file }: { file: ArrayBuffer }) {
|
|
89
38
|
const editorRef = useRef<DocxEditorRef>(null);
|
|
90
|
-
const [document, setDocument] = useState<Document | null>(null);
|
|
91
|
-
|
|
92
|
-
useEffect(() => {
|
|
93
|
-
fetch('/api/documents/123')
|
|
94
|
-
.then((r) => r.arrayBuffer())
|
|
95
|
-
.then((buffer) => parseDocx(buffer))
|
|
96
|
-
.then(setDocument);
|
|
97
|
-
}, []);
|
|
98
39
|
|
|
99
40
|
const handleSave = async () => {
|
|
100
41
|
const buffer = await editorRef.current?.save();
|
|
101
42
|
if (buffer) {
|
|
102
|
-
await fetch('/api/documents/
|
|
43
|
+
await fetch('/api/documents/1', { method: 'PUT', body: buffer });
|
|
103
44
|
}
|
|
104
45
|
};
|
|
105
46
|
|
|
106
|
-
if (!document) return <div>Loading...</div>;
|
|
107
|
-
|
|
108
47
|
return (
|
|
109
48
|
<>
|
|
110
49
|
<button onClick={handleSave}>Save</button>
|
|
111
|
-
<DocxEditor ref={editorRef}
|
|
50
|
+
<DocxEditor ref={editorRef} documentBuffer={file} onChange={() => {}} />
|
|
112
51
|
</>
|
|
113
52
|
);
|
|
114
53
|
}
|
|
115
54
|
```
|
|
116
55
|
|
|
117
|
-
|
|
56
|
+
> **Next.js / SSR:** The editor requires the DOM. Use a dynamic import or lazy `useEffect` load to avoid server-side rendering issues.
|
|
118
57
|
|
|
119
|
-
|
|
120
|
-
const editorRef = useRef<DocxEditorRef>(null);
|
|
121
|
-
|
|
122
|
-
// Save and get buffer
|
|
123
|
-
const buffer = await editorRef.current?.save();
|
|
58
|
+
## Props
|
|
124
59
|
|
|
125
|
-
|
|
126
|
-
|
|
60
|
+
| Prop | Type | Default | Description |
|
|
61
|
+
| ------------------- | ------------------------------- | ------- | ------------------------------------------- |
|
|
62
|
+
| `documentBuffer` | `ArrayBuffer` | — | `.docx` file contents to load |
|
|
63
|
+
| `document` | `Document` | — | Pre-parsed document (alternative to buffer) |
|
|
64
|
+
| `readOnly` | `boolean` | `false` | Disable editing |
|
|
65
|
+
| `showToolbar` | `boolean` | `true` | Show formatting toolbar |
|
|
66
|
+
| `showRuler` | `boolean` | `false` | Show horizontal ruler |
|
|
67
|
+
| `showZoomControl` | `boolean` | `true` | Show zoom controls |
|
|
68
|
+
| `showVariablePanel` | `boolean` | `true` | Show template variable panel |
|
|
69
|
+
| `initialZoom` | `number` | `1.0` | Initial zoom level |
|
|
70
|
+
| `onChange` | `(doc: Document) => void` | — | Called on document change |
|
|
71
|
+
| `onSave` | `(buffer: ArrayBuffer) => void` | — | Called on save |
|
|
72
|
+
| `onError` | `(error: Error) => void` | — | Called on error |
|
|
127
73
|
|
|
128
|
-
|
|
129
|
-
editorRef.current?.setZoom(1.5); // 150%
|
|
130
|
-
const zoom = editorRef.current?.getZoom();
|
|
131
|
-
|
|
132
|
-
// Navigation
|
|
133
|
-
editorRef.current?.focus();
|
|
134
|
-
editorRef.current?.scrollToPage(3);
|
|
135
|
-
```
|
|
136
|
-
|
|
137
|
-
### Headless mode (bring your own UI)
|
|
74
|
+
## Ref Methods
|
|
138
75
|
|
|
139
76
|
```tsx
|
|
140
|
-
|
|
77
|
+
const ref = useRef<DocxEditorRef>(null);
|
|
78
|
+
|
|
79
|
+
await ref.current.save(); // Returns ArrayBuffer of the .docx
|
|
80
|
+
ref.current.getDocument(); // Current document object
|
|
81
|
+
ref.current.setZoom(1.5); // Set zoom to 150%
|
|
82
|
+
ref.current.focus(); // Focus the editor
|
|
83
|
+
ref.current.scrollToPage(3); // Scroll to page 3
|
|
84
|
+
ref.current.print(); // Print the document
|
|
141
85
|
```
|
|
142
86
|
|
|
143
|
-
|
|
87
|
+
## Plugins
|
|
144
88
|
|
|
145
|
-
|
|
146
|
-
import {
|
|
147
|
-
Toolbar,
|
|
148
|
-
FontPicker,
|
|
149
|
-
ColorPicker,
|
|
150
|
-
parseDocx,
|
|
151
|
-
serializeDocx,
|
|
152
|
-
} from '@eigenpal/docx-js-editor';
|
|
153
|
-
```
|
|
154
|
-
|
|
155
|
-
### Template variables
|
|
89
|
+
Extend the editor with the plugin system. Wrap `DocxEditor` in a `PluginHost` and pass plugins that can contribute ProseMirror plugins, side panels, document overlays, and custom CSS:
|
|
156
90
|
|
|
157
91
|
```tsx
|
|
158
|
-
import {
|
|
92
|
+
import { DocxEditor, PluginHost, templatePlugin } from '@eigenpal/docx-js-editor';
|
|
159
93
|
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
}
|
|
94
|
+
function Editor({ file }: { file: ArrayBuffer }) {
|
|
95
|
+
return (
|
|
96
|
+
<PluginHost plugins={[templatePlugin]}>
|
|
97
|
+
<DocxEditor documentBuffer={file} />
|
|
98
|
+
</PluginHost>
|
|
99
|
+
);
|
|
100
|
+
}
|
|
164
101
|
```
|
|
165
102
|
|
|
103
|
+
| Plugin | Description |
|
|
104
|
+
| -------------------------------------- | -------------------------------------------------------------------------------------------- |
|
|
105
|
+
| [Docxtemplater](src/plugins/template/) | Syntax highlighting and annotation panel for [docxtemplater](https://docxtemplater.com) tags |
|
|
106
|
+
|
|
107
|
+
See [docs/PLUGINS.md](docs/PLUGINS.md) for the full plugin API, including how to create custom plugins with panels, overlays, and ProseMirror integrations.
|
|
108
|
+
|
|
166
109
|
## Features
|
|
167
110
|
|
|
168
111
|
- Full WYSIWYG editing with Microsoft Word fidelity
|
|
169
|
-
-
|
|
170
|
-
-
|
|
171
|
-
-
|
|
172
|
-
-
|
|
112
|
+
- Text and paragraph formatting (bold, italic, fonts, colors, alignment, spacing)
|
|
113
|
+
- Tables, images, hyperlinks
|
|
114
|
+
- Extensible plugin architecture
|
|
115
|
+
- Undo/redo, find & replace, keyboard shortcuts
|
|
116
|
+
- Print preview
|
|
173
117
|
- Zero server dependencies
|
|
174
118
|
|
|
175
119
|
## Development
|
|
@@ -179,13 +123,6 @@ bun install
|
|
|
179
123
|
bun run dev
|
|
180
124
|
```
|
|
181
125
|
|
|
182
|
-
## Contributing
|
|
183
|
-
|
|
184
|
-
This is an open-source project. Contributions are welcome!
|
|
185
|
-
|
|
186
|
-
- [Open an issue](https://github.com/eigenpal/docx-js-editor/issues) to report bugs or request features
|
|
187
|
-
- Submit pull requests to help improve the editor
|
|
188
|
-
|
|
189
126
|
## License
|
|
190
127
|
|
|
191
128
|
MIT
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import z from'jszip';function p(e){return e.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'")}function q(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 U(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 B(e){if(!e)return "";let t=[];if(e.styleId&&t.push(`<w:rStyle w:val="${p(e.styleId)}"/>`),e.fontFamily){let r=[];e.fontFamily.ascii&&r.push(`w:ascii="${p(e.fontFamily.ascii)}"`),e.fontFamily.hAnsi&&r.push(`w:hAnsi="${p(e.fontFamily.hAnsi)}"`),e.fontFamily.eastAsia&&r.push(`w:eastAsia="${p(e.fontFamily.eastAsia)}"`),e.fontFamily.cs&&r.push(`w:cs="${p(e.fontFamily.cs)}"`),e.fontFamily.asciiTheme&&r.push(`w:asciiTheme="${e.fontFamily.asciiTheme}"`),e.fontFamily.hAnsiTheme&&r.push(`w:hAnsiTheme="${e.fontFamily.hAnsiTheme}"`),e.fontFamily.eastAsiaTheme&&r.push(`w:eastAsiaTheme="${e.fontFamily.eastAsiaTheme}"`),e.fontFamily.csTheme&&r.push(`w:csTheme="${e.fontFamily.csTheme}"`),r.length>0&&t.push(`<w:rFonts ${r.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=q(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"&&t.push(`<w:highlight w:val="${e.highlight}"/>`),e.underline){let r=[`w:val="${e.underline.style}"`];e.underline.color&&(e.underline.color.rgb&&r.push(`w:color="${e.underline.color.rgb}"`),e.underline.color.themeColor&&r.push(`w:themeColor="${e.underline.color.themeColor}"`)),t.push(`<w:u ${r.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 i=U(e.shading);return i&&t.push(i),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 Z(e){return `<w:t${e.preserveSpace||e.text.startsWith(" ")||e.text.endsWith(" ")||e.text.includes(" ")?' xml:space="preserve"':""}>${p(e.text)}</w:t>`}function Y(e){return "<w:tab/>"}function J(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 K(e){return `<w:sym w:font="${p(e.font)}" w:char="${p(e.char)}"/>`}function Q(e){return e.type==="footnoteRef"?`<w:footnoteReference w:id="${e.id}"/>`:`<w:endnoteReference w:id="${e.id}"/>`}function ee(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 te(e){return `<w:instrText${e.text.startsWith(" ")||e.text.endsWith(" ")||e.text.includes(" ")?' xml:space="preserve"':""}>${p(e.text)}</w:instrText>`}function ne(e){return "<w:softHyphen/>"}function ie(e){return "<w:noBreakHyphen/>"}function S(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 re(e){if(!e||e.type==="none")return "<a:noFill/>";if(e.type==="solid"&&e.color)return `<a:solidFill>${S(e.color)}</a:solidFill>`;if(e.type==="gradient"&&e.gradient){let t=e.gradient,n=t.stops.map(r=>`<a:gs pos="${r.position}">${S(r.color)}</a:gs>`).join(""),i=t.type==="linear"?`<a:lin ang="${(t.angle||0)*6e4}" scaled="1"/>`:"";return `<a:gradFill><a:gsLst>${n}</a:gsLst>${i}</a:gradFill>`}return ""}function D(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>${S(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 j(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 i=e.vertical;return t.push(`<wp:positionV relativeFrom="${i.relativeTo}">`),i.alignment?t.push(`<wp:align>${i.alignment}</wp:align>`):t.push(`<wp:posOffset>${i.posOffset||0}</wp:posOffset>`),t.push("</wp:positionV>"),t.join("")}function k(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 se(e){let t=e.size.width,n=e.size.height,i=e.rId||"rId1",r=e.id||"0",s=e.filename||`image${r}`,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="${r}" name="${p(s)}"${e.alt?` descr="${p(e.alt)}"`:""}/>`,"<pic:cNvPicPr/>","</pic:nvPicPr>","<pic:blipFill>",`<a:blip r:embed="${i}"/>`,"<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?D(e.outline):"","</pic:spPr>","</pic:pic>","</a:graphicData>","</a:graphic>"].join("")}function oe(e){let t=e.image,n=t.wrap.type!=="inline",i=t.size.width,r=t.size.height,s=t.padding?.top??t.wrap.distT??0,o=t.padding?.bottom??t.wrap.distB??0,u=t.padding?.left??t.wrap.distL??0,f=t.padding?.right??t.wrap.distR??0,a=t.id||"1",l=t.title||t.filename||`Picture ${a}`,w=se(t);if(!n)return ["<w:drawing>",`<wp:inline distT="${s}" distB="${o}" distL="${u}" distR="${f}">`,`<wp:extent cx="${i}" cy="${r}"/>`,'<wp:effectExtent l="0" t="0" r="0" b="0"/>',`<wp:docPr id="${a}" name="${p(l)}"${t.alt?` descr="${p(t.alt)}"`:""}${t.decorative?' hidden="1"':""}/>`,'<wp:cNvGraphicFramePr><a:graphicFrameLocks xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main" noChangeAspect="1"/></wp:cNvGraphicFramePr>',w,"</wp:inline>","</w:drawing>"].join("");let m=t.wrap.type==="behind"?"1":"0",F=t.position?j(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=k(t.wrap);return ["<w:drawing>",`<wp:anchor distT="${s}" distB="${o}" distL="${u}" distR="${f}" simplePos="0" relativeHeight="251658240" behindDoc="${m}" locked="0" layoutInCell="1" allowOverlap="1">`,'<wp:simplePos x="0" y="0"/>',F,`<wp:extent cx="${i}" cy="${r}"/>`,'<wp:effectExtent l="0" t="0" r="0" b="0"/>',P,`<wp:docPr id="${a}" name="${p(l)}"${t.alt?` descr="${p(t.alt)}"`:""}/>`,'<wp:cNvGraphicFramePr><a:graphicFrameLocks xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main" noChangeAspect="1"/></wp:cNvGraphicFramePr>',w,"</wp:anchor>","</w:drawing>"].join("")}function ae(e){return e.map(t=>$(t)).join("")}function le(e){let t=e.shape,n=t.size.width,i=t.size.height,r=t.shapeType==="textBox",s=t.wrap&&t.wrap.type!=="inline",o=t.wrap?.distT??0,u=t.wrap?.distB??0,f=t.wrap?.distL??0,a=t.wrap?.distR??0,l=t.id||"1",w=t.name||(r?`TextBox ${l}`:`Shape ${l}`),m="";t.transform?.rotation&&(m+=` rot="${Math.round(t.transform.rotation*6e4)}"`),t.transform?.flipH&&(m+=' flipH="1"'),t.transform?.flipV&&(m+=' flipV="1"');let F=["<wps:spPr>",`<a:xfrm${m}>`,'<a:off x="0" y="0"/>',`<a:ext cx="${n}" cy="${i}"/>`,"</a:xfrm>",`<a:prstGeom prst="${t.shapeType==="textBox"?"rect":t.shapeType}"><a:avLst/></a:prstGeom>`,re(t.fill),D(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}"`)),r?P=["<wps:txbx><w:txbxContent>",ae(h.content),"</w:txbxContent></wps:txbx>",`<wps:bodyPr ${g.join(" ")}/>`].join(""):P=[`<wps:bodyPr ${g.join(" ")}/>`].join("");}let R=['<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${r?' txBox="1"':""}/>`,F,P,"</wps:wsp>"].join(""),"</a:graphicData>","</a:graphic>"].join("");if(!s)return ["<w:drawing>",`<wp:inline distT="${o}" distB="${u}" distL="${f}" distR="${a}">`,`<wp:extent cx="${n}" cy="${i}"/>`,'<wp:effectExtent l="0" t="0" r="0" b="0"/>',`<wp:docPr id="${l}" name="${p(w)}"/>`,"<wp:cNvGraphicFramePr/>",R,"</wp:inline>","</w:drawing>"].join("");let V=t.wrap?.type==="behind"?"1":"0",G=t.position?j(t.position):'<wp:positionH relativeFrom="column"><wp:posOffset>0</wp:posOffset></wp:positionH><wp:positionV relativeFrom="paragraph"><wp:posOffset>0</wp:posOffset></wp:positionV>',_=k(t.wrap);return ["<w:drawing>",`<wp:anchor distT="${o}" distB="${u}" distL="${f}" distR="${a}" simplePos="0" relativeHeight="251658240" behindDoc="${V}" locked="0" layoutInCell="1" allowOverlap="1">`,'<wp:simplePos x="0" y="0"/>',G,`<wp:extent cx="${n}" cy="${i}"/>`,'<wp:effectExtent l="0" t="0" r="0" b="0"/>',_,`<wp:docPr id="${l}" name="${p(w)}"/>`,"<wp:cNvGraphicFramePr/>",R,"</wp:anchor>","</w:drawing>"].join("")}function pe(e){switch(e.type){case "text":return Z(e);case "tab":return Y();case "break":return J(e);case "symbol":return K(e);case "footnoteRef":case "endnoteRef":return Q(e);case "fieldChar":return ee(e);case "instrText":return te(e);case "softHyphen":return ne();case "noBreakHyphen":return ie();case "drawing":return oe(e);case "shape":return le(e);default:return ""}}function y(e){let t=[],n=B(e.formatting);n&&t.push(n);for(let i of e.content){let r=pe(i);r&&t.push(r);}return `<w:r>${t.join("")}</w:r>`}function c(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 ce(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 ue(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 fe(e){return !e||e.length===0?"":`<w:tabs>${e.map(n=>{let i=[`w:val="${n.alignment}"`,`w:pos="${n.position}"`];return n.leader&&n.leader!=="none"&&i.push(`w:leader="${n.leader}"`),`<w:tab ${i.join(" ")}/>`}).join("")}</w:tabs>`}function he(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 de(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 we(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 me(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 ge(e){if(!e)return "";let t=[];e.styleId&&t.push(`<w:pStyle w:val="${c(e.styleId)}"/>`),e.keepNext&&t.push("<w:keepNext/>"),e.keepLines&&t.push("<w:keepLines/>"),e.pageBreakBefore&&t.push("<w:pageBreakBefore/>");let n=me(e.frame);n&&t.push(n),e.widowControl===false?t.push('<w:widowControl w:val="0"/>'):e.widowControl===true&&t.push("<w:widowControl/>");let i=we(e.numPr);i&&t.push(i);let r=ce(e.borders);r&&t.push(r);let s=ue(e.shading);s&&t.push(s);let o=fe(e.tabs);o&&t.push(o),e.suppressLineNumbers&&t.push("<w:suppressLineNumbers/>"),e.suppressAutoHyphens&&t.push("<w:suppressAutoHyphens/>");let u=he(e);u&&t.push(u);let f=de(e);if(f&&t.push(f),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 a=B(e.runProperties);a&&t.push(a);}return t.length===0?"":`<w:pPr>${t.join("")}</w:pPr>`}function C(e){let t=[];e.rId&&t.push(`r:id="${e.rId}"`),e.anchor&&t.push(`w:anchor="${c(e.anchor)}"`),e.tooltip&&t.push(`w:tooltip="${c(e.tooltip)}"`),e.target&&t.push(`w:tgtFrame="${c(e.target)}"`),e.history===false&&t.push('w:history="0"'),e.docLocation&&t.push(`w:docLocation="${c(e.docLocation)}"`);let n=e.children.map(r=>r.type==="run"?y(r):r.type==="bookmarkStart"?I(r):r.type==="bookmarkEnd"?X(r):"").join("");return `<w:hyperlink${t.length>0?" "+t.join(" "):""}>${n}</w:hyperlink>`}function I(e){let t=[`w:id="${e.id}"`,`w:name="${c(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 X(e){return `<w:bookmarkEnd w:id="${e.id}"/>`}function ye(e){let t=[`w:instr="${c(e.instruction)}"`];e.fldLock&&t.push('w:fldLock="true"'),e.dirty&&t.push('w:dirty="true"');let n=e.content.map(i=>i.type==="run"?y(i):i.type==="hyperlink"?C(i):"").join("");return `<w:fldSimple ${t.join(" ")}>${n}</w:fldSimple>`}function xe(e){let t=[],n=['w:fldCharType="begin"'];if(e.fldLock&&n.push('w:fldLock="true"'),e.dirty&&n.push('w:dirty="true"'),t.push(`<w:r><w:fldChar ${n.join(" ")}/></w:r>`),e.fieldCode.length>0)t.push(...e.fieldCode.map(i=>y(i)));else {let r=e.instruction.startsWith(" ")||e.instruction.endsWith(" ")||e.instruction.includes(" ")?' xml:space="preserve"':"";t.push(`<w:r><w:instrText${r}>${c(e.instruction)}</w:instrText></w:r>`);}return t.push('<w:r><w:fldChar w:fldCharType="separate"/></w:r>'),t.push(...e.fieldResult.map(i=>y(i))),t.push('<w:r><w:fldChar w:fldCharType="end"/></w:r>'),t.join("")}function $e(e){let t=e.properties,n=[];switch(t.alias&&n.push(`<w:alias w:val="${c(t.alias)}"/>`),t.tag&&n.push(`<w:tag w:val="${c(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="${c(t.dateFormat)}"/>`):n.push("<w:date/>");break;case "dropdown":{let r=(t.listItems??[]).map(s=>`<w:listItem w:displayText="${c(s.displayText)}" w:value="${c(s.value)}"/>`).join("");n.push(`<w:dropDownList>${r}</w:dropDownList>`);break}case "comboBox":{let r=(t.listItems??[]).map(s=>`<w:listItem w:displayText="${c(s.displayText)}" w:value="${c(s.value)}"/>`).join("");n.push(`<w:comboBox>${r}</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 i=e.content.map(r=>r.type==="run"?y(r):r.type==="hyperlink"?C(r):"").join("");return `<w:sdt><w:sdtPr>${n.join("")}</w:sdtPr><w:sdtContent>${i}</w:sdtContent></w:sdt>`}function E(e,t){let n=t.info,i=[`w:id="${n.id}"`,`w:author="${c(n.author)}"`];n.date&&i.push(`w:date="${c(n.date)}"`);let r=t.content.map(s=>s.type==="run"?y(s):s.type==="hyperlink"?C(s):"").join("");return `<w:${e} ${i.join(" ")}>${r}</w:${e}>`}function Te(e){switch(e.type){case "run":return y(e);case "hyperlink":return C(e);case "bookmarkStart":return I(e);case "bookmarkEnd":return X(e);case "simpleField":return ye(e);case "complexField":return xe(e);case "inlineSdt":return $e(e);case "commentRangeStart":return `<w:commentRangeStart w:id="${e.id}"/>`;case "commentRangeEnd":return `<w:commentRangeEnd w:id="${e.id}"/>`;case "insertion":return E("ins",e);case "deletion":return E("del",e);case "mathEquation":return e.ommlXml||"";default:return ""}}function $(e){let t=[],n=[];e.paraId&&n.push(`w14:paraId="${e.paraId}"`),e.textId&&n.push(`w14:textId="${e.textId}"`);let i=n.length>0?" "+n.join(" "):"",r=ge(e.formatting);r&&t.push(r);for(let s of e.content){let o=Te(s);o&&t.push(o);}return `<w:p${i}>${t.join("")}</w:p>`}function be(e){return e.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'")}function x(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 L(e,t){if(!e)return "";let n=[];if(e.top){let i=b(e.top,"top");i&&n.push(i);}if(e.left){let i=b(e.left,"left");i&&n.push(i);}if(e.bottom){let i=b(e.bottom,"bottom");i&&n.push(i);}if(e.right){let i=b(e.right,"right");i&&n.push(i);}if(e.insideH){let i=b(e.insideH,"insideH");i&&n.push(i);}if(e.insideV){let i=b(e.insideV,"insideV");i&&n.push(i);}return n.length===0?"":`<w:${t}>${n.join("")}</w:${t}>`}function O(e,t){if(!e)return "";let n=[];return e.top&&n.push(x(e.top,"top")),e.left&&n.push(x(e.left,"left")),e.bottom&&n.push(x(e.bottom,"bottom")),e.right&&n.push(x(e.right,"right")),n.length===0?"":`<w:${t}>${n.join("")}</w:${t}>`}function M(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 Pe(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 Ce(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 ve(e){if(!e)return "";let t=[];e.styleId&&t.push(`<w:tblStyle w:val="${be(e.styleId)}"/>`);let n=Ce(e.floating);n&&t.push(n),e.bidi&&t.push("<w:bidiVisual/>");let i=x(e.width,"tblW");i&&t.push(i),e.justification&&t.push(`<w:jc w:val="${e.justification}"/>`);let r=x(e.cellSpacing,"tblCellSpacing");r&&t.push(r);let s=x(e.indent,"tblInd");s&&t.push(s);let o=L(e.borders,"tblBorders");o&&t.push(o);let u=O(e.cellMargins,"tblCellMar");u&&t.push(u),e.layout&&t.push(`<w:tblLayout w:type="${e.layout}"/>`);let f=M(e.shading);f&&t.push(f);let a=Pe(e.look);return a&&t.push(a),e.overlap&&t.push(`<w:tblOverlap w:val="${e.overlap}"/>`),t.length===0?"":`<w:tblPr>${t.join("")}</w:tblPr>`}function Fe(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 Se(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 Be(e){if(!e)return "";let t=[],n=Se(e.conditionalFormat);n&&t.push(n);let i=x(e.width,"tcW");i&&t.push(i),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 r=L(e.borders,"tcBorders");r&&t.push(r);let s=M(e.shading);s&&t.push(s),e.noWrap&&t.push("<w:noWrap/>");let o=O(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 Ae(e){return !e||e.length===0?"":`<w:tblGrid>${e.map(n=>`<w:gridCol w:w="${n}"/>`).join("")}</w:tblGrid>`}function ze(e){let t=[];for(let n of e)n.type==="paragraph"?t.push($(n)):n.type==="table"&&t.push(A(n));return t.length===0&&t.push("<w:p/>"),t.join("")}function Re(e){let t=[],n=Be(e.formatting);return n&&t.push(n),t.push(ze(e.content)),`<w:tc>${t.join("")}</w:tc>`}function De(e){let t=[],n=Fe(e.formatting);n&&t.push(n);for(let i of e.cells)t.push(Re(i));return `<w:tr>${t.join("")}</w:tr>`}function A(e){let t=[],n=ve(e.formatting);n&&t.push(n);let i=Ae(e.columnWidths);i&&t.push(i);for(let r of e.rows)t.push(De(r));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 je(){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 v(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 ke(e){return `<w:headerReference ${[`w:type="${e.type}"`,`r:id="${e.rId}"`].join(" ")}/>`}function Ee(e){return `<w:footerReference ${[`w:type="${e.type}"`,`r:id="${e.rId}"`].join(" ")}/>`}function Ie(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 Xe(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 Le(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 Oe(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 Me(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(r=>{let s=[];return r.width!==void 0&&s.push(`w:w="${r.width}"`),r.space!==void 0&&s.push(`w:space="${r.space}"`),`<w:col ${s.join(" ")}/>`}).join("")),t.length===0&&!n?"":`<w:cols${t.length>0?" "+t.join(" "):""}>${n}</w:cols>`}function He(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 Ne(e){if(!e.pageBorders)return "";let t=e.pageBorders,n=[],i=[];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=v(t.top,"top");s&&i.push(s);}if(t.left){let s=v(t.left,"left");s&&i.push(s);}if(t.bottom){let s=v(t.bottom,"bottom");s&&i.push(s);}if(t.right){let s=v(t.right,"right");s&&i.push(s);}return i.length===0?"":`<w:pgBorders${n.length>0?" "+n.join(" "):""}>${i.join("")}</w:pgBorders>`}function We(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 Ve(e){if(!e)return "";let t=[];if(e.headerReferences)for(let l of e.headerReferences)t.push(ke(l));if(e.footerReferences)for(let l of e.footerReferences)t.push(Ee(l));let n=Ie(e.footnotePr);n&&t.push(n);let i=Xe(e.endnotePr);i&&t.push(i),e.sectionStart&&t.push(`<w:type w:val="${e.sectionStart}"/>`);let r=Le(e);r&&t.push(r);let s=Oe(e);if(s&&t.push(s),e.paperSrcFirst!==void 0||e.paperSrcOther!==void 0){let l=[];e.paperSrcFirst!==void 0&&l.push(`w:first="${e.paperSrcFirst}"`),e.paperSrcOther!==void 0&&l.push(`w:other="${e.paperSrcOther}"`),t.push(`<w:paperSrc ${l.join(" ")}/>`);}let o=Ne(e);o&&t.push(o);let u=He(e);u&&t.push(u);let f=Me(e);f&&t.push(f);let a=We(e);return a&&t.push(a),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 H(e){if(e.type==="paragraph")return $(e);if(e.type==="table")return A(e);if(e.type==="blockSdt"){let t=e.content.map(r=>H(r)).join(""),n=e.properties,i=[];return n.alias&&i.push(`<w:alias w:val="${n.alias}"/>`),n.tag&&i.push(`<w:tag w:val="${n.tag}"/>`),`<w:sdt><w:sdtPr>${i.join("")}</w:sdtPr><w:sdtContent>${t}</w:sdtContent></w:sdt>`}return ""}function Ge(e){return e.map(t=>H(t)).join("")}function _e(e){let t=[];return t.push(Ge(e.content)),e.finalSectionProperties&&t.push(Ve(e.finalSectionProperties)),t.join("")}function N(e){let t=[];t.push('<?xml version="1.0" encoding="UTF-8" standalone="yes"?>');let n=je();return t.push(`<w:document ${n} mc:Ignorable="w14 w15 wp14">`),t.push("<w:body>"),t.push(_e(e.package.document)),t.push("</w:body>"),t.push("</w:document>"),t.join("")}async function qe(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:i=true,modifiedBy:r}=t,s=await z.loadAsync(e.originalBuffer),o=new z;for(let[a,l]of Object.entries(s.files)){if(l.dir){o.folder(a.replace(/\/$/,""));continue}let w=await l.async("arraybuffer");o.file(a,w,{compression:"DEFLATE",compressionOptions:{level:n}});}let u=N(e);if(o.file("word/document.xml",u,{compression:"DEFLATE",compressionOptions:{level:n}}),i){let a="docProps/core.xml",l=s.file(a);if(l){let w=await l.async("text"),m=Ue(w,{updateModifiedDate:i,modifiedBy:r});o.file(a,m,{compression:"DEFLATE",compressionOptions:{level:n}});}}return await o.generateAsync({type:"arraybuffer",compression:"DEFLATE",compressionOptions:{level:n}})}function Ue(e,t){let n=e;if(t.updateModifiedDate){let i=new Date().toISOString();n.includes("<dcterms:modified")?n=n.replace(/<dcterms:modified[^>]*>[^<]*<\/dcterms:modified>/,`<dcterms:modified xsi:type="dcterms:W3CDTF">${i}</dcterms:modified>`):n=n.replace("</cp:coreProperties>",`<dcterms:modified xsi:type="dcterms:W3CDTF">${i}</dcterms:modified></cp:coreProperties>`);}return t.modifiedBy&&(n.includes("<cp:lastModifiedBy")?n=n.replace(/<cp:lastModifiedBy>[^<]*<\/cp:lastModifiedBy>/,`<cp:lastModifiedBy>${W(t.modifiedBy)}</cp:lastModifiedBy>`):n=n.replace("</cp:coreProperties>",`<cp:lastModifiedBy>${W(t.modifiedBy)}</cp:lastModifiedBy></cp:coreProperties>`)),n}function W(e){return e.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">")}async function Ze(){let e=new z;e.file("[Content_Types].xml",`<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
|
2
|
+
<Types xmlns="http://schemas.openxmlformats.org/package/2006/content-types">
|
|
3
|
+
<Default Extension="rels" ContentType="application/vnd.openxmlformats-package.relationships+xml"/>
|
|
4
|
+
<Default Extension="xml" ContentType="application/xml"/>
|
|
5
|
+
<Override PartName="/word/document.xml" ContentType="application/vnd.openxmlformats-officedocument.wordprocessingml.document.main+xml"/>
|
|
6
|
+
<Override PartName="/word/styles.xml" ContentType="application/vnd.openxmlformats-officedocument.wordprocessingml.styles+xml"/>
|
|
7
|
+
<Override PartName="/docProps/core.xml" ContentType="application/vnd.openxmlformats-package.core-properties+xml"/>
|
|
8
|
+
<Override PartName="/docProps/app.xml" ContentType="application/vnd.openxmlformats-officedocument.extended-properties+xml"/>
|
|
9
|
+
</Types>`),e.file("_rels/.rels",`<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
|
10
|
+
<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">
|
|
11
|
+
<Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument" Target="word/document.xml"/>
|
|
12
|
+
<Relationship Id="rId2" Type="http://schemas.openxmlformats.org/package/2006/relationships/metadata/core-properties" Target="docProps/core.xml"/>
|
|
13
|
+
<Relationship Id="rId3" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/extended-properties" Target="docProps/app.xml"/>
|
|
14
|
+
</Relationships>`),e.file("word/_rels/document.xml.rels",`<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
|
15
|
+
<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">
|
|
16
|
+
<Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles" Target="styles.xml"/>
|
|
17
|
+
</Relationships>`),e.file("word/document.xml",`<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
|
18
|
+
<w:document xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships">
|
|
19
|
+
<w:body>
|
|
20
|
+
<w:p>
|
|
21
|
+
<w:r>
|
|
22
|
+
<w:t></w:t>
|
|
23
|
+
</w:r>
|
|
24
|
+
</w:p>
|
|
25
|
+
<w:sectPr>
|
|
26
|
+
<w:pgSz w:w="12240" w:h="15840"/>
|
|
27
|
+
<w:pgMar w:top="1440" w:right="1440" w:bottom="1440" w:left="1440" w:header="720" w:footer="720" w:gutter="0"/>
|
|
28
|
+
</w:sectPr>
|
|
29
|
+
</w:body>
|
|
30
|
+
</w:document>`),e.file("word/styles.xml",`<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
|
31
|
+
<w:styles xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main">
|
|
32
|
+
<w:docDefaults>
|
|
33
|
+
<w:rPrDefault>
|
|
34
|
+
<w:rPr>
|
|
35
|
+
<w:rFonts w:ascii="Calibri" w:hAnsi="Calibri"/>
|
|
36
|
+
<w:sz w:val="22"/>
|
|
37
|
+
</w:rPr>
|
|
38
|
+
</w:rPrDefault>
|
|
39
|
+
<w:pPrDefault>
|
|
40
|
+
<w:pPr>
|
|
41
|
+
<w:spacing w:after="200" w:line="276" w:lineRule="auto"/>
|
|
42
|
+
</w:pPr>
|
|
43
|
+
</w:pPrDefault>
|
|
44
|
+
</w:docDefaults>
|
|
45
|
+
<w:style w:type="paragraph" w:default="1" w:styleId="Normal">
|
|
46
|
+
<w:name w:val="Normal"/>
|
|
47
|
+
</w:style>
|
|
48
|
+
</w:styles>`);let t=new Date().toISOString();return e.file("docProps/core.xml",`<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
|
49
|
+
<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">
|
|
50
|
+
<dc:creator>EigenPal DOCX Editor</dc:creator>
|
|
51
|
+
<dcterms:created xsi:type="dcterms:W3CDTF">${t}</dcterms:created>
|
|
52
|
+
<dcterms:modified xsi:type="dcterms:W3CDTF">${t}</dcterms:modified>
|
|
53
|
+
</cp:coreProperties>`),e.file("docProps/app.xml",`<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
|
54
|
+
<Properties xmlns="http://schemas.openxmlformats.org/officeDocument/2006/extended-properties">
|
|
55
|
+
<Application>EigenPal DOCX Editor</Application>
|
|
56
|
+
<AppVersion>1.0.0</AppVersion>
|
|
57
|
+
</Properties>`),e.generateAsync({type:"arraybuffer",compression:"DEFLATE",compressionOptions:{level:6}})}async function lt(e){let t=await Ze(),n={...e,originalBuffer:t};return qe(n)}export{Ve as a,_e as b,N as c,qe as d,lt as e};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {l}from'./chunk-
|
|
1
|
+
import {l}from'./chunk-I2C6ENCR.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 oe(e){return S.test(e)}function ae(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 ie(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 se(e){return `{${e}}`}function ce(e){let t=e.match(/^\{(.+?)\}$/);return t?t[1]:null}function le(e,t){return e&&e.replace(_,(r,o)=>{let n=o.trim();return n in t?t[n]:r})}function pe(e,t=""){return e&&e.replace(_,t)}function ue(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 ge(e,t,r={}){let o=O(e,t,r);return new Blob([o],{type:"application/vnd.openxmlformats-officedocument.wordprocessingml.document"})}function be(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 xe(e,t){return e.filter(r=>!(r in t)||t[r]===void 0||t[r]===null)}function he(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 ye(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 Te(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.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
'use strict';var K="Calibri";var _=null;function W(){if(!_){let e=typeof document<"u"?document.createElement("canvas"):null;if(!e)throw new Error("Canvas not available. Ensure this runs in a DOM environment.");if(_=e.getContext("2d"),!_)throw new Error("Failed to get 2D context from canvas")}return _}function ce(){_=null;}var oe='"Segoe UI", Arial, sans-serif';function U(e){let n=[];e.italic&&n.push("italic"),e.bold&&n.push("bold");let c=e.fontSize??11,r=J(c);n.push(`${r}px`);let a=e.fontFamily??K,t=a.includes(" ")?`"${a}"`:a;return n.push(`${t}, ${oe}`),n.join(" ")}function ae(e){let n=e.fontSize??11,c=e.fontFamily??K,r=J(n),a=r*.8,t=r*.2,s=r*1.15;try{let i=W();i.font=U(e);let o=i.measureText("Hg");typeof o.actualBoundingBoxAscent=="number"&&typeof o.actualBoundingBoxDescent=="number"&&(a=o.actualBoundingBoxAscent,t=o.actualBoundingBoxDescent),typeof o.fontBoundingBoxAscent=="number"&&typeof o.fontBoundingBoxDescent=="number"&&(s=o.fontBoundingBoxAscent+o.fontBoundingBoxDescent);}catch{}return s=Math.max(s,a+t),{fontSize:n,ascent:a,descent:t,lineHeight:s,fontFamily:c}}function se(e,n){if(!e)return 0;let c=W();c.font=U(n);let r=c.measureText(e),a=r.width,t=(r.actualBoundingBoxLeft||0)+(r.actualBoundingBoxRight||0),s=Math.max(a,t);return n.letterSpacing&&e.length>1&&(s+=n.letterSpacing*(e.length-1)),s}function G(e,n){let c=ae(n);if(!e)return {width:0,charWidths:[],metrics:c};let r=W();r.font=U(n);let a=n.letterSpacing??0,t=[],s=0;for(let i=0;i<e.length;i++){let o=e[i],m=r.measureText(o).width;a&&i<e.length-1&&(m+=a),t.push(m),s+=m;}return {width:s,charWidths:t,metrics:c}}function le(e,n){if(n.length===0||e<=0)return 0;let c=0;for(let r=0;r<n.length;r++){let a=n[r],t=c+a/2;if(e<=t)return r;c+=a;}return n.length}function J(e){return e*96/72}function $(e,n){let c=e.pageGap??0,r=0;for(let a=0;a<n&&a<e.pages.length;a++){let s=e.pages[a].size?.h??e.pageSize.h;r+=s+c;}return r}function Q(e,n){return e.findIndex(c=>c.id===n)}function ie(e,n){let c=0;for(let r=e.fromLine;r<e.toLine&&r<n.lines.length;r++)c+=n.lines[r].lineHeight;return c}function ge(e,n,c,r){let a=[...e.page.fragments].sort((t,s)=>{let i=t.y-s.y;return Math.abs(i)>.5?i:t.x-s.x});for(let t of a){let s=Q(n,t.blockId);if(s===-1)continue;let i=n[s],o=c[s];if(!i||!o)continue;let g;if(t.kind==="paragraph"){if(i.kind!=="paragraph"||o.kind!=="paragraph")continue;g=ie(t,o);}else if(t.kind==="table")g=t.height;else if(t.kind==="image")g=t.height;else continue;let m=r.x>=t.x&&r.x<=t.x+t.width,l=r.y>=t.y&&r.y<=t.y+g;if(m&&l)return {fragment:t,block:i,measure:o,pageIndex:e.pageIndex,localX:r.x-t.x,localY:r.y-t.y}}return null}function fe(e,n,c,r){for(let a of e.page.fragments){if(a.kind!=="table")continue;let t=a,s=r.x>=t.x&&r.x<=t.x+t.width,i=r.y>=t.y&&r.y<=t.y+t.height;if(!s||!i)continue;let o=Q(n,t.blockId);if(o===-1)continue;let g=n[o],m=c[o];if(!g||g.kind!=="table"||!m||m.kind!=="table")continue;let l=g,f=m,p=r.x-t.x,M=r.y-t.y,b=0,d=-1;if(f.rows.length===0||l.rows.length===0)continue;for(let u=t.fromRow;u<t.toRow&&u<f.rows.length;u++){let w=f.rows[u];if(M>=b&&M<b+w.height){d=u;break}b+=w.height;}if(d===-1&&(d=Math.min(t.toRow-1,f.rows.length-1),d<t.fromRow))continue;let h=f.rows[d],T=l.rows[d];if(!h||!T)continue;let x=0,k=-1;if(h.cells.length===0||T.cells.length===0)continue;for(let u=0;u<h.cells.length;u++){let w=h.cells[u];if(p>=x&&p<x+w.width){k=u;break}x+=w.width;}if(k===-1&&(k=h.cells.length-1,k<0))continue;let I=h.cells[k],B=T.cells[k];if(!I||!B)continue;let F=0;for(let u=t.fromRow;u<d;u++)F+=f.rows[u]?.height??0;let y=0;for(let u=0;u<k;u++)y+=h.cells[u]?.width??0;let S,P;if(B.blocks&&B.blocks.length>0){let u=B.blocks[0],w=I.blocks[0];u.kind==="paragraph"&&w?.kind==="paragraph"&&(S=u,P=w);}let R=p-y,H=M-F;return {fragment:t,block:l,measure:f,pageIndex:e.pageIndex,rowIndex:d,colIndex:k,cellBlock:S,cellMeasure:P,cellLocalX:Math.max(0,R),cellLocalY:Math.max(0,H)}}return null}function V(e){return {fontFamily:e.fontFamily??"Arial",fontSize:e.fontSize??12,bold:e.bold,italic:e.italic,letterSpacing:e.letterSpacing}}function Z(e,n){return e.findIndex(c=>c.id===n)}function z(e,n){let r=(e.pmStart??0)+1,a=0,t;for(let o=0;o<e.runs.length&&o<=n.toRun;o++){let g=e.runs[o];if(g){if(o<n.fromRun)g.kind==="text"?a+=(g.text??"").length:a+=1;else if(o===n.fromRun){a+=n.fromChar,t=r+a;break}}}t===void 0&&(t=r);let s=0;for(let o=n.fromRun;o<=n.toRun&&o<e.runs.length;o++){let g=e.runs[o];if(g)if(g.kind==="text"){let m=g.text??"",l=o===n.fromRun?n.fromChar:0,f=o===n.toRun?n.toChar:m.length;s+=f-l;}else s+=1;}let i=t+s;return {pmStart:t,pmEnd:i}}function ee(e,n,c,r){let a=[];for(let t=0;t<n.lines.length;t++){let s=n.lines[t],i=z(e,s);i.pmStart===void 0||i.pmEnd===void 0||i.pmEnd>c&&i.pmStart<r&&a.push({line:s,index:t});}return a}function X(e,n,c){let r=z(e,n);return r.pmStart===void 0?0:Math.max(0,c-r.pmStart)}function A(e,n,c,r){let a=0,t=0;for(let s=n.fromRun;s<=n.toRun&&s<e.runs.length;s++){let i=e.runs[s];if(i){if(i.kind==="tab"){let o=i.width??48;if(t+1>=c)return c<=t?a:a+o;a+=o,t+=1;continue}if(i.kind==="image"){let o=i.width;if(t+1>=c)return c<=t?a:a+o;a+=o,t+=1;continue}if(i.kind==="lineBreak"){if(c<=t)return a;t+=1;continue}if(i.kind==="text"){let o=i.text??"",g=s===n.fromRun,m=s===n.toRun,l=g?n.fromChar:0,f=m?n.toChar:o.length,p=o.slice(l,f);if(t+p.length>=c){let d=c-t,h=V(i),T=G(p.slice(0,d),h);return a+T.width}let M=V(i),b=G(p,M);a+=b.width,t+=p.length;}}}return a}function Y(e,n){let c=0;for(let r=0;r<n&&r<e.lines.length;r++)c+=e.lines[r].lineHeight;return c}function de(e,n,c,r,a){if(r===a)return [];let t=Math.min(r,a),s=Math.max(r,a),i=[];for(let o=0;o<e.pages.length;o++){let g=e.pages[o],m=$(e,o);for(let l of g.fragments){if(l.kind==="paragraph"){let f=Z(n,l.blockId);if(f===-1)continue;let p=n[f],M=c[f];if(!p||p.kind!=="paragraph"||!M||M.kind!=="paragraph")continue;let b=p,d=M,h=l,T=ee(b,d,t,s);for(let{line:x,index:k}of T){if(k<h.fromLine||k>=h.toLine)continue;let I=z(b,x);if(I.pmStart===void 0||I.pmEnd===void 0)continue;let B=Math.max(I.pmStart,t),F=Math.min(I.pmEnd,s);if(B>=F)continue;let y=X(b,x,B),S=X(b,x,F),P=b.attrs?.indent,R=P?.left??0,H=P?.right??0,u=Math.max(0,l.width-R-H),w=A(b,x,y),D=A(b,x,S),C=b.attrs?.alignment??"left",L=0;C==="center"?L=Math.max(0,(u-x.width)/2):C==="right"&&(L=Math.max(0,u-x.width));let v=Y(d,k)-Y(d,h.fromLine),E=l.x+R+L+Math.min(w,D),N=Math.max(1,Math.abs(D-w)),O=l.y+v;i.push({x:E,y:O+m,width:N,height:x.lineHeight,pageIndex:o});}}if(l.kind==="table"){let f=Z(n,l.blockId);if(f===-1)continue;let p=n[f],M=c[f];if(!p||p.kind!=="table"||!M||M.kind!=="table")continue;let b=p,d=M,h=l,T=0;for(let x=h.fromRow;x<h.toRow&&x<b.rows.length;x++){let k=b.rows[x],I=d.rows[x];if(!k||!I)continue;let B=0;for(let F=0;F<k.cells.length;F++){let y=k.cells[F],S=I.cells[F];if(!(!y||!S)){for(let P=0;P<y.blocks.length;P++){let R=y.blocks[P],H=S.blocks[P];if(!R||R.kind!=="paragraph"||!H||H.kind!=="paragraph")continue;let u=R,w=H,D=ee(u,w,t,s),C=0;for(let{line:L,index:v}of D){let E=z(u,L);if(E.pmStart===void 0||E.pmEnd===void 0)continue;let N=Math.max(E.pmStart,t),O=Math.min(E.pmEnd,s);if(N>=O)continue;let te=X(u,L,N),ne=X(u,L,O),j=A(u,L,te,S.width),q=A(u,L,ne,S.width),re=Y(w,v);i.push({x:h.x+B+Math.min(j,q),y:h.y+T+C+re+m,width:Math.max(1,Math.abs(q-j)),height:L.lineHeight,pageIndex:o});}C+=w.totalHeight;}B+=S.width;}}T+=I.height;}}if(l.kind==="image"){let f=l.pmStart??0;(l.pmEnd??f+1)>t&&f<s&&i.push({x:l.x,y:l.y+m,width:l.width,height:l.height,pageIndex:o});}}}return i}function xe(e,n,c,r){for(let a=0;a<e.pages.length;a++){let t=e.pages[a],s=$(e,a);for(let i of t.fragments){if(i.kind==="paragraph"){let o=Z(n,i.blockId);if(o===-1)continue;let g=n[o],m=c[o];if(!g||g.kind!=="paragraph"||!m||m.kind!=="paragraph")continue;let l=g,f=m,p=i,M=l.pmStart??0,b=l.pmEnd??M;if(r<M||r>b)continue;for(let d=p.fromLine;d<p.toLine;d++){let h=f.lines[d];if(!h)continue;let T=z(l,h);if(!(T.pmStart===void 0||T.pmEnd===void 0)&&r>=T.pmStart&&r<=T.pmEnd){let x=X(l,h,r),k=l.attrs?.indent,I=k?.left??0,B=k?.right??0,F=Math.max(0,i.width-I-B),y=A(l,h,x),S=l.attrs?.alignment??"left",P=0;S==="center"?P=Math.max(0,(F-h.width)/2):S==="right"&&(P=Math.max(0,F-h.width));let R=Y(f,d)-Y(f,p.fromLine);return {x:i.x+I+P+y,y:i.y+R+s,height:h.lineHeight,pageIndex:a}}}}if(i.kind==="image"){let o=i.pmStart??0,g=i.pmEnd??o+1;if(r>=o&&r<=g){let m=r===o?0:i.width;return {x:i.x+m,y:i.y+s,height:i.height,pageIndex:a}}}}}return null}function be(e){return e.length<=1?false:new Set(e.map(c=>c.pageIndex)).size>1}function ke(e){let n=new Map;for(let c of e){let r=n.get(c.pageIndex)??[];r.push(c),n.set(c.pageIndex,r);}return n}exports.a=ce;exports.b=ae;exports.c=se;exports.d=G;exports.e=le;exports.f=J;exports.g=ge;exports.h=fe;exports.i=de;exports.j=xe;exports.k=be;exports.l=ke;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
'use strict';var
|
|
1
|
+
'use strict';var chunkDQHQWQHL_cjs=require('./chunk-DQHQWQHL.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 oe(e){return S.test(e)}function ae(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 ie(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 se(e){return `{${e}}`}function ce(e){let t=e.match(/^\{(.+?)\}$/);return t?t[1]:null}function le(e,t){return e&&e.replace(_,(r,o)=>{let n=o.trim();return n in t?t[n]:r})}function pe(e,t=""){return e&&e.replace(_,t)}function ue(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 ge(e,t,r={}){let o=O(e,t,r);return new Blob([o],{type:"application/vnd.openxmlformats-officedocument.wordprocessingml.document"})}function be(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 xe(e,t){return e.filter(r=>!(r in t)||t[r]===void 0||t[r]===null)}function he(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 ye(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 Te(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
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-FSMRGT73.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 chunkDQHQWQHL_cjs.l(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
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=oe;exports.g=ae;exports.h=ie;exports.i=se;exports.j=ce;exports.k=le;exports.l=pe;exports.m=ue;exports.n=O;exports.o=E;exports.p=ge;exports.q=be;exports.r=L;exports.s=xe;exports.t=he;exports.u=ye;exports.v=Te;exports.w=J;exports.x=ee;
|