@betteroffice/docx 0.0.1 → 0.0.3

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 (165) hide show
  1. package/README.md +19 -0
  2. package/dist/chunk-AEQOEQJ7.mjs +57 -0
  3. package/dist/chunk-AZ52IWB6.mjs +16 -0
  4. package/dist/{chunk-SINEY6ZF.mjs → chunk-B4IR6YP4.mjs} +1 -1
  5. package/dist/chunk-GGEGIQRK.mjs +1 -0
  6. package/dist/chunk-IFT6DUJX.mjs +1 -0
  7. package/dist/chunk-J7LNO6SM.mjs +1 -0
  8. package/dist/{chunk-H3JCIGWK.mjs → chunk-NJHOPXZW.mjs} +1 -1
  9. package/dist/{chunk-KXNZFTTK.mjs → chunk-WBH3SXI6.mjs} +1 -1
  10. package/dist/chunk-WON6K4FY.mjs +1 -0
  11. package/dist/chunk-Y7RUNRU2.mjs +1 -0
  12. package/dist/collaboration/index.d.mts +65 -0
  13. package/dist/collaboration/index.mjs +1 -0
  14. package/dist/{content-sSHuWw49.d.mts → content-MOZ6hKP4.d.mts} +357 -357
  15. package/dist/core.d.mts +148 -341
  16. package/dist/core.mjs +1 -1
  17. package/dist/{displayListQueries-p-ijSzdh.d.mts → displayListQueries-BJlo7Jkz.d.mts} +24 -6
  18. package/dist/docx/index.d.mts +40 -520
  19. package/dist/docx/index.mjs +2 -2
  20. package/dist/editor/index.d.mts +36 -151
  21. package/dist/editor/index.mjs +1 -1
  22. package/dist/{fontLoader-Bx6DK6-2.d.mts → fontLoader-aSewHMKF.d.mts} +65 -63
  23. package/dist/{formatting-DoL7KBSL.d.mts → formatting-D1EPSaJP.d.mts} +1 -1
  24. package/dist/{rustDisplayList-dqunvwxH.d.mts → frameDelta-D965X8yK.d.mts} +3 -274
  25. package/dist/generated/edit/docx_edit_bg.wasm +0 -0
  26. package/dist/generated/layout/docx_layout_bg.wasm +0 -0
  27. package/dist/generated/opc/ooxml_opc_bg.wasm +0 -0
  28. package/dist/generated/parse/docx_parse_bg.wasm +0 -0
  29. package/dist/index-Dx4Z3lkz.d.mts +1010 -0
  30. package/dist/layout/index.d.mts +19 -240
  31. package/dist/layout/index.mjs +1 -1
  32. package/dist/layout/pagination/index.d.mts +10 -58
  33. package/dist/layout/pagination/index.mjs +1 -1
  34. package/dist/layout/render/index.d.mts +11 -11
  35. package/dist/layout/render/index.mjs +1 -1
  36. package/dist/plugin-api/RenderedDomContext.d.mts +9 -9
  37. package/dist/plugin-api/index.d.mts +191 -6
  38. package/dist/plugin-api/resolveItemPositions.d.mts +4 -5
  39. package/dist/rustDisplayList-BRuZBqdL.d.mts +278 -0
  40. package/dist/rustMeasureSource-D1KsQvVC.d.mts +106 -0
  41. package/dist/selectiveSave-CVoajSKE.d.mts +56 -0
  42. package/dist/styles/index.d.mts +4 -39
  43. package/dist/styles/index.mjs +1 -1
  44. package/dist/{styles-VxNcXLdi.d.mts → styles-Dn_o3Vo5.d.mts} +2 -2
  45. package/dist/types/content.d.mts +2 -2
  46. package/dist/types/document.d.mts +40 -14
  47. package/dist/{types-DNrYr6yQ.d.mts → types-BfqUl2h_.d.mts} +3 -71
  48. package/dist/utils/comments.d.mts +2 -2
  49. package/dist/utils/index.d.mts +110 -576
  50. package/dist/utils/index.mjs +1 -84
  51. package/dist/utils/stylePreview.d.mts +2 -2
  52. package/dist/utils/units.d.mts +33 -2
  53. package/dist/wasm-DO3BUV7C.mjs +1 -0
  54. package/dist/wasm-NWXX4H5G.mjs +1 -0
  55. package/dist/wasm-edit.d.mts +14 -5
  56. package/dist/wasm-edit.mjs +1 -1
  57. package/dist/wasm-layout.d.mts +10 -1
  58. package/dist/wasm-layout.mjs +1 -1
  59. package/dist/wasm-opc.mjs +1 -1
  60. package/dist/wasm-parse.mjs +1 -1
  61. package/dist/yrs/index.d.mts +6 -881
  62. package/dist/yrs/index.mjs +1 -1
  63. package/dist/yrs/residentEngineWorker.mjs +1 -1
  64. package/package.json +16 -139
  65. package/dist/Subscribable-DOz6Ohoo.d.mts +0 -33
  66. package/dist/agent/index.d.mts +0 -531
  67. package/dist/agent/index.mjs +0 -1
  68. package/dist/chunk-34K66SY4.mjs +0 -1
  69. package/dist/chunk-4RCISPPE.mjs +0 -1
  70. package/dist/chunk-52GB3Y42.mjs +0 -1
  71. package/dist/chunk-6NEKRDXF.mjs +0 -1
  72. package/dist/chunk-6PW4CWUG.mjs +0 -1
  73. package/dist/chunk-7DEIW7FL.mjs +0 -1
  74. package/dist/chunk-7PCO5I2O.mjs +0 -1
  75. package/dist/chunk-BI3B33LI.mjs +0 -1
  76. package/dist/chunk-BIQWVK5P.mjs +0 -2
  77. package/dist/chunk-CIRN3LZA.mjs +0 -1
  78. package/dist/chunk-DXKG3HQ5.mjs +0 -16
  79. package/dist/chunk-FPZBTOD6.mjs +0 -1
  80. package/dist/chunk-FZIA7OFY.mjs +0 -1
  81. package/dist/chunk-GWKJ2Y4Y.mjs +0 -1
  82. package/dist/chunk-HJGAQIU7.mjs +0 -2
  83. package/dist/chunk-I6KKMUUC.mjs +0 -1
  84. package/dist/chunk-IL5JZJT7.mjs +0 -1
  85. package/dist/chunk-JY6ILTNS.mjs +0 -1
  86. package/dist/chunk-KEE52TT5.mjs +0 -1
  87. package/dist/chunk-KVKLLTDP.mjs +0 -58
  88. package/dist/chunk-L5ISVQ3W.mjs +0 -1
  89. package/dist/chunk-LDUWIM7M.mjs +0 -1
  90. package/dist/chunk-N5Q3YN64.mjs +0 -1
  91. package/dist/chunk-NEWOMDTX.mjs +0 -1
  92. package/dist/chunk-O2QSE2I7.mjs +0 -1
  93. package/dist/chunk-OJOHXQNQ.mjs +0 -1
  94. package/dist/chunk-OMR3TWCD.mjs +0 -2
  95. package/dist/chunk-P3KDV4M2.mjs +0 -1
  96. package/dist/chunk-Q7PO7V73.mjs +0 -1
  97. package/dist/chunk-QOUFE3VX.mjs +0 -1
  98. package/dist/chunk-TYHI7RAD.mjs +0 -1
  99. package/dist/chunk-UIEJWORW.mjs +0 -1
  100. package/dist/chunk-VAOUFAUH.mjs +0 -1
  101. package/dist/chunk-VBOTMRXV.mjs +0 -1
  102. package/dist/chunk-VCER63GQ.mjs +0 -1
  103. package/dist/chunk-WAUF2UC7.mjs +0 -2
  104. package/dist/chunk-X4XDO3LZ.mjs +0 -1
  105. package/dist/chunk-XQBCCJBO.mjs +0 -9
  106. package/dist/chunk-XWUOLYRQ.mjs +0 -2
  107. package/dist/chunk-XYH6XWP3.mjs +0 -10
  108. package/dist/chunk-YBIM6UJV.mjs +0 -8
  109. package/dist/chunk-YCIH2Q3E.mjs +0 -1
  110. package/dist/chunk-ZOV5KL7C.mjs +0 -1
  111. package/dist/colorResolver-n0o7H7ep.d.mts +0 -290
  112. package/dist/core-plugins.d.mts +0 -37
  113. package/dist/core-plugins.mjs +0 -1
  114. package/dist/docx/parser.d.mts +0 -41
  115. package/dist/docx/parser.mjs +0 -1
  116. package/dist/docx/rezip.d.mts +0 -148
  117. package/dist/docx/rezip.mjs +0 -1
  118. package/dist/docx/serializer/index.d.mts +0 -42
  119. package/dist/docx/serializer/index.mjs +0 -1
  120. package/dist/editorTree-DO5PyDK8.d.mts +0 -37
  121. package/dist/executor-7O2RBJ2B.mjs +0 -1
  122. package/dist/headerFooterLayout-0zPT64Qc.d.mts +0 -316
  123. package/dist/headless.d.mts +0 -69
  124. package/dist/headless.mjs +0 -1
  125. package/dist/layout/flow/index.d.mts +0 -149
  126. package/dist/layout/flow/index.mjs +0 -1
  127. package/dist/layout/measure/index.d.mts +0 -324
  128. package/dist/layout/measure/index.mjs +0 -1
  129. package/dist/layout/pagination/types.d.mts +0 -4
  130. package/dist/layout/pagination/types.mjs +0 -1
  131. package/dist/managers/AutoSaveManager.d.mts +0 -81
  132. package/dist/managers/AutoSaveManager.mjs +0 -1
  133. package/dist/managers/TableSelectionManager.d.mts +0 -74
  134. package/dist/managers/TableSelectionManager.mjs +0 -1
  135. package/dist/managers/types.d.mts +0 -113
  136. package/dist/managers/types.mjs +0 -0
  137. package/dist/mcp-cli.mjs +0 -142
  138. package/dist/mcp.d.mts +0 -162
  139. package/dist/mcp.mjs +0 -16
  140. package/dist/measureBlocksPipeline-Df0Bbrwy.d.mts +0 -109
  141. package/dist/measuredBlock-DZwz8zhD.d.mts +0 -26
  142. package/dist/plugin-api/types.d.mts +0 -193
  143. package/dist/plugin-api/types.mjs +0 -0
  144. package/dist/processTemplate-HDUIZFJ5.mjs +0 -1
  145. package/dist/registry-DMM5VTdT.d.mts +0 -165
  146. package/dist/rustPagination-Bj2hq013.d.mts +0 -106
  147. package/dist/sectionConfigs-DW3J8q0X.d.mts +0 -55
  148. package/dist/selectionContext-Buc9BCU1.d.mts +0 -570
  149. package/dist/selectiveSave-oFBJ1n71.d.mts +0 -16
  150. package/dist/selectiveXmlPatch-ypkxlTD_.d.mts +0 -23
  151. package/dist/settingsParser-CcGvtmCK.d.mts +0 -33
  152. package/dist/types/agentApi.d.mts +0 -456
  153. package/dist/types/agentApi.mjs +0 -1
  154. package/dist/types-dYdjUZMo.d.mts +0 -311
  155. package/dist/units-O5Y02RKQ.d.mts +0 -34
  156. package/dist/utils/headingCollector.d.mts +0 -28
  157. package/dist/utils/headingCollector.mjs +0 -1
  158. package/dist/utils/highlightColors.d.mts +0 -14
  159. package/dist/utils/highlightColors.mjs +0 -1
  160. package/dist/utils/textSelection.d.mts +0 -92
  161. package/dist/utils/textSelection.mjs +0 -1
  162. package/dist/variableDetector-Borj29SF.d.mts +0 -115
  163. package/dist/wasm-FZQ5XB2Y.mjs +0 -1
  164. package/dist/wasm-SA237OSP.mjs +0 -1
  165. package/dist/watermarkApi-DCxjutkg.d.mts +0 -38
@@ -1,531 +0,0 @@
1
- export { A as AgentContextOptions, S as ContextSelectionOptions, D as DocumentAgent, E as ExtendedSelectionContext, F as FormattedTextSegment, a as FormattingSummary, I as InsertHyperlinkOptions, b as InsertImageOptions, c as InsertTableOptions, d as InsertTextOptions, e as SelectionContextOptions, f as buildExtendedSelectionContext, g as buildSelectionContext, h as buildSelectionContextFromContext, i as createAgent, j as createAgentFromDocument, k as executeCommand, l as executeCommands, m as getAgentContext, n as getDocumentSummary, o as getSelectionFormattingSummary } from '../selectionContext-Buc9BCU1.mjs';
2
- import { c as DocumentBody, P as Paragraph, H as Hyperlink, R as Run, T as Table, aQ as SdtType, aP as SdtProperties, aM as SdtDataBinding, p as BlockSdt, am as InlineSdt, B as BlockContent } from '../content-sSHuWw49.mjs';
3
- import { T as TextFormatting } from '../formatting-DoL7KBSL.mjs';
4
- import { Position } from '../types/agentApi.mjs';
5
- export { AIAction, AIActionRequest, AgentCommand, AgentContext, AgentResponse, SelectionContext as AgentSelectionContext, ApplyStyleCommand, ApplyVariablesCommand, DEFAULT_AI_ACTIONS, DeleteTextCommand, FormatParagraphCommand, FormatTextCommand, InsertHyperlinkCommand, InsertImageCommand, InsertParagraphBreakCommand, InsertTableCommand, InsertTextCommand, MergeParagraphsCommand, ParagraphContext, ParagraphOutline, Range, RemoveHyperlinkCommand, ReplaceTextCommand, SectionInfo, SetVariableCommand, SplitParagraphCommand, StyleInfo, SuggestedAction, comparePositions, createCollapsedRange, createCommand, createRange, getActionDescription, getActionLabel, isPositionInRange } from '../types/agentApi.mjs';
6
- import { Document } from '../types/document.mjs';
7
- import '../selectiveSave-oFBJ1n71.mjs';
8
- import '../docxInput-DTbCa48g.mjs';
9
- import '../docx/wrapTypes.mjs';
10
- import '../styles-VxNcXLdi.mjs';
11
- import '../settingsParser-CcGvtmCK.mjs';
12
-
13
- /**
14
- * Shared Text Utilities for Agent Module
15
- *
16
- * Common text extraction and manipulation utilities used by
17
- * context.ts, selectionContext.ts, and other agent-related code.
18
- *
19
- * Consolidates duplicated helper functions into a single location.
20
- */
21
-
22
- /**
23
- * Get plain text from a paragraph
24
- */
25
- declare function getParagraphText(paragraph: Paragraph): string;
26
- /**
27
- * Get plain text from a run
28
- */
29
- declare function getRunText(run: Run): string;
30
- /**
31
- * Get plain text from a hyperlink
32
- */
33
- declare function getHyperlinkText(hyperlink: Hyperlink): string;
34
- /**
35
- * Get plain text from a table
36
- */
37
- declare function getTableText(table: Table): string;
38
- /**
39
- * Get plain text from document body
40
- */
41
- declare function getBodyText(body: DocumentBody): string;
42
- /**
43
- * Count words in text
44
- */
45
- declare function countWords(text: string): number;
46
- /**
47
- * Count characters in text
48
- */
49
- declare function countCharacters(text: string, includeSpaces?: boolean): number;
50
- /**
51
- * Get word count from document body
52
- */
53
- declare function getBodyWordCount(body: DocumentBody): number;
54
- /**
55
- * Get character count from document body
56
- */
57
- declare function getBodyCharacterCount(body: DocumentBody): number;
58
- /**
59
- * Get text before a position
60
- *
61
- * @param paragraphs - Array of paragraphs
62
- * @param position - Position to get text before
63
- * @param maxChars - Maximum characters to return
64
- * @returns Text before the position
65
- */
66
- declare function getTextBefore(paragraphs: Paragraph[], position: Position, maxChars: number): string;
67
- /**
68
- * Get text after a position
69
- *
70
- * @param paragraphs - Array of paragraphs
71
- * @param position - Position to get text after
72
- * @param maxChars - Maximum characters to return
73
- * @returns Text after the position
74
- */
75
- declare function getTextAfter(paragraphs: Paragraph[], position: Position, maxChars: number): string;
76
- /**
77
- * Get formatting at a specific position in a paragraph
78
- *
79
- * @param paragraph - The paragraph to check
80
- * @param offset - Character offset in the paragraph
81
- * @returns Formatting at that position
82
- */
83
- declare function getFormattingAtPosition(paragraph: Paragraph, offset: number): Partial<TextFormatting>;
84
- /**
85
- * Check if position is within a hyperlink
86
- *
87
- * @param paragraph - The paragraph to check
88
- * @param offset - Character offset in the paragraph
89
- * @returns True if position is in a hyperlink
90
- */
91
- declare function isPositionInHyperlink(paragraph: Paragraph, offset: number): boolean;
92
- /**
93
- * Get hyperlink at position
94
- *
95
- * @param paragraph - The paragraph to check
96
- * @param offset - Character offset in the paragraph
97
- * @returns The hyperlink at that position, or undefined
98
- */
99
- declare function getHyperlinkAtPosition(paragraph: Paragraph, offset: number): Hyperlink | undefined;
100
- /**
101
- * Check if style ID represents a heading
102
- *
103
- * @param styleId - Style ID to check
104
- * @returns True if it's a heading style
105
- */
106
- declare function isHeadingStyle(styleId?: string): boolean;
107
- /**
108
- * Parse heading level from style ID
109
- *
110
- * @param styleId - Style ID to parse
111
- * @returns Heading level (1-9) or undefined
112
- */
113
- declare function parseHeadingLevel(styleId?: string): number | undefined;
114
- /**
115
- * Check if document body has images
116
- *
117
- * @param body - Document body to check
118
- * @returns True if contains images
119
- */
120
- declare function hasImages(body: DocumentBody): boolean;
121
- /**
122
- * Check if document body has hyperlinks
123
- *
124
- * @param body - Document body to check
125
- * @returns True if contains hyperlinks
126
- */
127
- declare function hasHyperlinks(body: DocumentBody): boolean;
128
- /**
129
- * Check if document body has tables
130
- *
131
- * @param body - Document body to check
132
- * @returns True if contains tables
133
- */
134
- declare function hasTables(body: DocumentBody): boolean;
135
- /**
136
- * Get all paragraphs from document body
137
- *
138
- * @param body - Document body
139
- * @returns Array of paragraphs
140
- */
141
- declare function getParagraphs(body: DocumentBody): Paragraph[];
142
- /**
143
- * Get paragraph at index from document body
144
- *
145
- * @param body - Document body
146
- * @param index - Paragraph index (0-indexed)
147
- * @returns Paragraph or undefined
148
- */
149
- declare function getParagraphAtIndex(body: DocumentBody, index: number): Paragraph | undefined;
150
- /**
151
- * Get block index for a paragraph index
152
- *
153
- * @param body - Document body
154
- * @param paragraphIndex - Paragraph index
155
- * @returns Block index or -1 if not found
156
- */
157
- declare function getBlockIndexForParagraph(body: DocumentBody, paragraphIndex: number): number;
158
-
159
- /**
160
- * Content-control (SDT) addressing for the document model.
161
- *
162
- * Content controls (`w:sdt`) are the natural anchor for template logic and
163
- * agent edits: they survive the round trip (see the parser + serializer) and
164
- * carry a stable `tag`/`alias`/`id`. This module discovers and edits them
165
- * without a DOM or an editor instance, so server-side pipelines and AI agents
166
- * can find an anchor by tag and act on it.
167
- *
168
- * Both **block-level** (`w:sdt` wrapping paragraphs/tables) and **inline**
169
- * (`w:sdt` inside a paragraph) controls are addressed, including inline
170
- * controls inside table cells (and nested tables). With
171
- * `{ includeHeadersFooters: true }` the walk also covers header/footer parts.
172
- *
173
- * Not surfaced (model limitations): a block SDT placed directly inside a table
174
- * cell (`TableCell.content` cannot hold one), an inline SDT inside a hyperlink
175
- * (`Hyperlink.children` excludes it), and controls inside tracked-change
176
- * wrappers.
177
- */
178
-
179
- /** Filter for {@link findContentControls}. All provided fields must match (AND). */
180
- interface ContentControlFilter {
181
- /** Developer identifier (`w:tag`), exact match. */
182
- tag?: string;
183
- /** Friendly name (`w:alias`), exact match. */
184
- alias?: string;
185
- /** Numeric id (`w:id`), exact match. */
186
- id?: number;
187
- /** Control type projection (`richText`, `dropDownList`, …). */
188
- type?: SdtType;
189
- }
190
- /**
191
- * Where a control lives. `body` = the main document story; `header`/`footer`
192
- * = a page-furniture part addressed by its relationship id (the key into
193
- * `package.headers`/`package.footers`).
194
- */
195
- type ContentControlLocation = {
196
- part: 'body';
197
- } | {
198
- part: 'header' | 'footer';
199
- rId: string;
200
- };
201
- /** A discovered content control plus enough context to address and edit it. */
202
- interface ContentControlInfo {
203
- /** Developer identifier (`w:tag`). */
204
- tag?: string;
205
- /** Friendly name (`w:alias`). */
206
- alias?: string;
207
- /** Numeric id (`w:id`). */
208
- id?: number;
209
- /** Control type projection. */
210
- sdtType: SdtType;
211
- /** Lock setting, if any. A locked control should refuse content edits. */
212
- lock?: SdtProperties['lock'];
213
- /** Dropdown/combobox list items, if modeled. */
214
- listItems?: {
215
- displayText: string;
216
- value: string;
217
- }[];
218
- /** Placeholder docPart reference, if any. */
219
- placeholder?: string;
220
- /** Whether the control is currently showing placeholder text (`w:showingPlcHdr`). */
221
- showingPlaceholder?: boolean;
222
- /** Checkbox state, for checkbox controls. */
223
- checked?: boolean;
224
- /** Date format string, for date controls. */
225
- dateFormat?: string;
226
- /** XML data binding (`w:dataBinding`), if the control is bound. */
227
- dataBinding?: SdtDataBinding;
228
- /** Plain text of the control's content (paragraphs/tables/nested controls flattened). */
229
- text: string;
230
- /**
231
- * Block-index path to this control: top-level `[i]`, a control nested in the
232
- * i-th block's content `[i, j]`, and so on. For inline / cell controls it is
233
- * the block indices of the nearest enclosing blocks.
234
- */
235
- path: number[];
236
- /** Nesting depth = number of enclosing content controls (0 = not inside another control). */
237
- depth: number;
238
- /** Block-level (`w:sdt` at block level) or inline (`w:sdt` inside a paragraph). */
239
- kind: 'block' | 'inline';
240
- /** Where the control lives (body vs a header/footer part). */
241
- location: ContentControlLocation;
242
- }
243
- /** Plain text of a control's content, descending into tables and nested SDTs. */
244
- declare function getContentControlText(control: BlockSdt | InlineSdt): string;
245
- /** Options for {@link findContentControls}. */
246
- interface FindContentControlsOptions {
247
- /**
248
- * When `true`, also search header/footer parts — but only when a full
249
- * {@link Document} is passed (a bare `DocumentBody` carries no parts, so this
250
- * then searches the body only and never throws). Defaults to `false` (the main
251
- * document story only).
252
- */
253
- includeHeadersFooters?: boolean;
254
- }
255
- /**
256
- * Find every content control in the document — block-level AND inline —
257
- * optionally filtered by tag/alias/id/type. Results are in strict document
258
- * order; nested controls follow their parent.
259
- *
260
- * The walk descends body blocks, block SDTs, tables (row-major, including
261
- * nested tables) into cell content, and paragraph inline content (inline
262
- * SDTs, recursing into nested inline SDTs). With `{ includeHeadersFooters: true }`
263
- * and a full {@link Document}, header then footer parts are searched after the
264
- * body, each sorted by relationship id for deterministic order.
265
- *
266
- * Not surfaced (model limitations, documented): a block SDT placed directly
267
- * inside a table cell (`TableCell.content` is `(Paragraph | Table)[]`), an
268
- * inline SDT inside a hyperlink (`Hyperlink.children` excludes it), and
269
- * controls buried inside tracked-change wrappers.
270
- */
271
- declare function findContentControls(input: Document | DocumentBody, filter?: ContentControlFilter, options?: FindContentControlsOptions): ContentControlInfo[];
272
- /** Convenience: the first control matching `filter`, or `undefined`. */
273
- declare function findContentControl(input: Document | DocumentBody, filter: ContentControlFilter, options?: FindContentControlsOptions): ContentControlInfo | undefined;
274
- /** No control matched the filter. */
275
- declare class ContentControlNotFoundError extends Error {
276
- constructor(filter: ContentControlFilter);
277
- }
278
- /** The matched control's lock forbids the attempted edit (pass `force` to override). */
279
- declare class ContentControlLockedError extends Error {
280
- constructor(lock: SdtProperties['lock'], op: 'edit' | 'remove');
281
- }
282
- /**
283
- * The control's type doesn't support free text/block replacement (e.g. a
284
- * dropdown, date, checkbox, or picture control), so writing arbitrary content
285
- * would desync the type marker from its value. Use a type-specific setter, or
286
- * pass `{ force: true }` to override.
287
- */
288
- declare class ContentControlTypeError extends Error {
289
- constructor(sdtType: SdtType);
290
- }
291
- /**
292
- * The control is bound to a Custom XML data store (`w:dataBinding`). Writing its
293
- * content won't stick — Word re-renders the control from the bound XML node — so
294
- * the write is refused. Update the data store instead, or pass `{ force: true }`.
295
- */
296
- declare class ContentControlBoundError extends Error {
297
- constructor();
298
- }
299
- /**
300
- * A `BlockContent[]` replacement was targeted at an inline control, which can
301
- * only hold inline content (runs, hyperlinks, fields, nested inline SDTs, math).
302
- * Splicing a paragraph into a paragraph would be invalid OOXML — pass a string,
303
- * or a single paragraph whose content is entirely inline.
304
- */
305
- declare class ContentControlKindError extends Error {
306
- constructor(detail: string);
307
- }
308
- /**
309
- * Replace the content of the first control matching `filter` — block-level OR
310
- * inline (including inside table cells and, with `includeHeadersFooters: true`,
311
- * headers and footers). `replacement` may be a string or block content.
312
- *
313
- * - For a **block** control the string is split into paragraphs on newlines
314
- * (a `plainText` control collapses to one paragraph); block content is used
315
- * as-is (cloned).
316
- * - For an **inline** control the string becomes a single run that inherits the
317
- * placeholder's formatting (so the value matches the field it replaces). A
318
- * richText control turns `\n` into a line break; a plainText control never
319
- * gets one. Passing `BlockContent[]` to an inline control throws
320
- * {@link ContentControlKindError} unless it is a single all-inline paragraph.
321
- *
322
- * Pass `{ all: true }` to fill **every** control matching `filter` (one logical
323
- * value that recurs under a shared tag — e.g. a name in the body, a running
324
- * header, and several table cells) instead of just the first.
325
- *
326
- * The control's properties, tag/alias, and lossless raw `w:sdtPr` are preserved.
327
- * When the control was showing its placeholder (`w:showingPlcHdr`), that flag is
328
- * cleared so Word doesn't render the new content as placeholder text.
329
- *
330
- * Throws {@link ContentControlNotFoundError} if nothing matches,
331
- * {@link ContentControlLockedError} if the lock forbids editing,
332
- * {@link ContentControlTypeError} for a typed (dropdown/date/…) control, and
333
- * {@link ContentControlBoundError} for a data-bound control. Pass
334
- * `{ force: true }` to override the guards.
335
- */
336
- declare function setContentControlContent(doc: Document, filter: ContentControlFilter, replacement: string | BlockContent[], options?: {
337
- force?: boolean;
338
- includeHeadersFooters?: boolean;
339
- all?: boolean;
340
- }): Document;
341
- /**
342
- * Remove the first control matching `filter` — block-level OR inline (incl.
343
- * inside table cells and, with `includeHeadersFooters: true`, headers/footers).
344
- * With `keepContent: true` the control's content is unwrapped in place (the box goes
345
- * away, the content stays) — block content lifts to its block siblings, inline
346
- * content stays inline in the enclosing paragraph. Otherwise the control and
347
- * its content are deleted.
348
- *
349
- * Pass `{ all: true }` to remove **every** control matching `filter` (e.g. to
350
- * flatten a finished template by unwrapping all controls) instead of the first.
351
- *
352
- * Unwrapping a repeating-section (item) is refused unless `force`, since lifting
353
- * its blocks out would orphan the (w15) repeating structure.
354
- *
355
- * Throws {@link ContentControlNotFoundError} / {@link ContentControlLockedError}
356
- * as {@link setContentControlContent} does.
357
- */
358
- declare function removeContentControl(doc: Document, filter: ContentControlFilter, options?: {
359
- force?: boolean;
360
- keepContent?: boolean;
361
- includeHeadersFooters?: boolean;
362
- all?: boolean;
363
- }): Document;
364
-
365
- /**
366
- * Create a new inline content control (`w:sdt`) by wrapping a text span.
367
- *
368
- * Complements the discovery/edit functions in {@link ./contentControls}: where
369
- * those find and mutate existing controls, this wraps an exact run of text
370
- * inside a paragraph in a new control with a synthesized, Word-correct
371
- * `w:sdtPr`. Pure — the input {@link Document} is not mutated.
372
- */
373
-
374
- /** A create request failed: the target couldn't be resolved, or the wrap is invalid. */
375
- declare class ContentControlCreateError extends Error {
376
- constructor(message: string);
377
- }
378
- /**
379
- * Where to create a control: an exact text span inside a paragraph. The
380
- * paragraph is located by Word `w14:paraId`, and the chosen `occurrence` of
381
- * `text` is wrapped in an inline control — including inside a table cell, where
382
- * block-level controls aren't allowed.
383
- */
384
- interface CreateContentControlTarget {
385
- /** Word `w14:paraId` of the paragraph containing the text. */
386
- paraId: string;
387
- /** Exact substring to wrap. */
388
- text: string;
389
- /** Which occurrence of `text` to wrap when it repeats (1-based; default 1). */
390
- occurrence?: number;
391
- }
392
- /** Modeled properties for a control created by {@link createContentControl}. */
393
- interface NewContentControlProps {
394
- /** Control type (default `richText`). */
395
- sdtType?: SdtType;
396
- /** Developer identifier (`w:tag`). */
397
- tag?: string;
398
- /** Friendly name (`w:alias`). */
399
- alias?: string;
400
- /** Numeric id (`w:id`). Default: auto-assigned, unique across the document. */
401
- id?: number;
402
- /** Lock setting (`w:lock`). */
403
- lock?: SdtProperties['lock'];
404
- /** Dropdown/combobox list items. */
405
- listItems?: {
406
- displayText: string;
407
- value: string;
408
- }[];
409
- /** Date display format (`w:date/w:dateFormat`), for `date` controls. */
410
- dateFormat?: string;
411
- /** Initial checkbox state, for `checkbox` controls. */
412
- checked?: boolean;
413
- /** Whether the control starts in placeholder state (`w:showingPlcHdr`). */
414
- showingPlaceholder?: boolean;
415
- }
416
- /**
417
- * Wrap an exact text span inside a paragraph in a new inline content control
418
- * (`w:sdt`), returning a new {@link Document} and the created control's
419
- * {@link ContentControlInfo}. Pure — the input is not mutated. This is the form
420
- * needed inside table cells and mid-sentence, where block controls aren't
421
- * allowed: runs are split at the span boundaries (formatting preserved) and
422
- * interior fields/tabs/breaks are kept wholesale.
423
- *
424
- * The control's `w:sdtPr` is synthesized from `props`, and its `w:id` is
425
- * auto-assigned (unique across the document) when `props.id` is omitted, so the
426
- * control round-trips and `findContentControl(doc, { tag })` resolves it after a
427
- * save/reload.
428
- *
429
- * **Body only:** the search covers body paragraphs and block/table content —
430
- * paragraphs inside headers or footers are not reachable. Passing a `paraId`
431
- * from a header/footer part throws {@link ContentControlCreateError} with a
432
- * "No paragraph found" message.
433
- *
434
- * @throws {@link ContentControlCreateError} when the paragraph or text isn't
435
- * found, the span overlaps an existing control or crosses a non-run boundary,
436
- * the `sdtType` can't be synthesized, or a supplied `id` already exists.
437
- */
438
- declare function createContentControl(doc: Document, target: CreateContentControlTarget, props?: NewContentControlProps): {
439
- doc: Document;
440
- control: ContentControlInfo;
441
- };
442
-
443
- /**
444
- * Typed value setters for block-level content controls — set a dropdown
445
- * selection, toggle a checkbox, or set a date. These produce both the visible
446
- * content (the run text Word shows) and the structured state inside the
447
- * captured raw `w:sdtPr` (dropdown `w:lastValue`, `w14:checked`, `w:date`'s
448
- * `w:fullDate`), patched in place so the rest of the control round-trips
449
- * verbatim. Use these instead of {@link setContentControlContent} for typed
450
- * controls, which that function refuses by design.
451
- *
452
- * Raw `w:sdtPr` is patched with targeted string edits (not a full re-serialize)
453
- * to preserve the `CT_SdtPr` element order and any unmodeled properties — the
454
- * same capture-and-replay contract used everywhere else for SDTs.
455
- */
456
-
457
- /** A typed value to apply to a content control. */
458
- type ContentControlValue = {
459
- kind: 'dropdown';
460
- value: string;
461
- } | {
462
- kind: 'checkbox';
463
- checked: boolean;
464
- } | {
465
- kind: 'date';
466
- date: string;
467
- };
468
- /** The control doesn't support the requested value kind, or the value is invalid. */
469
- declare class ContentControlValueError extends Error {
470
- constructor(message: string);
471
- }
472
- /** Format an ISO date (yyyy-mm-dd) with a subset of OOXML date tokens. */
473
- declare function formatSdtDate(iso: string, pattern?: string, language?: string): string;
474
- /**
475
- * Set a typed value (dropdown selection / checkbox / date) on the first control
476
- * matching `filter` — **block-level OR inline** (inline includes controls inside
477
- * table cells, and with `includeHeadersFooters: true`, headers/footers) — returning a new
478
- * {@link Document}. Updates both the visible content and the structured raw
479
- * state (dropdown `w:lastValue`, `w14:checked`, `w:date/@w:fullDate`), so the
480
- * result round-trips and Word shows the new value.
481
- *
482
- * Pass `{ all: true }` to set the value on **every** control matching `filter`
483
- * (a value shared across duplicated controls) instead of just the first.
484
- *
485
- * Throws `ContentControlNotFoundError` if nothing matches,
486
- * {@link ContentControlLockedError} if content-locked,
487
- * {@link ContentControlBoundError} if data-bound (the store would override the
488
- * write), and {@link ContentControlValueError} if the value doesn't fit the
489
- * control type. The lock/bound guards are overridable with `{ force: true }`.
490
- */
491
- declare function setContentControlValue(doc: Document, filter: ContentControlFilter, value: ContentControlValue, options?: {
492
- force?: boolean;
493
- includeHeadersFooters?: boolean;
494
- all?: boolean;
495
- }): Document;
496
-
497
- /**
498
- * Repeating-section (w15:repeatingSection) support — add and remove repeated
499
- * items, the way Word's "+" affordance does. A repeating section is a block
500
- * content control whose `w:sdtPr` carries `<w15:repeatingSection>`; its direct
501
- * children are item controls each carrying `<w15:repeatingSectionItem>`.
502
- *
503
- * Adding clones an existing item (with a fresh, unique `w:id`) and inserts it
504
- * after; removing drops one item but keeps at least one. The w15 elements ride
505
- * in the captured raw `w:sdtPr` (they're unmodeled), so we detect and patch the
506
- * raw string rather than re-serializing.
507
- */
508
-
509
- /** The control's raw `w:sdtPr` declares it a repeating section (the container). */
510
- declare function isRepeatingSection(props: SdtProperties): boolean;
511
- /** The control's raw `w:sdtPr` declares it a repeating-section item. */
512
- declare function isRepeatingSectionItem(props: SdtProperties): boolean;
513
- /** Raised when an operation targets something that isn't a repeating section/item. */
514
- declare class RepeatingSectionError extends Error {
515
- constructor(message: string);
516
- }
517
- /**
518
- * Add a new repeating-section item, cloned from an existing one and inserted
519
- * after it. `afterIndex` is the item ordinal to clone/insert after (default:
520
- * the last item). Returns a new {@link Document}.
521
- */
522
- declare function addRepeatingSectionItem(doc: Document, filter: ContentControlFilter, options?: {
523
- afterIndex?: number;
524
- }): Document;
525
- /**
526
- * Remove the repeating-section item at ordinal `index`. Keeps at least one item
527
- * (Word does not allow removing the last). Returns a new {@link Document}.
528
- */
529
- declare function removeRepeatingSectionItem(doc: Document, filter: ContentControlFilter, index: number): Document;
530
-
531
- export { ContentControlBoundError, ContentControlCreateError, type ContentControlFilter, type ContentControlInfo, ContentControlKindError, type ContentControlLocation, ContentControlLockedError, ContentControlNotFoundError, ContentControlTypeError, type ContentControlValue, ContentControlValueError, type CreateContentControlTarget, type FindContentControlsOptions, type NewContentControlProps, Position, RepeatingSectionError, addRepeatingSectionItem, countCharacters, countWords, createContentControl, findContentControl, findContentControls, formatSdtDate, getBlockIndexForParagraph, getBodyCharacterCount, getBodyText, getBodyWordCount, getContentControlText, getFormattingAtPosition, getHyperlinkAtPosition, getHyperlinkText, getParagraphAtIndex, getParagraphText, getParagraphs, getRunText, getTableText, getTextAfter, getTextBefore, hasHyperlinks, hasImages, hasTables, isHeadingStyle, isPositionInHyperlink, isRepeatingSection, isRepeatingSectionItem, parseHeadingLevel, removeContentControl, removeRepeatingSectionItem, setContentControlContent, setContentControlValue };
@@ -1 +0,0 @@
1
- export{a as ContentControlCreateError,e as RepeatingSectionError,f as addRepeatingSectionItem,b as createContentControl,c as isRepeatingSection,d as isRepeatingSectionItem,g as removeRepeatingSectionItem}from'../chunk-QOUFE3VX.mjs';export{C as ContentControlBoundError,F as ContentControlKindError,A as ContentControlLockedError,z as ContentControlNotFoundError,B as ContentControlTypeError,J as ContentControlValueError,g as countCharacters,f as countWords,y as findContentControl,x as findContentControls,K as formatSdtDate,v as getBlockIndexForParagraph,i as getBodyCharacterCount,e as getBodyText,h as getBodyWordCount,w as getContentControlText,l as getFormattingAtPosition,n as getHyperlinkAtPosition,c as getHyperlinkText,u as getParagraphAtIndex,a as getParagraphText,t as getParagraphs,b as getRunText,d as getTableText,k as getTextAfter,j as getTextBefore,r as hasHyperlinks,q as hasImages,s as hasTables,o as isHeadingStyle,m as isPositionInHyperlink,p as parseHeadingLevel,I as removeContentControl,H as setContentControlContent,M as setContentControlValue}from'../chunk-YBIM6UJV.mjs';export{g as DEFAULT_AI_ACTIONS,d as comparePositions,a as createCollapsedRange,h as createCommand,b as createRange,f as getActionDescription,e as getActionLabel,c as isPositionInRange}from'../chunk-Q7PO7V73.mjs';export{a as DocumentAgent,h as buildExtendedSelectionContext,g as buildSelectionContext,e as buildSelectionContextFromContext,b as createAgent,c as createAgentFromDocument,d as getAgentContext,f as getDocumentSummary,i as getSelectionFormattingSummary}from'../chunk-XQBCCJBO.mjs';import'../chunk-UIEJWORW.mjs';export{a as executeCommand,b as executeCommands}from'../chunk-6PW4CWUG.mjs';import'../chunk-KXNZFTTK.mjs';import'../chunk-VBOTMRXV.mjs';import'../chunk-OJOHXQNQ.mjs';import'../chunk-KVKLLTDP.mjs';import'../chunk-BIQWVK5P.mjs';import'../chunk-3UBMCDME.mjs';import'../chunk-LDUWIM7M.mjs';import'../chunk-DXKG3HQ5.mjs';import'../chunk-FPZBTOD6.mjs';import'../chunk-H3JCIGWK.mjs';import'../chunk-N5Q3YN64.mjs';import'../chunk-SINEY6ZF.mjs';import'../chunk-T4EZMUXM.mjs';import'../chunk-TTRUPDAB.mjs';
@@ -1 +0,0 @@
1
- function h(){return {type:"break",breakType:"page"}}function b(){return {type:"break",breakType:"column"}}function y(e){return {type:"break",breakType:"textWrapping",clear:e}}function C(){return {type:"run",content:[h()]}}function l(){return {type:"paragraph",content:[],formatting:{pageBreakBefore:true}}}function k(e){return e.content.filter(t=>t.type==="run")}function d(e,t){let{paragraphIndex:a}=t,n=[...e.package.document.content||[]],r=l();return n.splice(a+1,0,r),{...e,package:{...e.package,document:{...e.package.document,content:n}}}}function B(){return {type:"paragraph",content:[],formatting:{borders:{bottom:{style:"single",color:{rgb:"000000"},size:12,space:1}},spaceBefore:120,spaceAfter:120}}}function R(e,t){let{paragraphIndex:a}=t,n=[...e.package.document.content||[]],r=B();return n.splice(a+1,0,r),{...e,package:{...e.package,document:{...e.package.document,content:n}}}}function i(e){return e.type==="break"&&e.breakType==="page"}function I(e){return e.type==="break"&&e.breakType==="column"}function D(e){return e.type==="break"&&e.breakType==="textWrapping"}function T(e){return e.type==="break"}function g(e){return e.formatting?.pageBreakBefore===true}function z(e){let t=0;for(let a of e.package.document.content||[])if(a.type==="paragraph"){let n=a;g(n)&&t++;let r=k(n);for(let u of r)for(let o of u.content)i(o)&&t++;}return t}function w(e){let t=[],a=e.package.document.content||[];for(let n=0;n<a.length;n++){let r=a[n];if(r.type==="paragraph"){let u=r;g(u)&&t.push({paragraphIndex:n});let o=k(u);for(let p=0;p<o.length;p++){let s=o[p];for(let c of s.content)i(c)&&t.push({paragraphIndex:n,runIndex:p});}}}return t}function H(e,t){let{paragraphIndex:a,runIndex:n}=t,r=[...e.package.document.content||[]],u=r[a];if(u.type!=="paragraph")return e;let o=u;if(g(o)&&n===void 0)return r[a]={...o,formatting:{...o.formatting,pageBreakBefore:false}},{...e,package:{...e.package,document:{...e.package.document,content:r}}};if(n!==void 0){let p=[],s=0;for(let c of o.content)if(c.type==="run"){if(s===n){let f=c.content.filter(m=>!i(m));f.length>0&&p.push({...c,content:f});}else p.push(c);s++;}else p.push(c);return r[a]={...o,content:p},{...e,package:{...e.package,document:{...e.package.document,content:r}}}}return e}export{h as a,b,y as c,C as d,l as e,d as f,B as g,R as h,i,I as j,D as k,T as l,g as m,z as n,w as o,H as p};
@@ -1 +0,0 @@
1
- var R=/[\p{L}\p{N}\p{M}_''\-]/u,S=/\s/;function f(e){return !e||e.length===0?false:R.test(e)}function g(e){return !e||e.length===0?false:S.test(e)}function c(e,t){if(!e||e.length===0)return [0,0];t=Math.max(0,Math.min(t,e.length-1));let r=e[t];if(g(r)){let n=t,o=t;for(;n>0&&g(e[n-1]);)n--;for(;o<e.length&&g(e[o]);)o++;return [n,o]}if(f(r)){let n=t,o=t;for(;n>0&&f(e[n-1]);)n--;for(;o<e.length&&f(e[o]);)o++;return [n,o]}return [t,t+1]}function b(e,t){let[r,n]=c(e,t);return e.slice(r,n)}function O(e,t){let[r,n]=c(e,t);return {word:e.slice(r,n),startIndex:r,endIndex:n}}function p(){let e=window.getSelection();if(!e||e.rangeCount===0)return false;let t=e.getRangeAt(0),r=t.startContainer;if(r.nodeType===Node.TEXT_NODE){let n=r.textContent||"",o=t.startOffset,[s,l]=c(n,o);if(l>s)return t.setStart(r,s),t.setEnd(r,l),e.removeAllRanges(),e.addRange(t),true}if(r.nodeType===Node.ELEMENT_NODE){let n=r,o=x(n);if(o.length>0){let s=t.startOffset,l=null,a=s;if(s<n.childNodes.length){let i=n.childNodes[s];if(i.nodeType===Node.TEXT_NODE)l=i,a=0;else if(i instanceof Element){let d=x(i);d.length>0&&(l=d[0],a=0);}}if(!l&&o.length>0&&(l=o[0],a=0),l){let i=l.textContent||"",[d,h]=c(i,a);if(h>d){let E=document.createRange();return E.setStart(l,d),E.setEnd(l,h),e.removeAllRanges(),e.addRange(E),true}}}}return false}function A(e,t){let r=window.getSelection();if(!r)return false;let n=e.textContent||"",[o,s]=c(n,t);if(s>o){let l=document.createRange();return l.setStart(e,o),l.setEnd(e,s),r.removeAllRanges(),r.addRange(l),true}return false}function y(){let e=window.getSelection();if(!e||e.rangeCount===0)return false;let t=e.getRangeAt(0);if(t.collapsed)return p();let r=t.startContainer,n=t.endContainer,o=t.startOffset,s=t.endOffset;if(r.nodeType===Node.TEXT_NODE){let l=r.textContent||"",[a]=c(l,t.startOffset);o=a;}if(n.nodeType===Node.TEXT_NODE){let l=n.textContent||"",a=Math.max(0,t.endOffset-1),[,i]=c(l,a);s=i;}try{return t.setStart(r,o),t.setEnd(n,s),e.removeAllRanges(),e.addRange(t),!0}catch(l){return console.warn("Could not expand selection to word boundaries:",l),false}}function C(){let e=window.getSelection();if(!e||e.rangeCount===0)return false;let r=e.getRangeAt(0).commonAncestorContainer,n=W(r);if(n){let o=document.createRange();return o.selectNodeContents(n),e.removeAllRanges(),e.addRange(o),true}return false}function W(e){if(!e)return null;let t=e;for(;t;){if(t instanceof Element&&t.hasAttribute("data-paragraph-index"))return t;t=t.parentNode;}return null}function x(e){let t=[],r=document.createTreeWalker(e,NodeFilter.SHOW_TEXT,null),n;for(;n=r.nextNode();)n.nodeType===Node.TEXT_NODE&&t.push(n);return t}var T=0,u=null,m=null,M=500;function w(){T=0,m=null,u&&(clearTimeout(u),u=null);}function N(e){return e.target!==m&&w(),T++,m=e.target,u&&clearTimeout(u),u=setTimeout(w,M),Math.min(T,3)}function _(){return e=>{e.ctrlKey||e.metaKey||e.altKey||p();}}function k(){return e=>{if(N(e)===3){if(e.ctrlKey||e.metaKey||e.altKey)return;C();}}}var D={isWordCharacter:f,isWhitespace:g,findWordBoundaries:c,getWordAt:b,findWordAt:O,selectWordAtCursor:p,selectWordInTextNode:A,expandSelectionToWordBoundaries:y,selectParagraphAtCursor:C,handleClickForMultiClick:N,createDoubleClickWordSelector:_,createTripleClickParagraphSelector:k};export{f as a,g as b,c,b as d,O as e,p as f,A as g,y as h,C as i,N as j,_ as k,k as l,D as m};
@@ -1 +0,0 @@
1
- import {g}from'./chunk-3UBMCDME.mjs';function F(e,n,t){if(!(!e||e<=0)){if(n==="pct")return t*e/5e3;if(!n||n==="dxa"||n==="auto")return g(e)}}function p(e){let n=new Map,t=[];for(let r=0;r<e.rows.length;r++){let i=e.rows[r]?.cells??[],o=n.get(r)??new Set,a=Math.max(0,Math.min(16384,Math.trunc(e.rows[r]?.gridBefore??0)));for(;o.has(a);)a++;for(let m=0;m<i.length;m++){let u=i[m];if(!u)continue;u.gridStart!=null&&(a=Math.max(a,Math.min(16384,Math.trunc(u.gridStart))));let s=Math.max(1,Math.min(16384,Math.trunc(u.colSpan??1))),f=Math.max(1,Math.min(32768,Math.trunc(u.rowSpan??1)));if(t.push({rowIndex:r,cellIndex:m,columnIndex:a,colSpan:s,rowSpan:f}),f>1)for(let c=r+1;c<r+f;c++){n.has(c)||n.set(c,new Set);let d=n.get(c);for(let l=0;l<s;l++)d.add(a+l);}for(a+=s;o.has(a);)a++;}}return t}function Z(e){let n=p(e),t=1;for(let r of n)t=Math.max(t,r.columnIndex+r.colSpan);for(let r=0;r<e.rows.length;r++){let i=e.rows[r],a=n.filter(m=>m.rowIndex===r).reduce((m,u)=>Math.max(m,u.columnIndex+u.colSpan),Math.max(0,Math.trunc(i.gridBefore??0)));t=Math.max(t,a+Math.max(0,Math.trunc(i.gridAfter??0)));}return Math.min(16384,t)}function b(e,n,t,r,i){return F(e?.value,e?.type,r)??F(n,t,r)??(i!=null&&i>0?i:void 0)}function h(e,n,t,r){if(!(r>0)||n>=e.length)return;let i=Math.min(e.length,n+Math.max(1,t)),o=e.slice(n,i).reduce((u,s)=>u+s,0),a=r-o;if(a<=0)return;let m=a/Math.max(1,i-n);for(let u=n;u<i;u++)e[u]+=m;}function x(e,n){let t=e.reduce((i,o)=>i+o,0);if(!(n>t)||e.length===0)return e;let r=(n-t)/e.length;return e.map(i=>i+r)}function Y(e,n,t,r){let i=e.gridWidths??e.columnWidths??[],o=w(i,t,r??n),a=p(e).filter(m=>m.rowIndex===0);for(let m of a){let u=e.rows[0]?.cells[m.cellIndex];if(!u)continue;let s=b(u.preferredWidth,u.widthValue,u.widthType,r??n,u.width);s&&h(o,m.columnIndex,m.colSpan,s);}return r&&(o=x(o,r)),o}function A(e,n,t,r){let i=w(e.gridWidths??e.columnWidths??[],t,r??n),o=Array(t).fill(0),a=Array(t).fill(0);for(let l of p(e)){let g=e.rows[l.rowIndex]?.cells[l.cellIndex];if(!g)continue;let M=b(g.preferredWidth,g.widthValue,g.widthType,r??n,g.width),W=Math.max(0,g.minContentWidth??0,g.noWrap?g.maxContentWidth??0:0),v=Math.max(W,g.maxContentWidth??M??0);h(o,l.columnIndex,l.colSpan,W),h(a,l.columnIndex,l.colSpan,v),M&&h(a,l.columnIndex,l.colSpan,M);}for(let l=0;l<t;l++)o[l]<=0&&(o[l]=Math.min(i[l],a[l]||i[l])),a[l]=Math.max(o[l],a[l]||i[l]);let m=o.reduce((l,g)=>l+g,0),u=a.reduce((l,g)=>l+g,0),s=Math.max(m,Math.min(n,r??(u>0?u:n)));if(s>=u)return x(a,s);let f=a.map((l,g)=>Math.max(0,l-o[g])),c=f.reduce((l,g)=>l+g,0),d=Math.max(0,s-m);return c<=0?x(o,s):o.map((l,g)=>l+d*f[g]/c)}function w(e,n,t){if(n<=0)return [];let r=t>0?t/n:0;if(e.length===0)return Array(n).fill(r);let i=e.slice(0,n),o=n-i.length;if(o>0){let f=i.filter(d=>d>0),c=f.length>0?f.reduce((d,l)=>d+l,0)/f.length:r;i=i.concat(Array(o).fill(c));}let a=i.reduce((f,c)=>f+(c>0?c:0),0),m=i.filter(f=>f<=0).length;if(a<=0)return Array(n).fill(r);if(m===0)return i;let u=Math.max(0,t-a),s=u>0?u/m:a/Math.max(1,n-m);return i.map(f=>f>0?f:s)}function C(e,n){let t=e.columnWidths??[],r=b(e.preferredWidth,e.width,e.widthType,n),i=Z(e),o=r??n,a=e.widthAlgorithm??e.layoutMode??"legacy";if(e.rows.length>0&&a==="fixed")return Y(e,n,i,r);if(e.rows.length>0&&a==="autofit")return A(e,n,i,r);if(e.rows.length>0&&(t=w(t,i,o)),t.length>0&&r){let m=t.reduce((u,s)=>u+s,0);if(m>0&&Math.abs(m-r)>1){let u=r/m;t=t.map(s=>s*u);}}return t}function D(e,n){let t=C(e,n),r=b(e.preferredWidth,e.width,e.widthType,n);return t.reduce((i,o)=>i+o,0)||r||n}function O(e,n,t){let r=Math.max(1,t),i=Math.max(0,e),o=Math.max(0,n);return i>=r||o>=r||i+o>=r?{leftMargin:0,rightMargin:0}:{leftMargin:i,rightMargin:o}}function H(e,n){return e.map(t=>{let r=t.x-t.distLeft,i=t.x+t.width+t.distRight,o=t.y-t.distTop,a=t.y+t.height+t.distBottom;if(t.wrapType==="topAndBottom")return {leftMargin:0,rightMargin:0,topY:o,bottomY:a,fullWidthBlock:true};let m=0,u=0,s,f=t.wrapText??"bothSides";f==="right"?m=T(i):f==="left"?u=S(r,n):f==="largest"?{leftMargin:m,rightMargin:u}=G(r,i,n):E(r,i,n)?s=_(r,i,n):t.side==="left"?m=T(i):u=S(r,n);let c=O(m,u,n);return {leftMargin:c.leftMargin,rightMargin:c.rightMargin,topY:o,bottomY:a,segments:s}})}function V(e,n,t,r){if(!t||t.length===0)return {leftMargin:0,rightMargin:0};let i=0,o=0,a,m=r+e,u=m+n;for(let s of t)if(!(u<=s.topY||m>=s.bottomY)){if(s.fullWidthBlock)return {leftMargin:0,rightMargin:0,segments:[{leftOffset:0,availableWidth:0}]};if(s.segments?.length){a=a?R(a,s.segments):s.segments;continue}i=Math.max(i,s.leftMargin),o=Math.max(o,s.rightMargin);}return {leftMargin:i,rightMargin:o,segments:a}}function R(e,n){let t=[];for(let r of e)for(let i of n){let o=Math.max(r.leftOffset,i.leftOffset),a=Math.min(r.leftOffset+r.availableWidth,i.leftOffset+i.availableWidth);a>o&&t.push({leftOffset:o,availableWidth:a-o});}return t}function E(e,n,t){return e>24&&n+24<t}function _(e,n,t){return [{leftOffset:0,availableWidth:Math.max(0,e)},{leftOffset:Math.max(0,n),availableWidth:Math.max(0,t-n)}].filter(r=>r.availableWidth>1)}function G(e,n,t){let r=Math.max(0,e);return Math.max(0,t-n)>=r?{leftMargin:T(n),rightMargin:0}:{leftMargin:0,rightMargin:S(e,t)}}function T(e){return Math.max(0,e)}function S(e,n){return Math.max(0,n-e)}export{F as a,p as b,Z as c,w as d,C as e,D as f,O as g,H as h,V as i};