@sametalmdr/word-editor 0.2.0-alpha → 0.3.0-alpha

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 (82) hide show
  1. package/CHANGELOG.md +108 -70
  2. package/LICENSE +21 -21
  3. package/README.md +286 -247
  4. package/dist/canvas/box-clipboard.js +238 -238
  5. package/dist/canvas/box-selection.js +80 -80
  6. package/dist/canvas/canvas-editor.js +502 -502
  7. package/dist/canvas/controller.js +717 -717
  8. package/dist/canvas/geometry.js +131 -131
  9. package/dist/canvas/gesture.d.ts +0 -1
  10. package/dist/canvas/gesture.js +289 -289
  11. package/dist/canvas/handles.js +212 -212
  12. package/dist/canvas/menu.js +82 -82
  13. package/dist/canvas/mode-controller.js +81 -81
  14. package/dist/canvas/nudge.js +108 -108
  15. package/dist/canvas/overlay.js +149 -149
  16. package/dist/canvas/snap.js +132 -132
  17. package/dist/canvas/viewport.js +112 -112
  18. package/dist/canvas/z-order.js +171 -171
  19. package/dist/commands/alignment.js +150 -150
  20. package/dist/commands/box.js +272 -272
  21. package/dist/commands/clipboard.js +93 -93
  22. package/dist/commands/graphemes.js +112 -112
  23. package/dist/commands/marks.js +153 -153
  24. package/dist/commands/paragraph-props.js +176 -176
  25. package/dist/commands/size.js +368 -368
  26. package/dist/commands/text.js +291 -291
  27. package/dist/docx.d.ts +1 -0
  28. package/dist/docx.js +15 -13
  29. package/dist/editor/editing-host.js +434 -434
  30. package/dist/element.js +41 -41
  31. package/dist/fonts/OFL-Carlito.txt +94 -0
  32. package/dist/fonts/calibri-metrics.d.ts +27 -0
  33. package/dist/fonts/calibri-metrics.js +88 -0
  34. package/dist/history/history.js +433 -433
  35. package/dist/index.js +63 -63
  36. package/dist/input/beforeinput.js +224 -224
  37. package/dist/input/clipboard.js +107 -107
  38. package/dist/input/composition.js +341 -341
  39. package/dist/input/keymap.js +54 -54
  40. package/dist/io/ooxml/custgeom.js +72 -72
  41. package/dist/io/ooxml/drawingml.js +232 -232
  42. package/dist/io/ooxml/edits.js +67 -67
  43. package/dist/io/ooxml/export-splice.js +880 -880
  44. package/dist/io/ooxml/export.js +365 -365
  45. package/dist/io/ooxml/fill.d.ts +93 -8
  46. package/dist/io/ooxml/fill.js +618 -562
  47. package/dist/io/ooxml/fit.d.ts +252 -0
  48. package/dist/io/ooxml/fit.js +598 -0
  49. package/dist/io/ooxml/import-gate.js +200 -200
  50. package/dist/io/ooxml/import.js +691 -691
  51. package/dist/io/ooxml/inflate.js +126 -126
  52. package/dist/io/ooxml/media.js +87 -87
  53. package/dist/io/ooxml/ns.d.ts +2 -0
  54. package/dist/io/ooxml/ns.js +26 -21
  55. package/dist/io/ooxml/numbering.js +290 -290
  56. package/dist/io/ooxml/opc-write.js +171 -171
  57. package/dist/io/ooxml/provenance.js +93 -93
  58. package/dist/io/ooxml/recipe.js +708 -708
  59. package/dist/io/ooxml/relationships.js +59 -59
  60. package/dist/io/ooxml/run-fonts.d.ts +89 -0
  61. package/dist/io/ooxml/run-fonts.js +378 -0
  62. package/dist/io/ooxml/slots.d.ts +4 -0
  63. package/dist/io/ooxml/slots.js +582 -581
  64. package/dist/io/ooxml/styles-resolve.js +257 -257
  65. package/dist/io/ooxml/units.js +43 -43
  66. package/dist/io/ooxml/value.js +120 -120
  67. package/dist/io/ooxml/xml-scan.js +616 -616
  68. package/dist/io/ooxml/zip-container.js +228 -228
  69. package/dist/io/ooxml/zip-reject.js +106 -106
  70. package/dist/measure/placement.js +83 -83
  71. package/dist/measure/report.js +75 -75
  72. package/dist/model/ids.js +70 -70
  73. package/dist/model/normalize.js +146 -146
  74. package/dist/model/position.js +283 -283
  75. package/dist/model/transaction.js +209 -209
  76. package/dist/platform/capabilities.js +25 -25
  77. package/dist/react/index.js +21 -21
  78. package/dist/selection/controller.js +315 -315
  79. package/dist/selection/dom-map.js +334 -334
  80. package/dist/state/editor-state.js +109 -109
  81. package/dist/styles.css +66 -66
  82. package/package.json +94 -93
@@ -0,0 +1,252 @@
1
+ /**
2
+ * The width a scanned text box gives its text, or why it cannot be known.
3
+ * @param {import("./slots.js").AlternateContentRecord} ac a box the slot scan accepted
4
+ * @returns {{box: BoxGeometry} | {unknown: Unknown}}
5
+ */
6
+ export function boxGeometry(ac: import("./slots.js").AlternateContentRecord): {
7
+ box: BoxGeometry;
8
+ } | {
9
+ unknown: Unknown;
10
+ };
11
+ /**
12
+ * @typedef {{cp: number, u: number, sp: number, tab?: true}} Item a character, or a tab's jump to its stop
13
+ * @typedef {{lines: LineMeasure[], stops: number[]}} Laid the lines, and the stop each tab reached (u)
14
+ * @typedef {{unknown: Unknown & {codePoint?: number}} | {overflow: {code: "TAB_STOP_PASSED"}}} NotLaid
15
+ */
16
+ /**
17
+ * The lines a paragraph holds once its tags are filled, each measured: where it
18
+ * starts, where it must end, how wide it is (ADR-0042 Karar 5). A line ends at a
19
+ * w:br — the template's, or one a multi-line value's LF becomes. No break point is
20
+ * ever chosen (invariant #9): a line is measured whole, as the template and the
21
+ * values give it.
22
+ *
23
+ * A tab jumps to the first left stop past the pen, stops measured from the box's
24
+ * inner left edge (H6). The paragraph is laid out once with its tags empty: that
25
+ * fixes the stop each tab reaches. Filled, a tab whose text has passed that stop
26
+ * has broken the column the template aligned — an overflow, TAB_STOP_PASSED, even
27
+ * if the line itself still fits.
28
+ * @param {object} input
29
+ * @param {XmlElement} input.paragraph
30
+ * @param {BoxGeometry} input.box
31
+ * @param {ReturnType<typeof import("./run-fonts.js").layoutResolver>} input.layout
32
+ * @param {Map<XmlElement, string>} input.values tag run -> the value written into it
33
+ * @param {boolean} [input.preserve] every w:t inherits xml:space="preserve" (inheritsPreserve);
34
+ * otherwise a template text with edge whitespace and no preserve of its own is unknown —
35
+ * Word may drop that whitespace
36
+ * @returns {{lines: LineMeasure[]} | NotLaid}
37
+ */
38
+ export function measureParagraph({ paragraph, box, layout, values, preserve }: {
39
+ paragraph: XmlElement;
40
+ box: BoxGeometry;
41
+ layout: ReturnType<typeof import("./run-fonts.js").layoutResolver>;
42
+ values: Map<XmlElement, string>;
43
+ preserve?: boolean | undefined;
44
+ }): {
45
+ lines: LineMeasure[];
46
+ } | NotLaid;
47
+ /**
48
+ * @typedef {"fits" | "overflows" | "unknown" | "empty"} FitStatus
49
+ * @typedef {{status: "fits" | "overflows"} | {status: "unknown", reason: Unknown}} LineVerdict
50
+ * @typedef {object} FitOccurrence
51
+ * @property {number | null} docPrId
52
+ * @property {number} page
53
+ * @property {FitStatus} status
54
+ * @property {string} [reason] from a closed list (ADR-0042)
55
+ * @property {string} [property] the property or element the reason names
56
+ * @property {number} [codePoint] the character the table lacks
57
+ * @property {number} [widthPt] the tightest line's width
58
+ * @property {number} [availablePt] the room it has
59
+ * @property {number} [marginPt] room less width; negative when it overflows
60
+ * @property {number} [lines] a multi-line value's line count
61
+ * @property {number} [capacity]
62
+ * @property {string[]} [paragraphTags] the other tags measured on the same line
63
+ * @typedef {{name: string, status: FitStatus, occurrences: FitOccurrence[]}} FitTag
64
+ * @typedef {object} FitReport
65
+ * @property {boolean} ok no occurrence overflows or is unknown — the caller's approval rule
66
+ * @property {FitTag[]} tags sorted by name
67
+ * @property {{tags: number, occurrences: number, fits: number, overflows: number, unknown: number, empty: number}} counts
68
+ * @property {{version: string, metrics: {family: string, carlito: string | null, calibri: string | null}}} engine
69
+ */
70
+ /**
71
+ * One line against its room: fits when even with its trailing spaces counted and τ more it would
72
+ * fit, overflows when even with them hanging and τ less it would not; between, unknown (ADR-0042
73
+ * Karar 6) — TRAILING_SPACE when the trailing spaces alone decide.
74
+ * @param {LineMeasure} line
75
+ * @returns {LineVerdict}
76
+ */
77
+ export function decideLine(line: LineMeasure): LineVerdict;
78
+ /**
79
+ * Whether every w:t of the document inherits xml:space="preserve": the root sets it and no element
80
+ * below sets anything else (Word writes the root's; all 46 corpus documents carry it).
81
+ * @param {XmlElement} root
82
+ * @returns {boolean}
83
+ */
84
+ export function inheritsPreserve(root: XmlElement): boolean;
85
+ /**
86
+ * Settings that change every line, or that the evidence does not cover: the compatibility mode
87
+ * (14 only), the w:compat options, East Asian punctuation compression, a character grid.
88
+ * @param {Uint8Array | undefined} settingsXml
89
+ * @param {XmlElement} documentRoot
90
+ * @returns {Unknown | null}
91
+ */
92
+ export function documentUnknown(settingsXml: Uint8Array | undefined, documentRoot: XmlElement): Unknown | null;
93
+ /**
94
+ * Whether each value of `data` stays on the lines its box gives it, as Word lays the filled
95
+ * template out (ADR-0042). Validates exactly as fillTemplate does — the same TemplateError for
96
+ * the same input — and writes nothing. The report carries no value: widths, reasons, code points.
97
+ * @param {Uint8Array} bytes a .docx template
98
+ * @param {import("./fill.js").FillData} data
99
+ * @param {{expectedTags?: readonly string[], multiline?: readonly string[], capacity?: Record<string, number>}} [options]
100
+ * `capacity`: tag -> lines, for multi-line tags only; a binding manifest carries it as `fit`
101
+ * @returns {Promise<FitReport>}
102
+ */
103
+ export function checkFit(bytes: Uint8Array, data: import("./fill.js").FillData, options?: {
104
+ expectedTags?: readonly string[];
105
+ multiline?: readonly string[];
106
+ capacity?: Record<string, number>;
107
+ }): Promise<FitReport>;
108
+ /** DrawingML's default left and right inset (ECMA-376 §21.1.2.1.1 bodyPr: 91440 EMU, 0.1 in). */
109
+ export const DEFAULT_INSET_EMU: 91440;
110
+ /** u per EMU */
111
+ export const U_PER_EMU: 2048;
112
+ /** τ = 0.05 pt + 0.025 pt a glyph (ADR-0042 Karar 6), in u. */
113
+ export const TAU_BASE_U: number;
114
+ export const TAU_PER_GLYPH_U: number;
115
+ /**
116
+ * a character, or a tab's jump to its stop
117
+ */
118
+ export type Item = {
119
+ cp: number;
120
+ u: number;
121
+ sp: number;
122
+ tab?: true;
123
+ };
124
+ /**
125
+ * the lines, and the stop each tab reached (u)
126
+ */
127
+ export type Laid = {
128
+ lines: LineMeasure[];
129
+ stops: number[];
130
+ };
131
+ export type NotLaid = {
132
+ unknown: Unknown & {
133
+ codePoint?: number;
134
+ };
135
+ } | {
136
+ overflow: {
137
+ code: "TAB_STOP_PASSED";
138
+ };
139
+ };
140
+ export type FitStatus = "fits" | "overflows" | "unknown" | "empty";
141
+ export type LineVerdict = {
142
+ status: "fits" | "overflows";
143
+ } | {
144
+ status: "unknown";
145
+ reason: Unknown;
146
+ };
147
+ export type FitOccurrence = {
148
+ docPrId: number | null;
149
+ page: number;
150
+ status: FitStatus;
151
+ /**
152
+ * from a closed list (ADR-0042)
153
+ */
154
+ reason?: string | undefined;
155
+ /**
156
+ * the property or element the reason names
157
+ */
158
+ property?: string | undefined;
159
+ /**
160
+ * the character the table lacks
161
+ */
162
+ codePoint?: number | undefined;
163
+ /**
164
+ * the tightest line's width
165
+ */
166
+ widthPt?: number | undefined;
167
+ /**
168
+ * the room it has
169
+ */
170
+ availablePt?: number | undefined;
171
+ /**
172
+ * room less width; negative when it overflows
173
+ */
174
+ marginPt?: number | undefined;
175
+ /**
176
+ * a multi-line value's line count
177
+ */
178
+ lines?: number | undefined;
179
+ capacity?: number | undefined;
180
+ /**
181
+ * the other tags measured on the same line
182
+ */
183
+ paragraphTags?: string[] | undefined;
184
+ };
185
+ export type FitTag = {
186
+ name: string;
187
+ status: FitStatus;
188
+ occurrences: FitOccurrence[];
189
+ };
190
+ export type FitReport = {
191
+ /**
192
+ * no occurrence overflows or is unknown — the caller's approval rule
193
+ */
194
+ ok: boolean;
195
+ /**
196
+ * sorted by name
197
+ */
198
+ tags: FitTag[];
199
+ counts: {
200
+ tags: number;
201
+ occurrences: number;
202
+ fits: number;
203
+ overflows: number;
204
+ unknown: number;
205
+ empty: number;
206
+ };
207
+ engine: {
208
+ version: string;
209
+ metrics: {
210
+ family: string;
211
+ carlito: string | null;
212
+ calibri: string | null;
213
+ };
214
+ };
215
+ };
216
+ export type XmlElement = import("./xml-scan.js").XmlElement;
217
+ export type Unknown = import("./run-fonts.js").Unknown;
218
+ /**
219
+ * `textWidthEmu`: the width between the insets, where a paragraph's indents start
220
+ */
221
+ export type BoxGeometry = {
222
+ widthEmu: number;
223
+ lInsEmu: number;
224
+ rInsEmu: number;
225
+ textWidthEmu: number;
226
+ };
227
+ /**
228
+ * one line of a filled paragraph
229
+ */
230
+ export type LineMeasure = {
231
+ /**
232
+ * where it starts, from the box's inner left edge: the indents
233
+ */
234
+ startEmu: number;
235
+ /**
236
+ * where it must end: the text width less the right indent
237
+ */
238
+ limitEmu: number;
239
+ /**
240
+ * its natural width, every character counted — trailing spaces too (u = EMU × 2048)
241
+ */
242
+ widthU: number;
243
+ /**
244
+ * the same with the trailing spaces left out, as if Word hung them (H3)
245
+ */
246
+ widthWithoutTrailingU: number;
247
+ /**
248
+ * characters in `widthU` since its last exact place — the line start or a tab stop — whose
249
+ * deviations τ covers
250
+ */
251
+ glyphs: number;
252
+ };