mdast2docx 0.1.1 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. package/README.md +242 -203
  2. package/dist/chunk-GP6KO6J3.mjs +3 -0
  3. package/dist/{chunk-D4MVNKG6.mjs → chunk-GS5L4UWU.mjs} +1 -1
  4. package/dist/chunk-IW743AEN.mjs +1 -0
  5. package/dist/chunk-LXTXD4UG.mjs +1 -0
  6. package/dist/chunk-M5XHL7AG.mjs +4 -0
  7. package/dist/chunk-QR3NYQYH.mjs +1 -0
  8. package/dist/chunk-YNJKJBFY.mjs +3 -0
  9. package/dist/index.d.ts +1 -2
  10. package/dist/index.js +3 -2
  11. package/dist/index.mjs +1 -1
  12. package/dist/mdast.d.ts +1076 -0
  13. package/dist/mdast.js +1 -0
  14. package/dist/plugins/html.d.ts +9 -0
  15. package/dist/plugins/html.js +3 -1
  16. package/dist/plugins/html.mjs +1 -0
  17. package/dist/plugins/image.d.ts +8 -4
  18. package/dist/plugins/image.js +1 -1
  19. package/dist/plugins/image.mjs +1 -1
  20. package/dist/plugins/index.d.ts +1 -0
  21. package/dist/plugins/index.js +2 -74
  22. package/dist/plugins/index.mjs +1 -1
  23. package/dist/plugins/list.js +1 -1
  24. package/dist/plugins/list.mjs +1 -1
  25. package/dist/plugins/math.js +1 -75
  26. package/dist/plugins/math.mjs +1 -1
  27. package/dist/plugins/{node.js → node/index.js} +1 -1
  28. package/dist/plugins/node/index.mjs +1 -0
  29. package/dist/plugins/{node-image.d.ts → node/node-image.d.ts} +9 -5
  30. package/dist/plugins/{node-image.js → node/node-image.js} +1 -1
  31. package/dist/plugins/node/node-image.mjs +1 -0
  32. package/dist/section.d.ts +2 -7
  33. package/dist/section.js +3 -2
  34. package/dist/section.mjs +1 -1
  35. package/dist/utils.d.ts +22 -9
  36. package/dist/utils.js +1 -1
  37. package/dist/utils.mjs +1 -1
  38. package/package.json +95 -92
  39. package/dist/chunk-7LR5HC5O.mjs +0 -4
  40. package/dist/chunk-7W4N3GRD.mjs +0 -75
  41. package/dist/chunk-AHXJDPOO.mjs +0 -2
  42. package/dist/chunk-IBVI6OKS.mjs +0 -1
  43. package/dist/chunk-XIRSNIMN.mjs +0 -1
  44. package/dist/chunk-ZKNVKZAF.mjs +0 -1
  45. package/dist/plugins/node-image.mjs +0 -1
  46. package/dist/plugins/node.mjs +0 -1
  47. /package/dist/plugins/{node.d.ts → node/index.d.ts} +0 -0
package/README.md CHANGED
@@ -1,203 +1,242 @@
1
- # **MDAST (Markdown Abstract Syntax Tree) to DOCX** <img src="https://raw.githubusercontent.com/mayank1513/mayank1513/main/popper.png" style="height: 40px"/>
2
-
3
- 🚀 **Effortlessly convert Markdown Abstract Syntax Trees (MDAST) to DOCX.**
4
-
5
- [![Test](https://github.com/tiny-md/mdast2docx/actions/workflows/test.yml/badge.svg)](https://github.com/tiny-md/mdast2docx/actions/workflows/test.yml) [![Maintainability](https://api.codeclimate.com/v1/badges/aa896ec14c570f3bb274/maintainability)](https://codeclimate.com/github/tiny-md/mdast2docx/maintainability) [![Code Coverage](https://codecov.io/gh/tiny-md/mdast2docx/graph/badge.svg)](https://codecov.io/gh/tiny-md/mdast2docx) [![Version](https://img.shields.io/npm/v/mdast2docx.svg?colorB=green)](https://www.npmjs.com/package/mdast2docx) [![Downloads](https://img.shields.io/npm/d18m/mdast2docx)](https://www.npmjs.com/package/mdast2docx) ![Bundle Size](https://img.shields.io/bundlephobia/minzip/mdast2docx)
6
-
7
- ---
8
-
9
- ## **✨ Features**
10
-
11
- ✅ **MDAST to DOCX conversion** — Supports standard Markdown elements
12
- ✅ **Footnotes handling** — Converts Markdown footnotes to DOCX format
13
- ✅ **Tables support** — Converts Markdown tables into DOCX tables
14
- ✅ **Hyperlink support** — External and internal hyperlinks are now fully functional
15
- ✅ **New Plugin Architecture** — Extend and customize DOCX output with plugins
16
- ✅ **Customizable image handling** — Images are now supported via `imagePlugin`
17
-
18
- > **Note:** Images are no longer supported by default. To enable image support, use the `imagePlugin` explicitly.
19
- >
20
- > This change helps us keep the library lean and extensible by community via plugins.
21
-
22
- ---
23
-
24
- ## **📦 Installation**
25
-
26
- Install the package using `pnpm`, `npm`, or `yarn`:
27
-
28
- ```bash
29
- pnpm add mdast2docx
30
- ```
31
-
32
- **_or_**
33
-
34
- ```bash
35
- npm install mdast2docx
36
- ```
37
-
38
- **_or_**
39
-
40
- ```bash
41
- yarn add mdast2docx
42
- ```
43
-
44
- ---
45
-
46
- ## **🚀 Usage**
47
-
48
- ### **Basic Example**
49
-
50
- ```typescript
51
- import { toDocx } from "mdast2docx";
52
- import { unified } from "unified";
53
- import remarkParse from "remark-parse";
54
- import remarkMmd from "remark-mmd"; // Assumed MMD plugin
55
-
56
- const markdown = `
57
- # Sample Document
58
- This is a **bold** text and _italic_ text.
59
-
60
- > A blockquote example
61
-
62
- - List Item 1
63
- - List Item 2
64
-
65
- [Click Here](https://example.com)
66
-
67
- This is a footnote reference[^1].
68
-
69
- [^1]: This is the footnote content.
70
- `;
71
-
72
- const mdast = unified().use(remarkParse).use(remarkMmd).parse(markdown);
73
-
74
- (async () => {
75
- const docxBlob = await toDocx(mdast, { title: "My Document" }, {});
76
- const url = URL.createObjectURL(docxBlob as Blob);
77
- const link = document.createElement("a");
78
- link.href = url;
79
- link.download = "document.docx";
80
- link.click();
81
- URL.revokeObjectURL(url);
82
- })();
83
- ```
84
-
85
- ---
86
-
87
- ## **📜 API Reference**
88
-
89
- ### **`toDocx(astInputs, docxProps, defaultSectionProps, outputType?)`**
90
-
91
- | Parameter | Type | Description |
92
- | ------------------------- | -------------------------------------------------- | ---------------------------------------------------------------- |
93
- | `astInputs` | `Root` \| `{ ast: Root; props?: ISectionProps }[]` | Single or multiple MDAST trees with optional section properties. |
94
- | `docxProps` | `IDocxProps` | General document properties (title, styles, metadata). |
95
- | `defaultSectionProps` | `ISectionProps` | Default properties for document sections. |
96
- | `outputType` _(optional)_ | `"blob"` (default) \| `"buffer"` \| `"base64"` | Format of the generated DOCX document. |
97
-
98
- 📌 **Returns:** A `Promise` resolving to a DOCX document in the chosen format.
99
-
100
- ---
101
-
102
- ## **📜 Supported Markdown Elements**
103
-
104
- | Markdown Syntax | Supported in DOCX |
105
- | ---------------------------------- | ------------------------------------- |
106
- | Headings `# H1` to `###### H6` | ✅ |
107
- | Paragraphs | ✅ |
108
- | Bold `**text**` & Italics `_text_` | ✅ |
109
- | Blockquotes `> quote` | ✅ |
110
- | Lists (ordered & unordered) | ✅ _(ordered lists via `listPlugin`)_ |
111
- | Links `[text](url)` | ✅ |
112
- | Images `![alt](url)` | ✅ _(via `imagePlugin`)_ |
113
- | Code Blocks `` `code` `` | ✅ |
114
- | Footnotes `[^1]` | ✅ |
115
- | Tables | ✅ _(via `tablePlugin`)_ |
116
- | Hyperlinks (external & internal) | ✅ |
117
- | HTML Tags | 🚧 _(Work in progress)_ |
118
-
119
- ---
120
-
121
- ## **🔧 Configuration**
122
-
123
- You can customize the DOCX output using `ISectionProps` and `IDocxProps`.
124
-
125
- ### **Example: Customizing Styles**
126
-
127
- ```typescript
128
- const docxProps = {
129
- title: "Styled Document",
130
- author: "John Doe",
131
- };
132
-
133
- const sectionProps = {
134
- page: { margin: { top: 1000, bottom: 1000, left: 1200, right: 1200 } },
135
- };
136
-
137
- const docxBlob = await toDocx(mdast, docxProps, sectionProps);
138
- ```
139
-
140
- ### **Use Plugins**
141
-
142
- Plugins allow extending functionality like adding image or table support.
143
-
144
- ```typescript
145
- import { toDocx } from "mdast2docx";
146
- import { imagePlugin, tablePlugin, listPlugin, mathPlugin } from "mdast2docx/dist/plugins";
147
-
148
- const downloadDocx = () => {
149
- toDocx(
150
- mdast,
151
- {},
152
- { plugins: [imagePlugin(), tablePlugin(), listPlugin(), mathPlugin()] },
153
- "blob",
154
- ).then(blob => {
155
- const url = URL.createObjectURL(blob as Blob);
156
- const link = document.createElement("a");
157
- link.href = url;
158
- link.download = "my-document.docx";
159
- link.click();
160
- URL.revokeObjectURL(url);
161
- });
162
- };
163
- ```
164
-
165
- 📖 **More details:**
166
-
167
- - [DOCX.js Document Properties](https://docx.js.org/#/usage/document)
168
- - [DOCX.js Section Options](https://docx.js.org/#/usage/sections)
169
-
170
- ---
171
-
172
- ## **📝 Contributing**
173
-
174
- We welcome contributions! To get started:
175
-
176
- 1. **Fork** the repository
177
- 2. **Create a feature branch** (`git checkout -b feature-new`)
178
- 3. **Commit your changes** (`git commit -m "Add new feature"`)
179
- 4. **Push to GitHub** (`git push origin feature-new`)
180
- 5. **Open a Pull Request** 🚀
181
-
182
- ### **Extend Functionality with Plugins**
183
-
184
- The community can create plugins to extend the functionality of this library. For inspiration, check out the existing plugins in the [`lib/src/plugins`](https://github.com/tiny-md/mdast2docx/tree/main/lib/src/plugins) folder.
185
-
186
- ---
187
-
188
- ## **📄 License**
189
-
190
- This project is **licensed under MPL-2.0**. See the [LICENSE](./LICENSE) file for details.
191
-
192
- ---
193
-
194
- ## **🙌 Acknowledgments**
195
-
196
- Thanks to the **docx.js** and **unified.js** ecosystems for making this possible.
197
-
198
- > ⭐ **Star this repository** if you find it useful!
199
- > ❤️ Support our work by [sponsoring](https://github.com/sponsors/mayank1513).
200
-
201
- ---
202
-
203
- <p align="center">Made with 💖 by <a href="https://mayank-chaudhari.vercel.app" target="_blank">Mayank Kumar Chaudhari</a></p>
1
+ # **MDAST (Markdown Abstract Syntax Tree) to DOCX** <img src="https://raw.githubusercontent.com/mayank1513/mayank1513/main/popper.png" style="height: 40px"/>
2
+
3
+ 🚀 **Effortlessly convert Markdown Abstract Syntax Trees (MDAST) to DOCX.**
4
+
5
+ [![Test](https://github.com/tiny-md/mdast2docx/actions/workflows/test.yml/badge.svg)](https://github.com/tiny-md/mdast2docx/actions/workflows/test.yml) [![Maintainability](https://api.codeclimate.com/v1/badges/aa896ec14c570f3bb274/maintainability)](https://codeclimate.com/github/tiny-md/mdast2docx/maintainability) [![Code Coverage](https://codecov.io/gh/tiny-md/mdast2docx/graph/badge.svg)](https://codecov.io/gh/tiny-md/mdast2docx) [![Version](https://img.shields.io/npm/v/mdast2docx.svg?colorB=green)](https://www.npmjs.com/package/mdast2docx) [![Downloads](https://img.shields.io/npm/d18m/mdast2docx)](https://www.npmjs.com/package/mdast2docx) ![Bundle Size](https://img.shields.io/bundlephobia/minzip/mdast2docx)
6
+
7
+ ---
8
+
9
+ ## **✨ Features**
10
+
11
+ ✅ **MDAST to DOCX conversion** — Supports standard Markdown elements
12
+ ✅ **Footnotes handling** — Converts Markdown footnotes to DOCX format
13
+ ✅ **Tables support** — Converts Markdown tables into DOCX tables
14
+ ✅ **Hyperlink support** — External and internal hyperlinks are now fully functional
15
+ ✅ **New Plugin Architecture** — Extend and customize DOCX output with plugins
16
+ ✅ **Customizable image handling** — Images are now supported via `imagePlugin`
17
+
18
+ > **Note:** Images are no longer supported by default. To enable image support, use the `imagePlugin` explicitly.
19
+ >
20
+ > This change helps us keep the library lean and extensible by community via plugins.
21
+
22
+ ---
23
+
24
+ Got it! Here's an improved version of the **"🚀 Relevance to Generative AI"** section that reflects this process accurately:
25
+
26
+ ---
27
+
28
+ ## **🚀 Relevance to Generative AI**
29
+
30
+ <details open>
31
+ <summary>
32
+ <i>Converts markdown content/artifacts generated by Generative AI to docx for further processing/record-keeping/sharing.</i>
33
+ </summary>
34
+
35
+ Modern **Generative AI tools** often produce structured content in **Markdown (MD)** format. However, converting this AI-generated Markdown into **professional DOCX documents** requires an additional transformation step. This is where **MDAST to DOCX** comes in.
36
+
37
+ ### **How It Works**
38
+
39
+ 1. **AI tools generate content in Markdown**.
40
+ 2. **Unified.js & Remark Ecosystem** convert Markdown into **Markdown Abstract Syntax Tree (MDAST)**.
41
+ 3. **MDAST to DOCX** processes this structure and exports a **well-formatted DOCX document**.
42
+
43
+ ### **Use Cases**
44
+
45
+ - **AI-Generated Reports** – Convert AI-generated Markdown reports into polished DOCX files.
46
+ - **AI-Powered Content Export** – Transform AI-generated blogs, research papers, and structured content into a DOCX format for easy sharing and editing.
47
+ - **Client & Server Flexibility** – Works both in **browser-based AI tools** and **high-performance server environments**.
48
+
49
+ ### **✅ Benefits**
50
+
51
+ - **Works on both Client & Server** – Choose to **offload processing to the client** for better scalability or **run it on the server** for batch conversions.
52
+ - **Optimized & Extensible** – Use **only the plugins you need**, keeping your AI workflows lightweight.
53
+
54
+ By integrating **MDAST to DOCX**, AI applications can **seamlessly export Markdown-based content into DOCX**, making it more accessible, editable, and shareable. 🚀
55
+
56
+ </details>
57
+
58
+ ---
59
+
60
+ ---
61
+
62
+ ## **📦 Installation**
63
+
64
+ Install the package using `pnpm`, `npm`, or `yarn`:
65
+
66
+ ```bash
67
+ pnpm add mdast2docx
68
+ ```
69
+
70
+ **_or_**
71
+
72
+ ```bash
73
+ npm install mdast2docx
74
+ ```
75
+
76
+ **_or_**
77
+
78
+ ```bash
79
+ yarn add mdast2docx
80
+ ```
81
+
82
+ ---
83
+
84
+ ## **🚀 Usage**
85
+
86
+ ### **Basic Example**
87
+
88
+ ```typescript
89
+ import { toDocx } from "mdast2docx";
90
+ import { unified } from "unified";
91
+ import remarkParse from "remark-parse";
92
+ import remarkMmd from "remark-mmd"; // Assumed MMD plugin
93
+
94
+ const markdown = `
95
+ # Sample Document
96
+ This is a **bold** text and _italic_ text.
97
+
98
+ > A blockquote example
99
+
100
+ - List Item 1
101
+ - List Item 2
102
+
103
+ [Click Here](https://example.com)
104
+
105
+ This is a footnote reference[^1].
106
+
107
+ [^1]: This is the footnote content.
108
+ `;
109
+
110
+ const mdast = unified().use(remarkParse).use(remarkMmd).parse(markdown);
111
+
112
+ (async () => {
113
+ const docxBlob = await toDocx(mdast, { title: "My Document" }, {});
114
+ const url = URL.createObjectURL(docxBlob as Blob);
115
+ const link = document.createElement("a");
116
+ link.href = url;
117
+ link.download = "document.docx";
118
+ link.click();
119
+ URL.revokeObjectURL(url);
120
+ })();
121
+ ```
122
+
123
+ ---
124
+
125
+ ## **📜 API Reference**
126
+
127
+ ### **`toDocx(astInputs, docxProps, defaultSectionProps, outputType?)`**
128
+
129
+ | Parameter | Type | Description |
130
+ | ------------------------- | -------------------------------------------------- | ---------------------------------------------------------------- |
131
+ | `astInputs` | `Root` \| `{ ast: Root; props?: ISectionProps }[]` | Single or multiple MDAST trees with optional section properties. |
132
+ | `docxProps` | `IDocxProps` | General document properties (title, styles, metadata). |
133
+ | `defaultSectionProps` | `ISectionProps` | Default properties for document sections. |
134
+ | `outputType` _(optional)_ | `"blob"` (default) \| `"buffer"` \| `"base64"` | Format of the generated DOCX document. |
135
+
136
+ 📌 **Returns:** A `Promise` resolving to a DOCX document in the chosen format.
137
+
138
+ ---
139
+
140
+ ## **📜 Supported Markdown Elements**
141
+
142
+ | Markdown Syntax | Supported in DOCX |
143
+ | ---------------------------------- | ------------------------------------- |
144
+ | Headings `# H1` to `###### H6` | ✅ |
145
+ | Paragraphs | ✅ |
146
+ | Bold `**text**` & Italics `_text_` | ✅ |
147
+ | Blockquotes `> quote` | ✅ |
148
+ | Lists (ordered & unordered) | ✅ _(ordered lists via `listPlugin`)_ |
149
+ | Links `[text](url)` | ✅ |
150
+ | Images `![alt](url)` | ✅ _(via `imagePlugin`)_ |
151
+ | Code Blocks `` `code` `` | ✅ |
152
+ | Footnotes `[^1]` | ✅ |
153
+ | Tables | ✅ _(via `tablePlugin`)_ |
154
+ | Hyperlinks (external & internal) | ✅ |
155
+ | Latex Math | 🚧 _(via `mathPlugin`; in progress)_ |
156
+ | HTML Tags | 🚧 _(Work in progress; beta)_ |
157
+
158
+ ---
159
+
160
+ ## **🔧 Configuration**
161
+
162
+ You can customize the DOCX output using `ISectionProps` and `IDocxProps`.
163
+
164
+ ### **Example: Customizing Styles**
165
+
166
+ ```typescript
167
+ const docxProps = {
168
+ title: "Styled Document",
169
+ author: "John Doe",
170
+ };
171
+
172
+ const sectionProps = {
173
+ page: { margin: { top: 1000, bottom: 1000, left: 1200, right: 1200 } },
174
+ };
175
+
176
+ const docxBlob = await toDocx(mdast, docxProps, sectionProps);
177
+ ```
178
+
179
+ ### **Use Plugins**
180
+
181
+ Plugins allow extending functionality like adding image or table support.
182
+
183
+ ```typescript
184
+ import { toDocx } from "mdast2docx";
185
+ import { imagePlugin, tablePlugin, listPlugin, mathPlugin } from "mdast2docx/dist/plugins";
186
+
187
+ const downloadDocx = () => {
188
+ toDocx(
189
+ mdast,
190
+ {},
191
+ { plugins: [imagePlugin(), tablePlugin(), listPlugin(), mathPlugin()] },
192
+ "blob",
193
+ ).then(blob => {
194
+ const url = URL.createObjectURL(blob as Blob);
195
+ const link = document.createElement("a");
196
+ link.href = url;
197
+ link.download = "my-document.docx";
198
+ link.click();
199
+ URL.revokeObjectURL(url);
200
+ });
201
+ };
202
+ ```
203
+
204
+ 📖 **More details:**
205
+
206
+ - [DOCX.js Document Properties](https://docx.js.org/#/usage/document)
207
+ - [DOCX.js Section Options](https://docx.js.org/#/usage/sections)
208
+
209
+ ---
210
+
211
+ ## **📝 Contributing**
212
+
213
+ We welcome contributions! To get started:
214
+
215
+ 1. **Fork** the repository
216
+ 2. **Create a feature branch** (`git checkout -b feature-new`)
217
+ 3. **Commit your changes** (`git commit -m "Add new feature"`)
218
+ 4. **Push to GitHub** (`git push origin feature-new`)
219
+ 5. **Open a Pull Request** 🚀
220
+
221
+ ### **Extend Functionality with Plugins**
222
+
223
+ The community can create plugins to extend the functionality of this library. For inspiration, check out the existing plugins in the [`lib/src/plugins`](https://github.com/tiny-md/mdast2docx/tree/main/lib/src/plugins) folder.
224
+
225
+ ---
226
+
227
+ ## **📄 License**
228
+
229
+ This project is **licensed under MPL-2.0**. See the [LICENSE](./LICENSE) file for details.
230
+
231
+ ---
232
+
233
+ ## **🙌 Acknowledgments**
234
+
235
+ Thanks to the **docx.js** and **unified.js** ecosystems for making this possible.
236
+
237
+ > ⭐ **Star this repository** if you find it useful!
238
+ > ❤️ Support our work by [sponsoring](https://github.com/sponsors/mayank1513).
239
+
240
+ ---
241
+
242
+ <p align="center">Made with 💖 by <a href="https://mayank-chaudhari.vercel.app" target="_blank">Mayank Kumar Chaudhari</a></p>
@@ -0,0 +1,3 @@
1
+ import{f as b}from"./chunk-IW743AEN.mjs";import{AlignmentType as T,BorderStyle as l,FrameAnchorType as N,HorizontalPositionAlign as A,VerticalPositionAlign as R}from"docx";var k=["BR","IMG","EM","I","STRONG","B","DEL","S","A","SUP","SUB","IMG"],C={BR:"break",IMG:"image",EM:"emphasis",I:"emphasis",STRONG:"strong",B:"strong",DEL:"delete",S:"delete",A:"link"},S=["solid","dashed","dotted","double","none","ridge","groove","inset","outset"],H=t=>{var n;if(!t)return{};let r={},e=t.match(/border(-\w+)?:\s*[^;]+/gi);if(!e)return{};for(let s of e){let[a,i]=s.split(":").map(c=>c.trim()),d=i.split(/\s+/),p=(n=d.find(c=>c.endsWith("px")))==null?void 0:n.replace("px",""),o=d.find(c=>S.includes(c.toLowerCase())),m=d.find(c=>!c.endsWith("px")&&!S.includes(c.toLowerCase())),y=a==="border"?"border":a.replace("border-","");r[y]={...p?{width:parseInt(p,1)}:{},...o?{style:o}:{},...m?{color:m}:{}}}return r},O={solid:l.SINGLE,dashed:l.DASHED,dotted:l.DOTTED,double:l.DOUBLE,none:l.NONE,ridge:l.THREE_D_EMBOSS,groove:l.THREE_D_ENGRAVE,inset:l.INSET,outset:l.OUTSET},u=t=>{if(!t||!Object.keys(t).length)return;let{width:r,color:e,style:n}=t,s={style:n?O[n]:l.SINGLE};return r&&(s.size=r),e&&(s.color=b(e)),s},E=(t,r=!0)=>{let e={};if(!(t instanceof HTMLElement||t instanceof SVGElement))return e;let{textAlign:n,fontWeight:s,fontStyle:a,textDecoration:i,textTransform:d,color:p}=t.style,o=H(t.getAttribute("style"));if(r&&o.border)e.border=u(o.border);else if(Object.keys(o).length){let m={...o.border,...o.left},y={...o.border,...o.right},c={...o.border,...o.top},B={...o.border,...o.bottom};e.border={left:u(m),right:u(y),top:u(c),bottom:u(B)}}switch(n&&(Object.keys(T).includes(n)?e.alignment=n:n==="justify"&&(e.alignment=T.JUSTIFIED)),(/bold/.test(s)||parseInt(s)>=500)&&(e.bold=!0),/(italic|oblique)/.test(a)&&(e.italics=!0),i){case"underline":e.underline={};break;case"overline":e.emphasisMark={};break;case"line-through":e.strike=!0;break}return d==="uppercase"&&(e.allCaps=!0),d==="lowercase"&&(e.smallCaps=!0),p&&(e.color=b(p)),t.tagName==="SUP"?e.superScript=!0:t.tagName==="SUB"?e.subScript=!0:["STRONG","B"].includes(t.tagName)?e.bold=!0:["EM","I"].includes(t.tagName)?e.italics=!0:["DEL","S"].includes(t.tagName)?e.strike=!0:["U","INS"].includes(t.tagName)?e.underline={}:t.tagName==="MARK"?(e.highlight="yellow",e.emphasisMark={}):t.tagName==="PRE"&&(e.pre=!0),e},h=t=>{var s,a,i,d;if(!(t instanceof HTMLElement||t instanceof SVGElement))return{type:"text",value:(s=t.textContent)!=null?s:""};let r=Array.from(t.childNodes).map(h),e=E(t),n=t.getAttributeNames().reduce((p,o)=>({...p,[o]:t.getAttribute(o)}),{});switch(t.tagName){case"BR":return{type:"break"};case"IMG":return{type:"image",url:(a=n.src)!=null?a:"",alt:(i=n.alt)!=null?i:"",data:{...e,...n}};case"SVG":return{type:"image",url:`data:image/svg+xml;base64,${t.outerHTML}`,data:e};case"EM":case"I":case"STRONG":case"B":case"DEL":case"S":return{type:C[t.tagName],children:r,data:e};case"A":return{type:"link",url:(d=n.href)!=null?d:"",children:r,data:e};case"INPUT":if(/(radio|checkbox)/.test(t.type))return{type:"checkbox"}}return{type:"fragment",children:r,data:e}},I=(t,r)=>Array.from(t.children).map(e=>{let n={...r,...E(e)};return e instanceof HTMLTableRowElement?{type:"tableRow",children:Array.from(e.children).map(s=>({type:"tableCell",children:[h(s)]})),data:n}:I(e,n)}).flat(),g={style:"single"},M={left:g,right:g,top:g,bottom:g},D=t=>{let r=E(t);switch(t.tagName){case"H1":case"H2":case"H3":case"H4":case"H5":case"H6":return{type:"heading",depth:parseInt(t.tagName[1]),children:Array.from(t.childNodes).map(h),data:r};case"PRE":case"P":case"DIV":case"DETAILS":case"SUMMARY":case"FORM":case"LI":return f(t,r);case"UL":case"OL":return{type:"list",ordered:t.tagName==="OL",children:Array.from(t.childNodes).map(e=>({type:"listItem",children:[f(e)],data:r}))};case"HR":return{type:"thematicBreak",data:r};case"BLOCKQUOTE":return{type:"blockquote",children:Array.from(t.childNodes).map(e=>f(e)),data:r};case"TABLE":return{type:"table",children:I(t),data:r};case"STYLE":return{type:"paragraph",children:[{type:"text",value:`Not supported yet!
2
+
3
+ ${t.textContent}`}],data:{...r,pre:!0,border:M}};case"INPUT":if(!/(radio|checkbox)/.test(t.type))return{type:"paragraph",children:[],data:{...r,frame:{width:5e3,height:90,alignment:{x:A.LEFT,y:R.CENTER},anchor:{horizontal:N.TEXT,vertical:N.TEXT},type:"alignment"},border:M}}}return{type:"paragraph",children:[h(t)],data:r}},f=(t,r)=>{let e=Array.from(t.childNodes),n=[],s=[];for(let a of e)(a instanceof HTMLElement||a instanceof SVGElement)&&!k.includes(a.tagName)?(s.length&&(n.push({type:"paragraph",children:s.map(h)}),s.length=0),n.push(D(a))):s.push(a);return s.length&&n.push({type:"paragraph",children:s.map(h)}),n.length===1?{...n[0],data:{...r,...n[0].data}}:{type:"fragment",children:n,data:r}},L=t=>{var n,s;let r=[],e=[];for(let a of t.children)if((n=a.children)!=null&&n.length&&L(a),a.type==="html"&&/^<[^>]*[^/]>$/.test(a.value)){let i=a.value.split(" ")[0].slice(1);i[0]==="/"?((s=e[0])==null?void 0:s.tag)===i.slice(1,-1)&&r.push(e.shift()):e.unshift({...a,children:[],tag:i})}else e.length?e[0].children.push(a):r.push(a);t.children=r},_=()=>({block:async(t,r)=>{if(r.type==="html"){let e=document.createElement("div");e.innerHTML=r.value,Object.assign(r,f(e))}return[]},inline:async(t,r)=>{var e,n;if(r.type==="html"){let s=(n=(e=r.value)==null?void 0:e.trim())!=null?n:"",a=s.split(" ")[0].slice(1),i=document.createElement("div");i.innerHTML=s.endsWith("/>")?s:`${s}</${a}>`,Object.assign(r,{...h(i.children[0]),children:r.children})}return[]},preprocess:L});export{_ as a};
@@ -1 +1 @@
1
- import{c as g}from"./chunk-IBVI6OKS.mjs";import{AlignmentType as v,convertInchesToTwip as O,LevelFormat as e}from"docx";var E=[e.DECIMAL,e.DECIMAL,e.DECIMAL,e.DECIMAL,e.UPPER_LETTER,e.LOWER_LETTER,e.LOWER_ROMAN,e.UPPER_ROMAN],b=(c,o=.4,u=.25)=>c.map((i,t)=>({level:t,format:i,text:(i===e.DECIMAL?Array(t+1).fill(`%${t+1}`).join("."):`%${t+1}`)+".",alignment:v.START,style:{paragraph:{indent:{left:O(o+t*u)}}}})),R=b(E),y=["\u25CF","\u25CB","\u25A0","\u25C6","\u25B6","\u25C9","\u2B24","\u2666","\u25E6","\u25AA"],A={levels:R,bullets:y,defaultBullets:!1},x=c=>{let o=g(),u=`numbering-${o}`,i=`bullet-${o}`,{levels:t,bulletLevels:f,bullets:m,defaultBullets:I}={...A,...c};return{block:async(L,l,n,a)=>{var s,p;if(l.type!=="list")return[];let r=((p=(s=n.bullet)==null?void 0:s.level)!=null?p:-1)+1;return n.numbering=I?void 0:{level:r,reference:l.ordered?u:i},n.bullet={level:r},l.type="",await a(l,n)},root:L=>{var l,n;L.numbering={config:[...(n=(l=L.numbering)==null?void 0:l.config)!=null?n:[],{reference:u,levels:t},{reference:i,levels:f!=null?f:t.map((a,r)=>{var s;return{...a,text:(s=m[r])!=null?s:"\u2022",format:e.BULLET}})}]}}}};export{b as a,x as b};
1
+ import{c as g}from"./chunk-IW743AEN.mjs";import{AlignmentType as v,convertInchesToTwip as O,LevelFormat as e}from"docx";var E=[e.DECIMAL,e.DECIMAL,e.DECIMAL,e.DECIMAL,e.UPPER_LETTER,e.LOWER_LETTER,e.LOWER_ROMAN,e.UPPER_ROMAN],b=(c,o=.4,u=.25)=>c.map((i,t)=>({level:t,format:i,text:(i===e.DECIMAL?Array(t+1).fill(`%${t+1}`).join("."):`%${t+1}`)+".",alignment:v.START,style:{paragraph:{indent:{left:O(o+t*u)}}}})),R=b(E),y=["\u25CF","\u25CB","\u25A0","\u25C6","\u25B6","\u25C9","\u2B24","\u2666","\u25E6","\u25AA"],A={levels:R,bullets:y,defaultBullets:!1},x=c=>{let o=g(),u=`numbering-${o}`,i=`bullet-${o}`,{levels:t,bulletLevels:f,bullets:m,defaultBullets:I}={...A,...c};return{block:async(L,l,n,a)=>{var s,p;if(l.type!=="list")return[];let r=((p=(s=n.bullet)==null?void 0:s.level)!=null?p:-1)+1;return n.numbering=I?void 0:{level:r,reference:l.ordered?u:i},n.bullet={level:r},l.type="",await a(l,n)},root:L=>{var l,n;L.numbering={config:[...(n=(l=L.numbering)==null?void 0:l.config)!=null?n:[],{reference:u,levels:t},{reference:i,levels:f!=null?f:t.map((a,r)=>{var s;return{...a,text:(s=m[r])!=null?s:"\u2022",format:e.BULLET}})}]}}}};export{b as a,x as b};
@@ -0,0 +1 @@
1
+ import{convertInchesToTwip as f,convertMillimetersToTwip as P}from"docx";var i=t=>{let e={},n={};return t.forEach(o=>{var r;o.type==="definition"?e[o.identifier.toUpperCase()]=o.url:o.type==="footnoteDefinition"?n[o.identifier.toUpperCase()]={children:o.children}:(r=o.children)!=null&&r.length&&Object.assign(e,i(o.children))}),{definitions:e,footnoteDefinitions:n}},a=t=>{var e,n;return(e=t.children)!=null&&e.length?t.children.map(a).join(""):(n=t.value)!=null?n:""},s=()=>Math.random().toString(16).slice(2),p={useTitle:!0,plugins:[]},l={styles:{default:{document:{paragraph:{spacing:{before:175,line:300},alignment:"thaiDistribute"},run:{size:24}},heading1:{paragraph:{spacing:{before:350}}},heading2:{paragraph:{spacing:{before:350}}},heading3:{paragraph:{spacing:{before:350}}},heading4:{paragraph:{spacing:{before:350}}},heading5:{paragraph:{spacing:{before:350}}},heading6:{paragraph:{spacing:{before:350}}}}}},c=t=>{let e=document.createElement("canvas").getContext("2d");return e?(e.fillStyle=t,e.fillStyle.slice(1)):t.startsWith("#")?t.slice(1):"auto"};export{i as a,a as b,s as c,p as d,l as e,c as f,f as g,P as h};
@@ -0,0 +1 @@
1
+ var I=["jpeg","jpg","bmp","gif","png"],f=e=>{let a=new Uint8Array(e).slice(0,4);if(a[0]===66&&a[1]===77)return"bmp";switch(a.reduce((n,r)=>n+r.toString(16).padStart(2,"0"),"")){case"89504E47":return"png";case"47494638":return"gif";case"FFD8FFE0":case"FFD8FFE1":case"FFD8FFE2":case"FFD8FFE3":case"FFD8FFE8":return"jpg"}},d=3,p=async(e,a)=>{var l,h;let t=(l=a==null?void 0:a.scale)!=null?l:d,n=document.createElement("canvas"),r=n.getContext("2d");if(!r)throw new Error("Canvas context not available");let i=new Image;i.src=e,await new Promise(u=>i.onload=u);let s=i.width*t,g=i.height*t;n.width=s,n.height=g,r.drawImage(i,0,0,s,g);let m=e.split(";")[0].split("/")[1];if(I.includes(m))return{data:e,type:m,transformation:{width:s/t,height:g/t}};let o=(h=a==null?void 0:a.fallbackImageType)!=null?h:"png",c={data:n.toDataURL(`image/${o}`),type:o,transformation:{width:s/t,height:g/t}};return e.includes("svg")?{...c,type:"svg",data:e,fallback:{type:o,data:c.data}}:c},y=async(e,a)=>{var s;let t=await fetch(e.startsWith("http")?e:`${window.location.origin}/${e.replace(/^\/+/,"")}`);if(/(svg|xml)/.test((s=t.headers.get("content-type"))!=null?s:"")||e.endsWith(".svg")){let g=await t.text();return p(`data:image/svg+xml;base64,${btoa(g)}`,a)}let n=await t.arrayBuffer(),r=f(n)||"png",i=await createImageBitmap(new Blob([n],{type:r}));return I.includes(r)?{type:r,data:n,transformation:{width:i.width,height:i.height}}:(console.warn(`${r} not supported by docx. Using one of the supported mime types.`),p(e,a))},w=async(e,a)=>{try{return e.startsWith("data:")?await p(e,a):await y(e,a)}catch(t){return console.error(`Error resolving image: ${e}`,t),{type:"png",data:Buffer.from([]),transformation:{width:100,height:100}}}},F=e=>({inline:async(a,t,n,r)=>{var i,s,g,m;if(/^image/.test(t.type)){let o=(s=t.url)!=null?s:r[(i=t.identifier)==null?void 0:i.toUpperCase()],c=(g=t.alt)!=null?g:o==null?void 0:o.split("/").pop();return t.type="",[new a.ImageRun({...await((m=e==null?void 0:e.imageResolver)!=null?m:w)(o,e),altText:{description:c,name:c,title:c}})]}return[]}});export{I as a,f as b,F as c};