oasis-editor 0.0.88 → 0.0.90

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (39) hide show
  1. package/dist/{OasisEditorApp-Bx4I4GCm.js → OasisEditorApp-2b7y3aGj.js} +1996 -646
  2. package/dist/assets/{importDocxWorker-BcELKms0.js → importDocxWorker-BN5o1geV.js} +1 -1
  3. package/dist/core/commands/table/tableCommandUtils.d.ts +2 -1
  4. package/dist/core/commands/table/tableFloatingCommands.d.ts +5 -0
  5. package/dist/core/commands/table.d.ts +1 -0
  6. package/dist/core/model/index.d.ts +2 -2
  7. package/dist/core/model/types/layout.d.ts +4 -0
  8. package/dist/core/model/types/nodes.d.ts +23 -7
  9. package/dist/core/model/types/primitives.d.ts +19 -0
  10. package/dist/core/model/types/styles.d.ts +63 -6
  11. package/dist/core/model.d.ts +1 -0
  12. package/dist/core/tableStyleResolver.d.ts +20 -0
  13. package/dist/export/docx/tableXml.d.ts +1 -0
  14. package/dist/export/pdf/OasisPdfWriter.d.ts +6 -102
  15. package/dist/export/pdf/draw/drawFragment.d.ts +15 -1
  16. package/dist/export/pdf/draw/drawTextBoxShape.d.ts +1 -0
  17. package/dist/export/pdf/writer/PdfContentStream.d.ts +20 -0
  18. package/dist/export/pdf/writer/PdfDocumentSerializer.d.ts +5 -0
  19. package/dist/export/pdf/writer/PdfFontTable.d.ts +38 -0
  20. package/dist/export/pdf/writer/PdfImageTable.d.ts +12 -0
  21. package/dist/export/pdf/writer/pdfPrimitives.d.ts +20 -0
  22. package/dist/export/pdf/writer/pdfTypes.d.ts +107 -0
  23. package/dist/i18n/locales/en.d.ts +18 -0
  24. package/dist/i18n/locales/pt-BR.d.ts +18 -0
  25. package/dist/import/docx/tableProperties.d.ts +2 -1
  26. package/dist/import/docx/tables.d.ts +1 -1
  27. package/dist/{index-Ds5uOUe8.js → index-DcElQi6c.js} +1946 -1204
  28. package/dist/layoutProjection/floatingObjects.d.ts +15 -1
  29. package/dist/layoutProjection/paginationTrack.d.ts +2 -0
  30. package/dist/layoutProjection/paragraphPagination.d.ts +2 -2
  31. package/dist/oasis-editor.js +50 -50
  32. package/dist/oasis-editor.umd.cjs +4 -4
  33. package/dist/ui/canvas/CanvasLayoutSnapshot.d.ts +1 -1
  34. package/dist/ui/canvas/CanvasTableLayout.d.ts +7 -1
  35. package/dist/ui/canvas/canvasBorders.d.ts +2 -0
  36. package/dist/ui/canvas/canvasSnapshotTypes.d.ts +12 -0
  37. package/dist/ui/components/Dialogs/TablePropertiesDialog.d.ts +22 -1
  38. package/dist/ui/editorUiTypes.d.ts +1 -1
  39. package/package.json +1 -1
@@ -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 { 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 resolveNamedTextStyle, bH as togglePreciseFontMode, bI as nextFontSizePt, bJ as previousFontSizePt, bK as fontSizePtToPx, bL as createDefaultToolbarPreset, bM as MenuRegistry, bN as createToolbarRegistry, bO as Editor, bP as resolveCommandRef, bQ as commandRefName, bR as createOasisEditorClient, bS as createEditorZoom, bT as startLongTaskObserver, bU as installGlobalReport, bV as applyStoredPreciseFontPreference, bW as getWelcomeSeen, bX as isLocalFontAccessSupported, bY as EDITOR_SCROLL_PADDING_PX, bZ as Toolbar, b_ as OasisEditorLoading, b$ as I18nProvider, c0 as createTranslator, c1 as createEditorLogger, c2 as registerDomStatsSurface } from "./index-Ds5uOUe8.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 getImageFloatingGeometry, aK as textStyleToFontSizePt, aL as PX_PER_POINT, aM as DEFAULT_FONT_SIZE_PX, aN as isDoubleUnderlineStyle, aO as isWavyUnderlineStyle, aP as underlineStyleLineWidthPx, aQ as underlineStyleDashArray, aR as resolveListLabel, aS as getListLabelInset, aT as getAlignedListLabelInset, aU as getParagraphBorderInsets, aV as buildSegmentTable, aW as buildCanvasTableLayout, aX as resolveCanvasTableWidth, aY as resolveFloatingTableRect, aZ as normalizeFamily, a_ as ROBOTO_FONT_FILES, a$ as loadFontAsset, b0 as OFFICE_COMPAT_FONT_FAMILIES, b1 as buildSfnt, b2 as defaultFontDecoderRegistry, b3 as SfntFontProgram, b4 as collectPdfFontFamilies, b5 as projectDocumentLayout, b6 as getPageContentWidth, b7 as getPageHeaderZoneTop, b8 as getPageBodyTop, b9 as getPageColumnRects, ba as findFootnoteReference, bb as FOOTNOTE_MARKER_GUTTER_PX, bc as resolveImporterForFile, bd as getDocumentSectionsCanonical, be as getDocumentParagraphsCanonical, bf as getDocumentParagraphs, bg as getDocumentPageSettings, bh as getTableCellContentWidthForParagraph, bi as on, bj as debounce, bk as unwrap, bl as perfTimer, bm as getRunTextBox, bn as createEditorDocument, bo as resolveResizedDimensions, bp as resolveTextBoxRenderHeight, bq as getToolbarStyleState, br as getCachedCanvasImage, bs as measureParagraphMinContentWidthPx, bt as getEditableBlocksForZone, bu as findParagraphLocation, bv as createSectionBoundaryParagraph, bw as normalizePageSettings, bx as DEFAULT_EDITOR_PAGE_SETTINGS, by as markStart, bz as markEnd, bA as getParagraphEntries, bB as getParagraphById, bC as createEditorFootnote, bD as createFootnoteReferenceRun, bE as renumberFootnotes, bF as getFootnoteDisplayMarker, bG as getHeadingLevel, bH as preciseFontModeVersion, bI as isPreciseFontModeEnabled, bJ as resolveNamedTextStyle, bK as togglePreciseFontMode, bL as nextFontSizePt, bM as previousFontSizePt, bN as fontSizePtToPx, bO as createDefaultToolbarPreset, bP as MenuRegistry, bQ as createToolbarRegistry, bR as Editor, bS as resolveCommandRef, bT as commandRefName, bU as createOasisEditorClient, bV as createEditorZoom, bW as startLongTaskObserver, bX as installGlobalReport, bY as applyStoredPreciseFontPreference, bZ as getWelcomeSeen, b_ as isLocalFontAccessSupported, b$ as EDITOR_SCROLL_PADDING_PX, c0 as Toolbar, c1 as OasisEditorLoading, c2 as I18nProvider, c3 as createTranslator, c4 as createEditorLogger, c5 as registerDomStatsSurface } from "./index-DcElQi6c.js";
5
5
  function cloneStyle(style2) {
6
6
  return style2 ? { ...style2 } : void 0;
7
7
  }
@@ -113,20 +113,49 @@ function cloneBlocks(blocks) {
113
113
  ...block.style,
114
114
  defaultCellMargins: block.style.defaultCellMargins ? { ...block.style.defaultCellMargins } : void 0,
115
115
  floating: block.style.floating ? { ...block.style.floating } : void 0,
116
- revisionXml: block.style.revisionXml ? [...block.style.revisionXml] : void 0
116
+ revision: block.style.revision ? {
117
+ ...block.style.revision,
118
+ previous: { ...block.style.revision.previous }
119
+ } : void 0
120
+ } : void 0,
121
+ gridRevision: block.gridRevision ? {
122
+ ...block.gridRevision,
123
+ previous: [...block.gridRevision.previous]
117
124
  } : void 0,
118
- tblGridChangeXml: block.tblGridChangeXml,
119
125
  rows: block.rows.map((row) => ({
120
126
  ...row,
127
+ conditionalStyle: row.conditionalStyle ? { ...row.conditionalStyle } : void 0,
121
128
  style: row.style ? {
122
129
  ...row.style,
123
- revisionXml: row.style.revisionXml ? [...row.style.revisionXml] : void 0
130
+ revision: row.style.revision ? { ...row.style.revision } : void 0,
131
+ propertyRevision: row.style.propertyRevision ? {
132
+ ...row.style.propertyRevision,
133
+ previous: { ...row.style.propertyRevision.previous }
134
+ } : void 0
124
135
  } : void 0,
125
136
  cells: row.cells.map((cell) => ({
126
137
  ...cell,
138
+ conditionalStyle: cell.conditionalStyle ? { ...cell.conditionalStyle } : void 0,
139
+ mergeRevisionState: cell.mergeRevisionState ? {
140
+ ...cell.mergeRevisionState,
141
+ previousCells: cell.mergeRevisionState.previousCells.map(
142
+ (previousCell) => ({
143
+ ...previousCell,
144
+ mergeRevisionState: void 0,
145
+ style: previousCell.style ? { ...previousCell.style } : void 0,
146
+ blocks: cloneParagraphs(previousCell.blocks)
147
+ })
148
+ )
149
+ } : void 0,
127
150
  style: cell.style ? {
128
151
  ...cell.style,
129
- revisionXml: cell.style.revisionXml ? [...cell.style.revisionXml] : void 0
152
+ revision: cell.style.revision ? { ...cell.style.revision } : void 0,
153
+ propertyRevision: cell.style.propertyRevision ? {
154
+ ...cell.style.propertyRevision,
155
+ previous: {
156
+ ...cell.style.propertyRevision.previous
157
+ }
158
+ } : void 0
130
159
  } : void 0,
131
160
  blocks: cloneParagraphs(cell.blocks)
132
161
  }))
@@ -153,23 +182,54 @@ function cloneBlock(block) {
153
182
  ...block.style,
154
183
  defaultCellMargins: block.style.defaultCellMargins ? { ...block.style.defaultCellMargins } : void 0,
155
184
  floating: block.style.floating ? { ...block.style.floating } : void 0,
156
- revisionXml: block.style.revisionXml ? [...block.style.revisionXml] : void 0
185
+ revision: block.style.revision ? {
186
+ ...block.style.revision,
187
+ previous: { ...block.style.revision.previous }
188
+ } : void 0
189
+ } : void 0,
190
+ gridRevision: block.gridRevision ? {
191
+ ...block.gridRevision,
192
+ previous: [...block.gridRevision.previous]
157
193
  } : void 0,
158
- tblGridChangeXml: block.tblGridChangeXml,
159
194
  rows: block.rows.map((row) => ({
160
195
  ...row,
196
+ conditionalStyle: row.conditionalStyle ? { ...row.conditionalStyle } : void 0,
161
197
  style: row.style ? {
162
198
  ...row.style,
163
- revisionXml: row.style.revisionXml ? [...row.style.revisionXml] : void 0
199
+ revision: row.style.revision ? { ...row.style.revision } : void 0,
200
+ propertyRevision: row.style.propertyRevision ? {
201
+ ...row.style.propertyRevision,
202
+ previous: { ...row.style.propertyRevision.previous }
203
+ } : void 0
164
204
  } : void 0,
165
205
  cells: row.cells.map((cell) => ({
166
206
  ...cell,
207
+ conditionalStyle: cell.conditionalStyle ? { ...cell.conditionalStyle } : void 0,
208
+ mergeRevisionState: cell.mergeRevisionState ? {
209
+ ...cell.mergeRevisionState,
210
+ previousCells: cell.mergeRevisionState.previousCells.map(
211
+ (previousCell) => ({
212
+ ...previousCell,
213
+ mergeRevisionState: void 0,
214
+ style: previousCell.style ? { ...previousCell.style } : void 0,
215
+ blocks: previousCell.blocks.map(
216
+ (paragraph) => cloneBlock(paragraph)
217
+ )
218
+ })
219
+ )
220
+ } : void 0,
167
221
  colSpan: cell.colSpan ?? void 0,
168
222
  rowSpan: cell.rowSpan ?? void 0,
169
223
  vMerge: cell.vMerge ?? void 0,
170
224
  style: cell.style ? {
171
225
  ...cell.style,
172
- revisionXml: cell.style.revisionXml ? [...cell.style.revisionXml] : void 0
226
+ revision: cell.style.revision ? { ...cell.style.revision } : void 0,
227
+ propertyRevision: cell.style.propertyRevision ? {
228
+ ...cell.style.propertyRevision,
229
+ previous: {
230
+ ...cell.style.propertyRevision.previous
231
+ }
232
+ } : void 0
173
233
  } : void 0,
174
234
  blocks: cell.blocks.map((paragraph) => ({
175
235
  ...paragraph,
@@ -26566,6 +26626,17 @@ function createEditorDialogs() {
26566
26626
  tableIndentLeft: "",
26567
26627
  tableWrapping: "none",
26568
26628
  floatingSummary: "",
26629
+ floatingHorizontalAnchor: "margin",
26630
+ floatingVerticalAnchor: "text",
26631
+ floatingX: "0",
26632
+ floatingY: "0",
26633
+ floatingXAlign: "",
26634
+ floatingYAlign: "",
26635
+ floatingDistanceTop: "0",
26636
+ floatingDistanceRight: "0",
26637
+ floatingDistanceBottom: "0",
26638
+ floatingDistanceLeft: "0",
26639
+ floatingOverlap: "overlap",
26569
26640
  rowHeight: "",
26570
26641
  rowHeightRule: "",
26571
26642
  repeatHeader: false,
@@ -26589,6 +26660,10 @@ function createEditorDialogs() {
26589
26660
  borderRight: false,
26590
26661
  borderBottom: false,
26591
26662
  borderLeft: false,
26663
+ borderStart: false,
26664
+ borderEnd: false,
26665
+ borderTopLeftToBottomRight: false,
26666
+ borderTopRightToBottomLeft: false,
26592
26667
  shading: "",
26593
26668
  altTitle: "",
26594
26669
  altDescription: ""
@@ -28546,6 +28621,13 @@ function createParagraphDialogBridge(deps) {
28546
28621
  applyParagraphDialogValues
28547
28622
  };
28548
28623
  }
28624
+ function createTableRevisionMetadata() {
28625
+ return {
28626
+ id: `rev:${Math.random().toString(36).slice(2, 9)}`,
28627
+ author: "User",
28628
+ date: Date.now()
28629
+ };
28630
+ }
28549
28631
  function patchStyleValue(style2, key, value) {
28550
28632
  const nextStyle = { ...style2 ?? {} };
28551
28633
  if (value === null) {
@@ -28720,10 +28802,20 @@ function setTableCellStyleValue(state, key, value) {
28720
28802
  selectedParagraphIds.add(id);
28721
28803
  }
28722
28804
  }
28723
- const updateCell = (cell) => ({
28724
- ...cell,
28725
- style: patchStyleValue(cell.style, key, value)
28726
- });
28805
+ const updateCell = (cell) => {
28806
+ let style2 = cell.style;
28807
+ if (state.trackChangesEnabled && key !== "revision" && key !== "propertyRevision" && !(style2 == null ? void 0 : style2.propertyRevision)) {
28808
+ style2 = {
28809
+ ...style2 ?? {},
28810
+ propertyRevision: {
28811
+ ...createTableRevisionMetadata(),
28812
+ type: "property",
28813
+ previous: { ...style2 ?? {} }
28814
+ }
28815
+ };
28816
+ }
28817
+ return { ...cell, style: patchStyleValue(style2, key, value) };
28818
+ };
28727
28819
  const nextSections = getDocumentSections(state.document).map((section) => ({
28728
28820
  ...section,
28729
28821
  blocks: updateTableCellsInBlocks(
@@ -28771,10 +28863,20 @@ function collectLinearSelectedParagraphIds(state) {
28771
28863
  }
28772
28864
  function setTableStyleValue(state, key, value) {
28773
28865
  const selectedParagraphIds = collectLinearSelectedParagraphIds(state);
28774
- const updateTable = (table) => ({
28775
- ...table,
28776
- style: patchStyleValue(table.style, key, value)
28777
- });
28866
+ const updateTable = (table) => {
28867
+ let style2 = table.style;
28868
+ if (state.trackChangesEnabled && key !== "revision" && !(style2 == null ? void 0 : style2.revision)) {
28869
+ style2 = {
28870
+ ...style2 ?? {},
28871
+ revision: {
28872
+ ...createTableRevisionMetadata(),
28873
+ type: "property",
28874
+ previous: { ...style2 ?? {} }
28875
+ }
28876
+ };
28877
+ }
28878
+ return { ...table, style: patchStyleValue(style2, key, value) };
28879
+ };
28778
28880
  const updateBlocks = (blocks) => {
28779
28881
  return blocks.map((block) => {
28780
28882
  if (block.type === "paragraph") return block;
@@ -28798,9 +28900,20 @@ function setTableStyleValue(state, key, value) {
28798
28900
  function setActiveTableStyleValue(state, tableId, key, value) {
28799
28901
  const updateTable = (table) => {
28800
28902
  if (table.id !== tableId) return table;
28903
+ let style2 = table.style;
28904
+ if (state.trackChangesEnabled && key !== "revision" && !(style2 == null ? void 0 : style2.revision)) {
28905
+ style2 = {
28906
+ ...style2 ?? {},
28907
+ revision: {
28908
+ ...createTableRevisionMetadata(),
28909
+ type: "property",
28910
+ previous: { ...style2 ?? {} }
28911
+ }
28912
+ };
28913
+ }
28801
28914
  return {
28802
28915
  ...table,
28803
- style: patchStyleValue(table.style, key, value)
28916
+ style: patchStyleValue(style2, key, value)
28804
28917
  };
28805
28918
  };
28806
28919
  return updateStateSections(
@@ -28813,7 +28926,20 @@ function setSelectedTableRowStyleValue(state, key, value) {
28813
28926
  if (!target) return state;
28814
28927
  const updateTable = (table) => {
28815
28928
  const nextRows = table.rows.map(
28816
- (row, rowIndex) => rowIndex === target.loc.rowIndex ? { ...row, style: patchStyleValue(row.style, key, value) } : row
28929
+ (row, rowIndex) => rowIndex === target.loc.rowIndex ? (() => {
28930
+ let style2 = row.style;
28931
+ if (state.trackChangesEnabled && key !== "revision" && key !== "propertyRevision" && !(style2 == null ? void 0 : style2.propertyRevision)) {
28932
+ style2 = {
28933
+ ...style2 ?? {},
28934
+ propertyRevision: {
28935
+ ...createTableRevisionMetadata(),
28936
+ type: "property",
28937
+ previous: { ...style2 ?? {} }
28938
+ }
28939
+ };
28940
+ }
28941
+ return { ...row, style: patchStyleValue(style2, key, value) };
28942
+ })() : row
28817
28943
  );
28818
28944
  return { ...table, rows: nextRows };
28819
28945
  };
@@ -28824,9 +28950,26 @@ function setSelectedTableRowHeader(state, value) {
28824
28950
  if (!target) return state;
28825
28951
  const updateTable = (table) => ({
28826
28952
  ...table,
28827
- rows: table.rows.map(
28828
- (row, rowIndex) => rowIndex === target.loc.rowIndex ? { ...row, isHeader: value === null ? void 0 : value } : row
28829
- )
28953
+ rows: table.rows.map((row, rowIndex) => {
28954
+ if (rowIndex !== target.loc.rowIndex) return row;
28955
+ let style2 = row.style;
28956
+ if (state.trackChangesEnabled && !(style2 == null ? void 0 : style2.propertyRevision)) {
28957
+ style2 = {
28958
+ ...style2 ?? {},
28959
+ propertyRevision: {
28960
+ ...createTableRevisionMetadata(),
28961
+ type: "property",
28962
+ previous: { ...style2 ?? {}, isHeader: row.isHeader }
28963
+ }
28964
+ };
28965
+ }
28966
+ const isHeader = value === null ? void 0 : value;
28967
+ return {
28968
+ ...row,
28969
+ isHeader,
28970
+ style: patchStyleValue(style2, "isHeader", isHeader ?? null)
28971
+ };
28972
+ })
28830
28973
  });
28831
28974
  return updateActiveTableBlocks(state, updateTable);
28832
28975
  }
@@ -28836,9 +28979,20 @@ function setTableRowHeight(state, tableId, rowIndex, height) {
28836
28979
  const nextRows = [...table.rows];
28837
28980
  const row = nextRows[rowIndex];
28838
28981
  if (row) {
28982
+ let style2 = row.style;
28983
+ if (state.trackChangesEnabled && !(style2 == null ? void 0 : style2.propertyRevision)) {
28984
+ style2 = {
28985
+ ...style2 ?? {},
28986
+ propertyRevision: {
28987
+ ...createTableRevisionMetadata(),
28988
+ type: "property",
28989
+ previous: { ...style2 ?? {} }
28990
+ }
28991
+ };
28992
+ }
28839
28993
  nextRows[rowIndex] = {
28840
28994
  ...row,
28841
- style: patchStyleValue(row.style, "height", height)
28995
+ style: patchStyleValue(style2, "height", height)
28842
28996
  };
28843
28997
  }
28844
28998
  return { ...table, rows: nextRows };
@@ -28904,6 +29058,7 @@ function setTableColumnWidths(state, tableId, columnWidths, tableWidth, tableInd
28904
29058
  }
28905
29059
  const nextRows = table.rows.map((row, rowIndex) => {
28906
29060
  const nextCells = row.cells.map((cell, cellIndex) => {
29061
+ var _a2, _b;
28907
29062
  const entry = tableLayout.find(
28908
29063
  (item) => item.rowIndex === rowIndex && item.cellIndex === cellIndex
28909
29064
  );
@@ -28911,11 +29066,17 @@ function setTableColumnWidths(state, tableId, columnWidths, tableWidth, tableInd
28911
29066
  const rightVisualColumnIndex = entry.visualColumnIndex + entry.colSpan - 1;
28912
29067
  const newWidth = columnWidths[rightVisualColumnIndex];
28913
29068
  if (newWidth !== void 0 && entry.colSpan === 1) {
29069
+ const propertyRevision = state.trackChangesEnabled && !((_a2 = cell.style) == null ? void 0 : _a2.propertyRevision) ? {
29070
+ ...createTableRevisionMetadata(),
29071
+ type: "property",
29072
+ previous: { ...cell.style ?? {} }
29073
+ } : (_b = cell.style) == null ? void 0 : _b.propertyRevision;
28914
29074
  return {
28915
29075
  ...cell,
28916
29076
  style: {
28917
29077
  ...cell.style ?? {},
28918
- width: typeof newWidth === "number" ? newWidth : newWidth
29078
+ width: typeof newWidth === "number" ? newWidth : newWidth,
29079
+ ...propertyRevision ? { propertyRevision } : {}
28919
29080
  }
28920
29081
  };
28921
29082
  }
@@ -28924,6 +29085,13 @@ function setTableColumnWidths(state, tableId, columnWidths, tableWidth, tableInd
28924
29085
  return { ...row, cells: nextCells };
28925
29086
  });
28926
29087
  const nextStyle = { ...table.style ?? {} };
29088
+ if (state.trackChangesEnabled && !nextStyle.revision && (tableWidth !== void 0 || tableIndentLeft !== void 0)) {
29089
+ nextStyle.revision = {
29090
+ ...createTableRevisionMetadata(),
29091
+ type: "property",
29092
+ previous: { ...table.style ?? {} }
29093
+ };
29094
+ }
28927
29095
  if (tableWidth !== void 0) {
28928
29096
  nextStyle.width = tableWidth;
28929
29097
  }
@@ -28934,6 +29102,11 @@ function setTableColumnWidths(state, tableId, columnWidths, tableWidth, tableInd
28934
29102
  ...table,
28935
29103
  rows: nextRows,
28936
29104
  gridCols: hasGridOverride && canResolveGrid ? nextGridCols : table.gridCols,
29105
+ gridRevision: state.trackChangesEnabled && hasGridOverride && canResolveGrid && !table.gridRevision ? {
29106
+ ...createTableRevisionMetadata(),
29107
+ type: "grid",
29108
+ previous: [...table.gridCols ?? []]
29109
+ } : table.gridRevision,
28937
29110
  style: Object.keys(nextStyle).length > 0 ? nextStyle : void 0
28938
29111
  };
28939
29112
  };
@@ -28944,6 +29117,7 @@ function setTableColumnWidths(state, tableId, columnWidths, tableWidth, tableInd
28944
29117
  }
28945
29118
  function insertTableAtSelection(state, rows, cols) {
28946
29119
  const initialCellWidth = `${100 / Math.max(1, cols)}%`;
29120
+ const insertionRevision = state.trackChangesEnabled ? createTableRevisionMetadata() : void 0;
28947
29121
  const tableRows = [];
28948
29122
  for (let rowIndex = 0; rowIndex < rows; rowIndex += 1) {
28949
29123
  const cells = [];
@@ -28955,7 +29129,13 @@ function insertTableAtSelection(state, rows, cols) {
28955
29129
  }
28956
29130
  });
28957
29131
  }
28958
- tableRows.push(createEditorTableRow(cells));
29132
+ const row = createEditorTableRow(cells);
29133
+ if (insertionRevision) {
29134
+ row.style = {
29135
+ revision: { ...insertionRevision, type: "insert" }
29136
+ };
29137
+ }
29138
+ tableRows.push(row);
28959
29139
  }
28960
29140
  const table = {
28961
29141
  ...createEditorTable(tableRows),
@@ -29026,6 +29206,17 @@ const EMPTY_INITIAL = {
29026
29206
  tableIndentLeft: "",
29027
29207
  tableWrapping: "none",
29028
29208
  floatingSummary: "",
29209
+ floatingHorizontalAnchor: "margin",
29210
+ floatingVerticalAnchor: "text",
29211
+ floatingX: "0",
29212
+ floatingY: "0",
29213
+ floatingXAlign: "",
29214
+ floatingYAlign: "",
29215
+ floatingDistanceTop: "0",
29216
+ floatingDistanceRight: "0",
29217
+ floatingDistanceBottom: "0",
29218
+ floatingDistanceLeft: "0",
29219
+ floatingOverlap: "overlap",
29029
29220
  rowHeight: "",
29030
29221
  rowHeightRule: "",
29031
29222
  repeatHeader: false,
@@ -29049,6 +29240,10 @@ const EMPTY_INITIAL = {
29049
29240
  borderRight: false,
29050
29241
  borderBottom: false,
29051
29242
  borderLeft: false,
29243
+ borderStart: false,
29244
+ borderEnd: false,
29245
+ borderTopLeftToBottomRight: false,
29246
+ borderTopRightToBottomLeft: false,
29052
29247
  shading: "",
29053
29248
  altTitle: "",
29054
29249
  altDescription: ""
@@ -29105,7 +29300,7 @@ function buildFloatingSummary(table) {
29105
29300
  return Object.entries(floating).map(([key, value]) => `${key}=${value}`).join(", ");
29106
29301
  }
29107
29302
  function buildInitialValues(ctx, activeTab = "table") {
29108
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
29303
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _A, _B, _C, _D, _E, _F;
29109
29304
  const tableWidth = serializeWidth((_a = ctx.table.style) == null ? void 0 : _a.width);
29110
29305
  const row = ctx.table.rows[ctx.rowIndex];
29111
29306
  const cell = row == null ? void 0 : row.cells[ctx.cellIndex];
@@ -29118,7 +29313,11 @@ function buildInitialValues(ctx, activeTab = "table") {
29118
29313
  style2.borderTop,
29119
29314
  style2.borderRight,
29120
29315
  style2.borderBottom,
29121
- style2.borderLeft
29316
+ style2.borderLeft,
29317
+ style2.borderStart,
29318
+ style2.borderEnd,
29319
+ style2.borderTopLeftToBottomRight,
29320
+ style2.borderTopRightToBottomLeft
29122
29321
  ].filter(isVisibleBorder);
29123
29322
  const sharedBorder = candidateBorders[0];
29124
29323
  const floatingSummary = buildFloatingSummary(ctx.table);
@@ -29131,11 +29330,26 @@ function buildInitialValues(ctx, activeTab = "table") {
29131
29330
  tableIndentLeft: serializeWidth((_f = ctx.table.style) == null ? void 0 : _f.indentLeft).value,
29132
29331
  tableWrapping: floatingSummary ? "around" : "none",
29133
29332
  floatingSummary,
29333
+ floatingHorizontalAnchor: ((_h = (_g = ctx.table.style) == null ? void 0 : _g.floating) == null ? void 0 : _h.horizontalAnchor) ?? "margin",
29334
+ floatingVerticalAnchor: ((_j = (_i = ctx.table.style) == null ? void 0 : _i.floating) == null ? void 0 : _j.verticalAnchor) ?? "text",
29335
+ floatingX: ((_l = (_k = ctx.table.style) == null ? void 0 : _k.floating) == null ? void 0 : _l.x) != null ? String(ctx.table.style.floating.x) : "0",
29336
+ floatingY: ((_n = (_m = ctx.table.style) == null ? void 0 : _m.floating) == null ? void 0 : _n.y) != null ? String(ctx.table.style.floating.y) : "0",
29337
+ floatingXAlign: ((_p = (_o = ctx.table.style) == null ? void 0 : _o.floating) == null ? void 0 : _p.xAlign) ?? "",
29338
+ floatingYAlign: ((_r = (_q = ctx.table.style) == null ? void 0 : _q.floating) == null ? void 0 : _r.yAlign) ?? "",
29339
+ floatingDistanceTop: String(((_t = (_s = ctx.table.style) == null ? void 0 : _s.floating) == null ? void 0 : _t.distanceTop) ?? 0),
29340
+ floatingDistanceRight: String(
29341
+ ((_v = (_u = ctx.table.style) == null ? void 0 : _u.floating) == null ? void 0 : _v.distanceRight) ?? 0
29342
+ ),
29343
+ floatingDistanceBottom: String(
29344
+ ((_x = (_w = ctx.table.style) == null ? void 0 : _w.floating) == null ? void 0 : _x.distanceBottom) ?? 0
29345
+ ),
29346
+ floatingDistanceLeft: String(((_z = (_y = ctx.table.style) == null ? void 0 : _y.floating) == null ? void 0 : _z.distanceLeft) ?? 0),
29347
+ floatingOverlap: ((_A = ctx.table.style) == null ? void 0 : _A.tblOverlap) ?? "overlap",
29134
29348
  rowHeight: rowHeight.value,
29135
- rowHeightRule: ((_g = row == null ? void 0 : row.style) == null ? void 0 : _g.heightRule) ?? "",
29349
+ rowHeightRule: ((_B = row == null ? void 0 : row.style) == null ? void 0 : _B.heightRule) ?? "",
29136
29350
  repeatHeader: Boolean(row == null ? void 0 : row.isHeader),
29137
- allowBreakAcrossPages: ((_h = row == null ? void 0 : row.style) == null ? void 0 : _h.cantSplit) !== true,
29138
- hiddenRow: ((_i = row == null ? void 0 : row.style) == null ? void 0 : _i.hidden) === true,
29351
+ allowBreakAcrossPages: ((_C = row == null ? void 0 : row.style) == null ? void 0 : _C.cantSplit) !== true,
29352
+ hiddenRow: ((_D = row == null ? void 0 : row.style) == null ? void 0 : _D.hidden) === true,
29139
29353
  columnWidth: columnWidth.value,
29140
29354
  cellWidth: cellWidth.value,
29141
29355
  cellVerticalAlign: style2.verticalAlign ?? "",
@@ -29154,9 +29368,17 @@ function buildInitialValues(ctx, activeTab = "table") {
29154
29368
  borderRight: isVisibleBorder(style2.borderRight),
29155
29369
  borderBottom: isVisibleBorder(style2.borderBottom),
29156
29370
  borderLeft: isVisibleBorder(style2.borderLeft),
29371
+ borderStart: isVisibleBorder(style2.borderStart),
29372
+ borderEnd: isVisibleBorder(style2.borderEnd),
29373
+ borderTopLeftToBottomRight: isVisibleBorder(
29374
+ style2.borderTopLeftToBottomRight
29375
+ ),
29376
+ borderTopRightToBottomLeft: isVisibleBorder(
29377
+ style2.borderTopRightToBottomLeft
29378
+ ),
29157
29379
  shading: style2.shading ?? "",
29158
- altTitle: ((_j = ctx.table.style) == null ? void 0 : _j.altTitle) ?? "",
29159
- altDescription: ((_k = ctx.table.style) == null ? void 0 : _k.altDescription) ?? ""
29380
+ altTitle: ((_E = ctx.table.style) == null ? void 0 : _E.altTitle) ?? "",
29381
+ altDescription: ((_F = ctx.table.style) == null ? void 0 : _F.altDescription) ?? ""
29160
29382
  };
29161
29383
  }
29162
29384
  function setCellStyle(state, key, value) {
@@ -29174,14 +29396,36 @@ function applyTableProperties(state, values) {
29174
29396
  const ctx = resolveActiveTableContext(state);
29175
29397
  if (!ctx) return state;
29176
29398
  let next = state;
29177
- next = setActiveTableStyleValue(next, ctx.tableId, "width", values.tableWidth);
29178
- next = setActiveTableStyleValue(next, ctx.tableId, "align", values.tableAlign);
29399
+ next = setActiveTableStyleValue(
29400
+ next,
29401
+ ctx.tableId,
29402
+ "width",
29403
+ values.tableWidth
29404
+ );
29405
+ next = setActiveTableStyleValue(
29406
+ next,
29407
+ ctx.tableId,
29408
+ "align",
29409
+ values.tableAlign
29410
+ );
29179
29411
  next = setActiveTableStyleValue(
29180
29412
  next,
29181
29413
  ctx.tableId,
29182
29414
  "indentLeft",
29183
29415
  values.tableIndentLeft
29184
29416
  );
29417
+ next = setActiveTableStyleValue(
29418
+ next,
29419
+ ctx.tableId,
29420
+ "floating",
29421
+ values.tableFloating
29422
+ );
29423
+ next = setActiveTableStyleValue(
29424
+ next,
29425
+ ctx.tableId,
29426
+ "tblOverlap",
29427
+ values.tableOverlap
29428
+ );
29185
29429
  next = setActiveTableStyleValue(
29186
29430
  next,
29187
29431
  ctx.tableId,
@@ -29222,6 +29466,18 @@ function applyTableProperties(state, values) {
29222
29466
  next = setCellStyle(next, "borderRight", values.borders.right);
29223
29467
  next = setCellStyle(next, "borderBottom", values.borders.bottom);
29224
29468
  next = setCellStyle(next, "borderLeft", values.borders.left);
29469
+ next = setCellStyle(next, "borderStart", values.borders.start);
29470
+ next = setCellStyle(next, "borderEnd", values.borders.end);
29471
+ next = setCellStyle(
29472
+ next,
29473
+ "borderTopLeftToBottomRight",
29474
+ values.borders.topLeftToBottomRight
29475
+ );
29476
+ next = setCellStyle(
29477
+ next,
29478
+ "borderTopRightToBottomLeft",
29479
+ values.borders.topRightToBottomLeft
29480
+ );
29225
29481
  next = setCellStyle(next, "shading", values.shading);
29226
29482
  return next;
29227
29483
  }
@@ -31619,7 +31875,7 @@ function ParagraphDialog(props) {
31619
31875
  });
31620
31876
  }
31621
31877
  delegateEvents(["input", "click"]);
31622
- var _tmpl$$5 = /* @__PURE__ */ template(`<div class="oasis-editor-dialog-input-group oasis-editor-dialog-input-group-grow"><label class=oasis-editor-dialog-label></label><input type=number class=oasis-editor-dialog-input min=0 step=1>`), _tmpl$2$1 = /* @__PURE__ */ template(`<label class=oasis-editor-dialog-style-toggle><input type=checkbox>`), _tmpl$3$1 = /* @__PURE__ */ template(`<button class="oasis-editor-dialog-button oasis-editor-dialog-button-secondary"data-testid=editor-table-properties-cancel>`), _tmpl$4$1 = /* @__PURE__ */ template(`<button class="oasis-editor-dialog-button oasis-editor-dialog-button-primary"data-testid=editor-table-properties-apply>`), _tmpl$5$1 = /* @__PURE__ */ template(`<div class=oasis-editor-table-properties-panel><fieldset class=oasis-editor-font-dialog-fieldset><legend></legend><div class=oasis-editor-dialog-row><div class=oasis-editor-dialog-input-group><label class=oasis-editor-dialog-label></label><select class=oasis-editor-dialog-input data-testid=editor-table-properties-table-width-unit><option value=points></option><option value=percent></option></select></div></div></fieldset><fieldset class=oasis-editor-font-dialog-fieldset><legend></legend><div class=oasis-editor-dialog-style-row></div><div class=oasis-editor-dialog-row></div></fieldset><fieldset class=oasis-editor-font-dialog-fieldset><legend></legend><div class=oasis-editor-dialog-style-row><button type=button class="oasis-editor-dialog-button oasis-editor-dialog-button-secondary"disabled data-testid=editor-table-properties-positioning></button></div><div class=oasis-editor-dialog-help-text>`), _tmpl$6$1 = /* @__PURE__ */ template(`<label class=oasis-editor-dialog-style-toggle><input type=radio name=table-align>`), _tmpl$7 = /* @__PURE__ */ template(`<div class=oasis-editor-table-properties-panel><div class=oasis-editor-dialog-row><div class="oasis-editor-dialog-input-group oasis-editor-dialog-input-group-grow"><label class=oasis-editor-dialog-label></label><select class=oasis-editor-dialog-input data-testid=editor-table-properties-row-height-rule><option value></option><option value=atLeast></option><option value=exact></option></select></div></div><div class=oasis-editor-dialog-style-row>`), _tmpl$8 = /* @__PURE__ */ template(`<div class=oasis-editor-table-properties-panel><div class=oasis-editor-dialog-row>`), _tmpl$9 = /* @__PURE__ */ template(`<div class=oasis-editor-table-properties-panel><div class=oasis-editor-dialog-row><div class="oasis-editor-dialog-input-group oasis-editor-dialog-input-group-grow"><label class=oasis-editor-dialog-label></label><select class=oasis-editor-dialog-input data-testid=editor-table-properties-cell-valign><option value></option><option value=top></option><option value=middle></option><option value=bottom></option></select></div><div class="oasis-editor-dialog-input-group oasis-editor-dialog-input-group-grow"><label class=oasis-editor-dialog-label></label><select class=oasis-editor-dialog-input data-testid=editor-table-properties-cell-direction><option value></option><option value=lrTb>lrTb</option><option value=tbRl>tbRl</option><option value=btLr>btLr</option><option value=lrTbV>lrTbV</option><option value=tbRlV>tbRlV</option></select></div></div><fieldset class=oasis-editor-font-dialog-fieldset><legend></legend><div class=oasis-editor-dialog-style-row></div></fieldset><fieldset class=oasis-editor-font-dialog-fieldset><legend></legend><div class=oasis-editor-dialog-row></div></fieldset><fieldset class=oasis-editor-font-dialog-fieldset><legend></legend><div class=oasis-editor-dialog-row><div class="oasis-editor-dialog-input-group oasis-editor-dialog-input-group-grow"><label class=oasis-editor-dialog-label></label><select class=oasis-editor-dialog-input data-testid=editor-table-properties-border-style><option value=none></option><option value=solid></option><option value=dashed></option><option value=dotted></option></select></div><div class=oasis-editor-dialog-input-group><label class=oasis-editor-dialog-label></label><input type=color class=oasis-editor-dialog-input data-testid=editor-table-properties-border-color></div><div class=oasis-editor-dialog-input-group><label class=oasis-editor-dialog-label></label><input type=color class=oasis-editor-dialog-input data-testid=editor-table-properties-shading></div></div><div class=oasis-editor-dialog-style-row></div><div class=oasis-editor-table-properties-cell-preview data-testid=editor-table-properties-cell-preview>`), _tmpl$0 = /* @__PURE__ */ template(`<div class=oasis-editor-table-properties-panel><div class=oasis-editor-dialog-input-group><label class=oasis-editor-dialog-label></label><input class=oasis-editor-dialog-input data-testid=editor-table-properties-alt-title></div><div class=oasis-editor-dialog-input-group><label class=oasis-editor-dialog-label></label><textarea class="oasis-editor-dialog-input oasis-editor-table-properties-textarea"data-testid=editor-table-properties-alt-description>`);
31878
+ var _tmpl$$5 = /* @__PURE__ */ template(`<div class="oasis-editor-dialog-input-group oasis-editor-dialog-input-group-grow"><label class=oasis-editor-dialog-label></label><input type=number class=oasis-editor-dialog-input step=1>`), _tmpl$2$1 = /* @__PURE__ */ template(`<label class=oasis-editor-dialog-style-toggle><input type=checkbox>`), _tmpl$3$1 = /* @__PURE__ */ template(`<button class="oasis-editor-dialog-button oasis-editor-dialog-button-secondary"data-testid=editor-table-properties-cancel>`), _tmpl$4$1 = /* @__PURE__ */ template(`<button class="oasis-editor-dialog-button oasis-editor-dialog-button-primary"data-testid=editor-table-properties-apply>`), _tmpl$5$1 = /* @__PURE__ */ template(`<div class=oasis-editor-dialog-row><label class="oasis-editor-dialog-input-group oasis-editor-dialog-input-group-grow"><span class=oasis-editor-dialog-label></span><select class=oasis-editor-dialog-input data-testid=editor-table-properties-floating-h-anchor><option value=margin></option><option value=page></option><option value=text></option></select></label><label class="oasis-editor-dialog-input-group oasis-editor-dialog-input-group-grow"><span class=oasis-editor-dialog-label></span><select class=oasis-editor-dialog-input data-testid=editor-table-properties-floating-v-anchor><option value=margin></option><option value=page></option><option value=text>`), _tmpl$6$1 = /* @__PURE__ */ template(`<div class=oasis-editor-dialog-row><label class="oasis-editor-dialog-input-group oasis-editor-dialog-input-group-grow"><span class=oasis-editor-dialog-label></span><select class=oasis-editor-dialog-input data-testid=editor-table-properties-floating-x-align><option value></option></select></label><label class="oasis-editor-dialog-input-group oasis-editor-dialog-input-group-grow"><span class=oasis-editor-dialog-label></span><select class=oasis-editor-dialog-input data-testid=editor-table-properties-floating-y-align><option value>`), _tmpl$7 = /* @__PURE__ */ template(`<div class=oasis-editor-dialog-row>`), _tmpl$8 = /* @__PURE__ */ template(`<div class=oasis-editor-table-properties-panel><fieldset class=oasis-editor-font-dialog-fieldset><legend></legend><div class=oasis-editor-dialog-row><div class=oasis-editor-dialog-input-group><label class=oasis-editor-dialog-label></label><select class=oasis-editor-dialog-input data-testid=editor-table-properties-table-width-unit><option value=points></option><option value=percent></option></select></div></div></fieldset><fieldset class=oasis-editor-font-dialog-fieldset><legend></legend><div class=oasis-editor-dialog-style-row></div><div class=oasis-editor-dialog-row></div></fieldset><fieldset class=oasis-editor-font-dialog-fieldset><legend></legend><div class=oasis-editor-dialog-style-row>`), _tmpl$9 = /* @__PURE__ */ template(`<label class=oasis-editor-dialog-style-toggle><input type=radio name=table-align>`), _tmpl$0 = /* @__PURE__ */ template(`<option>`), _tmpl$1 = /* @__PURE__ */ template(`<div class=oasis-editor-table-properties-panel><div class=oasis-editor-dialog-row><div class="oasis-editor-dialog-input-group oasis-editor-dialog-input-group-grow"><label class=oasis-editor-dialog-label></label><select class=oasis-editor-dialog-input data-testid=editor-table-properties-row-height-rule><option value></option><option value=atLeast></option><option value=exact></option></select></div></div><div class=oasis-editor-dialog-style-row>`), _tmpl$10 = /* @__PURE__ */ template(`<div class=oasis-editor-table-properties-panel><div class=oasis-editor-dialog-row>`), _tmpl$11 = /* @__PURE__ */ template(`<div class=oasis-editor-table-properties-panel><div class=oasis-editor-dialog-row><div class="oasis-editor-dialog-input-group oasis-editor-dialog-input-group-grow"><label class=oasis-editor-dialog-label></label><select class=oasis-editor-dialog-input data-testid=editor-table-properties-cell-valign><option value></option><option value=top></option><option value=middle></option><option value=bottom></option></select></div><div class="oasis-editor-dialog-input-group oasis-editor-dialog-input-group-grow"><label class=oasis-editor-dialog-label></label><select class=oasis-editor-dialog-input data-testid=editor-table-properties-cell-direction><option value></option><option value=lrTb>lrTb</option><option value=tbRl>tbRl</option><option value=btLr>btLr</option><option value=lrTbV>lrTbV</option><option value=tbRlV>tbRlV</option></select></div></div><fieldset class=oasis-editor-font-dialog-fieldset><legend></legend><div class=oasis-editor-dialog-style-row></div></fieldset><fieldset class=oasis-editor-font-dialog-fieldset><legend></legend><div class=oasis-editor-dialog-row></div></fieldset><fieldset class=oasis-editor-font-dialog-fieldset><legend></legend><div class=oasis-editor-dialog-row><div class="oasis-editor-dialog-input-group oasis-editor-dialog-input-group-grow"><label class=oasis-editor-dialog-label></label><select class=oasis-editor-dialog-input data-testid=editor-table-properties-border-style><option value=none></option><option value=solid></option><option value=dashed></option><option value=dotted></option></select></div><div class=oasis-editor-dialog-input-group><label class=oasis-editor-dialog-label></label><input type=color class=oasis-editor-dialog-input data-testid=editor-table-properties-border-color></div><div class=oasis-editor-dialog-input-group><label class=oasis-editor-dialog-label></label><input type=color class=oasis-editor-dialog-input data-testid=editor-table-properties-shading></div></div><div class=oasis-editor-dialog-style-row></div><div class=oasis-editor-table-properties-cell-preview data-testid=editor-table-properties-cell-preview>`), _tmpl$12 = /* @__PURE__ */ template(`<div class=oasis-editor-table-properties-panel><div class=oasis-editor-dialog-input-group><label class=oasis-editor-dialog-label></label><input class=oasis-editor-dialog-input data-testid=editor-table-properties-alt-title></div><div class=oasis-editor-dialog-input-group><label class=oasis-editor-dialog-label></label><textarea class="oasis-editor-dialog-input oasis-editor-table-properties-textarea"data-testid=editor-table-properties-alt-description>`);
31623
31879
  const DEFAULT_BORDER_WIDTH_PT = 0.5;
31624
31880
  const DEFAULT_BORDER_COLOR = "#000000";
31625
31881
  function parseNumber(value) {
@@ -31649,6 +31905,17 @@ function TablePropertiesDialog(props) {
31649
31905
  const [tableAlign, setTableAlign] = createSignal("");
31650
31906
  const [tableIndentLeft, setTableIndentLeft] = createSignal("");
31651
31907
  const [tableWrapping, setTableWrapping] = createSignal("none");
31908
+ const [floatingHorizontalAnchor, setFloatingHorizontalAnchor] = createSignal("margin");
31909
+ const [floatingVerticalAnchor, setFloatingVerticalAnchor] = createSignal("text");
31910
+ const [floatingX, setFloatingX] = createSignal("");
31911
+ const [floatingY, setFloatingY] = createSignal("");
31912
+ const [floatingXAlign, setFloatingXAlign] = createSignal("");
31913
+ const [floatingYAlign, setFloatingYAlign] = createSignal("");
31914
+ const [floatingDistanceTop, setFloatingDistanceTop] = createSignal("");
31915
+ const [floatingDistanceRight, setFloatingDistanceRight] = createSignal("");
31916
+ const [floatingDistanceBottom, setFloatingDistanceBottom] = createSignal("");
31917
+ const [floatingDistanceLeft, setFloatingDistanceLeft] = createSignal("");
31918
+ const [floatingOverlap, setFloatingOverlap] = createSignal("overlap");
31652
31919
  const [rowHeight, setRowHeight] = createSignal("");
31653
31920
  const [rowHeightRule, setRowHeightRule] = createSignal("");
31654
31921
  const [repeatHeader, setRepeatHeader] = createSignal(false);
@@ -31672,6 +31939,10 @@ function TablePropertiesDialog(props) {
31672
31939
  const [borderRight, setBorderRight] = createSignal(false);
31673
31940
  const [borderBottom, setBorderBottom] = createSignal(false);
31674
31941
  const [borderLeft, setBorderLeft] = createSignal(false);
31942
+ const [borderStart, setBorderStart] = createSignal(false);
31943
+ const [borderEnd, setBorderEnd] = createSignal(false);
31944
+ const [borderTlBr, setBorderTlBr] = createSignal(false);
31945
+ const [borderTrBl, setBorderTrBl] = createSignal(false);
31675
31946
  const [shading, setShading] = createSignal("");
31676
31947
  const [altTitle, setAltTitle] = createSignal("");
31677
31948
  const [altDescription, setAltDescription] = createSignal("");
@@ -31683,6 +31954,17 @@ function TablePropertiesDialog(props) {
31683
31954
  setTableAlign(props.initial.tableAlign);
31684
31955
  setTableIndentLeft(props.initial.tableIndentLeft);
31685
31956
  setTableWrapping(props.initial.tableWrapping);
31957
+ setFloatingHorizontalAnchor(props.initial.floatingHorizontalAnchor);
31958
+ setFloatingVerticalAnchor(props.initial.floatingVerticalAnchor);
31959
+ setFloatingX(props.initial.floatingX);
31960
+ setFloatingY(props.initial.floatingY);
31961
+ setFloatingXAlign(props.initial.floatingXAlign);
31962
+ setFloatingYAlign(props.initial.floatingYAlign);
31963
+ setFloatingDistanceTop(props.initial.floatingDistanceTop);
31964
+ setFloatingDistanceRight(props.initial.floatingDistanceRight);
31965
+ setFloatingDistanceBottom(props.initial.floatingDistanceBottom);
31966
+ setFloatingDistanceLeft(props.initial.floatingDistanceLeft);
31967
+ setFloatingOverlap(props.initial.floatingOverlap);
31686
31968
  setRowHeight(props.initial.rowHeight);
31687
31969
  setRowHeightRule(props.initial.rowHeightRule);
31688
31970
  setRepeatHeader(props.initial.repeatHeader);
@@ -31706,6 +31988,10 @@ function TablePropertiesDialog(props) {
31706
31988
  setBorderRight(props.initial.borderRight);
31707
31989
  setBorderBottom(props.initial.borderBottom);
31708
31990
  setBorderLeft(props.initial.borderLeft);
31991
+ setBorderStart(props.initial.borderStart);
31992
+ setBorderEnd(props.initial.borderEnd);
31993
+ setBorderTlBr(props.initial.borderTopLeftToBottomRight);
31994
+ setBorderTrBl(props.initial.borderTopRightToBottomLeft);
31709
31995
  setShading(props.initial.shading);
31710
31996
  setAltTitle(props.initial.altTitle);
31711
31997
  setAltDescription(props.initial.altDescription);
@@ -31727,6 +32013,25 @@ function TablePropertiesDialog(props) {
31727
32013
  tableWidth: parseWidth(tableWidth(), tableWidthUnit()),
31728
32014
  tableAlign: tableAlign() || null,
31729
32015
  tableIndentLeft: parseWidth(tableIndentLeft(), "points"),
32016
+ tableFloating: tableWrapping() === "around" ? {
32017
+ horizontalAnchor: floatingHorizontalAnchor(),
32018
+ verticalAnchor: floatingVerticalAnchor(),
32019
+ ...floatingXAlign() ? {
32020
+ xAlign: floatingXAlign()
32021
+ } : {
32022
+ x: parseNumber(floatingX()) ?? 0
32023
+ },
32024
+ ...floatingYAlign() ? {
32025
+ yAlign: floatingYAlign()
32026
+ } : {
32027
+ y: parseNumber(floatingY()) ?? 0
32028
+ },
32029
+ distanceTop: parseNumber(floatingDistanceTop()) ?? 0,
32030
+ distanceRight: parseNumber(floatingDistanceRight()) ?? 0,
32031
+ distanceBottom: parseNumber(floatingDistanceBottom()) ?? 0,
32032
+ distanceLeft: parseNumber(floatingDistanceLeft()) ?? 0
32033
+ } : null,
32034
+ tableOverlap: tableWrapping() === "around" ? floatingOverlap() : null,
31730
32035
  rowHeight: parseWidth(rowHeight(), "points"),
31731
32036
  rowHeightRule: rowHeightRule() || null,
31732
32037
  repeatHeader: repeatHeader(),
@@ -31749,7 +32054,11 @@ function TablePropertiesDialog(props) {
31749
32054
  top: borderTop() ? border : null,
31750
32055
  right: borderRight() ? border : null,
31751
32056
  bottom: borderBottom() ? border : null,
31752
- left: borderLeft() ? border : null
32057
+ left: borderLeft() ? border : null,
32058
+ start: borderStart() ? border : null,
32059
+ end: borderEnd() ? border : null,
32060
+ topLeftToBottomRight: borderTlBr() ? border : null,
32061
+ topRightToBottomLeft: borderTrBl() ? border : null
31753
32062
  },
31754
32063
  shading: shading().trim() || null,
31755
32064
  altTitle: altTitle().trim() || null,
@@ -31757,10 +32066,11 @@ function TablePropertiesDialog(props) {
31757
32066
  }, props.initial);
31758
32067
  props.onClose();
31759
32068
  };
31760
- const numericInput = (label, value, setter, testId, disabled = false) => (() => {
32069
+ const numericInput = (label, value, setter, testId, disabled = false, allowNegative = false) => (() => {
31761
32070
  var _el$ = _tmpl$$5(), _el$2 = _el$.firstChild, _el$3 = _el$2.nextSibling;
31762
32071
  insert(_el$2, label);
31763
32072
  _el$3.$$input = (e) => setter(e.currentTarget.value);
32073
+ setAttribute(_el$3, "min", allowNegative ? void 0 : "0");
31764
32074
  _el$3.disabled = disabled;
31765
32075
  setAttribute(_el$3, "data-testid", testId);
31766
32076
  createRenderEffect(() => _el$3.value = value());
@@ -31817,7 +32127,7 @@ function TablePropertiesDialog(props) {
31817
32127
  label: t("table.tabTable"),
31818
32128
  testId: "editor-table-properties-tab-table",
31819
32129
  panel: (() => {
31820
- var _el$8 = _tmpl$5$1(), _el$9 = _el$8.firstChild, _el$0 = _el$9.firstChild, _el$1 = _el$0.nextSibling, _el$10 = _el$1.firstChild, _el$11 = _el$10.firstChild, _el$12 = _el$11.nextSibling, _el$13 = _el$12.firstChild, _el$14 = _el$13.nextSibling, _el$15 = _el$9.nextSibling, _el$16 = _el$15.firstChild, _el$17 = _el$16.nextSibling, _el$18 = _el$17.nextSibling, _el$19 = _el$15.nextSibling, _el$20 = _el$19.firstChild, _el$21 = _el$20.nextSibling, _el$22 = _el$21.firstChild, _el$23 = _el$21.nextSibling;
32130
+ var _el$8 = _tmpl$8(), _el$9 = _el$8.firstChild, _el$0 = _el$9.firstChild, _el$1 = _el$0.nextSibling, _el$10 = _el$1.firstChild, _el$11 = _el$10.firstChild, _el$12 = _el$11.nextSibling, _el$13 = _el$12.firstChild, _el$14 = _el$13.nextSibling, _el$15 = _el$9.nextSibling, _el$16 = _el$15.firstChild, _el$17 = _el$16.nextSibling, _el$18 = _el$17.nextSibling, _el$19 = _el$15.nextSibling, _el$20 = _el$19.firstChild, _el$21 = _el$20.nextSibling;
31821
32131
  insert(_el$0, () => t("table.sizeSection"));
31822
32132
  insert(_el$1, () => numericInput(t("table.preferredWidth"), tableWidth, setTableWidth, "editor-table-properties-table-width"), _el$10);
31823
32133
  insert(_el$11, () => t("table.measureIn"));
@@ -31826,19 +32136,72 @@ function TablePropertiesDialog(props) {
31826
32136
  insert(_el$14, () => t("table.percent"));
31827
32137
  insert(_el$16, () => t("table.alignmentSection"));
31828
32138
  insert(_el$17, () => ["left", "center", "right"].map((align) => (() => {
31829
- var _el$24 = _tmpl$6$1(), _el$25 = _el$24.firstChild;
31830
- _el$25.addEventListener("change", () => setTableAlign(align));
31831
- setAttribute(_el$25, "data-testid", `editor-table-properties-align-${align}`);
31832
- insert(_el$24, () => t(`table.align${align[0].toUpperCase()}${align.slice(1)}`), null);
31833
- createRenderEffect(() => _el$25.checked = tableAlign() === align);
31834
- return _el$24;
32139
+ var _el$45 = _tmpl$9(), _el$46 = _el$45.firstChild;
32140
+ _el$46.addEventListener("change", () => setTableAlign(align));
32141
+ setAttribute(_el$46, "data-testid", `editor-table-properties-align-${align}`);
32142
+ insert(_el$45, () => t(`table.align${align[0].toUpperCase()}${align.slice(1)}`), null);
32143
+ createRenderEffect(() => _el$46.checked = tableAlign() === align);
32144
+ return _el$45;
31835
32145
  })()));
31836
32146
  insert(_el$18, () => numericInput(t("table.indentFromLeft"), tableIndentLeft, setTableIndentLeft, "editor-table-properties-indent-left"));
31837
32147
  insert(_el$20, () => t("table.textWrappingSection"));
31838
- insert(_el$21, () => checkbox(t("table.wrapNone"), () => tableWrapping() === "none", () => setTableWrapping("none"), "editor-table-properties-wrap-none"), _el$22);
31839
- insert(_el$21, () => checkbox(t("table.wrapAround"), () => tableWrapping() === "around", () => setTableWrapping("around"), "editor-table-properties-wrap-around", !props.initial.floatingSummary), _el$22);
31840
- insert(_el$22, () => t("table.positioning"));
31841
- insert(_el$23, () => props.initial.floatingSummary || t("table.positioningReadOnly"));
32148
+ insert(_el$21, () => checkbox(t("table.wrapNone"), () => tableWrapping() === "none", () => setTableWrapping("none"), "editor-table-properties-wrap-none"), null);
32149
+ insert(_el$21, () => checkbox(t("table.wrapAround"), () => tableWrapping() === "around", () => setTableWrapping("around"), "editor-table-properties-wrap-around"), null);
32150
+ insert(_el$19, createComponent(Show, {
32151
+ get when() {
32152
+ return tableWrapping() === "around";
32153
+ },
32154
+ get children() {
32155
+ return [(() => {
32156
+ var _el$22 = _tmpl$5$1(), _el$23 = _el$22.firstChild, _el$24 = _el$23.firstChild, _el$25 = _el$24.nextSibling, _el$26 = _el$25.firstChild, _el$27 = _el$26.nextSibling, _el$28 = _el$27.nextSibling, _el$29 = _el$23.nextSibling, _el$30 = _el$29.firstChild, _el$31 = _el$30.nextSibling, _el$32 = _el$31.firstChild, _el$33 = _el$32.nextSibling, _el$34 = _el$33.nextSibling;
32157
+ insert(_el$24, () => t("table.horizontalAnchor"));
32158
+ _el$25.addEventListener("change", (e) => setFloatingHorizontalAnchor(e.currentTarget.value));
32159
+ insert(_el$26, () => t("table.anchorMargin"));
32160
+ insert(_el$27, () => t("table.anchorPage"));
32161
+ insert(_el$28, () => t("table.anchorText"));
32162
+ insert(_el$30, () => t("table.verticalAnchor"));
32163
+ _el$31.addEventListener("change", (e) => setFloatingVerticalAnchor(e.currentTarget.value));
32164
+ insert(_el$32, () => t("table.anchorMargin"));
32165
+ insert(_el$33, () => t("table.anchorPage"));
32166
+ insert(_el$34, () => t("table.anchorText"));
32167
+ createRenderEffect(() => _el$25.value = floatingHorizontalAnchor());
32168
+ createRenderEffect(() => _el$31.value = floatingVerticalAnchor());
32169
+ return _el$22;
32170
+ })(), (() => {
32171
+ var _el$35 = _tmpl$6$1(), _el$36 = _el$35.firstChild, _el$37 = _el$36.firstChild, _el$38 = _el$37.nextSibling, _el$39 = _el$38.firstChild, _el$40 = _el$36.nextSibling, _el$41 = _el$40.firstChild, _el$42 = _el$41.nextSibling, _el$43 = _el$42.firstChild;
32172
+ insert(_el$35, () => numericInput(t("table.positionX"), floatingX, setFloatingX, "editor-table-properties-floating-x", Boolean(floatingXAlign()), true), _el$36);
32173
+ insert(_el$35, () => numericInput(t("table.positionY"), floatingY, setFloatingY, "editor-table-properties-floating-y", Boolean(floatingYAlign()), true), _el$36);
32174
+ insert(_el$37, () => t("table.horizontalAlignment"));
32175
+ _el$38.addEventListener("change", (e) => setFloatingXAlign(e.currentTarget.value));
32176
+ insert(_el$39, () => t("table.explicitOffset"));
32177
+ insert(_el$38, () => ["left", "center", "right", "inside", "outside"].map((value) => (() => {
32178
+ var _el$47 = _tmpl$0();
32179
+ _el$47.value = value;
32180
+ insert(_el$47, value);
32181
+ return _el$47;
32182
+ })()), null);
32183
+ insert(_el$41, () => t("table.verticalAlignment"));
32184
+ _el$42.addEventListener("change", (e) => setFloatingYAlign(e.currentTarget.value));
32185
+ insert(_el$43, () => t("table.explicitOffset"));
32186
+ insert(_el$42, () => ["top", "center", "bottom", "inside", "outside"].map((value) => (() => {
32187
+ var _el$48 = _tmpl$0();
32188
+ _el$48.value = value;
32189
+ insert(_el$48, value);
32190
+ return _el$48;
32191
+ })()), null);
32192
+ createRenderEffect(() => _el$38.value = floatingXAlign());
32193
+ createRenderEffect(() => _el$42.value = floatingYAlign());
32194
+ return _el$35;
32195
+ })(), (() => {
32196
+ var _el$44 = _tmpl$7();
32197
+ insert(_el$44, () => numericInput(t("table.distanceTop"), floatingDistanceTop, setFloatingDistanceTop, "editor-table-properties-floating-distance-top"), null);
32198
+ insert(_el$44, () => numericInput(t("table.distanceRight"), floatingDistanceRight, setFloatingDistanceRight, "editor-table-properties-floating-distance-right"), null);
32199
+ insert(_el$44, () => numericInput(t("table.distanceBottom"), floatingDistanceBottom, setFloatingDistanceBottom, "editor-table-properties-floating-distance-bottom"), null);
32200
+ insert(_el$44, () => numericInput(t("table.distanceLeft"), floatingDistanceLeft, setFloatingDistanceLeft, "editor-table-properties-floating-distance-left"), null);
32201
+ return _el$44;
32202
+ })(), memo(() => checkbox(t("table.allowOverlap"), () => floatingOverlap() === "overlap", (value) => setFloatingOverlap(value ? "overlap" : "never"), "editor-table-properties-floating-overlap"))];
32203
+ }
32204
+ }), null);
31842
32205
  createRenderEffect(() => _el$12.value = tableWidthUnit());
31843
32206
  return _el$8;
31844
32207
  })()
@@ -31847,56 +32210,56 @@ function TablePropertiesDialog(props) {
31847
32210
  label: t("table.tabRow"),
31848
32211
  testId: "editor-table-properties-tab-row",
31849
32212
  panel: (() => {
31850
- var _el$26 = _tmpl$7(), _el$27 = _el$26.firstChild, _el$28 = _el$27.firstChild, _el$29 = _el$28.firstChild, _el$30 = _el$29.nextSibling, _el$31 = _el$30.firstChild, _el$32 = _el$31.nextSibling, _el$33 = _el$32.nextSibling, _el$34 = _el$27.nextSibling;
31851
- insert(_el$27, () => numericInput(t("table.rowHeight"), rowHeight, setRowHeight, "editor-table-properties-row-height"), _el$28);
31852
- insert(_el$29, () => t("table.rowHeightRule"));
31853
- _el$30.addEventListener("change", (e) => setRowHeightRule(e.currentTarget.value));
31854
- insert(_el$31, () => t("table.rowAuto"));
31855
- insert(_el$32, () => t("table.rowAtLeast"));
31856
- insert(_el$33, () => t("table.rowExactly"));
31857
- insert(_el$34, () => checkbox(t("table.repeatHeader"), repeatHeader, setRepeatHeader, "editor-table-properties-repeat-header"), null);
31858
- insert(_el$34, () => checkbox(t("table.allowBreakAcrossPages"), allowBreakAcrossPages, setAllowBreakAcrossPages, "editor-table-properties-allow-break"), null);
31859
- insert(_el$34, () => checkbox(t("table.hiddenRow"), hiddenRow, setHiddenRow, "editor-table-properties-hidden-row"), null);
31860
- createRenderEffect(() => _el$30.value = rowHeightRule());
31861
- return _el$26;
32213
+ var _el$49 = _tmpl$1(), _el$50 = _el$49.firstChild, _el$51 = _el$50.firstChild, _el$52 = _el$51.firstChild, _el$53 = _el$52.nextSibling, _el$54 = _el$53.firstChild, _el$55 = _el$54.nextSibling, _el$56 = _el$55.nextSibling, _el$57 = _el$50.nextSibling;
32214
+ insert(_el$50, () => numericInput(t("table.rowHeight"), rowHeight, setRowHeight, "editor-table-properties-row-height"), _el$51);
32215
+ insert(_el$52, () => t("table.rowHeightRule"));
32216
+ _el$53.addEventListener("change", (e) => setRowHeightRule(e.currentTarget.value));
32217
+ insert(_el$54, () => t("table.rowAuto"));
32218
+ insert(_el$55, () => t("table.rowAtLeast"));
32219
+ insert(_el$56, () => t("table.rowExactly"));
32220
+ insert(_el$57, () => checkbox(t("table.repeatHeader"), repeatHeader, setRepeatHeader, "editor-table-properties-repeat-header"), null);
32221
+ insert(_el$57, () => checkbox(t("table.allowBreakAcrossPages"), allowBreakAcrossPages, setAllowBreakAcrossPages, "editor-table-properties-allow-break"), null);
32222
+ insert(_el$57, () => checkbox(t("table.hiddenRow"), hiddenRow, setHiddenRow, "editor-table-properties-hidden-row"), null);
32223
+ createRenderEffect(() => _el$53.value = rowHeightRule());
32224
+ return _el$49;
31862
32225
  })()
31863
32226
  }, {
31864
32227
  id: "column",
31865
32228
  label: t("table.tabColumn"),
31866
32229
  testId: "editor-table-properties-tab-column",
31867
32230
  panel: (() => {
31868
- var _el$35 = _tmpl$8(), _el$36 = _el$35.firstChild;
31869
- insert(_el$36, () => numericInput(t("table.columnWidth"), columnWidth, setColumnWidth, "editor-table-properties-column-width"));
31870
- return _el$35;
32231
+ var _el$58 = _tmpl$10(), _el$59 = _el$58.firstChild;
32232
+ insert(_el$59, () => numericInput(t("table.columnWidth"), columnWidth, setColumnWidth, "editor-table-properties-column-width"));
32233
+ return _el$58;
31871
32234
  })()
31872
32235
  }, {
31873
32236
  id: "cell",
31874
32237
  label: t("table.tabCell"),
31875
32238
  testId: "editor-table-properties-tab-cell",
31876
32239
  panel: (() => {
31877
- var _el$37 = _tmpl$9(), _el$38 = _el$37.firstChild, _el$39 = _el$38.firstChild, _el$40 = _el$39.firstChild, _el$41 = _el$40.nextSibling, _el$42 = _el$41.firstChild, _el$43 = _el$42.nextSibling, _el$44 = _el$43.nextSibling, _el$45 = _el$44.nextSibling, _el$46 = _el$39.nextSibling, _el$47 = _el$46.firstChild, _el$48 = _el$47.nextSibling, _el$49 = _el$48.firstChild, _el$50 = _el$38.nextSibling, _el$51 = _el$50.firstChild, _el$52 = _el$51.nextSibling, _el$53 = _el$50.nextSibling, _el$54 = _el$53.firstChild, _el$55 = _el$54.nextSibling, _el$56 = _el$53.nextSibling, _el$57 = _el$56.firstChild, _el$58 = _el$57.nextSibling, _el$59 = _el$58.firstChild, _el$60 = _el$59.firstChild, _el$61 = _el$60.nextSibling, _el$62 = _el$61.firstChild, _el$63 = _el$62.nextSibling, _el$64 = _el$63.nextSibling, _el$65 = _el$64.nextSibling, _el$66 = _el$59.nextSibling, _el$67 = _el$66.firstChild, _el$68 = _el$67.nextSibling, _el$69 = _el$66.nextSibling, _el$70 = _el$69.firstChild, _el$71 = _el$70.nextSibling, _el$72 = _el$58.nextSibling, _el$73 = _el$72.nextSibling;
31878
- insert(_el$38, () => numericInput(t("table.cellWidth"), cellWidth, setCellWidth, "editor-table-properties-cell-width"), _el$39);
31879
- insert(_el$40, () => t("table.verticalAlignment"));
31880
- _el$41.addEventListener("change", (e) => setCellVerticalAlign(e.currentTarget.value));
31881
- insert(_el$42, () => t("table.inherit"));
31882
- insert(_el$43, () => t("table.valignTop"));
31883
- insert(_el$44, () => t("table.valignMiddle"));
31884
- insert(_el$45, () => t("table.valignBottom"));
31885
- insert(_el$47, () => t("table.textDirection"));
31886
- _el$48.addEventListener("change", (e) => setCellTextDirection(e.currentTarget.value));
31887
- insert(_el$49, () => t("table.inherit"));
31888
- insert(_el$51, () => t("table.options"));
31889
- insert(_el$52, () => checkbox(t("table.noWrap"), cellNoWrap, setCellNoWrap, "editor-table-properties-cell-nowrap"), null);
31890
- insert(_el$52, () => checkbox(t("table.fitText"), cellFitText, setCellFitText, "editor-table-properties-cell-fit-text"), null);
31891
- insert(_el$52, () => checkbox(t("table.hideMark"), cellHideMark, setCellHideMark, "editor-table-properties-cell-hide-mark"), null);
31892
- insert(_el$54, () => t("table.cellMargins"));
31893
- insert(_el$55, () => numericInput(t("paragraph.borderSideTop"), marginTop, setMarginTop, "editor-table-properties-margin-top"), null);
31894
- insert(_el$55, () => numericInput(t("paragraph.borderSideRight"), marginRight, setMarginRight, "editor-table-properties-margin-right"), null);
31895
- insert(_el$55, () => numericInput(t("paragraph.borderSideBottom"), marginBottom, setMarginBottom, "editor-table-properties-margin-bottom"), null);
31896
- insert(_el$55, () => numericInput(t("paragraph.borderSideLeft"), marginLeft, setMarginLeft, "editor-table-properties-margin-left"), null);
31897
- insert(_el$57, () => t("paragraph.bordersSection"));
31898
- insert(_el$60, () => t("paragraph.borderStyleLabel"));
31899
- _el$61.addEventListener("change", (e) => {
32240
+ var _el$60 = _tmpl$11(), _el$61 = _el$60.firstChild, _el$62 = _el$61.firstChild, _el$63 = _el$62.firstChild, _el$64 = _el$63.nextSibling, _el$65 = _el$64.firstChild, _el$66 = _el$65.nextSibling, _el$67 = _el$66.nextSibling, _el$68 = _el$67.nextSibling, _el$69 = _el$62.nextSibling, _el$70 = _el$69.firstChild, _el$71 = _el$70.nextSibling, _el$72 = _el$71.firstChild, _el$73 = _el$61.nextSibling, _el$74 = _el$73.firstChild, _el$75 = _el$74.nextSibling, _el$76 = _el$73.nextSibling, _el$77 = _el$76.firstChild, _el$78 = _el$77.nextSibling, _el$79 = _el$76.nextSibling, _el$80 = _el$79.firstChild, _el$81 = _el$80.nextSibling, _el$82 = _el$81.firstChild, _el$83 = _el$82.firstChild, _el$84 = _el$83.nextSibling, _el$85 = _el$84.firstChild, _el$86 = _el$85.nextSibling, _el$87 = _el$86.nextSibling, _el$88 = _el$87.nextSibling, _el$89 = _el$82.nextSibling, _el$90 = _el$89.firstChild, _el$91 = _el$90.nextSibling, _el$92 = _el$89.nextSibling, _el$93 = _el$92.firstChild, _el$94 = _el$93.nextSibling, _el$95 = _el$81.nextSibling, _el$96 = _el$95.nextSibling;
32241
+ insert(_el$61, () => numericInput(t("table.cellWidth"), cellWidth, setCellWidth, "editor-table-properties-cell-width"), _el$62);
32242
+ insert(_el$63, () => t("table.verticalAlignment"));
32243
+ _el$64.addEventListener("change", (e) => setCellVerticalAlign(e.currentTarget.value));
32244
+ insert(_el$65, () => t("table.inherit"));
32245
+ insert(_el$66, () => t("table.valignTop"));
32246
+ insert(_el$67, () => t("table.valignMiddle"));
32247
+ insert(_el$68, () => t("table.valignBottom"));
32248
+ insert(_el$70, () => t("table.textDirection"));
32249
+ _el$71.addEventListener("change", (e) => setCellTextDirection(e.currentTarget.value));
32250
+ insert(_el$72, () => t("table.inherit"));
32251
+ insert(_el$74, () => t("table.options"));
32252
+ insert(_el$75, () => checkbox(t("table.noWrap"), cellNoWrap, setCellNoWrap, "editor-table-properties-cell-nowrap"), null);
32253
+ insert(_el$75, () => checkbox(t("table.fitText"), cellFitText, setCellFitText, "editor-table-properties-cell-fit-text"), null);
32254
+ insert(_el$75, () => checkbox(t("table.hideMark"), cellHideMark, setCellHideMark, "editor-table-properties-cell-hide-mark"), null);
32255
+ insert(_el$77, () => t("table.cellMargins"));
32256
+ insert(_el$78, () => numericInput(t("paragraph.borderSideTop"), marginTop, setMarginTop, "editor-table-properties-margin-top"), null);
32257
+ insert(_el$78, () => numericInput(t("paragraph.borderSideRight"), marginRight, setMarginRight, "editor-table-properties-margin-right"), null);
32258
+ insert(_el$78, () => numericInput(t("paragraph.borderSideBottom"), marginBottom, setMarginBottom, "editor-table-properties-margin-bottom"), null);
32259
+ insert(_el$78, () => numericInput(t("paragraph.borderSideLeft"), marginLeft, setMarginLeft, "editor-table-properties-margin-left"), null);
32260
+ insert(_el$80, () => t("paragraph.bordersSection"));
32261
+ insert(_el$83, () => t("paragraph.borderStyleLabel"));
32262
+ _el$84.addEventListener("change", (e) => {
31900
32263
  const next = e.currentTarget.value;
31901
32264
  setBorderStyle(next);
31902
32265
  if (next === "none") {
@@ -31904,6 +32267,10 @@ function TablePropertiesDialog(props) {
31904
32267
  setBorderRight(false);
31905
32268
  setBorderBottom(false);
31906
32269
  setBorderLeft(false);
32270
+ setBorderStart(false);
32271
+ setBorderEnd(false);
32272
+ setBorderTlBr(false);
32273
+ setBorderTrBl(false);
31907
32274
  } else if (!borderTop() && !borderRight() && !borderBottom() && !borderLeft()) {
31908
32275
  setBorderTop(true);
31909
32276
  setBorderRight(true);
@@ -31911,48 +32278,52 @@ function TablePropertiesDialog(props) {
31911
32278
  setBorderLeft(true);
31912
32279
  }
31913
32280
  });
31914
- insert(_el$62, () => t("paragraph.borderNone"));
31915
- insert(_el$63, () => t("paragraph.borderSolid"));
31916
- insert(_el$64, () => t("paragraph.borderDashed"));
31917
- insert(_el$65, () => t("paragraph.borderDotted"));
31918
- insert(_el$58, () => numericInput(t("paragraph.borderWidthLabel"), borderWidth, setBorderWidth, "editor-table-properties-border-width", borderStyle() === "none"), _el$66);
31919
- insert(_el$67, () => t("paragraph.borderColorLabel"));
31920
- _el$68.$$input = (e) => setBorderColor(e.currentTarget.value);
31921
- insert(_el$70, () => t("paragraph.shadingLabel"));
31922
- _el$71.$$input = (e) => setShading(e.currentTarget.value);
31923
- insert(_el$72, () => checkbox(t("paragraph.borderSideTop"), borderTop, setBorderTop, "editor-table-properties-border-top", borderStyle() === "none"), null);
31924
- insert(_el$72, () => checkbox(t("paragraph.borderSideRight"), borderRight, setBorderRight, "editor-table-properties-border-right", borderStyle() === "none"), null);
31925
- insert(_el$72, () => checkbox(t("paragraph.borderSideBottom"), borderBottom, setBorderBottom, "editor-table-properties-border-bottom", borderStyle() === "none"), null);
31926
- insert(_el$72, () => checkbox(t("paragraph.borderSideLeft"), borderLeft, setBorderLeft, "editor-table-properties-border-left", borderStyle() === "none"), null);
32281
+ insert(_el$85, () => t("paragraph.borderNone"));
32282
+ insert(_el$86, () => t("paragraph.borderSolid"));
32283
+ insert(_el$87, () => t("paragraph.borderDashed"));
32284
+ insert(_el$88, () => t("paragraph.borderDotted"));
32285
+ insert(_el$81, () => numericInput(t("paragraph.borderWidthLabel"), borderWidth, setBorderWidth, "editor-table-properties-border-width", borderStyle() === "none"), _el$89);
32286
+ insert(_el$90, () => t("paragraph.borderColorLabel"));
32287
+ _el$91.$$input = (e) => setBorderColor(e.currentTarget.value);
32288
+ insert(_el$93, () => t("paragraph.shadingLabel"));
32289
+ _el$94.$$input = (e) => setShading(e.currentTarget.value);
32290
+ insert(_el$95, () => checkbox(t("paragraph.borderSideTop"), borderTop, setBorderTop, "editor-table-properties-border-top", borderStyle() === "none"), null);
32291
+ insert(_el$95, () => checkbox(t("paragraph.borderSideRight"), borderRight, setBorderRight, "editor-table-properties-border-right", borderStyle() === "none"), null);
32292
+ insert(_el$95, () => checkbox(t("paragraph.borderSideBottom"), borderBottom, setBorderBottom, "editor-table-properties-border-bottom", borderStyle() === "none"), null);
32293
+ insert(_el$95, () => checkbox(t("paragraph.borderSideLeft"), borderLeft, setBorderLeft, "editor-table-properties-border-left", borderStyle() === "none"), null);
32294
+ insert(_el$95, () => checkbox(t("table.borderStart"), borderStart, setBorderStart, "editor-table-properties-border-start", borderStyle() === "none"), null);
32295
+ insert(_el$95, () => checkbox(t("table.borderEnd"), borderEnd, setBorderEnd, "editor-table-properties-border-end", borderStyle() === "none"), null);
32296
+ insert(_el$95, () => checkbox(t("table.borderTlBr"), borderTlBr, setBorderTlBr, "editor-table-properties-border-tlbr", borderStyle() === "none"), null);
32297
+ insert(_el$95, () => checkbox(t("table.borderTrBl"), borderTrBl, setBorderTrBl, "editor-table-properties-border-trbl", borderStyle() === "none"), null);
31927
32298
  createRenderEffect((_p$) => {
31928
32299
  var _v$ = borderStyle() === "none", _v$2 = borderPreview();
31929
- _v$ !== _p$.e && (_el$68.disabled = _p$.e = _v$);
31930
- _p$.t = style(_el$73, _v$2, _p$.t);
32300
+ _v$ !== _p$.e && (_el$91.disabled = _p$.e = _v$);
32301
+ _p$.t = style(_el$96, _v$2, _p$.t);
31931
32302
  return _p$;
31932
32303
  }, {
31933
32304
  e: void 0,
31934
32305
  t: void 0
31935
32306
  });
31936
- createRenderEffect(() => _el$41.value = cellVerticalAlign());
31937
- createRenderEffect(() => _el$48.value = cellTextDirection());
31938
- createRenderEffect(() => _el$61.value = borderStyle());
31939
- createRenderEffect(() => _el$68.value = borderColor() || DEFAULT_BORDER_COLOR);
31940
- createRenderEffect(() => _el$71.value = shading() || "#ffffff");
31941
- return _el$37;
32307
+ createRenderEffect(() => _el$64.value = cellVerticalAlign());
32308
+ createRenderEffect(() => _el$71.value = cellTextDirection());
32309
+ createRenderEffect(() => _el$84.value = borderStyle());
32310
+ createRenderEffect(() => _el$91.value = borderColor() || DEFAULT_BORDER_COLOR);
32311
+ createRenderEffect(() => _el$94.value = shading() || "#ffffff");
32312
+ return _el$60;
31942
32313
  })()
31943
32314
  }, {
31944
32315
  id: "altText",
31945
32316
  label: t("table.tabAltText"),
31946
32317
  testId: "editor-table-properties-tab-alt-text",
31947
32318
  panel: (() => {
31948
- var _el$74 = _tmpl$0(), _el$75 = _el$74.firstChild, _el$76 = _el$75.firstChild, _el$77 = _el$76.nextSibling, _el$78 = _el$75.nextSibling, _el$79 = _el$78.firstChild, _el$80 = _el$79.nextSibling;
31949
- insert(_el$76, () => t("table.altTitle"));
31950
- _el$77.$$input = (e) => setAltTitle(e.currentTarget.value);
31951
- insert(_el$79, () => t("table.altDescription"));
31952
- _el$80.$$input = (e) => setAltDescription(e.currentTarget.value);
31953
- createRenderEffect(() => _el$77.value = altTitle());
31954
- createRenderEffect(() => _el$80.value = altDescription());
31955
- return _el$74;
32319
+ var _el$97 = _tmpl$12(), _el$98 = _el$97.firstChild, _el$99 = _el$98.firstChild, _el$100 = _el$99.nextSibling, _el$101 = _el$98.nextSibling, _el$102 = _el$101.firstChild, _el$103 = _el$102.nextSibling;
32320
+ insert(_el$99, () => t("table.altTitle"));
32321
+ _el$100.$$input = (e) => setAltTitle(e.currentTarget.value);
32322
+ insert(_el$102, () => t("table.altDescription"));
32323
+ _el$103.$$input = (e) => setAltDescription(e.currentTarget.value);
32324
+ createRenderEffect(() => _el$100.value = altTitle());
32325
+ createRenderEffect(() => _el$103.value = altDescription());
32326
+ return _el$97;
31956
32327
  })()
31957
32328
  }];
31958
32329
  }
@@ -32810,6 +33181,35 @@ function serializeParagraphBorders(style2) {
32810
33181
  const DEFAULT_TABLE_BORDER_COLOR = "6F6F6F";
32811
33182
  const DEFAULT_TABLE_BORDER_WIDTH_PT = 0.75;
32812
33183
  const DEFAULT_CELL_PADDING_LEFT_RIGHT_PT = 5.4;
33184
+ function serializeRevisionAttrs(revision) {
33185
+ const numericId = /^\d+$/.test(revision.id) ? revision.id : String(
33186
+ Array.from(revision.id).reduce(
33187
+ (hash, character) => hash * 31 + character.charCodeAt(0) >>> 0,
33188
+ 0
33189
+ )
33190
+ );
33191
+ const date = Number.isFinite(revision.date) ? new Date(revision.date).toISOString() : (/* @__PURE__ */ new Date(0)).toISOString();
33192
+ return `w:id="${numericId}" w:author="${escapeXml(revision.author)}" w:date="${date}"`;
33193
+ }
33194
+ function serializeConditionalFlags(flags) {
33195
+ if (!flags || Object.keys(flags).length === 0) return "";
33196
+ const attributes = [
33197
+ ["firstRow", "firstRow"],
33198
+ ["lastRow", "lastRow"],
33199
+ ["firstColumn", "firstCol"],
33200
+ ["lastColumn", "lastCol"],
33201
+ ["oddVBand", "band1Vert"],
33202
+ ["evenVBand", "band2Vert"],
33203
+ ["oddHBand", "band1Horz"],
33204
+ ["evenHBand", "band2Horz"],
33205
+ ["firstRowFirstColumn", "nwCell"],
33206
+ ["firstRowLastColumn", "neCell"],
33207
+ ["lastRowFirstColumn", "swCell"],
33208
+ ["lastRowLastColumn", "seCell"]
33209
+ ];
33210
+ const xml = attributes.filter(([, key]) => flags[key] !== void 0).map(([name, key]) => `w:${name}="${flags[key] ? "1" : "0"}"`).join(" ");
33211
+ return xml ? `<w:cnfStyle ${xml}/>` : "";
33212
+ }
32813
33213
  function serializeOnOffElement(tag, value) {
32814
33214
  if (value === void 0) {
32815
33215
  return "";
@@ -32900,7 +33300,9 @@ function serializeTableDefaultCellMargins(margins) {
32900
33300
  const parts = [];
32901
33301
  const edge = (name, value) => {
32902
33302
  if (value !== void 0 && Number.isFinite(value)) {
32903
- parts.push(`<w:${name} w:w="${pointsToTwips(value) ?? 0}" w:type="dxa"/>`);
33303
+ parts.push(
33304
+ `<w:${name} w:w="${pointsToTwips(value) ?? 0}" w:type="dxa"/>`
33305
+ );
32904
33306
  }
32905
33307
  };
32906
33308
  edge("top", margins.top);
@@ -32912,9 +33314,11 @@ function serializeTableDefaultCellMargins(margins) {
32912
33314
  return parts.length > 0 ? `<w:tblCellMar>${parts.join("")}</w:tblCellMar>` : "";
32913
33315
  }
32914
33316
  function serializeTableCellProperties(cell, fallbackWidthPt) {
32915
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
33317
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
32916
33318
  const colSpan = Math.max(1, Math.floor(cell.colSpan ?? 1));
32917
33319
  const parts = [];
33320
+ const conditional = serializeConditionalFlags(cell.conditionalStyle);
33321
+ if (conditional) parts.push(conditional);
32918
33322
  const widthXml = serializeCellWidth(((_a = cell.style) == null ? void 0 : _a.width) ?? fallbackWidthPt);
32919
33323
  if (widthXml) {
32920
33324
  parts.push(widthXml);
@@ -32956,11 +33360,33 @@ function serializeTableCellProperties(cell, fallbackWidthPt) {
32956
33360
  if (hideMark) {
32957
33361
  parts.push(hideMark);
32958
33362
  }
32959
- if ((_j = (_i = cell.style) == null ? void 0 : _i.revisionXml) == null ? void 0 : _j.length) {
32960
- parts.push(...cell.style.revisionXml);
33363
+ if ((_i = cell.style) == null ? void 0 : _i.propertyRevision) {
33364
+ const revision = cell.style.propertyRevision;
33365
+ const previous = serializeTableCellProperties({
33366
+ ...cell,
33367
+ style: revision.previous
33368
+ });
33369
+ parts.push(
33370
+ `<w:tcPrChange ${serializeRevisionAttrs(revision)}>${previous}</w:tcPrChange>`
33371
+ );
33372
+ }
33373
+ if ((_j = cell.style) == null ? void 0 : _j.revision) {
33374
+ const revision = cell.style.revision;
33375
+ const element = revision.type === "insert" ? "cellIns" : revision.type === "delete" ? "cellDel" : "cellMerge";
33376
+ const mergeAttrs = revision.type === "merge" ? `${((_k = revision.previous) == null ? void 0 : _k.vMerge) ? ` w:vMergeOrig="${revision.previous.vMerge === "restart" ? "rest" : "cont"}"` : ""}${cell.vMerge ? ` w:vMerge="${cell.vMerge === "restart" ? "rest" : "cont"}"` : ""}` : "";
33377
+ parts.push(
33378
+ `<w:${element} ${serializeRevisionAttrs(revision)}${mergeAttrs}/>`
33379
+ );
32961
33380
  }
32962
33381
  return parts.length > 0 ? `<w:tcPr>${parts.join("")}</w:tcPr>` : "";
32963
33382
  }
33383
+ function serializeTableCellStyleXml(style2) {
33384
+ return serializeTableCellProperties({
33385
+ id: "table-style-cell",
33386
+ blocks: [],
33387
+ style: style2
33388
+ });
33389
+ }
32964
33390
  function serializeGridSkip(tag, value) {
32965
33391
  if (value === void 0 || !Number.isFinite(value)) {
32966
33392
  return "";
@@ -32983,10 +33409,12 @@ function serializeTableRowHeightFromStyle(heightValue, heightRule) {
32983
33409
  }
32984
33410
  function serializeTableRowHeight(row) {
32985
33411
  var _a, _b;
32986
- return serializeTableRowHeightFromStyle((_a = row.style) == null ? void 0 : _a.height, (_b = row.style) == null ? void 0 : _b.heightRule);
33412
+ return serializeTableRowHeightFromStyle(
33413
+ (_a = row.style) == null ? void 0 : _a.height,
33414
+ (_b = row.style) == null ? void 0 : _b.heightRule
33415
+ );
32987
33416
  }
32988
33417
  function serializeTableRowStyleXml(style2) {
32989
- var _a;
32990
33418
  if (!style2) return "";
32991
33419
  const parts = [];
32992
33420
  const gridBefore = serializeGridSkip("gridBefore", style2.gridBefore);
@@ -32997,49 +33425,104 @@ function serializeTableRowStyleXml(style2) {
32997
33425
  if (widthBefore) parts.push(widthBefore);
32998
33426
  const widthAfter = serializeDocxWidthElement("wAfter", style2.widthAfter);
32999
33427
  if (widthAfter) parts.push(widthAfter);
33000
- const cellSpacingXml = serializeDocxWidthElement("tblCellSpacing", style2.cellSpacing);
33428
+ const cellSpacingXml = serializeDocxWidthElement(
33429
+ "tblCellSpacing",
33430
+ style2.cellSpacing
33431
+ );
33001
33432
  if (cellSpacingXml) parts.push(cellSpacingXml);
33002
- const heightXml = serializeTableRowHeightFromStyle(style2.height, style2.heightRule);
33433
+ const heightXml = serializeTableRowHeightFromStyle(
33434
+ style2.height,
33435
+ style2.heightRule
33436
+ );
33003
33437
  if (heightXml) parts.push(heightXml);
33004
33438
  const cantSplit = serializeOnOffElement("cantSplit", style2.cantSplit);
33005
33439
  if (cantSplit) parts.push(cantSplit);
33006
33440
  const hidden = serializeOnOffElement("hidden", style2.hidden);
33007
33441
  if (hidden) parts.push(hidden);
33008
- if ((_a = style2.revisionXml) == null ? void 0 : _a.length) parts.push(...style2.revisionXml);
33442
+ const header = serializeOnOffElement("tblHeader", style2.isHeader);
33443
+ if (header) parts.push(header);
33009
33444
  return parts.length > 0 ? `<w:trPr>${parts.join("")}</w:trPr>` : "";
33010
33445
  }
33011
33446
  function serializeTableRowProperties(row) {
33012
- var _a, _b, _c, _d, _e, _f, _g, _h, _i;
33447
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
33013
33448
  const parts = [];
33449
+ const conditional = serializeConditionalFlags(row.conditionalStyle);
33450
+ if (conditional) parts.push(conditional);
33014
33451
  const gridBefore = serializeGridSkip("gridBefore", (_a = row.style) == null ? void 0 : _a.gridBefore);
33015
33452
  if (gridBefore) parts.push(gridBefore);
33016
33453
  const gridAfter = serializeGridSkip("gridAfter", (_b = row.style) == null ? void 0 : _b.gridAfter);
33017
33454
  if (gridAfter) parts.push(gridAfter);
33018
- const widthBefore = serializeDocxWidthElement("wBefore", (_c = row.style) == null ? void 0 : _c.widthBefore);
33455
+ const widthBefore = serializeDocxWidthElement(
33456
+ "wBefore",
33457
+ (_c = row.style) == null ? void 0 : _c.widthBefore
33458
+ );
33019
33459
  if (widthBefore) parts.push(widthBefore);
33020
33460
  const widthAfter = serializeDocxWidthElement("wAfter", (_d = row.style) == null ? void 0 : _d.widthAfter);
33021
33461
  if (widthAfter) parts.push(widthAfter);
33022
- const cellSpacingXml = serializeDocxWidthElement("tblCellSpacing", (_e = row.style) == null ? void 0 : _e.cellSpacing);
33462
+ const cellSpacingXml = serializeDocxWidthElement(
33463
+ "tblCellSpacing",
33464
+ (_e = row.style) == null ? void 0 : _e.cellSpacing
33465
+ );
33023
33466
  if (cellSpacingXml) parts.push(cellSpacingXml);
33024
33467
  const height = serializeTableRowHeight(row);
33025
33468
  if (height) parts.push(height);
33026
33469
  const cantSplit = serializeOnOffElement("cantSplit", (_f = row.style) == null ? void 0 : _f.cantSplit);
33027
33470
  if (cantSplit) parts.push(cantSplit);
33028
- if (row.isHeader) parts.push("<w:tblHeader/>");
33029
- const hidden = serializeOnOffElement("hidden", (_g = row.style) == null ? void 0 : _g.hidden);
33471
+ if (((_g = row.style) == null ? void 0 : _g.isHeader) ?? row.isHeader) parts.push("<w:tblHeader/>");
33472
+ const hidden = serializeOnOffElement("hidden", (_h = row.style) == null ? void 0 : _h.hidden);
33030
33473
  if (hidden) parts.push(hidden);
33031
- if ((_i = (_h = row.style) == null ? void 0 : _h.revisionXml) == null ? void 0 : _i.length) parts.push(...row.style.revisionXml);
33474
+ if ((_i = row.style) == null ? void 0 : _i.propertyRevision) {
33475
+ const revision = row.style.propertyRevision;
33476
+ parts.push(
33477
+ `<w:trPrChange ${serializeRevisionAttrs(revision)}>${serializeTableRowStyleXml(revision.previous)}</w:trPrChange>`
33478
+ );
33479
+ }
33480
+ if (((_j = row.style) == null ? void 0 : _j.revision) && row.style.revision.type !== "merge") {
33481
+ const revision = row.style.revision;
33482
+ const element = revision.type === "insert" ? "ins" : "del";
33483
+ parts.push(`<w:${element} ${serializeRevisionAttrs(revision)}/>`);
33484
+ }
33032
33485
  return parts.length > 0 ? `<w:trPr>${parts.join("")}</w:trPr>` : "";
33033
33486
  }
33034
33487
  function serializeFloatingTableProperties(floating) {
33035
33488
  if (!floating || Object.keys(floating).length === 0) {
33036
33489
  return "";
33037
33490
  }
33038
- const attrs = Object.entries(floating).map(([key, value]) => `w:${key}="${escapeXml(value)}"`).join(" ");
33491
+ const twips = (value) => {
33492
+ const converted = pointsToTwips(value);
33493
+ return converted === null ? void 0 : String(converted);
33494
+ };
33495
+ const values = {
33496
+ horzAnchor: floating.horizontalAnchor,
33497
+ vertAnchor: floating.verticalAnchor,
33498
+ tblpX: twips(floating.x),
33499
+ tblpY: twips(floating.y),
33500
+ tblpXSpec: floating.xAlign,
33501
+ tblpYSpec: floating.yAlign,
33502
+ topFromText: twips(floating.distanceTop),
33503
+ rightFromText: twips(floating.distanceRight),
33504
+ bottomFromText: twips(floating.distanceBottom),
33505
+ leftFromText: twips(floating.distanceLeft)
33506
+ };
33507
+ const attrs = Object.entries(values).filter((entry) => entry[1] !== void 0).map(([key, value]) => `w:${key}="${escapeXml(value)}"`).join(" ");
33039
33508
  return `<w:tblpPr ${attrs}/>`;
33040
33509
  }
33510
+ function serializeTableBorders(style2) {
33511
+ const borders = style2 == null ? void 0 : style2.borders;
33512
+ if (!borders) return "";
33513
+ const edges = [
33514
+ ["top", borders.borderTop],
33515
+ ["left", borders.borderLeft],
33516
+ ["bottom", borders.borderBottom],
33517
+ ["right", borders.borderRight],
33518
+ ["insideH", borders.borderInsideH],
33519
+ ["insideV", borders.borderInsideV]
33520
+ ];
33521
+ const xml = edges.filter((entry) => !!entry[1]).map(([name, border]) => `<w:${name} ${serializeDocxBorderAttrs(border)}`).join("");
33522
+ return xml ? `<w:tblBorders>${xml}</w:tblBorders>` : "";
33523
+ }
33041
33524
  function serializeTableProperties(table) {
33042
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o;
33525
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n;
33043
33526
  const parts = [];
33044
33527
  if ((_a = table.style) == null ? void 0 : _a.styleId) {
33045
33528
  parts.push(`<w:tblStyle w:val="${escapeXml(table.style.styleId)}"/>`);
@@ -33080,6 +33563,8 @@ function serializeTableProperties(table) {
33080
33563
  if (defaultMarginsXml) {
33081
33564
  parts.push(defaultMarginsXml);
33082
33565
  }
33566
+ const tableBorders = serializeTableBorders(table.style);
33567
+ if (tableBorders) parts.push(tableBorders);
33083
33568
  const indentXml = serializeDocxWidthElement(
33084
33569
  "tblInd",
33085
33570
  (_j = table.style) == null ? void 0 : _j.indentLeft
@@ -33088,15 +33573,25 @@ function serializeTableProperties(table) {
33088
33573
  parts.push(indentXml);
33089
33574
  }
33090
33575
  parts.push(`<w:tblLayout w:type="${((_k = table.style) == null ? void 0 : _k.layout) ?? "fixed"}"/>`);
33091
- const bidiVisual = serializeOnOffElement("bidiVisual", (_l = table.style) == null ? void 0 : _l.bidiVisual);
33576
+ const bidiVisual = serializeOnOffElement(
33577
+ "bidiVisual",
33578
+ (_l = table.style) == null ? void 0 : _l.bidiVisual
33579
+ );
33092
33580
  if (bidiVisual) {
33093
33581
  parts.push(bidiVisual);
33094
33582
  }
33095
33583
  if ((_m = table.style) == null ? void 0 : _m.tblOverlap) {
33096
33584
  parts.push(`<w:tblOverlap w:val="${escapeXml(table.style.tblOverlap)}"/>`);
33097
33585
  }
33098
- if ((_o = (_n = table.style) == null ? void 0 : _n.revisionXml) == null ? void 0 : _o.length) {
33099
- parts.push(...table.style.revisionXml);
33586
+ if ((_n = table.style) == null ? void 0 : _n.revision) {
33587
+ const revision = table.style.revision;
33588
+ const previous = serializeTableProperties({
33589
+ ...table,
33590
+ style: revision.previous
33591
+ });
33592
+ parts.push(
33593
+ `<w:tblPrChange ${serializeRevisionAttrs(revision)}>${previous}</w:tblPrChange>`
33594
+ );
33100
33595
  }
33101
33596
  return `<w:tblPr>${parts.join("")}</w:tblPr>`;
33102
33597
  }
@@ -33127,7 +33622,7 @@ function serializeTableXml(table, serializeParagraphXml2) {
33127
33622
  }).join("");
33128
33623
  return `<w:tr>${row.tblPrExXml ?? ""}${serializeTableRowProperties(row)}${cellsXml}</w:tr>`;
33129
33624
  }).join("");
33130
- const gridXml = table.gridCols ? `<w:tblGrid>${table.gridCols.map((width) => `<w:gridCol w:w="${pointsToTwips(width) ?? 0}"/>`).join("")}${table.tblGridChangeXml ?? ""}</w:tblGrid>` : "";
33625
+ const gridXml = table.gridCols ? `<w:tblGrid>${table.gridCols.map((width) => `<w:gridCol w:w="${pointsToTwips(width) ?? 0}"/>`).join("")}${table.gridRevision ? `<w:tblGridChange ${serializeRevisionAttrs(table.gridRevision)}><w:tblGrid>${table.gridRevision.previous.map((width) => `<w:gridCol w:w="${pointsToTwips(width) ?? 0}"/>`).join("")}</w:tblGrid></w:tblGridChange>` : ""}</w:tblGrid>` : "";
33131
33626
  return `<w:tbl>${serializeTableProperties(table)}${gridXml}${rowsXml}</w:tbl>`;
33132
33627
  }
33133
33628
  function materializeParagraphStyle(paragraph, styles) {
@@ -33180,6 +33675,16 @@ function materializeRunStyle(run, paragraphStyleId, styles) {
33180
33675
  noProof: effective.noProof,
33181
33676
  webHidden: effective.webHidden,
33182
33677
  specVanish: effective.specVanish,
33678
+ rtl: effective.rtl,
33679
+ complexScript: effective.complexScript,
33680
+ snapToGrid: effective.snapToGrid,
33681
+ fitText: effective.fitText,
33682
+ emphasisMark: effective.emphasisMark,
33683
+ textBorder: effective.textBorder,
33684
+ outline: effective.outline,
33685
+ shadow: effective.shadow,
33686
+ emboss: effective.emboss,
33687
+ imprint: effective.imprint,
33183
33688
  textEffect: effective.textEffect,
33184
33689
  characterScale: effective.characterScale,
33185
33690
  characterSpacing: effective.characterSpacing,
@@ -33477,15 +33982,23 @@ function serializeRunProperties(styles) {
33477
33982
  }
33478
33983
  if (styles.strike) parts.push("<w:strike/>");
33479
33984
  if (styles.doubleStrike) parts.push("<w:dstrike/>");
33985
+ if (styles.outline) parts.push("<w:outline/>");
33986
+ if (styles.shadow) parts.push("<w:shadow/>");
33987
+ if (styles.emboss) parts.push("<w:emboss/>");
33988
+ if (styles.imprint) parts.push("<w:imprint/>");
33480
33989
  if (styles.smallCaps) parts.push("<w:smallCaps/>");
33481
33990
  if (styles.allCaps) parts.push("<w:caps/>");
33482
33991
  if (styles.hidden) parts.push("<w:vanish/>");
33483
33992
  if (styles.noProof) parts.push("<w:noProof/>");
33484
33993
  if (styles.webHidden) parts.push("<w:webHidden/>");
33485
33994
  if (styles.specVanish) parts.push("<w:specVanish/>");
33995
+ if (styles.snapToGrid === false) parts.push('<w:snapToGrid w:val="0"/>');
33486
33996
  if (styles.textEffect) {
33487
33997
  parts.push(`<w:effect w:val="${escapeXml(styles.textEffect)}"/>`);
33488
33998
  }
33999
+ if (styles.textBorder) {
34000
+ parts.push(`<w:bdr ${serializeDocxBorderAttrs(styles.textBorder)}`);
34001
+ }
33489
34002
  if (styles.characterScale !== void 0 && styles.characterScale !== null && Number.isFinite(styles.characterScale)) {
33490
34003
  parts.push(
33491
34004
  `<w:w w:val="${Math.max(1, Math.round(styles.characterScale))}"/>`
@@ -33553,6 +34066,17 @@ function serializeRunProperties(styles) {
33553
34066
  `<w:shd w:val="clear" w:color="auto" w:fill="${normalizeDocxColor(styles.shading, "FFFFFF")}"/>`
33554
34067
  );
33555
34068
  }
34069
+ if (styles.fitText !== void 0 && styles.fitText !== null && Number.isFinite(styles.fitText)) {
34070
+ const twips = pointsToSignedTwips(styles.fitText);
34071
+ if (twips !== null && twips > 0) {
34072
+ parts.push(`<w:fitText w:val="${twips}"/>`);
34073
+ }
34074
+ }
34075
+ if (styles.rtl) parts.push("<w:rtl/>");
34076
+ if (styles.complexScript) parts.push("<w:cs/>");
34077
+ if (styles.emphasisMark) {
34078
+ parts.push(`<w:em w:val="${escapeXml(styles.emphasisMark)}"/>`);
34079
+ }
33556
34080
  if (styles.language) {
33557
34081
  const attrs = [];
33558
34082
  if (styles.language.value) {
@@ -34282,6 +34806,9 @@ const CONDITIONAL_TYPE_ORDER = [
34282
34806
  "seCell"
34283
34807
  ];
34284
34808
  function serializeConditionalTcPr(cond) {
34809
+ if (cond.cellStyle) {
34810
+ return serializeTableCellStyleXml(cond.cellStyle);
34811
+ }
34285
34812
  const parts = [];
34286
34813
  if (cond.borders) {
34287
34814
  const b = cond.borders;
@@ -34305,12 +34832,63 @@ function serializeConditionalTcPr(cond) {
34305
34832
  }
34306
34833
  return parts.length > 0 ? `<w:tcPr>${parts.join("")}</w:tcPr>` : "";
34307
34834
  }
34835
+ function serializeWidthElement(name, value) {
34836
+ if (typeof value === "number") {
34837
+ return `<w:${name} w:w="${pointsToTwips(value) ?? 0}" w:type="dxa"/>`;
34838
+ }
34839
+ if (typeof value === "string" && value.endsWith("%")) {
34840
+ const percent = Number.parseFloat(value);
34841
+ return Number.isFinite(percent) ? `<w:${name} w:w="${Math.round(percent * 50)}" w:type="pct"/>` : "";
34842
+ }
34843
+ return value === "auto" ? `<w:${name} w:w="0" w:type="auto"/>` : "";
34844
+ }
34845
+ function serializeTableStyleProperties(style2) {
34846
+ if (!style2) return "";
34847
+ const parts = [];
34848
+ if (style2.rowBandSize !== void 0)
34849
+ parts.push(`<w:tblStyleRowBandSize w:val="${style2.rowBandSize}"/>`);
34850
+ if (style2.colBandSize !== void 0)
34851
+ parts.push(`<w:tblStyleColBandSize w:val="${style2.colBandSize}"/>`);
34852
+ const width = serializeWidthElement("tblW", style2.width);
34853
+ if (width) parts.push(width);
34854
+ const indent = serializeWidthElement("tblInd", style2.indentLeft);
34855
+ if (indent) parts.push(indent);
34856
+ const spacing = serializeWidthElement("tblCellSpacing", style2.cellSpacing);
34857
+ if (spacing) parts.push(spacing);
34858
+ if (style2.align) parts.push(`<w:jc w:val="${style2.align}"/>`);
34859
+ if (style2.layout) parts.push(`<w:tblLayout w:type="${style2.layout}"/>`);
34860
+ if (style2.bidiVisual !== void 0)
34861
+ parts.push(`<w:bidiVisual w:val="${style2.bidiVisual ? "1" : "0"}"/>`);
34862
+ if (style2.defaultCellMargins) {
34863
+ const margins = Object.entries(style2.defaultCellMargins).map(
34864
+ ([name, value]) => `<w:${name} w:w="${pointsToTwips(value) ?? 0}" w:type="dxa"/>`
34865
+ ).join("");
34866
+ if (margins) parts.push(`<w:tblCellMar>${margins}</w:tblCellMar>`);
34867
+ }
34868
+ if (style2.borders) {
34869
+ const edges = [
34870
+ ["top", style2.borders.borderTop],
34871
+ ["left", style2.borders.borderLeft],
34872
+ ["bottom", style2.borders.borderBottom],
34873
+ ["right", style2.borders.borderRight],
34874
+ ["insideH", style2.borders.borderInsideH],
34875
+ ["insideV", style2.borders.borderInsideV]
34876
+ ];
34877
+ const borders = edges.filter(
34878
+ (entry) => !!entry[1]
34879
+ ).map(([name, border]) => `<w:${name} ${serializeDocxBorderAttrs(border)}`).join("");
34880
+ if (borders) parts.push(`<w:tblBorders>${borders}</w:tblBorders>`);
34881
+ }
34882
+ return parts.length > 0 ? `<w:tblPr>${parts.join("")}</w:tblPr>` : "";
34883
+ }
34308
34884
  function serializeConditionalBlock(type, cond) {
34309
34885
  const parts = [];
34310
34886
  const pPr = cond.paragraphStyle ? serializeParagraphStyleXml(cond.paragraphStyle) : "";
34311
34887
  if (pPr) parts.push(pPr);
34312
34888
  const rPr = cond.textStyle ? serializeRunProperties(cond.textStyle) : "";
34313
34889
  if (rPr) parts.push(rPr);
34890
+ const tblPr = serializeTableStyleProperties(cond.tableStyle);
34891
+ if (tblPr) parts.push(tblPr);
34314
34892
  const trPr = cond.rowStyle ? serializeTableRowStyleXml(cond.rowStyle) : "";
34315
34893
  if (trPr) parts.push(trPr);
34316
34894
  const tcPr = serializeConditionalTcPr(cond);
@@ -34355,22 +34933,8 @@ function serializeNamedStyle(style2) {
34355
34933
  }
34356
34934
  if (style2.type === "table" && style2.tableStyle) {
34357
34935
  const ts = style2.tableStyle;
34358
- const tblPrParts = [];
34359
- if (ts.rowBandSize !== void 0) {
34360
- tblPrParts.push(`<w:tblStyleRowBandSize w:val="${ts.rowBandSize}"/>`);
34361
- }
34362
- if (ts.colBandSize !== void 0) {
34363
- tblPrParts.push(`<w:tblStyleColBandSize w:val="${ts.colBandSize}"/>`);
34364
- }
34365
- if (ts.indentLeft !== void 0) {
34366
- const val = typeof ts.indentLeft === "number" ? pointsToTwips(ts.indentLeft) : null;
34367
- if (val !== null) {
34368
- tblPrParts.push(`<w:tblInd w:w="${val}" w:type="dxa"/>`);
34369
- }
34370
- }
34371
- if (tblPrParts.length > 0) {
34372
- parts.push(`<w:tblPr>${tblPrParts.join("")}</w:tblPr>`);
34373
- }
34936
+ const tblPr = serializeTableStyleProperties(ts);
34937
+ if (tblPr) parts.push(tblPr);
34374
34938
  if (ts.conditionalFormats) {
34375
34939
  const orderedKeys = [
34376
34940
  ...CONDITIONAL_TYPE_ORDER.filter((k) => k in ts.conditionalFormats),
@@ -34388,7 +34952,7 @@ function serializeNamedStyle(style2) {
34388
34952
  }
34389
34953
  }
34390
34954
  const typeAttr = style2.type === "character" ? "character" : style2.type === "table" ? "table" : "paragraph";
34391
- return `<w:style w:type="${typeAttr}" w:styleId="${escapeXml(style2.id)}">${parts.join("")}</w:style>`;
34955
+ return `<w:style w:type="${typeAttr}" w:styleId="${escapeXml(style2.id)}"${style2.isDefault ? ' w:default="1"' : ""}>${parts.join("")}</w:style>`;
34392
34956
  }
34393
34957
  function buildStylesXml(styles) {
34394
34958
  const styleElements = Object.values(styles).map(serializeNamedStyle).join("");
@@ -35326,6 +35890,10 @@ async function drawFloatingTextBoxesForParagraph(options) {
35326
35890
  if (!(textBox == null ? void 0 : textBox.floating)) {
35327
35891
  continue;
35328
35892
  }
35893
+ const isBehind = Boolean(textBox.floating.behindDoc);
35894
+ if (options.layer && options.layer === "behind" !== isBehind) {
35895
+ continue;
35896
+ }
35329
35897
  const slot = slotByOffset.get(fragment.startOffset);
35330
35898
  const anchorLeft = contentLeft + ((slot == null ? void 0 : slot.left) ?? 0);
35331
35899
  const lineTop = paragraphTop + line.top;
@@ -35515,6 +36083,42 @@ function resolveFragmentBounds(line, fragment, fontSizePx) {
35515
36083
  right: (nextSlot == null ? void 0 : nextSlot.left) ?? last.left + fontSizePx * 0.55
35516
36084
  };
35517
36085
  }
36086
+ async function drawFloatingImagesForParagraph(options) {
36087
+ for (const line of options.lines) {
36088
+ const slots = new Map(line.slots.map((slot) => [slot.offset, slot]));
36089
+ for (const fragment of line.fragments) {
36090
+ const image = fragment.image;
36091
+ if (!(image == null ? void 0 : image.floating)) continue;
36092
+ const isBehind = Boolean(image.floating.behindDoc);
36093
+ if (options.layer === "behind" !== isBehind) continue;
36094
+ const slot = slots.get(fragment.startOffset);
36095
+ const rect = resolveFloatingObjectRect({
36096
+ object: getImageFloatingGeometry(image),
36097
+ pageSettings: options.pageSettings,
36098
+ contentLeft: options.contentLeft,
36099
+ contentTop: options.contentTop,
36100
+ contentWidth: options.contentWidth,
36101
+ paragraphTop: options.paragraphTop,
36102
+ lineTop: options.paragraphTop + line.top,
36103
+ anchorLeft: options.contentLeft + ((slot == null ? void 0 : slot.left) ?? 0)
36104
+ });
36105
+ const resourceName = await registerPdfImageRun(
36106
+ options.writer,
36107
+ options.document,
36108
+ image
36109
+ );
36110
+ if (!resourceName) continue;
36111
+ options.writer.drawImage(options.pageIndex, {
36112
+ resourceName,
36113
+ x: pxToPt$1(rect.x),
36114
+ y: pxToPt$1(rect.y),
36115
+ width: pxToPt$1(rect.width),
36116
+ height: pxToPt$1(rect.height),
36117
+ rotation: image.rotation
36118
+ });
36119
+ }
36120
+ }
36121
+ }
35518
36122
  function drawFragmentHighlight(writer, pageIndex, line, fragment, originX, originY, styles) {
35519
36123
  if (!styles.highlight) {
35520
36124
  return;
@@ -35555,6 +36159,63 @@ function drawFragmentShading(writer, pageIndex, line, fragment, originX, originY
35555
36159
  fill: styles.shading
35556
36160
  });
35557
36161
  }
36162
+ function drawFragmentBorder(writer, pageIndex, line, fragment, originX, originY, styles) {
36163
+ const border = styles.textBorder;
36164
+ if (!border || border.type === "none" || border.width <= 0) {
36165
+ return;
36166
+ }
36167
+ const bounds = resolveFragmentBounds(
36168
+ line,
36169
+ fragment,
36170
+ styles.fontSize ?? DEFAULT_FONT_SIZE_PX
36171
+ );
36172
+ if (!bounds) {
36173
+ return;
36174
+ }
36175
+ writer.drawRect(pageIndex, {
36176
+ x: pxToPt$1(originX + bounds.left),
36177
+ y: pxToPt$1(originY + line.top + 1),
36178
+ width: pxToPt$1(Math.max(0, bounds.right - bounds.left)),
36179
+ height: pxToPt$1(Math.max(2, line.height - 2)),
36180
+ stroke: border.color,
36181
+ lineWidth: pxToPt$1(Math.max(0.5, border.width * PX_PER_POINT))
36182
+ });
36183
+ }
36184
+ const PDF_EMPHASIS_GLYPH = {
36185
+ dot: "•",
36186
+ comma: "‚",
36187
+ circle: "○",
36188
+ underDot: "•"
36189
+ };
36190
+ function drawFragmentEmphasis(writer, pageIndex, line, fragment, originX, originY, styles) {
36191
+ const mark = styles.emphasisMark;
36192
+ if (!mark || mark === "none") {
36193
+ return;
36194
+ }
36195
+ const glyph = PDF_EMPHASIS_GLYPH[mark];
36196
+ if (!glyph) {
36197
+ return;
36198
+ }
36199
+ const slots = resolveFragmentSlots(line, fragment);
36200
+ const below = mark === "underDot";
36201
+ const size = Math.max(4, line.height * 0.35);
36202
+ const y = below ? originY + line.top + line.height + size : originY + line.top + size;
36203
+ for (let i = 0; i < slots.length; i += 1) {
36204
+ const slot = slots[i];
36205
+ if (slot.char === " " || slot.char === " " || slot.char === "\n") {
36206
+ continue;
36207
+ }
36208
+ const next = slots[i + 1];
36209
+ const centerX = next ? (slot.left + next.left) / 2 : slot.left + line.height * 0.25;
36210
+ writer.drawText(pageIndex, {
36211
+ x: pxToPt$1(originX + centerX - size * 0.25),
36212
+ y: pxToPt$1(y),
36213
+ text: glyph,
36214
+ fontSize: pxToPt$1(size),
36215
+ color: styles.color ?? "#000000"
36216
+ });
36217
+ }
36218
+ }
35558
36219
  function drawFragmentDecoration(writer, pageIndex, line, fragment, originX, originY, styles, kind) {
35559
36220
  const bounds = resolveFragmentBounds(
35560
36221
  line,
@@ -35754,6 +36415,9 @@ async function drawInlineTextBoxFragment(writer, pageIndex, line, fragment, docu
35754
36415
  async function drawFragmentText(writer, pageIndex, paragraph, line, fragment, document2, originX, originY, fontRegistry, drawers) {
35755
36416
  var _a;
35756
36417
  if (fragment.image) {
36418
+ if (fragment.image.floating) {
36419
+ return;
36420
+ }
35757
36421
  const slot = line.slots.find(
35758
36422
  (candidate) => candidate.offset === fragment.startOffset
35759
36423
  ) ?? line.slots.find((candidate) => candidate.offset >= fragment.startOffset);
@@ -35832,6 +36496,15 @@ async function drawFragmentText(writer, pageIndex, paragraph, line, fragment, do
35832
36496
  originY,
35833
36497
  styles
35834
36498
  );
36499
+ drawFragmentBorder(
36500
+ writer,
36501
+ pageIndex,
36502
+ line,
36503
+ fragment,
36504
+ originX,
36505
+ originY,
36506
+ styles
36507
+ );
35835
36508
  drawTabLeaders(
35836
36509
  writer,
35837
36510
  pageIndex,
@@ -35844,42 +36517,50 @@ async function drawFragmentText(writer, pageIndex, paragraph, line, fragment, do
35844
36517
  styles.color ?? "#000000"
35845
36518
  );
35846
36519
  const paragraphAlign = resolveEffectiveParagraphStyle(paragraph.style, document2.styles).align ?? "left";
35847
- if (paragraphAlign === "justify") {
35848
- const chunks = groupSlotChunksByWhitespace(chars);
35849
- for (const chunk of chunks) {
35850
- const chunkText = chunk.map((c) => styles.allCaps ? c.char.toUpperCase() : c.char).join("");
35851
- if (chunkText.length === 0) continue;
36520
+ const baseTextOptions = {
36521
+ fontSize: fontSizePt,
36522
+ bold: styles.bold,
36523
+ italic: styles.italic,
36524
+ fontResourceName: fontFace.writerResourceName,
36525
+ characterSpacing: styles.characterSpacing ?? 0,
36526
+ horizontalScale: styles.characterScale ?? 100
36527
+ };
36528
+ const mainColor = styles.color ?? "#000000";
36529
+ const offsetPt = pxToPt$1(1);
36530
+ const emitChunk = (leftPx, text2) => {
36531
+ if (styles.emboss || styles.imprint) {
36532
+ const dir = styles.imprint ? 1 : -1;
35852
36533
  writer.drawText(pageIndex, {
35853
- x: pxToPt$1(originX + chunk[0].left),
35854
- y: pxToPt$1(baselineY),
35855
- text: chunkText,
35856
- fontSize: fontSizePt,
35857
- color: styles.color ?? "#000000",
35858
- bold: styles.bold,
35859
- italic: styles.italic,
35860
- fontResourceName: fontFace.writerResourceName,
35861
- characterSpacing: styles.characterSpacing ?? 0,
35862
- horizontalScale: styles.characterScale ?? 100
36534
+ ...baseTextOptions,
36535
+ x: pxToPt$1(leftPx) + offsetPt * dir,
36536
+ y: pxToPt$1(baselineY) + offsetPt * dir,
36537
+ text: text2,
36538
+ color: "#BFBFBF"
35863
36539
  });
35864
36540
  }
35865
- } else {
35866
- const chunks = groupSlotChunksByOffsetGaps(chars);
35867
- for (const chunk of chunks) {
35868
- const chunkText = chunk.map((c) => styles.allCaps ? c.char.toUpperCase() : c.char).join("");
35869
- if (chunkText.length === 0) continue;
36541
+ if (styles.shadow) {
35870
36542
  writer.drawText(pageIndex, {
35871
- x: pxToPt$1(originX + chunk[0].left),
35872
- y: pxToPt$1(baselineY),
35873
- text: chunkText,
35874
- fontSize: fontSizePt,
35875
- color: styles.color ?? "#000000",
35876
- bold: styles.bold,
35877
- italic: styles.italic,
35878
- fontResourceName: fontFace.writerResourceName,
35879
- characterSpacing: styles.characterSpacing ?? 0,
35880
- horizontalScale: styles.characterScale ?? 100
36543
+ ...baseTextOptions,
36544
+ x: pxToPt$1(leftPx) + offsetPt,
36545
+ y: pxToPt$1(baselineY) + offsetPt,
36546
+ text: text2,
36547
+ color: "#808080"
35881
36548
  });
35882
36549
  }
36550
+ writer.drawText(pageIndex, {
36551
+ ...baseTextOptions,
36552
+ x: pxToPt$1(leftPx),
36553
+ y: pxToPt$1(baselineY),
36554
+ text: text2,
36555
+ color: mainColor,
36556
+ renderMode: styles.outline ? 1 : 0
36557
+ });
36558
+ };
36559
+ const chunks = paragraphAlign === "justify" ? groupSlotChunksByWhitespace(chars) : groupSlotChunksByOffsetGaps(chars);
36560
+ for (const chunk of chunks) {
36561
+ const chunkText = chunk.map((c) => styles.allCaps ? c.char.toUpperCase() : c.char).join("");
36562
+ if (chunkText.length === 0) continue;
36563
+ emitChunk(originX + chunk[0].left, chunkText);
35883
36564
  }
35884
36565
  if (styles.underline) {
35885
36566
  drawFragmentDecoration(
@@ -35917,6 +36598,17 @@ async function drawFragmentText(writer, pageIndex, paragraph, line, fragment, do
35917
36598
  "doubleStrike"
35918
36599
  );
35919
36600
  }
36601
+ if (styles.emphasisMark) {
36602
+ drawFragmentEmphasis(
36603
+ writer,
36604
+ pageIndex,
36605
+ line,
36606
+ fragment,
36607
+ originX,
36608
+ originY,
36609
+ styles
36610
+ );
36611
+ }
35920
36612
  }
35921
36613
  function getListOrdinals(document2) {
35922
36614
  return buildListLabels(document2);
@@ -36082,6 +36774,28 @@ function drawCellBorders(writer, pageIndex, cell, originX, originY) {
36082
36774
  bottom
36083
36775
  );
36084
36776
  drawCellEdge(writer, pageIndex, cell.borders.left, left, top, left, bottom);
36777
+ if (cell.borders.topLeftToBottomRight) {
36778
+ drawCellEdge(
36779
+ writer,
36780
+ pageIndex,
36781
+ cell.borders.topLeftToBottomRight,
36782
+ left,
36783
+ top,
36784
+ right,
36785
+ bottom
36786
+ );
36787
+ }
36788
+ if (cell.borders.topRightToBottomLeft) {
36789
+ drawCellEdge(
36790
+ writer,
36791
+ pageIndex,
36792
+ cell.borders.topRightToBottomLeft,
36793
+ right,
36794
+ top,
36795
+ left,
36796
+ bottom
36797
+ );
36798
+ }
36085
36799
  }
36086
36800
  async function drawTableBlock(writer, pageIndex, block, document2, originX, originY, contentWidth, fontRegistry, listOrdinals, drawers) {
36087
36801
  if (block.sourceBlock.type !== "table") {
@@ -36114,6 +36828,17 @@ async function drawTableBlock(writer, pageIndex, block, document2, originX, orig
36114
36828
  }
36115
36829
  for (const cell of tableLayout.cells) {
36116
36830
  drawCellBorders(writer, pageIndex, cell, originX, originY);
36831
+ if (cell.revision) {
36832
+ const color = cell.revision.type === "insert" ? "#059669" : cell.revision.type === "delete" ? "#dc2626" : "#d97706";
36833
+ writer.drawRect(pageIndex, {
36834
+ x: pxToPt$1(originX + cell.left + 1),
36835
+ y: pxToPt$1(originY + cell.top + 1),
36836
+ width: pxToPt$1(Math.max(0, cell.width - 2)),
36837
+ height: pxToPt$1(Math.max(0, cell.height - 2)),
36838
+ stroke: color,
36839
+ lineWidth: pxToPt$1(2)
36840
+ });
36841
+ }
36117
36842
  }
36118
36843
  for (const cell of tableLayout.cells) {
36119
36844
  for (const paragraphLayout of cell.paragraphs) {
@@ -36134,6 +36859,7 @@ async function drawTableBlock(writer, pageIndex, block, document2, originX, orig
36134
36859
  }
36135
36860
  const blockDrawers = { drawParagraph, drawTableBlock };
36136
36861
  async function drawBlockList(writer, pageIndex, blocks, document2, originX, originY, contentWidth, fontRegistry, listOrdinals, pageSettings) {
36862
+ var _a;
36137
36863
  if (!blocks || blocks.length === 0) {
36138
36864
  return;
36139
36865
  }
@@ -36161,6 +36887,34 @@ async function drawBlockList(writer, pageIndex, blocks, document2, originX, orig
36161
36887
  boxTop,
36162
36888
  contentWidth
36163
36889
  );
36890
+ if (pageSettings) {
36891
+ await drawFloatingImagesForParagraph({
36892
+ writer,
36893
+ pageIndex,
36894
+ lines: block.layout.lines,
36895
+ document: document2,
36896
+ pageSettings,
36897
+ contentLeft: originX,
36898
+ contentTop,
36899
+ contentWidth,
36900
+ paragraphTop: textTop,
36901
+ layer: "behind"
36902
+ });
36903
+ await drawFloatingTextBoxesForParagraph({
36904
+ writer,
36905
+ document: document2,
36906
+ fontRegistry,
36907
+ pageIndex,
36908
+ lines: block.layout.lines,
36909
+ pageSettings,
36910
+ contentLeft: originX,
36911
+ contentTop,
36912
+ contentWidth,
36913
+ paragraphTop: boxTop,
36914
+ drawers: blockDrawers,
36915
+ layer: "behind"
36916
+ });
36917
+ }
36164
36918
  await drawParagraph(
36165
36919
  writer,
36166
36920
  pageIndex,
@@ -36174,6 +36928,18 @@ async function drawBlockList(writer, pageIndex, blocks, document2, originX, orig
36174
36928
  blockDrawers
36175
36929
  );
36176
36930
  if (pageSettings) {
36931
+ await drawFloatingImagesForParagraph({
36932
+ writer,
36933
+ pageIndex,
36934
+ lines: block.layout.lines,
36935
+ document: document2,
36936
+ pageSettings,
36937
+ contentLeft: originX,
36938
+ contentTop,
36939
+ contentWidth,
36940
+ paragraphTop: textTop,
36941
+ layer: "front"
36942
+ });
36177
36943
  await drawFloatingTextBoxesForParagraph({
36178
36944
  writer,
36179
36945
  document: document2,
@@ -36185,12 +36951,44 @@ async function drawBlockList(writer, pageIndex, blocks, document2, originX, orig
36185
36951
  contentTop,
36186
36952
  contentWidth,
36187
36953
  paragraphTop: boxTop,
36188
- drawers: blockDrawers
36954
+ drawers: blockDrawers,
36955
+ layer: "front"
36189
36956
  });
36190
36957
  }
36191
36958
  break;
36192
36959
  }
36193
36960
  case "table":
36961
+ if (((_a = block.sourceBlock.style) == null ? void 0 : _a.floating) && pageSettings) {
36962
+ const width = resolveCanvasTableWidth(
36963
+ block.sourceBlock,
36964
+ contentWidth
36965
+ );
36966
+ const rect = resolveFloatingTableRect({
36967
+ floating: block.sourceBlock.style.floating,
36968
+ pageSettings,
36969
+ contentLeft: originX,
36970
+ contentTop,
36971
+ contentWidth,
36972
+ anchorTop: cursorY,
36973
+ width,
36974
+ height: block.floatingTableHeight ?? 1,
36975
+ pageIndex
36976
+ });
36977
+ rect.y += block.floatingTableOffsetY ?? 0;
36978
+ await drawTableBlock(
36979
+ writer,
36980
+ pageIndex,
36981
+ { ...block, estimatedHeight: rect.height },
36982
+ document2,
36983
+ rect.x,
36984
+ rect.y,
36985
+ contentWidth,
36986
+ fontRegistry,
36987
+ listOrdinals,
36988
+ blockDrawers
36989
+ );
36990
+ break;
36991
+ }
36194
36992
  await drawTableBlock(
36195
36993
  writer,
36196
36994
  pageIndex,
@@ -36382,227 +37180,6 @@ class PdfFontRegistry {
36382
37180
  return matchedFamilies;
36383
37181
  }
36384
37182
  }
36385
- class SimpleTextLayouter {
36386
- constructor(font) {
36387
- this.font = font;
36388
- }
36389
- layout(text) {
36390
- const glyphs = [];
36391
- const positions = [];
36392
- let advanceWidth = 0;
36393
- for (const char of text) {
36394
- const codePoint = char.codePointAt(0) ?? 65533;
36395
- const glyphId = this.font.glyphForCodePoint(codePoint);
36396
- const glyphAdvance = this.font.advanceWidthForGlyph(glyphId);
36397
- glyphs.push({
36398
- id: glyphId,
36399
- codePoints: glyphId === 0 ? [65533] : [codePoint],
36400
- advanceWidth: glyphAdvance
36401
- });
36402
- positions.push({ xAdvance: glyphAdvance });
36403
- advanceWidth += glyphAdvance;
36404
- }
36405
- return { glyphs, positions, advanceWidth };
36406
- }
36407
- }
36408
- function view(bytes) {
36409
- return new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
36410
- }
36411
- function u16(bytes, offset) {
36412
- return view(bytes).getUint16(offset);
36413
- }
36414
- function i16(bytes, offset) {
36415
- return view(bytes).getInt16(offset);
36416
- }
36417
- function writeU16(target, offset, value) {
36418
- view(target).setUint16(offset, value, false);
36419
- }
36420
- function writeU32(target, offset, value) {
36421
- view(target).setUint32(offset, value, false);
36422
- }
36423
- function pad4(length) {
36424
- return length + 3 & -4;
36425
- }
36426
- function concat(chunks) {
36427
- const total = chunks.reduce((sum, chunk) => sum + pad4(chunk.byteLength), 0);
36428
- const result = new Uint8Array(total);
36429
- let offset = 0;
36430
- for (const chunk of chunks) {
36431
- result.set(chunk, offset);
36432
- offset += pad4(chunk.byteLength);
36433
- }
36434
- return result;
36435
- }
36436
- function readLoca(loca, indexToLocFormat) {
36437
- const offsets = [];
36438
- const table = view(loca);
36439
- if (indexToLocFormat === 0) {
36440
- for (let offset = 0; offset + 1 < loca.byteLength; offset += 2) {
36441
- offsets.push(table.getUint16(offset) * 2);
36442
- }
36443
- } else {
36444
- for (let offset = 0; offset + 3 < loca.byteLength; offset += 4) {
36445
- offsets.push(table.getUint32(offset));
36446
- }
36447
- }
36448
- return offsets;
36449
- }
36450
- function glyphRange(offsets, glyphId) {
36451
- const start = offsets[glyphId];
36452
- const end = offsets[glyphId + 1];
36453
- return start === void 0 || end === void 0 ? null : { start, end };
36454
- }
36455
- function collectCompositeGlyphs(glyph, addGlyph) {
36456
- if (glyph.byteLength < 10 || i16(glyph, 0) >= 0) {
36457
- return;
36458
- }
36459
- let offset = 10;
36460
- let flags = 0;
36461
- do {
36462
- if (offset + 4 > glyph.byteLength) return;
36463
- flags = u16(glyph, offset);
36464
- addGlyph(u16(glyph, offset + 2));
36465
- offset += 4;
36466
- offset += flags & 1 ? 4 : 2;
36467
- if (flags & 8) offset += 2;
36468
- else if (flags & 64) offset += 4;
36469
- else if (flags & 128) offset += 8;
36470
- } while (flags & 32);
36471
- }
36472
- function subsetClosure(font, initialGlyphs) {
36473
- const glyf = font.getRawTableData("glyf");
36474
- const loca = font.getRawTableData("loca");
36475
- const head = font.getRawTableData("head");
36476
- if (!glyf || !loca || !head) {
36477
- return Array.from(/* @__PURE__ */ new Set([0, ...initialGlyphs])).sort((a, b) => a - b);
36478
- }
36479
- const offsets = readLoca(loca, u16(head, 50));
36480
- const used = /* @__PURE__ */ new Set([0, ...initialGlyphs]);
36481
- const stack = Array.from(used);
36482
- while (stack.length > 0) {
36483
- const glyphId = stack.pop();
36484
- const range = glyphRange(offsets, glyphId);
36485
- if (!range || range.end <= range.start || range.end > glyf.byteLength) {
36486
- continue;
36487
- }
36488
- const glyph = glyf.slice(range.start, range.end);
36489
- collectCompositeGlyphs(glyph, (componentId) => {
36490
- if (!used.has(componentId)) {
36491
- used.add(componentId);
36492
- stack.push(componentId);
36493
- }
36494
- });
36495
- }
36496
- return Array.from(used).sort((a, b) => a - b);
36497
- }
36498
- function buildLoca(offsets) {
36499
- const loca = new Uint8Array(offsets.length * 4);
36500
- offsets.forEach((offset, index) => writeU32(loca, index * 4, offset));
36501
- return loca;
36502
- }
36503
- function buildHmtx(font, maxGlyphId) {
36504
- const hmtx = new Uint8Array((maxGlyphId + 1) * 4);
36505
- for (let glyphId = 0; glyphId <= maxGlyphId; glyphId += 1) {
36506
- writeU16(hmtx, glyphId * 4, font.advanceWidthForGlyph(glyphId));
36507
- writeU16(hmtx, glyphId * 4 + 2, 0);
36508
- }
36509
- return hmtx;
36510
- }
36511
- function buildSubsetTables(font, glyphIds) {
36512
- const glyf = font.getRawTableData("glyf");
36513
- const loca = font.getRawTableData("loca");
36514
- const head = font.getRawTableData("head");
36515
- const hhea = font.getRawTableData("hhea");
36516
- const maxp = font.getRawTableData("maxp");
36517
- const cmap = font.getRawTableData("cmap");
36518
- if (!glyf || !loca || !head || !hhea || !maxp || !cmap) {
36519
- throw new Error("Missing required TrueType tables for subsetting");
36520
- }
36521
- const maxGlyphId = Math.max(0, ...glyphIds);
36522
- const used = new Set(glyphIds);
36523
- const sourceOffsets = readLoca(loca, u16(head, 50));
36524
- const locaOffsets = [];
36525
- const glyfChunks = [];
36526
- let glyfOffset = 0;
36527
- for (let glyphId = 0; glyphId <= maxGlyphId; glyphId += 1) {
36528
- locaOffsets.push(glyfOffset);
36529
- const range = glyphRange(sourceOffsets, glyphId);
36530
- if (used.has(glyphId) && range && range.end > range.start) {
36531
- const glyph = glyf.slice(range.start, range.end);
36532
- glyfChunks.push(glyph);
36533
- glyfOffset += pad4(glyph.byteLength);
36534
- }
36535
- }
36536
- locaOffsets.push(glyfOffset);
36537
- const newHead = head.slice();
36538
- writeU32(newHead, 8, 0);
36539
- writeU16(newHead, 50, 1);
36540
- const newHhea = hhea.slice();
36541
- writeU16(newHhea, 34, maxGlyphId + 1);
36542
- const newMaxp = maxp.slice();
36543
- writeU16(newMaxp, 4, maxGlyphId + 1);
36544
- const tables = {
36545
- cmap,
36546
- head: newHead,
36547
- hhea: newHhea,
36548
- hmtx: buildHmtx(font, maxGlyphId),
36549
- loca: buildLoca(locaOffsets),
36550
- maxp: newMaxp,
36551
- glyf: concat(glyfChunks)
36552
- };
36553
- for (const tag of ["OS/2", "name", "post"]) {
36554
- const table = font.getRawTableData(tag);
36555
- if (table) tables[tag] = table;
36556
- }
36557
- return tables;
36558
- }
36559
- class TrueTypePdfFontSubsetter {
36560
- createSubset(font, glyphs) {
36561
- const unicodeByGlyph = /* @__PURE__ */ new Map();
36562
- const initialGlyphs = [];
36563
- for (const glyph of glyphs) {
36564
- initialGlyphs.push(glyph.id);
36565
- if (!unicodeByGlyph.has(glyph.id)) {
36566
- unicodeByGlyph.set(glyph.id, glyph.codePoints);
36567
- }
36568
- }
36569
- const glyphIds = subsetClosure(font, initialGlyphs);
36570
- const tables = buildSubsetTables(font, glyphIds);
36571
- const fontFile = buildSfnt(
36572
- 65536,
36573
- new Map(
36574
- Object.entries(tables).map(([tag, data]) => [
36575
- tag.charCodeAt(0) << 24 | tag.charCodeAt(1) << 16 | tag.charCodeAt(2) << 8 | tag.charCodeAt(3),
36576
- data
36577
- ])
36578
- )
36579
- ).ttf;
36580
- const maxGlyphId = Math.max(0, ...glyphIds);
36581
- const widths = [];
36582
- const unicode = [];
36583
- for (let glyphId = 0; glyphId <= maxGlyphId; glyphId += 1) {
36584
- widths[glyphId] = font.advanceWidthForGlyph(glyphId) / font.unitsPerEm * 1e3;
36585
- unicode[glyphId] = unicodeByGlyph.get(glyphId) ?? [0];
36586
- }
36587
- return {
36588
- fontFile,
36589
- widths,
36590
- unicode,
36591
- encodeGlyph: (glyphId) => glyphId
36592
- };
36593
- }
36594
- }
36595
- function parseEmbeddedFontSync(sourceBytes) {
36596
- const sfntBytes = defaultFontDecoderRegistry.decodeSync(sourceBytes);
36597
- return SfntFontProgram.parse(sfntBytes);
36598
- }
36599
- function createPdfEmbeddableFont(program) {
36600
- return {
36601
- program,
36602
- layouter: new SimpleTextLayouter(program),
36603
- subsetter: new TrueTypePdfFontSubsetter()
36604
- };
36605
- }
36606
37183
  const PDF_HEADER = "%PDF-1.4\n% Oasis PDF\n";
36607
37184
  const DEFAULT_PDF_FONT_RESOURCES = [
36608
37185
  { kind: "base14", resourceName: "F1", baseFont: "Helvetica" },
@@ -36796,53 +37373,15 @@ function textMarkerComment(value) {
36796
37373
  );
36797
37374
  return `% OasisText ${encodePdfUtf16Hex(codePoints)}`;
36798
37375
  }
36799
- class OasisPdfWriter {
36800
- constructor(fontResources = DEFAULT_PDF_FONT_RESOURCES) {
36801
- __publicField(this, "pages", []);
36802
- __publicField(this, "fontResources", /* @__PURE__ */ new Map());
36803
- __publicField(this, "unicodeFontStates", /* @__PURE__ */ new Map());
36804
- __publicField(this, "usedFontResourceNames", /* @__PURE__ */ new Set());
36805
- __publicField(this, "imageResources", /* @__PURE__ */ new Map());
36806
- for (const resource of fontResources) {
36807
- this.registerFontResource(resource);
36808
- }
37376
+ class PdfContentStream {
37377
+ constructor(page, fonts, images) {
37378
+ this.page = page;
37379
+ this.fonts = fonts;
37380
+ this.images = images;
36809
37381
  }
36810
- registerFontResource(resource) {
36811
- this.fontResources.set(resource.resourceName, resource);
36812
- if (resource.kind === "unicode" && !this.unicodeFontStates.has(resource.resourceName)) {
36813
- const font = createPdfEmbeddableFont(
36814
- parseEmbeddedFontSync(resource.fontData)
36815
- );
36816
- const scale = 1e3 / font.program.unitsPerEm;
36817
- const notdef = {
36818
- id: 0,
36819
- codePoints: [0],
36820
- advanceWidth: font.program.advanceWidthForGlyph(0)
36821
- };
36822
- this.unicodeFontStates.set(resource.resourceName, {
36823
- resource,
36824
- font,
36825
- usedGlyphs: /* @__PURE__ */ new Map([[0, notdef]]),
36826
- scale,
36827
- layoutCache: /* @__PURE__ */ new Map()
36828
- });
36829
- }
36830
- }
36831
- addPage(size) {
36832
- this.pages.push({
36833
- width: Math.max(1, size.width),
36834
- height: Math.max(1, size.height),
36835
- commands: [],
36836
- imageResourceNames: /* @__PURE__ */ new Set()
36837
- });
36838
- return this.pages.length - 1;
36839
- }
36840
- getPageCount() {
36841
- return this.pages.length;
36842
- }
36843
- drawRect(pageIndex, options) {
36844
- const page = this.pages[pageIndex];
36845
- if (!page || options.width <= 0 || options.height <= 0) {
37382
+ drawRect(options) {
37383
+ const page = this.page;
37384
+ if (options.width <= 0 || options.height <= 0) {
36846
37385
  return;
36847
37386
  }
36848
37387
  const commands = ["q"];
@@ -36872,11 +37411,8 @@ class OasisPdfWriter {
36872
37411
  commands.push("Q");
36873
37412
  page.commands.push(commands.join("\n"));
36874
37413
  }
36875
- drawLine(pageIndex, options) {
36876
- const page = this.pages[pageIndex];
36877
- if (!page) {
36878
- return;
36879
- }
37414
+ drawLine(options) {
37415
+ const page = this.page;
36880
37416
  const dashCommand = options.dashArray && options.dashArray.length > 0 ? `[${options.dashArray.map((value) => formatNumber(value)).join(" ")}] 0 d` : null;
36881
37417
  const commands = [
36882
37418
  "q",
@@ -36897,9 +37433,9 @@ class OasisPdfWriter {
36897
37433
  // Fills/strokes an arbitrary path. Segment coordinates are in points with a
36898
37434
  // top-left origin (callers convert px→pt, like drawRect/drawLine); the y axis
36899
37435
  // is flipped here to the PDF bottom-left origin.
36900
- drawPath(pageIndex, options) {
36901
- const page = this.pages[pageIndex];
36902
- if (!page || options.segments.length === 0) {
37436
+ drawPath(options) {
37437
+ const page = this.page;
37438
+ if (options.segments.length === 0) {
36903
37439
  return;
36904
37440
  }
36905
37441
  if (!options.fill && !options.stroke) {
@@ -36948,24 +37484,18 @@ class OasisPdfWriter {
36948
37484
  }
36949
37485
  // Saves the graphics state (`q`). Pair with restoreGraphicsState. Any draw
36950
37486
  // commands emitted in between inherit the current transform/clip.
36951
- saveGraphicsState(pageIndex) {
36952
- const page = this.pages[pageIndex];
36953
- if (page) {
36954
- page.commands.push("q");
36955
- }
37487
+ saveGraphicsState() {
37488
+ this.page.commands.push("q");
36956
37489
  }
36957
- restoreGraphicsState(pageIndex) {
36958
- const page = this.pages[pageIndex];
36959
- if (page) {
36960
- page.commands.push("Q");
36961
- }
37490
+ restoreGraphicsState() {
37491
+ this.page.commands.push("Q");
36962
37492
  }
36963
37493
  // Concatenates a clockwise rotation (in degrees, matching the canvas/editor
36964
37494
  // convention) about a top-left-origin point onto the current CTM. Must sit
36965
37495
  // inside a saveGraphicsState/restoreGraphicsState pair.
36966
- rotateAbout(pageIndex, centerX, centerY, degrees) {
36967
- const page = this.pages[pageIndex];
36968
- if (!page || !degrees) {
37496
+ rotateAbout(centerX, centerY, degrees) {
37497
+ const page = this.page;
37498
+ if (!degrees) {
36969
37499
  return;
36970
37500
  }
36971
37501
  const cyf = page.height - centerY;
@@ -36980,9 +37510,9 @@ class OasisPdfWriter {
36980
37510
  }
36981
37511
  // Intersects the clip path with a rectangle (top-left origin). Must sit inside
36982
37512
  // a saveGraphicsState/restoreGraphicsState pair so the clip can be undone.
36983
- clipRect(pageIndex, x, y, width, height) {
36984
- const page = this.pages[pageIndex];
36985
- if (!page || width <= 0 || height <= 0) {
37513
+ clipRect(x, y, width, height) {
37514
+ const page = this.page;
37515
+ if (width <= 0 || height <= 0) {
36986
37516
  return;
36987
37517
  }
36988
37518
  page.commands.push(
@@ -36991,48 +37521,42 @@ class OasisPdfWriter {
36991
37521
  "n"
36992
37522
  );
36993
37523
  }
36994
- drawText(pageIndex, options) {
36995
- const page = this.pages[pageIndex];
36996
- if (!page || options.text.length === 0) {
37524
+ drawText(options) {
37525
+ if (options.text.length === 0) {
36997
37526
  return;
36998
37527
  }
36999
- const fontResourceName = resolveFontName(options);
37000
- this.usedFontResourceNames.add(fontResourceName);
37001
- const unicodeFont = this.unicodeFontStates.get(fontResourceName);
37002
- if (unicodeFont) {
37003
- this.drawUnicodeText(page, unicodeFont, options);
37528
+ const fontResourceName = this.fonts.resolveAndMarkFontName(options);
37529
+ const unicodeState = this.fonts.getUnicodeState(fontResourceName);
37530
+ const showCommand = unicodeState ? this.fonts.buildUnicodeShowCommand(unicodeState, options.text) : `<${encodePdfHexString(options.text)}> Tj`;
37531
+ if (showCommand === null) {
37004
37532
  return;
37005
37533
  }
37534
+ this.emitTextBlock(fontResourceName, showCommand, options);
37535
+ }
37536
+ emitTextBlock(fontResourceName, showCommand, options) {
37537
+ const page = this.page;
37006
37538
  page.commands.push(
37007
37539
  [
37008
37540
  textMarkerComment(options.text),
37009
37541
  "BT",
37010
37542
  colorCommand(options.color, "rg", [0, 0, 0]),
37011
37543
  `/${fontResourceName} ${formatNumber(options.fontSize ?? 12)} Tf`,
37544
+ ...options.renderMode && options.renderMode !== 0 ? [
37545
+ colorCommand(options.color, "RG", [0, 0, 0]),
37546
+ `${formatNumber(Math.max(0.3, (options.fontSize ?? 12) * 0.03))} w`,
37547
+ `${options.renderMode} Tr`
37548
+ ] : [],
37012
37549
  ...options.horizontalScale && options.horizontalScale > 0 && options.horizontalScale !== 100 ? [`${formatNumber(options.horizontalScale)} Tz`] : [],
37013
37550
  ...options.characterSpacing && options.characterSpacing !== 0 ? [`${formatNumber(options.characterSpacing)} Tc`] : [],
37014
37551
  `${formatNumber(options.x)} ${formatNumber(page.height - options.y)} Td`,
37015
- `<${encodePdfHexString(options.text)}> Tj`,
37552
+ showCommand,
37016
37553
  "ET"
37017
37554
  ].join("\n")
37018
37555
  );
37019
37556
  }
37020
- registerImageResource(resource) {
37021
- const resourceName = resource.resourceName ?? `Im${this.imageResources.size + 1}`;
37022
- if (!this.imageResources.has(resourceName)) {
37023
- this.imageResources.set(resourceName, {
37024
- resourceName,
37025
- width: Math.max(1, Math.round(resource.width)),
37026
- height: Math.max(1, Math.round(resource.height)),
37027
- data: resource.data,
37028
- filter: resource.filter
37029
- });
37030
- }
37031
- return resourceName;
37032
- }
37033
- drawImage(pageIndex, options) {
37034
- const page = this.pages[pageIndex];
37035
- if (!page || options.width <= 0 || options.height <= 0 || !this.imageResources.has(options.resourceName)) {
37557
+ drawImage(options) {
37558
+ const page = this.page;
37559
+ if (options.width <= 0 || options.height <= 0 || !this.images.has(options.resourceName)) {
37036
37560
  return;
37037
37561
  }
37038
37562
  page.imageResourceNames.add(options.resourceName);
@@ -37083,72 +37607,292 @@ class OasisPdfWriter {
37083
37607
  ].join("\n")
37084
37608
  );
37085
37609
  }
37086
- layoutUnicodeText(state, text) {
37087
- const cached = state.layoutCache.get(text);
37088
- if (cached) {
37089
- return cached;
37610
+ }
37611
+ class SimpleTextLayouter {
37612
+ constructor(font) {
37613
+ this.font = font;
37614
+ }
37615
+ layout(text) {
37616
+ const glyphs = [];
37617
+ const positions = [];
37618
+ let advanceWidth = 0;
37619
+ for (const char of text) {
37620
+ const codePoint = char.codePointAt(0) ?? 65533;
37621
+ const glyphId = this.font.glyphForCodePoint(codePoint);
37622
+ const glyphAdvance = this.font.advanceWidthForGlyph(glyphId);
37623
+ glyphs.push({
37624
+ id: glyphId,
37625
+ codePoints: glyphId === 0 ? [65533] : [codePoint],
37626
+ advanceWidth: glyphAdvance
37627
+ });
37628
+ positions.push({ xAdvance: glyphAdvance });
37629
+ advanceWidth += glyphAdvance;
37090
37630
  }
37091
- const run = state.font.layouter.layout(text);
37092
- state.layoutCache.set(text, run);
37093
- return run;
37631
+ return { glyphs, positions, advanceWidth };
37094
37632
  }
37095
- encodeUnicodeGlyphRun(state, run) {
37096
- return run.glyphs.map((glyph, index) => {
37097
- if (!state.usedGlyphs.has(glyph.id)) {
37098
- state.usedGlyphs.set(glyph.id, glyph);
37633
+ }
37634
+ function view(bytes) {
37635
+ return new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
37636
+ }
37637
+ function u16(bytes, offset) {
37638
+ return view(bytes).getUint16(offset);
37639
+ }
37640
+ function i16(bytes, offset) {
37641
+ return view(bytes).getInt16(offset);
37642
+ }
37643
+ function writeU16(target, offset, value) {
37644
+ view(target).setUint16(offset, value, false);
37645
+ }
37646
+ function writeU32(target, offset, value) {
37647
+ view(target).setUint32(offset, value, false);
37648
+ }
37649
+ function pad4(length) {
37650
+ return length + 3 & -4;
37651
+ }
37652
+ function concat(chunks) {
37653
+ const total = chunks.reduce((sum, chunk) => sum + pad4(chunk.byteLength), 0);
37654
+ const result = new Uint8Array(total);
37655
+ let offset = 0;
37656
+ for (const chunk of chunks) {
37657
+ result.set(chunk, offset);
37658
+ offset += pad4(chunk.byteLength);
37659
+ }
37660
+ return result;
37661
+ }
37662
+ function readLoca(loca, indexToLocFormat) {
37663
+ const offsets = [];
37664
+ const table = view(loca);
37665
+ if (indexToLocFormat === 0) {
37666
+ for (let offset = 0; offset + 1 < loca.byteLength; offset += 2) {
37667
+ offsets.push(table.getUint16(offset) * 2);
37668
+ }
37669
+ } else {
37670
+ for (let offset = 0; offset + 3 < loca.byteLength; offset += 4) {
37671
+ offsets.push(table.getUint32(offset));
37672
+ }
37673
+ }
37674
+ return offsets;
37675
+ }
37676
+ function glyphRange(offsets, glyphId) {
37677
+ const start = offsets[glyphId];
37678
+ const end = offsets[glyphId + 1];
37679
+ return start === void 0 || end === void 0 ? null : { start, end };
37680
+ }
37681
+ function collectCompositeGlyphs(glyph, addGlyph) {
37682
+ if (glyph.byteLength < 10 || i16(glyph, 0) >= 0) {
37683
+ return;
37684
+ }
37685
+ let offset = 10;
37686
+ let flags = 0;
37687
+ do {
37688
+ if (offset + 4 > glyph.byteLength) return;
37689
+ flags = u16(glyph, offset);
37690
+ addGlyph(u16(glyph, offset + 2));
37691
+ offset += 4;
37692
+ offset += flags & 1 ? 4 : 2;
37693
+ if (flags & 8) offset += 2;
37694
+ else if (flags & 64) offset += 4;
37695
+ else if (flags & 128) offset += 8;
37696
+ } while (flags & 32);
37697
+ }
37698
+ function subsetClosure(font, initialGlyphs) {
37699
+ const glyf = font.getRawTableData("glyf");
37700
+ const loca = font.getRawTableData("loca");
37701
+ const head = font.getRawTableData("head");
37702
+ if (!glyf || !loca || !head) {
37703
+ return Array.from(/* @__PURE__ */ new Set([0, ...initialGlyphs])).sort((a, b) => a - b);
37704
+ }
37705
+ const offsets = readLoca(loca, u16(head, 50));
37706
+ const used = /* @__PURE__ */ new Set([0, ...initialGlyphs]);
37707
+ const stack = Array.from(used);
37708
+ while (stack.length > 0) {
37709
+ const glyphId = stack.pop();
37710
+ const range = glyphRange(offsets, glyphId);
37711
+ if (!range || range.end <= range.start || range.end > glyf.byteLength) {
37712
+ continue;
37713
+ }
37714
+ const glyph = glyf.slice(range.start, range.end);
37715
+ collectCompositeGlyphs(glyph, (componentId) => {
37716
+ if (!used.has(componentId)) {
37717
+ used.add(componentId);
37718
+ stack.push(componentId);
37099
37719
  }
37100
- const position = run.positions[index];
37101
- const nominalWidth = glyph.advanceWidth * state.scale;
37102
- const desiredAdvance = ((position == null ? void 0 : position.xAdvance) ?? glyph.advanceWidth) * state.scale;
37103
- return { glyphId: glyph.id, nominalWidth, desiredAdvance };
37104
37720
  });
37105
37721
  }
37106
- drawUnicodeText(page, state, options) {
37107
- const run = this.layoutUnicodeText(state, options.text);
37722
+ return Array.from(used).sort((a, b) => a - b);
37723
+ }
37724
+ function buildLoca(offsets) {
37725
+ const loca = new Uint8Array(offsets.length * 4);
37726
+ offsets.forEach((offset, index) => writeU32(loca, index * 4, offset));
37727
+ return loca;
37728
+ }
37729
+ function buildHmtx(font, maxGlyphId) {
37730
+ const hmtx = new Uint8Array((maxGlyphId + 1) * 4);
37731
+ for (let glyphId = 0; glyphId <= maxGlyphId; glyphId += 1) {
37732
+ writeU16(hmtx, glyphId * 4, font.advanceWidthForGlyph(glyphId));
37733
+ writeU16(hmtx, glyphId * 4 + 2, 0);
37734
+ }
37735
+ return hmtx;
37736
+ }
37737
+ function buildSubsetTables(font, glyphIds) {
37738
+ const glyf = font.getRawTableData("glyf");
37739
+ const loca = font.getRawTableData("loca");
37740
+ const head = font.getRawTableData("head");
37741
+ const hhea = font.getRawTableData("hhea");
37742
+ const maxp = font.getRawTableData("maxp");
37743
+ const cmap = font.getRawTableData("cmap");
37744
+ if (!glyf || !loca || !head || !hhea || !maxp || !cmap) {
37745
+ throw new Error("Missing required TrueType tables for subsetting");
37746
+ }
37747
+ const maxGlyphId = Math.max(0, ...glyphIds);
37748
+ const used = new Set(glyphIds);
37749
+ const sourceOffsets = readLoca(loca, u16(head, 50));
37750
+ const locaOffsets = [];
37751
+ const glyfChunks = [];
37752
+ let glyfOffset = 0;
37753
+ for (let glyphId = 0; glyphId <= maxGlyphId; glyphId += 1) {
37754
+ locaOffsets.push(glyfOffset);
37755
+ const range = glyphRange(sourceOffsets, glyphId);
37756
+ if (used.has(glyphId) && range && range.end > range.start) {
37757
+ const glyph = glyf.slice(range.start, range.end);
37758
+ glyfChunks.push(glyph);
37759
+ glyfOffset += pad4(glyph.byteLength);
37760
+ }
37761
+ }
37762
+ locaOffsets.push(glyfOffset);
37763
+ const newHead = head.slice();
37764
+ writeU32(newHead, 8, 0);
37765
+ writeU16(newHead, 50, 1);
37766
+ const newHhea = hhea.slice();
37767
+ writeU16(newHhea, 34, maxGlyphId + 1);
37768
+ const newMaxp = maxp.slice();
37769
+ writeU16(newMaxp, 4, maxGlyphId + 1);
37770
+ const tables = {
37771
+ cmap,
37772
+ head: newHead,
37773
+ hhea: newHhea,
37774
+ hmtx: buildHmtx(font, maxGlyphId),
37775
+ loca: buildLoca(locaOffsets),
37776
+ maxp: newMaxp,
37777
+ glyf: concat(glyfChunks)
37778
+ };
37779
+ for (const tag of ["OS/2", "name", "post"]) {
37780
+ const table = font.getRawTableData(tag);
37781
+ if (table) tables[tag] = table;
37782
+ }
37783
+ return tables;
37784
+ }
37785
+ class TrueTypePdfFontSubsetter {
37786
+ createSubset(font, glyphs) {
37787
+ const unicodeByGlyph = /* @__PURE__ */ new Map();
37788
+ const initialGlyphs = [];
37789
+ for (const glyph of glyphs) {
37790
+ initialGlyphs.push(glyph.id);
37791
+ if (!unicodeByGlyph.has(glyph.id)) {
37792
+ unicodeByGlyph.set(glyph.id, glyph.codePoints);
37793
+ }
37794
+ }
37795
+ const glyphIds = subsetClosure(font, initialGlyphs);
37796
+ const tables = buildSubsetTables(font, glyphIds);
37797
+ const fontFile = buildSfnt(
37798
+ 65536,
37799
+ new Map(
37800
+ Object.entries(tables).map(([tag, data]) => [
37801
+ tag.charCodeAt(0) << 24 | tag.charCodeAt(1) << 16 | tag.charCodeAt(2) << 8 | tag.charCodeAt(3),
37802
+ data
37803
+ ])
37804
+ )
37805
+ ).ttf;
37806
+ const maxGlyphId = Math.max(0, ...glyphIds);
37807
+ const widths = [];
37808
+ const unicode = [];
37809
+ for (let glyphId = 0; glyphId <= maxGlyphId; glyphId += 1) {
37810
+ widths[glyphId] = font.advanceWidthForGlyph(glyphId) / font.unitsPerEm * 1e3;
37811
+ unicode[glyphId] = unicodeByGlyph.get(glyphId) ?? [0];
37812
+ }
37813
+ return {
37814
+ fontFile,
37815
+ widths,
37816
+ unicode,
37817
+ encodeGlyph: (glyphId) => glyphId
37818
+ };
37819
+ }
37820
+ }
37821
+ function parseEmbeddedFontSync(sourceBytes) {
37822
+ const sfntBytes = defaultFontDecoderRegistry.decodeSync(sourceBytes);
37823
+ return SfntFontProgram.parse(sfntBytes);
37824
+ }
37825
+ function createPdfEmbeddableFont(program) {
37826
+ return {
37827
+ program,
37828
+ layouter: new SimpleTextLayouter(program),
37829
+ subsetter: new TrueTypePdfFontSubsetter()
37830
+ };
37831
+ }
37832
+ class PdfFontTable {
37833
+ constructor(fontResources) {
37834
+ __publicField(this, "fontResources", /* @__PURE__ */ new Map());
37835
+ __publicField(this, "unicodeFontStates", /* @__PURE__ */ new Map());
37836
+ __publicField(this, "usedFontResourceNames", /* @__PURE__ */ new Set());
37837
+ for (const resource of fontResources) {
37838
+ this.registerFontResource(resource);
37839
+ }
37840
+ }
37841
+ registerFontResource(resource) {
37842
+ this.fontResources.set(resource.resourceName, resource);
37843
+ if (resource.kind === "unicode" && !this.unicodeFontStates.has(resource.resourceName)) {
37844
+ const font = createPdfEmbeddableFont(
37845
+ parseEmbeddedFontSync(resource.fontData)
37846
+ );
37847
+ const scale = 1e3 / font.program.unitsPerEm;
37848
+ const notdef = {
37849
+ id: 0,
37850
+ codePoints: [0],
37851
+ advanceWidth: font.program.advanceWidthForGlyph(0)
37852
+ };
37853
+ this.unicodeFontStates.set(resource.resourceName, {
37854
+ resource,
37855
+ font,
37856
+ usedGlyphs: /* @__PURE__ */ new Map([[0, notdef]]),
37857
+ scale,
37858
+ layoutCache: /* @__PURE__ */ new Map()
37859
+ });
37860
+ }
37861
+ }
37862
+ /** Resolves the font resource a run uses and marks it as referenced. */
37863
+ resolveAndMarkFontName(options) {
37864
+ const fontResourceName = resolveFontName(options);
37865
+ this.usedFontResourceNames.add(fontResourceName);
37866
+ return fontResourceName;
37867
+ }
37868
+ getUnicodeState(resourceName) {
37869
+ return this.unicodeFontStates.get(resourceName);
37870
+ }
37871
+ /**
37872
+ * Builds the glyph-show operator (`<...> Tj` or `[...] TJ`) for an embedded
37873
+ * Unicode run, recording the glyphs used for subsetting. Returns `null` when
37874
+ * the run produced no glyphs so the caller can skip emission entirely.
37875
+ */
37876
+ buildUnicodeShowCommand(state, text) {
37877
+ const run = this.layoutUnicodeText(state, text);
37108
37878
  const encoded = this.encodeUnicodeGlyphRun(state, run);
37109
37879
  if (encoded.length === 0) {
37110
- return;
37880
+ return null;
37111
37881
  }
37112
37882
  const usesAdjustments = encoded.some(
37113
37883
  (glyph) => Math.abs(glyph.nominalWidth - glyph.desiredAdvance) > 0.01
37114
37884
  );
37115
- const textCommand = usesAdjustments ? `[${encoded.map((glyph) => {
37885
+ return usesAdjustments ? `[${encoded.map((glyph) => {
37116
37886
  const adjustment = glyph.nominalWidth - glyph.desiredAdvance;
37117
37887
  return adjustment === 0 ? `<${encodeGlyphHex(glyph.glyphId)}>` : `<${encodeGlyphHex(glyph.glyphId)}> ${formatNumber(adjustment)}`;
37118
37888
  }).join(" ")}] TJ` : `<${encoded.map((glyph) => encodeGlyphHex(glyph.glyphId)).join("")}> Tj`;
37119
- page.commands.push(
37120
- [
37121
- textMarkerComment(options.text),
37122
- "BT",
37123
- colorCommand(options.color, "rg", [0, 0, 0]),
37124
- `/${state.resource.resourceName} ${formatNumber(options.fontSize ?? 12)} Tf`,
37125
- ...options.horizontalScale && options.horizontalScale > 0 && options.horizontalScale !== 100 ? [`${formatNumber(options.horizontalScale)} Tz`] : [],
37126
- ...options.characterSpacing && options.characterSpacing !== 0 ? [`${formatNumber(options.characterSpacing)} Tc`] : [],
37127
- `${formatNumber(options.x)} ${formatNumber(page.height - options.y)} Td`,
37128
- textCommand,
37129
- "ET"
37130
- ].join("\n")
37131
- );
37132
37889
  }
37133
- toArrayBuffer() {
37134
- const bytes = this.toUint8Array();
37135
- return Uint8Array.from(bytes).buffer;
37136
- }
37137
- toBlob() {
37138
- return new Blob([this.toArrayBuffer()], { type: "application/pdf" });
37139
- }
37140
- toUint8Array() {
37141
- if (this.pages.length === 0) {
37142
- this.addPage({ width: 612, height: 792 });
37143
- }
37144
- const objects = [];
37145
- const addObject = (body2) => {
37146
- const id = objects.length + 1;
37147
- objects.push({ id, body: body2 });
37148
- return id;
37149
- };
37150
- const catalogObjectId = addObject("");
37151
- const pagesObjectId = addObject("");
37890
+ /**
37891
+ * Emits the font objects (base-14 dictionaries and embedded Unicode font
37892
+ * programs) for every referenced resource and returns the `/Font` resource
37893
+ * dictionary XML for page objects.
37894
+ */
37895
+ buildFontObjects(addObject) {
37152
37896
  const fontResourceEntries = Array.from(this.fontResources.values()).filter(
37153
37897
  (resource) => resource.kind === "base14" || this.usedFontResourceNames.has(resource.resourceName)
37154
37898
  );
@@ -37161,86 +37905,28 @@ class OasisPdfWriter {
37161
37905
  }
37162
37906
  return addObject(fontResourceObjectBody(font));
37163
37907
  });
37164
- const fontResourceXml = fontResourceEntries.map((font, index) => `/${font.resourceName} ${fontObjectIds[index]} 0 R`).join(" ");
37165
- const imageObjectIds = /* @__PURE__ */ new Map();
37166
- for (const image of this.imageResources.values()) {
37167
- imageObjectIds.set(
37168
- image.resourceName,
37169
- this.addImageObject(image, addObject)
37170
- );
37171
- }
37172
- const pageObjectIds = [];
37173
- for (const page of this.pages) {
37174
- const stream = `${page.commands.join("\n")}
37175
- `;
37176
- const contentObjectId = addObject(
37177
- `<< /Length ${byteLength(stream)} >>
37178
- stream
37179
- ${stream}endstream`
37180
- );
37181
- const imageResourceXml = Array.from(page.imageResourceNames).map((resourceName) => {
37182
- const objectId = imageObjectIds.get(resourceName);
37183
- return objectId ? `/${resourceName} ${objectId} 0 R` : "";
37184
- }).filter(Boolean).join(" ");
37185
- const xObjectResourceXml = imageResourceXml ? ` /XObject << ${imageResourceXml} >>` : "";
37186
- const pageObjectId = addObject(
37187
- [
37188
- "<< /Type /Page",
37189
- `/Parent ${pagesObjectId} 0 R`,
37190
- `/MediaBox [0 0 ${formatNumber(page.width)} ${formatNumber(page.height)}]`,
37191
- `/Resources << /Font << ${fontResourceXml} >>${xObjectResourceXml} >>`,
37192
- `/Contents ${contentObjectId} 0 R`,
37193
- ">>"
37194
- ].join("\n")
37195
- );
37196
- pageObjectIds.push(pageObjectId);
37197
- }
37198
- objects[catalogObjectId - 1].body = `<< /Type /Catalog /Pages ${pagesObjectId} 0 R >>`;
37199
- objects[pagesObjectId - 1].body = [
37200
- "<< /Type /Pages",
37201
- `/Kids [${pageObjectIds.map((id) => `${id} 0 R`).join(" ")}]`,
37202
- `/Count ${pageObjectIds.length}`,
37203
- ">>"
37204
- ].join("\n");
37205
- let body = PDF_HEADER;
37206
- const offsets = [0];
37207
- for (const object of objects) {
37208
- offsets[object.id] = byteLength(body);
37209
- body += `${object.id} 0 obj
37210
- ${object.body}
37211
- endobj
37212
- `;
37213
- }
37214
- const xrefOffset = byteLength(body);
37215
- body += `xref
37216
- 0 ${objects.length + 1}
37217
- `;
37218
- body += "0000000000 65535 f \n";
37219
- for (const object of objects) {
37220
- body += `${String(offsets[object.id] ?? 0).padStart(10, "0")} 00000 n
37221
- `;
37908
+ const resourceXml = fontResourceEntries.map((font, index) => `/${font.resourceName} ${fontObjectIds[index]} 0 R`).join(" ");
37909
+ return { resourceXml };
37910
+ }
37911
+ layoutUnicodeText(state, text) {
37912
+ const cached = state.layoutCache.get(text);
37913
+ if (cached) {
37914
+ return cached;
37222
37915
  }
37223
- body += [
37224
- "trailer",
37225
- `<< /Size ${objects.length + 1} /Root ${catalogObjectId} 0 R >>`,
37226
- "startxref",
37227
- String(xrefOffset),
37228
- "%%EOF",
37229
- ""
37230
- ].join("\n");
37231
- return new TextEncoder().encode(body);
37916
+ const run = state.font.layouter.layout(text);
37917
+ state.layoutCache.set(text, run);
37918
+ return run;
37232
37919
  }
37233
- addImageObject(resource, addObject) {
37234
- return addObject(
37235
- asciiHexImageStreamObjectBody(resource.data, [
37236
- "/Type /XObject",
37237
- "/Subtype /Image",
37238
- `/Width ${resource.width}`,
37239
- `/Height ${resource.height}`,
37240
- "/ColorSpace /DeviceRGB",
37241
- "/BitsPerComponent 8"
37242
- ])
37243
- );
37920
+ encodeUnicodeGlyphRun(state, run) {
37921
+ return run.glyphs.map((glyph, index) => {
37922
+ if (!state.usedGlyphs.has(glyph.id)) {
37923
+ state.usedGlyphs.set(glyph.id, glyph);
37924
+ }
37925
+ const position = run.positions[index];
37926
+ const nominalWidth = glyph.advanceWidth * state.scale;
37927
+ const desiredAdvance = ((position == null ? void 0 : position.xAdvance) ?? glyph.advanceWidth) * state.scale;
37928
+ return { glyphId: glyph.id, nominalWidth, desiredAdvance };
37929
+ });
37244
37930
  }
37245
37931
  addUnicodeFontObjects(state, addObject) {
37246
37932
  const subset = state.font.subsetter.createSubset(
@@ -37318,6 +38004,200 @@ endobj
37318
38004
  );
37319
38005
  }
37320
38006
  }
38007
+ class PdfImageTable {
38008
+ constructor() {
38009
+ __publicField(this, "imageResources", /* @__PURE__ */ new Map());
38010
+ }
38011
+ registerImageResource(resource) {
38012
+ const resourceName = resource.resourceName ?? `Im${this.imageResources.size + 1}`;
38013
+ if (!this.imageResources.has(resourceName)) {
38014
+ this.imageResources.set(resourceName, {
38015
+ resourceName,
38016
+ width: Math.max(1, Math.round(resource.width)),
38017
+ height: Math.max(1, Math.round(resource.height)),
38018
+ data: resource.data,
38019
+ filter: resource.filter
38020
+ });
38021
+ }
38022
+ return resourceName;
38023
+ }
38024
+ has(resourceName) {
38025
+ return this.imageResources.has(resourceName);
38026
+ }
38027
+ /** Emits each registered image object, keyed by resource name for page maps. */
38028
+ buildImageObjects(addObject) {
38029
+ const imageObjectIds = /* @__PURE__ */ new Map();
38030
+ for (const image of this.imageResources.values()) {
38031
+ imageObjectIds.set(
38032
+ image.resourceName,
38033
+ this.addImageObject(image, addObject)
38034
+ );
38035
+ }
38036
+ return imageObjectIds;
38037
+ }
38038
+ addImageObject(resource, addObject) {
38039
+ return addObject(
38040
+ asciiHexImageStreamObjectBody(resource.data, [
38041
+ "/Type /XObject",
38042
+ "/Subtype /Image",
38043
+ `/Width ${resource.width}`,
38044
+ `/Height ${resource.height}`,
38045
+ "/ColorSpace /DeviceRGB",
38046
+ "/BitsPerComponent 8"
38047
+ ])
38048
+ );
38049
+ }
38050
+ }
38051
+ function serializePdfDocument(pages, fonts, images) {
38052
+ const objects = [];
38053
+ const addObject = (body2) => {
38054
+ const id = objects.length + 1;
38055
+ objects.push({ id, body: body2 });
38056
+ return id;
38057
+ };
38058
+ const catalogObjectId = addObject("");
38059
+ const pagesObjectId = addObject("");
38060
+ const { resourceXml: fontResourceXml } = fonts.buildFontObjects(addObject);
38061
+ const imageObjectIds = images.buildImageObjects(addObject);
38062
+ const pageObjectIds = [];
38063
+ for (const page of pages) {
38064
+ const stream = `${page.commands.join("\n")}
38065
+ `;
38066
+ const contentObjectId = addObject(
38067
+ `<< /Length ${byteLength(stream)} >>
38068
+ stream
38069
+ ${stream}endstream`
38070
+ );
38071
+ const imageResourceXml = Array.from(page.imageResourceNames).map((resourceName) => {
38072
+ const objectId = imageObjectIds.get(resourceName);
38073
+ return objectId ? `/${resourceName} ${objectId} 0 R` : "";
38074
+ }).filter(Boolean).join(" ");
38075
+ const xObjectResourceXml = imageResourceXml ? ` /XObject << ${imageResourceXml} >>` : "";
38076
+ const pageObjectId = addObject(
38077
+ [
38078
+ "<< /Type /Page",
38079
+ `/Parent ${pagesObjectId} 0 R`,
38080
+ `/MediaBox [0 0 ${formatNumber(page.width)} ${formatNumber(page.height)}]`,
38081
+ `/Resources << /Font << ${fontResourceXml} >>${xObjectResourceXml} >>`,
38082
+ `/Contents ${contentObjectId} 0 R`,
38083
+ ">>"
38084
+ ].join("\n")
38085
+ );
38086
+ pageObjectIds.push(pageObjectId);
38087
+ }
38088
+ objects[catalogObjectId - 1].body = `<< /Type /Catalog /Pages ${pagesObjectId} 0 R >>`;
38089
+ objects[pagesObjectId - 1].body = [
38090
+ "<< /Type /Pages",
38091
+ `/Kids [${pageObjectIds.map((id) => `${id} 0 R`).join(" ")}]`,
38092
+ `/Count ${pageObjectIds.length}`,
38093
+ ">>"
38094
+ ].join("\n");
38095
+ let body = PDF_HEADER;
38096
+ const offsets = [0];
38097
+ for (const object of objects) {
38098
+ offsets[object.id] = byteLength(body);
38099
+ body += `${object.id} 0 obj
38100
+ ${object.body}
38101
+ endobj
38102
+ `;
38103
+ }
38104
+ const xrefOffset = byteLength(body);
38105
+ body += `xref
38106
+ 0 ${objects.length + 1}
38107
+ `;
38108
+ body += "0000000000 65535 f \n";
38109
+ for (const object of objects) {
38110
+ body += `${String(offsets[object.id] ?? 0).padStart(10, "0")} 00000 n
38111
+ `;
38112
+ }
38113
+ body += [
38114
+ "trailer",
38115
+ `<< /Size ${objects.length + 1} /Root ${catalogObjectId} 0 R >>`,
38116
+ "startxref",
38117
+ String(xrefOffset),
38118
+ "%%EOF",
38119
+ ""
38120
+ ].join("\n");
38121
+ return new TextEncoder().encode(body);
38122
+ }
38123
+ class OasisPdfWriter {
38124
+ constructor(fontResources = DEFAULT_PDF_FONT_RESOURCES) {
38125
+ __publicField(this, "pages", []);
38126
+ __publicField(this, "streams", []);
38127
+ __publicField(this, "fonts");
38128
+ __publicField(this, "images", new PdfImageTable());
38129
+ this.fonts = new PdfFontTable(fontResources);
38130
+ }
38131
+ registerFontResource(resource) {
38132
+ this.fonts.registerFontResource(resource);
38133
+ }
38134
+ addPage(size) {
38135
+ const page = {
38136
+ width: Math.max(1, size.width),
38137
+ height: Math.max(1, size.height),
38138
+ commands: [],
38139
+ imageResourceNames: /* @__PURE__ */ new Set()
38140
+ };
38141
+ this.pages.push(page);
38142
+ this.streams.push(new PdfContentStream(page, this.fonts, this.images));
38143
+ return this.pages.length - 1;
38144
+ }
38145
+ getPageCount() {
38146
+ return this.pages.length;
38147
+ }
38148
+ drawRect(pageIndex, options) {
38149
+ var _a;
38150
+ (_a = this.streams[pageIndex]) == null ? void 0 : _a.drawRect(options);
38151
+ }
38152
+ drawLine(pageIndex, options) {
38153
+ var _a;
38154
+ (_a = this.streams[pageIndex]) == null ? void 0 : _a.drawLine(options);
38155
+ }
38156
+ drawPath(pageIndex, options) {
38157
+ var _a;
38158
+ (_a = this.streams[pageIndex]) == null ? void 0 : _a.drawPath(options);
38159
+ }
38160
+ saveGraphicsState(pageIndex) {
38161
+ var _a;
38162
+ (_a = this.streams[pageIndex]) == null ? void 0 : _a.saveGraphicsState();
38163
+ }
38164
+ restoreGraphicsState(pageIndex) {
38165
+ var _a;
38166
+ (_a = this.streams[pageIndex]) == null ? void 0 : _a.restoreGraphicsState();
38167
+ }
38168
+ rotateAbout(pageIndex, centerX, centerY, degrees) {
38169
+ var _a;
38170
+ (_a = this.streams[pageIndex]) == null ? void 0 : _a.rotateAbout(centerX, centerY, degrees);
38171
+ }
38172
+ clipRect(pageIndex, x, y, width, height) {
38173
+ var _a;
38174
+ (_a = this.streams[pageIndex]) == null ? void 0 : _a.clipRect(x, y, width, height);
38175
+ }
38176
+ drawText(pageIndex, options) {
38177
+ var _a;
38178
+ (_a = this.streams[pageIndex]) == null ? void 0 : _a.drawText(options);
38179
+ }
38180
+ registerImageResource(resource) {
38181
+ return this.images.registerImageResource(resource);
38182
+ }
38183
+ drawImage(pageIndex, options) {
38184
+ var _a;
38185
+ (_a = this.streams[pageIndex]) == null ? void 0 : _a.drawImage(options);
38186
+ }
38187
+ toArrayBuffer() {
38188
+ const bytes = this.toUint8Array();
38189
+ return Uint8Array.from(bytes).buffer;
38190
+ }
38191
+ toBlob() {
38192
+ return new Blob([this.toArrayBuffer()], { type: "application/pdf" });
38193
+ }
38194
+ toUint8Array() {
38195
+ if (this.pages.length === 0) {
38196
+ this.addPage({ width: 612, height: 792 });
38197
+ }
38198
+ return serializePdfDocument(this.pages, this.fonts, this.images);
38199
+ }
38200
+ }
37321
38201
  const FOOTNOTE_BLOCK_GAP_PX = 2;
37322
38202
  async function exportEditorDocumentToPdf(document2) {
37323
38203
  document2 = renumberImageCaptionsInDocument(document2);
@@ -40043,6 +40923,15 @@ function createTableSelectionResolvers(deps) {
40043
40923
  };
40044
40924
  }
40045
40925
  function createTableCellSpanOperations(deps) {
40926
+ const cloneCellSnapshot = (cell) => ({
40927
+ ...cell,
40928
+ style: cell.style ? { ...cell.style } : void 0,
40929
+ conditionalStyle: cell.conditionalStyle ? { ...cell.conditionalStyle } : void 0,
40930
+ mergeRevisionState: void 0,
40931
+ blocks: cell.blocks.map(
40932
+ (block) => cloneBlock(block)
40933
+ )
40934
+ });
40046
40935
  const mergeSelectedTableCells = (current) => {
40047
40936
  const range = deps.resolveHorizontalTableCellRange(current);
40048
40937
  if (!range) {
@@ -40064,6 +40953,7 @@ function createTableCellSpanOperations(deps) {
40064
40953
  if (selectedCells.length < 2) {
40065
40954
  return current;
40066
40955
  }
40956
+ const revision = current.trackChangesEnabled ? createTableRevisionMetadata() : void 0;
40067
40957
  const mergedCell = {
40068
40958
  ...selectedCells[0],
40069
40959
  colSpan: selectedCells.reduce(
@@ -40072,7 +40962,27 @@ function createTableCellSpanOperations(deps) {
40072
40962
  ),
40073
40963
  blocks: selectedCells.flatMap(
40074
40964
  (cell) => cell.blocks.map((paragraph) => cloneBlock(paragraph))
40075
- )
40965
+ ),
40966
+ ...revision ? {
40967
+ style: {
40968
+ ...selectedCells[0].style ?? {},
40969
+ revision: {
40970
+ ...revision,
40971
+ type: "merge",
40972
+ previous: {
40973
+ colSpan: selectedCells[0].colSpan,
40974
+ rowSpan: selectedCells[0].rowSpan,
40975
+ vMerge: selectedCells[0].vMerge
40976
+ }
40977
+ }
40978
+ },
40979
+ mergeRevisionState: {
40980
+ revisionId: revision.id,
40981
+ orientation: "horizontal",
40982
+ currentCellCount: 1,
40983
+ previousCells: selectedCells.map(cloneCellSnapshot)
40984
+ }
40985
+ } : {}
40076
40986
  };
40077
40987
  row.cells.splice(range.startCellIndex, selectedCells.length, mergedCell);
40078
40988
  const nextParagraph = mergedCell.blocks[0];
@@ -40120,13 +41030,34 @@ function createTableCellSpanOperations(deps) {
40120
41030
  )) {
40121
41031
  return current;
40122
41032
  }
41033
+ const revision = current.trackChangesEnabled ? createTableRevisionMetadata() : void 0;
40123
41034
  const mergedCell = {
40124
41035
  ...selectedCells[0],
40125
41036
  rowSpan: selectedCells.length,
40126
41037
  vMerge: "restart",
40127
41038
  blocks: selectedCells.flatMap(
40128
41039
  (cell) => cell.blocks.map((paragraph) => cloneBlock(paragraph))
40129
- )
41040
+ ),
41041
+ ...revision ? {
41042
+ style: {
41043
+ ...selectedCells[0].style ?? {},
41044
+ revision: {
41045
+ ...revision,
41046
+ type: "merge",
41047
+ previous: {
41048
+ colSpan: selectedCells[0].colSpan,
41049
+ rowSpan: selectedCells[0].rowSpan,
41050
+ vMerge: selectedCells[0].vMerge
41051
+ }
41052
+ }
41053
+ },
41054
+ mergeRevisionState: {
41055
+ revisionId: revision.id,
41056
+ orientation: "vertical",
41057
+ currentCellCount: 1,
41058
+ previousCells: selectedCells.map(cloneCellSnapshot)
41059
+ }
41060
+ } : {}
40130
41061
  };
40131
41062
  tableBlock.rows[range.startRowIndex].cells[range.cellIndex] = mergedCell;
40132
41063
  for (let rowIndex = range.startRowIndex + 1; rowIndex <= range.endRowIndex; rowIndex += 1) {
@@ -40184,9 +41115,38 @@ function createTableCellSpanOperations(deps) {
40184
41115
  if (!cell || span <= 1 || cell.vMerge !== "restart") {
40185
41116
  return current;
40186
41117
  }
41118
+ const previousCell = cloneCellSnapshot(cell);
41119
+ const revision = current.trackChangesEnabled ? createTableRevisionMetadata() : void 0;
41120
+ const preservedColSpan = Math.max(1, cell.colSpan ?? 1);
40187
41121
  cell.rowSpan = void 0;
40188
41122
  cell.vMerge = void 0;
40189
- const preservedColSpan = Math.max(1, cell.colSpan ?? 1);
41123
+ if (revision) {
41124
+ cell.style = {
41125
+ ...cell.style ?? {},
41126
+ revision: {
41127
+ ...revision,
41128
+ type: "merge",
41129
+ previous: {
41130
+ colSpan: previousCell.colSpan,
41131
+ rowSpan: previousCell.rowSpan,
41132
+ vMerge: previousCell.vMerge
41133
+ }
41134
+ }
41135
+ };
41136
+ cell.mergeRevisionState = {
41137
+ revisionId: revision.id,
41138
+ orientation: "vertical",
41139
+ currentCellCount: 1,
41140
+ previousCells: [
41141
+ previousCell,
41142
+ ...Array.from({ length: span - 1 }, (_, offset) => {
41143
+ var _a2;
41144
+ const prior = (_a2 = tableBlock.rows[location.rowIndex + offset + 1]) == null ? void 0 : _a2.cells[location.cellIndex];
41145
+ return prior ? cloneCellSnapshot(prior) : createEditorTableCell([], preservedColSpan);
41146
+ })
41147
+ ]
41148
+ };
41149
+ }
40190
41150
  for (let offset = 1; offset < span; offset += 1) {
40191
41151
  const row = tableBlock.rows[location.rowIndex + offset];
40192
41152
  if (!row) {
@@ -40236,13 +41196,35 @@ function createTableCellSpanOperations(deps) {
40236
41196
  if (!row || !cell || span <= 1) {
40237
41197
  return current;
40238
41198
  }
41199
+ const previousCell = cloneCellSnapshot(cell);
41200
+ const revision = current.trackChangesEnabled ? createTableRevisionMetadata() : void 0;
40239
41201
  const nextCells = [
40240
41202
  {
40241
41203
  ...cell,
40242
41204
  colSpan: 1,
40243
41205
  blocks: cell.blocks.map(
40244
41206
  (paragraph) => cloneBlock(paragraph)
40245
- )
41207
+ ),
41208
+ ...revision ? {
41209
+ style: {
41210
+ ...cell.style ?? {},
41211
+ revision: {
41212
+ ...revision,
41213
+ type: "merge",
41214
+ previous: {
41215
+ colSpan: previousCell.colSpan,
41216
+ rowSpan: previousCell.rowSpan,
41217
+ vMerge: previousCell.vMerge
41218
+ }
41219
+ }
41220
+ },
41221
+ mergeRevisionState: {
41222
+ revisionId: revision.id,
41223
+ orientation: "horizontal",
41224
+ currentCellCount: span,
41225
+ previousCells: [previousCell]
41226
+ }
41227
+ } : {}
40246
41228
  },
40247
41229
  ...Array.from(
40248
41230
  { length: span - 1 },
@@ -40351,6 +41333,15 @@ function createTableRowColumnOperations(deps) {
40351
41333
  );
40352
41334
  })
40353
41335
  );
41336
+ if (current.trackChangesEnabled) {
41337
+ blankRow.style = {
41338
+ ...blankRow.style ?? {},
41339
+ revision: {
41340
+ ...createTableRevisionMetadata(),
41341
+ type: "insert"
41342
+ }
41343
+ };
41344
+ }
40354
41345
  tableBlock.rows.splice(insertIndex, 0, blankRow);
40355
41346
  const targetVisualColumn = (selectedEntry == null ? void 0 : selectedEntry.visualColumnIndex) ?? location.cellIndex;
40356
41347
  const targetCell2 = findCellAtVisualColumn(blankRow, targetVisualColumn);
@@ -40385,6 +41376,15 @@ function createTableRowColumnOperations(deps) {
40385
41376
  )
40386
41377
  )
40387
41378
  );
41379
+ if (current.trackChangesEnabled) {
41380
+ blankRow.style = {
41381
+ ...blankRow.style ?? {},
41382
+ revision: {
41383
+ ...createTableRevisionMetadata(),
41384
+ type: "insert"
41385
+ }
41386
+ };
41387
+ }
40388
41388
  tableBlock.rows.splice(insertIndex, 0, blankRow);
40389
41389
  const targetCell = blankRow.cells[Math.min(location.cellIndex, blankRow.cells.length - 1)];
40390
41390
  const nextParagraph = (targetCell == null ? void 0 : targetCell.blocks[0]) ?? ((_b = blankRow.cells.find(
@@ -40420,13 +41420,23 @@ function createTableRowColumnOperations(deps) {
40420
41420
  if (!tableBlock || tableBlock.type !== "table") {
40421
41421
  return current;
40422
41422
  }
40423
- if (tableBlock.rows.length <= 1) {
41423
+ if (tableBlock.rows.length <= 1 && !current.trackChangesEnabled) {
40424
41424
  return current;
40425
41425
  }
40426
41426
  const rowToDelete = tableBlock.rows[location.rowIndex];
40427
41427
  if (!rowToDelete) {
40428
41428
  return current;
40429
41429
  }
41430
+ if (current.trackChangesEnabled) {
41431
+ rowToDelete.style = {
41432
+ ...rowToDelete.style ?? {},
41433
+ revision: {
41434
+ ...createTableRevisionMetadata(),
41435
+ type: "delete"
41436
+ }
41437
+ };
41438
+ return updateBlocksInCurrentSection(current, targetBlocks, location.zone);
41439
+ }
40430
41440
  const blockedByRestartCell = rowToDelete.cells.some(
40431
41441
  (cell) => cell.vMerge !== "continue" && Math.max(1, cell.rowSpan ?? 1) > 1
40432
41442
  );
@@ -40512,13 +41522,34 @@ function createTableRowColumnOperations(deps) {
40512
41522
  for (const cell of row.cells) {
40513
41523
  const span = Math.max(1, cell.colSpan ?? 1);
40514
41524
  if (!inserted && insertVisualColumn <= visualCursor) {
40515
- nextCells.push(createEditorTableCell([createEditorParagraph("")]));
41525
+ const insertedCell = createEditorTableCell([
41526
+ createEditorParagraph("")
41527
+ ]);
41528
+ if (current.trackChangesEnabled) {
41529
+ insertedCell.style = {
41530
+ revision: {
41531
+ ...createTableRevisionMetadata(),
41532
+ type: "insert"
41533
+ }
41534
+ };
41535
+ }
41536
+ nextCells.push(insertedCell);
40516
41537
  inserted = true;
40517
41538
  }
40518
41539
  if (!inserted && visualCursor < insertVisualColumn && insertVisualColumn < visualCursor + span) {
40519
41540
  nextCells.push({
40520
41541
  ...cell,
40521
- colSpan: span + 1
41542
+ colSpan: span + 1,
41543
+ ...current.trackChangesEnabled ? {
41544
+ style: {
41545
+ ...cell.style ?? {},
41546
+ revision: {
41547
+ ...createTableRevisionMetadata(),
41548
+ type: "merge",
41549
+ previous: { colSpan: cell.colSpan }
41550
+ }
41551
+ }
41552
+ } : {}
40522
41553
  });
40523
41554
  inserted = true;
40524
41555
  } else {
@@ -40527,7 +41558,18 @@ function createTableRowColumnOperations(deps) {
40527
41558
  visualCursor += span;
40528
41559
  }
40529
41560
  if (!inserted) {
40530
- nextCells.push(createEditorTableCell([createEditorParagraph("")]));
41561
+ const insertedCell = createEditorTableCell([
41562
+ createEditorParagraph("")
41563
+ ]);
41564
+ if (current.trackChangesEnabled) {
41565
+ insertedCell.style = {
41566
+ revision: {
41567
+ ...createTableRevisionMetadata(),
41568
+ type: "insert"
41569
+ }
41570
+ };
41571
+ }
41572
+ nextCells.push(insertedCell);
40531
41573
  }
40532
41574
  row.cells = nextCells;
40533
41575
  }
@@ -40562,11 +41604,16 @@ function createTableRowColumnOperations(deps) {
40562
41604
  )
40563
41605
  );
40564
41606
  for (const row of tableBlock.rows) {
40565
- row.cells.splice(
40566
- insertIndex,
40567
- 0,
40568
- createEditorTableCell([createEditorParagraph("")])
40569
- );
41607
+ const insertedCell = createEditorTableCell([createEditorParagraph("")]);
41608
+ if (current.trackChangesEnabled) {
41609
+ insertedCell.style = {
41610
+ revision: {
41611
+ ...createTableRevisionMetadata(),
41612
+ type: "insert"
41613
+ }
41614
+ };
41615
+ }
41616
+ row.cells.splice(insertIndex, 0, insertedCell);
40570
41617
  }
40571
41618
  const targetRow = tableBlock.rows[location.rowIndex];
40572
41619
  const targetCell = targetRow == null ? void 0 : targetRow.cells[insertIndex];
@@ -40605,6 +41652,26 @@ function createTableRowColumnOperations(deps) {
40605
41652
  if (getTableVisualWidth(tableBlock) <= 1) {
40606
41653
  return current;
40607
41654
  }
41655
+ if (current.trackChangesEnabled) {
41656
+ const layout = buildTableCellLayout(tableBlock);
41657
+ const selected = layout.find(
41658
+ (entry) => entry.rowIndex === location.rowIndex && entry.cellIndex === location.cellIndex
41659
+ );
41660
+ const visualColumn = (selected == null ? void 0 : selected.visualColumnIndex) ?? location.cellIndex;
41661
+ for (const row of tableBlock.rows) {
41662
+ const cell = findCellAtVisualColumn(row, visualColumn);
41663
+ if (cell) {
41664
+ cell.style = {
41665
+ ...cell.style ?? {},
41666
+ revision: {
41667
+ ...createTableRevisionMetadata(),
41668
+ type: "delete"
41669
+ }
41670
+ };
41671
+ }
41672
+ }
41673
+ return updateBlocksInCurrentSection(current, targetBlocks, location.zone);
41674
+ }
40608
41675
  const hasHorizontalSpansInTable = tableBlock.rows.some(
40609
41676
  (row) => row.cells.some((cell) => Math.max(1, cell.colSpan ?? 1) > 1)
40610
41677
  );
@@ -43040,6 +44107,7 @@ function createEditorTableDrag(deps) {
43040
44107
  null
43041
44108
  );
43042
44109
  const [startClientY, setStartClientY] = createSignal(0);
44110
+ const [startClientX, setStartClientX] = createSignal(0);
43043
44111
  const [mousePos, setMousePos] = createSignal({ x: 0, y: 0 });
43044
44112
  const stopDrag = () => {
43045
44113
  setDragging(false);
@@ -43093,9 +44161,32 @@ function createEditorTableDrag(deps) {
43093
44161
  event.clientY
43094
44162
  );
43095
44163
  const tableId = info == null ? void 0 : info.tableId;
43096
- if (pos && tableId) {
44164
+ if (tableId) {
43097
44165
  deps.applyTransactionalState((current) => {
43098
- return moveBlockToPosition(current, tableId, pos);
44166
+ var _a;
44167
+ const findTable = () => {
44168
+ for (const zone of ["main", "header", "footer"]) {
44169
+ const blocks = getEditableBlocksForZone(current, zone);
44170
+ const table2 = blocks.find(
44171
+ (block) => block.type === "table" && block.id === tableId
44172
+ );
44173
+ if (table2) return table2;
44174
+ }
44175
+ return void 0;
44176
+ };
44177
+ const table = findTable();
44178
+ if ((table == null ? void 0 : table.type) === "table" && ((_a = table.style) == null ? void 0 : _a.floating)) {
44179
+ const floating = table.style.floating;
44180
+ const pointsPerPixel = 72 / 96;
44181
+ return setActiveTableStyleValue(current, tableId, "floating", {
44182
+ ...floating,
44183
+ x: (floating.x ?? 0) + (event.clientX - startClientX()) * pointsPerPixel,
44184
+ y: (floating.y ?? 0) + (event.clientY - startClientY()) * pointsPerPixel,
44185
+ xAlign: void 0,
44186
+ yAlign: void 0
44187
+ });
44188
+ }
44189
+ return pos ? moveBlockToPosition(current, tableId, pos) : current;
43099
44190
  });
43100
44191
  }
43101
44192
  }
@@ -43116,6 +44207,7 @@ function createEditorTableDrag(deps) {
43116
44207
  offsetY: event.clientY - handleRect.top
43117
44208
  });
43118
44209
  setStartClientY(event.clientY);
44210
+ setStartClientX(event.clientX);
43119
44211
  setMousePos({ x: event.clientX, y: event.clientY });
43120
44212
  setDragging(false);
43121
44213
  setDropTargetPos(null);
@@ -44192,6 +45284,51 @@ function createEditorRevisionController(deps) {
44192
45284
  }
44193
45285
  if (foundRevision) break;
44194
45286
  }
45287
+ const findInBlocks = (blocks) => {
45288
+ var _a2, _b2, _c2, _d, _e, _f, _g, _h, _i, _j, _k;
45289
+ for (const block of blocks) {
45290
+ if (block.type === "paragraph") continue;
45291
+ if (((_b2 = (_a2 = block.style) == null ? void 0 : _a2.revision) == null ? void 0 : _b2.id) === revisionId) {
45292
+ return block.style.revision;
45293
+ }
45294
+ if (((_c2 = block.gridRevision) == null ? void 0 : _c2.id) === revisionId) return block.gridRevision;
45295
+ for (const row of block.rows) {
45296
+ if (((_e = (_d = row.style) == null ? void 0 : _d.revision) == null ? void 0 : _e.id) === revisionId) return row.style.revision;
45297
+ if (((_g = (_f = row.style) == null ? void 0 : _f.propertyRevision) == null ? void 0 : _g.id) === revisionId) {
45298
+ return row.style.propertyRevision;
45299
+ }
45300
+ for (const cell of row.cells) {
45301
+ if (((_i = (_h = cell.style) == null ? void 0 : _h.revision) == null ? void 0 : _i.id) === revisionId) {
45302
+ return cell.style.revision;
45303
+ }
45304
+ if (((_k = (_j = cell.style) == null ? void 0 : _j.propertyRevision) == null ? void 0 : _k.id) === revisionId) {
45305
+ return cell.style.propertyRevision;
45306
+ }
45307
+ const nested = findInBlocks(cell.blocks);
45308
+ if (nested) return nested;
45309
+ }
45310
+ }
45311
+ }
45312
+ return void 0;
45313
+ };
45314
+ if (!foundRevision) {
45315
+ for (const section of getDocumentSections(deps.state().document)) {
45316
+ for (const blocks of [
45317
+ section.blocks,
45318
+ section.header,
45319
+ section.firstPageHeader,
45320
+ section.evenPageHeader,
45321
+ section.footer,
45322
+ section.firstPageFooter,
45323
+ section.evenPageFooter
45324
+ ]) {
45325
+ if (!blocks) continue;
45326
+ foundRevision = findInBlocks(blocks);
45327
+ if (foundRevision) break;
45328
+ }
45329
+ if (foundRevision) break;
45330
+ }
45331
+ }
44195
45332
  if (!foundRevision) return;
44196
45333
  const rect = event.currentTarget.getBoundingClientRect();
44197
45334
  const surfaceRect = (_b = deps.surfaceRef()) == null ? void 0 : _b.getBoundingClientRect();
@@ -44545,6 +45682,148 @@ function toggleTrackChanges(state) {
44545
45682
  trackChangesEnabled: !state.trackChangesEnabled
44546
45683
  };
44547
45684
  }
45685
+ function transformTableRevisionBlocks(blocks, revisionId, accept) {
45686
+ return blocks.flatMap((block) => {
45687
+ var _a;
45688
+ if (block.type === "paragraph") return [block];
45689
+ let style2 = block.style;
45690
+ if (((_a = style2 == null ? void 0 : style2.revision) == null ? void 0 : _a.id) === revisionId) {
45691
+ if (accept) {
45692
+ const { revision: _revision, ...current } = style2;
45693
+ style2 = current;
45694
+ } else {
45695
+ style2 = { ...style2.revision.previous };
45696
+ }
45697
+ }
45698
+ let gridCols = block.gridCols;
45699
+ let gridRevision = block.gridRevision;
45700
+ if ((gridRevision == null ? void 0 : gridRevision.id) === revisionId) {
45701
+ gridCols = accept ? gridCols : [...gridRevision.previous];
45702
+ gridRevision = void 0;
45703
+ }
45704
+ const sourceRows = block.rows.map((row) => ({
45705
+ ...row,
45706
+ cells: [...row.cells]
45707
+ }));
45708
+ for (let rowIndex = 0; rowIndex < sourceRows.length; rowIndex += 1) {
45709
+ const row = sourceRows[rowIndex];
45710
+ for (let cellIndex = 0; cellIndex < row.cells.length; cellIndex += 1) {
45711
+ const cell = row.cells[cellIndex];
45712
+ const mergeState = cell.mergeRevisionState;
45713
+ if (!mergeState || mergeState.revisionId !== revisionId) continue;
45714
+ if (accept) {
45715
+ const { mergeRevisionState: _state, ...acceptedCell } = cell;
45716
+ row.cells[cellIndex] = acceptedCell;
45717
+ continue;
45718
+ }
45719
+ if (mergeState.orientation === "horizontal") {
45720
+ row.cells.splice(
45721
+ cellIndex,
45722
+ mergeState.currentCellCount,
45723
+ ...mergeState.previousCells
45724
+ );
45725
+ } else {
45726
+ mergeState.previousCells.forEach((previousCell, offset) => {
45727
+ const targetRow = sourceRows[rowIndex + offset];
45728
+ if (targetRow) targetRow.cells[cellIndex] = previousCell;
45729
+ });
45730
+ }
45731
+ }
45732
+ }
45733
+ const rows = sourceRows.flatMap((row) => {
45734
+ var _a2, _b, _c, _d;
45735
+ if (((_b = (_a2 = row.style) == null ? void 0 : _a2.revision) == null ? void 0 : _b.id) === revisionId) {
45736
+ const remove = accept && row.style.revision.type === "delete" || !accept && row.style.revision.type === "insert";
45737
+ if (remove) return [];
45738
+ }
45739
+ let rowStyle = row.style;
45740
+ if (((_c = rowStyle == null ? void 0 : rowStyle.propertyRevision) == null ? void 0 : _c.id) === revisionId) {
45741
+ if (accept) {
45742
+ const { propertyRevision: _revision, ...current } = rowStyle;
45743
+ rowStyle = current;
45744
+ } else {
45745
+ rowStyle = {
45746
+ ...rowStyle.propertyRevision.previous,
45747
+ revision: rowStyle.revision
45748
+ };
45749
+ }
45750
+ }
45751
+ if (((_d = rowStyle == null ? void 0 : rowStyle.revision) == null ? void 0 : _d.id) === revisionId) {
45752
+ const { revision: _revision, ...current } = rowStyle;
45753
+ rowStyle = current;
45754
+ }
45755
+ const cells = row.cells.flatMap((cell) => {
45756
+ var _a3, _b2, _c2, _d2, _e;
45757
+ if (((_b2 = (_a3 = cell.style) == null ? void 0 : _a3.revision) == null ? void 0 : _b2.id) === revisionId) {
45758
+ const remove = accept && cell.style.revision.type === "delete" || !accept && cell.style.revision.type === "insert";
45759
+ if (remove) return [];
45760
+ }
45761
+ let cellStyle = cell.style;
45762
+ if (((_c2 = cellStyle == null ? void 0 : cellStyle.propertyRevision) == null ? void 0 : _c2.id) === revisionId) {
45763
+ if (accept) {
45764
+ const { propertyRevision: _revision, ...current } = cellStyle;
45765
+ cellStyle = current;
45766
+ } else {
45767
+ cellStyle = {
45768
+ ...cellStyle.propertyRevision.previous,
45769
+ revision: cellStyle.revision
45770
+ };
45771
+ }
45772
+ }
45773
+ let nextCell = {
45774
+ ...cell,
45775
+ style: cellStyle,
45776
+ blocks: transformTableRevisionBlocks(
45777
+ cell.blocks,
45778
+ revisionId,
45779
+ accept
45780
+ )
45781
+ };
45782
+ if (((_d2 = cellStyle == null ? void 0 : cellStyle.revision) == null ? void 0 : _d2.id) === revisionId && ((_e = cell.mergeRevisionState) == null ? void 0 : _e.revisionId) !== revisionId) {
45783
+ const revision = cellStyle.revision;
45784
+ const { revision: _revision, ...current } = cellStyle;
45785
+ nextCell = {
45786
+ ...nextCell,
45787
+ ...accept || revision.type !== "merge" ? {} : revision.previous,
45788
+ style: current
45789
+ };
45790
+ }
45791
+ return [nextCell];
45792
+ });
45793
+ return [
45794
+ {
45795
+ ...row,
45796
+ isHeader: rowStyle && "isHeader" in rowStyle ? rowStyle.isHeader : row.isHeader,
45797
+ style: rowStyle,
45798
+ cells
45799
+ }
45800
+ ];
45801
+ });
45802
+ if (rows.length === 0) return [];
45803
+ return [{ ...block, style: style2, gridCols, gridRevision, rows }];
45804
+ });
45805
+ }
45806
+ function transformTableRevision(state, revisionId, accept) {
45807
+ const sections = getDocumentSections(state.document).map((section) => ({
45808
+ ...section,
45809
+ blocks: transformTableRevisionBlocks(section.blocks, revisionId, accept),
45810
+ header: section.header ? transformTableRevisionBlocks(section.header, revisionId, accept) : void 0,
45811
+ firstPageHeader: section.firstPageHeader ? transformTableRevisionBlocks(
45812
+ section.firstPageHeader,
45813
+ revisionId,
45814
+ accept
45815
+ ) : void 0,
45816
+ evenPageHeader: section.evenPageHeader ? transformTableRevisionBlocks(section.evenPageHeader, revisionId, accept) : void 0,
45817
+ footer: section.footer ? transformTableRevisionBlocks(section.footer, revisionId, accept) : void 0,
45818
+ firstPageFooter: section.firstPageFooter ? transformTableRevisionBlocks(
45819
+ section.firstPageFooter,
45820
+ revisionId,
45821
+ accept
45822
+ ) : void 0,
45823
+ evenPageFooter: section.evenPageFooter ? transformTableRevisionBlocks(section.evenPageFooter, revisionId, accept) : void 0
45824
+ }));
45825
+ return { ...state, document: { ...state.document, sections } };
45826
+ }
44548
45827
  function acceptRevision(state, revisionId) {
44549
45828
  const paragraphs = getParagraphs(state);
44550
45829
  const nextParagraphs = paragraphs.map((paragraph) => {
@@ -44567,7 +45846,7 @@ function acceptRevision(state, revisionId) {
44567
45846
  }
44568
45847
  return buildParagraphFromRuns(paragraph, nextRuns);
44569
45848
  });
44570
- return cloneStateWithParagraphs(
45849
+ const textState = cloneStateWithParagraphs(
44571
45850
  state,
44572
45851
  nextParagraphs,
44573
45852
  preserveSelectionByParagraphOffsets(
@@ -44575,6 +45854,7 @@ function acceptRevision(state, revisionId) {
44575
45854
  normalizeSelection(state)
44576
45855
  )
44577
45856
  );
45857
+ return transformTableRevision(textState, revisionId, true);
44578
45858
  }
44579
45859
  function rejectRevision(state, revisionId) {
44580
45860
  const paragraphs = getParagraphs(state);
@@ -44598,7 +45878,7 @@ function rejectRevision(state, revisionId) {
44598
45878
  }
44599
45879
  return buildParagraphFromRuns(paragraph, nextRuns);
44600
45880
  });
44601
- return cloneStateWithParagraphs(
45881
+ const textState = cloneStateWithParagraphs(
44602
45882
  state,
44603
45883
  nextParagraphs,
44604
45884
  preserveSelectionByParagraphOffsets(
@@ -44606,6 +45886,40 @@ function rejectRevision(state, revisionId) {
44606
45886
  normalizeSelection(state)
44607
45887
  )
44608
45888
  );
45889
+ return transformTableRevision(textState, revisionId, false);
45890
+ }
45891
+ function collectTableRevisionIds(blocks, selectedParagraphIds, revisionIds) {
45892
+ var _a, _b, _c, _d, _e;
45893
+ for (const block of blocks) {
45894
+ if (block.type === "paragraph") continue;
45895
+ const tableSelected = block.rows.some(
45896
+ (row) => row.cells.some(
45897
+ (cell) => cell.blocks.some((paragraph) => selectedParagraphIds.has(paragraph.id))
45898
+ )
45899
+ );
45900
+ if (tableSelected) {
45901
+ if ((_a = block.style) == null ? void 0 : _a.revision) revisionIds.add(block.style.revision.id);
45902
+ if (block.gridRevision) revisionIds.add(block.gridRevision.id);
45903
+ }
45904
+ for (const row of block.rows) {
45905
+ const selectedCells = row.cells.filter(
45906
+ (cell) => cell.blocks.some((paragraph) => selectedParagraphIds.has(paragraph.id))
45907
+ );
45908
+ if (selectedCells.length > 0) {
45909
+ if ((_b = row.style) == null ? void 0 : _b.revision) revisionIds.add(row.style.revision.id);
45910
+ if ((_c = row.style) == null ? void 0 : _c.propertyRevision) {
45911
+ revisionIds.add(row.style.propertyRevision.id);
45912
+ }
45913
+ }
45914
+ for (const cell of selectedCells) {
45915
+ if ((_d = cell.style) == null ? void 0 : _d.revision) revisionIds.add(cell.style.revision.id);
45916
+ if ((_e = cell.style) == null ? void 0 : _e.propertyRevision) {
45917
+ revisionIds.add(cell.style.propertyRevision.id);
45918
+ }
45919
+ collectTableRevisionIds(cell.blocks, selectedParagraphIds, revisionIds);
45920
+ }
45921
+ }
45922
+ }
44609
45923
  }
44610
45924
  function acceptRevisionsInSelection(state) {
44611
45925
  var _a;
@@ -44623,6 +45937,24 @@ function acceptRevisionsInSelection(state) {
44623
45937
  }
44624
45938
  }
44625
45939
  }
45940
+ const selectedParagraphIds = new Set(
45941
+ paragraphs.slice(normalized.startIndex, normalized.endIndex + 1).map((paragraph) => paragraph.id)
45942
+ );
45943
+ for (const section of getDocumentSections(state.document)) {
45944
+ for (const blocks of [
45945
+ section.blocks,
45946
+ section.header,
45947
+ section.firstPageHeader,
45948
+ section.evenPageHeader,
45949
+ section.footer,
45950
+ section.firstPageFooter,
45951
+ section.evenPageFooter
45952
+ ]) {
45953
+ if (blocks) {
45954
+ collectTableRevisionIds(blocks, selectedParagraphIds, revisionIds);
45955
+ }
45956
+ }
45957
+ }
44626
45958
  let nextState = state;
44627
45959
  for (const revisionId of revisionIds) {
44628
45960
  nextState = acceptRevision(nextState, revisionId);
@@ -44645,6 +45977,24 @@ function rejectRevisionsInSelection(state) {
44645
45977
  }
44646
45978
  }
44647
45979
  }
45980
+ const selectedParagraphIds = new Set(
45981
+ paragraphs.slice(normalized.startIndex, normalized.endIndex + 1).map((paragraph) => paragraph.id)
45982
+ );
45983
+ for (const section of getDocumentSections(state.document)) {
45984
+ for (const blocks of [
45985
+ section.blocks,
45986
+ section.header,
45987
+ section.firstPageHeader,
45988
+ section.evenPageHeader,
45989
+ section.footer,
45990
+ section.firstPageFooter,
45991
+ section.evenPageFooter
45992
+ ]) {
45993
+ if (blocks) {
45994
+ collectTableRevisionIds(blocks, selectedParagraphIds, revisionIds);
45995
+ }
45996
+ }
45997
+ }
44648
45998
  let nextState = state;
44649
45999
  for (const revisionId of revisionIds) {
44650
46000
  nextState = rejectRevision(nextState, revisionId);