@a3s-lab/office 0.10.0 → 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 (28) hide show
  1. package/COLLABORATION_ROADMAP.md +22 -12
  2. package/README.md +17 -14
  3. package/dist/{0~4705.js → 0~5093.js} +959 -10
  4. package/dist/0~document-editor.js +1 -0
  5. package/dist/0~work-docx-export.js +225 -6
  6. package/dist/0~work-docx-import.js +24 -753
  7. package/dist/0~work-office-diagnostics.js +6 -4
  8. package/dist/4104.js +1 -1
  9. package/dist/8928.js +448 -137
  10. package/dist/internal/features/work/work-document-format-change-tracking.d.ts +1 -1
  11. package/dist/internal/features/work/work-document-paragraph-format-change-tracking.d.ts +7 -0
  12. package/dist/internal/features/work/work-document-paragraph-format-changes.d.ts +8 -0
  13. package/dist/internal/features/work/work-docx-import.d.ts +3 -1
  14. package/dist/internal/features/work/work-docx-paragraph-alignment-import.d.ts +1 -0
  15. package/dist/internal/features/work/work-docx-paragraph-borders-import.d.ts +1 -0
  16. package/dist/internal/features/work/work-docx-paragraph-direction-import.d.ts +1 -0
  17. package/dist/internal/features/work/work-docx-paragraph-format-change-export.d.ts +13 -0
  18. package/dist/internal/features/work/work-docx-paragraph-format-change-import.d.ts +17 -0
  19. package/dist/internal/features/work/work-docx-paragraph-indent-import.d.ts +1 -0
  20. package/dist/internal/features/work/work-docx-paragraph-pagination-import.d.ts +1 -0
  21. package/dist/internal/features/work/work-docx-paragraph-shading-import.d.ts +1 -0
  22. package/dist/internal/features/work/work-docx-paragraph-spacing-import.d.ts +1 -0
  23. package/dist/internal/features/work/work-docx-tab-stop-import.d.ts +1 -0
  24. package/dist/internal/features/work/work-types.d.ts +1 -1
  25. package/dist/office-kernel.wasm +0 -0
  26. package/dist/styles.css +8 -0
  27. package/docs/latest/en/browser-editor-architecture.md +18 -0
  28. package/package.json +5 -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, docxThemeFont, XML_NAMESPACE as work_docx_settings_xml_XML_NAMESPACE, docxThemeColor, 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, serializeDocxThemeReference, documentParagraphShadingDomAttributes, importedDocumentCharacterFormatting, documentParagraphBordersDomAttributes, createDocumentEquationElement, normalizeDocumentPageGeometry, normalizeDocumentPageMargins, documentEquationText, normalizeDocumentPaperSource, documentWordLineHeightFactor } 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,6 +5661,944 @@ function work_docx_paragraph_shading_import_textNodes(root) {
5650
5661
  while(walker.nextNode())nodes.push(walker.currentNode);
5651
5662
  return nodes;
5652
5663
  }
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
+ }
5653
6602
  const work_docx_run_formatting_import_WORD_NAMESPACE = 'http://schemas.openxmlformats.org/wordprocessingml/2006/main';
5654
6603
  const work_docx_run_formatting_import_XML_NAMESPACE = 'http://www.w3.org/XML/1998/namespace';
5655
6604
  const RUN_FORMATTING_MARKER_PATTERN = /__A3S_WORK_RUN_(?:START|END)_\d+__/g;
@@ -5769,9 +6718,9 @@ function resolvedRunFormatting(propertySources, theme, runText) {
5769
6718
  assignFont(fonts, 'eastAsia', resolvedFont(runFonts, 'eastAsia', 'eastAsiaTheme', theme));
5770
6719
  assignFont(fonts, 'complex', resolvedFont(runFonts, 'cs', 'cstheme', theme));
5771
6720
  }
5772
- const size = numericAttribute(directChild(properties, 'sz'), 'val');
6721
+ const size = work_docx_run_formatting_import_numericAttribute(directChild(properties, 'sz'), 'val');
5773
6722
  if (void 0 !== size && size > 0) fontSize = Math.min(512, size / 2);
5774
- const complexSize = numericAttribute(directChild(properties, 'szCs'), 'val');
6723
+ const complexSize = work_docx_run_formatting_import_numericAttribute(directChild(properties, 'szCs'), 'val');
5775
6724
  if (void 0 !== complexSize && complexSize > 0) complexFontSize = Math.min(512, complexSize / 2);
5776
6725
  const colorElement = directChild(properties, 'color');
5777
6726
  if (colorElement) {
@@ -5891,7 +6840,7 @@ function formattingMarkup(document, formatting) {
5891
6840
  span.style.setProperty('--work-document-word-line-height-factor', factor);
5892
6841
  }
5893
6842
  if (void 0 !== formatting.wordSnapToGrid) span.dataset.officeWordSnapToGrid = String(formatting.wordSnapToGrid);
5894
- if (void 0 !== formatting.fontSize) span.style.fontSize = `${formatNumber(formatting.fontSize)}pt`;
6843
+ if (void 0 !== formatting.fontSize) span.style.fontSize = `${work_docx_run_formatting_import_formatNumber(formatting.fontSize)}pt`;
5895
6844
  if (formatting.color) span.style.color = formatting.color;
5896
6845
  const themeColor = serializeDocxThemeReference(formatting.themeColor ?? null);
5897
6846
  if (themeColor) span.dataset.officeThemeColor = themeColor;
@@ -5933,7 +6882,7 @@ function importedRunFormattingChange(runProperties, paragraphProperties, styles,
5933
6882
  return {
5934
6883
  id: `docx-format-change-${parsed.id}`,
5935
6884
  author: parsed.author,
5936
- date: normalizeRevisionDate(parsed.date),
6885
+ date: work_docx_run_formatting_import_normalizeRevisionDate(parsed.date),
5937
6886
  before: importedDocumentCharacterFormatting({
5938
6887
  ...beforeFormatting,
5939
6888
  themeColor: serializeDocxThemeReference(beforeFormatting.themeColor ?? null),
@@ -5985,7 +6934,7 @@ function formattingChangeMarkup(document, change) {
5985
6934
  end: '</span>'
5986
6935
  };
5987
6936
  }
5988
- function normalizeRevisionDate(value) {
6937
+ function work_docx_run_formatting_import_normalizeRevisionDate(value) {
5989
6938
  if (!value) return '';
5990
6939
  const time = Date.parse(value);
5991
6940
  return Number.isFinite(time) ? new Date(time).toISOString() : '';
@@ -6109,7 +7058,7 @@ function uniqueFonts(values) {
6109
7058
  function cssFontFamily(value) {
6110
7059
  return /[\s"',]/.test(value) ? `"${value.replaceAll('\\', '\\\\').replaceAll('"', '\\"')}"` : value;
6111
7060
  }
6112
- function numericAttribute(element, name) {
7061
+ function work_docx_run_formatting_import_numericAttribute(element, name) {
6113
7062
  if (!element) return;
6114
7063
  const raw = work_docx_run_formatting_import_wordAttribute(element, name);
6115
7064
  if (null === raw || !raw.trim()) return;
@@ -6141,10 +7090,10 @@ function wordHighlightColor(value) {
6141
7090
  };
6142
7091
  return colors[value] ?? 'transparent';
6143
7092
  }
6144
- function formatNumber(value) {
7093
+ function work_docx_run_formatting_import_formatNumber(value) {
6145
7094
  return Number(value.toFixed(2)).toString();
6146
7095
  }
6147
7096
  function formatLineHeightFactor(value) {
6148
7097
  return Number(value.toFixed(4)).toString();
6149
7098
  }
6150
- export { applyImportedDocxEquationMarkers, applyImportedDocxParagraphBorderMarkers, applyImportedDocxParagraphShadingMarkers, applyImportedDocxRunFormattingMarkers, createDocxParagraphStyleResolver, createDocxTableStyleResolver, docxCaptionBookmark, docxCaptionReferenceTarget, docxCaptionSequenceKind, docxEquationHtml, docxFieldInstructions, docxFieldOccurrenceIsInlineEditable, docxFieldOccurrences, docxFieldResultText, docxParagraphPropertySources, docxTableCellStyleLayers, docxTableParagraphPropertySources, docxTablePropertySources, hasImportedDocxParagraphBorderMarkers, hasImportedDocxParagraphShadingMarkers, hasImportedDocxRunFormattingMarkers, hasInvalidDocxFieldStructure, inspectDocxEquation, inspectDocxPageBorders, inspectDocxPageMarginSettings, inspectDocxPageMargins, inspectDocxPageSize, inspectDocxPaperSource, isDocxEquationLikeRoot, isSupportedDocxEquationPlacement, isSupportedDocxRunFormattingChange, markDocxPackageEquations, markDocxParagraphBorders, markDocxParagraphShading, markDocxRunFormatting, parseDirectDocxParagraphShading, parseDocxPageBorders, parseDocxPageGeometry, parseDocxPageMargins, parseDocxPaperSource, resolveDocxParagraphBordersForParagraph, resolveDocxParagraphStyleResolver, resolveDocxTableStyleResolver };
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 };