oasis-editor 0.0.81 → 0.0.83

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,21 +1,148 @@
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 { a as assertNever, c as createSignal, b as createEditorStateFromDocument, d as createInitialEditorState, S as STANDARD_FONT_SIZES_PT, f as fontSizePxToPt, p as probeLocalFontFamilies, e as createEditorParagraphFromRuns, i as isInlineObjectRun, g as createEditorStyledRun, h as getParagraphLength, j as getParagraphText, k as getActiveZone, l as getDocumentSections, m as getActiveSectionIndex, n as getParagraphs, o as normalizeSelection, q as positionToParagraphOffset, r as paragraphOffsetToPosition, s as clampPosition, t as findParagraphIndex, u as createCollapsedSelection, v as isSelectionCollapsed, w as parseFontSizePtToPx, x as formatFontSizePt, y as createEditorParagraph, z as getBlockParagraphs, A as findParagraphTableLocation, B as buildTableCellLayout, P as PT_PER_PX, C as createEditorTableCell, D as createEditorTableRow, E as createEditorTable, F as underlineStyleToCssDecorationStyle, G as resolveImageSrc, H as listKindForTag, I as isParagraphTag, J as collectInlineRuns, K as parseParagraphStyle, L as InlineShell, M as BalloonShell, N as DocumentShell, O as createMemo, Q as buildCanvasLayoutSnapshot, R as getCaretRectFromSnapshot, T as getParagraphRectFromSnapshot, U as createComponent, V as CaretOverlay, W as Show, X as createRenderEffect, Y as style, Z as setAttribute, _ as setStyleProperty, $ as memo, a0 as template, a1 as useI18n, a2 as createEffect, a3 as insert, a4 as use, a5 as addEventListener, a6 as Dialog, a7 as delegateEvents, a8 as className, a9 as For, aa as UNDERLINE_STYLE_OPTIONS, ab as Tabs, ac as onMount, ad as onCleanup, ae as PluginUiHost, af as OasisEditorEditor, ag as OasisBrandMark, ah as setPreciseFontPreference, ai as setWelcomeSeen, aj as enablePreciseFontMode, ak as TWIPS_PER_POINT, al as PX_PER_INCH, am as TWIPS_PER_INCH, an as resolveEffectiveParagraphStyle, ao as resolveEffectiveTextStyleForParagraph, ap as EMU_PER_PX, aq as EMU_PER_PT, ar as iterateFootnoteReferenceRuns, as as iterateEndnoteReferenceRuns, at as imageContentTypeDefaults, au as createEditorRun, av as JSZip, aw as imageExtensionFromMime, ax as pxToPt$1, ay as resolveFloatingObjectRect, az as getTextBoxFloatingGeometry, aA as getPresetPathSegments, aB as projectBlocksLayout, aC as buildListLabels, aD as textStyleToFontSizePt, aE as PX_PER_POINT, aF as DEFAULT_FONT_SIZE_PX, aG as isDoubleUnderlineStyle, aH as isWavyUnderlineStyle, aI as underlineStyleLineWidthPx, aJ as underlineStyleDashArray, aK as resolveListLabel, aL as getListLabelInset, aM as getAlignedListLabelInset, aN as getParagraphBorderInsets, aO as buildSegmentTable, aP as buildCanvasTableLayout, aQ as normalizeFamily, aR as ROBOTO_FONT_FILES, aS as loadFontAsset, aT as OFFICE_COMPAT_FONT_FAMILIES, aU as buildSfnt, aV as defaultFontDecoderRegistry, aW as SfntFontProgram, aX as collectPdfFontFamilies, aY as projectDocumentLayout, aZ as getPageContentWidth, a_ as getPageHeaderZoneTop, a$ as getPageBodyTop, b0 as getPageColumnRects, b1 as findFootnoteReference, b2 as FOOTNOTE_MARKER_GUTTER_PX, b3 as resolveImporterForFile, b4 as getDocumentSectionsCanonical, b5 as getDocumentParagraphsCanonical, b6 as getDocumentParagraphs, b7 as getDocumentPageSettings, b8 as getTableCellContentWidthForParagraph, b9 as on, ba as debounce, bb as unwrap, bc as perfTimer, bd as createEditorDocument, be as resolveResizedDimensions, bf as resolveTextBoxRenderHeight, bg as getToolbarStyleState, bh as getCachedCanvasImage, bi as measureParagraphMinContentWidthPx, bj as getEditableBlocksForZone, bk as findParagraphLocation, bl as createSectionBoundaryParagraph, bm as normalizePageSettings, bn as DEFAULT_EDITOR_PAGE_SETTINGS, bo as markStart, bp as markEnd, bq as getParagraphEntries, br as getParagraphById, bs as createEditorFootnote, bt as createFootnoteReferenceRun, bu as renumberFootnotes, bv as getFootnoteDisplayMarker, bw as getHeadingLevel, bx as preciseFontModeVersion, by as isPreciseFontModeEnabled, bz as togglePreciseFontMode, bA as nextFontSizePt, bB as previousFontSizePt, bC as fontSizePtToPx, bD as createDefaultToolbarPreset, bE as MenuRegistry, bF as createToolbarRegistry, bG as Editor, bH as resolveCommandRef, bI as commandRefName, bJ as createOasisEditorClient, bK as createEditorZoom, bL as startLongTaskObserver, bM as installGlobalReport, bN as applyStoredPreciseFontPreference, bO as getWelcomeSeen, bP as isLocalFontAccessSupported, bQ as EDITOR_SCROLL_PADDING_PX, bR as Toolbar, bS as OasisEditorLoading, bT as I18nProvider, bU as createTranslator, bV as createEditorLogger, bW as registerDomStatsSurface } from "./index-E2fsy7yp.js";
4
+ import { v as visitRun, a as assertNever, c as createSignal, b as createEditorStateFromDocument, d as createInitialEditorState, S as STANDARD_FONT_SIZES_PT, f as fontSizePxToPt, p as probeLocalFontFamilies, e as createEditorParagraphFromRuns, i as isInlineObjectRun, g as createEditorStyledRun, h as getParagraphLength, j as getParagraphText, k as getActiveZone, l as getDocumentSections, m as getActiveSectionIndex, n as getParagraphs, o as normalizeSelection, q as positionToParagraphOffset, r as paragraphOffsetToPosition, s as clampPosition, t as findParagraphIndex, u as createCollapsedSelection, w as isSelectionCollapsed, x as parseFontSizePtToPx, y as formatFontSizePt, z as createEditorParagraph, A as getBlockParagraphs, B as findParagraphTableLocation, C as buildTableCellLayout, P as PT_PER_PX, D as createEditorTableCell, E as createEditorTableRow, F as createEditorTable, G as underlineStyleToCssDecorationStyle, H as resolveImageSrc, I as listKindForTag, J as isParagraphTag, K as collectInlineRuns, L as parseParagraphStyle, M as getRunImage, N as InlineShell, O as BalloonShell, Q as DocumentShell, R as createMemo, T as buildCanvasLayoutSnapshot, U as getCaretRectFromSnapshot, V as getParagraphRectFromSnapshot, W as createComponent, X as CaretOverlay, Y as Show, Z as createRenderEffect, _ as style, $ as setAttribute, a0 as setStyleProperty, a1 as memo, a2 as template, a3 as useI18n, a4 as createEffect, a5 as insert, a6 as use, a7 as addEventListener, a8 as Dialog, a9 as delegateEvents, aa as className, ab as For, ac as UNDERLINE_STYLE_OPTIONS, ad as Tabs, ae as onMount, af as onCleanup, ag as PluginUiHost, ah as OasisEditorEditor, ai as OasisBrandMark, aj as setPreciseFontPreference, ak as setWelcomeSeen, al as enablePreciseFontMode, am as TWIPS_PER_POINT, an as PX_PER_INCH, ao as TWIPS_PER_INCH, ap as resolveEffectiveParagraphStyle, aq as resolveEffectiveTextStyleForParagraph, ar as EMU_PER_PX, as as EMU_PER_PT, at as getRunFootnoteReference, au as getRunEndnoteReference, av as iterateFootnoteReferenceRuns, aw as iterateEndnoteReferenceRuns, ax as imageContentTypeDefaults, ay as getRunFieldChar, az as getRunFieldInstruction, aA as createEditorRun, aB as JSZip, aC as imageExtensionFromMime, aD as pxToPt$1, aE as resolveFloatingObjectRect, aF as getTextBoxFloatingGeometry, aG as getPresetPathSegments, aH as projectBlocksLayout, aI as buildListLabels, aJ as textStyleToFontSizePt, aK as PX_PER_POINT, aL as DEFAULT_FONT_SIZE_PX, aM as isDoubleUnderlineStyle, aN as isWavyUnderlineStyle, aO as underlineStyleLineWidthPx, aP as underlineStyleDashArray, aQ as resolveListLabel, aR as getListLabelInset, aS as getAlignedListLabelInset, aT as getParagraphBorderInsets, aU as buildSegmentTable, aV as buildCanvasTableLayout, aW as normalizeFamily, aX as ROBOTO_FONT_FILES, aY as loadFontAsset, aZ as OFFICE_COMPAT_FONT_FAMILIES, a_ as buildSfnt, a$ as defaultFontDecoderRegistry, b0 as SfntFontProgram, b1 as collectPdfFontFamilies, b2 as projectDocumentLayout, b3 as getPageContentWidth, b4 as getPageHeaderZoneTop, b5 as getPageBodyTop, b6 as getPageColumnRects, b7 as findFootnoteReference, b8 as FOOTNOTE_MARKER_GUTTER_PX, b9 as resolveImporterForFile, ba as getDocumentSectionsCanonical, bb as getDocumentParagraphsCanonical, bc as getDocumentParagraphs, bd as getDocumentPageSettings, be as getTableCellContentWidthForParagraph, bf as on, bg as debounce, bh as unwrap, bi as perfTimer, bj as getRunTextBox, bk as createEditorDocument, bl as resolveResizedDimensions, bm as resolveTextBoxRenderHeight, bn as getToolbarStyleState, bo as getCachedCanvasImage, bp as measureParagraphMinContentWidthPx, bq as getEditableBlocksForZone, br as findParagraphLocation, bs as createSectionBoundaryParagraph, bt as normalizePageSettings, bu as DEFAULT_EDITOR_PAGE_SETTINGS, bv as markStart, bw as markEnd, bx as getParagraphEntries, by as getParagraphById, bz as createEditorFootnote, bA as createFootnoteReferenceRun, bB as renumberFootnotes, bC as getFootnoteDisplayMarker, bD as getHeadingLevel, bE as preciseFontModeVersion, bF as isPreciseFontModeEnabled, bG as togglePreciseFontMode, bH as nextFontSizePt, bI as previousFontSizePt, bJ as fontSizePtToPx, bK as createDefaultToolbarPreset, bL as MenuRegistry, bM as createToolbarRegistry, bN as Editor, bO as resolveCommandRef, bP as commandRefName, bQ as createOasisEditorClient, bR as createEditorZoom, bS as startLongTaskObserver, bT as installGlobalReport, bU as applyStoredPreciseFontPreference, bV as getWelcomeSeen, bW as isLocalFontAccessSupported, bX as EDITOR_SCROLL_PADDING_PX, bY as Toolbar, bZ as OasisEditorLoading, b_ as I18nProvider, b$ as createTranslator, c0 as createEditorLogger, c1 as registerDomStatsSurface } from "./index-CF99ClZS.js";
5
+ function cloneStyle(style2) {
6
+ return style2 ? { ...style2 } : void 0;
7
+ }
8
+ function stylesEqual(left, right) {
9
+ return JSON.stringify(left ?? null) === JSON.stringify(right ?? null);
10
+ }
11
+ function setBooleanStyle(style2, key, enabled) {
12
+ const next = { ...style2 ?? {} };
13
+ if (enabled) {
14
+ next[key] = true;
15
+ } else {
16
+ delete next[key];
17
+ }
18
+ return Object.keys(next).length > 0 ? next : void 0;
19
+ }
20
+ function setValueStyle(style2, key, value) {
21
+ const next = { ...style2 ?? {} };
22
+ if (value === null || value === void 0 || value === "") {
23
+ delete next[key];
24
+ } else {
25
+ next[key] = value;
26
+ }
27
+ return Object.keys(next).length > 0 ? next : void 0;
28
+ }
29
+ function setParagraphStyleValue(style2, key, value) {
30
+ const next = { ...style2 ?? {} };
31
+ if (value === null || value === void 0) {
32
+ delete next[key];
33
+ } else {
34
+ next[key] = value;
35
+ }
36
+ return Object.keys(next).length > 0 ? next : void 0;
37
+ }
38
+ function cloneTextBox(textBox) {
39
+ return {
40
+ ...textBox,
41
+ floating: textBox.floating ? {
42
+ ...textBox.floating,
43
+ positionH: textBox.floating.positionH ? { ...textBox.floating.positionH } : void 0,
44
+ positionV: textBox.floating.positionV ? { ...textBox.floating.positionV } : void 0
45
+ } : void 0,
46
+ shape: textBox.shape ? { ...textBox.shape } : void 0,
47
+ body: textBox.body ? { ...textBox.body } : void 0,
48
+ blocks: cloneBlocks(textBox.blocks)
49
+ };
50
+ }
51
+ function cloneRun(run) {
52
+ const base = {
53
+ id: run.id,
54
+ text: run.text,
55
+ styles: cloneStyle(run.styles),
56
+ revision: run.revision ? { ...run.revision } : void 0
57
+ };
58
+ return visitRun(run, {
59
+ text: () => ({ ...base, kind: "text" }),
60
+ image: (r) => ({ ...base, kind: "image", image: { ...r.image } }),
61
+ textBox: (r) => ({
62
+ ...base,
63
+ kind: "textBox",
64
+ textBox: cloneTextBox(r.textBox)
65
+ }),
66
+ field: (r) => ({ ...base, kind: "field", field: { ...r.field } }),
67
+ fieldChar: (r) => ({
68
+ ...base,
69
+ kind: "fieldChar",
70
+ fieldChar: { ...r.fieldChar }
71
+ }),
72
+ fieldInstruction: (r) => ({
73
+ ...base,
74
+ kind: "fieldInstruction",
75
+ fieldInstruction: r.fieldInstruction
76
+ }),
77
+ footnoteReference: (r) => ({
78
+ ...base,
79
+ kind: "footnoteReference",
80
+ footnoteReference: { ...r.footnoteReference }
81
+ }),
82
+ endnoteReference: (r) => ({
83
+ ...base,
84
+ kind: "endnoteReference",
85
+ endnoteReference: { ...r.endnoteReference }
86
+ }),
87
+ sym: (r) => ({ ...base, kind: "sym", sym: { ...r.sym } })
88
+ });
89
+ }
90
+ function cloneParagraph(paragraph) {
91
+ return {
92
+ ...paragraph,
93
+ runs: paragraph.runs.map(cloneRun),
94
+ style: paragraph.style ? { ...paragraph.style } : void 0,
95
+ list: paragraph.list ? { ...paragraph.list } : void 0
96
+ };
97
+ }
98
+ function cloneParagraphList(list) {
99
+ return list ? { ...list } : void 0;
100
+ }
101
+ function cloneParagraphs(paragraphs) {
102
+ return paragraphs.map(cloneParagraph);
103
+ }
104
+ function cloneBlocks(blocks) {
105
+ return blocks.map((block) => {
106
+ switch (block.type) {
107
+ case "paragraph":
108
+ return cloneParagraph(block);
109
+ case "table":
110
+ return {
111
+ ...block,
112
+ style: block.style ? {
113
+ ...block.style,
114
+ defaultCellMargins: block.style.defaultCellMargins ? { ...block.style.defaultCellMargins } : void 0,
115
+ floating: block.style.floating ? { ...block.style.floating } : void 0,
116
+ revisionXml: block.style.revisionXml ? [...block.style.revisionXml] : void 0
117
+ } : void 0,
118
+ tblGridChangeXml: block.tblGridChangeXml,
119
+ rows: block.rows.map((row) => ({
120
+ ...row,
121
+ style: row.style ? {
122
+ ...row.style,
123
+ revisionXml: row.style.revisionXml ? [...row.style.revisionXml] : void 0
124
+ } : void 0,
125
+ cells: row.cells.map((cell) => ({
126
+ ...cell,
127
+ style: cell.style ? {
128
+ ...cell.style,
129
+ revisionXml: cell.style.revisionXml ? [...cell.style.revisionXml] : void 0
130
+ } : void 0,
131
+ blocks: cloneParagraphs(cell.blocks)
132
+ }))
133
+ }))
134
+ };
135
+ default:
136
+ return assertNever(block, "block");
137
+ }
138
+ });
139
+ }
5
140
  function cloneBlock(block) {
6
141
  switch (block.type) {
7
142
  case "paragraph":
8
143
  return {
9
144
  ...block,
10
- runs: block.runs.map((run) => ({
11
- ...run,
12
- styles: run.styles ? { ...run.styles } : void 0,
13
- image: run.image ? { ...run.image } : void 0,
14
- field: run.field ? { ...run.field } : void 0,
15
- revision: run.revision ? { ...run.revision } : void 0,
16
- footnoteReference: run.footnoteReference ? { ...run.footnoteReference } : void 0,
17
- endnoteReference: run.endnoteReference ? { ...run.endnoteReference } : void 0
18
- })),
145
+ runs: block.runs.map(cloneRun),
19
146
  style: block.style ? { ...block.style } : void 0,
20
147
  list: block.list ? { ...block.list } : void 0
21
148
  };
@@ -46,15 +173,7 @@ function cloneBlock(block) {
46
173
  } : void 0,
47
174
  blocks: cell.blocks.map((paragraph) => ({
48
175
  ...paragraph,
49
- runs: paragraph.runs.map((run) => ({
50
- ...run,
51
- styles: run.styles ? { ...run.styles } : void 0,
52
- image: run.image ? { ...run.image } : void 0,
53
- field: run.field ? { ...run.field } : void 0,
54
- revision: run.revision ? { ...run.revision } : void 0,
55
- footnoteReference: run.footnoteReference ? { ...run.footnoteReference } : void 0,
56
- endnoteReference: run.endnoteReference ? { ...run.endnoteReference } : void 0
57
- })),
176
+ runs: paragraph.runs.map(cloneRun),
58
177
  style: paragraph.style ? { ...paragraph.style } : void 0,
59
178
  list: paragraph.list ? { ...paragraph.list } : void 0
60
179
  }))
@@ -26643,115 +26762,6 @@ function createEditorFontOptions(ctx) {
26643
26762
  loadLocalFontFamilyOptions
26644
26763
  };
26645
26764
  }
26646
- function cloneStyle(style2) {
26647
- return style2 ? { ...style2 } : void 0;
26648
- }
26649
- function stylesEqual(left, right) {
26650
- return JSON.stringify(left ?? null) === JSON.stringify(right ?? null);
26651
- }
26652
- function setBooleanStyle(style2, key, enabled) {
26653
- const next = { ...style2 ?? {} };
26654
- if (enabled) {
26655
- next[key] = true;
26656
- } else {
26657
- delete next[key];
26658
- }
26659
- return Object.keys(next).length > 0 ? next : void 0;
26660
- }
26661
- function setValueStyle(style2, key, value) {
26662
- const next = { ...style2 ?? {} };
26663
- if (value === null || value === void 0 || value === "") {
26664
- delete next[key];
26665
- } else {
26666
- next[key] = value;
26667
- }
26668
- return Object.keys(next).length > 0 ? next : void 0;
26669
- }
26670
- function setParagraphStyleValue(style2, key, value) {
26671
- const next = { ...style2 ?? {} };
26672
- if (value === null || value === void 0) {
26673
- delete next[key];
26674
- } else {
26675
- next[key] = value;
26676
- }
26677
- return Object.keys(next).length > 0 ? next : void 0;
26678
- }
26679
- function cloneTextBox(textBox) {
26680
- return {
26681
- ...textBox,
26682
- floating: textBox.floating ? {
26683
- ...textBox.floating,
26684
- positionH: textBox.floating.positionH ? { ...textBox.floating.positionH } : void 0,
26685
- positionV: textBox.floating.positionV ? { ...textBox.floating.positionV } : void 0
26686
- } : void 0,
26687
- shape: textBox.shape ? { ...textBox.shape } : void 0,
26688
- body: textBox.body ? { ...textBox.body } : void 0,
26689
- blocks: cloneBlocks(textBox.blocks)
26690
- };
26691
- }
26692
- function cloneRun(run) {
26693
- return {
26694
- ...run,
26695
- styles: cloneStyle(run.styles),
26696
- image: run.image ? { ...run.image } : void 0,
26697
- textBox: run.textBox ? cloneTextBox(run.textBox) : void 0,
26698
- field: run.field ? { ...run.field } : void 0,
26699
- fieldChar: run.fieldChar ? { ...run.fieldChar } : void 0,
26700
- revision: run.revision ? { ...run.revision } : void 0,
26701
- footnoteReference: run.footnoteReference ? { ...run.footnoteReference } : void 0,
26702
- endnoteReference: run.endnoteReference ? { ...run.endnoteReference } : void 0
26703
- };
26704
- }
26705
- function cloneParagraph(paragraph) {
26706
- return {
26707
- ...paragraph,
26708
- runs: paragraph.runs.map(cloneRun),
26709
- style: paragraph.style ? { ...paragraph.style } : void 0,
26710
- list: paragraph.list ? { ...paragraph.list } : void 0
26711
- };
26712
- }
26713
- function cloneParagraphList(list) {
26714
- return list ? { ...list } : void 0;
26715
- }
26716
- function cloneParagraphs(paragraphs) {
26717
- return paragraphs.map(cloneParagraph);
26718
- }
26719
- function cloneBlocks(blocks) {
26720
- return blocks.map((block) => {
26721
- switch (block.type) {
26722
- case "paragraph":
26723
- return cloneParagraph(block);
26724
- case "table":
26725
- return {
26726
- ...block,
26727
- style: block.style ? {
26728
- ...block.style,
26729
- defaultCellMargins: block.style.defaultCellMargins ? { ...block.style.defaultCellMargins } : void 0,
26730
- floating: block.style.floating ? { ...block.style.floating } : void 0,
26731
- revisionXml: block.style.revisionXml ? [...block.style.revisionXml] : void 0
26732
- } : void 0,
26733
- tblGridChangeXml: block.tblGridChangeXml,
26734
- rows: block.rows.map((row) => ({
26735
- ...row,
26736
- style: row.style ? {
26737
- ...row.style,
26738
- revisionXml: row.style.revisionXml ? [...row.style.revisionXml] : void 0
26739
- } : void 0,
26740
- cells: row.cells.map((cell) => ({
26741
- ...cell,
26742
- style: cell.style ? {
26743
- ...cell.style,
26744
- revisionXml: cell.style.revisionXml ? [...cell.style.revisionXml] : void 0
26745
- } : void 0,
26746
- blocks: cloneParagraphs(cell.blocks)
26747
- }))
26748
- }))
26749
- };
26750
- default:
26751
- return assertNever(block, "block");
26752
- }
26753
- });
26754
- }
26755
26765
  function normalizeRuns(runs, fallbackStyles) {
26756
26766
  const merged = [];
26757
26767
  for (const run of runs) {
@@ -26859,7 +26869,7 @@ function expandLinkRangeInParagraph(paragraph, offset) {
26859
26869
  var _a, _b, _c;
26860
26870
  const resolved = getRunAtOffset(paragraph, offset);
26861
26871
  const href = (_a = resolved == null ? void 0 : resolved.run.styles) == null ? void 0 : _a.link;
26862
- if (!resolved || !href || resolved.run.image) {
26872
+ if (!resolved || !href || resolved.run.kind === "image") {
26863
26873
  return null;
26864
26874
  }
26865
26875
  let startOffset = resolved.startOffset;
@@ -26877,14 +26887,14 @@ function expandLinkRangeInParagraph(paragraph, offset) {
26877
26887
  endOffset = consumed + resolved.run.text.length;
26878
26888
  for (let index = runIndex - 1; index >= 0; index -= 1) {
26879
26889
  const run = runs[index];
26880
- if (run.image || ((_b = run.styles) == null ? void 0 : _b.link) !== href) {
26890
+ if (run.kind === "image" || ((_b = run.styles) == null ? void 0 : _b.link) !== href) {
26881
26891
  break;
26882
26892
  }
26883
26893
  startOffset -= run.text.length;
26884
26894
  }
26885
26895
  for (let index = runIndex + 1; index < runs.length; index += 1) {
26886
26896
  const run = runs[index];
26887
- if (run.image || ((_c = run.styles) == null ? void 0 : _c.link) !== href) {
26897
+ if (run.kind === "image" || ((_c = run.styles) == null ? void 0 : _c.link) !== href) {
26888
26898
  break;
26889
26899
  }
26890
26900
  endOffset += run.text.length;
@@ -26908,31 +26918,13 @@ function sliceRuns(paragraph, startOffset, endOffset) {
26908
26918
  const overlapStart = Math.max(start, runStart);
26909
26919
  const overlapEnd = Math.min(end, runEnd);
26910
26920
  if (overlapStart < overlapEnd) {
26911
- const isObjectRun = isInlineObjectRun(run);
26912
- const piece = {
26913
- id: `run:${Math.random().toString(36).slice(2, 9)}`,
26914
- text: isObjectRun ? "" : run.text.slice(overlapStart - runStart, overlapEnd - runStart)
26915
- };
26916
- if (run.styles) {
26917
- piece.styles = { ...run.styles };
26918
- }
26919
- if (run.image) {
26920
- piece.image = { ...run.image };
26921
- }
26922
- if (run.textBox) {
26923
- piece.textBox = cloneTextBox(run.textBox);
26924
- }
26925
- if (run.revision) {
26926
- piece.revision = { ...run.revision };
26927
- }
26928
- if (run.field) {
26929
- piece.field = { ...run.field };
26930
- }
26931
- if (run.footnoteReference) {
26932
- piece.footnoteReference = { ...run.footnoteReference };
26933
- }
26934
- if (run.endnoteReference) {
26935
- piece.endnoteReference = { ...run.endnoteReference };
26921
+ const piece = cloneRun(run);
26922
+ piece.id = `run:${Math.random().toString(36).slice(2, 9)}`;
26923
+ if (!isInlineObjectRun(run)) {
26924
+ piece.text = run.text.slice(
26925
+ overlapStart - runStart,
26926
+ overlapEnd - runStart
26927
+ );
26936
26928
  }
26937
26929
  pieces.push(piece);
26938
26930
  }
@@ -27503,7 +27495,8 @@ function insertTextAtSelection(state, text, styleOverride) {
27503
27495
  const insertedRun = {
27504
27496
  id: `run:${Math.random().toString(36).slice(2, 9)}`,
27505
27497
  text,
27506
- styles
27498
+ styles,
27499
+ kind: "text"
27507
27500
  };
27508
27501
  if (collapsedState.trackChangesEnabled) {
27509
27502
  insertedRun.revision = {
@@ -27611,6 +27604,7 @@ function deleteBackward(state) {
27611
27604
  const deletionRun = {
27612
27605
  id: `run:${Math.random().toString(36).slice(2, 9)}`,
27613
27606
  text: charToDelete,
27607
+ kind: "text",
27614
27608
  styles: { ...targetRun.styles },
27615
27609
  revision: {
27616
27610
  id: `rev:${Math.random().toString(36).slice(2, 9)}`,
@@ -27719,6 +27713,7 @@ function deleteForward(state) {
27719
27713
  const deletionRun = {
27720
27714
  id: `run:${Math.random().toString(36).slice(2, 9)}`,
27721
27715
  text: charToDelete,
27716
+ kind: "text",
27722
27717
  styles: { ...targetRun.styles },
27723
27718
  revision: {
27724
27719
  id: `rev:${Math.random().toString(36).slice(2, 9)}`,
@@ -29406,7 +29401,7 @@ function textLanguageToHtmlAttributes(language) {
29406
29401
  }
29407
29402
  function serializeImageRunToHtml(run, document2) {
29408
29403
  var _a;
29409
- if (!run.image) {
29404
+ if (run.kind !== "image") {
29410
29405
  return "";
29411
29406
  }
29412
29407
  const resolvedSrc = resolveImageSrc(document2, run.image.src);
@@ -29418,7 +29413,7 @@ function serializeImageRunToHtml(run, document2) {
29418
29413
  return img;
29419
29414
  }
29420
29415
  function serializeTextRunToHtml(run, document2) {
29421
- if (run.image) {
29416
+ if (run.kind === "image") {
29422
29417
  return serializeImageRunToHtml(run, document2);
29423
29418
  }
29424
29419
  const text = escapeHtml(run.text).replace(/\n/g, "<br>");
@@ -29786,11 +29781,14 @@ function parseEditorClipboardHtmlWithDom(html) {
29786
29781
  const appendParagraph = (element, runs, list) => {
29787
29782
  const fallbackRuns = runs.length > 0 ? runs : [createEditorStyledRun("")];
29788
29783
  paragraphs.push({
29789
- runs: fallbackRuns.map((run) => ({
29790
- text: run.text,
29791
- styles: cloneStyle(run.styles),
29792
- image: run.image ? { ...run.image } : void 0
29793
- })),
29784
+ runs: fallbackRuns.map((run) => {
29785
+ const image = getRunImage(run);
29786
+ return {
29787
+ text: run.text,
29788
+ styles: cloneStyle(run.styles),
29789
+ image: image ? { ...image } : void 0
29790
+ };
29791
+ }),
29794
29792
  style: element ? parseParagraphStyle(element) : void 0,
29795
29793
  list
29796
29794
  });
@@ -33086,7 +33084,7 @@ function serializeTableXml(table, serializeParagraphXml2) {
33086
33084
  {
33087
33085
  id: "",
33088
33086
  type: "paragraph",
33089
- runs: [{ id: "", text: "" }]
33087
+ runs: [{ id: "", text: "", kind: "text" }]
33090
33088
  }
33091
33089
  ];
33092
33090
  const paragraphsXml = paragraphs.map((paragraph) => serializeParagraphXml2(paragraph, cell)).join("");
@@ -33817,7 +33815,7 @@ function serializeFootnoteRefMarker() {
33817
33815
  return serializeNoteRefMarker("footnote");
33818
33816
  }
33819
33817
  function serializeFootnoteReference(run, materializedRunStyle, context) {
33820
- const ref = run.footnoteReference;
33818
+ const ref = getRunFootnoteReference(run);
33821
33819
  return serializeNoteReference(
33822
33820
  "footnote",
33823
33821
  ref ? { noteId: ref.footnoteId, customMark: ref.customMark } : void 0,
@@ -33829,7 +33827,7 @@ function serializeEndnoteRefMarker() {
33829
33827
  return serializeNoteRefMarker("endnote");
33830
33828
  }
33831
33829
  function serializeEndnoteReference(run, materializedRunStyle, context) {
33832
- const ref = run.endnoteReference;
33830
+ const ref = getRunEndnoteReference(run);
33833
33831
  return serializeNoteReference(
33834
33832
  "endnote",
33835
33833
  ref ? { noteId: ref.endnoteId, customMark: ref.customMark } : void 0,
@@ -33859,73 +33857,35 @@ function serializeRun(run, context, paragraphStyleId, styles, serializeBlocksXml
33859
33857
  paragraphStyleId,
33860
33858
  styles
33861
33859
  );
33862
- if (run.footnoteReference) {
33863
- const result = serializeFootnoteReference(
33864
- run,
33865
- materializedRunStyle,
33866
- context
33867
- );
33868
- if (result !== null) {
33869
- return result;
33870
- }
33871
- }
33872
- if (run.endnoteReference) {
33873
- const result = serializeEndnoteReference(
33874
- run,
33875
- materializedRunStyle,
33876
- context
33877
- );
33878
- if (result !== null) {
33879
- return result;
33880
- }
33881
- }
33882
- if (run.fieldChar) {
33883
- return serializeFieldCharRun(
33884
- run.fieldChar,
33885
- serializeRunProperties(materializedRunStyle)
33886
- );
33887
- }
33888
- if (run.fieldInstruction !== void 0) {
33889
- return serializeInstrTextRun(
33890
- run.fieldInstruction,
33891
- serializeRunProperties(materializedRunStyle)
33892
- );
33893
- }
33894
- if (run.field) {
33895
- return serializeFieldRun(
33896
- run.field.type,
33897
- serializeRunProperties(materializedRunStyle)
33898
- );
33899
- }
33900
- if (run.textBox) {
33901
- return serializeTextBoxRun(
33902
- run,
33903
- run.textBox,
33860
+ const runProps = () => serializeRunProperties(materializedRunStyle);
33861
+ const asText = () => `<w:r>${runProps()}${serializeRunText(run.text)}</w:r>`;
33862
+ return visitRun(run, {
33863
+ footnoteReference: (r) => serializeFootnoteReference(r, materializedRunStyle, context) ?? asText(),
33864
+ endnoteReference: (r) => serializeEndnoteReference(r, materializedRunStyle, context) ?? asText(),
33865
+ fieldChar: (r) => serializeFieldCharRun(r.fieldChar, runProps()),
33866
+ fieldInstruction: (r) => serializeInstrTextRun(r.fieldInstruction, runProps()),
33867
+ field: (r) => serializeFieldRun(r.field.type, runProps()),
33868
+ textBox: (r) => serializeTextBoxRun(
33869
+ r,
33870
+ r.textBox,
33904
33871
  context,
33905
33872
  styles,
33906
- serializeRunProperties(materializedRunStyle),
33873
+ runProps(),
33907
33874
  serializeBlocksXml2
33908
- );
33909
- }
33910
- if (run.image) {
33911
- const rId = context.imageMap.get(run.id);
33912
- if (rId) {
33913
- const result = serializeImageRun(
33914
- run.id,
33915
- rId,
33916
- context,
33917
- serializeRunProperties(materializedRunStyle)
33918
- );
33919
- if (result !== null) {
33920
- return result;
33875
+ ),
33876
+ image: (r) => {
33877
+ const rId = context.imageMap.get(r.id);
33878
+ if (rId) {
33879
+ const result = serializeImageRun(r.id, rId, context, runProps());
33880
+ if (result !== null) {
33881
+ return result;
33882
+ }
33921
33883
  }
33922
- }
33923
- }
33924
- if (run.sym) {
33925
- const { font, char } = run.sym;
33926
- return `<w:r>${serializeRunProperties(materializedRunStyle)}<w:sym w:font="${escapeXml(font)}" w:char="${char}"/></w:r>`;
33927
- }
33928
- return `<w:r>${serializeRunProperties(materializedRunStyle)}${serializeRunText(run.text)}</w:r>`;
33884
+ return asText();
33885
+ },
33886
+ sym: (r) => `<w:r>${runProps()}<w:sym w:font="${escapeXml(r.sym.font)}" w:char="${r.sym.char}"/></w:r>`,
33887
+ text: () => asText()
33888
+ });
33929
33889
  }
33930
33890
  function serializeRunWithRelationships(run, context, paragraphStyleId, styles, serializeBlocksXml2) {
33931
33891
  var _a;
@@ -33952,7 +33912,7 @@ function stripRpr(rPr) {
33952
33912
  return rPr.replace(/^<w:rPr>/, "").replace(/<\/w:rPr>$/, "");
33953
33913
  }
33954
33914
  function isSplittableTextRun(run) {
33955
- return !run.image && !run.textBox && !run.field && !run.fieldChar && run.fieldInstruction === void 0 && !run.footnoteReference && !run.endnoteReference;
33915
+ return run.kind === "text" || run.kind === "sym";
33956
33916
  }
33957
33917
  function serializeRunsWithBoundaries(runs, tokens, context, paragraphStyleId, styles) {
33958
33918
  const sorted = [...tokens].sort(
@@ -34039,7 +33999,7 @@ function serializeBlocksXml(blocks, context, styles) {
34039
33999
  }
34040
34000
  function serializeParagraphXml(paragraph, context, styles, overrides) {
34041
34001
  var _a, _b, _c;
34042
- const runs = paragraph.runs.length > 0 ? paragraph.runs : [{ id: "", text: "" }];
34002
+ const runs = paragraph.runs.length > 0 ? paragraph.runs : [{ id: "", text: "", kind: "text" }];
34043
34003
  const dropCapFrame = paragraph.dropCap ? serializeDropCapFrameParagraph(paragraph.dropCap) : "";
34044
34004
  const bookmarkEvents = (_a = context.bookmarkEventsByParagraph) == null ? void 0 : _a.get(paragraph.id);
34045
34005
  const commentEvents = (_b = context.commentEventsByParagraph) == null ? void 0 : _b.get(paragraph.id);
@@ -34088,7 +34048,7 @@ function collectReferencedFootnotesForExport(document2) {
34088
34048
  const seen = /* @__PURE__ */ new Map();
34089
34049
  let nextDocxId = FIRST_FOOTNOTE_DOCX_ID;
34090
34050
  for (const { run } of iterateFootnoteReferenceRuns(document2)) {
34091
- const ref = run.footnoteReference;
34051
+ const ref = getRunFootnoteReference(run);
34092
34052
  if (!ref) continue;
34093
34053
  if (seen.has(ref.footnoteId)) continue;
34094
34054
  const footnote = items[ref.footnoteId];
@@ -34125,7 +34085,7 @@ function createEmptyFootnoteBodyParagraph(withMarker = true) {
34125
34085
  type: "paragraph",
34126
34086
  runs: [
34127
34087
  ...withMarker ? [makeFootnoteRefMarkerRun()] : [],
34128
- { id: "synthetic:footnote-body-empty-text", text: "" }
34088
+ { id: "synthetic:footnote-body-empty-text", text: "", kind: "text" }
34129
34089
  ],
34130
34090
  style: { styleId: "FootnoteText" }
34131
34091
  };
@@ -34142,6 +34102,7 @@ function makeFootnoteRefMarkerRun() {
34142
34102
  return {
34143
34103
  id: "synthetic:footnoteRef",
34144
34104
  text: "",
34105
+ kind: "text",
34145
34106
  styles: { styleId: "FootnoteReference", superscript: true },
34146
34107
  // Tag the run so the special serializer below can intercept it.
34147
34108
  __isFootnoteRefMarker: true
@@ -34183,7 +34144,7 @@ function collectReferencedEndnotesForExport(document2) {
34183
34144
  const seen = /* @__PURE__ */ new Map();
34184
34145
  let nextDocxId = FIRST_ENDNOTE_DOCX_ID;
34185
34146
  for (const { run } of iterateEndnoteReferenceRuns(document2)) {
34186
- const ref = run.endnoteReference;
34147
+ const ref = getRunEndnoteReference(run);
34187
34148
  if (!ref) continue;
34188
34149
  if (seen.has(ref.endnoteId)) continue;
34189
34150
  const endnote = items[ref.endnoteId];
@@ -34220,7 +34181,7 @@ function createEmptyEndnoteBodyParagraph(withMarker = true) {
34220
34181
  type: "paragraph",
34221
34182
  runs: [
34222
34183
  ...withMarker ? [makeEndnoteRefMarkerRun()] : [],
34223
- { id: "synthetic:endnote-body-empty-text", text: "" }
34184
+ { id: "synthetic:endnote-body-empty-text", text: "", kind: "text" }
34224
34185
  ],
34225
34186
  style: { styleId: "EndnoteText" }
34226
34187
  };
@@ -34237,6 +34198,7 @@ function makeEndnoteRefMarkerRun() {
34237
34198
  return {
34238
34199
  id: "synthetic:endnoteRef",
34239
34200
  text: "",
34201
+ kind: "text",
34240
34202
  styles: { styleId: "EndnoteReference", superscript: true },
34241
34203
  __isEndnoteRefMarker: true
34242
34204
  };
@@ -34484,7 +34446,7 @@ function buildPartRelationshipsXml(images, hyperlinks) {
34484
34446
  function visitParagraphDeep(paragraph, callback) {
34485
34447
  callback(paragraph);
34486
34448
  for (const run of paragraph.runs) {
34487
- if (run.textBox) {
34449
+ if (run.kind === "textBox") {
34488
34450
  visitBlocks(run.textBox.blocks, callback);
34489
34451
  }
34490
34452
  }
@@ -34659,14 +34621,20 @@ const IMAGE_CAPTION_STYLE_ID = "Caption";
34659
34621
  const IMAGE_CAPTION_FIELD_IDENTIFIER = "Figure";
34660
34622
  const IMAGE_CAPTION_FIELD_INSTRUCTION = " SEQ Figure \\* ARABIC ";
34661
34623
  function createFieldCharRun(kind) {
34662
- const run = createEditorRun("");
34663
- run.fieldChar = { kind };
34664
- return run;
34624
+ return {
34625
+ id: createEditorRun("").id,
34626
+ text: "",
34627
+ kind: "fieldChar",
34628
+ fieldChar: { kind }
34629
+ };
34665
34630
  }
34666
34631
  function createFieldInstructionRun(instruction) {
34667
- const run = createEditorRun("");
34668
- run.fieldInstruction = instruction;
34669
- return run;
34632
+ return {
34633
+ id: createEditorRun("").id,
34634
+ text: "",
34635
+ kind: "fieldInstruction",
34636
+ fieldInstruction: instruction
34637
+ };
34670
34638
  }
34671
34639
  function createImageCaptionParagraph(captionText, label, sequenceNumber) {
34672
34640
  const paragraph = createEditorParagraphFromRuns([
@@ -34695,11 +34663,12 @@ function isImageCaptionParagraph(paragraph) {
34695
34663
  if (styleId !== "caption") {
34696
34664
  return false;
34697
34665
  }
34698
- return paragraph.runs.some(
34699
- (run) => run.fieldInstruction !== void 0 && new RegExp(`\\bSEQ\\s+${IMAGE_CAPTION_FIELD_IDENTIFIER}\\b`, "i").test(
34700
- run.fieldInstruction
34701
- )
34702
- );
34666
+ return paragraph.runs.some((run) => {
34667
+ const instruction = getRunFieldInstruction(run);
34668
+ return instruction !== void 0 && new RegExp(`\\bSEQ\\s+${IMAGE_CAPTION_FIELD_IDENTIFIER}\\b`, "i").test(
34669
+ instruction
34670
+ );
34671
+ });
34703
34672
  }
34704
34673
  function getImageCaptionText(paragraph) {
34705
34674
  var _a;
@@ -34713,7 +34682,7 @@ function getImageCaptionText(paragraph) {
34713
34682
  value += run.text;
34714
34683
  continue;
34715
34684
  }
34716
- if (((_a = run.fieldChar) == null ? void 0 : _a.kind) === "end") {
34685
+ if (((_a = getRunFieldChar(run)) == null ? void 0 : _a.kind) === "end") {
34717
34686
  afterField = true;
34718
34687
  }
34719
34688
  }
@@ -34737,12 +34706,11 @@ function renumberCaptionParagraph(paragraph, sequenceNumber) {
34737
34706
  let insideSeqResult = false;
34738
34707
  let changed = false;
34739
34708
  const nextRuns = paragraph.runs.map((run) => {
34740
- var _a, _b;
34741
- if (((_a = run.fieldChar) == null ? void 0 : _a.kind) === "separate") {
34709
+ if (run.kind === "fieldChar" && run.fieldChar.kind === "separate") {
34742
34710
  insideSeqResult = true;
34743
34711
  return { ...run, fieldChar: { ...run.fieldChar } };
34744
34712
  }
34745
- if (((_b = run.fieldChar) == null ? void 0 : _b.kind) === "end") {
34713
+ if (run.kind === "fieldChar" && run.fieldChar.kind === "end") {
34746
34714
  insideSeqResult = false;
34747
34715
  return { ...run, fieldChar: { ...run.fieldChar } };
34748
34716
  }
@@ -34829,11 +34797,11 @@ function buildPartContext(blocks, numberingContext, state, document2) {
34829
34797
  hyperlinkMap.set(link, rId2);
34830
34798
  hyperlinks.push({ rId: rId2, href: link });
34831
34799
  }
34832
- if (run.textBox && !textBoxDocPrIds.has(run.id)) {
34800
+ if (run.kind === "textBox" && !textBoxDocPrIds.has(run.id)) {
34833
34801
  textBoxDocPrIds.set(run.id, state.nextTextBoxDocPrId);
34834
34802
  state.nextTextBoxDocPrId += 1;
34835
34803
  }
34836
- if (!run.image) {
34804
+ if (run.kind !== "image") {
34837
34805
  continue;
34838
34806
  }
34839
34807
  const imageNumber = state.nextImageId;
@@ -37781,7 +37749,7 @@ function isFloatingFixedPosition(floating) {
37781
37749
  return ((_a = floating == null ? void 0 : floating.positionV) == null ? void 0 : _a.relativeFrom) === "page";
37782
37750
  }
37783
37751
  function getSelectedImageRun(state) {
37784
- return getSelectedObjectRun(state, (run) => Boolean(run.image));
37752
+ return getSelectedObjectRun(state, (run) => run.kind === "image");
37785
37753
  }
37786
37754
  function insertImageAtSelection(state, image) {
37787
37755
  const collapsedState = isSelectionCollapsed(state.selection) ? state : deleteSelectionRange(state);
@@ -37816,7 +37784,7 @@ function resizeSelectedImage(state, width, height) {
37816
37784
  return {
37817
37785
  ...cloneParagraph(candidate),
37818
37786
  runs: candidate.runs.map(
37819
- (run) => run.id === targetRun.id && run.image ? {
37787
+ (run) => run.id === targetRun.id && run.kind === "image" ? {
37820
37788
  ...run,
37821
37789
  image: {
37822
37790
  ...run.image,
@@ -37858,7 +37826,7 @@ function rotateSelectedImage(state, rotation) {
37858
37826
  return {
37859
37827
  ...cloneParagraph(candidate),
37860
37828
  runs: candidate.runs.map(
37861
- (run) => run.id === targetRun.id && run.image ? {
37829
+ (run) => run.id === targetRun.id && run.kind === "image" ? {
37862
37830
  ...run,
37863
37831
  image: {
37864
37832
  ...run.image,
@@ -37879,19 +37847,20 @@ function rotateSelectedImage(state, rotation) {
37879
37847
  }
37880
37848
  function getSelectedImageWrapPreset(state) {
37881
37849
  const selectedImage = getSelectedImageRun(state);
37882
- if (!(selectedImage == null ? void 0 : selectedImage.run.image)) {
37850
+ const image = selectedImage && getRunImage(selectedImage.run);
37851
+ if (!image) {
37883
37852
  return null;
37884
37853
  }
37885
- return floatingToWrapPreset(selectedImage.run.image.floating);
37854
+ return floatingToWrapPreset(image.floating);
37886
37855
  }
37887
37856
  function isSelectedImageFixedPosition(state) {
37888
- var _a;
37889
37857
  const selectedImage = getSelectedImageRun(state);
37890
- return isFloatingFixedPosition((_a = selectedImage == null ? void 0 : selectedImage.run.image) == null ? void 0 : _a.floating);
37858
+ const image = selectedImage && getRunImage(selectedImage.run);
37859
+ return isFloatingFixedPosition(image == null ? void 0 : image.floating);
37891
37860
  }
37892
37861
  function patchSelectedImageFloating(state, next) {
37893
37862
  const selectedImage = getSelectedImageRun(state);
37894
- if (!(selectedImage == null ? void 0 : selectedImage.run.image)) {
37863
+ if (!selectedImage || !getRunImage(selectedImage.run)) {
37895
37864
  return state;
37896
37865
  }
37897
37866
  const paragraphs = getParagraphs(state);
@@ -37903,7 +37872,7 @@ function patchSelectedImageFloating(state, next) {
37903
37872
  return {
37904
37873
  ...cloneParagraph(candidate),
37905
37874
  runs: candidate.runs.map((run) => {
37906
- if (run.id !== targetRun.id || !run.image) {
37875
+ if (run.id !== targetRun.id || run.kind !== "image") {
37907
37876
  return cloneRun(run);
37908
37877
  }
37909
37878
  const floating = next(run.image.floating);
@@ -37942,13 +37911,13 @@ function setImageWrapPolygon(state, runId, polygon) {
37942
37911
  const paragraphs = getParagraphs(state);
37943
37912
  let matched = false;
37944
37913
  const nextParagraphs = paragraphs.map((candidate) => {
37945
- if (!candidate.runs.some((run) => run.id === runId && run.image)) {
37914
+ if (!candidate.runs.some((run) => run.id === runId && run.kind === "image")) {
37946
37915
  return cloneParagraph(candidate);
37947
37916
  }
37948
37917
  return {
37949
37918
  ...cloneParagraph(candidate),
37950
37919
  runs: candidate.runs.map((run) => {
37951
- if (run.id !== runId || !run.image) {
37920
+ if (run.id !== runId || run.kind !== "image") {
37952
37921
  return cloneRun(run);
37953
37922
  }
37954
37923
  matched = true;
@@ -37976,7 +37945,7 @@ function setImageWrapPolygon(state, runId, polygon) {
37976
37945
  }
37977
37946
  function setSelectedImageAlt(state, alt) {
37978
37947
  const selectedImage = getSelectedImageRun(state);
37979
- if (!(selectedImage == null ? void 0 : selectedImage.run.image)) {
37948
+ if (!selectedImage || !getRunImage(selectedImage.run)) {
37980
37949
  return state;
37981
37950
  }
37982
37951
  const paragraphs = getParagraphs(state);
@@ -37987,7 +37956,7 @@ function setSelectedImageAlt(state, alt) {
37987
37956
  return {
37988
37957
  ...cloneParagraph(candidate),
37989
37958
  runs: candidate.runs.map(
37990
- (run) => run.id === selectedImage.run.id && run.image ? {
37959
+ (run) => run.id === selectedImage.run.id && run.kind === "image" ? {
37991
37960
  ...run,
37992
37961
  image: {
37993
37962
  ...run.image,
@@ -38008,7 +37977,7 @@ function setSelectedImageAlt(state, alt) {
38008
37977
  }
38009
37978
  function getSelectedImageCaption(state) {
38010
37979
  const selectedImage = getSelectedImageRun(state);
38011
- if (!(selectedImage == null ? void 0 : selectedImage.run.image)) {
37980
+ if (!selectedImage || !getRunImage(selectedImage.run)) {
38012
37981
  return null;
38013
37982
  }
38014
37983
  const paragraphs = getParagraphs(state);
@@ -38016,7 +37985,7 @@ function getSelectedImageCaption(state) {
38016
37985
  }
38017
37986
  function setSelectedImageCaption(state, captionText, label) {
38018
37987
  const selectedImage = getSelectedImageRun(state);
38019
- if (!(selectedImage == null ? void 0 : selectedImage.run.image)) {
37988
+ if (!selectedImage || !getRunImage(selectedImage.run)) {
38020
37989
  return state;
38021
37990
  }
38022
37991
  const paragraphs = getParagraphs(state);
@@ -38086,7 +38055,7 @@ function moveSelectedImageToPosition(state, targetPosition) {
38086
38055
  createEditorStyledRun(
38087
38056
  "",
38088
38057
  getStyleAtOffset(paragraph, offset),
38089
- imageRun.image
38058
+ getRunImage(imageRun)
38090
38059
  )
38091
38060
  ]
38092
38061
  );
@@ -39143,7 +39112,7 @@ function createIndexedDbPersistence(options = {}) {
39143
39112
  };
39144
39113
  }
39145
39114
  function computeLayoutInvalidationFromTransaction(prev, next) {
39146
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p;
39115
+ var _a, _b, _c, _d, _e, _f;
39147
39116
  if (prev === next || prev.document === next.document) {
39148
39117
  return {};
39149
39118
  }
@@ -39185,7 +39154,9 @@ function computeLayoutInvalidationFromTransaction(prev, next) {
39185
39154
  changed = true;
39186
39155
  break;
39187
39156
  }
39188
- if (Boolean(a.image) !== Boolean(b.image) || (((_a = a.image) == null ? void 0 : _a.width) ?? -1) !== (((_b = b.image) == null ? void 0 : _b.width) ?? -1) || (((_c = a.image) == null ? void 0 : _c.height) ?? -1) !== (((_d = b.image) == null ? void 0 : _d.height) ?? -1) || (((_f = (_e = a.image) == null ? void 0 : _e.floating) == null ? void 0 : _f.wrap) ?? "") !== (((_h = (_g = b.image) == null ? void 0 : _g.floating) == null ? void 0 : _h.wrap) ?? "") || Boolean((_j = (_i = a.image) == null ? void 0 : _i.floating) == null ? void 0 : _j.behindDoc) !== Boolean((_l = (_k = b.image) == null ? void 0 : _k.floating) == null ? void 0 : _l.behindDoc) || (((_n = (_m = a.image) == null ? void 0 : _m.wrapPolygon) == null ? void 0 : _n.length) ?? -1) !== (((_p = (_o = b.image) == null ? void 0 : _o.wrapPolygon) == null ? void 0 : _p.length) ?? -1)) {
39157
+ const aImage = getRunImage(a);
39158
+ const bImage = getRunImage(b);
39159
+ if (Boolean(aImage) !== Boolean(bImage) || ((aImage == null ? void 0 : aImage.width) ?? -1) !== ((bImage == null ? void 0 : bImage.width) ?? -1) || ((aImage == null ? void 0 : aImage.height) ?? -1) !== ((bImage == null ? void 0 : bImage.height) ?? -1) || (((_a = aImage == null ? void 0 : aImage.floating) == null ? void 0 : _a.wrap) ?? "") !== (((_b = bImage == null ? void 0 : bImage.floating) == null ? void 0 : _b.wrap) ?? "") || Boolean((_c = aImage == null ? void 0 : aImage.floating) == null ? void 0 : _c.behindDoc) !== Boolean((_d = bImage == null ? void 0 : bImage.floating) == null ? void 0 : _d.behindDoc) || (((_e = aImage == null ? void 0 : aImage.wrapPolygon) == null ? void 0 : _e.length) ?? -1) !== (((_f = bImage == null ? void 0 : bImage.wrapPolygon) == null ? void 0 : _f.length) ?? -1)) {
39189
39160
  changed = true;
39190
39161
  break;
39191
39162
  }
@@ -39419,7 +39390,7 @@ function createEditorDocumentRuntime(deps) {
39419
39390
  }
39420
39391
  const MIN_TEXT_BOX_SIZE_PX = 24;
39421
39392
  function getSelectedTextBoxRun(state) {
39422
- return getSelectedObjectRun(state, (run) => Boolean(run.textBox));
39393
+ return getSelectedObjectRun(state, (run) => run.kind === "textBox");
39423
39394
  }
39424
39395
  function shiftFloatingForResize(floating, widthDelta, heightDelta, growsFromWest, growsFromNorth) {
39425
39396
  let next = floating;
@@ -39458,7 +39429,7 @@ function normalizeRotation(rotation) {
39458
39429
  }
39459
39430
  function rotateSelectedTextBox(state, rotation) {
39460
39431
  const selected = getSelectedTextBoxRun(state);
39461
- if (!selected || !selected.run.textBox) {
39432
+ if (!selected || !getRunTextBox(selected.run)) {
39462
39433
  return state;
39463
39434
  }
39464
39435
  const nextRotation = normalizeRotation(rotation);
@@ -39471,7 +39442,7 @@ function rotateSelectedTextBox(state, rotation) {
39471
39442
  return {
39472
39443
  ...cloneParagraph(candidate),
39473
39444
  runs: candidate.runs.map(
39474
- (run) => run.id === targetRun.id && run.textBox ? {
39445
+ (run) => run.id === targetRun.id && run.kind === "textBox" ? {
39475
39446
  ...run,
39476
39447
  textBox: { ...run.textBox, rotation: nextRotation }
39477
39448
  } : cloneRun(run)
@@ -39489,19 +39460,20 @@ function rotateSelectedTextBox(state, rotation) {
39489
39460
  }
39490
39461
  function getSelectedTextBoxWrapPreset(state) {
39491
39462
  const selected = getSelectedTextBoxRun(state);
39492
- if (!(selected == null ? void 0 : selected.run.textBox)) {
39463
+ const textBox = selected && getRunTextBox(selected.run);
39464
+ if (!textBox) {
39493
39465
  return null;
39494
39466
  }
39495
- return floatingToWrapPreset(selected.run.textBox.floating);
39467
+ return floatingToWrapPreset(textBox.floating);
39496
39468
  }
39497
39469
  function isSelectedTextBoxFixedPosition(state) {
39498
- var _a;
39499
39470
  const selected = getSelectedTextBoxRun(state);
39500
- return isFloatingFixedPosition((_a = selected == null ? void 0 : selected.run.textBox) == null ? void 0 : _a.floating);
39471
+ const textBox = selected && getRunTextBox(selected.run);
39472
+ return isFloatingFixedPosition(textBox == null ? void 0 : textBox.floating);
39501
39473
  }
39502
39474
  function patchSelectedTextBoxFloating(state, next) {
39503
39475
  const selected = getSelectedTextBoxRun(state);
39504
- if (!(selected == null ? void 0 : selected.run.textBox)) {
39476
+ if (!selected || !getRunTextBox(selected.run)) {
39505
39477
  return state;
39506
39478
  }
39507
39479
  const { paragraphIndex, run: targetRun } = selected;
@@ -39513,7 +39485,7 @@ function patchSelectedTextBoxFloating(state, next) {
39513
39485
  return {
39514
39486
  ...cloneParagraph(candidate),
39515
39487
  runs: candidate.runs.map((run) => {
39516
- if (run.id !== targetRun.id || !run.textBox) {
39488
+ if (run.id !== targetRun.id || run.kind !== "textBox") {
39517
39489
  return cloneRun(run);
39518
39490
  }
39519
39491
  const floating = next(run.textBox.floating);
@@ -39550,7 +39522,8 @@ function setSelectedTextBoxFixedPosition(state, fixed) {
39550
39522
  }
39551
39523
  function resizeSelectedTextBox(state, width, height, options = {}) {
39552
39524
  const selected = getSelectedTextBoxRun(state);
39553
- if (!selected || !selected.run.textBox) {
39525
+ const selectedTextBox = selected && getRunTextBox(selected.run);
39526
+ if (!selected || !selectedTextBox) {
39554
39527
  return state;
39555
39528
  }
39556
39529
  const direction = options.handleDirection ?? "se";
@@ -39560,8 +39533,8 @@ function resizeSelectedTextBox(state, width, height, options = {}) {
39560
39533
  const nextWidth = Math.max(MIN_TEXT_BOX_SIZE_PX, Math.round(width));
39561
39534
  const nextHeight = Math.max(MIN_TEXT_BOX_SIZE_PX, Math.round(height));
39562
39535
  const { paragraphIndex, run: targetRun } = selected;
39563
- const widthDelta = nextWidth - selected.run.textBox.width;
39564
- const heightDelta = nextHeight - selected.run.textBox.height;
39536
+ const widthDelta = nextWidth - selectedTextBox.width;
39537
+ const heightDelta = nextHeight - selectedTextBox.height;
39565
39538
  const paragraphs = getParagraphs(state);
39566
39539
  const nextParagraphs = paragraphs.map((candidate, candidateIndex) => {
39567
39540
  if (candidateIndex !== paragraphIndex) {
@@ -39571,7 +39544,7 @@ function resizeSelectedTextBox(state, width, height, options = {}) {
39571
39544
  ...cloneParagraph(candidate),
39572
39545
  runs: candidate.runs.map((run) => {
39573
39546
  var _a;
39574
- if (run.id !== targetRun.id || !run.textBox) {
39547
+ if (run.id !== targetRun.id || run.kind !== "textBox") {
39575
39548
  return cloneRun(run);
39576
39549
  }
39577
39550
  const textBox = run.textBox;
@@ -41092,7 +41065,7 @@ function createEditorImageOperations(deps) {
41092
41065
  for (const run of paragraph.runs) {
41093
41066
  const startOffset = offset;
41094
41067
  offset += run.text.length;
41095
- if (run.image && run.text.length === 1 && startOffset === normalized.startParagraphOffset) {
41068
+ if (run.kind === "image" && run.text.length === 1 && startOffset === normalized.startParagraphOffset) {
41096
41069
  return {
41097
41070
  paragraph,
41098
41071
  run,
@@ -41319,15 +41292,16 @@ function createEditorImageOperations(deps) {
41319
41292
  function createEditorTextBoxOperations(deps) {
41320
41293
  const getSelectedTextBoxSize = (current) => {
41321
41294
  const selected = getSelectedTextBoxRun(current);
41322
- if (!(selected == null ? void 0 : selected.run.textBox)) {
41295
+ const textBox = selected && getRunTextBox(selected.run);
41296
+ if (!textBox) {
41323
41297
  return null;
41324
41298
  }
41325
41299
  return {
41326
- width: selected.run.textBox.width,
41300
+ width: textBox.width,
41327
41301
  // Start the drag from the height actually painted on screen. For an
41328
41302
  // auto-fit box that is its content height, not the stored height, so the
41329
41303
  // box doesn't jump on the first pointer move.
41330
- height: resolveTextBoxRenderHeight(selected.run.textBox, current, 0)
41304
+ height: resolveTextBoxRenderHeight(textBox, current, 0)
41331
41305
  };
41332
41306
  };
41333
41307
  const resizeSession = createResizeSession(
@@ -42252,7 +42226,7 @@ function createEditorLayoutOptionsController(deps) {
42252
42226
  );
42253
42227
  if (preset === "tight" || preset === "through") {
42254
42228
  const selected = getSelectedImageRun(state());
42255
- const image = selected == null ? void 0 : selected.run.image;
42229
+ const image = selected && getRunImage(selected.run);
42256
42230
  if (image && !image.wrapPolygon) {
42257
42231
  ensureImageWrapContour(selected.run.id, image.src);
42258
42232
  }
@@ -44449,7 +44423,7 @@ function nextAutoMarker(document2) {
44449
44423
  let autoCount = startAt - 1;
44450
44424
  const seen = /* @__PURE__ */ new Set();
44451
44425
  for (const { run } of iterateFootnoteReferenceRuns(document2)) {
44452
- const ref = run.footnoteReference;
44426
+ const ref = getRunFootnoteReference(run);
44453
44427
  if (!ref || ref.customMark) continue;
44454
44428
  if (seen.has(ref.footnoteId)) continue;
44455
44429
  seen.add(ref.footnoteId);
@@ -44640,7 +44614,7 @@ function getLinkAtSelection(state) {
44640
44614
  const startOffset = paragraphIndex === normalized.startIndex ? normalized.startParagraphOffset : 0;
44641
44615
  const endOffset = paragraphIndex === normalized.endIndex ? normalized.endParagraphOffset : getParagraphLength(paragraph);
44642
44616
  return sliceRuns(paragraph, startOffset, endOffset);
44643
- }).filter((run) => run.text.length > 0 && !run.image);
44617
+ }).filter((run) => run.text.length > 0 && run.kind !== "image");
44644
44618
  if (touchedRuns.length === 0) {
44645
44619
  return null;
44646
44620
  }
@@ -45167,7 +45141,7 @@ function createEditorCommandsController(deps) {
45167
45141
  if (!run) {
45168
45142
  return;
45169
45143
  }
45170
- const currentAlt = ((_a = run.run.image) == null ? void 0 : _a.alt) ?? "";
45144
+ const currentAlt = ((_a = getRunImage(run.run)) == null ? void 0 : _a.alt) ?? "";
45171
45145
  deps.openImageAltDialog(currentAlt);
45172
45146
  };
45173
45147
  const applyImageCaptionCommand = (caption) => {
@@ -45967,8 +45941,19 @@ function collectTocHeadings(state, maxLevel = DEFAULT_TOC_MAX_LEVEL) {
45967
45941
  return headings;
45968
45942
  }
45969
45943
  function makeRun(partial) {
45970
- const run = createEditorRun(partial.text ?? "");
45971
- return { ...run, ...partial, id: run.id };
45944
+ const id = createEditorRun(partial.text).id;
45945
+ if (partial.fieldChar) {
45946
+ return { id, text: partial.text, kind: "fieldChar", fieldChar: partial.fieldChar };
45947
+ }
45948
+ if (partial.fieldInstruction !== void 0) {
45949
+ return {
45950
+ id,
45951
+ text: partial.text,
45952
+ kind: "fieldInstruction",
45953
+ fieldInstruction: partial.fieldInstruction
45954
+ };
45955
+ }
45956
+ return { id, text: partial.text, kind: "text" };
45972
45957
  }
45973
45958
  function makeParagraph(runs, style2) {
45974
45959
  const paragraph = createEditorParagraph("");
@@ -46047,7 +46032,6 @@ function insertTableOfContents(state, resolvePage = () => void 0, maxLevel = DEF
46047
46032
  return replaceSectionBlocks(state, sectionIndex, nextBlocks, tocBlocks[0]);
46048
46033
  }
46049
46034
  function findTocRegion(blocks) {
46050
- var _a, _b, _c;
46051
46035
  let depth = 0;
46052
46036
  let instruction = "";
46053
46037
  let separateBlockIndex = -1;
@@ -46057,7 +46041,9 @@ function findTocRegion(blocks) {
46057
46041
  const block = blocks[i];
46058
46042
  if (block.type !== "paragraph") continue;
46059
46043
  for (const run of block.runs) {
46060
- if (((_a = run.fieldChar) == null ? void 0 : _a.kind) === "begin") {
46044
+ const fieldChar = getRunFieldChar(run);
46045
+ const fieldInstruction = getRunFieldInstruction(run);
46046
+ if ((fieldChar == null ? void 0 : fieldChar.kind) === "begin") {
46061
46047
  depth += 1;
46062
46048
  if (depth === 1) {
46063
46049
  beginBlockIndex = i;
@@ -46065,12 +46051,12 @@ function findTocRegion(blocks) {
46065
46051
  isToc = false;
46066
46052
  separateBlockIndex = -1;
46067
46053
  }
46068
- } else if (depth === 1 && run.fieldInstruction !== void 0) {
46069
- instruction += run.fieldInstruction;
46054
+ } else if (depth === 1 && fieldInstruction !== void 0) {
46055
+ instruction += fieldInstruction;
46070
46056
  if (/\bTOC\b/i.test(instruction)) isToc = true;
46071
- } else if (((_b = run.fieldChar) == null ? void 0 : _b.kind) === "separate") {
46057
+ } else if ((fieldChar == null ? void 0 : fieldChar.kind) === "separate") {
46072
46058
  if (depth === 1) separateBlockIndex = i;
46073
- } else if (((_c = run.fieldChar) == null ? void 0 : _c.kind) === "end") {
46059
+ } else if ((fieldChar == null ? void 0 : fieldChar.kind) === "end") {
46074
46060
  if (depth === 1) {
46075
46061
  if (isToc) {
46076
46062
  return {