@docx-editor.dev/docx-to-markdown 0.0.1 → 2.19.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +201 -0
- package/README.md +89 -6
- package/THIRD_PARTY_NOTICES.md +18 -0
- package/dist/chunk-CYF5JG4K.js +1 -0
- package/dist/chunk-NP5KYCWK.cjs +1 -0
- package/dist/index.cjs +28 -0
- package/dist/index.d.cts +84 -0
- package/dist/index.d.ts +84 -0
- package/dist/index.js +28 -0
- package/dist/markdown-types-Cn-MizR0.d.cts +251 -0
- package/dist/markdown-types-Cn-MizR0.d.ts +251 -0
- package/dist/node.cjs +1 -0
- package/dist/node.d.cts +14 -0
- package/dist/node.d.ts +14 -0
- package/dist/node.js +1 -0
- package/docs/api.md +330 -0
- package/docs/fonts.md +172 -0
- package/docs/images.md +223 -0
- package/docs/integrations.md +112 -0
- package/package.json +56 -6
- package/types/index.d.cts +26 -0
- package/types/node.d.cts +3 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright 2026 EigenPal Inc.
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/README.md
CHANGED
|
@@ -1,11 +1,94 @@
|
|
|
1
1
|
# DOCX to Markdown
|
|
2
2
|
|
|
3
3
|
Use `@docx-editor.dev/docx-to-markdown` to convert DOCX files to Markdown.
|
|
4
|
-
The result includes the document body, individual pages, and separate headers,
|
|
5
|
-
footers, comments, and tracked changes.
|
|
4
|
+
The result includes the document body, individual pages, and separate headers, footers, comments, and tracked changes.
|
|
6
5
|
|
|
7
|
-
|
|
8
|
-
converter, install version 2.x.
|
|
9
|
-
|
|
10
|
-
For more information, see the
|
|
6
|
+
[Try the DOCX to Markdown demo](https://docx-to-markdown.docx-editor.dev/) or read the
|
|
11
7
|
[Markdown export guide](https://www.docx-editor.dev/docs/2.x/export/markdown).
|
|
8
|
+
|
|
9
|
+
## Before you begin
|
|
10
|
+
|
|
11
|
+
For Node.js, use version 20.16.0 or later in the 20.x release line, or version 22.3.0 or later.
|
|
12
|
+
The converter requires WebAssembly and uses bundled fonts by default.
|
|
13
|
+
|
|
14
|
+
## Install the package
|
|
15
|
+
|
|
16
|
+
```sh
|
|
17
|
+
npm install @docx-editor.dev/docx-to-markdown @docx-editor.dev/core
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
`@docx-editor.dev/core` is a required peer dependency. Install a version that satisfies the converter's peer dependency range and commit your lockfile.
|
|
21
|
+
|
|
22
|
+
## Convert a DOCX file
|
|
23
|
+
|
|
24
|
+
The following example reads a local file in Node.js:
|
|
25
|
+
|
|
26
|
+
```ts
|
|
27
|
+
import { readFile } from 'node:fs/promises';
|
|
28
|
+
import { exportMarkdown } from '@docx-editor.dev/docx-to-markdown';
|
|
29
|
+
|
|
30
|
+
const docxBytes = await readFile('document.docx');
|
|
31
|
+
const result = await exportMarkdown(docxBytes);
|
|
32
|
+
console.log(result.markdown);
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
## Include images
|
|
36
|
+
|
|
37
|
+
Set `images: true` to include image links and extracted bytes:
|
|
38
|
+
|
|
39
|
+
```ts
|
|
40
|
+
const result = await exportMarkdown(docxBytes, { images: true });
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
`result.media` contains image bytes and their page occurrences.
|
|
44
|
+
See [image workflows](docs/images.md) to save a folder, download a ZIP, or return hosted URLs.
|
|
45
|
+
|
|
46
|
+
### Preserve displayed image sizes
|
|
47
|
+
|
|
48
|
+
Use `images: { syntax: 'html' }` to include each image's displayed width and height in generated `<img>` tags.
|
|
49
|
+
Dimensions use whole CSS pixels. Configure your Markdown renderer to allow sanitized HTML and retain `width` and `height`.
|
|
50
|
+
The default `images: true` uses standard Markdown image syntax, which has no size attributes.
|
|
51
|
+
For custom previews, use each occurrence's `displayWidthPx` and `displayHeightPx`.
|
|
52
|
+
Asset `pixelWidth` and `pixelHeight` describe the image file's dimensions.
|
|
53
|
+
Crop, rotation, and floating text wrapping are not reproduced.
|
|
54
|
+
See [displayed image sizes and custom previews](docs/images.md#preserve-displayed-image-sizes).
|
|
55
|
+
|
|
56
|
+
## Read page output
|
|
57
|
+
|
|
58
|
+
The document layout engine calculates page breaks.
|
|
59
|
+
|
|
60
|
+
```ts
|
|
61
|
+
for (const page of result.pages) {
|
|
62
|
+
console.log(page.number, page.markdown);
|
|
63
|
+
console.log(page.headerMarkdown, page.footerMarkdown);
|
|
64
|
+
}
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
`result.markdown` joins the body into one document. Headers and footers stay in `result.pages`.
|
|
68
|
+
|
|
69
|
+
For search and AI ingestion, use `{ displayMode: 'proposed' }` to show pending insertions and hide pending deletions. The default, `'all-markup'`, shows both.
|
|
70
|
+
|
|
71
|
+
## Configure fonts for accurate layout
|
|
72
|
+
|
|
73
|
+
Fonts determine line wrapping, table row heights, and the page boundaries in `result.pages`. Markdown does not preserve the DOCX font family, but the converter needs font measurements to calculate layout.
|
|
74
|
+
|
|
75
|
+
Start with the bundled substitutes for common Word fonts. Use `fonts` to supply the author's licensed fonts or override a substitute. Use `fallbackFonts: googleFonts()` to load missing faces from Google Fonts; it requires network access and does not override faces already resolved by earlier sources.
|
|
76
|
+
|
|
77
|
+
See [font setup and troubleshooting](docs/fonts.md) for runnable examples, resolution reports, and guidance on matching page references to Word.
|
|
78
|
+
|
|
79
|
+
## Runtime and output
|
|
80
|
+
|
|
81
|
+
For Next.js, use the Node.js runtime and [server package configuration](docs/integrations.md#nextjs). Edge runtimes are not supported.
|
|
82
|
+
|
|
83
|
+
Page breaks depend on fonts, document features, and revision mode; they can differ from Microsoft Word. Store the document version with page citations. `result.warnings` reports omitted content and font problems. Images are omitted unless enabled. See [output limits](docs/api.md#markdown-limitations) before using the output as a complete transcription.
|
|
84
|
+
|
|
85
|
+
The package uses the Apache 2.0 license, including comment and tracked-change extraction.
|
|
86
|
+
Bundled fonts retain their own open-source licenses.
|
|
87
|
+
|
|
88
|
+
## Next steps
|
|
89
|
+
|
|
90
|
+
- [Configure fonts and troubleshoot page layout](docs/fonts.md).
|
|
91
|
+
|
|
92
|
+
- [Include and deliver images](docs/images.md).
|
|
93
|
+
- [Connect the converter to your application](docs/integrations.md).
|
|
94
|
+
- [Review export options and result fields](docs/api.md).
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# Third-party notices
|
|
2
|
+
|
|
3
|
+
`@docx-editor.dev/docx-to-markdown` is distributed under Apache-2.0. Its published bundles also contain
|
|
4
|
+
source from the open-source packages listed below, redistributed here under
|
|
5
|
+
their own licenses, reproduced in full.
|
|
6
|
+
|
|
7
|
+
Those copies are not verbatim. The build inlines, minifies and tree-shakes
|
|
8
|
+
them, and includes only the parts each bundle reaches, so what ships is a
|
|
9
|
+
modified form of the original source.
|
|
10
|
+
|
|
11
|
+
This file covers code copied INTO the published bundles. Packages this one
|
|
12
|
+
declares as `dependencies` or `peerDependencies` are installed separately by
|
|
13
|
+
the consumer and are not repeated here.
|
|
14
|
+
|
|
15
|
+
Generated by `bun run notices:generate` from the build's esbuild metafile.
|
|
16
|
+
Do not edit by hand.
|
|
17
|
+
|
|
18
|
+
No third-party code is bundled into this package.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import {strToU8,Zip,ZipPassThrough,ZipDeflate}from'fflate';var g=class extends Error{constructor(e,a,r={}){super(a,{cause:r.cause});this.code=e;this.assetId=r.assetId,this.limitBytes=r.limitBytes,this.actualBytes=r.actualBytes;}code;name="MarkdownMediaError";assetId;limitBytes;actualBytes},o=class extends Error{constructor(e,a,r={}){super(a,{cause:r.cause});this.code=e;this.path=r.path;}code;name="MarkdownBundleError";path};function R(t){try{return String(t)}catch{return "Font origin failed (cause could not be converted to text)."}}function O(t){return Object.freeze({...t,media:Object.freeze(t.media.map(({bytes:n,...e})=>Object.freeze(e))),fontResolution:t.fontResolution?Object.freeze({...t.fontResolution,originFailures:Object.freeze(t.fontResolution.originFailures.map(n=>Object.freeze({...n,cause:R(n.cause)})))}):null})}function v(t){let n=new Map;n.set("document.md",strToU8(t.markdown)),n.set("document.json",strToU8(JSON.stringify(O(t),null,2)));for(let e of t.media){if(!/^media\/[a-f0-9]{64}\.(?:png|jpg|gif|bmp|webp|svg)$/i.test(e.path))throw new o("invalid-media-path","Image paths must be generated media/<content-id>.<extension> filenames.",{path:e.path});if(n.has(e.path))throw new o("duplicate-output-path","Two assets have the same output path.",{path:e.path});if(e.url!==e.path)throw new o("non-portable-image-url","Portable bundles require images: true without resolveUrl. Export a separate portable result for local files.",{path:e.path});n.set(e.path,e.bytes);}return n}async function z(t){let n=v(t),e=[],a=0,r=null,f=false,m=new Zip((l,i,p)=>{if(l){r=l;return}e.push(i),a+=i.length,f=p;});try{let i=0;for(let[s,u]of n){let c=s.startsWith("media/")?new ZipPassThrough(s):new ZipDeflate(s,{level:6});c.mtime=new Date(1980,0,1),m.add(c),u.length===0&&c.push(u,!0);for(let d=0;d<u.length;d+=262144){let h=u.subarray(d,d+262144);if(c.push(h,d+h.length===u.length),r)throw r;i+=h.length,i>=262144&&(i=0,await new Promise(b=>setTimeout(b,0)));}}if(m.end(),r)throw r;if(!f)throw new Error("ZIP output did not finish.");let p=new Uint8Array(a),y=0;for(let s of e)p.set(s,y),y+=s.length;return p}catch(l){throw m.terminate(),new o("archive-failed","Could not create the Markdown ZIP.",{cause:l})}}export{g as a,o as b,O as c,v as d,z as e};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
'use strict';var fflate=require('fflate');var g=class extends Error{constructor(e,a,r={}){super(a,{cause:r.cause});this.code=e;this.assetId=r.assetId,this.limitBytes=r.limitBytes,this.actualBytes=r.actualBytes;}code;name="MarkdownMediaError";assetId;limitBytes;actualBytes},o=class extends Error{constructor(e,a,r={}){super(a,{cause:r.cause});this.code=e;this.path=r.path;}code;name="MarkdownBundleError";path};function R(t){try{return String(t)}catch{return "Font origin failed (cause could not be converted to text)."}}function O(t){return Object.freeze({...t,media:Object.freeze(t.media.map(({bytes:n,...e})=>Object.freeze(e))),fontResolution:t.fontResolution?Object.freeze({...t.fontResolution,originFailures:Object.freeze(t.fontResolution.originFailures.map(n=>Object.freeze({...n,cause:R(n.cause)})))}):null})}function v(t){let n=new Map;n.set("document.md",fflate.strToU8(t.markdown)),n.set("document.json",fflate.strToU8(JSON.stringify(O(t),null,2)));for(let e of t.media){if(!/^media\/[a-f0-9]{64}\.(?:png|jpg|gif|bmp|webp|svg)$/i.test(e.path))throw new o("invalid-media-path","Image paths must be generated media/<content-id>.<extension> filenames.",{path:e.path});if(n.has(e.path))throw new o("duplicate-output-path","Two assets have the same output path.",{path:e.path});if(e.url!==e.path)throw new o("non-portable-image-url","Portable bundles require images: true without resolveUrl. Export a separate portable result for local files.",{path:e.path});n.set(e.path,e.bytes);}return n}async function z(t){let n=v(t),e=[],a=0,r=null,f=false,m=new fflate.Zip((l,i,p)=>{if(l){r=l;return}e.push(i),a+=i.length,f=p;});try{let i=0;for(let[s,u]of n){let c=s.startsWith("media/")?new fflate.ZipPassThrough(s):new fflate.ZipDeflate(s,{level:6});c.mtime=new Date(1980,0,1),m.add(c),u.length===0&&c.push(u,!0);for(let d=0;d<u.length;d+=262144){let h=u.subarray(d,d+262144);if(c.push(h,d+h.length===u.length),r)throw r;i+=h.length,i>=262144&&(i=0,await new Promise(b=>setTimeout(b,0)));}}if(m.end(),r)throw r;if(!f)throw new Error("ZIP output did not finish.");let p=new Uint8Array(a),y=0;for(let s of e)p.set(s,y),y+=s.length;return p}catch(l){throw m.terminate(),new o("archive-failed","Could not create the Markdown ZIP.",{cause:l})}}exports.a=g;exports.b=o;exports.c=O;exports.d=v;exports.e=z;
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
'use strict';var chunkNP5KYCWK_cjs=require('./chunk-NP5KYCWK.cjs'),_export=require('@docx-editor.dev/core/export'),layout=require('@docx-editor.dev/core/layout'),editor=require('@docx-editor.dev/core/editor'),fonts=require('@docx-editor.dev/fonts');var wn=Object.freeze([]),yn=Object.freeze({"image/png":"png","image/jpeg":"jpg","image/gif":"gif","image/bmp":"bmp","image/webp":"webp","image/svg+xml":"svg"});function I(e){if(e?.aborted)throw new _export.ExportResourceError("aborted","Markdown export was aborted",{cause:e.reason})}function _(e){let n=e.images;if(n===void 0||n===false)return;if(n!==true&&(typeof n!="object"||n===null||Array.isArray(n)))throw new TypeError("images must be a boolean or an image options object");let r=n===true?{}:n;if(r.resolveUrl!==void 0&&typeof r.resolveUrl!="function")throw new TypeError("images.resolveUrl must be a function");if(r.syntax!==void 0&&r.syntax!=="markdown"&&r.syntax!=="html")throw new TypeError('images.syntax must be "markdown" or "html"');let o=r.maxTotalBytes??64*1024*1024;if(!Number.isSafeInteger(o)||o<=0)throw new TypeError("images.maxTotalBytes must be a positive safe integer");return r}function G(e,n,r){if(!r)return wn;let o=r.maxTotalBytes??64*1024*1024,t=new Map,a=0;return layout.forEachSemanticDrawing(e,({drawing:s,page:i,story:d,rootStory:c})=>{let l=s.resource;if(l.kind!=="ready"||s.accessibility.hidden)return;let p=l.contentId.startsWith("sha256:")?l.contentId.slice(7):l.contentId,u=t.get(p);if(u){if(u.data.mimeType!==l.mime||u.data.pixelWidth!==l.pixelWidth||u.data.pixelHeight!==l.pixelHeight)throw new TypeError(`Conflicting image metadata for content ID ${p}`)}else {let g=yn[l.mime];if(!g||!/^[a-f0-9]{64}$/i.test(p))throw new TypeError("Invalid ready-image content identifier or MIME type");let f=n.validatedImageBytes(s);if(!f)throw new chunkNP5KYCWK_cjs.a("image-bytes-unavailable",`Image bytes for ${p} are unavailable; keep the owning session open during extraction.`,{assetId:p});if(a+=f.byteLength,a>o)throw new chunkNP5KYCWK_cjs.a("media-limit",`Extracted images exceed images.maxTotalBytes (${a} > ${o} bytes). Increase images.maxTotalBytes or use images: false.`,{assetId:p,limitBytes:o,actualBytes:a});u={data:{id:p,path:`media/${p}.${g}`,mimeType:l.mime,bytes:f,byteLength:f.byteLength,pixelWidth:l.pixelWidth,pixelHeight:l.pixelHeight},occurrences:[]},t.set(p,u);}u.occurrences.push(Object.freeze({pageNumber:i.index+1,story:d,rootStory:c,partName:s.ownerPartName,drawingNodeId:s.drawingNodeId,paragraphId:s.paragraphId,start:s.start,displayWidthPx:s.width*(96/72),displayHeightPx:s.height*(96/72),kind:s.kind==="inlineDrawing"?"inline":"anchored",decorative:s.accessibility.decorative,alt:s.accessibility.decorative?"":s.accessibility.label??""}));}),Object.freeze(Array.from(t.values(),({data:s,occurrences:i})=>Object.freeze({...s,occurrences:Object.freeze(i)})))}function kn(e,n){let r=typeof e=="string"&&e.trim().length>0&&!/[\u0000-\u001f\u007f\\]/.test(e)&&!e.startsWith("//")&&e===e.trim();if(r&&typeof e=="string"&&/^[a-z][a-z0-9+.-]*:/i.exec(e))try{let t=new URL(e);r=/^https?:\/\//i.test(e)&&!!t.hostname;}catch{r=false;}if(!r)throw new chunkNP5KYCWK_cjs.a("invalid-image-url",`Image ${n} needs a relative path or an absolute HTTP(S) URL.`,{assetId:n})}async function X(e,n){I(n);let r,o=new Promise((t,a)=>{r=()=>a(new _export.ExportResourceError("aborted","Markdown export was aborted",{cause:n?.reason})),n?.addEventListener("abort",r,{once:true});});try{return await Promise.race([Promise.resolve().then(()=>(I(n),e())),o])}finally{r&&n?.removeEventListener("abort",r);}}async function J(e,n){let r=_(n)?.resolveUrl,o=[];for(let t of e){I(n.signal);let a=t.path;if(r)try{a=await X(()=>Promise.resolve(r(Object.freeze({...t,bytes:t.bytes.slice()}),{signal:n.signal})),n.signal);}catch(s){throw I(n.signal),new chunkNP5KYCWK_cjs.a("url-resolution-failed",`Could not resolve the URL for image ${t.id}. Completed uploads remain application-owned.`,{assetId:t.id,cause:s})}kn(a,t.id),o.push(Object.freeze({...t,url:a}));}return I(n.signal),Object.freeze(o)}var x=Object.freeze({markdown:"",sources:Object.freeze([])});function k(e){return e.length===0?x:{markdown:e,sources:[]}}function ue(e,n){return n===0?[...e]:e.map(r=>({...r,markdownStart:r.markdownStart+n,markdownEnd:r.markdownEnd+n,markdownBoundaries:r.markdownBoundaries?.map(o=>({...o,markdownOffset:o.markdownOffset+n}))}))}function b(e,n=""){let r="",o=[],t=[];for(let[a,s]of e.entries()){a>0&&(r+=n);for(let i of ue(s.sources,r.length))o.push(i);t.push(...s.paragraphs??[]),r+=s.markdown;}return {markdown:r,sources:o,...t.length>0?{paragraphs:t}:{}}}function C(e,n,r=""){return {markdown:n+e.markdown+r,sources:ue(e.sources,n.length),...e.paragraphs?{paragraphs:e.paragraphs}:{}}}function N(e,n){let r=n(e.markdown);if(r.boundaryMap.length!==e.markdown.length+1)throw new TypeError("Markdown transform returned an invalid boundary map");return {markdown:r.markdown,sources:e.sources.map(o=>({...o,markdownStart:r.boundaryMap[o.markdownStart],markdownEnd:r.boundaryMap[o.markdownEnd],markdownBoundaries:o.markdownBoundaries?.map(t=>({...t,markdownOffset:r.boundaryMap[t.markdownOffset]}))})),...e.paragraphs?{paragraphs:e.paragraphs}:{}}}function Z(e,n){return n.length===0?e:{...e,paragraphs:Object.freeze([...n])}}function ge(e){let n=/^[ \t]+/.exec(e.markdown)?.[0].length??0;return n===0?e:N(e,r=>{let o="",t=[0];for(let a=0;a<r.length;a+=1)o+=a<n?"\xA0":r[a],t.push(o.length);return {markdown:o,boundaryMap:t}})}function fe(e){return N(e,n=>{let r="",o=0,t=[0];for(let a=0;a<n.length;a+=1){let s=n[a];s==="\\"?(r+=s,o+=1):(s==="|"&&o%2===0&&(r+="\\"),r+=s,o=0),t[a+1]=r.length;}return {markdown:r,boundaryMap:t}})}function me(e){return N(e,n=>{let r="",o=[0],t=0;for(;t<n.length;){if(n[t]!==`
|
|
2
|
+
`){r+=n[t],t+=1,o[t]=r.length;continue}let a=t;for(;t<n.length&&n[t]===`
|
|
3
|
+
`;)t+=1;r+="<br>";for(let s=a+1;s<=t;s+=1)o[s]=r.length;}return {markdown:r,boundaryMap:o}})}function we(e,n){return N(e,r=>{let o="",t=[0];for(let a=0;a<r.length;a+=1){let s=r[a];o+=s,s===`
|
|
4
|
+
`&&(o+=n),t.push(o.length);}return {markdown:o,boundaryMap:t}})}function ye(e){return N(e,n=>{let r=a=>a===n.length||n[a]===`
|
|
5
|
+
`?">":"> ",o=r(0),t=[o.length];for(let a=0;a<n.length;a+=1){let s=n[a];o+=s,s===`
|
|
6
|
+
`&&(o+=r(a+1)),t.push(o.length);}return {markdown:o,boundaryMap:t}})}function v(e,n){return `${e}\0${n}`}var Mn=new Set("\\`*{}[]()#+-.!_|~="),ke=/[\p{P}\p{S}]/u,he=/[\p{L}\p{N}]/u;function bn(e,n,r){if(e[n]!=="-")return false;let o=n>0?T(e.slice(0,n),"last"):r.before,t=n+1<e.length?T(e.slice(n+1),"first"):r.after;return o!==void 0&&t!==void 0&&he.test(o)&&he.test(t)}function xe(e){throw new TypeError(`Unsupported Markdown inline style: ${String(e)}`)}function Se(e,n=false){return ne(e,n).markdown}function ne(e,n,r=new Set,o={}){let t="",a=new Map,s=d=>{r.has(d)&&a.set(d,t.length);};s(0);let i=0;for(;i<e.length;){let d=e[i];if(d==="\r"&&e[i+1]===`
|
|
7
|
+
`){t+=n?"<br>":`
|
|
8
|
+
`,i+=1,s(i),i+=1,s(i);continue}d==="\r"||d===`
|
|
9
|
+
`||d==="\f"?t+=n?"<br>":`
|
|
10
|
+
`:d==="&"?t+="&":d==="<"?t+="<":d===">"?t+=">":d===" "?t+=" ":(Mn.has(d)&&!bn(e,i,o)&&(t+="\\"),t+=d),i+=1,s(i);}return {markdown:t,boundaries:a}}function Re(e,n,r,o,t={}){let a=r?.offsetsBySource.get(v(o,e.paragraphId));if(!r||!r.allSourceScopes.has(o)&&!a)return k(ne(e.sourceText,n,new Set,t).markdown);let s=new Set([0,e.sourceText.length]);if(e.exact){let l=a??[],p=0,u=l.length;for(;p<u;){let g=p+u>>>1;l[g]<e.sourceStart?p=g+1:u=g;}for(let g=p;g<l.length;g+=1){let f=l[g];if(f>e.sourceEnd)break;s.add(f-e.sourceStart);}}let i=ne(e.sourceText,n,s,t),d=e.exact?[...i.boundaries].map(([l,p])=>({sourceOffset:e.sourceStart+l,markdownOffset:p})):void 0,c={sourceScope:o,paragraphId:e.paragraphId,sourceStart:e.sourceStart,sourceEnd:e.sourceEnd,markdownStart:0,markdownEnd:i.markdown.length,...d?{markdownBoundaries:d}:{},exact:e.exact};return {markdown:i.markdown,sources:[c]}}function xn(e,n){let r=n.displayMode==="all-markup"&&e.revisions!==void 0&&layout.revisionsAreDeletion(e.revisions);return [...e.style.italic?["italic"]:[],...e.style.bold&&!n.suppressBold?["bold"]:[],...e.style.strike||e.style.doubleStrike||r?["strike"]:[]]}function Q(e,n){return e.length===n.length&&e.every((r,o)=>r===n[o])}function Me(e){return e.length>0&&/^[ \t]+$/u.test(e)}function Sn(e){let n=[...e],r=0;for(;r<e.length;){let o=e[r];if(o?.kind!=="text"||o.styles.length>0||!Me(o.sourceText)){r+=1;continue}let t=r,a=true;for(;r<e.length;){let d=e[r];if(d?.kind!=="text"||d.styles.length>0||d.paragraphId!==o.paragraphId||!Me(d.sourceText))break;Q(d.semanticStyles,o.semanticStyles)||(a=false),r+=1;}let s=e[t-1],i=e[r];if(!(s?.kind!=="text"||i?.kind!=="text"||s.paragraphId!==o.paragraphId||i.paragraphId!==o.paragraphId||!a||s.styles.length===0||!Q(o.semanticStyles,s.styles)||!Q(s.styles,i.styles)))for(let d=t;d<r;d+=1){let c=e[d];c?.kind==="text"&&(n[d]={...c,styles:s.styles});}}return n}function be(e){switch(e){case "strike":return "~~";case "italic":return "*";case "bold":return "**";default:return xe(e)}}function ee(e){switch(e){case "strike":return "del";case "italic":return "em";case "bold":return "strong";default:return xe(e)}}function H(e,n){let r=0;for(;r<e.length&&r<n.length&&e[r]===n[r];)r+=1;return r}function T(e,n){if(e.length===0)return;if(n==="first")return String.fromCodePoint(e.codePointAt(0));let r=e.length-1,o=e.charCodeAt(r),t=r>0?e.charCodeAt(r-1):0,a=o>=56320&&o<=57343&&t>=55296&&t<=56319;return e.slice(a?r-1:r)}function Ie(e,n){let r=e[n];if(r?.kind!=="text")return {};let o=e[n-1],t=e[n+1];return {...o?.kind==="text"&&o.paragraphId===r.paragraphId?{before:T(o.sourceText,"last")}:{},...t?.kind==="text"&&t.paragraphId===r.paragraphId?{after:T(t.sourceText,"first")}:{}}}function Rn(e,n,r){for(let o=n;o<r;o+=1){let t=e[o];if(t.kind!=="text")continue;let a=e[o-1],s=e[o+1],i=o>n&&a?.kind==="text"?a.styles:[],d=o+1<r&&s?.kind==="text"?s.styles:[],c=H(i,t.styles)<t.styles.length,l=H(t.styles,d)<t.styles.length,p=T(t.sourceText,"first"),u=T(t.sourceText,"last"),g=a?T(a.kind==="text"?a.sourceText:a.value.markdown,"last"):void 0,f=s?T(s.kind==="text"?s.sourceText:s.value.markdown,"first"):void 0;if(c&&p&&g&&ke.test(p)&&!/\s/u.test(g)||l&&u&&f&&ke.test(u)&&!/\s/u.test(f))return true}return false}function In(e,n,r,o,t,a){let s=[],i=[];for(let d=n;d<r;d+=1){let c=e[d];if(c.kind!=="text")continue;let l=H(i,c.styles);for(let p=i.length-1;p>=l;p-=1)s.push(k(`</${ee(i[p])}>`));for(let p=l;p<c.styles.length;p+=1)s.push(k(`<${ee(c.styles[p])}>`));s.push(Re(c,o,t,a,Ie(e,d))),i=c.styles;}for(let d=i.length-1;d>=0;d-=1)s.push(k(`</${ee(i[d])}>`));return b(s)}var j=class{#e;#n=[];constructor(n){this.#e=n;}#r(n,r,o,t,a,s=t){r.length!==0&&this.#n.push({kind:"text",sourceText:r,styles:t,semanticStyles:s,paragraphId:n.paragraphId,sourceStart:a?n.span.range.start+(n.sourceOffset??0)+o:n.span.range.start,sourceEnd:a?n.span.range.start+(n.sourceOffset??0)+o+r.length:n.span.range.end,exact:a});}writeText(n){let r=/^(\s*)([\s\S]*?)(\s*)$/.exec(n.sourceText),o=r?.[1]??"",t=r?.[2]??n.sourceText,a=r?.[3]??"",s=n.exact??(n.span.projected!==true&&n.span.equation===void 0&&n.sourceText.length===n.span.range.end-n.span.range.start),i=xn(n.span,this.#e);this.#r(n,o,0,[],s,i),this.#r(n,t,o.length,i,s),this.#r(n,a,o.length+t.length,[],s,i);}writeBoundary(n){this.writeMappedBoundary(k(n));}writeMappedBoundary(n){n.markdown.length===0&&n.sources.length===0||this.#n.push({kind:"boundary",value:n});}finishMapped(){let n=Sn(this.#n),r=[],o=[],t=a=>{let s=H(o,a);for(let i=o.length-1;i>=s;i-=1)r.push(k(be(o[i])));for(let i=s;i<a.length;i+=1)r.push(k(be(a[i])));o=a;};for(let a=0;a<n.length;a+=1){let s=n[a];if(s.kind==="boundary"){t([]),r.push(s.value);continue}if(s.styles.length===0){t([]),r.push(this.#t(s,a));continue}let i=a+1;for(;i<n.length;){let d=n[i];if(d?.kind!=="text"||d.styles.length===0)break;i+=1;}if(Rn(n,a,i)){t([]),r.push(In(n,a,i,this.#e.tableCell||this.#e.hardBreakHtml===true,this.#e.sourceCapture,this.#e.sourceScope)),a=i-1;continue}t(s.styles),r.push(this.#t(s,a,n));}return t([]),b(r)}#t(n,r,o=this.#n){let t=this.#e.tableCell||this.#e.hardBreakHtml===true;return Re(n,t,this.#e.sourceCapture,this.#e.sourceScope,Ie(o,r))}finish(){return this.finishMapped().markdown}};function U(e){return e.replace(/[\u0000-\u0020\u007f<>()\\]/g,n=>`%${n.charCodeAt(0).toString(16).toUpperCase().padStart(2,"0")}`)}function K(e){return `${e.ownerPartName}\0${e.drawingNodeId}`}function Pe(e,n="markdown"){let r=new Map;for(let o of e)for(let t of o.occurrences)r.set(`${t.partName}\0${t.drawingNodeId}`,o);return {syntax:n,assets:e,byDrawing:r,represented:new Set,warnings:[]}}function Ee(e,n,r){if(!n||e.accessibility.hidden||e.kind==="anchoredDrawing"&&e.textboxStory)return "";let o=K(e),t=n.byDrawing.get(o);if(!t)return "";n.represented.add(o);let a=e.accessibility.decorative?"":e.accessibility.label??"";if(n.syntax==="html"){let i=Math.round(e.width*1.3333333333333333),d=Math.round(e.height*(96/72));return `<img src="${ve(t.url)}" alt="${ve(a)}" width="${i}" height="${d}">`}let s=U(t.url).replace(/&/g,"&").replace(/\|/g,"%7C");return `![${Se(a.replace(/[\r\n]+/g," "),r)}](${s})`}function ve(e){return e.replace(/[&"<>|\r\n\\]/g,n=>`&#${n.charCodeAt(0)};`)}function V(e,n){let r=new Map,o=new Set;if(n)for(let t of e){let a=K(t);if(o.has(a)||t.textboxStory||!n.byDrawing.has(a))continue;o.add(a);let s=r.get(t.paragraphId)??[];s.push(t),r.set(t.paragraphId,s);}for(let t of r.values())t.sort((a,s)=>a.start-s.start||(a.sourceOrder??0)-(s.sourceOrder??0)||a.drawingNodeId.localeCompare(s.drawingNodeId));return {byParagraph:r}}function re(e,n){let r=e?.byParagraph.get(n)??[];return e?.byParagraph.delete(n),r}function Te(e,n,r){let o=Array.from(e?.byParagraph.values()??[]).flat();e?.byParagraph.clear();for(let t of o)n?.warnings.push(Object.freeze({code:"image-placement-fallback",message:`Image ${t.drawingNodeId} has no rendered anchor paragraph; it follows this story.`,partName:t.ownerPartName,...r===void 0?{}:{pageNumber:r+1}}));return o}function L(e){return e.equation?.fallbackText??e.text}function $(e){return {span:e.span,paragraphId:e.span.range.paragraphId,sourceText:e.sourceText??L(e.span),sourceOffset:e.sourceOffset,...e.sourceText===void 0?{}:{exact:e.span.projected!==true&&e.span.equation===void 0&&L(e.span).length===e.span.range.end-e.span.range.start}}}function Ce(e){let n=[];for(let[r,o]of e.spans.entries())n.push({kind:"span",start:o.range.start,order:r*2+1,span:o});for(let[r,o]of e.drawings.entries())n.push({kind:"drawing",start:o.start,order:r*2,drawing:o});return n.sort((r,o)=>r.start-o.start||r.order-o.order)}function Ae(e,n){if(!n.length)return e;let r=new Set(e.flatMap(i=>i.kind==="drawing"?[`${i.drawing.ownerPartName}\0${i.drawing.drawingNodeId}`]:[])),o=n.filter(i=>!r.has(`${i.ownerPartName}\0${i.drawingNodeId}`)),t=[],a=0,s=()=>{let i=o[a++];t.push({kind:"drawing",start:i.start,order:0,drawing:i});};for(let i of e){for(;a<o.length&&o[a].start<=i.start;)s();if(i.kind!=="span"||i.span.noteNav||i.span.equation||i.span.projected===true){t.push(i);continue}let d=i.sourceText??L(i.span),c=0;for(;a<o.length&&o[a].start<i.start+d.length;){let l=o[a].start-i.start;l>c&&t.push({...i,start:i.start+c,sourceText:d.slice(c,l),sourceOffset:(i.sourceOffset??0)+c}),s(),c=l;}c===0?t.push(i):c<d.length&&t.push({...i,start:i.start+c,sourceText:d.slice(c),sourceOffset:(i.sourceOffset??0)+c});}for(;a<o.length;)s();return t}function Oe(e,n,r){if(!n?.byParagraph.size)return e;if(!e.length)return Ae(e,re(n,r));let o=[],t=[],a="",s=()=>{o.push(...Ae(t,re(n,a))),t=[];};for(let i of e){let d=i.kind==="span"?i.span.range.paragraphId:i.drawing.paragraphId;t.length&&a!==d&&s(),a=d,t.push(i);}return s(),o}function Fe(e,n){let r=e.contentWarnings?.map(t=>Object.freeze({code:t.code==="legacy-textbox"?"omitted-textbox":t.code==="legacy-drawing"?"omitted-drawing":"content-scan-limit",partName:t.partName,message:t.code==="legacy-textbox"?`Legacy text box content in ${t.partName} may be omitted from Markdown.`:t.code==="legacy-drawing"?n?`Some legacy drawing content in ${t.partName} could not be represented by layout and may be omitted from Markdown.`:`Legacy images or shapes in ${t.partName} are omitted from Markdown and may affect page breaks.`:`Content checks stopped at the scan limit in ${t.partName}.`}))??[],o=new Set;return layout.forEachSemanticStory(e,({host:t,page:a})=>{let s=i=>{if(n?.represented.has(K(i)))return;let d=i.kind==="anchoredDrawing"&&i.textboxStory!==void 0,c=d?"omitted-textbox":"omitted-drawing",l=`${a.index}:${c}`;o.has(l)||(o.add(l),r.push(Object.freeze({code:c,message:d?"Text box content is omitted from Markdown.":"Images and shapes are omitted from Markdown.",pageNumber:a.index+1})));};if("anchoredDrawings"in t)for(let i of t.anchoredDrawings??[])s(i);layout.forEachStoryParagraphFragment(t,(i,d)=>{if(!(d.textboxDepth>0))for(let c of i.lines)for(let l of c.drawings??[])s(l);});}),r.concat(n?.warnings??[])}function Be(e,n){return Math.max(e??(n??1)-1,1)}function De(e,n,r){let o=e.map(t=>{let a=t.isHeaderRow?"th":"td",s=Array.from({length:n},(i,d)=>b([k(`<${a}>`),r(t,d),k(`</${a}>`)]));return b([k("<tr>"),...s,k("</tr>")])});return b([k("<table>"),...o,k("</table>")])}function q(e){throw new TypeError(`Unsupported semantic record: ${JSON.stringify(e)}`)}function P(e){let n=[];for(let r of e){let o=n[n.length-1];switch(r.kind){case "paragraph":o?.kind==="paragraph"&&o.fragments[0]?.paragraphId===r.paragraphId?o.fragments.push(r):n.push({kind:"paragraph",fragments:[r]});break;case "table":o?.kind==="table"&&o.fragments[0]?.tableId===r.tableId?o.fragments.push(r):n.push({kind:"table",fragments:[r]});break;default:q(r);}}return n}function O(e,n){let r=[],o=new Map;for(let t of e)for(let a of t.rows){if(a.isHeaderRepeat&&!n)continue;let s=o.get(a.id);if(!(s&&n&&a.isHeaderRepeat)){s||(s={id:a.id,isHeaderRow:a.isHeaderRow,isHeaderRepeat:a.isHeaderRepeat,cells:[]},o.set(a.id,s),r.push(s));for(let[i,d]of a.cells.entries()){let c=d.logicalGridColumn??d.gridColumn??i,l=s.cells.find(p=>p.gridColumn===c);l?l.blocks.push(...d.blocks):s.cells.push({blocks:[...d.blocks],gridSpan:d.gridSpan,vMergeContinue:d.vMergeContinue,gridColumn:c});}s.cells.sort((i,d)=>i.gridColumn-d.gridColumn);}}return r}function En(e){for(let n of e.blocks)if(n.kind==="paragraph")return n.alignment;return "left"}function Ne(e,n,r){let o=Be(n?.columnCount,r[0]?.columnEdges.length);for(let t of e)for(let a of t.cells)o=Math.max(o,a.gridColumn+Math.max(a.gridSpan,1));return o}function je(e,n,r,o){let t=e[0]?.tableId,a=t?n.tablesById.get(t):void 0,s=a?.fragments??e,i=r?O(e,true):O(s,false);if(i.length===0)return x;let d=Ne(i,a,e),c={...n,tableCell:true};return De(i,d,(l,p)=>{let u=l.cells.find(g=>g.gridColumn===p);return !u||u.vMergeContinue?x:o(P(u.blocks),c,true,r)})}function Tn(e,n,r,o){let t=[],a={...n,tableCell:true};for(let s of e.cells){let i=s.vMergeContinue?x:me(fe(o(P(s.blocks),a,true,r)));for(;t.length<s.gridColumn;)t.push(x);t[s.gridColumn]=i;for(let d=1;d<s.gridSpan;d+=1)t[s.gridColumn+d]=x;}return t}function Le(e,n,r,o){let t=e[0]?.tableId,a=t?n.tablesById.get(t):void 0,s=a?.fragments??e,i=r?O(e,true):O(s,false);if(i.length===0)return x;let d=Ne(i,a,e),c=(g,f=x)=>Array.from({length:d},(w,m)=>g[m]??f),l=g=>b([k("| "),b(c(Tn(g,n,r,o))," | "),k(" |")],""),p=i[0],u=[];for(let g of p.cells){let f=En(g),w=f==="center"?":---:":f==="right"?"---:":"---";for(;u.length<g.gridColumn;)u.push("---");u[g.gridColumn]=w;for(let m=1;m<g.gridSpan;m+=1)u[g.gridColumn+m]="---";}return b([l(p),k(`| ${Array.from({length:d},(g,f)=>u[f]??"---").join(" | ")} |`),...i.slice(1).map(l)],`
|
|
11
|
+
`)}function Y(e,n){for(let r of e){if(r.kind==="paragraph")continue;let o=n.get(r.tableId);o||(o={fragments:[],columnCount:Math.max(1,r.columnEdges.length-1)},n.set(r.tableId,o)),o.fragments.push(r);for(let t of r.rows)if(!t.isHeaderRepeat)for(let a of t.cells)Y(a.blocks,n);}}function We(e,n,r){switch(e){case "body":return "body";case "header":case "footer":return `${e}:${n}`;case "footnote":case "endnote":return `${e}:${r??n}`;case "note-separator":return `note-separator:${n}`}}function _e(e){let n=new Map,r=new Set,o=(a,s,i)=>{let d=v(a,s),c=n.get(d)??new Set;c.add(i),n.set(d,c);};for(let a of e)for(let s of a.occurrences){let{start:i,end:d}=s.source,c=We(s.rootStory,s.source.partName,s.noteScopeId);o(c,i.paragraphId,i.offset),o(c,d.paragraphId,d.offset),i.paragraphId!==d.paragraphId&&r.add(c);}if(n.size===0)return;let t=new Map;for(let[a,s]of n)t.set(a,[...s].sort((i,d)=>i-d));return {allSourceScopes:r,offsetsBySource:t}}function He(e){let n=new Map;for(let r of e)for(let o of r.occurrences){let t=n.get(o.pageIndex)??{comments:[],trackedChanges:[],keys:new Set};n.set(o.pageIndex,t);let a=`${r.kind}\0${r.id}`;t.keys.has(a)||(t.keys.add(a),r.kind==="comment"?t.comments.push(r):t.trackedChanges.push(r));}return n}function ae(e,n,r){let o=Math.max(n,e.sourceStart),t=Math.min(r,e.sourceEnd);if(o>t||n!==r&&o===t)return null;if(n===r&&!e.exact)return n===e.sourceStart?{start:e.markdownStart,end:e.markdownStart,unit:"utf16-code-unit",precision:"exact"}:n===e.sourceEnd?{start:e.markdownEnd,end:e.markdownEnd,unit:"utf16-code-unit",precision:"exact"}:null;if(!e.exact||!e.markdownBoundaries)return {start:e.markdownStart,end:e.markdownEnd,unit:"utf16-code-unit",precision:"containing-construct"};let a=d=>{if(d===e.sourceStart)return e.markdownStart;if(d===e.sourceEnd)return e.markdownEnd;let c=e.markdownBoundaries??[],l=0,p=c.length;for(;l<p;){let u=l+p>>>1;c[u].sourceOffset<d?l=u+1:p=u;}return c[l]?.sourceOffset===d?c[l].markdownOffset:null},s=a(o),i=a(t);return s===null||i===null?null:{start:s,end:i,unit:"utf16-code-unit",precision:"exact"}}function $e(e){let n=[];for(let r of e){let o=n[n.length-1],t=o&&r.start<o.end,a=o&&r.start===o.end&&r.precision===o.precision;o&&(t||a)?n[n.length-1]={start:o.start,end:Math.max(o.end,r.end),unit:"utf16-code-unit",precision:o.precision==="containing-construct"||r.precision==="containing-construct"?"containing-construct":"exact"}:n.push(r);}return Object.freeze(n.map(r=>Object.freeze(r)))}function An(e){let n=new Map;for(let[s,i]of e.sources.entries()){let d=v(i.sourceScope,i.paragraphId),c=n.get(d)??[];c.push({index:s,slice:i}),n.set(d,c);}let r=new Map;for(let[s,i]of n){let d=i.sort((g,f)=>g.slice.sourceStart-f.slice.sourceStart||g.slice.sourceEnd-f.slice.sourceEnd||g.index-f.index),c=[],l=new Map,p=new Map,u=Number.NEGATIVE_INFINITY;for(let[g,f]of d.entries()){u=Math.max(u,f.slice.sourceEnd),c[g]=u;let w=l.get(f.slice.sourceStart)??[];w.push(f),l.set(f.slice.sourceStart,w);let m=p.get(f.slice.sourceEnd)??[];m.push(f),p.set(f.slice.sourceEnd,m);}r.set(s,{entries:d,prefixMaxEnd:c,byStart:l,byEnd:p});}let o=[];for(let s of e.paragraphs??[]){let i=o[o.length-1];i&&i.sourceScope===s.sourceScope&&i.paragraphId===s.paragraphId?o[o.length-1]={...i,sourceStart:Math.min(i.sourceStart,s.sourceStart),sourceEnd:Math.max(i.sourceEnd,s.sourceEnd)}:o.push(s);}let t=new Map,a=new Map;for(let s of o){let i=a.get(s.sourceScope)??[];i.push(s),a.set(s.sourceScope,i);}for(let[s,i]of a){let d=new Map;for(let[c,l]of i.entries()){let p=d.get(l.paragraphId)??[];p.push(c),d.set(l.paragraphId,p);}t.set(s,{entries:i,positionsByParagraphId:d});}return {sources:e.sources,bySourceKey:r,paragraphsByScope:t}}function ze(e,n){let r=0,o=e.length;for(;r<o;){let t=r+o>>>1;e[t]<n?r=t+1:o=t;}return e[r]??-1}function se(e,n){let r=0,o=e.prefixMaxEnd.length;for(;r<o;){let t=r+o>>>1;e.prefixMaxEnd[t]<=n?r=t+1:o=t;}return r}function Cn(e,n,r){let o=[];for(let t=se(e,n);t<e.entries.length;t+=1){let a=e.entries[t];if(a.slice.sourceStart>=r)break;a.slice.sourceEnd>n&&o.push(a);}return o.sort((t,a)=>t.index-a.index)}function On(e,n){let r=d=>d.reduce((c,l)=>!c||l.index<c.index?l:c,void 0),o=r(e.byStart.get(n)??[]),t=[];for(let d=se(e,n);d<e.entries.length;d+=1){let c=e.entries[d];if(c.slice.sourceStart>=n)break;c.slice.sourceEnd>n&&t.push(c);}let a=r(t),s=o??a??r(e.byEnd.get(n)??[]);if(!s)return Object.freeze([]);let i=ae(s.slice,n,n);return Object.freeze(i?[Object.freeze(i)]:[])}function te(e,n,r){let o=n;for(let t of [...e].sort((a,s)=>a.start-s.start||a.end-s.end))if(!(t.end<=o)){if(t.start>o)return false;if(o=t.end,o>=r)return true}return o>=r}function oe(e,n){return e.length===0?"none":n?"complete":"partial"}function Fn(e,n){let r=We(n.rootStory,n.source.partName,n.noteScopeId),o=n.source,{start:t,end:a}=o;if(t.paragraphId===a.paragraphId){let w=e.bySourceKey.get(v(r,t.paragraphId));if(!w)return {ranges:Object.freeze([]),coverage:"none"};if(t.offset===a.offset){let h=On(w,t.offset);return {ranges:h,coverage:oe(h,h.length>0)}}let m=[],y=Cn(w,t.offset,a.offset).map(({slice:h})=>{let S=ae(h,t.offset,a.offset);return S&&m.push({start:Math.max(t.offset,h.sourceStart),end:Math.min(a.offset,h.sourceEnd)}),S}).filter(h=>h!==null),M=$e(y);return {ranges:M,coverage:oe(M,te(m,t.offset,a.offset))}}let s=e.bySourceKey.get(v(r,t.paragraphId)),i;if(s)for(let w=se(s,t.offset);w<s.entries.length;w+=1){let m=s.entries[w];if(!(m.slice.sourceEnd<=t.offset)){i=m.index;break}}if(i===void 0){let w=e.paragraphsByScope.get(r),m=w?.positionsByParagraphId.get(t.paragraphId)?.[0];if(w&&m!==void 0){let y=ze(w.positionsByParagraphId.get(a.paragraphId)??[],m);for(let M=m+1;M>=0&&M<=y;M+=1){let h=w.entries[M],E=e.bySourceKey.get(v(r,h.paragraphId))?.entries.reduce((R,D)=>!R||D.index<R.index?D:R,void 0);if(E){i=E.index;break}}}}if(i===void 0)return {ranges:Object.freeze([]),coverage:"none"};let d=[],c=new Map,l=new Map,p=false;for(let w=i;w<e.sources.length;w+=1){let m=e.sources[w];if(m.sourceScope!==r||m.paragraphId===t.paragraphId&&m.sourceEnd<=t.offset)continue;let y=m.paragraphId===t.paragraphId?t.offset:m.sourceStart,M=m.paragraphId===a.paragraphId?a.offset:m.sourceEnd,h=Math.max(y,m.sourceStart),S=Math.min(M,m.sourceEnd),E=l.get(m.paragraphId);l.set(m.paragraphId,{start:Math.min(E?.start??h,h),end:Math.max(E?.end??S,S)});let R=ae(m,y,M);if(R){d.push(R);let D=c.get(m.paragraphId)??[];D.push({start:h,end:S}),c.set(m.paragraphId,D);}if(m.paragraphId===a.paragraphId&&m.sourceEnd>=a.offset){p=true;break}}let u=$e(d),g=p,f=e.paragraphsByScope.get(r);if(g&&f&&f.entries.length>0){let w=f.positionsByParagraphId.get(t.paragraphId)?.[0]??-1,m=ze(f.positionsByParagraphId.get(a.paragraphId)??[],Math.max(0,w));g=w>=0&&m>=w;for(let y=w;g&&y<=m;y+=1){let M=f.entries[y],h=M.paragraphId===t.paragraphId?t.offset:M.sourceStart,S=M.paragraphId===a.paragraphId?a.offset:M.sourceEnd;te(c.get(M.paragraphId)??[],h,S)||(g=false);}}else if(g)for(let[w,m]of l){let y=w===t.paragraphId?t.offset:0,M=w===a.paragraphId?a.offset:m.end;if(!te(c.get(w)??[],y,M)){g=false;break}}return {ranges:u,coverage:oe(u,g)}}function Bn(e){return Object.freeze({kind:"page",pageIndex:e.pageIndex,pageNumber:e.physicalPageNumber,field:e.rootStory==="header"?"headerMarkdown":e.rootStory==="footer"?"footerMarkdown":"markdown"})}function Dn(e,n,r){return n.story==="textbox"||n.rootStory==="note-separator"?"omitted-story-content":e.kind==="tracked-change"&&e.change==="structural"?"non-linear-structural-change":r.length===0?"not-represented-in-markdown":void 0}function Ue(e,n,r){let o=[],t=new WeakMap,a=i=>{let d=t.get(i);if(d)return d;let c=An(i);return t.set(i,c),c},s=(i,d,c,l,p)=>{let u=d.story==="textbox"||d.rootStory==="note-separator"||i.kind==="tracked-change"&&i.change==="structural"?{ranges:Object.freeze([]),coverage:"none"}:Fn(a(p),d),g=Dn(i,d,u.ranges);o.push(Object.freeze({artifactId:i.id,artifactKind:i.kind,occurrenceIndex:c,projection:l,ranges:u.ranges,coverage:u.coverage,...g?{unmappedReason:g}:{}}));};for(let i of e)for(let[d,c]of i.occurrences.entries()){let l=Bn(c),p=r.get(c.pageIndex);s(i,c,d,l,p?.[l.field]??x),c.story!=="textbox"&&(c.rootStory==="body"||c.rootStory==="footnote"||c.rootStory==="endnote")&&s(i,c,d,Object.freeze({kind:"document"}),n);}return Object.freeze(o)}var Ke=new Map;function Ve(e){let n=new Map,r=new Map,o=(t,a,s,i)=>{let d=t.get(a)??{kind:s,blocks:[]};d.blocks.push(...i),t.set(a,d);};return layout.forEachSemanticStory(e,({page:t,story:a,host:s,noteScopeId:i})=>{if(i===null||a!=="footnote"&&a!=="endnote")return;o(n,i,a,s.fragments);let d=r.get(t);d||(d=new Map,r.set(t,d)),o(d,i,a,s.fragments);}),{document:n,byPage:r}}function qe(e){let n=new Map;return layout.forEachSemanticSpan(e,({span:r,story:o})=>{o!=="textbox"&&(r.noteNav?.direction!=="to-note"||n.has(r.noteNav.scopeId)||n.set(r.noteNav.scopeId,String(n.size+1)));}),n}var $n=Object.freeze([]);function de(e,n,r){switch(e){case "body":return "body";case "header":case "footer":return `${e}:${n}`;case "footnote":case "endnote":return `${e}:${r??n}`;case "note-separator":return `note-separator:${n}`}}function Ze(e,n){return Ee(e,n.media,n.tableCell)}function ce(e){return b(Te(e.anchors,e.media,e.pageIndex).map(n=>en(n,e,Ze(n,e))),`
|
|
12
|
+
|
|
13
|
+
`)}function Qe(e,n){let r=e.sourceCapture;return !!(r&&(r.allSourceScopes.has(e.sourceScope)||r.offsetsBySource.has(v(e.sourceScope,n))))}function en(e,n,r){return r.length===0?x:Qe(n,e.paragraphId)?{markdown:r,sources:[{sourceScope:n.sourceScope,paragraphId:e.paragraphId,sourceStart:e.start,sourceEnd:e.start+1,markdownStart:0,markdownEnd:r.length,exact:false}]}:k(r)}function zn(e,n){if(!e.noteNav)return null;switch(e.noteNav.direction){case "to-note":{let r=n.noteLabelByScope.get(e.noteNav.scopeId);return r&&n.emittedNoteLabels?.add(r),r?`[^${r}]`:""}case "to-body":return "";default:return q(e.noteNav.direction)}}function Wn(e){let n=e.map(t=>({...t})),r=[];for(let t=0;t<n.length;t+=1){let a=n[t];if(a.sourceText.length===0)continue;let s=/^\s+/.exec(a.sourceText);if(!s||(r.push({...a,sourceText:s[0]}),n[t]={...a,sourceText:a.sourceText.slice(s[0].length),sourceOffset:(a.sourceOffset??0)+s[0].length},n[t].sourceText.length>0))break}let o=[];for(let t=n.length-1;t>=0;t-=1){let a=n[t];if(a.sourceText.length===0)continue;let s=/\s+$/.exec(a.sourceText);if(!s||(o.unshift({...a,sourceText:s[0],sourceOffset:(a.sourceOffset??0)+a.sourceText.length-s[0].length}),n[t]={...a,sourceText:a.sourceText.slice(0,-s[0].length)},n[t].sourceText.length>0))break}return {leading:r,content:n,trailing:o}}function ie(e,n){let r=new j(n);for(let o of e)r.writeText(o);return r.finishMapped()}function _n(e,n,r){let{leading:o,content:t,trailing:a}=Wn(e),s=ie(o,r),i=ie(t,r),d=ie(a,r);return i.markdown.length===0&&s.markdown.length+d.markdown.length>0?C(b([s,d]),"[",`](${U(n)})`):b([s,i.markdown.length>0?b([k("["),i,k(`](${U(n)})`)]):x,d])}function Hn(e,n){return e===n||e!==void 0&&n!==void 0&&e.id===n.id&&e.kind===n.kind&&e.href===n.href&&e.anchor===n.anchor&&e.tooltip===n.tooltip}function Un(e,n,r){for(let o=0;o<e.length;o+=1){let t=e[o];if(t.kind==="drawing"){let i=Ze(t.drawing,n);r.writeMappedBoundary(en(t.drawing,n,i)),i.length===0&&Kn(e,o)&&r.writeBoundary(" ");continue}let a=t.span.range.paragraphId,s=zn(t.span,n);if(s!==null){s.length>0&&Qe(n,a)?r.writeMappedBoundary({markdown:s,sources:[{sourceScope:n.sourceScope,paragraphId:a,sourceStart:t.span.range.start,sourceEnd:t.span.range.end,markdownStart:0,markdownEnd:s.length,exact:false}]}):r.writeBoundary(s);continue}if(t.span.link?.kind==="external"&&t.span.link.href){let i=[$(t)];for(;e[o+1]?.kind==="span";){let d=e[o+1];if(d.kind!=="span"||d.span.noteNav||!Hn(t.span.link,d.span.link))break;i.push($(d)),o+=1;}r.writeMappedBoundary(_n(i,t.span.link.href,n));continue}r.writeText($(t));}}function Ye(e){return e?.kind==="span"?$(e).sourceText:""}function Kn(e,n){if(e[n-1]?.kind==="drawing")return false;let r=n+1;for(;e[r]?.kind==="drawing";)r+=1;let o=Ye(e[n-1]),t=Ye(e[r]);return /[\p{L}\p{N}_]\p{M}*$/u.test(o)&&/^[\p{L}\p{N}_]\p{M}*/u.test(t)}function Vn(e,n){let r=new j(n),o=[];for(let t of e)for(let a of t.lines)for(let s of layout.lineSegments(a))o.push(...Ce(s));return Un(Oe(o,n.anchors,e[0]?.paragraphId??""),n,r),r.finishMapped()}function qn(e){let n=false;for(let r of e)for(let o of r.lines)for(let t of layout.lineSegments(o))for(let a of t.spans)if(L(a).trim().length!==0&&(n=true,!a.style.bold))return false;return n}function Yn(e,n,r=true){let o=e[0];if(!o)return x;let t=o.outlineLevel===null?null:o.outlineLevel+1,a=!n.tableCell&&t!==null&&t>=1&&t<=9?`${"#".repeat(Math.min(t,6))} `:"",s=ge(Vn(e,a.length>0?{...n,hardBreakHtml:true,suppressBold:qn(e)}:n)),i=o.marker??n.listMarkerByParagraphId.get(o.paragraphId),d=" ".repeat(n.listIndentByParagraphId.get(o.paragraphId)??(i?.level??0)*4),c;if(!r&&o.fragmentIndex>0)if(!i)c=s;else {let u=i.numFmt==="bullet"?"-":`${i.ordinal??1}.`;c=C(s,`${d}${" ".repeat(u.length+1)}`);}else if(i){let u=i.numFmt==="bullet"?"-":`${i.ordinal??1}.`;c=C(s,`${d}${u} ${a}`);}else c=C(s,a);if(!n.sourceCapture?.allSourceScopes.has(n.sourceScope))return c;let l=u=>{if(u.range)return u.range;let g=u.lines.map(f=>f.range);return {start:Math.min(...g.map(f=>f.start)),end:Math.max(...g.map(f=>f.end))}},p=e.map(l);return Z(c,[{sourceScope:n.sourceScope,paragraphId:o.paragraphId,sourceStart:Math.min(...p.map(u=>u.start)),sourceEnd:Math.max(...p.map(u=>u.end))}])}function F(e,n,r=false,o=false){let t=e.map(s=>{switch(s.kind){case "paragraph":return Yn(s.fragments,n,!o);case "table":return n.tableCell?je(s.fragments,n,o,F):Le(s.fragments,n,o,F);default:return q(s)}}),a=b(t.filter((s,i)=>s.markdown.length>0||i<t.length-1),r?`
|
|
14
|
+
`:`
|
|
15
|
+
|
|
16
|
+
`);return Z(a,t.flatMap(s=>s.paragraphs??[]))}function nn(e){return P(e.pages.flatMap(n=>n.fragments))}function Gn(e){return (e.numFmt==="bullet"?"-":`${e.ordinal??1}.`).length+1}function z(e,n,r){let o=new Map,t=null;for(let a of e){if(a.kind==="table"){o.clear(),t=null;for(let c of O(a.fragments,false))for(let l of c.cells)z(P(l.blocks),n,r);continue}let s=a.fragments[0];if(!s)continue;let i=a.fragments.find(c=>c.marker)?.marker;if(!i){o.clear(),t=null;continue}t!==i.numId&&o.clear(),t=i.numId;let d=0;for(let c=0;c<i.level;c+=1)d+=o.get(c)??0;n.set(s.paragraphId,d),r.set(s.paragraphId,i),o.set(i.level,Gn(i));for(let c of o.keys())c>i.level&&o.delete(c);}}function Xn(e){let n=new Map,r=new Map,o=new Map;return z(nn(e),n,r),layout.forEachSemanticStory(e,({story:t,host:a})=>{t==="header"||t==="footer"||t==="note-separator"||Y(a.fragments,o);}),{listIndentByParagraphId:n,listMarkerByParagraphId:r,tablesById:o}}function Jn(e,n){let r=P(e.fragments),o=new Map,t=new Map,a=new Set;z(r,o,t);let s={...n,pageIndex:e.index,anchors:V(e.anchoredDrawings??[],n.media),listIndentByParagraphId:o,listMarkerByParagraphId:t,emittedNoteLabels:a},i=F(r,s,false,true),d=ce(s);return {value:b([i,d].filter(c=>c.markdown.length>0),`
|
|
17
|
+
|
|
18
|
+
`),noteLabels:a}}function Zn(e,n){let r=new Map,o=new Map,t=new Map;z(P(e.fragments),r,o),Y(e.fragments,t);let a={...n,sourceScope:de(e.kind,e.partName,null),anchors:V(e.anchoredDrawings??[],n.media),listIndentByParagraphId:r,listMarkerByParagraphId:o,tablesById:t},s=F(P(e.fragments),a);return b([s,ce(a)].filter(i=>i.markdown.length>0),`
|
|
19
|
+
|
|
20
|
+
`)}function Qn(e,n,r){let t=`> **${e.kind==="footnote"?"Footnote":"Endnote"} ${n} (continued):**`;return r.markdown.length===0?k(t):b([k(`${t}
|
|
21
|
+
>
|
|
22
|
+
`),ye(r)])}function Ge(e,n,r=false,o=new Set,t=new Set){let a=[];for(let[s,i]of e){let d=n.noteLabelByScope.get(s);if(!d)continue;let c=P(i.blocks),l=new Map,p=new Map;z(c,l,p);let u={...n,sourceScope:de(i.kind,"",s),anchors:void 0,listIndentByParagraphId:l,listMarkerByParagraphId:p},g=F(c,u,false,r),f=r&&t.has(s)&&!o.has(d);if(r&&t.add(s),f){a.push(Qn(i,d,g));continue}let w=we(g," ");a.push(C(w,`[^${d}]: `));}return b(a,`
|
|
23
|
+
|
|
24
|
+
`)}function Xe(e,n){return b([e,n].filter(r=>r.markdown.length>0),`
|
|
25
|
+
|
|
26
|
+
`)}function W(e,n,r="markdown"){let o=e.reviewArtifacts??$n,t=e.displayMode??"all-markup",a=Xn(e),s=Ve(e),i=n===void 0?void 0:Pe(n,r),d={media:i,anchors:V(e.pages.flatMap(y=>y.anchoredDrawings??[]),i),noteLabelByScope:qe(e),tableCell:false,displayMode:t,sourceScope:de("body","",null),sourceCapture:_e(o),...a},c=Xe(b([F(nn(e),d),ce(d)].filter(y=>y.markdown.length>0),`
|
|
27
|
+
|
|
28
|
+
`),Ge(s.document,d)),l=He(o),p=new Set,u=new WeakMap,g=y=>{if(!y)return x;let M=`${y.kind}:${y.partName}`,h=u.get(y.fragments);if(h&&h.scope===M)return h.value;let S=Zn(y,d);return u.set(y.fragments,{scope:M,value:S}),S},f=new Map,w=e.pages.map(y=>{let M={...d,pageIndex:y.index},h=Jn(y,d),S=Ge(s.byPage.get(y)??Ke,M,true,h.noteLabels,p),E=l.get(y.index),R={markdown:Xe(h.value,S),headerMarkdown:g(y.header),footerMarkdown:g(y.footer)};return f.set(y.index,R),Object.freeze({id:y.id,number:y.index+1,markdown:R.markdown.markdown,headerMarkdown:R.headerMarkdown.markdown,footerMarkdown:R.footerMarkdown.markdown,comments:Object.freeze(E?.comments??[]),trackedChanges:Object.freeze(E?.trackedChanges??[])})}),m=Fe(e,i);return Object.freeze({media:n??Object.freeze([]),warnings:Object.freeze(m),pages:Object.freeze(w),reviewArtifacts:o,reviewBindings:Ue(o,c,f),fontResolution:null,pagination:Object.freeze({source:"layout-engine",scope:"export-snapshot",layoutRevision:e.revision,displayMode:t}),markdown:c.markdown})}async function rn(e,n){let r=n.resourceTimeoutMs??6e4;if(!Number.isFinite(r)||r<=0)throw new RangeError("resourceTimeoutMs must be a positive finite number");if(n.signal?.aborted)throw new _export.ExportResourceError("aborted","Font provisioning was aborted",{cause:n.signal.reason});let o=new AbortController,t,a=new Promise((d,c)=>{t=c;}),s=()=>{let d=new _export.ExportResourceError("aborted","Font provisioning was aborted",{cause:n.signal?.reason});t?.(d),o.abort(d);};n.signal?.addEventListener("abort",s,{once:true});let i=setTimeout(()=>{let d=new _export.ExportResourceError("timedOut","Font provisioning timed out");t?.(d),o.abort(d);},Math.max(1,r));try{return await Promise.race([Promise.resolve().then(()=>e(o.signal)),a])}catch(d){throw d instanceof _export.ExportResourceError?d:o.signal.reason instanceof _export.ExportResourceError?o.signal.reason:new _export.ExportResourceError("layoutFailed","Font provisioning failed",{cause:d})}finally{clearTimeout(i),n.signal?.removeEventListener("abort",s),t=void 0;}}function tn(e){let n,r;return async o=>{if(n!==void 0)return n;if(o.aborted)throw o.reason;let t=r;if(!t){let d=new AbortController,c={controller:d,subscribers:0,promise:void 0};c.promise=Promise.resolve().then(()=>e(d.signal)).then(l=>(r===c&&(n??=l),n??l)).finally(()=>{r===c&&(r=void 0);}),r=c,t=c;}t.subscribers+=1;let a,s=new Promise((d,c)=>{a=c;}),i=()=>a?.(o.reason);o.addEventListener("abort",i,{once:true});try{return await Promise.race([t.promise,s])}finally{o.removeEventListener("abort",i),a=void 0,t.subscribers-=1,t.subscribers===0&&r===t&&n===void 0&&(r=void 0,t.controller.abort(o.reason));}}}var le=class extends Error{constructor(r,o){super(`Unable to open DOCX for export: ${r}${o?` (${o})`:""}`);this.reason=r;this.detail=o;this.name="DocumentOpenError";}reason;detail},ln=fonts.FONT_ASSET_ROOT.protocol==="file:"?_export.createPackagedFileFetch({trustedRoot:new URL("./",fonts.FONT_ASSET_ROOT),maxBytes:layout.HARD_MAX_FONT_BYTES}):fetch,dr=tn(async e=>{let n=await fonts.loadDefaultFonts({fetcher:ln,signal:e});if(n.failures.length>0||n.sources.length===0){let t=n.failures.map(a=>`${a.file}: ${a.diagnostic}`).join("; ");throw new Error(`Unable to provision packaged fonts for headless export${t?`: ${t}`:""}`)}let r=Object.freeze({epoch:1,maxFontBytes:layout.HARD_MAX_FONT_BYTES,sources:n.sources,substitutions:n.substitutions,defaultFont:Object.freeze({family:"Calibri",sizeHalfPoints:22})}),o=layout.prepareLayoutFontConfiguration(r);return Object.freeze({configuration:o})}),cr=fonts.packagedFonts({fetcher:ln,onFailure(){}}),lr=editor.defineFontResolver(async e=>{let n=await cr(e);return {...n,failures:n.failures.map(r=>new Error(`Unable to load bundled font ${r.file}: ${r.diagnostic}. In Next.js, add the converter, core, and fonts packages to serverExternalPackages.`))}});function pr(e){return ArrayBuffer.isView(e)}function sn(e){return e===void 0?[]:Array.isArray(e)?e:[e]}function ur(e,n){return Object.freeze({fontResolution:n,layout:()=>e.layout(),layoutFor:r=>e.layoutFor(r),validatedImageBytes:r=>e.validatedImageBytes(r),dispose:()=>e.dispose()})}function dn(e,n){return e.ok?{ok:true,session:ur(e.session,n)}:e}function gr(e){return e.ok?{ok:true,session:e.session}:e}function pn(e,n){let r=[...e.warnings];for(let o of n?.originFailures??[]){let t="unknown error";try{o.cause instanceof Error&&typeof o.cause.message=="string"&&(t=o.cause.message);}catch{}r.push(Object.freeze({code:"font-origin-failed",message:`A font source failed: ${t}`}));}for(let o of n?.families??[])o.coverage!=="complete"&&r.push(Object.freeze({code:"incomplete-font",message:`Font coverage is incomplete for ${o.family}; page breaks may differ.`}));return Object.freeze({...e,fontResolution:n,warnings:Object.freeze(r)})}async function fr(e,n={}){let{fonts:r,fallbackFonts:o,...t}=n;if(n.measurer){if(n.fontPolicy!==void 0||n.onFontResolution!==void 0)throw new TypeError("fontPolicy and onFontResolution cannot verify a caller-supplied measurer; omit measurer to use document-aware Core font resolution");return dn(await _export.openDocumentForExport(e,t),null)}let a=sn(n.fonts),s=sn(n.fallbackFonts);if(pr(e)){if(n.reuseAcrossRevisions===true)throw new TypeError("reuseAcrossRevisions requires a live view or caller-supplied measurer; document-aware byte sessions are immutable");let d=await _export.openFontBackedDocumentForExport(e,{...t,reuseAcrossRevisions:false,fonts:[...a,lr,...s],onFontResolution:n.onFontResolution});return gr(d)}if(a.length>0||s.length>0)throw new TypeError("fonts and fallbackFonts require immutable DOCX bytes; pass a revision-stable measurer when exporting a live HeadlessDocumentView");if(n.fontPolicy!==void 0||n.onFontResolution!==void 0)throw new TypeError("fontPolicy and onFontResolution require document-aware font resolution from immutable DOCX bytes; pass a revision-stable measurer when exporting a live HeadlessDocumentView");let i=await rn(d=>dr(d).then(c=>_export.acquireSharedExportShaping(c.configuration)),n);return dn(await _export.openDocumentForExport(e,{...t,reuseAcrossRevisions:n.reuseAcrossRevisions,measurer:i.createMeasurer(),producer:n.producer??i.producer}),null)}async function at(e,n={}){let r=_(n),o=await X(()=>e.layout(),n.signal);I(n.signal);let t=G(o,e,r),a=r?await J(t,n):void 0,s=W(o,a,r?.syntax);return pn(s,"fontResolution"in e?e.fontResolution:s.fontResolution)}function st(e){return W(e)}async function it(e,n={}){let r=_(n);I(n.signal);let{images:o,...t}=n,a=await fr(e,t);if(!a.ok)throw a.reason==="aborted"?new _export.ExportResourceError("aborted","Export was aborted before layout",{cause:n.signal?.reason}):new le(a.reason,a.detail);let s,i;try{s=await a.session.layout(),I(n.signal),i=G(s,a.session,r);}finally{a.session.dispose();}let d=r?W(s,await J(i,n),r.syntax):W(s);return pn(d,a.session.fontResolution)}Object.defineProperty(exports,"MarkdownBundleError",{enumerable:true,get:function(){return chunkNP5KYCWK_cjs.b}});Object.defineProperty(exports,"MarkdownMediaError",{enumerable:true,get:function(){return chunkNP5KYCWK_cjs.a}});Object.defineProperty(exports,"createMarkdownZip",{enumerable:true,get:function(){return chunkNP5KYCWK_cjs.e}});Object.defineProperty(exports,"toMarkdownJSON",{enumerable:true,get:function(){return chunkNP5KYCWK_cjs.c}});Object.defineProperty(exports,"ExportResourceError",{enumerable:true,get:function(){return _export.ExportResourceError}});Object.defineProperty(exports,"HARD_MAX_AGGREGATE_FONT_BYTES",{enumerable:true,get:function(){return layout.HARD_MAX_AGGREGATE_FONT_BYTES}});Object.defineProperty(exports,"HARD_MAX_FONT_BYTES",{enumerable:true,get:function(){return layout.HARD_MAX_FONT_BYTES}});Object.defineProperty(exports,"HARD_MAX_FONT_SOURCES",{enumerable:true,get:function(){return layout.HARD_MAX_FONT_SOURCES}});Object.defineProperty(exports,"forEachSemanticDrawing",{enumerable:true,get:function(){return layout.forEachSemanticDrawing}});Object.defineProperty(exports,"createFontSource",{enumerable:true,get:function(){return editor.createFontSource}});Object.defineProperty(exports,"defineFontResolver",{enumerable:true,get:function(){return editor.defineFontResolver}});exports.DocumentOpenError=le;exports.exportMarkdown=it;exports.exportMarkdownFrom=at;exports.exportMarkdownLayout=st;exports.openDocumentForExport=fr;
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
/// <reference lib="dom" />
|
|
2
|
+
import { M as MarkdownImageAsset, a as MarkdownExportResult, b as MarkdownExportOptions, c as MarkdownProjectionOptions, O as OpenMarkdownDocumentForExportOptions } from './markdown-types-Cn-MizR0.cjs';
|
|
3
|
+
export { d as MarkdownComment, e as MarkdownFontOrigin, f as MarkdownFontsSource, g as MarkdownImageData, h as MarkdownImageOccurrence, i as MarkdownImageOptions, j as MarkdownPage, k as MarkdownPaginationInfo, l as MarkdownReviewArtifact, m as MarkdownReviewBinding, n as MarkdownReviewCoverage, o as MarkdownReviewOccurrence, p as MarkdownReviewProjection, q as MarkdownReviewRange, r as MarkdownReviewRangePrecision, s as MarkdownReviewUnmappedReason, t as MarkdownTrackedChange, u as MarkdownWarning } from './markdown-types-Cn-MizR0.cjs';
|
|
4
|
+
import { ExportSession, ExportFontResolutionReport, OpenDocumentForExportResult, ExportDocumentSource, ExportSemanticLayout } from '@docx-editor.dev/core/export';
|
|
5
|
+
export { ExportContentWarning, ExportDestinationAnchor, ExportDestinationGeometry, ExportDocumentMetadata, ExportDocumentSource, ExportDroppedEmbeddedFont, ExportFontFaceResolution, ExportFontFamilyResolution, ExportFontResolutionReport, ExportResourceError, ExportSemanticLayout, ExportSession, FontOriginFailure, OpenDocumentForExportOptions, OpenDocumentForExportResult, PreservedImageConverter } from '@docx-editor.dev/core/export';
|
|
6
|
+
import { HeadlessDocumentRejection } from '@docx-editor.dev/core/store';
|
|
7
|
+
export { HeadlessDocumentRejection, HeadlessDocumentView, ImageDecodePort, ImageResourceState } from '@docx-editor.dev/core/store';
|
|
8
|
+
export { AnchoredDrawingLayoutFallback, AnchoredDrawingRecord, DrawingAccessibility, DrawingGeometry, DrawingHorizontalReferenceFrame, DrawingTransform, DrawingVerticalReferenceFrame, FontRequest, FontSubstitution, HARD_MAX_AGGREGATE_FONT_BYTES, HARD_MAX_FONT_BYTES, HARD_MAX_FONT_SOURCES, ImageWrapTarget, InlineDrawingRecord, LayoutBox, RevisionAttribution, RevisionDisplayMode, SemanticArtifactRootStoryKind, SemanticArtifactStoryKind, SemanticCommentArtifactRecord, SemanticDrawingVisit, SemanticLayout, SemanticReviewArtifactOccurrence, SemanticReviewArtifactOccurrenceGeometry, SemanticReviewArtifactPosition, SemanticReviewArtifactRecord, SemanticReviewArtifactSource, SemanticTrackedChangeArtifactRecord, SourceCrop, TextMeasurer, TextboxStoryLayout, VectorShapeProjection, forEachSemanticDrawing } from '@docx-editor.dev/core/layout';
|
|
9
|
+
export { createFontSource, defineFontResolver } from '@docx-editor.dev/core/editor';
|
|
10
|
+
|
|
11
|
+
/** Failure to produce a complete image export. @public */
|
|
12
|
+
declare class MarkdownMediaError extends Error {
|
|
13
|
+
readonly code: 'media-limit' | 'url-resolution-failed' | 'invalid-image-url' | 'image-bytes-unavailable';
|
|
14
|
+
readonly name = "MarkdownMediaError";
|
|
15
|
+
constructor(code: 'media-limit' | 'url-resolution-failed' | 'invalid-image-url' | 'image-bytes-unavailable', message: string, details?: {
|
|
16
|
+
readonly assetId?: string;
|
|
17
|
+
readonly limitBytes?: number;
|
|
18
|
+
readonly actualBytes?: number;
|
|
19
|
+
readonly cause?: unknown;
|
|
20
|
+
});
|
|
21
|
+
readonly assetId?: string;
|
|
22
|
+
readonly limitBytes?: number;
|
|
23
|
+
readonly actualBytes?: number;
|
|
24
|
+
}
|
|
25
|
+
/** Failure to write a complete portable Markdown bundle. @public */
|
|
26
|
+
declare class MarkdownBundleError extends Error {
|
|
27
|
+
readonly code: 'invalid-media-path' | 'duplicate-output-path' | 'non-portable-image-url' | 'output-not-empty' | 'write-failed' | 'archive-failed';
|
|
28
|
+
readonly name = "MarkdownBundleError";
|
|
29
|
+
constructor(code: 'invalid-media-path' | 'duplicate-output-path' | 'non-portable-image-url' | 'output-not-empty' | 'write-failed' | 'archive-failed', message: string, details?: {
|
|
30
|
+
readonly path?: string;
|
|
31
|
+
readonly cause?: unknown;
|
|
32
|
+
});
|
|
33
|
+
readonly path?: string;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** JSON-safe image metadata. Binary bytes are delivered separately. @public */
|
|
37
|
+
type MarkdownJSONImage = Omit<MarkdownImageAsset, 'bytes'>;
|
|
38
|
+
/** JSON-safe export for HTTP responses and portable bundle manifests. @public */
|
|
39
|
+
type MarkdownJSONResult = Omit<MarkdownExportResult, 'media' | 'fontResolution'> & {
|
|
40
|
+
readonly media: readonly MarkdownJSONImage[];
|
|
41
|
+
readonly fontResolution: (Omit<NonNullable<MarkdownExportResult['fontResolution']>, 'originFailures'> & {
|
|
42
|
+
readonly originFailures: readonly {
|
|
43
|
+
readonly originIndex: number;
|
|
44
|
+
readonly originName?: string;
|
|
45
|
+
readonly cause: string;
|
|
46
|
+
}[];
|
|
47
|
+
}) | null;
|
|
48
|
+
};
|
|
49
|
+
/** Omit image bytes and normalize arbitrary font failure causes to diagnostic strings. @public */
|
|
50
|
+
declare function toMarkdownJSON(result: MarkdownExportResult): MarkdownJSONResult;
|
|
51
|
+
/** Create a portable ZIP containing document.md, document.json, and media files. @public */
|
|
52
|
+
declare function createMarkdownZip(result: MarkdownExportResult): Promise<Uint8Array>;
|
|
53
|
+
|
|
54
|
+
/** Typed one-shot failure for bytes that cannot be opened as a supported DOCX. @public */
|
|
55
|
+
declare class DocumentOpenError extends Error {
|
|
56
|
+
readonly reason: HeadlessDocumentRejection | 'aborted';
|
|
57
|
+
readonly detail?: string | undefined;
|
|
58
|
+
constructor(reason: HeadlessDocumentRejection | 'aborted', detail?: string | undefined);
|
|
59
|
+
}
|
|
60
|
+
/** Reusable Markdown session with the font evidence captured while it opened. @public */
|
|
61
|
+
interface MarkdownExportSession extends ExportSession {
|
|
62
|
+
/**
|
|
63
|
+
* Non-null for document-aware byte sessions opened by Markdown or Core; null for detached
|
|
64
|
+
* layouts, caller-supplied measurers, ordinary Core sessions, and live shared-shaping sessions.
|
|
65
|
+
*/
|
|
66
|
+
readonly fontResolution: ExportFontResolutionReport | null;
|
|
67
|
+
}
|
|
68
|
+
/** Open result whose successful session retains its structured font-resolution report. @public */
|
|
69
|
+
type OpenMarkdownDocumentForExportResult = {
|
|
70
|
+
readonly ok: true;
|
|
71
|
+
readonly session: MarkdownExportSession;
|
|
72
|
+
} | Exclude<OpenDocumentForExportResult, {
|
|
73
|
+
readonly ok: true;
|
|
74
|
+
}>;
|
|
75
|
+
/** Open a reusable export session with packaged fonts and HarfBuzz shaping by default. @public */
|
|
76
|
+
declare function openDocumentForExport(source: ExportDocumentSource, options?: OpenMarkdownDocumentForExportOptions): Promise<OpenMarkdownDocumentForExportResult>;
|
|
77
|
+
/** Translate an existing shared export session without reopening or re-laying out it. @public */
|
|
78
|
+
declare function exportMarkdownFrom(session: ExportSession, options?: MarkdownProjectionOptions): Promise<MarkdownExportResult>;
|
|
79
|
+
/** Translate a detached immutable core layout after its producer session is disposed. @public */
|
|
80
|
+
declare function exportMarkdownLayout(layout: ExportSemanticLayout): MarkdownExportResult;
|
|
81
|
+
/** Convert untrusted DOCX bytes with Node-safe resource and shaping defaults. @public */
|
|
82
|
+
declare function exportMarkdown(source: ExportDocumentSource, options?: MarkdownExportOptions): Promise<MarkdownExportResult>;
|
|
83
|
+
|
|
84
|
+
export { DocumentOpenError, MarkdownBundleError, MarkdownExportOptions, MarkdownExportResult, type MarkdownExportSession, MarkdownImageAsset, type MarkdownJSONImage, type MarkdownJSONResult, MarkdownMediaError, MarkdownProjectionOptions, OpenMarkdownDocumentForExportOptions, type OpenMarkdownDocumentForExportResult, createMarkdownZip, exportMarkdown, exportMarkdownFrom, exportMarkdownLayout, openDocumentForExport, toMarkdownJSON };
|