docxkeun 0.1.2 → 0.2.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 (197) hide show
  1. package/CHANGELOG.md +55 -0
  2. package/README.md +139 -16
  3. package/dist/api/editor.d.ts +172 -5
  4. package/dist/api/editor.js +814 -24
  5. package/dist/api/headers.d.ts +51 -0
  6. package/dist/api/headers.js +133 -0
  7. package/dist/api/index.d.ts +5 -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 +390 -0
  15. package/dist/api/selection.d.ts +57 -0
  16. package/dist/api/selection.js +91 -0
  17. package/dist/charts/color.d.ts +45 -0
  18. package/dist/charts/color.js +322 -0
  19. package/dist/charts/format.d.ts +12 -0
  20. package/dist/charts/format.js +459 -0
  21. package/dist/charts/index.d.ts +11 -0
  22. package/dist/charts/index.js +8 -0
  23. package/dist/charts/model.d.ts +225 -0
  24. package/dist/charts/model.js +758 -0
  25. package/dist/charts/outline.d.ts +17 -0
  26. package/dist/charts/outline.js +214 -0
  27. package/dist/charts/render.d.ts +20 -0
  28. package/dist/charts/render.js +1772 -0
  29. package/dist/drawing/arrows.d.ts +37 -0
  30. package/dist/drawing/arrows.js +99 -0
  31. package/dist/drawing/formula.d.ts +40 -0
  32. package/dist/drawing/formula.js +159 -0
  33. package/dist/drawing/geometry.d.ts +61 -0
  34. package/dist/drawing/geometry.js +286 -0
  35. package/dist/drawing/index.d.ts +12 -0
  36. package/dist/drawing/index.js +8 -0
  37. package/dist/drawing/presets.d.ts +72 -0
  38. package/dist/drawing/presets.js +2874 -0
  39. package/dist/fonts/shaping/apply.d.ts +94 -0
  40. package/dist/fonts/shaping/apply.js +349 -0
  41. package/dist/fonts/shaping/arabic.d.ts +28 -0
  42. package/dist/fonts/shaping/arabic.js +235 -0
  43. package/dist/fonts/shaping/buffer.d.ts +53 -0
  44. package/dist/fonts/shaping/buffer.js +95 -0
  45. package/dist/fonts/shaping/gdef.d.ts +30 -0
  46. package/dist/fonts/shaping/gdef.js +66 -0
  47. package/dist/fonts/shaping/gpos.d.ts +86 -0
  48. package/dist/fonts/shaping/gpos.js +428 -0
  49. package/dist/fonts/shaping/gsub.d.ts +65 -0
  50. package/dist/fonts/shaping/gsub.js +313 -0
  51. package/dist/fonts/shaping/index.d.ts +32 -0
  52. package/dist/fonts/shaping/index.js +402 -0
  53. package/dist/fonts/shaping/indic.d.ts +6 -0
  54. package/dist/fonts/shaping/indic.js +805 -0
  55. package/dist/fonts/shaping/layout-common.d.ts +124 -0
  56. package/dist/fonts/shaping/layout-common.js +349 -0
  57. package/dist/fonts/shaping/plan.d.ts +87 -0
  58. package/dist/fonts/shaping/plan.js +152 -0
  59. package/dist/fonts/shaping/scripts.d.ts +26 -0
  60. package/dist/fonts/shaping/scripts.js +160 -0
  61. package/dist/fonts/shaping/shaper.d.ts +23 -0
  62. package/dist/fonts/shaping/shaper.js +5 -0
  63. package/dist/fonts/shaping/unicode.d.ts +34 -0
  64. package/dist/fonts/shaping/unicode.js +138 -0
  65. package/dist/images/bmp.d.ts +9 -0
  66. package/dist/images/bmp.js +234 -0
  67. package/dist/images/gif.d.ts +9 -0
  68. package/dist/images/gif.js +215 -0
  69. package/dist/images/index.d.ts +18 -0
  70. package/dist/images/index.js +63 -0
  71. package/dist/images/png-encode.d.ts +4 -0
  72. package/dist/images/png-encode.js +73 -0
  73. package/dist/images/size.d.ts +10 -0
  74. package/dist/images/size.js +83 -0
  75. package/dist/images/tiff.d.ts +14 -0
  76. package/dist/images/tiff.js +407 -0
  77. package/dist/index.d.ts +7 -2
  78. package/dist/index.js +5 -0
  79. package/dist/layout/bidi.d.ts +18 -0
  80. package/dist/layout/bidi.js +71 -0
  81. package/dist/layout/blocks.d.ts +20 -3
  82. package/dist/layout/blocks.js +88 -58
  83. package/dist/layout/cache.d.ts +31 -0
  84. package/dist/layout/cache.js +38 -0
  85. package/dist/layout/drawing.d.ts +30 -0
  86. package/dist/layout/drawing.js +120 -0
  87. package/dist/layout/engine.d.ts +3 -0
  88. package/dist/layout/engine.js +218 -11
  89. package/dist/layout/index.d.ts +1 -0
  90. package/dist/layout/index.js +1 -0
  91. package/dist/layout/lines.d.ts +63 -5
  92. package/dist/layout/lines.js +245 -20
  93. package/dist/layout/paint.d.ts +25 -3
  94. package/dist/layout/paint.js +26 -10
  95. package/dist/layout/shapes.d.ts +7 -0
  96. package/dist/layout/shapes.js +338 -0
  97. package/dist/layout/style.d.ts +4 -0
  98. package/dist/layout/style.js +2 -0
  99. package/dist/layout/types.d.ts +89 -2
  100. package/dist/math/boxes.d.ts +88 -0
  101. package/dist/math/boxes.js +166 -0
  102. package/dist/math/index.d.ts +29 -0
  103. package/dist/math/index.js +44 -0
  104. package/dist/math/layout.d.ts +13 -0
  105. package/dist/math/layout.js +771 -0
  106. package/dist/math/linear.d.ts +3 -0
  107. package/dist/math/linear.js +152 -0
  108. package/dist/math/omml.d.ts +15 -0
  109. package/dist/math/omml.js +57 -0
  110. package/dist/math/paths.d.ts +61 -0
  111. package/dist/math/paths.js +450 -0
  112. package/dist/math/symbols.d.ts +49 -0
  113. package/dist/math/symbols.js +269 -0
  114. package/dist/math/text.d.ts +53 -0
  115. package/dist/math/text.js +316 -0
  116. package/dist/metafile/canvas.d.ts +80 -0
  117. package/dist/metafile/canvas.js +515 -0
  118. package/dist/metafile/dib.d.ts +27 -0
  119. package/dist/metafile/dib.js +300 -0
  120. package/dist/metafile/emf.d.ts +31 -0
  121. package/dist/metafile/emf.js +591 -0
  122. package/dist/metafile/geometry.d.ts +49 -0
  123. package/dist/metafile/geometry.js +85 -0
  124. package/dist/metafile/index.d.ts +27 -0
  125. package/dist/metafile/index.js +34 -0
  126. package/dist/metafile/reader.d.ts +28 -0
  127. package/dist/metafile/reader.js +59 -0
  128. package/dist/metafile/state.d.ts +118 -0
  129. package/dist/metafile/state.js +172 -0
  130. package/dist/metafile/text.d.ts +17 -0
  131. package/dist/metafile/text.js +130 -0
  132. package/dist/metafile/wmf.d.ts +33 -0
  133. package/dist/metafile/wmf.js +395 -0
  134. package/dist/model/content.d.ts +92 -7
  135. package/dist/model/content.js +251 -17
  136. package/dist/model/document.d.ts +34 -1
  137. package/dist/model/document.js +80 -1
  138. package/dist/model/fields.d.ts +4 -0
  139. package/dist/model/fields.js +10 -0
  140. package/dist/model/numbering.d.ts +2 -0
  141. package/dist/model/numbering.js +22 -0
  142. package/dist/model/props.d.ts +2 -0
  143. package/dist/model/props.js +3 -0
  144. package/dist/opc/index.d.ts +1 -1
  145. package/dist/opc/package.d.ts +34 -0
  146. package/dist/opc/package.js +58 -4
  147. package/dist/pdf/export.js +97 -6
  148. package/dist/pdf/images.d.ts +7 -0
  149. package/dist/pdf/images.js +39 -2
  150. package/dist/render/activity.d.ts +138 -0
  151. package/dist/render/activity.js +794 -0
  152. package/dist/render/clipboard.d.ts +29 -0
  153. package/dist/render/clipboard.js +401 -0
  154. package/dist/render/comments.d.ts +166 -0
  155. package/dist/render/comments.js +779 -0
  156. package/dist/render/context-menu.d.ts +124 -0
  157. package/dist/render/context-menu.js +525 -0
  158. package/dist/render/editing.d.ts +146 -5
  159. package/dist/render/editing.js +678 -53
  160. package/dist/render/index.d.ts +12 -0
  161. package/dist/render/index.js +11 -0
  162. package/dist/render/navigation-panel.d.ts +76 -0
  163. package/dist/render/navigation-panel.js +431 -0
  164. package/dist/render/selection.js +5 -0
  165. package/dist/render/svg.d.ts +4 -6
  166. package/dist/render/svg.js +69 -7
  167. package/dist/render/toolbar.d.ts +83 -0
  168. package/dist/render/toolbar.js +505 -0
  169. package/dist/render/ui/comment-layout.d.ts +39 -0
  170. package/dist/render/ui/comment-layout.js +79 -0
  171. package/dist/render/ui/icons.d.ts +6 -0
  172. package/dist/render/ui/icons.js +38 -0
  173. package/dist/render/ui/menu.d.ts +38 -0
  174. package/dist/render/ui/menu.js +274 -0
  175. package/dist/render/ui/nav-model.d.ts +11 -0
  176. package/dist/render/ui/nav-model.js +34 -0
  177. package/dist/render/ui/overflow.d.ts +5 -0
  178. package/dist/render/ui/overflow.js +18 -0
  179. package/dist/render/ui/popover.d.ts +18 -0
  180. package/dist/render/ui/popover.js +109 -0
  181. package/dist/render/ui/theme.d.ts +2 -0
  182. package/dist/render/ui/theme.js +29 -0
  183. package/dist/render/undo.d.ts +76 -0
  184. package/dist/render/undo.js +144 -0
  185. package/dist/render/viewer.d.ts +100 -7
  186. package/dist/render/viewer.js +302 -92
  187. package/dist/security/policy.d.ts +3 -0
  188. package/dist/security/policy.js +6 -2
  189. package/dist/security/protection.d.ts +1 -0
  190. package/dist/security/protection.js +1 -1
  191. package/dist/text/bidi-data.d.ts +53 -0
  192. package/dist/text/bidi-data.js +318 -0
  193. package/dist/text/bidi.d.ts +37 -0
  194. package/dist/text/bidi.js +508 -0
  195. package/dist/xml/ns.d.ts +5 -0
  196. package/dist/xml/ns.js +7 -0
  197. package/package.json +9 -2
@@ -0,0 +1,166 @@
1
+ /** Script sizes relative to the base: Cambria Math's ScriptPercentScaleDown (73) and ScriptScript (60). */
2
+ export const SCALE = [1, 0.73, 0.6];
3
+ /** Default rule thickness (fraction bars, overbars, radicals), in em. */
4
+ export const RULE = 0.06;
5
+ export const THIN = 3 / 18;
6
+ export const MEDIUM = 4 / 18;
7
+ export const THICK = 5 / 18;
8
+ export const X_HEIGHT = 0.46;
9
+ export function em(ctx) {
10
+ return ctx.base * SCALE[ctx.level];
11
+ }
12
+ export function scriptStyle(ctx, cramped = ctx.cramped) {
13
+ return { ...ctx, level: Math.min(2, ctx.level + 1), display: false, cramped, align: false, fn: false };
14
+ }
15
+ /** Numerators and denominators: display → text size, text → script, and so on. */
16
+ export function fractionStyle(ctx, cramped) {
17
+ if (ctx.display && ctx.level === 0)
18
+ return { ...ctx, display: false, cramped, align: false, fn: false };
19
+ return scriptStyle(ctx, cramped);
20
+ }
21
+ export function emptyBox(width = 0) {
22
+ return { width, ascent: 0, descent: 0, items: [], italic: 0 };
23
+ }
24
+ /** Move items in place (boxes are owned by exactly one parent, so nothing is copied). */
25
+ export function shiftItems(items, dx, dy) {
26
+ if (dx === 0 && dy === 0)
27
+ return;
28
+ for (const it of items) {
29
+ switch (it.type) {
30
+ case 'text':
31
+ it.x += dx;
32
+ it.y += dy;
33
+ for (let i = 0; i < it.xs.length; i++)
34
+ it.xs[i] += dx;
35
+ break;
36
+ case 'rect':
37
+ case 'image':
38
+ it.x += dx;
39
+ it.y += dy;
40
+ break;
41
+ case 'line':
42
+ it.x1 += dx;
43
+ it.x2 += dx;
44
+ it.y1 += dy;
45
+ it.y2 += dy;
46
+ break;
47
+ case 'path':
48
+ for (const c of it.commands) {
49
+ if (c.op === 'Z')
50
+ continue;
51
+ c.x += dx;
52
+ c.y += dy;
53
+ if (c.op === 'C') {
54
+ c.x1 += dx;
55
+ c.y1 += dy;
56
+ c.x2 += dx;
57
+ c.y2 += dy;
58
+ }
59
+ }
60
+ break;
61
+ }
62
+ }
63
+ }
64
+ /** Collects boxes and drawn items into a new box, tracking its extent. */
65
+ export class Builder {
66
+ items = [];
67
+ ascent = 0;
68
+ descent = 0;
69
+ right = 0;
70
+ /** Place a box with its origin at (x, y); y is down, so a raised box has negative y. */
71
+ put(box, x, y) {
72
+ shiftItems(box.items, x, y);
73
+ for (const it of box.items)
74
+ this.items.push(it);
75
+ this.ascent = Math.max(this.ascent, box.ascent - y);
76
+ this.descent = Math.max(this.descent, box.descent + y);
77
+ this.right = Math.max(this.right, x + box.width);
78
+ }
79
+ /** Add an item the caller drew, covering `top`..`bottom` (y down). */
80
+ draw(item, top, bottom) {
81
+ this.items.push(item);
82
+ this.ascent = Math.max(this.ascent, -top);
83
+ this.descent = Math.max(this.descent, bottom);
84
+ }
85
+ done(width = this.right, italic = 0) {
86
+ return { width, ascent: this.ascent, descent: this.descent, items: this.items, italic };
87
+ }
88
+ }
89
+ // ---------------------------------------------------------------------------------------------
90
+ // Operator spacing.
91
+ const CLASSES = ['ord', 'op', 'bin', 'rel', 'open', 'close', 'punct', 'inner'];
92
+ /**
93
+ * TeX's inter-atom spacing table (rows: left atom, columns: right atom). 1 thin, 2 medium,
94
+ * 3 thick; negative entries apply only in display and text style, not in scripts.
95
+ */
96
+ const TABLE = [
97
+ /* ord */ [0, 1, -2, -3, 0, 0, 0, -1],
98
+ /* op */ [1, 1, 0, -3, 0, 0, 0, -1],
99
+ /* bin */ [-2, -2, 0, 0, -2, 0, 0, -2],
100
+ /* rel */ [-3, -3, 0, 0, -3, 0, 0, -3],
101
+ /* open */ [0, 0, 0, 0, 0, 0, 0, 0],
102
+ /* close */ [0, 1, -2, -3, 0, 0, 0, -1],
103
+ /* punct */ [-1, -1, 0, -1, -1, -1, -1, -1],
104
+ /* inner */ [-1, 1, -2, -3, -1, 0, -1, -1],
105
+ ];
106
+ const AMOUNT = [0, THIN, MEDIUM, THICK];
107
+ export function spaceBetween(left, right, ctx) {
108
+ const code = TABLE[CLASSES.indexOf(left)][CLASSES.indexOf(right)];
109
+ if (code < 0 && ctx.level > 0)
110
+ return 0;
111
+ return AMOUNT[Math.abs(code)] * em(ctx);
112
+ }
113
+ const UNARY_AFTER = new Set(['bin', 'op', 'rel', 'open', 'punct']);
114
+ const UNARY_BEFORE = new Set(['rel', 'close', 'punct']);
115
+ /**
116
+ * A binary operator with no left operand (start of a row, after an opening delimiter or another
117
+ * operator) or no right operand is unary: it becomes ordinary and gets no space ("−b", "(−1)").
118
+ */
119
+ export function resolveBinaries(atoms) {
120
+ const real = atoms.filter((a) => !a.kind);
121
+ for (let i = 0; i < real.length; i++) {
122
+ const a = real[i];
123
+ if (a.left !== 'bin' || a.right !== 'bin')
124
+ continue;
125
+ const prev = real[i - 1];
126
+ if (!prev || UNARY_AFTER.has(prev.right))
127
+ a.left = a.right = 'ord';
128
+ }
129
+ for (let i = 0; i < real.length; i++) {
130
+ const a = real[i];
131
+ if (a.left !== 'bin' || a.right !== 'bin')
132
+ continue;
133
+ const next = real[i + 1];
134
+ if (!next || UNARY_BEFORE.has(next.left))
135
+ a.left = a.right = 'ord';
136
+ }
137
+ }
138
+ /** Lay atoms side by side with operator spacing. `before` is the class of the atom to the left. */
139
+ export function hpack(atoms, ctx, before) {
140
+ const b = new Builder();
141
+ let x = 0;
142
+ let prev = before;
143
+ let first;
144
+ let last;
145
+ let real = 0;
146
+ let lastBox;
147
+ for (const a of atoms) {
148
+ if (a.kind === 'mark')
149
+ continue;
150
+ if (!a.kind) {
151
+ if (prev)
152
+ x += spaceBetween(prev, a.left, ctx);
153
+ prev = a.right;
154
+ first ??= a.left;
155
+ last = a.right;
156
+ real++;
157
+ }
158
+ b.put(a.box, x, 0);
159
+ x += a.box.width;
160
+ lastBox = a.box;
161
+ }
162
+ const box = b.done(x, lastBox?.italic ?? 0);
163
+ if (real === 1 && atoms.length === 1 && lastBox?.simple)
164
+ box.simple = true;
165
+ return { box, first, last };
166
+ }
@@ -0,0 +1,29 @@
1
+ /**
2
+ * Office Math (OMML) typesetting: lays out an m:oMath or m:oMathPara into a box of display items,
3
+ * and renders it as linear-format text. Line layout places the box like an inline object.
4
+ */
5
+ import type { DisplayItem, FontProvider } from '../layout/types.js';
6
+ import type { XmlElement } from '../xml/dom.js';
7
+ export { mathToText } from './linear.js';
8
+ export interface MathLayoutOptions {
9
+ fonts: FontProvider;
10
+ /** Font size of the equation's text (pt); scripts and limits are scaled from it. */
11
+ size: number;
12
+ /** Default colour (RRGGBB); run colours (w:color) override it. */
13
+ color: string;
14
+ /** Display style (an equation on its own line): big operators, limits above and below, full-size fractions. */
15
+ display: boolean;
16
+ }
17
+ export interface MathLayout {
18
+ width: number;
19
+ /**
20
+ * Ink extent above and below the baseline. Line layout should take the larger of these and
21
+ * the paragraph font's own ascent and descent, as it would for any inline object.
22
+ */
23
+ ascent: number;
24
+ descent: number;
25
+ /** Items relative to the left end of the (first) baseline: x right, y down. */
26
+ items: DisplayItem[];
27
+ }
28
+ /** Lay out an equation. An m:oMathPara stacks its equations, aligned by m:oMathParaPr/m:jc. */
29
+ export declare function layoutMath(node: XmlElement, options: MathLayoutOptions): MathLayout;
@@ -0,0 +1,44 @@
1
+ import { elements, firstChild } from '../xml/dom.js';
2
+ import { Builder } from './boxes.js';
3
+ import { mergeText, row } from './layout.js';
4
+ import { val } from './omml.js';
5
+ import { MathFonts, axisHeight } from './text.js';
6
+ export { mathToText } from './linear.js';
7
+ function rootContext(options) {
8
+ const fonts = new MathFonts(options.fonts);
9
+ return {
10
+ fonts,
11
+ base: options.size,
12
+ level: 0,
13
+ display: options.display,
14
+ cramped: false,
15
+ color: options.color,
16
+ axis: axisHeight(fonts),
17
+ fn: false,
18
+ align: false,
19
+ };
20
+ }
21
+ /** Lay out an equation. An m:oMathPara stacks its equations, aligned by m:oMathParaPr/m:jc. */
22
+ export function layoutMath(node, options) {
23
+ const ctx = rootContext(options);
24
+ const lines = node.name === 'm:oMathPara' ? elements(node, 'm:oMath') : [node];
25
+ const boxes = lines.map((line) => row(line, ctx).box);
26
+ if (boxes.length === 1) {
27
+ const box = boxes[0];
28
+ return { width: box.width, ascent: box.ascent, descent: box.descent, items: mergeText(box.items) };
29
+ }
30
+ const jc = val(firstChild(node, 'm:oMathParaPr'), 'm:jc') ?? 'centerGroup';
31
+ const width = Math.max(0, ...boxes.map((b) => b.width));
32
+ const size = options.size;
33
+ const b = new Builder();
34
+ let y = 0;
35
+ boxes.forEach((box, i) => {
36
+ const prev = boxes[i - 1];
37
+ // Baselines at least a single line apart (Cambria's line height), further when the equations are tall.
38
+ if (prev)
39
+ y += Math.max(prev.descent + 0.3 * size + box.ascent, 1.3 * size);
40
+ const x = jc === 'left' ? 0 : jc === 'right' ? width - box.width : (width - box.width) / 2;
41
+ b.put(box, x, y);
42
+ });
43
+ return { width, ascent: b.ascent, descent: b.descent, items: mergeText(b.items) };
44
+ }
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Equation layout: each OMML structure (fraction, scripts, radical, n-ary operator, delimiters,
3
+ * matrix, accent, …) is built into a box from the boxes of its arguments. Sizes and shifts follow
4
+ * TeX's rules and the Office math constants, scaled by the current style's em.
5
+ */
6
+ import type { DisplayItem } from '../layout/types.js';
7
+ import type { XmlElement } from '../xml/dom.js';
8
+ import type { Atom, AtomClass, Ctx, Row } from './boxes.js';
9
+ export declare function rowAtoms(container: XmlElement | undefined, ctx: Ctx): Atom[];
10
+ /** Lay out an argument (m:e, m:num, m:sub, m:oMath…) as a spaced row. */
11
+ export declare function row(container: XmlElement | undefined, ctx: Ctx, before?: AtomClass): Row;
12
+ /** Join neighbouring text items of one font, size and colour on one baseline (fewer items to draw). */
13
+ export declare function mergeText(items: DisplayItem[]): DisplayItem[];