@folijs/pdf 0.0.0-stage → 0.6.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.
- package/CHANGELOG.md +34 -0
- package/LICENSE +21 -0
- package/README.md +88 -2
- package/dist/index.d.ts +79 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +93 -0
- package/dist/index.js.map +1 -0
- package/dist/renderer.js +7 -0
- package/package.json +37 -3
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# @folijs/pdf
|
|
2
|
+
|
|
3
|
+
## 0.6.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- cd343e4: Sections, headers and footers, notes, fields, content controls, find and replace, and PDF, as Word models them: imported, laid out on pages, edited there and written back to `.docx`.
|
|
8
|
+
- **Schema v5** (`@folijs/core`, ADR-0007): `stories` in the envelope (headers, footers, footnotes and endnotes, each a tree of blocks), `controls` (content controls' properties) and `settings` (even and odd headers, note options, `doNotUseHTMLParagraphAutoSpacing`); field markers (`fieldStart`, `fieldCode`, `fieldSeparator`, `fieldEnd`), content control markers (`controlStart`, `controlEnd`; a `controls` attribute on blocks, rows and cells), `noteReference` and `noteMark` nodes; sections gain `columns`, `pageNumbers`, note properties and a tracked setup change (`change`). `SCHEMA_VERSION` 5: v4 documents migrate on load (the version only: what was opaque stays so until the `.docx` is imported again).
|
|
9
|
+
- **Stories and undo** (`@folijs/core`): `editor.story(id)` gives an editor over a header, footer or note; its changes are `StoryStep`s of the body's history (one undo across the document), `EnvelopeStep` for the last section, settings and controls; accept and reject all reach every story.
|
|
10
|
+
- **Sections** (`@folijs/core`, `@folijs/view`, `@folijs/react`): columns (equal and set widths, the line between, column breaks), continuous, next-column and even and odd page sections with Word's blank page, balanced columns above a continuous break; `insertSectionBreak`, `removeSectionBreak`, `setSectionSetup`, `insertColumnBreak`, tracked as Word records them; a Section menu and Page setup dialog.
|
|
11
|
+
- **Headers and footers**: drawn in their margins on every page (first, even and default variants, linked to the previous section, a taller one pushing the text, page fields filled per page), edited in place (double click or the Header menu, Escape returns) with typing, formatting, pictures, tables, undo and tracking; `setDifferentFirstPage`, `setDifferentEvenPages`, `setStoryLinked`.
|
|
12
|
+
- **Footnotes and endnotes**: at their reference's page foot under a separator, continued on the next page, beneath the text or at the end of a section or the document; numbered in Word's formats with restarts (`noteNumbers`, never stored); `insertNote`, `setNoteProperties`, `convertNotes`; deleted with their reference, tracked, carried on the clipboard; edited in place (double click, Shift+Alt+N, the Notes menu and its options dialog).
|
|
13
|
+
- **Fields**: shown with their results, selected and deleted whole, codes hidden or shown (Alt+F9); `updateFields` (`PAGE`, `NUMPAGES`, `SECTIONPAGES`, `DATE`, `TIME`, `REF`, `PAGEREF`, `SEQ`, `TOC` from heading styles with their pages, `MERGEFIELD` from data; F9, Ctrl+A then F9, `view.updateFields`, `view.print()`) returning what it updated and what it left; `fieldsIn`, `insertField`, `insertPageNumber`, `insertDate`, `insertCrossReference`, `insertTableOfContents`; a Fields menu and cross-reference dialog.
|
|
14
|
+
- **Content controls**: plain and rich text, drop-down, combo box, date, check box, picture, repeating sections, with Word's locks, placeholders and what each kind holds; frames, titles, lists, a date picker and check boxes in the view (Alt+Down, Space); `insertControl`, `setControlValue` and `controlValues` (by id or tag), `setControlProperties`, `addRepeatingItem`; a Controls menu and properties dialog.
|
|
15
|
+
- **Navigation**: `findAll`, `replace`, `replaceAll` over the body and every story (match case, whole words, tracked while tracking, one undo step), `insertBookmark`, `renameBookmark`, `deleteBookmark`, `listBookmarks`, `goTo`, `documentOutline`; matches marked with the CSS Custom Highlight API; `FoliNavigation` (find, replace and go to panel, bookmarks dialog, outline), included in `FoliEditor`, with Word's keys (Ctrl+F, Ctrl+H, Ctrl+G, F3, Shift+F3, Ctrl+Shift+F5) and a Navigate menu.
|
|
16
|
+
- **DOCX** (`@folijs/docx`): headers, footers, footnotes and endnotes read and written as stories (unchanged ones byte for byte, new ones with their parts, relationships and content types), complex and simple fields, content controls at every level (properties patched into the kept `w:sdtPr`), sections' columns, page numbers and note properties, `word/settings.xml`'s even and odd headers and note options. Word reads Foli's sections, headers, notes, fields, controls and replacements back (`scripts/corpus/*-roundtrip.mjs`).
|
|
17
|
+
- **PDF** (`@folijs/pdf`, first released): `exportPdf(document, { page, resources, review, styles })` prints Foli's own pages with a headless Chromium page the app supplies (Playwright 1.42+; Puppeteer's page type fits): each section on its own sheet size, fields updated from the pages first, safe links and bookmark links as PDF links, headings as PDF bookmarks, a tagged PDF. The page loads nothing from the network (images and fonts as `data:` URLs only). Against Word's PDFs of the corpus it scores 0.954 over 24 pages.
|
|
18
|
+
- **Pages against Word**: all 158 paragraphs outside tables that the harness compares on Word's page; headers, footers and notes scored with the rest of the page (0.889 over 24 pages on screen).
|
|
19
|
+
|
|
20
|
+
0.5.0 cannot read documents saved by 0.6.0 (schema v5). Known limits are in [Known limitations](https://github.com/josep-audenis/foli/blob/main/docs/limitations.md) (content, finding and going places, print and PDF sections).
|
|
21
|
+
|
|
22
|
+
Changed behaviour (pre-1.0 minor):
|
|
23
|
+
- `.docx` headers, footers and notes import as `stories` (0.5.0 kept them as parts, never shown); note references, fields (`w:fldChar`, `w:instrText`, `w:fldSimple`) and content controls (`w:sdt`) that imported as `opaqueInline` or `opaqueBlock` now import as nodes. A v4 document's opaque content stays opaque until the `.docx` is imported again.
|
|
24
|
+
- Layout: between two paragraphs goes the larger of the first's space after and the second's space before, as in Word's PDFs (0.5.0 added them; they still add up with `w:doNotUseHTMLParagraphAutoSpacing`); a line is as tall as its runs and paragraph mark, not the paragraph style's font; a header or footer taller than its margin pushes the text. Pages break differently than in 0.5.0, closer to Word.
|
|
25
|
+
- `FoliEditor` includes `FoliNavigation` and takes Ctrl+F, Ctrl+H, Ctrl+G, F3, Shift+F3 and Ctrl+Shift+F5 while the focus is in the document or its panels (the browser's own find no longer opens there).
|
|
26
|
+
- `FoliToolbar` shows the Section, Header, Fields, Navigate, Notes and Controls menus.
|
|
27
|
+
- `view.print()` updates every field before printing; the print rules are shared with `exportPdf`.
|
|
28
|
+
- Backspace at a field's edge selects the field first, and a selection crossing a field's markers takes the whole field, as in Word; the caret steps over a field's code.
|
|
29
|
+
- `acceptAllChanges` and `rejectAllChanges` also settle the tracked changes in headers, footers and notes.
|
|
30
|
+
|
|
31
|
+
### Patch Changes
|
|
32
|
+
|
|
33
|
+
- Updated dependencies [cd343e4]
|
|
34
|
+
- @folijs/core@0.6.0
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Josep Audenis
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,89 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @folijs/pdf
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
PDF for [Foli](https://github.com/josep-audenis/foli): `exportPdf` prints a Foli document (schema
|
|
4
|
+
v5 of `@folijs/core`) to PDF with a headless Chromium page your app supplies, from Foli's own page
|
|
5
|
+
layout: the pages the editor shows and prints. No browser dependency of its own: bring
|
|
6
|
+
Playwright (1.42+) or Puppeteer.
|
|
7
|
+
|
|
8
|
+
> Early release: the API may change in any 0.x minor version (changes in `CHANGELOG.md`).
|
|
9
|
+
|
|
10
|
+
```bash
|
|
11
|
+
npm install @folijs/pdf @folijs/core
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
```ts
|
|
15
|
+
import { importDocx } from "@folijs/docx";
|
|
16
|
+
import { exportPdf } from "@folijs/pdf";
|
|
17
|
+
import { chromium } from "playwright";
|
|
18
|
+
|
|
19
|
+
const { document, package: pkg } = await importDocx(bytes);
|
|
20
|
+
const browser = await chromium.launch();
|
|
21
|
+
const page = await browser.newPage();
|
|
22
|
+
const { pdf, pages, fields } = await exportPdf(document, {
|
|
23
|
+
page,
|
|
24
|
+
// The pictures' images: here a .docx package's parts.
|
|
25
|
+
resources: (_key, resource) => (resource.part ? pkg.part(`/${resource.part}`) : undefined),
|
|
26
|
+
});
|
|
27
|
+
await browser.close();
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
What it does, in the page (its content is replaced):
|
|
31
|
+
|
|
32
|
+
1. Adds the package's renderer (`dist/renderer.js`: `@folijs/core` and `@folijs/view`'s read-only
|
|
33
|
+
renderer, bundled; your app needs nothing else) and the CSS you give (`styles`).
|
|
34
|
+
2. Lays the document out on pages: every section's page size, margins and columns, headers and
|
|
35
|
+
footers, footnotes and endnotes, tables, pictures, tracked changes as `review` says (`markup`,
|
|
36
|
+
the default; `simple`; `final`).
|
|
37
|
+
3. Updates the fields from those pages (`updateFields` of `@folijs/core`: `PAGE`, `NUMPAGES`,
|
|
38
|
+
`SECTIONPAGES`, `PAGEREF`, `REF`, `SEQ`, `DATE`, tables of contents…), lays out again what
|
|
39
|
+
that changed, and again once for what depends on the pages. `fields` reports what was updated
|
|
40
|
+
and what was left as it was (a locked field, an unknown one).
|
|
41
|
+
4. Makes links PDF links: a web link (`https:`, `mailto:`… the editor's safe targets) and a link to
|
|
42
|
+
a bookmark of the document; other targets stay text.
|
|
43
|
+
5. Prints with `page.pdf({ preferCSSPageSize: true, printBackground: true, outline: true, tagged: true })`
|
|
44
|
+
and the editor's own print rules: one sheet per page, each the size of its section's pages
|
|
45
|
+
(CSS named pages: a landscape section prints on landscape sheets), headings as PDF bookmarks,
|
|
46
|
+
a tagged PDF.
|
|
47
|
+
|
|
48
|
+
The document is validated first (`parseDocument`): an invalid one throws before the page is used.
|
|
49
|
+
|
|
50
|
+
## Fonts
|
|
51
|
+
|
|
52
|
+
Chromium lays the text out with the fonts it has: the machine's, and those the page loads. A
|
|
53
|
+
document in fonts the machine lacks (Office's cloud fonts, such as Aptos, are not installed
|
|
54
|
+
system-wide) prints in a fallback, with other line breaks than Word's. Install the fonts on the
|
|
55
|
+
machine that prints, or give `@font-face` rules in `styles` with the font files as `data:` URLs
|
|
56
|
+
(`src: url("data:font/ttf;base64,…")`; each face declared is loaded before the layout). A web
|
|
57
|
+
font's URL is not loaded (below). Only fonts you may embed in a PDF.
|
|
58
|
+
|
|
59
|
+
## Pictures
|
|
60
|
+
|
|
61
|
+
`resources(key, resource)` gives each picture's image: `{ data, contentType }` (a package part
|
|
62
|
+
is one), an image `data:` URL, `null` for the picture's box, `undefined` for the resource's own
|
|
63
|
+
`data:` URL. PNG, JPEG, GIF, WebP, BMP and SVG are drawn; EMF, WMF and TIFF print as the
|
|
64
|
+
picture's box. A picture whose image has not decoded after 10 seconds prints without it.
|
|
65
|
+
|
|
66
|
+
## Nothing leaves the page
|
|
67
|
+
|
|
68
|
+
A document is often a user's, and the server that exports it is inside your network: a picture
|
|
69
|
+
or font URL in it would make that server request any address it names. So the page loads nothing:
|
|
70
|
+
`exportPdf` hands it images and fonts as `data:` URLs only, a web URL (a resource's own `url`, or
|
|
71
|
+
one `resources` returns) prints the picture's box, and the page's Content Security Policy
|
|
72
|
+
(`default-src 'none'; img-src data:; font-src data:; style-src 'unsafe-inline'; script-src
|
|
73
|
+
'unsafe-inline'`) blocks every other request, those of `styles` included (`@import`, a web font).
|
|
74
|
+
To print a web image, fetch it yourself (checking the address) and give its bytes. Links are kept
|
|
75
|
+
in the PDF but never followed.
|
|
76
|
+
|
|
77
|
+
## Puppeteer
|
|
78
|
+
|
|
79
|
+
`PdfPage` is the part of a page `exportPdf` uses (`setContent`, `addScriptTag`, `evaluate`,
|
|
80
|
+
`pdf`). Playwright's and Puppeteer's (24) `Page` types fit it; it is run with Playwright's
|
|
81
|
+
Chromium only.
|
|
82
|
+
|
|
83
|
+
## In the browser
|
|
84
|
+
|
|
85
|
+
The editor prints the same pages with the user's dialog: `view.print()` (`@folijs/view`) updates
|
|
86
|
+
the fields from the pages, then opens the browser's print, with the same print rules.
|
|
87
|
+
|
|
88
|
+
- [API reference](https://github.com/josep-audenis/foli/blob/main/docs/api.md#folijspdf)
|
|
89
|
+
- [Limitations](https://github.com/josep-audenis/foli/blob/main/docs/limitations.md#print-and-pdf)
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { type FieldsReport, type FoliDocument, type ResourceJSON, type ReviewView } from "@folijs/core";
|
|
2
|
+
/**
|
|
3
|
+
* What `exportPdf` uses of a page: Playwright's `Page` (1.42+ for the outline and tags) and
|
|
4
|
+
* Puppeteer's `Page` have these. The page is the app's: `exportPdf` replaces its content.
|
|
5
|
+
*/
|
|
6
|
+
export interface PdfPage {
|
|
7
|
+
setContent(html: string): Promise<unknown>;
|
|
8
|
+
addScriptTag(options: {
|
|
9
|
+
content: string;
|
|
10
|
+
}): Promise<unknown>;
|
|
11
|
+
evaluate(fn: (arg: RenderInput) => Promise<Rendered>, arg: RenderInput): Promise<unknown>;
|
|
12
|
+
pdf(options: PdfPrintOptions): Promise<Uint8Array>;
|
|
13
|
+
}
|
|
14
|
+
/** The options `exportPdf` gives `page.pdf`. */
|
|
15
|
+
export interface PdfPrintOptions {
|
|
16
|
+
/** Each sheet the size of its section's pages (the print rules' `@page`). */
|
|
17
|
+
preferCSSPageSize: true;
|
|
18
|
+
printBackground: true;
|
|
19
|
+
/** PDF bookmarks from the headings (Chromium; Playwright 1.42+). */
|
|
20
|
+
outline: true;
|
|
21
|
+
/** A tagged PDF (Chromium; Playwright 1.42+). */
|
|
22
|
+
tagged: true;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* A picture's image: bytes with their type (a `.docx` package part is one), an image `data:` URL,
|
|
26
|
+
* `null` for the picture's box, `undefined` for the resource's own `data:` URL. The page loads
|
|
27
|
+
* nothing from the network: a web URL, given here or in the resource, prints the picture's box.
|
|
28
|
+
*/
|
|
29
|
+
export type PdfImage = {
|
|
30
|
+
data: Uint8Array;
|
|
31
|
+
contentType: string;
|
|
32
|
+
} | string | null | undefined;
|
|
33
|
+
export interface ExportPdfOptions {
|
|
34
|
+
/** The page that prints: the app's Chromium page (headless), with the document's fonts. */
|
|
35
|
+
page: PdfPage;
|
|
36
|
+
/**
|
|
37
|
+
* The images of the document's pictures, by resource, as bytes or `data:` URLs (for a `.docx`:
|
|
38
|
+
* `(key, r) => (r.part ? pkg.part(`/${r.part}`) : undefined)`).
|
|
39
|
+
*/
|
|
40
|
+
resources?: ((key: string, resource: ResourceJSON) => PdfImage) | undefined;
|
|
41
|
+
/** How tracked changes print: `markup` (default), `simple` or `final` (as if accepted). */
|
|
42
|
+
review?: ReviewView | undefined;
|
|
43
|
+
/**
|
|
44
|
+
* CSS added to the page before the document is laid out: `@font-face` rules for fonts the
|
|
45
|
+
* machine does not have, their `src` as `data:` URLs (the page loads nothing from the network).
|
|
46
|
+
* Each face declared is loaded first.
|
|
47
|
+
*/
|
|
48
|
+
styles?: string | undefined;
|
|
49
|
+
}
|
|
50
|
+
export interface ExportedPdf {
|
|
51
|
+
/** The PDF file. */
|
|
52
|
+
pdf: Uint8Array;
|
|
53
|
+
/** Its pages. */
|
|
54
|
+
pages: number;
|
|
55
|
+
/** The fields updated before printing, and those left as they were and why. */
|
|
56
|
+
fields: FieldsReport;
|
|
57
|
+
}
|
|
58
|
+
/** What the page's renderer is given (`renderer.ts`). */
|
|
59
|
+
export interface RenderInput {
|
|
60
|
+
document: FoliDocument;
|
|
61
|
+
/** Image URLs by resource key; `null`: the picture's box. */
|
|
62
|
+
images: Record<string, string | null>;
|
|
63
|
+
review: ReviewView;
|
|
64
|
+
styles: string;
|
|
65
|
+
}
|
|
66
|
+
/** What the page's renderer gives back. */
|
|
67
|
+
export interface Rendered {
|
|
68
|
+
pages: number;
|
|
69
|
+
fields: FieldsReport;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Prints `document` to PDF with `options.page`: laid out on Foli's pages, fields updated from
|
|
73
|
+
* them (`PAGE`, `NUMPAGES`, `PAGEREF`, tables of contents…), headers, footers, notes, columns
|
|
74
|
+
* and sections as the editor shows them; each sheet its section's page size; links kept and
|
|
75
|
+
* headings as PDF bookmarks. The page's content is replaced. `document` is validated first
|
|
76
|
+
* (`parseDocument`): an invalid one throws before the page is touched.
|
|
77
|
+
*/
|
|
78
|
+
export declare function exportPdf(document: FoliDocument, options: ExportPdfOptions): Promise<ExportedPdf>;
|
|
79
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAQA,OAAO,EACL,KAAK,YAAY,EACjB,KAAK,YAAY,EAEjB,KAAK,YAAY,EACjB,KAAK,UAAU,EAChB,MAAM,cAAc,CAAC;AAEtB;;;GAGG;AACH,MAAM,WAAW,OAAO;IACtB,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;IAC3C,YAAY,CAAC,OAAO,EAAE;QAAE,OAAO,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;IAE7D,QAAQ,CAAC,EAAE,EAAE,CAAC,GAAG,EAAE,WAAW,KAAK,OAAO,CAAC,QAAQ,CAAC,EAAE,GAAG,EAAE,WAAW,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;IAC1F,GAAG,CAAC,OAAO,EAAE,eAAe,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC;CACpD;AAED,gDAAgD;AAChD,MAAM,WAAW,eAAe;IAC9B,6EAA6E;IAC7E,iBAAiB,EAAE,IAAI,CAAC;IACxB,eAAe,EAAE,IAAI,CAAC;IACtB,oEAAoE;IACpE,OAAO,EAAE,IAAI,CAAC;IACd,iDAAiD;IACjD,MAAM,EAAE,IAAI,CAAC;CACd;AAED;;;;GAIG;AACH,MAAM,MAAM,QAAQ,GAAG;IAAE,IAAI,EAAE,UAAU,CAAC;IAAC,WAAW,EAAE,MAAM,CAAA;CAAE,GAAG,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC;AAE7F,MAAM,WAAW,gBAAgB;IAC/B,2FAA2F;IAC3F,IAAI,EAAE,OAAO,CAAC;IACd;;;OAGG;IACH,SAAS,CAAC,EAAE,CAAC,CAAC,GAAG,EAAE,MAAM,EAAE,QAAQ,EAAE,YAAY,KAAK,QAAQ,CAAC,GAAG,SAAS,CAAC;IAC5E,2FAA2F;IAC3F,MAAM,CAAC,EAAE,UAAU,GAAG,SAAS,CAAC;IAChC;;;;OAIG;IACH,MAAM,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;CAC7B;AAED,MAAM,WAAW,WAAW;IAC1B,oBAAoB;IACpB,GAAG,EAAE,UAAU,CAAC;IAChB,iBAAiB;IACjB,KAAK,EAAE,MAAM,CAAC;IACd,+EAA+E;IAC/E,MAAM,EAAE,YAAY,CAAC;CACtB;AAED,yDAAyD;AACzD,MAAM,WAAW,WAAW;IAC1B,QAAQ,EAAE,YAAY,CAAC;IACvB,6DAA6D;IAC7D,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC,CAAC;IACtC,MAAM,EAAE,UAAU,CAAC;IACnB,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,2CAA2C;AAC3C,MAAM,WAAW,QAAQ;IACvB,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,YAAY,CAAC;CACtB;AAkED;;;;;;GAMG;AACH,wBAAsB,SAAS,CAC7B,QAAQ,EAAE,YAAY,EACtB,OAAO,EAAE,gBAAgB,GACxB,OAAO,CAAC,WAAW,CAAC,CA4BtB"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `exportPdf` (11.12, ADR-0007): a document printed to PDF by a Chromium page the app supplies,
|
|
3
|
+
* from Foli's own layout. The page is given the read-only renderer (`dist/renderer.js`, bundled
|
|
4
|
+
* with `@folijs/core` and `@folijs/view`), which lays the document out on pages, updates its
|
|
5
|
+
* fields from them and adds the editor's print rules; then Chromium prints it. No browser
|
|
6
|
+
* dependency: Playwright's and Puppeteer's pages fit `PdfPage`.
|
|
7
|
+
*/
|
|
8
|
+
import { readFile } from "node:fs/promises";
|
|
9
|
+
import { parseDocument, } from "@folijs/core";
|
|
10
|
+
/** Image types Chromium shows in an `img`; others (EMF, WMF, TIFF) print as the picture's box. */
|
|
11
|
+
const SHOWN = new Set([
|
|
12
|
+
"image/png",
|
|
13
|
+
"image/jpeg",
|
|
14
|
+
"image/jpg",
|
|
15
|
+
"image/gif",
|
|
16
|
+
"image/webp",
|
|
17
|
+
"image/bmp",
|
|
18
|
+
"image/svg+xml",
|
|
19
|
+
]);
|
|
20
|
+
const DATA_IMAGE = /^data:image\//i;
|
|
21
|
+
/**
|
|
22
|
+
* Every resource's image as the page shows it: a `data:` URL, or null for the picture's box.
|
|
23
|
+
* Never a web URL: a document could make the server exporting it fetch any address, its own
|
|
24
|
+
* network's included. An SVG is an `img`'s `data:` URL: its scripts never run.
|
|
25
|
+
*/
|
|
26
|
+
function images(document, resources) {
|
|
27
|
+
const out = {};
|
|
28
|
+
for (const [key, resource] of Object.entries(document.resources ?? {})) {
|
|
29
|
+
// null from the app is the picture's box; only undefined falls back to the resource's own data.
|
|
30
|
+
const given = resources?.(key, resource);
|
|
31
|
+
const image = given === undefined ? (resource.data ?? null) : given;
|
|
32
|
+
if (image === null || typeof image === "string")
|
|
33
|
+
out[key] = image && DATA_IMAGE.test(image) ? image : null;
|
|
34
|
+
else if (!SHOWN.has(image.contentType.toLowerCase()))
|
|
35
|
+
out[key] = null;
|
|
36
|
+
else {
|
|
37
|
+
const { data, contentType } = image;
|
|
38
|
+
const base64 = Buffer.from(data.buffer, data.byteOffset, data.byteLength).toString("base64");
|
|
39
|
+
out[key] = `data:${contentType};base64,${base64}`;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
return out;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* The page's document. Its policy keeps everything inside the page: images and fonts from
|
|
46
|
+
* `data:` URLs only, no other request, inline scripts (the renderer) and styles.
|
|
47
|
+
*/
|
|
48
|
+
const PAGE = '<!doctype html><html><head><meta charset="utf-8"><meta http-equiv="Content-Security-Policy" ' +
|
|
49
|
+
`content="default-src 'none'; img-src data:; font-src data:; style-src 'unsafe-inline'; ` +
|
|
50
|
+
`script-src 'unsafe-inline'"></head><body></body></html>`;
|
|
51
|
+
let bundle = null;
|
|
52
|
+
/** The page's renderer, built with the package (`dist/renderer.js`). */
|
|
53
|
+
function rendererBundle() {
|
|
54
|
+
// From src/ (the source condition) and dist/ alike.
|
|
55
|
+
bundle ??= readFile(new URL("../dist/renderer.js", import.meta.url), "utf8").catch((error) => {
|
|
56
|
+
bundle = null;
|
|
57
|
+
throw new Error("@folijs/pdf: dist/renderer.js is missing; build the package", {
|
|
58
|
+
cause: error,
|
|
59
|
+
});
|
|
60
|
+
});
|
|
61
|
+
return bundle;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Prints `document` to PDF with `options.page`: laid out on Foli's pages, fields updated from
|
|
65
|
+
* them (`PAGE`, `NUMPAGES`, `PAGEREF`, tables of contents…), headers, footers, notes, columns
|
|
66
|
+
* and sections as the editor shows them; each sheet its section's page size; links kept and
|
|
67
|
+
* headings as PDF bookmarks. The page's content is replaced. `document` is validated first
|
|
68
|
+
* (`parseDocument`): an invalid one throws before the page is touched.
|
|
69
|
+
*/
|
|
70
|
+
export async function exportPdf(document, options) {
|
|
71
|
+
const valid = parseDocument(document);
|
|
72
|
+
const { page } = options;
|
|
73
|
+
if (!page || typeof page.pdf !== "function" || typeof page.evaluate !== "function")
|
|
74
|
+
throw new TypeError("@folijs/pdf: options.page must be a Playwright or Puppeteer page");
|
|
75
|
+
const input = {
|
|
76
|
+
document: valid,
|
|
77
|
+
images: images(valid, options.resources),
|
|
78
|
+
review: options.review ?? "markup",
|
|
79
|
+
styles: options.styles ?? "",
|
|
80
|
+
};
|
|
81
|
+
const script = await rendererBundle();
|
|
82
|
+
await page.setContent(PAGE);
|
|
83
|
+
await page.addScriptTag({ content: script });
|
|
84
|
+
const rendered = (await page.evaluate((arg) => window.foliPdf.render(arg), input));
|
|
85
|
+
const pdf = await page.pdf({
|
|
86
|
+
preferCSSPageSize: true,
|
|
87
|
+
printBackground: true,
|
|
88
|
+
outline: true,
|
|
89
|
+
tagged: true,
|
|
90
|
+
});
|
|
91
|
+
return { pdf, pages: rendered.pages, fields: rendered.fields };
|
|
92
|
+
}
|
|
93
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAGL,aAAa,GAGd,MAAM,cAAc,CAAC;AA0EtB,kGAAkG;AAClG,MAAM,KAAK,GAAG,IAAI,GAAG,CAAC;IACpB,WAAW;IACX,YAAY;IACZ,WAAW;IACX,WAAW;IACX,YAAY;IACZ,WAAW;IACX,eAAe;CAChB,CAAC,CAAC;AAEH,MAAM,UAAU,GAAG,gBAAgB,CAAC;AAEpC;;;;GAIG;AACH,SAAS,MAAM,CACb,QAAsB,EACtB,SAAwC;IAExC,MAAM,GAAG,GAAkC,EAAE,CAAC;IAC9C,KAAK,MAAM,CAAC,GAAG,EAAE,QAAQ,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,QAAQ,CAAC,SAAS,IAAI,EAAE,CAAC,EAAE,CAAC;QACvE,gGAAgG;QAChG,MAAM,KAAK,GAAG,SAAS,EAAE,CAAC,GAAG,EAAE,QAAQ,CAAC,CAAC;QACzC,MAAM,KAAK,GAAG,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,IAAI,IAAI,IAAI,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC;QACpE,IAAI,KAAK,KAAK,IAAI,IAAI,OAAO,KAAK,KAAK,QAAQ;YAC7C,GAAG,CAAC,GAAG,CAAC,GAAG,KAAK,IAAI,UAAU,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC;aACvD,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,KAAK,CAAC,WAAW,CAAC,WAAW,EAAE,CAAC;YAAE,GAAG,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC;aACjE,CAAC;YACJ,MAAM,EAAE,IAAI,EAAE,WAAW,EAAE,GAAG,KAAK,CAAC;YACpC,MAAM,MAAM,GAAG,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,UAAU,EAAE,IAAI,CAAC,UAAU,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;YAC7F,GAAG,CAAC,GAAG,CAAC,GAAG,QAAQ,WAAW,WAAW,MAAM,EAAE,CAAC;QACpD,CAAC;IACH,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC;AAED;;;GAGG;AACH,MAAM,IAAI,GACR,8FAA8F;IAC9F,yFAAyF;IACzF,yDAAyD,CAAC;AAE5D,IAAI,MAAM,GAA2B,IAAI,CAAC;AAE1C,wEAAwE;AACxE,SAAS,cAAc;IACrB,oDAAoD;IACpD,MAAM,KAAK,QAAQ,CAAC,IAAI,GAAG,CAAC,qBAAqB,EAAE,OAAO,IAAI,CAAC,GAAG,CAAC,EAAE,MAAM,CAAC,CAAC,KAAK,CAChF,CAAC,KAAc,EAAE,EAAE;QACjB,MAAM,GAAG,IAAI,CAAC;QACd,MAAM,IAAI,KAAK,CAAC,6DAA6D,EAAE;YAC7E,KAAK,EAAE,KAAK;SACb,CAAC,CAAC;IACL,CAAC,CACF,CAAC;IACF,OAAO,MAAM,CAAC;AAChB,CAAC;AAED;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,SAAS,CAC7B,QAAsB,EACtB,OAAyB;IAEzB,MAAM,KAAK,GAAG,aAAa,CAAC,QAAQ,CAAC,CAAC;IACtC,MAAM,EAAE,IAAI,EAAE,GAAG,OAAO,CAAC;IACzB,IAAI,CAAC,IAAI,IAAI,OAAO,IAAI,CAAC,GAAG,KAAK,UAAU,IAAI,OAAO,IAAI,CAAC,QAAQ,KAAK,UAAU;QAChF,MAAM,IAAI,SAAS,CAAC,kEAAkE,CAAC,CAAC;IAC1F,MAAM,KAAK,GAAgB;QACzB,QAAQ,EAAE,KAAK;QACf,MAAM,EAAE,MAAM,CAAC,KAAK,EAAE,OAAO,CAAC,SAAS,CAAC;QACxC,MAAM,EAAE,OAAO,CAAC,MAAM,IAAI,QAAQ;QAClC,MAAM,EAAE,OAAO,CAAC,MAAM,IAAI,EAAE;KAC7B,CAAC;IACF,MAAM,MAAM,GAAG,MAAM,cAAc,EAAE,CAAC;IACtC,MAAM,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC;IAC5B,MAAM,IAAI,CAAC,YAAY,CAAC,EAAE,OAAO,EAAE,MAAM,EAAE,CAAC,CAAC;IAC7C,MAAM,QAAQ,GAAG,CAAC,MAAM,IAAI,CAAC,QAAQ,CACnC,CAAC,GAAgB,EAAE,EAAE,CAEjB,MACD,CAAC,OAAO,CAAC,MAAM,CAAC,GAAG,CAAC,EACvB,KAAK,CACN,CAAa,CAAC;IACf,MAAM,GAAG,GAAG,MAAM,IAAI,CAAC,GAAG,CAAC;QACzB,iBAAiB,EAAE,IAAI;QACvB,eAAe,EAAE,IAAI;QACrB,OAAO,EAAE,IAAI;QACb,MAAM,EAAE,IAAI;KACb,CAAC,CAAC;IACH,OAAO,EAAE,GAAG,EAAE,KAAK,EAAE,QAAQ,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,CAAC,MAAM,EAAE,CAAC;AACjE,CAAC"}
|
package/dist/renderer.js
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
var foliPdfRenderer=(function(e){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var t=class{expr;elements;matches=new Map;constructor(e,t){this.expr=e,this.elements=t}match(e){let t=e.join(`,`),r=this.matches.get(t);return r||(r=new n(this,e),this.matches.set(t,r)),r}close(e){let t=new Set;for(let n of e)for(t.add(n);n<this.elements.length&&this.elements[n]?.optional;)t.add(++n);return[...t].sort((e,t)=>e-t)}},n=class{program;states;next=new Map;validEnd;constructor(e,t){this.program=e,this.states=t,this.validEnd=t.includes(e.elements.length)}matchType(e){let t=this.next.get(e);if(t===void 0){let n=[];for(let t of this.states){let r=this.program.elements[t];r?.types.includes(e)&&n.push(r.repeat?t:t+1)}t=n.length?this.program.match(this.program.close(n)):null,this.next.set(e,t)}return t}matchFragment(e,t=0,n=e.childCount){let r=this;for(let i=t;r&&i<n;i++)r=r.matchType(e.child(i).type);return r}get nextTypes(){let e=[];for(let t of this.states)for(let n of this.program.elements[t]?.types??[])e.includes(n)||e.push(n);return e}get defaultType(){return this.nextTypes.find(e=>!e.isText&&!e.hasRequiredAttrs()&&e.contentMatch.validEnd)??null}findWrapping(e){let t=new Set,n=[{match:this,type:null,via:null}];for(;n.length;){let r=n.shift();if(r.match.matchType(e)){let e=[];for(let t=r;t?.type;t=t.via)e.push(t.type);return e.reverse()}for(let e of r.match.nextTypes){let i=r.match.matchType(e);e.isLeaf||e.hasRequiredAttrs()||t.has(e)||r.type&&!i?.validEnd||(t.add(e),n.push({match:e.contentMatch,type:e,via:r}))}}return null}get inlineContent(){return this.program.elements[0]?.types[0]?.isInline??!1}toString(){return this.program.expr}static compile(e,n){let i=new t(e,r(e,n)),a=i.elements.flatMap(e=>e.types).map(e=>e.isInline);if(a.some(e=>e!==a[0]))throw Error(`Content expression "${e}" mixes inline and block nodes`);return i.match(i.close([0]))}};function r(e,t){let n=e.match(/\w+|[()|*+?]|\S/g)??[],r=[],i=0,a=t=>{throw Error(`Invalid content expression "${e}": ${t}`)},o=e=>{if(e===void 0||!/^\w+$/.test(e))return a(`expected a name, got ${e}`);let n=t.filter(t=>t.name===e),r=n.length?n:t.filter(t=>t.groups.includes(e));return r.length?r:a(`no node type or group "${e}"`)};for(;i<n.length;){let e;if(n[i]===`(`){for(i++,e=o(n[i++]);n[i]===`|`;)i++,e=e.concat(o(n[i++]));n[i++]!==`)`&&a(`expected ")"`)}else e=o(n[i++]);let t=n[i];(t===`*`||t===`+`||t===`?`)&&i++,t===`+`&&r.push({types:e,optional:!1,repeat:!1}),r.push({types:e,optional:t===`*`||t===`+`||t===`?`,repeat:t===`*`||t===`+`})}return r}var i=class extends Error{name=`FoliDocumentError`},a=class extends Error{name=`ReplaceError`};function o(e,t){throw new i(`${e}: ${t}`)}var s=Object.freeze({});function c(e,t,n){for(let r of Object.keys(t??s))e&&Object.hasOwn(e,r)||o(`${n}.${r}`,`unknown attribute`);if(!e)return s;let r={};for(let[i,a]of Object.entries(e)){let e=t?.[i];e===void 0&&(`default`in a||o(`${n}.${i}`,`required attribute is missing`),e=a.default);let s=a.validate?.(e);s!==void 0&&o(`${n}.${i}`,s),r[i]=e}return r}function l(e,t){if(!e)return;let n;for(let[r,i]of Object.entries(e)){let e=t[r];`default`in i&&u(e,i.default)||(n??={},n[r]=e)}return n}function u(e,t){if(e===t)return!0;if(typeof e!=`object`||typeof t!=`object`||e===null||t===null||Array.isArray(e)!==Array.isArray(t))return!1;let n=Object.keys(e);return n.length===Object.keys(t).length&&n.every(n=>Object.hasOwn(t,n)&&u(e[n],t[n]))}var d=class e{type;attrs;static none=Object.freeze([]);constructor(e,t){this.type=e,this.attrs=t}addToSet(e){let t,n=!1;for(let r=0;r<e.length;r++){let i=e[r];if(this.eq(i))return e;if(this.type.excludes(i.type))t??=e.slice(0,r);else{if(i.type.excludes(this.type))return e;!n&&i.type.rank>this.type.rank&&(t??=e.slice(0,r),t.push(this),n=!0),t?.push(i)}}return t??=e.slice(),n||t.push(this),t}removeFromSet(e){return this.isInSet(e)?e.filter(e=>!e.eq(this)):e}isInSet(e){return e.some(e=>e.eq(this))}eq(e){return this===e||this.type===e.type&&u(this.attrs,e.attrs)}toJSON(){let e={type:this.type.name},t=l(this.type.spec.attrs,this.attrs);return t&&(e.attrs=t),e}static sameSet(e,t){return e===t||e.length===t.length&&e.every((e,n)=>e.eq(t[n]))}static setFrom(t){return t?t instanceof e?[t]:t.length<2?t:[...t].sort((e,t)=>e.type.rank-t.type.rank):e.none}},f=class e{content;size;static empty=new e([],0);constructor(e,t){this.content=e,this.size=t}static fromArray(t){if(!t.length)return e.empty;let n=[],r=0;for(let e of t){r+=e.nodeSize;let t=n[n.length-1];t?.isText&&e.isText&&d.sameSet(t.marks,e.marks)?n[n.length-1]=t.withText(t.textContent+e.textContent):n.push(e)}return new e(n,r)}static from(t){return t?t instanceof e?t:e.fromArray(Array.isArray(t)?t:[t]):e.empty}get childCount(){return this.content.length}get firstChild(){return this.content[0]??null}get lastChild(){return this.content[this.content.length-1]??null}child(e){let t=this.content[e];if(!t)throw RangeError(`Index ${e} out of range for fragment of ${this.childCount}`);return t}maybeChild(e){return this.content[e]??null}forEach(e){for(let t=0,n=0;t<this.content.length;t++){let r=this.content[t];e(r,n,t),n+=r.nodeSize}}nodesBetween(e,t,n,r=0,i=null){for(let a=0,o=0;o<t&&a<this.content.length;a++){let s=this.content[a],c=o+s.nodeSize;if(c>e&&n(s,r+o,i,a)!==!1&&s.content.size){let i=o+1;s.content.nodesBetween(Math.max(0,e-i),Math.min(s.content.size,t-i),n,r+i,s)}o=c}}textBetween(e,t,n=``,r=``){let i=``,a=!0;return this.nodesBetween(e,t,(o,s)=>{o.isTextblock?(a||(i+=n),a=!1):o.isText?i+=o.textContent.slice(Math.max(e,s)-s,t-s):o.isLeaf&&(i+=typeof r==`string`?r:r(o))}),i}append(t){return t.size?this.size?e.fromArray([...this.content,...t.content]):t:this}cut(t,n=this.size){if(t<=0&&n>=this.size)return this;if(t>=n)return e.empty;let r=[],i=0;for(let e=0,a=0;a<n;e++){let o=this.content[e],s=a+o.nodeSize;s>t&&((a<t||s>n)&&(o=o.isText?o.cut(Math.max(0,t-a),Math.min(o.nodeSize,n-a)):o.cut(Math.max(0,t-a-1),Math.min(o.content.size,n-a-1))),r.push(o),i+=o.nodeSize),a=s}return new e(r,i)}cutByIndex(t,n){return t===n?e.empty:t===0&&n===this.content.length?this:e.fromArray(this.content.slice(t,n))}replaceChild(t,n){let r=this.child(t);if(r===n)return this;let i=this.content.slice();return i[t]=n,new e(i,this.size-r.nodeSize+n.nodeSize)}findIndex(e){if(e===0)return{index:0,offset:0};if(e===this.size)return{index:this.content.length,offset:e};if(e<0||e>this.size)throw RangeError(`Position ${e} outside fragment`);for(let t=0,n=0;;t++){let r=n+this.content[t].nodeSize;if(r>e)return{index:t,offset:n};n=r}}eq(e){return this===e||this.content.length===e.content.length&&this.content.every((t,n)=>t.eq(e.content[n]))}toJSON(){return this.content.map(e=>e.toJSON())}toString(){return`<${this.content.join(`, `)}>`}};function p(e,t,n){if(n.openStart>e.depth)throw new a(`Inserted content is deeper than the insertion position`);if(e.depth-n.openStart!==t.depth-n.openEnd)throw new a(`Inconsistent open depths`);return m(e,t,n,0)}function m(e,t,n,r){let i=e.index(r),a=e.node(r);if(i===t.index(r)&&r<e.depth-n.openStart){let o=m(e,t,n,r+1);return a.copy(a.content.replaceChild(i,o))}if(!n.content.size)return x(a,_(e,t,r));if(!n.openStart&&!n.openEnd&&e.depth===r&&t.depth===r){let r=a.content;return x(a,r.cut(0,e.parentOffset).append(n.content).append(r.cut(t.parentOffset)))}let{start:o,end:s}=h(n,e);return x(a,g(e,o,s,t,r))}function h(e,t){let n=t.depth-e.openStart,r=t.node(n).copy(e.content);for(let e=n-1;e>=0;e--)r=t.node(e).copy(f.from(r));return{start:r.resolve(e.openStart+n),end:r.resolve(r.content.size-e.openEnd-n)}}function g(e,t,n,r,i){let a=e.depth>i?y(e,t,i+1):null,o=r.depth>i?y(n,r,i+1):null,s=[];return v(null,e,i,s),a&&o&&t.index(i)===n.index(i)?(b(a,o),s.push(x(a,g(e,t,n,r,i+1)))):(a&&s.push(x(a,_(e,t,i+1))),v(t,n,i,s),o&&s.push(x(o,_(n,r,i+1)))),v(r,null,i,s),f.fromArray(s)}function _(e,t,n){let r=[];if(v(null,e,n,r),e.depth>n){let i=y(e,t,n+1);r.push(x(i,_(e,t,n+1)))}return v(t,null,n,r),f.fromArray(r)}function v(e,t,n,r){let i=(t??e).node(n),a=0,o=t?t.index(n):i.childCount;e&&(a=e.index(n),e.depth>n?a++:e.textOffset&&(r.push(e.nodeAfter),a++));for(let e=a;e<o;e++)r.push(i.child(e));t&&t.depth===n&&t.textOffset&&r.push(t.nodeBefore)}function y(e,t,n){let r=e.node(n);return b(r,t.node(n)),r}function b(e,t){if(!t.type.compatibleContent(e.type))throw new a(`Cannot join ${t.type.name} onto ${e.type.name}`)}function x(e,t){if(!e.type.validContent(t))throw new a(`Invalid content for node ${e.type.name}`);return e.copy(t)}var S=class e{pos;nodes;indices;starts;parentOffset;textOffset;constructor(e,t,n,r,i,a){this.pos=e,this.nodes=t,this.indices=n,this.starts=r,this.parentOffset=i,this.textOffset=a}static resolve(t,n){if(!(n>=0&&n<=t.content.size)||!Number.isInteger(n))throw RangeError(`Position ${n} out of range 0..${t.content.size}`);let r=[],i=[],a=[],o=t,s=0,c=n;for(;;){let{index:t,offset:l}=o.content.findIndex(c);r.push(o),i.push(t),a.push(s);let u=c-l,d=o.content.maybeChild(t);if(u===0||!d)return new e(n,r,i,a,c,0);if(d.isText)return new e(n,r,i,a,c,u);o=d,s+=l+1,c=u-1}}get depth(){return this.nodes.length-1}get parent(){return this.node(this.depth)}get doc(){return this.node(0)}node(e=this.depth){return this.nodes[this.at(e)]}index(e=this.depth){return this.indices[this.at(e)]}indexAfter(e=this.depth){let t=this.at(e);return this.index(t)+(t===this.depth&&!this.textOffset?0:1)}start(e=this.depth){return this.starts[this.at(e)]}end(e=this.depth){let t=this.at(e);return this.start(t)+this.node(t).content.size}before(e=this.depth){if(e===this.depth+1)return this.pos;let t=this.at(e);if(!t)throw RangeError(`There is no position before the root node`);return this.start(t)-1}after(e=this.depth){if(e===this.depth+1)return this.pos;let t=this.at(e);if(!t)throw RangeError(`There is no position after the root node`);return this.end(t)+1}get nodeAfter(){let e=this.parent.maybeChild(this.index());return e?this.textOffset?e.cut(this.textOffset):e:null}get nodeBefore(){let e=this.index();return this.textOffset?this.parent.child(e).cut(0,this.textOffset):this.parent.maybeChild(e-1)}posAtIndex(e,t=this.depth){let n=this.node(t),r=this.start(t);for(let t=0;t<e;t++)r+=n.child(t).nodeSize;return r}sharedDepth(e){for(let t=this.depth;t>0;t--)if(this.start(t)<=e&&this.end(t)>=e)return t;return 0}blockRange(e=this,t){if(e.pos<this.pos)return e.blockRange(this,t);let n=this.depth-(this.parent.inlineContent||this.pos===e.pos?1:0);for(let r=n;r>=0;r--)if(e.pos<=this.end(r)&&(!t||t(this.node(r))))return new C(this,e,r);return null}sameParent(e){return this.pos-this.parentOffset===e.pos-e.parentOffset}toString(){return`${this.nodes.slice(1).map((e,t)=>`${e.type.name}_${this.indices[t]}`).join(`/`)}:${this.parentOffset}`}at(e){let t=e<0?this.depth+e:e;if(t<0||t>this.depth)throw RangeError(`Depth ${e} out of range`);return t}},C=class{$from;$to;depth;constructor(e,t,n){this.$from=e,this.$to=t,this.depth=n}get start(){return this.$from.before(this.depth+1)}get end(){return this.$to.after(this.depth+1)}get parent(){return this.$from.node(this.depth)}get startIndex(){return this.$from.index(this.depth)}get endIndex(){return this.$to.indexAfter(this.depth)}},w=class e{content;openStart;openEnd;static empty=new e(f.empty,0,0);constructor(e,t,n){this.content=e,this.openStart=t,this.openEnd=n}get size(){return this.content.size-this.openStart-this.openEnd}insertAt(t,n){let r=ee(this.content,t+this.openStart,n,{parent:null,level:0,onStart:!0,onEnd:!0,openStart:this.openStart,openEnd:this.openEnd});return r&&new e(r,this.openStart,this.openEnd)}removeBetween(t,n){return new e(te(this.content,t+this.openStart,n+this.openStart),this.openStart,this.openEnd)}eq(e){return this.content.eq(e.content)&&this.openStart===e.openStart&&this.openEnd===e.openEnd}toJSON(){return{content:this.content.toJSON(),openStart:this.openStart,openEnd:this.openEnd}}};function ee(e,t,n,r){let{index:i,offset:a}=e.findIndex(t),o=e.maybeChild(i);if(a===t||!o||o.isText){let i=e.cut(0,t).append(n).append(e.cut(t)),{parent:a,level:o}=r,s=r.onStart&&o<=r.openStart||r.onEnd&&o<=r.openEnd;return a&&!s&&!a.type.validContent(i)?null:i}let s=ee(o.content,t-a-1,n,{...r,parent:o,level:r.level+1,onStart:r.onStart&&i===0,onEnd:r.onEnd&&i===e.childCount-1});return s&&e.replaceChild(i,o.copy(s))}function te(e,t,n){let{index:r,offset:i}=e.findIndex(t),a=e.maybeChild(r),{index:o,offset:s}=e.findIndex(n);if(i===t||!a||a.isText){if(s!==n&&!e.child(o).isText)throw RangeError(`Removing a non-flat range`);return e.cut(0,t).append(e.cut(n))}if(r!==o)throw RangeError(`Removing a non-flat range`);return e.replaceChild(r,a.copy(te(a.content,t-i-1,n-i-1)))}var T=class e{type;attrs;content;marks;constructor(e,t,n,r){this.type=e,this.attrs=t,this.content=n,this.marks=r}get nodeSize(){return this.type.isLeaf?1:2+this.content.size}get childCount(){return this.content.childCount}get firstChild(){return this.content.firstChild}get lastChild(){return this.content.lastChild}get isText(){return this.type.isText}get isInline(){return this.type.isInline}get isBlock(){return this.type.isBlock}get isTextblock(){return this.type.isTextblock}get isLeaf(){return this.type.isLeaf}get isAtom(){return this.type.isAtom}get inlineContent(){return this.type.inlineContent}get textContent(){return this.content.textBetween(0,this.content.size)}child(e){return this.content.child(e)}maybeChild(e){return this.content.maybeChild(e)}forEach(e){this.content.forEach(e)}nodesBetween(e,t,n){this.content.nodesBetween(e,t,n,0,this)}descendants(e){this.nodesBetween(0,this.content.size,e)}textBetween(e,t,n,r){return this.content.textBetween(e,t,n,r)}sameMarkup(e){return this.type===e.type&&u(this.attrs,e.attrs)&&d.sameSet(this.marks,e.marks)}eq(e){return this===e||this.sameMarkup(e)&&this.content.eq(e.content)}copy(t=f.empty){return t===this.content?this:new e(this.type,this.attrs,t,this.marks)}contentMatchAt(e){let t=this.type.contentMatch.matchFragment(this.content,0,e);if(!t)throw RangeError(`Invalid content in ${this.type.name}`);return t}canReplace(e,t,n=f.empty,r=0,i=n.childCount){if(!this.contentMatchAt(e).matchFragment(n,r,i)?.matchFragment(this.content,t)?.validEnd)return!1;for(let e=r;e<i;e++)if(!this.type.allowsMarks(n.child(e).marks))return!1;return!0}canReplaceWith(e,t,n){return!!this.contentMatchAt(e).matchType(n)?.matchFragment(this.content,t)?.validEnd}mark(t){return d.sameSet(t,this.marks)?this:new e(this.type,this.attrs,this.content,t)}cut(e,t=this.content.size){return e===0&&t===this.content.size?this:this.copy(this.content.cut(e,t))}slice(e,t=this.content.size){if(e>t)throw RangeError(`Invalid range ${e}..${t}`);if(e===t)return w.empty;let n=this.resolve(e),r=this.resolve(t),i=n.sharedDepth(t),a=n.start(i);return new w(n.node(i).content.cut(n.pos-a,r.pos-a),n.depth-i,r.depth-i)}replace(e,t,n){if(e>t)throw RangeError(`Invalid range ${e}..${t}`);return p(this.resolve(e),this.resolve(t),n)}nodeAt(e){let t=this;for(;;){let{index:n,offset:r}=t.content.findIndex(e),i=t.content.maybeChild(n);if(!i)return null;if(r===e||i.isText)return i;t=i,e-=r+1}}resolve(e){return S.resolve(this,e)}check(){if(!this.type.validContent(this.content))throw new i(`Invalid content for node ${this.type.name}: ${this.content}`);this.content.forEach(e=>{e.check()})}toJSON(){let e={type:this.type.name},t=l(this.type.spec.attrs,this.attrs);return t&&(e.attrs=t),this.content.size&&(e.content=this.content.toJSON()),this.marks.length&&(e.marks=this.marks.map(e=>e.toJSON())),e}toString(){return this.content.size?`${this.type.name}(${this.content.content.join(`, `)})`:this.type.name}},E=class e extends T{text;constructor(e,t,n){if(super(e,s,f.empty,n),this.text=t,!t)throw RangeError(`Empty text nodes are not allowed`)}get nodeSize(){return this.text.length}get textContent(){return this.text}eq(e){return this===e||this.sameMarkup(e)&&this.text===e.text}mark(t){return d.sameSet(t,this.marks)?this:new e(this.type,this.text,t)}cut(e=0,t=this.text.length){return e===0&&t===this.text.length?this:this.withText(this.text.slice(e,t))}withText(t){return t===this.text?this:new e(this.type,t,this.marks)}toJSON(){let e={type:this.type.name,text:this.text};return this.marks.length&&(e.marks=this.marks.map(e=>e.toJSON())),e}toString(){let e=JSON.stringify(this.text);return this.marks.length?`${this.marks.map(e=>e.type.name).join(`+`)}${e}`:e}},D=[`type`,`attrs`,`content`,`text`,`marks`],O=[`type`,`attrs`],k=[`content`,`openStart`,`openEnd`],ne=class{name;schema;spec;groups;isText;isInline;isBlock;isLeaf;contentMatch;markSet;constructor(e,t,n){this.name=e,this.schema=t,this.spec=n,this.groups=n.group?n.group.split(` `):[],this.isText=e===`text`,this.isInline=this.isText||!!n.inline,this.isBlock=!this.isInline,this.isLeaf=!n.content}get inlineContent(){return this.contentMatch.inlineContent}get isTextblock(){return this.isBlock&&this.inlineContent}get isAtom(){return this.isLeaf||!!this.spec.atom}hasRequiredAttrs(){return Object.values(this.spec.attrs??{}).some(e=>!(`default`in e))}create(e,t,n){if(this.isText)throw RangeError(`Use Schema.text to create text nodes`);let r=f.from(t);return this.validContent(r)||o(this.name,`invalid content ${r}`),new T(this,c(this.spec.attrs,e??void 0,`${this.name}.attrs`),r,d.setFrom(n))}createOpen(e,t){if(this.isText)throw RangeError(`Use Schema.text to create text nodes`);return new T(this,c(this.spec.attrs,e??void 0,`${this.name}.attrs`),f.from(t),d.none)}validContent(e){return this.contentMatch.matchFragment(e)?.validEnd?e.content.every(e=>this.allowsMarks(e.marks)):!1}allowsMarkType(e){return this.markSet===null||this.markSet.includes(e)}allowsMarks(e){return this.markSet===null||e.every(e=>this.allowsMarkType(e.type))}compatibleContent(e){return this===e||!this.isLeaf&&!e.isLeaf&&this.inlineContent===e.inlineContent}checkContent(e,t){let n=this.contentMatch;e.forEach((e,r)=>{let i=n.matchType(e.type);i||o(`${t}.content[${r}]`,`${e.type.name} is not allowed here in ${this.name}`),this.allowsMarks(e.marks)||o(`${t}.content[${r}].marks`,`marks not allowed in ${this.name}`),n=i}),n.validEnd||o(`${t}.content`,`${this.name} content is incomplete (expected "${n}")`)}},re=class{name;schema;spec;rank;excluded;groups;instance;constructor(e,t,n,r){this.name=e,this.schema=t,this.spec=n,this.rank=r,this.groups=n.group?n.group.split(` `):[],this.instance=n.attrs?null:new d(this,s)}create(e){return this.instance&&!(e&&Object.keys(e).length)?this.instance:new d(this,c(this.spec.attrs,e??void 0,`${this.name}.attrs`))}get inclusive(){return this.spec.inclusive??!0}excludes(e){return this.excluded.includes(e)}isInSet(e){return e.find(e=>e.type===this)}removeFromSet(e){return this.isInSet(e)?e.filter(e=>e.type!==this):e}},ie=class{spec;nodes;marks;topNodeType;constructor(e){this.spec=e;let t=Object.create(null),r=Object.create(null);for(let[n,r]of Object.entries(e.nodes))t[n]=new ne(n,this,r);Object.entries(e.marks??{}).forEach(([e,t],n)=>{r[e]=new re(e,this,t,n)}),this.nodes=t,this.marks=r;let i=t.text;if(!i||i.spec.attrs||i.spec.content)throw Error("A schema needs a `text` node type without attrs or content");let a=t[e.topNode??`doc`];if(!a)throw Error(`Schema has no top node type "${e.topNode??`doc`}"`);this.topNodeType=a;let o=Object.values(t),s=Object.values(r);for(let e of o){e.contentMatch=n.compile(e.spec.content??``,o);let t=e.spec.marks??(e.inlineContent?`_`:``);e.markSet=t===`_`?null:A(s,t)}for(let e of s){let t=e.spec.excludes??e.name;e.excluded=t===`_`?s:A(s,t)}}nodeType(e){return this.nodes[e]}markType(e){return this.marks[e]}node(e,t,n,r){return this.resolveNodeType(e).create(t,n,r)}text(e,t){return new E(this.resolveNodeType(`text`),e,d.setFrom(t))}mark(e,t){if(typeof e!=`string`)return e.create(t);let n=this.marks[e];if(!n)throw RangeError(`Unknown mark type "${e}"`);return n.create(t)}nodeFromJSON(e,t=`$`){return this.parseNode(e,t,0,0)}markFromJSON(e,t=`$`){let n=j(e,t,O),r=typeof n.type==`string`?this.marks[n.type]:void 0;if(!r)return o(`${t}.type`,`unknown mark type ${JSON.stringify(n.type)}`);if(!r.spec.attrs)return n.attrs!==void 0&&o(`${t}.attrs`,`${r.name} has no attributes`),r.create();let i=n.attrs===void 0?void 0:j(n.attrs,`${t}.attrs`);return new d(r,c(r.spec.attrs,i,`${t}.attrs`))}sliceFromJSON(e,t=`$`){let n=j(e,t,k),r=ae(n.content,`${t}.content`),{openStart:i,openEnd:a}=n;oe(i)||o(`${t}.openStart`,`expected a non-negative integer`),oe(a)||o(`${t}.openEnd`,`expected a non-negative integer`),!r.length&&(i||a)&&o(t,`an empty slice cannot be open`);let s=r.map((e,n)=>this.parseNode(e,`${t}.content[${n}]`,n===0?i:0,n===r.length-1?a:0));return new w(f.fromArray(s),i,a)}parseNode(e,t,n,r,i=0){i>300&&o(t,`nodes nested deeper than 300 levels`);let a=j(e,t,D),s=typeof a.type==`string`?this.nodes[a.type]:void 0;if(!s)return o(`${t}.type`,`unknown node type ${JSON.stringify(a.type)}`);let l=a.marks===void 0?d.none:this.marksFromJSON(a.marks,`${t}.marks`);if((n||r)&&s.isLeaf&&o(t,`a leaf node cannot be open`),s.isText)return a.attrs!==void 0&&o(`${t}.attrs`,`text nodes have no attributes`),a.content!==void 0&&o(`${t}.content`,`text nodes have no content`),typeof a.text==`string`&&a.text||o(`${t}.text`,`text must be a non-empty string`),new E(s,a.text,l);a.text!==void 0&&o(`${t}.text`,`only text nodes have text`),a.attrs!==void 0&&!s.spec.attrs&&o(`${t}.attrs`,`${s.name} has no attributes`);let u=c(s.spec.attrs,a.attrs===void 0?void 0:j(a.attrs,`${t}.attrs`),`${t}.attrs`),p=[];if(a.content!==void 0){s.isLeaf&&o(`${t}.content`,`${s.name} cannot have content`);let e=ae(a.content,`${t}.content`);p=e.map((a,o)=>this.parseNode(a,`${t}.content[${o}]`,o===0?Math.max(n-1,0):0,o===e.length-1?Math.max(r-1,0):0,i+1))}return n||r?!p.length&&(n>1||r>1)&&o(`${t}.content`,`open depth exceeds the content`):s.checkContent(p,t),new T(s,u,f.fromArray(p),l)}marksFromJSON(e,t){let n=d.none;return ae(e,t).forEach((e,r)=>{let i=this.markFromJSON(e,`${t}[${r}]`),a=n.find(e=>e.type.excludes(i.type)||i.type.excludes(e.type));a&&o(`${t}[${r}]`,a.type===i.type?`duplicate mark`:`${i.type.name} cannot be combined with ${a.type.name}`),n=i.addToSet(n)}),n}resolveNodeType(e){if(typeof e!=`string`)return e;let t=this.nodes[e];if(!t)throw RangeError(`Unknown node type "${e}"`);return t}};function A(e,t){let n=[];for(let r of t.split(` `).filter(Boolean)){let t=e.filter(e=>e.name===r||e.groups.includes(r));if(!t.length)throw Error(`Unknown mark type or group "${r}"`);for(let e of t)n.includes(e)||n.push(e)}return n}function j(e,t,n){if((typeof e!=`object`||!e||Array.isArray(e))&&o(t,`expected an object`),n)for(let r of Object.keys(e))n.includes(r)||o(`${t}.${r}`,`unknown key`);return e}function ae(e,t){return Array.isArray(e)||o(t,`expected an array`),e}function oe(e){return typeof e==`number`&&Number.isInteger(e)&&e>=0}var M=[1,2,3,4,5,6],se=[`start`,`center`,`end`,`justify`],ce=[`http:`,`https:`,`mailto:`,`tel:`];function le(e){if(typeof e!=`string`||!e||e.length>8192||/[\u0000- \u007f-\u009f\\]/.test(e))return!1;let t=/^([a-zA-Z][a-zA-Z0-9+.-]*):/.exec(e);return!t||ce.includes(`${t[1]?.toLowerCase()}:`)}function ue(e){return e?.href===null||e?.href===void 0?typeof e?.anchor==`string`:le(e.href)}function N(e){return typeof e==`string`&&/^#[0-9a-f]{6}$/.test(e)}var de={default:`start`,validate:e=>se.includes(e)?void 0:`align must be one of ${se.join(`, `)}`},fe={validate:e=>N(e)?void 0:`color must be a lowercase #rrggbb value`},pe=new ie({nodes:{doc:{content:`block+`},paragraph:{group:`block`,content:`inline*`,attrs:{align:de}},heading:{group:`block`,content:`inline*`,attrs:{level:{validate:e=>M.includes(e)?void 0:`heading level must be an integer from 1 to 6`},align:de}},bulletList:{group:`block`,content:`listItem+`},orderedList:{group:`block`,content:`listItem+`,attrs:{start:{default:1,validate:e=>Number.isInteger(e)&&e>=0&&e<=99999?void 0:`start must be an integer from 0 to 99999`}}},listItem:{content:`paragraph block*`},horizontalRule:{group:`block`},text:{group:`inline`},hardBreak:{group:`inline`,inline:!0,selectable:!1},pageBreak:{group:`inline`,inline:!0,selectable:!1}},marks:{link:{attrs:{href:{validate:e=>le(e)?void 0:`href must be a relative URL or use http, https, mailto or tel`}},inclusive:!1},bold:{},italic:{},underline:{},strike:{},textColor:{attrs:{color:fe}},highlight:{attrs:{color:fe}}}}),me=2,he={1:e=>({...e,schemaVersion:2})},ge={pageSize:{A4:{width:210,height:297},Letter:{width:215.9,height:279.4}}.A4,margins:{top:25.4,right:25.4,bottom:25.4,left:25.4}};function _e(e){if(!be(e))throw new i(`Document must be an object`);let t=e.schemaVersion;if(!Number.isInteger(t)||t<1)throw new i(`Unsupported schemaVersion: ${String(t)}`);if(t>me)throw new i(`Unsupported schemaVersion: ${t} (this version of @folijs/core reads 1 to ${me}; the document was saved by a newer one)`);let n=e;for(let e=t;e<me;e++){let t=he[e];if(!t)throw new i(`No migration from schemaVersion ${e}`);n=t(n)}return{schemaVersion:me,settings:ye(n.settings),content:ve(n.content).toJSON()}}function ve(e,t=`content`){let n=pe.nodeFromJSON(e,t);if(n.type!==pe.topNodeType)throw new i(`${t}: root node must be of type "doc"`);if(n.marks.length)throw new i(`${t}.marks: doc cannot have marks`);return n}function ye(e){if(!be(e)||!be(e.pageSize)||!be(e.margins))throw new i(`settings.pageSize and settings.margins are required`);let{width:t,height:n}=e.pageSize,{top:r,right:a,bottom:o,left:s}=e.margins;if(!xe(t)||!xe(n))throw new i(`pageSize width/height must be positive numbers (mm)`);if(![r,a,o,s].every(Se))throw new i(`margins must be non-negative numbers (mm)`);let c={top:r,right:a,bottom:o,left:s};if(c.left+c.right>=t||c.top+c.bottom>=n)throw new i(`margins leave no content area on the page`);return{pageSize:{width:t,height:n},margins:c}}function be(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function xe(e){return typeof e==`number`&&Number.isFinite(e)&&e>0}function Se(e){return typeof e==`number`&&Number.isFinite(e)&&e>=0}var Ce=65536,we=(e,t)=>e+t*Ce,Te=e=>e%Ce,Ee=e=>(e-Te(e))/Ce,De=class e{ranges;inverted;static empty=new e([]);constructor(e,t=!1){this.ranges=e,this.inverted=t}mapResult(e,t=1,n){let r=0,i=this.inverted?2:1,a=this.inverted?1:2;for(let o=0;o<this.ranges.length;o+=3){let s=this.ranges[o]-(this.inverted?r:0);if(s>e)break;let c=this.ranges[o+i],l=this.ranges[o+a],u=s+c;if(e<=u){let i=c?e===s?-1:e===u?1:t:n?.[o/3]||t,a=e!==(t<0?s:u);return{pos:s+r+(i<0?0:l),deleted:e>s&&e<u,recover:a?we(o/3,e-s):null}}r+=l-c}return{pos:e+r,deleted:!1,recover:null}}map(e,t=1){return this.mapResult(e,t).pos}recover(e){let t=0,n=Te(e);if(!this.inverted)for(let e=0;e<n;e++)t+=this.ranges[e*3+2]-this.ranges[e*3+1];return this.ranges[n*3]+t+Ee(e)}forEach(e){let t=this.inverted?2:1,n=this.inverted?1:2;for(let r=0,i=0;r<this.ranges.length;r+=3){let a=this.ranges[r],o=a-(this.inverted?i:0),s=a+(this.inverted?0:i),c=this.ranges[r+t],l=this.ranges[r+n];e(o,o+c,s,s+l),i+=l-c}}sides(e){let t=[];return this.forEach((n,r)=>{t.push(e<=n?-1:+(e>=r))}),t}invert(){return new e(this.ranges,!this.inverted)}},Oe=class e{maps;mirror;from;to;constructor(e=[],t=new Map,n=0,r=e.length){this.maps=e,this.mirror=t,this.from=n,this.to=r}slice(t=0,n=this.maps.length){return new e(this.maps,this.mirror,t,n)}appendMap(e,t){this.to=this.maps.push(e),t!==void 0&&(this.mirror.set(this.maps.length-1,t),this.mirror.set(t,this.maps.length-1))}appendMapping(e){let t=this.maps.length;for(let n=e.from;n<e.to;n++){let r=e.getMirror(n);this.appendMap(e.maps[n],r!==void 0&&r<n&&r>=e.from?t+r-e.from:void 0)}}getMirror(e){return this.mirror.get(e)}map(e,t=1){return this.mapResult(e,t).pos}mapResult(e,t=1){let n=!1;for(let r=this.from;r<this.to;r++){let i=this.maps[r].mapResult(e,t);if(i.recover!==null){let t=this.getMirror(r);if(t!==void 0&&t>r&&t<this.to){r=t,e=this.maps[t].recover(i.recover);continue}}n||=i.deleted,e=i.pos}return{pos:e,deleted:n,recover:null}}},P=class e{doc;failed;constructor(e,t){this.doc=e,this.failed=t}static ok(t){return new e(t,null)}static fail(t){return new e(null,t)}static fromReplace(t,n,r,i){try{return e.ok(t.replace(n,r,i))}catch(t){if(t instanceof a||t instanceof RangeError)return e.fail(t.message);throw t}}},ke=class{getMap(){return De.empty}},Ae=class e extends ke{from;to;slice;structure;constructor(e,t,n,r=!1){super(),this.from=e,this.to=t,this.slice=n,this.structure=r}apply(e){return this.structure&&Me(e,this.from,this.to)?P.fail(`Structure replace would overwrite content`):P.fromReplace(e,this.from,this.to,this.slice)}getMap(){return new De([this.from,this.to-this.from,this.slice.size])}invert(t){return new e(this.from,this.from+this.slice.size,t.slice(this.from,this.to))}map(t){let n=t.mapResult(this.from,1),r=t.mapResult(this.to,-1);return n.deleted&&r.deleted?null:new e(n.pos,Math.max(n.pos,r.pos),this.slice,this.structure)}merge(t){if(!(t instanceof e)||t.structure||this.structure)return null;let n=(e,t)=>e.size+t.size===0?w.empty:new w(e.content.append(t.content),e.openStart,t.openEnd);return this.from+this.slice.size===t.from&&!this.slice.openEnd&&!t.slice.openStart?new e(this.from,this.to+(t.to-t.from),n(this.slice,t.slice)):t.to===this.from&&!this.slice.openStart&&!t.slice.openEnd?new e(t.from,this.to,n(t.slice,this.slice)):null}},je=class e extends ke{from;to;gapFrom;gapTo;slice;insert;structure;constructor(e,t,n,r,i,a,o=!1){super(),this.from=e,this.to=t,this.gapFrom=n,this.gapTo=r,this.slice=i,this.insert=a,this.structure=o}apply(e){if(this.from<0||this.from>this.gapFrom||this.gapFrom>this.gapTo||this.gapTo>this.to||this.to>e.content.size)return P.fail(`Invalid gap range ${this.from}..${this.to}`);if(this.structure&&(Me(e,this.from,this.gapFrom)||Me(e,this.gapTo,this.to)))return P.fail(`Structure gap-replace would overwrite content`);let t=e.slice(this.gapFrom,this.gapTo);if(t.openStart||t.openEnd)return P.fail(`Gap is not a flat range`);let n;try{n=this.slice.insertAt(this.insert,t.content)}catch(e){if(e instanceof RangeError)return P.fail(e.message);throw e}return n?P.fromReplace(e,this.from,this.to,n):P.fail(`Content does not fit in gap`)}getMap(){return new De([this.from,this.gapFrom-this.from,this.insert,this.gapTo,this.to-this.gapTo,this.slice.size-this.insert])}invert(t){let n=this.gapTo-this.gapFrom;return new e(this.from,this.from+this.slice.size+n,this.from+this.insert,this.from+this.insert+n,t.slice(this.from,this.to).removeBetween(this.gapFrom-this.from,this.gapTo-this.from),this.gapFrom-this.from,this.structure)}map(t){let n=t.mapResult(this.from,1),r=t.mapResult(this.to,-1),i=this.from===this.gapFrom?n.pos:t.map(this.gapFrom,-1),a=this.to===this.gapTo?r.pos:t.map(this.gapTo,1);return n.deleted&&r.deleted||i<n.pos||a>r.pos||this.gapTo>this.gapFrom&&a<=i?null:new e(n.pos,r.pos,i,a,this.slice,this.insert,this.structure)}};function Me(e,t,n){let r=e.resolve(t),i=n-t,a=r.depth;for(;i>0&&a>0&&r.indexAfter(a)===r.node(a).childCount;)a--,i--;if(i>0){let e=r.node(a).maybeChild(r.indexAfter(a));for(;i>0;){if(!e||e.isLeaf)return!0;e=e.firstChild,i--}}return!1}function Ne(e,t,n){let r=[];return e.forEach(e=>{let i=e.content.size?e.copy(Ne(e.content,t,e)):e;i.isInline&&(i=t(i,n)),r.push(i)}),f.fromArray(r)}var Pe=class extends ke{from;to;mark;constructor(e,t,n){super(),this.from=e,this.to=t,this.mark=n}apply(e){if(this.from>=this.to||this.from<0||this.to>e.content.size)return P.fail(`Invalid mark range ${this.from}..${this.to}`);let t=e.slice(this.from,this.to),n=e.resolve(this.from),r=n.node(n.sharedDepth(this.to)),i=Ne(t.content,(e,t)=>t.type.allowsMarkType(this.mark.type)?e.mark(this.change(e.marks)):e,r);return P.fromReplace(e,this.from,this.to,new w(i,t.openStart,t.openEnd))}map(e){let t=e.mapResult(this.from,1),n=e.mapResult(this.to,-1);return t.deleted&&n.deleted||t.pos>=n.pos?null:this.create(t.pos,n.pos)}},Fe=class e extends Pe{change(e){return this.mark.addToSet(e)}create(t,n){return new e(t,n,this.mark)}invert(){return new Ie(this.from,this.to,this.mark)}},Ie=class e extends Pe{change(e){return this.mark.removeFromSet(e)}create(t,n){return new e(t,n,this.mark)}invert(){return new Fe(this.from,this.to,this.mark)}},Le=class e extends ke{pos;type;attrs;marks;constructor(e,t,n,r){super(),this.pos=e,this.type=t,this.attrs=n,this.marks=r}apply(e){let t=this.pos>=0&&this.pos<e.content.size?e.nodeAt(this.pos):null;if(!t||t.isText)return P.fail(`No node at position ${this.pos}`);let n;try{n=this.type.create(this.attrs,t.content,this.marks??t.marks)}catch(e){if(e instanceof i)return P.fail(e.message);throw e}return P.fromReplace(e,this.pos,this.pos+t.nodeSize,new w(f.from(n),0,0))}invert(t){let n=t.nodeAt(this.pos);if(!n)throw RangeError(`No node at position ${this.pos}`);return new e(this.pos,n.type,n.attrs,n.marks)}map(t){let n=t.mapResult(this.pos,1),r=t.mapResult(this.pos+1,-1);return n.deleted||r.deleted||r.pos<=n.pos?null:new e(n.pos,this.type,this.attrs,this.marks)}};function Re(e,t,n){let r=[],i=0;if(e.forEach((e,a)=>{let o=t+a,s=i;for(;i<n.length&&n[i].pos<o+e.nodeSize;)i++;if(s===i){r.push(e);return}let c=n[s].pos===o?n[s]:void 0,l=n.slice(c?s+1:s,i),u=l.length?Re(e,o+1,l):e;if(c){if(u.isText)throw RangeError(`No node at position ${o}`);if(u=c.type.create(c.attrs,u.content,c.marks??u.marks),u.nodeSize!==e.nodeSize)throw RangeError(`Node markup must keep the node size`)}r.push(u)}),i<n.length)throw RangeError(`No node at position ${n[i]?.pos}`);let a=f.fromArray(r);if(!e.type.validContent(a))throw RangeError(`Invalid content for node ${e.type.name}`);return e.copy(a)}var ze=class e extends ke{steps;constructor(e){super(),this.steps=e}apply(e){for(let e=0;e<this.steps.length;e++){let t=this.steps[e].pos;if(t<0||e>0&&t<=this.steps[e-1].pos)return P.fail(`Unsorted or invalid node markup position ${t}`)}try{return P.ok(Re(e,0,this.steps))}catch(e){if(e instanceof i||e instanceof RangeError)return P.fail(e.message);throw e}}invert(t){let n=[],r=this.steps[this.steps.length-1];if(r&&t.nodesBetween(this.steps[0].pos,r.pos+1,(e,t)=>{this.steps[n.length]?.pos===t&&n.push(new Le(t,e.type,e.attrs,e.marks));let r=this.steps[n.length];return r!==void 0&&r.pos<t+e.nodeSize}),n.length!==this.steps.length)throw RangeError(`Node markup batch does not fit`);return new e(n)}map(t){let n=this.steps.map(e=>e.map(t)).filter(e=>e!==null);return n.length?new e(n):null}};function Be(e,t,n){let r={},a=e.type.spec.attrs??{};for(let i of Object.keys(t.spec.attrs??{}))n&&Object.hasOwn(n,i)?r[i]=n[i]:Object.hasOwn(a,i)&&(r[i]=e.attrs[i]);for(let e of Object.keys(n??{}))Object.hasOwn(r,e)||(r[e]=n?.[e]);try{return t.createOpen(r).attrs}catch(e){throw e instanceof i?new F(e.message):e}}var F=class extends Error{name=`TransformError`},Ve=class{current;steps=[];docs=[];mapping=new Oe;constructor(e){this.current=e}get doc(){return this.current}get before(){return this.docs[0]??this.doc}get docChanged(){return this.steps.length>0}step(e){let t=this.maybeStep(e);if(t.failed!==null)throw new F(t.failed);return this}maybeStep(e){let t=e.apply(this.doc);return t.doc&&this.addStep(e,t.doc),t}addStep(e,t){this.docs.push(this.doc),this.steps.push(e),this.mapping.appendMap(e.getMap()),this.current=t}replace(e,t=e,n=w.empty){return e===t&&!n.size?this:this.step(new Ae(e,t,n))}delete(e,t){return this.replace(e,t)}insert(e,t){return this.replace(e,e,new w(f.from(t),0,0))}insertText(e,t,n=t,r){if(!e)return this.delete(t,n);let i=this.doc.type.schema.text(e,r);return this.replace(t,n,new w(f.from(i),0,0))}addMark(e,t,n){let r=[],i=[];this.doc.nodesBetween(e,t,(a,o,s)=>{if(!a.isInline||!s||!s.type.allowsMarkType(n.type))return;let c=n.addToSet(a.marks);if(c===a.marks)return;let l=Math.max(o,e),u=Math.min(o+a.nodeSize,t);for(let e of a.marks){if(e.isInSet(c))continue;let t=r[r.length-1];t&&t.to===l&&t.mark.eq(e)?t.to=u:r.push({from:l,to:u,mark:e})}let d=i[i.length-1];d&&d.to===l?d.to=u:i.push({from:l,to:u})});for(let e of r)this.step(new Ie(e.from,e.to,e.mark));for(let e of i)this.step(new Fe(e.from,e.to,n));return this}removeMark(e,t,n){let r=[],i=0;this.doc.nodesBetween(e,t,(a,o)=>{if(!a.isInline)return;i++;let s=n instanceof re?a.marks.filter(e=>e.type===n):n.isInSet(a.marks)?[n]:[],c=Math.min(o+a.nodeSize,t);for(let t of s){let n=r.find(e=>e.index===i-1&&e.mark.eq(t));n?(n.to=c,n.index=i):r.push({from:Math.max(o,e),to:c,mark:t,index:i})}});for(let e of r)this.step(new Ie(e.from,e.to,e.mark));return this}split(e,t=1,n){let r=this.doc.resolve(e);if(t<1||t>r.depth)throw new F(`Cannot split ${t} levels at ${e}`);let a=f.empty,o=f.empty;for(let e=r.depth,s=t-1;e>r.depth-t;e--,s--){a=f.from(r.node(e).copy(a));let t=n?.[s],c;try{c=t?t.type.createOpen(t.attrs,o):r.node(e).copy(o)}catch(e){throw e instanceof i?new F(e.message):e}o=f.from(c)}return this.step(new Ae(e,e,new w(a.append(o),t,t),!0))}join(e,t=1){let n=e>0&&e<this.doc.content.size?this.doc.resolve(e):null,r=n?.nodeBefore,i=n?.nodeAfter;if(!r||!i||r.isLeaf||i.isLeaf||n?.textOffset)throw new F(`Position ${e} is not between two joinable nodes`);return this.step(new Ae(e-t,e+t,w.empty,!0))}wrap(e,t){let n=f.empty;for(let e=t.length-1;e>=0;e--){let r=t[e];if(n.size&&!r.type.contentMatch.matchFragment(n)?.validEnd)throw new F(`${r.type.name} cannot hold the next wrapper`);n=f.from(r.type.createOpen(r.attrs,n))}let{start:r,end:i}=e;return this.step(new je(r,i,r,i,new w(n,0,0),t.length,!0))}lift(e,t){let{$from:n,$to:r,depth:i}=e,a=n.before(i+1),o=r.after(i+1),s=a,c=o,l=f.empty,u=0;for(let e=i,r=!1;e>t;e--)r||n.index(e)>0?(r=!0,l=f.from(n.node(e).copy(l)),u++):s--;let d=f.empty,p=0;for(let e=i,n=!1;e>t;e--)n||r.after(e+1)<r.end(e)?(n=!0,d=f.from(r.node(e).copy(d)),p++):c++;return this.step(new je(s,c,a,o,new w(l.append(d),u,p),l.size-u,!0))}setBlockType(e,t,n,r=null){let i=[];return this.doc.nodesBetween(e,t,(e,t)=>{if(!e.isTextblock)return;let a=Be(e,n,r);return e.type===n&&u(e.attrs,a)||i.push(new Le(t,n,a)),!1}),i.length?this.step(new ze(i)):this}setBlockAttrs(e,t,n){let r=[];return this.doc.nodesBetween(e,t,(e,t)=>{if(!e.isTextblock)return;let i=e.type.spec.attrs??{},a=Object.fromEntries(Object.entries(n).filter(([e])=>e in i));if(!Object.keys(a).length)return!1;let o={...e.attrs,...a};return u(e.attrs,o)||r.push(new Le(t,e.type,o)),!1}),r.length?this.step(new ze(r)):this}setNodeMarkup(e,t,n=null,r){return this.step(new Le(e,t,n,r))}};function I(e,t,n){let r=e.tr;try{n(r)}catch(e){if(e instanceof F)return!1;throw e}return!r.docChanged&&r.selection.eq(e.selection)&&r.storedMarks===e.storedMarks?!1:(t?.(r),!0)}var L=class e{$anchor;$head;constructor(e,t){this.$anchor=e,this.$head=t}get anchor(){return this.$anchor.pos}get head(){return this.$head.pos}get $from(){return this.anchor<=this.head?this.$anchor:this.$head}get $to(){return this.anchor<=this.head?this.$head:this.$anchor}get from(){return this.$from.pos}get to(){return this.$to.pos}get empty(){return this.from===this.to}get ranges(){return[{from:this.from,to:this.to}]}eq(e){return e.constructor===this.constructor&&e.anchor===this.anchor&&e.head===this.head}static near(e,t=1){if(e.parent.inlineContent)return new R(e,e);let n=e.doc,r=He(n,e.pos,t)??He(n,e.pos,-t);return r===null?new Ge(n):R.create(n,r)}static atStart(t){return e.near(t.resolve(0),1)}static atEnd(t){return e.near(t.resolve(t.content.size),-1)}static kinds=new Map;static fromJSON(t,n){if(n.type===`all`)return new Ge(t);let r=e.kinds.get(n.type);if(r)return r(t,n);let i=e=>Math.max(0,Math.min(e,t.content.size));if(n.type===`node`){let r=t.resolve(i(n.anchor)),a=r.nodeAfter;return a&&!r.textOffset&&We.isSelectable(a)?new We(r):e.near(r)}return R.between(t.resolve(i(n.anchor)),t.resolve(i(n.head)))}};function He(e,t,n){let r=null;return e.descendants((e,i)=>{if(!e.isTextblock)return!0;let a=i+1,o=a+e.content.size;return n>0&&a>=t&&r===null&&(r=a),n<0&&o<=t&&(r=o),!1}),r}function Ue(e){if(!e.textOffset)return e;let t=e.parent.child(e.index()).text??``,n=t.charCodeAt(e.textOffset-1),r=t.charCodeAt(e.textOffset);return n>=55296&&n<=56319&&r>=56320&&r<=57343?e.doc.resolve(e.pos-1):e}var R=class e extends L{static create(t,n,r=n){return e.between(t.resolve(n),t.resolve(r))}static between(t,n){let r=n.pos>=t.pos?1:-1,i=n.parent.inlineContent?n:L.near(n,r).$head,a=t.parent.inlineContent?t:L.near(t,-r).$head;return!i.parent.inlineContent||!a.parent.inlineContent?L.near(n,r):new e(Ue(a),Ue(i))}map(t,n){let r=t.resolve(n.map(this.head));if(!r.parent.inlineContent)return L.near(r);let i=t.resolve(n.map(this.anchor));return new e(i.parent.inlineContent?i:r,r)}toJSON(){return{type:`text`,anchor:this.anchor,head:this.head}}},We=class e extends L{node;constructor(t){let n=t.nodeAfter;if(!n||t.textOffset||!e.isSelectable(n))throw RangeError(`No selectable node at position ${t.pos}`);super(t,t.doc.resolve(t.pos+n.nodeSize)),this.node=n}static create(t,n){return new e(t.resolve(n))}static isSelectable(e){return!e.isText&&e.type.spec.selectable!==!1}map(t,n){let r=n.mapResult(this.anchor,1),i=n.mapResult(this.head,-1),a=t.resolve(r.pos),o=a.nodeAfter;return r.deleted||i.deleted||!o||a.textOffset||r.pos+o.nodeSize!==i.pos?L.near(a):e.isSelectable(o)?new e(a):L.near(a)}toJSON(){return{type:`node`,anchor:this.anchor,head:this.head}}},Ge=class e extends L{constructor(e){super(e.resolve(0),e.resolve(e.content.size))}map(t){return new e(t)}toJSON(){return{type:`all`,anchor:this.anchor,head:this.head}}};function Ke(e){if(!e.parent.inlineContent)return d.none;if(e.textOffset)return e.parent.child(e.index()).marks;let t=e.nodeBefore,n=e.nodeAfter,r=t??n,i=t?n:null,a=r?.marks??d.none;for(let e of a)!e.type.inclusive&&!(i&&e.isInSet(i.marks))&&(a=e.removeFromSet(a));return a}var qe=[`section`,`revision`,`formatChange`,`attributes`],Je=new Set([`bookmarkStart`,`bookmarkEnd`,`commentStart`,`commentEnd`,`controlStart`,`controlEnd`]);function Ye(e,t,n,r=0){let i=e.doc.nodeAt(t);if(!i?.isTextblock||!Object.hasOwn(i.attrs,`revision`))return;let a=!1;if(i.content.cut(0,i.content.size-(n.content.size-r)).forEach(e=>{Je.has(e.type.name)||(a=!0)}),!a){(i.type!==n.type||JSON.stringify(i.attrs)!==JSON.stringify(n.attrs))&&e.setNodeMarkup(t,n.type,n.attrs);return}let o={...i.attrs},s=!1;for(let e of qe){let t=n.attrs[e]??null;JSON.stringify(o[e]??null)!==JSON.stringify(t)&&(o[e]=t,s=!0)}s&&e.setNodeMarkup(t,i.type,o)}var Xe=new Set([`insertion`,`deletion`,`formatChange`]);function Ze(e){return e.some(e=>Xe.has(e.type.name))?e.filter(e=>!Xe.has(e.type.name)):e}var Qe=class{name;constructor(e){this.name=e}getState(e){return e.pluginState(this)}},$e=class{spec;key;constructor(e){this.spec=e,this.key=e.key??new Qe(`plugin`)}},et=class extends Ve{time=Date.now();storedMarks;currentSelection;selectionStep=0;storedMarksSet=!1;meta=new Map;constructor(e){super(e.doc),this.currentSelection=e.selection,this.storedMarks=e.storedMarks}get selection(){return this.selectionStep<this.steps.length&&(this.currentSelection=this.currentSelection.map(this.doc,this.mapping.slice(this.selectionStep)),this.selectionStep=this.steps.length),this.currentSelection}setSelection(e){if(e.$anchor.doc!==this.doc)throw RangeError(`Selection is not in this document`);return this.currentSelection=e,this.selectionStep=this.steps.length,this}setStoredMarks(e){return this.storedMarks=e,this.storedMarksSet=!0,this}addStep(e,t){super.addStep(e,t),this.storedMarksSet||(this.storedMarks=null)}setMeta(e,t){return this.meta.set(e,t),this}getMeta(e){return this.meta.get(e)}copyMeta(e){for(let[t,n]of e.meta)this.meta.set(t,n);return this.time=e.time,this}get addToHistory(){return this.meta.get(`addToHistory`)!==!1}deleteSelection(){let e=this.selection;if(e.empty)return this;if(e instanceof Ge){let e=tt(this.doc.type.schema),t=this.doc.childCount===1?this.doc.firstChild:null;return(t?.type!==e||t.content.size!==0)&&this.replace(0,this.doc.content.size,new w(f.from(e.create()),0,0)),this.setSelection(L.atStart(this.doc))}let t=this.steps.length,{$from:n}=e,r=n.index();if(e instanceof We&&!n.parent.canReplace(r,r+1)){let t=n.parent.contentMatchAt(r).defaultType;if(!t?.isTextblock)throw new F(`The selected node cannot be deleted`);return this.replace(e.from,e.to,new w(f.from(t.create()),0,0)),this.setSelection(R.create(this.doc,e.from+1))}let{$to:i}=e,a=n.depth>0&&n.parent!==i.parent&&n.parent.isTextblock&&i.parent.isTextblock?i.parent:null;this.delete(e.from,e.to),a&&Ye(this,n.before(),a,i.parentOffset);let o=this.mapping.slice(t).map(e.from,-1);return this.setSelection(R.create(this.doc,o))}replaceSelection(e){this.deleteSelection();let t=this.selection.from,n=this.steps.length;this.replace(t,t,e);let r=this.mapping.slice(n).map(t,1);return this.setSelection(L.near(this.doc.resolve(r),-1))}};function tt(e){let t=Object.values(e.nodes).find(e=>e.isTextblock);if(!t)throw RangeError(`Schema has no textblock type`);return t}var nt=class e{doc;selection;storedMarks;plugins;fields;constructor(e,t,n,r,i){this.doc=e,this.selection=t,this.storedMarks=n,this.plugins=r,this.fields=i}static create(t){let n=new e(t.doc,t.selection??L.atStart(t.doc),t.storedMarks??null,t.plugins??[],new Map);for(let e of n.plugins)e.spec.state&&n.fields.set(e,e.spec.state.init(n));return n}get schema(){return this.doc.type.schema}get tr(){return new et(this)}pluginState(e){let t=this.plugins.find(t=>t.key===e);return t?this.fields.get(t):void 0}apply(e){return this.applyTransaction(e).state}withDocument(t,n){return new e(t,n,null,this.plugins,new Map(this.fields))}applyTransaction(e){if(!this.passesFilters(e))return{state:this,transactions:[]};let t=[e],n=this.applyInner(e),r=[];for(let i=0;;i++){if(i>100)throw RangeError(`appendTransaction did not settle after 100 rounds`);let a=!1;if(this.plugins.forEach((i,o)=>{let s=i.spec.appendTransaction;if(!s)return;let c=r[o]??{state:this,count:0},l=c.count<t.length?s(t.slice(c.count),c.state,n):null;l&&n.passesFilters(l,o)&&(l.setMeta(`appendedTransaction`,e),t.push(l),n=n.applyInner(l),a=!0),r[o]={state:n,count:t.length}}),!a)return{state:n,transactions:t}}}passesFilters(e,t=-1){return this.plugins.every((n,r)=>r===t||n.spec.filterTransaction?.(e,this)!==!1)}applyInner(t){if(t.before!==this.doc)throw RangeError(`Transaction was not created from this state`);let n=new e(t.doc,t.selection,t.storedMarks,this.plugins,new Map);for(let e of this.plugins){let r=e.spec.state;r&&n.fields.set(e,r.apply(t,this.fields.get(e),this,n))}return n}};function rt(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}var z=e=>typeof e==`boolean`?void 0:`must be true or false`,B=(e,t)=>n=>Number.isInteger(n)&&n>=e&&n<=t?void 0:`must be an integer from ${e} to ${t}`,V=(e=255)=>t=>typeof t==`string`&&t.length<=e?void 0:`must be a string of at most ${e} characters`,H=(e=255)=>t=>typeof t==`string`&&t.length>0&&t.length<=e?void 0:`must be a non-empty string of at most ${e} characters`,U=e=>t=>e.includes(t)?void 0:`must be one of ${e.join(`, `)}`,it=e=>typeof e==`string`&&/^[A-Za-z][A-Za-z0-9-]{0,63}$/.test(e)?void 0:`must be a Word token`,at=e=>typeof e==`string`&&/^([0-9A-Fa-f]{6}|auto)$/.test(e)?void 0:`must be RRGGBB or auto`,ot=e=>typeof e==`string`&&/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}(:\d{2}(\.\d+)?)?(Z|[+-]\d{2}:\d{2})?$/.test(e)?void 0:`must be an ISO 8601 date-time`,W=e=>typeof e==`string`&&e.length>0&&e.length<=16777216?void 0:`must be an XML string`,st=e=>{if(!rt(e))return`must be an object`;let t=Object.entries(e);if(t.length===0)return`must not be empty (use null)`;if(t.length>64)return`must have at most 64 attributes`;for(let[e,n]of t){if(!/^[A-Za-z_][\w.-]*(:[A-Za-z_][\w.-]*)?$/.test(e))return`${e} is not an attribute name`;if(typeof n!=`string`||n.length>65535)return`${e} must be a string`}},G=e=>t=>t===null?void 0:e(t),ct=(e,t=1e5)=>n=>{if(!Array.isArray(n))return`must be an array`;if(n.length>t)return`must have at most ${t} items`;for(let t=0;t<n.length;t++){let r=e(n[t]);if(r)return`[${t}] ${r}`}},K=(e,t=[],n=!1)=>r=>{if(!rt(r))return`must be an object`;let i=Object.keys(r);if(i.length===0&&!n)return`must not be empty (use null)`;for(let t of i){if(!Object.hasOwn(e,t))return`unknown key ${t}`;let n=e[t](r[t]);if(n)return`${t} ${n}`}for(let e of t)if(!Object.hasOwn(r,e))return`${e} is required`},lt=1440;function ut(e){return Math.round(e*lt/25.4)}function dt(e){return e*25.4/lt}function ft(e){let t=[],n=_t(e.content.content,{instances:t});return{schemaVersion:3,section:gt(e.settings),defaults:{paragraph:{spacing:{after:220,line:360,lineRule:`auto`}},run:[{type:`font`,attrs:{ascii:`Georgia`,hAnsi:`Georgia`,cs:`Georgia`}},{type:`fontSize`,attrs:{value:22,complexScript:22}}]},styles:structuredClone(Ct),numbering:{abstracts:structuredClone([Tt,Et]),instances:t},comments:[],content:{type:`doc`,content:n}}}var pt=720,mt=360;function ht(e){return Math.min(ut(e),31680)}function gt(e){let{width:t,height:n}=e.pageSize,{top:r,right:i,bottom:a,left:o}=e.margins;return{pageSize:{width:Math.max(ht(t),1),height:Math.max(ht(n),1),...t>n?{orientation:`landscape`}:{}},margins:{top:ht(r),right:ht(i),bottom:ht(a),left:ht(o)}}}function _t(e,t){let n=[];for(let r of e)r.type===`bulletList`||r.type===`orderedList`?vt(r,0,void 0,t,n):n.push(yt(r,{}));return n}function vt(e,t,n,r,i){let a=Math.min(t,8),o=e.type===`bulletList`?`bullet`:`number`,s=e.type===`orderedList`?e.attrs?.start??1:1,c=n!==void 0&&n.kind===o&&s===1&&t<=8&&!n.item.continued,l;c&&(l=n.id,n.item.continued=!0),l===void 0&&(l=r.instances.length+1,r.instances.push({id:l,abstract:o===`bullet`?Tt.id:Et.id,...o===`number`?{overrides:[{level:a,start:s}]}:{}}));for(let n of e.content){let[e,...s]=n.content,c={continued:!1};i.push(yt(e,{style:`ListParagraph`,numbering:{id:l,level:a}}));for(let e of s)if(e.type===`bulletList`||e.type===`orderedList`)vt(e,t+1,{id:l,kind:o,item:c},r,i);else{let t=e.type===`paragraph`||e.type===`horizontalRule`?{style:`ListParagraph`}:{};i.push(yt(e,{...t,indent:{left:pt*(a+1)}}))}}}function yt(e,t){if(e.type===`horizontalRule`)return{type:`paragraph`,attrs:{...t,borders:{bottom:{style:`single`,size:6,space:1,color:`auto`}}}};let n={...t};e.type===`heading`&&(n.style=`Heading${e.attrs.level}`);let r=e.attrs?.align;return r&&r!==`start`&&(n.justification=bt[r]),{type:`paragraph`,...Object.keys(n).length?{attrs:n}:{},...e.content?.length?{content:e.content.map(xt)}:{}}}var bt={center:`center`,end:`right`,justify:`both`};function xt(e){let t=e.marks?.flatMap(e=>e.type===`link`?[St(e),{type:`characterStyle`,attrs:{id:`Hyperlink`}}]:[St(e)]);return{...e,...t?.length?{marks:t}:{}}}function St(e){switch(e.type){case`link`:return{type:`link`,attrs:{href:e.attrs.href}};case`textColor`:return{type:`color`,attrs:{value:e.attrs.color.slice(1).toUpperCase()}};case`highlight`:return{type:`shading`,attrs:{pattern:`clear`,fill:e.attrs.color.slice(1).toUpperCase()}};default:return{type:e.type}}}var Ct=[{id:`Normal`,type:`paragraph`,name:`Normal`,isDefault:!0},...[32,28,26,24,22,22].map((e,t)=>({id:`Heading${t+1}`,type:`paragraph`,name:`heading ${t+1}`,basedOn:`Normal`,next:`Normal`,paragraph:{keepNext:!0,keepLines:!0,outlineLevel:t,spacing:{before:240,after:120}},run:[{type:`bold`},{type:`fontSize`,attrs:{value:e}}]})),{id:`ListParagraph`,type:`paragraph`,name:`List Paragraph`,basedOn:`Normal`,paragraph:{indent:{left:pt},contextualSpacing:!0}},{id:`DefaultParagraphFont`,type:`character`,name:`Default Paragraph Font`,isDefault:!0},{id:`Hyperlink`,type:`character`,name:`Hyperlink`,basedOn:`DefaultParagraphFont`,run:[{type:`color`,attrs:{value:`0563C1`,themeColor:`hyperlink`}},{type:`underline`}]}];function wt(e){return Array.from({length:9},(t,n)=>({level:n,start:1,format:e===`bullet`?`bullet`:`decimal`,text:e===`bullet`?[`•`,`◦`,`▪`][n%3]:`%${n+1}.`,justification:`left`,paragraph:{indent:{left:pt*(n+1),hanging:mt}}}))}var Tt={id:0,multiLevelType:`hybridMultilevel`,levels:wt(`bullet`)},Et={id:1,multiLevelType:`hybridMultilevel`,levels:wt(`number`)},Dt=31680,Ot=B(-31680,Dt),kt=B(0,Dt),At=B(-31680,Dt),jt=[`left`,`center`,`right`,`both`,`start`,`end`,`distribute`,`mediumKashida`,`highKashida`,`lowKashida`,`thaiDistribute`,`numTab`],Mt=[`auto`,`exact`,`atLeast`],Nt=[`left`,`center`,`right`,`decimal`,`bar`,`clear`,`num`,`start`,`end`],Pt=[`none`,`dot`,`hyphen`,`underscore`,`heavy`,`middleDot`],Ft=[`nextPage`,`continuous`,`evenPage`,`oddPage`,`nextColumn`],It=[`baseline`,`superscript`,`subscript`],Lt=[`black`,`blue`,`cyan`,`green`,`magenta`,`red`,`yellow`,`white`,`darkBlue`,`darkCyan`,`darkGreen`,`darkMagenta`,`darkRed`,`darkYellow`,`darkGray`,`lightGray`,`none`],Rt=[`majorAscii`,`majorHAnsi`,`majorEastAsia`,`majorBidi`,`minorAscii`,`minorHAnsi`,`minorEastAsia`,`minorBidi`],zt=K({style:it,size:B(0,96),space:B(0,31),color:at,themeColor:it},[`style`]),Bt=K({pattern:it,color:at,fill:at,themeFill:it},[`pattern`]),q=e=>({default:null,validate:G(e)}),Vt=B(0,2147483647),Ht={id:Vt,author:V(),date:G(ot)},Ut=K(Ht,[`id`,`author`]),Wt=K({position:U([`pageBottom`,`beneathText`,`sectEnd`,`docEnd`]),format:it,start:Vt,restart:U([`continuous`,`eachSect`,`eachPage`])}),Gt=45,Kt=e=>qt(e),qt=K({pageSize:K({width:B(1,Dt),height:B(1,Dt),orientation:U([`portrait`,`landscape`])}),margins:K({top:Ot,right:kt,bottom:Ot,left:kt,header:kt,footer:kt,gutter:kt}),type:U(Ft),titlePage:z,headers:K({default:H(),first:H(),even:H()}),footers:K({default:H(),first:H(),even:H()}),columns:K({count:B(1,Gt),space:kt,equalWidth:z,separator:z,widths:ct(K({width:kt,space:kt},[`width`]),Gt)}),pageNumbers:K({start:Vt,format:it}),footnotes:Wt,endnotes:Wt,change:K({...Ht,previous:Kt},[`id`,`author`,`previous`]),ext:W},[],!0),Jt=K({value:Ot,type:U([`auto`,`dxa`,`pct`,`nil`])},[`value`,`type`]),Yt=(e,t=[])=>K(Object.fromEntries([`top`,`left`,`bottom`,`right`,`start`,`end`,...t].map(t=>[t,e]))),Xt=1e3,Zt={style:q(H()),width:q(Jt),justification:q(U([`left`,`center`,`right`,`start`,`end`])),indent:q(Jt),layout:q(U([`fixed`,`autofit`])),borders:q(Yt(zt,[`insideH`,`insideV`])),cellMargins:q(Yt(Jt)),cellSpacing:q(Jt),shading:q(Bt),look:q(K({firstRow:z,lastRow:z,firstColumn:z,lastColumn:z,noHBand:z,noVBand:z})),rowBandSize:q(B(1,Xt)),columnBandSize:q(B(1,Xt)),ext:q(W)},Qt={height:q(K({value:kt,rule:U([`auto`,`exact`,`atLeast`])},[`value`])),cantSplit:q(z),header:q(z),gridBefore:q(B(1,Xt)),widthBefore:q(Jt),gridAfter:q(B(1,Xt)),widthAfter:q(Jt),ext:q(W)},$t={width:q(Jt),gridSpan:q(B(1,Xt)),vMerge:q(U([`restart`,`continue`])),borders:q(Yt(zt,[`insideH`,`insideV`,`tl2br`,`tr2bl`])),shading:q(Bt),margins:q(Yt(Jt)),verticalAlign:q(U([`top`,`center`,`bottom`,`both`])),textDirection:q(it),noWrap:q(z),ext:q(W)},en=e=>t=>{if(!rt(t))return`must be an object`;for(let[n,r]of Object.entries(t)){if(!Object.hasOwn(e,n))return`unknown key ${n}`;let t=r===null?`must not be null (leave it out)`:e[n].validate?.(r);if(t)return`${n} ${t}`}},tn=en(Zt),nn=en(Qt),rn=en($t),an=B(0,2147483647),on=B(-2147483648,2147483647),sn=K({horizontal:K({relativeTo:it,offset:on,align:it},[`relativeTo`]),vertical:K({relativeTo:it,offset:on,align:it},[`relativeTo`]),wrap:U([`square`,`tight`,`through`,`topAndBottom`,`behind`,`inFront`]),side:U([`bothSides`,`left`,`right`,`largest`]),distance:K({top:an,bottom:an,left:an,right:an}),allowOverlap:z,layoutInCell:z},[`horizontal`,`vertical`,`wrap`]),cn=[`characterStyle`,`bold`,`italic`,`underline`,`strike`,`doubleStrike`,`caps`,`smallCaps`,`hidden`,`font`,`fontSize`,`color`,`highlight`,`shading`,`verticalAlign`,`characterSpacing`],ln=e=>{if(!Array.isArray(e))return`must be an array of marks`;for(let t of e)if(!rt(t)||!cn.includes(t.type))return`${rt(t)?String(t.type):`a non-object`} is not a run property`;try{Sn.nodeFromJSON({type:`text`,text:`x`,marks:e});return}catch(e){return e.message}},un={style:q(H()),justification:q(U(jt)),indent:q(K({left:Ot,right:Ot,firstLine:kt,hanging:kt})),spacing:q(K({before:kt,after:kt,line:At,lineRule:U(Mt),beforeAutospacing:z,afterAutospacing:z})),keepNext:q(z),keepLines:q(z),widowControl:q(z),pageBreakBefore:q(z),contextualSpacing:q(z),outlineLevel:q(B(0,9)),numbering:q(K({id:Vt,level:B(0,8)})),tabs:q(ct(K({position:Ot,kind:U(Nt),leader:U(Pt)},[`position`,`kind`]),64)),borders:q(K({top:zt,bottom:zt,left:zt,right:zt,between:zt,bar:zt})),shading:q(Bt),markFormat:q(ln),ext:q(W)},dn=Object.keys(un),fn=e=>{if(!rt(e))return`must be an object`;for(let[t,n]of Object.entries(e)){if(!Object.hasOwn(un,t))return`unknown key ${t}`;let e=n===null?`must not be null (leave it out)`:un[t].validate?.(n);if(e)return`${t} ${e}`}},J=(e,t)=>t===void 0?{validate:e}:{default:t,validate:e},pn={attrs:{value:J(z,!0)}},mn={attrs:{value:J(G(z),!0),complexScript:J(G(z),null)}},hn={attrs:{id:J(Vt),author:J(V()),date:J(G(ot),null),move:J(G(H()),null),attributes:J(G(st),null)},inclusive:!1},gn={attributes:q(st)},_n={controls:q(e=>{let t=ct(H(),64)(e);if(t)return t;let n=e;return n.length?new Set(n).size===n.length?void 0:`must not repeat an id`:`must not be empty (use null)`})},vn={group:`inline`,inline:!0,selectable:!1},yn=J(G(H()),null),bn=J(G(U(Rt)),null),xn=e=>typeof e==`string`&&/^[0-9A-Fa-f]{2}$/.test(e)?void 0:`must be a hex byte`,Sn=new ie({nodes:{doc:{content:`block+`},paragraph:{group:`block`,content:`inline*`,attrs:{...un,..._n,section:q(Kt),revision:q(K({insertion:Ut,deletion:Ut})),formatChange:q(K({...Ht,previous:fn},[`id`,`author`,`previous`])),attributes:q(st)}},table:{group:`block`,content:`tableRow+`,attrs:{...Zt,..._n,grid:{default:[],validate:ct(kt,Xt)},gridExt:q(W)}},tableRow:{content:`tableCell+`,attrs:{...Qt,..._n,revision:q(K({insertion:Ut,deletion:Ut})),exceptions:q(tn),attributes:q(st)}},tableCell:{content:`block* paragraph`,attrs:{...$t,..._n}},opaqueBlock:{group:`block`,attrs:{xml:{validate:W},label:q(H()),..._n}},text:{group:`inline`},tab:{group:`inline`,inline:!0},hardBreak:{group:`inline`,inline:!0,selectable:!1,attrs:{clear:q(U([`none`,`left`,`right`,`all`]))}},pageBreak:{group:`inline`,inline:!0,selectable:!1},columnBreak:{group:`inline`,inline:!0,selectable:!1},bookmarkStart:{group:`inline`,inline:!0,selectable:!1,attrs:{id:{validate:Vt},name:{validate:V()},...gn}},bookmarkEnd:{group:`inline`,inline:!0,selectable:!1,attrs:{id:{validate:Vt},...gn}},commentStart:{group:`inline`,inline:!0,selectable:!1,attrs:{id:{validate:Vt},...gn}},commentEnd:{group:`inline`,inline:!0,selectable:!1,attrs:{id:{validate:Vt},...gn}},commentReference:{group:`inline`,inline:!0,attrs:{id:{validate:Vt},...gn}},fieldStart:{...vn,attrs:{dirty:q(z),locked:q(z),simple:q(z),ext:q(W)}},fieldCode:{...vn,attrs:{text:{validate:V(65535)},...gn}},fieldSeparator:{...vn,attrs:{ext:q(W)}},fieldEnd:{...vn,attrs:{ext:q(W)}},controlStart:{group:`inline`,inline:!0,selectable:!1,attrs:{id:{validate:H()}}},controlEnd:{group:`inline`,inline:!0,selectable:!1,attrs:{id:{validate:H()}}},noteReference:{group:`inline`,inline:!0,attrs:{story:{validate:H()},customMark:q(z),...gn}},noteMark:{group:`inline`,inline:!0,selectable:!1},picture:{group:`inline`,inline:!0,attrs:{resource:{validate:H()},width:{validate:an},height:{validate:an},alt:q(V(65535)),title:q(V(65535)),decorative:q(z),float:q(sn),ext:q(W)}},opaqueInline:{group:`inline`,inline:!0,attrs:{xml:{validate:W},label:q(H()),run:{default:!1,validate:z}}}},marks:{link:{attrs:{href:J(G(H(8192)),null),anchor:J(G(H()),null),tooltip:J(G(V(1024)),null),attributes:J(G(st),null)},inclusive:!1},insertion:hn,deletion:hn,characterStyle:{attrs:{id:J(H())}},bold:mn,italic:mn,underline:{attrs:{style:J(it,`single`),color:J(G(at),null)}},strike:pn,doubleStrike:pn,caps:pn,smallCaps:pn,hidden:pn,font:{attrs:{ascii:yn,hAnsi:yn,eastAsia:yn,cs:yn,asciiTheme:bn,hAnsiTheme:bn,eastAsiaTheme:bn,csTheme:bn,hint:J(G(U([`default`,`eastAsia`,`cs`])),null)}},fontSize:{attrs:{value:J(G(B(1,3276)),null),complexScript:J(G(B(1,3276)),null)}},color:{attrs:{value:J(at),themeColor:J(G(it),null),themeTint:J(G(xn),null),themeShade:J(G(xn),null)}},highlight:{attrs:{value:J(U(Lt))}},shading:{attrs:{pattern:J(it),color:J(at,`auto`),fill:J(at,`auto`)}},verticalAlign:{attrs:{value:J(U(It))}},characterSpacing:{attrs:{value:J(Ot)}},formatChange:{attrs:{id:J(Vt),author:J(V()),date:J(G(ot),null),previous:J(ln)}},runExt:{attrs:{xml:J(W)}}}}),Cn=[`wholeTable`,`band1Vert`,`band2Vert`,`band1Horz`,`band2Horz`,`firstCol`,`lastCol`,`firstRow`,`lastRow`,`nwCell`,`neCell`,`swCell`,`seCell`];function wn(e){return{...e,schemaVersion:4}}function Tn(e){return{...e,schemaVersion:5}}function En(e={type:`doc`,content:[{type:`paragraph`}]},t){let n=Tn(wn(ft({schemaVersion:2,settings:ge,content:{type:`doc`,content:[]}}))),r=n.section;return{...n,section:{...t,pageSize:{...r.pageSize,...t?.pageSize},margins:{...r.margins,...t?.margins}},content:e}}function Dn(e){if(!rt(e))throw new i(`Document must be an object`);let t=e.schemaVersion;if(t===1||t===2)return Dn(Tn(wn(ft(_e(e)))));if(t===3||t===4){t===3&&Object.hasOwn(e,`resources`)&&Y(`resources`,`unknown key (schema 4 and later)`);for(let t of Fn)Object.hasOwn(e,t)&&Y(t,`unknown key (schema 5 and later)`);let n=Dn({...e,schemaVersion:5}),r=Ln(n.section);r&&Y(`section`,`${r} is of schema 5 (the document says schema ${t})`);for(let[e,r]of[[`content`,n.content],...n.comments.map((e,t)=>[`comments[${t}].content`,{content:e.content}])]){let n=Rn(r,t);n&&Y(e,`${n.name} is a schema ${n.schema} node (the document says schema ${t})`)}return t===3&&n.styles.forEach((e,t)=>{for(let n of[`table`,`row`,`cell`,`conditions`])Object.hasOwn(e,n)&&Y(`styles[${t}]`,`unknown key ${n} (schema 4 and later)`)}),n}if(t!==5)throw new i(`Unsupported schemaVersion: ${String(t)} (this version of @folijs/core reads 1 to 5${Number.isInteger(t)&&t>5?`; the document was saved by a newer one`:``})`);for(let t of Object.keys(e))if(!zn.includes(t))throw new i(`${t}: unknown key`);Bn(`section`,e.section,Kt),Bn(`defaults`,e.defaults,K({paragraph:fn,run:ln,ext:W},[],!0)),Bn(`styles`,e.styles,ct(Wn)),Bn(`numbering`,e.numbering,K({abstracts:ct(nr),instances:ct(rr)},[`abstracts`,`instances`])),e.theme!==void 0&&Bn(`theme`,e.theme,ar),Bn(`comments`,e.comments,ct(or)),e.resources!==void 0&&Bn(`resources`,e.resources,Xn),e.stories!==void 0&&Bn(`stories`,e.stories,Qn),e.controls!==void 0&&Bn(`controls`,e.controls,$n),e.settings!==void 0&&Bn(`settings`,e.settings,er);let n=e.styles,r=e.comments;Vn(`styles`,n,e=>e.id,e=>e.basedOn,e=>`${e.id} is based on itself`),Vn(`comments`,r,e=>e.id,e=>e.parent,e=>`comment ${e.id} replies to itself`);let a=kn(e.content),o=Object.entries(e.stories??{}).map(([e,t])=>{let n=`stories[${JSON.stringify(e)}].content`,r=kn(t.content,n);return jn(r,t.kind,n),[e,{...structuredClone({...t,content:null}),content:On(r)}]}),s=structuredClone({section:e.section,defaults:e.defaults,styles:n,numbering:e.numbering,theme:e.theme,resources:e.resources,controls:e.controls,settings:e.settings});return{schemaVersion:5,section:s.section,defaults:s.defaults,styles:s.styles,numbering:s.numbering,...s.theme===void 0?{}:{theme:s.theme},comments:r.map((e,t)=>({...structuredClone({...e,content:[]}),content:Hn(e.content,`comments[${t}].content`).map(e=>(e.descendants(e=>(e.type.name===`noteReference`&&Y(`comments[${t}].content`,`a comment cannot hold a note reference`),!0)),On(e)))})),...s.resources===void 0?{}:{resources:s.resources},...e.stories===void 0?{}:{stories:Object.fromEntries(o)},...s.controls===void 0?{}:{controls:s.controls},...s.settings===void 0?{}:{settings:s.settings},content:On(a)}}var On=e=>structuredClone(e.toJSON());function kn(e,t=`content`,n=!1){let r=Sn.nodeFromJSON(e,t);return r.type!==Sn.topNodeType&&Y(t,`root node must be of type "doc"`),r.marks.length&&Y(`${t}.marks`,`doc cannot have marks`),An(r,t,!1,n),r}function An(e,t,n,r=!1){e.forEach((i,a,o)=>{let s=`${t}.content[${o}]`;if(i.type.name===`table`){let t=e.maybeChild(o+1);t?.type.name===`table`&&JSON.stringify(t.attrs.controls)===JSON.stringify(i.attrs.controls)&&Y(s,`a table cannot follow a table (Word would merge them): a paragraph goes between`),!t&&e.type.name===`doc`&&!r&&Y(s,`a table cannot end the document: a paragraph follows it, as in Word`),i.forEach((e,t,n)=>{e.forEach((e,t,r)=>{An(e,`${s}.content[${n}].content[${r}]`,!0)})})}else n&&i.type.name===`paragraph`&&(i.attrs.section&&Y(`${s}.attrs.section`,`a paragraph in a table cannot end a section`),i.forEach((e,t,n)=>{(e.type.name===`pageBreak`||e.type.name===`columnBreak`)&&Y(`${s}.content[${n}]`,`a ${e.type.name} cannot be in a table`)}))})}function jn(e,t,n){e.descendants(e=>{let r=e.type.name;return e.attrs.section&&Y(n,`a story cannot end a section`),r===`noteReference`&&Y(n,`a story cannot hold a note reference`),Mn.has(r)&&Y(n,`a ${t} cannot hold comments`),t!==`footnote`&&t!==`endnote`||r!==`pageBreak`&&r!==`columnBreak`||Y(n,`a note cannot hold a ${r}`),!0})}var Mn=new Set([`commentStart`,`commentEnd`,`commentReference`]),Nn=new Set([`table`,`tableRow`,`tableCell`,`picture`]),Pn=new Set([`fieldStart`,`fieldCode`,`fieldSeparator`,`fieldEnd`,`controlStart`,`controlEnd`,`noteReference`,`noteMark`]),Fn=[`stories`,`controls`,`settings`],In=[`columns`,`pageNumbers`,`footnotes`,`endnotes`];function Ln(e){return rt(e)?In.find(t=>Object.hasOwn(e,t)):void 0}function Rn(e,t){let n=[e];for(;n.length;){let e=n.pop();if(!rt(e))continue;let r=e.type;if(t<4&&Nn.has(r))return{name:r,schema:4};if(Pn.has(r))return{name:r,schema:5};let i=rt(e.attrs)?e.attrs:{};if(i.controls)return{name:`controls`,schema:5};let a=Ln(i.section);if(a)return{name:a,schema:5};if(Array.isArray(e.content))for(let t of e.content)n.push(t)}}var zn=[`schemaVersion`,`section`,`defaults`,`styles`,`numbering`,`theme`,`comments`,`resources`,`stories`,`controls`,`settings`,`content`];function Y(e,t){throw new i(`${e}: ${t}`)}function Bn(e,t,n){let r=n(t);r&&Y(e,r)}function Vn(e,t,n,r,i){let a=new Map;t.forEach((e,t)=>{a.has(n(e))||a.set(n(e),t)});let o=new Uint8Array(t.length);t.forEach((n,s)=>{let c=[],l=s;for(;l!==void 0&&o[l]===0;){o[l]=1,c.push(l);let e=r(t[l]);l=e===void 0?void 0:a.get(e)}l!==void 0&&o[l]===1&&Y(`${e}[${l}]`,i(t[l]));for(let e of c)o[e]=2})}function Hn(e,t){let n=kn({type:`doc`,content:e},t),r=[];return n.forEach(e=>{r.push(e)}),r}var Un=K({type:U(Cn.filter(e=>e!==`wholeTable`)),paragraph:fn,run:ln,table:tn,row:nn,cell:rn,ext:W},[`type`]),Wn=K({id:H(),type:U([`paragraph`,`character`,`table`,`numbering`]),name:V(),basedOn:H(),next:H(),link:H(),isDefault:z,paragraph:fn,run:ln,table:tn,row:nn,cell:rn,conditions:ct(Un,Cn.length),ext:W},[`id`,`type`]),Gn=new Set([`http:`,`https:`,`blob:`]);function Kn(e){try{return new URL(e,`https://base.invalid/`).protocol}catch{return``}}var qn=/^image\/[A-Za-z0-9][\w.+-]{0,126}$/,Jn=e=>{let t=K({contentType:e=>typeof e==`string`&&qn.test(e)?void 0:`must be an image media type`,size:B(0,2**53-1),part:H(1024),url:e=>H(8192)(e)??(Gn.has(Kn(e))?void 0:`must be relative, http(s) or blob`),data:e=>typeof e==`string`&&/^data:image\/[\w.+-]+[;,]/i.test(e)&&e.length<=67108864?void 0:`must be a data: URL of an image`},[`contentType`])(e);if(t)return t;let n=e;return n.part===void 0&&n.url===void 0&&n.data===void 0?`needs part, url or data`:void 0},Yn=(e,t)=>n=>{if(!rt(n))return`must be an object`;let r=Object.entries(n);if(r.length>1e5)return`must have at most 100000 ${t}s`;for(let[n,i]of r){let r=n===`__proto__`?`is not a ${t} key`:H()(n);if(r)return`${n.slice(0,64)} ${r}`;let a=e(i);if(a)return`${n} ${a}`}},Xn=Yn(Jn,`resource`),Zn=[`footnote`,`endnote`],Qn=Yn(e=>K({kind:U([`header`,`footer`,...Zn]),noteType:U([`normal`,`separator`,`continuationSeparator`,`continuationNotice`]),content:e=>rt(e)?void 0:`must be an object`,ext:W},[`kind`,`content`])(e)??(rt(e)&&e.noteType!==void 0&&!Zn.includes(e.kind)?`noteType is for notes`:void 0),`story`),$n=Yn(K({kind:U([`text`,`richText`,`dropDown`,`comboBox`,`date`,`checkbox`,`picture`,`repeating`,`repeatingItem`,`other`]),tag:V(),alias:V(),lock:U([`sdtLocked`,`contentLocked`,`sdtContentLocked`,`unlocked`]),items:ct(K({value:V(),display:V()},[`value`])),dateFormat:V(),date:V(),checked:z,checkedState:K({value:V(),font:V()},[`value`]),uncheckedState:K({value:V(),font:V()},[`value`]),multiLine:z,format:ln,noInsertDelete:z,deleted:z,placeholder:K({showing:z,docPart:V(),text:V(65535)},[],!0),binding:K({xpath:V(65535),storeItemId:V(),prefixMappings:V(65535)},[],!0),ext:W},[`kind`]),`control`),er=K({doNotUseHTMLParagraphAutoSpacing:z,evenAndOddHeaders:z,footnotes:Wt,endnotes:Wt},[],!0),tr=K({level:B(0,8),start:B(0,2147483647),format:it,text:V(),justification:U([`left`,`center`,`right`,`start`,`end`]),restart:B(0,9),legal:z,suffix:U([`tab`,`space`,`nothing`]),style:H(),paragraph:fn,run:ln,ext:W},[`level`]),nr=K({id:B(0,2147483647),multiLevelType:U([`singleLevel`,`multilevel`,`hybridMultilevel`]),levels:ct(tr,9),styleLink:H(),numStyleLink:H(),ext:W},[`id`,`levels`]),rr=K({id:B(1,2147483647),abstract:B(0,2147483647),overrides:ct(K({level:B(0,8),start:B(0,2147483647),definition:tr},[`level`]),9),ext:W},[`id`,`abstract`]),ir=K({latin:V(),eastAsia:V(),cs:V()},[`latin`]),ar=K({fonts:K({major:ir,minor:ir},[`major`,`minor`]),colors:e=>{if(!rt(e))return`must be an object`;for(let[t,n]of Object.entries(e)){if(!/^(dk[12]|lt[12]|accent[1-6]|hlink|folHlink)$/.test(t))return`unknown color ${t}`;let e=at(n);if(e)return`${t} ${e}`}}},[`fonts`,`colors`]),or=K({id:B(0,2147483647),author:V(),initials:V(9),date:ot,content:e=>Array.isArray(e)?void 0:`must be an array of blocks`,parent:B(0,2147483647),done:z,ext:W},[`id`,`author`,`content`]),sr=[`bold`,`boldCs`,`italic`,`italicCs`,`caps`,`smallCaps`,`strike`,`doubleStrike`,`hidden`],cr={bold:!1,boldCs:!1,italic:!1,italicCs:!1,caps:!1,smallCaps:!1,strike:!1,doubleStrike:!1,hidden:!1,underline:null,underlineColor:null,font:{ascii:null,hAnsi:null,eastAsia:null,cs:null},size:20,sizeCs:20,color:null,highlight:null,shading:null,verticalAlign:`baseline`,characterSpacing:0},lr={style:null,justification:null,indent:{left:0,right:0,firstLine:0,hanging:0},spacing:{before:0,after:0,line:null,lineRule:`auto`,beforeAutospacing:!1,afterAutospacing:!1},keepNext:!1,keepLines:!1,widowControl:!1,pageBreakBefore:!1,contextualSpacing:!1,outlineLevel:null,tabs:[],borders:null,shading:null,numbering:null},ur=new Set([`justification`,`keepNext`,`keepLines`,`widowControl`,`pageBreakBefore`,`contextualSpacing`,`outlineLevel`,`shading`]);function dr(e,t){if(!t)return;let{indent:n,spacing:r,numbering:i,borders:a,tabs:o}=t;if(n&&(n.firstLine!==void 0&&(e.indent.hanging=0),Object.assign(e.indent,n),e.indent.hanging&&(e.indent.firstLine=0)),r&&Object.assign(e.spacing,r),i&&(e.numbering={id:i.id??e.numbering?.id??0,level:i.level??e.numbering?.level}),a&&(e.borders={...e.borders,...a}),o){let t=new Map(e.tabs.map(e=>[e.position,e]));for(let e of o)e.kind===`clear`?t.delete(e.position):t.set(e.position,{position:e.position,kind:e.kind,leader:e.leader??null});e.tabs=[...t.values()].sort((e,t)=>e.position-t.position)}for(let[n,r]of Object.entries(t))ur.has(n)&&r!=null&&(e[n]=r)}function fr(e){return{...e,indent:{...e.indent},spacing:{...e.spacing},tabs:e.tabs.map(e=>({...e})),borders:e.borders?Object.fromEntries(Object.entries(e.borders).map(([e,t])=>[e,{...t}])):null,shading:e.shading?{...e.shading}:null,numbering:e.numbering?{...e.numbering}:null}}function pr(e){return{...e,font:{...e.font}}}function mr(e){let t={};for(let n of e??[]){let e=n.attrs??{},r=e.value===void 0||e.value;switch(n.type){case`bold`:case`italic`:{r!==null&&(t[n.type]=r);let i=e.complexScript;i!=null&&(t[n.type===`bold`?`boldCs`:`italicCs`]=i);break}case`caps`:case`smallCaps`:case`strike`:case`doubleStrike`:case`hidden`:r!==null&&(t[n.type]=r)}}return t}var hr={text1:`dk1`,background1:`lt1`,text2:`dk2`,background2:`lt2`,dark1:`dk1`,light1:`lt1`,dark2:`dk2`,light2:`lt2`,hyperlink:`hlink`,followedHyperlink:`folHlink`};function gr(e,t,n){for(let r of t??[]){let t=r.attrs??{};switch(r.type){case`underline`:{let n=t.style??`single`;e.underline=n===`none`?null:n,e.underlineColor=t.color??null;break}case`font`:for(let r of[`ascii`,`hAnsi`,`eastAsia`,`cs`]){let i=t[`${r}Theme`],a=i&&yr(n,i)||t[r];a&&(e.font[r]=a)}break;case`fontSize`:typeof t.value==`number`&&(e.size=t.value),typeof t.complexScript==`number`&&(e.sizeCs=t.complexScript);break;case`color`:{let r=(t.themeColor&&!t.themeTint&&!t.themeShade?n?.colors[hr[t.themeColor]??t.themeColor]:void 0)??t.value;e.color=r===void 0||r===`auto`?null:r.toUpperCase();break}case`highlight`:e.highlight=t.value===`none`?null:t.value;break;case`shading`:e.shading=t.fill===`auto`||t.fill===void 0?null:String(t.fill).toUpperCase();break;case`verticalAlign`:e.verticalAlign=t.value;break;case`characterSpacing`:e.characterSpacing=t.value}}}function _r(e,t,n){Object.assign(e,mr(t)),gr(e,t,n)}function vr(e,t,n){let r={};for(let i of t)Object.assign(r,mr(i)),gr(e,i,n);for(let t of sr)r[t]&&(e[t]=!e[t])}function yr(e,t){if(!e)return null;let n=t.startsWith(`major`)?e.fonts.major:e.fonts.minor,r=t.slice(5);return(r===`EastAsia`?n.eastAsia:r===`Bidi`?n.cs:n.latin)||null}function br(e,t){switch(t??`decimal`){case`none`:return``;case`decimalZero`:return e>=0&&e<10?`0${e}`:String(e);case`upperRoman`:return Cr(e);case`lowerRoman`:return Cr(e).toLowerCase();case`upperLetter`:return wr(e);case`lowerLetter`:return wr(e).toLowerCase();case`ordinal`:return Tr(e);case`chicago`:return xr(e);case`numberInDash`:return`- ${e} -`;default:return String(e)}}function xr(e){return e<1?String(e):[`*`,`†`,`‡`,`§`][(e-1)%4].repeat(Math.ceil(e/4))}var Sr=[[1e3,`M`],[900,`CM`],[500,`D`],[400,`CD`],[100,`C`],[90,`XC`],[50,`L`],[40,`XL`],[10,`X`],[9,`IX`],[5,`V`],[4,`IV`],[1,`I`]];function Cr(e){if(e<=0||e>=4e3)return String(e);let t=``,n=e;for(let[e,r]of Sr)for(;n>=e;n-=e)t+=r;return t}function wr(e){return e<=0||e>780?String(e):String.fromCharCode(65+(e-1)%26).repeat(Math.floor((e-1)/26)+1)}function Tr(e){let t=e%100;return`${e}${t>=11&&t<=13?`th`:[`th`,`st`,`nd`,`rd`][e%10]??`th`}`}var Er=new Set([`width`,`justification`,`indent`,`layout`,`borders`,`cellMargins`,`cellSpacing`,`shading`,`look`,`rowBandSize`,`columnBandSize`]),Dr=new Set([`borders`,`cellMargins`,`look`]);function Or(e,t){if(t)for(let[n,r]of Object.entries(t))r!=null&&Er.has(n)&&(e[n]=Dr.has(n)?{...e[n],...r}:r)}function kr(e){if(e)return e.type===`dxa`?e.value:0}function Ar(e,t){for(let n=e.length-1;n>=0;n--){let r=t(e[n]);if(r!=null)return r}}function jr(e,t,n=1,r=1){let i=[`wholeTable`],a=!!e.firstRow&&t.row===0,o=!!e.lastRow&&t.row===t.rows-1,s=!!e.firstColumn&&t.cell===0,c=!!e.lastColumn&&t.cell===t.cells-1;if(!e.noVBand&&!s&&!c){let n=t.cell-+!!e.firstColumn;i.push(Math.floor(n/r)%2==0?`band1Vert`:`band2Vert`)}if(!e.noHBand&&!a&&!o){let r=t.row-+!!e.firstRow;i.push(Math.floor(r/n)%2==0?`band1Horz`:`band2Horz`)}return s&&i.push(`firstCol`),c&&i.push(`lastCol`),a&&i.push(`firstRow`),o&&i.push(`lastRow`),a&&s&&i.push(`nwCell`),a&&c&&i.push(`neCell`),o&&s&&i.push(`swCell`),o&&c&&i.push(`seCell`),i}var Mr=class{#e=new Map;#t;#n;#r=new Map;#i=new Map;#a=new Map;#o=new Map;#s;#c=new Map;get addsParagraphSpacing(){return this.#n.settings?.doNotUseHTMLParagraphAutoSpacing===!0}constructor(e){this.#n=e;for(let t of e.styles)this.#e.has(t.id)||this.#e.set(t.id,t);for(let t of e.styles)t.type===`paragraph`&&t.isDefault&&(this.#t=t.id),t.type===`table`&&t.isDefault&&(this.#s=t.id);for(let t of e.numbering.instances)this.#a.has(t.id)||this.#a.set(t.id,t);for(let t of e.numbering.abstracts)this.#o.has(t.id)||this.#o.set(t.id,t)}#l(e,t){let n=[],r=new Set;for(let i=e;i!==void 0&&!r.has(i);){r.add(i);let e=this.#e.get(i);if(e?.type!==t)break;n.unshift(e),i=e.basedOn}return n}#u(e){let t=e?this.#l(e,`table`):[];return t.length?t:this.#l(this.#s,`table`)}#d(e,t){let n=JSON.stringify([e,t]),r=this.#c.get(n);if(r)return r;let i={key:n,paragraph:[],run:[],cell:[]},a=this.#u(e);for(let e of t)for(let t of a){let n=e===`wholeTable`?t:t.conditions?.find(t=>t.type===e);n?.paragraph&&i.paragraph.push(n.paragraph),n?.run&&i.run.push(n.run),n?.cell&&i.cell.push(n.cell)}return this.#c.set(n,i),i}table(e){let t=this.#u(e.style),n={};for(let e of t)Or(n,e.table);return Or(n,e),structuredClone({...n,style:t.at(-1)?.id??null})}cell(e,t,n,r){let i=this.table(e);Or(i,t.exceptions);let a=i,o=jr(a.look??{},r,a.rowBandSize,a.columnBandSize),s=[...this.#d(a.style,o).cell,n],c=Ar(s,e=>e.shading)?.fill??a.shading?.fill,l=a.borders??{},u=(e,t,n,r)=>Ar(s,n=>n.borders?.[e]??(t?n.borders?.[t]:void 0))??(r?l[e]??(t?l[t]:void 0):n),d={},f=[[`top`,null,l.insideH,r.row===0],[`bottom`,null,l.insideH,r.row===r.rows-1],[`left`,`start`,l.insideV,r.cell===0],[`right`,`end`,l.insideV,r.cell===r.cells-1]];for(let[e,t,n,r]of f){let i=u(e,t,n,r);i&&(d[e]={...i})}let p=(e,t)=>kr(Ar(s,n=>n.margins?.[e]??(t?n.margins?.[t]:void 0))??a.cellMargins?.[e]??(t?a.cellMargins?.[t]:void 0))??0;return{style:a.style,conditions:o,shading:c===void 0||c===`auto`?null:c.toUpperCase(),borders:d,margins:{top:p(`top`,null),bottom:p(`bottom`,null),left:p(`left`,`start`),right:p(`right`,`end`)},verticalAlign:Ar(s,e=>e.verticalAlign)??`top`}}#f(e,t){let n=JSON.stringify([t?.key??null,e??null]),r=this.#r.get(n);if(r)return r;let i=fr(lr),a=pr(cr);this.#p(i,a,t);let o=e===void 0?[]:this.#l(e,`paragraph`);o.length||(o=this.#l(this.#t,`paragraph`));for(let e of o)dr(i,e.paragraph);vr(a,o.map(e=>e.run??[]),this.#n.theme),i.style=o.at(-1)?.id??null;let s={paragraph:i,run:a,chain:o};return this.#r.set(n,s),s}#p(e,t,n){let{defaults:r,theme:i}=this.#n;dr(e,r.paragraph),t&&_r(t,r.run,i);for(let t of n?.paragraph??[])dr(e,t);if(t)for(let e of n?.run??[])_r(t,e,i)}paragraph(e,t){let{paragraph:n,run:r}=this.#m(e,t);return{paragraph:n,run:r}}#m(e,t){let n=e,r=t?this.#d(t.style,t.conditions):void 0,i=this.#f(n.style??void 0,r),a=fr(i.paragraph),o=n.numbering?.id!=null;n.numbering&&dr(a,{numbering:n.numbering});let s=this.#h(a);if(s?.level.paragraph){if(o)dr(a,s.level.paragraph);else{let e=fr(lr);this.#p(e,null,r),dr(e,s.level.paragraph);for(let t of i.chain)dr(e,t.paragraph);e.style=a.style,e.numbering=a.numbering,a=e}}let{style:c,numbering:l,...u}=n;dr(a,u);let d=s?{id:s.instance.id,level:s.index}:null;return{paragraph:{...fr(a),numbering:d},run:pr(i.run),level:s}}numberFormat(e){let t=this.#m(e).level;return t?t.level.format??`decimal`:null}run(e,t){let n=pr(e),r=t.find(e=>e.type===`characterStyle`)?.attrs?.id;if(r){let e=this.#i.get(r);e||(e=this.#l(r,`character`).map(e=>e.run??[]),this.#i.set(r,e)),vr(n,e,this.#n.theme)}return _r(n,t,this.#n.theme),n}#h(e){let t=e.numbering?.id,n=t?this.#a.get(t):void 0,r=n&&this.#_(n.abstract);if(!n||!r)return;let i=e.numbering?.level??r.levels.find(t=>t.style!==void 0&&t.style===e.style)?.level??0,a=this.#g(n,r,i);return a?{instance:n,abstract:r,index:i,level:a}:void 0}#g(e,t,n){return e.overrides?.find(e=>e.level===n)?.definition??t.levels.find(e=>e.level===n)}#_(e){let t=this.#o.get(e);for(let e=0;t?.numStyleLink&&e<8;e++){let e=this.#e.get(t.numStyleLink)?.paragraph?.numbering?.id,n=e?this.#a.get(e):void 0,r=n?this.#o.get(n.abstract):void 0;if(!r||r===t)break;t=r}return t}markers(e){let t=new Map,n=new Set;return e.map(e=>{let{run:r,level:i}=this.#m(e);if(!i)return null;let{instance:a,abstract:o,index:s,level:c}=i,l=t.get(o.id);l||(l=[],t.set(o.id,l));let u=e=>a.overrides?.find(t=>t.level===e)?.start??this.#g(a,o,e)?.start??0,d=`${a.id}:${s}`,f=a.overrides?.find(e=>e.level===s)?.start,p=l[s];f!==void 0&&!n.has(d)?(n.add(d),l[s]=f):l[s]=p===void 0?u(s):p+1;for(let e=s+1;e<9;e++){let t=this.#g(a,o,e)?.restart;(t===void 0||t!==0&&s<t)&&(l[e]=void 0)}let m=e=>e.replace(/%([1-9])/g,(e,t)=>{let n=Number(t)-1,r=c.legal?`decimal`:this.#g(a,o,n)?.format;return br(l[n]??u(n),r)}),h=m(c.text??``),g=pr(r);return _r(g,e.markFormat,this.#n.theme),_r(g,c.run,this.#n.theme),{text:h,plain:m((c.text??``).replace(/\p{L}+/gu,``)).trim(),suffix:c.suffix??`tab`,justification:c.justification??`left`,run:g,instance:a.id,abstract:o.id,level:s}})}},Nr=new Qe(`word`),Pr=class e extends ke{id;comment;previous;index;constructor(e,t,n,r){super(),this.id=e,this.comment=t,this.previous=n,this.index=r}apply(e){return P.ok(e)}invert(){return new e(this.id,this.previous,this.comment,this.index)}map(){return this}};function Fr(e,t){let n=e;for(let e of t){if(!(e instanceof Pr))continue;let t=n.findIndex(t=>t.id===e.id);if(e.previous===null!=t<0)continue;let r=t<0?n:[...n.slice(0,t),...n.slice(t+1)];if(!e.comment)n=r;else{let i=t<0?Math.min(e.index,r.length):t;n=[...r.slice(0,i),e.comment,...r.slice(i)]}}return n}function Ir(e,t,n){let r=Fr(t,e.steps),i=new Map(n.map(e=>[e.id,e]));for(let t of r)i.has(t.id)||(e.step(new Pr(t.id,null,t,r.indexOf(t))),r=Fr(r,e.steps.slice(-1)));return n.forEach((t,n)=>{let i=r.find(e=>e.id===t.id)??null;i===t||i&&JSON.stringify(i)===JSON.stringify(t)||(e.step(new Pr(t.id,t,i,n)),r=Fr(r,e.steps.slice(-1)))}),e}var Lr=class e extends ke{key;before;after;constructor(e,t,n){super(),this.key=e,this.before=t,this.after=n}apply(e){return P.ok(e)}invert(){return new e(this.key,this.after,this.before)}map(){return this}},Rr=class e extends ke{id;before;after;selectionBefore;selectionAfter;constructor(e,t,n,r=null,i=null){super(),this.id=e,this.before=t,this.after=n,this.selectionBefore=r,this.selectionAfter=i}apply(e){return P.ok(e)}invert(){return new e(this.id,this.after,this.before,this.selectionAfter,this.selectionBefore)}map(){return this}merge(t){return t.id!==this.id||!zr(this.after,t.before)?null:new e(this.id,this.before,t.after,this.selectionBefore,t.selectionAfter)}};function zr(e,t){return e===t||!e&&!t||!!e&&!!t&&e.kind===t.kind&&e.noteType===t.noteType&&e.ext===t.ext&&(e.doc===t.doc||e.doc.eq(t.doc))}function Br({doc:e,...t}){return{...t,content:e.toJSON()}}function Vr(e,t,n){let r=t;for(let t of n)t instanceof Lr&&t.key===e&&(r=t.after);return r}function Hr(e,t,n,r){let i=X(e)?.envelope;return i?t.step(new Lr(n,Vr(n,i[n],t.steps),r)):t}function Ur(e,t){let n=new Map,r=new Map;for(let i of t)if(i instanceof Lr){let t=i.key;if(!u(n.has(t)?n.get(t):e.envelope[t],i.before))return!1;n.set(t,i.after)}else if(i instanceof Rr){if(!zr(r.has(i.id)?r.get(i.id):e.stories.get(i.id)??null,i.before))return!1;r.set(i.id,i.after)}return!0}function Wr(e,t,n){let r=X(e)?.stories.get(n)??null;for(let e of t.steps)e instanceof Rr&&e.id===n&&(r=e.after);return r}var Gr=new Qe(`storyBody`),Kr=e=>Gr.getState(e)??null;function qr(e,t,n){let r=X(e),i=n?{...r,envelope:n}:r;return nt.create({doc:t,plugins:[Xr(i.envelope,i)]})}function Jr(e){let t=[...X(e)?.stories.values()??[]].map(e=>e.doc),n=Kr(e)?.state.doc;return(n?[n,...t]:t).filter(t=>t!==e.doc)}function Yr(e){return new Map(Object.entries(e.stories??{}).map(([e,{content:t,...n}])=>[e,{...n,doc:kn(t,`stories[${JSON.stringify(e)}].content`)}]))}function Xr(e,t){let n=`${Date.now().toString(36)}${Math.random().toString(36).slice(2)}`,r=t??{envelope:e,resolver:new Mr(e),stories:Yr(e),id:n};return new $e({key:Nr,state:{init:()=>r,apply:(e,t)=>{let n=e.getMeta(Qr);if(n)return n;let r=e.getMeta(Nr),i=Fr(t.envelope.comments,e.steps),a=r??t.envelope,o=Vr(`section`,a.section,e.steps),s=Vr(`settings`,t.envelope.settings,e.steps),c=Vr(`controls`,a.controls,e.steps),{stories:l}=t,u=t.envelope.stories;for(let t of e.steps){if(!(t instanceof Rr))continue;let e=new Map(l),n={...u};t.after?(e.set(t.id,t.after),n[t.id]=Br(t.after)):(e.delete(t.id),delete n[t.id]),l=e,u=n}if(!r&&i===t.envelope.comments&&o===a.section&&s===t.envelope.settings&&c===t.envelope.controls&&l===t.stories)return t;let{stories:d,settings:f,controls:p,...m}=a,h={...m,section:o,comments:i,...u&&Object.keys(u).length?{stories:u}:{},...s?{settings:s}:{},...c?{controls:c}:{}};return{envelope:h,resolver:r?new Mr(h):t.resolver,stories:l,id:t.id}}}})}function Zr(e,t){return e.setMeta(Nr,t)}var Qr=`adoptWordContext`,$r=(e,t)=>e.setMeta(Qr,t),ei=e=>e.getMeta(Nr);function X(e){return Nr.getState(e)??null}var ti=Object.fromEntries(qe.map(e=>[e,null]));function ni(e){let t;for(let n of e.styles)n.type===`paragraph`&&n.isDefault&&(t=n.id);return t}function ri(e,t,n){let r=t.attrs,i=Object.keys(ti).some(e=>r[e]!==null)?{...r,...ti}:null;if(!n)return{before:i,after:r};let a=r.style??ni(e.envelope),o=e.envelope.styles.find(e=>e.id===a)?.next;return o===void 0||o===a?{before:i,after:r}:{before:i,after:{...Object.fromEntries(Object.keys(ti).map(e=>[e,r[e]??null])),controls:r.controls,style:o}}}var ii={bold:e=>e.bold,italic:e=>e.italic,underline:e=>e.underline!==null,strike:e=>e.strike,doubleStrike:e=>e.doubleStrike,caps:e=>e.caps,smallCaps:e=>e.smallCaps,hidden:e=>e.hidden};function ai(e,t){return e!==null&&Object.hasOwn(ii,t.name)}function oi(e,t,n,r,i=!0){let{run:a}=e.resolver.paragraph(t.attrs),o=n.filter(e=>i||e.type!==r).map(e=>e.toJSON());return ii[r.name](e.resolver.run(a,o))}function si(e,t,n,r){let i=r?.attrs.complexScript??null,a=Object.hasOwn(e.spec.attrs??{},`complexScript`);return t===n?a&&i!==null?e.create({value:null,complexScript:i}):null:e.name===`underline`?e.create({style:t?`single`:`none`}):e.create(a?{value:t,complexScript:i}:{value:t})}function ci(e,t,n,r){let i=[];e.doc.nodesBetween(t,n,(e,t,n)=>{if(e.isInline&&n?.type.allowsMarkType(r))return fi.has(e.type.name)||i.push({node:e,pos:t,parent:n}),!1});let a=i.filter(e=>e.node.isText);return a.length?{all:i,judged:a}:{all:i,judged:i}}function li(e,t,n,r){let{selection:i}=t;if(r)return oi(e,i.$from.parent,r,n);let a=i.ranges.flatMap(e=>ci(t,e.from,e.to,n).judged);return a.length>0&&a.every(t=>oi(e,t.parent,t.node.marks,n))}function ui(e,t,n,r){let i=!oi(e,t,n,r),a=r.isInSet(n),o=a?a.removeFromSet(n):n,s=si(r,i,oi(e,t,n,r,!1),a);return s?s.addToSet(o):o}function di(e,t,n,r,i,a){return ci(t,n,r,i).all.map(({node:t,pos:o,parent:s})=>({from:Math.max(n,o),to:Math.min(r,o+t.nodeSize),mark:si(i,a,oi(e,s,t.marks,i,!1),i.isInSet(t.marks))}))}var fi=new Set([`bookmarkStart`,`bookmarkEnd`,`commentStart`,`commentEnd`,`controlStart`,`controlEnd`,`fieldStart`,`fieldCode`,`fieldSeparator`,`fieldEnd`,`noteMark`,`commentReference`]);function pi(e,t){return e!==null&&!!t&&fi.has(t.type.name)}function mi(e,t){return e!==null&&!!t&&(t.type.name===`opaqueInline`||t.type.name===`opaqueBlock`)}function hi(e,t){let n=e.doc.nodeAt(t);return n&&We.isSelectable(n)?We.create(e.doc,t):R.create(e.doc,t)}var gi=new WeakMap,_i=e=>e.marks.some(e=>e.type.name===`deletion`);function vi(e){let t=gi.get(e);if(t)return t;let n=[],r=[],i=e=>{let t=r[r.length-1];t&&e&&(t.field.separator===null?t.code+=e:(t.broke&&(t.text+=`\r`),t.broke=!1,t.text+=e))};if(e.descendants((e,t)=>{if(e.isTextblock){for(let e of r)e.field.separator!==null&&(e.broke=!0);return!0}if(!e.isInline)return!0;let a=r[r.length-1];switch(e.type.name){case`fieldStart`:r.push({code:``,text:``,broke:!1,field:{from:t,to:t,separator:null,codeEnd:t,resultFrom:t,resultTo:t,instruction:``,name:``,result:``,locked:e.attrs.locked===!0,deleted:_i(e),codeMarks:null,resultMarks:null,parent:a?.field??null,inCode:!!a&&a.field.separator===null}});break;case`fieldCode`:a?.field.separator===null&&(a.code+=String(e.attrs.text??``),a.field.codeMarks??=e.marks);break;case`fieldSeparator`:a?.field.separator===null&&(a.field.separator=t);break;case`fieldEnd`:{let e=r.pop();if(!e)break;let{field:a}=e;a.to=t+1,a.codeEnd=a.separator??t,a.resultFrom=a.separator===null?t:a.separator+1,a.resultTo=t,a.instruction=e.code.trim(),a.name=(/^\S*/.exec(a.instruction)?.[0]??``).toUpperCase(),a.result=e.text,n.push(a),i(e.text);let o=r[r.length-1]?.field;o&&o.separator!==null&&(o.resultMarks??=a.resultMarks);break}case`text`:_i(e)||(i(e.text??``),a&&a.field.separator!==null&&(a.field.resultMarks??=e.marks));break;case`tab`:_i(e)||i(` `);break;case`hardBreak`:_i(e)||i(`
|
|
2
|
+
`)}return!1}),n.sort((e,t)=>e.from-t.from),r.length){let e=new Set(r.map(e=>e.field));for(let t of n)t.parent&&e.has(t.parent)&&(t.parent=null,t.inCode=!1)}return gi.set(e,n),n}function yi(e,t){let n=null;for(let r of vi(e)){if(r.from>=t)break;t<r.to&&(n=r)}return n}function bi(e,t){let n=null;for(let r of vi(e)){if(r.from>t)break;t<r.to&&(n=r)}return n}var xi=e=>!!e&&Si.has(e.type.name),Si=new Set([`fieldStart`,`fieldCode`,`fieldSeparator`,`fieldEnd`]),Ci={hidden:new Set,braces:new Map,gone:!1},wi=new Set([...Si,`bookmarkStart`,`bookmarkEnd`,`commentStart`,`commentEnd`,`commentReference`,`controlStart`,`controlEnd`]);function Ti(e,t){let n=(e,t)=>e*65536+t,r=new Map,i=[];if(e.forEach((e,t)=>{e.forEach((e,a)=>{if(e===`fieldStart`)i.push({at:n(t,a),separator:null});else if(e===`fieldSeparator`){let e=i[i.length-1];e&&e.separator===null&&(e.separator=n(t,a))}else if(e===`fieldEnd`){let e=i.pop();if(!e)return;r.set(e.at,`start`),e.separator!==null&&r.set(e.separator,`separator`),r.set(n(t,a),`end`)}})}),!r.size)return e.map(()=>Ci);let a=[],o=0,s=0,c=()=>t?s>0:o>0;return e.map((e,i)=>{let l=new Set,u=new Map,d=c(),f=!1;e.forEach((e,d)=>{let p=r.get(n(i,d));p===`start`?(t&&!s&&u.set(d,`{`),a.push(`code`),o++):p===`separator`?(o--,t&&!s&&u.set(d,`}`),s++,a[a.length-1]=`result`):p===`end`?a.pop()===`code`?(o--,t&&!s&&u.set(d,`}`)):s--:c()?l.add(d):(!wi.has(e)||t&&e===`fieldCode`)&&(f=!0)});let p=d&&c()&&!f&&!u.size;return l.size||u.size||p?{hidden:l,braces:u,gone:p}:Ci})}var Ei=new Qe(`fields`),Di=e=>Ei.getState(Kr(e)?.state??e)===!0;function Oi(e,t,n){return t>e.from&&(n?t<e.to:t<=e.codeEnd)}function ki(e,t,n,r){let i=t;for(let t=!0;t;){t=!1;for(let a of e)Oi(a,i,r)&&(i=n?r||a.separator===null?a.to:a.separator+1:a.from,t=!0)}return i}function Ai(e,t,n){let r=t;for(let t=!0;t;){t=!1;for(let i of e){if(i.separator===null||r<i.resultFrom||r>i.resultTo)continue;let e=r===i.resultTo&&(r!==i.resultFrom||n);(e||r===i.resultFrom)&&(r=e?i.to:i.from,t=!0)}}return r}function ji(e,t,n){let r=Math.min(t,n),i=Math.max(t,n);if(e.resolve(r).parent!==e.resolve(i).parent)return!1;let a=!1;return e.nodesBetween(r,i,e=>(e.isInline&&!wi.has(e.type.name)&&(a=!0),!a)),!a}function Mi(e,t,n){let{selection:r,doc:i}=e;if(!(r instanceof R))return null;let a=vi(i);if(!a.length)return null;let o=Di(e),s=r.head>=t.head,c=ki(a,r.head,s,o);r.empty&&n&&!o&&(c=Ai(a,c,s));let l=r.empty?c:ki(a,r.anchor,r.anchor>r.head,o);n&&!r.empty&&(!t.empty&&ji(i,c,t.head)&&(c=t.head),ji(i,l,t.anchor)&&(l=t.anchor));let u=(e,t)=>t>e.from&&t<e.to;if(l!==c)for(let e=!0,n=0;e&&n<64;n++){e=!1;for(let n of a)if(!(n.deleted||u(n,l)===u(n,c))){if(e=!0,u(n,l))l=c>n.from?n.from:n.to;else{let[e,r]=l<=n.from?[n.to,n.from]:[n.from,n.to],a=l<=n.from?t.head>=e:t.head<=e;c=!ji(i,c,e)&&a?r:e}}}return l===r.anchor&&c===r.head?null:R.create(i,l,c)}function Ni(){return new $e({key:Ei,state:{init:()=>!1,apply:(e,t)=>e.getMeta(Ei)??t},appendTransaction(e,t,n){if(t.selection.eq(n.selection)&&t.doc===n.doc&&Di(t)===Di(n))return null;let r=Mi(n,t.selection,t.doc===n.doc);return r?n.tr.setSelection(r):null}})}var Pi=(e,t)=>R.create(e,t.from,t.to),Fi=new Qe(`history`),Ii=`historyOp`,Li=`closeHistory`,Ri=`joinHistory`,zi=`storyEdit`,Bi={done:[],undone:[],prevTime:0,prevRanges:null};function Vi({newGroupDelay:e=500,depth:t=100}={}){return new $e({key:Fi,state:{init:()=>Bi,apply(n,r,i){let a=n.getMeta(Fi);if(a)return a;if(!n.docChanged)return r;let o=n.getMeta(`appendedTransaction`),s=o?.getMeta(Ii),c=n.steps.map((e,t)=>e.invert(n.docs[t])).reverse();if(s){let e=s===`undo`?r.undone:r.done,t=e[e.length-1],a=t?[...e.slice(0,-1),{steps:Hi(c,t.steps),selection:t.selection}]:[...e,{steps:c,selection:i.selection.toJSON()}];return s===`undo`?{...r,undone:a,done:Ji(r.done,n.mapping,n.doc)}:{...r,done:a,undone:Ji(r.undone,n.mapping,n.doc)}}if(!n.addToHistory||o&&!o.addToHistory)return{done:Ji(r.done,n.mapping,n.doc),undone:Ji(r.undone,n.mapping,n.doc),prevTime:0,prevRanges:null};let l=r.done[r.done.length-1],u=n.getMeta(zi);return{done:(l!==void 0&&(o!==void 0||n.getMeta(`joinHistory`)===!0||!n.getMeta(`closeHistory`)&&n.time-r.prevTime<e&&(r.prevStory??null)===(u?.id??null)&&Ui(r.prevRanges,u?.tr??n))?[...r.done.slice(0,-1),{steps:Hi(c,l.steps),selection:l.selection}]:[...r.done,{steps:c,selection:i.selection.toJSON()}]).slice(-t),undone:[],prevTime:o?r.prevTime:n.getMeta(`closeHistory`)?0:n.time,prevRanges:o?Gi(r.prevRanges,n.mapping):Wi(u?.tr??n),prevStory:o?r.prevStory??null:u?.id??null}}}})}function Hi(e,t){let n=e[e.length-1],r=t[0],i=n instanceof Ae&&r||n instanceof Rr&&r instanceof Rr?n.merge(r):null;return i?[...e.slice(0,-1),i,...t.slice(1)]:[...e,...t]}function Ui(e,t){let n=t.mapping.maps[0];if(!e||!n)return!1;let r=!1;return n.forEach((t,n)=>{for(let i=0;i<e.length;i+=2)t<=e[i+1]&&n>=e[i]&&(r=!0)}),r}function Wi(e){let t=[];return e.mapping.maps.forEach((n,r)=>{let i=e.mapping.slice(r+1);n.forEach((e,n,r,a)=>{t.push(i.map(r,-1),i.map(a,1))})}),t}function Gi(e,t){return e&&e.map((e,n)=>t.map(e,n%2?1:-1))}var Ki=class{base;inverted=[];rebased=[];constructor(e){this.base=e}push(e,t){this.inverted.push(e.getMap().invert()),this.rebased.push(t?t.getMap():null)}map(e,t=1){return this.mapResult(e,t).pos}mapResult(e,t=1){let n=!1,r=0,i=!1,a=[];for(let o=this.inverted.length-1;o>=0;o--){a[o]=this.inverted[o].sides(e);let s=this.inverted[o].mapResult(e,t),c=this.rebased[o];if(s.recover!==null&&c){e=c.recover(s.recover),r=o+1,i=!0;break}n||=s.deleted,e=s.pos}if(!i){let r=this.base.mapResult(e,t);n||=r.deleted,e=r.pos}for(let i=r;i<this.rebased.length;i++){let r=this.rebased[i]?.mapResult(e,t,a[i]);r&&(n||=r.deleted,e=r.pos)}return{pos:e,deleted:n,recover:null}}};function qi(e,t){let n=e.anchor<=e.head?-1:1,r=e.anchor===e.head?-1:-n;return{...e,anchor:t.map(e.anchor,n),head:t.map(e.head,r)}}function Ji(e,t,n){let r=new Ki(t),i=n,a=[];for(let t=e.length-1;t>=0;t--){let n=e[t],o=[];for(let e of n.steps){let t=e.map(r),n=t?.apply(i),a=n?.doc?t:null;a&&n?.doc&&(i=n.doc,o.push(a)),r.push(e,a)}o.length&&a.unshift({steps:o,selection:qi(n.selection,r)})}return a}function Yi(e,t){if(t instanceof Fe||t instanceof Ie){if(t.from<0||t.to>e.doc.content.size||t.from>=t.to)return!1;try{return t instanceof Fe?e.addMark(t.from,t.to,t.mark):e.removeMark(t.from,t.to,t.mark),!0}catch(e){if(e instanceof F)return!1;throw e}}return e.maybeStep(t).failed===null}function Xi(e){let t=(n,r)=>{let i=Kr(n);if(i)return r?i.run(t):i.can(t);let a=Fi.getState(n),o=a&&(e?a.undone:a.done),s=o?.[o.length-1];if(!a||!o||!s)return!1;if(r){let t=n.tr,i=X(n);if(i&&!Ur(i,s.steps)){let n=o.slice(0,-1);return t.setMeta(Fi,{done:e?a.done:n,undone:e?n:a.undone,prevTime:0,prevRanges:null}),r(t),!0}let c=null;for(let e of s.steps){let n=c?e.map(c):e,r=n!==null&&Yi(t,n);!r&&!c&&(c=new Ki(new Oe)),c?.push(e,r?n:null)}let l=c?qi(s.selection,c):s.selection;t.setSelection(L.fromJSON(t.doc,l));let u={steps:t.steps.map((e,n)=>e.invert(t.docs[n])).reverse(),selection:n.selection.toJSON()},d=o.slice(0,-1),f=u.steps.length?[u]:[];t.setMeta(Fi,{done:e?[...a.done,...f]:d,undone:e?d:[...a.undone,...f],prevTime:0,prevRanges:null}),t.setMeta(Ii,e?`redo`:`undo`),r(t)}return!0};return t}var Zi=Xi(!1),Qi=Xi(!0),$i=e=>e.type.name===`table`;function ea(e){for(let t=e.depth;t>0;t--)if(e.node(t).type.name===`tableCell`)return t;return-1}function ta(e,t){return e.depth>t&&$i(e.node(t+1))?t+1:-1}function na(e,t,n){let r=e.doc,i=r.resolve(t),a=r.resolve(n),o=ea(i),s=ea(a);if(o<0&&s<0||o>=0&&s>=0&&i.before(o)===a.before(s))return!1;let c=i.sharedDepth(n),l=i.node(c).type.name;if(l===`table`||l===`tableRow`)return ia(e,t,n,i.before(c+1),a.after(c+1)),!0;let u=ta(a,c),d=ta(i,c);if(u<0&&d<0)return!1;let f=n;if(u>=0){let t=a.node(u),n=a.before(u),r=a.index(u);if(r===t.childCount-1)e.delete(n,n+t.nodeSize);else{let i=n+1;for(let e=0;e<=r;e++)i+=t.child(e).nodeSize;e.delete(n+1,i)}f=n}let p=t,m=null;if(d>=0){let e=i.node(d),t=i.before(d),n=t+e.nodeSize,r=i.index(d);if(r===0)m=[t,n];else{let i=t+1;for(let t=0;t<r;t++)i+=e.child(t).nodeSize;m=[i,n-1]}p=n}return p<f&&ra(e,p,f),m&&e.delete(m[0],m[1]),!0}function ra(e,t,n){let r=e.doc.resolve(t),i=e.doc.resolve(n),a=[],o=t,s=n;r.parent.inlineContent&&(a.push([t,r.end()]),o=r.after()),i.parent.inlineContent&&(a.push([i.start(),n]),s=i.before()),o<s&&a.push([o,s]);for(let[t,n]of a.sort((e,t)=>t[0]-e[0]))t<n&&e.delete(t,n)}function ia(e,t,n,r,i){let a=[];e.doc.nodesBetween(r,i,(e,o)=>{let s=o>=r&&o+e.nodeSize<=i;return e.type.name!==`tableCell`||!s||(o<n&&o+e.nodeSize>t&&a.push({pos:o,node:e}),!1)}),aa(e,a.map(e=>e.pos))}function aa(e,t){for(let n of[...t].sort((e,t)=>t-e)){let t=e.doc.nodeAt(n);if(t?.type.name!==`tableCell`)continue;let r=!0;if(t.forEach(e=>{e.type.name!==`paragraph`&&(r=!1)}),r){let r=n+2,i=n+t.nodeSize-2;r<i&&e.delete(r,i);continue}let i=t.type.schema.nodes.paragraph?.create();i&&e.replace(n+1,n+t.nodeSize-1,new w(f.from(i),0,0))}}function oa(e){let t=e.doc.type.schema.nodes.paragraph;if(!t)return;let n=[],r=(e,t)=>{let i=t;e.forEach((t,a,o)=>{if($i(t)){let a=e.maybeChild(o+1);(a?$i(a):e.type.name===`doc`)&&n.push(i+t.nodeSize);let s=i+1;t.forEach(e=>{let t=s+1;e.forEach(e=>{r(e,t+1),t+=e.nodeSize}),s+=e.nodeSize})}i+=t.nodeSize})};r(e.doc,0);for(let r of n.reverse())e.insert(r,t.create())}function sa(e){let t=e.selection.$head,n=ea(t);return n<0?null:{$pos:t,depth:n}}function ca(e,t){let n=[],r=t+1;return e.forEach(e=>{let t=r+1;e.forEach(e=>{e.attrs.vMerge!==`continue`&&n.push(t),t+=e.nodeSize}),r+=e.nodeSize}),n}function la(e,t){let n=e.doc.nodeAt(t),r=L.near(e.doc.resolve(t+1),1).from,i=L.near(e.doc.resolve(t+n.nodeSize-1),-1).to;e.setSelection(R.create(e.doc,r,Math.max(r,i)))}function ua(e){return(t,n)=>{let r=sa(t);if(!r)return!1;let{$pos:i,depth:a}=r,o=a-2,s=i.node(o),c=i.before(o),l=ca(s,c),u=l[l.indexOf(i.before(a))+e];if(u!==void 0){if(n){let e=t.tr;la(e,u),n(e)}return!0}if(e<0)return!0;let d=da(s.lastChild);if(!d)return!1;let f=c+s.nodeSize-1;return I(t,n,e=>{e.insert(f,d),e.setSelection(R.create(e.doc,f+3))})}}function da(e){let t=e.type.schema.nodes.paragraph;if(!t)return null;let n={...e.attrs,revision:null,header:null,attributes:null},r=Object.fromEntries(qe.map(e=>[e,null])),i=[];return e.forEach(e=>{let n=e.firstChild,a=n?.type===t?{...n.attrs,...r}:null;i.push(e.type.create({...e.attrs,vMerge:null},t.create(a)))}),e.type.create(n,i)}function fa(){return new $e({keymap:{Tab:ua(1),"Shift-Tab":ua(-1)}})}function pa(e,t){let n=[],r=new Map,i=t+1;return e.forEach((e,t,a)=>{let o=e.attrs.gridBefore??0,s=i+1;e.forEach(e=>{let t=e.attrs.gridSpan??1,i=r.get(o);if(e.attrs.vMerge===`continue`&&i&&i.row+i.rowSpan===a)i.rowSpan++;else{let i={pos:s,row:a,rowSpan:1,column:o,span:t};n.push(i),e.attrs.vMerge===`restart`?r.set(o,i):r.delete(o)}o+=t,s+=e.nodeSize}),i+=e.nodeSize}),n}var ma=class e extends L{cells;constructor(e,t){super(e,t),this.cells=_a(e,t)}static create(t,n,r=n){return new e(t.resolve(n),t.resolve(r))}static valid(e,t,n){let r=e.resolve(t),i=e.resolve(n);return r.nodeAfter?.type.name===`tableCell`&&i.nodeAfter?.type.name===`tableCell`&&r.depth===i.depth&&r.before(r.depth-1)===i.before(i.depth-1)}get from(){return this.cells[0]??this.anchor}get to(){let e=this.cells[this.cells.length-1]??this.head;return e+(this.$head.doc.nodeAt(e)?.nodeSize??0)}get empty(){return!1}get ranges(){let e=this.$head.doc;return this.cells.map(t=>({from:t+1,to:t+(e.nodeAt(t)?.nodeSize??2)-1}))}map(t,n){let r=n.mapResult(this.anchor,1),i=n.mapResult(this.head,1);return!r.deleted&&!i.deleted&&e.valid(t,r.pos,i.pos)?e.create(t,r.pos,i.pos):L.near(t.resolve(Math.min(i.pos,t.content.size)))}toJSON(){return{type:`cell`,anchor:this.anchor,head:this.head}}};function ha(e,t,n,r){let i=t+1;for(let t=0;t<e.childCount;t++){let a=e.child(t),o=a.attrs.gridBefore??0,s=i+1;for(let e=0;e<a.childCount;e++){let i=a.child(e);if(s===r)return ga(n,t,o);o+=i.attrs.gridSpan??1,s+=i.nodeSize}i+=a.nodeSize}}var ga=(e,t,n)=>e.find(e=>e.row<=t&&t<e.row+e.rowSpan&&e.column<=n&&n<e.column+e.span);function _a(e,t){let n=e.depth-1,r=e.node(n),i=e.before(n),a=pa(r,i),o=e=>a.find(t=>t.pos===e)??ha(r,i,a,e),s=o(e.pos),c=o(t.pos);if(!s||!c)return[e.pos];let l=Math.min(s.row,c.row),u=Math.max(s.row+s.rowSpan,c.row+c.rowSpan)-1,d=Math.min(s.column,c.column),f=Math.max(s.column+s.span,c.column+c.span)-1,p=e=>e.row<=u&&e.row+e.rowSpan-1>=l&&e.column<=f&&e.column+e.span-1>=d;for(let e=!0;e;){e=!1;for(let t of a){if(!p(t))continue;let n=[Math.min(l,t.row),Math.max(u,t.row+t.rowSpan-1),Math.min(d,t.column),Math.max(f,t.column+t.span-1)];(n[0]!==l||n[1]!==u||n[2]!==d||n[3]!==f)&&([l,u,d,f]=n,e=!0)}}return a.filter(p).map(e=>e.pos)}L.kinds.set(`cell`,(e,t)=>{let n=t=>Math.max(0,Math.min(t,e.content.size)),r=n(t.anchor),i=n(t.head);return ma.valid(e,r,i)?ma.create(e,r,i):L.near(e.resolve(i))});var va=e=>JSON.stringify(e??null);function ya(e){let t=[];for(let{from:n,to:r}of e.selection.ranges)e.doc.nodesBetween(n,r,(e,n)=>e.type.name!==`paragraph`||(t.push({node:e,pos:n}),!1));return t}function ba(e,t,n,r){let i=ya(e).flatMap(({node:e,pos:t})=>{let r=n(e);return r&&va(r)!==va(e.attrs)?[new Le(t,e.type,r)]:[]});return i.length?I(e,t,e=>{e.step(new ze(i)),r&&Zr(e,r)}):!1}function xa(e){let[t]=e;return t!==void 0&&e.every(e=>va(e)===va(t))?t:null}function Sa(e,t,n=`paragraph`){let r=t.toLowerCase();return e.envelope.styles.find(e=>e.type===n&&e.name?.toLowerCase()===r)?.id??null}function Ca(e,t=`paragraph`){let n=null;for(let r of e.envelope.styles)r.type===t&&r.isDefault&&(n=r.id);return n}var wa=e=>/^Heading[1-9]$/.test(e)?`heading ${e.slice(7)}`:e===`ListParagraph`?`List Paragraph`:null;function Ta(e,t){let n=Ca(e),r=n?{basedOn:n}:{},i=/^heading ([1-9])$/.exec(t)?.[1];if(i){let e=Number(i),a=e>=8?{value:`272727`,themeColor:`text1`,themeTint:`D8`}:{...[3,6,7].includes(e)?{value:`1F3763`,themeShade:`7F`}:{value:`2F5496`,themeShade:`BF`},themeColor:`accent1`},o=[32,26,24,0,0,0,0,21,21][e-1];return{id:`Heading${e}`,type:`paragraph`,name:t,...r,...n?{next:n}:{},paragraph:{keepNext:!0,keepLines:!0,spacing:{before:e===1?240:40,after:0},outlineLevel:e-1},run:[{type:`font`,attrs:{asciiTheme:`majorHAnsi`,eastAsiaTheme:`majorEastAsia`,hAnsiTheme:`majorHAnsi`,csTheme:`majorBidi`}},...[4,7,9].includes(e)?[{type:`italic`,attrs:{complexScript:!0}}]:[],{type:`color`,attrs:a},...o?[{type:`fontSize`,attrs:{value:o,complexScript:o}}]:[]]}}let a=/^toc ([1-9])$/.exec(t)?.[1];if(a){let i=e.envelope.defaults.run?.find(e=>e.type===`fontSize`)?.attrs?.value,o=(Number(a)-1)*(typeof i==`number`?i*10:220);return{id:`TOC${a}`,type:`paragraph`,name:t,...r,...n?{next:n}:{},paragraph:{spacing:{after:100},...o?{indent:{left:o}}:{}}}}if(t===`List Paragraph`)return{id:`ListParagraph`,type:`paragraph`,name:t,...r,paragraph:{indent:{left:720},contextualSpacing:!0}};if(t===`Table Grid`){let n={style:`single`,size:4,space:0,color:`auto`},r=Sa(e,`Normal Table`,`table`);return{id:`TableGrid`,type:`table`,name:t,...r?{basedOn:r}:{},paragraph:{spacing:{after:0,line:240,lineRule:`auto`}},table:{borders:{top:n,left:n,bottom:n,right:n,insideH:n,insideV:n}}}}let o=/^(foot|end)note (text|reference)$/.exec(t),s=/^(Foot|End)note Text Char$/.exec(t);if(o||s){let n=Ca(e,`character`),i=n?{basedOn:n}:{},a={type:`fontSize`,attrs:{value:20,complexScript:20}},c=(o?.[1]??s?.[1]??``).toLowerCase()===`foot`?`Footnote`:`Endnote`;return s?{id:`${c}TextChar`,type:`character`,name:t,...i,link:`${c}Text`,run:[a]}:o?.[2]===`reference`?{id:`${c}Reference`,type:`character`,name:t,...i,run:[{type:`verticalAlign`,attrs:{value:`superscript`}}]}:{id:`${c}Text`,type:`paragraph`,name:t,...r,link:`${c}TextChar`,paragraph:{spacing:{after:0,line:240,lineRule:`auto`}},run:[a]}}if(t===`Placeholder Text`){let n=Ca(e,`character`);return{id:`PlaceholderText`,type:`character`,name:t,...n?{basedOn:n}:{},run:[{type:`color`,attrs:{value:`666666`}}]}}if(t===`Hyperlink`){let n=Ca(e,`character`);return{id:`Hyperlink`,type:`character`,name:t,...n?{basedOn:n}:{},run:[{type:`color`,attrs:{value:`0563C1`,themeColor:`hyperlink`}},{type:`underline`,attrs:{style:`single`}}]}}return null}function Ea(e,t,n=`paragraph`){let{envelope:r}=e,i=Sa(e,t,n);if(i)return{id:i,envelope:r};let a=Ta(e,t);if(!a)return null;let o=new Set(r.styles.map(e=>e.id)),s=a.id;for(let e=1;o.has(s);e++)s=`${a.id}${e}`;return{id:s,envelope:{...r,styles:[...r.styles,{...a,id:s}]}}}function Da(e){return(t,n)=>{let r=X(t);if(!r)return!1;if(r.envelope.styles.some(t=>t.id===e&&t.type===`paragraph`))return ka(t,n,r,{id:e,envelope:r.envelope});let i=wa(e);return!!i&&Oa(i)(t,n)}}function Oa(e){return(t,n)=>{let r=X(t),i=r&&Ea(r,e);return!!i&&ka(t,n,r,i)}}function ka(e,t,n,r){let i=r.id===Ca(n)?null:r.id;return ba(e,t,e=>({...e.attrs,style:i}),r.envelope===n.envelope?void 0:r.envelope)}function Aa(e,t){let n=X(e),r=[];for(let{from:i,to:a}of e.selection.ranges)e.doc.nodesBetween(i,a,(e,i,a)=>{if(e.isInline&&a?.type.allowsMarkType(t))return pi(n,e)||r.push({node:e,pos:i,parent:a}),!1});return r}function ja(e,t,n,r){let{run:i}=e.resolver.paragraph(t.attrs);return e.resolver.run(i,n.filter(e=>e.type!==r).map(e=>e.toJSON()))}function Ma(e,t){return(n,r)=>{let i=X(n),a=n.schema.marks[e];if(!i||!a)return!1;let{selection:o}=n;if(o.empty&&o instanceof R){let{$from:e}=o;if(!e.parent.type.allowsMarkType(a))return!1;let s=n.storedMarks??Ke(e),c=t(a.isInSet(s),ja(i,e.parent,s,a),a),l=a.removeFromSet(s);return r?.(n.tr.setStoredMarks(c?c.addToSet(l):l)),!0}let s=Aa(n,a);return s.length?I(n,r,e=>{for(let{node:n,pos:r,parent:c}of s){let s=Math.max(o.from,r),l=Math.min(o.to,r+n.nodeSize),u=a.isInSet(n.marks),d=t(u,ja(i,c,n.marks,a),a);(d?u?.eq(d):!u)||(e.removeMark(s,l,a),d&&e.addMark(s,l,d))}}):!1}}var Na=e=>e.slice(1).toUpperCase(),Pa={black:`#000000`,blue:`#0000ff`,cyan:`#00ffff`,green:`#00ff00`,magenta:`#ff00ff`,red:`#ff0000`,yellow:`#ffff00`,white:`#ffffff`,darkBlue:`#000080`,darkCyan:`#008080`,darkGreen:`#008000`,darkMagenta:`#800080`,darkRed:`#800000`,darkYellow:`#808000`,darkGray:`#808080`,lightGray:`#c0c0c0`};function Fa(e){return Ma(`color`,(t,n,r)=>e===null?n.color===null?null:r.create({value:`auto`}):n.color===Na(e)?null:r.create({value:Na(e)}))}function Ia(e){return(t,n)=>{let r=e?Object.keys(Pa).find(t=>Pa[t]===e.toLowerCase()):void 0;if(e===null||r){let e=Ma(`highlight`,(e,t,n)=>r?t.highlight===r?null:n.create({value:r}):t.highlight===null?null:n.create({value:`none`}));return r?e(t,n):Ra(t,n,[e,Ma(`shading`,e=>e?.attrs.pattern===`clear`&&e.attrs.color===`auto`?null:e??null)])}return Ra(t,n,[La(`highlight`),Ma(`shading`,(t,n,r)=>r.create({pattern:`clear`,color:`auto`,fill:Na(e)}))])}}function La(e){return Ma(e,()=>null)}function Ra(e,t,n){let r=e,i=null;for(let e of n)e(r,e=>{if(!i)i=e;else{for(let t of e.steps)i.step(t);e.storedMarks!==r.storedMarks&&i.setStoredMarks(e.storedMarks)}r=r.apply(e)});return i?(t?.(i),!0):!1}var za={start:`left`,center:`center`,end:`right`,justify:`both`};function Ba(e){return e===null||e===`left`||e===`start`?`start`:e===`center`?`center`:e===`right`||e===`end`?`end`:e===`both`||e===`distribute`?`justify`:null}function Va(e,t,n,r,i){let a={...t.attrs,[n]:null},o=e.resolver.paragraph(a).paragraph;return i(o)?a:{...t.attrs,[n]:r}}function Ha(e){return(t,n)=>{let r=X(t);return r?ba(t,n,t=>Va(r,t,`justification`,za[e],t=>Ba(t.justification)===e)):!1}}var Ua=720;function Wa(e){return(t,n)=>{let r=X(t);return r?ba(t,n,t=>{let{paragraph:n}=r.resolver.paragraph(t.attrs);if(n.numbering){let{id:i}=n.numbering,a=n.numbering.level+e;if(a<0)return qa(r,t);let o=Za(r,i,a);if(!o)return null;let s=o.style;return s&&r.envelope.styles.some(e=>e.id===s)?{...t.attrs,style:s,numbering:t.attrs.numbering?{id:i,level:a}:null}:{...t.attrs,numbering:{id:i,level:a}}}let i=n.indent.left,a=e>0?(Math.floor(i/Ua)+1)*Ua:(Math.ceil(i/Ua)-1)*Ua;if(a<0||a>31680)return null;let o=t.attrs.indent??{};return{...t.attrs,indent:{...o,left:a}}}):!1}}function Ga(e,t){let n=e.resolver.numberFormat(t);return n===null||n===`none`?null:n===`bullet`?`bulletList`:`orderedList`}function Ka(e){let t=X(e);if(!t)return null;let n=ya(e).map(({node:e})=>Ga(t,e.attrs));return n.length?xa(n):null}function qa(e,t){let n={...t.attrs,numbering:null},r=e.resolver.paragraph(n).paragraph.numbering!==null,i=Sa(e,`List Paragraph`),a=i!==null&&t.attrs.style===i?null:t.attrs.style;return{...n,style:a,numbering:r?{id:0}:null}}function Ja(e){let t=[[``,`Symbol`],[`o`,`Courier New`],[``,`Wingdings`]],n=[`decimal`,`lowerLetter`,`lowerRoman`];return Array.from({length:9},(r,i)=>{let a={indent:{left:Ua*(i+1),hanging:360}};if(e===`bulletList`){let[e,n]=t[i%3];return{level:i,start:1,format:`bullet`,text:e,justification:`left`,paragraph:a,run:[{type:`font`,attrs:{ascii:n,hAnsi:n,hint:`default`}}]}}return{level:i,start:1,format:n[i%3],text:`%${i+1}.`,justification:i%3==2?`right`:`left`,paragraph:i%3==2?{indent:{left:Ua*(i+1),hanging:180}}:a}})}var Ya=e=>!e.styleLink&&!e.numStyleLink&&!e.levels.some(e=>e.style);function Xa(e,t){let{abstracts:n,instances:r}=e.envelope.numbering;return n.find(e=>e.id===r.find(e=>e.id===t)?.abstract)}function Za(e,t,n){return Xa(e,t)?.levels.find(e=>e.level===n)}function Qa(e,t){let n=Xa(e,t);return!!n&&Ya(n)}function $a(e,t){let{abstracts:n,instances:r}=e.numbering,i=e=>e.levels.find(e=>e.level===0)?.format,a=t===`bulletList`?r.find(e=>{let t=n.find(t=>t.id===e.abstract);return t&&Ya(t)&&i(t)===`bullet`&&!e.overrides?.length}):void 0;if(a)return{id:a.id,envelope:e};let o=e=>Math.max(0,...e)+1,s=n.find(e=>Ya(e)&&i(e)===(t===`bulletList`?`bullet`:`decimal`)),c=[];s||(s={id:Math.max(-1,...n.map(e=>e.id))+1,multiLevelType:`hybridMultilevel`,levels:Ja(t)},c.push(s));let l={id:o(r.map(e=>e.id)),abstract:s.id,...t===`orderedList`?{overrides:[{level:0,start:1}]}:{}};return{id:l.id,envelope:{...e,numbering:{abstracts:[...n,...c],instances:[...r,l]}}}}function eo(e){return(t,n)=>{let r=X(t);return!r||!ya(t).length?!1:Ka(t)===e?ba(t,n,e=>qa(r,e)):to(e)(t,n)}}function to(e){return(t,n)=>{let r=X(t);if(!r)return!1;let i=ya(t),a=i[0];if(!a)return!1;let o=a.pos>0?t.doc.resolve(a.pos).nodeBefore:null,s=o?.attrs.numbering?.id,c=Ca(r),l=e=>{let t=r.resolver.paragraph(e.attrs).paragraph.style;return t===c||t===null},u=i.some(({node:e})=>l(e))?Ea(r,`List Paragraph`):null,d=u?.id??null,f=u?.envelope??r.envelope,p;return s&&o&&Ga(r,o.attrs)===e&&Qa(r,s)?p=s:{id:p,envelope:f}=$a(f,e),ba(t,n,e=>{let t=r.resolver.paragraph(e.attrs).paragraph.numbering?.level??0,n=d&&l(e)?d:e.attrs.style;return{...e.attrs,style:n,numbering:{id:p,level:t}}},f===r.envelope?void 0:f)}}function no(e,t,n){let{selection:r}=e;if(!r.empty)return null;let{$from:i}=r;return i.parent.type.name!==`paragraph`||n&&i.parentOffset>0?null:t.resolver.paragraph(i.parent.attrs).paragraph.numbering?i.parent:null}var ro=(e,t)=>{let n=X(e);return!n||ya(e).length<2&&!no(e,n,!0)?!1:Wa(1)(e,t)},io=(e,t)=>{let n=X(e);return n?ya(e).some(({node:e})=>n.resolver.paragraph(e.attrs).paragraph.numbering)&&Wa(-1)(e,t):!1},ao=(e,t)=>{let n=X(e),r=n&&no(e,n,!0);return!n||!r||r.content.size?!1:Wa(-1)(e,t)},oo=(e,t)=>{let n=X(e),r=n&&no(e,n,!0);return!n||!r?!1:ba(e,t,e=>{let{indent:t}=n.resolver.paragraph(e.attrs).paragraph;return{...qa(n,e),indent:{left:t.left,right:t.right,firstLine:0}}})};function so(e,t,n,r){let i=X(t),a=t.schema.marks.characterStyle,o=i&&a&&Ea(i,`Hyperlink`,`character`);i&&a&&o&&(e.addMark(n,r,a.create({id:o.id})),o.envelope!==i.envelope&&Zr(e,o.envelope))}function co(e,t,n,r){let i=X(t),a=t.schema.marks.characterStyle,o=i&&Sa(i,`Hyperlink`,`character`);o&&a&&e.doc.nodesBetween(n,r,(t,i)=>{a.isInSet(t.marks)?.attrs.id===o&&e.removeMark(Math.max(n,i),Math.min(r,i+t.nodeSize),a)})}var lo=/^[^\s@/:]+@[^\s@/:]+\.\p{L}{2,}$/iu,uo=/^(?:www\.|(?:[\p{L}\p{N}-]+\.)+\p{L}{2,}(?:[:/?#]|$))/iu;function fo(e){let t=e.trim().replace(/\\/g,`/`).replace(/ /g,`%20`);return lo.test(t)?`mailto:${t}`:uo.test(t)?`https://${t}`:t}var po=e=>e.schema.marks.link;function mo(e,t){let n=e.parent;if(!n.inlineContent)return null;let r=e.index();for(let i of e.textOffset?[r]:[r-1,r]){let r=t.isInSet(n.maybeChild(i)?.marks??[]);if(!r)continue;let a=i,o=i+1;for(;a>0&&r.isInSet(n.child(a-1).marks);)a--;for(;o<n.childCount&&r.isInSet(n.child(o).marks);)o++;let s=e.start(),c=s;for(let e=0;e<o;e++){let t=n.child(e).nodeSize;e<a&&(s+=t),c+=t}return{from:s,to:c,mark:r}}return null}function ho(e,t){let{selection:n}=e;if(n.empty){let{parent:e}=n.$from;return e.inlineContent&&e.type.allowsMarkType(t)}let r=!1;for(let{from:i,to:a}of n.ranges)e.doc.nodesBetween(i,a,e=>(e.isTextblock&&e.type.allowsMarkType(t)&&(r=!0),!r));return r}function go(e,t){return(n,r)=>{let i=po(n),a=fo(e),o=t??a,{selection:s}=n;if(!i||!o||!le(a)||s instanceof ma||!(s instanceof Ge)&&!ho(n,i))return!1;let c=i.create({href:a});return I(n,r,e=>{let t=n.storedMarks??Ke(s.$from);e.deleteSelection();let r=e.selection.from,a=e.doc.resolve(r).parent;if(!a.inlineContent||!a.type.allowsMarkType(i))throw new F(`No link here`);let l=t.filter(e=>a.type.allowsMarkType(e.type));e.insertText(o,r,r,c.addToSet(l)),so(e,n,r,r+o.length),e.setSelection(R.create(e.doc,r+o.length))})}}function _o(e){return(t,n)=>{let r=po(t),i=fo(e);if(!r||!le(i)||!ho(t,r))return!1;let a=r.create({href:i}),{selection:o}=t;if(!o.empty)return I(t,n,e=>{for(let{from:n,to:r}of o.ranges)e.addMark(n,r,a),so(e,t,n,r)});let s=mo(o.$from,r);return s?I(t,n,e=>e.addMark(s.from,s.to,a)):go(i)(t,n)}}var vo=(e,t)=>{let n=po(e);if(!n)return!1;let{selection:r}=e,i=r.empty&&mo(r.$from,n),a=r.empty?i?[i]:[]:r.ranges;return a.length?I(e,t,t=>{for(let r of a)t.removeMark(r.from,r.to,n),co(t,e,r.from,r.to)}):!1},yo=`linkEditorRequest`,bo=(e,t)=>{let n=po(e);return!n||!ho(e,n)?!1:(t?.(e.tr.setMeta(yo,!0)),!0)},xo=new Qe(`track`),So=`untracked`,Co=`trackedDeletes`,wo=new Set([`bookmarkStart`,`bookmarkEnd`,`commentStart`,`commentEnd`,`controlStart`,`controlEnd`]),To=new Set(cn),Eo=new Set([`markFormat`,`ext`]),Do=dn.filter(e=>!Eo.has(e)),Oo=e=>Object.fromEntries(Do.filter(t=>e[t]!=null).map(t=>[t,e[t]])),ko=(e,t)=>Do.every(n=>u(e[n]??null,t[n]??null));function Ao(e){return new $e({key:xo,state:{init:()=>e,apply:(e,t)=>e.getMeta(xo)??t}})}function jo(e){return xo.getState(e)??null}var Mo=(e,t)=>e.setMeta(xo,t);function No(e,t){return(n,r)=>{let i=xo.getState(n);return!i||!n.schema.marks.insertion?!1:(r?.(n.tr.setMeta(xo,{...i,on:e,author:t??i.author})),!0)}}function Po(e){return(t,n)=>{let r=xo.getState(t);return!r||!t.schema.marks.insertion?!1:(n?.(t.tr.setMeta(xo,{...r,view:e})),!0)}}function Fo(){return new Date().toISOString().replace(/\.\d+Z$/,`Z`)}var Io=new Set([`insertion`,`deletion`,`formatChange`]);function Lo(e){let t=-1,n=e=>{let n=e?.id;typeof n==`number`&&n>t&&(t=n)};return e.descendants(e=>{for(let t of e.marks)Io.has(t.type.name)&&n(t.attrs);if(e.isTextblock){let t=e.attrs.revision;n(t?.insertion),n(t?.deletion),n(e.attrs.formatChange),n(e.attrs.section?.change)}return!0}),t}function Ro(e){let t=X(e)?.envelope,n=t?.comments??[],r=t?.section,i=-1,a=e=>{let t=e?.id;typeof t==`number`&&t>i&&(i=t)};a(r?.change);for(let t of[e.doc,...Jr(e)])i=Math.max(i,Lo(t));let o=e=>{if(Array.isArray(e))e.forEach(o);else if(e&&typeof e==`object`){let t=e;Io.has(t.type)&&a(t.attrs),t.type===`paragraph`&&a(t.attrs?.formatChange);let n=t.revision;n&&typeof n==`object`&&(a(n.insertion),a(n.deletion)),Object.values(t).forEach(o)}};return o(n.map(e=>e.content)),i}function zo(e){return Ro(e)+1}function Bo(e){let t=e.mapping.maps,n=[];t.forEach((r,i)=>{if(!r.ranges.length)return;let a=new Oe(t.slice(0,i).map(e=>e.invert()).reverse()),o=e.mapping.slice(i+1);r.forEach((e,t,r,i)=>{let s=a.map(e,-1),c=o.map(r,-1);n.push({a:s,b:Math.max(s,a.map(t,1)),c,d:Math.max(c,o.map(i,1))})})}),n.sort((e,t)=>e.a-t.a);let r=[];for(let e of n){let t=r[r.length-1];t&&e.a<=t.b?(t.b=Math.max(t.b,e.b),t.c=Math.min(t.c,e.c),t.d=Math.max(t.d,e.d)):r.push({...e})}return r}function Vo(e,t){let n=xo.getState(e),{insertion:r,deletion:i}=e.schema.marks;if(!n?.on||!r||!i||!t.docChanged||t.getMeta(`untracked`)||t.getMeta(`historyOp`)||!t.addToHistory)return t;try{return Ho(e,t,n.author,r,i)}catch(e){if(e instanceof F)return null;throw e}}function Ho(e,t,n,r,i){let a=e.tr.copyMeta(t);a.setMeta(Co,Bo(t).filter(e=>e.b>e.a).map(e=>[e.a,e.b]));let o=Fo(),s=-1,c=()=>(s<0&&(s=Math.max(Ro(e)+1,t.getMeta(`revisionFloor`)??0)),s++),l=(e,t)=>a.mapping.slice(e.step).map(e.pos,t),d=e=>({pos:e,step:a.steps.length}),f=[],p=[],m=[],h=[],g=(e,t,o)=>{let s=a.doc;for(let a of[s.resolve(t).nodeBefore,s.resolve(o).nodeAfter]){let t=a&&e.isInSet(a.marks),o=e===r?i:r;if(t&&t.attrs.author===n&&!o.isInSet(a.marks))return t}},_=e=>({id:e.attrs.id,author:n,date:e.attrs.date??o}),v=(e,t,s)=>{let u=a.doc,h=a.steps.length,v,y=()=>v??=g(i,e,t)??i.create({id:c(),author:n,date:o}),b=[],x=[],S=[],C=new Map,w=null,ee=!1,te=[];u.nodesBetween(e,t,(a,o)=>{if(a.isTextblock){let r=o+a.nodeSize,c=w??o,l=a.attrs.revision,m=e<r&&t>r||e<=o&&t>=r&&(s||!!u.resolve(r).nodeAfter);return m&&!l?.deletion&&l?.insertion?.author===n&&u.resolve(r).nodeAfter?.isTextblock?(b.push([r-1,r+1]),w===null&&(ee=!1,a.forEach((t,n)=>{!wo.has(t.type.name)&&!i.isInSet(t.marks)&&o+1+n<e&&(ee=!0)})),w=c,!0):(w!==null&&te.push({at:d(w),node:a,live:ee}),w=null,m&&p.push(d(c)),m&&!l?.deletion&&f.push({at:d(c),kind:`deletion`,revision:_(y())}),!0)}if(a.type.name===`tableRow`&&e<=o&&t>=o+a.nodeSize){let e=a.attrs.revision;if(e?.insertion?.author===n&&!e.deletion){let e=u.resolve(o).before();C.set(e,[...C.get(e)??[],[o,o+a.nodeSize]])}else e?.deletion||S.push({pos:o,node:a});return!1}if([`table`,`tableRow`,`tableCell`].includes(a.type.name))return!0;if(!a.isInline)throw new F(`This content cannot be deleted as a tracked change`);let c=Math.max(o,e),l=Math.min(o+a.nodeSize,t);if(c>=l||wo.has(a.type.name)||i.isInSet(a.marks))return!1;let m=r.isInSet(a.marks);return(m&&m.attrs.author===n?b:x).push([c,l]),!1});for(let[e,t]of C){let n=u.nodeAt(e);n&&t.length===n.childCount?b.push([e,e+n.nodeSize]):b.push(...t)}for(let[e,t]of Uo(x))a.addMark(e,t,y());for(let{pos:e,node:t}of S){let n=t.attrs.revision??{},r=_(y());a.step(new Le(e,t.type,{...t.attrs,revision:{...n,deletion:r}},t.marks))}for(let[e,t]of Uo(b).reverse())a.delete(e,t);for(let{at:e,node:t,live:r}of te){let i=l(e,1),s=a.doc.nodeAt(i);if(!s?.isTextblock)continue;if(!r){a.step(new Le(i,t.type,t.attrs,s.marks)),m.push(d(i));continue}let u={...s.attrs};for(let e of qe)u[e]=t.attrs[e]??null;let f=t.attrs.revision;!u.formatChange&&f?.insertion?.author!==n&&!ko(u,t.attrs)&&(u.formatChange={id:c(),author:n,date:o,previous:Oo(t.attrs)});let p=u.formatChange;p?.author===n&&ko(u,p.previous)&&(u.formatChange=null),a.step(new Le(i,s.type,u,s.marks)),m.push(d(i))}let T=a.mapping.slice(h);return{start:d(T.map(e,-1)),end:d(T.map(t,1))}},y=Bo(t),b=[];for(let s of[...y].reverse()){let l=t.doc.slice(s.c,s.d),u=l.content.firstChild,p=s.a===0&&s.b===e.doc.content.size&&!l.openStart&&l.content.childCount===1&&u?.isTextblock&&!u.content.size,{start:m,end:y}=s.a<s.b?v(s.a,s.b,l.size>0&&!p):{start:d(s.a),end:d(s.a)},x=null,S=y.pos;if(l.size&&!p){let e=a.doc.resolve(S).parent,t=g(r,S,S)??r.create({id:c(),author:n,date:o}),s=Wo(l.content,t,r,i);a.replace(S,S,new w(s,l.openStart,l.openEnd)),x=d(S);let u=l.size,p=[];a.doc.nodesBetween(S,S+u,(e,n)=>{if(e.type.name===`tableRow`&&n>=S&&n+e.nodeSize<=S+u&&p.push(n),!e.isTextblock)return!e.isInline;let r=n+e.nodeSize-1;return r>=S&&r<S+u&&f.push({at:d(n),kind:`insertion`,revision:_(t)}),!1});for(let e of p){let n=a.doc.nodeAt(e);if(!n)continue;let r=n.attrs.revision??{};r.insertion||a.step(new Le(e,n.type,{...n.attrs,revision:{...r,insertion:_(t)}},n.marks))}let m=a.doc.resolve(S+u);l.openEnd&&e.isTextblock&&m.parent.isTextblock&&m.depth>0&&h.push({at:d(m.before()),host:e})}b.unshift({range:s,start:m,end:y,inserted:x})}let x=(e,t)=>{let n=0;for(let{range:r,start:i,end:a,inserted:o}of b){let{a:s,b:c,c:u,d}=r;if(e<u)break;if(e<=d)return o?l(o,-1)+(e-u):u===d&&t<0?l(i,-1):l(a,1);n+=d-u-(c-s)}return a.mapping.map(e-n,t)},S=e.schema.marks.formatChange,C=e=>r.isInSet(e.marks)?.attrs.author===n,ee=e=>{if(!S||!To.has(e.mark.type.name))return;let t=[];a.doc.nodesBetween(e.from,e.to,(n,r)=>{if(!n.isInline)return!0;if(wo.has(n.type.name)||S.isInSet(n.marks)||C(n))return!1;let i=e.mark.isInSet(n.marks);if(e instanceof Fe?i:!i)return!1;let a=JSON.stringify(n.marks.filter(e=>To.has(e.type.name)).map(e=>e.toJSON())),o=Math.max(r,e.from),s=Math.min(r+n.nodeSize,e.to),c=t[t.length-1];return c&&c.to===o&&c.previous===a?c.to=s:t.push({from:o,to:s,previous:a}),!1});for(let{from:e,to:r,previous:i}of t){let t={id:c(),author:n,date:o,previous:JSON.parse(i)};a.addMark(e,r,S.create(t))}},te=e=>{let t=a.doc.nodeAt(e.pos),r=e.attrs;if(!t?.isTextblock||!r||t.type!==e.type||ko(t.attrs,r))return e;if(t.attrs.formatChange){if(u(r.formatChange??null,t.attrs.formatChange))return e;let n={...r,formatChange:t.attrs.formatChange};return new Le(e.pos,e.type,n,e.marks)}if(t.attrs.revision?.insertion?.author===n)return e;let i={id:c(),author:n,date:o,previous:Oo(t.attrs)};return new Le(e.pos,e.type,{...r,formatChange:i},e.marks)};t.steps.forEach((e,n)=>{if(e.getMap().ranges.length)return;let r=t.mapping.slice(n+1),i=e.map({map:(e,t=1)=>x(r.map(e,t),t),mapResult:(e,t=1)=>{let n=r.mapResult(e,t);return{pos:x(n.pos,t),deleted:n.deleted,recover:null}}}),o=new Set([...p,...m].map(e=>l(e,1)));if(i instanceof Le&&o.has(i.pos)&&(i=null),i instanceof ze){let e=i.steps.filter(e=>!o.has(e.pos));i=e.length?new ze(e):null}(i instanceof Fe||i instanceof Ie)&&ee(i),i instanceof Le&&(i=te(i)),i instanceof ze&&(i=new ze(i.steps.map(te))),i&&a.step(i)});for(let{at:e,host:t}of h){let r=l(e,1),i=a.doc.nodeAt(r),s=i?.attrs.revision;if(!i?.isTextblock||i.attrs.formatChange||s?.insertion?.author===n||ko(i.attrs,t.attrs))continue;let u={id:c(),author:n,date:o,previous:Oo(t.attrs)};a.step(new Le(r,i.type,{...i.attrs,formatChange:u},i.marks))}let T=new Set;for(let{at:e,kind:t,revision:n}of f){let r=l(e,1),i=a.doc.nodeAt(r);if(!i?.isTextblock||T.has(r*2+ +(t===`insertion`)))continue;T.add(r*2+ +(t===`insertion`));let o=i.attrs.revision??{},s=t===`insertion`?{insertion:n}:{...o,deletion:n};a.step(new Le(r,i.type,{...i.attrs,revision:s}))}let E=y.length===1?y[0]:void 0,D=e.selection.empty&&E!==void 0&&E.c===E.d&&e.selection.head===E.b?-1:1,O=t.selection,k=x(O.anchor,D),ne=x(O.head,D);return O instanceof We&&a.doc.nodeAt(k)?.type===O.node.type?a.setSelection(We.create(a.doc,k)):O instanceof R?a.setSelection(R.create(a.doc,k,ne)):O.toJSON().type===`cell`?a.setSelection(L.fromJSON(a.doc,{type:`cell`,anchor:k,head:ne})):a.setSelection(L.near(a.doc.resolve(ne))),t.storedMarks&&a.setStoredMarks(t.storedMarks.filter(e=>e.type!==r&&e.type!==i)),a}function Uo(e){let t=[];for(let[n,r]of[...e].sort((e,t)=>e[0]-t[0])){let e=t[t.length-1];e&&n<=e[1]?e[1]=Math.max(e[1],r):t.push([n,r])}return t}function Wo(e,t,n,r){let i=[];return e.forEach(e=>{if(e.isInline){if(wo.has(e.type.name))i.push(e);else{let a=e.marks.filter(e=>e.type!==n&&e.type!==r);i.push(e.mark(t.addToSet(a)))}return}let a=[`table`,`tableRow`,`tableCell`].includes(e.type.name);if(!e.isTextblock&&!a)throw new F(`This content cannot be inserted as a tracked change`);i.push(e.copy(Wo(e.content,t,n,r)))}),f.fromArray(i)}var Go={width:12240,height:15840,margin:1440},Ko=720;function qo(e){let{columns:t={}}=e,n=t.separator===!0,r=t.space??Ko,i=t.equalWidth===!1?t.widths:void 0;if(i?.length)return{widths:i.map(e=>e.width),gaps:i.slice(0,-1).map(e=>e.space??r),separator:n};let a=Math.max(t.count??1,1),o=Math.max((Jo(e)-r*(a-1))/a,1);return{widths:Array.from({length:a},()=>o),gaps:Array.from({length:a-1},()=>r),separator:n}}function Jo({pageSize:e,margins:t={}}){return(e?.width??Go.width)-(t.left??Go.margin)-(t.right??Go.margin)-(t.gutter??0)}function Yo(e){return Object.fromEntries(Object.entries(e).filter(([,e])=>e!==void 0))}function Xo(e,t){let n=null;return e.forEach((e,r)=>{!n&&r+e.nodeSize>t&&e.attrs.section&&(n={pos:r,node:e})}),n}function Zo(e,t){let n=X(e)?.envelope.section??{};for(let e of t.steps)e instanceof Lr&&e.key===`section`&&(n=e.after);return n}function Qo(e,t,n,r){n?t.setNodeMarkup(n.pos,n.node.type,{...n.node.attrs,section:r}):Hr(e,t,`section`,r)}function $o(e,t,n,r){let i=Xo(t.doc,r),a=i?i.node.attrs.section:Zo(e,t),o=(e,t)=>e||t?{...t,...e}:void 0;Qo(e,t,i,Yo({...a,type:n.type,headers:o(a.headers,n.headers),footers:o(a.footers,n.footers)}))}var es={header:`headers`,footer:`footers`};function ts(e,t,n,r){for(let i=Math.min(t,e.length-1);i>=0;i--){let t=e[i]?.[es[n]]?.[r];if(t)return{id:t,section:i}}return null}function ns(e,t,n){return e.titlePage&&t.first?`first`:n&&t.number%2==0?`even`:`default`}function rs(e,t){let{change:n,...r}=e;return t||!n?r:Yo({...n.previous,headers:e.headers,footers:e.footers,ext:e.ext})}var is=`
|
|
3
|
+
`,as=new Intl.Segmenter(void 0,{granularity:`grapheme`}),os=new Intl.Segmenter(void 0,{granularity:`word`});function ss(e,t){return t===e.selection.head?e:e.apply(e.tr.setSelection(R.create(e.doc,t)))}function cs(e){let{selection:t}=e;return t.empty&&t instanceof R?t.$head:null}var ls=(e,t)=>!e.selection.empty&&I(e,t,e=>us(e));function us(e,t=!1){let n=e.selection;if(n instanceof ma){let r=n.anchor;aa(e,t?[r]:n.cells),e.setSelection(L.near(e.doc.resolve(e.mapping.map(r,1)+1),1));return}let{from:r,to:i}=n;na(e,r,i)?e.setSelection(L.near(e.doc.resolve(e.mapping.map(r,-1)),1)):e.deleteSelection(),oa(e)}function ds(e){return(t,n)=>{if(!e)return!1;let{selection:r}=t;return Cs(t)?ws(t,n,t.schema.text(e,t.storedMarks??[])):!(r instanceof Ge)&&!(r instanceof ma)&&!r.$from.parent.inlineContent?!1:I(t,n,n=>{let i=r instanceof ma?L.near(t.doc.resolve(r.anchor+1),1).$from:r.$from,a=t.storedMarks??(r.empty?Ke(i):i.nodeAfter?.marks??Ke(i));r.empty||us(n,!0);let o=n.selection.$from;if(!o.parent.inlineContent)throw new F(`No text where the selection was`);let s=Ze(a).filter(e=>o.parent.type.allowsMarkType(e.type));n.insertText(e,o.pos,o.pos,s),n.setSelection(R.create(n.doc,o.pos+e.length))})}}function fs(e,t,n=!1){let r=0;if(n&&t===`word`&&e.parent.forEach((t,n)=>{!t.isText&&n<e.parentOffset&&(r=n+t.nodeSize)}),r===e.parentOffset&&r>0)return 1;let i=e.parent.textBetween(r,e.parentOffset,``,is);if(t===`char`)return[...as.segment(i)].pop()?.segment.length??0;let a=[...os.segment(i)],o=0;for(;a.length&&!a[a.length-1]?.isWordLike;)o+=a.pop()?.segment.length??0;return o+(a.pop()?.segment.length??0)}function ps(e,t,n=!1){let r=e.parent.content.size;if(n&&t===`word`&&e.parent.forEach((t,n)=>{!t.isText&&n>=e.parentOffset&&n<r&&(r=n)}),r===e.parentOffset&&r<e.parent.content.size)return 1;let i=e.parent.textBetween(e.parentOffset,r,``,is),a=[...(t===`char`?as:os).segment(i)];if(t===`char`)return a[0]?.segment.length??0;let o=0;for(;a.length&&!a[0]?.isWordLike;)o+=a.shift()?.segment.length??0;return o+(a.shift()?.segment.length??0)}function ms(e){let t=jo(e);return t?.on===!0||(t?.view??`markup`)!==`markup`}var hs=e=>e.marks.some(e=>e.type.name===`deletion`);function gs(e,t,n,r){if(!xi(n))return!1;let i=bi(e.doc,r);return!i||i.deleted?!1:(t?.(e.tr.setSelection(Pi(e.doc,i))),!0)}function _s(e=`char`){return(t,n)=>{if(!t.selection.empty)return ls(t,n);let r=cs(t);if(!r)return!1;let i=X(t),a=ms(t),o=r;for(;o.parentOffset>0;){let e=o.nodeBefore;if(a&&e&&hs(e))o=t.doc.resolve(o.pos-e.nodeSize);else if(gs(t,n,e,o.pos-1))return!0;else if(pi(i,e))o=t.doc.resolve(o.pos-1);else break}if(o.parentOffset===0)return bs(ss(t,o.pos),n);if(mi(i,o.nodeBefore)){let e=o.nodeBefore;return n?.(t.tr.setSelection(hi(t,o.pos-e.nodeSize))),!0}let s=fs(o,e,i!==null);return I(t,n,e=>e.delete(o.pos-s,o.pos))}}function vs(e=`char`){return(t,n)=>{if(!t.selection.empty)return ls(t,n);let r=cs(t);if(!r)return!1;let i=X(t),a=ms(t),o=r;for(;o.parentOffset<o.parent.content.size;){let e=o.nodeAfter;if(a&&e&&hs(e))o=t.doc.resolve(o.pos+e.nodeSize);else if(gs(t,n,e,o.pos))return!0;else if(pi(i,e))o=t.doc.resolve(o.pos+1);else break}if(o.parentOffset===o.parent.content.size)return xs(ss(t,o.pos),n);if(mi(i,o.nodeAfter))return n?.(t.tr.setSelection(hi(t,o.pos))),!0;let s=ps(o,e,i!==null);return I(t,n,e=>e.delete(o.pos,o.pos+s))}}function ys(e,t,n,r){let i=n.attrs.section;i&&!jo(e)?.on&&$o(e,t,i,r)}var bs=(e,t)=>{let n=cs(e);if(!n?.parent.isTextblock||n.parentOffset>0||n.depth<1)return!1;let r=n.index(n.depth-1);if(r===0)return!1;let i=n.node(n.depth-1).child(r-1),a=n.before();return i.isTextblock?I(e,t,t=>{t.join(a),Ye(t,a-i.nodeSize,n.parent),ys(e,t,i,a-i.nodeSize)}):i.type.name===`table`?(t?.(e.tr.setSelection(L.near(e.doc.resolve(a-1),-1))),!0):mi(X(e),i)?(t?.(e.tr.setSelection(hi(e,a-i.nodeSize))),!0):!1},xs=(e,t)=>{let n=cs(e);if(!n?.parent.isTextblock||n.parentOffset<n.parent.content.size||n.depth<1)return!1;let r=n.node(n.depth-1).maybeChild(n.index(n.depth-1)+1);if(!r)return!1;let i=n.after();return r.isTextblock?I(e,t,t=>{t.join(i),Ye(t,n.before(),r),ys(e,t,n.parent,n.before())}):r.type.name===`table`?(t?.(e.tr.setSelection(L.near(e.doc.resolve(i+1),1))),!0):mi(X(e),r)?(t?.(e.tr.setSelection(hi(e,i))),!0):!1},Ss=(e,t)=>{let{selection:n}=e;return Cs(e)?I(e,t,t=>{t.insert(n.to,tt(e.schema).create()),t.setSelection(R.create(t.doc,n.to+1))}):!(n instanceof Ge)&&!n.$from.parent.isTextblock?!1:I(e,t,t=>{let r=e.storedMarks??Ke(n.$from);if(n.empty||us(t),!t.selection.$from.parent.inlineContent)throw new F(`No text where the selection was`);let i=t.selection.$from,a=i.parentOffset===i.parent.content.size,o=X(e);if(o&&i.parent.type.name===`paragraph`){let{before:e,after:n}=ri(o,i.parent,a);t.split(i.pos,1,[{type:i.parent.type,attrs:n}]),e&&t.setNodeMarkup(i.before(),i.parent.type,e)}else{let n=tt(e.schema);t.split(i.pos,1,a&&i.parent.type!==n?[{type:n}]:void 0)}t.setSelection(R.create(t.doc,i.pos+2)),r.length&&t.setStoredMarks(r)})};function Cs(e){let{selection:t}=e;return t instanceof We&&t.node.isBlock?t.node:null}function ws(e,t,n){let{from:r,to:i}=e.selection,a=tt(e.schema).create(null,n);return I(e,t,e=>{e.replace(r,i,new w(f.from(a),0,0)),e.setSelection(R.create(e.doc,r+1+n.nodeSize))})}function Ts(e,t,n){let r=e.resolve(t);for(;;){let t=n<0?r.nodeBefore:r.nodeAfter;if(t){let e=n<0?r.pos-t.nodeSize:r.pos;for(;!t.isTextblock&&!t.isLeaf;){let r=n<0?t.lastChild:t.firstChild;if(!r)return null;e=n<0?e+t.nodeSize-1-r.nodeSize:e+1,t=r}return{node:t,pos:e}}if(r.depth===0)return null;r=e.resolve(n<0?r.before():r.after())}}function Es(e,t){return(n,r)=>{let{selection:i,doc:a}=n;if(Cs(n)){let t=Ts(a,e<0?i.from:i.to,e);if(!t)return!0;let o=t.node.isTextblock?R.create(a,e<0?t.pos+t.node.nodeSize-1:t.pos+1):We.isSelectable(t.node)?We.create(a,t.pos):L.near(a.resolve(t.pos),e);return r?.(n.tr.setSelection(o)),!0}if(t===`none`||!i.empty||!(i instanceof R))return!1;let{$from:o}=i;if(!o.parent.isTextblock||o.depth<1)return!1;let s=e<0?o.parentOffset===0:o.parentOffset===o.parent.content.size;if(t===`char`&&!s)return!1;let c=Ts(a,e<0?o.before():o.after(),e);return!c||c.node.isTextblock||!We.isSelectable(c.node)?!1:(r?.(n.tr.setSelection(We.create(a,c.pos))),!0)}}var Ds=(e,t)=>As(`tab`,e,t),Os=(e,t)=>As(`hardBreak`,e,t),ks=(e,t)=>As(`pageBreak`,e,t);function As(e,...[t,n]){let r=t.schema.nodes[e],{selection:i}=t;return!r||!(i instanceof Ge)&&!i.$from.parent.inlineContent?!1:I(t,n,e=>{let n=t.storedMarks??Ke(i.$from);if(i.empty||us(e),!e.selection.$from.parent.inlineContent)throw new F(`No text where the selection was`);let a=e.selection.from;e.insert(a,r.create(null,null,Ze(n).filter(t=>e.doc.resolve(a).parent.type.allowsMarkType(t.type)))),e.setSelection(R.create(e.doc,a+1))})}var js=(e,t)=>(t?.(e.tr.setSelection(new Ge(e.doc))),!0);function Ms(e,t){return typeof t==`string`?e.schema.marks[t]:t}function Ns(e,t){let n=!0,r=!1;for(let{from:i,to:a}of e.selection.ranges)e.doc.nodesBetween(i,a,(e,i,a)=>{if(n&&e.isInline&&a?.type.allowsMarkType(t))return r=!0,t.isInSet(e.marks)||(n=!1),!1});return r&&n}function Ps(e,t){return(n,r)=>{let i=Ms(n,e);if(!i)return!1;let{selection:a}=n,o=cs(n);if(o){if(!o.parent.type.allowsMarkType(i))return!1;let e=n.storedMarks??Ke(o),a=X(n);if(a&&ai(a,i))return r?.(n.tr.setStoredMarks(ui(a,o.parent,e,i))),!0;let s=i.isInSet(e),c=s?null:Fs(i,t);return!s&&!c?!1:(r?.(n.tr.setStoredMarks(s?s.removeFromSet(e):c.addToSet(e))),!0)}let{ranges:s}=a,c=!1;for(let{from:e,to:t}of s)n.doc.nodesBetween(e,t,e=>(e.isTextblock&&e.type.allowsMarkType(i)&&(c=!0),!c));if(!c)return!1;let l=X(n);if(l&&ai(l,i)){let e=!li(l,n,i,null);return I(n,r,t=>{for(let{from:r,to:a}of s)for(let o of di(l,n,r,a,i,e))t.removeMark(o.from,o.to,i),o.mark&&t.addMark(o.from,o.to,o.mark)})}let u=Ns(n,i),d=u?null:Fs(i,t);return!u&&!d?!1:I(n,r,e=>{for(let{from:t,to:n}of s)u?e.removeMark(t,n,i):e.addMark(t,n,d)})}}function Fs(e,t){if(e.name===`link`&&!ue(t))return null;try{return e.create(t)}catch(e){if(e instanceof i)return null;throw e}}function Is(e,t){let n=Ms(e,t);if(!n)return!1;let r=cs(e),i=X(e);return i&&ai(i,n)?li(i,e,n,r?e.storedMarks??Ke(r):null):r?n.isInSet(e.storedMarks??Ke(r))!==void 0:Ns(e,n)}function Ls(e,t=null){return(n,r)=>{let i=X(n);if(!i)return!1;let a=typeof e==`string`?e:e.name;if(a===`heading`)return Oa(`heading ${String(t?.level??1)}`)(n,r);let o=a===`paragraph`?Ca(i):null;return o!==null&&Da(o)(n,r)}}function Rs(){return new $e({keymap:{Enter:Ss,"Shift-Enter":Os,"Mod-Enter":ks,Tab:Ds,Backspace:_s(),Delete:vs(),"Mod-b":Ps(`bold`),"Mod-i":Ps(`italic`),"Mod-u":Ps(`underline`),"Mod-k":bo,"Mod-a":js,ArrowLeft:Es(-1,`char`),ArrowRight:Es(1,`char`),ArrowUp:Es(-1,`none`),ArrowDown:Es(1,`none`),"Mod-z":Zi,"Mod-Shift-z":Qi,"Mod-y":Qi}})}var zs=new Set([`commentStart`,`commentEnd`,`commentReference`]);function Bs(e){return typeof e==`string`?e.split(/\r\n|\r|\n/).map(e=>e?{type:`paragraph`,content:[{type:`text`,text:e}]}:{type:`paragraph`}):structuredClone([...e])}var Vs=9,Hs=e=>e.initials===void 0?{}:{initials:e.initials.slice(0,Vs)};function Us(e){let t=new Set;return e.descendants(e=>{if(e.type.name===`opaqueBlock`||e.type.name===`opaqueInline`)for(let[,n]of String(e.attrs.xml).matchAll(/<\w+:comment(?:RangeStart|RangeEnd|Reference)\b[^>]*?\b\w+:id="(\d+)"/g))t.add(Number(n));return e.isBlock}),t}function Ws(e,t){let n=-1;for(let e of t)n=Math.max(n,e.id);e.descendants(e=>(zs.has(e.type.name)&&(n=Math.max(n,e.attrs.id)),e.isBlock));for(let t of Us(e))n=Math.max(n,t);return n+1}function Gs(e,t){let n=e.find(e=>e.id===t),r=new Set;for(;n?.parent!==void 0&&!r.has(n.id);){r.add(n.id);let t=n.parent;n=e.find(e=>e.id===t)}return n}function Ks(e){let t=new Map;return e.descendants((e,n)=>{if(!zs.has(e.type.name))return e.isBlock;let r=e.attrs.id,i=t.get(r)??{};return e.type.name===`commentStart`?i.start??=n:e.type.name===`commentEnd`?i.end??=n:i.reference??=n,t.set(r,i),!1}),t}var qs=e=>e.tr.setMeta(So,!0).setMeta(Li,!0),Js=(e,t)=>t.author??jo(e)?.author??`Author`;function Ys(e,t={}){return(n,r)=>{let i=X(n),{schema:a}=n,o={start:a.nodes.commentStart,end:a.nodes.commentEnd,reference:a.nodes.commentReference};if(!i||Kr(n)||!o.start||!o.end||!o.reference)return!1;let s=n.selection instanceof Ge,c=s?L.atStart(n.doc).$from:n.selection.$from,l=s?L.atEnd(n.doc).$to:n.selection.$to;if(!c.parent.inlineContent||!l.parent.inlineContent)return!1;if(r){let a=i.envelope.comments,s=Ws(n.doc,a),u=qs(n);u.insert(l.pos,[o.end.create({id:s}),o.reference.create({id:s})]),u.insert(c.pos,o.start.create({id:s})),u.setSelection(R.create(u.doc,c.pos+1,l.pos+1));let d={id:s,author:Js(n,t),...Hs(t),date:Fo(),content:Bs(e)};Ir(u,a,[...a,d]),r(u)}return!0}}function Xs(e,t,n={}){return(r,i)=>{let a=X(r),{schema:o}=r,s=a?.envelope.comments??[],c=Gs(s,e),l=Ks(r.doc),u=c&&l.get(c.id),{commentStart:d,commentEnd:f,commentReference:p}=o.nodes;if(!a||!c||!u||!d||!f||!p)return!1;if(i){let e=Ws(r.doc,s),a=qs(r),o=ec(s,c.id),u=e=>Math.max(...[...o].map(t=>l.get(t)?.[e]??-1)),m=u(`start`),h=u(`reference`);h>=0&&a.insert(h+1,[f.create({id:e}),p.create({id:e})]),m>=0&&a.insert(m+1,d.create({id:e}));let g={id:e,author:Js(r,n),...Hs(n),date:Fo(),content:Bs(t),parent:c.id};Ir(a,s,[...s,g]),i(a)}return!0}}function Zs(e,t){return(n,r)=>{let i=X(n)?.envelope.comments,a=i?.find(t=>t.id===e);if(!i||!a)return!1;if(r){let e=i.flatMap(e=>e===a?t(e,i):[e]);r(Ir(qs(n),i,e))}return!0}}var Qs=(e,t)=>Zs(e,e=>[{...e,content:Bs(t)}]);function $s(e,t=!0){return(n,r)=>{let i=X(n)?.envelope.comments??[],a=Gs(i,e);if(!a)return!1;if(r){let e=ec(i,a.id),o=i.map(n=>{if(!e.has(n.id))return n;let{done:r,...i}=n;return t?{...i,done:!0}:i});r(Ir(qs(n),i,o))}return!0}}function ec(e,t){let n=new Set([t]);for(let t=!0;t;){t=!1;for(let r of e)r.parent!==void 0&&n.has(r.parent)&&!n.has(r.id)&&(n.add(r.id),t=!0)}return n}function tc(e,t,n){let r=[];e.doc.descendants((e,t)=>(zs.has(e.type.name)&&n.has(e.attrs.id)&&r.push(t),e.isBlock));for(let t of r.reverse())e.delete(t,t+1);Ir(e,t,t.filter(e=>!n.has(e.id)))}function nc(e){let t=(n,r)=>{let i=Kr(n);if(i)return r?i.run(t):i.can(t);let a=X(n)?.envelope.comments??[],o=ec(a,e),s=Us(n.doc);if(!a.some(t=>t.id===e)||[...o].some(e=>s.has(e)))return!1;if(r){let e=qs(n);tc(e,a,o),r(e)}return!0};return t}var rc=(e,t)=>{let n=Kr(e);if(n)return t?n.run(rc):n.can(rc);let r=X(e)?.envelope.comments??[],i=Us(e.doc),a=new Set;for(let e of r){let t=Gs(r,e.id);if(t&&i.has(t.id))for(let e of ec(r,t.id))a.add(e);i.has(e.id)&&a.add(e.id)}let o=new Set(r.map(e=>e.id).filter(e=>!a.has(e)));if(!o.size)return!1;if(t){let n=qs(e);tc(n,r,o),t(n)}return!0},ic=new Qe(`comments`);function ac(e){return e.steps.some((t,n)=>{let r=!1;return t.getMap().forEach((t,i)=>{t<i&&e.docs[n].nodesBetween(t,i,e=>(e.type.name===`commentReference`&&(r=!0),!r))}),r})}function oc(){return new $e({key:ic,appendTransaction(e,t,n){let r=X(n)?.envelope.comments;if(!r?.length||!e.some(ac))return null;let i=Ks(t.doc),a=Ks(n.doc),o=new Set;for(let[e,t]of i)if(t.reference!==void 0&&a.get(e)?.reference===void 0)for(let t of ec(r,e))o.add(t);let s=[...o].filter(e=>r.some(t=>t.id===e));if(!s.length)return null;let c=n.tr.setMeta(So,!0);return tc(c,r,new Set(s)),c}})}var sc={SEQ:`rs`,TOC:`abcdflnopst`,MERGEFIELD:`bf`,REF:`d`},cc=`*@#`;function lc(e){let t=[],n=0;for(;n<e.length;)if(/\s/.test(e[n]))n++;else if(e[n]===`"`){let r=``;for(n++;n<e.length&&e[n]!==`"`;n++)e[n]===`\\`&&(e[n+1]===`"`||e[n+1]===`\\`)&&n++,r+=e[n];n++,t.push({value:r,quoted:!0})}else{let r=n;for(;n<e.length&&!/[\s"]/.test(e[n]);)n++;t.push({value:e.slice(r,n),quoted:!1})}return t}function uc(e){let t=lc(e),n=(t[0]?.value??``).toUpperCase(),r=cc+(sc[n]??``),i=[],a=new Map;for(let e=1;e<t.length;e++){let{value:n,quoted:o}=t[e];if(o||!n.startsWith(`\\`)||n.length<2){i.push(n);continue}let s=n[1].toLowerCase(),c=n.slice(2),l=t[e+1];!c&&r.includes(s)&&l&&(l.quoted||l.value[0]!==`\\`)&&(c=l.value,e++),a.set(s,[...a.get(s)??[],c])}return{name:n,args:i,switches:a}}var dc=`January February March April May June July August September October November December`.split(` `),fc=`Sunday Monday Tuesday Wednesday Thursday Friday Saturday`.split(` `),pc=(e,t=2)=>String(e).padStart(t,`0`);function mc(e,t){let n=e.getHours()%12||12,r={d:String(e.getDate()),dd:pc(e.getDate()),ddd:fc[e.getDay()].slice(0,3),dddd:fc[e.getDay()],M:String(e.getMonth()+1),MM:pc(e.getMonth()+1),MMM:dc[e.getMonth()].slice(0,3),MMMM:dc[e.getMonth()],yy:pc(e.getFullYear()%100),yyyy:String(e.getFullYear()),h:String(n),hh:pc(n),H:String(e.getHours()),HH:pc(e.getHours()),m:String(e.getMinutes()),mm:pc(e.getMinutes()),s:String(e.getSeconds()),ss:pc(e.getSeconds())},i=e.getHours()<12;return t.replace(/'([^']*)'|AM\/PM|am\/pm|A\/P|a\/p|d+|M+|y+|h+|H+|m+|s+/g,(e,t)=>t===void 0?e.includes(`/`)?i?e.split(`/`)[0]:e.split(`/`)[1]:r[e]??e:t)}function hc(e,t){let n=[``],r=!1;for(let e of t)e===`'`&&(r=!r),e===`;`&&!r?n.push(``):n[n.length-1]+=e;let i=e<0&&n[1]!==void 0,a=e===0&&n[2]!==void 0,o=i?n[1]:a?n[2]:n[0],s=[],c=[],l=[],u=[],d=!1,f=!1;r=!1;for(let e of o)if(e===`'`)r=!r;else if(r)s.push(e);else if(e==="`")return null;else if(e===`0`||e===`#`||e===`x`)(d?l:c).push({at:s.length,slot:e}),s.push(``);else if(e===`.`){if(d)return null;d=!0,s.push(`.`)}else if(e===`,`){if(d)return null;f=!0}else e===`+`||e===`-`?(u.push({at:s.length,sign:e}),s.push(``)):s.push(e);let p=Math.abs(e);if(!Number.isFinite(p)||p>=1e21)return null;let[m=``,h=``]=p.toFixed(Math.min(l.length,100)).split(`.`),g=h.padEnd(l.length,`0`),_=m===`0`?``:m,v=!_&&!/[1-9]/.test(g),y=_.length-1,b=0,x=e=>f&&b>0&&b%3==0&&e!==` `?`${e},`:e;for(let e=c.length-1;e>=0;e--,b++){let{at:t,slot:n}=c[e];s[t]=x(y>=0?_[y--]:n===`0`?`0`:` `)}let S=c[0],C=y>=0&&S?.slot===`x`;if(S&&S.slot!==`x`)for(;y>=0;y--,b++)s[S.at]=x(_[y])+s[S.at];l.forEach(({at:e,slot:t},n)=>{let r=g.slice(n),i=r[0];t===`0`||/[1-9]/.test(r)?s[e]=i:v&&n===0?s[e]=`0`:s[e]=t===`#`?` `:``});for(let{at:t,sign:n}of u)s[t]=v?` `:e<0?`-`:n===`+`?`+`:` `;if(e<0&&!i&&!v&&!u.length&&!C){let e=c.find(({slot:e})=>e!==`x`);e&&(s[e.at]=`-${s[e.at]}`)}return s.join(``)}var gc={ROMAN:`upperRoman`,roman:`lowerRoman`,ALPHABETIC:`upperLetter`,alphabetic:`lowerLetter`},_c={arabic:`decimal`,arabicdash:`numberInDash`,ordinal:`ordinal`},vc={upper:e=>e.toUpperCase(),lower:e=>e.toLowerCase(),firstcap:e=>e.charAt(0).toUpperCase()+e.slice(1),caps:e=>e.replace(/(^|\s)(\S)/g,(e,t,n)=>t+n.toUpperCase())},yc=new Set([`mergeformat`,`charformat`]);function bc(e,t,n){let r=typeof e==`number`?e:Number(e.trim().replace(/,/g,``)),i=String(e).trim()!==``&&Number.isFinite(r)?r:null,a=t.switches.get(`#`)?.[0],o=n,s=!1,c=[];for(let e of t.switches.get(`*`)??[]){let t=e.toLowerCase();if(yc.has(t))continue;let n=gc[e]??_c[t];if(n)o=n;else if(t===`hex`)s=!0;else if(vc[t])c.push(vc[t]);else return null}let l=String(e);if(i!==null&&a!==void 0){let e=hc(i,a);if(e===null)return null;l=e}else i!==null&&s?l=i.toString(16).toUpperCase():i!==null&&(o||typeof e==`number`)&&(l=br(i,o));for(let e of c)l=e(l);return l}var xc=()=>({updated:0,unchanged:0,rebuilt:0,skipped:[]}),Sc=new WeakMap;function Cc(e){let t=Sc.get(e);if(t)return t;let n=new Map,r=new Map;return e.descendants((e,t)=>{if(e.type.name===`bookmarkStart`)n.set(e.attrs.id,{name:String(e.attrs.name),from:t+1});else if(e.type.name===`bookmarkEnd`){let i=n.get(e.attrs.id),a=i?.name.toLowerCase();i&&a!==void 0&&!r.has(a)&&r.set(a,{...i,to:t})}return!e.isInline}),Sc.set(e,r),r}var wc=(e,t)=>Cc(e).get(t.toLowerCase());function Tc(e,t){let n=Cc(e),r=2e8;for(let{name:e}of n.values()){let i=e.toLowerCase().startsWith(t.toLowerCase())?Number(e.slice(t.length)):0;Number.isSafeInteger(i+1+n.size)&&(r=Math.max(r,i))}return()=>{let e;do e=`${t}${++r}`;while(n.has(e.toLowerCase()));return e}}var Ec=new WeakMap;function Dc(e,t){let n=Ec.get(e);if(!n){n=[];for(let{from:t,codeEnd:r}of vi(e)){let e=n[n.length-1];e&&t<e[1]?e[1]=Math.max(e[1],r):n.push([t,r])}Ec.set(e,n)}let r=0,i=n.length;for(;r<i;){let e=r+i>>1;n[e][1]<=t?r=e+1:i=e}let a=n[r];return!!a&&a[0]<=t}function Oc(e){let t=[];return e.descendants((e,n)=>(e.type.name===`paragraph`&&t.push({node:e,pos:n}),!e.isTextblock)),t}var kc=new Set([`insertion`,`deletion`,`formatChange`]),Ac=e=>e.filter(e=>!kc.has(e.type.name)),jc=e=>e.marks.some(e=>e.type.name===`deletion`);function Mc(e,t,n){let r=e.nodes,i=[];for(let a of t.split(/(\t|\r\n|\r|\n)/))a&&(a===` `?i.push(r.tab.create(null,null,n)):/^[\r\n]/.test(a)?i.push(r.hardBreak.create(null,null,n)):i.push(e.text(a,n)));return i}function Nc(e,t){return Ac(((t.switches.get(`*`)??[]).some(e=>e.toLowerCase()===`mergeformat`)?e.resultMarks:null)??e.codeMarks??[])}function Pc(e,t){let n=e.type.schema,r=[],i=n.nodes.hardBreak,a=null;return e.nodesBetween(t.from,t.to,(n,o,s)=>{if(!n.isInline)return!0;if(a&&s!==a&&r.push(i.create()),a=s,jc(n)||Dc(e,o))return!1;if(n.isText){let e=Math.max(t.from-o,0),i=Math.min(t.to-o,n.nodeSize);i>e&&r.push(n.cut(e,i).mark(Fc(n.marks)))}else[`tab`,`hardBreak`,`picture`].includes(n.type.name)&&r.push(n.mark(Fc(n.marks)));return!1}),r}var Fc=e=>Ac(e).filter(e=>e.type.name!==`link`),Ic=class{paragraphs;markers;lists=new Map;constructor(e,t){this.paragraphs=Oc(e),this.markers=t.resolver.markers(this.paragraphs.map(e=>e.node.attrs)),this.markers.forEach((e,t)=>{if(!e)return;let n=this.lists.get(e.instance);n?n.push(t):this.lists.set(e.instance,[t])})}lastOfList(e,t){let n=this.lists.get(e)??[],r=0,i=n.length;for(;r<i;){let e=r+i>>1;n[e]<=t?r=e+1:i=e}return n[r-1]??-1}indexAt(e){let t=0,n=this.paragraphs.length;for(;t<n;){let r=t+n>>1;this.paragraphs[r].pos<=e?t=r+1:n=r}let r=this.paragraphs[t-1];return r&&e<=r.pos+r.node.nodeSize?t-1:-1}marker(e){return this.markers[this.indexAt(e)]??null}chain(e){let t=[e],n=this.markers[e]?.level??0,r=this.markers[e]?.abstract;for(let i=e-1;i>=0&&n>0;i--){let e=this.markers[i];e?.abstract===r&&e&&e.level<n&&(t.unshift(i),n=e.level)}return t}number(e,t,n,r){let i=this.indexAt(e),a=this.markers[i];if(!a)return`0`;let o=e=>{let t=this.markers[e];return r?t.plain:t.text},s=t===`n`?[i]:this.chain(i);if(t===`r`){let e=this.lastOfList(a.instance,this.indexAt(n)),t=e<0?[]:this.chain(e),r=0;for(;r<s.length-1&&s[r]===t[r];)r++;s=s.slice(r)}let c=[];for(let e of s){let t=o(e),n=c[c.length-1]?.replace(/\.+$/,``);n&&t.startsWith(n)&&!/^\w/.test(t.slice(n.length))?c[c.length-1]=t:c.push(t)}return c.join(``).replace(/\.+$/,``)}},Lc=new Set([`PAGE`,`NUMPAGES`,`SECTIONPAGES`]),Rc=new Set([...Lc,`DATE`,`TIME`,`SEQ`,`MERGEFIELD`]),zc={PAGE:``,NUMPAGES:``,SECTIONPAGES:``,DATE:``,TIME:``,SEQ:`cnrsh`,MERGEFIELD:`bf`,REF:`hnrwpt`,PAGEREF:`hp`,TOC:`ohzutnbpwx`};function Bc(e,t){let n=t;for(let t=e.mapping.maps.length-1;t>=0;t--)n=e.mapping.maps[t].invert().map(n,1);return n}var Z=(e,t,n,r)=>{e.report.skipped.push({instruction:t.instruction,story:e.story,reason:n,...r?{detail:r}:{}})};function Vc(e,t,n){let{layout:r}=e.options;if(!r)return Z(e,t,`no-layout`),null;let i=r.pageAt(Bc(e.bodyTr,n));return i||Z(e,t,`no-layout`),i}function Hc(e,t){return Oc(e).flatMap(({node:e,pos:n})=>{let r=Uc(t,e);return r===null?[]:[{pos:n,level:r}]})}function Uc(e,t){let n=e.resolver.paragraph(t.attrs).paragraph.style,r=e.envelope.styles.find(e=>e.id===n)?.name??``,i=/^heading ([1-9])$/i.exec(r);return i?Number(i[1]):null}function Wc(e,t){let n=e.tr.doc,r=new Map,i=new Map,a=new Map,o=Hc(n,e.word);for(let e of t){if(e.name!==`SEQ`||e.deleted)continue;let{args:t,switches:s}=uc(e.instruction),c=(t[0]??``).toLowerCase(),l=a.get(c)??[];a.set(c,l);let u=i.get(c)??0,d=Number(s.get(`s`)?.[0]),f=l[l.length-1]?.pos??0;d&&o.some(t=>t.pos>=f&&t.pos<e.from&&t.level<=d)&&(u=0);let p=t[1]?wc(n,t[1]):void 0,m=[...s.keys()].find(e=>`cnr`.includes(e)),h=Number(s.get(`r`)?.[0]);p?u=[...l].reverse().find(e=>e.pos<p.from)?.value??0:m===`r`&&Number.isFinite(h)?u=h:m!==`c`&&u++,p||i.set(c,u),l.push({pos:e.from,value:u}),r.set(e,u)}return r}var Gc=(e,t)=>{if(Object.hasOwn(e,t))return{found:!0,value:e[t]};let n=t.toLowerCase(),r=Object.keys(e).find(e=>e.toLowerCase()===n);return r===void 0?{found:!1,value:void 0}:{found:!0,value:e[r]}},Kc=(e,t)=>e.from<t.from?`below`:`above`;function qc(e,t){let n=wc(e.tr.doc,t);if(n)return{mark:n,tree:e.tr.doc,inBody:e.story===null};let r=e.story===null?void 0:wc(e.bodyTr.doc,t);return r?{mark:r,tree:e.bodyTr.doc,inBody:!0}:null}function Jc(e,t){let{name:n,args:r,switches:i}=uc(t.instruction);if(Rc.has(n)||n===`PAGEREF`||n===`TOC`||i.has(`n`)||i.has(`r`)||i.has(`w`)||i.has(`p`))return;let a=n===`REF`?r[0]:lc(t.instruction)[0]?.value;return a?wc(e,a):void 0}function Yc(e,t,n){let r=vi(e),i=new Set([n]),a=[n];for(let n=a.pop();n;n=a.pop()){if(n.from<=t.from&&t.to<=n.to)return!0;let o=0,s=r.length;for(;o<s;){let e=o+s>>1;r[e].from<n.from?o=e+1:s=e}for(let t=o;t<r.length&&r[t].from<n.to;t++){let n=Jc(e,r[t]);n&&!i.has(n)&&(i.add(n),a.push(n))}}return!1}function Xc(e,t,n){let r=uc(t.instruction),{name:i,args:a,switches:o}=r,s=!Rc.has(i)&&i!==`REF`&&i!==`PAGEREF`,c=s?lc(t.instruction)[0]?.value:a[0],l=!Rc.has(i)&&c?qc(e,c):null;if(s&&!l)return Z(e,t,`unknown`),null;let u=zc[s?`REF`:i]??``;for(let n of o.keys())if(!cc.includes(n)&&!u.includes(n))return Z(e,t,`unsupported-switch`,`\\${n}`),null;let d=(n,i)=>{let a=bc(n,r,i);return a===null&&Z(e,t,`unsupported-switch`,`\\*`),a===null?null:{text:a}},{layout:f}=e.options;switch(i){case`PAGE`:case`SECTIONPAGES`:{let n=Vc(e,t,t.from);return n?i===`PAGE`?d(n.number,n.format):d(n.sectionPages):null}case`NUMPAGES`:return f||Z(e,t,`no-layout`),f?d(f.pages):null;case`DATE`:case`TIME`:{let t=o.get(`@`)?.[0]??(i===`DATE`?`M/d/yyyy`:`h:mm AM/PM`);return d(mc(e.options.now??new Date,t))}case`SEQ`:{let e=(o.get(`*`)??[]).some(e=>!yc.has(e.toLowerCase()));return o.has(`h`)&&!e?{text:``}:d(n.get(t)??0)}case`MERGEFIELD`:{let{data:n}=e.options;if(!n)return null;let i=a[0]??``,{found:s,value:c}=Gc(n,i);if(!s)return Z(e,t,`no-data`,i),null;let l=c??``,u=o.get(`@`)?.[0];c instanceof Date?l=u?mc(c,u):c.toISOString():u&&typeof c==`string`&&!Number.isNaN(Date.parse(c))&&(l=mc(new Date(c),u));let d=bc(typeof l==`number`?l:String(l),r);if(d===null)return Z(e,t,`unsupported-switch`,`\\*`),null;let f=o.get(`b`)?.[0]??``,p=o.get(`f`)?.[0]??``;return{text:d?`${f}${d}${p}`:``}}}if(!l)return Z(e,t,`missing-bookmark`,c),null;let{mark:p,tree:m,inBody:h}=l,g=o.has(`p`)&&m===e.tr.doc?Kc(t,p):null;if(i===`PAGEREF`){if(!h)return Z(e,t,`no-layout`,c),null;let n=Vc(e,t,p.from);if(!n)return null;let r=g&&e.story===null&&f?f.pageAt(Bc(e.bodyTr,t.from)):null;if(g&&r?.number===n.number)return{text:g};let i=d(n.number,n.format);return i&&o.has(`p`)?{text:`on page ${i.text}`}:i}let _=[`n`,`r`,`w`].find(e=>o.has(e));if(_){let n=e.numbers.get(m);n||(n=new Ic(m,e.word),e.numbers.set(m,n));let r=n.number(p.from,_,t.from,o.has(`t`));return d(g?`${r} ${g}`:r)}if(g)return d(g);if(m===e.tr.doc&&Yc(m,t,p))return Z(e,t,`self-reference`,c),null;let v=Pc(m,p),y=v.map(e=>e.isText?e.text:e.type.name===`tab`?` `:`
|
|
4
|
+
`).join(``),b=d(y);if(!b)return null;let x=!(o.get(`*`)??[]).some(e=>yc.has(e.toLowerCase()));return b.text===y&&x?{text:y,nodes:v}:b}function Zc(e,t,n){let{tr:r}=e;if(t.separator!==null){r.replace(t.resultFrom,t.resultTo,new w(f.fromArray([...n]),0,0));return}let i=Nc(t,uc(t.instruction)),a=r.doc.type.schema.nodes.fieldSeparator.create(null,null,i);r.insert(t.to-1,[a,...n])}function Qc(e,t){let{tr:n}=e,r=[...t].reverse();if(t.length<32||jo(e.state)?.on){for(let[t,n]of r)Zc(e,t,n);return}let i=Oc(n.doc),a=e=>{let t=0,n=i.length;for(;t<n;){let r=t+n>>1;i[r].pos<e?t=r+1:n=r}return i[t-1]},o=[],s,c=()=>{let e=s,[t]=o,r=o[o.length-1];if(e&&t&&r){let i=[...o].reverse(),a=r[0].resultFrom,s=t[0].resultTo,c=[];e.node.forEach((t,n)=>{let r=e.pos+1+n;r>=a&&r<s&&c.push({at:r,node:t})});let l=[],u=0;for(let[e,t]of i){for(;c[u]&&c[u].at<e.resultFrom;)l.push(c[u++].node);for(l.push(...t);c[u]&&c[u].at<e.resultTo;)u++}n.replace(a,s,new w(f.fromArray(l),0,0))}o=[],s=void 0};for(let t of r){let[n,r]=t,i=a(n.from);n.separator!==null&&i&&n.resultTo<i.pos+i.node.nodeSize?(i!==s&&c(),s=i,o.push(t)):(c(),Zc(e,n,r))}c()}var $c=new WeakMap;function el(e){let t=[],n=!1;for(let r=e;r;r=r.parent){let e=$c.get(r);if(e!==void 0){n=e;break}if(t.push(r),r.locked){n=!0;break}}for(let e of t)$c.set(e,n);return n}function tl(e){return vi(e).filter(e=>{if(e.name!==`TOC`)return!1;for(let t=e.parent;t;t=t.parent)if(t.name===`TOC`)return!1;return!0})}var nl=e=>e.inCode?0:Rc.has(e.name)?1:e.name===`TOC`?3:2;function rl(e){let{tr:t,report:n,story:r}=e,i=t.doc.type.schema,a=new Set,o=n=>{if(n.deleted||!e.picked(n)||r!==null&&Lc.has(n.name))return!1;if(!el(n))return!0;let i=Bc(t,n.from);return a.has(i)||Z(e,n,`locked`),a.add(i),!1};for(let r of[0,1,2]){let a=vi(t.doc);if(!a.length)return;let s=Wc(e,a),c=new Map;for(let t of a)if(nl(t)===r&&o(t))try{let r=Xc(e,t,s);if(!r)continue;if(r.text===t.result){n.unchanged++;continue}let a=Nc(t,uc(t.instruction));c.set(t,r.nodes??Mc(i,r.text,a)),n.updated++}catch(n){Z(e,t,`failed`,n.message)}let l=new Set;for(let e of a)e.parent&&(c.has(e.parent)||l.has(e.parent))&&l.add(e);Qc(e,[...c].filter(([e])=>!l.has(e)))}if(r!==null){for(let n of vi(t.doc))n.name===`TOC`&&o(n)&&Z(e,n,`unknown`,`in a story`);return}let s=tl(t.doc).length;for(let n=0;n<s;n++){let r=tl(t.doc)[n];if(r&&o(r)){if(!e.contents)Z(e,r,`untrackable`);else try{hl(e,n)}catch(t){Z(e,r,`failed`,t.message)}}}}var il=new WeakMap;function al(e){let t=il.get(e);return t||(t=vi(e).filter(e=>e.name===`TOC`),il.set(e,t)),t}function ol(e,t,{node:n,pos:r}){let{run:i}=t.resolver.paragraph(n.attrs),a=al(e),o=[],s=null;return n.forEach((n,c)=>{let l=r+1+c;a.some(e=>l>=e.from&&l<e.to)?s=null:(s||(s={title:``,from:l,to:l,bookmark:null},o.push(s)),s.to=l+n.nodeSize,n.type.name===`bookmarkStart`&&sl.test(String(n.attrs.name))&&(s.bookmark??=String(n.attrs.name)),jc(n)||Dc(e,l)||t.resolver.run(i,n.marks.map(e=>e.toJSON())).hidden||(n.isText?s.title+=n.text:n.type.name===`tab`?s.title+=` `:n.type.name===`hardBreak`&&(s.title+=` `)))}),o.map(e=>({...e,title:e.title.trim()})).filter(e=>e.title)}var sl=/^_Toc\d+$/,cl=e=>{let t=/(\d)\s*-\s*(\d)/.exec(e??``);return t?[Number(t[1]),Number(t[2])]:[1,9]};function ll(e,t){let n=e.envelope.styles.find(e=>e.id===t)?.name??``,r=/^heading ([1-9])$/i.exec(n);if(r)return Number(r[1]);let i=t?e.resolver.paragraph({style:t}).paragraph.outlineLevel:null;return i!==null&&i<9?i+1:null}function ul(e,t,{switches:n}){let r=n.has(`o`)||n.has(`u`)||n.has(`t`),[i,a]=cl(n.get(`o`)?.[0]),o=new Map,s=(n.get(`t`)?.[0]??``).split(/[,;]/).map(e=>e.trim());for(let e=0;e+1<s.length;e+=2)o.set(s[e].toLowerCase(),Number(s[e+1])||1);let c=n.has(`b`)?wc(e,n.get(`b`)?.[0]??``):null,l=Oc(e),u=t.resolver.markers(l.map(e=>e.node.attrs)),d=e=>e>=i&&e<=a,f=[];return l.forEach((i,a)=>{let{node:s,pos:l}=i;if(c&&(l+s.nodeSize<=c.from||l>=c.to))return;let p=t.resolver.paragraph(s.attrs).paragraph,m=t.envelope.styles.find(e=>e.id===p.style),h=o.get((m?.name??p.style??``).toLowerCase());if(h===void 0&&(n.has(`o`)||n.has(`u`)||!r)){let e=ll(t,p.style);e!==null&&d(e)&&(h=e)}let g=p.outlineLevel;if(h===void 0&&n.has(`u`)&&g!==null&&g<9&&d(g+1)&&(h=g+1),h===void 0)return;let _=u[a];for(let{title:n,from:r,to:a,bookmark:o}of ol(e,t,i))f.push({from:r,to:a,level:h,title:n,number:_?.text??``,numberGap:_?.suffix===`space`?` `:_?.suffix===`nothing`?``:` `,bookmark:o})}),f}function dl(e,t,n){let r;e.forEach((e,t)=>{!r&&t+e.nodeSize>n&&e.attrs.section&&(r=e.attrs.section)});let{pageSize:i,margins:a}=r??t.envelope.section;return(i?.width??12240)-(a?.left??1440)-(a?.right??1440)-(a?.gutter??0)}function fl(e,t,n){let r=t<n.from;return e.forEach((e,i)=>{let a=t+1+i;a>=n.from&&a<n.to&&!jc(e)&&(r||=!e.type.name.startsWith(`field`)||a===n.from)}),r}function pl(e,t){let n=[];return e.nodesBetween(t.from,t.to,(e,r)=>!e.isTextblock||(fl(e,r,t)&&r+1!==t.resultTo&&n.push(e.attrs.style??null),!1)),n}var ml=`No table of contents entries found.`;function hl(e,t){let{tr:n,word:r,report:i}=e,a=()=>tl(n.doc)[t],o=a(),s=uc(o.instruction),{switches:c}=s;for(let t of c.keys())if(!cc.includes(t)&&!zc.TOC.includes(t)){Z(e,o,`unsupported-switch`,`\\${t}`);return}let l=n.doc.type.schema,u=ul(n.doc,r,s),d=c.get(`p`)?.[0]||` `,p=cl(c.get(`n`)?.[0]),m=e=>c.has(`n`)&&e>=p[0]&&e<=p[1],{layout:h}=e.options,g=e=>{if(m(e.level)||!h)return``;let t=h.pageAt(Bc(n,e.from));return t?br(t.number,t.format):``},_=(e,t)=>(e.number?e.number+e.numberGap:``)+e.title+(m(e.level)?``:d+t),v=[],y=t=>{let n=Ea({envelope:e.envelope},`toc ${t}`);if(!n)throw new F(`No table of contents style`);return e.envelope=n.envelope,n.id};for(let e of u)v.push(y(e.level));let b=e=>h?e:e.replace(/\t[^\t\r]*(?=\r|$)/g,` `),x=n.doc.resolve(o.from).parentOffset===0,S=(x?``:`\r`)+u.map(e=>_(e,g(e))).join(`\r`),C=pl(n.doc,o).slice(+!x);if((u.length?b(S)===b(o.result):o.result===ml)&&(!u.length||v.every((e,t)=>C[t]===e))){i.unchanged++;return}i.updated++,i.rebuilt++;let ee=Tc(n.doc,`_Toc`),te=gl(e.state,n),T=l.nodes.bookmarkStart,E=l.nodes.bookmarkEnd,D=u.filter(e=>!e.bookmark),O=new Map(D.map(e=>[e,te++]));for(let e of D)e.bookmark=ee();for(let e of D.reverse()){let t=O.get(e);n.insert(e.to,E.create({id:t})),n.insert(e.from,T.create({id:t,name:e.bookmark}))}o=a();let k=c.has(`h`),ne=k&&Ea({envelope:e.envelope},`Hyperlink`,`character`);ne&&(e.envelope=ne.envelope);let re=dl(n.doc,r,o.from)-10,ie=n.doc.resolve(o.from);n.doc.resolve(o.resultTo);let A=ie.parent.attrs.controls??null,j=(e,t,n)=>l.nodes[e].create(t??null,null,n??[]),ae=u.map((t,n)=>{let r=k?[l.mark(`link`,{anchor:t.bookmark})]:[],i=ne?[...r,l.mark(`characterStyle`,{id:ne.id})]:r,a=[];t.number&&a.push(...Mc(l,t.number+t.numberGap,i)),a.push(...Mc(l,t.title,i)),m(t.level)||(a.push(...Mc(l,d,r)),a.push(j(`fieldStart`,null,r),j(`fieldCode`,{text:` PAGEREF ${t.bookmark} \\h `},r),j(`fieldSeparator`,null,r),...Mc(l,g(t),r),j(`fieldEnd`,null,r)));let o=e.envelope.styles.find(e=>e.id===v[n])?.paragraph?.tabs??[],s=[...t.number&&t.numberGap===` `&&!o.some(e=>e.kind!==`right`)?[{position:440*t.level,kind:`left`}]:[],...d===` `&&!o.some(e=>e.kind===`right`)?[{position:re,kind:`right`,leader:`dot`}]:[]];return l.nodes.paragraph.create({style:v[n],...s.length?{tabs:s}:{},...A?{controls:A}:{}},a)});if(h||i.skipped.push({instruction:o.instruction,story:null,reason:`no-layout`}),!ae.length){n.replace(o.resultFrom,o.resultTo,new w(f.from(l.text(ml)),0,0));return}if(o.separator===null){let e=o.codeMarks??[];n.insert(o.resultTo,j(`fieldSeparator`,null,Ac(e))),o=a()}let oe=e=>{let t=[];return n.doc.nodesBetween(o.from,o.resultTo,(n,r)=>!n.isTextblock||(r!==e&&(r>ie.before()||x)&&fl(n,r,o)&&t.push({node:n,pos:r}),!1)),t},M=n.doc.resolve(o.resultTo);M.parentOffset&&(M.before()!==ie.before()&&ae.length<=oe(M.before()).length?n.delete(M.start(),o.resultTo):n.split(o.resultTo),o=a());let se=n.doc.resolve(o.resultTo),ce=se.before(),le=se.parent,ue=oe(ce),N=le.attrs.section??null;n.doc.nodesBetween(o.from,o.resultTo,(e,t)=>(e.isTextblock&&t!==ce&&(N??=e.attrs.section??null),!e.isTextblock)),N!==(le.attrs.section??null)&&n.setNodeMarkup(ce,le.type,{...le.attrs,section:N}),ae.length>ue.length&&n.insert(ce,ae.slice(ue.length));for(let e=ue.length-1;e>=0;e--){let{node:t,pos:r}=ue[e],i=ae[e];if(!i){n.delete(r,r+t.nodeSize);continue}let a=r<o.from?o.resultFrom:r+1;n.replace(a,r+1+t.content.size,new w(i.content,0,0));let{revision:s,formatChange:c}=t.attrs;n.setNodeMarkup(r,t.type,{...i.attrs,revision:s,formatChange:c})}if(!x){let e=n.doc.resolve(o.from);o.resultFrom<e.end()&&n.delete(o.resultFrom,e.end()),e.parent.attrs.section&&n.setNodeMarkup(e.before(),e.parent.type,{...e.parent.attrs,section:null})}}function gl(e,t){let n=-1;for(let r of[t.doc,...Jr(e)])r.descendants(e=>(e.type.name.startsWith(`bookmark`)&&(n=Math.max(n,e.attrs.id)),!e.isInline));return n+1}function _l(e,t,n){let r=vi(e);if(t<n)return new Set(r.filter(e=>e.from<n&&e.to>t).map(e=>e.from));let i=yi(e,t)??r.find(e=>e.to===t||e.from===t)??null;return i?.parent?.name===`TOC`&&(i=i.parent),new Set(i?[i.from]:[])}function vl(e,t,n,r,i){let a=e.story(t);if(!a||!vi(n.doc).length)return;let{state:o}=a,s=o.tr.setMeta(xl,`fields`),{updated:c,unchanged:l}=r.report;if(rl({...r,state:o,tr:s,story:t,bodyTr:r.tr}),!s.docChanged)return;let u=Vo(o,s);if(!u){r.report.updated=c,r.report.unchanged=l,r.report.skipped.push({instruction:``,story:t,reason:`untrackable`});return}let d=o.applyTransaction(u).state;i.step(new Rr(t,n,{...n,doc:d.doc},o.selection.toJSON(),d.selection.toJSON()))}function yl(e,t){for(let[n,r]of X(e)?.stories??[])if(r.doc===t)return n;return``}function bl(e,t={}){let{state:n}=e,r=X(n);if(!r)return xc();let i=Kr(n)?.state,{only:a}=t,o=a&&typeof a!=`function`?_l(n.doc,a.from,a.to):null,s=e=>{let s=n.tr.setMeta(xl,`fields`),c={state:n,tr:s,word:r,story:null,bodyTr:s,options:t,report:xc(),envelope:r.envelope,numbers:new Map,contents:e,picked:e=>typeof a==`function`?a(e):!o||[e,e.parent?.name===`TOC`?e.parent:null].some(e=>e&&o.has(Bc(s,e.from)))};return i&&(c.story=yl(i,n.doc),c.bodyTr=i.tr),rl(c),{run:c,out:Vo(n,s)}},c=s(!0);c.out||(c=s(!1));let{run:l,out:u}=c;if(!u){let e=xc();return e.skipped.push({instruction:``,story:l.story,reason:`untrackable`}),e}if(!i&&!o)for(let[t,n]of r.stories)vl(e,t,n,l,u);return u.docChanged&&(l.envelope!==r.envelope&&Zr(u,l.envelope),u.setMeta(t.continues?Ri:Li,!0),e.dispatch(u.setMeta(So,!0))),l.report}var xl=`controlEdit`,Sl=new Set([`contentLocked`,`sdtContentLocked`]),Cl=new Set([`sdtLocked`,`sdtContentLocked`]),wl=new Set([`text`,`comboBox`,`date`]),Tl=new Set([`dropDown`,`checkbox`,`picture`]),El=new Set([`checkbox`,`picture`,`repeating`,`repeatingItem`,`other`]),Dl=new Set([`insertion`,`deletion`,`formatChange`]),Ol=new Set([`commentStart`,`commentEnd`,`commentReference`]),kl=e=>e?.type.name===`controlStart`||e?.type.name===`controlEnd`,Al=e=>e.marks.some(e=>e.type.name===`deletion`),jl={text:{docPart:`DefaultPlaceholder_-1854013440`,text:`Click or tap here to enter text.`},richText:{docPart:`DefaultPlaceholder_-1854013440`,text:`Click or tap here to enter text.`},dropDown:{docPart:`DefaultPlaceholder_-1854013438`,text:`Choose an item.`},comboBox:{docPart:`DefaultPlaceholder_-1854013438`,text:`Choose an item.`},date:{docPart:`DefaultPlaceholder_-1854013437`,text:`Click or tap to enter a date.`}},Ml=` `,Nl={value:`2612`,font:`MS Gothic`},Pl={value:`2610`,font:`MS Gothic`},Fl=e=>Sl.has(e.lock??``)||!!e.binding,Il=new WeakMap;function Ll(e,t){let n=t;for(let r=e.nodeAt(n);r;r=r.firstChild){if(r.isTextblock)return n+1;if(r.isLeaf)return t;n++}return t}function Rl(e,t){let n=t;for(let r=e.resolve(n).nodeBefore;r;r=r.lastChild){if(r.isTextblock)return n-1;if(r.isLeaf)return t;n--}return t}function zl(e){let t=Il.get(e);if(t)return t;let n=[],r=new Set,i=(e,t)=>{let i=[];e.forEach((e,a)=>{let o=e.attrs.id;if(e.type.name===`controlStart`)i.push({id:o,at:t+a});else if(e.type.name===`controlEnd`){let e=i.map(e=>e.id).lastIndexOf(o);if(e<0){r.add(o);return}let{at:s}=i.splice(e,1)[0],c=t+a;n.push({id:o,level:`inline`,from:s,to:c+1,contentFrom:s+1,contentTo:c})}});for(let{id:e}of i)r.add(e)},a=(t,r)=>{let o=new Map,s=[];t.forEach((e,t,n)=>{let c=r+t,l=c+e.nodeSize;for(let t of e.attrs.controls??[]){let r=o.get(t);if(r&&r.index===n-1){r.index=n,r.to=l;continue}let i=e.type.name,a={index:n,from:c,to:l,level:i===`tableRow`?`row`:i===`tableCell`?`cell`:`block`};o.set(t,a),s.push({id:t,run:a})}e.isTextblock?i(e,c+1):e.isLeaf||a(e,c+1)});for(let{id:t,run:r}of s)n.push({id:t,level:r.level,from:r.from,to:r.to,contentFrom:Ll(e,r.from),contentTo:Rl(e,r.to)})};a(e,0),n.sort((e,t)=>e.from-t.from||t.to-e.to);let o={ranges:n,unpaired:r};return Il.set(e,o),o}var Bl=e=>zl(e).ranges;function Vl(e,t){let n=null;for(let r of Bl(e)){if(r.from>=t)break;t<r.to&&(n=r)}return n}var Hl=(e,t)=>{let n=X(e)?.envelope.controls;return n&&Object.hasOwn(n,t)?n[t]:void 0};function Ul(e,t,n){if(t===n)return!0;let r=Math.min(t,n),i=Math.max(t,n);if(e.resolve(r).parent!==e.resolve(i).parent)return!1;let a=!0;return e.nodesBetween(r,i,e=>(e.isInline&&!kl(e)&&(a=!1),a)),a}function Wl(e,t,n,r){if(!t)return!1;let i=e=>Object.hasOwn(t,e)?t[e]:void 0,a=Bl(e);return a.some(e=>{let t=i(e.id);return!t||!Fl(t)||t.deleted||e.from>=Math.max(r,n+1)||n>=e.to?!1:!a.some(t=>{let a=i(t.id);return t!==e&&t.from>=e.from&&t.to<=e.to&&t.from<n&&r<t.to&&!!a&&!Fl(a)})})}var Gl=(e,t)=>t.level===`inline`?e.slice(t.from+1,t.to-1).content:e.slice(t.from,t.to).content;function Kl(e,t){let n=new Map;t.forEach((e,t)=>{let r=n.get(e.id);r?r.push(t):n.set(e.id,[t])});let r=new Map,i=new Map;for(let t of e){let e=r.get(t.id)??0;r.set(t.id,e+1);let a=n.get(t.id)?.[e];a!==void 0&&i.set(t,a)}return i}function ql(e,t){let n=Math.min(e.childCount,t.childCount),r=0,i=0;for(;r<n&&e.child(r)===t.child(r);)i+=e.child(r).nodeSize,r++;let a=i,o=e.content.size,s=t.content.size;for(let i=1;i<=n-r;i++){let n=e.child(e.childCount-i);if(n!==t.child(t.childCount-i))break;o-=n.nodeSize,s-=n.nodeSize}return{fromA:i,toA:o,fromB:a,toB:s}}function Jl(e,t){let n=e[t],r=[],i=-1;for(let a=t+1;a<e.length;a++){let t=e[a];if(t.from>=n.to)break;t.to>n.to||t.from<i||(r.push(t),i=t.to)}return r}function Yl(e,t,n,r){let[i,a]=t.level===`inline`?[t.from+1,t.to-1]:[t.from,t.to],o=e=>e.level===`inline`?e.contentFrom:e.from,s=e=>e.level===`inline`?e.contentTo:e.to,c=[],l=null,u=0,d=-1;return e.nodesBetween(i,a,(e,t)=>{for(;n[u]&&t>=s(n[u]);)u++;let i=n[u];if(i&&t>=o(i))return i.level!==`inline`&&d!==u&&(d=u,l=null,c.push(`[${i.id}]`)),!1;if(Ol.has(e.type.name))return!1;let a=JSON.stringify(e.marks.filter(e=>r||e.type.name===`insertion`||e.type.name===`deletion`).map(e=>e.toJSON()));if(e.isText)return l===a?c[c.length-1]+=e.text??``:c.push(`${a}:${e.text}`),l=a,!1;l=null;let f=r||e.isInline?JSON.stringify(e.attrs):``;return c.push(`<${e.type.name}${f}${a}>`),!0}),c.join(``)}var Xl=(e,t)=>t.some(([t,n])=>t<=e.contentFrom&&n>=e.contentTo&&(t<e.contentFrom||n>e.contentTo));function Zl(e,t){let n=[];return Gl(e,t).forEach(e=>{e.isInline?n.push(e):e.descendants(e=>(e.isInline&&n.push(e),!0))}),n}function Ql(e,t,n,r){if(t.level!==`inline`){let n=e.nodeAt(t.from);if(!(t.level===`cell`?n?.childCount===1&&n.firstChild?.isTextblock:n?.isTextblock&&n.nodeSize===t.to-t.from))return!1}let i=new Set(r.map(e=>e.type.name));return Zl(e,t).every(e=>e.isText||i.has(e.type.name)||Ol.has(e.type.name)||e.type.name===`hardBreak`&&n.multiLine===!0)}function $l(e,t){if(!e.docChanged||e.doc===t.doc||e.getMeta(`historyOp`))return!0;let n=X(t)?.envelope.controls;if(!n)return!0;let r=zl(t.doc);if(!r.ranges.length)return!0;let i=zl(e.doc),a=e.getMeta(xl),o=e.getMeta(`trackedDeletes`)??[],s=Kl(r.ranges,i.ranges),c=ql(t.doc,e.doc);for(let[l,u]of r.ranges.entries()){let d=Object.hasOwn(n,u.id)?n[u.id]:void 0;if(!d)continue;if(i.unpaired.has(u.id)&&!r.unpaired.has(u.id))return!1;let f=s.get(u);if(f===void 0){if(Cl.has(d.lock??``))return!1;continue}if(u.to<=c.fromA||u.from>=c.toA)continue;let p=i.ranges[f];if(Gl(t.doc,u).eq(Gl(e.doc,p)))continue;if(Xl(u,o)){if(Cl.has(d.lock??``))return!1;continue}if(a===`fields`||a===`accept`||a===`reject`)continue;let m=Fl(d);if(m||Tl.has(d.kind)&&!a){if(Yl(t.doc,u,Jl(r.ranges,l),m)!==Yl(e.doc,p,Jl(i.ranges,f),m))return!1}else if(wl.has(d.kind)&&!Ql(e.doc,p,d,Zl(t.doc,u)))return!1}return!0}function eu(e){return Sa(e,`Placeholder Text`,`character`)}var tu=e=>e.placeholder?.text??(e.placeholder?.docPart?.startsWith(`DefaultPlaceholder_`)?jl[e.kind]?.text??Ml:Ml);function nu(e,t,n){let r=tu(t);if(r===Ml)return{run:e.schema.text(r),envelope:n};let i=Ea({envelope:n},`Placeholder Text`,`character`),a=i&&e.schema.marks.characterStyle?.create({id:i.id});return{run:e.schema.text(r,a?[a]:[]),envelope:i?.envelope??n}}var ru=(e,t)=>t.mapping.map(e.contentFrom,1)>=t.mapping.map(e.contentTo,-1),iu=(e,t)=>(t.format??[]).map(t=>e.schema.markFromJSON(t));function au(e,t,n,r,i){e.doc.nodesBetween(t,n,(t,n)=>{if(!t.isText)return!0;let a=n+t.nodeSize,o=e=>!!r&&(e.type.name===`characterStyle`&&e.attrs.id===r||e.type.name===`runExt`&&String(e.attrs.xml).includes(`"${r}"`));for(let r of t.marks)o(r)&&e.removeMark(n,a,r);let s=t.marks.filter(e=>!o(e));for(let t of i)s.some(e=>e.type===t.type)||e.addMark(n,a,t);return!1})}function ou(e,t,n){let r=n.checkedState??Nl,i=n.uncheckedState??Pl,a=yu(e,t);if(a===Tu(r))return!0;if(a===Tu(i))return!1;for(let n of Zl(e,t)){let e=/:char="([0-9a-f]+)"/i.exec(String(n.attrs.xml??``))?.[1];if(!e||Al(n))continue;let t=Number.parseInt(e,16)&255;if(t===(Number.parseInt(r.value,16)&255))return!0;if(t===(Number.parseInt(i.value,16)&255))return!1}return null}function su(e){try{return[`long`,`short`].map(t=>{let n=new Intl.DateTimeFormat(e,{month:t,timeZone:`UTC`});return Array.from({length:12},(e,t)=>n.format(Date.UTC(2024,t,1)).toLowerCase().replace(/\.$/,``))})}catch{return null}}function cu(e,t){let n=su(e.ext&&/:lid\b[^>]*:val="([^"]+)"/.exec(e.ext)?.[1]||`en-US`)??[],r=[],i=(e.dateFormat??`d MMMM yyyy`).replace(/'[^']*'|d+|M+|y+|[Hhms]+|[AaPp]{2}|[.*+?^${}()|[\]\\/]/g,e=>e[0]===`'`?e.slice(1,-1).replace(/[.*+?^${}()|[\]\\]/g,`\\$&`):/^[.*+?^${}()|[\]\\/]$/.test(e)?`\\${e}`:e[0]===`d`&&e.length>2?`\\p{L}+\\.?`:((e[0]===`d`||e[0]===`y`||e[0]===`M`)&&r.push(e),e[0]===`M`&&e.length>2?`(\\p{L}+)\\.?`:e[0]===`d`||e[0]===`M`||e[0]===`y`?`(\\d+)`:`\\S+`)),a=RegExp(`^\\s*${i}\\s*$`,`iu`).exec(t);if(!a)return null;let[o,s,c]=[0,0,0];return r.forEach((e,t)=>{let r=a[t+1];if(e[0]===`d`)o=Number(r);else if(e[0]===`y`)c=Number(r)+(e.length<3?2e3:0);else if(e.length<3)s=Number(r);else{let e=r.toLowerCase();for(let t of n)t.includes(e)&&(s=t.indexOf(e)+1)}}),lu(c,s,o)}function lu(e,t,n){let r=new Date(Date.UTC(2e3,t-1,n));if(r.setUTCFullYear(e,t-1,n),r.getUTCMonth()!==t-1||r.getUTCDate()!==n)return null;let i=(e,t=2)=>String(e).padStart(t,`0`);return`${i(e,4)}-${i(t)}-${i(n)}T00:00:00Z`}function uu(e,t,n,r){let i=e=>e.marks.filter(e=>!Dl.has(e.type.name)),a=[];e.doc.nodesBetween(t,n,(e,t)=>(e.isText&&a.push({node:e,pos:t}),!0));let o=(e,t)=>e.length===t.length&&e.every(e=>t.some(t=>t.eq(e)));if(!a.length)return;let s=i(a[0].node);if(a.every(e=>o(i(e.node),s)))return;let c=a.map(e=>i(e.node)).find(e=>!r||!o(e,r))??s;for(let{node:t,pos:n}of a){let r=n+t.nodeSize;for(let a of i(t))c.some(e=>e.eq(a))||e.removeMark(n,r,a);for(let i of c)i.isInSet(t.marks)||e.addMark(n,r,i)}}function du(e,t,n,r){let i=X(r).envelope,a=i.controls,o=X(n)?.envelope.controls,s=Bl(n.doc),c=Bl(e.doc);if(!o||!s.length||!c.length)return a;let l=new Map;for(let[e,t]of Kl(s,c))l.set(c[t],e);let u=ql(n.doc,r.doc),d=new Oe(t.flatMap(e=>e.mapping.maps)),f=t.map(e=>e.getMeta(xl)).find(Boolean),p=f===`accept`||f===`reject`,m=t.flatMap(e=>e.getMeta(`trackedDeletes`)??[]),h=i,g={...a},_=!1,v=(e,t)=>{g[e]=t,_=!0},y=(t,n)=>{let i=nu(r,n,h);h=i.envelope,e.insert(e.mapping.map(t.contentFrom,-1),i.run),n.placeholder?.showing||v(t.id,{...n,placeholder:{...n.placeholder,showing:!0}})},b=t=>{if(t.level===`inline`){e.delete(e.mapping.map(t.to,-1)-1,e.mapping.map(t.to,-1));let n=e.mapping.map(t.from,1);e.delete(n,n+1)}else e.doc.nodesBetween(e.mapping.map(t.from,1),e.mapping.map(t.to,-1),(n,r)=>{let i=n.attrs.controls;if(i?.includes(t.id)){let a=i.filter(e=>e!==t.id);e.setNodeMarkup(r,n.type,{...n.attrs,controls:a.length?a:null})}return!0})};for(let t of[...c].reverse()){if(t.to<=u.fromB||t.from>=u.toB)continue;let i=Object.hasOwn(g,t.id)?g[t.id]:void 0,a=l.get(t);if(!i||!a||Gl(n.doc,a).eq(Gl(r.doc,t)))continue;if(Xl(a,m)){i.deleted||v(t.id,{...i,deleted:!0});continue}if(i.deleted&&p){let{deleted:n,...r}=i;if(f===`accept`&&!ru(t,e))continue;if(v(t.id,r),f===`accept`){b(t);continue}i=r}let s=o[t.id]?.placeholder?.showing===!0;if(s){let t=e.mapping.map(d.map(a.contentFrom,1),1),n=e.mapping.map(d.map(a.contentTo,-1),-1);t<n&&e.delete(t,n)}if(ru(t,e)&&!El.has(i.kind))y(t,i);else{if(s&&(au(e,e.mapping.map(t.contentFrom,-1),e.mapping.map(t.contentTo,1),eu({envelope:h}),iu(r,i)),i.placeholder?.showing&&(i={...i,placeholder:{...i.placeholder,showing:!1}},v(t.id,i))),i.kind===`checkbox`&&p){let e=ou(r.doc,t,i);e!==null&&e!==i.checked&&v(t.id,{...i,checked:e})}if(f!==`value`&&f!==`fields`){if(i.kind===`date`){let e=yu(r.doc,t);if(s||e!==yu(n.doc,a)){let{date:n,...r}=i,a=cu(i,e);a!==(n??null)&&v(t.id,a?{...r,date:a}:r)}}if(wl.has(i.kind)&&!s&&!p){let r=Zl(n.doc,a).find(e=>e.isText);uu(e,e.mapping.map(t.contentFrom,-1),e.mapping.map(t.contentTo,1),r?r.marks.filter(e=>!Dl.has(e.type.name)):null)}}}}return h!==i&&Zr(e,h),_?(Hr(r,e,`controls`,g),g):a}function fu(e,t,n,r,i){if(!(t instanceof R))return null;let a=Bl(e);if(!a.length)return null;let{anchor:o,head:s}=t,c=(e,t)=>e.from<t&&t<e.to;if(o!==s)for(let t=0,n=!0;n&&t<8;t++){n=!1;for(let t of a){if(t.level!==`inline`||c(t,o)===c(t,s))continue;n=!0;let r=c(t,o),i=r?s:o,a=i<=t.from?t.contentFrom:t.contentTo;Ul(e,i,a)?r?s=a:o=a:r?o=i<=t.from?t.to:t.from:s=i<=t.from?t.to:t.from}}let l=Math.min(o,s),u=Math.max(o,s),d=Vl(e,l),f=d&&Object.hasOwn(i,d.id)?i[d.id]:void 0;if(d&&f?.placeholder?.showing&&u<d.to&&d.contentFrom<d.contentTo){let{contentFrom:t,contentTo:i}=d,a=l===t&&u===i,c=r&&n.from===t&&n.to===i;if(l===u&&c&&(l===t||l===i)){if(d.level===`inline`)o=l===i?d.to:d.from,s=o;else return L.near(e.resolve(l===i?d.to:d.from),l===i?1:-1)}else a||(o=t,s=i)}return o===t.anchor&&s===t.head?null:R.create(e,o,s)}var pu=(e,t,n)=>(t?.(e.tr.setSelection(R.create(e.doc,n.contentFrom,n.contentTo))),!0),mu=e=>{let{from:t,to:n}=e.selection,r=Vl(e.doc,t);return r&&Hl(e,r.id)?.placeholder?.showing&&t===r.contentFrom&&n===r.contentTo?r:null},hu=e=>(t,n)=>{if(!X(t)?.envelope.controls)return!1;if(mu(t))return!0;let{selection:r,doc:i}=t;if(!r.empty||!(r instanceof R))return!1;let{$from:a}=r,o=e?a.nodeAfter:a.nodeBefore;if(kl(o)){if(o?.type.name!==(e?`controlStart`:`controlEnd`))return!0;let r=Vl(i,a.pos+(e?1:-1));return r?pu(t,n,r):!1}if(e?a.parentOffset<a.parent.content.size:a.parentOffset>0)return!1;let s=Bl(i).filter(e=>e.level!==`inline`);if(s.some(t=>(e?t.contentTo:t.contentFrom)===a.pos))return!0;let c=e?a.after():a.before(),l=s.find(t=>(e?t.from:t.to)===c);return l?pu(t,n,l):!1},gu=(e,t)=>{let n=Vl(e.doc,e.selection.from),r=n&&Hl(e,n.id);return!n||!r?!1:mu(e)?!0:wl.has(r.kind)?!r.multiLine||Os(e,t):n.level===`inline`},_u=(e,t)=>{let n=Vl(e.doc,e.selection.from),r=n&&Hl(e,n.id);return!n||r?.kind!==`checkbox`?!1:(Fu(n.id,!r.checked)(e,t),!0)};function vu(){return new $e({filterTransaction:$l,appendTransaction(e,t,n){let r=X(n)?.envelope.controls;if(!r)return null;let i=n.tr,a=t.doc!==n.doc&&!e.some(e=>e.getMeta(`historyOp`))?du(i,e,t,n):r,o=fu(i.doc,i.selection,t.selection,t.doc===n.doc,a);return o&&i.setSelection(o),i.steps.length||o?i:null},keymap:{Backspace:hu(!1),Delete:hu(!0),Enter:gu," ":_u}})}function yu(e,t){let n=``,r=0,i=e=>{if(e.isTextblock&&r++&&(n+=`
|
|
5
|
+
`),e.isInline){if(Al(e))return;e.isText?n+=e.text:e.type.name===`hardBreak`?n+=`
|
|
6
|
+
`:e.type.name===`tab`&&(n+=` `)}else e.forEach(i)};return Gl(e,t).forEach(i),n}var bu=(e,t)=>e.items?.find(e=>(e.display??e.value)===t);function xu(e){let t=new Set,n=[];for(let r of Bl(e.doc)){let i=Hl(e,r.id);if(!i||t.has(r.id))continue;t.add(r.id);let a=i.placeholder?.showing===!0,o=a?``:yu(e.doc,r),s=a?null:o;i.kind===`checkbox`?s=i.checked===!0:a?s=null:i.kind===`dropDown`||i.kind===`comboBox`?s=bu(i,o)?.value??o:i.kind===`date`?s=i.date?.slice(0,10)??o:[`text`,`richText`].includes(i.kind)||(s=null),n.push({id:r.id,kind:i.kind,...i.tag===void 0?{}:{tag:i.tag},...i.alias===void 0?{}:{title:i.alias},showingPlaceholder:a,text:o,value:s,...i.kind===`richText`&&!a?{content:(r.level===`cell`?e.doc.slice(r.from+1,r.to-1).content:Gl(e.doc,r)).toJSON()}:{}})}return n}function Su(e,t){let n=Bl(e.doc),r=n.filter(e=>e.id===t);return r.length?r:n.filter(n=>Hl(e,n.id)?.tag===t)}function Cu(e){if(e instanceof Date)return Number.isNaN(e.getTime())?null:lu(e.getFullYear(),e.getMonth()+1,e.getDate());let t=typeof e==`string`?/^(\d{4})-(\d{2})-(\d{2})/.exec(e):null;return t?lu(Number(t[1]),Number(t[2]),Number(t[3])):null}function wu(e,t){let[n,r,i]=t.slice(0,10).split(`-`).map(Number);return mc(new Date(n,r-1,i),e.dateFormat??`d MMMM yyyy`)}function Tu(e){let t=/^[0-9a-f]{1,6}$/i.test(e.value)?Number.parseInt(e.value,16):-1;return t>=0&&t<=1114111&&(t<55296||t>57343)?String.fromCodePoint(t):`☐`}function Eu(e,t,n){let{schema:r}=e;return t.split(`
|
|
7
|
+
`).flatMap((e,t)=>[...t?[r.nodes.hardBreak?.create(null,null,n)]:[],...e?[r.text(e,n)]:[]])}function Du(e,t,n){if(n.placeholder?.showing)return iu(e,n);let r=Zl(e.doc,t).find(e=>e.isText);return r?r.marks.filter(e=>!Dl.has(e.type.name)):[]}function Ou(e,t,n,r){if(!Au(e.doc,t)&&!(n.kind===`richText`&&ju(r)))return null;let i=Du(e,t,n),a=n;if(r===null||r===``)return n.kind===`checkbox`?null:{nodes:[],control:n};let o=t=>({nodes:Eu(e,t,i),control:a});switch(n.kind){case`text`:return typeof r==`string`?o(n.multiLine?r:r.replace(/\r\n?|\n/g,` `)):null;case`richText`:{if(typeof r==`string`)return o(r);if(typeof r!=`object`||r instanceof Date||!Array.isArray(r.content)||!Nu(e,t,r.content))return null;if(!r.content.length)return{nodes:[],control:n};if(t.level===`row`){let t=r.content.map(t=>e.schema.nodeFromJSON(t));return t.every(e=>e.type.name===`tableRow`)?{nodes:t,blocks:!0,control:a}:null}let i=r.content.every(t=>e.schema.nodes[t.type]?.isInline)?r.content.map(t=>e.schema.nodeFromJSON(t)):Mu(r.content);if(i.every(e=>e.isInline))return{nodes:i,control:a};if(t.level===`inline`){let e=i.length===1?i[0]:void 0;if(!e?.isTextblock)return null;let t=[];return e.forEach(e=>{t.push(e)}),{nodes:t,control:a}}return i.at(-1)?.type.name===`table`?null:{nodes:i,blocks:!0,control:a}}case`dropDown`:case`comboBox`:{if(typeof r!=`string`)return null;let e=n.items?.find(e=>e.value===r||e.display===r);return!e&&n.kind===`dropDown`?null:o(e?e.display??e.value:r)}case`date`:{let e=Cu(r);if(e)return{...o(wu(n,e)),control:{...a,date:e}};if(typeof r!=`string`)return null;let{date:t,...i}=a;return{...o(r),control:i}}case`checkbox`:{if(typeof r!=`boolean`)return null;let t=r?n.checkedState??Nl:n.uncheckedState??Pl,a=e.schema.marks.font,o=a&&t.font?Pu(a,t.font):null,s=i.filter(e=>e.type!==a);return{nodes:[e.schema.text(Tu(t),o?o.addToSet(s):i)],control:{...n,checked:r}}}default:return null}}function ku(e,t){let n=e.nodeAt(t.from)?.attrs.controls??[];return n.slice(0,n.indexOf(t.id)+1)}function Au(e,t){if(t.level===`inline`)return!0;if(t.level===`row`)return!1;let n=e.resolve(t.contentFrom),r=e.resolve(t.contentTo);return n.parent.isTextblock&&r.parent.isTextblock&&n.depth===r.depth&&n.node(n.depth-1)===r.node(r.depth-1)}var ju=e=>typeof e==`object`&&!!e&&`content`in e;function Mu(e){let t=[];return kn({type:`doc`,content:e},`content`,!0).forEach(e=>{t.push(e)}),t}function Nu(e,t,n){let r=X(e)?.envelope.controls??{},i=new Set(Bl(e.doc).filter(e=>e===t||e.from<t.from||e.to>t.to).map(e=>e.id)),a=e=>typeof e==`string`&&Object.hasOwn(r,e)&&!i.has(e),o=t.level===`inline`?[]:ku(e.doc,t),s=e.doc.resolve(t.contentFrom),c=!1;for(let e=s.depth;e>0;e--)c||=s.node(e).type.name===`tableCell`;let l=new Map,u=e=>{if(typeof e!=`object`||!e||typeof e.type!=`string`)return!1;let t=e.attrs;if(Ol.has(e.type)||e.type===`noteReference`||e.type===`noteMark`||c&&(e.type===`pageBreak`||e.type===`columnBreak`)||t?.section)return!1;if(e.type===`controlStart`||e.type===`controlEnd`){if(!a(t?.id))return!1;let n=t?.id;l.set(n,(l.get(n)??0)+(e.type===`controlStart`?1:-1))}let n=t?.controls;return n!=null&&!(Array.isArray(n)&&n.every(e=>o.includes(e)||a(e)))||e.marks?.some(e=>e.type===`link`&&!ue(e.attrs))?!1:e.content===void 0||Array.isArray(e.content)&&e.content.every(u)};return n.every(u)&&[...l.values()].every(e=>e===0)}function Pu(e,t){return e.create({ascii:t,hAnsi:t,eastAsia:t,...t===`MS Gothic`?{hint:`eastAsia`}:{}})}function Fu(e,t,n=!1){return(r,a)=>{let o=X(r);if(!o?.envelope.controls)return!1;let s=[];try{for(let n of Su(r,e)){let e=Hl(r,n.id);if(!e||Fl(e))continue;let i=Ou(r,n,e,t);i&&s.push({range:n,next:i})}}catch(e){if(e instanceof i)return!1;throw e}if(!s.length)return!1;let c=r.tr;c.setMeta(xl,`value`).setMeta(n?Ri:Li,!0);let l={...o.envelope.controls};try{for(let{range:e,next:t}of[...s].reverse())if(l[e.id]=t.control,t.blocks){let n=ku(r.doc,e),i=e.level===`cell`,a=t.nodes.map(e=>i?e:e.type.create({...e.attrs,controls:[...n,...(e.attrs.controls??[]).filter(e=>!n.includes(e))]},e.content,e.marks)),[o,s]=i?[e.from+1,e.to-1]:[e.from,e.to];c.replace(o,s,new w(f.fromArray(a),0,0))}else e.contentTo>e.contentFrom&&c.delete(e.contentFrom,e.contentTo),t.nodes.length&&c.insert(e.contentFrom,t.nodes)}catch(e){if(e instanceof F)return!1;throw e}Hr(r,c,`controls`,l);let u=Vo(r,c);return!u||!r.applyTransaction(u).transactions.length?!1:(a?.(c),!0)}}[...Ol];var Iu=Ha,Lu=e=>t=>{let n=t?.toLowerCase()??null;return n!==null&&!N(n)?()=>!1:e(n)},Ru=Lu(Fa),zu=Lu(Ia),Bu=to,Vu=eo,Hu=ao,Uu=ro,Wu=io,Gu=oo;function Ku(){return new $e({keymap:{Enter:Hu,Backspace:Gu,Tab:Uu,"Shift-Tab":Wu,"Mod-Shift-7":Vu(`orderedList`),"Mod-Shift-8":Vu(`bulletList`)}})}var qu={insertion:`insertion`,deletion:`deletion`,formatChange:`formatting`},Ju=new Set(cn);function Yu(e,t){let n=[],r=e.content.size;t?.change&&e.lastChild?.isTextblock&&n.push({kind:`sectionFormatting`,id:t.change.id,author:t.change.author,date:t.change.date??null,from:r-1,to:r,move:null});let i=e=>{let t=e.mark.attrs;n.push({kind:qu[e.mark.type.name],id:t.id,author:t.author,date:t.date??null,from:e.from,to:e.to,move:t.move??null})};return e.descendants((e,t)=>{if(e.type.name===`tableRow`){let r=e.attrs.revision;for(let[i,a]of[[`rowInsertion`,r?.insertion],[`rowDeletion`,r?.deletion]])a&&n.push({kind:i,id:a.id,author:a.author,date:a.date??null,from:t,to:t+e.nodeSize,move:null});return!0}if(!e.isTextblock)return!0;let r=e.attrs.formatChange;r&&n.push(Xu(`paragraphFormatting`,r,t,e));let a=e.attrs.section?.change;a&&n.push(Xu(`sectionFormatting`,a,t,e));let o=[];e.forEach((e,n)=>{let r=t+1+n,a=[];for(let t of e.marks){if(!qu[t.type.name])continue;let n=o.find(e=>e.to===r&&e.mark.eq(t));n&&(n.to=r+e.nodeSize),a.push(n??{mark:t,from:r,to:r+e.nodeSize})}for(let e of o)a.includes(e)||i(e);o=a});for(let e of o)i(e);let s=e.attrs.revision;return s?.insertion&&n.push(Xu(`paragraphInsertion`,s.insertion,t,e)),s?.deletion&&n.push(Xu(`paragraphDeletion`,s.deletion,t,e)),!1}),n.sort((e,t)=>e.from-t.from||e.to-t.to)}function Xu(e,t,n,r){let i=n+r.nodeSize;return{kind:e,id:t.id,author:t.author,date:t.date??null,from:e===`paragraphFormatting`?n+1:i-1,to:e===`paragraphFormatting`?i-1:i,move:null}}var Zu=new Set([`insertion`,`deletion`,`formatting`]),Qu=new Set([`bookmarkStart`,`bookmarkEnd`,`commentStart`,`commentEnd`,`controlStart`,`controlEnd`]);function $u(e,t,n,r,i={}){let a=Yu(e,t).filter(e=>!i.author||e.author===i.author),o;if(n===r){let e=a.filter(e=>e.from<=n&&n<=e.to),t=e.filter(e=>e.kind!==`paragraphFormatting`&&e.kind!==`sectionFormatting`);o=t.length?t:e}else o=a.filter(e=>e.from<r&&n<e.to).map(e=>Zu.has(e.kind)?{...e,from:Math.max(e.from,n),to:Math.min(e.to,r)}:e);let s=new Set(o.map(e=>e.move).filter(e=>e!==null)),c=a.filter(e=>e.move!==null&&s.has(e.move)&&!o.some(t=>t.id===e.id&&t.kind===e.kind));return[...o,...c]}function ed(e,t,n,r){let i=t.doc.type.schema,a=[],o=[],s=new Map,c=!1,l=[...n.filter(e=>e.kind===`sectionFormatting`),...n.filter(e=>e.kind!==`sectionFormatting`)];for(let n of l){let{kind:l,from:u,to:d}=n,f=i.marks[l===`formatting`?`formatChange`:l];switch(l){case`insertion`:case`deletion`:if(!f)break;l===`insertion`===r?nd(t,u,d,f.name,n.id):a.push([u,d]);break;case`formatting`:t.doc.nodesBetween(u,d,(e,a)=>{if(!e.isInline)return!0;let o=e.marks.find(e=>e.type.name===`formatChange`);if(!o||o.attrs.id!==n.id)return!1;let s=Math.max(a,u),c=Math.min(a+e.nodeSize,d);if(!r){for(let n of e.marks)Ju.has(n.type.name)&&t.removeMark(s,c,n);for(let e of o.attrs.previous)t.addMark(s,c,i.mark(e.type,e.attrs??null))}return t.removeMark(s,c,o),!1});break;case`paragraphFormatting`:{let e=t.doc.resolve(u).before(),n=t.doc.nodeAt(e);if(!n?.isTextblock)break;let i={...n.attrs,formatChange:null};if(!r){let e=n.attrs.formatChange.previous;for(let t of Do)i[t]=e[t]??null}t.setNodeMarkup(e,n.type,i);break}case`sectionFormatting`:{let i=t.doc.resolve(u).before(),a=t.doc.nodeAt(i),o=a?.attrs.section;a&&o?.change?.id===n.id?t.setNodeMarkup(i,a.type,{...a.attrs,section:rs(o,r)}):Hr(e,t,`section`,rs(Zo(e,t),r));break}case`rowInsertion`:case`rowDeletion`:{let e=t.doc.nodeAt(u);if(e?.type.name!==`tableRow`)break;if(l===`rowDeletion`===r){let e=t.doc.resolve(u).before();s.set(e,[...s.get(e)??[],[u,d]])}else{let n={...e.attrs.revision};delete n[l===`rowInsertion`?`insertion`:`deletion`];let r=Object.keys(n).length?n:null;t.setNodeMarkup(u,e.type,{...e.attrs,revision:r})}break}case`paragraphInsertion`:case`paragraphDeletion`:{let n=t.doc.resolve(u).before(),i=t.doc.nodeAt(n);if(!i?.isTextblock)break;let s={...i.attrs.revision},d=l===`paragraphDeletion`===r;delete s[l===`paragraphInsertion`?`insertion`:`deletion`];let f=Object.keys(s).length?s:null;t.setNodeMarkup(n,i.type,{...i.attrs,revision:f});let p=n+i.nodeSize,m=td(i,n+1,a),h=d&&!!t.doc.resolve(p).nodeAfter?.isTextblock,g=i.attrs.section;d&&g&&($o(e,t,g,p),h||t.setNodeMarkup(n,i.type,{...i.attrs,revision:f,section:null})),h?o.push({pos:p,keepFirst:r&&!m}):d&&!r&&(!i.content.size||m)&&t.doc.resolve(n).parent.childCount>1&&(a.push([n,p]),c=!0);break}}}for(let[e,n]of s){let r=t.doc.nodeAt(e);r&&n.length===r.childCount?a.push([e,e+r.nodeSize]):a.push(...n)}if(s.size||c){let e=a.filter(([e,t])=>!a.some(([n,r])=>n<e&&t<=r||n<=e&&t<r));a.length=0,a.push(...e)}let u=[...a.map(([e,n])=>({at:e,run:()=>t.delete(e,n)})),...o.filter(({pos:e})=>!(s.size||c)||!a.some(([t,n])=>t<e&&e<n)).map(({pos:e,keepFirst:n})=>({at:e-1,run:()=>rd(t,e,n)}))].sort((e,t)=>t.at-e.at);for(let e of u)e.run();oa(t)}function td(e,t,n){let r=!0;return e.forEach((e,i)=>{let a=t+i;Qu.has(e.type.name)||n.some(([t,n])=>t<=a&&a+e.nodeSize<=n)||(r=!1)}),r}function nd(e,t,n,r,i){e.doc.nodesBetween(t,n,(a,o)=>{if(!a.isInline)return!0;let s=a.marks.find(e=>e.type.name===r&&e.attrs.id===i);return s&&e.removeMark(Math.max(o,t),Math.min(o+a.nodeSize,n),s),!1})}function rd(e,t,n){let r=e.doc.resolve(t),i=r.nodeBefore,a=r.nodeAfter;if(!i?.isTextblock||!a?.isTextblock)return;let o=t-i.nodeSize;e.join(t);let s=n?{...i.attrs}:{...a.attrs};if(n)for(let e of qe)s[e]=a.attrs[e]??null;e.setNodeMarkup(o,i.type,s)}function id(e,t,n,r,i){let a=Wr(e,t,n);if(!a)return;let o=i===`insertion`?`paragraphInsertion`:`paragraphDeletion`,s=$u(a.doc,void 0,0,a.doc.content.size).filter(e=>e.kind===i||e.kind===o);if(!s.length)return;let c=qr(e,a.doc),l=c.tr;ed(c,l,s,r),t.step(new Rr(n,a,{...a,doc:l.doc}))}function ad(e,t,n,r=!1){let i=(a,o)=>{if(!a.schema.marks.insertion)return!1;let s=r?Kr(a):null;if(s)return o?s.run(i):s.can(i);let c=X(a)?.envelope.controls,l=t=>n=>n.kind.toLowerCase().includes(`deletion`)!==e||!Wl(t,c,n.from,n.to),u=new Set,d=t(a).flatMap(e=>$u(a.doc,X(a)?.envelope.section,e.from,e.to,n)).filter(l(a.doc)).filter(e=>{let t=`${e.kind} ${e.id} ${e.from} ${e.to}`;return!u.has(t)&&!!u.add(t)}),f=r?[...X(a)?.stories??[]].flatMap(([e,t])=>{let r=$u(t.doc,void 0,0,t.doc.content.size,n).filter(l(t.doc));return r.length?[{id:e,story:t,changes:r}]:[]}):[];if(!d.length&&!f.length)return!1;if(o){let t=a.tr.setMeta(So,!0).setMeta(Li,!0),n=e?`accept`:`reject`;t.setMeta(xl,n);let r=X(a)?.envelope,i=r;try{d.length&&ed(a,t,d,e);for(let{id:i,story:o,changes:s}of f){let c=nt.create({doc:o.doc,plugins:[...qr(a,o.doc,r).plugins,vu()]}),l=c.tr.setMeta(xl,n);ed(c,l,s,e);let u=c.applyTransaction(l).state;r=X(u)?.envelope,t.step(new Rr(i,o,{...o,doc:u.doc}))}r&&r!==i&&(r.styles!==i?.styles&&Zr(t,{...i,styles:r.styles}),r.controls!==i?.controls&&Hr(a,t,`controls`,r.controls))}catch(e){if(e instanceof F)return!1;throw e}o(t)}return!0};return i}var od=e=>e.selection.ranges,sd=e=>[{from:0,to:e.doc.content.size}],cd=ad(!0,od),ld=ad(!1,od),ud=e=>ad(!0,sd,e===void 0?{}:{author:e},!0),dd=e=>ad(!1,sd,e===void 0?{}:{author:e},!0);function fd(e){return(t,n)=>{let r=(jo(t)?.view??`markup`)!==`markup`,i=Yu(t.doc,X(t)?.envelope.section).filter(e=>!r||e.kind!==`deletion`&&e.kind!==`paragraphDeletion`),{from:a,to:o}=t.selection,s=e?i.find(e=>e.from>a||e.from===a&&e.to>o):[...i].reverse().find(e=>e.from<a||e.from===a&&e.to<o);if(!s)return!1;if(n){let e=s.kind===`paragraphInsertion`||s.kind===`paragraphDeletion`||s.kind===`sectionFormatting`?s.from:s.to;n(t.tr.setSelection(R.create(t.doc,s.from,e)))}return!0}}var pd=fd(!0),md=fd(!1),hd={footnote:`footnotes`,endnote:`endnotes`},gd={footnote:{position:`pageBottom`,format:`decimal`,start:1,restart:`continuous`},endnote:{position:`docEnd`,format:`lowerRoman`,start:1,restart:`continuous`}};function _d(e){return e.startsWith(`footnote:`)?`footnote`:e.startsWith(`endnote:`)?`endnote`:null}var vd=e=>(e?.kind===`footnote`||e?.kind===`endnote`)&&(e.noteType??`normal`)===`normal`;function yd(e,t,n){let r=hd[t];return{...gd[t],...e.settings?.[r],...n?.[r]}}var bd=[],xd=new WeakMap;function Sd(e){let t=xd.get(e);if(!t){let n=[];e.descendants((e,t)=>(e.type.name===`noteReference`&&n.push({story:String(e.attrs.story),offset:t+1,customMark:e.attrs.customMark===!0,insertion:e.marks.find(e=>e.type.name===`insertion`),deletion:e.marks.find(e=>e.type.name===`deletion`)}),!0)),t=n.length?n:bd,xd.set(e,t)}return t}function Cd(e,t,n={}){let r=[],i={footnote:{n:0,section:-1,page:void 0,start:1},endnote:{n:0,section:-1,page:void 0,start:1}},a=[];e.forEach(e=>{let t=e.attrs.section;t&&a.push(t)});let o=0;return e.forEach((e,s)=>{let c=a[o]??t.section;for(let a of Sd(e)){let e=_d(a.story);if(!e)continue;let l=s+a.offset,u=!!a.deletion,d={story:a.story,kind:e,pos:l,section:o,deleted:u,customMark:a.customMark};if(a.customMark||u&&n.hideDeleted){r.push({...d,text:``});continue}let f=yd(t,e,c),p=i[e],m=f.restart===`eachPage`?n.pageOf?.(l,a.story):void 0,h=p.section<0,g=p.section!==o;h||f.restart===`eachSect`&&g||f.restart===`eachPage`&&m!==void 0&&m!==p.page||g&&f.start!==p.start?p.n=f.start:p.n++,p.section=o,p.start=f.start,p.page=m,r.push({...d,text:br(p.n,f.format)})}e.attrs.section&&o++}),r}var wd=e=>new Map(e.map(e=>[e.story,e.text]));function Td(e,t,n,r){let i=qr(e,t.doc).tr,a=n.type.name,o={id:n.attrs.id,author:n.attrs.author,date:n.attrs.date};return t.doc.descendants((e,t)=>{if(e.isInline)return!Ed.has(e.type.name)&&!e.marks.some(e=>e.type.name===a)&&i.addMark(t,t+e.nodeSize,n),!1;if(e.isTextblock&&r){let n=e.attrs.revision??{};i.setNodeMarkup(t,e.type,{...e.attrs,revision:{...n,[a]:o}})}return!0}),{...t,doc:i.doc}}var Ed=new Set([`bookmarkStart`,`bookmarkEnd`,`commentStart`,`commentEnd`,`controlStart`,`controlEnd`]);function Dd(e){let t=new Map;return e.forEach(e=>{for(let n of Sd(e))t.set(n.story,n)}),t}function Od(){return new $e({appendTransaction(e,t,n){if(t.doc===n.doc||e.some(e=>e.getMeta(`historyOp`)))return null;let r=X(n);if(!r||![...r.stories.values()].some(vd))return null;let i=Dd(t.doc),a=Dd(n.doc),o=n.tr.setMeta(So,!0),s=-1,c=e=>(s<0&&(s=zo(n)),e.type.create({...e.attrs,id:s++}));for(let[e,t]of i){let r=Wr(n,o,e);if(!r||!vd(r))continue;let i=a.get(e);i?(i.deletion&&!t.deletion&&o.step(new Rr(e,r,Td(n,r,c(i.deletion),!0))),t.deletion&&!i.deletion&&id(n,o,e,!1,`deletion`),t.insertion&&!i.insertion&&id(n,o,e,!0,`insertion`)):o.step(new Rr(e,r,null))}for(let[e,t]of a){let r=Wr(n,o,e);!i.has(e)&&t.insertion&&r&&vd(r)&&o.step(new Rr(e,r,Td(n,r,c(t.insertion),!1)))}return o.steps.length?o:null}})}function kd(e,t,n,r,i,a){let o=t.stories.get(n),s=o;i.doc!==r.doc&&(s={...o,doc:i.doc},e.step(new Rr(n,o,s,r.selection.toJSON(),i.selection.toJSON())));let c=!1;for(let t of a){for(let n of t.steps)(n instanceof Pr||n instanceof Lr)&&e.step(n);c||=ei(t)!==void 0}if(c){let{numbering:n,styles:r,resources:a,controls:o}=X(i).envelope,{resources:s,controls:c,...l}=ei(e)??t.envelope;Zr(e,{...l,numbering:n,styles:r,...a?{resources:a}:{},...o?{controls:o}:{}})}return{after:s,patched:c}}var Ad=class{id;host;state;own=!1;alive=!0;listeners=new Set;constructor(e,t){this.id=e,this.host=t;let n=this.tree()?.doc;this.state=this.create(n)}tree(){return X(this.host.state)?.stories.get(this.id)}create(e){let{host:t,id:n}=this,r=X(t.state),a=r.stories.get(n)?.kind;return nt.create({doc:e,selection:L.atStart(e),plugins:[new $e({key:Gr,state:{init:()=>t,apply:()=>t}}),new $e({filterTransaction(e){if(!e.docChanged)return!0;try{return jn(e.doc,a,`story`),!0}catch(e){if(e instanceof i)return!1;throw e}}}),...t.plugins(r,jo(t.state))]})}notify(e){for(let t of this.listeners)t(this.state,e)}current(e){let t=X(this.host.state),n=jo(this.host.state);if(X(e)===t&&jo(e)===n)return e;let r=$r(e.tr,t);return n&&Mo(r,n),e.apply(r)}dispatch=e=>{if(!this.alive)return;let{host:t,id:n,state:r}=this,i=Vo(r,e);if(!i)return;let a=r.applyTransaction(i);if(!a.transactions.length)return;let o=a.state,s=t.state,c=X(s),l=c.stories.get(n),u=s.tr,{after:d,patched:f}=kd(u,c,n,r,o,a.transactions),p=jo(o),m=!!p&&p!==jo(r);if(m&&Mo(u,p),u.steps.length||f||m){u.setMeta(So,!0),u.setMeta(zi,{id:n,tr:i}),u.time=i.time,i.addToHistory||u.setMeta(`addToHistory`,!1),i.getMeta(`closeHistory`)&&u.setMeta(Li,!0),i.getMeta(`joinHistory`)&&u.setMeta(Ri,!0),this.own=!0;try{t.dispatch(u)}finally{this.own=!1}if(d!==l&&X(t.state)?.stories.get(n)!==d)return}this.state=this.current(o),this.notify(a.transactions)};sync(e){if(this.own)return;let t=this.tree();if(!t){this.retire();return}let{state:n}=this,r=null;for(let t of e)for(let e of t.steps)e instanceof Rr&&e.id===this.id&&(r=e.selectionAfter);if(t.doc!==n.doc){let e=r??n.selection.toJSON();this.state=this.current(n.withDocument(t.doc,L.fromJSON(t.doc,e))),this.notify([]);return}let i=this.current(n);i!==n&&(this.state=i,this.notify([]))}retire(){this.alive=!1}},jd={width:12240,height:15840,margin:1440};function Md(e){let t=e.margins??{};return{pageSize:{width:dt(e.pageSize?.width??jd.width),height:dt(e.pageSize?.height??jd.height)},margins:{top:dt(Math.abs(t.top??jd.margin)),right:dt(t.right??jd.margin),bottom:dt(Math.abs(t.bottom??jd.margin)),left:dt((t.left??jd.margin)+(t.gutter??0))}}}function Nd(e){let{content:t,...n}=Dn(e);return{doc:kn(t),settings:Md(n.section),envelope:n}}function Pd(e){let{dispatch:t}=e,n=n=>n(e.state(),t),r=()=>{let t=e.state(),n=[...(Kr(t)?null:X(t))?.stories??[]].filter(([,e])=>Bl(e.doc).length);return[{editor:i},...n.flatMap(([t])=>{let n=e.story(t);return n?[{editor:n,story:t}]:[]})]},i={get settings(){return e.settings()},get state(){return e.state()},dispatch:t,run:n,can:t=>t(e.state()),handleKey(n){let r=e.state();return r.plugins.some(e=>{let i=e.spec.keymap?.[n];return i?i(r,t):!1})},select(n,r=n){let i=e.state(),a=i.doc.content.size,o=e=>Math.max(0,Math.min(e,a));t(i.tr.setSelection(R.create(i.doc,o(n),o(r))))},commands:{insertText:e=>n(ds(e)),deleteSelection:()=>n(ls),deleteBackward:e=>n(_s(e)),deleteForward:e=>n(vs(e)),joinBackward:()=>n(bs),joinForward:()=>n(xs),splitBlock:()=>n(Ss),insertHardBreak:()=>n(Os),insertPageBreak:()=>n(ks),toggleMark:(e,t)=>n(Ps(e,t)),setBlockType:(e,t)=>n(Ls(e,t)),selectAll:()=>n(js),undo:()=>n(Zi),redo:()=>n(Qi),wrapInList:e=>n(Bu(e)),toggleList:e=>n(Vu(e)),indentListItem:()=>n(Uu),outdentListItem:()=>n(Wu),setLink:e=>n(_o(e)),removeLink:()=>n(vo),setAlign:e=>n(Iu(e)),setTextColor:e=>n(Ru(e)),setHighlight:e=>n(zu(e)),setTrackChanges:(e,t)=>n(No(e,t)),setReviewView:e=>n(Po(e)),acceptChange:()=>n(cd),rejectChange:()=>n(ld),acceptAllChanges:e=>n(ud(e)),rejectAllChanges:e=>n(dd(e)),nextChange:()=>n(pd),previousChange:()=>n(md),addComment:(e,t)=>n(Ys(e,t)),replyToComment:(e,t,r)=>n(Xs(e,t,r)),editComment:(e,t)=>n(Qs(e,t)),resolveComment:(e,t)=>n($s(e,t)),deleteComment:e=>n(nc(e)),deleteAllComments:()=>n(rc),setControlValue(e,t){let n=!1;for(let{editor:i}of r())i.run(Fu(e,t,n))&&(n=!0);return n}},controlValues:()=>r().flatMap(({editor:e,story:t})=>xu(e.state).map(e=>t?{...e,story:t}:e)),get trackingChanges(){return jo(e.state())?.on??!1},isMarkActive:t=>Is(e.state(),t),getDocument:e.getDocument,setDocument:e.setDocument,subscribe:e.subscribe,story:e.story,get storyView(){return e.views.current},set storyView(t){e.views.current=t},storyChanged:e.storyChanged,get navigation(){return e.views.navigation},set navigation(t){e.views.navigation=t}};return i}function Fd({document:e=En(),plugins:t=[],author:n=`Author`,trackChanges:r=!1,reviewView:i=`markup`}={}){let a=Nd(e),o={on:r,author:n,view:i},s=({envelope:e})=>[...t,Vi(),Xr(e),Ao(o),Ni(),vu(),oc(),Od(),fa(),Ku(),Rs()],c=nt.create({doc:a.doc,plugins:s(a)}),l=new Set,u={current:null,navigation:null},d=new Map,f=e=>{for(let t of l)t(c,e)},p=()=>f([]),m=e=>{let t=Vo(c,e);if(!t)return;let n=c.applyTransaction(t);if(c=n.state,n.transactions.length){for(let[e,{editing:t}]of d)t.sync(n.transactions),t.alive||d.delete(e);f(n.transactions)}},h=e=>e(c,m),g={section:a.envelope.section,settings:a.settings},_=()=>{let e=X(c)?.envelope.section??g.section;return e!==g.section&&(g={section:e,settings:Md(e)}),g.settings},v=()=>({...structuredClone(X(c)?.envelope??a.envelope),content:c.doc.toJSON()}),y=e=>{let n=new Ad(e,{get state(){return c},run:h,can:e=>e(c),dispatch:m,plugins:(e,n)=>[...t,Xr(e.envelope,e),Ao(n??o),Ni(),vu(),oc(),fa(),Ku(),Rs()]}),r=Pd({state:()=>n.state,dispatch:n.dispatch,settings:_,getDocument:()=>({...v(),content:n.state.doc.toJSON()}),setDocument(e){let{doc:t}=Nd(e),r=n.state.tr.replace(0,n.state.doc.content.size,new w(t.content,0,0));n.dispatch(r.setSelection(L.atStart(r.doc)))},subscribe(e){return n.listeners.add(e),()=>n.listeners.delete(e)},story:b,views:u,storyChanged:p});return d.set(e,{editing:n,editor:r}),r},b=e=>X(c)?.stories.has(e)?d.get(e)?.editor??y(e):null;return Pd({state:()=>c,dispatch:m,settings:_,getDocument:v,setDocument(e){o=jo(c)??o,a=Nd(e),c=nt.create({doc:a.doc,plugins:s(a)});for(let{editing:e}of d.values())e.retire();d.clear(),f([])},subscribe(e){return l.add(e),()=>l.delete(e)},story:b,views:u,storyChanged:p})}var Id=`data-page-break`,Ld=`data-column-break`,Q=96/1440,Rd=9525,zd=`data-foli-picture`;function Bd(e){let t=e?.data;if(t&&/^data:image\//i.test(t))return t;let n=e?.url;return n&&/^(https?|blob):/i.test(n)?n:void 0}function Vd(e,t,n){let r=String(e.resource??``),i=`${Number(e.width)/Rd}px`,a=`${Number(e.height)/Rd}px`,o=e.decorative===!0,s=String(e.alt??``),c=o?``:s||`Picture without alt text`,l=n?.(r),u;if(l){let e=t.createElement(`img`);e.src=l,e.alt=c,e.draggable=!1,e.referrerPolicy=`no-referrer`,u=e}else u=t.createElement(`span`),u.setAttribute(`role`,`img`),c?u.setAttribute(`aria-label`,c):u.setAttribute(`aria-hidden`,`true`),u.style.boxSizing=`border-box`,u.style.border=`1px dashed GrayText`;u.setAttribute(zd,r),!s&&!o&&(u.dataset.foliNoAlt=``),e.title&&(u.title=String(e.title));let d=u.style;return d.display=l?`inline`:`inline-block`,d.verticalAlign=`baseline`,d.maxWidth=`none`,d.maxHeight=`none`,d.width=i,d.height=a,u}var Hd=`data-foli-float`;function Ud(e){let t=e?.margins??{},n=e?.pageSize?.width??12240,r=e?.pageSize?.height??15840,i=(t.left??1440)+(t.gutter??0),a=Math.abs(t.top??1440);return{pageWidth:n*Q,pageHeight:r*Q,marginLeft:i*Q,marginTop:a*Q,textWidth:(n-i-(t.right??1440))*Q,textHeight:(r-a-Math.abs(t.bottom??1440))*Q}}function Wd(e,t){let n=t.pageWidth-t.marginLeft-t.textWidth;switch(e){case`page`:return[0,t.pageWidth];case`leftMargin`:case`insideMargin`:return[0,t.marginLeft];case`rightMargin`:case`outsideMargin`:return[t.marginLeft+t.textWidth,n];default:return[t.marginLeft,t.textWidth]}}function Gd(e,t){let n=t.pageHeight-t.marginTop-t.textHeight;switch(e){case`page`:return[0,t.pageHeight];case`topMargin`:case`insideMargin`:return[0,t.marginTop];case`bottomMargin`:case`outsideMargin`:return[t.pageHeight-n,n];default:return[t.marginTop,t.textHeight]}}function Kd(e,[t,n],r){if(typeof e.offset==`number`)return t+e.offset/Rd;let{align:i}=e;return i===`right`||i===`bottom`||i===`outside`?t+n-r:i===`center`?t+(n-r)/2:t}function qd(e,t,n){return Kd(e,Wd(e.relativeTo,n),t)-n.marginLeft}function Jd(e,t,n){return e.relativeTo===`paragraph`||e.relativeTo===`line`?{paragraph:typeof e.offset==`number`?e.offset/Rd:0}:{page:Kd(e,Gd(e.relativeTo,n),t)}}function Yd(e,t,n,r){let i=e.float,a=Number(e.width)/Rd,o=Number(e.height)/Rd,s=e=>(i.distance?.[e]??0)/Rd,c=Vd(e,t,n);c.style.display=`block`;let l=t.createElement(`span`);l.setAttribute(Hd,i.wrap),l.append(c);let u=l.style;u.display=`block`;let d=qd(i.horizontal,a,r),f=Jd(i.vertical,o,r);if(i.wrap===`behind`||i.wrap===`inFront`)return u.position=`absolute`,u.zIndex=i.wrap===`behind`?`-1`:`1`,u.left=`${r.marginLeft+d}px`,f.page===void 0?u.marginTop=`${f.paragraph}px`:u.top=`${f.page}px`,{nodes:[l],holder:l};let p=s(`top`),m=(f.paragraph??0)-p,h=t.createElement(`span`);if(h.setAttribute(`aria-hidden`,`true`),h.style.width=`0`,h.style.height=`${Math.max(0,m)}px`,u.marginTop=`${p+Math.min(0,m)}px`,u.marginBottom=`${s(`bottom`)}px`,i.wrap===`topAndBottom`)return h.style.float=`left`,u.float=`left`,u.clear=`both`,u.width=`100%`,c.style.marginLeft=`${d}px`,{nodes:[h,l],holder:l};let g=i.side===`left`||i.side!==`right`&&d+a/2>r.textWidth/2,_=g?`right`:`left`;return h.style.float=_,u.float=_,u.clear=_,g?(u.marginRight=`${r.textWidth-d-a}px`,u.marginLeft=`${s(`left`)}px`):(u.marginLeft=`${d}px`,u.marginRight=`${s(`right`)}px`),{nodes:[h,l],holder:l}}var Xd=[`#B5082E`,`#1F5FAD`,`#2E7D32`,`#8E24AA`,`#A64B00`,`#00737F`,`#AD1457`,`#5D4037`];function Zd(e){let t=0;for(let n of e)t=t*31+(n.codePointAt(0)??0)>>>0;return Xd[t%Xd.length]}function Qd(e,t,n,r,i){let a=e.createElement(t?`ins`:`del`),o=r?`, ${r.slice(0,10)}`:``;return a.title=`${t?`Inserted`:`Deleted`} by ${n||`an unknown author`}${o}`,i===`markup`?(a.style.color=Zd(n),a.style.textDecorationLine=t?`underline`:`line-through`):(a.style.textDecorationLine=`none`,t||(a.style.display=`none`)),a}var $d=`data-foli-note-ref`,ef=`data-foli-note-number`,tf=192;function nf(e,t){if(!e||![e,...e.getElementsByTagName(`*`)].some(e=>e.localName===`separator`||e.localName===`continuationSeparator`))return null;let n=t.createElement(`span`);n.dataset.foliSeparator=``;let{style:r}=n;return r.display=`inline-block`,r.width=`${tf}px`,r.maxWidth=`100%`,r.height=`0`,r.borderTop=`1px solid #000`,r.verticalAlign=`middle`,n}function rf(e,t){return n=>{let r=e&&Object.hasOwn(e,n)?e[n]:void 0;if(!r)return;let i=t?.(n,r);return i===void 0?Bd(r):i||void 0}}var af={calibri:[`Carlito`],cambria:[`Caladea`],arial:[`Liberation Sans`,`Arimo`],"times new roman":[`Liberation Serif`,`Tinos`],"courier new":[`Liberation Mono`,`Cousine`],georgia:[`Gelasio`]},of=new Set([`cambria`,`times new roman`,`georgia`,`garamond`,`book antiqua`]),sf=new Set([`courier new`,`consolas`,`courier`]);function cf(e){let t=e??`Times New Roman`,n=t.toLowerCase(),r=of.has(n)?`serif`:sf.has(n)?`monospace`:`sans-serif`,i=e=>`"${e.replace(/["\\]/g,``)}"`;return[t,...Object.hasOwn(af,n)?af[n]:[]].map(i).concat(r).join(`, `)}var lf={black:`#000000`,blue:`#0000FF`,cyan:`#00FFFF`,green:`#00FF00`,magenta:`#FF00FF`,red:`#FF0000`,yellow:`#FFFF00`,white:`#FFFFFF`,darkBlue:`#000080`,darkCyan:`#008080`,darkGreen:`#008000`,darkMagenta:`#800080`,darkRed:`#800000`,darkYellow:`#808000`,darkGray:`#808080`,lightGray:`#C0C0C0`},uf={double:`double`,dotted:`dotted`,dottedHeavy:`dotted`,dash:`dashed`,dashedHeavy:`dashed`,dashLong:`dashed`,wave:`wavy`,wavyHeavy:`wavy`,wavyDouble:`wavy`},df={left:`left`,start:`left`,right:`right`,end:`right`,center:`center`,both:`justify`,distribute:`justify`},ff={double:`double`,dotted:`dotted`,dashed:`dashed`,dashSmallGap:`dashed`,none:`none`,nil:`none`},pf=e=>e.font.ascii??e.font.hAnsi;function mf(e,t,n){let r=t.size/2*(96/72),{line:i,lineRule:a}=e.spacing;return i===null?String(n):a===`exact`?`${i*Q}px`:a===`atLeast`?`${Math.max(i*Q,n*r)}px`:String(n*i/240)}function hf(e,t,n){let{style:r}=e;r.fontFamily=cf(pf(t)),r.fontSize=`${t.size/2}pt`,r.lineHeight=n,r.fontWeight=t.bold?`700`:`400`,r.fontStyle=t.italic?`italic`:`normal`;let i=[];t.underline&&i.push(`underline`),(t.strike||t.doubleStrike)&&i.push(`line-through`),i.length&&(r.textDecorationLine=i.join(` `),t.doubleStrike||t.underline===`double`?r.textDecorationStyle=`double`:t.underline&&uf[t.underline]&&(r.textDecorationStyle=uf[t.underline]),t.underlineColor&&t.underlineColor!==`auto`&&(r.textDecorationColor=`#${t.underlineColor}`)),t.caps&&(r.textTransform=`uppercase`),t.smallCaps&&(r.fontVariant=`small-caps`),t.color&&(r.color=`#${t.color}`);let a=t.highlight?lf[t.highlight]:t.shading&&`#${t.shading}`;a&&(r.backgroundColor=a),t.verticalAlign!==`baseline`&&(r.verticalAlign=t.verticalAlign===`superscript`?`super`:`sub`,r.fontSize=`${t.size/2*(2/3)}pt`,r.lineHeight=`0`),t.characterSpacing&&(r.letterSpacing=`${t.characterSpacing*Q}px`),t.hidden&&(r.display=`none`)}function gf(e,t){let{style:n}=e;n.margin=`0`,n.whiteSpace=`pre-wrap`,n.overflowWrap=`break-word`,n.tabSize=`${720*Q}px`;let{left:r,right:i,firstLine:a,hanging:o}=t.indent;n.paddingLeft=`${r*Q}px`,n.paddingRight=`${i*Q}px`,n.textIndent=`${(a-o)*Q}px`;let s=t.justification&&df[t.justification];s&&(n.textAlign=s),t.shading?.fill&&t.shading.fill!==`auto`&&(n.backgroundColor=`#${t.shading.fill}`);for(let[e,r]of Object.entries(t.borders??{})){if(!r||e===`between`||e===`bar`)continue;let t=ff[r.style]??`solid`,i=t===`none`?0:Math.max((r.size??4)/8*(96/72),1),a=r.color&&r.color!==`auto`?`#${r.color}`:`currentColor`;n.setProperty(`border-${e}`,`${i}px ${t} ${a}`),n.setProperty(`padding-${e}`,`${(r.space??0)*96/72}px`)}}var _f=new Set([`txbxContent`,`Fallback`]);function vf(e){let t=``;for(let n of e.children)_f.has(n.localName)||(n.localName===`t`?t+=n.textContent:n.localName===`tab`?t+=` `:t+=vf(n));return t}function yf(e,t){let n=[];for(let r of e.children)t.has(r.localName)?n.push(r):_f.has(r.localName)||n.push(...yf(r,t));return n}var bf=new Set([`p`]),xf=new Set([`r`]),Sf=new Set([`tr`]),Cf=new Set([`tc`]),wf=new Set([`p`,`tbl`]);function Tf(e,t){let n=t.defaultView;if(!n?.DOMParser)return null;let r=new Set;for(let t of e.matchAll(/<\/?([A-Za-z_][\w.-]*):|\s([A-Za-z_][\w.-]*):[\w.-]+\s*=/g)){let e=t[1]??t[2];e&&e!==`xml`&&e!==`xmlns`&&r.add(e)}let i=[...r].map(e=>` xmlns:${e}="urn:foli:${e}"`).join(``),a=new n.DOMParser().parseFromString(`<foli${i}>${e}</foli>`,`application/xml`),o=a.documentElement;return o.localName!==`foli`||a.getElementsByTagName(`parsererror`).length?null:o.firstElementChild}function Ef(e,t,n={}){let r=n.review??`markup`,i=n.fieldCodes===!0,a=new Map,o=e=>{let t=a.get(e);return t===void 0&&(t=n.lineRatio?.(e)??1.2,a.set(e,t)),t},s=n.resolver??new Mr(e),c=rf(e.resources,n.resource),l=Ud(e.section),u=e.content.content??[],d=e=>e.attrs??{},f=e=>{let t=u[e],n=t&&d(t).revision;return r!==`markup`&&t?.type===`paragraph`&&!!n?.deletion&&u[e+1]?.type===`paragraph`},p=s.markers(u.map((e,t)=>e.type===`paragraph`&&!f(t-1)?d(e):{numbering:{id:0}})),m=[],h=Ti(u.map(Of),i),g=null,_=new Set;return u.forEach((e,a)=>{if(e.type!==`paragraph`){m.push(Rf(e,a,s,t,o,c,l,i,n.notes));return}let u=d(e),v=h[a];if(f(a)){let t=g??{nodes:[],inline:[],display:Df};g={nodes:[...t.nodes,a],inline:[...t.inline,...e.content??[]],display:kf(t.display,t.inline.length,v)};return}let y=g??{nodes:[],inline:[],display:Df};g=null;let b=kf(y.display,y.inline.length,v),{paragraph:x,run:S}=s.paragraph(u),C=t.createElement(Nf(x));gf(C,x);let w=s.run(S,u.markFormat??[]);hf(C,w,mf(x,w,o(cf(pf(w)))));let ee=p[a],te=y.nodes[0],T=te===void 0?ee:p[te]??null;T&&C.append(If(T,x,t,o));let E=[...y.inline,...e.content??[]];if(Lf(C,E,S,x,{resolver:s,doc:t,review:r,comments:_,ratio:o,image:c,geometry:l,codes:i,display:b,notes:n.notes}),b.gone&&(C.style.display=`none`),Af(E,e=>e.type,e=>!!e.attrs?.float))for(let e of C.querySelectorAll(`[${zd}]`))e.style.verticalAlign=`bottom`;let D=C.lastChild,O=D?.nodeName===`BR`;(O&&!D?.hasAttribute(`data-page-break`)||!O&&!C.textContent)&&C.append(t.createElement(`br`));let k=e=>e*Q,{before:ne,after:re}=x.spacing,ie=x.spacing.beforeAutospacing?280:ne,A=x.spacing.afterAutospacing?280:re;m.push({element:C,nodes:[...y.nodes,a],before:b.gone?0:k(ie),after:b.gone?0:k(A),keepNext:x.keepNext,keepLines:x.keepLines,pageBreakBefore:x.pageBreakBefore,section:u.section??null}),C.dataset.style=x.style??``,x.contextualSpacing&&(C.dataset.contextual=``)}),Pf(m,s.addsParagraphSpacing),m}var Df=Ti([[]],!1)[0],Of=e=>e.type===`paragraph`?(e.content??[]).map(e=>e.type):[];function kf(e,t,n){return t?{hidden:new Set([...e.hidden,...[...n.hidden].map(e=>e+t)]),braces:new Map([...e.braces,...[...n.braces].map(([e,n])=>[e+t,n])]),gone:e.gone&&n.gone}:n}function Af(e,t,n){let r=!1;for(let i of e){let e=t(i);if(e===`picture`)r||=!n(i);else if(!jf.has(e))return!1}return r}var jf=new Set([`bookmarkStart`,`bookmarkEnd`,`commentStart`,`commentEnd`,`commentReference`,`controlStart`,`controlEnd`,`fieldStart`,`fieldCode`,`fieldSeparator`,`fieldEnd`]);function Mf(e,t,n){return n.addsParagraphSpacing?e+t:e}function Nf(e){let t=e.outlineLevel;return t!==null&&t>=0&&t<6?`h${t+1}`:`p`}function Pf(e,t){for(let n=1;n<e.length;n++){let r=e[n-1],i=e[n],a=r.element.dataset.style;if(a===void 0||a!==i.element.dataset.style)continue;let o=`contextual`in r.element.dataset;`contextual`in i.element.dataset?i.before=0:o&&!t&&(i.before=Math.max(0,i.before-r.after)),o&&(r.after=0)}}var Ff={"":`•`,"":`▪`,"":`◻`,"":`●`,"":`■`,"":`❑`,"":`◆`,"":`❖`,"":`➢`,"":`✓`};function If(e,t,n,r){let i=n.createElement(`span`);i.dataset.foliMarker=``,i.setAttribute(`aria-hidden`,`true`),hf(i,e.run,mf(t,e.run,r(cf(pf(e.run))))),i.textContent=e.text;let a=pf(e.run)?.toLowerCase(),o=a===`symbol`||a?.startsWith(`wingdings`)?Ff[e.text]:void 0;o&&(i.textContent=o,i.style.fontFamily=`sans-serif`);let s=t.indent.hanging*Q;return e.suffix===`tab`&&s>0?(i.style.display=`inline-block`,i.style.minWidth=`${s}px`,i.style.textIndent=`0`):e.suffix===`tab`?i.textContent+=` `:e.suffix===`space`&&(i.textContent+=` `),i}function Lf(e,t,n,r,i){let{resolver:a,doc:o,review:s,comments:c,ratio:l,image:u,codes:d,display:f}=i,p=[];for(let[m,h]of t.entries()){if(f.hidden.has(m))continue;let t=h.marks??[],g=t.some(e=>e.type===`insertion`),_=t.some(e=>e.type===`deletion`);if(_&&s!==`markup`)continue;let v=h.attrs??{};switch(h.type){case`commentStart`:c.add(v.id);continue;case`commentEnd`:c.delete(v.id);continue;case`commentReference`:{let t=o.createElement(`span`);t.dataset.foliCommentReference=String(v.id),e.append(t);continue}case`bookmarkStart`:{let t=o.createElement(`span`);t.dataset.foliBookmark=String(v.name??``),t.style.position=`absolute`,e.append(t);continue}case`bookmarkEnd`:case`controlStart`:case`controlEnd`:continue;case`picture`:v.float?p.push(...Yd(v,o,u,i.geometry).nodes):e.append(Vd(v,o,u));continue;case`hardBreak`:e.append(o.createElement(`br`));continue;case`columnBreak`:{let t=o.createElement(`br`);t.setAttribute(Ld,``),e.append(t);continue}case`pageBreak`:{let t=o.createElement(`br`);t.setAttribute(Id,``),e.append(t);continue}}let y=f.braces.get(m)??(d&&h.type===`fieldCode`?String(v.text):``),b;if(y)b=y;else if(h.type===`text`)b=h.text??``;else if(h.type===`tab`)b=` `;else if(h.type===`noteReference`)b=i.notes?.references?.get(String(v.story))??``;else if(h.type===`noteMark`)b=i.notes?.mark??``;else if(h.type===`opaqueInline`){let t=Tf(String(v.xml??``),o),n=nf(t,o);if(n){e.append(n);continue}if(b=t?vf(t):``,!b){let t=o.createElement(`span`);t.dataset.foliOpaque=String(v.label??``),e.append(t);continue}}else continue;let x=a.run(n,t),S=o.createElement(`span`);hf(S,x,mf(r,x,l(cf(pf(x))))),S.textContent=b,h.type===`noteReference`&&S.setAttribute($d,String(v.story)),(h.type===`noteReference`||h.type===`noteMark`)&&S.setAttribute(ef,``);let C=t.find(e=>e.type===`link`);if(C&&(S.dataset.href=String(C.attrs?.href??`#${String(C.attrs?.anchor)}`)),c.size&&(S.dataset.foliComments=[...c].join(` `),!x.highlight&&!x.shading&&(S.style.backgroundColor=`rgba(255, 213, 79, 0.35)`)),s===`markup`&&(g||_)){let e=t.find(e=>e.type===(_?`deletion`:`insertion`))?.attrs,n=String(e?.author??``),r=e?.date??null,i=Qd(o,!_,n,r,s);i.append(S),S=i}e.append(S)}e.prepend(...p)}function Rf(e,t,n,r,i,a,o=Ud(void 0),s=!1,c){let l=e.attrs??{},u=r.createElement(`div`);u.dataset.foliOpaque=String(l.label??``),u.style.margin=`0`,u.style.display=`flow-root`;let d=e.type===`table`?null:Tf(String(l.xml??``),r),f=0;if(e.type===`table`)u.append(Kf(e,n,r,i,a,o,s,c));else if(d?.localName===`tbl`)u.append(Wf(d,n,r,i));else if(d){let e=yf(d,bf),t=0;e.forEach((a,o)=>{let s=Bf(a,n,r,i,t);o<e.length-1?s.element.style.marginBottom=`${s.after}px`:f=s.after,t=s.after,u.append(s.element)})}return u.firstChild||(u.style.minHeight=`1em`,u.style.outline=`1px dashed #999`),{element:u,nodes:[t],before:0,after:f,keepNext:!1,keepLines:!1,pageBreakBefore:!1,section:null}}function zf(e,t,n=`val`){for(let r of e?.children??[])if(r.localName===t){for(let e of r.attributes)if(e.localName===n)return e.value}}function $(e,t){for(let n of e?.children??[])if(n.localName===t)return n}function Bf(e,t,n,r,i=0){let a=$(e,`pPr`),o=zf(a,`pStyle`),s=zf(a,`jc`),{paragraph:c,run:l}=t.paragraph({...o?{style:o}:{},...s?{justification:s}:{}}),u=n.createElement(Nf(c));gf(u,c),hf(u,l,mf(c,l,r(cf(pf(l)))));for(let i of yf(e,xf)){let e=vf(i),a=t.run(l,Vf($(i,`rPr`))),o=n.createElement(`span`);hf(o,a,mf(c,a,r(cf(pf(a))))),o.textContent=e,u.append(o)}u.textContent||u.append(n.createElement(`br`));let d=Mf(c.spacing.before*Q,i,t);return d&&(u.style.marginTop=`${d}px`),{element:u,after:c.spacing.after*Q}}function Vf(e){let t=[],n=t=>{let n=zf(e,t);return n===void 0||![`0`,`false`,`off`].includes(n)},r=zf(e,`rStyle`);r&&t.push({type:`characterStyle`,attrs:{id:r}});for(let[r,i]of[[`b`,`bold`],[`i`,`italic`],[`caps`,`caps`],[`smallCaps`,`smallCaps`],[`strike`,`strike`]])$(e,r)&&t.push({type:i,attrs:{value:n(r)}});let i=zf(e,`u`);i&&t.push({type:`underline`,attrs:{style:i}});let a=zf(e,`color`);a&&t.push({type:`color`,attrs:{value:a}});let o=Number(zf(e,`sz`));o>0&&t.push({type:`fontSize`,attrs:{value:o}});let s=zf(e,`highlight`);return s&&t.push({type:`highlight`,attrs:{value:s}}),t}function Hf(e){if(!e)return;let t=qf(e,`val`)??`single`;if(t===`nil`||t===`none`)return`none`;let n=Number(qf(e,`sz`)??4),r=qf(e,`color`),i=ff[t]??`solid`;return`${Math.max(n/8*(96/72),.5)}px ${i} ${r&&r!==`auto`?`#${r}`:`#000`}`}function Uf(e,t){let n={...t};for(let t of e?.children??[]){let e=t.localName===`start`?`left`:t.localName===`end`?`right`:t.localName,r=Number(qf(t,`w`));e in n&&Number.isFinite(r)&&(n[e]=r*Q)}return n}function Wf(e,t,n,r){let i=n.createElement(`table`),{style:a}=i;a.borderCollapse=`collapse`,a.tableLayout=`fixed`;let o=$(e,`tblPr`),s=$(o,`tblBorders`);for(let e of[`top`,`left`,`bottom`,`right`]){let t=Hf($(s,e));t&&a.setProperty(`border-${e}`,t)}let c=Uf($(o,`tblCellMar`),{top:0,bottom:0,left:108*Q,right:108*Q}),l=[...$(e,`tblGrid`)?.children??[]].filter(e=>e.localName===`gridCol`).map(e=>Number(qf(e,`w`))||0),u=l.reduce((e,t)=>e+t,0);u&&(a.width=`${u*Q}px`);let d=n.createElement(`colgroup`);for(let e of l){let t=n.createElement(`col`);t.style.width=`${e*Q}px`,d.append(t)}i.append(d);let f={horizontal:Hf($(s,`insideH`)),vertical:Hf($(s,`insideV`))},p=n.createElement(`tbody`);for(let i of yf(e,Sf)){let e=n.createElement(`tr`),a=$(i,`trPr`),o=zf(a,`tblHeader`);$(a,`tblHeader`)&&o!==`0`&&o!==`false`&&(e.dataset.foliHeader=``);let s=Uf($($(i,`tblPrEx`),`tblCellMar`),c);for(let a of yf(i,Cf)){let i=$(a,`tcPr`),o=n.createElement(`td`),c=Number(zf(i,`gridSpan`));c>1&&(o.colSpan=c);let l=zf(i,`shd`,`fill`);l&&l!==`auto`&&(o.style.backgroundColor=`#${l}`);let u=Uf($(i,`tcMar`),s);o.style.padding=`${u.top}px ${u.right}px ${u.bottom}px ${u.left}px`,o.style.verticalAlign=`top`,f.horizontal&&(o.style.borderTop=o.style.borderBottom=f.horizontal),f.vertical&&(o.style.borderLeft=o.style.borderRight=f.vertical);let d=$(i,`tcBorders`);for(let e of[`top`,`left`,`bottom`,`right`]){let t=Hf($(d,e));t&&o.style.setProperty(`border-${e}`,t)}if($(i,`vMerge`)&&zf(i,`vMerge`)!==`restart`){e.append(o);continue}let p=0;for(let e of yf(a,wf)){if(e.localName===`tbl`){o.append(Wf(e,t,n,r)),p=0;continue}let i=Bf(e,t,n,r,p);i.element.style.marginBottom=`${i.after}px`,p=i.after,o.append(i.element)}e.append(o)}p.append(e)}return i.append(p),i}function Gf(e){if(!e)return;if(e.style===`nil`||e.style===`none`)return`none`;let t=Math.max((e.size??4)/8*(96/72),.5),n=e.color&&e.color!==`auto`?`#${e.color}`:`#000`;return`${t}px ${ff[e.style??`single`]??`solid`} ${n}`}function Kf(e,t,n,r,i,a,o,s){let c=e.attrs??{},l=n.createElement(`table`);l.style.borderCollapse=`collapse`,l.style.tableLayout=`fixed`;let u=c.grid??[],d=u.reduce((e,t)=>e+t,0);d&&(l.style.width=`${d*Q}px`);let f=n.createElement(`colgroup`);for(let e of u){let t=n.createElement(`col`);t.style.width=`${e*Q}px`,f.append(t)}l.append(f);let p=n.createElement(`tbody`),m=e.content??[],h={resolver:t,doc:n,review:`markup`,comments:new Set,ratio:r,image:i,geometry:a,codes:o};return m.forEach((e,l)=>{let u=e.attrs??{},d=n.createElement(`tr`);u.header&&(d.dataset.foliHeader=``),u.cantSplit&&(d.dataset.foliCantSplit=``);let f=e.content??[];f.forEach((e,p)=>{let g=e.attrs??{},_=t.cell(c,u,g,{row:l,rows:m.length,cell:p,cells:f.length}),v=n.createElement(`td`),y=g.gridSpan;y&&y>1&&(v.colSpan=y),_.shading&&(v.style.backgroundColor=`#${_.shading}`);let b=_.margins;v.style.padding=`${b.top*Q}px ${b.right*Q}px ${b.bottom*Q}px ${b.left*Q}px`,v.style.verticalAlign=_.verticalAlign===`center`?`middle`:_.verticalAlign;for(let e of[`top`,`left`,`bottom`,`right`]){let t=Gf(_.borders[e]);t&&v.style.setProperty(`border-${e}`,t)}if(d.append(v),g.vMerge===`continue`)return;let x=0,S=e.content??[],C=Ti(S.map(Of),o);for(let[e,c]of S.entries()){if(c.type===`table`){v.append(Kf(c,t,n,r,i,a,o,s)),x=0;continue}if(c.type!==`paragraph`){v.append(Rf(c,0,t,n,r,i,a,o,s).element),x=0;continue}let{paragraph:l,run:u}=t.paragraph(c.attrs??{},_),d=n.createElement(Nf(l));d.dataset.foliCell=``,gf(d,l),hf(d,u,mf(l,u,r(cf(pf(u)))));let f=C[e];Lf(d,c.content??[],u,l,{...h,display:f,notes:s}),f.gone&&(d.style.display=`none`),d.textContent||d.append(n.createElement(`br`));let p=l.spacing.before*Q;d.style.marginTop=`${Mf(p,x,t)}px`,x=l.spacing.after*Q,d.style.marginBottom=`${x}px`,v.append(d)}}),p.append(d)}),l.append(p),l}function qf(e,t){for(let n of e.attributes)if(n.localName===t)return n.value}var Jf={orphans:2,widows:2},Yf=.5,Xf=e=>e?e.page*1e6+(e.band??0)*1e3+(e.column??0):0;function Zf(e,t,n=Jf,r){let i=r?Math.min(r.from,e.length,r.previous.fragments.length):0,a=t=>e[t]?.section?.balanced===!0,o=t=>e[t]?.section===e[t-1]?.section;for(;;)if(i>0&&e[i-1]?.keepWithNext)i--;else if(i>0&&i<e.length&&a(i)&&o(i))i--;else break;let s=r?r.previous.fragments.slice(0,i):[],c=r?r.previous.states.slice(0,i):[],l=r?r.previous.gaps.slice(0,i):[],u=r?.previous.states[i]?{...r.previous.states[i]}:{page:0,number:e[0]?.section?.pageStart??1,sectionPage:0,band:0,bandTop:0,lead:0,column:0,used:0,bandBottom:0,previousMargin:0,onPage:0,breakPending:!1,columnPending:!1,forcedPage:!0,owner:null,notes:0,noteParts:[],pageNotes:0,carry:[],reserves:{}},d=new Set,f=n.spacing===`word`,p=null,m=[],h=null,g=()=>`${u.page}|${u.band}`,_=()=>u.reserves[g()]??0,v=(e=!1)=>{u.page++,u.number++,u.band=0,u.bandTop=0,u.lead=0,u.column=0,u.used=0,u.bandBottom=0,u.onPage=0,u.forcedPage=e,u.owner=null,u.notes=0,u.noteParts=[],u.pageNotes=0,Object.keys(u.reserves).length&&(u.reserves=Object.fromEntries(Object.entries(u.reserves).filter(([e])=>Number.parseInt(e,10)>=u.page)))},y=(e,t=!1)=>{u.column+1>=(e.section?.columns??1)?v(t):(u.bandBottom=Math.max(u.bandBottom,u.used),u.column++,u.used=0,u.lead=0,u.onPage=0,u.forcedPage=t)},b=e=>x(e)-Math.max(u.notes,_()),x=e=>{let n=u.owner?.section??e.section,r=(n?n.box({index:u.page,number:u.number,first:u.owner?.first??u.page===u.sectionPage}).height:e.pageHeight??t)-u.bandTop-u.pageNotes;return p?.page===u.page?Math.min(r,p.height):r},S=(e,t,n)=>({id:e.id,page:u.page,...u.band?{band:u.band}:{},...u.column?{column:u.column}:{},fromLine:t,toLine:n}),C=(e,t,n)=>({id:e.id,page:u.page,...u.band?{band:u.band}:{},fromLine:t,toLine:n}),w=(e,t,n)=>{let r=e.lines(u.column),i=t?r[t-1]:0,a=t;for(;a<r.length&&r[a]-i<=n+Yf;)a++;return{to:a,height:a>t?r[a-1]-i:0,all:r.length}},ee=(e,t,n,r,i)=>{let a=e.lines(0),o=t?a[t-1]:0,s=i>1?0:ep(r,1),c=e=>a[e]-o,l=t;for(;l<a.length&&(i>1?ep([...r,c(l)],i):s+c(l))<=n+Yf;)l++;return{to:l,height:l>t?c(l-1):0,all:a.length}},te=e=>e.lines(0).at(-1)??0,T=e=>C(e,0,e.lines(0).length),E=(e,t=!1)=>{if(!u.carry.length||u.notes||u.onPage||!n.notes)return;let{continuation:r}=n.notes,i=e.section?.columns??1,a=te(r),o=x(e)-u.used-a,s=[],c=[],l=[];for(let e of u.carry){if(c.length){c.push(e);continue}let n=ee(e.note,e.from,o,l,i);n.to===e.from&&t&&!s.length&&(n=ee(e.note,e.from,D(e),l,1)),n.to>e.from&&(s.push(C(e.note,e.from,n.to)),l=[...l,n.height]),n.to<n.all&&c.push({note:e.note,from:n.to})}s.length&&(m.push(T(r),...s),u.notes=a+ep(l,i),u.noteParts=l,u.carry=c)},D=({note:e,from:t})=>{let n=e.lines(0);return n[t]-(t?n[t-1]:0)},O=e=>u.onPage>0||u.notes>0||u.bandTop>0||u.column+1<(e.section?.columns??1),k=(e,t)=>{let r=u.breakPending;u.breakPending=!1,u.columnPending=!1;let i=(u.notes>0||u.pageNotes>0)&&e.columns!==t?.columns,a=!t||e.samePage(t)&&!i;if(!r&&a&&e.start===`continuous`){u.owner??={section:t??e,first:u.page===u.sectionPage};let n=u.previousMargin;return u.bandTop+=Math.max(u.bandBottom,u.used)+n,u.lead=n,u.band++,u.column=0,u.used=0,u.bandBottom=0,u.onPage=0,u.forcedPage=!0,u.sectionPage=u.page,u.pageNotes+=u.notes,u.notes=0,u.noteParts=[],n}if(!r&&a&&e.start===`nextColumn`&&e.columns===t?.columns&&u.column+1<e.columns){y({section:e},!0);return}u.onPage||u.used||u.column||u.band?v(!0):u.forcedPage=!0;let o=t=>e.start===`oddPage`&&t%2==0||e.start===`evenPage`&&t%2==1;o(u.number)&&(e.pageStart===void 0||n.evenAndOddHeaders)&&v(!0),e.pageStart!==void 0&&(u.number=e.pageStart+ +!!o(e.pageStart)),u.sectionPage=u.page},ne=(e,t)=>{let n=ie(e,t);return e.endnotes?.length&&re(e,n),n},re=(e,t)=>{let n=u.onPage?u.previousMargin:0;for(let t of e.endnotes??[]){let r=0;for(;;){let i=t.lines(u.column);if(r>=i.length)break;let a=r?i[r-1]:0;E(e);let o=u.onPage?n??0:0,s=w(t,r,b(e)-u.used-o);if(s.to===r){if(O(e)){y(e);continue}s={...s,to:r+1,height:i[r]-a}}let c=S(t,r,s.to);c.end=!0,o&&(c.lead=o),m.push(c),n=void 0,u.used+=o+s.height,u.onPage++,r=s.to,r<i.length&&y(e)}}u.previousMargin=0;let r=t[t.length-1];r&&m.length&&(r.notes=[...r.notes??[],...m]),r&&(m=[])},ie=(t,r)=>{let i=e[r-1],a;r>0&&t.section&&i?.section!==t.section?a=k(t.section,i?.section):u.breakPending&&u.onPage?v(!0):u.columnPending?y(t,!0):d.has(r)&&u.onPage&&y(t),u.breakPending=!1,u.columnPending=!1;let o=u.page,s=(e,t)=>{let n={page:u.page,fromLine:e,toLine:t};return u.band&&(n.band=u.band),u.column&&(n.column=u.column),a!==void 0&&u.page===o&&(n.lead=a),a=void 0,m.length&&(n.notes=m,m=[]),n};if(t.sectionMark&&u.onPage)return l[r]=0,[{...s(0,1/0),mark:!0}];let c=u.previousMargin;u.previousMargin=t.marginBottom;let p=f&&n.addSpacing===!0,S=()=>u.onPage?p?c+t.marginTop:Math.max(c,t.marginTop):f&&!u.forcedPage?0:p?t.marginTop:Math.max(0,t.marginTop-u.lead),w=f?0:t.marginBottom,ne=t.breaksAfter?.(u.column)??[],re=t.columnBreaksAfter?.(u.column)??[],ie=ne.length+re.length>0,A=t.inColumn?.(u.column)??t,j=()=>{let e=new Map;for(let{line:n,note:r}of t.notes?.(u.column)??[])e.set(n,[...e.get(n)??[],r]);return e},ae=j();if(u.carry.length&&!u.onPage&&E(t),!ie&&!ae.size&&u.used+S()+A.height+w<=b(t)+Yf){let e=S();return l[r]=e,u.used+=e+A.height,u.onPage++,[s(0,1/0)]}let oe=A.lines(),M=oe.length,se=e=>new Set(e.filter(e=>e>=0&&e<M)),ce=se(ne),le=se(re),ue=[],N=0,de=0,fe=(e=!1)=>{if(!t.inColumn)return;let n=t.inColumn(u.column);if(n===A)return;let r=n.lines(),i=N?oe[N-1]/(A.height||1):0;if(A=n,oe=r,M=oe.length,ce=se(t.breaksAfter?.(u.column)??[]),le=se(t.columnBreaksAfter?.(u.column)??[]),N>0){let t=[...ce,...le].sort((e,t)=>e-t)[de-1],r=oe.findIndex(e=>e/(n.height||1)>i+1e-6);r<0&&(r=M-1),N=e&&t!==void 0?t+1:Math.max(r,1)}if(N>=M){let e=ue.at(-1);e&&(e.toLine=1/0)}};for(;N<M;){let e=N;for(;e<M&&!ce.has(e)&&!le.has(e);)e++;e=Math.min(e+1,M);let i=N?oe[N-1]:0,a=N===0?S():t.repeat??0;ae=j(),E(t);let o=x(t),c=M===1,d=(r,s=!1)=>{let l={notes:u.notes,parts:u.noteParts,carry:u.carry,pieces:[]};if(!ae.size||!n.notes)return l;let d=t.section?.columns??1;for(let f=N;f<r;f++)for(let r of ae.get(f)??[]){if(l.carry.length){l.carry=[...l.carry,{note:r,from:0}];continue}let{separator:p}=n.notes,m=!l.notes,v=m?te(p):l.notes-ep(l.parts,d),y=f+1;!t.anyLine&&!c&&(y=Math.max(y,N+n.orphans),M-y<n.widows&&(y=M),y=Math.min(y,e));let b=y===M?t.marginBottom:0,x=u.used+a+oe[y-1]-i+b,S=Math.max(x,d>1&&u.column?u.bandBottom:0),w=ee(r,0,o-S-v,l.parts,d);if(d>1&&u.column&&!s&&(!w.to||w.to<w.all&&S>x)){let e=r.lines(0),t=v+ep([...l.parts,e.at(-1)],d),n=v+ep([...l.parts,e[0]],d),i=t<o/2?t:n;i>_()+Yf&&i<o&&(h={key:g(),height:i})}if(!w.to){if(!s)return null;w=ee(r,0,D({note:r,from:0}),[],1)}m&&l.pieces.push(T(p)),l.pieces.push(C(r,0,w.to)),l.parts=[...l.parts,w.height],l.notes=v+ep(l.parts,d),w.to<w.all&&(l.carry=[{note:r,from:w.to}])}return l},f=N;for(;f<e;){let e=oe[f]-i+(f+1===M?w:0),t=d(f+1);if(!t||u.used+a+e+Math.max(t.notes,_())>o+Yf)break;f++}if(f<e&&f>N&&!t.anyLine){let r=Math.min(f,e-n.widows);r-N>=n.orphans?f=r:O(t)&&(f=N)}if(f===N){if(O(t)){y(t),fe();continue}f=N+1}let p=d(f,!0);p&&(u.notes=p.notes,u.noteParts=p.parts,u.carry=p.carry,m.push(...p.pieces)),N===0&&(l[r]=a),ue.push(s(N,f)),u.used+=a+oe[f-1]-i,u.onPage++,N=f;let b=ce.has(f-1),k=le.has(f-1);N<M?((b||k)&&de++,b?v():y(t,k),fe(b||k)):b?u.breakPending=!0:k&&(u.columnPending=!0)}let[pe]=ue;return ue.length===1&&pe&&!ie&&(pe.toLine=1/0),ue},A=new Map,j=(t,n)=>{let f=t;for(;f<n;){let n=r&&!p&&f>i&&!A.size&&r.previousIndex(f-1)>=0?r.previousIndex(f):-1,g=n>=0?r?.previous.states[n]:void 0;if(g&&!e[f-1]?.keepWithNext&&!(a(f)&&o(f))&&rp(g,u)){let e=r.previous;return s.length=f,c.length=f,l.length=f,s.push(...e.fragments.slice(n)),c.push(...e.states.slice(n,-1)),l.push(...e.gaps.slice(n)),{fragments:s,states:[...c,{...e.states.at(-1)}],gaps:l}}c[f]={...u};let _=ne(e[f],f);if(h){let{key:e,height:n}=h;h=null;let[r,i]=e.split(`|`).map(Number),a=f;for(;a>t&&s[a-1]?.some(e=>e.page===r&&(e.band??0)===i);)a--;let o=c[a];u={...o,reserves:{...o.reserves,[e]:n}},s.length=a,c.length=a,l.length=a,A.clear();for(let e of d)e>=a&&d.delete(e);m=[],f=a;continue}s[f]=_;let v=s[f-1],y=v!==void 0&&Xf(_[0])>Xf(v[v.length-1]),b=A.get(f);if(b&&(A.delete(f),y)){s.splice(b.first,s.length-b.first,...b.result),c.splice(b.first,c.length-b.first,...b.snapshots),l.splice(b.first,l.length-b.first,...b.gaps),u=b.state,f++;continue}if(y&&e[f-1]?.keepWithNext&&o(f)){let t=f-1;for(;t>0&&o(t)&&e[t-1]?.keepWithNext&&s[t-1]?.length===1&&Xf(s[t-1]?.[0])===Xf(s[t]?.[0]);)t--;let n=c[t];if(!d.has(t)&&n.onPage>0&&s[t]?.length===1){A.set(f,{first:t,result:s.slice(t),snapshots:c.slice(t),gaps:l.slice(t),state:{...u}}),d.add(t),u={...n},s.length=t,f=t;continue}}f++;let x=e[f-1]?.section;!p&&x?.balanced&&x.columns>1&&e[f]?.section!==x&&ae(f)}return null},ae=t=>{let n=e[t-1]?.section,r=t-1;for(;r>0&&e[r-1]?.section===n;)r--;let i=c[r],{page:a}=u,o=Math.max(u.bandBottom,u.used),l=o/n.columns-1,f=e=>{p={page:a,height:e},u={...i},s.length=r,c.length=r,A.clear();for(let e of d)e>=r&&d.delete(e);return j(r,t),u.page===a&&Math.max(u.used,u.bandBottom)<=e+Yf};for(;o-l>.5;){let e=(l+o)/2;f(e)?o=e:l=e}f(o)||f(1/0),p=null};return j(i,e.length)||((()=>{let t=s[s.length-1],n=t?.[t.length-1],r=e[e.length-1];if(!t||!n||!r||!u.carry.length&&!n.notes?.some(e=>e.tail))return;let i=u;for(u={...u};u.carry.length;)v(),E(r,!0);let a=[...(n.notes??[]).filter(e=>!e.tail),...m.map(e=>({...e,tail:!0}))];m=[],u=i,s[s.length-1]=[...t.slice(0,-1),{...n,notes:a}]})(),{fragments:s,states:[...c.slice(0,e.length),{...u}],gaps:l.slice(0,e.length)})}function Qf(e,t){let n=[],r=[],i=new Set,a=new Map;t.fragments.forEach((o,s)=>{let c=e[s]?.section,l=t.states[s+1],u=a.get(c)??new Set;a.set(c,u);let d=[...o,...o.flatMap(e=>e.notes??[])];for(let{page:e}of d)u.add(e),n[e]||(r[e]=c,n[e]={index:e,number:l.number-(l.page-e),first:!i.has(c),section:c.index??0,sectionPages:0}),i.add(c)}),n.forEach((e,t)=>{e&&(e.sectionPages=a.get(r[t])?.size??0)});for(let e=n.length-1;e>=0;e--){let t=n[e+1];n[e]??={...t,index:e,number:t.number-1,first:!1,sectionPages:0}}return n}function $f(e,t){let n=e.reduce((e,t)=>e+t,0);if(t<=1||e.length<=1)return{height:n,columnOf:e.map(()=>0)};let r=n=>{let r=[],i=0,a=0,o=0;for(let t of e)a&&a+t>n+.01&&(i++,a=0),a+=t,o=Math.max(o,a),r.push(i);return i<t?{height:o,columnOf:r}:null},i=Math.max(...e,n/t),a=r(i);if(a)return a;let o=n;for(a=r(o);o-i>.25;){let e=(i+o)/2,t=r(e);t?(a=t,o=e):i=e}return a}var ep=(e,t)=>$f(e,t).height;function tp(e,t,n,r,i){for(let a=t.fragments.length-1;a>=0;a--)for(let o of t.fragments[a]??[])if(o.page===n&&(o.band??0)===r&&(o.column??0)===i)return e[a]?.marginBottom??0;return 0}var np=e=>e.fragments.flatMap(e=>e.flatMap(e=>e.notes??[]));function rp(e,t){return e.notes===t.notes&&JSON.stringify(e.reserves)===JSON.stringify(t.reserves)&&e.noteParts.length===t.noteParts.length&&e.noteParts.every((e,n)=>e===t.noteParts[n])&&e.pageNotes===t.pageNotes&&e.carry.length===t.carry.length&&e.carry.every((e,n)=>e.note.id===t.carry[n]?.note.id&&e.from===t.carry[n]?.from)&&e.page===t.page&&e.number===t.number&&e.sectionPage===t.sectionPage&&e.band===t.band&&e.bandTop===t.bandTop&&e.lead===t.lead&&e.column===t.column&&e.used===t.used&&e.bandBottom===t.bandBottom&&e.previousMargin===t.previousMargin&&e.onPage===t.onPage&&e.breakPending===t.breakPending&&e.columnPending===t.columnPending&&e.forcedPage===t.forcedPage&&e.owner===t.owner}var ip=`data-foli-sheet`;function ap(e,t,n,r){let i=n.every(e=>e.width===t.width&&e.height===t.height)?``:n.map(({width:t,height:n,index:i})=>{let a=`foli-${r}-${i}`;return`@page ${a}{size:${t} ${n};margin:0}${e}[${ip}="${i}"]{page:${a};height:${n}!important}`}).join(``);return`@media print{@page{size:${t.width} ${t.height};margin:0}${e}{height:${t.height}!important;margin-block:0!important;break-after:page;break-inside:avoid}${e}:last-child{break-after:auto}${i}}`}var op=`foli-band`,sp=`foli-column`;function cp(e){let{widths:t,gaps:n,separator:r}=qo(e);return{widths:t.map(e=>e*Q),gaps:n.map(e=>e*Q),separator:r}}function lp(e,t,n){if(e.className=op,e.style.display=`flex`,n.separator&&n.gaps.length){let t=0,r=n.gaps.map((e,r)=>(t+=n.widths[r]+e,t-e/2));e.style.backgroundImage=r.map(()=>`linear-gradient(#000,#000)`).join(`,`),e.style.backgroundRepeat=`no-repeat`,e.style.backgroundSize=r.map(()=>`1px 100%`).join(`,`),e.style.backgroundPosition=r.map(e=>`${e-.5}px 0`).join(`,`),e.style.printColorAdjust=`exact`}t.forEach((e,t)=>{e.className=sp,e.style.flex=`none`,e.style.display=`flow-root`,e.style.width=`${n.widths[t]}px`,e.style.marginRight=`${n.gaps[t]??0}px`})}function up(e,t){let n=e.createElement(`div`),r=t.widths.map(()=>e.createElement(`div`));return lp(n,r,t),n.append(...r),{band:n,columns:r}}var dp=`data-foli-page-field`,fp=`foli-region`,pp=`foli-region-content`,mp=720,hp=new Set([`PAGE`,`NUMPAGES`,`SECTIONPAGES`]),gp=new Map([[`roman`,`lowerRoman`],[`ROMAN`,`upperRoman`],[`alphabetic`,`lowerLetter`],[`ALPHABETIC`,`upperLetter`]]),_p=``,vp=/\uE000([\uE100-\uF8FF])/g;function yp(e){let t=e.trim().split(/\s+/)[0]?.toUpperCase()??``;if(!hp.has(t))return null;let n=/\\\*\s*(\S+)/.exec(e)?.[1];return{name:t,format:n?.toLowerCase()===`arabic`?`decimal`:gp.get(n??``)}}function bp(e,t,n){let r=e.name===`PAGE`?t.page:e.name===`NUMPAGES`?t.pages:t.sectionPages;return br(Number(r),e.format??(e.name===`PAGE`?n:void 0))}function xp(e,t){let n=[];for(let r=0;r<e.length;r++){let i=e[r];if(n.push(i),i.type!==`fieldStart`)continue;let a=1,o=-1,s=-1,c=``;for(let t=r+1;t<e.length&&s<0;t++){let n=e[t];n.type===`fieldStart`?a++:n.type===`fieldEnd`&&--a===0?s=t:a===1&&n.type===`fieldSeparator`&&o<0?o=t:a===1&&o<0&&n.type===`fieldCode`&&(c+=String(n.attrs?.text??``))}let l=s<0?null:yp(c);if(!l)continue;let u=o<0?s:o+1,d=e.slice(u,s).find(e=>e.type===`text`)??e[u-1];n.push(...e.slice(r+1,u)),n.push({type:`text`,text:_p+String.fromCharCode(57600+t.length),...d?.marks?{marks:d.marks}:{}}),t.push(l),n.push(e[s]),r=s}return n}function Sp(e,t){if(!e.content)return e;let n=e.type===`paragraph`?xp(e.content,t):e.content.map(e=>Sp(e,t));return{...e,content:n}}function Cp(e,t){let n=e.cloneNode(!0);if(!t.length)return n;let r=e.ownerDocument.createTreeWalker(n,NodeFilter.SHOW_TEXT);for(let e=r.nextNode();e;e=r.nextNode()){let n=e;n.data.replace(vp,``)===``&&n.data&&n.parentElement?.setAttribute(dp,``),n.data.includes(_p)&&(n.data=n.data.replace(vp,(e,n)=>t[n.charCodeAt(0)-57600]??``))}return n}function wp(e){let t=e.margins??{},n=t.top??1440,r=t.bottom??1440,i=(t.left??1440)+(t.gutter??0),a=t.right??1440,o=e.pageSize?.width??12240;return{top:Math.abs(n)*Q,bottom:Math.abs(r)*Q,pushesTop:n>=0,pushesBottom:r>=0,header:(t.header??mp)*Q,footer:(t.footer??mp)*Q,left:i*Q,right:a*Q,height:(e.pageSize?.height??15840)*Q,width:Math.max(o-i-a,1)*Q}}function Tp(e,t,n){let r=0;return e.forEach((e,i)=>{let a=i?n?r+e.before:Math.max(r,e.before):e.before;e.element.style.marginTop=`${a}px`,e.element.style.marginBottom=`0`,r=e.after,t.append(e.element)}),r}var Ep=class{doc;options;cache;pages=1;sectionPages=new Map;edges=[];flowed=[];document=null;sections=[];resolver=null;constructor(e,t,n){this.doc=e,this.options=t,this.cache=n}setDocument(e,t,n){this.document=e,this.sections=t,this.resolver=n,this.edges=[]}story(e){let t=this.document?.stories;return t&&Object.hasOwn(t,e)?t[e]:void 0}edgesAt(e){let t=this.edges[e];return t||(t=wp(this.sections[e]??{}),this.edges[e]=t),t}storyId(e,t,n){let r=this.sections[e];if(!r)return null;let i=ns(r,n,this.document?.settings?.evenAndOddHeaders===!0),a=ts(this.sections,e,t,i);return a&&this.story(a.id)?a.id:null}entry(e){let t=this.cache.get(e);if(!t){let n=[],r=Sp(e.content,n),i=this.doc.createElement(`div`);i.className=pp,i.style.paddingTop=`0.01px`;let a=Tp(Ef({...this.document,content:r},this.doc,{...this.options,...this.resolver?{resolver:this.resolver}:{}}),i,!!this.resolver?.addsParagraphSpacing);i.style.paddingBottom=`${a}px`,t={slots:n,template:i,after:a,drawn:new Map,heights:new Map},this.cache.set(e,t)}return t}valuesFor(e,t){return{page:String(t),pages:String(this.pages),sectionPages:String(this.sectionPages.get(e)??1)}}drawn(e,t,n){let r=this.entry(this.story(e)),i=this.edgesAt(t),a=this.valuesFor(t,n),o=this.sections[t]?.pageNumbers?.format,s=r.slots.map(e=>bp(e,a,o)),c=`${i.width}|${s.join(`|`)}`,l=r.drawn.get(c);if(!l){let e=null,t=()=>(e??=Cp(r.template,s),e),n=`${i.width}|${s.map(e=>/^\d*$/.test(e)?e.length:e).join(` `)}`,a=r.heights.get(n);a===void 0&&(a=this.measure(t(),i.width,r.after),r.heights.set(n,a)),l={height:a,get content(){return t()}},r.drawn.set(c,l)}return l}measure(e,t,n){let{style:r}=e;r.position=`absolute`,r.visibility=`hidden`,r.width=`${t}px`,this.options.measureIn().append(e);let i=e.lastElementChild,a=this.options.scale?.()??1,o=e.getBoundingClientRect().top,s=i?i.getBoundingClientRect().bottom:o;return e.remove(),r.position=``,r.visibility=``,r.width=``,(s-o)/a+n}heightOf(e,t,n){let r=this.storyId(e,t,n);return r?this.drawn(r,e,n.number).height:0}margins(e,t){let n=this.edgesAt(e),r=n.pushesTop?this.heightOf(e,`header`,t):0,i=n.pushesBottom?this.heightOf(e,`footer`,t):0;return{top:r?Math.max(n.top,n.header+r):n.top,bottom:i?Math.max(n.bottom,n.footer+i):n.bottom}}boxHeight(e,t){let{top:n,bottom:r}=this.margins(e,t);return this.edgesAt(e).height-n-r}settle(e){let t=()=>e.filter(e=>e.sectionPages).map(e=>this.boxHeight(e.section,e)).join(` `),n=t();this.flowed=e,this.pages=e.length,this.sectionPages=new Map;for(let t of e)t.sectionPages&&this.sectionPages.set(t.section,t.sectionPages);return t()!==n}key(){let e=[`header`,`footer`],t=this.sections.flatMap((t,n)=>e.flatMap(e=>[{first:!0,number:1},{first:!1,number:1},{first:!1,number:2}].map(t=>this.heightOf(n,e,{...t,index:0})))),n=this.flowed.filter(e=>e.sectionPages&&e.section<this.sections.length).flatMap(t=>e.map(e=>this.heightOf(t.section,e,t)));return[...t,`|`,...n].join(` `)}drawing(e,t,n){let r=this.storyId(e,t,n);return r?{id:r,content:this.drawn(r,e,n.number),story:this.story(r)}:null}element(e,t){let n=this.edgesAt(e),r=this.doc.createElement(`div`);r.className=`${fp} foli-${t}`,r.setAttribute(`contenteditable`,`false`);let{style:i}=r;return i.position=`absolute`,i.inset=`0`,i.boxSizing=`border-box`,i.pointerEvents=`none`,i.userSelect=`none`,i.setProperty(`-webkit-user-select`,`none`),i.paddingLeft=`${n.left}px`,i.paddingRight=`${n.right}px`,t===`header`?i.paddingTop=`${n.header}px`:(i.display=`flex`,i.flexDirection=`column`,i.justifyContent=`flex-end`,i.paddingBottom=`${n.footer}px`),r}},Dp=`data-foli-note`,Op=`foli-notes`;function kp(e){let t=e.getBoundingClientRect(),n=e.ownerDocument,r=n.createRange(),i=[],a=n.createTreeWalker(e,NodeFilter.SHOW_TEXT|NodeFilter.SHOW_ELEMENT);for(let e=a.nextNode();e;e=a.nextNode())if(e.nodeType===Node.TEXT_NODE){if(e.parentElement?.style.verticalAlign===`super`)continue;r.selectNodeContents(e);for(let e of r.getClientRects())i.push({rect:e,text:!0})}else e.nodeName===`BR`&&i.push({rect:e.getBoundingClientRect(),text:!1});i.sort((e,t)=>e.rect.top-t.rect.top);let o=[];for(let{rect:e,text:t}of i){if(e.height<=0)continue;let n=o[o.length-1];n&&e.top<(n.top+n.bottom)/2?t&&!n.text?Object.assign(n,{top:e.top,bottom:e.bottom,text:t}):t===n.text&&(n.top=Math.min(n.top,e.top),n.bottom=Math.max(n.bottom,e.bottom)):o.push({top:e.top,bottom:e.bottom,text:t})}let s=o.slice(1).map((e,n)=>(o[n].bottom+e.top)/2-t.top);return s.push(t.height),s}var Ap=e=>({kind:`footnote`,noteType:e,content:{type:`doc`,content:[{type:`paragraph`,attrs:{spacing:{after:0,line:240,lineRule:`auto`}},content:[{type:`opaqueInline`,attrs:{xml:`<w:r><w:${e}/></w:r>`,label:e}}]}]}}),jp=Ap(`separator`);function Mp(e){if((e.noteType??`normal`)===`normal`)return e.content;let t={before:0,after:0,line:240,lineRule:`auto`};return{...e.content,content:(e.content.content??[]).map(e=>e.type===`paragraph`?{...e,attrs:{...e.attrs,spacing:{...t}}}:e)}}var Np=Ap(`continuationSeparator`),Pp=0,Fp=class{doc;options;cache;document=null;sections=[];resolver=null;references=[];numbers=new Map;open=null;constructor(e,t,n){this.doc=e,this.options=t,this.cache=n}setDocument(e,t,n,r){this.document=e,this.sections=t,this.resolver=n,this.references=r,this.numbers=new Map(r.map(e=>[e.story,e.text]))}story(e){let t=this.document?.stories;return t&&Object.hasOwn(t,e)?t[e]:void 0}separator(e,t){let n=Object.entries(this.document?.stories??{}).find(([,n])=>n.kind===e&&n.noteType===t);return n?{id:n[0],story:n[1]}:{id:`${e}:${t}`,story:t===`separator`?jp:Np}}storyFor(e){return e===`footnote:separator`||e===`endnote:separator`?jp:e.endsWith(`:continuationSeparator`)?Np:this.story(e)}drawn(e,t){let n=this.storyFor(e),r=this.numbers.get(e)??``,i=this.cache.get(n);i||(i=new Map,this.cache.set(n,i));let a=`${r}|${t}`,o=i.get(a);if(!o){let e=this.doc.createElement(`div`);e.className=pp,e.style.paddingTop=`0.01px`;let s={...this.options,notes:{mark:r},...this.resolver?{resolver:this.resolver}:{}},c=Ef({...this.document,content:Mp(n)},this.doc,s),l=Tp(c,e,!!this.resolver?.addsParagraphSpacing),{style:u}=e;u.position=`absolute`,u.visibility=`hidden`,u.width=`${t}px`,this.options.measureIn().append(e);let d=this.options.scale?.()??1,f=e.getBoundingClientRect().top,p=c.flatMap(({element:e})=>{let t=(e.getBoundingClientRect().top-f)/d;return kp(e).map(e=>t+e/d)});e.remove(),u.position=``,u.visibility=``,u.width=``,p.length&&(p[p.length-1]=p.at(-1)+l),o={serial:++Pp,template:e,lines:p.length?p:[0]},i.set(a,o)}return o}linesOf(e,t){let{lines:n}=this.drawn(e,t);return e===this.open?[n.at(-1)]:n}flowNote(e,t){return{id:e,lines:n=>this.linesOf(e,t[n]??t[0])}}widths(e){return cp(this.sections[e]??{}).widths}footnote(e,t){return _d(e)===`footnote`&&this.numbers.has(e)&&this.story(e)?this.flowNote(e,this.widths(t)):null}flowRules(){if(!this.references.some(e=>e.kind===`footnote`&&this.story(e.story)))return;let e=this.widths(0);return{separator:this.flowNote(this.separator(`footnote`,`separator`).id,e),continuation:this.flowNote(this.separator(`footnote`,`continuationSeparator`).id,e)}}endnotes(){let e=new Map,t=Math.max(this.sections.length-1,0),n=this.document;if(!n)return e;let r=yd(n,`endnote`).position===`sectEnd`;for(let{story:n,kind:i,section:a}of this.references){if(i!==`endnote`||!this.story(n))continue;let o=r?a:t,s=e.get(o)??[this.flowNote(this.separator(`endnote`,`separator`).id,this.widths(o))];s.push(this.flowNote(n,this.widths(o))),e.set(o,s)}return e}key(){if(!this.references.length)return``;let e=this.references.filter(e=>this.story(e.story)).map(({story:e,section:t})=>{let n=this.linesOf(e,this.widths(t)[0]);return`${n.length}:${n.at(-1)}`});return`${this.open??``}|${e.join(` `)}`}groups(e,t){let n=new Map;for(let r of e){let e=r.band??0,i=r.column??0,a=t(r.page,e),o=this.sections[a],s=!!this.document&&this.widths(a).length===1&&yd(this.document,`footnote`,o).position===`beneathText`,c=!!r.end||s&&_d(r.id)===`footnote`,l=`${r.page}|${e}|${c?i:0}|${c}`,u=n.get(l);u||(u={page:r.page,band:e,column:i,inFlow:c,pieces:[],section:a},n.set(l,u)),u.pieces.push(r)}return[...n.values()]}widthOf(e){let t=this.widths(e.section);return t[e.column]??t[0]}pieceHeight(e,t){let n=this.linesOf(e.id,t),r=Math.min(e.toLine,n.length);return(e.lead??0)+(n[r-1]??0)-(e.fromLine?n[e.fromLine-1]??0:0)}arranged(e){let t=this.widthOf(e),n=e=>(this.storyFor(e.id)?.noteType??`normal`)!==`normal`,r=e.pieces.filter(n),i=e.pieces.filter(e=>!n(e)),a=e.inFlow?1:this.widths(e.section).length,{height:o,columnOf:s}=$f(i.map(e=>this.pieceHeight(e,t)),a);return{separators:r,notes:i,columnOf:s,columns:a,above:r.reduce((e,n)=>e+this.pieceHeight(n,t),0),height:o}}heightOf(e){let{above:t,height:n}=this.arranged(e);return t+n}keyOf(e){let t=this.widthOf(e);return e.pieces.map(e=>{let{serial:n}=this.drawn(e.id,t);return`${e.id}|${n}|${e.fromLine}|${e.toLine}|${e.lead??0}|${e.id===this.open}`}).join(`;`)}pieceElement(e,t){let n=this.widthOf(t),{lines:r,template:i}=this.drawn(e.id,n),a=this.doc.createElement(`div`);a.setAttribute(Dp,e.id),e.lead&&(a.style.marginTop=`${e.lead}px`);let o=i.cloneNode(!0);if(e.fromLine===0&&e.toLine>=r.length||e.id===this.open)return a.append(o),a;let s=e.fromLine?r[e.fromLine-1]:0,c=r[Math.min(e.toLine,r.length)-1];return a.style.overflow=`hidden`,a.style.height=`${c-s}px`,o.style.marginTop=`${-s}px`,e.fromLine&&o.setAttribute(`aria-hidden`,`true`),a.append(o),a}groupElement(e,t,n=t=>this.pieceElement(t,e),r=0){let i=this.doc.createElement(`div`);i.className=`${fp} ${Op}`,i.setAttribute(`contenteditable`,`false`);let{style:a}=i;a.userSelect=`none`,a.setProperty(`-webkit-user-select`,`none`),a.width=`${this.widthOf(e)}px`,r&&(a.marginTop=`${r}px`),t&&(a.position=`absolute`,a.left=`${t.left}px`,a.bottom=`${t.bottom}px`);let{separators:o,notes:s,columnOf:c,columns:l,above:u}=this.arranged(e);if(l===1)return i.append(...e.pieces.map(n)),i;let{widths:d,gaps:f}=cp(this.sections[e.section]??{});a.width=`auto`,a.display=`flex`,a.alignItems=`flex-start`;for(let e=0;e<l;e++){let t=this.doc.createElement(`div`);t.style.flex=`none`,t.style.width=`${d[e]}px`,t.style.marginRight=`${f[e]??0}px`,e?t.style.paddingTop=`${u}px`:t.append(...o.map(n)),t.append(...s.filter((t,n)=>c[n]===e).map(n)),i.append(t)}return i}footPlace(e,t){return{left:e.left,bottom:e.bottom+t}}stacked(e,t){let n=new Map;for(let r of t)r.page===e.page&&!r.inFlow&&r.band>e.band&&n.set(r.band,Math.max(n.get(r.band)??0,this.heightOf(r)));return[...n.values()].reduce((e,t)=>e+t,0)}},Ip=`foli-word-page`,Lp=`br[${Id}],br[${Ld}]`,Rp={width:12240,height:15840,margin:1440};function zp(e){let t=e.margins??{};return{width:(e.pageSize?.width??Rp.width)*Q,height:(e.pageSize?.height??Rp.height)*Q,top:Math.abs(t.top??Rp.margin)*Q,right:(t.right??Rp.margin)*Q,bottom:Math.abs(t.bottom??Rp.margin)*Q,left:((t.left??Rp.margin)+(t.gutter??0))*Q}}var Bp=(e,t)=>e.width===t.width&&e.height===t.height&&e.top===t.top&&e.bottom===t.bottom&&e.left===t.left&&e.right===t.right;function Vp(e,t){let n=e.createElement(`div`);n.className=Ip;let{style:r}=n;r.boxSizing=`border-box`,r.position=`relative`,r.isolation=`isolate`,r.width=`${t.width}px`,r.height=`${t.height}px`,r.padding=`${t.top}px ${t.right}px ${t.bottom}px ${t.left}px`,r.background=`#fff`,r.color=`#000`,r.overflow=`hidden`;let i=e.createElement(`div`);return i.style.display=`flow-root`,n.append(i),{page:n,body:i}}function Hp(e){return t=>{let n=e.ownerDocument.createElement(`div`),{style:r}=n;r.position=`absolute`,r.visibility=`hidden`,r.fontFamily=t,r.fontSize=`100px`,r.lineHeight=`normal`,r.whiteSpace=`nowrap`,n.textContent=`x`,e.append(n);let i=n.getBoundingClientRect().height;return n.remove(),i>0?i/100:1.2}}function Up(e,t,n){let r=e.querySelectorAll(`:scope > table > tbody > tr[data-foli-cant-split]`);if(!r.length)return t;let i=e.getBoundingClientRect().top,a=[...r].map(e=>{let t=e.getBoundingClientRect();return[t.top-i,t.bottom-i]}).filter(([e,t])=>t-e<=n);return t.filter(e=>!a.some(([t,n])=>e>t+.5&&e<n-.5))}function Wp(e){let t=0;for(let n of e.querySelectorAll(`:scope > table > tbody > tr`)){if(!n.dataset||!(`foliHeader`in n.dataset))break;t=n.getBoundingClientRect().bottom}return t?t-e.getBoundingClientRect().top:0}function Gp(e,t,n){let r=e.getBoundingClientRect().top;return[...e.querySelectorAll(`br[${n}]`)].map(e=>{let n=e.getBoundingClientRect().top-r,i=t.findIndex(e=>n<e);return i<0?t.length-1:i})}function Kp(e,t,n={}){let r=t.ownerDocument,i=e.stories?kn(e.content):null,a=(n.review??`markup`)!==`markup`,o=t=>i?Cd(i,e,{hideDeleted:a,...t?{pageOf:t}:{}}).filter(e=>!a||!e.deleted):[],s=o(),c=wd(s),l=Ef(e,r,{...n,lineRatio:Hp(t),notes:{references:c}}),u=[],d=[],f=Hp(t),p=new Ep(r,{...n,lineRatio:f,measureIn:()=>t},new WeakMap),m=new Mr(e);p.setDocument(e,d,m);let h=new Fp(r,{...n,lineRatio:f,measureIn:()=>t},new WeakMap),g=new Map,_=new Map,v=[],y=e=>{let n=zp(e),i=cp(e),a=d.length;d.push(e);let o={index:a,start:e.type??`nextPage`,columns:i.widths.length,pageStart:e.pageNumbers?.start,box:e=>({height:p.boxHeight(a,e)}),samePage:e=>Bp(n,g.get(e))};g.set(o,n);let{page:s,body:c}=Vp(r,n);s.style.position=`absolute`,s.style.visibility=`hidden`,s.style.height=`auto`;let l=r.createElement(`div`);l.style.display=`flow-root`,l.style.width=`${i.widths[0]}px`,c.append(l),t.append(s),l.append(...v.map(e=>e.element));let f={setup:e,geometry:n,columns:i,blocks:v,flow:o,measuring:s,column:l};for(let e of v)_.set(e,f);u.push(f),v=[]};for(let e of l)v.push(e),e.section&&y(e.section);(v.length||!u.length)&&y(e.section),h.setDocument(e,d,m,s),u.forEach((e,t)=>{let n=u[t+1];e.flow.balanced=!!n&&e.flow.columns>1&&n.setup.type===`continuous`&&Bp(e.geometry,n.geometry)});let b=new Map,x=(e,t)=>{let n=_.get(e),r=b.get(e)??new Map;b.set(e,r);let i=r.get(t);if(i)return i;let{column:a,geometry:o}=n,s=o.height-o.top-o.bottom,c=e=>{let n=a.style.width;a.style.width=`${t}px`;let r=e();return a.style.width=n,r},l=c(()=>e.element.getBoundingClientRect().height),u=!!e.element.querySelector(Lp),d=e.keepLines&&!u&&l<=s,f,p=()=>(f??=c(()=>Up(e.element,kp(e.element),s)),f),m={height:l,shown:p,lines:()=>d?[l]:p(),breaks:t=>c(()=>Gp(e.element,m.lines(),t)),references:()=>c(()=>{let t=e.element.getBoundingClientRect().top,n=m.lines();return[...e.element.querySelectorAll(`[${$d}]`)].map(e=>{let r=e.getBoundingClientRect().bottom-t,i=n.findIndex(e=>r<=e+1);return{story:e.getAttribute($d),line:i<0?n.length-1:i}})})};return r.set(t,m),m},S=(e,t)=>e.columns.widths[t.column??0],C=new Map;for(let e of l){let t=e.element.querySelectorAll(`[data-foli-cell]`);if(!t.length)continue;let n=e.element.getBoundingClientRect().top;C.set(e,[...t].map(e=>({top:e.getBoundingClientRect().top-n,text:e.textContent??``})))}let w=new Map,ee=h.endnotes(),te=(e,t)=>!l[t+1]||_.get(l[t+1])!==_.get(e),T=l.map((e,t)=>{let n=_.get(e),{widths:r}=n.columns,i=x(e,r[0]),a=e.element.querySelector(`tr`)?Wp(e.element):0;a&&w.set(e,a);let o=l[t+1],s=t=>!!e.element.querySelector(`br[${t}]`),c=s(Id),u=s(Ld),d=n.flow.index??0;return{notes:e.element.querySelector(`[data-foli-note-ref]`)?t=>x(e,r[t]).references().flatMap(({story:e,line:t})=>{let n=h.footnote(e,d);return n?[{line:t,note:n}]:[]}):void 0,endnotes:te(e,t)?ee.get(d):void 0,height:i.height,marginTop:e.before,marginBottom:e.after,repeat:a,anyLine:!!e.element.querySelector(`:scope > table`),keepWithNext:e.keepNext,section:n.flow,sectionMark:!!e.section&&!e.element.textContent&&!e.element.querySelector(`[data-foli-picture]`),lines:i.lines,inColumn:r.every(e=>e===r[0])?void 0:t=>x(e,r[t]),breaksAfter:(t=0)=>{let n=x(e,r[t]),i=c?n.breaks(Id):[];return o?.pageBreakBefore&&i.push(n.lines().length-1),i},columnBreaksAfter:(t=0)=>u?x(e,r[t]).breaks(Ld):[]}}),E={orphans:2,widows:2,spacing:`word`,addSpacing:e.settings?.doNotUseHTMLParagraphAutoSpacing===!0,evenAndOddHeaders:e.settings?.evenAndOddHeaders===!0,notes:h.flowRules()},D=Zf(T,0,E),O=Qf(T,D);for(let e=0;e<2&&p.settle(O);e++)D=Zf(T,0,E),O=Qf(T,D);if(d.some(t=>yd(e,`footnote`,t).restart===`eachPage`)){let t=new Map;for(let e of np(D))!e.fromLine&&!t.has(e.id)&&t.set(e.id,e.page);s=o((e,n)=>t.get(n));let n=wd(s);h.setDocument(e,d,m,s);for(let e of l)for(let t of e.element.querySelectorAll(`[${$d}]`))t.textContent=n.get(t.getAttribute(`data-foli-note-ref`))??``;D=Zf(T,0,E),O=Qf(T,D)}let{fragments:k,gaps:ne}=D,re=np(D);l.forEach((e,t)=>{let n=k[t]??[];if(n.length<2)return;let r=_.get(e);for(let t of n)x(e,S(r,t)).lines()});for(let e of u)e.measuring.remove();let ie=[];l.forEach((e,t)=>{for(let n of k[t]??[]){let t=ie[n.page]??[];ie[n.page]=t,t[n.band??0]??=_.get(e)}});let A=Math.max(1,ie.length,...re.map(e=>e.page+1)),j=[];for(let e=A-1;e>=0;e--)j[e]=ie[e]?.[0]??j[e+1]??u.at(-1);let ae=j.map((e,t)=>{let n=Vp(r,e.geometry);n.page.setAttribute(ip,String(e.flow.index??0));let i=O[t];if(!i?.sectionPages)return n;let{top:a,bottom:o}=p.margins(i.section,i);n.page.style.paddingTop=`${a}px`,n.page.style.paddingBottom=`${o}px`;for(let e of[`header`,`footer`]){let t=p.drawing(i.section,e,i);if(!t)continue;let r=p.element(i.section,e);r.append(t.content.content.cloneNode(!0)),n.page.append(r)}return n}),oe=new Map,M=(e,t)=>{let{body:n}=ae[e.page],i=ie[e.page]??[t];if(i.length===1&&t.flow.columns===1)return n;let a=e.band??0;for(let t=0;t<=a;t++){let a=`${e.page} ${t}`;if(oe.has(a))continue;let o=up(r,i[t].columns);oe.set(a,o),n.append(o.band)}let o=oe.get(`${e.page} ${a}`);return e.lead&&(o.band.style.marginTop=`${e.lead}px`),o.columns[e.column??0]},se=(e,t)=>(ie[e]?.[t]??j[e])?.flow.index??0,ce=e=>h.groups(e,se),le=ce(re).filter(e=>!e.inFlow),ue=new Map,N=[],de=[];l.forEach((e,t)=>{let n=_.get(e),i=k[t]??[],a=t=>x(e,S(n,t)).lines();i.forEach((o,s)=>{let c=M(o,n),l=e.element;if(i.length>1){let t=a(o),n=o.fromLine?t[o.fromLine-1]??0:0,i=o.toLine===1/0?t[t.length-1]??0:t[o.toLine-1]??0,c=r.createElement(`div`);c.style.overflow=`hidden`,c.style.height=`${i-n}px`;let u=s===0?e.element:e.element.cloneNode(!0);s>0&&u.setAttribute(`aria-hidden`,`true`),u.style.marginTop=`${-n}px`,c.append(u),l=c;let d=s>0?w.get(e)??0:0;if(d){let t=r.createElement(`div`);t.style.overflow=`hidden`,t.style.height=`${d}px`;let n=e.element.cloneNode(!0);n.setAttribute(`aria-hidden`,`true`),n.style.marginTop=`0`,t.append(n),l=r.createElement(`div`),l.append(t,c)}}o.mark&&(l.style.position=`absolute`),l.style.marginTop=`${o.fromLine===0?ne[t]??0:0}px`,c.append(l),N.push({page:o.page,nodes:s===0?e.nodes:null,mark:!!o.mark,lines:()=>(o.toLine===1/0?x(e,S(n,o)).shown().length:o.toLine)-o.fromLine})});for(let t of C.get(e)??[]){let e=i[0]?.page??0;for(let n of i){let r=n.fromLine?a(n)[n.fromLine-1]??0:0;t.top+.5>=r&&(e=n.page)}de.push({page:e,text:t.text})}let o=i[0];if(o)for(let t of e.nodes)ue.set(t,o.page)});for(let e of ce(re))e.inFlow&&M({page:e.page,band:e.band,column:e.column},u[e.section]).append(h.groupElement(e,null,void 0,e.pieces[0]?.end?0:tp(T,D,e.page,e.band,e.column)));for(let e of ce(re)){if(e.inFlow)continue;let{page:t}=ae[e.page],n=u[e.section],r=O[e.page],i=r?.sectionPages?p.margins(r.section,r).bottom:n.geometry.bottom,a=h.footPlace({left:n.geometry.left,bottom:i},h.stacked(e,le));t.append(h.groupElement(e,a))}let fe=ae.map(({page:e})=>(t.append(e),e)),pe=null,me=null,he={pages:O.length,pageAt:t=>{if(!me){let t=[];(i??kn(e.content)).forEach((e,n)=>{t.push(n)}),me=t}let n=me.length-1;for(;n>0&&me[n]>t;)n--;for(;n>0&&!ue.has(n);)n--;let r=O[ue.get(n)??-1];if(!r)return null;let a=d[r.section]?.pageNumbers?.format;return{number:r.number,sectionPages:r.sectionPages,format:a}}},ge=e=>`${e}px`;return{pages:fe,fieldLayout:he,printStyles:()=>{let e=u.at(-1).geometry;return ap(`.${Ip}`,{width:ge(e.width),height:ge(e.height)},u.map(({geometry:e,flow:t})=>({width:ge(e.width),height:ge(e.height),index:t.index??0})),`word`)},pageOf:e=>ue.get(e),lineOf:e=>{if(!pe){pe=new Map;let e=-1,t=1;for(let n of N){n.page!==e&&(e=n.page,t=1);for(let e of n.nodes??[])pe.set(e,n.mark?Math.max(t-1,1):t);n.mark||(t+=n.lines())}}return pe.get(e)},cellParagraphs:()=>de,destroy:()=>{for(let e of fe)e.remove()}}}var qp=new Set([`PAGE`,`NUMPAGES`,`SECTIONPAGES`,`PAGEREF`]);function Jp(e){let t=e.ownerDocument,n=new Map;for(let t of e.querySelectorAll(`[data-foli-bookmark]`)){let e=t.getAttribute(`data-foli-bookmark`)??``;e&&!n.has(e)&&!t.closest(`[aria-hidden]`)&&n.set(e,t)}let r=0;for(let i of e.querySelectorAll(`[data-href]`)){let e=i.dataset.href??``,a=null;if(e.startsWith(`#`)){let t=n.get(e.slice(1));t&&(t.id||=`foli-bookmark-${r++}`,a=`#${t.id}`)}else/^[a-z][a-z0-9+.-]*:/i.test(e)&&le(e)&&(a=e);if(!a)continue;let o=t.createElement(`a`);o.href=a,o.style.color=`inherit`,o.style.textDecoration=`none`,i.replaceWith(o),o.append(i)}}var Yp=1e4;async function Xp(e){let t=[...e.images].filter(e=>!e.complete),n;await Promise.race([Promise.all(t.map(e=>e.decode().catch(()=>null))),new Promise(e=>{n=setTimeout(e,Yp)})]),clearTimeout(n);for(let e of t)e.complete||e.removeAttribute(`src`)}async function Zp({document:e,images:t,review:n,styles:r}){let i=window.document,a=i.createElement(`style`);a.textContent=`html,body{margin:0;background:#fff}${r}`,i.head.append(a),await Promise.all([...i.fonts].map(e=>e.load().catch(()=>null)));let o=i.body,s=e=>t[e]??null,c=e=>Kp(e,o,{review:n,resource:s}),l=Dn(e),u=c(l),d=Fd({document:l}),f=bl(d,{layout:u.fieldLayout});if(f.updated){u.destroy(),u=c(d.getDocument());let e=bl(d,{layout:u.fieldLayout,only:e=>qp.has(e.name)});e.updated&&(u.destroy(),u=c(d.getDocument())),f.updated+=e.updated}Jp(o);let p=i.createElement(`style`);return p.textContent=u.printStyles(),i.head.append(p),await Xp(i),await i.fonts.ready,{pages:u.pages.length,fields:f}}return window.foliPdf={render:Zp},e.imagesLoaded=Xp,e})({});
|
package/package.json
CHANGED
|
@@ -1,6 +1,40 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@folijs/pdf",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.6.0",
|
|
4
|
+
"description": "PDF for the Foli document engine: a document printed by a headless Chromium page the app supplies (Playwright or Puppeteer), from Foli's own page layout, fields updated, links and the outline kept.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/josep-audenis/foli.git",
|
|
9
|
+
"directory": "packages/pdf"
|
|
10
|
+
},
|
|
11
|
+
"homepage": "https://github.com/josep-audenis/foli#readme",
|
|
12
|
+
"bugs": "https://github.com/josep-audenis/foli/issues",
|
|
13
|
+
"type": "module",
|
|
14
|
+
"sideEffects": false,
|
|
15
|
+
"engines": {
|
|
16
|
+
"node": ">=20.19"
|
|
17
|
+
},
|
|
18
|
+
"exports": {
|
|
19
|
+
".": {
|
|
20
|
+
"types": "./dist/index.d.ts",
|
|
21
|
+
"default": "./dist/index.js"
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
"files": [
|
|
25
|
+
"dist",
|
|
26
|
+
"CHANGELOG.md"
|
|
27
|
+
],
|
|
28
|
+
"dependencies": {
|
|
29
|
+
"@folijs/core": "^0.6.0"
|
|
30
|
+
},
|
|
31
|
+
"devDependencies": {
|
|
32
|
+
"@types/node": "^20.19.43",
|
|
33
|
+
"vite": "^8.3.5",
|
|
34
|
+
"@folijs/view": "^0.6.0"
|
|
35
|
+
},
|
|
36
|
+
"scripts": {
|
|
37
|
+
"build": "node -e \"require('node:fs').rmSync('dist',{recursive:true,force:true})\" && vite build && tsc -p tsconfig.build.json",
|
|
38
|
+
"typecheck": "tsc -p tsconfig.json --noEmit"
|
|
39
|
+
}
|
|
6
40
|
}
|