oasis-editor 0.0.143 → 0.0.144

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,7 +1,7 @@
1
1
  var __defProp = Object.defineProperty;
2
2
  var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3
3
  var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
4
- import { E as EMPTY_PROJECTION_CONTEXT, d as domTextMeasurer, g as getProjectedParagraphBlockHeight, e as estimateTableBlockHeight, p as projectParagraphLayout, a as getPageBodyBottom, b as getPageBodyTop, c as getPageContentWidth, F as FOOTNOTE_MARKER_GUTTER_PX, f as getParagraphText, h as getBlockParagraphs, i as getRunFootnoteReference, l as listReferencedEndnotes, j as getFootnoteDisplayMarker, k as createProjectionContext, m as getDocumentSections, n as getRunField, o as projectBlocksLayout, v as visitRun, q as assertNever, r as createSignal, s as createEditorStateFromDocument, t as createInitialEditorState, S as STANDARD_FONT_SIZES_PT, u as fontSizePxToPt, w as probeLocalFontFamilies, x as createEditorParagraphFromRuns, y as isInlineObjectRun, z as createEditorStyledRun, A as getParagraphLength, B as getActiveZone, C as getActiveSectionIndex, D as getParagraphs, G as normalizeSelection, H as positionToParagraphOffset, I as paragraphOffsetToPosition, J as findParagraphIndex, K as createCollapsedSelection, L as isSelectionCollapsed, M as parseFontSizePtToPx, N as formatFontSizePt, O as createEditorParagraph, P as resolveDefaultParagraphStyleId, Q as findParagraphTableLocation, R as buildTableCellLayout, T as PT_PER_PX, U as createEditorTableCell, V as createEditorTableRow, W as createEditorTable, X as clampPosition, Y as PX_PER_POINT, Z as underlineStyleToCssDecorationStyle, _ as resolveImageSrc, $ as listKindForTag, a0 as isParagraphTag, a1 as collectInlineRuns, a2 as parseParagraphStyle, a3 as getRunImage, a4 as InlineShell, a5 as BalloonShell, a6 as DocumentShell, a7 as createMemo, a8 as getCaretRectFromSnapshot, a9 as getParagraphRectFromSnapshot, aa as createComponent, ab as CaretOverlay, ac as Show, ad as createRenderEffect, ae as style, af as setStyleProperty, ag as setAttribute, ah as memo, ai as template, aj as Button, ak as useI18n, al as createEffect, am as TextField, an as Dialog, ao as insert, ap as className, aq as Grid, ar as SelectField, as as StatusText, at as ColorField, au as UNDERLINE_STYLE_OPTIONS, av as Stack, aw as For, ax as ToggleChip, ay as FormField, az as Checkbox, aA as FieldGroup, aB as Tabs, aC as NumberField, aD as parseNumber, aE as createStore, aF as reconcile, aG as RadioGroup, aH as Radio$1, aI as TextAreaField, aJ as Text, aK as SurfaceButton, aL as delegateEvents, aM as onMount, aN as onCleanup, aO as CheckIcon, aP as use, aQ as PluginUiHost, aR as OasisEditorEditor, aS as OasisBrandMark, aT as setPreciseFontPreference, aU as setWelcomeSeen, aV as enablePreciseFontMode, aW as TWIPS_PER_POINT, aX as PX_PER_INCH, aY as TWIPS_PER_INCH, aZ as normalizeHex6, a_ as TABLE_CONDITIONAL_FLAG_ATTRIBUTES, a$ as TABLE_BORDER_EDGE_KEYS, b0 as resolveEffectiveParagraphStyle, b1 as resolveEffectiveTextStyleForParagraph, b2 as EMU_PER_PT, b3 as OOXML_ROTATION_UNITS, b4 as OOXML_PERCENT_DENOMINATOR, b5 as parseHexColorToRgb255, b6 as EMU_PER_PX, b7 as getRunEndnoteReference, b8 as iterateFootnoteReferenceRuns, b9 as iterateEndnoteReferenceRuns, ba as imageContentTypeDefaults, bb as getRunFieldChar, bc as getRunFieldInstruction, bd as createEditorRun, be as JSZip, bf as imageExtensionFromMime, bg as pxToPt$1, bh as resolveFloatingObjectRect, bi as getTextBoxFloatingGeometry, bj as getPresetPathSegments, bk as buildListLabels, bl as lineDashPatternPt, bm as DEFAULT_FONT_SIZE_PX, bn as resolveGradientAxis, bo as isDoubleUnderlineStyle, bp as isWavyUnderlineStyle, bq as underlineStyleLineWidthPx, br as WAVY_UNDERLINE_WAVELENGTH_PX, bs as WAVY_UNDERLINE_AMPLITUDE_PX, bt as DOUBLE_UNDERLINE_OFFSET_PX, bu as underlineStyleDashArray, bv as EMPHASIS_GLYPH, bw as rgb255ToHex, bx as getImageFloatingGeometry, by as textStyleToFontSizePt, bz as resolveTextAlignmentBaselineOffset, bA as TEXT_BASELINE_RATIO, bB as resolveRenderedTextChar, bC as resolveOpenTypeFeatureTags, bD as isLowercaseSmallCapsChar, bE as resolveDecorationLineY, bF as DOUBLE_STRIKE_OFFSET_PX, bG as resolveListLabel, bH as getListLabelInset, bI as getAlignedListLabelInset, bJ as getParagraphBorderInsets, bK as buildSegmentTable, bL as buildCanvasTableLayout, bM as resolveCanvasTableWidth, bN as resolveFloatingTableRect, bO as paragraphBetweenBorderMatches, bP as normalizeFamily, bQ as ROBOTO_FONT_FILES, bR as loadFontAsset, bS as getRemotePdfFontFaces, bT as OFFICE_COMPAT_FONT_FAMILIES, bU as BinaryReader, bV as buildSfnt, bW as defaultFontDecoderRegistry, bX as SfntFontProgram, bY as zlibSync, bZ as collectPdfFontFamilies, b_ as outlineFrom, b$ as getPageHeaderZoneTop, c0 as getPageColumnRects, c1 as findFootnoteReference, c2 as resolveImporterForFile, c3 as roundTo, c4 as getDocumentSectionsCanonical, c5 as getDocumentParagraphsCanonical, c6 as getDocumentParagraphs, c7 as PX_PER_CM, c8 as getDocumentPageSettings, c9 as getTableCellContentWidthForParagraph, ca as layoutMetricsEpoch, cb as bumpLayoutMetricsEpoch, cc as createCanvasLayoutSnapshotProvider, cd as on, ce as debounce, cf as unwrap, cg as perfTimer, ch as prepareDocumentFonts, ci as getRunTextBox, cj as createEditorDocument, ck as resolveResizedDimensions, cl as axisSignForDirection, cm as clamp$1, cn as MIN_RESIZE_SIZE_PX, co as resolveTextBoxRenderHeight, cp as getToolbarStyleState, cq as VERTICAL_HIT_WEIGHT, cr as getCachedCanvasImage, cs as measureParagraphMinContentWidthPx, ct as getEditableBlocksForZone, cu as findParagraphLocation, cv as createSectionBoundaryParagraph, cw as normalizePageSettings, cx as DEFAULT_EDITOR_PAGE_SETTINGS, cy as markStart, cz as markEnd, cA as getParagraphEntries, cB as getParagraphById, cC as createEditorFootnote, cD as createFootnoteReferenceRun, cE as renumberFootnotes, cF as preciseFontModeVersion, cG as isPreciseFontModeEnabled, cH as getHeadingLevel, cI as togglePreciseFontMode, cJ as nextFontSizePt, cK as previousFontSizePt, cL as fontSizePtToPx, cM as resolveNamedTextStyle, cN as resolveNamedTableStyle, cO as resolveEffectiveTableStyle, cP as createDefaultToolbarPreset, cQ as MenuRegistry, cR as createToolbarRegistry, cS as Editor, cT as resolveCommandRef, cU as commandRefName, cV as createOasisEditorClient, cW as createEditorZoom, cX as startLongTaskObserver, cY as installGlobalReport, cZ as applyStoredPreciseFontPreference, c_ as getWelcomeSeen, c$ as isLocalFontAccessSupported, d0 as EDITOR_SCROLL_PADDING_PX, d1 as Toolbar, d2 as OasisEditorLoading, d3 as I18nProvider, d4 as createTranslator, d5 as registerDomStatsSurface, d6 as createEditorLogger } from "./index-PWJQT9bT.js";
4
+ import { E as EMPTY_PROJECTION_CONTEXT, d as domTextMeasurer, g as getProjectedParagraphBlockHeight, e as estimateTableBlockHeight, p as projectParagraphLayout, a as getPageBodyBottom, b as getPageBodyTop, c as getPageContentWidth, F as FOOTNOTE_MARKER_GUTTER_PX, f as getParagraphText, h as getBlockParagraphs, i as getRunFootnoteReference, l as listReferencedEndnotes, j as getFootnoteDisplayMarker, k as createProjectionContext, m as getDocumentSections, n as getRunField, o as projectBlocksLayout, v as visitRun, q as copyEditorRunOoxmlSource, r as assertNever, s as createSignal, t as createEditorStateFromDocument, u as createInitialEditorState, S as STANDARD_FONT_SIZES_PT, w as fontSizePxToPt, x as probeLocalFontFamilies, y as createEditorParagraphFromRuns, z as isInlineObjectRun, A as createEditorStyledRun, B as getParagraphLength, C as getActiveZone, D as getActiveSectionIndex, G as getParagraphs, H as normalizeSelection, I as positionToParagraphOffset, J as paragraphOffsetToPosition, K as findParagraphIndex, L as createCollapsedSelection, M as isSelectionCollapsed, N as parseFontSizePtToPx, O as formatFontSizePt, P as createEditorParagraph, Q as resolveDefaultParagraphStyleId, R as findParagraphTableLocation, T as buildTableCellLayout, U as PT_PER_PX, V as createEditorTableCell, W as createEditorTableRow, X as createEditorTable, Y as clampPosition, Z as PX_PER_POINT, _ as underlineStyleToCssDecorationStyle, $ as resolveImageSrc, a0 as listKindForTag, a1 as isParagraphTag, a2 as collectInlineRuns$1, a3 as parseParagraphStyle, a4 as getRunImage, a5 as InlineShell, a6 as BalloonShell, a7 as DocumentShell, a8 as createMemo, a9 as getCaretRectFromSnapshot, aa as getParagraphRectFromSnapshot, ab as createComponent, ac as CaretOverlay, ad as Show, ae as createRenderEffect, af as style, ag as setStyleProperty, ah as setAttribute, ai as memo, aj as template, ak as Button, al as useI18n, am as createEffect, an as TextField, ao as Dialog, ap as insert, aq as className, ar as Grid, as as SelectField, at as StatusText, au as ColorField, av as UNDERLINE_STYLE_OPTIONS, aw as Stack, ax as For, ay as ToggleChip, az as FormField, aA as Checkbox, aB as FieldGroup, aC as Tabs, aD as NumberField, aE as parseNumber, aF as createStore, aG as reconcile, aH as RadioGroup, aI as Radio$1, aJ as TextAreaField, aK as Text, aL as SurfaceButton, aM as delegateEvents, aN as onMount, aO as onCleanup, aP as CheckIcon, aQ as use, aR as PluginUiHost, aS as OasisEditorEditor, aT as OasisBrandMark, aU as setPreciseFontPreference, aV as setWelcomeSeen, aW as enablePreciseFontMode, aX as TWIPS_PER_POINT, aY as PX_PER_INCH, aZ as TWIPS_PER_INCH, a_ as normalizeHex6, a$ as TABLE_CONDITIONAL_FLAG_ATTRIBUTES, b0 as TABLE_BORDER_EDGE_KEYS, b1 as resolveEffectiveParagraphStyle, b2 as resolveEffectiveTextStyleForParagraph, b3 as EMU_PER_PT, b4 as OOXML_ROTATION_UNITS, b5 as OOXML_PERCENT_DENOMINATOR, b6 as parseHexColorToRgb255, b7 as EMU_PER_PX, b8 as getRunEndnoteReference, b9 as getEditorRunOoxmlSource, ba as ooxmlSourceNeedsCanonicalRunSerialization, bb as createEditorRunSemanticSignature, bc as createEditorRunStructureSignature, bd as XMLSerializer, be as DOMParser, bf as getEditorParagraphOoxmlSource, bg as createEditorParagraphPropertiesSignature, bh as getReusableEditorParagraphXml, bi as getEditorParagraphOoxmlAttributes, bj as iterateFootnoteReferenceRuns, bk as iterateEndnoteReferenceRuns, bl as imageContentTypeDefaults, bm as getEditorListOoxmlNumberingMetadata, bn as getEffectiveEditorListOoxmlFormat, bo as getRunFieldChar, bp as getRunFieldInstruction, bq as createEditorRun, br as JSZip, bs as imageExtensionFromMime, bt as normalizeOpcPartPath, bu as OPC_CONTENT_TYPES_PATH, bv as parseOpcRelationships, bw as serializeOpcRelationships, bx as OPC_ROOT_RELATIONSHIPS_PATH, by as parseOpcContentTypes, bz as serializeOpcContentTypes, bA as pxToPt$1, bB as resolveFloatingObjectRect, bC as getTextBoxFloatingGeometry, bD as getPresetPathSegments, bE as buildListLabels, bF as lineDashPatternPt, bG as DEFAULT_FONT_SIZE_PX, bH as resolveGradientAxis, bI as isDoubleUnderlineStyle, bJ as isWavyUnderlineStyle, bK as underlineStyleLineWidthPx, bL as WAVY_UNDERLINE_WAVELENGTH_PX, bM as WAVY_UNDERLINE_AMPLITUDE_PX, bN as DOUBLE_UNDERLINE_OFFSET_PX, bO as underlineStyleDashArray, bP as EMPHASIS_GLYPH, bQ as rgb255ToHex, bR as getImageFloatingGeometry, bS as textStyleToFontSizePt, bT as resolveTextAlignmentBaselineOffset, bU as TEXT_BASELINE_RATIO, bV as resolveRenderedTextChar, bW as resolveOpenTypeFeatureTags, bX as isLowercaseSmallCapsChar, bY as resolveDecorationLineY, bZ as DOUBLE_STRIKE_OFFSET_PX, b_ as resolveListLabel, b$ as getListLabelInset, c0 as getAlignedListLabelInset, c1 as getParagraphBorderInsets, c2 as buildSegmentTable, c3 as buildCanvasTableLayout, c4 as resolveCanvasTableWidth, c5 as resolveFloatingTableRect, c6 as paragraphBetweenBorderMatches, c7 as normalizeFamily, c8 as ROBOTO_FONT_FILES, c9 as loadFontAsset, ca as getRemotePdfFontFaces, cb as OFFICE_COMPAT_FONT_FAMILIES, cc as BinaryReader, cd as buildSfnt, ce as defaultFontDecoderRegistry, cf as SfntFontProgram, cg as zlibSync, ch as collectPdfFontFamilies, ci as outlineFrom, cj as getPageHeaderZoneTop, ck as getPageColumnRects, cl as findFootnoteReference, cm as resolveImporterForFile, cn as roundTo, co as getDocumentSectionsCanonical, cp as getDocumentParagraphsCanonical, cq as getDocumentParagraphs, cr as PX_PER_CM, cs as getDocumentPageSettings, ct as getTableCellContentWidthForParagraph, cu as layoutMetricsEpoch, cv as bumpLayoutMetricsEpoch, cw as createCanvasLayoutSnapshotProvider, cx as on, cy as debounce, cz as unwrap, cA as perfTimer, cB as prepareDocumentFonts, cC as getRunTextBox, cD as createEditorDocument, cE as resolveResizedDimensions, cF as axisSignForDirection, cG as clamp$1, cH as MIN_RESIZE_SIZE_PX, cI as resolveTextBoxRenderHeight, cJ as getToolbarStyleState, cK as VERTICAL_HIT_WEIGHT, cL as getCachedCanvasImage, cM as measureParagraphMinContentWidthPx, cN as getEditableBlocksForZone, cO as findParagraphLocation, cP as createSectionBoundaryParagraph, cQ as normalizePageSettings, cR as DEFAULT_EDITOR_PAGE_SETTINGS, cS as markStart, cT as markEnd, cU as getParagraphEntries, cV as getParagraphById, cW as createEditorFootnote, cX as createFootnoteReferenceRun, cY as renumberFootnotes, cZ as preciseFontModeVersion, c_ as isPreciseFontModeEnabled, c$ as getHeadingLevel, d0 as togglePreciseFontMode, d1 as nextFontSizePt, d2 as previousFontSizePt, d3 as fontSizePtToPx, d4 as resolveNamedTextStyle, d5 as resolveNamedTableStyle, d6 as resolveEffectiveTableStyle, d7 as createDefaultToolbarPreset, d8 as MenuRegistry, d9 as createToolbarRegistry, da as Editor, db as resolveCommandRef, dc as commandRefName, dd as createOasisEditorClient, de as createEditorZoom, df as startLongTaskObserver, dg as installGlobalReport, dh as applyStoredPreciseFontPreference, di as getWelcomeSeen, dj as isLocalFontAccessSupported, dk as EDITOR_SCROLL_PADDING_PX, dl as Toolbar, dm as OasisEditorLoading, dn as I18nProvider, dp as createTranslator, dq as registerDomStatsSurface, dr as createEditorLogger } from "./index-DOtfE4EA.js";
5
5
  function projectHeaderFooterBlocksWithDependencies(blocks, deps, context = {}) {
6
6
  const {
7
7
  pageIndex,
@@ -667,7 +667,7 @@ function cloneRun(run) {
667
667
  styles: cloneStyle(run.styles),
668
668
  revision: run.revision ? { ...run.revision } : void 0
669
669
  };
670
- return visitRun(run, {
670
+ const cloned = visitRun(run, {
671
671
  text: () => ({ ...base, kind: "text" }),
672
672
  image: (r) => ({ ...base, kind: "image", image: { ...r.image } }),
673
673
  textBox: (r) => ({
@@ -698,6 +698,7 @@ function cloneRun(run) {
698
698
  }),
699
699
  sym: (r) => ({ ...base, kind: "sym", sym: { ...r.sym } })
700
700
  });
701
+ return copyEditorRunOoxmlSource(run, cloned);
701
702
  }
702
703
  function cloneParagraph(paragraph) {
703
704
  return {
@@ -31195,7 +31196,7 @@ function parseEditorClipboardHtmlWithDom(html) {
31195
31196
  if (child.tagName !== "LI") {
31196
31197
  continue;
31197
31198
  }
31198
- appendParagraph(child, collectInlineRuns(child, void 0), {
31199
+ appendParagraph(child, collectInlineRuns$1(child, void 0), {
31199
31200
  kind,
31200
31201
  level: 0
31201
31202
  });
@@ -31221,12 +31222,12 @@ function parseEditorClipboardHtmlWithDom(html) {
31221
31222
  if (isParagraphTag(element.tagName)) {
31222
31223
  appendParagraph(
31223
31224
  element,
31224
- collectInlineRuns(element, void 0),
31225
+ collectInlineRuns$1(element, void 0),
31225
31226
  element.tagName === "LI" ? { kind: "bullet", level: 0 } : void 0
31226
31227
  );
31227
31228
  continue;
31228
31229
  }
31229
- const inlineRuns = collectInlineRuns(element, void 0);
31230
+ const inlineRuns = collectInlineRuns$1(element, void 0);
31230
31231
  if (inlineRuns.length > 0) {
31231
31232
  appendParagraph(null, inlineRuns);
31232
31233
  }
@@ -38060,6 +38061,312 @@ function wrapRunWithHyperlink(runXml, link, context) {
38060
38061
  }
38061
38062
  return `<w:hyperlink r:id="${rId}">${runXml}</w:hyperlink>`;
38062
38063
  }
38064
+ const MARKUP_COMPATIBILITY_NS$1 = "http://schemas.openxmlformats.org/markup-compatibility/2006";
38065
+ const XMLNS_NS$1 = "http://www.w3.org/2000/xmlns/";
38066
+ const TEXT_CONTENT_NAMES = /* @__PURE__ */ new Set([
38067
+ "t",
38068
+ "tab",
38069
+ "br",
38070
+ "cr",
38071
+ "noBreakHyphen",
38072
+ "softHyphen"
38073
+ ]);
38074
+ const GENERATED_RUN_CONTENT_NAMES = /* @__PURE__ */ new Set([
38075
+ ...TEXT_CONTENT_NAMES,
38076
+ "drawing",
38077
+ "pict",
38078
+ "sym",
38079
+ "fldChar",
38080
+ "instrText",
38081
+ "footnoteReference",
38082
+ "endnoteReference",
38083
+ "separator",
38084
+ "continuationSeparator"
38085
+ ]);
38086
+ const MODELED_WORD_RUN_PROPERTY_NAMES = /* @__PURE__ */ new Set([
38087
+ "rStyle",
38088
+ "rFonts",
38089
+ "b",
38090
+ "bCs",
38091
+ "i",
38092
+ "iCs",
38093
+ "caps",
38094
+ "smallCaps",
38095
+ "strike",
38096
+ "dstrike",
38097
+ "outline",
38098
+ "shadow",
38099
+ "emboss",
38100
+ "imprint",
38101
+ "noProof",
38102
+ "snapToGrid",
38103
+ "vanish",
38104
+ "webHidden",
38105
+ "color",
38106
+ "spacing",
38107
+ "w",
38108
+ "kern",
38109
+ "position",
38110
+ "sz",
38111
+ "szCs",
38112
+ "highlight",
38113
+ "u",
38114
+ "effect",
38115
+ "bdr",
38116
+ "shd",
38117
+ "fitText",
38118
+ "vertAlign",
38119
+ "rtl",
38120
+ "cs",
38121
+ "em",
38122
+ "lang",
38123
+ "eastAsianLayout",
38124
+ "specVanish",
38125
+ "oMath"
38126
+ ]);
38127
+ const MODELED_WORD14_RUN_PROPERTY_NAMES = /* @__PURE__ */ new Set([
38128
+ "ligatures",
38129
+ "numSpacing",
38130
+ "numForm",
38131
+ "stylisticSets",
38132
+ "cntxtAlts",
38133
+ "textFill",
38134
+ "textOutline",
38135
+ "shadow",
38136
+ "glow",
38137
+ "reflection",
38138
+ "scene3d",
38139
+ "props3d"
38140
+ ]);
38141
+ function hasRelationshipReference$2(xml) {
38142
+ return /\br:(?:id|embed|link)\s*=/.test(xml);
38143
+ }
38144
+ function directElementChildren$2(element) {
38145
+ const children = [];
38146
+ for (let index = 0; index < element.childNodes.length; index += 1) {
38147
+ const node = element.childNodes[index];
38148
+ if ((node == null ? void 0 : node.nodeType) === node.ELEMENT_NODE) {
38149
+ children.push(node);
38150
+ }
38151
+ }
38152
+ return children;
38153
+ }
38154
+ function elementLocalName$2(element) {
38155
+ return element.localName ?? element.tagName;
38156
+ }
38157
+ function directChild(element, namespaceUri, localName) {
38158
+ return directElementChildren$2(element).find(
38159
+ (child) => child.namespaceURI === namespaceUri && elementLocalName$2(child) === localName
38160
+ );
38161
+ }
38162
+ function elementKey$1(element) {
38163
+ return `${element.namespaceURI ?? ""}\0${elementLocalName$2(element)}`;
38164
+ }
38165
+ function parseSingleRunXml(xml) {
38166
+ const document2 = new DOMParser().parseFromString(xml, "application/xml");
38167
+ const root = document2.documentElement;
38168
+ return root && elementLocalName$2(root) === "r" ? root : void 0;
38169
+ }
38170
+ function parseGeneratedSingleRunXml(xml) {
38171
+ const wrapper = new DOMParser().parseFromString(
38172
+ `<oasis:root xmlns:oasis="urn:oasis:docx" xmlns:w="${WORD_NS$1}" xmlns:w14="${WORD14_NS}" xmlns:r="${OFFICE_REL_NS}" xmlns:mc="${MARKUP_COMPATIBILITY_NS$1}" xmlns:wp="http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing" xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main" xmlns:pic="http://schemas.openxmlformats.org/drawingml/2006/picture" xmlns:wps="http://schemas.microsoft.com/office/word/2010/wordprocessingShape">${xml}</oasis:root>`,
38173
+ "application/xml"
38174
+ ).documentElement;
38175
+ if (!wrapper) {
38176
+ return void 0;
38177
+ }
38178
+ const children = directElementChildren$2(wrapper);
38179
+ return children.length === 1 && elementLocalName$2(children[0]) === "r" ? children[0] : void 0;
38180
+ }
38181
+ function patchTextRunSourceXml(run, sourceXml) {
38182
+ if (run.kind !== "text") {
38183
+ return void 0;
38184
+ }
38185
+ const sourceRun = parseSingleRunXml(sourceXml);
38186
+ if (!sourceRun) {
38187
+ return void 0;
38188
+ }
38189
+ const sourceChildren = directElementChildren$2(sourceRun);
38190
+ const oldTextChildren = sourceChildren.filter(
38191
+ (child) => child.namespaceURI === WORD_NS$1 && TEXT_CONTENT_NAMES.has(elementLocalName$2(child))
38192
+ );
38193
+ const insertionPoint = oldTextChildren[0] ?? sourceChildren.find(
38194
+ (child) => !(child.namespaceURI === WORD_NS$1 && elementLocalName$2(child) === "rPr")
38195
+ ) ?? null;
38196
+ const generatedRun = parseGeneratedSingleRunXml(
38197
+ `<w:r>${serializeRunText(run.text)}</w:r>`
38198
+ );
38199
+ if (!generatedRun) {
38200
+ return void 0;
38201
+ }
38202
+ const generatedChildren = directElementChildren$2(generatedRun);
38203
+ for (const child of generatedChildren) {
38204
+ sourceRun.insertBefore(child.cloneNode(true), insertionPoint);
38205
+ }
38206
+ for (const child of oldTextChildren) {
38207
+ sourceRun.removeChild(child);
38208
+ }
38209
+ return new XMLSerializer().serializeToString(sourceRun);
38210
+ }
38211
+ function isNamespaceDeclaration$1(attribute) {
38212
+ return attribute.namespaceURI === XMLNS_NS$1 || attribute.prefix === "xmlns" || attribute.name === "xmlns";
38213
+ }
38214
+ function hasPreservableAttributes(element) {
38215
+ for (let index = 0; index < element.attributes.length; index += 1) {
38216
+ const attribute = element.attributes[index];
38217
+ if (attribute && !isNamespaceDeclaration$1(attribute) && attribute.namespaceURI !== OFFICE_REL_NS) {
38218
+ return true;
38219
+ }
38220
+ }
38221
+ return false;
38222
+ }
38223
+ function copySourceRunAttributes(sourceRun, generatedRun) {
38224
+ for (let index = 0; index < sourceRun.attributes.length; index += 1) {
38225
+ const attribute = sourceRun.attributes[index];
38226
+ if (!attribute || attribute.namespaceURI === OFFICE_REL_NS) {
38227
+ continue;
38228
+ }
38229
+ const localName = attribute.localName ?? attribute.name;
38230
+ const hasAttribute = attribute.namespaceURI ? generatedRun.hasAttributeNS(attribute.namespaceURI, localName) : generatedRun.hasAttribute(attribute.name);
38231
+ if (hasAttribute) {
38232
+ continue;
38233
+ }
38234
+ if (attribute.namespaceURI) {
38235
+ generatedRun.setAttributeNS(
38236
+ attribute.namespaceURI,
38237
+ attribute.name,
38238
+ attribute.value
38239
+ );
38240
+ } else {
38241
+ generatedRun.setAttribute(attribute.name, attribute.value);
38242
+ }
38243
+ }
38244
+ }
38245
+ function isModeledRunProperty(element) {
38246
+ const localName = elementLocalName$2(element);
38247
+ if (element.namespaceURI === WORD_NS$1) {
38248
+ return MODELED_WORD_RUN_PROPERTY_NAMES.has(localName);
38249
+ }
38250
+ if (element.namespaceURI === WORD14_NS) {
38251
+ return MODELED_WORD14_RUN_PROPERTY_NAMES.has(localName);
38252
+ }
38253
+ return element.namespaceURI === MARKUP_COMPATIBILITY_NS$1 && localName === "AlternateContent";
38254
+ }
38255
+ function ensureGeneratedRunProperties(generatedRun) {
38256
+ const existing = directChild(generatedRun, WORD_NS$1, "rPr");
38257
+ if (existing) {
38258
+ return existing;
38259
+ }
38260
+ const properties = generatedRun.ownerDocument.createElementNS(
38261
+ WORD_NS$1,
38262
+ "w:rPr"
38263
+ );
38264
+ generatedRun.insertBefore(properties, generatedRun.firstChild);
38265
+ return properties;
38266
+ }
38267
+ function mergeSourceRunProperties(sourceRun, generatedRun) {
38268
+ const sourceProperties = directChild(sourceRun, WORD_NS$1, "rPr");
38269
+ if (!sourceProperties) {
38270
+ return;
38271
+ }
38272
+ const sourceChildren = directElementChildren$2(sourceProperties);
38273
+ const generatedProperties = directChild(generatedRun, WORD_NS$1, "rPr");
38274
+ const generatedChildren = generatedProperties ? directElementChildren$2(generatedProperties) : [];
38275
+ const generatedKeys = new Set(generatedChildren.map(elementKey$1));
38276
+ const preserved = sourceChildren.filter(
38277
+ (child) => !isModeledRunProperty(child) && !generatedKeys.has(elementKey$1(child))
38278
+ );
38279
+ if (preserved.length === 0) {
38280
+ return;
38281
+ }
38282
+ const targetProperties = ensureGeneratedRunProperties(generatedRun);
38283
+ for (const child of preserved) {
38284
+ const sourceIndex = sourceChildren.indexOf(child);
38285
+ const nextKnownSourceChild = sourceChildren.slice(sourceIndex + 1).find((candidate) => generatedKeys.has(elementKey$1(candidate)));
38286
+ const anchor = nextKnownSourceChild ? directElementChildren$2(targetProperties).find(
38287
+ (candidate) => elementKey$1(candidate) === elementKey$1(nextKnownSourceChild)
38288
+ ) ?? null : null;
38289
+ targetProperties.insertBefore(child.cloneNode(true), anchor);
38290
+ }
38291
+ }
38292
+ function alternateContentContainsGeneratedRunContent(alternateContent) {
38293
+ const visit = (element) => directElementChildren$2(element).some((child) => {
38294
+ const localName = elementLocalName$2(child);
38295
+ if (child.namespaceURI === WORD_NS$1 && GENERATED_RUN_CONTENT_NAMES.has(localName)) {
38296
+ return true;
38297
+ }
38298
+ return visit(child);
38299
+ });
38300
+ return visit(alternateContent);
38301
+ }
38302
+ function isGeneratedRunContent(element) {
38303
+ const localName = elementLocalName$2(element);
38304
+ if (element.namespaceURI === MARKUP_COMPATIBILITY_NS$1 && localName === "AlternateContent") {
38305
+ return alternateContentContainsGeneratedRunContent(element);
38306
+ }
38307
+ return element.namespaceURI === WORD_NS$1 && (localName === "rPr" || GENERATED_RUN_CONTENT_NAMES.has(localName));
38308
+ }
38309
+ function hasPreservableSourceRunContent(sourceRun) {
38310
+ if (hasPreservableAttributes(sourceRun)) {
38311
+ return true;
38312
+ }
38313
+ const sourceProperties = directChild(sourceRun, WORD_NS$1, "rPr");
38314
+ if (sourceProperties && (hasPreservableAttributes(sourceProperties) || directElementChildren$2(sourceProperties).some(
38315
+ (child) => !isModeledRunProperty(child)
38316
+ ))) {
38317
+ return true;
38318
+ }
38319
+ return directElementChildren$2(sourceRun).some(
38320
+ (child) => !isGeneratedRunContent(child)
38321
+ );
38322
+ }
38323
+ function mergeSourceRunChildren(sourceRun, generatedRun) {
38324
+ const sourceChildren = directElementChildren$2(sourceRun);
38325
+ const generatedChildren = directElementChildren$2(generatedRun);
38326
+ const generatedKeys = new Set(generatedChildren.map(elementKey$1));
38327
+ const preserved = sourceChildren.filter(
38328
+ (child) => !isGeneratedRunContent(child) && !generatedKeys.has(elementKey$1(child))
38329
+ );
38330
+ for (const child of preserved) {
38331
+ const sourceIndex = sourceChildren.indexOf(child);
38332
+ const nextGeneratedSourceChild = sourceChildren.slice(sourceIndex + 1).find((candidate) => isGeneratedRunContent(candidate));
38333
+ const anchor = nextGeneratedSourceChild ? directElementChildren$2(generatedRun).find(
38334
+ (candidate) => elementKey$1(candidate) === elementKey$1(nextGeneratedSourceChild)
38335
+ ) ?? null : null;
38336
+ generatedRun.insertBefore(child.cloneNode(true), anchor);
38337
+ }
38338
+ }
38339
+ function serializeRunFromOoxmlSource(run) {
38340
+ const source = getEditorRunOoxmlSource(run);
38341
+ if (!source || hasRelationshipReference$2(source.xml) || ooxmlSourceNeedsCanonicalRunSerialization(source.xml)) {
38342
+ return void 0;
38343
+ }
38344
+ if (source.semanticSignature === createEditorRunSemanticSignature(run)) {
38345
+ return source.xml;
38346
+ }
38347
+ if (source.structureSignature !== createEditorRunStructureSignature(run)) {
38348
+ return void 0;
38349
+ }
38350
+ return patchTextRunSourceXml(run, source.xml);
38351
+ }
38352
+ function mergeRunOoxmlSourceIntoGeneratedXml(run, generatedXml) {
38353
+ const source = getEditorRunOoxmlSource(run);
38354
+ if (!source || hasRelationshipReference$2(source.xml)) {
38355
+ return generatedXml;
38356
+ }
38357
+ const sourceRun = parseSingleRunXml(source.xml);
38358
+ if (!sourceRun || !hasPreservableSourceRunContent(sourceRun)) {
38359
+ return generatedXml;
38360
+ }
38361
+ const generatedRun = parseGeneratedSingleRunXml(generatedXml);
38362
+ if (!generatedRun) {
38363
+ return generatedXml;
38364
+ }
38365
+ copySourceRunAttributes(sourceRun, generatedRun);
38366
+ mergeSourceRunProperties(sourceRun, generatedRun);
38367
+ mergeSourceRunChildren(sourceRun, generatedRun);
38368
+ return new XMLSerializer().serializeToString(generatedRun);
38369
+ }
38063
38370
  function serializeRun(run, context, paragraphStyleId, styles, serializeBlocksXml2) {
38064
38371
  if (run.__isFootnoteRefMarker) {
38065
38372
  return serializeFootnoteRefMarker();
@@ -38067,6 +38374,10 @@ function serializeRun(run, context, paragraphStyleId, styles, serializeBlocksXml
38067
38374
  if (run.__isEndnoteRefMarker) {
38068
38375
  return serializeEndnoteRefMarker();
38069
38376
  }
38377
+ const preservedSourceXml = serializeRunFromOoxmlSource(run);
38378
+ if (preservedSourceXml) {
38379
+ return preservedSourceXml;
38380
+ }
38070
38381
  const materializedRunStyle = materializeRunStyle(
38071
38382
  run,
38072
38383
  paragraphStyleId,
@@ -38074,7 +38385,7 @@ function serializeRun(run, context, paragraphStyleId, styles, serializeBlocksXml
38074
38385
  );
38075
38386
  const runProps = () => serializeRunProperties(materializedRunStyle);
38076
38387
  const asText = () => `<w:r>${runProps()}${serializeRunText(run.text)}</w:r>`;
38077
- return visitRun(run, {
38388
+ const generatedXml = visitRun(run, {
38078
38389
  footnoteReference: (r) => serializeFootnoteReference(r, materializedRunStyle, context) ?? asText(),
38079
38390
  endnoteReference: (r) => serializeEndnoteReference(r, materializedRunStyle, context) ?? asText(),
38080
38391
  fieldChar: (r) => serializeFieldCharRun(r.fieldChar, runProps()),
@@ -38101,6 +38412,7 @@ function serializeRun(run, context, paragraphStyleId, styles, serializeBlocksXml
38101
38412
  sym: (r) => `<w:r>${runProps()}<w:sym w:font="${escapeXml(r.sym.font)}" w:char="${r.sym.char}"/></w:r>`,
38102
38413
  text: () => asText()
38103
38414
  });
38415
+ return mergeRunOoxmlSourceIntoGeneratedXml(run, generatedXml);
38104
38416
  }
38105
38417
  function serializeRunWithRelationships(run, context, paragraphStyleId, styles, serializeBlocksXml2) {
38106
38418
  var _a;
@@ -38262,6 +38574,281 @@ function serializeDropCapFrameParagraph(dropCap) {
38262
38574
  function stripRpr(rPr) {
38263
38575
  return rPr.replace(/^<w:rPr>/, "").replace(/<\/w:rPr>$/, "");
38264
38576
  }
38577
+ const MODELED_PARAGRAPH_PROPERTY_NAMES = /* @__PURE__ */ new Set([
38578
+ "pStyle",
38579
+ "keepNext",
38580
+ "keepLines",
38581
+ "pageBreakBefore",
38582
+ "framePr",
38583
+ "widowControl",
38584
+ "numPr",
38585
+ "suppressLineNumbers",
38586
+ "pBdr",
38587
+ "shd",
38588
+ "tabs",
38589
+ "suppressAutoHyphens",
38590
+ "kinsoku",
38591
+ "wordWrap",
38592
+ "overflowPunct",
38593
+ "topLinePunct",
38594
+ "autoSpaceDE",
38595
+ "autoSpaceDN",
38596
+ "bidi",
38597
+ "adjustRightInd",
38598
+ "snapToGrid",
38599
+ "spacing",
38600
+ "ind",
38601
+ "contextualSpacing",
38602
+ "mirrorIndents",
38603
+ "suppressOverlap",
38604
+ "jc",
38605
+ "textDirection",
38606
+ "textAlignment",
38607
+ "textboxTightWrap",
38608
+ "outlineLvl",
38609
+ "divId",
38610
+ "cnfStyle",
38611
+ "rPr",
38612
+ "sectPr",
38613
+ "pPrChange"
38614
+ ]);
38615
+ function hasRelationshipReference$1(xml) {
38616
+ return /\br:(?:id|embed|link)\s*=/.test(xml);
38617
+ }
38618
+ function directElementChildren$1(element) {
38619
+ const children = [];
38620
+ for (let index = 0; index < element.childNodes.length; index += 1) {
38621
+ const node = element.childNodes[index];
38622
+ if ((node == null ? void 0 : node.nodeType) === node.ELEMENT_NODE) {
38623
+ children.push(node);
38624
+ }
38625
+ }
38626
+ return children;
38627
+ }
38628
+ function elementLocalName$1(element) {
38629
+ return element.localName ?? element.tagName;
38630
+ }
38631
+ function elementKey(element) {
38632
+ return `${element.namespaceURI ?? ""}\0${elementLocalName$1(element)}`;
38633
+ }
38634
+ function parseParagraphPropertiesXml(xml) {
38635
+ const document2 = new DOMParser().parseFromString(xml, "application/xml");
38636
+ const root = document2.documentElement;
38637
+ return (root == null ? void 0 : root.namespaceURI) === WORD_NS$1 && elementLocalName$1(root) === "pPr" ? root : void 0;
38638
+ }
38639
+ function createGeneratedParagraphProperties(xml) {
38640
+ if (xml) {
38641
+ const wrapper = new DOMParser().parseFromString(
38642
+ `<oasis:root xmlns:oasis="urn:oasis:docx" xmlns:w="${WORD_NS$1}">${xml}</oasis:root>`,
38643
+ "application/xml"
38644
+ ).documentElement;
38645
+ const children = wrapper ? directElementChildren$1(wrapper) : [];
38646
+ if (children.length === 1 && children[0].namespaceURI === WORD_NS$1 && elementLocalName$1(children[0]) === "pPr") {
38647
+ return children[0];
38648
+ }
38649
+ }
38650
+ return new DOMParser().parseFromString(
38651
+ `<w:pPr xmlns:w="${WORD_NS$1}"/>`,
38652
+ "application/xml"
38653
+ ).documentElement;
38654
+ }
38655
+ function copySourceAttributes(source, generated) {
38656
+ for (let index = 0; index < source.attributes.length; index += 1) {
38657
+ const attribute = source.attributes[index];
38658
+ if (!attribute || attribute.namespaceURI === OFFICE_REL_NS) {
38659
+ continue;
38660
+ }
38661
+ const localName = attribute.localName ?? attribute.name;
38662
+ const hasAttribute = attribute.namespaceURI ? generated.hasAttributeNS(attribute.namespaceURI, localName) : generated.hasAttribute(attribute.name);
38663
+ if (hasAttribute) {
38664
+ continue;
38665
+ }
38666
+ if (attribute.namespaceURI) {
38667
+ generated.setAttributeNS(
38668
+ attribute.namespaceURI,
38669
+ attribute.name,
38670
+ attribute.value
38671
+ );
38672
+ } else {
38673
+ generated.setAttribute(attribute.name, attribute.value);
38674
+ }
38675
+ }
38676
+ }
38677
+ function isModeledParagraphProperty(element) {
38678
+ return element.namespaceURI === WORD_NS$1 && MODELED_PARAGRAPH_PROPERTY_NAMES.has(elementLocalName$1(element));
38679
+ }
38680
+ function mergeParagraphPropertiesOoxmlSource(paragraph, generatedXml, hasOverrides) {
38681
+ var _a;
38682
+ const source = (_a = getEditorParagraphOoxmlSource(paragraph)) == null ? void 0 : _a.paragraphProperties;
38683
+ if (!source || hasRelationshipReference$1(source.xml)) {
38684
+ return generatedXml;
38685
+ }
38686
+ if (!hasOverrides && !paragraph.list && source.semanticSignature === createEditorParagraphPropertiesSignature(paragraph)) {
38687
+ return source.xml;
38688
+ }
38689
+ const sourceProperties = parseParagraphPropertiesXml(source.xml);
38690
+ const generatedProperties = createGeneratedParagraphProperties(generatedXml);
38691
+ if (!sourceProperties || !generatedProperties) {
38692
+ return generatedXml;
38693
+ }
38694
+ copySourceAttributes(sourceProperties, generatedProperties);
38695
+ const sourceChildren = directElementChildren$1(sourceProperties);
38696
+ const generatedChildren = directElementChildren$1(generatedProperties);
38697
+ const generatedKeys = new Set(generatedChildren.map(elementKey));
38698
+ const preserved = sourceChildren.filter(
38699
+ (child) => !isModeledParagraphProperty(child) && !generatedKeys.has(elementKey(child))
38700
+ );
38701
+ for (const child of preserved) {
38702
+ const sourceIndex = sourceChildren.indexOf(child);
38703
+ const nextGeneratedSourceChild = sourceChildren.slice(sourceIndex + 1).find((candidate) => generatedKeys.has(elementKey(candidate)));
38704
+ const anchor = nextGeneratedSourceChild ? directElementChildren$1(generatedProperties).find(
38705
+ (candidate) => elementKey(candidate) === elementKey(nextGeneratedSourceChild)
38706
+ ) ?? null : null;
38707
+ generatedProperties.insertBefore(child.cloneNode(true), anchor);
38708
+ }
38709
+ if (!generatedXml && generatedProperties.attributes.length === 1 && directElementChildren$1(generatedProperties).length === 0) {
38710
+ return "";
38711
+ }
38712
+ return new XMLSerializer().serializeToString(generatedProperties);
38713
+ }
38714
+ const MARKUP_COMPATIBILITY_NS = "http://schemas.openxmlformats.org/markup-compatibility/2006";
38715
+ const XMLNS_NS = "http://www.w3.org/2000/xmlns/";
38716
+ const STANDARD_PARAGRAPH_CHILD_NAMES = /* @__PURE__ */ new Set([
38717
+ "pPr",
38718
+ "r",
38719
+ "hyperlink",
38720
+ "fldSimple",
38721
+ "bookmarkStart",
38722
+ "bookmarkEnd",
38723
+ "commentRangeStart",
38724
+ "commentRangeEnd"
38725
+ ]);
38726
+ function hasRelationshipReference(xml) {
38727
+ return /\br:(?:id|embed|link)\s*=/.test(xml);
38728
+ }
38729
+ function directElementChildren(element) {
38730
+ const children = [];
38731
+ for (let index = 0; index < element.childNodes.length; index += 1) {
38732
+ const node = element.childNodes[index];
38733
+ if ((node == null ? void 0 : node.nodeType) === node.ELEMENT_NODE) {
38734
+ children.push(node);
38735
+ }
38736
+ }
38737
+ return children;
38738
+ }
38739
+ function elementLocalName(element) {
38740
+ return element.localName ?? element.tagName;
38741
+ }
38742
+ function directWordChild(element, localName) {
38743
+ return directElementChildren(element).find(
38744
+ (child) => child.namespaceURI === WORD_NS$1 && elementLocalName(child) === localName
38745
+ );
38746
+ }
38747
+ function collectInlineRuns(paragraph) {
38748
+ const runs = [];
38749
+ const visit = (container) => {
38750
+ for (const child of directElementChildren(container)) {
38751
+ const localName = elementLocalName(child);
38752
+ if (child.namespaceURI === WORD_NS$1 && localName === "r") {
38753
+ runs.push(child);
38754
+ continue;
38755
+ }
38756
+ if (child.namespaceURI === WORD_NS$1 && (localName === "pPr" || localName === "p" || localName === "tbl" || localName === "txbxContent")) {
38757
+ continue;
38758
+ }
38759
+ visit(child);
38760
+ }
38761
+ };
38762
+ visit(paragraph);
38763
+ return runs;
38764
+ }
38765
+ function parseSourceParagraph(xml) {
38766
+ const root = new DOMParser().parseFromString(xml, "application/xml").documentElement;
38767
+ return (root == null ? void 0 : root.namespaceURI) === WORD_NS$1 && elementLocalName(root) === "p" ? root : void 0;
38768
+ }
38769
+ function parseGeneratedElement(xml, expectedLocalName) {
38770
+ const wrapper = new DOMParser().parseFromString(
38771
+ `<oasis:root xmlns:oasis="urn:oasis:docx" xmlns:w="${WORD_NS$1}" xmlns:w14="${WORD14_NS}" xmlns:r="${OFFICE_REL_NS}" xmlns:mc="${MARKUP_COMPATIBILITY_NS}" xmlns:wp="http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing" xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main" xmlns:pic="http://schemas.openxmlformats.org/drawingml/2006/picture" xmlns:wps="http://schemas.microsoft.com/office/word/2010/wordprocessingShape">${xml}</oasis:root>`,
38772
+ "application/xml"
38773
+ ).documentElement;
38774
+ if (!wrapper) {
38775
+ return void 0;
38776
+ }
38777
+ const children = directElementChildren(wrapper);
38778
+ return children.length === 1 && children[0].namespaceURI === WORD_NS$1 && elementLocalName(children[0]) === expectedLocalName ? children[0] : void 0;
38779
+ }
38780
+ function isNamespaceDeclaration(attribute) {
38781
+ return attribute.namespaceURI === XMLNS_NS || attribute.prefix === "xmlns" || attribute.name === "xmlns";
38782
+ }
38783
+ function sourceParagraphNeedsOverlay(paragraph) {
38784
+ for (let index = 0; index < paragraph.attributes.length; index += 1) {
38785
+ const attribute = paragraph.attributes[index];
38786
+ if (attribute && !isNamespaceDeclaration(attribute) && attribute.namespaceURI !== OFFICE_REL_NS) {
38787
+ return true;
38788
+ }
38789
+ }
38790
+ return directElementChildren(paragraph).some((child) => {
38791
+ const localName = elementLocalName(child);
38792
+ return child.namespaceURI !== WORD_NS$1 || !STANDARD_PARAGRAPH_CHILD_NAMES.has(localName);
38793
+ });
38794
+ }
38795
+ function replaceParagraphProperties(sourceParagraph, generatedPropertiesXml) {
38796
+ const sourceProperties = directWordChild(sourceParagraph, "pPr");
38797
+ if (!generatedPropertiesXml) {
38798
+ if (sourceProperties) {
38799
+ sourceParagraph.removeChild(sourceProperties);
38800
+ }
38801
+ return true;
38802
+ }
38803
+ const generatedProperties = parseGeneratedElement(
38804
+ generatedPropertiesXml,
38805
+ "pPr"
38806
+ );
38807
+ if (!generatedProperties) {
38808
+ return false;
38809
+ }
38810
+ const replacement = generatedProperties.cloneNode(true);
38811
+ if (sourceProperties) {
38812
+ sourceParagraph.replaceChild(replacement, sourceProperties);
38813
+ } else {
38814
+ sourceParagraph.insertBefore(replacement, sourceParagraph.firstChild);
38815
+ }
38816
+ return true;
38817
+ }
38818
+ function overlayEditorParagraphOnOoxmlSource(paragraph, generatedParagraphPropertiesXml, generatedRunXml, options) {
38819
+ var _a, _b;
38820
+ const sourceXml = (_a = getEditorParagraphOoxmlSource(paragraph)) == null ? void 0 : _a.xml;
38821
+ if (!sourceXml || options.hasOverrides || options.hasBoundaryTokens || paragraph.dropCap || hasRelationshipReference(sourceXml)) {
38822
+ return void 0;
38823
+ }
38824
+ const sourceParagraph = parseSourceParagraph(sourceXml);
38825
+ if (!sourceParagraph || !sourceParagraphNeedsOverlay(sourceParagraph)) {
38826
+ return void 0;
38827
+ }
38828
+ const sourceRuns = collectInlineRuns(sourceParagraph);
38829
+ if (sourceRuns.length !== generatedRunXml.length) {
38830
+ return void 0;
38831
+ }
38832
+ const generatedRuns = generatedRunXml.map(
38833
+ (xml) => parseGeneratedElement(xml, "r")
38834
+ );
38835
+ if (generatedRuns.some((run) => !run)) {
38836
+ return void 0;
38837
+ }
38838
+ if (!replaceParagraphProperties(
38839
+ sourceParagraph,
38840
+ generatedParagraphPropertiesXml
38841
+ )) {
38842
+ return void 0;
38843
+ }
38844
+ for (let index = 0; index < sourceRuns.length; index += 1) {
38845
+ (_b = sourceRuns[index].parentNode) == null ? void 0 : _b.replaceChild(
38846
+ generatedRuns[index].cloneNode(true),
38847
+ sourceRuns[index]
38848
+ );
38849
+ }
38850
+ return new XMLSerializer().serializeToString(sourceParagraph);
38851
+ }
38265
38852
  function isSplittableTextRun(run) {
38266
38853
  return run.kind === "text" || run.kind === "sym";
38267
38854
  }
@@ -38396,13 +38983,14 @@ function serializeParagraphXml(paragraph, context, styles, overrides) {
38396
38983
  })
38397
38984
  )
38398
38985
  ];
38399
- const runsXml = boundaryTokens.length > 0 ? serializeRunsWithBoundaries(
38400
- runs,
38401
- boundaryTokens,
38402
- context,
38403
- (_c = paragraph.style) == null ? void 0 : _c.styleId,
38404
- styles
38405
- ) : runs.map(
38986
+ const reusableParagraphXml = getReusableEditorParagraphXml(paragraph, {
38987
+ hasOverrides: Boolean(overrides),
38988
+ hasBoundaryTokens: boundaryTokens.length > 0
38989
+ });
38990
+ if (reusableParagraphXml) {
38991
+ return reusableParagraphXml;
38992
+ }
38993
+ const serializedRunXml = boundaryTokens.length === 0 ? runs.map(
38406
38994
  (run) => {
38407
38995
  var _a2;
38408
38996
  return serializeRunWithRelationships(
@@ -38413,13 +39001,42 @@ function serializeParagraphXml(paragraph, context, styles, overrides) {
38413
39001
  serializeBlocksXml
38414
39002
  );
38415
39003
  }
38416
- ).join("");
38417
- return `${dropCapFrame}<w:p>${serializeParagraphProperties(
39004
+ ) : void 0;
39005
+ const runsXml = serializedRunXml ? serializedRunXml.join("") : serializeRunsWithBoundaries(
39006
+ runs,
39007
+ boundaryTokens,
39008
+ context,
39009
+ (_c = paragraph.style) == null ? void 0 : _c.styleId,
39010
+ styles
39011
+ );
39012
+ const sourceAttributes = getEditorParagraphOoxmlAttributes(paragraph);
39013
+ const paragraphAttributes = sourceAttributes ? ` ${sourceAttributes}` : "";
39014
+ const generatedParagraphProperties = serializeParagraphProperties(
38418
39015
  paragraph,
38419
39016
  context.numberingInfo,
38420
39017
  styles,
38421
39018
  overrides
38422
- )}${runsXml}</w:p>`;
39019
+ );
39020
+ const paragraphProperties = mergeParagraphPropertiesOoxmlSource(
39021
+ paragraph,
39022
+ generatedParagraphProperties,
39023
+ Boolean(overrides)
39024
+ );
39025
+ if (serializedRunXml) {
39026
+ const overlaidParagraphXml = overlayEditorParagraphOnOoxmlSource(
39027
+ paragraph,
39028
+ paragraphProperties,
39029
+ serializedRunXml,
39030
+ {
39031
+ hasOverrides: Boolean(overrides),
39032
+ hasBoundaryTokens: false
39033
+ }
39034
+ );
39035
+ if (overlaidParagraphXml) {
39036
+ return overlaidParagraphXml;
39037
+ }
39038
+ }
39039
+ return `${dropCapFrame}<w:p${paragraphAttributes}>${paragraphProperties}${runsXml}</w:p>`;
38423
39040
  }
38424
39041
  const FIRST_FOOTNOTE_DOCX_ID = 1;
38425
39042
  function collectReferencedFootnotesForExport(document2) {
@@ -38959,6 +39576,8 @@ function buildNumberingContext(document2) {
38959
39576
  definitions.push(definition);
38960
39577
  }
38961
39578
  if (!definition.levels.some((candidate) => candidate.level === level)) {
39579
+ const sourceMetadata = getEditorListOoxmlNumberingMetadata(paragraph.list);
39580
+ const sourceFormat = getEffectiveEditorListOoxmlFormat(paragraph.list);
38962
39581
  definition.levels.push({
38963
39582
  kind: paragraph.list.kind,
38964
39583
  level,
@@ -38969,7 +39588,13 @@ function buildNumberingContext(document2) {
38969
39588
  alignment: paragraph.list.alignment,
38970
39589
  legal: paragraph.list.legal,
38971
39590
  bulletGlyph: paragraph.list.bulletGlyph,
38972
- bulletFont: paragraph.list.bulletFont
39591
+ bulletFont: paragraph.list.bulletFont,
39592
+ ...sourceMetadata ? {
39593
+ ooxml: {
39594
+ ...sourceMetadata,
39595
+ ...sourceFormat ? { format: sourceFormat } : { format: void 0 }
39596
+ }
39597
+ } : {}
38973
39598
  });
38974
39599
  }
38975
39600
  numberingInfo.set(paragraph.id, { numId: definition.numId, level });
@@ -39010,16 +39635,19 @@ function buildNumberingXml(definitions) {
39010
39635
  alignment,
39011
39636
  legal,
39012
39637
  bulletGlyph,
39013
- bulletFont
39638
+ bulletFont,
39639
+ ooxml
39014
39640
  }) => {
39015
- const numFmtVal = kind === "bullet" ? "bullet" : format ?? "decimal";
39641
+ const numFmtVal = kind === "bullet" ? "bullet" : (ooxml == null ? void 0 : ooxml.format) ?? format ?? "decimal";
39016
39642
  const effectiveLevelText = levelText ?? (kind === "bullet" ? bulletGlyph ?? "" : `%${level + 1}.`);
39017
39643
  const startVal = startAt ?? 1;
39018
39644
  const fontName = kind === "bullet" ? bulletFont ?? "Symbol" : void 0;
39019
39645
  const runFonts = fontName ? `<w:rPr><w:rFonts w:ascii="${escapeXml(fontName)}" w:hAnsi="${escapeXml(fontName)}" w:hint="default"/></w:rPr>` : "";
39020
39646
  const suffixXml = suffix && suffix !== "tab" ? `<w:suff w:val="${suffix}"/>` : "";
39021
39647
  const legalXml = legal ? "<w:isLgl/>" : "";
39022
- return `<w:lvl w:ilvl="${level}"><w:start w:val="${startVal}"/><w:numFmt w:val="${numFmtVal}"/><w:lvlText w:val="${escapeXml(effectiveLevelText)}"/><w:lvlJc w:val="${alignment ?? "left"}"/>${suffixXml}${legalXml}${runFonts}</w:lvl>`;
39648
+ const restartXml = (ooxml == null ? void 0 : ooxml.restartAfterLevel) !== void 0 ? `<w:lvlRestart w:val="${ooxml.restartAfterLevel}"/>` : "";
39649
+ const paragraphStyleXml = (ooxml == null ? void 0 : ooxml.paragraphStyleId) ? `<w:pStyle w:val="${escapeXml(ooxml.paragraphStyleId)}"/>` : "";
39650
+ return `<w:lvl w:ilvl="${level}"><w:start w:val="${startVal}"/><w:numFmt w:val="${escapeXml(numFmtVal)}"/>${restartXml}${paragraphStyleXml}<w:lvlText w:val="${escapeXml(effectiveLevelText)}"/><w:lvlJc w:val="${alignment ?? "left"}"/>${suffixXml}${legalXml}${runFonts}</w:lvl>`;
39023
39651
  }
39024
39652
  ).join("");
39025
39653
  return `<w:abstractNum w:abstractNumId="${abstractNumId}">${levelsXml}</w:abstractNum>`;
@@ -39585,6 +40213,119 @@ async function exportEditorDocumentToDocxBlob(document2) {
39585
40213
  type: "application/vnd.openxmlformats-officedocument.wordprocessingml.document"
39586
40214
  });
39587
40215
  }
40216
+ const OFFICE_DOCUMENT_RELATIONSHIP_SUFFIX = "/officeDocument";
40217
+ function relationshipKey(relationship) {
40218
+ return [
40219
+ relationship.type,
40220
+ relationship.target,
40221
+ relationship.targetMode ?? "Internal"
40222
+ ].join("\0");
40223
+ }
40224
+ function mergeRelationships(source, rebuilt, relationshipPartPath) {
40225
+ const result = [...rebuilt];
40226
+ const rebuiltById = new Map(
40227
+ rebuilt.map(
40228
+ (relationship) => [
40229
+ relationship.id,
40230
+ relationship
40231
+ ]
40232
+ )
40233
+ );
40234
+ const replacesOfficeDocument = relationshipPartPath === OPC_ROOT_RELATIONSHIPS_PATH && rebuilt.some(
40235
+ (relationship) => relationship.type.endsWith(OFFICE_DOCUMENT_RELATIONSHIP_SUFFIX)
40236
+ );
40237
+ for (const relationship of source) {
40238
+ if (replacesOfficeDocument && relationship.type.endsWith(OFFICE_DOCUMENT_RELATIONSHIP_SUFFIX)) {
40239
+ continue;
40240
+ }
40241
+ const rebuiltWithSameId = rebuiltById.get(relationship.id);
40242
+ if (rebuiltWithSameId) {
40243
+ if (relationshipKey(rebuiltWithSameId) === relationshipKey(relationship)) {
40244
+ continue;
40245
+ }
40246
+ throw new Error(
40247
+ `Cannot safely preserve ${relationshipPartPath}: relationship id ${relationship.id} is used by both the source package and rebuilt document for different targets.`
40248
+ );
40249
+ }
40250
+ result.push(relationship);
40251
+ }
40252
+ return result;
40253
+ }
40254
+ function mergeContentTypes(source, rebuiltXml) {
40255
+ const rebuilt = parseOpcContentTypes(rebuiltXml);
40256
+ return serializeOpcContentTypes({
40257
+ defaults: { ...source.defaults, ...rebuilt.defaults },
40258
+ overrides: { ...source.overrides, ...rebuilt.overrides }
40259
+ });
40260
+ }
40261
+ function writeSourcePart(zip, sourcePackage, path) {
40262
+ const part = sourcePackage.parts[path];
40263
+ if (!part) {
40264
+ return;
40265
+ }
40266
+ if (part.encoding === "base64") {
40267
+ zip.file(path, part.data, { base64: true });
40268
+ } else {
40269
+ zip.file(path, part.data);
40270
+ }
40271
+ }
40272
+ async function patchRebuiltDocxWithSourcePackage(document2, rebuiltBuffer) {
40273
+ const sourcePackage = document2.sourcePackage;
40274
+ if (!sourcePackage) {
40275
+ return rebuiltBuffer;
40276
+ }
40277
+ const output = new JSZip();
40278
+ for (const path of Object.keys(sourcePackage.parts)) {
40279
+ writeSourcePart(output, sourcePackage, path);
40280
+ }
40281
+ const rebuilt = await JSZip.loadAsync(rebuiltBuffer);
40282
+ let rebuiltContentTypesXml = null;
40283
+ for (const [rawPath, entry] of Object.entries(rebuilt.files)) {
40284
+ if (entry.dir) {
40285
+ continue;
40286
+ }
40287
+ const path = normalizeOpcPartPath(rawPath);
40288
+ if (path === OPC_CONTENT_TYPES_PATH) {
40289
+ rebuiltContentTypesXml = await entry.async("string");
40290
+ continue;
40291
+ }
40292
+ if (path.endsWith(".rels")) {
40293
+ const rebuiltRelationshipsXml = await entry.async("string");
40294
+ const sourcePart = sourcePackage.parts[path];
40295
+ const mergedRelationships = mergeRelationships(
40296
+ (sourcePart == null ? void 0 : sourcePart.kind) === "xml" ? parseOpcRelationships(sourcePart.data) : [],
40297
+ parseOpcRelationships(rebuiltRelationshipsXml),
40298
+ path
40299
+ );
40300
+ output.file(path, serializeOpcRelationships(mergedRelationships));
40301
+ continue;
40302
+ }
40303
+ output.file(path, await entry.async("uint8array"));
40304
+ }
40305
+ if (rebuiltContentTypesXml) {
40306
+ output.file(
40307
+ OPC_CONTENT_TYPES_PATH,
40308
+ mergeContentTypes(sourcePackage.contentTypes, rebuiltContentTypesXml)
40309
+ );
40310
+ }
40311
+ return output.generateAsync({ type: "arraybuffer" });
40312
+ }
40313
+ async function exportEditorDocumentToDocxPreservingSource(document2) {
40314
+ if (!document2.sourcePackage) {
40315
+ return exportEditorDocumentToDocx(document2);
40316
+ }
40317
+ const rebuilt = await exportEditorDocumentToDocx(document2);
40318
+ return patchRebuiltDocxWithSourcePackage(document2, rebuilt);
40319
+ }
40320
+ async function exportEditorDocumentToDocxBlobPreservingSource(document2) {
40321
+ if (!document2.sourcePackage) {
40322
+ return exportEditorDocumentToDocxBlob(document2);
40323
+ }
40324
+ const buffer = await exportEditorDocumentToDocxPreservingSource(document2);
40325
+ return new Blob([buffer], {
40326
+ type: "application/vnd.openxmlformats-officedocument.wordprocessingml.document"
40327
+ });
40328
+ }
39588
40329
  function borderDashArray(type) {
39589
40330
  switch (type) {
39590
40331
  case "dashed":
@@ -43914,7 +44655,9 @@ function downloadBlob(blob, filename) {
43914
44655
  function createDocumentExporter(deps) {
43915
44656
  const download = deps.download ?? downloadBlob;
43916
44657
  const handleExportDocx = async () => {
43917
- const blob = await exportEditorDocumentToDocxBlob(deps.document());
44658
+ const blob = await exportEditorDocumentToDocxBlobPreservingSource(
44659
+ deps.document()
44660
+ );
43918
44661
  download(blob, "oasis-editor.docx");
43919
44662
  deps.focusInput();
43920
44663
  return blob;
@@ -43925,7 +44668,7 @@ function createDocumentExporter(deps) {
43925
44668
  deps.focusInput();
43926
44669
  return blob;
43927
44670
  };
43928
- const exportDocxBlob = () => exportEditorDocumentToDocxBlob(deps.document());
44671
+ const exportDocxBlob = () => exportEditorDocumentToDocxBlobPreservingSource(deps.document());
43929
44672
  const exportPdfBlob = () => exportEditorDocumentToPdfBlob(deps.document());
43930
44673
  return {
43931
44674
  handleExportDocx,