@a3s-lab/office 0.9.2 → 0.11.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 +29 -5
- package/README.md +19 -6
- package/dist/{0~7754.js → 0~5093.js} +1449 -3
- package/dist/0~document-editor.js +8 -1
- package/dist/0~work-docx-export.js +482 -16
- package/dist/0~work-docx-import.js +31 -1142
- package/dist/0~work-office-diagnostics.js +9 -5
- package/dist/4104.js +1 -1
- package/dist/8928.js +763 -149
- package/dist/internal/features/work/work-document-format-change-tracking.d.ts +9 -0
- package/dist/internal/features/work/work-document-format-changes.d.ts +28 -0
- package/dist/internal/features/work/work-document-paragraph-format-change-tracking.d.ts +7 -0
- package/dist/internal/features/work/work-document-paragraph-format-changes.d.ts +8 -0
- package/dist/internal/features/work/work-docx-format-change-export.d.ts +17 -0
- package/dist/internal/features/work/work-docx-import.d.ts +3 -1
- package/dist/internal/features/work/work-docx-paragraph-alignment-import.d.ts +1 -0
- package/dist/internal/features/work/work-docx-paragraph-borders-import.d.ts +1 -0
- package/dist/internal/features/work/work-docx-paragraph-direction-import.d.ts +1 -0
- package/dist/internal/features/work/work-docx-paragraph-format-change-export.d.ts +13 -0
- package/dist/internal/features/work/work-docx-paragraph-format-change-import.d.ts +17 -0
- package/dist/internal/features/work/work-docx-paragraph-indent-import.d.ts +1 -0
- package/dist/internal/features/work/work-docx-paragraph-pagination-import.d.ts +1 -0
- package/dist/internal/features/work/work-docx-paragraph-shading-import.d.ts +1 -0
- package/dist/internal/features/work/work-docx-paragraph-spacing-import.d.ts +1 -0
- package/dist/internal/features/work/work-docx-run-formatting-import.d.ts +10 -0
- package/dist/internal/features/work/work-docx-tab-stop-import.d.ts +1 -0
- package/dist/internal/features/work/work-types.d.ts +1 -1
- package/dist/office-kernel.wasm +0 -0
- package/dist/styles.css +28 -0
- package/docs/latest/en/browser-editor-architecture.md +18 -0
- package/package.json +7 -3
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import jszip from "jszip";
|
|
2
2
|
import { contentTypeForPart, directChildren, bytesToDataUrl, OoxmlPackage, firstDescendant, descendants, directChild, attribute } from "./5184.js";
|
|
3
|
-
import { normalizeDocumentBookmarkName,
|
|
4
|
-
import {
|
|
5
|
-
import { xmlAttributeLocalName,
|
|
3
|
+
import { normalizeDocumentBookmarkName, documentInitialSectionLayout, normalizeDocumentFieldsHtml, applyDocumentImageIdentityToElement, renderDocumentTableCellMarginOverrides, documentCaptionLabel, documentTableBordersFromElement, isContourImageLayout, normalizeDocumentCitationsHtml, createDocumentImageIdentityRegistry, normalizeDocumentColumns, normalizeDocumentImageIdentity, normalizeDocumentImageWrapSide, applyDocumentParagraphIdentityToElement, docxDocumentFieldKind, serializeDocxThemeReference, renderDocumentTableBorders, docxBookmarkReferenceTarget, normalizeDocumentImagePosition, wrapsBesideImage, documentPageChromeLegacyFields, normalizeDocumentImageWrapContour, documentParagraphShadingDomAttributes, normalizeDocumentBookmarksHtml, documentParagraphBordersDomAttributes, DOCUMENT_TABLE_ROW_ID_ATTRIBUTE, applyDocumentTableRowIdentityToElement, normalizeDocumentCaptionsHtml, normalizeDocumentParagraphIdentity, DEFAULT_DOCUMENT_TABLE_CELL_MARGINS, DEFAULT_DOCUMENT_TABLE_GEOMETRY, documentSectionDomAttributes, documentPageMarginBody, normalizeDocumentImageAlignment, normalizeDocumentParagraphId, applyDocumentImageLayerToElement, normalizeDocumentBookmarkNativeId, normalizeDocumentTableRowIdentity, uniqueDocumentImageIdentity, normalizeDocumentBookmarkReferencesHtml, documentCitationTagsFromInstruction, applyDocumentImageWrapContourToElement, normalizeDocumentNotesHtml, applyDocumentTableGeometryToElement, normalizeDocumentImageCrop, normalizeDocumentPageChrome, normalizeDocumentImageLayoutOptions, applyDocumentImageCropToElement, documentPageMarginsForLayout, applyDocumentPageGeometry, documentContentLayoutProperties, createDocumentNoteElement, normalizeDocumentImageLayer, DOCUMENT_TABLE_ROW_TEXT_ID_ATTRIBUTE, documentBookmarkReferenceInstruction } from "./8928.js";
|
|
4
|
+
import { markDocxParagraphFormattingChanges, markDocxParagraphIndents, parseDocxPageGeometry, parseDocxPageBorders, docxCaptionReferenceTarget, applyImportedDocxEquationMarkers, hasImportedDocxParagraphPaginationMarkers, createDocxTableStyleResolver, applyImportedDocxParagraphSpacingMarkers, hasImportedDocxParagraphShadingMarkers, hasImportedDocxParagraphDirectionMarkers, isDocxEquationLikeRoot, inspectDocxPageMarginSettings, applyImportedDocxParagraphFormattingChangeMarkers, hasImportedDocxParagraphTabStopMarkers, hasImportedDocxRunFormattingMarkers, hasImportedDocxParagraphIndentMarkers, docxCaptionSequenceKind, resolveDocxParagraphBordersForParagraph, applyImportedDocxRunFormattingMarkers, markDocxParagraphAlignments, markDocxParagraphDirections, applyImportedDocxParagraphShadingMarkers, markDocxParagraphSpacing, hasImportedDocxParagraphBorderMarkers, hasImportedDocxParagraphFormattingChangeMarkers, docxCaptionBookmark, docxFieldResultText, createDocxParagraphStyleResolver, docxEquationHtml, docxFieldOccurrences, hasImportedDocxParagraphAlignmentMarkers, markDocxParagraphTabStops, applyImportedDocxParagraphIndentMarkers, resolveDocxTableStyleResolver, applyImportedDocxParagraphDirectionMarkers, docxTableCellStyleLayers, applyImportedDocxParagraphAlignmentMarkers, markDocxParagraphPagination, markDocxParagraphBorders, markDocxRunFormatting, applyImportedDocxParagraphTabStopMarkers, docxFieldOccurrenceIsInlineEditable, applyImportedDocxParagraphBorderMarkers, applyImportedDocxParagraphPaginationMarkers, parseDocxPaperSource, hasImportedDocxParagraphSpacingMarkers, docxTablePropertySources, parseDirectDocxParagraphShading, parseDocxPageMargins, markDocxParagraphShading, markDocxPackageEquations } from "./0~5093.js";
|
|
5
|
+
import { xmlAttributeLocalName, readDocxBibliography, createDocxThemeResolver, docxThemeColor, parseDocxParagraphDefaultCollapsed, resolveDocxThemeResolver, DOCX_WORDPROCESSING_NAMESPACES, xmlAttributeNamespace } from "./0~2805.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';
|
|
@@ -1881,216 +1881,6 @@ function updateFieldState(field, fieldType) {
|
|
|
1881
1881
|
function fieldContentVisible(field) {
|
|
1882
1882
|
return !field.active || field.separated && !field.skipResult;
|
|
1883
1883
|
}
|
|
1884
|
-
const work_docx_paragraph_alignment_import_WORD_NAMESPACE = 'http://schemas.openxmlformats.org/wordprocessingml/2006/main';
|
|
1885
|
-
const work_docx_paragraph_alignment_import_XML_NAMESPACE = 'http://www.w3.org/XML/1998/namespace';
|
|
1886
|
-
const PARAGRAPH_ALIGNMENT_MARKER_PATTERN = /__A3S_WORK_PARAGRAPH_ALIGNMENT_\d+__/g;
|
|
1887
|
-
function markDocxParagraphAlignments(document, styleSource, tableStyleSource) {
|
|
1888
|
-
const paragraphs = [];
|
|
1889
|
-
const styles = resolveDocxParagraphStyleResolver(styleSource);
|
|
1890
|
-
const tableStyles = resolveDocxTableStyleResolver(tableStyleSource);
|
|
1891
|
-
for (const paragraph of descendants(document, 'p')){
|
|
1892
|
-
let properties = directChild(paragraph, 'pPr');
|
|
1893
|
-
const sources = docxParagraphPropertySources(properties, styles, docxTableParagraphPropertySources(paragraph, tableStyles));
|
|
1894
|
-
const alignment = paragraphAlignment(sources);
|
|
1895
|
-
if (!alignment) continue;
|
|
1896
|
-
properties ??= insertParagraphProperties(document, paragraph);
|
|
1897
|
-
const marker = `__A3S_WORK_PARAGRAPH_ALIGNMENT_${paragraphs.length + 1}__`;
|
|
1898
|
-
work_docx_paragraph_alignment_import_insertParagraphMarker(document, paragraph, properties, marker);
|
|
1899
|
-
paragraphs.push({
|
|
1900
|
-
marker,
|
|
1901
|
-
alignment
|
|
1902
|
-
});
|
|
1903
|
-
}
|
|
1904
|
-
return {
|
|
1905
|
-
paragraphs
|
|
1906
|
-
};
|
|
1907
|
-
}
|
|
1908
|
-
function applyImportedDocxParagraphAlignmentMarkers(document, markers) {
|
|
1909
|
-
const alignmentByMarker = new Map(markers.paragraphs.map(({ marker, alignment })=>[
|
|
1910
|
-
marker,
|
|
1911
|
-
alignment
|
|
1912
|
-
]));
|
|
1913
|
-
for (const node of work_docx_paragraph_alignment_import_textNodes(document.body))if (node.data.includes('__A3S_WORK_PARAGRAPH_ALIGNMENT_')) node.data = node.data.replace(PARAGRAPH_ALIGNMENT_MARKER_PATTERN, (marker)=>{
|
|
1914
|
-
const alignment = alignmentByMarker.get(marker);
|
|
1915
|
-
const block = alignment ? closestParagraphBlock(node.parentElement, node) : null;
|
|
1916
|
-
if (block && alignment) block.style.textAlign = alignment;
|
|
1917
|
-
return '';
|
|
1918
|
-
});
|
|
1919
|
-
document.body.normalize();
|
|
1920
|
-
}
|
|
1921
|
-
function hasImportedDocxParagraphAlignmentMarkers(markers) {
|
|
1922
|
-
return markers.paragraphs.length > 0;
|
|
1923
|
-
}
|
|
1924
|
-
function paragraphAlignment(propertySources) {
|
|
1925
|
-
let direction = 'ltr';
|
|
1926
|
-
let justification = null;
|
|
1927
|
-
let hasJustification = false;
|
|
1928
|
-
for (const properties of propertySources){
|
|
1929
|
-
const bidi = directChild(properties, 'bidi');
|
|
1930
|
-
if (bidi) direction = onOffValue(bidi) ? 'rtl' : 'ltr';
|
|
1931
|
-
const source = directChild(properties, 'jc');
|
|
1932
|
-
if (source) {
|
|
1933
|
-
hasJustification = true;
|
|
1934
|
-
justification = wordAttribute(source, 'val')?.trim() ?? null;
|
|
1935
|
-
}
|
|
1936
|
-
}
|
|
1937
|
-
if (!hasJustification || !justification) return null;
|
|
1938
|
-
if ('center' === justification) return 'center';
|
|
1939
|
-
if ('left' === justification) return 'left';
|
|
1940
|
-
if ('right' === justification) return 'right';
|
|
1941
|
-
if ('start' === justification) return 'rtl' === direction ? 'right' : 'left';
|
|
1942
|
-
if ('end' === justification) return 'rtl' === direction ? 'left' : 'right';
|
|
1943
|
-
if ('both' === justification || 'distribute' === justification || 'highKashida' === justification || 'lowKashida' === justification || 'mediumKashida' === justification || 'thaiDistribute' === justification) return 'justify';
|
|
1944
|
-
return null;
|
|
1945
|
-
}
|
|
1946
|
-
function onOffValue(element) {
|
|
1947
|
-
const value = wordAttribute(element, 'val')?.trim().toLowerCase();
|
|
1948
|
-
return '0' !== value && 'false' !== value && 'off' !== value;
|
|
1949
|
-
}
|
|
1950
|
-
function wordAttribute(element, name) {
|
|
1951
|
-
return attribute(element, name) ?? attribute(element, `w:${name}`);
|
|
1952
|
-
}
|
|
1953
|
-
function work_docx_paragraph_alignment_import_insertParagraphMarker(document, paragraph, properties, marker) {
|
|
1954
|
-
const run = document.createElementNS(work_docx_paragraph_alignment_import_WORD_NAMESPACE, 'w:r');
|
|
1955
|
-
const text = document.createElementNS(work_docx_paragraph_alignment_import_WORD_NAMESPACE, 'w:t');
|
|
1956
|
-
text.setAttributeNS(work_docx_paragraph_alignment_import_XML_NAMESPACE, 'xml:space', 'preserve');
|
|
1957
|
-
text.textContent = marker;
|
|
1958
|
-
run.append(text);
|
|
1959
|
-
paragraph.insertBefore(run, properties.nextSibling);
|
|
1960
|
-
}
|
|
1961
|
-
function insertParagraphProperties(document, paragraph) {
|
|
1962
|
-
const properties = document.createElementNS(work_docx_paragraph_alignment_import_WORD_NAMESPACE, 'w:pPr');
|
|
1963
|
-
paragraph.insertBefore(properties, paragraph.firstChild);
|
|
1964
|
-
return properties;
|
|
1965
|
-
}
|
|
1966
|
-
function closestParagraphBlock(element, markerNode) {
|
|
1967
|
-
const block = element?.closest('p, h1, h2, h3, h4, h5, h6, blockquote, li');
|
|
1968
|
-
if (!(block instanceof HTMLElement)) return null;
|
|
1969
|
-
return 'li' === block.tagName.toLowerCase() ? wrapListItemParagraph(block, markerNode) : block;
|
|
1970
|
-
}
|
|
1971
|
-
function wrapListItemParagraph(item, markerNode) {
|
|
1972
|
-
let anchor = markerNode;
|
|
1973
|
-
while(anchor.parentNode && anchor.parentNode !== item)anchor = anchor.parentNode;
|
|
1974
|
-
const children = Array.from(item.childNodes);
|
|
1975
|
-
const anchorIndex = children.indexOf(anchor);
|
|
1976
|
-
if (anchorIndex < 0) return item;
|
|
1977
|
-
let start = anchorIndex;
|
|
1978
|
-
let end = anchorIndex;
|
|
1979
|
-
while(start > 0 && !isListItemBlock(children[start - 1]))start -= 1;
|
|
1980
|
-
while(end + 1 < children.length && !isListItemBlock(children[end + 1]))end += 1;
|
|
1981
|
-
const paragraph = item.ownerDocument.createElement('p');
|
|
1982
|
-
const grouped = children.slice(start, end + 1);
|
|
1983
|
-
item.insertBefore(paragraph, grouped[0] ?? null);
|
|
1984
|
-
paragraph.append(...grouped);
|
|
1985
|
-
return paragraph;
|
|
1986
|
-
}
|
|
1987
|
-
function isListItemBlock(node) {
|
|
1988
|
-
if (!(node instanceof HTMLElement)) return false;
|
|
1989
|
-
return [
|
|
1990
|
-
'blockquote',
|
|
1991
|
-
'div',
|
|
1992
|
-
'h1',
|
|
1993
|
-
'h2',
|
|
1994
|
-
'h3',
|
|
1995
|
-
'h4',
|
|
1996
|
-
'h5',
|
|
1997
|
-
'h6',
|
|
1998
|
-
'hr',
|
|
1999
|
-
'ol',
|
|
2000
|
-
'p',
|
|
2001
|
-
'pre',
|
|
2002
|
-
'table',
|
|
2003
|
-
'ul'
|
|
2004
|
-
].includes(node.tagName.toLowerCase());
|
|
2005
|
-
}
|
|
2006
|
-
function work_docx_paragraph_alignment_import_textNodes(root) {
|
|
2007
|
-
const document = root.ownerDocument;
|
|
2008
|
-
const walker = document?.createTreeWalker(root, NodeFilter.SHOW_TEXT);
|
|
2009
|
-
const nodes = [];
|
|
2010
|
-
if (!walker) return nodes;
|
|
2011
|
-
while(walker.nextNode())nodes.push(walker.currentNode);
|
|
2012
|
-
return nodes;
|
|
2013
|
-
}
|
|
2014
|
-
const work_docx_paragraph_direction_import_WORD_NAMESPACE = 'http://schemas.openxmlformats.org/wordprocessingml/2006/main';
|
|
2015
|
-
const work_docx_paragraph_direction_import_XML_NAMESPACE = 'http://www.w3.org/XML/1998/namespace';
|
|
2016
|
-
const PARAGRAPH_DIRECTION_MARKER_PATTERN = /__A3S_WORK_PARAGRAPH_DIRECTION_\d+__/g;
|
|
2017
|
-
function markDocxParagraphDirections(document, styleSource, tableStyleSource) {
|
|
2018
|
-
const paragraphs = [];
|
|
2019
|
-
const styles = resolveDocxParagraphStyleResolver(styleSource);
|
|
2020
|
-
const tableStyles = resolveDocxTableStyleResolver(tableStyleSource);
|
|
2021
|
-
for (const paragraph of descendants(document, 'p')){
|
|
2022
|
-
let properties = directChild(paragraph, 'pPr');
|
|
2023
|
-
const sources = docxParagraphPropertySources(properties, styles, docxTableParagraphPropertySources(paragraph, tableStyles));
|
|
2024
|
-
const direction = paragraphDirection(sources);
|
|
2025
|
-
if (!direction) continue;
|
|
2026
|
-
properties ??= work_docx_paragraph_direction_import_insertParagraphProperties(document, paragraph);
|
|
2027
|
-
const marker = `__A3S_WORK_PARAGRAPH_DIRECTION_${paragraphs.length + 1}__`;
|
|
2028
|
-
work_docx_paragraph_direction_import_insertParagraphMarker(document, paragraph, properties, marker);
|
|
2029
|
-
paragraphs.push({
|
|
2030
|
-
marker,
|
|
2031
|
-
direction
|
|
2032
|
-
});
|
|
2033
|
-
}
|
|
2034
|
-
return {
|
|
2035
|
-
paragraphs
|
|
2036
|
-
};
|
|
2037
|
-
}
|
|
2038
|
-
function applyImportedDocxParagraphDirectionMarkers(document, markers) {
|
|
2039
|
-
const directionByMarker = new Map(markers.paragraphs.map(({ marker, direction })=>[
|
|
2040
|
-
marker,
|
|
2041
|
-
direction
|
|
2042
|
-
]));
|
|
2043
|
-
for (const node of work_docx_paragraph_direction_import_textNodes(document.body)){
|
|
2044
|
-
if (!node.data.includes('__A3S_WORK_PARAGRAPH_DIRECTION_')) continue;
|
|
2045
|
-
const block = work_docx_paragraph_direction_import_closestParagraphBlock(node.parentElement);
|
|
2046
|
-
node.data = node.data.replace(PARAGRAPH_DIRECTION_MARKER_PATTERN, (marker)=>{
|
|
2047
|
-
const direction = directionByMarker.get(marker);
|
|
2048
|
-
if (block && direction) block.setAttribute('dir', direction);
|
|
2049
|
-
return '';
|
|
2050
|
-
});
|
|
2051
|
-
}
|
|
2052
|
-
document.body.normalize();
|
|
2053
|
-
}
|
|
2054
|
-
function hasImportedDocxParagraphDirectionMarkers(markers) {
|
|
2055
|
-
return markers.paragraphs.length > 0;
|
|
2056
|
-
}
|
|
2057
|
-
function paragraphDirection(propertySources) {
|
|
2058
|
-
let direction = null;
|
|
2059
|
-
for (const properties of propertySources){
|
|
2060
|
-
const bidi = directChild(properties, 'bidi');
|
|
2061
|
-
if (bidi) direction = work_docx_paragraph_direction_import_onOffValue(bidi) ? 'rtl' : 'ltr';
|
|
2062
|
-
}
|
|
2063
|
-
return direction;
|
|
2064
|
-
}
|
|
2065
|
-
function work_docx_paragraph_direction_import_onOffValue(element) {
|
|
2066
|
-
const value = (attribute(element, 'val') ?? attribute(element, 'w:val'))?.trim().toLowerCase();
|
|
2067
|
-
return '0' !== value && 'false' !== value && 'off' !== value;
|
|
2068
|
-
}
|
|
2069
|
-
function work_docx_paragraph_direction_import_insertParagraphMarker(document, paragraph, properties, marker) {
|
|
2070
|
-
const run = document.createElementNS(work_docx_paragraph_direction_import_WORD_NAMESPACE, 'w:r');
|
|
2071
|
-
const text = document.createElementNS(work_docx_paragraph_direction_import_WORD_NAMESPACE, 'w:t');
|
|
2072
|
-
text.setAttributeNS(work_docx_paragraph_direction_import_XML_NAMESPACE, 'xml:space', 'preserve');
|
|
2073
|
-
text.textContent = marker;
|
|
2074
|
-
run.append(text);
|
|
2075
|
-
paragraph.insertBefore(run, properties.nextSibling);
|
|
2076
|
-
}
|
|
2077
|
-
function work_docx_paragraph_direction_import_insertParagraphProperties(document, paragraph) {
|
|
2078
|
-
const properties = document.createElementNS(work_docx_paragraph_direction_import_WORD_NAMESPACE, 'w:pPr');
|
|
2079
|
-
paragraph.insertBefore(properties, paragraph.firstChild);
|
|
2080
|
-
return properties;
|
|
2081
|
-
}
|
|
2082
|
-
function work_docx_paragraph_direction_import_closestParagraphBlock(element) {
|
|
2083
|
-
const block = element?.closest('p, h1, h2, h3, h4, h5, h6, blockquote, li');
|
|
2084
|
-
return block instanceof HTMLElement ? block : null;
|
|
2085
|
-
}
|
|
2086
|
-
function work_docx_paragraph_direction_import_textNodes(root) {
|
|
2087
|
-
const document = root.ownerDocument;
|
|
2088
|
-
const walker = document?.createTreeWalker(root, NodeFilter.SHOW_TEXT);
|
|
2089
|
-
const nodes = [];
|
|
2090
|
-
if (!walker) return nodes;
|
|
2091
|
-
while(walker.nextNode())nodes.push(walker.currentNode);
|
|
2092
|
-
return nodes;
|
|
2093
|
-
}
|
|
2094
1884
|
const work_docx_paragraph_identity_import_WORD_2010_NAMESPACE = 'http://schemas.microsoft.com/office/word/2010/wordml';
|
|
2095
1885
|
const work_docx_paragraph_identity_import_XML_NAMESPACE = 'http://www.w3.org/XML/1998/namespace';
|
|
2096
1886
|
const PARAGRAPH_IDENTITY_MARKER_PATTERN = /__A3S_WORK_PARAGRAPH_IDENTITY_\d+__/g;
|
|
@@ -2144,7 +1934,7 @@ function applyImportedDocxParagraphIdentityMarkers(document, markers) {
|
|
|
2144
1934
|
]));
|
|
2145
1935
|
for (const node of work_docx_paragraph_identity_import_textNodes(document.body))if (node.data.includes('__A3S_WORK_PARAGRAPH_IDENTITY_')) node.data = node.data.replace(PARAGRAPH_IDENTITY_MARKER_PATTERN, (marker)=>{
|
|
2146
1936
|
const identity = identities.get(marker);
|
|
2147
|
-
const block = identity ?
|
|
1937
|
+
const block = identity ? closestParagraphBlock(node.parentElement, node) : null;
|
|
2148
1938
|
if (identity && block) applyDocumentParagraphIdentityToElement(block, identity);
|
|
2149
1939
|
return '';
|
|
2150
1940
|
});
|
|
@@ -2174,7 +1964,7 @@ function work_docx_paragraph_identity_import_insertParagraphMarker(paragraph, ma
|
|
|
2174
1964
|
const properties = directChildren(paragraph, 'pPr').find((element)=>DOCX_WORDPROCESSING_NAMESPACES.has(element.namespaceURI ?? ''));
|
|
2175
1965
|
paragraph.insertBefore(run, properties?.nextSibling ?? paragraph.firstChild);
|
|
2176
1966
|
}
|
|
2177
|
-
function
|
|
1967
|
+
function closestParagraphBlock(element, markerNode) {
|
|
2178
1968
|
const explicit = element?.closest('p, h1, h2, h3, h4, h5, h6, figcaption');
|
|
2179
1969
|
if (explicit instanceof HTMLElement) return explicit;
|
|
2180
1970
|
const container = element?.closest('li, blockquote, td, th, div');
|
|
@@ -2223,916 +2013,6 @@ function work_docx_paragraph_identity_import_textNodes(root) {
|
|
|
2223
2013
|
while(walker.nextNode())nodes.push(walker.currentNode);
|
|
2224
2014
|
return nodes;
|
|
2225
2015
|
}
|
|
2226
|
-
const work_docx_paragraph_indent_import_WORD_NAMESPACE = 'http://schemas.openxmlformats.org/wordprocessingml/2006/main';
|
|
2227
|
-
const work_docx_paragraph_indent_import_XML_NAMESPACE = 'http://www.w3.org/XML/1998/namespace';
|
|
2228
|
-
const TWIPS_PER_CSS_PIXEL = 15;
|
|
2229
|
-
const PARAGRAPH_INDENT_MARKER_PATTERN = /__A3S_WORK_PARAGRAPH_INDENT_\d+__/g;
|
|
2230
|
-
function markDocxParagraphIndents(document, styleSource, tableStyleSource) {
|
|
2231
|
-
const paragraphs = [];
|
|
2232
|
-
const styles = resolveDocxParagraphStyleResolver(styleSource);
|
|
2233
|
-
const tableStyles = resolveDocxTableStyleResolver(tableStyleSource);
|
|
2234
|
-
for (const paragraph of descendants(document, 'p')){
|
|
2235
|
-
let properties = directChild(paragraph, 'pPr');
|
|
2236
|
-
const sources = docxParagraphPropertySources(properties, styles, docxTableParagraphPropertySources(paragraph, tableStyles));
|
|
2237
|
-
if (sources.some((source)=>directChild(source, 'numPr'))) continue;
|
|
2238
|
-
const indent = paragraphIndent(sources);
|
|
2239
|
-
if (!indent.left && !indent.right && !indent.firstLine) continue;
|
|
2240
|
-
properties ??= work_docx_paragraph_indent_import_insertParagraphProperties(document, paragraph);
|
|
2241
|
-
const marker = `__A3S_WORK_PARAGRAPH_INDENT_${paragraphs.length + 1}__`;
|
|
2242
|
-
work_docx_paragraph_indent_import_insertParagraphMarker(document, paragraph, properties, marker);
|
|
2243
|
-
paragraphs.push({
|
|
2244
|
-
marker,
|
|
2245
|
-
indent
|
|
2246
|
-
});
|
|
2247
|
-
}
|
|
2248
|
-
return {
|
|
2249
|
-
paragraphs
|
|
2250
|
-
};
|
|
2251
|
-
}
|
|
2252
|
-
function applyImportedDocxParagraphIndentMarkers(document, markers) {
|
|
2253
|
-
const indentByMarker = new Map(markers.paragraphs.map(({ marker, indent })=>[
|
|
2254
|
-
marker,
|
|
2255
|
-
indent
|
|
2256
|
-
]));
|
|
2257
|
-
for (const node of work_docx_paragraph_indent_import_textNodes(document.body)){
|
|
2258
|
-
if (!node.data.includes('__A3S_WORK_PARAGRAPH_INDENT_')) continue;
|
|
2259
|
-
const block = work_docx_paragraph_indent_import_closestParagraphBlock(node.parentElement);
|
|
2260
|
-
node.data = node.data.replace(PARAGRAPH_INDENT_MARKER_PATTERN, (marker)=>{
|
|
2261
|
-
const indent = indentByMarker.get(marker);
|
|
2262
|
-
if (block && indent) applyParagraphIndent(block, indent);
|
|
2263
|
-
return '';
|
|
2264
|
-
});
|
|
2265
|
-
}
|
|
2266
|
-
document.body.normalize();
|
|
2267
|
-
}
|
|
2268
|
-
function hasImportedDocxParagraphIndentMarkers(markers) {
|
|
2269
|
-
return markers.paragraphs.length > 0;
|
|
2270
|
-
}
|
|
2271
|
-
function paragraphIndent(propertySources) {
|
|
2272
|
-
let left;
|
|
2273
|
-
let right;
|
|
2274
|
-
let firstLine;
|
|
2275
|
-
for (const properties of propertySources){
|
|
2276
|
-
const indent = directChild(properties, 'ind');
|
|
2277
|
-
if (!indent) continue;
|
|
2278
|
-
const sourceLeft = work_docx_paragraph_indent_import_numericAttribute(indent, 'start') ?? work_docx_paragraph_indent_import_numericAttribute(indent, 'left');
|
|
2279
|
-
const sourceRight = work_docx_paragraph_indent_import_numericAttribute(indent, 'end') ?? work_docx_paragraph_indent_import_numericAttribute(indent, 'right');
|
|
2280
|
-
const sourceFirstLine = work_docx_paragraph_indent_import_numericAttribute(indent, 'firstLine');
|
|
2281
|
-
const sourceHanging = work_docx_paragraph_indent_import_numericAttribute(indent, 'hanging');
|
|
2282
|
-
if (void 0 !== sourceLeft) left = sourceLeft;
|
|
2283
|
-
if (void 0 !== sourceRight) right = sourceRight;
|
|
2284
|
-
if (void 0 !== sourceFirstLine) firstLine = sourceFirstLine;
|
|
2285
|
-
else if (void 0 !== sourceHanging) firstLine = -sourceHanging;
|
|
2286
|
-
}
|
|
2287
|
-
return normalizeDocumentParagraphIndent({
|
|
2288
|
-
left: twipsToPixels(left),
|
|
2289
|
-
right: twipsToPixels(right),
|
|
2290
|
-
firstLine: twipsToPixels(firstLine)
|
|
2291
|
-
});
|
|
2292
|
-
}
|
|
2293
|
-
function work_docx_paragraph_indent_import_insertParagraphMarker(document, paragraph, properties, marker) {
|
|
2294
|
-
const run = document.createElementNS(work_docx_paragraph_indent_import_WORD_NAMESPACE, 'w:r');
|
|
2295
|
-
const text = document.createElementNS(work_docx_paragraph_indent_import_WORD_NAMESPACE, 'w:t');
|
|
2296
|
-
text.setAttributeNS(work_docx_paragraph_indent_import_XML_NAMESPACE, 'xml:space', 'preserve');
|
|
2297
|
-
text.textContent = marker;
|
|
2298
|
-
run.append(text);
|
|
2299
|
-
paragraph.insertBefore(run, properties.nextSibling);
|
|
2300
|
-
}
|
|
2301
|
-
function work_docx_paragraph_indent_import_insertParagraphProperties(document, paragraph) {
|
|
2302
|
-
const properties = document.createElementNS(work_docx_paragraph_indent_import_WORD_NAMESPACE, 'w:pPr');
|
|
2303
|
-
paragraph.insertBefore(properties, paragraph.firstChild);
|
|
2304
|
-
return properties;
|
|
2305
|
-
}
|
|
2306
|
-
function work_docx_paragraph_indent_import_closestParagraphBlock(element) {
|
|
2307
|
-
const block = element?.closest('p, h1, h2, h3, h4, h5, h6, blockquote');
|
|
2308
|
-
return block instanceof HTMLElement ? block : null;
|
|
2309
|
-
}
|
|
2310
|
-
function applyParagraphIndent(element, value) {
|
|
2311
|
-
const indent = normalizeDocumentParagraphIndent(value);
|
|
2312
|
-
if (indent.left) {
|
|
2313
|
-
element.dataset.officeIndentLevel = work_docx_paragraph_indent_import_formatNumber(indent.left / 24);
|
|
2314
|
-
element.style.marginLeft = `${work_docx_paragraph_indent_import_formatNumber(indent.left)}px`;
|
|
2315
|
-
}
|
|
2316
|
-
if (indent.right) {
|
|
2317
|
-
element.dataset.officeIndentRight = work_docx_paragraph_indent_import_formatNumber(indent.right);
|
|
2318
|
-
element.style.marginRight = `${work_docx_paragraph_indent_import_formatNumber(indent.right)}px`;
|
|
2319
|
-
}
|
|
2320
|
-
if (indent.firstLine) {
|
|
2321
|
-
element.dataset.officeIndentFirstLine = work_docx_paragraph_indent_import_formatNumber(indent.firstLine);
|
|
2322
|
-
element.style.textIndent = `${work_docx_paragraph_indent_import_formatNumber(indent.firstLine)}px`;
|
|
2323
|
-
}
|
|
2324
|
-
}
|
|
2325
|
-
function work_docx_paragraph_indent_import_numericAttribute(element, name) {
|
|
2326
|
-
const raw = attribute(element, name) ?? attribute(element, `w:${name}`);
|
|
2327
|
-
if (null === raw || !raw.trim()) return;
|
|
2328
|
-
const value = Number(raw);
|
|
2329
|
-
return Number.isFinite(value) ? value : void 0;
|
|
2330
|
-
}
|
|
2331
|
-
function twipsToPixels(value) {
|
|
2332
|
-
if (void 0 === value) return 0;
|
|
2333
|
-
return Math.round(value / TWIPS_PER_CSS_PIXEL);
|
|
2334
|
-
}
|
|
2335
|
-
function work_docx_paragraph_indent_import_formatNumber(value) {
|
|
2336
|
-
return Number(value.toFixed(2)).toString();
|
|
2337
|
-
}
|
|
2338
|
-
function work_docx_paragraph_indent_import_textNodes(root) {
|
|
2339
|
-
const document = root.ownerDocument;
|
|
2340
|
-
const walker = document?.createTreeWalker(root, NodeFilter.SHOW_TEXT);
|
|
2341
|
-
const nodes = [];
|
|
2342
|
-
if (!walker) return nodes;
|
|
2343
|
-
while(walker.nextNode())nodes.push(walker.currentNode);
|
|
2344
|
-
return nodes;
|
|
2345
|
-
}
|
|
2346
|
-
const work_docx_paragraph_pagination_import_WORD_NAMESPACE = 'http://schemas.openxmlformats.org/wordprocessingml/2006/main';
|
|
2347
|
-
const work_docx_paragraph_pagination_import_XML_NAMESPACE = 'http://www.w3.org/XML/1998/namespace';
|
|
2348
|
-
const PARAGRAPH_PAGINATION_MARKER_PATTERN = /__A3S_WORK_PARAGRAPH_PAGINATION_\d+__/g;
|
|
2349
|
-
function markDocxParagraphPagination(document, styleSource, tableStyleSource) {
|
|
2350
|
-
const paragraphs = [];
|
|
2351
|
-
const styles = resolveDocxParagraphStyleResolver(styleSource);
|
|
2352
|
-
const tableStyles = resolveDocxTableStyleResolver(tableStyleSource);
|
|
2353
|
-
for (const paragraph of descendants(document, 'p')){
|
|
2354
|
-
let properties = directChild(paragraph, 'pPr');
|
|
2355
|
-
if (properties && directChild(properties, 'numPr')) continue;
|
|
2356
|
-
const pagination = paragraphPagination(docxParagraphPropertySources(properties, styles, docxTableParagraphPropertySources(paragraph, tableStyles)));
|
|
2357
|
-
if (!Object.keys(pagination).length) continue;
|
|
2358
|
-
properties ??= work_docx_paragraph_pagination_import_insertParagraphProperties(document, paragraph);
|
|
2359
|
-
const marker = `__A3S_WORK_PARAGRAPH_PAGINATION_${paragraphs.length + 1}__`;
|
|
2360
|
-
work_docx_paragraph_pagination_import_insertParagraphMarker(document, paragraph, properties, marker);
|
|
2361
|
-
paragraphs.push({
|
|
2362
|
-
marker,
|
|
2363
|
-
pagination
|
|
2364
|
-
});
|
|
2365
|
-
}
|
|
2366
|
-
return {
|
|
2367
|
-
paragraphs
|
|
2368
|
-
};
|
|
2369
|
-
}
|
|
2370
|
-
function applyImportedDocxParagraphPaginationMarkers(document, markers) {
|
|
2371
|
-
const paginationByMarker = new Map(markers.paragraphs.map(({ marker, pagination })=>[
|
|
2372
|
-
marker,
|
|
2373
|
-
pagination
|
|
2374
|
-
]));
|
|
2375
|
-
for (const node of work_docx_paragraph_pagination_import_textNodes(document.body)){
|
|
2376
|
-
if (!node.data.includes('__A3S_WORK_PARAGRAPH_PAGINATION_')) continue;
|
|
2377
|
-
const block = work_docx_paragraph_pagination_import_closestParagraphBlock(node.parentElement);
|
|
2378
|
-
node.data = node.data.replace(PARAGRAPH_PAGINATION_MARKER_PATTERN, (marker)=>{
|
|
2379
|
-
const pagination = paginationByMarker.get(marker);
|
|
2380
|
-
if (block && pagination) applyParagraphPagination(block, pagination);
|
|
2381
|
-
return '';
|
|
2382
|
-
});
|
|
2383
|
-
}
|
|
2384
|
-
document.body.normalize();
|
|
2385
|
-
}
|
|
2386
|
-
function hasImportedDocxParagraphPaginationMarkers(markers) {
|
|
2387
|
-
return markers.paragraphs.length > 0;
|
|
2388
|
-
}
|
|
2389
|
-
function paragraphPagination(sources) {
|
|
2390
|
-
const pagination = {};
|
|
2391
|
-
for (const properties of sources){
|
|
2392
|
-
const keepLines = directChild(properties, 'keepLines');
|
|
2393
|
-
const keepWithNext = directChild(properties, 'keepNext');
|
|
2394
|
-
const pageBreakBefore = directChild(properties, 'pageBreakBefore');
|
|
2395
|
-
const widowControl = directChild(properties, 'widowControl');
|
|
2396
|
-
const contextualSpacing = directChild(properties, 'contextualSpacing');
|
|
2397
|
-
const outlineLevel = directChild(properties, 'outlineLvl');
|
|
2398
|
-
const defaultCollapsed = parseDocxParagraphDefaultCollapsed(properties);
|
|
2399
|
-
if (keepLines) pagination.keepLines = work_docx_paragraph_pagination_import_onOffValue(keepLines);
|
|
2400
|
-
if (keepWithNext) pagination.keepWithNext = work_docx_paragraph_pagination_import_onOffValue(keepWithNext);
|
|
2401
|
-
if (pageBreakBefore) pagination.pageBreakBefore = work_docx_paragraph_pagination_import_onOffValue(pageBreakBefore);
|
|
2402
|
-
if (widowControl) pagination.widowControl = work_docx_paragraph_pagination_import_onOffValue(widowControl);
|
|
2403
|
-
if (contextualSpacing) pagination.contextualSpacing = work_docx_paragraph_pagination_import_onOffValue(contextualSpacing);
|
|
2404
|
-
const outline = integerValue(outlineLevel);
|
|
2405
|
-
if (null !== outline && outline <= 9) pagination.outlineLevel = outline;
|
|
2406
|
-
if ('valid' === defaultCollapsed.status) pagination.defaultCollapsed = defaultCollapsed.value;
|
|
2407
|
-
else if ('invalid' === defaultCollapsed.status) delete pagination.defaultCollapsed;
|
|
2408
|
-
}
|
|
2409
|
-
return pagination;
|
|
2410
|
-
}
|
|
2411
|
-
function work_docx_paragraph_pagination_import_onOffValue(element) {
|
|
2412
|
-
const value = (attribute(element, 'val') ?? attribute(element, 'w:val'))?.trim().toLowerCase();
|
|
2413
|
-
return '0' !== value && 'false' !== value && 'off' !== value;
|
|
2414
|
-
}
|
|
2415
|
-
function work_docx_paragraph_pagination_import_insertParagraphMarker(document, paragraph, properties, marker) {
|
|
2416
|
-
const run = document.createElementNS(work_docx_paragraph_pagination_import_WORD_NAMESPACE, 'w:r');
|
|
2417
|
-
const text = document.createElementNS(work_docx_paragraph_pagination_import_WORD_NAMESPACE, 'w:t');
|
|
2418
|
-
text.setAttributeNS(work_docx_paragraph_pagination_import_XML_NAMESPACE, 'xml:space', 'preserve');
|
|
2419
|
-
text.textContent = marker;
|
|
2420
|
-
run.append(text);
|
|
2421
|
-
paragraph.insertBefore(run, properties.nextSibling);
|
|
2422
|
-
}
|
|
2423
|
-
function work_docx_paragraph_pagination_import_insertParagraphProperties(document, paragraph) {
|
|
2424
|
-
const properties = document.createElementNS(work_docx_paragraph_pagination_import_WORD_NAMESPACE, 'w:pPr');
|
|
2425
|
-
paragraph.insertBefore(properties, paragraph.firstChild);
|
|
2426
|
-
return properties;
|
|
2427
|
-
}
|
|
2428
|
-
function work_docx_paragraph_pagination_import_closestParagraphBlock(element) {
|
|
2429
|
-
const block = element?.closest('p, h1, h2, h3, h4, h5, h6, blockquote');
|
|
2430
|
-
return block instanceof HTMLElement ? block : null;
|
|
2431
|
-
}
|
|
2432
|
-
function applyParagraphPagination(element, pagination) {
|
|
2433
|
-
setBooleanAttribute(element, 'data-office-keep-lines', pagination.keepLines);
|
|
2434
|
-
setBooleanAttribute(element, 'data-office-keep-with-next', pagination.keepWithNext);
|
|
2435
|
-
setBooleanAttribute(element, 'data-office-page-break-before', pagination.pageBreakBefore);
|
|
2436
|
-
setBooleanAttribute(element, 'data-office-widow-control', pagination.widowControl);
|
|
2437
|
-
setBooleanAttribute(element, 'data-office-contextual-spacing', pagination.contextualSpacing);
|
|
2438
|
-
setBooleanAttribute(element, 'data-office-default-collapsed', pagination.defaultCollapsed);
|
|
2439
|
-
if (void 0 !== pagination.outlineLevel) element.dataset.officeOutlineLevel = String(pagination.outlineLevel);
|
|
2440
|
-
}
|
|
2441
|
-
function integerValue(element) {
|
|
2442
|
-
if (!element) return null;
|
|
2443
|
-
const value = Number(attribute(element, 'val') ?? attribute(element, 'w:val'));
|
|
2444
|
-
return Number.isSafeInteger(value) && value >= 0 ? value : null;
|
|
2445
|
-
}
|
|
2446
|
-
function setBooleanAttribute(element, name, value) {
|
|
2447
|
-
if (void 0 !== value) element.setAttribute(name, String(value));
|
|
2448
|
-
}
|
|
2449
|
-
function work_docx_paragraph_pagination_import_textNodes(root) {
|
|
2450
|
-
const document = root.ownerDocument;
|
|
2451
|
-
const walker = document?.createTreeWalker(root, NodeFilter.SHOW_TEXT);
|
|
2452
|
-
const nodes = [];
|
|
2453
|
-
if (!walker) return nodes;
|
|
2454
|
-
while(walker.nextNode())nodes.push(walker.currentNode);
|
|
2455
|
-
return nodes;
|
|
2456
|
-
}
|
|
2457
|
-
const work_docx_paragraph_spacing_import_WORD_NAMESPACE = 'http://schemas.openxmlformats.org/wordprocessingml/2006/main';
|
|
2458
|
-
const work_docx_paragraph_spacing_import_XML_NAMESPACE = 'http://www.w3.org/XML/1998/namespace';
|
|
2459
|
-
const PARAGRAPH_SPACING_MARKER_PATTERN = /__A3S_WORK_PARAGRAPH_SPACING_\d+__/g;
|
|
2460
|
-
function markDocxParagraphSpacing(document, styleSource, tableStyleSource) {
|
|
2461
|
-
const paragraphs = [];
|
|
2462
|
-
const styles = resolveDocxParagraphStyleResolver(styleSource);
|
|
2463
|
-
const tableStyles = resolveDocxTableStyleResolver(tableStyleSource);
|
|
2464
|
-
for (const paragraph of descendants(document, 'p')){
|
|
2465
|
-
let properties = directChild(paragraph, 'pPr');
|
|
2466
|
-
const sources = docxParagraphPropertySources(properties, styles, docxTableParagraphPropertySources(paragraph, tableStyles));
|
|
2467
|
-
if (sources.some((source)=>directChild(source, 'numPr'))) continue;
|
|
2468
|
-
const spacing = paragraphSpacing(sources);
|
|
2469
|
-
if (!Object.keys(spacing).length) continue;
|
|
2470
|
-
properties ??= work_docx_paragraph_spacing_import_insertParagraphProperties(document, paragraph);
|
|
2471
|
-
const marker = `__A3S_WORK_PARAGRAPH_SPACING_${paragraphs.length + 1}__`;
|
|
2472
|
-
work_docx_paragraph_spacing_import_insertParagraphMarker(document, paragraph, properties, marker);
|
|
2473
|
-
paragraphs.push({
|
|
2474
|
-
marker,
|
|
2475
|
-
spacing
|
|
2476
|
-
});
|
|
2477
|
-
}
|
|
2478
|
-
return {
|
|
2479
|
-
paragraphs
|
|
2480
|
-
};
|
|
2481
|
-
}
|
|
2482
|
-
function applyImportedDocxParagraphSpacingMarkers(document, markers) {
|
|
2483
|
-
const spacingByMarker = new Map(markers.paragraphs.map(({ marker, spacing })=>[
|
|
2484
|
-
marker,
|
|
2485
|
-
spacing
|
|
2486
|
-
]));
|
|
2487
|
-
for (const node of work_docx_paragraph_spacing_import_textNodes(document.body)){
|
|
2488
|
-
if (!node.data.includes('__A3S_WORK_PARAGRAPH_SPACING_')) continue;
|
|
2489
|
-
const block = work_docx_paragraph_spacing_import_closestParagraphBlock(node.parentElement);
|
|
2490
|
-
node.data = node.data.replace(PARAGRAPH_SPACING_MARKER_PATTERN, (marker)=>{
|
|
2491
|
-
const spacing = spacingByMarker.get(marker);
|
|
2492
|
-
if (block && spacing) applyParagraphSpacing(block, spacing);
|
|
2493
|
-
return '';
|
|
2494
|
-
});
|
|
2495
|
-
}
|
|
2496
|
-
document.body.normalize();
|
|
2497
|
-
}
|
|
2498
|
-
function hasImportedDocxParagraphSpacingMarkers(markers) {
|
|
2499
|
-
return markers.paragraphs.length > 0;
|
|
2500
|
-
}
|
|
2501
|
-
function paragraphSpacing(propertySources) {
|
|
2502
|
-
let before;
|
|
2503
|
-
let after;
|
|
2504
|
-
let line;
|
|
2505
|
-
let lineRule;
|
|
2506
|
-
for (const properties of propertySources){
|
|
2507
|
-
const spacing = directChild(properties, 'spacing');
|
|
2508
|
-
if (!spacing) continue;
|
|
2509
|
-
const sourceBefore = work_docx_paragraph_spacing_import_numericAttribute(spacing, 'before');
|
|
2510
|
-
const sourceAfter = work_docx_paragraph_spacing_import_numericAttribute(spacing, 'after');
|
|
2511
|
-
const sourceLine = work_docx_paragraph_spacing_import_numericAttribute(spacing, 'line');
|
|
2512
|
-
const sourceLineRule = normalizedLineRule(work_docx_paragraph_spacing_import_wordAttribute(spacing, 'lineRule'));
|
|
2513
|
-
if (void 0 !== sourceBefore) before = sourceBefore;
|
|
2514
|
-
if (void 0 !== sourceAfter) after = sourceAfter;
|
|
2515
|
-
if (void 0 !== sourceLine) {
|
|
2516
|
-
line = sourceLine;
|
|
2517
|
-
lineRule = sourceLineRule ?? 'auto';
|
|
2518
|
-
} else if (sourceLineRule) lineRule = sourceLineRule;
|
|
2519
|
-
}
|
|
2520
|
-
const result = {};
|
|
2521
|
-
if (void 0 !== before) result.before = twipsToPoints(before);
|
|
2522
|
-
if (void 0 !== after) result.after = twipsToPoints(after);
|
|
2523
|
-
if (void 0 !== line) {
|
|
2524
|
-
const rule = lineRule ?? 'auto';
|
|
2525
|
-
result.lineHeight = 'auto' === rule ? work_docx_paragraph_spacing_import_formatNumber(line / 240) : `${work_docx_paragraph_spacing_import_formatNumber(line / 20)}pt`;
|
|
2526
|
-
result.lineRule = rule;
|
|
2527
|
-
}
|
|
2528
|
-
return result;
|
|
2529
|
-
}
|
|
2530
|
-
function applyParagraphSpacing(element, spacing) {
|
|
2531
|
-
if (void 0 !== spacing.before && null !== spacing.before) {
|
|
2532
|
-
const value = work_docx_paragraph_spacing_import_formatNumber(spacing.before);
|
|
2533
|
-
element.dataset.officeSpaceBefore = value;
|
|
2534
|
-
element.style.marginTop = `${value}pt`;
|
|
2535
|
-
}
|
|
2536
|
-
if (void 0 !== spacing.after && null !== spacing.after) {
|
|
2537
|
-
const value = work_docx_paragraph_spacing_import_formatNumber(spacing.after);
|
|
2538
|
-
element.dataset.officeSpaceAfter = value;
|
|
2539
|
-
element.style.marginBottom = `${value}pt`;
|
|
2540
|
-
}
|
|
2541
|
-
if (spacing.lineHeight) element.style.lineHeight = spacing.lineHeight;
|
|
2542
|
-
if (spacing.lineRule) element.dataset.officeLineRule = spacing.lineRule;
|
|
2543
|
-
if ('auto' === spacing.lineRule) {
|
|
2544
|
-
const autoLineHeight = documentAutoLineHeight(spacing.lineHeight);
|
|
2545
|
-
for (const [name, value] of Object.entries(renderDocumentAutoLineHeight(spacing.lineHeight, autoLineHeight)))if ('style' === name) for (const declaration of value.split(';')){
|
|
2546
|
-
const separator = declaration.indexOf(':');
|
|
2547
|
-
if (!(separator < 0)) element.style.setProperty(declaration.slice(0, separator).trim(), declaration.slice(separator + 1).trim());
|
|
2548
|
-
}
|
|
2549
|
-
else element.setAttribute(name, value);
|
|
2550
|
-
}
|
|
2551
|
-
}
|
|
2552
|
-
function work_docx_paragraph_spacing_import_insertParagraphMarker(document, paragraph, properties, marker) {
|
|
2553
|
-
const run = document.createElementNS(work_docx_paragraph_spacing_import_WORD_NAMESPACE, 'w:r');
|
|
2554
|
-
const text = document.createElementNS(work_docx_paragraph_spacing_import_WORD_NAMESPACE, 'w:t');
|
|
2555
|
-
text.setAttributeNS(work_docx_paragraph_spacing_import_XML_NAMESPACE, 'xml:space', 'preserve');
|
|
2556
|
-
text.textContent = marker;
|
|
2557
|
-
run.append(text);
|
|
2558
|
-
paragraph.insertBefore(run, properties.nextSibling);
|
|
2559
|
-
}
|
|
2560
|
-
function work_docx_paragraph_spacing_import_insertParagraphProperties(document, paragraph) {
|
|
2561
|
-
const properties = document.createElementNS(work_docx_paragraph_spacing_import_WORD_NAMESPACE, 'w:pPr');
|
|
2562
|
-
paragraph.insertBefore(properties, paragraph.firstChild);
|
|
2563
|
-
return properties;
|
|
2564
|
-
}
|
|
2565
|
-
function work_docx_paragraph_spacing_import_closestParagraphBlock(element) {
|
|
2566
|
-
const block = element?.closest('p, h1, h2, h3, h4, h5, h6, blockquote');
|
|
2567
|
-
return block instanceof HTMLElement ? block : null;
|
|
2568
|
-
}
|
|
2569
|
-
function work_docx_paragraph_spacing_import_numericAttribute(element, name) {
|
|
2570
|
-
const raw = work_docx_paragraph_spacing_import_wordAttribute(element, name);
|
|
2571
|
-
if (null === raw || !raw.trim()) return;
|
|
2572
|
-
const value = Number(raw);
|
|
2573
|
-
return Number.isFinite(value) ? value : void 0;
|
|
2574
|
-
}
|
|
2575
|
-
function work_docx_paragraph_spacing_import_wordAttribute(element, name) {
|
|
2576
|
-
return attribute(element, name) ?? attribute(element, `w:${name}`);
|
|
2577
|
-
}
|
|
2578
|
-
function normalizedLineRule(value) {
|
|
2579
|
-
if ('auto' === value || 'atLeast' === value) return value;
|
|
2580
|
-
if ('exact' === value || 'exactly' === value) return 'exact';
|
|
2581
|
-
}
|
|
2582
|
-
function twipsToPoints(value) {
|
|
2583
|
-
return Number((value / 20).toFixed(2));
|
|
2584
|
-
}
|
|
2585
|
-
function work_docx_paragraph_spacing_import_formatNumber(value) {
|
|
2586
|
-
return Number(value.toFixed(3)).toString();
|
|
2587
|
-
}
|
|
2588
|
-
function work_docx_paragraph_spacing_import_textNodes(root) {
|
|
2589
|
-
const document = root.ownerDocument;
|
|
2590
|
-
const walker = document?.createTreeWalker(root, NodeFilter.SHOW_TEXT);
|
|
2591
|
-
const nodes = [];
|
|
2592
|
-
if (!walker) return nodes;
|
|
2593
|
-
while(walker.nextNode())nodes.push(walker.currentNode);
|
|
2594
|
-
return nodes;
|
|
2595
|
-
}
|
|
2596
|
-
const work_docx_run_formatting_import_WORD_NAMESPACE = 'http://schemas.openxmlformats.org/wordprocessingml/2006/main';
|
|
2597
|
-
const work_docx_run_formatting_import_XML_NAMESPACE = 'http://www.w3.org/XML/1998/namespace';
|
|
2598
|
-
const RUN_FORMATTING_MARKER_PATTERN = /__A3S_WORK_RUN_(?:START|END)_\d+__/g;
|
|
2599
|
-
function markDocxRunFormatting(document, styleSource, themeSource, tableStyleSource) {
|
|
2600
|
-
const runs = [];
|
|
2601
|
-
const styles = resolveDocxParagraphStyleResolver(styleSource);
|
|
2602
|
-
const theme = resolveDocxThemeResolver(themeSource);
|
|
2603
|
-
const tableStyles = resolveDocxTableStyleResolver(tableStyleSource);
|
|
2604
|
-
for (const run of descendants(document, 'r')){
|
|
2605
|
-
const runText = directRunText(run);
|
|
2606
|
-
if (!runText || runText.includes('__A3S_')) continue;
|
|
2607
|
-
const paragraph = work_docx_run_formatting_import_closestAncestor(run, 'p');
|
|
2608
|
-
if (!paragraph) continue;
|
|
2609
|
-
const paragraphProperties = directChild(paragraph, 'pPr');
|
|
2610
|
-
const runProperties = directChild(run, 'rPr');
|
|
2611
|
-
const formatting = resolvedRunFormatting(docxRunPropertySources(paragraphProperties, runProperties, styles, docxTableRunPropertySources(run, tableStyles)), theme, runText);
|
|
2612
|
-
if (!Object.keys(formatting).length) continue;
|
|
2613
|
-
const index = runs.length + 1;
|
|
2614
|
-
const startMarker = `__A3S_WORK_RUN_START_${index}__`;
|
|
2615
|
-
const endMarker = `__A3S_WORK_RUN_END_${index}__`;
|
|
2616
|
-
insertRunMarkers(document, run, runProperties, startMarker, endMarker);
|
|
2617
|
-
runs.push({
|
|
2618
|
-
startMarker,
|
|
2619
|
-
endMarker,
|
|
2620
|
-
formatting
|
|
2621
|
-
});
|
|
2622
|
-
}
|
|
2623
|
-
return {
|
|
2624
|
-
runs
|
|
2625
|
-
};
|
|
2626
|
-
}
|
|
2627
|
-
function applyImportedDocxRunFormattingMarkers(document, markers) {
|
|
2628
|
-
const replacements = new Map();
|
|
2629
|
-
for (const marker of markers.runs){
|
|
2630
|
-
const markup = formattingMarkup(document, marker.formatting);
|
|
2631
|
-
replacements.set(marker.startMarker, markup.start);
|
|
2632
|
-
replacements.set(marker.endMarker, markup.end);
|
|
2633
|
-
}
|
|
2634
|
-
document.body.innerHTML = document.body.innerHTML.replace(RUN_FORMATTING_MARKER_PATTERN, (marker)=>replacements.get(marker) ?? '');
|
|
2635
|
-
}
|
|
2636
|
-
function hasImportedDocxRunFormattingMarkers(markers) {
|
|
2637
|
-
return markers.runs.length > 0;
|
|
2638
|
-
}
|
|
2639
|
-
function resolvedRunFormatting(propertySources, theme, runText) {
|
|
2640
|
-
const fonts = {};
|
|
2641
|
-
let fontSize;
|
|
2642
|
-
let complexFontSize;
|
|
2643
|
-
let color;
|
|
2644
|
-
let backgroundColor;
|
|
2645
|
-
let themeColor;
|
|
2646
|
-
let themeFill;
|
|
2647
|
-
let bold;
|
|
2648
|
-
let complexBold;
|
|
2649
|
-
let italic;
|
|
2650
|
-
let complexItalic;
|
|
2651
|
-
let underline;
|
|
2652
|
-
let strike;
|
|
2653
|
-
let snapToGrid;
|
|
2654
|
-
let complexScriptFormatting;
|
|
2655
|
-
let rightToLeft;
|
|
2656
|
-
let fontHint;
|
|
2657
|
-
for (const properties of propertySources){
|
|
2658
|
-
bold = overriddenBoolean(bold, onOffProperty(properties, 'b'));
|
|
2659
|
-
complexBold = overriddenBoolean(complexBold, onOffProperty(properties, 'bCs'));
|
|
2660
|
-
italic = overriddenBoolean(italic, onOffProperty(properties, 'i'));
|
|
2661
|
-
complexItalic = overriddenBoolean(complexItalic, onOffProperty(properties, 'iCs'));
|
|
2662
|
-
underline = overriddenBoolean(underline, underlineProperty(properties));
|
|
2663
|
-
strike = overriddenBoolean(strike, onOffProperty(properties, 'strike'));
|
|
2664
|
-
strike = overriddenBoolean(strike, onOffProperty(properties, 'dstrike'));
|
|
2665
|
-
snapToGrid = overriddenBoolean(snapToGrid, onOffProperty(properties, 'snapToGrid'));
|
|
2666
|
-
complexScriptFormatting = overriddenBoolean(complexScriptFormatting, onOffProperty(properties, 'cs'));
|
|
2667
|
-
rightToLeft = overriddenBoolean(rightToLeft, onOffProperty(properties, 'rtl'));
|
|
2668
|
-
const runFonts = directChild(properties, 'rFonts');
|
|
2669
|
-
if (runFonts) {
|
|
2670
|
-
fontHint = resolvedFontHint(runFonts) ?? fontHint;
|
|
2671
|
-
assignFont(fonts, 'ascii', resolvedFont(runFonts, 'ascii', 'asciiTheme', theme));
|
|
2672
|
-
assignFont(fonts, 'hAnsi', resolvedFont(runFonts, 'hAnsi', 'hAnsiTheme', theme));
|
|
2673
|
-
assignFont(fonts, 'eastAsia', resolvedFont(runFonts, 'eastAsia', 'eastAsiaTheme', theme));
|
|
2674
|
-
assignFont(fonts, 'complex', resolvedFont(runFonts, 'cs', 'cstheme', theme));
|
|
2675
|
-
}
|
|
2676
|
-
const size = work_docx_run_formatting_import_numericAttribute(directChild(properties, 'sz'), 'val');
|
|
2677
|
-
if (void 0 !== size && size > 0) fontSize = Math.min(512, size / 2);
|
|
2678
|
-
const complexSize = work_docx_run_formatting_import_numericAttribute(directChild(properties, 'szCs'), 'val');
|
|
2679
|
-
if (void 0 !== complexSize && complexSize > 0) complexFontSize = Math.min(512, complexSize / 2);
|
|
2680
|
-
const colorElement = directChild(properties, 'color');
|
|
2681
|
-
if (colorElement) {
|
|
2682
|
-
const value = work_docx_run_formatting_import_wordAttribute(colorElement, 'val')?.trim();
|
|
2683
|
-
const themed = docxThemeColor(theme, work_docx_run_formatting_import_wordAttribute(colorElement, 'themeColor'), work_docx_run_formatting_import_wordAttribute(colorElement, 'themeTint'), work_docx_run_formatting_import_wordAttribute(colorElement, 'themeShade'));
|
|
2684
|
-
if (themed) {
|
|
2685
|
-
color = `#${themed}`;
|
|
2686
|
-
themeColor = themeReference(colorElement, 'themeColor', 'themeTint', 'themeShade', color);
|
|
2687
|
-
} else if (value?.toLowerCase() === 'auto') {
|
|
2688
|
-
color = 'inherit';
|
|
2689
|
-
themeColor = void 0;
|
|
2690
|
-
} else if (value && /^[0-9a-f]{6}$/i.test(value)) {
|
|
2691
|
-
color = `#${value.toLowerCase()}`;
|
|
2692
|
-
themeColor = void 0;
|
|
2693
|
-
}
|
|
2694
|
-
}
|
|
2695
|
-
const highlight = directChild(properties, 'highlight');
|
|
2696
|
-
if (highlight) {
|
|
2697
|
-
const value = work_docx_run_formatting_import_wordAttribute(highlight, 'val')?.trim().toLowerCase();
|
|
2698
|
-
if (value) {
|
|
2699
|
-
backgroundColor = wordHighlightColor(value);
|
|
2700
|
-
themeFill = void 0;
|
|
2701
|
-
}
|
|
2702
|
-
} else {
|
|
2703
|
-
const shading = directChild(properties, 'shd');
|
|
2704
|
-
const fill = shading ? work_docx_run_formatting_import_wordAttribute(shading, 'fill')?.trim() : void 0;
|
|
2705
|
-
const themed = shading ? docxThemeColor(theme, work_docx_run_formatting_import_wordAttribute(shading, 'themeFill'), work_docx_run_formatting_import_wordAttribute(shading, 'themeFillTint'), work_docx_run_formatting_import_wordAttribute(shading, 'themeFillShade')) : void 0;
|
|
2706
|
-
if (themed) {
|
|
2707
|
-
backgroundColor = `#${themed}`;
|
|
2708
|
-
themeFill = themeReference(shading, 'themeFill', 'themeFillTint', 'themeFillShade', backgroundColor);
|
|
2709
|
-
} else if (fill?.toLowerCase() === 'auto') {
|
|
2710
|
-
backgroundColor = 'transparent';
|
|
2711
|
-
themeFill = void 0;
|
|
2712
|
-
} else if (fill && /^[0-9a-f]{6}$/i.test(fill)) {
|
|
2713
|
-
backgroundColor = `#${fill.toLowerCase()}`;
|
|
2714
|
-
themeFill = void 0;
|
|
2715
|
-
}
|
|
2716
|
-
}
|
|
2717
|
-
}
|
|
2718
|
-
const fontSlot = true === complexScriptFormatting || true === rightToLeft ? 'complex' : docxFontSlotForText(runText, fontHint);
|
|
2719
|
-
const usesComplexFormatting = 'complex' === fontSlot;
|
|
2720
|
-
const resolvedBold = usesComplexFormatting ? complexBold ?? bold : bold;
|
|
2721
|
-
const resolvedItalic = usesComplexFormatting ? complexItalic ?? italic : italic;
|
|
2722
|
-
const resolvedFontSize = usesComplexFormatting ? complexFontSize ?? fontSize : fontSize;
|
|
2723
|
-
let fontFamily = uniqueFonts(orderedFonts(fonts, fontSlot));
|
|
2724
|
-
if (!fontFamily) fontFamily = uniqueFonts(orderedFonts({
|
|
2725
|
-
ascii: docxThemeFont(theme, 'minorAscii'),
|
|
2726
|
-
hAnsi: docxThemeFont(theme, 'minorHAnsi'),
|
|
2727
|
-
eastAsia: docxThemeFont(theme, 'minorEastAsia'),
|
|
2728
|
-
complex: docxThemeFont(theme, 'minorBidi')
|
|
2729
|
-
}, fontSlot));
|
|
2730
|
-
const hasRunPropertySource = propertySources.length > 0;
|
|
2731
|
-
return {
|
|
2732
|
-
...void 0 !== resolvedBold || hasRunPropertySource ? {
|
|
2733
|
-
bold: resolvedBold ?? false
|
|
2734
|
-
} : {},
|
|
2735
|
-
...void 0 !== resolvedItalic || hasRunPropertySource ? {
|
|
2736
|
-
italic: resolvedItalic ?? false
|
|
2737
|
-
} : {},
|
|
2738
|
-
...void 0 !== underline || hasRunPropertySource ? {
|
|
2739
|
-
underline: underline ?? false
|
|
2740
|
-
} : {},
|
|
2741
|
-
...void 0 !== strike || hasRunPropertySource ? {
|
|
2742
|
-
strike: strike ?? false
|
|
2743
|
-
} : {},
|
|
2744
|
-
...fontFamily ? {
|
|
2745
|
-
fontFamily,
|
|
2746
|
-
wordLineHeightFactor: documentWordLineHeightFactor(fontFamily)
|
|
2747
|
-
} : {},
|
|
2748
|
-
...void 0 !== resolvedFontSize ? {
|
|
2749
|
-
fontSize: resolvedFontSize
|
|
2750
|
-
} : {},
|
|
2751
|
-
...void 0 !== snapToGrid ? {
|
|
2752
|
-
wordSnapToGrid: snapToGrid
|
|
2753
|
-
} : {},
|
|
2754
|
-
...color ? {
|
|
2755
|
-
color
|
|
2756
|
-
} : {},
|
|
2757
|
-
...backgroundColor ? {
|
|
2758
|
-
backgroundColor
|
|
2759
|
-
} : {},
|
|
2760
|
-
...themeColor ? {
|
|
2761
|
-
themeColor
|
|
2762
|
-
} : {},
|
|
2763
|
-
...themeFill ? {
|
|
2764
|
-
themeFill
|
|
2765
|
-
} : {}
|
|
2766
|
-
};
|
|
2767
|
-
}
|
|
2768
|
-
function insertRunMarkers(document, run, properties, startMarker, endMarker) {
|
|
2769
|
-
const start = work_docx_run_formatting_import_markerText(document, startMarker);
|
|
2770
|
-
const end = work_docx_run_formatting_import_markerText(document, endMarker);
|
|
2771
|
-
run.insertBefore(start, properties?.nextSibling ?? run.firstChild);
|
|
2772
|
-
run.append(end);
|
|
2773
|
-
}
|
|
2774
|
-
function work_docx_run_formatting_import_markerText(document, marker) {
|
|
2775
|
-
const text = document.createElementNS(work_docx_run_formatting_import_WORD_NAMESPACE, 'w:t');
|
|
2776
|
-
text.setAttributeNS(work_docx_run_formatting_import_XML_NAMESPACE, 'xml:space', 'preserve');
|
|
2777
|
-
text.textContent = marker;
|
|
2778
|
-
return text;
|
|
2779
|
-
}
|
|
2780
|
-
function formattingMarkup(document, formatting) {
|
|
2781
|
-
const span = document.createElement('span');
|
|
2782
|
-
if (false === formatting.bold) span.style.fontWeight = 'normal';
|
|
2783
|
-
if (false === formatting.italic) span.style.fontStyle = 'normal';
|
|
2784
|
-
if ((false === formatting.underline || false === formatting.strike) && !formatting.underline && !formatting.strike) span.style.textDecorationLine = 'none';
|
|
2785
|
-
if (formatting.fontFamily) span.style.fontFamily = formatting.fontFamily;
|
|
2786
|
-
if (void 0 !== formatting.wordLineHeightFactor) {
|
|
2787
|
-
const factor = formatLineHeightFactor(formatting.wordLineHeightFactor);
|
|
2788
|
-
span.dataset.officeWordLineHeightFactor = factor;
|
|
2789
|
-
span.style.setProperty('--work-document-word-line-height-factor', factor);
|
|
2790
|
-
}
|
|
2791
|
-
if (void 0 !== formatting.wordSnapToGrid) span.dataset.officeWordSnapToGrid = String(formatting.wordSnapToGrid);
|
|
2792
|
-
if (void 0 !== formatting.fontSize) span.style.fontSize = `${work_docx_run_formatting_import_formatNumber(formatting.fontSize)}pt`;
|
|
2793
|
-
if (formatting.color) span.style.color = formatting.color;
|
|
2794
|
-
const themeColor = serializeDocxThemeReference(formatting.themeColor ?? null);
|
|
2795
|
-
if (themeColor) span.dataset.officeThemeColor = themeColor;
|
|
2796
|
-
if (formatting.backgroundColor) span.style.backgroundColor = formatting.backgroundColor;
|
|
2797
|
-
const themeFill = serializeDocxThemeReference(formatting.themeFill ?? null);
|
|
2798
|
-
if (themeFill) span.dataset.officeThemeFill = themeFill;
|
|
2799
|
-
const html = span.outerHTML;
|
|
2800
|
-
const tags = [
|
|
2801
|
-
...formatting.bold ? [
|
|
2802
|
-
'strong'
|
|
2803
|
-
] : [],
|
|
2804
|
-
...formatting.italic ? [
|
|
2805
|
-
'em'
|
|
2806
|
-
] : [],
|
|
2807
|
-
...formatting.underline ? [
|
|
2808
|
-
'u'
|
|
2809
|
-
] : [],
|
|
2810
|
-
...formatting.strike ? [
|
|
2811
|
-
's'
|
|
2812
|
-
] : []
|
|
2813
|
-
];
|
|
2814
|
-
return {
|
|
2815
|
-
start: `${html.slice(0, html.indexOf('>') + 1)}${tags.map((tag)=>`<${tag}>`).join('')}`,
|
|
2816
|
-
end: `${[
|
|
2817
|
-
...tags
|
|
2818
|
-
].reverse().map((tag)=>`</${tag}>`).join('')}</span>`
|
|
2819
|
-
};
|
|
2820
|
-
}
|
|
2821
|
-
function themeReference(element, themeName, tintName, shadeName, resolved) {
|
|
2822
|
-
const theme = work_docx_run_formatting_import_wordAttribute(element, themeName)?.trim();
|
|
2823
|
-
if (!theme) return;
|
|
2824
|
-
const tint = normalizedByteHex(work_docx_run_formatting_import_wordAttribute(element, tintName));
|
|
2825
|
-
const shade = normalizedByteHex(work_docx_run_formatting_import_wordAttribute(element, shadeName));
|
|
2826
|
-
return {
|
|
2827
|
-
theme,
|
|
2828
|
-
resolved,
|
|
2829
|
-
...tint ? {
|
|
2830
|
-
tint
|
|
2831
|
-
} : {},
|
|
2832
|
-
...shade ? {
|
|
2833
|
-
shade
|
|
2834
|
-
} : {}
|
|
2835
|
-
};
|
|
2836
|
-
}
|
|
2837
|
-
function normalizedByteHex(value) {
|
|
2838
|
-
const normalized = value?.trim().toUpperCase();
|
|
2839
|
-
return normalized && /^[0-9A-F]{2}$/.test(normalized) ? normalized : void 0;
|
|
2840
|
-
}
|
|
2841
|
-
function overriddenBoolean(current, next) {
|
|
2842
|
-
return void 0 === next ? current : next;
|
|
2843
|
-
}
|
|
2844
|
-
function onOffProperty(properties, propertyName) {
|
|
2845
|
-
const element = directChild(properties, propertyName);
|
|
2846
|
-
if (!element) return;
|
|
2847
|
-
const value = work_docx_run_formatting_import_wordAttribute(element, 'val')?.trim().toLowerCase();
|
|
2848
|
-
return '0' !== value && 'false' !== value && 'off' !== value;
|
|
2849
|
-
}
|
|
2850
|
-
function underlineProperty(properties) {
|
|
2851
|
-
const element = directChild(properties, 'u');
|
|
2852
|
-
if (!element) return;
|
|
2853
|
-
const value = work_docx_run_formatting_import_wordAttribute(element, 'val')?.trim().toLowerCase();
|
|
2854
|
-
return '0' !== value && 'false' !== value && 'off' !== value && 'none' !== value;
|
|
2855
|
-
}
|
|
2856
|
-
function directRunText(run) {
|
|
2857
|
-
return Array.from(run.children).filter((child)=>'t' === child.localName || 'delText' === child.localName).map((child)=>child.textContent ?? '').join('');
|
|
2858
|
-
}
|
|
2859
|
-
function work_docx_run_formatting_import_closestAncestor(element, localName) {
|
|
2860
|
-
let current = element.parentElement;
|
|
2861
|
-
while(current){
|
|
2862
|
-
if (current.localName === localName) return current;
|
|
2863
|
-
current = current.parentElement;
|
|
2864
|
-
}
|
|
2865
|
-
return null;
|
|
2866
|
-
}
|
|
2867
|
-
function assignFont(fonts, key, value) {
|
|
2868
|
-
const normalized = value?.trim();
|
|
2869
|
-
if (normalized) fonts[key] = normalized;
|
|
2870
|
-
}
|
|
2871
|
-
function resolvedFontHint(element) {
|
|
2872
|
-
const hint = work_docx_run_formatting_import_wordAttribute(element, 'hint')?.trim().toLowerCase();
|
|
2873
|
-
if ('eastasia' === hint) return 'eastAsia';
|
|
2874
|
-
if ('cs' === hint) return 'complex';
|
|
2875
|
-
if ('default' === hint) return 'ascii';
|
|
2876
|
-
}
|
|
2877
|
-
function orderedFonts(fonts, preferred) {
|
|
2878
|
-
const order = {
|
|
2879
|
-
ascii: [
|
|
2880
|
-
'ascii',
|
|
2881
|
-
'hAnsi',
|
|
2882
|
-
'eastAsia',
|
|
2883
|
-
'complex'
|
|
2884
|
-
],
|
|
2885
|
-
hAnsi: [
|
|
2886
|
-
'hAnsi',
|
|
2887
|
-
'ascii',
|
|
2888
|
-
'eastAsia',
|
|
2889
|
-
'complex'
|
|
2890
|
-
],
|
|
2891
|
-
eastAsia: [
|
|
2892
|
-
'eastAsia',
|
|
2893
|
-
'hAnsi',
|
|
2894
|
-
'ascii',
|
|
2895
|
-
'complex'
|
|
2896
|
-
],
|
|
2897
|
-
complex: [
|
|
2898
|
-
'complex',
|
|
2899
|
-
'hAnsi',
|
|
2900
|
-
'ascii',
|
|
2901
|
-
'eastAsia'
|
|
2902
|
-
]
|
|
2903
|
-
};
|
|
2904
|
-
return order[preferred].map((slot)=>fonts[slot]);
|
|
2905
|
-
}
|
|
2906
|
-
function docxFontSlotForText(text, hint) {
|
|
2907
|
-
for (const character of text){
|
|
2908
|
-
const codePoint = character.codePointAt(0);
|
|
2909
|
-
if (!(void 0 === codePoint || isNeutralCodePoint(codePoint))) {
|
|
2910
|
-
if (isComplexScriptCodePoint(codePoint)) return 'complex';
|
|
2911
|
-
if (isEastAsianCodePoint(codePoint)) return 'eastAsia';
|
|
2912
|
-
return codePoint <= 0x7f ? 'ascii' : 'hAnsi';
|
|
2913
|
-
}
|
|
2914
|
-
}
|
|
2915
|
-
return hint ?? 'ascii';
|
|
2916
|
-
}
|
|
2917
|
-
function isNeutralCodePoint(codePoint) {
|
|
2918
|
-
return codePoint <= 0x20 || codePoint <= 0x7f && !(codePoint >= 0x41 && codePoint <= 0x5a || codePoint >= 0x61 && codePoint <= 0x7a) || codePoint >= 0x300 && codePoint <= 0x36f || codePoint >= 0x2000 && codePoint <= 0x206f;
|
|
2919
|
-
}
|
|
2920
|
-
function isComplexScriptCodePoint(codePoint) {
|
|
2921
|
-
return codePoint >= 0x0590 && codePoint <= 0x08ff || codePoint >= 0xfb1d && codePoint <= 0xfdff || codePoint >= 0xfe70 && codePoint <= 0xfeff || codePoint >= 0x1ee00 && codePoint <= 0x1eeff;
|
|
2922
|
-
}
|
|
2923
|
-
function isEastAsianCodePoint(codePoint) {
|
|
2924
|
-
return codePoint >= 0x1100 && codePoint <= 0x11ff || codePoint >= 0x2e80 && codePoint <= 0xa4cf || codePoint >= 0xac00 && codePoint <= 0xd7af || codePoint >= 0xf900 && codePoint <= 0xfaff || codePoint >= 0xfe10 && codePoint <= 0xfe6f || codePoint >= 0xff00 && codePoint <= 0xffef || codePoint >= 0x20000 && codePoint <= 0x323af;
|
|
2925
|
-
}
|
|
2926
|
-
function resolvedFont(element, explicitName, themeName, theme) {
|
|
2927
|
-
const explicit = work_docx_run_formatting_import_wordAttribute(element, explicitName);
|
|
2928
|
-
if (explicit?.trim()) return explicit;
|
|
2929
|
-
return docxThemeFont(theme, work_docx_run_formatting_import_wordAttribute(element, themeName)) ?? null;
|
|
2930
|
-
}
|
|
2931
|
-
function uniqueFonts(values) {
|
|
2932
|
-
const fonts = [
|
|
2933
|
-
...new Set(values.filter((value)=>!!value))
|
|
2934
|
-
];
|
|
2935
|
-
return fonts.length ? fonts.map(cssFontFamily).join(', ') : void 0;
|
|
2936
|
-
}
|
|
2937
|
-
function cssFontFamily(value) {
|
|
2938
|
-
return /[\s"',]/.test(value) ? `"${value.replaceAll('\\', '\\\\').replaceAll('"', '\\"')}"` : value;
|
|
2939
|
-
}
|
|
2940
|
-
function work_docx_run_formatting_import_numericAttribute(element, name) {
|
|
2941
|
-
if (!element) return;
|
|
2942
|
-
const raw = work_docx_run_formatting_import_wordAttribute(element, name);
|
|
2943
|
-
if (null === raw || !raw.trim()) return;
|
|
2944
|
-
const value = Number(raw);
|
|
2945
|
-
return Number.isFinite(value) ? value : void 0;
|
|
2946
|
-
}
|
|
2947
|
-
function work_docx_run_formatting_import_wordAttribute(element, name) {
|
|
2948
|
-
return attribute(element, name) ?? attribute(element, `w:${name}`);
|
|
2949
|
-
}
|
|
2950
|
-
function wordHighlightColor(value) {
|
|
2951
|
-
const colors = {
|
|
2952
|
-
black: '#000000',
|
|
2953
|
-
blue: '#0000ff',
|
|
2954
|
-
cyan: '#00ffff',
|
|
2955
|
-
darkblue: '#000080',
|
|
2956
|
-
darkcyan: '#008080',
|
|
2957
|
-
darkgray: '#808080',
|
|
2958
|
-
darkgreen: '#008000',
|
|
2959
|
-
darkmagenta: '#800080',
|
|
2960
|
-
darkred: '#800000',
|
|
2961
|
-
darkyellow: '#808000',
|
|
2962
|
-
green: '#00ff00',
|
|
2963
|
-
lightgray: '#c0c0c0',
|
|
2964
|
-
magenta: '#ff00ff',
|
|
2965
|
-
none: 'transparent',
|
|
2966
|
-
red: '#ff0000',
|
|
2967
|
-
white: '#ffffff',
|
|
2968
|
-
yellow: '#ffff00'
|
|
2969
|
-
};
|
|
2970
|
-
return colors[value] ?? 'transparent';
|
|
2971
|
-
}
|
|
2972
|
-
function work_docx_run_formatting_import_formatNumber(value) {
|
|
2973
|
-
return Number(value.toFixed(2)).toString();
|
|
2974
|
-
}
|
|
2975
|
-
function formatLineHeightFactor(value) {
|
|
2976
|
-
return Number(value.toFixed(4)).toString();
|
|
2977
|
-
}
|
|
2978
|
-
const work_docx_tab_stop_import_WORD_NAMESPACE = 'http://schemas.openxmlformats.org/wordprocessingml/2006/main';
|
|
2979
|
-
const work_docx_tab_stop_import_XML_NAMESPACE = 'http://www.w3.org/XML/1998/namespace';
|
|
2980
|
-
const work_docx_tab_stop_import_TWIPS_PER_CSS_PIXEL = 15;
|
|
2981
|
-
const PARAGRAPH_TAB_STOP_MARKER_PATTERN = /__A3S_WORK_PARAGRAPH_TAB_STOPS_\d+__/g;
|
|
2982
|
-
const INLINE_TAB_MARKER_PATTERN = /__A3S_WORK_INLINE_TAB_\d+__/g;
|
|
2983
|
-
function markDocxParagraphTabStops(document, styleSource, tableStyleSource) {
|
|
2984
|
-
const paragraphs = [];
|
|
2985
|
-
const inlineTabs = [];
|
|
2986
|
-
const styles = resolveDocxParagraphStyleResolver(styleSource);
|
|
2987
|
-
const tableStyles = resolveDocxTableStyleResolver(tableStyleSource);
|
|
2988
|
-
for (const paragraph of descendants(document, 'p')){
|
|
2989
|
-
let properties = directChild(paragraph, 'pPr');
|
|
2990
|
-
const tabStops = resolvedParagraphTabStops(docxParagraphPropertySources(properties, styles, docxTableParagraphPropertySources(paragraph, tableStyles)));
|
|
2991
|
-
if (tabStops.length) {
|
|
2992
|
-
properties ??= work_docx_tab_stop_import_insertParagraphProperties(document, paragraph);
|
|
2993
|
-
const marker = `__A3S_WORK_PARAGRAPH_TAB_STOPS_${paragraphs.length + 1}__`;
|
|
2994
|
-
work_docx_tab_stop_import_insertParagraphMarker(document, paragraph, properties, marker);
|
|
2995
|
-
paragraphs.push({
|
|
2996
|
-
marker,
|
|
2997
|
-
tabStops
|
|
2998
|
-
});
|
|
2999
|
-
}
|
|
3000
|
-
for (const tab of inlineRunTabs(paragraph)){
|
|
3001
|
-
const marker = `__A3S_WORK_INLINE_TAB_${inlineTabs.length + 1}__`;
|
|
3002
|
-
const text = document.createElementNS(work_docx_tab_stop_import_WORD_NAMESPACE, 'w:t');
|
|
3003
|
-
text.setAttributeNS(work_docx_tab_stop_import_XML_NAMESPACE, 'xml:space', 'preserve');
|
|
3004
|
-
text.textContent = marker;
|
|
3005
|
-
tab.replaceWith(text);
|
|
3006
|
-
inlineTabs.push(marker);
|
|
3007
|
-
}
|
|
3008
|
-
}
|
|
3009
|
-
return {
|
|
3010
|
-
paragraphs,
|
|
3011
|
-
inlineTabs
|
|
3012
|
-
};
|
|
3013
|
-
}
|
|
3014
|
-
function applyImportedDocxParagraphTabStopMarkers(document, markers) {
|
|
3015
|
-
const tabStopsByMarker = new Map(markers.paragraphs.map(({ marker, tabStops })=>[
|
|
3016
|
-
marker,
|
|
3017
|
-
tabStops
|
|
3018
|
-
]));
|
|
3019
|
-
for (const node of work_docx_tab_stop_import_textNodes(document.body)){
|
|
3020
|
-
if (!node.data.includes('__A3S_WORK_PARAGRAPH_TAB_STOPS_')) continue;
|
|
3021
|
-
const block = work_docx_tab_stop_import_closestParagraphBlock(node.parentElement);
|
|
3022
|
-
node.data = node.data.replace(PARAGRAPH_TAB_STOP_MARKER_PATTERN, (marker)=>{
|
|
3023
|
-
const tabStops = tabStopsByMarker.get(marker);
|
|
3024
|
-
if (block && tabStops?.length) block.dataset.officeTabStops = serializeDocumentTabStops(tabStops);
|
|
3025
|
-
return '';
|
|
3026
|
-
});
|
|
3027
|
-
}
|
|
3028
|
-
const inlineMarkers = new Set(markers.inlineTabs);
|
|
3029
|
-
for (const node of work_docx_tab_stop_import_textNodes(document.body))if (node.data.includes('__A3S_WORK_INLINE_TAB_')) replaceInlineTabMarkers(node, inlineMarkers);
|
|
3030
|
-
document.body.normalize();
|
|
3031
|
-
}
|
|
3032
|
-
function hasImportedDocxParagraphTabStopMarkers(markers) {
|
|
3033
|
-
return markers.paragraphs.length > 0 || markers.inlineTabs.length > 0;
|
|
3034
|
-
}
|
|
3035
|
-
function resolvedParagraphTabStops(sources) {
|
|
3036
|
-
const byPosition = new Map();
|
|
3037
|
-
for (const properties of sources){
|
|
3038
|
-
const tabs = directChild(properties, 'tabs');
|
|
3039
|
-
if (tabs) for (const tab of directChildren(tabs, 'tab')){
|
|
3040
|
-
const positionTwips = work_docx_tab_stop_import_numericAttribute(tab, 'pos');
|
|
3041
|
-
if (void 0 === positionTwips || positionTwips <= 0) continue;
|
|
3042
|
-
const position = positionTwips / work_docx_tab_stop_import_TWIPS_PER_CSS_PIXEL;
|
|
3043
|
-
const value = work_docx_tab_stop_import_wordAttribute(tab, 'val')?.trim();
|
|
3044
|
-
if ('clear' === value || 'bar' === value) {
|
|
3045
|
-
byPosition.delete(position);
|
|
3046
|
-
continue;
|
|
3047
|
-
}
|
|
3048
|
-
byPosition.set(position, {
|
|
3049
|
-
position,
|
|
3050
|
-
alignment: docxTabAlignment(value),
|
|
3051
|
-
leader: docxTabLeader(work_docx_tab_stop_import_wordAttribute(tab, 'leader'))
|
|
3052
|
-
});
|
|
3053
|
-
}
|
|
3054
|
-
}
|
|
3055
|
-
return normalizeDocumentTabStops(Array.from(byPosition.values()));
|
|
3056
|
-
}
|
|
3057
|
-
function inlineRunTabs(paragraph) {
|
|
3058
|
-
return descendants(paragraph, 'tab').filter((tab)=>{
|
|
3059
|
-
let parent = tab.parentElement;
|
|
3060
|
-
while(parent && parent !== paragraph){
|
|
3061
|
-
if ('tabs' === parent.localName) return false;
|
|
3062
|
-
parent = parent.parentElement;
|
|
3063
|
-
}
|
|
3064
|
-
return parent === paragraph;
|
|
3065
|
-
});
|
|
3066
|
-
}
|
|
3067
|
-
function replaceInlineTabMarkers(node, markers) {
|
|
3068
|
-
const matches = Array.from(node.data.matchAll(INLINE_TAB_MARKER_PATTERN));
|
|
3069
|
-
if (!matches.length) return;
|
|
3070
|
-
const fragment = node.ownerDocument.createDocumentFragment();
|
|
3071
|
-
let offset = 0;
|
|
3072
|
-
for (const match of matches){
|
|
3073
|
-
const marker = match[0];
|
|
3074
|
-
const index = match.index ?? 0;
|
|
3075
|
-
if (index > offset) fragment.append(node.data.slice(offset, index));
|
|
3076
|
-
if (markers.has(marker)) {
|
|
3077
|
-
const tab = node.ownerDocument.createElement('span');
|
|
3078
|
-
tab.dataset.documentTab = 'true';
|
|
3079
|
-
tab.className = 'work-document-tab';
|
|
3080
|
-
tab.setAttribute('role', 'separator');
|
|
3081
|
-
tab.setAttribute('aria-label', '制表符');
|
|
3082
|
-
fragment.append(tab);
|
|
3083
|
-
} else fragment.append(marker);
|
|
3084
|
-
offset = index + marker.length;
|
|
3085
|
-
}
|
|
3086
|
-
if (offset < node.data.length) fragment.append(node.data.slice(offset));
|
|
3087
|
-
node.replaceWith(fragment);
|
|
3088
|
-
}
|
|
3089
|
-
function work_docx_tab_stop_import_insertParagraphMarker(document, paragraph, properties, marker) {
|
|
3090
|
-
const run = document.createElementNS(work_docx_tab_stop_import_WORD_NAMESPACE, 'w:r');
|
|
3091
|
-
const text = document.createElementNS(work_docx_tab_stop_import_WORD_NAMESPACE, 'w:t');
|
|
3092
|
-
text.setAttributeNS(work_docx_tab_stop_import_XML_NAMESPACE, 'xml:space', 'preserve');
|
|
3093
|
-
text.textContent = marker;
|
|
3094
|
-
run.append(text);
|
|
3095
|
-
paragraph.insertBefore(run, properties.nextSibling);
|
|
3096
|
-
}
|
|
3097
|
-
function work_docx_tab_stop_import_insertParagraphProperties(document, paragraph) {
|
|
3098
|
-
const properties = document.createElementNS(work_docx_tab_stop_import_WORD_NAMESPACE, 'w:pPr');
|
|
3099
|
-
paragraph.insertBefore(properties, paragraph.firstChild);
|
|
3100
|
-
return properties;
|
|
3101
|
-
}
|
|
3102
|
-
function work_docx_tab_stop_import_closestParagraphBlock(element) {
|
|
3103
|
-
const block = element?.closest('p, h1, h2, h3, h4, h5, h6, blockquote');
|
|
3104
|
-
return block instanceof HTMLElement ? block : null;
|
|
3105
|
-
}
|
|
3106
|
-
function docxTabAlignment(value) {
|
|
3107
|
-
if ('center' === value) return 'center';
|
|
3108
|
-
if ('right' === value || 'end' === value) return 'right';
|
|
3109
|
-
if ('decimal' === value || 'num' === value) return 'decimal';
|
|
3110
|
-
return 'left';
|
|
3111
|
-
}
|
|
3112
|
-
function docxTabLeader(value) {
|
|
3113
|
-
if ('dot' === value) return 'dot';
|
|
3114
|
-
if ('hyphen' === value) return 'hyphen';
|
|
3115
|
-
if ('underscore' === value || 'heavy' === value) return 'underscore';
|
|
3116
|
-
if ('middleDot' === value) return 'middleDot';
|
|
3117
|
-
return 'none';
|
|
3118
|
-
}
|
|
3119
|
-
function work_docx_tab_stop_import_numericAttribute(element, name) {
|
|
3120
|
-
const raw = work_docx_tab_stop_import_wordAttribute(element, name);
|
|
3121
|
-
if (null === raw || !raw.trim()) return;
|
|
3122
|
-
const value = Number(raw);
|
|
3123
|
-
return Number.isFinite(value) ? value : void 0;
|
|
3124
|
-
}
|
|
3125
|
-
function work_docx_tab_stop_import_wordAttribute(element, name) {
|
|
3126
|
-
return attribute(element, name) ?? attribute(element, `w:${name}`);
|
|
3127
|
-
}
|
|
3128
|
-
function work_docx_tab_stop_import_textNodes(root) {
|
|
3129
|
-
const document = root.ownerDocument;
|
|
3130
|
-
const walker = document?.createTreeWalker(root, NodeFilter.SHOW_TEXT);
|
|
3131
|
-
const nodes = [];
|
|
3132
|
-
if (!walker) return nodes;
|
|
3133
|
-
while(walker.nextNode())nodes.push(walker.currentNode);
|
|
3134
|
-
return nodes;
|
|
3135
|
-
}
|
|
3136
2016
|
const TABLE_BORDER_EDGES = [
|
|
3137
2017
|
'top',
|
|
3138
2018
|
'right',
|
|
@@ -3369,7 +2249,7 @@ function parseBorder(edge, theme) {
|
|
|
3369
2249
|
style,
|
|
3370
2250
|
width: Math.max(0.5, Math.min(6, Math.round(2 * width) / 2)),
|
|
3371
2251
|
...themed ? {
|
|
3372
|
-
theme:
|
|
2252
|
+
theme: themeReference(edge, 'themeColor', 'themeTint', 'themeShade', color)
|
|
3373
2253
|
} : {}
|
|
3374
2254
|
};
|
|
3375
2255
|
}
|
|
@@ -3389,7 +2269,7 @@ function tableCellBackgroundColor(shading, theme) {
|
|
|
3389
2269
|
const color = `#${themed}`;
|
|
3390
2270
|
return {
|
|
3391
2271
|
color,
|
|
3392
|
-
theme:
|
|
2272
|
+
theme: themeReference(shading, 'themeFill', 'themeFillTint', 'themeFillShade', color)
|
|
3393
2273
|
};
|
|
3394
2274
|
}
|
|
3395
2275
|
const color = ooxmlColor(attribute(shading, 'fill'));
|
|
@@ -3397,10 +2277,10 @@ function tableCellBackgroundColor(shading, theme) {
|
|
|
3397
2277
|
color
|
|
3398
2278
|
} : null;
|
|
3399
2279
|
}
|
|
3400
|
-
function
|
|
2280
|
+
function themeReference(element, themeName, tintName, shadeName, resolved) {
|
|
3401
2281
|
const theme = attribute(element, themeName)?.trim() ?? '';
|
|
3402
|
-
const tint =
|
|
3403
|
-
const shade =
|
|
2282
|
+
const tint = normalizedByteHex(attribute(element, tintName));
|
|
2283
|
+
const shade = normalizedByteHex(attribute(element, shadeName));
|
|
3404
2284
|
return {
|
|
3405
2285
|
theme,
|
|
3406
2286
|
resolved,
|
|
@@ -3412,7 +2292,7 @@ function work_docx_table_cell_import_themeReference(element, themeName, tintName
|
|
|
3412
2292
|
} : {}
|
|
3413
2293
|
};
|
|
3414
2294
|
}
|
|
3415
|
-
function
|
|
2295
|
+
function normalizedByteHex(value) {
|
|
3416
2296
|
const normalized = value?.trim().toUpperCase();
|
|
3417
2297
|
return normalized && /^[0-9A-F]{2}$/.test(normalized) ? normalized : void 0;
|
|
3418
2298
|
}
|
|
@@ -3500,7 +2380,7 @@ function markDocxTableRows(document) {
|
|
|
3500
2380
|
const cantSplit = properties ? directChild(properties, 'cantSplit') : void 0;
|
|
3501
2381
|
const repeatHeader = properties ? directChild(properties, 'tblHeader') : void 0;
|
|
3502
2382
|
const height = properties ? directChild(properties, 'trHeight') : void 0;
|
|
3503
|
-
const rowHeight = height ?
|
|
2383
|
+
const rowHeight = height ? twipsToPixels(Number(attribute(height, 'val'))) : null;
|
|
3504
2384
|
const rowHeightRule = tableRowHeightRule(attribute(height ?? row, 'hRule'));
|
|
3505
2385
|
const rowIdentity = identities.get(row);
|
|
3506
2386
|
const uniqueIdentity = rowIdentity && 1 === identityCounts.get(rowIdentity.rowId) ? rowIdentity : null;
|
|
@@ -3512,10 +2392,10 @@ function markDocxTableRows(document) {
|
|
|
3512
2392
|
rows.push({
|
|
3513
2393
|
marker,
|
|
3514
2394
|
...cantSplit ? {
|
|
3515
|
-
cantSplit:
|
|
2395
|
+
cantSplit: onOffValue(cantSplit)
|
|
3516
2396
|
} : {},
|
|
3517
2397
|
...repeatHeader ? {
|
|
3518
|
-
repeatHeader:
|
|
2398
|
+
repeatHeader: onOffValue(repeatHeader)
|
|
3519
2399
|
} : {},
|
|
3520
2400
|
...uniqueIdentity ?? {},
|
|
3521
2401
|
...null !== rowHeight ? {
|
|
@@ -3554,8 +2434,8 @@ function applyImportedDocxTableRowMarkers(document, markers) {
|
|
|
3554
2434
|
const properties = rowByMarker.get(marker);
|
|
3555
2435
|
if (row instanceof HTMLTableRowElement && properties) {
|
|
3556
2436
|
applyDocumentTableRowIdentityToElement(row, properties);
|
|
3557
|
-
|
|
3558
|
-
|
|
2437
|
+
setBooleanAttribute(row, 'data-office-cant-split', properties.cantSplit);
|
|
2438
|
+
setBooleanAttribute(row, 'data-office-repeat-header', properties.repeatHeader);
|
|
3559
2439
|
if (void 0 !== properties.rowHeight) {
|
|
3560
2440
|
row.dataset.officeRowHeight = String(properties.rowHeight);
|
|
3561
2441
|
row.style.height = `${properties.rowHeight}px`;
|
|
@@ -3601,18 +2481,18 @@ function wordTableRowIdentity(row) {
|
|
|
3601
2481
|
function work_docx_table_row_import_word2010Attribute(element, localName) {
|
|
3602
2482
|
return Array.from(element.attributes).find((item)=>xmlAttributeLocalName(item) === localName && xmlAttributeNamespace(element, item) === work_docx_table_row_import_WORD_2010_NAMESPACE)?.value ?? null;
|
|
3603
2483
|
}
|
|
3604
|
-
function
|
|
2484
|
+
function onOffValue(element) {
|
|
3605
2485
|
const value = (attribute(element, 'val') ?? attribute(element, 'w:val'))?.trim().toLowerCase();
|
|
3606
2486
|
return '0' !== value && 'false' !== value && 'off' !== value;
|
|
3607
2487
|
}
|
|
3608
|
-
function
|
|
2488
|
+
function setBooleanAttribute(element, name, value) {
|
|
3609
2489
|
if (void 0 !== value) element.setAttribute(name, String(value));
|
|
3610
2490
|
}
|
|
3611
2491
|
function tableRowHeightRule(value) {
|
|
3612
2492
|
if ('exact' === value) return 'exact';
|
|
3613
2493
|
return 'atLeast' === value ? 'atLeast' : null;
|
|
3614
2494
|
}
|
|
3615
|
-
function
|
|
2495
|
+
function twipsToPixels(value) {
|
|
3616
2496
|
if (!Number.isFinite(value) || value <= 0) return null;
|
|
3617
2497
|
return Math.round(value * work_docx_table_row_import_PIXELS_PER_TWIP * 100) / 100;
|
|
3618
2498
|
}
|
|
@@ -3947,6 +2827,9 @@ async function prepareDocxImport(buffer) {
|
|
|
3947
2827
|
paragraphIdentityMarkers: {
|
|
3948
2828
|
paragraphs: []
|
|
3949
2829
|
},
|
|
2830
|
+
paragraphFormattingChangeMarkers: {
|
|
2831
|
+
paragraphs: []
|
|
2832
|
+
},
|
|
3950
2833
|
paragraphAlignmentMarkers: {
|
|
3951
2834
|
paragraphs: []
|
|
3952
2835
|
},
|
|
@@ -4023,14 +2906,15 @@ async function prepareDocxImport(buffer) {
|
|
|
4023
2906
|
const paragraphBorderMarkers = markDocxParagraphBorders(document, paragraphStyles, theme, tableStyles);
|
|
4024
2907
|
const paragraphShadingMarkers = markDocxParagraphShading(document, paragraphStyles, theme, tableStyles);
|
|
4025
2908
|
const runFormattingMarkers = markDocxRunFormatting(document, paragraphStyles, theme, tableStyles);
|
|
2909
|
+
const paragraphFormattingChangeMarkers = markDocxParagraphFormattingChanges(document, paragraphStyles, theme, tableStyles);
|
|
4026
2910
|
const tabStopMarkers = markDocxParagraphTabStops(document, paragraphStyles, tableStyles);
|
|
4027
2911
|
const tableCellMarkers = markDocxTableCells(document, theme, tableStyles);
|
|
4028
2912
|
const tableRowMarkers = markDocxTableRows(document);
|
|
4029
2913
|
const tableSizingMarkers = markDocxTableSizing(document, tableStyles);
|
|
4030
|
-
const trackChanges = Boolean(settings && firstDescendant(settings, 'trackRevisions')) || changeMarkers.changes.length > 0;
|
|
2914
|
+
const trackChanges = Boolean(settings && firstDescendant(settings, 'trackRevisions')) || changeMarkers.changes.length > 0 || paragraphFormattingChangeMarkers.paragraphs.length > 0 || runFormattingMarkers.runs.some((run)=>Boolean(run.change));
|
|
4031
2915
|
const sectionElements = effectiveSectionProperties(document);
|
|
4032
2916
|
if (!sectionElements.length) return {
|
|
4033
|
-
conversionBuffer: hasImportedDocxCaptionMarkers(captionMarkers) || hasImportedDocxBookmarkMarkers(bookmarkMarkers) || hasImportedDocxChangeMarkers(changeMarkers) || hasImportedDocxCommentMarkers(commentMarkers) || hasImportedDocxCitationMarkers(citationMarkers) || hasImportedDocxFieldMarkers(fieldMarkers) || equationMarkers.changed || hasImportedDocxListMarkers(listMarkers) || hasImportedDocxImageLayoutMarkers(imageLayoutMarkers) || hasImportedDocxParagraphIdentityMarkers(paragraphIdentityMarkers) || hasImportedDocxParagraphAlignmentMarkers(paragraphAlignmentMarkers) || hasImportedDocxParagraphDirectionMarkers(paragraphDirectionMarkers) || hasImportedDocxParagraphIndentMarkers(paragraphIndentMarkers) || hasImportedDocxParagraphSpacingMarkers(paragraphSpacingMarkers) || hasImportedDocxParagraphBorderMarkers(paragraphBorderMarkers) || hasImportedDocxParagraphShadingMarkers(paragraphShadingMarkers) || hasImportedDocxParagraphPaginationMarkers(paragraphPaginationMarkers) || hasImportedDocxRunFormattingMarkers(runFormattingMarkers) || hasImportedDocxParagraphTabStopMarkers(tabStopMarkers) || hasImportedDocxTableCellMarkers(tableCellMarkers) || hasImportedDocxTableRowMarkers(tableRowMarkers) || hasImportedDocxTableSizingMarkers(tableSizingMarkers) ? await writeDocumentXml(buffer, document, equationMarkers.parts) : buffer,
|
|
2917
|
+
conversionBuffer: hasImportedDocxCaptionMarkers(captionMarkers) || hasImportedDocxBookmarkMarkers(bookmarkMarkers) || hasImportedDocxChangeMarkers(changeMarkers) || hasImportedDocxCommentMarkers(commentMarkers) || hasImportedDocxCitationMarkers(citationMarkers) || hasImportedDocxFieldMarkers(fieldMarkers) || equationMarkers.changed || hasImportedDocxListMarkers(listMarkers) || hasImportedDocxImageLayoutMarkers(imageLayoutMarkers) || hasImportedDocxParagraphIdentityMarkers(paragraphIdentityMarkers) || hasImportedDocxParagraphFormattingChangeMarkers(paragraphFormattingChangeMarkers) || hasImportedDocxParagraphAlignmentMarkers(paragraphAlignmentMarkers) || hasImportedDocxParagraphDirectionMarkers(paragraphDirectionMarkers) || hasImportedDocxParagraphIndentMarkers(paragraphIndentMarkers) || hasImportedDocxParagraphSpacingMarkers(paragraphSpacingMarkers) || hasImportedDocxParagraphBorderMarkers(paragraphBorderMarkers) || hasImportedDocxParagraphShadingMarkers(paragraphShadingMarkers) || hasImportedDocxParagraphPaginationMarkers(paragraphPaginationMarkers) || hasImportedDocxRunFormattingMarkers(runFormattingMarkers) || hasImportedDocxParagraphTabStopMarkers(tabStopMarkers) || hasImportedDocxTableCellMarkers(tableCellMarkers) || hasImportedDocxTableRowMarkers(tableRowMarkers) || hasImportedDocxTableSizingMarkers(tableSizingMarkers) ? await writeDocumentXml(buffer, document, equationMarkers.parts) : buffer,
|
|
4034
2918
|
sections: [
|
|
4035
2919
|
{
|
|
4036
2920
|
id: 'document-section-1',
|
|
@@ -4048,6 +2932,7 @@ async function prepareDocxImport(buffer) {
|
|
|
4048
2932
|
listMarkers,
|
|
4049
2933
|
imageLayoutMarkers,
|
|
4050
2934
|
paragraphIdentityMarkers,
|
|
2935
|
+
paragraphFormattingChangeMarkers,
|
|
4051
2936
|
paragraphAlignmentMarkers,
|
|
4052
2937
|
paragraphDirectionMarkers,
|
|
4053
2938
|
paragraphIndentMarkers,
|
|
@@ -4077,7 +2962,7 @@ async function prepareDocxImport(buffer) {
|
|
|
4077
2962
|
}
|
|
4078
2963
|
if (sections.length > 1) addSectionMarkers(document, sectionElements);
|
|
4079
2964
|
return {
|
|
4080
|
-
conversionBuffer: sections.length > 1 || hasImportedDocxCaptionMarkers(captionMarkers) || hasImportedDocxBookmarkMarkers(bookmarkMarkers) || hasImportedDocxChangeMarkers(changeMarkers) || hasImportedDocxCommentMarkers(commentMarkers) || hasImportedDocxCitationMarkers(citationMarkers) || hasImportedDocxFieldMarkers(fieldMarkers) || equationMarkers.changed || hasImportedDocxListMarkers(listMarkers) || hasImportedDocxImageLayoutMarkers(imageLayoutMarkers) || hasImportedDocxParagraphIdentityMarkers(paragraphIdentityMarkers) || hasImportedDocxParagraphAlignmentMarkers(paragraphAlignmentMarkers) || hasImportedDocxParagraphDirectionMarkers(paragraphDirectionMarkers) || hasImportedDocxParagraphIndentMarkers(paragraphIndentMarkers) || hasImportedDocxParagraphSpacingMarkers(paragraphSpacingMarkers) || hasImportedDocxParagraphBorderMarkers(paragraphBorderMarkers) || hasImportedDocxParagraphShadingMarkers(paragraphShadingMarkers) || hasImportedDocxParagraphPaginationMarkers(paragraphPaginationMarkers) || hasImportedDocxRunFormattingMarkers(runFormattingMarkers) || hasImportedDocxParagraphTabStopMarkers(tabStopMarkers) || hasImportedDocxTableCellMarkers(tableCellMarkers) || hasImportedDocxTableRowMarkers(tableRowMarkers) || hasImportedDocxTableSizingMarkers(tableSizingMarkers) ? await writeDocumentXml(buffer, document, equationMarkers.parts) : buffer,
|
|
2965
|
+
conversionBuffer: sections.length > 1 || hasImportedDocxCaptionMarkers(captionMarkers) || hasImportedDocxBookmarkMarkers(bookmarkMarkers) || hasImportedDocxChangeMarkers(changeMarkers) || hasImportedDocxCommentMarkers(commentMarkers) || hasImportedDocxCitationMarkers(citationMarkers) || hasImportedDocxFieldMarkers(fieldMarkers) || equationMarkers.changed || hasImportedDocxListMarkers(listMarkers) || hasImportedDocxImageLayoutMarkers(imageLayoutMarkers) || hasImportedDocxParagraphIdentityMarkers(paragraphIdentityMarkers) || hasImportedDocxParagraphFormattingChangeMarkers(paragraphFormattingChangeMarkers) || hasImportedDocxParagraphAlignmentMarkers(paragraphAlignmentMarkers) || hasImportedDocxParagraphDirectionMarkers(paragraphDirectionMarkers) || hasImportedDocxParagraphIndentMarkers(paragraphIndentMarkers) || hasImportedDocxParagraphSpacingMarkers(paragraphSpacingMarkers) || hasImportedDocxParagraphBorderMarkers(paragraphBorderMarkers) || hasImportedDocxParagraphShadingMarkers(paragraphShadingMarkers) || hasImportedDocxParagraphPaginationMarkers(paragraphPaginationMarkers) || hasImportedDocxRunFormattingMarkers(runFormattingMarkers) || hasImportedDocxParagraphTabStopMarkers(tabStopMarkers) || hasImportedDocxTableCellMarkers(tableCellMarkers) || hasImportedDocxTableRowMarkers(tableRowMarkers) || hasImportedDocxTableSizingMarkers(tableSizingMarkers) ? await writeDocumentXml(buffer, document, equationMarkers.parts) : buffer,
|
|
4081
2966
|
sections,
|
|
4082
2967
|
pageColor,
|
|
4083
2968
|
captionMarkers,
|
|
@@ -4090,6 +2975,7 @@ async function prepareDocxImport(buffer) {
|
|
|
4090
2975
|
listMarkers,
|
|
4091
2976
|
imageLayoutMarkers,
|
|
4092
2977
|
paragraphIdentityMarkers,
|
|
2978
|
+
paragraphFormattingChangeMarkers,
|
|
4093
2979
|
paragraphAlignmentMarkers,
|
|
4094
2980
|
paragraphDirectionMarkers,
|
|
4095
2981
|
paragraphIndentMarkers,
|
|
@@ -4130,6 +3016,8 @@ function applyDocxSectionsToHtml(html, sections, captionMarkers = {
|
|
|
4130
3016
|
images: []
|
|
4131
3017
|
}, paragraphIdentityMarkers = {
|
|
4132
3018
|
paragraphs: []
|
|
3019
|
+
}, paragraphFormattingChangeMarkers = {
|
|
3020
|
+
paragraphs: []
|
|
4133
3021
|
}, paragraphAlignmentMarkers = {
|
|
4134
3022
|
paragraphs: []
|
|
4135
3023
|
}, runFormattingMarkers = {
|
|
@@ -4177,6 +3065,7 @@ function applyDocxSectionsToHtml(html, sections, captionMarkers = {
|
|
|
4177
3065
|
applyImportedDocxParagraphPaginationMarkers(document, paragraphPaginationMarkers);
|
|
4178
3066
|
applyImportedDocxParagraphTabStopMarkers(document, tabStopMarkers);
|
|
4179
3067
|
applyImportedDocxParagraphAlignmentMarkers(document, paragraphAlignmentMarkers);
|
|
3068
|
+
applyImportedDocxParagraphFormattingChangeMarkers(document, paragraphFormattingChangeMarkers);
|
|
4180
3069
|
applyImportedDocxTableCellMarkers(document, tableCellMarkers);
|
|
4181
3070
|
applyImportedDocxTableSizingMarkers(document, tableSizingMarkers);
|
|
4182
3071
|
applyImportedDocxTableRowMarkers(document, tableRowMarkers);
|