@folijs/docx 0.0.0-stage → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (79) hide show
  1. package/CHANGELOG.md +29 -0
  2. package/LICENSE +21 -0
  3. package/README.md +141 -2
  4. package/dist/export/content.d.ts +17 -0
  5. package/dist/export/content.d.ts.map +1 -0
  6. package/dist/export/content.js +165 -0
  7. package/dist/export/content.js.map +1 -0
  8. package/dist/export/index.d.ts +14 -0
  9. package/dist/export/index.d.ts.map +1 -0
  10. package/dist/export/index.js +352 -0
  11. package/dist/export/index.js.map +1 -0
  12. package/dist/export/parts.d.ts +24 -0
  13. package/dist/export/parts.d.ts.map +1 -0
  14. package/dist/export/parts.js +413 -0
  15. package/dist/export/parts.js.map +1 -0
  16. package/dist/export/properties.d.ts +39 -0
  17. package/dist/export/properties.d.ts.map +1 -0
  18. package/dist/export/properties.js +506 -0
  19. package/dist/export/properties.js.map +1 -0
  20. package/dist/export/xmlout.d.ts +63 -0
  21. package/dist/export/xmlout.d.ts.map +1 -0
  22. package/dist/export/xmlout.js +194 -0
  23. package/dist/export/xmlout.js.map +1 -0
  24. package/dist/import/content.d.ts +35 -0
  25. package/dist/import/content.d.ts.map +1 -0
  26. package/dist/import/content.js +370 -0
  27. package/dist/import/content.js.map +1 -0
  28. package/dist/import/index.d.ts +26 -0
  29. package/dist/import/index.d.ts.map +1 -0
  30. package/dist/import/index.js +96 -0
  31. package/dist/import/index.js.map +1 -0
  32. package/dist/import/ooxml.d.ts +38 -0
  33. package/dist/import/ooxml.d.ts.map +1 -0
  34. package/dist/import/ooxml.js +70 -0
  35. package/dist/import/ooxml.js.map +1 -0
  36. package/dist/import/parts.d.ts +35 -0
  37. package/dist/import/parts.d.ts.map +1 -0
  38. package/dist/import/parts.js +365 -0
  39. package/dist/import/parts.js.map +1 -0
  40. package/dist/import/properties.d.ts +50 -0
  41. package/dist/import/properties.d.ts.map +1 -0
  42. package/dist/import/properties.js +403 -0
  43. package/dist/import/properties.js.map +1 -0
  44. package/dist/import/report.d.ts +28 -0
  45. package/dist/import/report.d.ts.map +1 -0
  46. package/dist/import/report.js +42 -0
  47. package/dist/import/report.js.map +1 -0
  48. package/dist/index.d.ts +6 -0
  49. package/dist/index.d.ts.map +1 -0
  50. package/dist/index.js +6 -0
  51. package/dist/index.js.map +1 -0
  52. package/dist/package.d.ts +70 -0
  53. package/dist/package.d.ts.map +1 -0
  54. package/dist/package.js +259 -0
  55. package/dist/package.js.map +1 -0
  56. package/dist/xml.d.ts +79 -0
  57. package/dist/xml.d.ts.map +1 -0
  58. package/dist/xml.js +384 -0
  59. package/dist/xml.js.map +1 -0
  60. package/dist/zip.d.ts +66 -0
  61. package/dist/zip.d.ts.map +1 -0
  62. package/dist/zip.js +356 -0
  63. package/dist/zip.js.map +1 -0
  64. package/package.json +36 -3
  65. package/src/export/content.ts +229 -0
  66. package/src/export/index.ts +445 -0
  67. package/src/export/parts.ts +545 -0
  68. package/src/export/properties.ts +608 -0
  69. package/src/export/xmlout.ts +225 -0
  70. package/src/import/content.ts +413 -0
  71. package/src/import/index.ts +126 -0
  72. package/src/import/ooxml.ts +77 -0
  73. package/src/import/parts.ts +423 -0
  74. package/src/import/properties.ts +504 -0
  75. package/src/import/report.ts +64 -0
  76. package/src/index.ts +24 -0
  77. package/src/package.ts +328 -0
  78. package/src/xml.ts +443 -0
  79. package/src/zip.ts +401 -0
@@ -0,0 +1,26 @@
1
+ import { type FoliDocument } from "@folijs/core";
2
+ import { type DocxPackage, type ReadPackageOptions } from "../package.js";
3
+ import { type ImportReport } from "./report.js";
4
+ export interface DocxImport {
5
+ /** The document in schema v3, validated. */
6
+ readonly document: FoliDocument;
7
+ /**
8
+ * The package it was read from. Export (8.5) writes the parts Foli does not edit back from
9
+ * it, unchanged; keep it with the document.
10
+ */
11
+ readonly package: DocxPackage;
12
+ readonly report: ImportReport;
13
+ }
14
+ /** Reads a `.docx` into schema v3, keeping its package for export. */
15
+ export declare function importDocx(bytes: Uint8Array, options?: ReadPackageOptions): Promise<DocxImport>;
16
+ /**
17
+ * The document of a package in schema v3: paragraphs with their properties, runs as text with
18
+ * marks, tracked changes, comments, styles, numbering, the theme and sections. Every element
19
+ * Foli does not model is kept verbatim (opaque nodes, `ext`, attribute bags) and counted in the
20
+ * report; a value the model cannot hold stays in its verbatim element and is reported
21
+ * (`unmodeled`); not imported is only what Word recomputes or shows nothing (`dropped`).
22
+ * Every failure is a `DocxError` (or the package's `ZipError`).
23
+ */
24
+ export declare function importPackage(pkg: DocxPackage): DocxImport;
25
+ export type { ImportReport } from "./report.js";
26
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/import/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,YAAY,EAAiB,MAAM,cAAc,CAAC;AAChE,OAAO,EAEL,KAAK,WAAW,EAChB,KAAK,kBAAkB,EAGxB,MAAM,eAAe,CAAC;AAMvB,OAAO,EAAE,KAAK,YAAY,EAAY,MAAM,aAAa,CAAC;AAE1D,MAAM,WAAW,UAAU;IACzB,4CAA4C;IAC5C,QAAQ,CAAC,QAAQ,EAAE,YAAY,CAAC;IAChC;;;OAGG;IACH,QAAQ,CAAC,OAAO,EAAE,WAAW,CAAC;IAC9B,QAAQ,CAAC,MAAM,EAAE,YAAY,CAAC;CAC/B;AAED,sEAAsE;AACtE,wBAAsB,UAAU,CAC9B,KAAK,EAAE,UAAU,EACjB,OAAO,GAAE,kBAAuB,GAC/B,OAAO,CAAC,UAAU,CAAC,CAErB;AAED;;;;;;;GAOG;AACH,wBAAgB,aAAa,CAAC,GAAG,EAAE,WAAW,GAAG,UAAU,CAiF1D;AAED,YAAY,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC"}
@@ -0,0 +1,96 @@
1
+ import { parseDocument } from "@folijs/core";
2
+ import { DocxError, readPackage, } from "../package.js";
3
+ import { blocks, Moves } from "./content.js";
4
+ import { child, isW, REL, W_STRICT } from "./ooxml.js";
5
+ import { comments, numbering, styles, theme } from "./parts.js";
6
+ import { section } from "./properties.js";
7
+ import { Recorder } from "./report.js";
8
+ /** Reads a `.docx` into schema v3, keeping its package for export. */
9
+ export async function importDocx(bytes, options = {}) {
10
+ return importPackage(await readPackage(bytes, options));
11
+ }
12
+ /**
13
+ * The document of a package in schema v3: paragraphs with their properties, runs as text with
14
+ * marks, tracked changes, comments, styles, numbering, the theme and sections. Every element
15
+ * Foli does not model is kept verbatim (opaque nodes, `ext`, attribute bags) and counted in the
16
+ * report; a value the model cannot hold stays in its verbatim element and is reported
17
+ * (`unmodeled`); not imported is only what Word recomputes or shows nothing (`dropped`).
18
+ * Every failure is a `DocxError` (or the package's `ZipError`).
19
+ */
20
+ export function importPackage(pkg) {
21
+ const report = new Recorder();
22
+ const main = pkg.xml(pkg.mainDocument);
23
+ if (main.root.ns === W_STRICT)
24
+ throw new DocxError("Strict Open XML documents are not supported yet");
25
+ if (!isW(main.root, "document"))
26
+ throw new DocxError(`${pkg.mainDocument}: not a WordprocessingML document`);
27
+ const body = child(main.root, "body");
28
+ if (!body)
29
+ throw new DocxError(`${pkg.mainDocument}: no w:body`);
30
+ const contextFor = (part, source) => {
31
+ report.part = part;
32
+ // One lookup table per part: hyperlinks resolve in constant time.
33
+ let byId;
34
+ const relationship = (id) => {
35
+ byId ??= new Map(pkg.relationships(part).map((r) => [r.id, r]));
36
+ return byId.get(id);
37
+ };
38
+ return { source, report, pkg, part, moves: new Moves(), relationship };
39
+ };
40
+ const related = (type) => {
41
+ const relationship = pkg
42
+ .relationships(pkg.mainDocument)
43
+ .find((r) => r.type === type && !r.external);
44
+ const part = relationship?.partName ? pkg.part(relationship.partName) : undefined;
45
+ if (!part)
46
+ return undefined;
47
+ const xml = pkg.xml(part.name);
48
+ return { name: part.name, root: xml.root, source: xml.source };
49
+ };
50
+ const mainContext = contextFor(pkg.mainDocument, main.source);
51
+ // The body's section: its last `w:sectPr`, whatever follows it (a bookmark end…).
52
+ const sectPr = body.children
53
+ .filter((c) => c.kind === "element" && isW(c, "sectPr"))
54
+ .at(-1);
55
+ let content = blocks(body.children, mainContext, sectPr);
56
+ if (content.length === 0)
57
+ content = [{ type: "paragraph" }];
58
+ const lastSection = sectPr ? section(sectPr, mainContext) : {};
59
+ const stylesPart = related(REL.styles);
60
+ const styled = stylesPart
61
+ ? styles(stylesPart.root, contextFor(stylesPart.name, stylesPart.source))
62
+ : { defaults: {}, styles: [] };
63
+ const numberingPart = related(REL.numbering);
64
+ const numbered = numberingPart
65
+ ? numbering(numberingPart.root, contextFor(numberingPart.name, numberingPart.source))
66
+ : { abstracts: [], instances: [] };
67
+ const themePart = related(REL.theme);
68
+ const themed = themePart
69
+ ? theme(themePart.root, contextFor(themePart.name, themePart.source))
70
+ : undefined;
71
+ const commentsPart = related(REL.comments);
72
+ const extended = related(REL.commentsExtended);
73
+ const commented = commentsPart
74
+ ? comments(commentsPart.root, extended?.root, contextFor(commentsPart.name, commentsPart.source))
75
+ : [];
76
+ let document;
77
+ try {
78
+ document = parseDocument({
79
+ schemaVersion: 3,
80
+ section: lastSection,
81
+ defaults: styled.defaults,
82
+ styles: styled.styles,
83
+ numbering: numbered,
84
+ ...(themed ? { theme: themed } : {}),
85
+ comments: commented,
86
+ content: { type: "doc", content },
87
+ });
88
+ }
89
+ catch (error) {
90
+ // Each value was checked as it was read; what is left is beyond the model's limits (an
91
+ // element over 16 MiB kept verbatim…). A DocxError like every other import failure.
92
+ throw new DocxError(`Cannot import: ${error.message}`, { cause: error });
93
+ }
94
+ return { document, package: pkg, report: report.report() };
95
+ }
96
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/import/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAqB,aAAa,EAAE,MAAM,cAAc,CAAC;AAChE,OAAO,EACL,SAAS,EAIT,WAAW,GACZ,MAAM,eAAe,CAAC;AA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@ -0,0 +1,38 @@
1
+ /** WordprocessingML names and the small helpers the importer reads XML with. */
2
+ import type { XmlElement, XmlNode } from "../xml.js";
3
+ export declare const W = "http://schemas.openxmlformats.org/wordprocessingml/2006/main";
4
+ /** Strict Open XML's WordprocessingML namespace (not supported yet: other units and names). */
5
+ export declare const W_STRICT = "http://purl.oclc.org/ooxml/wordprocessingml/main";
6
+ export declare const R = "http://schemas.openxmlformats.org/officeDocument/2006/relationships";
7
+ export declare const W14 = "http://schemas.microsoft.com/office/word/2010/wordml";
8
+ export declare const W15 = "http://schemas.microsoft.com/office/word/2012/wordml";
9
+ export declare const A = "http://schemas.openxmlformats.org/drawingml/2006/main";
10
+ export declare const REL: {
11
+ styles: string;
12
+ numbering: string;
13
+ theme: string;
14
+ comments: string;
15
+ commentsExtended: string;
16
+ hyperlink: string;
17
+ };
18
+ /** Whether `node` is the WordprocessingML element `local`. */
19
+ export declare function isW(node: XmlNode, local?: string): boolean;
20
+ export declare function elements(element: XmlElement): XmlElement[];
21
+ /** The first WordprocessingML child named `local`. */
22
+ export declare function child(element: XmlElement, local: string): XmlElement | undefined;
23
+ /** A WordprocessingML attribute (`w:val`) of `element`. */
24
+ export declare function attr(element: XmlElement | undefined, local: string, ns?: string): string | undefined;
25
+ /** The text of an element's character data children (`w:t`, `w:delText`, `w:instrText`). */
26
+ export declare function textOf(element: XmlElement): string;
27
+ /** Every `w:t` and `w:delText` of an element's descendants, in order (the text it shows). */
28
+ export declare function deepText(element: XmlElement): string;
29
+ /** An integer as Word writes it; undefined for anything else (universal measures, decimals). */
30
+ export declare function integer(value: string | undefined): number | undefined;
31
+ /**
32
+ * An on/off property (ST_OnOff): absent value is on. Undefined for a value that is not one of
33
+ * Word's spellings.
34
+ */
35
+ export declare function toggle(element: XmlElement): boolean | undefined;
36
+ /** `{ key: value }` without the undefined values; undefined when none remain. */
37
+ export declare function compact<T extends Record<string, unknown>>(object: T): Partial<T> | undefined;
38
+ //# sourceMappingURL=ooxml.d.ts.map
@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AGG;AACH,wBAAgB,MAAM,CAAC,OAAO,EAAE,UAAU,GAAG,OAAO,GAAG,SAAS,CAK/D;AAED,iFAAiF;AACjF,wBAAgB,OAAO,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,GAAG,SAAS,CAI5F"}
@@ -0,0 +1,70 @@
1
+ /** WordprocessingML names and the small helpers the importer reads XML with. */
2
+ export const W = "http://schemas.openxmlformats.org/wordprocessingml/2006/main";
3
+ /** Strict Open XML's WordprocessingML namespace (not supported yet: other units and names). */
4
+ export const W_STRICT = "http://purl.oclc.org/ooxml/wordprocessingml/main";
5
+ export const R = "http://schemas.openxmlformats.org/officeDocument/2006/relationships";
6
+ export const W14 = "http://schemas.microsoft.com/office/word/2010/wordml";
7
+ export const W15 = "http://schemas.microsoft.com/office/word/2012/wordml";
8
+ export const A = "http://schemas.openxmlformats.org/drawingml/2006/main";
9
+ export const REL = {
10
+ styles: "http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles",
11
+ numbering: "http://schemas.openxmlformats.org/officeDocument/2006/relationships/numbering",
12
+ theme: "http://schemas.openxmlformats.org/officeDocument/2006/relationships/theme",
13
+ comments: "http://schemas.openxmlformats.org/officeDocument/2006/relationships/comments",
14
+ commentsExtended: "http://schemas.microsoft.com/office/2011/relationships/commentsExtended",
15
+ hyperlink: "http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink",
16
+ };
17
+ /** Whether `node` is the WordprocessingML element `local`. */
18
+ export function isW(node, local) {
19
+ return node.kind === "element" && node.ns === W && (local === undefined || node.local === local);
20
+ }
21
+ export function elements(element) {
22
+ return element.children.filter((child) => child.kind === "element");
23
+ }
24
+ /** The first WordprocessingML child named `local`. */
25
+ export function child(element, local) {
26
+ return element.children.find((c) => c.kind === "element" && isW(c, local));
27
+ }
28
+ /** A WordprocessingML attribute (`w:val`) of `element`. */
29
+ export function attr(element, local, ns = W) {
30
+ return element?.attributes.find((a) => a.local === local && a.ns === ns)?.value;
31
+ }
32
+ /** The text of an element's character data children (`w:t`, `w:delText`, `w:instrText`). */
33
+ export function textOf(element) {
34
+ return element.children.map((c) => (c.kind === "text" ? c.text : "")).join("");
35
+ }
36
+ /** Every `w:t` and `w:delText` of an element's descendants, in order (the text it shows). */
37
+ export function deepText(element) {
38
+ let out = "";
39
+ for (const c of element.children) {
40
+ if (c.kind !== "element")
41
+ continue;
42
+ out += isW(c, "t") || isW(c, "delText") ? textOf(c) : deepText(c);
43
+ }
44
+ return out;
45
+ }
46
+ /** An integer as Word writes it; undefined for anything else (universal measures, decimals). */
47
+ export function integer(value) {
48
+ return value !== undefined && /^-?\d+$/.test(value) ? Number.parseInt(value, 10) : undefined;
49
+ }
50
+ /**
51
+ * An on/off property (ST_OnOff): absent value is on. Undefined for a value that is not one of
52
+ * Word's spellings.
53
+ */
54
+ export function toggle(element) {
55
+ const value = attr(element, "val");
56
+ if (value === undefined || value === "1" || value === "true" || value === "on")
57
+ return true;
58
+ if (value === "0" || value === "false" || value === "off")
59
+ return false;
60
+ return undefined;
61
+ }
62
+ /** `{ key: value }` without the undefined values; undefined when none remain. */
63
+ export function compact(object) {
64
+ const out = {};
65
+ for (const [key, value] of Object.entries(object))
66
+ if (value !== undefined)
67
+ out[key] = value;
68
+ return Object.keys(out).length ? out : undefined;
69
+ }
70
+ //# sourceMappingURL=ooxml.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ooxml.js","sourceRoot":"","sources":["../../src/import/ooxml.ts"],"names":[],"mappings":"AAAA,gFAAgF;AAIhF,MAAM,CAAC,MAAM,CAAC,GAAG,8DAA8D,CAAC;AAChF,+FAA+F;AAC/F,MAAM,CAAC,MAAM,QAAQ,GAAG,kDAAkD,CAAC;AAC3E,MAAM,CAAC,MAAM,CAAC,GAAG,qEAAqE,CAAC;AACvF,MAAM,CAAC,MAAM,GAAG,GAAG,sDAAsD,CAAC;AAC1E,MAAM,CA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,KAAK,OAAO,IAAI,KAAK,KAAK,KAAK;QAAE,OAAO,KAAK,CAAC;IACxE,OAAO,SAAS,CAAC;AACnB,CAAC;AAED,iFAAiF;AACjF,MAAM,UAAU,OAAO,CAAoC,MAAS;IAClE,MAAM,GAAG,GAA4B,EAAE,CAAC;IACxC,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC;QAAE,IAAI,KAAK,KAAK,SAAS;YAAE,GAAG,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;IAC7F,OAAO,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,CAAC,CAAE,GAAkB,CAAC,CAAC,CAAC,SAAS,CAAC;AACnE,CAAC"}
@@ -0,0 +1,35 @@
1
+ /** The parts beside the document: styles, numbering, theme, comments. */
2
+ import { type AbstractNumberingJSON, type CommentJSON, type NumberingInstanceJSON, type NumberingLevelJSON, type StyleJSON, type ThemeJSON } from "@folijs/core";
3
+ import type { XmlElement } from "../xml.js";
4
+ import { type ContentContext } from "./content.js";
5
+ import { type Context } from "./properties.js";
6
+ /** `w:styles`: the document defaults and the styles (each with its element verbatim). */
7
+ export declare function styles(root: XmlElement, context: Context): {
8
+ defaults: Record<string, unknown>;
9
+ styles: StyleJSON[];
10
+ };
11
+ /** `w:docDefaults` as the envelope's defaults (with the element verbatim). */
12
+ export declare function defaultsOf(docDefaults: XmlElement, context: Context): Record<string, unknown>;
13
+ /** Whether import keeps a `w:style` (it has a usable id and type); others stay in the part only. */
14
+ export declare function usableStyle(el: XmlElement): boolean;
15
+ /** A `w:style` as a style (with the element verbatim); undefined (reported) when unusable. */
16
+ export declare function styleOf(el: XmlElement, context: Context): StyleJSON | undefined;
17
+ export declare function level(lvl: XmlElement, context: Context): NumberingLevelJSON | undefined;
18
+ /** `w:numbering`: abstract definitions and instances (each with its element verbatim). */
19
+ export declare function numbering(root: XmlElement, context: Context): {
20
+ abstracts: AbstractNumberingJSON[];
21
+ instances: NumberingInstanceJSON[];
22
+ };
23
+ /** A `w:abstractNum` as a definition (with the element verbatim); undefined (reported) when unusable. */
24
+ export declare function abstractOf(el: XmlElement, context: Context): AbstractNumberingJSON | undefined;
25
+ /** A `w:num` as an instance (with the element verbatim); undefined (reported) when unusable. */
26
+ export declare function instanceOf(el: XmlElement, context: Context): NumberingInstanceJSON | undefined;
27
+ /** `a:theme`'s fonts and colors; undefined (reported) when its fonts are missing or unusable. */
28
+ export declare function theme(root: XmlElement, context: Context): ThemeJSON | undefined;
29
+ /**
30
+ * `w:comments`, with replies and resolved state from `commentsExtended` (keyed by the
31
+ * `w14:paraId` of each comment's last paragraph). Each comment keeps its start tag verbatim
32
+ * (`ext`): values the model cannot hold (a long author, a date without a time) stay there.
33
+ */
34
+ export declare function comments(root: XmlElement, extended: XmlElement | undefined, context: ContentContext): CommentJSON[];
35
+ //# sourceMappingURL=parts.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"parts.d.ts","sourceRoot":"","sources":["../../src/import/parts.ts"],"names":[],"mappings":"AAAA,yEAAyE;AAEzE,OAAO,EACL,KAAK,qBAAqB,EAC1B,KAAK,WAAW,EAEhB,KAAK,qBAAqB,EAC1B,KAAK,kBAAkB,EAEvB,KAAK,SAAS,EAEd,KAAK,SAAS,EACf,MAAM,cAAc,CAAC;AACtB,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAC5C,OAAO,EAAU,KAAK,cAAc,EAAE,MAAM,cAAc,CAAC;AAE3D,OAAO,EAAE,KAAK,OAAO,EAAuD,MAAM,iBAAiB,CAAC;AA+BpG,yFAAyF;AACzF,wBAAgB,MAAM,CACpB,IAAI,EAAE,UAAU,EAChB,OAAO,EAAE,OAAO,GACf;IAAE,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAAC,MAAM,EAAE,SAAS,EAAE,CAAA;CAAE,CAmB5D;AAED,8EAA8E;AAC9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