@a3s-lab/office 0.2.2 → 0.4.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/COLLABORATION_ROADMAP.md +426 -0
- package/README.md +649 -10
- package/dist/0~1403.js +1 -1
- package/dist/0~2805.js +1279 -0
- package/dist/{0~use-office-draft.js → 0~345.js} +30 -1
- package/dist/0~3539.js +1 -1
- package/dist/0~3557.js +1 -1
- package/dist/0~3635.js +1 -1
- package/dist/0~4595.js +123 -12
- package/dist/0~4980.js +154 -0
- package/dist/0~5050.js +124 -113
- package/dist/{0~9512.js → 0~6090.js} +540 -3
- package/dist/0~7048.js +92 -66
- package/dist/0~7614.js +2 -1
- package/dist/0~7754.js +5653 -0
- package/dist/0~9445.js +1 -1
- package/dist/0~document-editor.js +4992 -3323
- package/dist/0~markdown-editor.js +250 -44
- package/dist/0~pdf-viewer.js +1016 -24
- package/dist/0~presentation-editor.js +179 -8
- package/dist/0~spreadsheet-editor.js +3371 -578
- package/dist/0~work-docx-export.js +6801 -658
- package/dist/0~work-docx-import.js +1388 -795
- package/dist/0~work-office-diagnostics.js +524 -30
- package/dist/0~work-pptx-export.js +2 -1
- package/dist/0~work-pptx-import.js +1 -2
- package/dist/0~work-presentation-charts.js +1 -1
- package/dist/2591.js +197 -0
- package/dist/3818.js +1090 -0
- package/dist/4104.js +970 -60
- package/dist/432.js +171 -14
- package/dist/4476.js +2008 -0
- package/dist/4560.js +674 -0
- package/dist/4650.js +70 -0
- package/dist/{1134.js → 5184.js} +183 -1
- package/dist/6489.js +18 -18
- package/dist/7060.js +132 -0
- package/dist/8715.js +2 -136
- package/dist/8928.js +16778 -0
- package/dist/9787.js +209 -0
- package/dist/core.d.ts +29 -9
- package/dist/core.js +10 -2
- package/dist/index.js +13 -3
- package/dist/internal/collaboration/office-collaboration-flat-json.d.ts +13 -0
- package/dist/internal/collaboration/office-collaboration-json.d.ts +4 -0
- package/dist/internal/collaboration/office-collaboration-presence.d.ts +86 -0
- package/dist/internal/collaboration/office-collaboration-transport.d.ts +42 -0
- package/dist/internal/collaboration/office-collaboration.d.ts +85 -0
- package/dist/internal/collaboration/office-document-collaboration-bibliography.d.ts +7 -0
- package/dist/internal/collaboration/office-document-collaboration-claims.d.ts +9 -0
- package/dist/internal/collaboration/office-document-collaboration-comments.d.ts +7 -0
- package/dist/internal/collaboration/office-document-collaboration-sidecar-utils.d.ts +27 -0
- package/dist/internal/collaboration/office-document-collaboration-sidecars.d.ts +16 -0
- package/dist/internal/collaboration/office-document-collaboration.d.ts +45 -0
- package/dist/internal/collaboration/office-markdown-collaboration.d.ts +31 -0
- package/dist/internal/collaboration/office-pdf-collaboration-claims.d.ts +4 -0
- package/dist/internal/collaboration/office-pdf-collaboration-conflicts.d.ts +2 -0
- package/dist/internal/collaboration/office-pdf-collaboration-model.d.ts +26 -0
- package/dist/internal/collaboration/office-pdf-collaboration-records.d.ts +21 -0
- package/dist/internal/collaboration/office-pdf-collaboration-types.d.ts +91 -0
- package/dist/internal/collaboration/office-pdf-collaboration-validation.d.ts +4 -0
- package/dist/internal/collaboration/office-pdf-collaboration.d.ts +35 -0
- package/dist/internal/collaboration/office-presentation-collaboration-model.d.ts +25 -0
- package/dist/internal/collaboration/office-presentation-collaboration-records.d.ts +22 -0
- package/dist/internal/collaboration/office-presentation-collaboration-validation.d.ts +4 -0
- package/dist/internal/collaboration/office-presentation-collaboration.d.ts +32 -0
- package/dist/internal/collaboration/office-spreadsheet-collaboration-cells.d.ts +13 -0
- package/dist/internal/collaboration/office-spreadsheet-collaboration-claims.d.ts +4 -0
- package/dist/internal/collaboration/office-spreadsheet-collaboration-conflicts.d.ts +2 -0
- package/dist/internal/collaboration/office-spreadsheet-collaboration-flat-json.d.ts +10 -0
- package/dist/internal/collaboration/office-spreadsheet-collaboration-model.d.ts +31 -0
- package/dist/internal/collaboration/office-spreadsheet-collaboration-records.d.ts +17 -0
- package/dist/internal/collaboration/office-spreadsheet-collaboration-validation.d.ts +4 -0
- package/dist/internal/collaboration/office-spreadsheet-collaboration.d.ts +32 -0
- package/dist/internal/design-system/primitives/navigation/tabs.d.ts +3 -1
- package/dist/internal/features/work/components/work-document-page-border.d.ts +6 -0
- package/dist/internal/features/work/editors/document-command-catalog.d.ts +536 -0
- package/dist/internal/features/work/editors/document-editor-focus.d.ts +1 -1
- package/dist/internal/features/work/editors/document-editor-support.d.ts +7 -3
- package/dist/internal/features/work/editors/document-editor.d.ts +8 -2
- package/dist/internal/features/work/editors/document-external-content.d.ts +14 -0
- package/dist/internal/features/work/editors/document-format-clipboard.d.ts +6 -0
- package/dist/internal/features/work/editors/document-format-tools.d.ts +4 -0
- package/dist/internal/features/work/editors/document-layout-panel.d.ts +4 -1
- package/dist/internal/features/work/editors/document-page-chrome-wps-shortcuts.d.ts +2 -0
- package/dist/internal/features/work/editors/document-page-layout-ribbon.d.ts +14 -0
- package/dist/internal/features/work/editors/document-page-stack.d.ts +10 -1
- package/dist/internal/features/work/editors/document-page-thumbnail.d.ts +2 -0
- package/dist/internal/features/work/editors/document-pagination-run-coordinator.d.ts +26 -0
- package/dist/internal/features/work/editors/document-picture-properties-dialog-model.d.ts +20 -1
- package/dist/internal/features/work/editors/document-review-navigation.d.ts +9 -0
- package/dist/internal/features/work/editors/document-statistics-dialog.d.ts +7 -0
- package/dist/internal/features/work/editors/document-status-bar.d.ts +2 -1
- package/dist/internal/features/work/editors/document-table-properties-dialog-model.d.ts +4 -1
- package/dist/internal/features/work/editors/document-toolbar.d.ts +19 -42
- package/dist/internal/features/work/editors/document-wps-shortcuts.d.ts +12 -0
- package/dist/internal/features/work/editors/document-zoom.d.ts +17 -0
- package/dist/internal/features/work/editors/markdown-editor-focus.d.ts +1 -1
- package/dist/internal/features/work/editors/markdown-editor.d.ts +5 -1
- package/dist/internal/features/work/editors/markdown-toolbar.d.ts +2 -1
- package/dist/internal/features/work/editors/office-collaboration-participants.d.ts +3 -0
- package/dist/internal/features/work/editors/office-collaboration-presence-context.d.ts +17 -0
- package/dist/internal/features/work/editors/office-collaboration-presence-ui.d.ts +25 -0
- package/dist/internal/features/work/editors/office-editor-focus-handoff.d.ts +27 -0
- package/dist/internal/features/work/editors/pdf-annotation-controller.d.ts +5 -0
- package/dist/internal/features/work/editors/pdf-collaboration-presence.d.ts +3 -0
- package/dist/internal/features/work/editors/pdf-collaboration-projection.d.ts +10 -0
- package/dist/internal/features/work/editors/pdf-evidence-contract.d.ts +36 -0
- package/dist/internal/features/work/editors/pdf-evidence-overlay.d.ts +37 -0
- package/dist/internal/features/work/editors/pdf-toolbar.d.ts +2 -1
- package/dist/internal/features/work/editors/pdf-viewer-controller.d.ts +7 -1
- package/dist/internal/features/work/editors/pdf-viewer.d.ts +11 -1
- package/dist/internal/features/work/editors/presentation-collaboration-presence.d.ts +5 -0
- package/dist/internal/features/work/editors/presentation-editor-focus.d.ts +3 -2
- package/dist/internal/features/work/editors/presentation-editor-types.d.ts +3 -0
- package/dist/internal/features/work/editors/presentation-editor.d.ts +1 -1
- package/dist/internal/features/work/editors/spreadsheet-auto-filter.d.ts +9 -0
- package/dist/internal/features/work/editors/spreadsheet-cell-clear.d.ts +3 -0
- package/dist/internal/features/work/editors/spreadsheet-cell-merge.d.ts +12 -0
- package/dist/internal/features/work/editors/spreadsheet-clipboard-shortcuts.d.ts +3 -7
- package/dist/internal/features/work/editors/spreadsheet-collaboration-presence.d.ts +9 -0
- package/dist/internal/features/work/editors/spreadsheet-command-catalog.d.ts +464 -0
- package/dist/internal/features/work/editors/spreadsheet-command-controller.d.ts +45 -9
- package/dist/internal/features/work/editors/spreadsheet-context-menu.d.ts +2 -0
- package/dist/internal/features/work/editors/spreadsheet-editor-ribbon.d.ts +9 -28
- package/dist/internal/features/work/editors/spreadsheet-editor.d.ts +8 -2
- package/dist/internal/features/work/editors/spreadsheet-format-painter.d.ts +27 -0
- package/dist/internal/features/work/editors/spreadsheet-freeze-panes.d.ts +14 -0
- package/dist/internal/features/work/editors/use-document-insert-commands.d.ts +3 -2
- package/dist/internal/features/work/editors/use-document-pagination.d.ts +6 -1
- package/dist/internal/features/work/editors/use-document-review-conflicts.d.ts +28 -0
- package/dist/internal/features/work/editors/use-spreadsheet-auto-filter.d.ts +21 -0
- package/dist/internal/features/work/editors/use-spreadsheet-collaboration.d.ts +27 -0
- package/dist/internal/features/work/editors/use-spreadsheet-format-painter.d.ts +18 -0
- package/dist/internal/features/work/editors/work-office-chrome.d.ts +22 -3
- package/dist/internal/features/work/editors/work-office-ribbon-overflow.d.ts +2 -0
- package/dist/internal/features/work/work-document-bookmark-references.d.ts +37 -0
- package/dist/internal/features/work/work-document-bookmarks.d.ts +29 -0
- package/dist/internal/features/work/work-document-caption-nodes.d.ts +4 -1
- package/dist/internal/features/work/work-document-comments.d.ts +1 -1
- package/dist/internal/features/work/work-document-equations.d.ts +513 -0
- package/dist/internal/features/work/work-document-extensions.d.ts +1 -0
- package/dist/internal/features/work/work-document-field-identity.d.ts +2 -0
- package/dist/internal/features/work/work-document-field-node.d.ts +2 -2
- package/dist/internal/features/work/work-document-fields.d.ts +7 -0
- package/dist/internal/features/work/work-document-image-identity.d.ts +30 -0
- package/dist/internal/features/work/work-document-image-layout.d.ts +46 -1
- package/dist/internal/features/work/work-document-image-wrap-contour.d.ts +16 -0
- package/dist/internal/features/work/work-document-incremental-layout.d.ts +2 -2
- package/dist/internal/features/work/work-document-model-codec.d.ts +4 -1
- package/dist/internal/features/work/work-document-note-integrity.d.ts +2 -0
- package/dist/internal/features/work/work-document-page-borders.d.ts +25 -0
- package/dist/internal/features/work/work-document-page-capture.d.ts +8 -0
- package/dist/internal/features/work/work-document-page-frames.d.ts +15 -0
- package/dist/internal/features/work/work-document-page-margins.d.ts +56 -0
- package/dist/internal/features/work/work-document-page-size.d.ts +47 -0
- package/dist/internal/features/work/work-document-pagination-measurement.d.ts +1 -2
- package/dist/internal/features/work/work-document-pagination-types.d.ts +7 -2
- package/dist/internal/features/work/work-document-pagination.d.ts +2 -2
- package/dist/internal/features/work/work-document-paragraph-borders.d.ts +32 -0
- package/dist/internal/features/work/work-document-paragraph-identity.d.ts +26 -0
- package/dist/internal/features/work/work-document-paragraph-shading.d.ts +18 -0
- package/dist/internal/features/work/work-document-review-conflicts.d.ts +35 -0
- package/dist/internal/features/work/work-document-section.d.ts +4 -0
- package/dist/internal/features/work/work-document-snapshot.d.ts +19 -0
- package/dist/internal/features/work/work-document-source.d.ts +23 -0
- package/dist/internal/features/work/work-document-table-column-widths.d.ts +7 -0
- package/dist/internal/features/work/work-document-table-property-changes.d.ts +3 -0
- package/dist/internal/features/work/work-document-table-row-identity.d.ts +15 -0
- package/dist/internal/features/work/work-document-table-sizing.d.ts +3 -0
- package/dist/internal/features/work/work-document-text-layout.d.ts +3 -1
- package/dist/internal/features/work/work-document-word-line-metrics.d.ts +2 -0
- package/dist/internal/features/work/work-docx-bookmark-diagnostics.d.ts +3 -0
- package/dist/internal/features/work/work-docx-bookmark-import.d.ts +24 -0
- package/dist/internal/features/work/work-docx-bookmarks.d.ts +17 -0
- package/dist/internal/features/work/work-docx-comment-durable-id-preservation.d.ts +2 -0
- package/dist/internal/features/work/work-docx-comment-export.d.ts +3 -0
- package/dist/internal/features/work/work-docx-comment-metadata.d.ts +2 -0
- package/dist/internal/features/work/work-docx-drawing-extension-preservation.d.ts +4 -0
- package/dist/internal/features/work/work-docx-equation-diagnostics.d.ts +3 -0
- package/dist/internal/features/work/work-docx-equation-export.d.ts +14 -0
- package/dist/internal/features/work/work-docx-equation-import.d.ts +30 -0
- package/dist/internal/features/work/work-docx-equation-story.d.ts +9 -0
- package/dist/internal/features/work/work-docx-export-formatting.d.ts +3 -1
- package/dist/internal/features/work/work-docx-export-image.d.ts +5 -1
- package/dist/internal/features/work/work-docx-export.d.ts +1 -1
- package/dist/internal/features/work/work-docx-field-instructions.d.ts +8 -0
- package/dist/internal/features/work/work-docx-font-table-preservation.d.ts +3 -0
- package/dist/internal/features/work/work-docx-ignorable-extension-preservation.d.ts +15 -0
- package/dist/internal/features/work/work-docx-image-crop.d.ts +12 -0
- package/dist/internal/features/work/work-docx-image-identity.d.ts +17 -0
- package/dist/internal/features/work/work-docx-image-layer.d.ts +12 -0
- package/dist/internal/features/work/work-docx-image-layout-import.d.ts +14 -2
- package/dist/internal/features/work/work-docx-image-wrap.d.ts +15 -0
- package/dist/internal/features/work/work-docx-import.d.ts +13 -3
- package/dist/internal/features/work/work-docx-list-export.d.ts +18 -0
- package/dist/internal/features/work/work-docx-list-import.d.ts +14 -0
- package/dist/internal/features/work/work-docx-note-comment-content-control-block-preservation.d.ts +18 -0
- package/dist/internal/features/work/work-docx-note-comment-content-control-model.d.ts +47 -0
- package/dist/internal/features/work/work-docx-note-comment-content-control-preservation.d.ts +4 -0
- package/dist/internal/features/work/work-docx-note-comment-content-control-properties.d.ts +17 -0
- package/dist/internal/features/work/work-docx-note-comment-content-control-table-model.d.ts +17 -0
- package/dist/internal/features/work/work-docx-note-comment-content-control-xml.d.ts +14 -0
- package/dist/internal/features/work/work-docx-note-comment-extension-preservation.d.ts +2 -0
- package/dist/internal/features/work/work-docx-note-comment-hyperlink-content.d.ts +40 -0
- package/dist/internal/features/work/work-docx-note-comment-hyperlink-preservation.d.ts +5 -0
- package/dist/internal/features/work/work-docx-note-comment-hyperlink-relationships.d.ts +35 -0
- package/dist/internal/features/work/work-docx-note-comment-identity.d.ts +15 -0
- package/dist/internal/features/work/work-docx-note-comment-run-preservation.d.ts +4 -0
- package/dist/internal/features/work/work-docx-note-comment-run-properties.d.ts +2 -0
- package/dist/internal/features/work/work-docx-note-image-import.d.ts +12 -0
- package/dist/internal/features/work/work-docx-note-image-relationships.d.ts +1 -0
- package/dist/internal/features/work/work-docx-numbering-extension-preservation.d.ts +6 -0
- package/dist/internal/features/work/work-docx-numbering.d.ts +1 -0
- package/dist/internal/features/work/work-docx-page-borders-diagnostics.d.ts +3 -0
- package/dist/internal/features/work/work-docx-page-borders-import.d.ts +10 -0
- package/dist/internal/features/work/work-docx-page-margins-diagnostics.d.ts +3 -0
- package/dist/internal/features/work/work-docx-page-margins-import.d.ts +18 -0
- package/dist/internal/features/work/work-docx-page-size-diagnostics.d.ts +2 -0
- package/dist/internal/features/work/work-docx-page-size-import.d.ts +17 -0
- package/dist/internal/features/work/work-docx-paragraph-borders-diagnostics.d.ts +3 -0
- package/dist/internal/features/work/work-docx-paragraph-borders-export.d.ts +18 -0
- package/dist/internal/features/work/work-docx-paragraph-borders-import.d.ts +24 -0
- package/dist/internal/features/work/work-docx-paragraph-default-collapsed.d.ts +19 -0
- package/dist/internal/features/work/work-docx-paragraph-extension-preservation.d.ts +2 -0
- package/dist/internal/features/work/work-docx-paragraph-identity-import.d.ts +10 -0
- package/dist/internal/features/work/work-docx-paragraph-identity.d.ts +18 -0
- package/dist/internal/features/work/work-docx-paragraph-pagination-import.d.ts +6 -1
- package/dist/internal/features/work/work-docx-paragraph-shading-diagnostics.d.ts +3 -0
- package/dist/internal/features/work/work-docx-paragraph-shading-export.d.ts +5 -0
- package/dist/internal/features/work/work-docx-paragraph-shading-import.d.ts +18 -0
- package/dist/internal/features/work/work-docx-run-formatting-import.d.ts +3 -0
- package/dist/internal/features/work/work-docx-settings-preservation.d.ts +10 -0
- package/dist/internal/features/work/work-docx-settings-xml.d.ts +16 -0
- package/dist/internal/features/work/work-docx-style-extension-preservation.d.ts +2 -0
- package/dist/internal/features/work/work-docx-table-cell-export.d.ts +2 -1
- package/dist/internal/features/work/work-docx-table-cell-import.d.ts +3 -0
- package/dist/internal/features/work/work-docx-table-extension-preservation.d.ts +2 -0
- package/dist/internal/features/work/work-docx-table-row-import.d.ts +2 -0
- package/dist/internal/features/work/work-docx-table-sizing-import.d.ts +1 -0
- package/dist/internal/features/work/work-docx-theme-reference.d.ts +23 -0
- package/dist/internal/features/work/work-docx-theme.d.ts +4 -1
- package/dist/internal/features/work/work-docx-twips.d.ts +12 -0
- package/dist/internal/features/work/work-file-contract.d.ts +1 -0
- package/dist/internal/features/work/work-file-io.d.ts +1 -1
- package/dist/internal/features/work/work-markdown-extensions.d.ts +4 -1
- package/dist/internal/features/work/work-ooxml-package-preservation.d.ts +12 -0
- package/dist/internal/features/work/work-ooxml-package-security.d.ts +6 -0
- package/dist/internal/features/work/work-ooxml-relationship-preservation.d.ts +10 -0
- package/dist/internal/features/work/work-ooxml-xml.d.ts +2 -0
- package/dist/internal/features/work/work-pdf-export.d.ts +10 -0
- package/dist/internal/features/work/work-repository.d.ts +2 -0
- package/dist/internal/features/work/work-types.d.ts +15 -2
- package/dist/internal/kernel/office-kernel-client-types.d.ts +1 -0
- package/dist/internal/kernel/office-kernel-protocol.d.ts +7 -0
- package/dist/internal/kernel/office-kernel-version.d.ts +1 -1
- package/dist/office-kernel.wasm +0 -0
- package/dist/office-kernel.worker.js +93 -41
- package/dist/react.d.ts +18 -12
- package/dist/react.js +1 -1
- package/dist/styles.css +1367 -16
- package/dist/vue.d.ts +48 -5
- package/dist/vue.js +42 -3
- package/dist/web-component.d.ts +24 -2
- package/dist/web-component.js +101 -2
- package/docs/latest/en/browser-editor-architecture.md +262 -47
- package/package.json +29 -4
- package/dist/0~152.js +0 -94
- package/dist/0~2582.js +0 -485
- package/dist/0~4750.js +0 -939
- package/dist/0~5861.js +0 -596
- package/dist/0~work-document-extensions.js +0 -3045
- package/dist/0~work-document-model-codec.js +0 -42
- package/dist/0~work-docx-bibliography.js +0 -347
- package/dist/0~work-docx-page-color.js +0 -42
- package/dist/2881.js +0 -1455
- package/dist/8728.js +0 -723
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import { generateHTML, getSchema } from "@tiptap/core";
|
|
2
|
-
import { DOMParser as model_DOMParser } from "@tiptap/pm/model";
|
|
3
|
-
import { createWorkDocumentModel, syncDocumentContentFromHtml, documentModelForContent, documentHtmlFingerprint } from "./2881.js";
|
|
4
|
-
import { createWorkDocumentExtensions } from "./0~work-document-extensions.js";
|
|
5
|
-
let schema = null;
|
|
6
|
-
let extensions = null;
|
|
7
|
-
function createWorkDocumentModelFromContent(content) {
|
|
8
|
-
const previous = content.model;
|
|
9
|
-
const synchronized = syncDocumentContentFromHtml(content, content.html);
|
|
10
|
-
const document = new DOMParser().parseFromString(synchronized.html, 'text/html');
|
|
11
|
-
schema ??= getSchema(documentExtensions());
|
|
12
|
-
const root = model_DOMParser.fromSchema(schema).parse(document.body).toJSON();
|
|
13
|
-
return {
|
|
14
|
-
...synchronized,
|
|
15
|
-
model: createWorkDocumentModel(synchronized.html, root, previous)
|
|
16
|
-
};
|
|
17
|
-
}
|
|
18
|
-
function materializeWorkDocumentContent(content) {
|
|
19
|
-
const model = documentModelForContent(content);
|
|
20
|
-
if (!model) return content;
|
|
21
|
-
let html;
|
|
22
|
-
try {
|
|
23
|
-
html = generateHTML(model.root, documentExtensions());
|
|
24
|
-
} catch (error) {
|
|
25
|
-
throw new Error('The structured document model cannot be serialized by this Office schema.', {
|
|
26
|
-
cause: error
|
|
27
|
-
});
|
|
28
|
-
}
|
|
29
|
-
const synchronized = syncDocumentContentFromHtml(content, html);
|
|
30
|
-
return {
|
|
31
|
-
...synchronized,
|
|
32
|
-
model: {
|
|
33
|
-
...model,
|
|
34
|
-
htmlFingerprint: documentHtmlFingerprint(synchronized.html)
|
|
35
|
-
}
|
|
36
|
-
};
|
|
37
|
-
}
|
|
38
|
-
function documentExtensions() {
|
|
39
|
-
extensions ??= createWorkDocumentExtensions();
|
|
40
|
-
return extensions;
|
|
41
|
-
}
|
|
42
|
-
export { createWorkDocumentModelFromContent, materializeWorkDocumentContent };
|
|
@@ -1,347 +0,0 @@
|
|
|
1
|
-
import jszip from "jszip";
|
|
2
|
-
import { directChild, directChildren, attribute, parseXml } from "./8715.js";
|
|
3
|
-
import { documentCitationStyle, createDocumentBibliography, documentCitationStyleDetails } from "./2881.js";
|
|
4
|
-
const BIBLIOGRAPHY_NAMESPACE = 'http://schemas.openxmlformats.org/officeDocument/2006/bibliography';
|
|
5
|
-
const CUSTOM_XML_NAMESPACE = 'http://schemas.openxmlformats.org/officeDocument/2006/customXml';
|
|
6
|
-
const OFFICE_RELATIONSHIPS_NAMESPACE = 'http://schemas.openxmlformats.org/officeDocument/2006/relationships';
|
|
7
|
-
const PACKAGE_RELATIONSHIPS_NAMESPACE = 'http://schemas.openxmlformats.org/package/2006/relationships';
|
|
8
|
-
const CONTENT_TYPES_NAMESPACE = 'http://schemas.openxmlformats.org/package/2006/content-types';
|
|
9
|
-
const CUSTOM_XML_RELATIONSHIP = `${OFFICE_RELATIONSHIPS_NAMESPACE}/customXml`;
|
|
10
|
-
const CUSTOM_XML_PROPS_RELATIONSHIP = `${OFFICE_RELATIONSHIPS_NAMESPACE}/customXmlProps`;
|
|
11
|
-
const CUSTOM_XML_PROPS_CONTENT_TYPE = 'application/vnd.openxmlformats-officedocument.customXmlProperties+xml';
|
|
12
|
-
const COMMON_SOURCE_TYPES = new Set([
|
|
13
|
-
'Book',
|
|
14
|
-
'BookSection',
|
|
15
|
-
'JournalArticle',
|
|
16
|
-
'ArticleInAPeriodical',
|
|
17
|
-
'ConferenceProceedings',
|
|
18
|
-
'Report',
|
|
19
|
-
'InternetSite',
|
|
20
|
-
'DocumentFromInternetSite',
|
|
21
|
-
'ElectronicSource',
|
|
22
|
-
'Misc'
|
|
23
|
-
]);
|
|
24
|
-
const RESERVED_FIELDS = new Set([
|
|
25
|
-
'Tag',
|
|
26
|
-
'SourceType',
|
|
27
|
-
'Guid',
|
|
28
|
-
'Author',
|
|
29
|
-
'Title',
|
|
30
|
-
'Year',
|
|
31
|
-
'Publisher',
|
|
32
|
-
'City',
|
|
33
|
-
'JournalName',
|
|
34
|
-
'Volume',
|
|
35
|
-
'Issue',
|
|
36
|
-
'Pages',
|
|
37
|
-
'URL',
|
|
38
|
-
'StandardNumber',
|
|
39
|
-
'ConferenceName',
|
|
40
|
-
'Institution'
|
|
41
|
-
]);
|
|
42
|
-
async function readDocxBibliography(archive) {
|
|
43
|
-
const paths = archive.paths('customXml/').filter((path)=>/^customXml\/item(?!Props)[^/]*\.xml$/i.test(path));
|
|
44
|
-
const sources = [];
|
|
45
|
-
const usedTags = new Set();
|
|
46
|
-
const duplicateTags = new Set();
|
|
47
|
-
const uncommonSourceTypes = new Set();
|
|
48
|
-
let sourcePartCount = 0;
|
|
49
|
-
let unreadablePartCount = 0;
|
|
50
|
-
let selectedStyle = '';
|
|
51
|
-
let styleName = '';
|
|
52
|
-
for (const path of paths)try {
|
|
53
|
-
const document = await archive.xml(path);
|
|
54
|
-
if ('Sources' !== document.documentElement.localName || document.documentElement.namespaceURI !== BIBLIOGRAPHY_NAMESPACE) continue;
|
|
55
|
-
sourcePartCount += 1;
|
|
56
|
-
selectedStyle ||= attribute(document.documentElement, 'SelectedStyle')?.trim() ?? '';
|
|
57
|
-
styleName ||= attribute(document.documentElement, 'StyleName')?.trim() ?? '';
|
|
58
|
-
for (const element of directChildren(document.documentElement, 'Source')){
|
|
59
|
-
const source = parseCitationSource(element, sources.length + 1);
|
|
60
|
-
if (usedTags.has(source.tag)) {
|
|
61
|
-
duplicateTags.add(source.tag);
|
|
62
|
-
source.tag = uniqueSourceTag(source.tag, usedTags);
|
|
63
|
-
}
|
|
64
|
-
usedTags.add(source.tag);
|
|
65
|
-
if (!COMMON_SOURCE_TYPES.has(source.sourceType)) uncommonSourceTypes.add(source.sourceType);
|
|
66
|
-
sources.push(source);
|
|
67
|
-
}
|
|
68
|
-
} catch {
|
|
69
|
-
unreadablePartCount += 1;
|
|
70
|
-
}
|
|
71
|
-
if (!sourcePartCount) return {
|
|
72
|
-
sourcePartCount,
|
|
73
|
-
unreadablePartCount,
|
|
74
|
-
duplicateTags: [],
|
|
75
|
-
uncommonSourceTypes: [],
|
|
76
|
-
uncommonStyle: void 0
|
|
77
|
-
};
|
|
78
|
-
const styleResult = bibliographyStyle(selectedStyle, styleName);
|
|
79
|
-
const style = styleResult.style;
|
|
80
|
-
return {
|
|
81
|
-
bibliography: {
|
|
82
|
-
...createDocumentBibliography(style),
|
|
83
|
-
selectedStyle: selectedStyle || documentCitationStyleDetails(style).selectedStyle,
|
|
84
|
-
styleName: styleName || documentCitationStyleDetails(style).name,
|
|
85
|
-
sources
|
|
86
|
-
},
|
|
87
|
-
sourcePartCount,
|
|
88
|
-
unreadablePartCount,
|
|
89
|
-
duplicateTags: Array.from(duplicateTags),
|
|
90
|
-
uncommonSourceTypes: Array.from(uncommonSourceTypes),
|
|
91
|
-
uncommonStyle: styleResult.recognized ? void 0 : styleName || selectedStyle
|
|
92
|
-
};
|
|
93
|
-
}
|
|
94
|
-
async function patchDocxBibliography(buffer, bibliography) {
|
|
95
|
-
if (!bibliography?.sources.length) return buffer;
|
|
96
|
-
const archive = await jszip.loadAsync(buffer);
|
|
97
|
-
const itemId = stableGuid(`bibliography:${bibliography.sources.map((source)=>source.tag).join('|')}`);
|
|
98
|
-
archive.file('customXml/item1.xml', serializeBibliographySources(bibliography));
|
|
99
|
-
archive.file('customXml/itemProps1.xml', serializeCustomXmlProperties(itemId));
|
|
100
|
-
archive.file('customXml/_rels/item1.xml.rels', serializeCustomXmlRelationships());
|
|
101
|
-
await upsertRelationship(archive, 'word/document.xml', CUSTOM_XML_RELATIONSHIP, '../customXml/item1.xml');
|
|
102
|
-
await upsertContentType(archive, '/customXml/itemProps1.xml', CUSTOM_XML_PROPS_CONTENT_TYPE);
|
|
103
|
-
return archive.generateAsync({
|
|
104
|
-
type: 'arraybuffer',
|
|
105
|
-
compression: 'DEFLATE'
|
|
106
|
-
});
|
|
107
|
-
}
|
|
108
|
-
function parseCitationSource(element, index) {
|
|
109
|
-
const simple = new Map(directChildren(element).filter((child)=>!child.children.length).map((child)=>[
|
|
110
|
-
child.localName,
|
|
111
|
-
child.textContent?.trim() ?? ''
|
|
112
|
-
]));
|
|
113
|
-
const tag = simple.get('Tag') || `Source${index}`;
|
|
114
|
-
const additionalFields = {};
|
|
115
|
-
for (const [name, value] of simple)if (!RESERVED_FIELDS.has(name) && value) additionalFields[name] = value;
|
|
116
|
-
return {
|
|
117
|
-
id: `docx-source-${safeIdPart(tag)}-${index}`,
|
|
118
|
-
tag,
|
|
119
|
-
sourceType: simple.get('SourceType') || 'Misc',
|
|
120
|
-
guid: simple.get('Guid') || void 0,
|
|
121
|
-
title: simple.get('Title') || '',
|
|
122
|
-
year: simple.get('Year') || void 0,
|
|
123
|
-
contributors: parseCitationContributors(directChild(element, 'Author')),
|
|
124
|
-
publisher: simple.get('Publisher') || void 0,
|
|
125
|
-
city: simple.get('City') || void 0,
|
|
126
|
-
journalName: simple.get('JournalName') || void 0,
|
|
127
|
-
volume: simple.get('Volume') || void 0,
|
|
128
|
-
issue: simple.get('Issue') || void 0,
|
|
129
|
-
pages: simple.get('Pages') || void 0,
|
|
130
|
-
url: simple.get('URL') || void 0,
|
|
131
|
-
standardNumber: simple.get('StandardNumber') || void 0,
|
|
132
|
-
conferenceName: simple.get('ConferenceName') || void 0,
|
|
133
|
-
institution: simple.get('Institution') || void 0,
|
|
134
|
-
additionalFields: Object.keys(additionalFields).length ? additionalFields : void 0
|
|
135
|
-
};
|
|
136
|
-
}
|
|
137
|
-
function parseCitationContributors(wrapper) {
|
|
138
|
-
if (!wrapper) return;
|
|
139
|
-
const roles = directChild(wrapper, 'NameList') || directChild(wrapper, 'Corporate') ? [
|
|
140
|
-
wrapper
|
|
141
|
-
] : directChildren(wrapper);
|
|
142
|
-
const contributors = {};
|
|
143
|
-
for (const role of roles){
|
|
144
|
-
const nameList = directChild(role, 'NameList');
|
|
145
|
-
const people = nameList ? directChildren(nameList, 'Person').map(parseCitationPerson).filter(validCitationPerson) : [];
|
|
146
|
-
const corporate = directChild(role, 'Corporate')?.textContent?.trim();
|
|
147
|
-
if (people.length || corporate) contributors[role === wrapper ? 'Author' : role.localName] = {
|
|
148
|
-
people: people.length ? people : void 0,
|
|
149
|
-
corporate: corporate || void 0
|
|
150
|
-
};
|
|
151
|
-
}
|
|
152
|
-
return Object.keys(contributors).length ? contributors : void 0;
|
|
153
|
-
}
|
|
154
|
-
function parseCitationPerson(element) {
|
|
155
|
-
return {
|
|
156
|
-
first: directChild(element, 'First')?.textContent?.trim() ?? '',
|
|
157
|
-
middle: directChild(element, 'Middle')?.textContent?.trim() || void 0,
|
|
158
|
-
last: directChild(element, 'Last')?.textContent?.trim() ?? '',
|
|
159
|
-
suffix: directChild(element, 'Suffix')?.textContent?.trim() || void 0
|
|
160
|
-
};
|
|
161
|
-
}
|
|
162
|
-
function validCitationPerson(person) {
|
|
163
|
-
return Boolean(person.first || person.middle || person.last || person.suffix);
|
|
164
|
-
}
|
|
165
|
-
function serializeBibliographySources(bibliography) {
|
|
166
|
-
const styleDetails = documentCitationStyleDetails(bibliography.style);
|
|
167
|
-
const document = parseXml(`<b:Sources xmlns:b="${BIBLIOGRAPHY_NAMESPACE}" xmlns="${BIBLIOGRAPHY_NAMESPACE}"/>`, 'DOCX bibliography sources');
|
|
168
|
-
const root = document.documentElement;
|
|
169
|
-
root.setAttribute('SelectedStyle', bibliography.selectedStyle || styleDetails.selectedStyle);
|
|
170
|
-
root.setAttribute('StyleName', bibliography.styleName || styleDetails.name);
|
|
171
|
-
root.setAttribute('Version', '6');
|
|
172
|
-
for (const source of bibliography.sources){
|
|
173
|
-
const element = bibliographyElement(document, 'Source');
|
|
174
|
-
appendTextElement(document, element, 'Tag', source.tag);
|
|
175
|
-
appendTextElement(document, element, 'SourceType', source.sourceType || 'Misc');
|
|
176
|
-
appendTextElement(document, element, 'Guid', normalizeGuid(source.guid) || stableGuid(`source:${source.id}:${source.tag}`));
|
|
177
|
-
appendContributors(document, element, source.contributors);
|
|
178
|
-
appendTextElement(document, element, 'Title', source.title);
|
|
179
|
-
appendTextElement(document, element, 'Year', source.year);
|
|
180
|
-
appendTextElement(document, element, 'Publisher', source.publisher);
|
|
181
|
-
appendTextElement(document, element, 'City', source.city);
|
|
182
|
-
appendTextElement(document, element, 'JournalName', source.journalName);
|
|
183
|
-
appendTextElement(document, element, 'Volume', source.volume);
|
|
184
|
-
appendTextElement(document, element, 'Issue', source.issue);
|
|
185
|
-
appendTextElement(document, element, 'Pages', source.pages);
|
|
186
|
-
appendTextElement(document, element, 'URL', source.url);
|
|
187
|
-
appendTextElement(document, element, 'StandardNumber', source.standardNumber);
|
|
188
|
-
appendTextElement(document, element, 'ConferenceName', source.conferenceName);
|
|
189
|
-
appendTextElement(document, element, 'Institution', source.institution);
|
|
190
|
-
for (const [name, value] of Object.entries(source.additionalFields ?? {}).sort(([left], [right])=>left.localeCompare(right)))if (!RESERVED_FIELDS.has(name) && /^[A-Za-z_][A-Za-z0-9_.-]*$/.test(name)) appendTextElement(document, element, name, value);
|
|
191
|
-
root.append(element);
|
|
192
|
-
}
|
|
193
|
-
return new XMLSerializer().serializeToString(document);
|
|
194
|
-
}
|
|
195
|
-
function appendContributors(document, source, contributors) {
|
|
196
|
-
const entries = Object.entries(contributors ?? {}).filter(([, contributor])=>contributor.people?.length || contributor.corporate?.trim());
|
|
197
|
-
if (!entries.length) return;
|
|
198
|
-
const wrapper = bibliographyElement(document, 'Author');
|
|
199
|
-
for (const [roleName, contributor] of entries){
|
|
200
|
-
if (!/^[A-Za-z_][A-Za-z0-9_.-]*$/.test(roleName)) continue;
|
|
201
|
-
const role = bibliographyElement(document, roleName);
|
|
202
|
-
if (contributor.people?.length) {
|
|
203
|
-
const nameList = bibliographyElement(document, 'NameList');
|
|
204
|
-
for (const person of contributor.people){
|
|
205
|
-
const element = bibliographyElement(document, 'Person');
|
|
206
|
-
appendTextElement(document, element, 'Last', person.last);
|
|
207
|
-
appendTextElement(document, element, 'First', person.first);
|
|
208
|
-
appendTextElement(document, element, 'Middle', person.middle);
|
|
209
|
-
appendTextElement(document, element, 'Suffix', person.suffix);
|
|
210
|
-
nameList.append(element);
|
|
211
|
-
}
|
|
212
|
-
role.append(nameList);
|
|
213
|
-
} else if (contributor.corporate?.trim()) appendTextElement(document, role, 'Corporate', contributor.corporate);
|
|
214
|
-
wrapper.append(role);
|
|
215
|
-
}
|
|
216
|
-
if (wrapper.children.length) source.append(wrapper);
|
|
217
|
-
}
|
|
218
|
-
function appendTextElement(document, parent, name, value) {
|
|
219
|
-
if (!value?.trim()) return;
|
|
220
|
-
const element = bibliographyElement(document, name);
|
|
221
|
-
element.textContent = value.trim();
|
|
222
|
-
parent.append(element);
|
|
223
|
-
}
|
|
224
|
-
function bibliographyElement(document, name) {
|
|
225
|
-
return document.createElementNS(BIBLIOGRAPHY_NAMESPACE, `b:${name}`);
|
|
226
|
-
}
|
|
227
|
-
function serializeCustomXmlProperties(itemId) {
|
|
228
|
-
const document = parseXml(`<ds:datastoreItem xmlns:ds="${CUSTOM_XML_NAMESPACE}" ds:itemID="${itemId}"/>`, 'DOCX custom XML properties');
|
|
229
|
-
const references = document.createElementNS(CUSTOM_XML_NAMESPACE, 'ds:schemaRefs');
|
|
230
|
-
const reference = document.createElementNS(CUSTOM_XML_NAMESPACE, 'ds:schemaRef');
|
|
231
|
-
reference.setAttributeNS(CUSTOM_XML_NAMESPACE, 'ds:uri', BIBLIOGRAPHY_NAMESPACE);
|
|
232
|
-
references.append(reference);
|
|
233
|
-
document.documentElement.append(references);
|
|
234
|
-
return new XMLSerializer().serializeToString(document);
|
|
235
|
-
}
|
|
236
|
-
function serializeCustomXmlRelationships() {
|
|
237
|
-
return [
|
|
238
|
-
`<Relationships xmlns="${PACKAGE_RELATIONSHIPS_NAMESPACE}">`,
|
|
239
|
-
`<Relationship Id="rId1" Type="${CUSTOM_XML_PROPS_RELATIONSHIP}" Target="itemProps1.xml"/>`,
|
|
240
|
-
'</Relationships>'
|
|
241
|
-
].join('');
|
|
242
|
-
}
|
|
243
|
-
async function upsertRelationship(archive, sourcePart, type, target) {
|
|
244
|
-
const path = relationshipPartPath(sourcePart);
|
|
245
|
-
const entry = archive.file(path);
|
|
246
|
-
const document = entry ? parseXml(await entry.async('text'), path) : parseXml(`<Relationships xmlns="${PACKAGE_RELATIONSHIPS_NAMESPACE}"/>`, path);
|
|
247
|
-
const root = document.documentElement;
|
|
248
|
-
const existing = directChildren(root, 'Relationship').find((item)=>attribute(item, 'Type') === type);
|
|
249
|
-
if (existing) existing.setAttribute('Target', target);
|
|
250
|
-
else {
|
|
251
|
-
const relationship = document.createElementNS(PACKAGE_RELATIONSHIPS_NAMESPACE, 'Relationship');
|
|
252
|
-
relationship.setAttribute('Id', nextRelationshipId(root));
|
|
253
|
-
relationship.setAttribute('Type', type);
|
|
254
|
-
relationship.setAttribute('Target', target);
|
|
255
|
-
root.append(relationship);
|
|
256
|
-
}
|
|
257
|
-
archive.file(path, new XMLSerializer().serializeToString(document));
|
|
258
|
-
}
|
|
259
|
-
async function upsertContentType(archive, partName, contentType) {
|
|
260
|
-
const path = '[Content_Types].xml';
|
|
261
|
-
const entry = archive.file(path);
|
|
262
|
-
if (!entry) throw new Error('DOCX content types part is missing.');
|
|
263
|
-
const document = parseXml(await entry.async('text'), path);
|
|
264
|
-
const existing = directChildren(document.documentElement, 'Override').find((item)=>attribute(item, 'PartName') === partName);
|
|
265
|
-
if (existing) existing.setAttribute('ContentType', contentType);
|
|
266
|
-
else {
|
|
267
|
-
const override = document.createElementNS(CONTENT_TYPES_NAMESPACE, 'Override');
|
|
268
|
-
override.setAttribute('PartName', partName);
|
|
269
|
-
override.setAttribute('ContentType', contentType);
|
|
270
|
-
document.documentElement.append(override);
|
|
271
|
-
}
|
|
272
|
-
archive.file(path, new XMLSerializer().serializeToString(document));
|
|
273
|
-
}
|
|
274
|
-
function bibliographyStyle(selectedStyle, styleName) {
|
|
275
|
-
const value = `${selectedStyle} ${styleName}`.toLowerCase();
|
|
276
|
-
if (value.includes('ieee')) return {
|
|
277
|
-
style: 'ieee',
|
|
278
|
-
recognized: true
|
|
279
|
-
};
|
|
280
|
-
if (value.includes('mla')) return {
|
|
281
|
-
style: 'mla',
|
|
282
|
-
recognized: true
|
|
283
|
-
};
|
|
284
|
-
if (value.includes('chicago')) return {
|
|
285
|
-
style: 'chicago',
|
|
286
|
-
recognized: true
|
|
287
|
-
};
|
|
288
|
-
if (!value.trim() || value.includes('apa')) return {
|
|
289
|
-
style: documentCitationStyle('apa'),
|
|
290
|
-
recognized: true
|
|
291
|
-
};
|
|
292
|
-
return {
|
|
293
|
-
style: documentCitationStyle('apa'),
|
|
294
|
-
recognized: false
|
|
295
|
-
};
|
|
296
|
-
}
|
|
297
|
-
function relationshipPartPath(sourcePart) {
|
|
298
|
-
const separator = sourcePart.lastIndexOf('/');
|
|
299
|
-
const directory = separator >= 0 ? sourcePart.slice(0, separator + 1) : '';
|
|
300
|
-
const fileName = separator >= 0 ? sourcePart.slice(separator + 1) : sourcePart;
|
|
301
|
-
return `${directory}_rels/${fileName}.rels`;
|
|
302
|
-
}
|
|
303
|
-
function nextRelationshipId(root) {
|
|
304
|
-
const used = new Set(directChildren(root, 'Relationship').map((item)=>attribute(item, 'Id') ?? ''));
|
|
305
|
-
let index = 1;
|
|
306
|
-
while(used.has(`rId${index}`))index += 1;
|
|
307
|
-
return `rId${index}`;
|
|
308
|
-
}
|
|
309
|
-
function uniqueSourceTag(base, used) {
|
|
310
|
-
let index = 2;
|
|
311
|
-
while(used.has(`${base}_${index}`))index += 1;
|
|
312
|
-
return `${base}_${index}`;
|
|
313
|
-
}
|
|
314
|
-
function safeIdPart(value) {
|
|
315
|
-
return value.replace(/[^a-z0-9_-]/gi, '-').replace(/-+/g, '-').replace(/^-|-$/g, '') || 'source';
|
|
316
|
-
}
|
|
317
|
-
function normalizeGuid(value) {
|
|
318
|
-
const match = /^\{?([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})\}?$/i.exec(value?.trim() ?? '');
|
|
319
|
-
return match ? `{${match[1].toUpperCase()}}` : '';
|
|
320
|
-
}
|
|
321
|
-
function stableGuid(source) {
|
|
322
|
-
const values = [
|
|
323
|
-
0,
|
|
324
|
-
1,
|
|
325
|
-
2,
|
|
326
|
-
3
|
|
327
|
-
].map((salt)=>stableHash(`${salt}:${source}`));
|
|
328
|
-
const hex = values.join('').slice(0, 32).split('');
|
|
329
|
-
hex[12] = '4';
|
|
330
|
-
hex[16] = [
|
|
331
|
-
'8',
|
|
332
|
-
'9',
|
|
333
|
-
'A',
|
|
334
|
-
'B'
|
|
335
|
-
][Number.parseInt(hex[16] ?? '0', 16) % 4];
|
|
336
|
-
const value = hex.join('').toUpperCase();
|
|
337
|
-
return `{${value.slice(0, 8)}-${value.slice(8, 12)}-${value.slice(12, 16)}-${value.slice(16, 20)}-${value.slice(20)}}`;
|
|
338
|
-
}
|
|
339
|
-
function stableHash(source) {
|
|
340
|
-
let hash = 2166136261;
|
|
341
|
-
for(let index = 0; index < source.length; index += 1){
|
|
342
|
-
hash ^= source.charCodeAt(index);
|
|
343
|
-
hash = Math.imul(hash, 16777619);
|
|
344
|
-
}
|
|
345
|
-
return (hash >>> 0).toString(16).padStart(8, '0');
|
|
346
|
-
}
|
|
347
|
-
export { patchDocxBibliography, readDocxBibliography };
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import jszip from "jszip";
|
|
2
|
-
import { directChild, xmlNamespacePrefix, attribute, parseXml } from "./8715.js";
|
|
3
|
-
import { DEFAULT_DOCUMENT_PAGE_COLOR, normalizeDocumentPageColor } from "./0~work-document-page-color.js";
|
|
4
|
-
const WORD_NAMESPACE = 'http://schemas.openxmlformats.org/wordprocessingml/2006/main';
|
|
5
|
-
function importDocxPageColor(document) {
|
|
6
|
-
const background = directChild(document.documentElement, 'background');
|
|
7
|
-
const color = attribute(background ?? document.documentElement, 'color');
|
|
8
|
-
if (!background || !color || 'auto' === color.toLowerCase()) return;
|
|
9
|
-
return normalizeDocumentPageColor(`#${color}`);
|
|
10
|
-
}
|
|
11
|
-
async function patchDocxPageColor(buffer, value) {
|
|
12
|
-
const pageColor = normalizeDocumentPageColor(value);
|
|
13
|
-
if (!pageColor || pageColor === DEFAULT_DOCUMENT_PAGE_COLOR) return buffer;
|
|
14
|
-
const archive = await jszip.loadAsync(buffer);
|
|
15
|
-
const documentEntry = archive.file('word/document.xml');
|
|
16
|
-
if (!documentEntry) return buffer;
|
|
17
|
-
const document = parseXml(await documentEntry.async('text'), 'word/document.xml');
|
|
18
|
-
upsertDocumentBackground(document, pageColor.slice(1).toUpperCase());
|
|
19
|
-
archive.file('word/document.xml', new XMLSerializer().serializeToString(document));
|
|
20
|
-
const settingsEntry = archive.file('word/settings.xml');
|
|
21
|
-
if (settingsEntry) {
|
|
22
|
-
const settings = parseXml(await settingsEntry.async('text'), 'word/settings.xml');
|
|
23
|
-
if (!directChild(settings.documentElement, 'displayBackgroundShape')) settings.documentElement.append(settings.createElementNS(WORD_NAMESPACE, wordQualifiedName(settings.documentElement, 'displayBackgroundShape')));
|
|
24
|
-
archive.file('word/settings.xml', new XMLSerializer().serializeToString(settings));
|
|
25
|
-
}
|
|
26
|
-
return archive.generateAsync({
|
|
27
|
-
type: 'arraybuffer'
|
|
28
|
-
});
|
|
29
|
-
}
|
|
30
|
-
function upsertDocumentBackground(document, color) {
|
|
31
|
-
const root = document.documentElement;
|
|
32
|
-
let background = directChild(root, 'background');
|
|
33
|
-
if (!background) {
|
|
34
|
-
background = document.createElementNS(WORD_NAMESPACE, wordQualifiedName(root, 'background'));
|
|
35
|
-
root.insertBefore(background, directChild(root, 'body') ?? root.firstChild);
|
|
36
|
-
}
|
|
37
|
-
background.setAttributeNS(WORD_NAMESPACE, wordQualifiedName(root, 'color'), color);
|
|
38
|
-
}
|
|
39
|
-
function wordQualifiedName(root, localName) {
|
|
40
|
-
return `${xmlNamespacePrefix(root, WORD_NAMESPACE) ?? root.prefix ?? 'w'}:${localName}`;
|
|
41
|
-
}
|
|
42
|
-
export { importDocxPageColor, patchDocxPageColor };
|