docxkeun 0.1.3 → 0.3.0

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 (199) hide show
  1. package/CHANGELOG.md +74 -0
  2. package/README.md +166 -16
  3. package/dist/api/editor.d.ts +231 -7
  4. package/dist/api/editor.js +1125 -26
  5. package/dist/api/headers.d.ts +51 -0
  6. package/dist/api/headers.js +133 -0
  7. package/dist/api/index.d.ts +6 -1
  8. package/dist/api/index.js +4 -1
  9. package/dist/api/lists.d.ts +37 -0
  10. package/dist/api/lists.js +132 -0
  11. package/dist/api/parts.js +1 -0
  12. package/dist/api/positions.js +1 -0
  13. package/dist/api/revisions.d.ts +61 -0
  14. package/dist/api/revisions.js +401 -0
  15. package/dist/api/selection.d.ts +57 -0
  16. package/dist/api/selection.js +91 -0
  17. package/dist/api/tables.d.ts +60 -0
  18. package/dist/api/tables.js +138 -0
  19. package/dist/charts/color.d.ts +45 -0
  20. package/dist/charts/color.js +322 -0
  21. package/dist/charts/format.d.ts +12 -0
  22. package/dist/charts/format.js +459 -0
  23. package/dist/charts/index.d.ts +11 -0
  24. package/dist/charts/index.js +8 -0
  25. package/dist/charts/model.d.ts +225 -0
  26. package/dist/charts/model.js +758 -0
  27. package/dist/charts/outline.d.ts +17 -0
  28. package/dist/charts/outline.js +214 -0
  29. package/dist/charts/render.d.ts +20 -0
  30. package/dist/charts/render.js +1772 -0
  31. package/dist/drawing/arrows.d.ts +37 -0
  32. package/dist/drawing/arrows.js +99 -0
  33. package/dist/drawing/formula.d.ts +40 -0
  34. package/dist/drawing/formula.js +159 -0
  35. package/dist/drawing/geometry.d.ts +61 -0
  36. package/dist/drawing/geometry.js +286 -0
  37. package/dist/drawing/index.d.ts +12 -0
  38. package/dist/drawing/index.js +8 -0
  39. package/dist/drawing/presets.d.ts +72 -0
  40. package/dist/drawing/presets.js +2874 -0
  41. package/dist/fonts/shaping/apply.d.ts +94 -0
  42. package/dist/fonts/shaping/apply.js +349 -0
  43. package/dist/fonts/shaping/arabic.d.ts +28 -0
  44. package/dist/fonts/shaping/arabic.js +235 -0
  45. package/dist/fonts/shaping/buffer.d.ts +53 -0
  46. package/dist/fonts/shaping/buffer.js +95 -0
  47. package/dist/fonts/shaping/gdef.d.ts +30 -0
  48. package/dist/fonts/shaping/gdef.js +66 -0
  49. package/dist/fonts/shaping/gpos.d.ts +86 -0
  50. package/dist/fonts/shaping/gpos.js +428 -0
  51. package/dist/fonts/shaping/gsub.d.ts +65 -0
  52. package/dist/fonts/shaping/gsub.js +313 -0
  53. package/dist/fonts/shaping/index.d.ts +32 -0
  54. package/dist/fonts/shaping/index.js +402 -0
  55. package/dist/fonts/shaping/indic.d.ts +6 -0
  56. package/dist/fonts/shaping/indic.js +805 -0
  57. package/dist/fonts/shaping/layout-common.d.ts +124 -0
  58. package/dist/fonts/shaping/layout-common.js +349 -0
  59. package/dist/fonts/shaping/plan.d.ts +87 -0
  60. package/dist/fonts/shaping/plan.js +152 -0
  61. package/dist/fonts/shaping/scripts.d.ts +26 -0
  62. package/dist/fonts/shaping/scripts.js +160 -0
  63. package/dist/fonts/shaping/shaper.d.ts +23 -0
  64. package/dist/fonts/shaping/shaper.js +5 -0
  65. package/dist/fonts/shaping/unicode.d.ts +34 -0
  66. package/dist/fonts/shaping/unicode.js +138 -0
  67. package/dist/images/bmp.d.ts +9 -0
  68. package/dist/images/bmp.js +234 -0
  69. package/dist/images/gif.d.ts +9 -0
  70. package/dist/images/gif.js +215 -0
  71. package/dist/images/index.d.ts +18 -0
  72. package/dist/images/index.js +63 -0
  73. package/dist/images/png-encode.d.ts +4 -0
  74. package/dist/images/png-encode.js +73 -0
  75. package/dist/images/size.d.ts +10 -0
  76. package/dist/images/size.js +83 -0
  77. package/dist/images/tiff.d.ts +14 -0
  78. package/dist/images/tiff.js +407 -0
  79. package/dist/index.d.ts +7 -2
  80. package/dist/index.js +5 -0
  81. package/dist/layout/bidi.d.ts +18 -0
  82. package/dist/layout/bidi.js +71 -0
  83. package/dist/layout/blocks.d.ts +20 -3
  84. package/dist/layout/blocks.js +88 -58
  85. package/dist/layout/cache.d.ts +31 -0
  86. package/dist/layout/cache.js +38 -0
  87. package/dist/layout/drawing.d.ts +30 -0
  88. package/dist/layout/drawing.js +120 -0
  89. package/dist/layout/engine.d.ts +3 -0
  90. package/dist/layout/engine.js +218 -11
  91. package/dist/layout/index.d.ts +1 -0
  92. package/dist/layout/index.js +1 -0
  93. package/dist/layout/lines.d.ts +63 -5
  94. package/dist/layout/lines.js +245 -20
  95. package/dist/layout/paint.d.ts +25 -3
  96. package/dist/layout/paint.js +26 -10
  97. package/dist/layout/shapes.d.ts +7 -0
  98. package/dist/layout/shapes.js +338 -0
  99. package/dist/layout/style.d.ts +4 -0
  100. package/dist/layout/style.js +2 -0
  101. package/dist/layout/types.d.ts +89 -2
  102. package/dist/math/boxes.d.ts +88 -0
  103. package/dist/math/boxes.js +166 -0
  104. package/dist/math/index.d.ts +29 -0
  105. package/dist/math/index.js +44 -0
  106. package/dist/math/layout.d.ts +13 -0
  107. package/dist/math/layout.js +771 -0
  108. package/dist/math/linear.d.ts +3 -0
  109. package/dist/math/linear.js +152 -0
  110. package/dist/math/omml.d.ts +15 -0
  111. package/dist/math/omml.js +57 -0
  112. package/dist/math/paths.d.ts +61 -0
  113. package/dist/math/paths.js +450 -0
  114. package/dist/math/symbols.d.ts +49 -0
  115. package/dist/math/symbols.js +269 -0
  116. package/dist/math/text.d.ts +53 -0
  117. package/dist/math/text.js +316 -0
  118. package/dist/metafile/canvas.d.ts +80 -0
  119. package/dist/metafile/canvas.js +515 -0
  120. package/dist/metafile/dib.d.ts +27 -0
  121. package/dist/metafile/dib.js +300 -0
  122. package/dist/metafile/emf.d.ts +31 -0
  123. package/dist/metafile/emf.js +591 -0
  124. package/dist/metafile/geometry.d.ts +49 -0
  125. package/dist/metafile/geometry.js +85 -0
  126. package/dist/metafile/index.d.ts +27 -0
  127. package/dist/metafile/index.js +34 -0
  128. package/dist/metafile/reader.d.ts +28 -0
  129. package/dist/metafile/reader.js +59 -0
  130. package/dist/metafile/state.d.ts +118 -0
  131. package/dist/metafile/state.js +172 -0
  132. package/dist/metafile/text.d.ts +17 -0
  133. package/dist/metafile/text.js +130 -0
  134. package/dist/metafile/wmf.d.ts +33 -0
  135. package/dist/metafile/wmf.js +395 -0
  136. package/dist/model/content.d.ts +92 -7
  137. package/dist/model/content.js +251 -17
  138. package/dist/model/document.d.ts +34 -1
  139. package/dist/model/document.js +80 -1
  140. package/dist/model/fields.d.ts +4 -0
  141. package/dist/model/fields.js +10 -0
  142. package/dist/model/numbering.d.ts +2 -0
  143. package/dist/model/numbering.js +22 -0
  144. package/dist/model/props.d.ts +2 -0
  145. package/dist/model/props.js +3 -0
  146. package/dist/opc/index.d.ts +1 -1
  147. package/dist/opc/package.d.ts +34 -0
  148. package/dist/opc/package.js +58 -4
  149. package/dist/pdf/export.js +97 -6
  150. package/dist/pdf/images.d.ts +7 -0
  151. package/dist/pdf/images.js +39 -2
  152. package/dist/render/activity.d.ts +179 -0
  153. package/dist/render/activity.js +1003 -0
  154. package/dist/render/clipboard.d.ts +29 -0
  155. package/dist/render/clipboard.js +401 -0
  156. package/dist/render/comments.d.ts +166 -0
  157. package/dist/render/comments.js +779 -0
  158. package/dist/render/context-menu.d.ts +124 -0
  159. package/dist/render/context-menu.js +525 -0
  160. package/dist/render/editing.d.ts +146 -5
  161. package/dist/render/editing.js +678 -53
  162. package/dist/render/index.d.ts +12 -0
  163. package/dist/render/index.js +11 -0
  164. package/dist/render/navigation-panel.d.ts +76 -0
  165. package/dist/render/navigation-panel.js +431 -0
  166. package/dist/render/selection.js +5 -0
  167. package/dist/render/svg.d.ts +4 -6
  168. package/dist/render/svg.js +69 -7
  169. package/dist/render/toolbar.d.ts +83 -0
  170. package/dist/render/toolbar.js +505 -0
  171. package/dist/render/ui/comment-layout.d.ts +39 -0
  172. package/dist/render/ui/comment-layout.js +79 -0
  173. package/dist/render/ui/icons.d.ts +6 -0
  174. package/dist/render/ui/icons.js +38 -0
  175. package/dist/render/ui/menu.d.ts +38 -0
  176. package/dist/render/ui/menu.js +274 -0
  177. package/dist/render/ui/nav-model.d.ts +11 -0
  178. package/dist/render/ui/nav-model.js +34 -0
  179. package/dist/render/ui/overflow.d.ts +5 -0
  180. package/dist/render/ui/overflow.js +18 -0
  181. package/dist/render/ui/popover.d.ts +18 -0
  182. package/dist/render/ui/popover.js +109 -0
  183. package/dist/render/ui/theme.d.ts +2 -0
  184. package/dist/render/ui/theme.js +29 -0
  185. package/dist/render/undo.d.ts +76 -0
  186. package/dist/render/undo.js +144 -0
  187. package/dist/render/viewer.d.ts +100 -7
  188. package/dist/render/viewer.js +304 -92
  189. package/dist/security/policy.d.ts +3 -0
  190. package/dist/security/policy.js +6 -2
  191. package/dist/security/protection.d.ts +1 -0
  192. package/dist/security/protection.js +1 -1
  193. package/dist/text/bidi-data.d.ts +53 -0
  194. package/dist/text/bidi-data.js +318 -0
  195. package/dist/text/bidi.d.ts +37 -0
  196. package/dist/text/bidi.js +508 -0
  197. package/dist/xml/ns.d.ts +5 -0
  198. package/dist/xml/ns.js +7 -0
  199. package/package.json +9 -2
@@ -6,22 +6,65 @@
6
6
  * Positions are kept as (paragraph index, character offset) so they survive re-layout and
7
7
  * the run splitting that edits cause.
8
8
  */
9
- import { type EditGuard } from '../api/editor.js';
9
+ import { DocxEditor, type EditGuard, type ParagraphFormat, type TextFormat } from '../api/editor.js';
10
+ import type { ListFormat } from '../api/lists.js';
11
+ import { type PastedParagraph } from './clipboard.js';
12
+ import { type SelectionInfo } from '../api/selection.js';
10
13
  import type { DocPosition } from '../api/positions.js';
14
+ import { type XmlElement } from '../xml/index.js';
11
15
  import type { DocxViewer } from './viewer.js';
12
16
  export interface EditingOptions {
13
17
  /** Checks every change (e.g. an AccessPolicy from docxkeun/security). */
14
18
  guard?: EditGuard;
19
+ /** Record typing as tracked changes (default: the document's Track Changes setting). */
20
+ trackChanges?: boolean;
21
+ /** Author of tracked changes. */
22
+ author?: string;
15
23
  }
16
24
  /** A place in the text: paragraph index (document order, tables included) and UTF-16 offset. */
17
25
  export interface Caret {
18
26
  para: number;
19
27
  char: number;
20
28
  }
29
+ /** Which text the caret is in: the body, a header or footer, a note, or a text box. */
30
+ export type EditStory = {
31
+ kind: 'body';
32
+ } | {
33
+ kind: 'header' | 'footer';
34
+ part: string;
35
+ } | {
36
+ kind: 'footnote' | 'endnote';
37
+ part: string;
38
+ noteId: string;
39
+ } | {
40
+ kind: 'textbox';
41
+ container: XmlElement;
42
+ };
43
+ /** Formatting at the caret, for toolbars (see the viewer's `caretchange` event). */
44
+ export interface CaretFormat {
45
+ bold: boolean;
46
+ italic: boolean;
47
+ underline: boolean;
48
+ strike: boolean;
49
+ /** Points. */
50
+ size?: number;
51
+ font?: string;
52
+ color?: string;
53
+ highlight?: string;
54
+ align: 'left' | 'center' | 'right' | 'justify';
55
+ direction: 'ltr' | 'rtl';
56
+ styleId?: string;
57
+ list?: 'bullet' | 'number';
58
+ story: EditStory['kind'];
59
+ hasSelection: boolean;
60
+ trackChanges: boolean;
61
+ canUndo: boolean;
62
+ canRedo: boolean;
63
+ }
21
64
  export declare class InlineEditing {
22
65
  private readonly viewer;
23
- private readonly options;
24
66
  private enabled;
67
+ private storyValue;
25
68
  private anchor;
26
69
  private focusPos;
27
70
  private hasCaret;
@@ -29,14 +72,18 @@ export declare class InlineEditing {
29
72
  private composing;
30
73
  private dragging;
31
74
  private goalX;
32
- private readonly undoStack;
33
- private readonly redoStack;
75
+ private readonly history;
76
+ private historyDoc;
34
77
  private lastEdit;
78
+ /** Formatting chosen with no selection: applied to the next text typed. */
79
+ private pending;
80
+ private lastFormat;
35
81
  private paras;
36
82
  private readonly nodeIndex;
37
83
  private readonly paraIndex;
38
84
  private readonly layers;
39
85
  private readonly cleanup;
86
+ private readonly options;
40
87
  constructor(viewer: DocxViewer, options?: EditingOptions);
41
88
  setEnabled(on: boolean): void;
42
89
  get isEnabled(): boolean;
@@ -48,6 +95,30 @@ export declare class InlineEditing {
48
95
  /** Place the caret (and optionally extend a selection) programmatically. */
49
96
  select(anchor: Caret, focus?: Caret): void;
50
97
  focus(): void;
98
+ /** The selection (or caret) with paragraph numbers, text and pages, for AI assistants and toolbars. */
99
+ selectionInfo(): SelectionInfo | undefined;
100
+ /** Whether typing is recorded as tracked changes. */
101
+ get trackChanges(): boolean;
102
+ set trackChanges(on: boolean);
103
+ /** The story the caret is in. */
104
+ get story(): EditStory;
105
+ /** Move the caret into a header, footer, note or text box (or back to the body). */
106
+ enterStory(story: EditStory, caret?: Caret): void;
107
+ /** The guard checking this layer's edits, if any. */
108
+ get guard(): EditGuard | undefined;
109
+ /** Who new comments and replies are written by: the `author` option, else the guard's user. */
110
+ get author(): string;
111
+ /** Put the caret at a point on a page (points), as a click would. No-op while editing is off. */
112
+ placeCaretAt(page: number, x: number, y: number): void;
113
+ /** Whether a point on a page (points) lies inside the current, non-empty selection. */
114
+ selectionContains(page: number, x: number, y: number): boolean;
115
+ /** Where the start of the selection is: its page and the line's top (points on the page). */
116
+ selectionSpot(): {
117
+ page: number;
118
+ x: number;
119
+ y: number;
120
+ h: number;
121
+ } | undefined;
51
122
  /** An editor range (for DocxEditor calls such as addComment) between two carets. */
52
123
  rangeOf(a: Caret, b: Caret): {
53
124
  start: DocPosition;
@@ -55,7 +126,10 @@ export declare class InlineEditing {
55
126
  };
56
127
  destroy(): void;
57
128
  private get doc();
129
+ /** Part holding the current story. */
130
+ private get storyPart();
58
131
  private editor;
132
+ private storyParagraphs;
59
133
  private refreshModel;
60
134
  private textOf;
61
135
  private clamp;
@@ -63,7 +137,11 @@ export declare class InlineEditing {
63
137
  private toDoc;
64
138
  private fromDoc;
65
139
  private pages;
140
+ /** Lines of the current story on a page. */
66
141
  private bodyLines;
142
+ private linesOf;
143
+ /** The run child an inline image stands for, when it is in the current story. */
144
+ private imageNode;
67
145
  private lineItems;
68
146
  private clusterLength;
69
147
  /** Caret for a point on a page (in points). */
@@ -75,7 +153,13 @@ export declare class InlineEditing {
75
153
  private onPageMount;
76
154
  private redraw;
77
155
  private drawPage;
156
+ private pagePoint;
78
157
  private pointToCaret;
158
+ /**
159
+ * Switch stories for a click, as Word does: a click in a note or text box enters it, a
160
+ * double-click enters a header or footer, and a click in the body leaves them.
161
+ */
162
+ private storyForClick;
79
163
  private onMouseDown;
80
164
  private onMouseMove;
81
165
  private onDoubleClick;
@@ -83,7 +167,21 @@ export declare class InlineEditing {
83
167
  private onInput;
84
168
  private selectedText;
85
169
  private onCopy;
170
+ /**
171
+ * Copy (or cut) the selection with the async clipboard: HTML and plain text, or plain text only
172
+ * where rich items are refused. For menus; the keyboard shortcuts use the native events above.
173
+ */
174
+ copySelection(cut?: boolean): Promise<void>;
86
175
  private onPaste;
176
+ /** Paste HTML (rich paste: formatting, headings, lists and links). False when it holds no paragraphs. */
177
+ pasteHtml(html: string): boolean;
178
+ /** Paste plain text at the caret (replacing the selection). */
179
+ pasteText(text: string): void;
180
+ /** The selection as HTML (formatting, headings and lists), for pasting into other programs. */
181
+ private selectedHtml;
182
+ private listKind;
183
+ /** Insert formatted paragraphs (from pasted HTML) at the caret. */
184
+ pasteParagraphs(paragraphs: PastedParagraph[]): void;
87
185
  private ordered;
88
186
  private setCaret;
89
187
  private moveHorizontal;
@@ -102,7 +200,50 @@ export declare class InlineEditing {
102
200
  private newParagraph;
103
201
  private deleteBackward;
104
202
  private deleteForward;
105
- private toggle;
203
+ /** Turn bold, italic, underline or strikethrough on or off for the selection (or the next text typed). */
204
+ toggle(prop: 'bold' | 'italic' | 'underline' | 'strike'): void;
205
+ /** Format the selected text; with only a caret, the format applies to the next text typed. */
206
+ format(format: TextFormat): void;
207
+ /** Paragraphs the selection touches. */
208
+ private selectedParagraphs;
209
+ /** Alignment, direction, indents or spacing of the selected paragraphs. */
210
+ formatParagraphs(format: ParagraphFormat): Promise<void>;
211
+ /** Apply a paragraph style (e.g. "Heading1") to the selected paragraphs. */
212
+ setStyle(styleId: string): Promise<void>;
213
+ /** Make the selected paragraphs a bulleted or numbered list, or take them out of one. */
214
+ setList(format: ListFormat | 'none'): Promise<void>;
215
+ /** Increase (1) or decrease (-1) the indent: the list level in a list, else the left indent by half an inch. */
216
+ indent(dir: 1 | -1): Promise<void>;
217
+ /** Whether there is something to undo or redo (for toolbars). */
218
+ get canUndo(): boolean;
219
+ get canRedo(): boolean;
220
+ /**
221
+ * Run an edit that may touch any part of the document as one undo step. A failure puts the
222
+ * document back, reports `editerror` and rethrows. Inside `fn`, change the document through the
223
+ * `editor` it receives. A nested `transaction()`, `setList()` and the like joins this step only
224
+ * before `fn`'s first `await`; after it, it waits for this step and gives up after
225
+ * `UndoHistory.queueTimeout` (10 s by default): a nested `transaction()` rejects with an
226
+ * `EditError`, while `setList()` and the like report it through `editerror`. Edits requested
227
+ * elsewhere meanwhile wait their turn, act on the selection they were requested with, and are
228
+ * undo steps of their own.
229
+ */
230
+ transaction<T>(label: string, fn: (editor: DocxEditor) => T | Promise<T>): Promise<T>;
231
+ /** Make `story` (a text box found again by its index) and the selection current, with a fresh model. */
232
+ private putSelection;
233
+ /** Errors already reported through `editerror` (a nested transaction's failure reaching the outer one). */
234
+ private readonly reported;
235
+ private reportError;
236
+ /** A transaction on the selection whose failure has already been reported through `editerror`. */
237
+ private act;
238
+ /** Formatting at the caret (start of the selection), with any format waiting for the next text typed. */
239
+ caretFormat(): CaretFormat | undefined;
240
+ private reportFormat;
241
+ /** The current story's part as it is now, with the selection. */
242
+ private snapshot;
243
+ /** Put a snapshot's XML back into its part. */
244
+ private putRoot;
245
+ /** The entry for the state being left, of the same kind as the one being restored. */
246
+ private currentFor;
106
247
  undo(): void;
107
248
  redo(): void;
108
249
  private restore;