@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.
Files changed (31) hide show
  1. package/COLLABORATION_ROADMAP.md +29 -5
  2. package/README.md +19 -6
  3. package/dist/{0~7754.js → 0~5093.js} +1449 -3
  4. package/dist/0~document-editor.js +8 -1
  5. package/dist/0~work-docx-export.js +482 -16
  6. package/dist/0~work-docx-import.js +31 -1142
  7. package/dist/0~work-office-diagnostics.js +9 -5
  8. package/dist/4104.js +1 -1
  9. package/dist/8928.js +763 -149
  10. package/dist/internal/features/work/work-document-format-change-tracking.d.ts +9 -0
  11. package/dist/internal/features/work/work-document-format-changes.d.ts +28 -0
  12. package/dist/internal/features/work/work-document-paragraph-format-change-tracking.d.ts +7 -0
  13. package/dist/internal/features/work/work-document-paragraph-format-changes.d.ts +8 -0
  14. package/dist/internal/features/work/work-docx-format-change-export.d.ts +17 -0
  15. package/dist/internal/features/work/work-docx-import.d.ts +3 -1
  16. package/dist/internal/features/work/work-docx-paragraph-alignment-import.d.ts +1 -0
  17. package/dist/internal/features/work/work-docx-paragraph-borders-import.d.ts +1 -0
  18. package/dist/internal/features/work/work-docx-paragraph-direction-import.d.ts +1 -0
  19. package/dist/internal/features/work/work-docx-paragraph-format-change-export.d.ts +13 -0
  20. package/dist/internal/features/work/work-docx-paragraph-format-change-import.d.ts +17 -0
  21. package/dist/internal/features/work/work-docx-paragraph-indent-import.d.ts +1 -0
  22. package/dist/internal/features/work/work-docx-paragraph-pagination-import.d.ts +1 -0
  23. package/dist/internal/features/work/work-docx-paragraph-shading-import.d.ts +1 -0
  24. package/dist/internal/features/work/work-docx-paragraph-spacing-import.d.ts +1 -0
  25. package/dist/internal/features/work/work-docx-run-formatting-import.d.ts +10 -0
  26. package/dist/internal/features/work/work-docx-tab-stop-import.d.ts +1 -0
  27. package/dist/internal/features/work/work-types.d.ts +1 -1
  28. package/dist/office-kernel.wasm +0 -0
  29. package/dist/styles.css +28 -0
  30. package/docs/latest/en/browser-editor-architecture.md +18 -0
  31. package/package.json +7 -3
@@ -1,6 +1,6 @@
1
1
  import { descendants, directChildren as work_ooxml_package_directChildren, xmlNamespacePrefix, directChild, attribute as work_ooxml_package_attribute, childPath } from "./5184.js";
2
- import { xmlAttributeLocalName, docxThemeColor, XML_NAMESPACE as work_docx_settings_xml_XML_NAMESPACE, resolveDocxThemeResolver as work_docx_theme_resolveDocxThemeResolver, DOCX_WORDPROCESSING_NAMESPACES, XMLNS_NAMESPACE as work_docx_settings_xml_XMLNS_NAMESPACE, xmlAttributeNamespace } from "./0~2805.js";
3
- import { DOCUMENT_PARAGRAPH_BORDER_STYLES, normalizeDocumentParagraphBorders as work_document_paragraph_borders_normalizeDocumentParagraphBorders, DOCUMENT_PARAGRAPH_BORDER_EDGES, normalizeDocumentPageBorders, normalizeDocumentParagraphBorder, normalizeDocumentEquation, DOCUMENT_PAGE_BORDER_EDGES, DOCUMENT_PARAGRAPH_SHADING_PATTERNS, documentParagraphShadingDomAttributes, documentParagraphBordersDomAttributes, createDocumentEquationElement, normalizeDocumentPageGeometry, normalizeDocumentPageMargins, documentEquationText, normalizeDocumentPaperSource } from "./8928.js";
2
+ import { xmlAttributeLocalName, docxThemeFont, XML_NAMESPACE as work_docx_settings_xml_XML_NAMESPACE, docxThemeColor, parseDocxParagraphDefaultCollapsed, resolveDocxThemeResolver as work_docx_theme_resolveDocxThemeResolver, DOCX_WORDPROCESSING_NAMESPACES, XMLNS_NAMESPACE as work_docx_settings_xml_XMLNS_NAMESPACE, xmlAttributeNamespace } from "./0~2805.js";
3
+ import { DOCUMENT_PARAGRAPH_BORDER_STYLES, normalizeDocumentParagraphBorders as work_document_paragraph_borders_normalizeDocumentParagraphBorders, DOCUMENT_PARAGRAPH_BORDER_EDGES, normalizeDocumentPageBorders, normalizeDocumentParagraphBorder, normalizeDocumentParagraphIndent, serializeDocumentParagraphFormatting, normalizeDocumentEquation, DOCUMENT_PAGE_BORDER_EDGES, normalizeDocumentTabStops, DOCUMENT_PARAGRAPH_SHADING_PATTERNS, documentWordLineHeightFactor, documentAutoLineHeight, renderDocumentAutoLineHeight, serializeDocxThemeReference, documentParagraphShadingDomAttributes, importedDocumentCharacterFormatting, documentParagraphBordersDomAttributes, createDocumentEquationElement, normalizeDocumentPageGeometry, normalizeDocumentPageMargins, documentEquationText, normalizeDocumentPaperSource, serializeDocumentTabStops } from "./8928.js";
4
4
  function docxFieldInstructions(root) {
5
5
  return docxFieldOccurrences(root).map((field)=>field.instruction);
6
6
  }
@@ -4495,6 +4495,14 @@ function resolveDocxParagraphBordersForParagraph(paragraph, styleSource, themeSo
4495
4495
  spoofedCount: resolved.spoofedCount
4496
4496
  };
4497
4497
  }
4498
+ function resolveDocxParagraphBordersFromSources(propertySources, themeSource) {
4499
+ const resolved = resolveParagraphBorderSources(propertySources, work_docx_theme_resolveDocxThemeResolver(themeSource));
4500
+ return {
4501
+ borders: work_document_paragraph_borders_normalizeDocumentParagraphBorders(resolved.borders),
4502
+ invalidCount: resolved.invalidCount,
4503
+ spoofedCount: resolved.spoofedCount
4504
+ };
4505
+ }
4498
4506
  function applyImportedDocxParagraphBorderMarkers(document, markers) {
4499
4507
  const bordersByMarker = new Map(markers.paragraphs.map(({ marker, borders })=>[
4500
4508
  marker,
@@ -5476,6 +5484,9 @@ function parseDirectDocxParagraphShading(properties, themeSource) {
5476
5484
  const candidate = candidates[0];
5477
5485
  return candidate ? parseDocxParagraphShadingElement(candidate, themeSource) : void 0;
5478
5486
  }
5487
+ function resolveDocxParagraphShadingFromSources(propertySources, themeSource) {
5488
+ return resolveParagraphShading(propertySources, work_docx_theme_resolveDocxThemeResolver(themeSource)).shading;
5489
+ }
5479
5490
  function resolveParagraphShading(propertySources, theme) {
5480
5491
  let shading = null;
5481
5492
  let specified = false;
@@ -5650,4 +5661,1439 @@ function work_docx_paragraph_shading_import_textNodes(root) {
5650
5661
  while(walker.nextNode())nodes.push(walker.currentNode);
5651
5662
  return nodes;
5652
5663
  }
5653
- export { applyImportedDocxEquationMarkers, applyImportedDocxParagraphBorderMarkers, applyImportedDocxParagraphShadingMarkers, createDocxParagraphStyleResolver, createDocxTableStyleResolver, docxCaptionBookmark, docxCaptionReferenceTarget, docxCaptionSequenceKind, docxEquationHtml, docxFieldInstructions, docxFieldOccurrenceIsInlineEditable, docxFieldOccurrences, docxFieldResultText, docxParagraphPropertySources, docxRunPropertySources, docxTableCellStyleLayers, docxTableParagraphPropertySources, docxTablePropertySources, docxTableRunPropertySources, hasImportedDocxParagraphBorderMarkers, hasImportedDocxParagraphShadingMarkers, hasInvalidDocxFieldStructure, inspectDocxEquation, inspectDocxPageBorders, inspectDocxPageMarginSettings, inspectDocxPageMargins, inspectDocxPageSize, inspectDocxPaperSource, isDocxEquationLikeRoot, isSupportedDocxEquationPlacement, markDocxPackageEquations, markDocxParagraphBorders, markDocxParagraphShading, parseDirectDocxParagraphShading, parseDocxPageBorders, parseDocxPageGeometry, parseDocxPageMargins, parseDocxPaperSource, resolveDocxParagraphBordersForParagraph, resolveDocxParagraphStyleResolver, resolveDocxTableStyleResolver };
5664
+ const work_docx_paragraph_alignment_import_WORD_NAMESPACE = 'http://schemas.openxmlformats.org/wordprocessingml/2006/main';
5665
+ const work_docx_paragraph_alignment_import_XML_NAMESPACE = 'http://www.w3.org/XML/1998/namespace';
5666
+ const PARAGRAPH_ALIGNMENT_MARKER_PATTERN = /__A3S_WORK_PARAGRAPH_ALIGNMENT_\d+__/g;
5667
+ function markDocxParagraphAlignments(document, styleSource, tableStyleSource) {
5668
+ const paragraphs = [];
5669
+ const styles = resolveDocxParagraphStyleResolver(styleSource);
5670
+ const tableStyles = resolveDocxTableStyleResolver(tableStyleSource);
5671
+ for (const paragraph of descendants(document, 'p')){
5672
+ let properties = directChild(paragraph, 'pPr');
5673
+ const sources = docxParagraphPropertySources(properties, styles, docxTableParagraphPropertySources(paragraph, tableStyles));
5674
+ const alignment = resolveDocxParagraphAlignment(sources);
5675
+ if (!alignment) continue;
5676
+ properties ??= work_docx_paragraph_alignment_import_insertParagraphProperties(document, paragraph);
5677
+ const marker = `__A3S_WORK_PARAGRAPH_ALIGNMENT_${paragraphs.length + 1}__`;
5678
+ work_docx_paragraph_alignment_import_insertParagraphMarker(document, paragraph, properties, marker);
5679
+ paragraphs.push({
5680
+ marker,
5681
+ alignment
5682
+ });
5683
+ }
5684
+ return {
5685
+ paragraphs
5686
+ };
5687
+ }
5688
+ function applyImportedDocxParagraphAlignmentMarkers(document, markers) {
5689
+ const alignmentByMarker = new Map(markers.paragraphs.map(({ marker, alignment })=>[
5690
+ marker,
5691
+ alignment
5692
+ ]));
5693
+ 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)=>{
5694
+ const alignment = alignmentByMarker.get(marker);
5695
+ const block = alignment ? work_docx_paragraph_alignment_import_closestParagraphBlock(node.parentElement, node) : null;
5696
+ if (block && alignment) block.style.textAlign = alignment;
5697
+ return '';
5698
+ });
5699
+ document.body.normalize();
5700
+ }
5701
+ function hasImportedDocxParagraphAlignmentMarkers(markers) {
5702
+ return markers.paragraphs.length > 0;
5703
+ }
5704
+ function resolveDocxParagraphAlignment(propertySources) {
5705
+ let direction = 'ltr';
5706
+ let justification = null;
5707
+ let hasJustification = false;
5708
+ for (const properties of propertySources){
5709
+ const bidi = directChild(properties, 'bidi');
5710
+ if (bidi) direction = work_docx_paragraph_alignment_import_onOffValue(bidi) ? 'rtl' : 'ltr';
5711
+ const source = directChild(properties, 'jc');
5712
+ if (source) {
5713
+ hasJustification = true;
5714
+ justification = work_docx_paragraph_alignment_import_wordAttribute(source, 'val')?.trim() ?? null;
5715
+ }
5716
+ }
5717
+ if (!hasJustification || !justification) return null;
5718
+ if ('center' === justification) return 'center';
5719
+ if ('left' === justification) return 'left';
5720
+ if ('right' === justification) return 'right';
5721
+ if ('start' === justification) return 'rtl' === direction ? 'right' : 'left';
5722
+ if ('end' === justification) return 'rtl' === direction ? 'left' : 'right';
5723
+ if ('both' === justification || 'distribute' === justification || 'highKashida' === justification || 'lowKashida' === justification || 'mediumKashida' === justification || 'thaiDistribute' === justification) return 'justify';
5724
+ return null;
5725
+ }
5726
+ function work_docx_paragraph_alignment_import_onOffValue(element) {
5727
+ const value = work_docx_paragraph_alignment_import_wordAttribute(element, 'val')?.trim().toLowerCase();
5728
+ return '0' !== value && 'false' !== value && 'off' !== value;
5729
+ }
5730
+ function work_docx_paragraph_alignment_import_wordAttribute(element, name) {
5731
+ return work_ooxml_package_attribute(element, name) ?? work_ooxml_package_attribute(element, `w:${name}`);
5732
+ }
5733
+ function work_docx_paragraph_alignment_import_insertParagraphMarker(document, paragraph, properties, marker) {
5734
+ const run = document.createElementNS(work_docx_paragraph_alignment_import_WORD_NAMESPACE, 'w:r');
5735
+ const text = document.createElementNS(work_docx_paragraph_alignment_import_WORD_NAMESPACE, 'w:t');
5736
+ text.setAttributeNS(work_docx_paragraph_alignment_import_XML_NAMESPACE, 'xml:space', 'preserve');
5737
+ text.textContent = marker;
5738
+ run.append(text);
5739
+ paragraph.insertBefore(run, properties.nextSibling);
5740
+ }
5741
+ function work_docx_paragraph_alignment_import_insertParagraphProperties(document, paragraph) {
5742
+ const properties = document.createElementNS(work_docx_paragraph_alignment_import_WORD_NAMESPACE, 'w:pPr');
5743
+ paragraph.insertBefore(properties, paragraph.firstChild);
5744
+ return properties;
5745
+ }
5746
+ function work_docx_paragraph_alignment_import_closestParagraphBlock(element, markerNode) {
5747
+ const block = element?.closest('p, h1, h2, h3, h4, h5, h6, blockquote, li');
5748
+ if (!(block instanceof HTMLElement)) return null;
5749
+ return 'li' === block.tagName.toLowerCase() ? work_docx_paragraph_alignment_import_wrapListItemParagraph(block, markerNode) : block;
5750
+ }
5751
+ function work_docx_paragraph_alignment_import_wrapListItemParagraph(item, markerNode) {
5752
+ let anchor = markerNode;
5753
+ while(anchor.parentNode && anchor.parentNode !== item)anchor = anchor.parentNode;
5754
+ const children = Array.from(item.childNodes);
5755
+ const anchorIndex = children.indexOf(anchor);
5756
+ if (anchorIndex < 0) return item;
5757
+ let start = anchorIndex;
5758
+ let end = anchorIndex;
5759
+ while(start > 0 && !work_docx_paragraph_alignment_import_isListItemBlock(children[start - 1]))start -= 1;
5760
+ while(end + 1 < children.length && !work_docx_paragraph_alignment_import_isListItemBlock(children[end + 1]))end += 1;
5761
+ const paragraph = item.ownerDocument.createElement('p');
5762
+ const grouped = children.slice(start, end + 1);
5763
+ item.insertBefore(paragraph, grouped[0] ?? null);
5764
+ paragraph.append(...grouped);
5765
+ return paragraph;
5766
+ }
5767
+ function work_docx_paragraph_alignment_import_isListItemBlock(node) {
5768
+ if (!(node instanceof HTMLElement)) return false;
5769
+ return [
5770
+ 'blockquote',
5771
+ 'div',
5772
+ 'h1',
5773
+ 'h2',
5774
+ 'h3',
5775
+ 'h4',
5776
+ 'h5',
5777
+ 'h6',
5778
+ 'hr',
5779
+ 'ol',
5780
+ 'p',
5781
+ 'pre',
5782
+ 'table',
5783
+ 'ul'
5784
+ ].includes(node.tagName.toLowerCase());
5785
+ }
5786
+ function work_docx_paragraph_alignment_import_textNodes(root) {
5787
+ const document = root.ownerDocument;
5788
+ const walker = document?.createTreeWalker(root, NodeFilter.SHOW_TEXT);
5789
+ const nodes = [];
5790
+ if (!walker) return nodes;
5791
+ while(walker.nextNode())nodes.push(walker.currentNode);
5792
+ return nodes;
5793
+ }
5794
+ const work_docx_paragraph_direction_import_WORD_NAMESPACE = 'http://schemas.openxmlformats.org/wordprocessingml/2006/main';
5795
+ const work_docx_paragraph_direction_import_XML_NAMESPACE = 'http://www.w3.org/XML/1998/namespace';
5796
+ const PARAGRAPH_DIRECTION_MARKER_PATTERN = /__A3S_WORK_PARAGRAPH_DIRECTION_\d+__/g;
5797
+ function markDocxParagraphDirections(document, styleSource, tableStyleSource) {
5798
+ const paragraphs = [];
5799
+ const styles = resolveDocxParagraphStyleResolver(styleSource);
5800
+ const tableStyles = resolveDocxTableStyleResolver(tableStyleSource);
5801
+ for (const paragraph of descendants(document, 'p')){
5802
+ let properties = directChild(paragraph, 'pPr');
5803
+ const sources = docxParagraphPropertySources(properties, styles, docxTableParagraphPropertySources(paragraph, tableStyles));
5804
+ const direction = resolveDocxParagraphDirection(sources);
5805
+ if (!direction) continue;
5806
+ properties ??= work_docx_paragraph_direction_import_insertParagraphProperties(document, paragraph);
5807
+ const marker = `__A3S_WORK_PARAGRAPH_DIRECTION_${paragraphs.length + 1}__`;
5808
+ work_docx_paragraph_direction_import_insertParagraphMarker(document, paragraph, properties, marker);
5809
+ paragraphs.push({
5810
+ marker,
5811
+ direction
5812
+ });
5813
+ }
5814
+ return {
5815
+ paragraphs
5816
+ };
5817
+ }
5818
+ function applyImportedDocxParagraphDirectionMarkers(document, markers) {
5819
+ const directionByMarker = new Map(markers.paragraphs.map(({ marker, direction })=>[
5820
+ marker,
5821
+ direction
5822
+ ]));
5823
+ for (const node of work_docx_paragraph_direction_import_textNodes(document.body)){
5824
+ if (!node.data.includes('__A3S_WORK_PARAGRAPH_DIRECTION_')) continue;
5825
+ const block = work_docx_paragraph_direction_import_closestParagraphBlock(node.parentElement);
5826
+ node.data = node.data.replace(PARAGRAPH_DIRECTION_MARKER_PATTERN, (marker)=>{
5827
+ const direction = directionByMarker.get(marker);
5828
+ if (block && direction) block.setAttribute('dir', direction);
5829
+ return '';
5830
+ });
5831
+ }
5832
+ document.body.normalize();
5833
+ }
5834
+ function hasImportedDocxParagraphDirectionMarkers(markers) {
5835
+ return markers.paragraphs.length > 0;
5836
+ }
5837
+ function resolveDocxParagraphDirection(propertySources) {
5838
+ let direction = null;
5839
+ for (const properties of propertySources){
5840
+ const bidi = directChild(properties, 'bidi');
5841
+ if (bidi) direction = work_docx_paragraph_direction_import_onOffValue(bidi) ? 'rtl' : 'ltr';
5842
+ }
5843
+ return direction;
5844
+ }
5845
+ function work_docx_paragraph_direction_import_onOffValue(element) {
5846
+ const value = (work_ooxml_package_attribute(element, 'val') ?? work_ooxml_package_attribute(element, 'w:val'))?.trim().toLowerCase();
5847
+ return '0' !== value && 'false' !== value && 'off' !== value;
5848
+ }
5849
+ function work_docx_paragraph_direction_import_insertParagraphMarker(document, paragraph, properties, marker) {
5850
+ const run = document.createElementNS(work_docx_paragraph_direction_import_WORD_NAMESPACE, 'w:r');
5851
+ const text = document.createElementNS(work_docx_paragraph_direction_import_WORD_NAMESPACE, 'w:t');
5852
+ text.setAttributeNS(work_docx_paragraph_direction_import_XML_NAMESPACE, 'xml:space', 'preserve');
5853
+ text.textContent = marker;
5854
+ run.append(text);
5855
+ paragraph.insertBefore(run, properties.nextSibling);
5856
+ }
5857
+ function work_docx_paragraph_direction_import_insertParagraphProperties(document, paragraph) {
5858
+ const properties = document.createElementNS(work_docx_paragraph_direction_import_WORD_NAMESPACE, 'w:pPr');
5859
+ paragraph.insertBefore(properties, paragraph.firstChild);
5860
+ return properties;
5861
+ }
5862
+ function work_docx_paragraph_direction_import_closestParagraphBlock(element) {
5863
+ const block = element?.closest('p, h1, h2, h3, h4, h5, h6, blockquote, li');
5864
+ return block instanceof HTMLElement ? block : null;
5865
+ }
5866
+ function work_docx_paragraph_direction_import_textNodes(root) {
5867
+ const document = root.ownerDocument;
5868
+ const walker = document?.createTreeWalker(root, NodeFilter.SHOW_TEXT);
5869
+ const nodes = [];
5870
+ if (!walker) return nodes;
5871
+ while(walker.nextNode())nodes.push(walker.currentNode);
5872
+ return nodes;
5873
+ }
5874
+ const work_docx_paragraph_indent_import_WORD_NAMESPACE = 'http://schemas.openxmlformats.org/wordprocessingml/2006/main';
5875
+ const work_docx_paragraph_indent_import_XML_NAMESPACE = 'http://www.w3.org/XML/1998/namespace';
5876
+ const TWIPS_PER_CSS_PIXEL = 15;
5877
+ const PARAGRAPH_INDENT_MARKER_PATTERN = /__A3S_WORK_PARAGRAPH_INDENT_\d+__/g;
5878
+ function markDocxParagraphIndents(document, styleSource, tableStyleSource) {
5879
+ const paragraphs = [];
5880
+ const styles = resolveDocxParagraphStyleResolver(styleSource);
5881
+ const tableStyles = resolveDocxTableStyleResolver(tableStyleSource);
5882
+ for (const paragraph of descendants(document, 'p')){
5883
+ let properties = directChild(paragraph, 'pPr');
5884
+ const sources = docxParagraphPropertySources(properties, styles, docxTableParagraphPropertySources(paragraph, tableStyles));
5885
+ if (sources.some((source)=>directChild(source, 'numPr'))) continue;
5886
+ const indent = resolveDocxParagraphIndent(sources);
5887
+ if (!indent.left && !indent.right && !indent.firstLine) continue;
5888
+ properties ??= work_docx_paragraph_indent_import_insertParagraphProperties(document, paragraph);
5889
+ const marker = `__A3S_WORK_PARAGRAPH_INDENT_${paragraphs.length + 1}__`;
5890
+ work_docx_paragraph_indent_import_insertParagraphMarker(document, paragraph, properties, marker);
5891
+ paragraphs.push({
5892
+ marker,
5893
+ indent
5894
+ });
5895
+ }
5896
+ return {
5897
+ paragraphs
5898
+ };
5899
+ }
5900
+ function applyImportedDocxParagraphIndentMarkers(document, markers) {
5901
+ const indentByMarker = new Map(markers.paragraphs.map(({ marker, indent })=>[
5902
+ marker,
5903
+ indent
5904
+ ]));
5905
+ for (const node of work_docx_paragraph_indent_import_textNodes(document.body)){
5906
+ if (!node.data.includes('__A3S_WORK_PARAGRAPH_INDENT_')) continue;
5907
+ const block = work_docx_paragraph_indent_import_closestParagraphBlock(node.parentElement);
5908
+ node.data = node.data.replace(PARAGRAPH_INDENT_MARKER_PATTERN, (marker)=>{
5909
+ const indent = indentByMarker.get(marker);
5910
+ if (block && indent) applyParagraphIndent(block, indent);
5911
+ return '';
5912
+ });
5913
+ }
5914
+ document.body.normalize();
5915
+ }
5916
+ function hasImportedDocxParagraphIndentMarkers(markers) {
5917
+ return markers.paragraphs.length > 0;
5918
+ }
5919
+ function resolveDocxParagraphIndent(propertySources) {
5920
+ let left;
5921
+ let right;
5922
+ let firstLine;
5923
+ for (const properties of propertySources){
5924
+ const indent = directChild(properties, 'ind');
5925
+ if (!indent) continue;
5926
+ const sourceLeft = numericAttribute(indent, 'start') ?? numericAttribute(indent, 'left');
5927
+ const sourceRight = numericAttribute(indent, 'end') ?? numericAttribute(indent, 'right');
5928
+ const sourceFirstLine = numericAttribute(indent, 'firstLine');
5929
+ const sourceHanging = numericAttribute(indent, 'hanging');
5930
+ if (void 0 !== sourceLeft) left = sourceLeft;
5931
+ if (void 0 !== sourceRight) right = sourceRight;
5932
+ if (void 0 !== sourceFirstLine) firstLine = sourceFirstLine;
5933
+ else if (void 0 !== sourceHanging) firstLine = -sourceHanging;
5934
+ }
5935
+ return normalizeDocumentParagraphIndent({
5936
+ left: twipsToPixels(left),
5937
+ right: twipsToPixels(right),
5938
+ firstLine: twipsToPixels(firstLine)
5939
+ });
5940
+ }
5941
+ function work_docx_paragraph_indent_import_insertParagraphMarker(document, paragraph, properties, marker) {
5942
+ const run = document.createElementNS(work_docx_paragraph_indent_import_WORD_NAMESPACE, 'w:r');
5943
+ const text = document.createElementNS(work_docx_paragraph_indent_import_WORD_NAMESPACE, 'w:t');
5944
+ text.setAttributeNS(work_docx_paragraph_indent_import_XML_NAMESPACE, 'xml:space', 'preserve');
5945
+ text.textContent = marker;
5946
+ run.append(text);
5947
+ paragraph.insertBefore(run, properties.nextSibling);
5948
+ }
5949
+ function work_docx_paragraph_indent_import_insertParagraphProperties(document, paragraph) {
5950
+ const properties = document.createElementNS(work_docx_paragraph_indent_import_WORD_NAMESPACE, 'w:pPr');
5951
+ paragraph.insertBefore(properties, paragraph.firstChild);
5952
+ return properties;
5953
+ }
5954
+ function work_docx_paragraph_indent_import_closestParagraphBlock(element) {
5955
+ const block = element?.closest('p, h1, h2, h3, h4, h5, h6, blockquote');
5956
+ return block instanceof HTMLElement ? block : null;
5957
+ }
5958
+ function applyParagraphIndent(element, value) {
5959
+ const indent = normalizeDocumentParagraphIndent(value);
5960
+ if (indent.left) {
5961
+ element.dataset.officeIndentLevel = formatNumber(indent.left / 24);
5962
+ element.style.marginLeft = `${formatNumber(indent.left)}px`;
5963
+ }
5964
+ if (indent.right) {
5965
+ element.dataset.officeIndentRight = formatNumber(indent.right);
5966
+ element.style.marginRight = `${formatNumber(indent.right)}px`;
5967
+ }
5968
+ if (indent.firstLine) {
5969
+ element.dataset.officeIndentFirstLine = formatNumber(indent.firstLine);
5970
+ element.style.textIndent = `${formatNumber(indent.firstLine)}px`;
5971
+ }
5972
+ }
5973
+ function numericAttribute(element, name) {
5974
+ const raw = work_ooxml_package_attribute(element, name) ?? work_ooxml_package_attribute(element, `w:${name}`);
5975
+ if (null === raw || !raw.trim()) return;
5976
+ const value = Number(raw);
5977
+ return Number.isFinite(value) ? value : void 0;
5978
+ }
5979
+ function twipsToPixels(value) {
5980
+ if (void 0 === value) return 0;
5981
+ return Math.round(value / TWIPS_PER_CSS_PIXEL);
5982
+ }
5983
+ function formatNumber(value) {
5984
+ return Number(value.toFixed(2)).toString();
5985
+ }
5986
+ function work_docx_paragraph_indent_import_textNodes(root) {
5987
+ const document = root.ownerDocument;
5988
+ const walker = document?.createTreeWalker(root, NodeFilter.SHOW_TEXT);
5989
+ const nodes = [];
5990
+ if (!walker) return nodes;
5991
+ while(walker.nextNode())nodes.push(walker.currentNode);
5992
+ return nodes;
5993
+ }
5994
+ const work_docx_paragraph_pagination_import_WORD_NAMESPACE = 'http://schemas.openxmlformats.org/wordprocessingml/2006/main';
5995
+ const work_docx_paragraph_pagination_import_XML_NAMESPACE = 'http://www.w3.org/XML/1998/namespace';
5996
+ const PARAGRAPH_PAGINATION_MARKER_PATTERN = /__A3S_WORK_PARAGRAPH_PAGINATION_\d+__/g;
5997
+ function markDocxParagraphPagination(document, styleSource, tableStyleSource) {
5998
+ const paragraphs = [];
5999
+ const styles = resolveDocxParagraphStyleResolver(styleSource);
6000
+ const tableStyles = resolveDocxTableStyleResolver(tableStyleSource);
6001
+ for (const paragraph of descendants(document, 'p')){
6002
+ let properties = directChild(paragraph, 'pPr');
6003
+ if (properties && directChild(properties, 'numPr')) continue;
6004
+ const pagination = resolveDocxParagraphPagination(docxParagraphPropertySources(properties, styles, docxTableParagraphPropertySources(paragraph, tableStyles)));
6005
+ if (!Object.keys(pagination).length) continue;
6006
+ properties ??= work_docx_paragraph_pagination_import_insertParagraphProperties(document, paragraph);
6007
+ const marker = `__A3S_WORK_PARAGRAPH_PAGINATION_${paragraphs.length + 1}__`;
6008
+ work_docx_paragraph_pagination_import_insertParagraphMarker(document, paragraph, properties, marker);
6009
+ paragraphs.push({
6010
+ marker,
6011
+ pagination
6012
+ });
6013
+ }
6014
+ return {
6015
+ paragraphs
6016
+ };
6017
+ }
6018
+ function applyImportedDocxParagraphPaginationMarkers(document, markers) {
6019
+ const paginationByMarker = new Map(markers.paragraphs.map(({ marker, pagination })=>[
6020
+ marker,
6021
+ pagination
6022
+ ]));
6023
+ for (const node of work_docx_paragraph_pagination_import_textNodes(document.body)){
6024
+ if (!node.data.includes('__A3S_WORK_PARAGRAPH_PAGINATION_')) continue;
6025
+ const block = work_docx_paragraph_pagination_import_closestParagraphBlock(node.parentElement);
6026
+ node.data = node.data.replace(PARAGRAPH_PAGINATION_MARKER_PATTERN, (marker)=>{
6027
+ const pagination = paginationByMarker.get(marker);
6028
+ if (block && pagination) applyParagraphPagination(block, pagination);
6029
+ return '';
6030
+ });
6031
+ }
6032
+ document.body.normalize();
6033
+ }
6034
+ function hasImportedDocxParagraphPaginationMarkers(markers) {
6035
+ return markers.paragraphs.length > 0;
6036
+ }
6037
+ function resolveDocxParagraphPagination(sources) {
6038
+ const pagination = {};
6039
+ for (const properties of sources){
6040
+ const keepLines = directChild(properties, 'keepLines');
6041
+ const keepWithNext = directChild(properties, 'keepNext');
6042
+ const pageBreakBefore = directChild(properties, 'pageBreakBefore');
6043
+ const widowControl = directChild(properties, 'widowControl');
6044
+ const contextualSpacing = directChild(properties, 'contextualSpacing');
6045
+ const outlineLevel = directChild(properties, 'outlineLvl');
6046
+ const defaultCollapsed = parseDocxParagraphDefaultCollapsed(properties);
6047
+ if (keepLines) pagination.keepLines = work_docx_paragraph_pagination_import_onOffValue(keepLines);
6048
+ if (keepWithNext) pagination.keepWithNext = work_docx_paragraph_pagination_import_onOffValue(keepWithNext);
6049
+ if (pageBreakBefore) pagination.pageBreakBefore = work_docx_paragraph_pagination_import_onOffValue(pageBreakBefore);
6050
+ if (widowControl) pagination.widowControl = work_docx_paragraph_pagination_import_onOffValue(widowControl);
6051
+ if (contextualSpacing) pagination.contextualSpacing = work_docx_paragraph_pagination_import_onOffValue(contextualSpacing);
6052
+ const outline = integerValue(outlineLevel);
6053
+ if (null !== outline && outline <= 9) pagination.outlineLevel = outline;
6054
+ if ('valid' === defaultCollapsed.status) pagination.defaultCollapsed = defaultCollapsed.value;
6055
+ else if ('invalid' === defaultCollapsed.status) delete pagination.defaultCollapsed;
6056
+ }
6057
+ return pagination;
6058
+ }
6059
+ function work_docx_paragraph_pagination_import_onOffValue(element) {
6060
+ const value = (work_ooxml_package_attribute(element, 'val') ?? work_ooxml_package_attribute(element, 'w:val'))?.trim().toLowerCase();
6061
+ return '0' !== value && 'false' !== value && 'off' !== value;
6062
+ }
6063
+ function work_docx_paragraph_pagination_import_insertParagraphMarker(document, paragraph, properties, marker) {
6064
+ const run = document.createElementNS(work_docx_paragraph_pagination_import_WORD_NAMESPACE, 'w:r');
6065
+ const text = document.createElementNS(work_docx_paragraph_pagination_import_WORD_NAMESPACE, 'w:t');
6066
+ text.setAttributeNS(work_docx_paragraph_pagination_import_XML_NAMESPACE, 'xml:space', 'preserve');
6067
+ text.textContent = marker;
6068
+ run.append(text);
6069
+ paragraph.insertBefore(run, properties.nextSibling);
6070
+ }
6071
+ function work_docx_paragraph_pagination_import_insertParagraphProperties(document, paragraph) {
6072
+ const properties = document.createElementNS(work_docx_paragraph_pagination_import_WORD_NAMESPACE, 'w:pPr');
6073
+ paragraph.insertBefore(properties, paragraph.firstChild);
6074
+ return properties;
6075
+ }
6076
+ function work_docx_paragraph_pagination_import_closestParagraphBlock(element) {
6077
+ const block = element?.closest('p, h1, h2, h3, h4, h5, h6, blockquote');
6078
+ return block instanceof HTMLElement ? block : null;
6079
+ }
6080
+ function applyParagraphPagination(element, pagination) {
6081
+ setBooleanAttribute(element, 'data-office-keep-lines', pagination.keepLines);
6082
+ setBooleanAttribute(element, 'data-office-keep-with-next', pagination.keepWithNext);
6083
+ setBooleanAttribute(element, 'data-office-page-break-before', pagination.pageBreakBefore);
6084
+ setBooleanAttribute(element, 'data-office-widow-control', pagination.widowControl);
6085
+ setBooleanAttribute(element, 'data-office-contextual-spacing', pagination.contextualSpacing);
6086
+ setBooleanAttribute(element, 'data-office-default-collapsed', pagination.defaultCollapsed);
6087
+ if (void 0 !== pagination.outlineLevel) element.dataset.officeOutlineLevel = String(pagination.outlineLevel);
6088
+ }
6089
+ function integerValue(element) {
6090
+ if (!element) return null;
6091
+ const value = Number(work_ooxml_package_attribute(element, 'val') ?? work_ooxml_package_attribute(element, 'w:val'));
6092
+ return Number.isSafeInteger(value) && value >= 0 ? value : null;
6093
+ }
6094
+ function setBooleanAttribute(element, name, value) {
6095
+ if (void 0 !== value) element.setAttribute(name, String(value));
6096
+ }
6097
+ function work_docx_paragraph_pagination_import_textNodes(root) {
6098
+ const document = root.ownerDocument;
6099
+ const walker = document?.createTreeWalker(root, NodeFilter.SHOW_TEXT);
6100
+ const nodes = [];
6101
+ if (!walker) return nodes;
6102
+ while(walker.nextNode())nodes.push(walker.currentNode);
6103
+ return nodes;
6104
+ }
6105
+ const work_docx_paragraph_spacing_import_WORD_NAMESPACE = 'http://schemas.openxmlformats.org/wordprocessingml/2006/main';
6106
+ const work_docx_paragraph_spacing_import_XML_NAMESPACE = 'http://www.w3.org/XML/1998/namespace';
6107
+ const PARAGRAPH_SPACING_MARKER_PATTERN = /__A3S_WORK_PARAGRAPH_SPACING_\d+__/g;
6108
+ function markDocxParagraphSpacing(document, styleSource, tableStyleSource) {
6109
+ const paragraphs = [];
6110
+ const styles = resolveDocxParagraphStyleResolver(styleSource);
6111
+ const tableStyles = resolveDocxTableStyleResolver(tableStyleSource);
6112
+ for (const paragraph of descendants(document, 'p')){
6113
+ let properties = directChild(paragraph, 'pPr');
6114
+ const sources = docxParagraphPropertySources(properties, styles, docxTableParagraphPropertySources(paragraph, tableStyles));
6115
+ if (sources.some((source)=>directChild(source, 'numPr'))) continue;
6116
+ const spacing = resolveDocxParagraphSpacing(sources);
6117
+ if (!Object.keys(spacing).length) continue;
6118
+ properties ??= work_docx_paragraph_spacing_import_insertParagraphProperties(document, paragraph);
6119
+ const marker = `__A3S_WORK_PARAGRAPH_SPACING_${paragraphs.length + 1}__`;
6120
+ work_docx_paragraph_spacing_import_insertParagraphMarker(document, paragraph, properties, marker);
6121
+ paragraphs.push({
6122
+ marker,
6123
+ spacing
6124
+ });
6125
+ }
6126
+ return {
6127
+ paragraphs
6128
+ };
6129
+ }
6130
+ function applyImportedDocxParagraphSpacingMarkers(document, markers) {
6131
+ const spacingByMarker = new Map(markers.paragraphs.map(({ marker, spacing })=>[
6132
+ marker,
6133
+ spacing
6134
+ ]));
6135
+ for (const node of work_docx_paragraph_spacing_import_textNodes(document.body)){
6136
+ if (!node.data.includes('__A3S_WORK_PARAGRAPH_SPACING_')) continue;
6137
+ const block = work_docx_paragraph_spacing_import_closestParagraphBlock(node.parentElement);
6138
+ node.data = node.data.replace(PARAGRAPH_SPACING_MARKER_PATTERN, (marker)=>{
6139
+ const spacing = spacingByMarker.get(marker);
6140
+ if (block && spacing) applyParagraphSpacing(block, spacing);
6141
+ return '';
6142
+ });
6143
+ }
6144
+ document.body.normalize();
6145
+ }
6146
+ function hasImportedDocxParagraphSpacingMarkers(markers) {
6147
+ return markers.paragraphs.length > 0;
6148
+ }
6149
+ function resolveDocxParagraphSpacing(propertySources) {
6150
+ let before;
6151
+ let after;
6152
+ let line;
6153
+ let lineRule;
6154
+ for (const properties of propertySources){
6155
+ const spacing = directChild(properties, 'spacing');
6156
+ if (!spacing) continue;
6157
+ const sourceBefore = work_docx_paragraph_spacing_import_numericAttribute(spacing, 'before');
6158
+ const sourceAfter = work_docx_paragraph_spacing_import_numericAttribute(spacing, 'after');
6159
+ const sourceLine = work_docx_paragraph_spacing_import_numericAttribute(spacing, 'line');
6160
+ const sourceLineRule = normalizedLineRule(work_docx_paragraph_spacing_import_wordAttribute(spacing, 'lineRule'));
6161
+ if (void 0 !== sourceBefore) before = sourceBefore;
6162
+ if (void 0 !== sourceAfter) after = sourceAfter;
6163
+ if (void 0 !== sourceLine) {
6164
+ line = sourceLine;
6165
+ lineRule = sourceLineRule ?? 'auto';
6166
+ } else if (sourceLineRule) lineRule = sourceLineRule;
6167
+ }
6168
+ const result = {};
6169
+ if (void 0 !== before) result.before = twipsToPoints(before);
6170
+ if (void 0 !== after) result.after = twipsToPoints(after);
6171
+ if (void 0 !== line) {
6172
+ const rule = lineRule ?? 'auto';
6173
+ result.lineHeight = 'auto' === rule ? work_docx_paragraph_spacing_import_formatNumber(line / 240) : `${work_docx_paragraph_spacing_import_formatNumber(line / 20)}pt`;
6174
+ result.lineRule = rule;
6175
+ }
6176
+ return result;
6177
+ }
6178
+ function applyParagraphSpacing(element, spacing) {
6179
+ if (void 0 !== spacing.before && null !== spacing.before) {
6180
+ const value = work_docx_paragraph_spacing_import_formatNumber(spacing.before);
6181
+ element.dataset.officeSpaceBefore = value;
6182
+ element.style.marginTop = `${value}pt`;
6183
+ }
6184
+ if (void 0 !== spacing.after && null !== spacing.after) {
6185
+ const value = work_docx_paragraph_spacing_import_formatNumber(spacing.after);
6186
+ element.dataset.officeSpaceAfter = value;
6187
+ element.style.marginBottom = `${value}pt`;
6188
+ }
6189
+ if (spacing.lineHeight) element.style.lineHeight = spacing.lineHeight;
6190
+ if (spacing.lineRule) element.dataset.officeLineRule = spacing.lineRule;
6191
+ if ('auto' === spacing.lineRule) {
6192
+ const autoLineHeight = documentAutoLineHeight(spacing.lineHeight);
6193
+ for (const [name, value] of Object.entries(renderDocumentAutoLineHeight(spacing.lineHeight, autoLineHeight)))if ('style' === name) for (const declaration of value.split(';')){
6194
+ const separator = declaration.indexOf(':');
6195
+ if (!(separator < 0)) element.style.setProperty(declaration.slice(0, separator).trim(), declaration.slice(separator + 1).trim());
6196
+ }
6197
+ else element.setAttribute(name, value);
6198
+ }
6199
+ }
6200
+ function work_docx_paragraph_spacing_import_insertParagraphMarker(document, paragraph, properties, marker) {
6201
+ const run = document.createElementNS(work_docx_paragraph_spacing_import_WORD_NAMESPACE, 'w:r');
6202
+ const text = document.createElementNS(work_docx_paragraph_spacing_import_WORD_NAMESPACE, 'w:t');
6203
+ text.setAttributeNS(work_docx_paragraph_spacing_import_XML_NAMESPACE, 'xml:space', 'preserve');
6204
+ text.textContent = marker;
6205
+ run.append(text);
6206
+ paragraph.insertBefore(run, properties.nextSibling);
6207
+ }
6208
+ function work_docx_paragraph_spacing_import_insertParagraphProperties(document, paragraph) {
6209
+ const properties = document.createElementNS(work_docx_paragraph_spacing_import_WORD_NAMESPACE, 'w:pPr');
6210
+ paragraph.insertBefore(properties, paragraph.firstChild);
6211
+ return properties;
6212
+ }
6213
+ function work_docx_paragraph_spacing_import_closestParagraphBlock(element) {
6214
+ const block = element?.closest('p, h1, h2, h3, h4, h5, h6, blockquote');
6215
+ return block instanceof HTMLElement ? block : null;
6216
+ }
6217
+ function work_docx_paragraph_spacing_import_numericAttribute(element, name) {
6218
+ const raw = work_docx_paragraph_spacing_import_wordAttribute(element, name);
6219
+ if (null === raw || !raw.trim()) return;
6220
+ const value = Number(raw);
6221
+ return Number.isFinite(value) ? value : void 0;
6222
+ }
6223
+ function work_docx_paragraph_spacing_import_wordAttribute(element, name) {
6224
+ return work_ooxml_package_attribute(element, name) ?? work_ooxml_package_attribute(element, `w:${name}`);
6225
+ }
6226
+ function normalizedLineRule(value) {
6227
+ if ('auto' === value || 'atLeast' === value) return value;
6228
+ if ('exact' === value || 'exactly' === value) return 'exact';
6229
+ }
6230
+ function twipsToPoints(value) {
6231
+ return Number((value / 20).toFixed(2));
6232
+ }
6233
+ function work_docx_paragraph_spacing_import_formatNumber(value) {
6234
+ return Number(value.toFixed(3)).toString();
6235
+ }
6236
+ function work_docx_paragraph_spacing_import_textNodes(root) {
6237
+ const document = root.ownerDocument;
6238
+ const walker = document?.createTreeWalker(root, NodeFilter.SHOW_TEXT);
6239
+ const nodes = [];
6240
+ if (!walker) return nodes;
6241
+ while(walker.nextNode())nodes.push(walker.currentNode);
6242
+ return nodes;
6243
+ }
6244
+ const work_docx_tab_stop_import_WORD_NAMESPACE = 'http://schemas.openxmlformats.org/wordprocessingml/2006/main';
6245
+ const work_docx_tab_stop_import_XML_NAMESPACE = 'http://www.w3.org/XML/1998/namespace';
6246
+ const work_docx_tab_stop_import_TWIPS_PER_CSS_PIXEL = 15;
6247
+ const PARAGRAPH_TAB_STOP_MARKER_PATTERN = /__A3S_WORK_PARAGRAPH_TAB_STOPS_\d+__/g;
6248
+ const INLINE_TAB_MARKER_PATTERN = /__A3S_WORK_INLINE_TAB_\d+__/g;
6249
+ function markDocxParagraphTabStops(document, styleSource, tableStyleSource) {
6250
+ const paragraphs = [];
6251
+ const inlineTabs = [];
6252
+ const styles = resolveDocxParagraphStyleResolver(styleSource);
6253
+ const tableStyles = resolveDocxTableStyleResolver(tableStyleSource);
6254
+ for (const paragraph of descendants(document, 'p')){
6255
+ let properties = directChild(paragraph, 'pPr');
6256
+ const tabStops = resolveDocxParagraphTabStops(docxParagraphPropertySources(properties, styles, docxTableParagraphPropertySources(paragraph, tableStyles)));
6257
+ if (tabStops.length) {
6258
+ properties ??= work_docx_tab_stop_import_insertParagraphProperties(document, paragraph);
6259
+ const marker = `__A3S_WORK_PARAGRAPH_TAB_STOPS_${paragraphs.length + 1}__`;
6260
+ work_docx_tab_stop_import_insertParagraphMarker(document, paragraph, properties, marker);
6261
+ paragraphs.push({
6262
+ marker,
6263
+ tabStops
6264
+ });
6265
+ }
6266
+ for (const tab of inlineRunTabs(paragraph)){
6267
+ const marker = `__A3S_WORK_INLINE_TAB_${inlineTabs.length + 1}__`;
6268
+ const text = document.createElementNS(work_docx_tab_stop_import_WORD_NAMESPACE, 'w:t');
6269
+ text.setAttributeNS(work_docx_tab_stop_import_XML_NAMESPACE, 'xml:space', 'preserve');
6270
+ text.textContent = marker;
6271
+ tab.replaceWith(text);
6272
+ inlineTabs.push(marker);
6273
+ }
6274
+ }
6275
+ return {
6276
+ paragraphs,
6277
+ inlineTabs
6278
+ };
6279
+ }
6280
+ function applyImportedDocxParagraphTabStopMarkers(document, markers) {
6281
+ const tabStopsByMarker = new Map(markers.paragraphs.map(({ marker, tabStops })=>[
6282
+ marker,
6283
+ tabStops
6284
+ ]));
6285
+ for (const node of work_docx_tab_stop_import_textNodes(document.body)){
6286
+ if (!node.data.includes('__A3S_WORK_PARAGRAPH_TAB_STOPS_')) continue;
6287
+ const block = work_docx_tab_stop_import_closestParagraphBlock(node.parentElement);
6288
+ node.data = node.data.replace(PARAGRAPH_TAB_STOP_MARKER_PATTERN, (marker)=>{
6289
+ const tabStops = tabStopsByMarker.get(marker);
6290
+ if (block && tabStops?.length) block.dataset.officeTabStops = serializeDocumentTabStops(tabStops);
6291
+ return '';
6292
+ });
6293
+ }
6294
+ const inlineMarkers = new Set(markers.inlineTabs);
6295
+ for (const node of work_docx_tab_stop_import_textNodes(document.body))if (node.data.includes('__A3S_WORK_INLINE_TAB_')) replaceInlineTabMarkers(node, inlineMarkers);
6296
+ document.body.normalize();
6297
+ }
6298
+ function hasImportedDocxParagraphTabStopMarkers(markers) {
6299
+ return markers.paragraphs.length > 0 || markers.inlineTabs.length > 0;
6300
+ }
6301
+ function resolveDocxParagraphTabStops(sources) {
6302
+ const byPosition = new Map();
6303
+ for (const properties of sources){
6304
+ const tabs = directChild(properties, 'tabs');
6305
+ if (tabs) for (const tab of work_ooxml_package_directChildren(tabs, 'tab')){
6306
+ const positionTwips = work_docx_tab_stop_import_numericAttribute(tab, 'pos');
6307
+ if (void 0 === positionTwips || positionTwips <= 0) continue;
6308
+ const position = positionTwips / work_docx_tab_stop_import_TWIPS_PER_CSS_PIXEL;
6309
+ const value = work_docx_tab_stop_import_wordAttribute(tab, 'val')?.trim();
6310
+ if ('clear' === value || 'bar' === value) {
6311
+ byPosition.delete(position);
6312
+ continue;
6313
+ }
6314
+ byPosition.set(position, {
6315
+ position,
6316
+ alignment: docxTabAlignment(value),
6317
+ leader: docxTabLeader(work_docx_tab_stop_import_wordAttribute(tab, 'leader'))
6318
+ });
6319
+ }
6320
+ }
6321
+ return normalizeDocumentTabStops(Array.from(byPosition.values()));
6322
+ }
6323
+ function inlineRunTabs(paragraph) {
6324
+ return descendants(paragraph, 'tab').filter((tab)=>{
6325
+ let parent = tab.parentElement;
6326
+ while(parent && parent !== paragraph){
6327
+ if ('tabs' === parent.localName) return false;
6328
+ parent = parent.parentElement;
6329
+ }
6330
+ return parent === paragraph;
6331
+ });
6332
+ }
6333
+ function replaceInlineTabMarkers(node, markers) {
6334
+ const matches = Array.from(node.data.matchAll(INLINE_TAB_MARKER_PATTERN));
6335
+ if (!matches.length) return;
6336
+ const fragment = node.ownerDocument.createDocumentFragment();
6337
+ let offset = 0;
6338
+ for (const match of matches){
6339
+ const marker = match[0];
6340
+ const index = match.index ?? 0;
6341
+ if (index > offset) fragment.append(node.data.slice(offset, index));
6342
+ if (markers.has(marker)) {
6343
+ const tab = node.ownerDocument.createElement('span');
6344
+ tab.dataset.documentTab = 'true';
6345
+ tab.className = 'work-document-tab';
6346
+ tab.setAttribute('role', 'separator');
6347
+ tab.setAttribute('aria-label', '制表符');
6348
+ fragment.append(tab);
6349
+ } else fragment.append(marker);
6350
+ offset = index + marker.length;
6351
+ }
6352
+ if (offset < node.data.length) fragment.append(node.data.slice(offset));
6353
+ node.replaceWith(fragment);
6354
+ }
6355
+ function work_docx_tab_stop_import_insertParagraphMarker(document, paragraph, properties, marker) {
6356
+ const run = document.createElementNS(work_docx_tab_stop_import_WORD_NAMESPACE, 'w:r');
6357
+ const text = document.createElementNS(work_docx_tab_stop_import_WORD_NAMESPACE, 'w:t');
6358
+ text.setAttributeNS(work_docx_tab_stop_import_XML_NAMESPACE, 'xml:space', 'preserve');
6359
+ text.textContent = marker;
6360
+ run.append(text);
6361
+ paragraph.insertBefore(run, properties.nextSibling);
6362
+ }
6363
+ function work_docx_tab_stop_import_insertParagraphProperties(document, paragraph) {
6364
+ const properties = document.createElementNS(work_docx_tab_stop_import_WORD_NAMESPACE, 'w:pPr');
6365
+ paragraph.insertBefore(properties, paragraph.firstChild);
6366
+ return properties;
6367
+ }
6368
+ function work_docx_tab_stop_import_closestParagraphBlock(element) {
6369
+ const block = element?.closest('p, h1, h2, h3, h4, h5, h6, blockquote');
6370
+ return block instanceof HTMLElement ? block : null;
6371
+ }
6372
+ function docxTabAlignment(value) {
6373
+ if ('center' === value) return 'center';
6374
+ if ('right' === value || 'end' === value) return 'right';
6375
+ if ('decimal' === value || 'num' === value) return 'decimal';
6376
+ return 'left';
6377
+ }
6378
+ function docxTabLeader(value) {
6379
+ if ('dot' === value) return 'dot';
6380
+ if ('hyphen' === value) return 'hyphen';
6381
+ if ('underscore' === value || 'heavy' === value) return 'underscore';
6382
+ if ('middleDot' === value) return 'middleDot';
6383
+ return 'none';
6384
+ }
6385
+ function work_docx_tab_stop_import_numericAttribute(element, name) {
6386
+ const raw = work_docx_tab_stop_import_wordAttribute(element, name);
6387
+ if (null === raw || !raw.trim()) return;
6388
+ const value = Number(raw);
6389
+ return Number.isFinite(value) ? value : void 0;
6390
+ }
6391
+ function work_docx_tab_stop_import_wordAttribute(element, name) {
6392
+ return work_ooxml_package_attribute(element, name) ?? work_ooxml_package_attribute(element, `w:${name}`);
6393
+ }
6394
+ function work_docx_tab_stop_import_textNodes(root) {
6395
+ const document = root.ownerDocument;
6396
+ const walker = document?.createTreeWalker(root, NodeFilter.SHOW_TEXT);
6397
+ const nodes = [];
6398
+ if (!walker) return nodes;
6399
+ while(walker.nextNode())nodes.push(walker.currentNode);
6400
+ return nodes;
6401
+ }
6402
+ const work_docx_paragraph_format_change_import_WORD_NAMESPACE = 'http://schemas.openxmlformats.org/wordprocessingml/2006/main';
6403
+ const WORD_2012_NAMESPACE = 'http://schemas.microsoft.com/office/word/2012/wordml';
6404
+ const work_docx_paragraph_format_change_import_XML_NAMESPACE = 'http://www.w3.org/XML/1998/namespace';
6405
+ const MAX_PARAGRAPH_FORMATTING_CHANGES = 65536;
6406
+ const PARAGRAPH_FORMATTING_CHANGE_MARKER_PATTERN = /__A3S_WORK_PARAGRAPH_FORMAT_CHANGE_\d+__/g;
6407
+ const SUPPORTED_PARAGRAPH_PROPERTY_CHANGE_CHILDREN = new Set([
6408
+ 'jc',
6409
+ 'bidi',
6410
+ 'ind',
6411
+ 'spacing',
6412
+ 'keepLines',
6413
+ 'keepNext',
6414
+ 'pageBreakBefore',
6415
+ 'widowControl',
6416
+ 'contextualSpacing',
6417
+ 'outlineLvl',
6418
+ 'tabs',
6419
+ 'pBdr',
6420
+ 'shd'
6421
+ ]);
6422
+ function markDocxParagraphFormattingChanges(document, styleSource, themeSource, tableStyleSource) {
6423
+ const paragraphs = [];
6424
+ const styles = resolveDocxParagraphStyleResolver(styleSource);
6425
+ const theme = work_docx_theme_resolveDocxThemeResolver(themeSource);
6426
+ const tableStyles = resolveDocxTableStyleResolver(tableStyleSource);
6427
+ for (const paragraph of descendants(document, 'p')){
6428
+ if (!work_docx_paragraph_format_change_import_isWordElement(paragraph)) continue;
6429
+ const propertyNodes = work_ooxml_package_directChildren(paragraph, 'pPr').filter((element)=>element.namespaceURI === paragraph.namespaceURI);
6430
+ if (1 !== propertyNodes.length) continue;
6431
+ const properties = propertyNodes[0];
6432
+ if (!properties) continue;
6433
+ const change = supportedParagraphFormattingChange(properties);
6434
+ if (!change) continue;
6435
+ if (paragraphs.length >= MAX_PARAGRAPH_FORMATTING_CHANGES) continue;
6436
+ const sources = docxParagraphPropertySources(change.properties, styles, docxTableParagraphPropertySources(paragraph, tableStyles));
6437
+ const borders = resolveDocxParagraphBordersFromSources(sources, theme);
6438
+ if (borders.invalidCount || borders.spoofedCount) continue;
6439
+ const indent = resolveDocxParagraphIndent(sources);
6440
+ const spacing = resolveDocxParagraphSpacing(sources);
6441
+ const pagination = resolveDocxParagraphPagination(sources);
6442
+ const tabStops = resolveDocxParagraphTabStops(sources);
6443
+ const before = serializeDocumentParagraphFormatting({
6444
+ textAlign: resolveDocxParagraphAlignment(sources),
6445
+ paragraphDirection: resolveDocxParagraphDirection(sources),
6446
+ indentLevel: indent.left / 24,
6447
+ rightIndent: indent.right,
6448
+ firstLineIndent: indent.firstLine,
6449
+ spaceBefore: spacing.before ?? null,
6450
+ spaceAfter: spacing.after ?? null,
6451
+ lineHeight: spacing.lineHeight ?? null,
6452
+ lineRule: spacing.lineRule ?? null,
6453
+ autoLineHeight: 'auto' === spacing.lineRule ? documentAutoLineHeight(spacing.lineHeight) : null,
6454
+ keepLines: pagination.keepLines ?? null,
6455
+ keepWithNext: pagination.keepWithNext ?? null,
6456
+ pageBreakBefore: pagination.pageBreakBefore ?? null,
6457
+ widowControl: pagination.widowControl ?? null,
6458
+ contextualSpacing: pagination.contextualSpacing ?? null,
6459
+ outlineLevel: pagination.outlineLevel ?? null,
6460
+ tabStops: tabStops.length ? tabStops : null,
6461
+ paragraphBorders: borders.borders,
6462
+ paragraphShading: resolveDocxParagraphShadingFromSources(sources, theme),
6463
+ defaultCollapsed: pagination.defaultCollapsed ?? null
6464
+ });
6465
+ const marker = `__A3S_WORK_PARAGRAPH_FORMAT_CHANGE_${paragraphs.length + 1}__`;
6466
+ work_docx_paragraph_format_change_import_insertParagraphMarker(document, paragraph, properties, marker);
6467
+ paragraphs.push({
6468
+ marker,
6469
+ id: `docx-paragraph-format-change-${change.id}`,
6470
+ author: change.author,
6471
+ date: normalizeRevisionDate(change.date),
6472
+ before
6473
+ });
6474
+ }
6475
+ return {
6476
+ paragraphs
6477
+ };
6478
+ }
6479
+ function applyImportedDocxParagraphFormattingChangeMarkers(document, markers) {
6480
+ const changes = new Map(markers.paragraphs.map((change)=>[
6481
+ change.marker,
6482
+ change
6483
+ ]));
6484
+ for (const node of work_docx_paragraph_format_change_import_textNodes(document.body))if (node.data.includes('__A3S_WORK_PARAGRAPH_FORMAT_CHANGE_')) node.data = node.data.replace(PARAGRAPH_FORMATTING_CHANGE_MARKER_PATTERN, (marker)=>{
6485
+ const change = changes.get(marker);
6486
+ const block = change ? work_docx_paragraph_format_change_import_closestParagraphBlock(node.parentElement, node) : null;
6487
+ if (block && change) applyParagraphChange(block, change);
6488
+ return '';
6489
+ });
6490
+ document.body.normalize();
6491
+ }
6492
+ function hasImportedDocxParagraphFormattingChangeMarkers(markers) {
6493
+ return markers.paragraphs.length > 0;
6494
+ }
6495
+ function isSupportedDocxParagraphFormattingChange(change) {
6496
+ const parent = change.parentElement;
6497
+ const paragraph = parent?.parentElement;
6498
+ return Boolean(parent?.localName === 'pPr' && DOCX_WORDPROCESSING_NAMESPACES.has(parent.namespaceURI ?? '') && paragraph?.localName === 'p' && DOCX_WORDPROCESSING_NAMESPACES.has(paragraph.namespaceURI ?? '') && 1 === Array.from(parent.children).filter((child)=>'pPrChange' === child.localName).length && supportedParagraphFormattingChangeElement(change));
6499
+ }
6500
+ function supportedParagraphFormattingChange(properties) {
6501
+ const changes = Array.from(properties.children).filter((child)=>'pPrChange' === child.localName);
6502
+ return 1 === changes.length ? supportedParagraphFormattingChangeElement(changes[0]) : null;
6503
+ }
6504
+ function supportedParagraphFormattingChangeElement(change) {
6505
+ if ('pPrChange' !== change.localName || !DOCX_WORDPROCESSING_NAMESPACES.has(change.namespaceURI ?? '')) return null;
6506
+ const propertyNodes = Array.from(change.children).filter((child)=>'pPr' === child.localName && DOCX_WORDPROCESSING_NAMESPACES.has(child.namespaceURI ?? ''));
6507
+ if (1 !== propertyNodes.length || 1 !== change.children.length) return null;
6508
+ const properties = propertyNodes[0];
6509
+ if (!properties) return null;
6510
+ const names = new Set();
6511
+ for (const child of Array.from(properties.children)){
6512
+ const supportedWordChild = DOCX_WORDPROCESSING_NAMESPACES.has(child.namespaceURI ?? '') && SUPPORTED_PARAGRAPH_PROPERTY_CHANGE_CHILDREN.has(child.localName);
6513
+ const supportedCollapsed = 'collapsed' === child.localName && child.namespaceURI === WORD_2012_NAMESPACE;
6514
+ if (!supportedWordChild && !supportedCollapsed || names.has(child.localName)) return null;
6515
+ names.add(child.localName);
6516
+ }
6517
+ const id = work_ooxml_package_attribute(change, 'id')?.trim() ?? '';
6518
+ const author = work_ooxml_package_attribute(change, 'author')?.trim() ?? '';
6519
+ const date = work_ooxml_package_attribute(change, 'date');
6520
+ if (!/^\+?\d{1,10}$/.test(id) || !author || author.length > 255) return null;
6521
+ if (date && !Number.isFinite(Date.parse(date))) return null;
6522
+ return {
6523
+ id,
6524
+ author,
6525
+ date,
6526
+ properties
6527
+ };
6528
+ }
6529
+ function applyParagraphChange(element, change) {
6530
+ element.dataset.documentChange = 'true';
6531
+ element.dataset.changeKind = 'paragraph-formatting';
6532
+ element.dataset.changeId = change.id;
6533
+ element.dataset.changeAuthor = change.author;
6534
+ element.dataset.changeDate = change.date;
6535
+ element.dataset.changeBefore = change.before;
6536
+ }
6537
+ function work_docx_paragraph_format_change_import_insertParagraphMarker(document, paragraph, properties, marker) {
6538
+ const namespace = paragraph.namespaceURI ?? work_docx_paragraph_format_change_import_WORD_NAMESPACE;
6539
+ const prefix = paragraph.prefix || 'w';
6540
+ const run = document.createElementNS(namespace, `${prefix}:r`);
6541
+ const text = document.createElementNS(namespace, `${prefix}:t`);
6542
+ text.setAttributeNS(work_docx_paragraph_format_change_import_XML_NAMESPACE, 'xml:space', 'preserve');
6543
+ text.textContent = marker;
6544
+ run.append(text);
6545
+ paragraph.insertBefore(run, properties.nextSibling);
6546
+ }
6547
+ function work_docx_paragraph_format_change_import_closestParagraphBlock(element, markerNode) {
6548
+ const block = element?.closest('p, h1, h2, h3, h4, h5, h6, blockquote, li');
6549
+ if (!(block instanceof HTMLElement)) return null;
6550
+ return 'li' === block.tagName.toLowerCase() ? work_docx_paragraph_format_change_import_wrapListItemParagraph(block, markerNode) : block;
6551
+ }
6552
+ function work_docx_paragraph_format_change_import_wrapListItemParagraph(item, markerNode) {
6553
+ let anchor = markerNode;
6554
+ while(anchor.parentNode && anchor.parentNode !== item)anchor = anchor.parentNode;
6555
+ const children = Array.from(item.childNodes);
6556
+ const anchorIndex = children.indexOf(anchor);
6557
+ if (anchorIndex < 0) return item;
6558
+ let start = anchorIndex;
6559
+ let end = anchorIndex;
6560
+ while(start > 0 && !work_docx_paragraph_format_change_import_isListItemBlock(children[start - 1]))start -= 1;
6561
+ while(end + 1 < children.length && !work_docx_paragraph_format_change_import_isListItemBlock(children[end + 1]))end += 1;
6562
+ const paragraph = item.ownerDocument.createElement('p');
6563
+ const grouped = children.slice(start, end + 1);
6564
+ item.insertBefore(paragraph, grouped[0] ?? null);
6565
+ paragraph.append(...grouped);
6566
+ return paragraph;
6567
+ }
6568
+ function work_docx_paragraph_format_change_import_isListItemBlock(node) {
6569
+ return node instanceof HTMLElement && [
6570
+ 'blockquote',
6571
+ 'div',
6572
+ 'h1',
6573
+ 'h2',
6574
+ 'h3',
6575
+ 'h4',
6576
+ 'h5',
6577
+ 'h6',
6578
+ 'hr',
6579
+ 'ol',
6580
+ 'p',
6581
+ 'pre',
6582
+ 'table',
6583
+ 'ul'
6584
+ ].includes(node.tagName.toLowerCase());
6585
+ }
6586
+ function normalizeRevisionDate(value) {
6587
+ if (!value) return '';
6588
+ const time = Date.parse(value);
6589
+ return Number.isFinite(time) ? new Date(time).toISOString() : '';
6590
+ }
6591
+ function work_docx_paragraph_format_change_import_isWordElement(element) {
6592
+ return DOCX_WORDPROCESSING_NAMESPACES.has(element.namespaceURI ?? '');
6593
+ }
6594
+ function work_docx_paragraph_format_change_import_textNodes(root) {
6595
+ const document = root.ownerDocument;
6596
+ const walker = document?.createTreeWalker(root, NodeFilter.SHOW_TEXT);
6597
+ const nodes = [];
6598
+ if (!walker) return nodes;
6599
+ while(walker.nextNode())nodes.push(walker.currentNode);
6600
+ return nodes;
6601
+ }
6602
+ const work_docx_run_formatting_import_WORD_NAMESPACE = 'http://schemas.openxmlformats.org/wordprocessingml/2006/main';
6603
+ const work_docx_run_formatting_import_XML_NAMESPACE = 'http://www.w3.org/XML/1998/namespace';
6604
+ const RUN_FORMATTING_MARKER_PATTERN = /__A3S_WORK_RUN_(?:START|END)_\d+__/g;
6605
+ const SUPPORTED_RUN_PROPERTY_CHANGE_CHILDREN = new Set([
6606
+ 'b',
6607
+ 'bCs',
6608
+ 'i',
6609
+ 'iCs',
6610
+ 'u',
6611
+ 'strike',
6612
+ 'dstrike',
6613
+ 'rFonts',
6614
+ 'sz',
6615
+ 'szCs',
6616
+ 'color',
6617
+ 'highlight',
6618
+ 'shd',
6619
+ 'snapToGrid',
6620
+ 'cs',
6621
+ 'rtl',
6622
+ 'vertAlign'
6623
+ ]);
6624
+ function markDocxRunFormatting(document, styleSource, themeSource, tableStyleSource) {
6625
+ const runs = [];
6626
+ const styles = resolveDocxParagraphStyleResolver(styleSource);
6627
+ const theme = work_docx_theme_resolveDocxThemeResolver(themeSource);
6628
+ const tableStyles = resolveDocxTableStyleResolver(tableStyleSource);
6629
+ for (const run of descendants(document, 'r')){
6630
+ const runText = directRunText(run);
6631
+ if (!runText || runText.includes('__A3S_')) continue;
6632
+ const paragraph = work_docx_run_formatting_import_closestAncestor(run, 'p');
6633
+ if (!paragraph) continue;
6634
+ const paragraphProperties = directChild(paragraph, 'pPr');
6635
+ const runProperties = directChild(run, 'rPr');
6636
+ const formatting = resolvedRunFormatting(docxRunPropertySources(paragraphProperties, runProperties, styles, docxTableRunPropertySources(run, tableStyles)), theme, runText);
6637
+ const change = importedRunFormattingChange(runProperties, paragraphProperties, styles, docxTableRunPropertySources(run, tableStyles), theme, runText);
6638
+ if (!Object.keys(formatting).length && !change) continue;
6639
+ const index = runs.length + 1;
6640
+ const startMarker = `__A3S_WORK_RUN_START_${index}__`;
6641
+ const endMarker = `__A3S_WORK_RUN_END_${index}__`;
6642
+ insertRunMarkers(document, run, runProperties, startMarker, endMarker);
6643
+ runs.push({
6644
+ startMarker,
6645
+ endMarker,
6646
+ formatting,
6647
+ ...change ? {
6648
+ change
6649
+ } : {}
6650
+ });
6651
+ }
6652
+ return {
6653
+ runs
6654
+ };
6655
+ }
6656
+ function applyImportedDocxRunFormattingMarkers(document, markers) {
6657
+ const replacements = new Map();
6658
+ for (const marker of markers.runs){
6659
+ const markup = formattingMarkup(document, marker.formatting);
6660
+ const change = marker.change ? formattingChangeMarkup(document, marker.change) : {
6661
+ start: '',
6662
+ end: ''
6663
+ };
6664
+ replacements.set(marker.startMarker, `${change.start}${markup.start}`);
6665
+ replacements.set(marker.endMarker, `${markup.end}${change.end}`);
6666
+ }
6667
+ document.body.innerHTML = document.body.innerHTML.replace(RUN_FORMATTING_MARKER_PATTERN, (marker)=>replacements.get(marker) ?? '');
6668
+ }
6669
+ function hasImportedDocxRunFormattingMarkers(markers) {
6670
+ return markers.runs.length > 0;
6671
+ }
6672
+ function resolvedRunFormatting(propertySources, theme, runText) {
6673
+ const fonts = {};
6674
+ let fontSize;
6675
+ let complexFontSize;
6676
+ let color;
6677
+ let backgroundColor;
6678
+ let themeColor;
6679
+ let themeFill;
6680
+ let bold;
6681
+ let complexBold;
6682
+ let italic;
6683
+ let complexItalic;
6684
+ let underline;
6685
+ let strike;
6686
+ let subscript;
6687
+ let superscript;
6688
+ let snapToGrid;
6689
+ let complexScriptFormatting;
6690
+ let rightToLeft;
6691
+ let fontHint;
6692
+ for (const properties of propertySources){
6693
+ bold = overriddenBoolean(bold, onOffProperty(properties, 'b'));
6694
+ complexBold = overriddenBoolean(complexBold, onOffProperty(properties, 'bCs'));
6695
+ italic = overriddenBoolean(italic, onOffProperty(properties, 'i'));
6696
+ complexItalic = overriddenBoolean(complexItalic, onOffProperty(properties, 'iCs'));
6697
+ underline = overriddenBoolean(underline, underlineProperty(properties));
6698
+ strike = overriddenBoolean(strike, onOffProperty(properties, 'strike'));
6699
+ strike = overriddenBoolean(strike, onOffProperty(properties, 'dstrike'));
6700
+ const verticalAlign = directChild(properties, 'vertAlign');
6701
+ if (verticalAlign) {
6702
+ const value = work_docx_run_formatting_import_wordAttribute(verticalAlign, 'val')?.trim().toLowerCase();
6703
+ subscript = "subscript" === value;
6704
+ superscript = "superscript" === value;
6705
+ if ('baseline' === value) {
6706
+ subscript = false;
6707
+ superscript = false;
6708
+ }
6709
+ }
6710
+ snapToGrid = overriddenBoolean(snapToGrid, onOffProperty(properties, 'snapToGrid'));
6711
+ complexScriptFormatting = overriddenBoolean(complexScriptFormatting, onOffProperty(properties, 'cs'));
6712
+ rightToLeft = overriddenBoolean(rightToLeft, onOffProperty(properties, 'rtl'));
6713
+ const runFonts = directChild(properties, 'rFonts');
6714
+ if (runFonts) {
6715
+ fontHint = resolvedFontHint(runFonts) ?? fontHint;
6716
+ assignFont(fonts, 'ascii', resolvedFont(runFonts, 'ascii', 'asciiTheme', theme));
6717
+ assignFont(fonts, 'hAnsi', resolvedFont(runFonts, 'hAnsi', 'hAnsiTheme', theme));
6718
+ assignFont(fonts, 'eastAsia', resolvedFont(runFonts, 'eastAsia', 'eastAsiaTheme', theme));
6719
+ assignFont(fonts, 'complex', resolvedFont(runFonts, 'cs', 'cstheme', theme));
6720
+ }
6721
+ const size = work_docx_run_formatting_import_numericAttribute(directChild(properties, 'sz'), 'val');
6722
+ if (void 0 !== size && size > 0) fontSize = Math.min(512, size / 2);
6723
+ const complexSize = work_docx_run_formatting_import_numericAttribute(directChild(properties, 'szCs'), 'val');
6724
+ if (void 0 !== complexSize && complexSize > 0) complexFontSize = Math.min(512, complexSize / 2);
6725
+ const colorElement = directChild(properties, 'color');
6726
+ if (colorElement) {
6727
+ const value = work_docx_run_formatting_import_wordAttribute(colorElement, 'val')?.trim();
6728
+ 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'));
6729
+ if (themed) {
6730
+ color = `#${themed}`;
6731
+ themeColor = work_docx_run_formatting_import_themeReference(colorElement, 'themeColor', 'themeTint', 'themeShade', color);
6732
+ } else if (value?.toLowerCase() === 'auto') {
6733
+ color = 'inherit';
6734
+ themeColor = void 0;
6735
+ } else if (value && /^[0-9a-f]{6}$/i.test(value)) {
6736
+ color = `#${value.toLowerCase()}`;
6737
+ themeColor = void 0;
6738
+ }
6739
+ }
6740
+ const highlight = directChild(properties, 'highlight');
6741
+ if (highlight) {
6742
+ const value = work_docx_run_formatting_import_wordAttribute(highlight, 'val')?.trim().toLowerCase();
6743
+ if (value) {
6744
+ backgroundColor = wordHighlightColor(value);
6745
+ themeFill = void 0;
6746
+ }
6747
+ } else {
6748
+ const shading = directChild(properties, 'shd');
6749
+ const fill = shading ? work_docx_run_formatting_import_wordAttribute(shading, 'fill')?.trim() : void 0;
6750
+ 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;
6751
+ if (themed) {
6752
+ backgroundColor = `#${themed}`;
6753
+ themeFill = work_docx_run_formatting_import_themeReference(shading, 'themeFill', 'themeFillTint', 'themeFillShade', backgroundColor);
6754
+ } else if (fill?.toLowerCase() === 'auto') {
6755
+ backgroundColor = 'transparent';
6756
+ themeFill = void 0;
6757
+ } else if (fill && /^[0-9a-f]{6}$/i.test(fill)) {
6758
+ backgroundColor = `#${fill.toLowerCase()}`;
6759
+ themeFill = void 0;
6760
+ }
6761
+ }
6762
+ }
6763
+ const fontSlot = true === complexScriptFormatting || true === rightToLeft ? 'complex' : docxFontSlotForText(runText, fontHint);
6764
+ const usesComplexFormatting = 'complex' === fontSlot;
6765
+ const resolvedBold = usesComplexFormatting ? complexBold ?? bold : bold;
6766
+ const resolvedItalic = usesComplexFormatting ? complexItalic ?? italic : italic;
6767
+ const resolvedFontSize = usesComplexFormatting ? complexFontSize ?? fontSize : fontSize;
6768
+ let fontFamily = uniqueFonts(orderedFonts(fonts, fontSlot));
6769
+ if (!fontFamily) fontFamily = uniqueFonts(orderedFonts({
6770
+ ascii: docxThemeFont(theme, 'minorAscii'),
6771
+ hAnsi: docxThemeFont(theme, 'minorHAnsi'),
6772
+ eastAsia: docxThemeFont(theme, 'minorEastAsia'),
6773
+ complex: docxThemeFont(theme, 'minorBidi')
6774
+ }, fontSlot));
6775
+ const hasRunPropertySource = propertySources.length > 0;
6776
+ return {
6777
+ ...void 0 !== resolvedBold || hasRunPropertySource ? {
6778
+ bold: resolvedBold ?? false
6779
+ } : {},
6780
+ ...void 0 !== resolvedItalic || hasRunPropertySource ? {
6781
+ italic: resolvedItalic ?? false
6782
+ } : {},
6783
+ ...void 0 !== underline || hasRunPropertySource ? {
6784
+ underline: underline ?? false
6785
+ } : {},
6786
+ ...void 0 !== strike || hasRunPropertySource ? {
6787
+ strike: strike ?? false
6788
+ } : {},
6789
+ ...void 0 !== subscript ? {
6790
+ subscript
6791
+ } : {},
6792
+ ...void 0 !== superscript ? {
6793
+ superscript
6794
+ } : {},
6795
+ ...fontFamily ? {
6796
+ fontFamily,
6797
+ wordLineHeightFactor: documentWordLineHeightFactor(fontFamily)
6798
+ } : {},
6799
+ ...void 0 !== resolvedFontSize ? {
6800
+ fontSize: resolvedFontSize
6801
+ } : {},
6802
+ ...void 0 !== snapToGrid ? {
6803
+ wordSnapToGrid: snapToGrid
6804
+ } : {},
6805
+ ...color ? {
6806
+ color
6807
+ } : {},
6808
+ ...backgroundColor ? {
6809
+ backgroundColor
6810
+ } : {},
6811
+ ...themeColor ? {
6812
+ themeColor
6813
+ } : {},
6814
+ ...themeFill ? {
6815
+ themeFill
6816
+ } : {}
6817
+ };
6818
+ }
6819
+ function insertRunMarkers(document, run, properties, startMarker, endMarker) {
6820
+ const start = markerText(document, startMarker);
6821
+ const end = markerText(document, endMarker);
6822
+ run.insertBefore(start, properties?.nextSibling ?? run.firstChild);
6823
+ run.append(end);
6824
+ }
6825
+ function markerText(document, marker) {
6826
+ const text = document.createElementNS(work_docx_run_formatting_import_WORD_NAMESPACE, 'w:t');
6827
+ text.setAttributeNS(work_docx_run_formatting_import_XML_NAMESPACE, 'xml:space', 'preserve');
6828
+ text.textContent = marker;
6829
+ return text;
6830
+ }
6831
+ function formattingMarkup(document, formatting) {
6832
+ const span = document.createElement('span');
6833
+ if (false === formatting.bold) span.style.fontWeight = 'normal';
6834
+ if (false === formatting.italic) span.style.fontStyle = 'normal';
6835
+ if ((false === formatting.underline || false === formatting.strike) && !formatting.underline && !formatting.strike) span.style.textDecorationLine = 'none';
6836
+ if (formatting.fontFamily) span.style.fontFamily = formatting.fontFamily;
6837
+ if (void 0 !== formatting.wordLineHeightFactor) {
6838
+ const factor = formatLineHeightFactor(formatting.wordLineHeightFactor);
6839
+ span.dataset.officeWordLineHeightFactor = factor;
6840
+ span.style.setProperty('--work-document-word-line-height-factor', factor);
6841
+ }
6842
+ if (void 0 !== formatting.wordSnapToGrid) span.dataset.officeWordSnapToGrid = String(formatting.wordSnapToGrid);
6843
+ if (void 0 !== formatting.fontSize) span.style.fontSize = `${work_docx_run_formatting_import_formatNumber(formatting.fontSize)}pt`;
6844
+ if (formatting.color) span.style.color = formatting.color;
6845
+ const themeColor = serializeDocxThemeReference(formatting.themeColor ?? null);
6846
+ if (themeColor) span.dataset.officeThemeColor = themeColor;
6847
+ if (formatting.backgroundColor) span.style.backgroundColor = formatting.backgroundColor;
6848
+ const themeFill = serializeDocxThemeReference(formatting.themeFill ?? null);
6849
+ if (themeFill) span.dataset.officeThemeFill = themeFill;
6850
+ const html = span.outerHTML;
6851
+ const tags = [
6852
+ ...formatting.bold ? [
6853
+ 'strong'
6854
+ ] : [],
6855
+ ...formatting.italic ? [
6856
+ 'em'
6857
+ ] : [],
6858
+ ...formatting.underline ? [
6859
+ 'u'
6860
+ ] : [],
6861
+ ...formatting.strike ? [
6862
+ 's'
6863
+ ] : [],
6864
+ ...formatting.subscript ? [
6865
+ 'sub'
6866
+ ] : [],
6867
+ ...formatting.superscript ? [
6868
+ 'sup'
6869
+ ] : []
6870
+ ];
6871
+ return {
6872
+ start: `${html.slice(0, html.indexOf('>') + 1)}${tags.map((tag)=>`<${tag}>`).join('')}`,
6873
+ end: `${[
6874
+ ...tags
6875
+ ].reverse().map((tag)=>`</${tag}>`).join('')}</span>`
6876
+ };
6877
+ }
6878
+ function importedRunFormattingChange(runProperties, paragraphProperties, styles, contextualProperties, theme, runText) {
6879
+ const parsed = supportedRunFormattingChange(runProperties);
6880
+ if (!parsed) return;
6881
+ const beforeFormatting = resolvedRunFormatting(docxRunPropertySources(paragraphProperties, parsed.properties, styles, contextualProperties), theme, runText);
6882
+ return {
6883
+ id: `docx-format-change-${parsed.id}`,
6884
+ author: parsed.author,
6885
+ date: work_docx_run_formatting_import_normalizeRevisionDate(parsed.date),
6886
+ before: importedDocumentCharacterFormatting({
6887
+ ...beforeFormatting,
6888
+ themeColor: serializeDocxThemeReference(beforeFormatting.themeColor ?? null),
6889
+ themeFill: serializeDocxThemeReference(beforeFormatting.themeFill ?? null)
6890
+ })
6891
+ };
6892
+ }
6893
+ function isSupportedDocxRunFormattingChange(change) {
6894
+ return Boolean(supportedRunFormattingChangeElement(change));
6895
+ }
6896
+ function supportedRunFormattingChange(runProperties) {
6897
+ if (!runProperties) return null;
6898
+ const changes = Array.from(runProperties.children).filter((child)=>'rPrChange' === child.localName);
6899
+ return 1 === changes.length ? supportedRunFormattingChangeElement(changes[0]) : null;
6900
+ }
6901
+ function supportedRunFormattingChangeElement(change) {
6902
+ if ('rPrChange' !== change.localName || !DOCX_WORDPROCESSING_NAMESPACES.has(change.namespaceURI ?? '')) return null;
6903
+ const properties = Array.from(change.children).filter((child)=>'rPr' === child.localName && DOCX_WORDPROCESSING_NAMESPACES.has(child.namespaceURI ?? ''));
6904
+ if (1 !== properties.length || 1 !== change.children.length) return null;
6905
+ const source = properties[0];
6906
+ const names = new Set();
6907
+ for (const child of Array.from(source.children)){
6908
+ if (!DOCX_WORDPROCESSING_NAMESPACES.has(child.namespaceURI ?? '') || !SUPPORTED_RUN_PROPERTY_CHANGE_CHILDREN.has(child.localName) || names.has(child.localName)) return null;
6909
+ names.add(child.localName);
6910
+ }
6911
+ const id = work_ooxml_package_attribute(change, 'id')?.trim() ?? '';
6912
+ const author = work_ooxml_package_attribute(change, 'author')?.trim() ?? '';
6913
+ const date = work_ooxml_package_attribute(change, 'date');
6914
+ if (!/^\+?\d{1,10}$/.test(id) || !author || author.length > 255) return null;
6915
+ if (date && !Number.isFinite(Date.parse(date))) return null;
6916
+ return {
6917
+ id,
6918
+ author,
6919
+ date,
6920
+ properties: source
6921
+ };
6922
+ }
6923
+ function formattingChangeMarkup(document, change) {
6924
+ const span = document.createElement('span');
6925
+ span.dataset.documentChange = 'true';
6926
+ span.dataset.changeKind = 'formatting';
6927
+ span.dataset.changeId = change.id;
6928
+ span.dataset.changeAuthor = change.author;
6929
+ span.dataset.changeDate = change.date;
6930
+ span.dataset.changeBefore = change.before;
6931
+ const html = span.outerHTML;
6932
+ return {
6933
+ start: html.slice(0, html.indexOf('>') + 1),
6934
+ end: '</span>'
6935
+ };
6936
+ }
6937
+ function work_docx_run_formatting_import_normalizeRevisionDate(value) {
6938
+ if (!value) return '';
6939
+ const time = Date.parse(value);
6940
+ return Number.isFinite(time) ? new Date(time).toISOString() : '';
6941
+ }
6942
+ function work_docx_run_formatting_import_themeReference(element, themeName, tintName, shadeName, resolved) {
6943
+ const theme = work_docx_run_formatting_import_wordAttribute(element, themeName)?.trim();
6944
+ if (!theme) return;
6945
+ const tint = normalizedByteHex(work_docx_run_formatting_import_wordAttribute(element, tintName));
6946
+ const shade = normalizedByteHex(work_docx_run_formatting_import_wordAttribute(element, shadeName));
6947
+ return {
6948
+ theme,
6949
+ resolved,
6950
+ ...tint ? {
6951
+ tint
6952
+ } : {},
6953
+ ...shade ? {
6954
+ shade
6955
+ } : {}
6956
+ };
6957
+ }
6958
+ function normalizedByteHex(value) {
6959
+ const normalized = value?.trim().toUpperCase();
6960
+ return normalized && /^[0-9A-F]{2}$/.test(normalized) ? normalized : void 0;
6961
+ }
6962
+ function overriddenBoolean(current, next) {
6963
+ return void 0 === next ? current : next;
6964
+ }
6965
+ function onOffProperty(properties, propertyName) {
6966
+ const element = directChild(properties, propertyName);
6967
+ if (!element) return;
6968
+ const value = work_docx_run_formatting_import_wordAttribute(element, 'val')?.trim().toLowerCase();
6969
+ return '0' !== value && 'false' !== value && 'off' !== value;
6970
+ }
6971
+ function underlineProperty(properties) {
6972
+ const element = directChild(properties, 'u');
6973
+ if (!element) return;
6974
+ const value = work_docx_run_formatting_import_wordAttribute(element, 'val')?.trim().toLowerCase();
6975
+ return '0' !== value && 'false' !== value && 'off' !== value && 'none' !== value;
6976
+ }
6977
+ function directRunText(run) {
6978
+ return Array.from(run.children).filter((child)=>'t' === child.localName || 'delText' === child.localName).map((child)=>child.textContent ?? '').join('');
6979
+ }
6980
+ function work_docx_run_formatting_import_closestAncestor(element, localName) {
6981
+ let current = element.parentElement;
6982
+ while(current){
6983
+ if (current.localName === localName) return current;
6984
+ current = current.parentElement;
6985
+ }
6986
+ return null;
6987
+ }
6988
+ function assignFont(fonts, key, value) {
6989
+ const normalized = value?.trim();
6990
+ if (normalized) fonts[key] = normalized;
6991
+ }
6992
+ function resolvedFontHint(element) {
6993
+ const hint = work_docx_run_formatting_import_wordAttribute(element, 'hint')?.trim().toLowerCase();
6994
+ if ('eastasia' === hint) return 'eastAsia';
6995
+ if ('cs' === hint) return 'complex';
6996
+ if ('default' === hint) return 'ascii';
6997
+ }
6998
+ function orderedFonts(fonts, preferred) {
6999
+ const order = {
7000
+ ascii: [
7001
+ 'ascii',
7002
+ 'hAnsi',
7003
+ 'eastAsia',
7004
+ 'complex'
7005
+ ],
7006
+ hAnsi: [
7007
+ 'hAnsi',
7008
+ 'ascii',
7009
+ 'eastAsia',
7010
+ 'complex'
7011
+ ],
7012
+ eastAsia: [
7013
+ 'eastAsia',
7014
+ 'hAnsi',
7015
+ 'ascii',
7016
+ 'complex'
7017
+ ],
7018
+ complex: [
7019
+ 'complex',
7020
+ 'hAnsi',
7021
+ 'ascii',
7022
+ 'eastAsia'
7023
+ ]
7024
+ };
7025
+ return order[preferred].map((slot)=>fonts[slot]);
7026
+ }
7027
+ function docxFontSlotForText(text, hint) {
7028
+ for (const character of text){
7029
+ const codePoint = character.codePointAt(0);
7030
+ if (!(void 0 === codePoint || isNeutralCodePoint(codePoint))) {
7031
+ if (isComplexScriptCodePoint(codePoint)) return 'complex';
7032
+ if (isEastAsianCodePoint(codePoint)) return 'eastAsia';
7033
+ return codePoint <= 0x7f ? 'ascii' : 'hAnsi';
7034
+ }
7035
+ }
7036
+ return hint ?? 'ascii';
7037
+ }
7038
+ function isNeutralCodePoint(codePoint) {
7039
+ return codePoint <= 0x20 || codePoint <= 0x7f && !(codePoint >= 0x41 && codePoint <= 0x5a || codePoint >= 0x61 && codePoint <= 0x7a) || codePoint >= 0x300 && codePoint <= 0x36f || codePoint >= 0x2000 && codePoint <= 0x206f;
7040
+ }
7041
+ function isComplexScriptCodePoint(codePoint) {
7042
+ return codePoint >= 0x0590 && codePoint <= 0x08ff || codePoint >= 0xfb1d && codePoint <= 0xfdff || codePoint >= 0xfe70 && codePoint <= 0xfeff || codePoint >= 0x1ee00 && codePoint <= 0x1eeff;
7043
+ }
7044
+ function isEastAsianCodePoint(codePoint) {
7045
+ 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;
7046
+ }
7047
+ function resolvedFont(element, explicitName, themeName, theme) {
7048
+ const explicit = work_docx_run_formatting_import_wordAttribute(element, explicitName);
7049
+ if (explicit?.trim()) return explicit;
7050
+ return docxThemeFont(theme, work_docx_run_formatting_import_wordAttribute(element, themeName)) ?? null;
7051
+ }
7052
+ function uniqueFonts(values) {
7053
+ const fonts = [
7054
+ ...new Set(values.filter((value)=>!!value))
7055
+ ];
7056
+ return fonts.length ? fonts.map(cssFontFamily).join(', ') : void 0;
7057
+ }
7058
+ function cssFontFamily(value) {
7059
+ return /[\s"',]/.test(value) ? `"${value.replaceAll('\\', '\\\\').replaceAll('"', '\\"')}"` : value;
7060
+ }
7061
+ function work_docx_run_formatting_import_numericAttribute(element, name) {
7062
+ if (!element) return;
7063
+ const raw = work_docx_run_formatting_import_wordAttribute(element, name);
7064
+ if (null === raw || !raw.trim()) return;
7065
+ const value = Number(raw);
7066
+ return Number.isFinite(value) ? value : void 0;
7067
+ }
7068
+ function work_docx_run_formatting_import_wordAttribute(element, name) {
7069
+ return work_ooxml_package_attribute(element, name) ?? work_ooxml_package_attribute(element, `w:${name}`);
7070
+ }
7071
+ function wordHighlightColor(value) {
7072
+ const colors = {
7073
+ black: '#000000',
7074
+ blue: '#0000ff',
7075
+ cyan: '#00ffff',
7076
+ darkblue: '#000080',
7077
+ darkcyan: '#008080',
7078
+ darkgray: '#808080',
7079
+ darkgreen: '#008000',
7080
+ darkmagenta: '#800080',
7081
+ darkred: '#800000',
7082
+ darkyellow: '#808000',
7083
+ green: '#00ff00',
7084
+ lightgray: '#c0c0c0',
7085
+ magenta: '#ff00ff',
7086
+ none: 'transparent',
7087
+ red: '#ff0000',
7088
+ white: '#ffffff',
7089
+ yellow: '#ffff00'
7090
+ };
7091
+ return colors[value] ?? 'transparent';
7092
+ }
7093
+ function work_docx_run_formatting_import_formatNumber(value) {
7094
+ return Number(value.toFixed(2)).toString();
7095
+ }
7096
+ function formatLineHeightFactor(value) {
7097
+ return Number(value.toFixed(4)).toString();
7098
+ }
7099
+ export { applyImportedDocxEquationMarkers, applyImportedDocxParagraphAlignmentMarkers, applyImportedDocxParagraphBorderMarkers, applyImportedDocxParagraphDirectionMarkers, applyImportedDocxParagraphFormattingChangeMarkers, applyImportedDocxParagraphIndentMarkers, applyImportedDocxParagraphPaginationMarkers, applyImportedDocxParagraphShadingMarkers, applyImportedDocxParagraphSpacingMarkers, applyImportedDocxParagraphTabStopMarkers, applyImportedDocxRunFormattingMarkers, createDocxParagraphStyleResolver, createDocxTableStyleResolver, docxCaptionBookmark, docxCaptionReferenceTarget, docxCaptionSequenceKind, docxEquationHtml, docxFieldInstructions, docxFieldOccurrenceIsInlineEditable, docxFieldOccurrences, docxFieldResultText, docxTableCellStyleLayers, docxTablePropertySources, hasImportedDocxParagraphAlignmentMarkers, hasImportedDocxParagraphBorderMarkers, hasImportedDocxParagraphDirectionMarkers, hasImportedDocxParagraphFormattingChangeMarkers, hasImportedDocxParagraphIndentMarkers, hasImportedDocxParagraphPaginationMarkers, hasImportedDocxParagraphShadingMarkers, hasImportedDocxParagraphSpacingMarkers, hasImportedDocxParagraphTabStopMarkers, hasImportedDocxRunFormattingMarkers, hasInvalidDocxFieldStructure, inspectDocxEquation, inspectDocxPageBorders, inspectDocxPageMarginSettings, inspectDocxPageMargins, inspectDocxPageSize, inspectDocxPaperSource, isDocxEquationLikeRoot, isSupportedDocxEquationPlacement, isSupportedDocxParagraphFormattingChange, isSupportedDocxRunFormattingChange, markDocxPackageEquations, markDocxParagraphAlignments, markDocxParagraphBorders, markDocxParagraphDirections, markDocxParagraphFormattingChanges, markDocxParagraphIndents, markDocxParagraphPagination, markDocxParagraphShading, markDocxParagraphSpacing, markDocxParagraphTabStops, markDocxRunFormatting, parseDirectDocxParagraphShading, parseDocxPageBorders, parseDocxPageGeometry, parseDocxPageMargins, parseDocxPaperSource, resolveDocxParagraphBordersForParagraph, resolveDocxTableStyleResolver };