@a3s-lab/office 0.46.0 → 0.48.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.
@@ -1,8 +1,8 @@
1
1
  import jszip from "jszip";
2
2
  import { documentRunBorderDomAttributes, contentTypeForPart, bytesToDataUrl, OoxmlPackage, normalizeDocumentIndexesHtml, firstDescendant, normalizeDocumentParagraphId, applyDocumentParagraphIdentityToElement, descendants, documentHighlightDomAttributes, attribute as work_ooxml_package_attribute, documentHighlightFromDocxValue, serializeDocxThemeReference, normalizeDocumentTableOfContentsHtml, directChildren, documentParagraphShadingDomAttributes, documentProofingDomAttributes, documentParagraphBordersDomAttributes, directChild, documentScriptFontSegments, normalizeDocumentParagraphIdentity, documentRunShadingDomAttributes } from "./6968.js";
3
- import { normalizeDocumentBookmarkName, renderDocumentTableCellMarginOverrides, applyDocumentImageIdentityToElement, documentCharacterPositionDomAttributes, createDocumentImageIdentityRegistry, normalizeDocumentColumns, documentStrikeDomAttributes, normalizeDocumentImageWrapContour, DOCUMENT_TABLE_ROW_ID_ATTRIBUTE, normalizeDocumentBookmarksHtml, applyDocumentTableRowIdentityToElement, normalizeDocumentCaptionsHtml, documentCharacterSpacingDomAttributes, normalizeDocumentImageAlignment, applyDocumentImageLayerToElement, normalizeDocumentNotesHtml, normalizeDocumentBookmarkReferencesHtml, documentCitationTagsFromInstruction, applyDocumentImageWrapContourToElement, documentUnderlineDomAttributes, documentHiddenTextDomAttributes, normalizeDocumentPageChrome, normalizeDocumentImageLayoutOptions, applyDocumentImageCropToElement, documentPageMarginsForLayout, applyDocumentPageGeometry, createDocumentNoteElement, normalizeDocumentImageLayer, DOCUMENT_TABLE_ROW_TEXT_ID_ATTRIBUTE, documentBookmarkReferenceInstruction, applyDocumentImageTransformToElement, documentInitialSectionLayout, normalizeDocumentFieldsHtml, documentCaptionLabel, documentTableBordersFromElement, isContourImageLayout, normalizeDocumentCitationsHtml, normalizeDocumentImageIdentity, normalizeDocumentImageWrapSide, documentKerningDomAttributes, docxDocumentFieldKind, renderDocumentTableBorders, docxBookmarkReferenceTarget, normalizeDocumentImagePosition, wrapsBesideImage, documentPageChromeLegacyFields, documentCharacterScaleDomAttributes, DEFAULT_DOCUMENT_TABLE_GEOMETRY, documentSectionDomAttributes, DEFAULT_DOCUMENT_TABLE_CELL_MARGINS, documentPageMarginBody, documentLegacyTextEffectsDomAttributes, normalizeDocumentTableRowIdentity, normalizeDocumentBookmarkNativeId, documentOpenTypeDomAttributes, uniqueDocumentImageIdentity, applyDocumentTableGeometryToElement, normalizeDocumentImageCrop, documentContentLayoutProperties, documentEmphasisMarkDomAttributes } from "./4174.js";
4
- import { hasImportedDocxIndexMarkers, markDocxRunFormattingIntoState, applyImportedDocxParagraphSpacingMarkers, hasImportedDocxParagraphDirectionMarkers, hasImportedDocxParagraphIndentMarkers, resolveDocxParagraphBordersForParagraph, applyImportedDocxTextBoxMarkers, applyImportedDocxNumberingChangeMarkers, applyImportedDocxParagraphShadingMarkers, markDocxParagraphSpacing, docxCaptionBookmark, docxFieldResultText, markDocxTextBoxes, createDocxParagraphStyleResolver, docxTableCellStyleLayers, createImportedDocxRunFormattingMarkerState, parseDocxPaperSource, resolveDocxLegacyTextEffects, markDocxTablesOfContents, hasImportedDocxParagraphSpacingMarkers, applyImportedDocxIndexMarkers, applyImportedDocxTableOfContentsMarkers, markDocxIndexes, docxTablePropertySources, parseDirectDocxParagraphShading, markDocxPackageEquations, markDocxParagraphIndents, parseDocxPageMargins, resolveDocxRunBorder, parseDocxPageGeometry, docxCaptionReferenceTarget, applyImportedDocxEquationMarkers, hasImportedDocxParagraphPaginationMarkers, createDocxTableStyleResolver, hasImportedDocxParagraphShadingMarkers, isDocxEquationLikeRoot, importedDocxStrike, docxTableRunPropertySources, hasImportedDocxNumberingChangeMarkers, inspectDocxPageMarginSettings, hasImportedDocxRunFormattingMarkers, hasImportedDocxTableOfContentsMarkers, applyImportedDocxParagraphFormattingChangeMarkers, hasImportedDocxParagraphTabStopMarkers, resolveDocxRunShading, docxCaptionSequenceKind, applyImportedDocxRunFormattingMarkers, markDocxParagraphAlignments, markDocxParagraphDirections, hasImportedDocxParagraphBorderMarkers, hasImportedDocxParagraphFormattingChangeMarkers, resolveDocxHiddenText, docxEquationHtml, docxFieldOccurrences, hasImportedDocxParagraphAlignmentMarkers, markDocxParagraphTabStops, applyImportedDocxParagraphIndentMarkers, resolveDocxTableStyleResolver, hasImportedDocxTextBoxMarkers, markDocxNumberingChanges, markDocxParagraphPagination, importedDocxUnderline, markDocxParagraphBorders, applyImportedDocxParagraphDirectionMarkers, applyImportedDocxParagraphAlignmentMarkers, docxFieldOccurrenceIsInlineEditable, applyImportedDocxParagraphBorderMarkers, applyImportedDocxParagraphPaginationMarkers, applyImportedDocxParagraphTabStopMarkers, docxRunPropertySources, markDocxParagraphFormattingChanges, markDocxParagraphShading, parseDocxPageBorders } from "./0~2133.js";
5
- import { readDocxBibliography, resolveDocxProofing, XMLNS_NAMESPACE, docxCharacterScalePercentFromProperties, docxCharacterSpacingTwipsFromProperties, parseBoundedDocxInteger, resolveDocxOpenTypeFeatures, xmlAttributeLocalName, resolveDocxEmphasisMark, createDocxThemeResolver, docxCharacterPositionHalfPointsFromProperties, readDocxImageTransform, docxThemeColor, parseDocxParagraphDefaultCollapsed, resolveDocxKerningThresholdHalfPoints, resolveDocxThemeResolver, DOCX_WORDPROCESSING_NAMESPACES, xmlAttributeNamespace } from "./0~4042.js";
3
+ import { normalizeDocumentBookmarkName, renderDocumentTableCellMarginOverrides, applyDocumentImageIdentityToElement, documentCharacterPositionDomAttributes, createDocumentImageIdentityRegistry, normalizeDocumentColumns, documentStrikeDomAttributes, normalizeDocumentImageWrapContour, DOCUMENT_TABLE_ROW_ID_ATTRIBUTE, normalizeDocumentBookmarksHtml, applyDocumentTableRowIdentityToElement, normalizeDocumentCaptionsHtml, documentCharacterSpacingDomAttributes, normalizeDocumentImageAlignment, applyDocumentImageLayerToElement, normalizeDocumentNotesHtml, normalizeDocumentBookmarkReferencesHtml, documentCitationTagsFromInstruction, applyDocumentImageWrapContourToElement, documentUnderlineDomAttributes, documentHiddenTextDomAttributes, normalizeDocumentPageChrome, normalizeDocumentImageLayoutOptions, applyDocumentImageCropToElement, documentPageMarginsForLayout, applyDocumentPageGeometry, createDocumentNoteElement, normalizeDocumentImageLayer, DOCUMENT_TABLE_ROW_TEXT_ID_ATTRIBUTE, documentBookmarkReferenceInstruction, applyDocumentImageTransformToElement, documentInitialSectionLayout, normalizeDocumentFieldsHtml, documentCaptionLabel, documentTableBordersFromElement, isContourImageLayout, normalizeDocumentCitationsHtml, normalizeDocumentImageIdentity, normalizeDocumentImageWrapSide, supportedDocxDocumentFieldInstruction, documentKerningDomAttributes, docxDocumentFieldKind, renderDocumentTableBorders, docxBookmarkReferenceTarget, normalizeDocumentImagePosition, wrapsBesideImage, documentPageChromeLegacyFields, documentCharacterScaleDomAttributes, DEFAULT_DOCUMENT_TABLE_GEOMETRY, documentSectionDomAttributes, DEFAULT_DOCUMENT_TABLE_CELL_MARGINS, documentPageMarginBody, documentLegacyTextEffectsDomAttributes, normalizeDocumentTableRowIdentity, normalizeDocumentBookmarkNativeId, documentOpenTypeDomAttributes, uniqueDocumentImageIdentity, applyDocumentTableGeometryToElement, normalizeDocumentImageCrop, documentContentLayoutProperties, documentEmphasisMarkDomAttributes, docxDocumentFieldTarget } from "./4174.js";
4
+ import { hasImportedDocxIndexMarkers, markDocxRunFormattingIntoState, applyImportedDocxParagraphSpacingMarkers, hasImportedDocxParagraphDirectionMarkers, hasImportedDocxParagraphIndentMarkers, resolveDocxParagraphBordersForParagraph, applyImportedDocxTextBoxMarkers, applyImportedDocxNumberingChangeMarkers, applyImportedDocxParagraphShadingMarkers, markDocxParagraphSpacing, docxCaptionBookmark, docxFieldResultText, applyImportedDocxContentControlMarkers, createDocxParagraphStyleResolver, markDocxTextBoxes, docxTableCellStyleLayers, createImportedDocxRunFormattingMarkerState, markDocxContentControls, parseDocxPaperSource, resolveDocxLegacyTextEffects, markDocxTablesOfContents, applyImportedDocxIndexMarkers, docxTablePropertySources, applyImportedDocxTableOfContentsMarkers, markDocxIndexes, parseDirectDocxParagraphShading, markDocxPackageEquations, hasImportedDocxParagraphSpacingMarkers, markDocxParagraphIndents, parseDocxPageMargins, resolveDocxRunBorder, parseDocxPageGeometry, docxCaptionReferenceTarget, applyImportedDocxEquationMarkers, hasImportedDocxParagraphPaginationMarkers, createDocxTableStyleResolver, hasImportedDocxParagraphShadingMarkers, isDocxEquationLikeRoot, importedDocxStrike, docxTableRunPropertySources, hasImportedDocxNumberingChangeMarkers, inspectDocxPageMarginSettings, hasImportedDocxRunFormattingMarkers, hasImportedDocxTableOfContentsMarkers, applyImportedDocxParagraphFormattingChangeMarkers, hasImportedDocxContentControlMarkers, hasImportedDocxParagraphTabStopMarkers, resolveDocxRunShading, docxCaptionSequenceKind, applyImportedDocxRunFormattingMarkers, markDocxParagraphAlignments, markDocxParagraphDirections, hasImportedDocxParagraphBorderMarkers, hasImportedDocxParagraphFormattingChangeMarkers, resolveDocxHiddenText, docxEquationHtml, docxFieldOccurrences, hasImportedDocxParagraphAlignmentMarkers, markDocxParagraphTabStops, applyImportedDocxParagraphIndentMarkers, resolveDocxTableStyleResolver, applyImportedDocxParagraphAlignmentMarkers, hasImportedDocxTextBoxMarkers, markDocxNumberingChanges, importedDocxUnderline, markDocxParagraphBorders, applyImportedDocxParagraphDirectionMarkers, markDocxParagraphPagination, docxFieldOccurrenceIsInlineEditable, applyImportedDocxParagraphBorderMarkers, applyImportedDocxParagraphPaginationMarkers, applyImportedDocxParagraphTabStopMarkers, docxRunPropertySources, markDocxParagraphFormattingChanges, markDocxParagraphShading, parseDocxPageBorders } from "./0~3320.js";
5
+ import { readDocxBibliography, resolveDocxProofing, XMLNS_NAMESPACE, docxCharacterScalePercentFromProperties, docxCharacterSpacingTwipsFromProperties, parseBoundedDocxInteger, resolveDocxOpenTypeFeatures, xmlAttributeLocalName, resolveDocxEmphasisMark, createDocxThemeResolver, docxCharacterPositionHalfPointsFromProperties, readDocxImageTransform, docxThemeColor, parseDocxParagraphDefaultCollapsed, resolveDocxKerningThresholdHalfPoints, resolveDocxThemeResolver, DOCX_WORDPROCESSING_NAMESPACES, xmlAttributeNamespace } from "./0~3534.js";
6
6
  import { importDocxPageColor, importedDocumentNoteId } from "./0~4980.js";
7
7
  const WORD_NAMESPACE = 'http://schemas.openxmlformats.org/wordprocessingml/2006/main';
8
8
  const XML_NAMESPACE = 'http://www.w3.org/XML/1998/namespace';
@@ -933,17 +933,34 @@ function work_docx_comment_import_compareDocumentOrder(left, right) {
933
933
  }
934
934
  const work_docx_field_import_WORD_NAMESPACE = 'http://schemas.openxmlformats.org/wordprocessingml/2006/main';
935
935
  const work_docx_field_import_XML_NAMESPACE = 'http://www.w3.org/XML/1998/namespace';
936
- function markDocxBodyFields(document) {
936
+ function markDocxBodyFields(document, bookmarks = []) {
937
+ const bookmarkTargets = bookmarks.length ? new Map(bookmarks.map((bookmark)=>[
938
+ bookmark.sourceName.trim().toLowerCase(),
939
+ {
940
+ id: bookmark.id,
941
+ name: bookmark.name
942
+ }
943
+ ])) : pairedBookmarkTargets(document);
937
944
  const fields = docxFieldOccurrences(document).flatMap((field, index)=>{
938
945
  const kind = docxDocumentFieldKind(field.instruction);
939
- if (!kind || !docxFieldOccurrenceIsInlineEditable(field)) return [];
946
+ if (!kind || !supportedDocxDocumentFieldInstruction(field.instruction) || !docxFieldOccurrenceIsInlineEditable(field)) return [];
947
+ const targetName = docxDocumentFieldTarget(field.instruction) ?? void 0;
948
+ const target = targetName ? bookmarkTargets.get(targetName.toLowerCase()) : void 0;
949
+ if ('pageReference' === kind && !target) return [];
940
950
  const marker = {
941
951
  start: `__A3S_WORK_FIELD_START_${index + 1}__`,
942
952
  end: `__A3S_WORK_FIELD_END_${index + 1}__`,
943
953
  id: `docx-field-${index + 1}`,
944
954
  kind,
945
955
  instruction: field.instruction,
946
- display: docxFieldResultText(field)
956
+ display: docxFieldResultText(field),
957
+ ...target ? {
958
+ targetId: target.id,
959
+ targetName: target.name
960
+ } : {},
961
+ ...'pageReference' === kind ? {
962
+ orphaned: !target
963
+ } : {}
947
964
  };
948
965
  work_docx_field_import_insertFieldBoundaryMarkers(document, field, marker.start, marker.end);
949
966
  return [
@@ -954,6 +971,22 @@ function markDocxBodyFields(document) {
954
971
  fields
955
972
  };
956
973
  }
974
+ function pairedBookmarkTargets(document) {
975
+ const endIds = new Set(descendants(document, 'bookmarkEnd').map((element)=>work_ooxml_package_attribute(element, 'id')?.trim() ?? '').filter(Boolean));
976
+ return new Map(descendants(document, 'bookmarkStart').flatMap((element)=>{
977
+ const id = work_ooxml_package_attribute(element, 'id')?.trim() ?? '';
978
+ const name = work_ooxml_package_attribute(element, 'name')?.trim() ?? '';
979
+ return id && name && endIds.has(id) ? [
980
+ [
981
+ name.toLowerCase(),
982
+ {
983
+ id,
984
+ name
985
+ }
986
+ ]
987
+ ] : [];
988
+ }));
989
+ }
957
990
  function applyImportedDocxFieldMarkers(document, markers) {
958
991
  for (const field of markers.fields){
959
992
  const element = document.createElement('span');
@@ -961,6 +994,9 @@ function applyImportedDocxFieldMarkers(document, markers) {
961
994
  element.dataset.fieldId = field.id;
962
995
  element.dataset.fieldKind = field.kind;
963
996
  element.dataset.fieldInstruction = field.instruction;
997
+ if (field.targetId) element.dataset.fieldTargetId = field.targetId;
998
+ if (field.targetName) element.dataset.fieldTargetName = field.targetName;
999
+ if (field.orphaned) element.dataset.fieldOrphaned = 'true';
964
1000
  const convertedDisplay = work_docx_field_import_replaceMarkerRange(document.body, field.start, field.end, element);
965
1001
  const display = field.display.trim() || convertedDisplay.trim();
966
1002
  element.dataset.fieldDisplay = display;
@@ -2913,6 +2949,10 @@ async function prepareDocxImport(buffer, sourcePackage) {
2913
2949
  textBoxMarkers: {
2914
2950
  textBoxes: []
2915
2951
  },
2952
+ contentControlMarkers: {
2953
+ controls: [],
2954
+ unsupported: 0
2955
+ },
2916
2956
  paragraphIdentityMarkers: {
2917
2957
  paragraphs: []
2918
2958
  },
@@ -2967,6 +3007,7 @@ async function prepareDocxImport(buffer, sourcePackage) {
2967
3007
  const pageColor = importDocxPageColor(document);
2968
3008
  const tableOfContentsMarkers = markDocxTablesOfContents(document);
2969
3009
  const indexMarkers = markDocxIndexes(document);
3010
+ const contentControlMarkers = markDocxContentControls(document);
2970
3011
  const textBoxMarkers = markDocxTextBoxes(document);
2971
3012
  const paragraphIdentityMarkers = markDocxParagraphIdentities(document);
2972
3013
  const numbering = archive.has('word/numbering.xml') ? await archive.xml('word/numbering.xml') : null;
@@ -2975,7 +3016,7 @@ async function prepareDocxImport(buffer, sourcePackage) {
2975
3016
  const captionMarkers = markDocxCaptionFields(document);
2976
3017
  const bookmarkMarkers = markDocxBookmarks(document);
2977
3018
  const citationMarkers = markDocxCitationFields(document);
2978
- const fieldMarkers = markDocxBodyFields(document);
3019
+ const fieldMarkers = markDocxBodyFields(document, bookmarkMarkers.bookmarks);
2979
3020
  const listMarkers = markDocxLists(document, numbering);
2980
3021
  const numberingChangeMarkers = markDocxNumberingChanges(document);
2981
3022
  const imageLayoutMarkerState = createImportedDocxImageLayoutMarkerState();
@@ -3013,7 +3054,7 @@ async function prepareDocxImport(buffer, sourcePackage) {
3013
3054
  const trackChanges = Boolean(settings && firstDescendant(settings, 'trackRevisions')) || changeMarkers.changes.length > 0 || numberingChangeMarkers.groups.length > 0 || paragraphFormattingChangeMarkers.paragraphs.length > 0 || runFormattingMarkers.runs.some((run)=>Boolean(run.change));
3014
3055
  const sectionElements = effectiveSectionProperties(document);
3015
3056
  if (!sectionElements.length) return {
3016
- conversionBuffer: hasImportedDocxCaptionMarkers(captionMarkers) || hasImportedDocxBookmarkMarkers(bookmarkMarkers) || hasImportedDocxChangeMarkers(changeMarkers) || hasImportedDocxCommentMarkers(commentMarkers) || hasImportedDocxCitationMarkers(citationMarkers) || hasImportedDocxFieldMarkers(fieldMarkers) || hasImportedDocxTableOfContentsMarkers(tableOfContentsMarkers) || hasImportedDocxIndexMarkers(indexMarkers) || equationMarkers.changed || hasImportedDocxListMarkers(listMarkers) || hasImportedDocxNumberingChangeMarkers(numberingChangeMarkers) || hasImportedDocxImageLayoutMarkers(imageLayoutMarkers) || hasImportedDocxTextBoxMarkers(textBoxMarkers) || hasImportedDocxParagraphIdentityMarkers(paragraphIdentityMarkers) || hasImportedDocxParagraphFormattingChangeMarkers(paragraphFormattingChangeMarkers) || hasImportedDocxParagraphAlignmentMarkers(paragraphAlignmentMarkers) || hasImportedDocxParagraphDirectionMarkers(paragraphDirectionMarkers) || hasImportedDocxParagraphIndentMarkers(paragraphIndentMarkers) || hasImportedDocxParagraphSpacingMarkers(paragraphSpacingMarkers) || hasImportedDocxParagraphBorderMarkers(paragraphBorderMarkers) || hasImportedDocxParagraphShadingMarkers(paragraphShadingMarkers) || hasImportedDocxParagraphPaginationMarkers(paragraphPaginationMarkers) || hasImportedDocxRunFormattingMarkers(runFormattingMarkers) || hasImportedDocxParagraphTabStopMarkers(tabStopMarkers) || hasImportedDocxTableCellMarkers(tableCellMarkers) || hasImportedDocxTableRowMarkers(tableRowMarkers) || hasImportedDocxTableSizingMarkers(tableSizingMarkers) ? await writeDocumentXml(buffer, document, equationMarkers.parts) : buffer,
3057
+ conversionBuffer: hasImportedDocxCaptionMarkers(captionMarkers) || hasImportedDocxBookmarkMarkers(bookmarkMarkers) || hasImportedDocxChangeMarkers(changeMarkers) || hasImportedDocxCommentMarkers(commentMarkers) || hasImportedDocxCitationMarkers(citationMarkers) || hasImportedDocxFieldMarkers(fieldMarkers) || hasImportedDocxTableOfContentsMarkers(tableOfContentsMarkers) || hasImportedDocxIndexMarkers(indexMarkers) || equationMarkers.changed || hasImportedDocxListMarkers(listMarkers) || hasImportedDocxNumberingChangeMarkers(numberingChangeMarkers) || hasImportedDocxImageLayoutMarkers(imageLayoutMarkers) || hasImportedDocxTextBoxMarkers(textBoxMarkers) || hasImportedDocxContentControlMarkers(contentControlMarkers) || hasImportedDocxParagraphIdentityMarkers(paragraphIdentityMarkers) || hasImportedDocxParagraphFormattingChangeMarkers(paragraphFormattingChangeMarkers) || hasImportedDocxParagraphAlignmentMarkers(paragraphAlignmentMarkers) || hasImportedDocxParagraphDirectionMarkers(paragraphDirectionMarkers) || hasImportedDocxParagraphIndentMarkers(paragraphIndentMarkers) || hasImportedDocxParagraphSpacingMarkers(paragraphSpacingMarkers) || hasImportedDocxParagraphBorderMarkers(paragraphBorderMarkers) || hasImportedDocxParagraphShadingMarkers(paragraphShadingMarkers) || hasImportedDocxParagraphPaginationMarkers(paragraphPaginationMarkers) || hasImportedDocxRunFormattingMarkers(runFormattingMarkers) || hasImportedDocxParagraphTabStopMarkers(tabStopMarkers) || hasImportedDocxTableCellMarkers(tableCellMarkers) || hasImportedDocxTableRowMarkers(tableRowMarkers) || hasImportedDocxTableSizingMarkers(tableSizingMarkers) ? await writeDocumentXml(buffer, document, equationMarkers.parts) : buffer,
3017
3058
  sections: [
3018
3059
  {
3019
3060
  id: 'document-section-1',
@@ -3034,6 +3075,7 @@ async function prepareDocxImport(buffer, sourcePackage) {
3034
3075
  numberingChangeMarkers,
3035
3076
  imageLayoutMarkers,
3036
3077
  textBoxMarkers,
3078
+ contentControlMarkers,
3037
3079
  paragraphIdentityMarkers,
3038
3080
  paragraphFormattingChangeMarkers,
3039
3081
  paragraphAlignmentMarkers,
@@ -3065,7 +3107,7 @@ async function prepareDocxImport(buffer, sourcePackage) {
3065
3107
  }
3066
3108
  if (sections.length > 1) addSectionMarkers(document, sectionElements);
3067
3109
  return {
3068
- conversionBuffer: sections.length > 1 || hasImportedDocxCaptionMarkers(captionMarkers) || hasImportedDocxBookmarkMarkers(bookmarkMarkers) || hasImportedDocxChangeMarkers(changeMarkers) || hasImportedDocxCommentMarkers(commentMarkers) || hasImportedDocxCitationMarkers(citationMarkers) || hasImportedDocxFieldMarkers(fieldMarkers) || hasImportedDocxTableOfContentsMarkers(tableOfContentsMarkers) || hasImportedDocxIndexMarkers(indexMarkers) || equationMarkers.changed || hasImportedDocxListMarkers(listMarkers) || hasImportedDocxNumberingChangeMarkers(numberingChangeMarkers) || hasImportedDocxImageLayoutMarkers(imageLayoutMarkers) || hasImportedDocxTextBoxMarkers(textBoxMarkers) || hasImportedDocxParagraphIdentityMarkers(paragraphIdentityMarkers) || hasImportedDocxParagraphFormattingChangeMarkers(paragraphFormattingChangeMarkers) || hasImportedDocxParagraphAlignmentMarkers(paragraphAlignmentMarkers) || hasImportedDocxParagraphDirectionMarkers(paragraphDirectionMarkers) || hasImportedDocxParagraphIndentMarkers(paragraphIndentMarkers) || hasImportedDocxParagraphSpacingMarkers(paragraphSpacingMarkers) || hasImportedDocxParagraphBorderMarkers(paragraphBorderMarkers) || hasImportedDocxParagraphShadingMarkers(paragraphShadingMarkers) || hasImportedDocxParagraphPaginationMarkers(paragraphPaginationMarkers) || hasImportedDocxRunFormattingMarkers(runFormattingMarkers) || hasImportedDocxParagraphTabStopMarkers(tabStopMarkers) || hasImportedDocxTableCellMarkers(tableCellMarkers) || hasImportedDocxTableRowMarkers(tableRowMarkers) || hasImportedDocxTableSizingMarkers(tableSizingMarkers) ? await writeDocumentXml(buffer, document, equationMarkers.parts) : buffer,
3110
+ conversionBuffer: sections.length > 1 || hasImportedDocxCaptionMarkers(captionMarkers) || hasImportedDocxBookmarkMarkers(bookmarkMarkers) || hasImportedDocxChangeMarkers(changeMarkers) || hasImportedDocxCommentMarkers(commentMarkers) || hasImportedDocxCitationMarkers(citationMarkers) || hasImportedDocxFieldMarkers(fieldMarkers) || hasImportedDocxTableOfContentsMarkers(tableOfContentsMarkers) || hasImportedDocxIndexMarkers(indexMarkers) || equationMarkers.changed || hasImportedDocxListMarkers(listMarkers) || hasImportedDocxNumberingChangeMarkers(numberingChangeMarkers) || hasImportedDocxImageLayoutMarkers(imageLayoutMarkers) || hasImportedDocxTextBoxMarkers(textBoxMarkers) || hasImportedDocxContentControlMarkers(contentControlMarkers) || hasImportedDocxParagraphIdentityMarkers(paragraphIdentityMarkers) || hasImportedDocxParagraphFormattingChangeMarkers(paragraphFormattingChangeMarkers) || hasImportedDocxParagraphAlignmentMarkers(paragraphAlignmentMarkers) || hasImportedDocxParagraphDirectionMarkers(paragraphDirectionMarkers) || hasImportedDocxParagraphIndentMarkers(paragraphIndentMarkers) || hasImportedDocxParagraphSpacingMarkers(paragraphSpacingMarkers) || hasImportedDocxParagraphBorderMarkers(paragraphBorderMarkers) || hasImportedDocxParagraphShadingMarkers(paragraphShadingMarkers) || hasImportedDocxParagraphPaginationMarkers(paragraphPaginationMarkers) || hasImportedDocxRunFormattingMarkers(runFormattingMarkers) || hasImportedDocxParagraphTabStopMarkers(tabStopMarkers) || hasImportedDocxTableCellMarkers(tableCellMarkers) || hasImportedDocxTableRowMarkers(tableRowMarkers) || hasImportedDocxTableSizingMarkers(tableSizingMarkers) ? await writeDocumentXml(buffer, document, equationMarkers.parts) : buffer,
3069
3111
  sections,
3070
3112
  pageColor,
3071
3113
  captionMarkers,
@@ -3081,6 +3123,7 @@ async function prepareDocxImport(buffer, sourcePackage) {
3081
3123
  numberingChangeMarkers,
3082
3124
  imageLayoutMarkers,
3083
3125
  textBoxMarkers,
3126
+ contentControlMarkers,
3084
3127
  paragraphIdentityMarkers,
3085
3128
  paragraphFormattingChangeMarkers,
3086
3129
  paragraphAlignmentMarkers,
@@ -3163,6 +3206,9 @@ function applyDocxSectionsToHtml(html, sections, captionMarkers = {
3163
3206
  tables: []
3164
3207
  }, textBoxMarkers = {
3165
3208
  textBoxes: []
3209
+ }, contentControlMarkers = {
3210
+ controls: [],
3211
+ unsupported: 0
3166
3212
  }) {
3167
3213
  const document = new DOMParser().parseFromString(html, 'text/html');
3168
3214
  applyImportedDocxRunFormattingMarkers(document, runFormattingMarkers);
@@ -3192,6 +3238,7 @@ function applyDocxSectionsToHtml(html, sections, captionMarkers = {
3192
3238
  applyImportedDocxTextBoxMarkers(document, textBoxMarkers);
3193
3239
  applyImportedDocxTableOfContentsMarkers(document, tableOfContentsMarkers);
3194
3240
  applyImportedDocxIndexMarkers(document, indexMarkers);
3241
+ applyImportedDocxContentControlMarkers(document, contentControlMarkers);
3195
3242
  const notes = extractMammothDocumentNotes(document);
3196
3243
  const sourceNodes = Array.from(document.body.childNodes);
3197
3244
  document.body.replaceChildren();
@@ -1,9 +1,9 @@
1
1
  import { __webpack_require__ } from "./0~rslib-runtime.js";
2
2
  import { contentTypeForPart, directChildren, OoxmlPackage, parseXml, firstDescendant, isDocumentParagraphArtBorderStyle, descendants, directChild, xmlContainsAnyElement, attribute, documentRunBorderIsVisible } from "./6968.js";
3
- import { normalizeDocumentBookmarkName, docxBookmarkReferenceTarget, normalizeDocumentBookmarkNativeId, DOCUMENT_LEGACY_TEXT_EFFECT_NAMES, supportedDocxBookmarkReferenceInstruction, documentCitationTagsFromInstruction, docxDocumentFieldKind } from "./4174.js";
4
- import { isSupportedDocxEquationPlacement, inspectDocxPageSize, hasInvalidDocxFieldStructure, createDocxTableStyleResolver, inspectDocxRunBorder, inspectDocxEquation, inspectDocxPageMarginSettings, inspectDocxRunShading, supportedDocxIndexField, docxCaptionSequenceKind, inspectDocxPageBorders, docxCaptionBookmark, inspectDocxLegacyTextEffects, inspectDocxPageMargins, inspectDocxPaperSource, createDocxParagraphStyleResolver, inspectDocxRunFonts, supportedDocxTableOfContentsField, docxFieldOccurrences, supportedDocxIndexEntryField, inspectDocxTextBoxes, markDocxParagraphBorders, isSupportedDocxParagraphFormattingChange, docxFieldOccurrenceIsInlineEditable, inspectDocxHiddenText, isSupportedDocxRunFormattingChange, isSupportedDocxNumberingChange, markDocxParagraphShading, docxFieldInstructions } from "./0~2133.js";
3
+ import { normalizeDocumentBookmarkName, docxBookmarkReferenceTarget, DOCUMENT_LEGACY_TEXT_EFFECT_NAMES, normalizeDocumentBookmarkNativeId, supportedDocxDocumentFieldInstruction, supportedDocxBookmarkReferenceInstruction, documentCitationTagsFromInstruction, docxDocumentFieldKind, docxDocumentFieldTarget } from "./4174.js";
4
+ import { isSupportedDocxEquationPlacement, inspectDocxPageSize, inspectDocxContentControls, hasInvalidDocxFieldStructure, createDocxTableStyleResolver, inspectDocxRunBorder, inspectDocxEquation, inspectDocxPageMarginSettings, inspectDocxRunShading, supportedDocxIndexField, docxCaptionSequenceKind, inspectDocxPageBorders, docxCaptionBookmark, inspectDocxLegacyTextEffects, inspectDocxPageMargins, inspectDocxPaperSource, createDocxParagraphStyleResolver, inspectDocxRunFonts, supportedDocxTableOfContentsField, docxFieldOccurrences, supportedDocxIndexEntryField, inspectDocxTextBoxes, markDocxParagraphBorders, isSupportedDocxParagraphFormattingChange, docxFieldOccurrenceIsInlineEditable, inspectDocxHiddenText, isSupportedDocxRunFormattingChange, isSupportedDocxNumberingChange, markDocxParagraphShading, docxFieldInstructions } from "./0~3320.js";
5
5
  import { normalizeDocumentHref } from "./0~work-document-links.js";
6
- import { xmlAttributeLocalName, resolveDocxOpenTypeFeatures, inspectDocxProofingLanguages, readDocxBibliography, inspectDocxEmphasisMark, createDocxThemeResolver, DOCX_WORD_2010_NAMESPACE, inspectDocxNoProof, parseDocxParagraphDefaultCollapsed, readDocxImageTransform, DOCX_WORDPROCESSING_NAMESPACES, xmlAttributeNamespace, inspectDocxKerningThresholdHalfPoints } from "./0~4042.js";
6
+ import { xmlAttributeLocalName, resolveDocxOpenTypeFeatures, inspectDocxProofingLanguages, readDocxBibliography, inspectDocxEmphasisMark, createDocxThemeResolver, DOCX_WORD_2010_NAMESPACE, inspectDocxNoProof, parseDocxParagraphDefaultCollapsed, readDocxImageTransform, DOCX_WORDPROCESSING_NAMESPACES, xmlAttributeNamespace, inspectDocxKerningThresholdHalfPoints } from "./0~3534.js";
7
7
  import { updateSpreadsheetWorksheetCompatibilitySummary, inspectXlsxPivotTables, isSupportedXlsxChartLegend, isSupportedXlsxChartPlotLayout, xlsxChartNodeUsesStackedGrouping, isSupportedXlsxChartSeriesFormatting, readXlsxFormulaFeaturesFromPackage, inspectXlsxHeaderFooterText, emptySpreadsheetWorksheetCompatibilitySummary, isSupportedXlsxWorksheetImageContentType, MAX_XLSX_WORKSHEET_IMAGE_BYTES, xlsxChartSeriesFormattingShapeProperties, diagnoseXlsxProtection, isEditableXlsxPaperSizeCode, isSupportedXlsxCombinationChartNodes } from "./4166.js";
8
8
  import { spreadsheetConditionalComparisonNeedsUpperValue, isSpreadsheetConditionalIconSetName, isSpreadsheetConditionalComparisonOperator, spreadsheetConditionalIconSetCount, xlsxWorksheetCellEntries } from "./9333.js";
9
9
  import { formulaHasStructuredReference, formulaHasExternalReference, parseSpreadsheetPrintTitles, volatileSpreadsheetFormulaFunctions, stripSpreadsheetSheetQualifier } from "./8715.js";
@@ -117,13 +117,15 @@ function diagnoseDocxCaptions(document) {
117
117
  };
118
118
  const isSupportedBlockField = (field)=>isTableOfContentsField(field) || isIndexField(field);
119
119
  const sequences = fields.filter((field)=>docxCaptionSequenceKind(field.instruction));
120
- const bodyFields = fields.filter((field)=>'orphan' !== field.syntax && Boolean(docxDocumentFieldKind(field.instruction)));
121
- const editableBodyFields = bodyFields.filter(docxFieldOccurrenceIsInlineEditable);
122
- const hasUnsupportedFieldStructure = hasInvalidDocxFieldStructure(document, isSupportedBlockField) || bodyFields.some((field)=>!docxFieldOccurrenceIsInlineEditable(field));
123
120
  const bookmarkNames = new Set([
124
121
  ...captionBookmarkNames(sequences),
125
122
  ...pairedBookmarkNames(document)
126
123
  ]);
124
+ const bodyFields = fields.filter((field)=>'orphan' !== field.syntax && Boolean(docxDocumentFieldKind(field.instruction)));
125
+ const supportedBodyFields = bodyFields.filter((field)=>supportedBodyField(field, bookmarkNames));
126
+ const unsupportedBodyFields = bodyFields.filter((field)=>!supportedBodyField(field, bookmarkNames));
127
+ const editableBodyFields = supportedBodyFields.filter(docxFieldOccurrenceIsInlineEditable);
128
+ const hasUnsupportedFieldStructure = hasInvalidDocxFieldStructure(document, isSupportedBlockField) || bodyFields.some((field)=>!docxFieldOccurrenceIsInlineEditable(field));
127
129
  return {
128
130
  issues: [
129
131
  ...sequences.length ? [
@@ -138,10 +140,18 @@ function diagnoseDocxCaptions(document) {
138
140
  {
139
141
  code: 'docx.fields.body',
140
142
  feature: 'Body fields',
141
- message: 'PAGE, NUMPAGES, SECTION, SECTIONPAGES, DATE, and TIME fields remain live, editable body fields and update in preview, PDF, and native DOCX output.',
143
+ message: 'PAGE, NUMPAGES, SECTION, SECTIONPAGES, NUMWORDS, NUMCHARS, DATE, TIME, and bookmark-backed PAGEREF fields remain live, editable body fields and update in preview, PDF, and native DOCX output.',
142
144
  severity: 'info'
143
145
  }
144
146
  ] : [],
147
+ ...unsupportedBodyFields.length ? [
148
+ {
149
+ code: 'docx.fields.instructions',
150
+ feature: 'Field instructions',
151
+ message: 'Unsupported field switches or PAGEREF targets remain at their cached displayed value; only the bounded common instruction subset is made editable.',
152
+ severity: 'warning'
153
+ }
154
+ ] : [],
145
155
  ...tableOfContentsFields.length ? [
146
156
  {
147
157
  code: 'docx.tableOfContents',
@@ -183,11 +193,16 @@ function captionBookmarkNames(fields) {
183
193
  }
184
194
  function isSupportedCaptionField(instruction, bookmarkNames) {
185
195
  if (documentCitationTagsFromInstruction(instruction).length || /^\s*BIBLIOGRAPHY\b/i.test(instruction)) return true;
186
- if (docxDocumentFieldKind(instruction)) return true;
196
+ if (docxDocumentFieldKind(instruction)) return supportedDocxDocumentFieldInstruction(instruction) && ('pageReference' !== docxDocumentFieldKind(instruction) || Boolean(docxDocumentFieldTarget(instruction) && bookmarkNames.has(docxDocumentFieldTarget(instruction)?.toLowerCase() ?? '')));
187
197
  if (docxCaptionSequenceKind(instruction)) return true;
188
198
  const target = docxBookmarkReferenceTarget(instruction);
189
199
  return Boolean(target && bookmarkNames.has(target.toLowerCase()));
190
200
  }
201
+ function supportedBodyField(field, bookmarkNames) {
202
+ if (!supportedDocxDocumentFieldInstruction(field.instruction)) return false;
203
+ const kind = docxDocumentFieldKind(field.instruction);
204
+ return 'pageReference' !== kind || Boolean(docxDocumentFieldTarget(field.instruction) && bookmarkNames.has(docxDocumentFieldTarget(field.instruction)?.toLowerCase() ?? ''));
205
+ }
191
206
  function pairedBookmarkNames(document) {
192
207
  const endIds = new Set(descendants(document, 'bookmarkEnd').map((bookmark)=>attribute(bookmark, 'id')?.trim() ?? ''));
193
208
  return new Set(descendants(document, 'bookmarkStart').flatMap((bookmark)=>{
@@ -2193,6 +2208,9 @@ async function analyzeDocxCompatibility(file, messages, sourcePackage) {
2193
2208
  const textBoxInspection = inspectDocxTextBoxes(document);
2194
2209
  if (textBoxInspection.supported) issues.push(work_office_diagnostics_issue('docx.text-boxes', 'Text boxes', `${textBoxInspection.supported} isolated WPS text box(es) remain editable with native DrawingML geometry, inline or floating layout, safe page-relative offsets, fill, outline, padding, and vertical alignment. Mixed paragraphs are intentionally kept on the normal DOCX compatibility path.`, 'info'));
2195
2210
  if (textBoxInspection.unsupported) issues.push(work_office_diagnostics_issue('docx.text-boxes.unsupported', 'Text boxes', `${textBoxInspection.unsupported} WPS text box(es) mix a drawing with other paragraph content or have unsupported shape content. Only isolated text-box paragraphs are converted to editable text boxes; the rest may normalize during browser conversion.`));
2211
+ const contentControlInspection = inspectDocxContentControls(document);
2212
+ if (contentControlInspection.supported) issues.push(work_office_diagnostics_issue('docx.content-controls', 'Content controls', `${contentControlInspection.supported} inline text or rich-text content control(s) remain editable with aliases, tags, bounded locking, multiline text, appearance, color, and native DOCX w:sdt round-tripping. Data bindings, placeholders, repeating sections, form controls, and block or relationship-bound controls remain outside the safe subset.`, 'info'));
2213
+ if (contentControlInspection.unsupported) issues.push(work_office_diagnostics_issue('docx.content-controls.unsupported', 'Content controls', `${contentControlInspection.unsupported} body content control(s) use active bindings, placeholders, form semantics, unsupported structure, or malformed properties. They are flattened to safe editable text during browser conversion instead of being revived with incomplete behavior.`));
2196
2214
  if (descendants(document, 'tbl').length) issues.push(work_office_diagnostics_issue('docx.tables', 'Tables', 'Table rows, non-splitting rows, repeated headers, cell shading, vertical alignment, per-edge borders, and paragraph-boundary row continuation remain editable. Native row identities survive body and page-chrome HTML; uniquely matched passive extensions on stable table, row, and cell scopes and their property nodes are retained, while duplicate, cross-kind, relationship-bound, or semantic branches fail closed. Layout algorithm, preferred auto, percentage, or pixel width, alignment, indent, percentage or pixel column widths, table-level cell margins, and cell-level margin overrides are preserved independently across edit, preview, and DOCX export. Percentage column preferences use pixel grid widths as responsive browser fallbacks and remain coherent through merged cells. Nested tables retain independent edit and DOCX geometry, and tall outer rows can paginate at nested-row boundaries. Row-spanning cells continue through every covered physical row with in-cell page breaks and contiguous content ranges; combined row and column spans retain native DOCX merge semantics. Common inherited Word table styles apply whole-table, banded row or column, first or last row or column, corner-cell, border, fill, text-emphasis, paragraph alignment, direction, indents, spacing, line, pagination, and tab-stop rules before direct table, cell, paragraph, and run formatting. Theme tint and shade values resolve to stable RGB for edit and preview, while untouched run colors, run shading, cell fills, and per-edge borders retain their semantic theme references on export; explicit color edits use direct RGB. Less-common conditional paragraph properties may be normalized.'));
2197
2215
  const drawingCount = descendants(document, 'drawing').length;
2198
2216
  const textBoxDrawingCount = textBoxInspection.supported + textBoxInspection.unsupported;