@betteroffice/docx 0.0.1

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 (190) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +41 -0
  3. package/dist/Subscribable-DOz6Ohoo.d.mts +33 -0
  4. package/dist/agent/index.d.mts +531 -0
  5. package/dist/agent/index.mjs +1 -0
  6. package/dist/chunk-34K66SY4.mjs +1 -0
  7. package/dist/chunk-3UBMCDME.mjs +1 -0
  8. package/dist/chunk-4RCISPPE.mjs +1 -0
  9. package/dist/chunk-4UD54UM5.mjs +1 -0
  10. package/dist/chunk-52GB3Y42.mjs +1 -0
  11. package/dist/chunk-6NEKRDXF.mjs +1 -0
  12. package/dist/chunk-6PW4CWUG.mjs +1 -0
  13. package/dist/chunk-7DEIW7FL.mjs +1 -0
  14. package/dist/chunk-7PCO5I2O.mjs +1 -0
  15. package/dist/chunk-BI3B33LI.mjs +1 -0
  16. package/dist/chunk-BIQWVK5P.mjs +2 -0
  17. package/dist/chunk-CIRN3LZA.mjs +1 -0
  18. package/dist/chunk-DXKG3HQ5.mjs +16 -0
  19. package/dist/chunk-EUUIJVM6.mjs +0 -0
  20. package/dist/chunk-FPZBTOD6.mjs +1 -0
  21. package/dist/chunk-FZIA7OFY.mjs +1 -0
  22. package/dist/chunk-GWKJ2Y4Y.mjs +1 -0
  23. package/dist/chunk-H3JCIGWK.mjs +1 -0
  24. package/dist/chunk-HJGAQIU7.mjs +2 -0
  25. package/dist/chunk-I6KKMUUC.mjs +1 -0
  26. package/dist/chunk-IL5JZJT7.mjs +1 -0
  27. package/dist/chunk-JY6ILTNS.mjs +1 -0
  28. package/dist/chunk-KEE52TT5.mjs +1 -0
  29. package/dist/chunk-KVKLLTDP.mjs +58 -0
  30. package/dist/chunk-KXNZFTTK.mjs +1 -0
  31. package/dist/chunk-L5ISVQ3W.mjs +1 -0
  32. package/dist/chunk-LDUWIM7M.mjs +1 -0
  33. package/dist/chunk-N5Q3YN64.mjs +1 -0
  34. package/dist/chunk-NEWOMDTX.mjs +1 -0
  35. package/dist/chunk-O2QSE2I7.mjs +1 -0
  36. package/dist/chunk-OBQGPMPQ.mjs +1 -0
  37. package/dist/chunk-OJOHXQNQ.mjs +1 -0
  38. package/dist/chunk-OMR3TWCD.mjs +2 -0
  39. package/dist/chunk-P3KDV4M2.mjs +1 -0
  40. package/dist/chunk-Q7PO7V73.mjs +1 -0
  41. package/dist/chunk-QOUFE3VX.mjs +1 -0
  42. package/dist/chunk-SINEY6ZF.mjs +1 -0
  43. package/dist/chunk-T4EZMUXM.mjs +1 -0
  44. package/dist/chunk-TTRUPDAB.mjs +1 -0
  45. package/dist/chunk-TYHI7RAD.mjs +1 -0
  46. package/dist/chunk-UIEJWORW.mjs +1 -0
  47. package/dist/chunk-VAOUFAUH.mjs +1 -0
  48. package/dist/chunk-VBOTMRXV.mjs +1 -0
  49. package/dist/chunk-VCER63GQ.mjs +1 -0
  50. package/dist/chunk-WAUF2UC7.mjs +2 -0
  51. package/dist/chunk-WRWRCBLK.mjs +1 -0
  52. package/dist/chunk-X4XDO3LZ.mjs +1 -0
  53. package/dist/chunk-XQBCCJBO.mjs +9 -0
  54. package/dist/chunk-XWUOLYRQ.mjs +2 -0
  55. package/dist/chunk-XYH6XWP3.mjs +10 -0
  56. package/dist/chunk-YBIM6UJV.mjs +8 -0
  57. package/dist/chunk-YCIH2Q3E.mjs +1 -0
  58. package/dist/chunk-YUOKI2HB.mjs +1 -0
  59. package/dist/chunk-ZOV5KL7C.mjs +1 -0
  60. package/dist/colorResolver-n0o7H7ep.d.mts +290 -0
  61. package/dist/content-sSHuWw49.d.mts +2202 -0
  62. package/dist/core-plugins.d.mts +37 -0
  63. package/dist/core-plugins.mjs +1 -0
  64. package/dist/core.d.mts +451 -0
  65. package/dist/core.mjs +1 -0
  66. package/dist/displayListQueries-p-ijSzdh.d.mts +222 -0
  67. package/dist/docx/index.d.mts +618 -0
  68. package/dist/docx/index.mjs +2 -0
  69. package/dist/docx/parser.d.mts +41 -0
  70. package/dist/docx/parser.mjs +1 -0
  71. package/dist/docx/rezip.d.mts +148 -0
  72. package/dist/docx/rezip.mjs +1 -0
  73. package/dist/docx/serializer/index.d.mts +42 -0
  74. package/dist/docx/serializer/index.mjs +1 -0
  75. package/dist/docx/wrapTypes.d.mts +19 -0
  76. package/dist/docx/wrapTypes.mjs +1 -0
  77. package/dist/docxInput-DTbCa48g.d.mts +21 -0
  78. package/dist/editor/index.d.mts +170 -0
  79. package/dist/editor/index.mjs +1 -0
  80. package/dist/editorTree-DO5PyDK8.d.mts +37 -0
  81. package/dist/executor-7O2RBJ2B.mjs +1 -0
  82. package/dist/fontLoader-Bx6DK6-2.d.mts +327 -0
  83. package/dist/formatting-DoL7KBSL.d.mts +823 -0
  84. package/dist/generated/edit/docx_edit_bg.wasm +0 -0
  85. package/dist/generated/layout/docx_layout_bg.wasm +0 -0
  86. package/dist/generated/opc/ooxml_opc_bg.wasm +0 -0
  87. package/dist/generated/parse/docx_parse_bg.wasm +0 -0
  88. package/dist/headerFooterLayout-0zPT64Qc.d.mts +316 -0
  89. package/dist/headless.d.mts +69 -0
  90. package/dist/headless.mjs +1 -0
  91. package/dist/layout/flow/index.d.mts +149 -0
  92. package/dist/layout/flow/index.mjs +1 -0
  93. package/dist/layout/index.d.mts +307 -0
  94. package/dist/layout/index.mjs +1 -0
  95. package/dist/layout/measure/index.d.mts +324 -0
  96. package/dist/layout/measure/index.mjs +1 -0
  97. package/dist/layout/pagination/index.d.mts +60 -0
  98. package/dist/layout/pagination/index.mjs +1 -0
  99. package/dist/layout/pagination/types.d.mts +4 -0
  100. package/dist/layout/pagination/types.mjs +1 -0
  101. package/dist/layout/render/index.d.mts +733 -0
  102. package/dist/layout/render/index.mjs +1 -0
  103. package/dist/loadWasmAsset-CMvnVkfA.d.mts +3 -0
  104. package/dist/managers/AutoSaveManager.d.mts +81 -0
  105. package/dist/managers/AutoSaveManager.mjs +1 -0
  106. package/dist/managers/TableSelectionManager.d.mts +74 -0
  107. package/dist/managers/TableSelectionManager.mjs +1 -0
  108. package/dist/managers/types.d.mts +113 -0
  109. package/dist/managers/types.mjs +0 -0
  110. package/dist/mcp-cli.mjs +142 -0
  111. package/dist/mcp.d.mts +162 -0
  112. package/dist/mcp.mjs +16 -0
  113. package/dist/measureBlocksPipeline-Df0Bbrwy.d.mts +109 -0
  114. package/dist/measuredBlock-DZwz8zhD.d.mts +26 -0
  115. package/dist/plugin-api/RenderedDomContext.d.mts +114 -0
  116. package/dist/plugin-api/RenderedDomContext.mjs +1 -0
  117. package/dist/plugin-api/index.d.mts +7 -0
  118. package/dist/plugin-api/index.mjs +0 -0
  119. package/dist/plugin-api/resolveItemPositions.d.mts +39 -0
  120. package/dist/plugin-api/resolveItemPositions.mjs +1 -0
  121. package/dist/plugin-api/types.d.mts +193 -0
  122. package/dist/plugin-api/types.mjs +0 -0
  123. package/dist/processTemplate-HDUIZFJ5.mjs +1 -0
  124. package/dist/registry-DMM5VTdT.d.mts +165 -0
  125. package/dist/rustDisplayList-dqunvwxH.d.mts +1036 -0
  126. package/dist/rustPagination-Bj2hq013.d.mts +106 -0
  127. package/dist/sectionConfigs-DW3J8q0X.d.mts +55 -0
  128. package/dist/selectionContext-Buc9BCU1.d.mts +570 -0
  129. package/dist/selectiveSave-oFBJ1n71.d.mts +16 -0
  130. package/dist/selectiveXmlPatch-ypkxlTD_.d.mts +23 -0
  131. package/dist/settingsParser-CcGvtmCK.d.mts +33 -0
  132. package/dist/styles/index.d.mts +162 -0
  133. package/dist/styles/index.mjs +1 -0
  134. package/dist/styles-VxNcXLdi.d.mts +189 -0
  135. package/dist/types/agentApi.d.mts +456 -0
  136. package/dist/types/agentApi.mjs +1 -0
  137. package/dist/types/content.d.mts +3 -0
  138. package/dist/types/content.mjs +1 -0
  139. package/dist/types/document.d.mts +117 -0
  140. package/dist/types/document.mjs +1 -0
  141. package/dist/types-DNrYr6yQ.d.mts +1754 -0
  142. package/dist/types-dYdjUZMo.d.mts +311 -0
  143. package/dist/units-O5Y02RKQ.d.mts +34 -0
  144. package/dist/utils/autoScroll.d.mts +24 -0
  145. package/dist/utils/autoScroll.mjs +1 -0
  146. package/dist/utils/cardStyles.d.mts +22 -0
  147. package/dist/utils/cardStyles.mjs +1 -0
  148. package/dist/utils/comments.d.mts +120 -0
  149. package/dist/utils/comments.mjs +4 -0
  150. package/dist/utils/findReplace.d.mts +114 -0
  151. package/dist/utils/findReplace.mjs +2 -0
  152. package/dist/utils/findVerticalScrollParent.d.mts +25 -0
  153. package/dist/utils/findVerticalScrollParent.mjs +1 -0
  154. package/dist/utils/fontOptions.d.mts +21 -0
  155. package/dist/utils/fontOptions.mjs +1 -0
  156. package/dist/utils/headingCollector.d.mts +28 -0
  157. package/dist/utils/headingCollector.mjs +1 -0
  158. package/dist/utils/highlightColors.d.mts +14 -0
  159. package/dist/utils/highlightColors.mjs +1 -0
  160. package/dist/utils/index.d.mts +956 -0
  161. package/dist/utils/index.mjs +84 -0
  162. package/dist/utils/listState.d.mts +27 -0
  163. package/dist/utils/listState.mjs +1 -0
  164. package/dist/utils/reportIssue.d.mts +23 -0
  165. package/dist/utils/reportIssue.mjs +2 -0
  166. package/dist/utils/sidebarConstants.d.mts +10 -0
  167. package/dist/utils/sidebarConstants.mjs +1 -0
  168. package/dist/utils/stylePreview.d.mts +70 -0
  169. package/dist/utils/stylePreview.mjs +1 -0
  170. package/dist/utils/textSelection.d.mts +92 -0
  171. package/dist/utils/textSelection.mjs +1 -0
  172. package/dist/utils/units.d.mts +78 -0
  173. package/dist/utils/units.mjs +1 -0
  174. package/dist/variableDetector-Borj29SF.d.mts +115 -0
  175. package/dist/wasm-FZQ5XB2Y.mjs +1 -0
  176. package/dist/wasm-SA237OSP.mjs +1 -0
  177. package/dist/wasm-edit.d.mts +473 -0
  178. package/dist/wasm-edit.mjs +1 -0
  179. package/dist/wasm-layout.d.mts +112 -0
  180. package/dist/wasm-layout.mjs +1 -0
  181. package/dist/wasm-opc.d.mts +16 -0
  182. package/dist/wasm-opc.mjs +1 -0
  183. package/dist/wasm-parse.d.mts +18 -0
  184. package/dist/wasm-parse.mjs +1 -0
  185. package/dist/watermarkApi-DCxjutkg.d.mts +38 -0
  186. package/dist/yrs/index.d.mts +882 -0
  187. package/dist/yrs/index.mjs +1 -0
  188. package/dist/yrs/residentEngineWorker.d.mts +2 -0
  189. package/dist/yrs/residentEngineWorker.mjs +1 -0
  190. package/package.json +365 -0
@@ -0,0 +1,109 @@
1
+ import { W as WrapTextDirection, i as PageGeometry, e as LayoutBlock, B as BlockExtent } from './types-DNrYr6yQ.mjs';
2
+
3
+ /**
4
+ * Clamp floating-wrap margins so at least a usable strip of the line
5
+ * remains. Unchecked margins from near-full-width tables/images can exceed
6
+ * contentWidth and collapse every line to ~1 glyph (the "single character
7
+ * per line after a wide floating table" bug).
8
+ *
9
+ * Returned margins are zeroed when:
10
+ * - either side alone is >= contentWidth (no strip on that side at all), or
11
+ * - their sum is >= contentWidth (no strip exists between the two sides).
12
+ */
13
+ declare function clampFloatingWrapMargins(leftMargin: number, rightMargin: number, contentWidth: number): {
14
+ leftMargin: number;
15
+ rightMargin: number;
16
+ };
17
+ interface FloatingExclusionRect {
18
+ /** which margin absorbs the exclusion when wrapText alone doesn't pick a side. */
19
+ side: 'left' | 'right';
20
+ /** object's left edge in content-area px. */
21
+ x: number;
22
+ /** object's top edge in content-area px. */
23
+ y: number;
24
+ width: number;
25
+ height: number;
26
+ distTop: number;
27
+ distBottom: number;
28
+ distLeft: number;
29
+ distRight: number;
30
+ wrapText?: WrapTextDirection;
31
+ wrapType?: string;
32
+ }
33
+ interface FloatingImageZone {
34
+ leftMargin: number;
35
+ rightMargin: number;
36
+ topY: number;
37
+ bottomY: number;
38
+ segments?: FloatingLineSegmentZone[];
39
+ /**
40
+ * Full-width vertical band (OOXML `topAndBottom` wrap): no text fits beside
41
+ * it, so any line overlapping `[topY, bottomY]` is pushed below the band.
42
+ */
43
+ fullWidthBlock?: boolean;
44
+ }
45
+ interface FloatingLineSegmentZone {
46
+ leftOffset: number;
47
+ availableWidth: number;
48
+ }
49
+ interface FloatingLineMargins {
50
+ leftMargin: number;
51
+ rightMargin: number;
52
+ segments?: FloatingLineSegmentZone[];
53
+ }
54
+ declare function rectsToFloatingZones(rects: FloatingExclusionRect[], contentWidth: number): FloatingImageZone[];
55
+ declare function getFloatingMargins(lineY: number, lineHeight: number, zones: FloatingImageZone[] | undefined, paragraphYOffset: number): FloatingLineMargins;
56
+
57
+ /**
58
+ * Floating-aware block measurement pipeline.
59
+ *
60
+ * Pre-scans a block list to extract exclusion zones from anchored images,
61
+ * floating tables, and floating text boxes; groups co-located floats so
62
+ * their combined exclusion applies starting from the earliest anchor; then
63
+ * walks the blocks calling the caller-supplied `measureBlock` with the
64
+ * active zones and cumulative Y at each step.
65
+ *
66
+ * Adapters (React, Vue) provide their own `measureBlock` so they can
67
+ * decide e.g. whether to cache paragraph measures. The orchestration,
68
+ * extraction, and grouping live here so both adapters stay in lockstep.
69
+ *
70
+ * @packageDocumentation
71
+ * @public
72
+ */
73
+
74
+ /**
75
+ * Block-measurement callback shape passed to {@link measureBlocksWithFloats}.
76
+ * Adapters (React, Vue) supply this so they can decide platform-specific
77
+ * concerns (e.g. paragraph-measure caching, per-section width) while
78
+ * sharing the floating-zone orchestration. This is adapter-author API,
79
+ * not end-consumer API.
80
+ *
81
+ * @public
82
+ */
83
+ type MeasureBlockFn = (block: LayoutBlock, contentWidth: number, floatingZones?: FloatingImageZone[], cumulativeY?: number) => BlockExtent;
84
+ /**
85
+ * Page geometry (CSS px) used to resolve page/margin-relative anchored objects
86
+ * into content-area coordinates — currently the vertical anchor of a top-pinned
87
+ * `topAndBottom` band. Same shape the painter uses (see `pageGeometryFromPage`),
88
+ * so both paths resolve to identical positions.
89
+ *
90
+ * @public
91
+ */
92
+ type FloatPageGeometry = PageGeometry;
93
+ /**
94
+ * Walk `blocks` and produce one `BlockExtent` per block. Before measuring, this
95
+ * extracts floating exclusion zones (images / floating tables / floating
96
+ * textboxes), groups overlapping co-located floats, and threads the active
97
+ * zones plus cumulative Y into each `measureBlock` call.
98
+ *
99
+ * Pass `pageGeometry` whenever the document may contain page/margin-anchored
100
+ * `topAndBottom` text boxes (e.g. a title banner pinned to the page top):
101
+ * without it their reserved band falls back to flow-relative Y and the band
102
+ * won't line up with where the painter places the box. Build it with the
103
+ * shared `pageGeometryFromPage` helper.
104
+ *
105
+ * @public
106
+ */
107
+ declare function measureBlocksWithFloats(blocks: LayoutBlock[], contentWidth: number | number[], measureBlock: MeasureBlockFn, pageGeometry?: FloatPageGeometry): BlockExtent[];
108
+
109
+ export { type FloatPageGeometry as F, type MeasureBlockFn as M, type FloatingExclusionRect as a, type FloatingImageZone as b, type FloatingLineSegmentZone as c, clampFloatingWrapMargins as d, getFloatingMargins as g, measureBlocksWithFloats as m, rectsToFloatingZones as r };
@@ -0,0 +1,26 @@
1
+ import { e as LayoutBlock, B as BlockExtent } from './types-DNrYr6yQ.mjs';
2
+
3
+ /**
4
+ * The colocated block+measure unit consumed by the paginator.
5
+ */
6
+
7
+ /**
8
+ * A flow block paired with its measurement. The paginator consumes
9
+ * `MeasuredBlock[]` instead of two parallel `LayoutBlock[]` + `BlockExtent[]`
10
+ * arrays kept in lockstep by index — colocating the pair makes a misaligned
11
+ * block/measure unrepresentable.
12
+ * @public
13
+ */
14
+ type MeasuredBlock = {
15
+ block: LayoutBlock;
16
+ measure: BlockExtent;
17
+ };
18
+ /**
19
+ * Zip aligned `blocks` and `measures` into `MeasuredBlock[]`. This is the one
20
+ * place a length assumption is localized — the pervasive per-index coupling it
21
+ * replaces is what the measured-block model removes.
22
+ * @public
23
+ */
24
+ declare function toMeasuredBlocks(blocks: LayoutBlock[], measures: BlockExtent[]): MeasuredBlock[];
25
+
26
+ export { type MeasuredBlock as M, toMeasuredBlocks as t };
@@ -0,0 +1,114 @@
1
+ import { RenderedDomContext, PositionCoordinates } from './types.mjs';
2
+ import { D as DisplayListRect, a as DisplayListQueries } from '../displayListQueries-p-ijSzdh.mjs';
3
+ import '../types/document.mjs';
4
+ import '../content-sSHuWw49.mjs';
5
+ import '../formatting-DoL7KBSL.mjs';
6
+ import '../docx/wrapTypes.mjs';
7
+ import '../styles-VxNcXLdi.mjs';
8
+ import '../settingsParser-CcGvtmCK.mjs';
9
+ import '../rustDisplayList-dqunvwxH.mjs';
10
+ import '../types-DNrYr6yQ.mjs';
11
+ import '../measuredBlock-DZwz8zhD.mjs';
12
+
13
+ /**
14
+ * RenderedDomContext Implementation
15
+ *
16
+ * Provides position mapping over the canvas renderer's output. Geometry is
17
+ * served by the Rust display-list queries when available; DOM fallbacks read
18
+ * the accessibility mirror's data-doc-start/data-doc-end span contract.
19
+ * @packageDocumentation
20
+ * @public
21
+ */
22
+
23
+ /**
24
+ * Options controlling how a {@link RenderedDomContextImpl} resolves geometry.
25
+ *
26
+ * @public
27
+ */
28
+ interface RenderedDomContextOptions {
29
+ /** Immutable display-list query source. Omit for the mirror-DOM backend. */
30
+ displayListQueries?: DisplayListQueries;
31
+ /** Page-local display-list geometry → pages-container coordinates. */
32
+ projector?: DisplayListPageProjector;
33
+ }
34
+ interface ProjectedDisplayListRect {
35
+ x: number;
36
+ y: number;
37
+ width: number;
38
+ height: number;
39
+ }
40
+ /** Canvas-host projection contract kept separate from document geometry. */
41
+ interface DisplayListPageProjector {
42
+ projectRect(rect: DisplayListRect): ProjectedDisplayListRect | null;
43
+ getPageBounds(pageIndex: number): ProjectedDisplayListRect | null;
44
+ }
45
+ /**
46
+ * Project through the live canvas for each page. Reading its client rect is a
47
+ * host-coordinate transform only; document geometry stays display-list-owned.
48
+ */
49
+ declare function createCanvasHostProjector(pagesContainer: HTMLElement, queries: DisplayListQueries, zoom?: number): DisplayListPageProjector;
50
+ /**
51
+ * Implementation of RenderedDomContext.
52
+ *
53
+ * This class provides position mapping between display-list document
54
+ * positions and pixel coordinates in the rendered output. Geometry comes
55
+ * from the Rust display-list queries; the DOM fallbacks use the
56
+ * data-doc-start and data-doc-end attributes the accessibility mirror
57
+ * emits (see {@link RenderedDomContextOptions}).
58
+ */
59
+ declare class RenderedDomContextImpl implements RenderedDomContext {
60
+ pagesContainer: HTMLElement;
61
+ zoom: number;
62
+ private readonly queries;
63
+ private readonly projector;
64
+ constructor(pagesContainer: HTMLElement, zoom?: number, options?: RenderedDomContextOptions);
65
+ /**
66
+ * Run spans (`data-doc-start`/`data-doc-end`) in reading order, deep-queried
67
+ * from the a11y mirror subtree nested under `.canvas-pages`.
68
+ */
69
+ private spanEntries;
70
+ /** Empty-paragraph runs, deep-queried from the a11y mirror. */
71
+ private emptyRuns;
72
+ /**
73
+ * Get pixel coordinates for a display position.
74
+ * Uses the browser's text rendering via Range API for precise positioning.
75
+ */
76
+ getCoordinatesForPosition(position: number): PositionCoordinates | null;
77
+ /**
78
+ * Find DOM elements that overlap with a display-position range.
79
+ */
80
+ findElementsForRange(from: number, to: number): Element[];
81
+ /**
82
+ * Get bounding rectangles for a range of text.
83
+ * Handles line wraps by returning multiple rects.
84
+ */
85
+ getRectsForRange(from: number, to: number): Array<{
86
+ x: number;
87
+ y: number;
88
+ width: number;
89
+ height: number;
90
+ }>;
91
+ getCoordinatesForHfPosition(region: 'header' | 'footer', rId: string, position: number, pageIndex: number): PositionCoordinates | null;
92
+ getRectsForHfRange(region: 'header' | 'footer', rId: string, from: number, to: number, pageIndex: number): ProjectedDisplayListRect[];
93
+ getPageBounds(pageIndex: number): ProjectedDisplayListRect | null;
94
+ /**
95
+ * Get the offset of the pages container from its parent viewport.
96
+ * This is needed for positioning overlays that are rendered in the
97
+ * viewport container rather than directly in the pages container.
98
+ */
99
+ getContainerOffset(): {
100
+ x: number;
101
+ y: number;
102
+ };
103
+ }
104
+ /**
105
+ * Create a RenderedDomContext for a pages container element.
106
+ *
107
+ * @param pagesContainer - The `.canvas-pages` host holding the rendered pages
108
+ * @param zoom - Current zoom level (default 1)
109
+ * @param options - query/projector backend options. Omit for the mirror-DOM
110
+ * fallback.
111
+ */
112
+ declare function createRenderedDomContext(pagesContainer: HTMLElement, zoom?: number, options?: RenderedDomContextOptions): RenderedDomContext;
113
+
114
+ export { type DisplayListPageProjector, type ProjectedDisplayListRect, RenderedDomContextImpl, type RenderedDomContextOptions, createCanvasHostProjector, createRenderedDomContext };
@@ -0,0 +1 @@
1
+ import {a}from'../chunk-WRWRCBLK.mjs';import {b}from'../chunk-TTRUPDAB.mjs';function E(h,n,s=1){let t=s>0?s:1,o=e=>{let r=n.pageSize(e.pageIndex),i=a(h,n,e.pageIndex);if(!i||!r||r.width<=0||r.height<=0)return null;let a$1=h.getBoundingClientRect(),c=i.width/r.width,u=i.height/r.height;return {x:(i.left-a$1.left+e.x*c)/t,y:(i.top-a$1.top+e.y*u)/t,width:e.width*c/t,height:e.height*u/t}};return {projectRect:o,getPageBounds:e=>{let r=n.pageBounds(e);return r?o(r):null}}}var f=class{constructor(n,s=1,t){b(this,"pagesContainer");b(this,"zoom");b(this,"queries");b(this,"projector");if(this.pagesContainer=n,this.zoom=s,this.queries=t?.displayListQueries??null,this.projector=t?.projector??null,this.queries===null!=(this.projector===null))throw new Error("RenderedDomContext requires displayListQueries and projector together")}spanEntries(){let n=[],s=Array.from(this.pagesContainer.querySelectorAll(".layout-page-content")),t=s.length>0?s:[this.pagesContainer];for(let o of t)for(let e of Array.from(o.querySelectorAll("span[data-doc-start][data-doc-end]")))n.push({el:e,start:Number(e.dataset.docStart),end:Number(e.dataset.docEnd)});return n}emptyRuns(){return Array.from(this.pagesContainer.querySelectorAll(".layout-empty-run"))}getCoordinatesForPosition(n){if(this.queries&&this.projector){let t=this.queries.caretRect(n),o=t?this.projector.projectRect(t):null;return o?{x:o.x,y:o.y,height:o.height}:null}let s=this.pagesContainer.getBoundingClientRect();for(let{el:t,start:o,end:e}of this.spanEntries()){let r=t;if(t.classList.contains("layout-run-tab")){if(n>=o&&n<e){let i=t.getBoundingClientRect(),a=t.closest(".layout-line"),c=a?a.offsetHeight:16;return {x:(i.left-s.left)/this.zoom,y:(i.top-s.top)/this.zoom,height:c/this.zoom}}continue}if(n>=o&&n<=e&&r.firstChild?.nodeType===Node.TEXT_NODE){let i=r.firstChild,a=Math.min(n-o,i.length),c=t.ownerDocument;if(!c)continue;let u=c.createRange();u.setStart(i,a),u.setEnd(i,a);let p=u.getBoundingClientRect(),d=t.closest(".layout-line"),l=d?d.offsetHeight:16;return {x:(p.left-s.left)/this.zoom,y:(p.top-s.top)/this.zoom,height:l/this.zoom}}}for(let t of this.emptyRuns()){let o=t.closest(".layout-paragraph");if(!o)continue;let e=Number(o.dataset.docStart),r=Number(o.dataset.docEnd);if(n>=e&&n<=r){let i=t.getBoundingClientRect(),a=t.closest(".layout-line"),c=a?a.offsetHeight:16;return {x:(i.left-s.left)/this.zoom,y:(i.top-s.top)/this.zoom,height:c/this.zoom}}}return null}findElementsForRange(n,s){let t=[];for(let{el:o,start:e,end:r}of this.spanEntries())r>n&&e<s&&t.push(o);return t}getRectsForRange(n,s){if(this.queries&&this.projector)return this.queries.rangeRects(n,s).map(e=>this.projector.projectRect(e)).filter(e=>e!==null);let t=this.pagesContainer.getBoundingClientRect(),o=[];for(let{el:e,start:r,end:i}of this.spanEntries()){let a=e;if(i>n&&r<s){if(e.classList.contains("layout-run-tab")){let l=e.getBoundingClientRect();o.push({x:(l.left-t.left)/this.zoom,y:(l.top-t.top)/this.zoom,width:l.width/this.zoom,height:l.height/this.zoom});continue}if(a.firstChild?.nodeType!==Node.TEXT_NODE)continue;let c=a.firstChild,u=e.ownerDocument;if(!u)continue;let p=Math.max(0,n-r),d=Math.min(c.length,s-r);if(p<d){let l=u.createRange();l.setStart(c,p),l.setEnd(c,d);let R=l.getClientRects();for(let m of Array.from(R))o.push({x:(m.left-t.left)/this.zoom,y:(m.top-t.top)/this.zoom,width:m.width/this.zoom,height:m.height/this.zoom});}}}return o}getCoordinatesForHfPosition(n,s,t,o){if(!this.queries||!this.projector)return null;let e=this.queries.hfCaretRects(n,s,t).find(i=>i.pageIndex===o),r=e?this.projector.projectRect(e):null;return r?{x:r.x,y:r.y,height:r.height}:null}getRectsForHfRange(n,s,t,o,e){return !this.queries||!this.projector?[]:this.queries.hfRangeRects(n,s,t,o).filter(r=>r.pageIndex===e).map(r=>this.projector.projectRect(r)).filter(r=>r!==null)}getPageBounds(n){if(this.projector)return this.projector.getPageBounds(n);let s=this.pagesContainer.querySelectorAll(".layout-page"),t=Array.from(s).find((r,i)=>Number(r.dataset.pageIndex??i)===n);if(!t)return null;let o=t.getBoundingClientRect(),e=this.pagesContainer.getBoundingClientRect();return {x:(o.left-e.left)/this.zoom,y:(o.top-e.top)/this.zoom,width:o.width/this.zoom,height:o.height/this.zoom}}getContainerOffset(){let n=this.pagesContainer.parentElement;if(!n)return {x:0,y:0};let s=this.pagesContainer.getBoundingClientRect(),t=n.getBoundingClientRect();return {x:(s.left-t.left)/this.zoom,y:(s.top-t.top)/this.zoom}}};function L(h,n=1,s){return new f(h,n,s)}export{f as RenderedDomContextImpl,E as createCanvasHostProjector,L as createRenderedDomContext};
@@ -0,0 +1,7 @@
1
+ export { EditorPluginCore, PanelConfig, PluginPanelProps, PositionCoordinates, RenderedDomContext, SidebarItem, SidebarItemContext } from './types.mjs';
2
+ import '../types/document.mjs';
3
+ import '../content-sSHuWw49.mjs';
4
+ import '../formatting-DoL7KBSL.mjs';
5
+ import '../docx/wrapTypes.mjs';
6
+ import '../styles-VxNcXLdi.mjs';
7
+ import '../settingsParser-CcGvtmCK.mjs';
File without changes
@@ -0,0 +1,39 @@
1
+ import { SidebarItem, RenderedDomContext } from './types.mjs';
2
+ import '../types/document.mjs';
3
+ import '../content-sSHuWw49.mjs';
4
+ import '../formatting-DoL7KBSL.mjs';
5
+ import '../docx/wrapTypes.mjs';
6
+ import '../styles-VxNcXLdi.mjs';
7
+ import '../settingsParser-CcGvtmCK.mjs';
8
+
9
+ /**
10
+ * Pure layout algorithm: given a list of sidebar items + their
11
+ * anchor sources, return a list of resolved Y positions with
12
+ * collision avoidance applied. Lifted from React's
13
+ * components/sidebar/resolveItemPositions.ts so the Vue adapter
14
+ * can call it directly.
15
+ *
16
+ * The algorithm walks the items in three priority stages:
17
+ * 1. explicit fixedY (already in scroll-container coords)
18
+ * 2. anchorKey lookup in anchorPositions (layout/pagination coords)
19
+ * 3. DOM-based anchor lookup via renderedDomContext.getRectsForRange
20
+ * 4. last-known cache so cards don't pop out during transient layout
21
+ *
22
+ * Then it sorts by target Y and pushes overlapping cards down by
23
+ * their height + MIN_CARD_GAP.
24
+ * @packageDocumentation
25
+ * @public
26
+ */
27
+
28
+ /** Generic sidebar item with optional fixedY / estimatedHeight. */
29
+ interface ResolvableSidebarItem extends SidebarItem {
30
+ fixedY?: number;
31
+ estimatedHeight?: number;
32
+ }
33
+ interface ResolvedPosition<T extends ResolvableSidebarItem = ResolvableSidebarItem> {
34
+ item: T;
35
+ y: number;
36
+ }
37
+ declare function resolveItemPositions<T extends ResolvableSidebarItem>(items: T[], anchorPositions: Map<string, number>, renderedDomContext: RenderedDomContext | null, zoom: number, cardHeights: Map<string, number>, lastKnown: Map<string, number>): ResolvedPosition<T>[];
38
+
39
+ export { type ResolvableSidebarItem, type ResolvedPosition, resolveItemPositions };
@@ -0,0 +1 @@
1
+ import'../chunk-YUOKI2HB.mjs';import'../chunk-TTRUPDAB.mjs';function p(s,u,n,r,d,l){if(s.length===0)return [];let a=n?.getContainerOffset(),o=[];for(let e of s){let t;if(e.fixedY!=null&&(t=e.fixedY*r),t==null&&e.anchorKey){let i=u.get(e.anchorKey);i!=null&&(t=i*r);}if(t==null&&n){let i=n.getRectsForRange(e.anchorPos,e.anchorPos+1);i.length>0&&a&&(t=(i[0].y+a.y)*r);}if(t==null){let i=l.get(e.id);i!=null&&(t=i);}t!=null&&(o.push({item:e,targetY:t}),l.set(e.id,t));}o.sort((e,t)=>{let i=e.targetY-t.targetY;return i!==0?i:(e.item.priority??0)-(t.item.priority??0)});let m=[],f=0;for(let e of o){let t=d.get(e.item.id)??e.item.estimatedHeight??80,i=Math.max(e.targetY,f+8);m.push({item:e.item,y:i}),f=i+t;}return m}export{p as resolveItemPositions};
@@ -0,0 +1,193 @@
1
+ import { Document } from '../types/document.mjs';
2
+ import '../content-sSHuWw49.mjs';
3
+ import '../formatting-DoL7KBSL.mjs';
4
+ import '../docx/wrapTypes.mjs';
5
+ import '../styles-VxNcXLdi.mjs';
6
+ import '../settingsParser-CcGvtmCK.mjs';
7
+
8
+ /**
9
+ * Framework-Agnostic Plugin Interface for the DOCX Editor
10
+ *
11
+ * Core plugin types that can be used by any framework (React, Vue, etc.).
12
+ * Framework-specific adapters extend EditorPluginCore with their own
13
+ * UI rendering capabilities (e.g., ReactEditorPlugin, VueEditorPlugin).
14
+ * @packageDocumentation
15
+ * @public
16
+ */
17
+
18
+ /**
19
+ * Coordinates returned by position lookup in the rendered DOM.
20
+ */
21
+ interface PositionCoordinates {
22
+ x: number;
23
+ y: number;
24
+ height: number;
25
+ }
26
+ /**
27
+ * Context for accessing rendered-page geometry in the paged editor.
28
+ *
29
+ * Provides position mapping over the canvas renderer's output (Rust
30
+ * display-list queries, with the accessibility mirror's DOM as fallback).
31
+ * Use this for rendering overlays, annotations, and other visual elements
32
+ * positioned relative to rendered content.
33
+ *
34
+ * The mirror DOM uses data-doc-start/data-doc-end attributes on spans
35
+ * to map between display positions and DOM elements.
36
+ */
37
+ interface RenderedDomContext {
38
+ /** The container element holding all rendered pages. */
39
+ pagesContainer: HTMLElement;
40
+ /**
41
+ * Get pixel coordinates for a display position in the rendered DOM.
42
+ * Returns null if the position cannot be found.
43
+ */
44
+ getCoordinatesForPosition(position: number): PositionCoordinates | null;
45
+ /**
46
+ * Find DOM elements that overlap with a display-position range.
47
+ */
48
+ findElementsForRange(from: number, to: number): Element[];
49
+ /**
50
+ * Get bounding rectangles for a range of text, accounting for line wraps.
51
+ * Returns rects relative to the pages container.
52
+ */
53
+ getRectsForRange(from: number, to: number): Array<{
54
+ x: number;
55
+ y: number;
56
+ width: number;
57
+ height: number;
58
+ }>;
59
+ /** Query-backed caret coordinates for one explicit header/footer page. */
60
+ getCoordinatesForHfPosition(region: 'header' | 'footer', rId: string, position: number, pageIndex: number): PositionCoordinates | null;
61
+ /** Query-backed range rectangles for one explicit header/footer page. */
62
+ getRectsForHfRange(region: 'header' | 'footer', rId: string, from: number, to: number, pageIndex: number): Array<{
63
+ x: number;
64
+ y: number;
65
+ width: number;
66
+ height: number;
67
+ }>;
68
+ /** Bounds of one rendered page relative to the pages container. */
69
+ getPageBounds(pageIndex: number): {
70
+ x: number;
71
+ y: number;
72
+ width: number;
73
+ height: number;
74
+ } | null;
75
+ /** Current zoom level (1 = 100%). */
76
+ zoom: number;
77
+ /**
78
+ * Offset of the pages container from its parent viewport.
79
+ */
80
+ getContainerOffset(): {
81
+ x: number;
82
+ y: number;
83
+ };
84
+ }
85
+ /**
86
+ * Props passed to plugin panel components (framework-agnostic base).
87
+ */
88
+ interface PluginPanelProps<TState = unknown> {
89
+ /** Current serializer-facing document snapshot. */
90
+ document: Document | null;
91
+ /** Scroll editor to a specific position */
92
+ scrollToPosition: (pos: number) => void;
93
+ /** Select a range in the editor */
94
+ selectRange: (from: number, to: number) => void;
95
+ /** Plugin-specific state (managed by the plugin) */
96
+ pluginState: TState;
97
+ /** Width of the panel in pixels */
98
+ panelWidth: number;
99
+ /**
100
+ * Context for the rendered pages (canvas renderer output).
101
+ * May be null if layout hasn't completed yet.
102
+ */
103
+ renderedDomContext: RenderedDomContext | null;
104
+ }
105
+ /**
106
+ * Configuration for plugin panel rendering.
107
+ */
108
+ interface PanelConfig {
109
+ /** Where to render the panel */
110
+ position: 'left' | 'right' | 'bottom';
111
+ /** Default width/height of the panel */
112
+ defaultSize: number;
113
+ /** Minimum size */
114
+ minSize?: number;
115
+ /** Maximum size */
116
+ maxSize?: number;
117
+ /** Whether the panel is resizable */
118
+ resizable?: boolean;
119
+ /** Whether the panel can be collapsed */
120
+ collapsible?: boolean;
121
+ /** Initial collapsed state */
122
+ defaultCollapsed?: boolean;
123
+ }
124
+ /**
125
+ * Framework-agnostic core plugin interface.
126
+ *
127
+ * Contains all non-UI plugin capabilities:
128
+ * - State management (initialize, onStateChange, destroy)
129
+ * - CSS injection
130
+ * - Panel configuration
131
+ *
132
+ * Framework adapters (ReactEditorPlugin, VueEditorPlugin) extend this
133
+ * with their own Panel component type and renderOverlay function.
134
+ */
135
+ interface EditorPluginCore<TState = any> {
136
+ /** Unique plugin identifier */
137
+ id: string;
138
+ /** Display name for the plugin */
139
+ name: string;
140
+ /**
141
+ * Configuration for the panel (position, size, etc.)
142
+ */
143
+ panelConfig?: PanelConfig;
144
+ /**
145
+ * Called when the projected document changes.
146
+ * Use this to update plugin-specific state based on document changes.
147
+ */
148
+ onStateChange?: (document: Document) => TState | undefined;
149
+ /**
150
+ * Initialize plugin state when the plugin is first loaded.
151
+ */
152
+ initialize?: (document: Document | null) => TState;
153
+ /**
154
+ * Called when the plugin is being destroyed.
155
+ * Use this for cleanup (subscriptions, timers, etc.)
156
+ */
157
+ destroy?: () => void;
158
+ /**
159
+ * CSS styles to inject for this plugin.
160
+ * Can be a string of CSS or a URL to a stylesheet.
161
+ */
162
+ styles?: string;
163
+ }
164
+ /**
165
+ * A sidebar item anchored to a document position.
166
+ * Framework adapters extend this with rendering capabilities.
167
+ */
168
+ interface SidebarItem {
169
+ /** Unique ID for this item (used as React key and for overlap resolution). */
170
+ id: string;
171
+ /** Display position this item anchors to. */
172
+ anchorPos: number;
173
+ /** Optional key into the anchorPositions Map (e.g. "comment-42", "revision-7"). */
174
+ anchorKey?: string;
175
+ /** Sort priority within items at the same anchor Y. Lower = first. Default: 0. */
176
+ priority?: number;
177
+ /** Temporary items (e.g. "add comment" input) skip entrance animation. */
178
+ isTemporary?: boolean;
179
+ /** Pre-computed Y position (scroll-container coords, pre-zoom). Overrides anchor resolution. */
180
+ fixedY?: number;
181
+ }
182
+ /**
183
+ * Context provided to plugins when computing sidebar items.
184
+ */
185
+ interface SidebarItemContext {
186
+ document: Document | null;
187
+ renderedDomContext: RenderedDomContext | null;
188
+ /** Pre-computed Y positions from layout engine (keys like "comment-{id}"). */
189
+ anchorPositions: Map<string, number>;
190
+ zoom: number;
191
+ }
192
+
193
+ export type { EditorPluginCore, PanelConfig, PluginPanelProps, PositionCoordinates, RenderedDomContext, SidebarItem, SidebarItemContext };
File without changes
@@ -0,0 +1 @@
1
+ export{j as createTemplateProcessor,k as default,g as getMissingVariables,e as getTemplateTags,h as previewTemplate,a as processTemplate,i as processTemplateAdvanced,d as processTemplateAndDownload,c as processTemplateAsBlob,b as processTemplateDetailed,f as validateTemplate}from'./chunk-O2QSE2I7.mjs';import'./chunk-TTRUPDAB.mjs';
@@ -0,0 +1,165 @@
1
+ import { b as CorePlugin, k as PluginOptions, l as PluginRegistrationResult, C as CommandHandler, f as McpToolDefinition, j as PluginEventListener } from './types-dYdjUZMo.mjs';
2
+
3
+ /**
4
+ * Plugin Registry
5
+ *
6
+ * Central registry for core plugins. Manages plugin lifecycle,
7
+ * collects command handlers from all plugins, and aggregates
8
+ * MCP tool definitions for the MCP server.
9
+ */
10
+
11
+ /**
12
+ * Plugin Registry - manages core plugins
13
+ *
14
+ * @example
15
+ * ```ts
16
+ * import { pluginRegistry, docxtemplaterPlugin } from '@betteroffice/docx/core-plugins';
17
+ *
18
+ * // Register plugins
19
+ * pluginRegistry.register(docxtemplaterPlugin);
20
+ *
21
+ * // Get all MCP tools for MCP server
22
+ * const tools = pluginRegistry.getMcpTools();
23
+ *
24
+ * // Get command handler for executor
25
+ * const handler = pluginRegistry.getCommandHandler('insertTemplateVariable');
26
+ * ```
27
+ */
28
+ declare class PluginRegistry {
29
+ private plugins;
30
+ private commandHandlers;
31
+ private eventListeners;
32
+ private initialized;
33
+ /**
34
+ * Register a plugin
35
+ *
36
+ * @param plugin - The plugin to register
37
+ * @param options - Optional configuration
38
+ * @returns Registration result
39
+ */
40
+ register(plugin: CorePlugin, options?: PluginOptions): PluginRegistrationResult;
41
+ /**
42
+ * Unregister a plugin
43
+ *
44
+ * @param pluginId - ID of the plugin to unregister
45
+ * @returns Whether unregistration succeeded
46
+ */
47
+ unregister(pluginId: string): boolean;
48
+ /**
49
+ * Get a registered plugin by ID
50
+ *
51
+ * @param id - Plugin ID
52
+ * @returns The plugin or undefined
53
+ */
54
+ get(id: string): CorePlugin | undefined;
55
+ /**
56
+ * Get all registered plugins
57
+ *
58
+ * @returns Array of all plugins
59
+ */
60
+ getAll(): CorePlugin[];
61
+ /**
62
+ * Check if a plugin is registered
63
+ *
64
+ * @param id - Plugin ID
65
+ * @returns Whether the plugin is registered
66
+ */
67
+ has(id: string): boolean;
68
+ /**
69
+ * Get number of registered plugins
70
+ */
71
+ get size(): number;
72
+ /**
73
+ * Get a command handler for a command type
74
+ *
75
+ * @param commandType - The command type
76
+ * @returns The handler or undefined
77
+ */
78
+ getCommandHandler(commandType: string): CommandHandler | undefined;
79
+ /**
80
+ * Get all registered command types
81
+ *
82
+ * @returns Array of command type strings
83
+ */
84
+ getCommandTypes(): string[];
85
+ /**
86
+ * Check if a command type has a handler
87
+ *
88
+ * @param commandType - The command type
89
+ * @returns Whether a handler exists
90
+ */
91
+ hasCommandHandler(commandType: string): boolean;
92
+ /**
93
+ * Get all MCP tools from all registered plugins
94
+ *
95
+ * @returns Array of MCP tool definitions
96
+ */
97
+ getMcpTools(): McpToolDefinition[];
98
+ /**
99
+ * Get MCP tools from a specific plugin
100
+ *
101
+ * @param pluginId - Plugin ID
102
+ * @returns Array of MCP tool definitions
103
+ */
104
+ getMcpToolsForPlugin(pluginId: string): McpToolDefinition[];
105
+ /**
106
+ * Get an MCP tool by name
107
+ *
108
+ * @param toolName - Tool name
109
+ * @returns The tool definition or undefined
110
+ */
111
+ getMcpTool(toolName: string): McpToolDefinition | undefined;
112
+ /**
113
+ * Add an event listener
114
+ *
115
+ * @param listener - Event listener function
116
+ */
117
+ addEventListener(listener: PluginEventListener): void;
118
+ /**
119
+ * Remove an event listener
120
+ *
121
+ * @param listener - Event listener function
122
+ */
123
+ removeEventListener(listener: PluginEventListener): void;
124
+ /**
125
+ * Emit an event to all listeners
126
+ */
127
+ private emit;
128
+ /**
129
+ * Clear all registered plugins
130
+ *
131
+ * Useful for testing or resetting state.
132
+ */
133
+ clear(): void;
134
+ /**
135
+ * Get registry state for debugging
136
+ */
137
+ getDebugInfo(): {
138
+ plugins: string[];
139
+ commandTypes: string[];
140
+ mcpTools: string[];
141
+ initialized: string[];
142
+ };
143
+ }
144
+ /**
145
+ * Global plugin registry instance
146
+ *
147
+ * Use this for registering plugins and accessing their capabilities.
148
+ */
149
+ declare const pluginRegistry: PluginRegistry;
150
+ /**
151
+ * Register multiple plugins at once
152
+ *
153
+ * @param plugins - Array of plugins to register
154
+ * @returns Array of registration results
155
+ */
156
+ declare function registerPlugins(plugins: CorePlugin[], options?: PluginOptions): PluginRegistrationResult[];
157
+ /**
158
+ * Create a plugin registration helper with options pre-configured
159
+ *
160
+ * @param options - Default options for plugin registration
161
+ * @returns Registration function
162
+ */
163
+ declare function createPluginRegistrar(options: PluginOptions): (plugin: CorePlugin) => PluginRegistrationResult;
164
+
165
+ export { PluginRegistry as P, createPluginRegistrar as c, pluginRegistry as p, registerPlugins as r };