@a3s-lab/office 0.26.0 → 0.27.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/README.md +75 -2
- package/dist/0~4595.js +16 -2
- package/dist/0~5093.js +463 -201
- package/dist/0~6090.js +77 -77
- package/dist/{0~2805.js → 0~7043.js} +305 -2
- package/dist/0~document-editor.js +2451 -985
- package/dist/0~spreadsheet-editor.js +1324 -378
- package/dist/0~work-docx-export.js +492 -10
- package/dist/0~work-docx-import.js +171 -98
- package/dist/0~work-office-diagnostics.js +198 -4
- package/dist/{164.js → 1544.js} +1083 -785
- package/dist/4104.js +145 -29
- package/dist/6282.js +1774 -384
- package/dist/core.js +1 -1
- package/dist/index.js +1 -1
- package/dist/internal/features/work/editors/document-command-catalog.d.ts +102 -0
- package/dist/internal/features/work/editors/document-font-dialog-model.d.ts +83 -0
- package/dist/internal/features/work/editors/document-font-dialog-script-font-model.d.ts +18 -0
- package/dist/internal/features/work/editors/document-font-dialog.d.ts +9 -0
- package/dist/internal/features/work/editors/document-home-ribbon.d.ts +2 -1
- package/dist/internal/features/work/editors/document-page-chrome-editor.d.ts +6 -0
- package/dist/internal/features/work/editors/document-page-chrome-ribbon.d.ts +2 -1
- package/dist/internal/features/work/editors/document-strike-ribbon.d.ts +7 -0
- package/dist/internal/features/work/editors/document-text-case-ribbon.d.ts +4 -0
- package/dist/internal/features/work/editors/document-toolbar.d.ts +3 -1
- package/dist/internal/features/work/editors/document-underline-ribbon.d.ts +9 -0
- package/dist/internal/features/work/editors/document-wps-shortcuts.d.ts +1 -0
- package/dist/internal/features/work/editors/spreadsheet-cell-fill-format.d.ts +11 -0
- package/dist/internal/features/work/editors/spreadsheet-cell-format.d.ts +2 -1
- package/dist/internal/features/work/editors/spreadsheet-format-cells-dialog-model.d.ts +13 -2
- package/dist/internal/features/work/editors/spreadsheet-format-cells-fill-panel.d.ts +13 -0
- package/dist/internal/features/work/editors/spreadsheet-format-cells-fill-preview.d.ts +6 -0
- package/dist/internal/features/work/editors/spreadsheet-format-painter.d.ts +1 -1
- package/dist/internal/features/work/editors/work-office-chrome.d.ts +9 -1
- package/dist/internal/features/work/work-document-character-formatting.d.ts +16 -1
- package/dist/internal/features/work/work-document-character-position.d.ts +9 -0
- package/dist/internal/features/work/work-document-character-scale.d.ts +8 -0
- package/dist/internal/features/work/work-document-character-spacing.d.ts +8 -0
- package/dist/internal/features/work/work-document-emphasis.d.ts +7 -0
- package/dist/internal/features/work/work-document-equations.d.ts +2 -1
- package/dist/internal/features/work/work-document-format-changes.d.ts +16 -2
- package/dist/internal/features/work/work-document-hidden-text.d.ts +5 -0
- package/dist/internal/features/work/work-document-kerning.d.ts +10 -0
- package/dist/internal/features/work/work-document-script-font-extension.d.ts +2 -0
- package/dist/internal/features/work/work-document-script-fonts.d.ts +51 -0
- package/dist/internal/features/work/work-document-strike.d.ts +21 -0
- package/dist/internal/features/work/work-document-text-case.d.ts +10 -0
- package/dist/internal/features/work/work-document-underline.d.ts +37 -0
- package/dist/internal/features/work/work-document-word-line-metrics.d.ts +12 -0
- package/dist/internal/features/work/work-docx-character-position.d.ts +2 -0
- package/dist/internal/features/work/work-docx-character-scale.d.ts +2 -0
- package/dist/internal/features/work/work-docx-character-spacing.d.ts +4 -0
- package/dist/internal/features/work/work-docx-emphasis-diagnostics.d.ts +3 -0
- package/dist/internal/features/work/work-docx-emphasis.d.ts +14 -0
- package/dist/internal/features/work/work-docx-hidden-text-diagnostics.d.ts +3 -0
- package/dist/internal/features/work/work-docx-hidden-text-export.d.ts +16 -0
- package/dist/internal/features/work/work-docx-hidden-text.d.ts +11 -0
- package/dist/internal/features/work/work-docx-kerning-diagnostics.d.ts +3 -0
- package/dist/internal/features/work/work-docx-kerning.d.ts +14 -0
- package/dist/internal/features/work/work-docx-run-fonts-diagnostics.d.ts +3 -0
- package/dist/internal/features/work/work-docx-run-fonts-export.d.ts +14 -0
- package/dist/internal/features/work/work-docx-run-fonts.d.ts +13 -0
- package/dist/internal/features/work/work-docx-run-formatting-import.d.ts +23 -2
- package/dist/internal/features/work/work-docx-run-script-font-import.d.ts +9 -0
- package/dist/internal/features/work/work-docx-strike.d.ts +8 -0
- package/dist/internal/features/work/work-docx-theme-reference.d.ts +1 -1
- package/dist/internal/features/work/work-docx-twips.d.ts +6 -0
- package/dist/internal/features/work/work-docx-underline.d.ts +3 -0
- package/dist/internal/features/work/work-spreadsheet-gradient-fill-canvas.d.ts +10 -0
- package/dist/internal/features/work/work-spreadsheet-native-fill-canvas.d.ts +8 -0
- package/dist/internal/features/work/work-spreadsheet-pattern-fill-canvas.d.ts +8 -0
- package/dist/internal/features/work/work-xlsx-cell-style-origin.d.ts +2 -1
- package/dist/internal/features/work/work-xlsx-cell-style-writer.d.ts +3 -0
- package/dist/internal/features/work/work-xlsx-cell-styles.d.ts +4 -0
- package/dist/internal/features/work/work-xlsx-gradient-fill.d.ts +31 -0
- package/dist/internal/features/work/work-xlsx-native-fill.d.ts +17 -0
- package/dist/internal/features/work/work-xlsx-pattern-fill.d.ts +21 -0
- package/dist/office-kernel.wasm +0 -0
- package/dist/styles.css +770 -80
- package/docs/latest/en/browser-editor-architecture.md +10 -0
- package/package.json +32 -1
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import jszip from "jszip";
|
|
2
|
-
import { contentTypeForPart, directChildren, bytesToDataUrl, OoxmlPackage, firstDescendant, descendants, directChild, attribute } from "./5184.js";
|
|
3
|
-
import { normalizeDocumentBookmarkName,
|
|
4
|
-
import {
|
|
5
|
-
import { xmlAttributeLocalName,
|
|
2
|
+
import { contentTypeForPart, directChildren, bytesToDataUrl, OoxmlPackage, firstDescendant, descendants, directChild, attribute as work_ooxml_package_attribute } from "./5184.js";
|
|
3
|
+
import { normalizeDocumentBookmarkName, renderDocumentTableCellMarginOverrides, applyDocumentImageIdentityToElement, documentCharacterPositionDomAttributes, createDocumentImageIdentityRegistry, normalizeDocumentColumns, documentStrikeDomAttributes, normalizeDocumentImageWrapContour, DOCUMENT_TABLE_ROW_ID_ATTRIBUTE, normalizeDocumentBookmarksHtml, applyDocumentTableRowIdentityToElement, normalizeDocumentCaptionsHtml, documentCharacterSpacingDomAttributes, normalizeDocumentImageAlignment, normalizeDocumentParagraphId, applyDocumentImageLayerToElement, normalizeDocumentNotesHtml, normalizeDocumentBookmarkReferencesHtml, documentCitationTagsFromInstruction, applyDocumentImageWrapContourToElement, documentUnderlineDomAttributes, documentHiddenTextDomAttributes, normalizeDocumentPageChrome, normalizeDocumentImageLayoutOptions, applyDocumentImageCropToElement, documentPageMarginsForLayout, applyDocumentPageGeometry, createDocumentNoteElement, normalizeDocumentImageLayer, DOCUMENT_TABLE_ROW_TEXT_ID_ATTRIBUTE, documentBookmarkReferenceInstruction, documentInitialSectionLayout, normalizeDocumentFieldsHtml, documentCaptionLabel, documentTableBordersFromElement, isContourImageLayout, normalizeDocumentCitationsHtml, normalizeDocumentImageIdentity, normalizeDocumentImageWrapSide, applyDocumentParagraphIdentityToElement, documentKerningDomAttributes, docxDocumentFieldKind, serializeDocxThemeReference, renderDocumentTableBorders, docxBookmarkReferenceTarget, normalizeDocumentImagePosition, wrapsBesideImage, documentPageChromeLegacyFields, documentParagraphShadingDomAttributes, documentCharacterScaleDomAttributes, documentParagraphBordersDomAttributes, DEFAULT_DOCUMENT_TABLE_GEOMETRY, documentSectionDomAttributes, DEFAULT_DOCUMENT_TABLE_CELL_MARGINS, normalizeDocumentParagraphIdentity, documentPageMarginBody, normalizeDocumentTableRowIdentity, normalizeDocumentBookmarkNativeId, uniqueDocumentImageIdentity, applyDocumentTableGeometryToElement, normalizeDocumentImageCrop, documentContentLayoutProperties, documentEmphasisMarkDomAttributes } from "./6282.js";
|
|
4
|
+
import { markDocxRunFormattingIntoState, applyImportedDocxParagraphSpacingMarkers, hasImportedDocxParagraphDirectionMarkers, hasImportedDocxParagraphIndentMarkers, resolveDocxParagraphBordersForParagraph, applyImportedDocxParagraphShadingMarkers, markDocxParagraphSpacing, docxCaptionBookmark, docxFieldResultText, createDocxParagraphStyleResolver, docxTableCellStyleLayers, createImportedDocxRunFormattingMarkerState, parseDocxPaperSource, hasImportedDocxParagraphSpacingMarkers, docxTablePropertySources, parseDocxPageMargins, parseDirectDocxParagraphShading, markDocxPackageEquations, parseDocxPageGeometry, markDocxParagraphIndents, docxCaptionReferenceTarget, applyImportedDocxEquationMarkers, hasImportedDocxParagraphPaginationMarkers, createDocxTableStyleResolver, hasImportedDocxParagraphShadingMarkers, isDocxEquationLikeRoot, importedDocxStrike, docxTableRunPropertySources, inspectDocxPageMarginSettings, hasImportedDocxRunFormattingMarkers, applyImportedDocxParagraphFormattingChangeMarkers, hasImportedDocxParagraphTabStopMarkers, docxCaptionSequenceKind, applyImportedDocxRunFormattingMarkers, markDocxParagraphAlignments, markDocxParagraphDirections, hasImportedDocxParagraphBorderMarkers, hasImportedDocxParagraphFormattingChangeMarkers, resolveDocxHiddenText, docxEquationHtml, docxFieldOccurrences, hasImportedDocxParagraphAlignmentMarkers, markDocxParagraphTabStops, applyImportedDocxParagraphIndentMarkers, resolveDocxTableStyleResolver, applyImportedDocxParagraphDirectionMarkers, applyImportedDocxParagraphAlignmentMarkers, markDocxParagraphPagination, importedDocxUnderline, markDocxParagraphBorders, applyImportedDocxParagraphTabStopMarkers, docxFieldOccurrenceIsInlineEditable, applyImportedDocxParagraphBorderMarkers, applyImportedDocxParagraphPaginationMarkers, docxRunPropertySources, markDocxParagraphFormattingChanges, markDocxParagraphShading, parseDocxPageBorders } from "./0~5093.js";
|
|
5
|
+
import { readDocxBibliography, XMLNS_NAMESPACE, docxCharacterScalePercentFromProperties, docxCharacterSpacingTwipsFromProperties, parseBoundedDocxInteger, xmlAttributeLocalName, resolveDocxEmphasisMark, createDocxThemeResolver, docxCharacterPositionHalfPointsFromProperties, docxThemeColor, parseDocxParagraphDefaultCollapsed, resolveDocxKerningThresholdHalfPoints, resolveDocxThemeResolver, DOCX_WORDPROCESSING_NAMESPACES, xmlAttributeNamespace } from "./0~7043.js";
|
|
6
6
|
import { importDocxPageColor, importedDocumentNoteId } from "./0~4980.js";
|
|
7
7
|
const WORD_NAMESPACE = 'http://schemas.openxmlformats.org/wordprocessingml/2006/main';
|
|
8
8
|
const XML_NAMESPACE = 'http://www.w3.org/XML/1998/namespace';
|
|
@@ -10,7 +10,7 @@ const MAX_BOOKMARK_NAME_LENGTH = 40;
|
|
|
10
10
|
const MAX_BOOKMARK_NATIVE_ID = 0x7fffffff;
|
|
11
11
|
function markDocxBookmarks(document) {
|
|
12
12
|
const captionBookmarks = captionBookmarkStarts(document);
|
|
13
|
-
const captionNames = new Set(Array.from(captionBookmarks).map((bookmark)=>
|
|
13
|
+
const captionNames = new Set(Array.from(captionBookmarks).map((bookmark)=>work_ooxml_package_attribute(bookmark, 'name')?.trim().toLowerCase()).filter((name)=>Boolean(name)));
|
|
14
14
|
const pairs = docxBookmarkPairs(document).filter((pair)=>!captionBookmarks.has(pair.start) && '_GoBack' !== pair.sourceName);
|
|
15
15
|
const names = new Set();
|
|
16
16
|
const normalizedNames = new Map();
|
|
@@ -96,19 +96,19 @@ function docxBookmarkPairs(document) {
|
|
|
96
96
|
const pairs = [];
|
|
97
97
|
for (const element of Array.from(document.getElementsByTagName('*'))){
|
|
98
98
|
if ('bookmarkStart' === element.localName) {
|
|
99
|
-
const id =
|
|
99
|
+
const id = work_ooxml_package_attribute(element, 'id')?.trim() ?? '';
|
|
100
100
|
const stack = open.get(id) ?? [];
|
|
101
101
|
stack.push(element);
|
|
102
102
|
open.set(id, stack);
|
|
103
103
|
continue;
|
|
104
104
|
}
|
|
105
105
|
if ('bookmarkEnd' !== element.localName) continue;
|
|
106
|
-
const id =
|
|
106
|
+
const id = work_ooxml_package_attribute(element, 'id')?.trim() ?? '';
|
|
107
107
|
const start = open.get(id)?.pop();
|
|
108
108
|
if (start) pairs.push({
|
|
109
109
|
start,
|
|
110
110
|
end: element,
|
|
111
|
-
sourceName:
|
|
111
|
+
sourceName: work_ooxml_package_attribute(start, 'name')?.trim() ?? '',
|
|
112
112
|
sourceNativeId: id
|
|
113
113
|
});
|
|
114
114
|
}
|
|
@@ -287,7 +287,7 @@ function markDocxCaptionFields(document) {
|
|
|
287
287
|
})).find((item)=>Boolean(item.kind));
|
|
288
288
|
if (!sequence) continue;
|
|
289
289
|
const bookmark = docxCaptionBookmark(paragraph, sequence.field);
|
|
290
|
-
const bookmarkName =
|
|
290
|
+
const bookmarkName = work_ooxml_package_attribute(bookmark ?? paragraph, 'name')?.trim() ?? '';
|
|
291
291
|
const id = uniqueCaptionId(bookmarkName, sequence.kind, captions.length + 1, captions);
|
|
292
292
|
if (bookmarkName) bookmarkTargets.set(bookmarkName, id);
|
|
293
293
|
const marker = captionMarker(captions.length + 1, id, sequence.kind);
|
|
@@ -442,13 +442,13 @@ function markDocxTextChanges(document) {
|
|
|
442
442
|
if (!revisionText(revision, kind)) continue;
|
|
443
443
|
if ('deletion' === kind) convertDeletedText(document, revision);
|
|
444
444
|
const index = changes.length + 1;
|
|
445
|
-
const sourceId =
|
|
445
|
+
const sourceId = work_ooxml_package_attribute(revision, 'id')?.trim() ?? '';
|
|
446
446
|
const id = uniqueChangeId(sourceId ? `docx-change-${sourceId}` : `docx-change-${index}`, changes);
|
|
447
447
|
const marker = {
|
|
448
448
|
id,
|
|
449
449
|
kind,
|
|
450
|
-
author:
|
|
451
|
-
date: normalizeDate(
|
|
450
|
+
author: work_ooxml_package_attribute(revision, 'author')?.trim() || '未知审阅者',
|
|
451
|
+
date: normalizeDate(work_ooxml_package_attribute(revision, 'date')),
|
|
452
452
|
start: `__A3S_WORK_CHANGE_START_${index}__`,
|
|
453
453
|
end: `__A3S_WORK_CHANGE_END_${index}__`
|
|
454
454
|
};
|
|
@@ -712,7 +712,7 @@ function importDocxColumns(element, fallback) {
|
|
|
712
712
|
const columnElements = directChildren(element, 'col');
|
|
713
713
|
const sourceCount = numberAttribute(element, 'num') || columnElements.length || fallback.count;
|
|
714
714
|
const count = Math.min(6, Math.max(1, sourceCount));
|
|
715
|
-
const spacingAttribute =
|
|
715
|
+
const spacingAttribute = work_ooxml_package_attribute(element, 'space');
|
|
716
716
|
const spacing = null === spacingAttribute ? fallback.spacing : twipsToMillimeters(Number(spacingAttribute), fallback.spacing);
|
|
717
717
|
const base = {
|
|
718
718
|
count,
|
|
@@ -724,7 +724,7 @@ function importDocxColumns(element, fallback) {
|
|
|
724
724
|
...base,
|
|
725
725
|
count: Math.min(count, columnElements.length),
|
|
726
726
|
custom: columnElements.slice(0, count).map((column, index)=>{
|
|
727
|
-
const columnSpacing =
|
|
727
|
+
const columnSpacing = work_ooxml_package_attribute(column, 'space');
|
|
728
728
|
return {
|
|
729
729
|
widthPercent: Math.max(1, numberAttribute(column, 'w')),
|
|
730
730
|
spacing: index === Math.min(count, columnElements.length) - 1 ? 0 : null === columnSpacing ? spacing : twipsToMillimeters(Number(columnSpacing), spacing)
|
|
@@ -733,11 +733,11 @@ function importDocxColumns(element, fallback) {
|
|
|
733
733
|
});
|
|
734
734
|
}
|
|
735
735
|
function numberAttribute(element, name) {
|
|
736
|
-
const value = Number(
|
|
736
|
+
const value = Number(work_ooxml_package_attribute(element, name));
|
|
737
737
|
return Number.isFinite(value) ? value : 0;
|
|
738
738
|
}
|
|
739
739
|
function enabledAttribute(element, name) {
|
|
740
|
-
const value =
|
|
740
|
+
const value = work_ooxml_package_attribute(element, name)?.toLowerCase();
|
|
741
741
|
return '1' === value || 'true' === value || 'on' === value;
|
|
742
742
|
}
|
|
743
743
|
function twipsToMillimeters(value, fallback) {
|
|
@@ -763,9 +763,9 @@ async function markDocxComments(document, archive) {
|
|
|
763
763
|
const comments = [];
|
|
764
764
|
const starts = descendants(document, 'commentRangeStart').sort(work_docx_comment_import_compareDocumentOrder);
|
|
765
765
|
for (const start of starts){
|
|
766
|
-
const sourceId =
|
|
766
|
+
const sourceId = work_ooxml_package_attribute(start, 'id')?.trim() ?? '';
|
|
767
767
|
if (!sourceId) continue;
|
|
768
|
-
const end = descendants(document, 'commentRangeEnd').find((candidate)=>
|
|
768
|
+
const end = descendants(document, 'commentRangeEnd').find((candidate)=>work_ooxml_package_attribute(candidate, 'id') === sourceId && Boolean(start.compareDocumentPosition(candidate) & Node.DOCUMENT_POSITION_FOLLOWING));
|
|
769
769
|
if (!end?.parentNode || !start.parentNode) continue;
|
|
770
770
|
const workId = workIds.get(sourceId) ?? uniqueWorkCommentId(`docx-comment-${sourceId}`, comments);
|
|
771
771
|
if (!workIds.has(sourceId)) {
|
|
@@ -782,7 +782,7 @@ async function markDocxComments(document, archive) {
|
|
|
782
782
|
end.parentNode.insertBefore(work_docx_comment_import_markerRun(document, range.end), end.nextSibling);
|
|
783
783
|
start.remove();
|
|
784
784
|
end.remove();
|
|
785
|
-
for (const reference of descendants(document, 'commentReference').filter((candidate)=>
|
|
785
|
+
for (const reference of descendants(document, 'commentReference').filter((candidate)=>work_ooxml_package_attribute(candidate, 'id') === sourceId))reference.remove();
|
|
786
786
|
ranges.push(range);
|
|
787
787
|
}
|
|
788
788
|
return {
|
|
@@ -806,12 +806,12 @@ async function readCommentDefinitions(archive) {
|
|
|
806
806
|
const extended = await readCommentExtended(archive);
|
|
807
807
|
return descendants(document, 'comment').map((comment)=>{
|
|
808
808
|
const paragraphs = descendants(comment, 'p');
|
|
809
|
-
const paraId =
|
|
809
|
+
const paraId = work_ooxml_package_attribute(paragraphs.at(-1) ?? comment, 'paraId')?.trim() ?? '';
|
|
810
810
|
const metadata = extended.get(paraId);
|
|
811
811
|
return {
|
|
812
|
-
sourceId:
|
|
813
|
-
author:
|
|
814
|
-
date: work_docx_comment_import_normalizeDate(
|
|
812
|
+
sourceId: work_ooxml_package_attribute(comment, 'id')?.trim() ?? '',
|
|
813
|
+
author: work_ooxml_package_attribute(comment, 'author')?.trim() || '未知审阅者',
|
|
814
|
+
date: work_docx_comment_import_normalizeDate(work_ooxml_package_attribute(comment, 'date')),
|
|
815
815
|
text: commentText(comment),
|
|
816
816
|
paraId,
|
|
817
817
|
parentParaId: metadata?.parentParaId ?? '',
|
|
@@ -823,12 +823,12 @@ async function readCommentExtended(archive) {
|
|
|
823
823
|
if (!archive.has('word/commentsExtended.xml')) return new Map();
|
|
824
824
|
const document = await archive.xml('word/commentsExtended.xml');
|
|
825
825
|
return new Map(descendants(document, 'commentEx').map((comment)=>{
|
|
826
|
-
const paraId =
|
|
826
|
+
const paraId = work_ooxml_package_attribute(comment, 'paraId')?.trim() ?? '';
|
|
827
827
|
return [
|
|
828
828
|
paraId,
|
|
829
829
|
{
|
|
830
|
-
parentParaId:
|
|
831
|
-
resolved: '1' ===
|
|
830
|
+
parentParaId: work_ooxml_package_attribute(comment, 'paraIdParent')?.trim() ?? '',
|
|
831
|
+
resolved: '1' === work_ooxml_package_attribute(comment, 'done') || 'true' === work_ooxml_package_attribute(comment, 'done')
|
|
832
832
|
}
|
|
833
833
|
];
|
|
834
834
|
}).filter(([paraId])=>Boolean(paraId)));
|
|
@@ -1156,7 +1156,7 @@ function anchorWrapDistance(anchor, layout) {
|
|
|
1156
1156
|
return distance / EMUS_PER_MILLIMETER;
|
|
1157
1157
|
}
|
|
1158
1158
|
function anchorWrapSide(anchor, layout) {
|
|
1159
|
-
return normalizeDocumentImageWrapSide(
|
|
1159
|
+
return normalizeDocumentImageWrapSide(work_ooxml_package_attribute(anchorWrapElement(anchor, layout) ?? anchor, 'wrapText'));
|
|
1160
1160
|
}
|
|
1161
1161
|
function anchorWrapElement(anchor, layout) {
|
|
1162
1162
|
if ('square' === layout) return directChild(anchor, 'wrapSquare');
|
|
@@ -1172,10 +1172,10 @@ function anchorWrapContour(anchor, layout) {
|
|
|
1172
1172
|
const vertices = directChildren(polygon);
|
|
1173
1173
|
if (vertices[0]?.localName !== 'start' || vertices.slice(1).some((element)=>'lineTo' !== element.localName)) return null;
|
|
1174
1174
|
return normalizeDocumentImageWrapContour({
|
|
1175
|
-
edited:
|
|
1175
|
+
edited: work_ooxml_package_attribute(polygon, 'edited'),
|
|
1176
1176
|
points: vertices.map((point)=>({
|
|
1177
|
-
x:
|
|
1178
|
-
y:
|
|
1177
|
+
x: work_ooxml_package_attribute(point, 'x'),
|
|
1178
|
+
y: work_ooxml_package_attribute(point, 'y')
|
|
1179
1179
|
}))
|
|
1180
1180
|
});
|
|
1181
1181
|
}
|
|
@@ -1188,8 +1188,8 @@ function anchorPosition(anchor) {
|
|
|
1188
1188
|
return normalizeDocumentImagePosition({
|
|
1189
1189
|
horizontalOffset,
|
|
1190
1190
|
verticalOffset,
|
|
1191
|
-
horizontalReference: horizontal ?
|
|
1192
|
-
verticalReference: vertical ?
|
|
1191
|
+
horizontalReference: horizontal ? work_ooxml_package_attribute(horizontal, 'relativeFrom') : null,
|
|
1192
|
+
verticalReference: vertical ? work_ooxml_package_attribute(vertical, 'relativeFrom') : null
|
|
1193
1193
|
});
|
|
1194
1194
|
}
|
|
1195
1195
|
function anchorCrop(anchor) {
|
|
@@ -1204,7 +1204,7 @@ function anchorCrop(anchor) {
|
|
|
1204
1204
|
}
|
|
1205
1205
|
function anchorLayer(anchor) {
|
|
1206
1206
|
return normalizeDocumentImageLayer({
|
|
1207
|
-
relativeHeight:
|
|
1207
|
+
relativeHeight: work_ooxml_package_attribute(anchor, 'relativeHeight'),
|
|
1208
1208
|
behindDocument: anchorBooleanAttribute(anchor, 'behindDoc', false),
|
|
1209
1209
|
allowOverlap: anchorBooleanAttribute(anchor, 'allowOverlap', false),
|
|
1210
1210
|
layoutInCell: anchorBooleanAttribute(anchor, 'layoutInCell', true),
|
|
@@ -1214,13 +1214,13 @@ function anchorLayer(anchor) {
|
|
|
1214
1214
|
function drawingIdentitySource(anchor) {
|
|
1215
1215
|
const properties = directChild(anchor, 'docPr');
|
|
1216
1216
|
return {
|
|
1217
|
-
docPropertiesId: properties ?
|
|
1218
|
-
anchorId:
|
|
1219
|
-
editId:
|
|
1217
|
+
docPropertiesId: properties ? work_ooxml_package_attribute(properties, 'id') : null,
|
|
1218
|
+
anchorId: work_ooxml_package_attribute(anchor, 'anchorId'),
|
|
1219
|
+
editId: work_ooxml_package_attribute(anchor, 'editId')
|
|
1220
1220
|
};
|
|
1221
1221
|
}
|
|
1222
1222
|
function cropPercentage(source, name) {
|
|
1223
|
-
const value =
|
|
1223
|
+
const value = work_ooxml_package_attribute(source, name)?.trim() ?? '';
|
|
1224
1224
|
if (!value) return 0;
|
|
1225
1225
|
const number = Number(value.endsWith('%') ? value.slice(0, -1) : value);
|
|
1226
1226
|
if (!Number.isFinite(number)) return 0;
|
|
@@ -1267,14 +1267,14 @@ function applyImageLayout(image, options, position, crop, contour, layer, identi
|
|
|
1267
1267
|
if (layer) applyDocumentImageLayerToElement(image, layer);
|
|
1268
1268
|
}
|
|
1269
1269
|
function anchorBooleanAttribute(element, name, fallback) {
|
|
1270
|
-
const value =
|
|
1270
|
+
const value = work_ooxml_package_attribute(element, name)?.trim().toLowerCase();
|
|
1271
1271
|
if ('1' === value || 'true' === value || 'on' === value) return true;
|
|
1272
1272
|
if ('0' === value || 'false' === value || 'off' === value) return false;
|
|
1273
1273
|
return fallback;
|
|
1274
1274
|
}
|
|
1275
1275
|
function numericAttribute(element, name) {
|
|
1276
1276
|
if (!element) return null;
|
|
1277
|
-
const source =
|
|
1277
|
+
const source = work_ooxml_package_attribute(element, name);
|
|
1278
1278
|
if (null === source || !source.trim()) return null;
|
|
1279
1279
|
const value = Number(source);
|
|
1280
1280
|
return Number.isFinite(value) && value >= 0 ? value : null;
|
|
@@ -1486,14 +1486,14 @@ function insertParagraphMarker(document, paragraph, marker) {
|
|
|
1486
1486
|
}
|
|
1487
1487
|
function integerAttribute(element, name) {
|
|
1488
1488
|
if (!element) return null;
|
|
1489
|
-
const source =
|
|
1489
|
+
const source = work_ooxml_package_attribute(element, name) ?? (name.includes(':') ? null : work_ooxml_package_attribute(element, `w:${name}`));
|
|
1490
1490
|
if (null === source) return null;
|
|
1491
1491
|
const value = Number(source);
|
|
1492
1492
|
return Number.isSafeInteger(value) && value >= 0 ? value : null;
|
|
1493
1493
|
}
|
|
1494
1494
|
function signedIntegerAttribute(element, name) {
|
|
1495
1495
|
if (!element) return null;
|
|
1496
|
-
const source =
|
|
1496
|
+
const source = work_ooxml_package_attribute(element, name) ?? (name.includes(':') ? null : work_ooxml_package_attribute(element, `w:${name}`));
|
|
1497
1497
|
if (null === source) return null;
|
|
1498
1498
|
const value = Number(source);
|
|
1499
1499
|
return Number.isSafeInteger(value) ? value : null;
|
|
@@ -1503,12 +1503,12 @@ function setOptionalDataset(element, key, value) {
|
|
|
1503
1503
|
}
|
|
1504
1504
|
function stringAttribute(element, name) {
|
|
1505
1505
|
if (!element) return null;
|
|
1506
|
-
const value =
|
|
1506
|
+
const value = work_ooxml_package_attribute(element, name) ?? (name.includes(':') ? null : work_ooxml_package_attribute(element, `w:${name}`));
|
|
1507
1507
|
return value?.trim() || null;
|
|
1508
1508
|
}
|
|
1509
1509
|
function rawStringAttribute(element, name) {
|
|
1510
1510
|
if (!element) return null;
|
|
1511
|
-
return
|
|
1511
|
+
return work_ooxml_package_attribute(element, name) ?? (name.includes(':') ? null : work_ooxml_package_attribute(element, `w:${name}`));
|
|
1512
1512
|
}
|
|
1513
1513
|
function work_docx_list_import_textNodes(root) {
|
|
1514
1514
|
const document = root.ownerDocument;
|
|
@@ -1658,8 +1658,8 @@ async function importVariant(section, variant, archive, documentRelationships, f
|
|
|
1658
1658
|
};
|
|
1659
1659
|
}
|
|
1660
1660
|
async function importReferencedPart(section, referenceName, variant, archive, documentRelationships) {
|
|
1661
|
-
const reference = directChildren(section, referenceName).find((element)=>(
|
|
1662
|
-
const relationship = documentRelationships.get(
|
|
1661
|
+
const reference = directChildren(section, referenceName).find((element)=>(work_ooxml_package_attribute(element, 'type') ?? 'default') === variant);
|
|
1662
|
+
const relationship = documentRelationships.get(work_ooxml_package_attribute(reference ?? section, 'r:id') ?? '');
|
|
1663
1663
|
if (!relationship || 'External' === relationship.targetMode || !archive.has(relationship.target)) return null;
|
|
1664
1664
|
const document = await archive.xml(relationship.target);
|
|
1665
1665
|
return {
|
|
@@ -1687,7 +1687,15 @@ async function pageChromePartHtml(document, archive, partPath) {
|
|
|
1687
1687
|
}
|
|
1688
1688
|
async function paragraphHtml(paragraph, archive, relationships, theme, paragraphStyles, tableStyles) {
|
|
1689
1689
|
const properties = directChild(paragraph, 'pPr');
|
|
1690
|
-
const
|
|
1690
|
+
const runContext = {
|
|
1691
|
+
archive,
|
|
1692
|
+
relationships,
|
|
1693
|
+
theme,
|
|
1694
|
+
paragraphProperties: properties,
|
|
1695
|
+
paragraphStyles,
|
|
1696
|
+
tableStyles
|
|
1697
|
+
};
|
|
1698
|
+
const alignmentValue = work_ooxml_package_attribute(firstDescendant(properties, 'jc') ?? paragraph, 'val');
|
|
1691
1699
|
const alignment = 'center' === alignmentValue ? 'center' : 'right' === alignmentValue || 'end' === alignmentValue ? 'right' : 'both' === alignmentValue || 'distribute' === alignmentValue ? 'justify' : 'left' === alignmentValue || 'start' === alignmentValue ? 'left' : '';
|
|
1692
1700
|
const field = {
|
|
1693
1701
|
active: false,
|
|
@@ -1702,19 +1710,19 @@ async function paragraphHtml(paragraph, archive, relationships, theme, paragraph
|
|
|
1702
1710
|
continue;
|
|
1703
1711
|
}
|
|
1704
1712
|
if ('hyperlink' === child.localName) {
|
|
1705
|
-
const content = await containerRunsHtml(child, field,
|
|
1706
|
-
const relationship = relationships.get(
|
|
1707
|
-
const anchor =
|
|
1713
|
+
const content = await containerRunsHtml(child, field, runContext);
|
|
1714
|
+
const relationship = relationships.get(work_ooxml_package_attribute(child, 'r:id') ?? '');
|
|
1715
|
+
const anchor = work_ooxml_package_attribute(child, 'anchor');
|
|
1708
1716
|
const href = relationship?.targetMode === 'External' ? relationship.target : anchor ? `#${anchor}` : '';
|
|
1709
1717
|
html += href ? `<a href="${escapeHtml(href)}">${content}</a>` : content;
|
|
1710
1718
|
continue;
|
|
1711
1719
|
}
|
|
1712
1720
|
if ('fldSimple' === child.localName) {
|
|
1713
|
-
const instruction =
|
|
1714
|
-
if (!/\bPAGE\b/i.test(instruction)) html += await containerRunsHtml(child, field,
|
|
1721
|
+
const instruction = work_ooxml_package_attribute(child, 'instr') ?? '';
|
|
1722
|
+
if (!/\bPAGE\b/i.test(instruction)) html += await containerRunsHtml(child, field, runContext);
|
|
1715
1723
|
continue;
|
|
1716
1724
|
}
|
|
1717
|
-
html += await containerRunsHtml(child, field,
|
|
1725
|
+
html += await containerRunsHtml(child, field, runContext);
|
|
1718
1726
|
}
|
|
1719
1727
|
const identityAttributes = paragraphIdentityAttributes(paragraph);
|
|
1720
1728
|
const defaultCollapsed = properties ? parseDocxParagraphDefaultCollapsed(properties) : {
|
|
@@ -1744,23 +1752,23 @@ function paragraphIdentityAttributes(paragraph) {
|
|
|
1744
1752
|
});
|
|
1745
1753
|
return identity ? ` data-office-paragraph-id="${identity.paragraphId}" data-office-paragraph-text-id="${identity.textId}"` : '';
|
|
1746
1754
|
}
|
|
1747
|
-
async function containerRunsHtml(container, field,
|
|
1748
|
-
if ('r' === container.localName) return runHtml(container, field,
|
|
1755
|
+
async function containerRunsHtml(container, field, context) {
|
|
1756
|
+
if ('r' === container.localName) return runHtml(container, field, context);
|
|
1749
1757
|
let html = '';
|
|
1750
1758
|
for (const child of directChildren(container)){
|
|
1751
1759
|
if (isDocxEquationLikeRoot(child)) {
|
|
1752
1760
|
html += docxEquationHtml(child);
|
|
1753
1761
|
continue;
|
|
1754
1762
|
}
|
|
1755
|
-
html += await containerRunsHtml(child, field,
|
|
1763
|
+
html += await containerRunsHtml(child, field, context);
|
|
1756
1764
|
}
|
|
1757
1765
|
return html;
|
|
1758
1766
|
}
|
|
1759
|
-
async function runHtml(run, field,
|
|
1767
|
+
async function runHtml(run, field, context) {
|
|
1760
1768
|
let content = '';
|
|
1761
1769
|
for (const child of directChildren(run)){
|
|
1762
1770
|
if ('fldChar' === child.localName) {
|
|
1763
|
-
updateFieldState(field,
|
|
1771
|
+
updateFieldState(field, work_ooxml_package_attribute(child, 'fldCharType'));
|
|
1764
1772
|
continue;
|
|
1765
1773
|
}
|
|
1766
1774
|
if ('instrText' === child.localName) {
|
|
@@ -1775,30 +1783,60 @@ async function runHtml(run, field, archive, relationships) {
|
|
|
1775
1783
|
if ('t' === child.localName) content += escapeHtml(child.textContent ?? '');
|
|
1776
1784
|
if ('tab' === child.localName) content += '	';
|
|
1777
1785
|
if ('br' === child.localName || 'cr' === child.localName) content += '<br>';
|
|
1778
|
-
if ('drawing' === child.localName) content += await drawingHtml(child, archive, relationships);
|
|
1786
|
+
if ('drawing' === child.localName) content += await drawingHtml(child, context.archive, context.relationships);
|
|
1779
1787
|
}
|
|
1780
1788
|
}
|
|
1781
1789
|
if (!content) return '';
|
|
1782
1790
|
const properties = directChild(run, 'rPr');
|
|
1791
|
+
const propertySources = docxRunPropertySources(context.paragraphProperties, properties, context.paragraphStyles, docxTableRunPropertySources(run, context.tableStyles));
|
|
1783
1792
|
if (enabledElement(directChild(properties ?? run, 'b'))) content = `<strong>${content}</strong>`;
|
|
1784
1793
|
if (enabledElement(directChild(properties ?? run, 'i'))) content = `<em>${content}</em>`;
|
|
1785
1794
|
const underline = directChild(properties ?? run, 'u');
|
|
1786
|
-
if (underline
|
|
1787
|
-
|
|
1788
|
-
|
|
1795
|
+
if (underline) {
|
|
1796
|
+
const attributes = documentUnderlineDomAttributes(importedDocxUnderline(underline, context.theme));
|
|
1797
|
+
content = `<u${htmlAttributes(attributes)}>${content}</u>`;
|
|
1798
|
+
}
|
|
1799
|
+
const strike = importedDocxStrike(properties ?? run);
|
|
1800
|
+
if (strike) content = `<s${htmlAttributes(documentStrikeDomAttributes(strike))}>${content}</s>`;
|
|
1801
|
+
const verticalAlign = work_ooxml_package_attribute(directChild(properties ?? run, 'vertAlign') ?? run, 'val');
|
|
1789
1802
|
if ("superscript" === verticalAlign) content = `<sup>${content}</sup>`;
|
|
1790
1803
|
if ("subscript" === verticalAlign) content = `<sub>${content}</sub>`;
|
|
1791
|
-
const
|
|
1804
|
+
const characterScale = docxCharacterScalePercentFromProperties(properties ?? run);
|
|
1805
|
+
if (void 0 !== characterScale) content = `<span${htmlAttributes(documentCharacterScaleDomAttributes(characterScale))}>${content}</span>`;
|
|
1806
|
+
const fontSize = resolveDocxPageChromeFontSizePoints(propertySources);
|
|
1807
|
+
const kerningThreshold = resolveDocxKerningThresholdHalfPoints(propertySources);
|
|
1808
|
+
if (void 0 !== fontSize || void 0 !== kerningThreshold) {
|
|
1809
|
+
const attributes = void 0 === kerningThreshold ? {} : documentKerningDomAttributes(kerningThreshold, fontSize);
|
|
1810
|
+
const styles = [
|
|
1811
|
+
void 0 === fontSize ? '' : `font-size: ${work_docx_page_chrome_import_formatNumber(fontSize)}pt`,
|
|
1812
|
+
attributes.style ?? ''
|
|
1813
|
+
].filter(Boolean);
|
|
1814
|
+
content = `<span${htmlAttributes({
|
|
1815
|
+
...attributes,
|
|
1816
|
+
...styles.length ? {
|
|
1817
|
+
style: styles.join('; ')
|
|
1818
|
+
} : {}
|
|
1819
|
+
})}>${content}</span>`;
|
|
1820
|
+
}
|
|
1821
|
+
const characterPosition = docxCharacterPositionHalfPointsFromProperties(properties ?? run);
|
|
1822
|
+
if (void 0 !== characterPosition) content = `<span${htmlAttributes(documentCharacterPositionDomAttributes(characterPosition))}>${content}</span>`;
|
|
1823
|
+
const emphasisMark = resolveDocxEmphasisMark(propertySources);
|
|
1824
|
+
if (void 0 !== emphasisMark) content = `<span${htmlAttributes(documentEmphasisMarkDomAttributes(emphasisMark))}>${content}</span>`;
|
|
1825
|
+
const hiddenText = resolveDocxHiddenText(propertySources);
|
|
1826
|
+
if (void 0 !== hiddenText) content = `<span${htmlAttributes(documentHiddenTextDomAttributes(hiddenText))}>${content}</span>`;
|
|
1827
|
+
const characterSpacing = docxCharacterSpacingTwipsFromProperties(properties ?? run);
|
|
1828
|
+
if (void 0 !== characterSpacing) content = `<span${htmlAttributes(documentCharacterSpacingDomAttributes(characterSpacing))}>${content}</span>`;
|
|
1829
|
+
const color = work_ooxml_package_attribute(directChild(properties ?? run, 'color') ?? run, 'val');
|
|
1792
1830
|
if (color && /^[0-9a-f]{6}$/i.test(color)) content = `<span style="color: #${color}">${content}</span>`;
|
|
1793
1831
|
return content;
|
|
1794
1832
|
}
|
|
1795
1833
|
async function drawingHtml(drawing, archive, relationships) {
|
|
1796
|
-
const relationship = relationships.get(
|
|
1834
|
+
const relationship = relationships.get(work_ooxml_package_attribute(firstDescendant(drawing, 'blip') ?? drawing, 'embed') ?? '');
|
|
1797
1835
|
if (!relationship || 'External' === relationship.targetMode || !archive.has(relationship.target)) return '';
|
|
1798
1836
|
const source = bytesToDataUrl(await archive.bytes(relationship.target), contentTypeForPart(relationship.target));
|
|
1799
1837
|
const extent = firstDescendant(drawing, 'extent');
|
|
1800
|
-
const width = Math.max(1, Math.round(Number(
|
|
1801
|
-
const height = Math.max(1, Math.round(Number(
|
|
1838
|
+
const width = Math.max(1, Math.round(Number(work_ooxml_package_attribute(extent ?? drawing, 'cx')) / 9525));
|
|
1839
|
+
const height = Math.max(1, Math.round(Number(work_ooxml_package_attribute(extent ?? drawing, 'cy')) / 9525));
|
|
1802
1840
|
const identityAttributes = drawingIdentityAttributes(drawing);
|
|
1803
1841
|
return `<img src="${source}" alt="Header or footer image"${width > 1 ? ` width="${width}"` : ''}${height > 1 ? ` height="${height}"` : ''}${identityAttributes}>`;
|
|
1804
1842
|
}
|
|
@@ -1842,19 +1880,48 @@ function tableRowIdentityAttributes(row) {
|
|
|
1842
1880
|
return identity ? ` ${DOCUMENT_TABLE_ROW_ID_ATTRIBUTE}="${identity.rowId}" ${DOCUMENT_TABLE_ROW_TEXT_ID_ATTRIBUTE}="${identity.rowTextId}"` : '';
|
|
1843
1881
|
}
|
|
1844
1882
|
function containsPageNumber(document) {
|
|
1845
|
-
return descendants(document, 'instrText').some((element)=>/\bPAGE\b/i.test(element.textContent ?? '')) || descendants(document, 'fldSimple').some((element)=>/\bPAGE\b/i.test(
|
|
1883
|
+
return descendants(document, 'instrText').some((element)=>/\bPAGE\b/i.test(element.textContent ?? '')) || descendants(document, 'fldSimple').some((element)=>/\bPAGE\b/i.test(work_ooxml_package_attribute(element, 'instr') ?? ''));
|
|
1846
1884
|
}
|
|
1847
1885
|
function hasVariantReference(section, variant) {
|
|
1848
1886
|
return [
|
|
1849
1887
|
...directChildren(section, 'headerReference'),
|
|
1850
1888
|
...directChildren(section, 'footerReference')
|
|
1851
|
-
].some((element)=>(
|
|
1889
|
+
].some((element)=>(work_ooxml_package_attribute(element, 'type') ?? 'default') === variant);
|
|
1852
1890
|
}
|
|
1853
1891
|
function enabledElement(element) {
|
|
1854
1892
|
if (!element) return false;
|
|
1855
|
-
const value =
|
|
1893
|
+
const value = work_ooxml_package_attribute(element, 'val')?.toLowerCase();
|
|
1856
1894
|
return '0' !== value && 'false' !== value && 'off' !== value;
|
|
1857
1895
|
}
|
|
1896
|
+
function resolveDocxPageChromeFontSizePoints(propertySources) {
|
|
1897
|
+
let fontSize;
|
|
1898
|
+
for (const properties of propertySources){
|
|
1899
|
+
const candidate = docxPageChromeFontSizePointsFromProperties(properties);
|
|
1900
|
+
if (void 0 !== candidate) fontSize = candidate;
|
|
1901
|
+
}
|
|
1902
|
+
return fontSize;
|
|
1903
|
+
}
|
|
1904
|
+
function docxPageChromeFontSizePointsFromProperties(properties) {
|
|
1905
|
+
const localMatches = directChildren(properties, 'sz');
|
|
1906
|
+
const nativeMatches = localMatches.filter((element)=>DOCX_WORDPROCESSING_NAMESPACES.has(element.namespaceURI ?? ''));
|
|
1907
|
+
if (1 !== localMatches.length || 1 !== nativeMatches.length) return;
|
|
1908
|
+
const size = nativeMatches[0];
|
|
1909
|
+
if (directChildren(size).length || Array.from(size.childNodes).some((node)=>(node.nodeType === Node.TEXT_NODE || node.nodeType === Node.CDATA_SECTION_NODE) && Boolean(node.textContent?.trim()))) return;
|
|
1910
|
+
const attributes = Array.from(size.attributes).filter((attribute)=>xmlAttributeNamespace(size, attribute) !== XMLNS_NAMESPACE && 'xmlns' !== attribute.name && !attribute.name.startsWith('xmlns:'));
|
|
1911
|
+
if (1 !== attributes.length || 'val' !== xmlAttributeLocalName(attributes[0]) || !DOCX_WORDPROCESSING_NAMESPACES.has(xmlAttributeNamespace(size, attributes[0]) ?? '')) return;
|
|
1912
|
+
const halfPoints = parseBoundedDocxInteger(attributes[0].value.trim(), {
|
|
1913
|
+
minimum: 1,
|
|
1914
|
+
maximum: 1024,
|
|
1915
|
+
signed: false
|
|
1916
|
+
});
|
|
1917
|
+
return null === halfPoints ? void 0 : halfPoints / 2;
|
|
1918
|
+
}
|
|
1919
|
+
function work_docx_page_chrome_import_formatNumber(value) {
|
|
1920
|
+
return Number(value.toFixed(2)).toString();
|
|
1921
|
+
}
|
|
1922
|
+
function htmlAttributes(attributes) {
|
|
1923
|
+
return Object.entries(attributes).map(([name, value])=>` ${name}="${escapeHtml(value)}"`).join('');
|
|
1924
|
+
}
|
|
1858
1925
|
function escapeHtml(value) {
|
|
1859
1926
|
return value.replaceAll('&', '&').replaceAll('<', '<').replaceAll('>', '>').replaceAll('"', '"');
|
|
1860
1927
|
}
|
|
@@ -2148,9 +2215,9 @@ function importedTableCellMargins(layers) {
|
|
|
2148
2215
|
}
|
|
2149
2216
|
function assignCellMargin(target, side, element) {
|
|
2150
2217
|
if (!element) return;
|
|
2151
|
-
const type =
|
|
2218
|
+
const type = work_ooxml_package_attribute(element, 'type');
|
|
2152
2219
|
if (type && 'dxa' !== type) return;
|
|
2153
|
-
const twips = Number(
|
|
2220
|
+
const twips = Number(work_ooxml_package_attribute(element, 'w'));
|
|
2154
2221
|
if (!Number.isFinite(twips) || twips < 0) return;
|
|
2155
2222
|
target[side] = Math.round(twips * PIXELS_PER_TWIP * 100) / 100;
|
|
2156
2223
|
}
|
|
@@ -2233,16 +2300,16 @@ function compactBorders(borders) {
|
|
|
2233
2300
|
}
|
|
2234
2301
|
function parseBorder(edge, theme) {
|
|
2235
2302
|
if (!edge) return null;
|
|
2236
|
-
const style = tableBorderStyle(
|
|
2303
|
+
const style = tableBorderStyle(work_ooxml_package_attribute(edge, 'val'));
|
|
2237
2304
|
if (!style) return null;
|
|
2238
2305
|
if ('none' === style) return {
|
|
2239
2306
|
color: '#000000',
|
|
2240
2307
|
style,
|
|
2241
2308
|
width: 0
|
|
2242
2309
|
};
|
|
2243
|
-
const themed = docxThemeColor(theme,
|
|
2244
|
-
const color = themed ? `#${themed}` : ooxmlColor(
|
|
2245
|
-
const size = Number(
|
|
2310
|
+
const themed = docxThemeColor(theme, work_ooxml_package_attribute(edge, 'themeColor'), work_ooxml_package_attribute(edge, 'themeTint'), work_ooxml_package_attribute(edge, 'themeShade'));
|
|
2311
|
+
const color = themed ? `#${themed}` : ooxmlColor(work_ooxml_package_attribute(edge, 'color')) ?? '#000000';
|
|
2312
|
+
const size = Number(work_ooxml_package_attribute(edge, 'sz'));
|
|
2246
2313
|
const width = Number.isFinite(size) && size > 0 ? size / 6 : 1;
|
|
2247
2314
|
return {
|
|
2248
2315
|
color,
|
|
@@ -2264,7 +2331,7 @@ function importedTableCellBackgroundColor(layers, theme) {
|
|
|
2264
2331
|
return color;
|
|
2265
2332
|
}
|
|
2266
2333
|
function tableCellBackgroundColor(shading, theme) {
|
|
2267
|
-
const themed = docxThemeColor(theme,
|
|
2334
|
+
const themed = docxThemeColor(theme, work_ooxml_package_attribute(shading, 'themeFill'), work_ooxml_package_attribute(shading, 'themeFillTint'), work_ooxml_package_attribute(shading, 'themeFillShade'));
|
|
2268
2335
|
if (themed) {
|
|
2269
2336
|
const color = `#${themed}`;
|
|
2270
2337
|
return {
|
|
@@ -2272,15 +2339,15 @@ function tableCellBackgroundColor(shading, theme) {
|
|
|
2272
2339
|
theme: themeReference(shading, 'themeFill', 'themeFillTint', 'themeFillShade', color)
|
|
2273
2340
|
};
|
|
2274
2341
|
}
|
|
2275
|
-
const color = ooxmlColor(
|
|
2342
|
+
const color = ooxmlColor(work_ooxml_package_attribute(shading, 'fill'));
|
|
2276
2343
|
return color ? {
|
|
2277
2344
|
color
|
|
2278
2345
|
} : null;
|
|
2279
2346
|
}
|
|
2280
2347
|
function themeReference(element, themeName, tintName, shadeName, resolved) {
|
|
2281
|
-
const theme =
|
|
2282
|
-
const tint = normalizedByteHex(
|
|
2283
|
-
const shade = normalizedByteHex(
|
|
2348
|
+
const theme = work_ooxml_package_attribute(element, themeName)?.trim() ?? '';
|
|
2349
|
+
const tint = normalizedByteHex(work_ooxml_package_attribute(element, tintName));
|
|
2350
|
+
const shade = normalizedByteHex(work_ooxml_package_attribute(element, shadeName));
|
|
2284
2351
|
return {
|
|
2285
2352
|
theme,
|
|
2286
2353
|
resolved,
|
|
@@ -2301,7 +2368,7 @@ function importedTableCellVerticalAlign(layers) {
|
|
|
2301
2368
|
for (const layer of layers){
|
|
2302
2369
|
const element = layer.cellProperties ? directChild(layer.cellProperties, 'vAlign') : void 0;
|
|
2303
2370
|
if (!element) continue;
|
|
2304
|
-
const value = tableVerticalAlign(
|
|
2371
|
+
const value = tableVerticalAlign(work_ooxml_package_attribute(element, 'val'));
|
|
2305
2372
|
if (value) alignment = value;
|
|
2306
2373
|
}
|
|
2307
2374
|
return alignment;
|
|
@@ -2380,8 +2447,8 @@ function markDocxTableRows(document) {
|
|
|
2380
2447
|
const cantSplit = properties ? directChild(properties, 'cantSplit') : void 0;
|
|
2381
2448
|
const repeatHeader = properties ? directChild(properties, 'tblHeader') : void 0;
|
|
2382
2449
|
const height = properties ? directChild(properties, 'trHeight') : void 0;
|
|
2383
|
-
const rowHeight = height ? twipsToPixels(Number(
|
|
2384
|
-
const rowHeightRule = tableRowHeightRule(
|
|
2450
|
+
const rowHeight = height ? twipsToPixels(Number(work_ooxml_package_attribute(height, 'val'))) : null;
|
|
2451
|
+
const rowHeightRule = tableRowHeightRule(work_ooxml_package_attribute(height ?? row, 'hRule'));
|
|
2385
2452
|
const rowIdentity = identities.get(row);
|
|
2386
2453
|
const uniqueIdentity = rowIdentity && 1 === identityCounts.get(rowIdentity.rowId) ? rowIdentity : null;
|
|
2387
2454
|
if (!cantSplit && !repeatHeader && null === rowHeight && !uniqueIdentity) continue;
|
|
@@ -2482,7 +2549,7 @@ function work_docx_table_row_import_word2010Attribute(element, localName) {
|
|
|
2482
2549
|
return Array.from(element.attributes).find((item)=>xmlAttributeLocalName(item) === localName && xmlAttributeNamespace(element, item) === work_docx_table_row_import_WORD_2010_NAMESPACE)?.value ?? null;
|
|
2483
2550
|
}
|
|
2484
2551
|
function onOffValue(element) {
|
|
2485
|
-
const value = (
|
|
2552
|
+
const value = (work_ooxml_package_attribute(element, 'val') ?? work_ooxml_package_attribute(element, 'w:val'))?.trim().toLowerCase();
|
|
2486
2553
|
return '0' !== value && 'false' !== value && 'off' !== value;
|
|
2487
2554
|
}
|
|
2488
2555
|
function setBooleanAttribute(element, name, value) {
|
|
@@ -2523,7 +2590,7 @@ function markDocxTableSizing(document, tableStyleSource) {
|
|
|
2523
2590
|
const paragraph = firstTableParagraph(document, table);
|
|
2524
2591
|
if (!paragraph) continue;
|
|
2525
2592
|
const grid = directChild(table, 'tblGrid');
|
|
2526
|
-
const columnWidths = grid ? directChildren(grid, 'gridCol').map((column)=>work_docx_table_sizing_import_twipsToPixels(Number(
|
|
2593
|
+
const columnWidths = grid ? directChildren(grid, 'gridCol').map((column)=>work_docx_table_sizing_import_twipsToPixels(Number(work_ooxml_package_attribute(column, 'w')), false)).filter((width)=>null !== width) : [];
|
|
2527
2594
|
const marker = `__A3S_WORK_TABLE_SIZING_${tables.length + 1}__`;
|
|
2528
2595
|
insertMarker(document, paragraph, marker);
|
|
2529
2596
|
tables.push({
|
|
@@ -2574,13 +2641,13 @@ function importedTableGeometry(propertySources) {
|
|
|
2574
2641
|
};
|
|
2575
2642
|
for (const properties of propertySources){
|
|
2576
2643
|
const layoutElement = directChild(properties, 'tblLayout');
|
|
2577
|
-
const layoutValue = layoutElement ? importedTableLayout(
|
|
2644
|
+
const layoutValue = layoutElement ? importedTableLayout(work_ooxml_package_attribute(layoutElement, 'type')) : null;
|
|
2578
2645
|
if (layoutValue) layout = layoutValue;
|
|
2579
2646
|
const widthElement = directChild(properties, 'tblW');
|
|
2580
2647
|
const widthValue = widthElement ? importedTablePreferredWidth(widthElement) : null;
|
|
2581
2648
|
if (widthValue) width = widthValue;
|
|
2582
2649
|
const alignmentElement = directChild(properties, 'jc');
|
|
2583
|
-
const alignmentValue = alignmentElement ? importedTableAlignment(
|
|
2650
|
+
const alignmentValue = alignmentElement ? importedTableAlignment(work_ooxml_package_attribute(alignmentElement, 'val')) : null;
|
|
2584
2651
|
if (alignmentValue) alignment = alignmentValue;
|
|
2585
2652
|
const indentElement = directChild(properties, 'tblInd');
|
|
2586
2653
|
const indentValue = indentElement ? tableWidthPixels(indentElement, true) : null;
|
|
@@ -2604,13 +2671,13 @@ function importedTableLayout(value) {
|
|
|
2604
2671
|
return 'autofit' === value ? 'autofit' : null;
|
|
2605
2672
|
}
|
|
2606
2673
|
function importedTablePreferredWidth(width) {
|
|
2607
|
-
const type =
|
|
2674
|
+
const type = work_ooxml_package_attribute(width, 'type');
|
|
2608
2675
|
if ('auto' === type || 'nil' === type) return {
|
|
2609
2676
|
type: 'auto',
|
|
2610
2677
|
value: null
|
|
2611
2678
|
};
|
|
2612
2679
|
if ('pct' === type) {
|
|
2613
|
-
const value = percentageValue(
|
|
2680
|
+
const value = percentageValue(work_ooxml_package_attribute(width, 'w'));
|
|
2614
2681
|
return null === value ? null : {
|
|
2615
2682
|
type: 'percent',
|
|
2616
2683
|
value
|
|
@@ -2649,9 +2716,9 @@ function assignMargin(target, side, element) {
|
|
|
2649
2716
|
if (null !== value) target[side] = value;
|
|
2650
2717
|
}
|
|
2651
2718
|
function tableWidthPixels(element, allowZero) {
|
|
2652
|
-
const type =
|
|
2719
|
+
const type = work_ooxml_package_attribute(element, 'type');
|
|
2653
2720
|
if (type && 'dxa' !== type) return null;
|
|
2654
|
-
return work_docx_table_sizing_import_twipsToPixels(Number(
|
|
2721
|
+
return work_docx_table_sizing_import_twipsToPixels(Number(work_ooxml_package_attribute(element, 'w')), allowZero);
|
|
2655
2722
|
}
|
|
2656
2723
|
function percentageValue(value) {
|
|
2657
2724
|
const normalized = value?.trim();
|
|
@@ -2703,9 +2770,9 @@ function importedColumnPercentages(table, columnWidths) {
|
|
|
2703
2770
|
for (const cell of directChildren(row, 'tc')){
|
|
2704
2771
|
const properties = directChild(cell, 'tcPr');
|
|
2705
2772
|
const gridSpan = directChild(properties ?? cell, 'gridSpan');
|
|
2706
|
-
const span = Math.max(1, Number(gridSpan ?
|
|
2773
|
+
const span = Math.max(1, Number(gridSpan ? work_ooxml_package_attribute(gridSpan, 'val') : null) || 1);
|
|
2707
2774
|
const width = directChild(properties ?? cell, 'tcW');
|
|
2708
|
-
const total = width && 'pct' ===
|
|
2775
|
+
const total = width && 'pct' === work_ooxml_package_attribute(width, 'type') ? percentageValue(work_ooxml_package_attribute(width, 'w')) : null;
|
|
2709
2776
|
if (null !== total) {
|
|
2710
2777
|
const physical = columnWidths.slice(column, column + span);
|
|
2711
2778
|
const physicalTotal = physical.reduce((sum, value)=>sum + value, 0);
|
|
@@ -2725,7 +2792,7 @@ function logicalTableColumnCount(table) {
|
|
|
2725
2792
|
const count = directChildren(row, 'tc').reduce((sum, cell)=>{
|
|
2726
2793
|
const properties = directChild(cell, 'tcPr');
|
|
2727
2794
|
const gridSpan = directChild(properties ?? cell, 'gridSpan');
|
|
2728
|
-
const span = Number(gridSpan ?
|
|
2795
|
+
const span = Number(gridSpan ? work_ooxml_package_attribute(gridSpan, 'val') : null);
|
|
2729
2796
|
return sum + (Number.isSafeInteger(span) && span > 0 ? span : 1);
|
|
2730
2797
|
}, rowGridBefore(row));
|
|
2731
2798
|
return Math.max(maximum, count);
|
|
@@ -2734,7 +2801,7 @@ function logicalTableColumnCount(table) {
|
|
|
2734
2801
|
function rowGridBefore(row) {
|
|
2735
2802
|
const properties = directChild(row, 'trPr');
|
|
2736
2803
|
const gridBefore = directChild(properties ?? row, 'gridBefore');
|
|
2737
|
-
const value = Number(gridBefore ?
|
|
2804
|
+
const value = Number(gridBefore ? work_ooxml_package_attribute(gridBefore, 'val') : null);
|
|
2738
2805
|
return Number.isSafeInteger(value) && value > 0 ? value : 0;
|
|
2739
2806
|
}
|
|
2740
2807
|
function firstTableParagraph(document, table) {
|
|
@@ -2905,7 +2972,13 @@ async function prepareDocxImport(buffer, sourcePackage) {
|
|
|
2905
2972
|
const theme = createDocxThemeResolver(themeDocument, settings);
|
|
2906
2973
|
const paragraphBorderMarkers = markDocxParagraphBorders(document, paragraphStyles, theme, tableStyles);
|
|
2907
2974
|
const paragraphShadingMarkers = markDocxParagraphShading(document, paragraphStyles, theme, tableStyles);
|
|
2908
|
-
const
|
|
2975
|
+
const runFormattingMarkerState = createImportedDocxRunFormattingMarkerState([
|
|
2976
|
+
document,
|
|
2977
|
+
...equationMarkers.parts.map((part)=>part.document)
|
|
2978
|
+
]);
|
|
2979
|
+
markDocxRunFormattingIntoState(document, runFormattingMarkerState, paragraphStyles, theme, tableStyles);
|
|
2980
|
+
for (const part of equationMarkers.parts)markDocxRunFormattingIntoState(part.document, runFormattingMarkerState, paragraphStyles, theme, tableStyles);
|
|
2981
|
+
const runFormattingMarkers = runFormattingMarkerState.markers;
|
|
2909
2982
|
const paragraphFormattingChangeMarkers = markDocxParagraphFormattingChanges(document, paragraphStyles, theme, tableStyles);
|
|
2910
2983
|
const tabStopMarkers = markDocxParagraphTabStops(document, paragraphStyles, tableStyles);
|
|
2911
2984
|
const tableCellMarkers = markDocxTableCells(document, theme, tableStyles);
|
|
@@ -3152,7 +3225,7 @@ async function parseSectionLayout(section, archive, relationships, previous, odd
|
|
|
3152
3225
|
return pageGeometry ? applyDocumentPageGeometry(layout, pageGeometry) : layout;
|
|
3153
3226
|
}
|
|
3154
3227
|
function parseDocumentGrid(element) {
|
|
3155
|
-
const sourceType =
|
|
3228
|
+
const sourceType = work_ooxml_package_attribute(element, 'type');
|
|
3156
3229
|
const type = 'lines' === sourceType || 'linesAndChars' === sourceType || 'snapToChars' === sourceType ? sourceType : 'default';
|
|
3157
3230
|
const sourceLinePitch = work_docx_import_numberAttribute(element, 'linePitch');
|
|
3158
3231
|
return {
|
|
@@ -3237,13 +3310,13 @@ function sectionMarker(index) {
|
|
|
3237
3310
|
}
|
|
3238
3311
|
function parseSectionBreak(element) {
|
|
3239
3312
|
if (!element) return 'nextPage';
|
|
3240
|
-
const value =
|
|
3313
|
+
const value = work_ooxml_package_attribute(element, 'val');
|
|
3241
3314
|
if ('continuous' === value || 'evenPage' === value || 'oddPage' === value || 'nextColumn' === value) return value;
|
|
3242
3315
|
return 'nextPage';
|
|
3243
3316
|
}
|
|
3244
3317
|
function work_docx_import_numberAttribute(element, name) {
|
|
3245
3318
|
if (!element) return 0;
|
|
3246
|
-
const value = Number(
|
|
3319
|
+
const value = Number(work_ooxml_package_attribute(element, name));
|
|
3247
3320
|
return Number.isFinite(value) ? value : 0;
|
|
3248
3321
|
}
|
|
3249
3322
|
function work_docx_import_closestAncestor(element, localName) {
|