@a3s-lab/office 0.45.0 → 0.47.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,5 +1,5 @@
1
1
  import jszip from "jszip";
2
- import { normalizeDocumentBookmarkName, normalizeDocumentEmphasisMark, DOCUMENT_STRIKE_STYLE_ATTRIBUTE, applyDocumentImageIdentityToElement, documentEmphasisMarkFromElement, DOCUMENT_PAGE_BORDER_EDGES, DOCUMENT_UNDERLINE_STYLE_ATTRIBUTE, createDocumentImageIdentityRegistry, normalizeDocumentColumns, normalizeDocumentTableVerticalAlign, normalizeDocumentTextCase, documentCharacterSpacingTwipsFromElement, documentCharacterPositionHalfPointsFromElement, documentTableColumnPercentagesFromElement, documentTableCellMarginOverridesFromElement, applyDocumentTableRowIdentityToElement, normalizeDocumentBookmarksHtml, documentImageIdentityFromElement, documentTableGeometryFromElement, normalizeDocumentTableRowHeightRule, documentNoteKey, DOCUMENT_LEGACY_TEXT_EMBOSS_ATTRIBUTE, normalizeDocumentHiddenText, documentLegacyTextEffectsConflict, normalizeDocumentTableBorderWidth, normalizeDocumentCharacterSpacingTwips, documentStrikeFormattingFromElement, normalizeDocumentTableBorderStyle, parseDocumentNumberingChange, normalizeDocumentBookmarkReferencesHtml, documentCitationInstruction, documentImageWrapContourFromElement, documentImagePositionFromElement, normalizeDocumentCharacterScalePercent, normalizeDocumentUnderlineStyle, normalizeDocumentPageChrome, documentPageMarginsForLayout, normalizeDocumentImageLayer, documentKerningThresholdHalfPointsFromElement, documentImageCropFromElement, documentBookmarkReferenceInstruction, normalizeDocumentPageBorders, documentImageLayerFromElement, serializeDocumentOpenTypeFeatures, documentCaptionLabel, documentCaptionKind, isContourImageLayout, normalizeDocumentLegacyTextEffects, DOCUMENT_LEGACY_TEXT_IMPRINT_ATTRIBUTE, normalizeDocumentImageIdentity, normalizeDocumentStrikeStyle, normalizeTableColor, normalizeDocumentOpenTypeFeatures, documentCitationTags, docxDocumentFieldKind, documentTableBordersFromElement, documentSections, wrapsBesideImage, normalizeDocumentCharacterPositionHalfPoints, normalizeDocumentKerningThresholdHalfPoints, defaultDocumentImageWrapContour, parseDocumentOpenTypeFeatures, normalizeDocumentPaperSource, DOCUMENT_LEGACY_TEXT_OUTLINE_ATTRIBUTE, documentEquationFromElement, documentImageTransformFromElement, parseDocumentCharacterFormatting, documentLegacyTextEffectsFromElement, documentUnderlineFormattingFromElement, DOCUMENT_LEGACY_TEXT_SHADOW_ATTRIBUTE, normalizeDocumentEquation, parseDocumentParagraphFormatting, documentOpenTypeFeaturesFromElement, normalizeDocumentBookmarkNativeId, documentTableRowIdentityFromElement, DOCUMENT_PAGE_MARGIN_KEYS, uniqueDocumentImageIdentity, documentHiddenTextFromElement, collectDocumentNotes, documentImageLayoutFromElement, documentPageHorizontalMarginTwips, DOCUMENT_OPEN_TYPE_ATTRIBUTE, MAX_DOCUMENT_NUMBERING_START, documentPageGeometryForLayout, DOCUMENT_LEGACY_TEXT_EFFECT_NAMES, documentCharacterScalePercentFromElement, normalizeDocumentPageMargins, normalizeDocumentLegacyTextEffect, documentNoteKind } from "./4174.js";
2
+ import { normalizeDocumentBookmarkName, normalizeDocumentEmphasisMark, DOCUMENT_STRIKE_STYLE_ATTRIBUTE, applyDocumentImageIdentityToElement, documentEmphasisMarkFromElement, DOCUMENT_PAGE_BORDER_EDGES, DOCUMENT_UNDERLINE_STYLE_ATTRIBUTE, createDocumentImageIdentityRegistry, normalizeDocumentColumns, normalizeDocumentTableVerticalAlign, normalizeDocumentTextCase, documentCharacterSpacingTwipsFromElement, documentCharacterPositionHalfPointsFromElement, documentTableColumnPercentagesFromElement, documentTableCellMarginOverridesFromElement, applyDocumentTableRowIdentityToElement, normalizeDocumentBookmarksHtml, documentImageIdentityFromElement, documentTableGeometryFromElement, normalizeDocumentTableRowHeightRule, documentNoteKey, DOCUMENT_LEGACY_TEXT_EMBOSS_ATTRIBUTE, normalizeDocumentHiddenText, documentLegacyTextEffectsConflict, normalizeDocumentTableBorderWidth, normalizeDocumentCharacterSpacingTwips, documentStrikeFormattingFromElement, normalizeDocumentTableBorderStyle, parseDocumentNumberingChange, normalizeDocumentBookmarkReferencesHtml, documentCitationInstruction, documentImageWrapContourFromElement, documentImagePositionFromElement, normalizeDocumentCharacterScalePercent, normalizeDocumentUnderlineStyle, normalizeDocumentPageChrome, documentPageMarginsForLayout, normalizeDocumentImageLayer, documentKerningThresholdHalfPointsFromElement, documentImageCropFromElement, documentBookmarkReferenceInstruction, normalizeDocumentPageBorders, documentImageLayerFromElement, serializeDocumentOpenTypeFeatures, documentCaptionLabel, documentCaptionKind, isContourImageLayout, normalizeDocumentLegacyTextEffects, DOCUMENT_LEGACY_TEXT_IMPRINT_ATTRIBUTE, normalizeDocumentImageIdentity, supportedDocxDocumentFieldInstruction, normalizeDocumentStrikeStyle, normalizeDocumentOpenTypeFeatures, documentCitationTags, docxDocumentFieldKind, normalizeTableColor, documentTableBordersFromElement, documentSections, wrapsBesideImage, normalizeDocumentCharacterPositionHalfPoints, normalizeDocumentKerningThresholdHalfPoints, documentTextBoxPropertiesFromElement, defaultDocumentImageWrapContour, parseDocumentOpenTypeFeatures, normalizeDocumentPaperSource, DOCUMENT_LEGACY_TEXT_OUTLINE_ATTRIBUTE, documentEquationFromElement, documentImageTransformFromElement, parseDocumentCharacterFormatting, documentLegacyTextEffectsFromElement, documentUnderlineFormattingFromElement, DOCUMENT_LEGACY_TEXT_SHADOW_ATTRIBUTE, normalizeDocumentEquation, parseDocumentParagraphFormatting, documentOpenTypeFeaturesFromElement, normalizeDocumentBookmarkNativeId, documentTableRowIdentityFromElement, DOCUMENT_PAGE_MARGIN_KEYS, uniqueDocumentImageIdentity, documentHiddenTextFromElement, collectDocumentNotes, documentImageLayoutFromElement, documentPageHorizontalMarginTwips, DOCUMENT_OPEN_TYPE_ATTRIBUTE, MAX_DOCUMENT_NUMBERING_START, documentPageGeometryForLayout, DOCUMENT_LEGACY_TEXT_EFFECT_NAMES, documentCharacterScalePercentFromElement, normalizeDocumentPageMargins, normalizeDocumentLegacyTextEffect, documentNoteKind } from "./4174.js";
3
3
  import { normalizeDocumentRunBorder, parseDocumentScriptFonts, parseDocxThemeReference, parseXml, parseDocumentRunShading, applyDocumentParagraphIdentityToElement, DOCUMENT_RUN_SHADING_ATTRIBUTE, documentScriptFontSlotFromElement, DOCUMENT_HIGHLIGHT_ATTRIBUTE, normalizeDocumentIndexesHtml, serializeDocumentScriptFonts, attribute as work_ooxml_package_attribute, createDocumentParagraphIdentityRegistry, uniqueDocumentParagraphIdentity, DOCUMENT_NO_PROOF_ATTRIBUTE, documentHighlightForCssColor, directChildren, documentTableOfContentsValueFromElement, DOCUMENT_PROOFING_LANGUAGES_ATTRIBUTE, DocxThemePatchCollector, normalizeDocumentScriptFonts, normalizeDocumentParagraphIdentity, normalizeDocumentHighlight, normalizeDocumentParagraphBorders, serializeUtf8Xml, DOCUMENT_PARAGRAPH_BORDER_EDGES, parseDocumentRunBorder, normalizeDocumentNoProof, decodeXmlBytes, documentParagraphIdentityFromElement, normalizeDocumentParagraphId, documentScriptFontFamily, descendants, resolvePartTarget, documentProofingLanguagesFromElement, documentHighlightFromElement, parseDocumentRunShadingElement, parseDocumentProofingLanguages, patchDocxThemeReferences, parseDocumentParagraphBordersElement, DOCUMENT_RUN_BORDER_ATTRIBUTE, parseDocumentRunBorderElement, xmlNamespacePrefix, documentScriptFontSlotFromHint, documentNoProofFromElement, documentScriptFontsFromElement, normalizeDocumentRunShading, normalizeDocumentScriptFontSlot, directChild, documentIndexEntryFromElement, documentIndexValueFromElement, parseDocumentParagraphShadingElement, documentFontNameFromCssFamily } from "./6968.js";
4
4
  import { assignDocxNoteIds, patchDocxPageColor, normalizeDocxCommentId, assignDocxCommentThreads } from "./0~4980.js";
5
5
  import { DocxImageTransformPatchCollector, paragraphTabStops, patchDocxImageTransforms, mergeDocxIgnorableExtensionsAtPairs, DOCX_WORD_2010_NAMESPACE, docxKerningThresholdValue, patchDocxBibliography, documentIndexInstruction, docxCharacterScaleValue, XMLNS_NAMESPACE as work_docx_settings_xml_XMLNS_NAMESPACE, paragraphAlignment, xmlNamespaceUri, paragraphSpacingOptions, docxCharacterPositionValue, documentIndexEntryInstruction, docxEmphasisMarkRunOptions, hasNonWhitespaceXmlText, patchDocxExplicitZeroCharacterSpacing, cloneXmlElement, cssColorToHex, xmlDeclaredPrefix, assertXmlRoot, DOCX_WORDPROCESSING_NAMESPACES, paragraphIndent, domDirection, xmlAttributeNamespace, paragraphBidirectional, XML_NAMESPACE as work_docx_settings_xml_XML_NAMESPACE, mergeDocxIgnorableExtensions, DocxParagraphDefaultCollapsedPatchCollector, dataBoolean, patchDocxParagraphDefaultCollapsed, patchDocxExplicitZeroKerningThresholds, parseDocxColorSchemeMappingElement, paragraphPaginationOptions, DOCX_COLOR_SCHEME_MAPPING_ATTRIBUTES, documentProofingLanguageDocxOptions, xmlAttributeLocalName, cssFontSize, paragraphDirectionOptions, cssFontFamily, docxCharacterSpacingValue } from "./0~4042.js";
@@ -2093,7 +2093,7 @@ function imageDimensions(blob) {
2093
2093
  function docxDocumentFieldRun(element, docx) {
2094
2094
  const instruction = element.dataset.fieldInstruction?.trim() ?? '';
2095
2095
  const display = element.dataset.fieldDisplay?.trim() || element.textContent?.trim() || '';
2096
- if (!docxDocumentFieldKind(instruction)) return new docx.TextRun(display);
2096
+ if (!docxDocumentFieldKind(instruction) || !supportedDocxDocumentFieldInstruction(instruction)) return new docx.TextRun(display);
2097
2097
  return new docx.SimpleField(instruction, display);
2098
2098
  }
2099
2099
  const work_docx_run_shading_export_WORD_NAMESPACE = 'http://schemas.openxmlformats.org/wordprocessingml/2006/main';
@@ -4906,6 +4906,84 @@ function removeWordAttribute(element, localName) {
4906
4906
  function work_docx_table_of_contents_export_wordQualifiedName(root, localName) {
4907
4907
  return `${xmlNamespacePrefix(root, work_docx_table_of_contents_export_WORD_NAMESPACE) ?? 'w'}:${localName}`;
4908
4908
  }
4909
+ const DOC_PROPERTIES_ID_MAX = 0xffffffff;
4910
+ const TEXT_BOX_ID_MARKER_PATTERN = /__A3S_TEXT_BOX_ID_\d+__/g;
4911
+ class DocxTextBoxIdentityPatchCollector {
4912
+ patches = [];
4913
+ nextMarker = 1;
4914
+ register(properties) {
4915
+ const marker = `__A3S_TEXT_BOX_ID_${this.nextMarker}__`;
4916
+ this.nextMarker += 1;
4917
+ this.patches.push({
4918
+ marker,
4919
+ preferredId: properties.docPropertiesId
4920
+ });
4921
+ return {
4922
+ marker,
4923
+ docPropertiesId: properties.docPropertiesId
4924
+ };
4925
+ }
4926
+ }
4927
+ async function patchDocxTextBoxIdentities(buffer, patches) {
4928
+ if (!patches.length) return buffer;
4929
+ const archive = await jszip.loadAsync(buffer);
4930
+ const byMarker = new Map(patches.map((patch)=>[
4931
+ patch.marker,
4932
+ patch
4933
+ ]));
4934
+ const entries = Object.values(archive.files).filter((entry)=>!entry.dir && /^word\/(?:document|header\d+|footer\d+|footnotes|endnotes|comments)\.xml$/.test(entry.name));
4935
+ const documents = await Promise.all(entries.map(async (entry)=>({
4936
+ entry,
4937
+ document: parseXml(await entry.async('text'), entry.name)
4938
+ })));
4939
+ const properties = documents.flatMap(({ document })=>descendants(document, 'docPr'));
4940
+ const marked = properties.map((property)=>({
4941
+ property,
4942
+ patch: textBoxIdentityPatch(property, byMarker)
4943
+ })).filter((value)=>Boolean(value.patch));
4944
+ if (!marked.length) return buffer;
4945
+ const used = new Set();
4946
+ for (const property of properties){
4947
+ if (marked.some((value)=>value.property === property)) continue;
4948
+ const id = parseDocPropertiesId(property.getAttribute('id'));
4949
+ if (null !== id) used.add(id);
4950
+ }
4951
+ let nextId = 1;
4952
+ const changedDocuments = new Set();
4953
+ for (const { property, patch } of marked){
4954
+ removeTextBoxIdentityMarker(property, patch.marker);
4955
+ const preferred = null === patch.preferredId || used.has(patch.preferredId) ? nextAvailableDocPropertiesId(used, nextId) : patch.preferredId;
4956
+ used.add(preferred);
4957
+ nextId = preferred + 1;
4958
+ property.setAttribute('id', String(preferred));
4959
+ changedDocuments.add(property.ownerDocument);
4960
+ }
4961
+ for (const { entry, document } of documents)if (changedDocuments.has(document)) archive.file(entry.name, new XMLSerializer().serializeToString(document));
4962
+ return archive.generateAsync({
4963
+ type: 'arraybuffer'
4964
+ });
4965
+ }
4966
+ function textBoxIdentityPatch(property, byMarker) {
4967
+ for (const attribute of Array.from(property.attributes)){
4968
+ const marker = attribute.value.match(TEXT_BOX_ID_MARKER_PATTERN)?.find((value)=>byMarker.has(value));
4969
+ if (marker) return byMarker.get(marker) ?? null;
4970
+ }
4971
+ return null;
4972
+ }
4973
+ function removeTextBoxIdentityMarker(property, marker) {
4974
+ for (const attribute of Array.from(property.attributes))if (attribute.value.includes(marker)) attribute.value = attribute.value.replace(marker, '').replace(/\s{2,}/g, ' ').trim();
4975
+ }
4976
+ function parseDocPropertiesId(value) {
4977
+ if (null === value || !/^\d+$/.test(value)) return null;
4978
+ const id = Number(value);
4979
+ return Number.isSafeInteger(id) && id <= DOC_PROPERTIES_ID_MAX ? id : null;
4980
+ }
4981
+ function nextAvailableDocPropertiesId(used, start) {
4982
+ let candidate = Math.max(1, start);
4983
+ while(candidate <= DOC_PROPERTIES_ID_MAX && used.has(candidate))candidate += 1;
4984
+ if (candidate > DOC_PROPERTIES_ID_MAX) throw new Error('DOCX drawing-property IDs are exhausted.');
4985
+ return candidate;
4986
+ }
4909
4987
  const work_docx_table_sizing_export_TWIPS_PER_PIXEL = 15;
4910
4988
  function documentTableSizingDocxOptions(table, docx) {
4911
4989
  const geometry = documentTableGeometryFromElement(table);
@@ -8688,6 +8766,7 @@ async function createDocxBlob(content, sourcePackage) {
8688
8766
  imageLayerPatches: new DocxImageLayerPatchCollector(),
8689
8767
  imageWrapPatches: new DocxImageWrapPatchCollector(),
8690
8768
  imageTransformPatches: new DocxImageTransformPatchCollector(),
8769
+ textBoxIdentityPatches: new DocxTextBoxIdentityPatchCollector(),
8691
8770
  paragraphBorderPatches: new DocxParagraphBorderPatchCollector(JSON.stringify(normalizedContent)),
8692
8771
  paragraphDefaultCollapsedPatches: new DocxParagraphDefaultCollapsedPatchCollector(),
8693
8772
  paragraphIdentityPatches: new DocxParagraphIdentityPatchCollector(JSON.stringify(normalizedContent)),
@@ -8777,7 +8856,8 @@ async function createDocxBlob(content, sourcePackage) {
8777
8856
  const imageLayerPatched = await patchDocxImageLayers(imageWrapPatched, noteContext.imageLayerPatches.patches);
8778
8857
  const imageTransformPatched = await patchDocxImageTransforms(imageLayerPatched, noteContext.imageTransformPatches.patches);
8779
8858
  const imageIdentityPatched = await patchDocxImageIdentities(imageTransformPatched, noteContext.imageIdentityPatches.patches);
8780
- const bookmarkPatched = await patchDocxBookmarks(imageIdentityPatched, noteContext.bookmarkPatches.patches);
8859
+ const textBoxIdentityPatched = await patchDocxTextBoxIdentities(imageIdentityPatched, noteContext.textBoxIdentityPatches.patches);
8860
+ const bookmarkPatched = await patchDocxBookmarks(textBoxIdentityPatched, noteContext.bookmarkPatches.patches);
8781
8861
  const paragraphDefaultCollapsedPatched = await patchDocxParagraphDefaultCollapsed(bookmarkPatched, noteContext.paragraphDefaultCollapsedPatches.patches);
8782
8862
  const paragraphIdentityPatched = await patchDocxParagraphIdentities(paragraphDefaultCollapsedPatched, noteContext.paragraphIdentityPatches.patches);
8783
8863
  const tableOfContentsPatched = await patchDocxTableOfContents(paragraphIdentityPatched, noteContext.tableOfContentsPatches.patches);
@@ -8977,6 +9057,13 @@ async function blockToFileChildren(element, docx, noteContext) {
8977
9057
  if (element.hasAttribute('data-document-caption')) return [
8978
9058
  docxCaptionParagraph(element, await paragraphRuns(element, docx, noteContext), docx, paragraphBidirectional(element))
8979
9059
  ];
9060
+ if (element.hasAttribute('data-document-text-box')) return [
9061
+ new docx.Paragraph({
9062
+ children: [
9063
+ await textBoxToDocx(element, docx, noteContext)
9064
+ ]
9065
+ })
9066
+ ];
8980
9067
  if ('table' === tag) return [
8981
9068
  await tableToDocx(element, docx, noteContext)
8982
9069
  ];
@@ -9007,6 +9094,114 @@ async function blockToFileChildren(element, docx, noteContext) {
9007
9094
  })
9008
9095
  ];
9009
9096
  }
9097
+ async function textBoxToDocx(element, docx, noteContext) {
9098
+ const properties = documentTextBoxPropertiesFromElement(element);
9099
+ const identity = noteContext.textBoxIdentityPatches.register(properties);
9100
+ const runs = await paragraphRuns(element, docx, noteContext);
9101
+ const paragraph = new docx.Paragraph({
9102
+ children: runs.length ? runs : [
9103
+ new docx.TextRun('')
9104
+ ],
9105
+ alignment: paragraphAlignment(element, docx),
9106
+ ...paragraphDirectionOptions(element)
9107
+ });
9108
+ const shapeOptions = {
9109
+ type: 'wps',
9110
+ transformation: {
9111
+ width: millimetersToPixels(properties.width),
9112
+ height: millimetersToPixels(properties.height)
9113
+ },
9114
+ children: [
9115
+ paragraph
9116
+ ],
9117
+ nonVisualProperties: {
9118
+ txBox: '1'
9119
+ },
9120
+ bodyProperties: {
9121
+ verticalAnchor: textBoxVerticalAnchor(properties, docx),
9122
+ margins: {
9123
+ top: work_docx_export_millimetersToEmus(properties.padding),
9124
+ right: work_docx_export_millimetersToEmus(properties.padding),
9125
+ bottom: work_docx_export_millimetersToEmus(properties.padding),
9126
+ left: work_docx_export_millimetersToEmus(properties.padding)
9127
+ },
9128
+ noAutoFit: true
9129
+ },
9130
+ altText: {
9131
+ name: `A3S Text Box ${properties.id || 'text-box'} ${identity.marker}`,
9132
+ description: 'A3S editable text box',
9133
+ title: 'Text box',
9134
+ ...null === identity.docPropertiesId ? {} : {
9135
+ id: String(identity.docPropertiesId)
9136
+ }
9137
+ },
9138
+ ...'transparent' === properties.fill ? {} : {
9139
+ solidFill: {
9140
+ type: 'rgb',
9141
+ value: properties.fill.slice(1)
9142
+ }
9143
+ },
9144
+ outline: 'none' === properties.borderColor || properties.borderWidth <= 0 ? {
9145
+ type: 'noFill'
9146
+ } : {
9147
+ type: 'solidFill',
9148
+ solidFillType: 'rgb',
9149
+ value: properties.borderColor.slice(1),
9150
+ width: work_docx_export_millimetersToEmus(properties.borderWidth)
9151
+ },
9152
+ ...'floating' === properties.layout ? {
9153
+ floating: textBoxFloatingOptions(properties, docx)
9154
+ } : {}
9155
+ };
9156
+ return new docx.WpsShapeRun(shapeOptions);
9157
+ }
9158
+ function textBoxVerticalAnchor(properties, docx) {
9159
+ if ('center' === properties.verticalAlign) return docx.VerticalAnchor.CENTER;
9160
+ if ('bottom' === properties.verticalAlign) return docx.VerticalAnchor.BOTTOM;
9161
+ return docx.VerticalAnchor.TOP;
9162
+ }
9163
+ function textBoxFloatingOptions(properties, docx) {
9164
+ return {
9165
+ horizontalPosition: {
9166
+ relative: textBoxHorizontalReference(properties, docx),
9167
+ offset: work_docx_export_millimetersToEmus(properties.horizontalOffset ?? 0)
9168
+ },
9169
+ verticalPosition: {
9170
+ relative: textBoxVerticalReference(properties, docx),
9171
+ offset: work_docx_export_millimetersToEmus(properties.verticalOffset ?? 0)
9172
+ },
9173
+ allowOverlap: true,
9174
+ behindDocument: false,
9175
+ layoutInCell: true,
9176
+ lockAnchor: false,
9177
+ zIndex: 0,
9178
+ margins: {
9179
+ top: 0,
9180
+ right: 0,
9181
+ bottom: 0,
9182
+ left: 0
9183
+ },
9184
+ wrap: {
9185
+ type: docx.TextWrappingType.SQUARE
9186
+ }
9187
+ };
9188
+ }
9189
+ function textBoxHorizontalReference(properties, docx) {
9190
+ if ('margin' === properties.horizontalReference) return docx.HorizontalPositionRelativeFrom.MARGIN;
9191
+ if ('page' === properties.horizontalReference) return docx.HorizontalPositionRelativeFrom.PAGE;
9192
+ return docx.HorizontalPositionRelativeFrom.COLUMN;
9193
+ }
9194
+ function textBoxVerticalReference(properties, docx) {
9195
+ if ('margin' === properties.verticalReference) return docx.VerticalPositionRelativeFrom.MARGIN;
9196
+ if ('page' === properties.verticalReference) return docx.VerticalPositionRelativeFrom.PAGE;
9197
+ return docx.VerticalPositionRelativeFrom.PARAGRAPH;
9198
+ }
9199
+ function millimetersToPixels(value) {
9200
+ return 96 * value / 25.4;
9201
+ }
9202
+ function work_docx_export_millimetersToEmus(value) {
9203
+ return Math.round(36000 * value);
9204
+ }
9010
9205
  function paragraphHeadingLevel(tag, docx) {
9011
9206
  if ('h1' === tag) return docx.HeadingLevel.HEADING_1;
9012
9207
  if ('h2' === tag) return docx.HeadingLevel.HEADING_2;
@@ -1,7 +1,7 @@
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, applyImportedDocxNumberingChangeMarkers, applyImportedDocxParagraphShadingMarkers, markDocxParagraphSpacing, docxCaptionBookmark, docxFieldResultText, createDocxParagraphStyleResolver, docxTableCellStyleLayers, createImportedDocxRunFormattingMarkerState, parseDocxPaperSource, resolveDocxLegacyTextEffects, markDocxTablesOfContents, hasImportedDocxParagraphSpacingMarkers, applyImportedDocxIndexMarkers, applyImportedDocxTableOfContentsMarkers, markDocxIndexes, parseDocxPageMargins, docxTablePropertySources, parseDirectDocxParagraphShading, markDocxParagraphIndents, markDocxPackageEquations, 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, applyImportedDocxParagraphDirectionMarkers, markDocxNumberingChanges, applyImportedDocxParagraphAlignmentMarkers, importedDocxUnderline, markDocxParagraphBorders, markDocxParagraphPagination, applyImportedDocxParagraphTabStopMarkers, applyImportedDocxParagraphPaginationMarkers, docxFieldOccurrenceIsInlineEditable, applyImportedDocxParagraphBorderMarkers, docxRunPropertySources, markDocxParagraphFormattingChanges, markDocxParagraphShading, parseDocxPageBorders } from "./0~2330.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, 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
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";
6
6
  import { importDocxPageColor, importedDocumentNoteId } from "./0~4980.js";
7
7
  const WORD_NAMESPACE = 'http://schemas.openxmlformats.org/wordprocessingml/2006/main';
@@ -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;
@@ -2910,6 +2946,9 @@ async function prepareDocxImport(buffer, sourcePackage) {
2910
2946
  imageLayoutMarkers: {
2911
2947
  images: []
2912
2948
  },
2949
+ textBoxMarkers: {
2950
+ textBoxes: []
2951
+ },
2913
2952
  paragraphIdentityMarkers: {
2914
2953
  paragraphs: []
2915
2954
  },
@@ -2964,6 +3003,7 @@ async function prepareDocxImport(buffer, sourcePackage) {
2964
3003
  const pageColor = importDocxPageColor(document);
2965
3004
  const tableOfContentsMarkers = markDocxTablesOfContents(document);
2966
3005
  const indexMarkers = markDocxIndexes(document);
3006
+ const textBoxMarkers = markDocxTextBoxes(document);
2967
3007
  const paragraphIdentityMarkers = markDocxParagraphIdentities(document);
2968
3008
  const numbering = archive.has('word/numbering.xml') ? await archive.xml('word/numbering.xml') : null;
2969
3009
  const commentMarkers = await markDocxComments(document, archive);
@@ -2971,7 +3011,7 @@ async function prepareDocxImport(buffer, sourcePackage) {
2971
3011
  const captionMarkers = markDocxCaptionFields(document);
2972
3012
  const bookmarkMarkers = markDocxBookmarks(document);
2973
3013
  const citationMarkers = markDocxCitationFields(document);
2974
- const fieldMarkers = markDocxBodyFields(document);
3014
+ const fieldMarkers = markDocxBodyFields(document, bookmarkMarkers.bookmarks);
2975
3015
  const listMarkers = markDocxLists(document, numbering);
2976
3016
  const numberingChangeMarkers = markDocxNumberingChanges(document);
2977
3017
  const imageLayoutMarkerState = createImportedDocxImageLayoutMarkerState();
@@ -3009,7 +3049,7 @@ async function prepareDocxImport(buffer, sourcePackage) {
3009
3049
  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));
3010
3050
  const sectionElements = effectiveSectionProperties(document);
3011
3051
  if (!sectionElements.length) return {
3012
- 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) || 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,
3052
+ 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,
3013
3053
  sections: [
3014
3054
  {
3015
3055
  id: 'document-section-1',
@@ -3029,6 +3069,7 @@ async function prepareDocxImport(buffer, sourcePackage) {
3029
3069
  listMarkers,
3030
3070
  numberingChangeMarkers,
3031
3071
  imageLayoutMarkers,
3072
+ textBoxMarkers,
3032
3073
  paragraphIdentityMarkers,
3033
3074
  paragraphFormattingChangeMarkers,
3034
3075
  paragraphAlignmentMarkers,
@@ -3060,7 +3101,7 @@ async function prepareDocxImport(buffer, sourcePackage) {
3060
3101
  }
3061
3102
  if (sections.length > 1) addSectionMarkers(document, sectionElements);
3062
3103
  return {
3063
- 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) || 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,
3104
+ 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,
3064
3105
  sections,
3065
3106
  pageColor,
3066
3107
  captionMarkers,
@@ -3075,6 +3116,7 @@ async function prepareDocxImport(buffer, sourcePackage) {
3075
3116
  listMarkers,
3076
3117
  numberingChangeMarkers,
3077
3118
  imageLayoutMarkers,
3119
+ textBoxMarkers,
3078
3120
  paragraphIdentityMarkers,
3079
3121
  paragraphFormattingChangeMarkers,
3080
3122
  paragraphAlignmentMarkers,
@@ -3155,6 +3197,8 @@ function applyDocxSectionsToHtml(html, sections, captionMarkers = {
3155
3197
  rows: []
3156
3198
  }, tableSizingMarkers = {
3157
3199
  tables: []
3200
+ }, textBoxMarkers = {
3201
+ textBoxes: []
3158
3202
  }) {
3159
3203
  const document = new DOMParser().parseFromString(html, 'text/html');
3160
3204
  applyImportedDocxRunFormattingMarkers(document, runFormattingMarkers);
@@ -3181,6 +3225,7 @@ function applyDocxSectionsToHtml(html, sections, captionMarkers = {
3181
3225
  applyImportedDocxChangeMarkers(document, changeMarkers);
3182
3226
  applyImportedDocxCommentMarkers(document, commentMarkers);
3183
3227
  applyImportedDocxParagraphIdentityMarkers(document, paragraphIdentityMarkers);
3228
+ applyImportedDocxTextBoxMarkers(document, textBoxMarkers);
3184
3229
  applyImportedDocxTableOfContentsMarkers(document, tableOfContentsMarkers);
3185
3230
  applyImportedDocxIndexMarkers(document, indexMarkers);
3186
3231
  const notes = extractMammothDocumentNotes(document);
@@ -1,7 +1,7 @@
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 { markDocxParagraphShading, inspectDocxPageSize, isSupportedDocxNumberingChange, docxCaptionBookmark, hasInvalidDocxFieldStructure, inspectDocxLegacyTextEffects, inspectDocxPageMargins, inspectDocxPaperSource, createDocxParagraphStyleResolver, supportedDocxTableOfContentsField, docxFieldOccurrences, supportedDocxIndexEntryField, createDocxTableStyleResolver, inspectDocxEquation, inspectDocxPageMarginSettings, inspectDocxRunBorder, inspectDocxRunFonts, inspectDocxRunShading, markDocxParagraphBorders, isSupportedDocxParagraphFormattingChange, docxFieldOccurrenceIsInlineEditable, supportedDocxIndexField, docxCaptionSequenceKind, inspectDocxHiddenText, inspectDocxPageBorders, isSupportedDocxRunFormattingChange, docxFieldInstructions, isSupportedDocxEquationPlacement } from "./0~2330.js";
3
+ import { normalizeDocumentBookmarkName, docxBookmarkReferenceTarget, DOCUMENT_LEGACY_TEXT_EFFECT_NAMES, normalizeDocumentBookmarkNativeId, supportedDocxDocumentFieldInstruction, supportedDocxBookmarkReferenceInstruction, documentCitationTagsFromInstruction, docxDocumentFieldKind, docxDocumentFieldTarget } 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";
5
5
  import { normalizeDocumentHref } from "./0~work-document-links.js";
6
6
  import { xmlAttributeLocalName, resolveDocxOpenTypeFeatures, inspectDocxProofingLanguages, readDocxBibliography, inspectDocxEmphasisMark, createDocxThemeResolver, DOCX_WORD_2010_NAMESPACE, inspectDocxNoProof, parseDocxParagraphDefaultCollapsed, readDocxImageTransform, DOCX_WORDPROCESSING_NAMESPACES, xmlAttributeNamespace, inspectDocxKerningThresholdHalfPoints } from "./0~4042.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";
@@ -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)=>{
@@ -2190,8 +2205,13 @@ async function analyzeDocxCompatibility(file, messages, sourcePackage) {
2190
2205
  issues.push(...await diagnoseDocxCitations(archive, document));
2191
2206
  const captionDiagnostics = diagnoseDocxCaptions(document);
2192
2207
  issues.push(...captionDiagnostics.issues);
2208
+ const textBoxInspection = inspectDocxTextBoxes(document);
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'));
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.`));
2193
2211
  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.'));
2194
- if (descendants(document, 'drawing').length || descendants(document, 'pict').length) {
2212
+ const drawingCount = descendants(document, 'drawing').length;
2213
+ const textBoxDrawingCount = textBoxInspection.supported + textBoxInspection.unsupported;
2214
+ if (drawingCount > textBoxDrawingCount || descendants(document, 'pict').length) {
2195
2215
  const unsupportedImageTransforms = docxUnsupportedImageTransformCount(document);
2196
2216
  issues.push(work_office_diagnostics_issue('docx.images', 'Images', 'Inline images and supported square, tight, through, top-and-bottom, or no-wrap free-floating images remain embedded with editable size, alternative text, alignment, wrap side and distance where applicable, signed horizontal or vertical offsets relative to the column, paragraph, margin, or page, four-edge percentage cropping, 90-degree rotation, horizontal or vertical reflection, and drawing-layer options. Aligned and precise DOCX anchors retain their distinct position semantics; inline and floating crop geometry round-trips as DrawingML source rectangles; tight or through anchors retain their ordered wrap polygons; no-wrap anchors remain outside the body text flow and use behind-text placement to choose their side of the text; and supported floating images preserve relative Z-order, overlap and cell-layout policy, and anchor locking. Inline and floating pictures retain unique drawing-property and anchor IDs together with their edit IDs. Copies receive independent identities while move, delete, undo, and relationship regeneration retain the original object identity. Arbitrary-angle or malformed picture transforms and unsupported drawing types may be normalized.'));
2197
2217
  if (unsupportedImageTransforms) issues.push(work_office_diagnostics_issue('docx.images.transform', 'Image transforms', `${unsupportedImageTransforms} picture transform(s) use an arbitrary angle or malformed rotation/reflection value. Work imports the editable 90-degree/reflection subset and normalizes the unsupported transform instead of exposing an inexact control.`));