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
@@ -0,0 +1,450 @@
1
+ /** Closed polygons (y up) as path commands (y down). */
2
+ export function polygons(shapes) {
3
+ const out = [];
4
+ for (const pts of shapes) {
5
+ if (pts.length < 2)
6
+ continue;
7
+ pts.forEach(([x, y], i) => out.push({ op: i === 0 ? 'M' : 'L', x, y: -y }));
8
+ out.push({ op: 'Z' });
9
+ }
10
+ return out;
11
+ }
12
+ /** An ellipse (y up) as four cubic arcs (y down). */
13
+ export function ellipse(cx, cy, rx, ry) {
14
+ const k = 0.5523;
15
+ const y = -cy;
16
+ return [
17
+ { op: 'M', x: cx + rx, y },
18
+ { op: 'C', x1: cx + rx, y1: y - ry * k, x2: cx + rx * k, y2: y - ry, x: cx, y: y - ry },
19
+ { op: 'C', x1: cx - rx * k, y1: y - ry, x2: cx - rx, y2: y - ry * k, x: cx - rx, y },
20
+ { op: 'C', x1: cx - rx, y1: y + ry * k, x2: cx - rx * k, y2: y + ry, x: cx, y: y + ry },
21
+ { op: 'C', x1: cx + rx * k, y1: y + ry, x2: cx + rx, y2: y + ry * k, x: cx + rx, y },
22
+ { op: 'Z' },
23
+ ];
24
+ }
25
+ export function filled(commands, color) {
26
+ return { type: 'path', commands, fill: color };
27
+ }
28
+ export function stroked(commands, color, width) {
29
+ return { type: 'path', commands, stroke: color, strokeWidth: width, lineCap: 'round', lineJoin: 'round' };
30
+ }
31
+ function intersect(p, d, q, e) {
32
+ const den = d[0] * e[1] - d[1] * e[0];
33
+ if (Math.abs(den) < 1e-9)
34
+ return undefined;
35
+ const t = ((q[0] - p[0]) * e[1] - (q[1] - p[1]) * e[0]) / den;
36
+ return [p[0] + d[0] * t, p[1] + d[1] * t];
37
+ }
38
+ /**
39
+ * Outline of a polyline stroked with a width per segment. Joins are mitred, falling back to a
40
+ * bevel when the mitre would reach further than `limit` half-widths (very sharp corners).
41
+ */
42
+ export function strokeOutline(pts, widths, limit = 3) {
43
+ const n = pts.length;
44
+ const dirs = [];
45
+ for (let i = 0; i < n - 1; i++) {
46
+ const [x0, y0] = pts[i];
47
+ const [x1, y1] = pts[i + 1];
48
+ const len = Math.hypot(x1 - x0, y1 - y0) || 1;
49
+ dirs.push([(x1 - x0) / len, (y1 - y0) / len]);
50
+ }
51
+ const side = (sign) => {
52
+ const out = [];
53
+ const offset = (p, seg) => {
54
+ const d = dirs[seg];
55
+ const h = (widths[seg] / 2) * sign;
56
+ return [p[0] - d[1] * h, p[1] + d[0] * h];
57
+ };
58
+ for (let i = 0; i < n; i++) {
59
+ const p = pts[i];
60
+ if (i === 0)
61
+ out.push(offset(p, 0));
62
+ else if (i === n - 1)
63
+ out.push(offset(p, n - 2));
64
+ else {
65
+ const a = offset(p, i - 1);
66
+ const b = offset(p, i);
67
+ const hit = intersect(a, dirs[i - 1], b, dirs[i]);
68
+ const reach = limit * Math.max(widths[i - 1], widths[i]) * 0.5;
69
+ if (hit && Math.hypot(hit[0] - p[0], hit[1] - p[1]) <= reach)
70
+ out.push(hit);
71
+ else
72
+ out.push(a, b);
73
+ }
74
+ }
75
+ return out;
76
+ };
77
+ return [...side(1), ...side(-1).reverse()];
78
+ }
79
+ /** Outline of a sampled curve stroked with a width that varies along it (s from 0 to 1). */
80
+ export function taperOutline(pts, width) {
81
+ const n = pts.length;
82
+ const lengths = [0];
83
+ for (let i = 1; i < n; i++)
84
+ lengths.push(lengths[i - 1] + Math.hypot(pts[i][0] - pts[i - 1][0], pts[i][1] - pts[i - 1][1]));
85
+ const total = lengths[n - 1] || 1;
86
+ const left = [];
87
+ const right = [];
88
+ for (let i = 0; i < n; i++) {
89
+ const a = pts[Math.max(0, i - 1)];
90
+ const b = pts[Math.min(n - 1, i + 1)];
91
+ const len = Math.hypot(b[0] - a[0], b[1] - a[1]) || 1;
92
+ const nx = -(b[1] - a[1]) / len;
93
+ const ny = (b[0] - a[0]) / len;
94
+ const h = width(lengths[i] / total) / 2;
95
+ const p = pts[i];
96
+ left.push([p[0] + nx * h, p[1] + ny * h]);
97
+ right.push([p[0] - nx * h, p[1] - ny * h]);
98
+ }
99
+ return [...left, ...right.reverse()];
100
+ }
101
+ /** Points along a cubic Bézier, without its first point (so pieces concatenate). */
102
+ function cubic(p0, p1, p2, p3, steps) {
103
+ const out = [];
104
+ for (let i = 1; i <= steps; i++) {
105
+ const t = i / steps;
106
+ const u = 1 - t;
107
+ const a = u * u * u;
108
+ const b = 3 * u * u * t;
109
+ const c = 3 * u * t * t;
110
+ const d = t * t * t;
111
+ out.push([a * p0[0] + b * p1[0] + c * p2[0] + d * p3[0], a * p0[1] + b * p1[1] + c * p2[1] + d * p3[1]]);
112
+ }
113
+ return out;
114
+ }
115
+ function line(p0, p1, steps) {
116
+ const out = [];
117
+ for (let i = 1; i <= steps; i++)
118
+ out.push([p0[0] + ((p1[0] - p0[0]) * i) / steps, p0[1] + ((p1[1] - p0[1]) * i) / steps]);
119
+ return out;
120
+ }
121
+ /** Thickness that rises from `thin` at both ends to `thick`, reaching it a fraction `ramp` in. */
122
+ function profile(thin, thick, ramp) {
123
+ return (s) => {
124
+ const t = Math.min(1, Math.min(s, 1 - s) / ramp);
125
+ return thin + (thick - thin) * Math.sin((t * Math.PI) / 2);
126
+ };
127
+ }
128
+ /** A vertical delimiter occupying x0..x0+W and y bottom..bottom+L (y up). */
129
+ export function verticalFrame(x0, width, bottom, side) {
130
+ return side === 'left' ? (a, c) => [x0 + c, bottom + a] : (a, c) => [x0 + width - c, bottom + a];
131
+ }
132
+ /** A horizontal delimiter occupying x0..x0+L and y bottom..bottom+W (y up). */
133
+ export function horizontalFrame(x0, depth, bottom, outer) {
134
+ return outer === 'top' ? (a, c) => [x0 + a, bottom + depth - c] : (a, c) => [x0 + a, bottom + c];
135
+ }
136
+ /** Natural thickness (across) of a stretchy delimiter of length L, before side bearings. */
137
+ export function delimiterWidth(kind, L, em) {
138
+ const grow = Math.max(0, L / em - 1);
139
+ switch (kind) {
140
+ case 'paren':
141
+ return Math.min(0.3 + 0.05 * grow, 0.55) * em;
142
+ case 'bracket':
143
+ case 'ceil':
144
+ case 'floor':
145
+ return Math.min(0.26 + 0.02 * grow, 0.36) * em;
146
+ case 'brace':
147
+ return Math.min(0.36 + 0.04 * grow, 0.55) * em;
148
+ case 'angle':
149
+ return Math.min(0.3 + 0.05 * grow, 0.5) * em;
150
+ case 'bar':
151
+ return 0.07 * em;
152
+ case 'dbar':
153
+ return 0.2 * em;
154
+ }
155
+ }
156
+ /** Polygons of a stretchy delimiter in (along, across) coordinates. */
157
+ export function delimiterShape(kind, L, W, em) {
158
+ const grow = Math.max(0, L / em - 1);
159
+ switch (kind) {
160
+ case 'paren': {
161
+ const thick = Math.min(0.075 + 0.012 * grow, 0.11) * em;
162
+ const thin = 0.022 * em;
163
+ const mid = thick / 2;
164
+ const r = Math.min(L / 2, 0.9 * em);
165
+ let pts;
166
+ if (L / 2 <= r + 1e-9) {
167
+ // One symmetric arc; the control points put its middle at `mid`.
168
+ const c = (8 * mid - 2 * W) / 6;
169
+ pts = [[L, W], ...cubic([L, W], [L * 0.7, c], [L * 0.3, c], [0, W], 32)];
170
+ }
171
+ else {
172
+ // Tall: curved ends joined by a straight stretch, as in big parenthesis glyphs.
173
+ const top = cubic([L, W], [L - r * 0.25, W - (W - mid) * 0.5], [L - r * 0.45, mid], [L - r, mid], 16);
174
+ const straight = line([L - r, mid], [r, mid], 8);
175
+ const bottom = cubic([r, mid], [r * 0.45, mid], [r * 0.25, W - (W - mid) * 0.5], [0, W], 16);
176
+ pts = [[L, W], ...top, ...straight, ...bottom];
177
+ }
178
+ return [taperOutline(pts, profile(thin, thick, Math.min(0.5, r / L)))];
179
+ }
180
+ case 'bracket':
181
+ case 'ceil':
182
+ case 'floor': {
183
+ const stem = Math.min(0.06 + 0.006 * grow, 0.085) * em;
184
+ const arm = 0.045 * em;
185
+ const top = kind !== 'floor';
186
+ const bottom = kind !== 'ceil';
187
+ const pts = [[L, 0]];
188
+ if (top)
189
+ pts.push([L, W], [L - arm, W], [L - arm, stem]);
190
+ else
191
+ pts.push([L, stem]);
192
+ if (bottom)
193
+ pts.push([arm, stem], [arm, W], [0, W]);
194
+ else
195
+ pts.push([0, stem]);
196
+ pts.push([0, 0]);
197
+ return [pts];
198
+ }
199
+ case 'brace': {
200
+ const half = L / 2;
201
+ const stemAt = W / 2;
202
+ const r = Math.min(0.2 * em, half / 2);
203
+ const thick = Math.min(0.075 + 0.008 * grow, 0.1) * em;
204
+ const thin = 0.02 * em;
205
+ // Upper half from the tip to the cusp; the lower half mirrors it.
206
+ const tip = [L, W];
207
+ const pts = [
208
+ tip,
209
+ ...cubic(tip, [L, W - (W - stemAt) * 0.55], [L - r * 0.45, stemAt], [L - r, stemAt], 10),
210
+ ...line([L - r, stemAt], [half + r, stemAt], 6),
211
+ ...cubic([half + r, stemAt], [half + r * 0.45, stemAt], [half, stemAt * 0.55], [half, 0], 10),
212
+ ];
213
+ const upper = taperOutline(pts, profile(thin, thick, 0.35));
214
+ const lower = upper.map(([a, c]) => [L - a, c]);
215
+ return [upper, lower];
216
+ }
217
+ case 'angle': {
218
+ const t = 0.05 * em;
219
+ return [strokeOutline([[L, W - t / 2], [L / 2, t / 2], [0, W - t / 2]], [t, t], 6)];
220
+ }
221
+ case 'bar': {
222
+ const t = 0.055 * em;
223
+ const c = W / 2;
224
+ return [[[0, c - t / 2], [L, c - t / 2], [L, c + t / 2], [0, c + t / 2]]];
225
+ }
226
+ case 'dbar': {
227
+ const t = 0.05 * em;
228
+ const gap = 0.09 * em;
229
+ const c = W / 2;
230
+ return [c - gap / 2 - t / 2, c + gap / 2 + t / 2].map((m) => [[0, m - t / 2], [L, m - t / 2], [L, m + t / 2], [0, m + t / 2]]);
231
+ }
232
+ }
233
+ }
234
+ export function mapShape(shape, frame) {
235
+ return shape.map((pts) => pts.map(([a, c]) => frame(a, c)));
236
+ }
237
+ // ---------------------------------------------------------------------------------------------
238
+ // Radical sign: a short rising hook, a thick downstroke, a thin upstroke and the overbar, all one
239
+ // polygon so the joins are clean. Coordinates y up; the sign starts at x0, its vertex at `bottom`.
240
+ export function radicalShape(x0, bottom, signWidth, top, barEnd, rule, em) {
241
+ const height = top - bottom;
242
+ const hook = Math.min(0.48 * em, height * 0.5);
243
+ const thick = 0.085 * em;
244
+ const p0 = [x0 + 0.02 * em, bottom + hook * 0.86];
245
+ const p1 = [x0 + 0.12 * em, bottom + hook];
246
+ const p2 = [x0 + Math.min(0.29 * em, signWidth * 0.5), bottom + 0.05 * em];
247
+ const p3 = [x0 + signWidth, top - rule / 2];
248
+ const p4 = [barEnd, top - rule / 2];
249
+ return strokeOutline([p0, p1, p2, p3, p4], [rule * 0.9, thick, rule, rule], 4);
250
+ }
251
+ // ---------------------------------------------------------------------------------------------
252
+ // Integral signs: a slanted stroke with curled ends and ball terminals, scaled to any height.
253
+ /** Polygons and terminal circles of an integral in the box x0..x0+W, bottom..bottom+H (y up). */
254
+ export function integralShape(x0, bottom, W, H, em) {
255
+ const P = (x, y) => [x0 + x * W, bottom + y * H];
256
+ const start = P(0.98, 0.9);
257
+ const pts = [
258
+ start,
259
+ ...cubic(start, P(0.95, 1.0), P(0.78, 1.02), P(0.68, 0.88), 12),
260
+ ...line(P(0.68, 0.88), P(0.32, 0.12), 12),
261
+ ...cubic(P(0.32, 0.12), P(0.22, -0.02), P(0.05, 0.0), P(0.02, 0.1), 12),
262
+ ];
263
+ const big = H > 1.6 * em;
264
+ const thick = (big ? 0.085 : 0.07) * em;
265
+ const outline = taperOutline(pts, profile(0.02 * em, thick, 0.3));
266
+ const r = (big ? 0.05 : 0.04) * em;
267
+ const end = pts[pts.length - 1];
268
+ return { outline, balls: [[start[0] - r * 0.4, start[1] - r * 0.2, r], [end[0] + r * 0.4, end[1] + r * 0.2, r]] };
269
+ }
270
+ /** Big operators drawn as shapes (y up) in x0..x0+W, bottom..bottom+H. Returns undefined for unknown ones. */
271
+ export function bigOperatorPaths(ch, x0, bottom, W, H, em, color) {
272
+ const t = Math.max(0.065, Math.min(0.09, H / em / 18)) * em;
273
+ const top = bottom + H;
274
+ const rect = (xa, ya, xb, yb) => [[xa, ya], [xb, ya], [xb, yb], [xa, yb]];
275
+ switch (ch) {
276
+ case '∏':
277
+ case '∐': {
278
+ const bar = t * 0.8;
279
+ const stem = t * 1.15;
280
+ const serif = 0.08 * em;
281
+ const inset = 0.1 * W;
282
+ const shapes = [
283
+ rect(x0, top - bar, x0 + W, top),
284
+ rect(x0 + inset, bottom, x0 + inset + stem, top),
285
+ rect(x0 + W - inset - stem, bottom, x0 + W - inset, top),
286
+ rect(x0 + inset - serif, bottom, x0 + inset + stem + serif, bottom + bar * 0.7),
287
+ rect(x0 + W - inset - stem - serif, bottom, x0 + W - inset + serif, bottom + bar * 0.7),
288
+ ];
289
+ // ∐ is ∏ upside down.
290
+ const flipped = ch === '∐' ? shapes.map((pts) => pts.map(([x, y]) => [x, bottom + top - y])) : shapes;
291
+ return [filled(polygons(flipped), color)];
292
+ }
293
+ case '∑': {
294
+ const pts = strokeOutline([[x0 + W, top - t * 0.4], [x0 + t * 0.4, top - t * 0.4], [x0 + W * 0.55, bottom + H / 2], [x0 + t * 0.4, bottom + t * 0.4], [x0 + W, bottom + t * 0.4]], [t * 0.8, t * 1.2, t * 0.7, t * 0.8], 8);
295
+ return [filled(polygons([pts]), color)];
296
+ }
297
+ case '⋃':
298
+ case '⋂': {
299
+ const r = W / 2 - t / 2;
300
+ const cx = x0 + W / 2;
301
+ const up = ch === '⋃';
302
+ const yEnd = up ? top : bottom;
303
+ const yTurn = up ? bottom + t / 2 + r : top - t / 2 - r;
304
+ const yTip = up ? bottom + t / 2 : top - t / 2;
305
+ const k = 0.5523 * r;
306
+ const d = [
307
+ { op: 'M', x: cx - r, y: -yEnd },
308
+ { op: 'L', x: cx - r, y: -yTurn },
309
+ { op: 'C', x1: cx - r, y1: -(yTurn + (up ? -k : k)), x2: cx - k, y2: -yTip, x: cx, y: -yTip },
310
+ { op: 'C', x1: cx + k, y1: -yTip, x2: cx + r, y2: -(yTurn + (up ? -k : k)), x: cx + r, y: -yTurn },
311
+ { op: 'L', x: cx + r, y: -yEnd },
312
+ ];
313
+ return [{ ...stroked(d, color, t), lineCap: 'butt' }];
314
+ }
315
+ case '⋁':
316
+ case '⋀': {
317
+ const down = ch === '⋁';
318
+ const pts = down
319
+ ? [[x0 + t / 2, top], [x0 + W / 2, bottom + t / 2], [x0 + W - t / 2, top]]
320
+ : [[x0 + t / 2, bottom], [x0 + W / 2, top - t / 2], [x0 + W - t / 2, bottom]];
321
+ return [filled(polygons([strokeOutline(pts, [t * 0.6, t * 1.1], 8)]), color)];
322
+ }
323
+ case '⨀':
324
+ case '⨁':
325
+ case '⨂': {
326
+ const r = Math.min(W, H) / 2 - t / 2;
327
+ const cx = x0 + W / 2;
328
+ const cy = bottom + H / 2;
329
+ const items = [stroked(ellipse(cx, cy, r, r), color, t * 0.8)];
330
+ if (ch === '⨀')
331
+ items.push(filled(ellipse(cx, cy, t * 1.2, t * 1.2), color));
332
+ else {
333
+ const d = ch === '⨁' ? r : r * Math.SQRT1_2;
334
+ const segs = ch === '⨁' ? [[[cx - d, cy], [cx + d, cy]], [[cx, cy - d], [cx, cy + d]]] : [[[cx - d, cy - d], [cx + d, cy + d]], [[cx - d, cy + d], [cx + d, cy - d]]];
335
+ for (const [a, b] of segs)
336
+ items.push({ ...stroked([{ op: 'M', x: a[0], y: -a[1] }, { op: 'L', x: b[0], y: -b[1] }], color, t * 0.8), lineCap: 'butt' });
337
+ }
338
+ return items;
339
+ }
340
+ default:
341
+ return undefined;
342
+ }
343
+ }
344
+ // ---------------------------------------------------------------------------------------------
345
+ // Arrows (stretchy group characters and vector accents), y up, from x0 to x1 centred on y.
346
+ export function arrowPaths(x0, x1, y, em, spec, color, small) {
347
+ const t = (small ? 0.04 : 0.05) * em;
348
+ const headLength = (small ? 0.16 : 0.24) * em;
349
+ const headHalf = (small ? 0.075 : 0.12) * em * (spec.double ? 1.5 : 1);
350
+ const shapes = [];
351
+ const notch = headLength * (spec.double ? 0.45 : 0.6);
352
+ const sx0 = spec.left ? x0 + notch : x0;
353
+ const sx1 = spec.right ? x1 - notch : x1;
354
+ const shafts = spec.double ? [y + 0.08 * em, y - 0.08 * em] : [y];
355
+ for (const sy of shafts)
356
+ shapes.push([[sx0, sy - t / 2], [sx1, sy - t / 2], [sx1, sy + t / 2], [sx0, sy + t / 2]]);
357
+ const head = (tip, dir) => {
358
+ const back = tip - dir * headLength;
359
+ const inner = tip - dir * notch;
360
+ if (spec.harpoon)
361
+ return [[tip, y - t / 2], [back, y + headHalf], [inner, y + t / 2], [back + dir * 0.0, y - t / 2]];
362
+ return [[tip, y], [back, y + headHalf], [inner, y], [back, y - headHalf]];
363
+ };
364
+ if (spec.right)
365
+ shapes.push(head(x1, 1));
366
+ if (spec.left)
367
+ shapes.push(head(x0, -1));
368
+ return [filled(polygons(shapes), color)];
369
+ }
370
+ // ---------------------------------------------------------------------------------------------
371
+ // Accents, drawn above a base from x0 over width w with their lowest ink at y (y up).
372
+ /** Natural width of an accent (em), and whether it stretches over wide bases. */
373
+ export function accentMetrics(kind) {
374
+ switch (kind) {
375
+ case 'hat':
376
+ case 'check':
377
+ return { width: 0.32, stretch: true };
378
+ case 'tilde':
379
+ return { width: 0.34, stretch: true };
380
+ case 'bar':
381
+ case 'arrow':
382
+ return { width: 0.36, stretch: true };
383
+ case 'ddot':
384
+ return { width: 0.26, stretch: false };
385
+ case 'dddot':
386
+ return { width: 0.42, stretch: false };
387
+ default:
388
+ return { width: 0.2, stretch: false };
389
+ }
390
+ }
391
+ /** Draw an accent; returns the items and the accent's ink height. */
392
+ export function accentPaths(kind, x0, w, y, em, color, arrow) {
393
+ const t = 0.045 * em;
394
+ const cx = x0 + w / 2;
395
+ switch (kind) {
396
+ case 'hat':
397
+ case 'check': {
398
+ const h = Math.min(0.13 * em + 0.04 * w, 0.3 * em);
399
+ const pts = kind === 'hat' ? [[x0, y + t / 2], [cx, y + h - t / 2], [x0 + w, y + t / 2]] : [[x0, y + h - t / 2], [cx, y + t / 2], [x0 + w, y + h - t / 2]];
400
+ return { items: [filled(polygons([strokeOutline(pts, [t * 0.8, t * 1.2], 8)]), color)], height: h };
401
+ }
402
+ case 'tilde': {
403
+ const h = Math.min(0.09 * em + 0.025 * w, 0.2 * em);
404
+ const pts = [];
405
+ for (let i = 0; i <= 24; i++) {
406
+ const s = i / 24;
407
+ pts.push([x0 + s * w, y + t / 2 + ((h - t) / 2) * (1 + Math.sin(2 * Math.PI * s - Math.PI * 0.15))]);
408
+ }
409
+ return { items: [filled(polygons([taperOutline(pts, profile(t * 0.5, t * 1.2, 0.3))]), color)], height: h };
410
+ }
411
+ case 'bar':
412
+ return { items: [filled(polygons([[[x0, y], [x0 + w, y], [x0 + w, y + t], [x0, y + t]]]), color)], height: t };
413
+ case 'dot':
414
+ case 'ddot':
415
+ case 'dddot': {
416
+ const r = 0.05 * em;
417
+ const n = kind === 'dot' ? 1 : kind === 'ddot' ? 2 : 3;
418
+ const gap = 0.16 * em;
419
+ const commands = [];
420
+ for (let i = 0; i < n; i++)
421
+ commands.push(...ellipse(cx + (i - (n - 1) / 2) * gap, y + r, r, r));
422
+ return { items: [filled(commands, color)], height: 2 * r };
423
+ }
424
+ case 'acute':
425
+ case 'grave': {
426
+ const h = 0.16 * em;
427
+ const pts = kind === 'acute' ? [[cx - 0.05 * em, y], [cx + 0.07 * em, y + h]] : [[cx + 0.05 * em, y], [cx - 0.07 * em, y + h]];
428
+ return { items: [filled(polygons([strokeOutline(pts, [t * 1.4])]), color)], height: h };
429
+ }
430
+ case 'breve': {
431
+ const h = 0.12 * em;
432
+ const r = 0.12 * em;
433
+ const pts = [];
434
+ for (let i = 0; i <= 16; i++) {
435
+ const a = Math.PI + (Math.PI * i) / 16;
436
+ pts.push([cx + r * Math.cos(a), y + h + h * Math.sin(a) * 0.9]);
437
+ }
438
+ return { items: [filled(polygons([taperOutline(pts, profile(t * 0.5, t * 1.2, 0.4))]), color)], height: h };
439
+ }
440
+ case 'ring': {
441
+ const r = 0.075 * em;
442
+ return { items: [stroked(ellipse(cx, y + r, r - t / 3, r - t / 3), color, t * 0.7)], height: 2 * r };
443
+ }
444
+ case 'arrow': {
445
+ const spec = arrow ?? { left: false, right: true, double: false, harpoon: false };
446
+ const h = 0.15 * em;
447
+ return { items: arrowPaths(x0, x0 + w, y + h / 2, em, spec, color, true), height: h };
448
+ }
449
+ }
450
+ }
@@ -0,0 +1,49 @@
1
+ /**
2
+ * Character knowledge for equations: the atom class of each operator (which decides the TeX-style
3
+ * spacing Word applies), the function names Word sets upright, the Unicode mathematical
4
+ * alphanumerics, and the accents, delimiters and big operators that layout draws itself.
5
+ */
6
+ import type { AtomClass } from './boxes.js';
7
+ export declare function charClass(ch: string): AtomClass;
8
+ export declare function displayChar(ch: string): string;
9
+ /** Look-alikes for symbols no registered font has (the bundled fonts lack many math symbols). */
10
+ export declare const GLYPH_FALLBACK: Record<string, string>;
11
+ /** Function names Word sets upright when they appear as a whole word. */
12
+ export declare const FUNCTION_NAMES: Set<string>;
13
+ export declare function isDigit(ch: string): boolean;
14
+ /** Latin and Greek letters: the characters Word's math italic applies to. */
15
+ export declare function isLetter(cp: number): boolean;
16
+ export declare function isSpace(ch: string): boolean;
17
+ export type Script = 'roman' | 'script' | 'fraktur' | 'double-struck' | 'sans-serif' | 'monospace';
18
+ export interface MathAlpha {
19
+ base: string;
20
+ script: Script;
21
+ bold: boolean;
22
+ italic: boolean;
23
+ }
24
+ export declare function decodeMathAlpha(cp: number): MathAlpha | undefined;
25
+ /** The mathematical alphanumeric for a letter or digit in a style, when Unicode has one. */
26
+ export declare function encodeMathAlpha(base: string, script: Script, bold: boolean, italic: boolean): number | undefined;
27
+ export type DelimiterKind = 'paren' | 'bracket' | 'ceil' | 'floor' | 'brace' | 'angle' | 'bar' | 'dbar';
28
+ export declare function delimiterOf(ch: string): {
29
+ kind: DelimiterKind;
30
+ side: 'left' | 'right' | 'both';
31
+ } | undefined;
32
+ export declare function groupShapeOf(ch: string): {
33
+ kind: DelimiterKind | 'arrow';
34
+ outer: 'top' | 'bottom';
35
+ } | undefined;
36
+ export declare function arrowOf(ch: string): {
37
+ left: boolean;
38
+ right: boolean;
39
+ double: boolean;
40
+ harpoon: boolean;
41
+ } | undefined;
42
+ export type AccentKind = 'hat' | 'check' | 'tilde' | 'bar' | 'dot' | 'ddot' | 'dddot' | 'acute' | 'grave' | 'breve' | 'ring' | 'arrow';
43
+ export declare function accentOf(ch: string): AccentKind | undefined;
44
+ export declare function integralOf(ch: string): {
45
+ count: number;
46
+ contour: boolean;
47
+ } | undefined;
48
+ /** Big operators layout always draws (the bundled fonts lack them, or their glyphs would not scale well). */
49
+ export declare const DRAWN_OPERATORS: Set<string>;