docxkeun 0.1.3 → 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 +48 -0
  2. package/README.md +137 -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,17 @@
1
+ /**
2
+ * Glyph outlines from TrueType `glyf` data, for chart text that is rotated (vertical axis titles,
3
+ * rotated tick labels). Display-list TextItems are always horizontal, so rotated text is drawn as
4
+ * filled paths. Fonts without glyf outlines (CFF, or fonts known only by metrics) return undefined
5
+ * and the caller falls back to horizontal text.
6
+ */
7
+ import type { LayoutFont, PathCommand } from '../layout/types.js';
8
+ /** Whether rotated text can be drawn in this font. */
9
+ export declare function hasOutlines(font: LayoutFont): boolean;
10
+ /**
11
+ * Outline of a run of text as path commands. `place(u, v)` maps text space (u along the baseline from
12
+ * the run's start, v downward from the baseline, in points) to page space.
13
+ */
14
+ export declare function textOutline(chars: string[], font: LayoutFont, size: number, place: (u: number, v: number) => {
15
+ x: number;
16
+ y: number;
17
+ }): PathCommand[] | undefined;
@@ -0,0 +1,214 @@
1
+ const cache = new WeakMap();
2
+ function readGlyph(font, gid, depth) {
3
+ const range = font.glyphRange(gid);
4
+ if (!range)
5
+ return null;
6
+ if (range.length === 0)
7
+ return [];
8
+ const data = font.data;
9
+ const view = new DataView(data.buffer, data.byteOffset, data.byteLength);
10
+ let p = range.offset;
11
+ const numberOfContours = view.getInt16(p);
12
+ p += 10;
13
+ if (numberOfContours >= 0) {
14
+ const ends = [];
15
+ for (let i = 0; i < numberOfContours; i++, p += 2)
16
+ ends.push(view.getUint16(p));
17
+ const nPoints = numberOfContours ? ends[ends.length - 1] + 1 : 0;
18
+ p += 2 + view.getUint16(p); // instructions
19
+ const flags = [];
20
+ while (flags.length < nPoints) {
21
+ const f = view.getUint8(p++);
22
+ flags.push(f);
23
+ if (f & 8) {
24
+ const repeat = view.getUint8(p++);
25
+ for (let r = 0; r < repeat; r++)
26
+ flags.push(f);
27
+ }
28
+ }
29
+ const xs = [];
30
+ let v = 0;
31
+ for (const f of flags) {
32
+ if (f & 2) {
33
+ const d = view.getUint8(p++);
34
+ v += f & 16 ? d : -d;
35
+ }
36
+ else if (!(f & 16)) {
37
+ v += view.getInt16(p);
38
+ p += 2;
39
+ }
40
+ xs.push(v);
41
+ }
42
+ const ys = [];
43
+ v = 0;
44
+ for (const f of flags) {
45
+ if (f & 4) {
46
+ const d = view.getUint8(p++);
47
+ v += f & 32 ? d : -d;
48
+ }
49
+ else if (!(f & 32)) {
50
+ v += view.getInt16(p);
51
+ p += 2;
52
+ }
53
+ ys.push(v);
54
+ }
55
+ const contours = [];
56
+ let start = 0;
57
+ for (const end of ends) {
58
+ const c = [];
59
+ for (let i = start; i <= end; i++)
60
+ c.push({ x: xs[i], y: ys[i], on: (flags[i] & 1) === 1 });
61
+ contours.push(c);
62
+ start = end + 1;
63
+ }
64
+ return contours;
65
+ }
66
+ // Composite glyph: components with offsets and optional scale/2x2 transforms.
67
+ if (depth > 8)
68
+ return [];
69
+ const out = [];
70
+ let more = true;
71
+ while (more) {
72
+ const flags = view.getUint16(p);
73
+ const glyphIndex = view.getUint16(p + 2);
74
+ p += 4;
75
+ let dx;
76
+ let dy;
77
+ if (flags & 1) {
78
+ dx = view.getInt16(p);
79
+ dy = view.getInt16(p + 2);
80
+ p += 4;
81
+ }
82
+ else {
83
+ dx = view.getInt8(p);
84
+ dy = view.getInt8(p + 1);
85
+ p += 2;
86
+ }
87
+ if (!(flags & 2))
88
+ dx = dy = 0; // point matching: rare in text fonts, placed unshifted
89
+ let a = 1;
90
+ let b = 0;
91
+ let c = 0;
92
+ let d = 1;
93
+ const f2 = (o) => view.getInt16(o) / 16384;
94
+ if (flags & 8) {
95
+ a = d = f2(p);
96
+ p += 2;
97
+ }
98
+ else if (flags & 0x40) {
99
+ a = f2(p);
100
+ d = f2(p + 2);
101
+ p += 4;
102
+ }
103
+ else if (flags & 0x80) {
104
+ a = f2(p);
105
+ b = f2(p + 2);
106
+ c = f2(p + 4);
107
+ d = f2(p + 6);
108
+ p += 8;
109
+ }
110
+ const part = readGlyph(font, glyphIndex, depth + 1) ?? [];
111
+ for (const contour of part)
112
+ out.push(contour.map((pt) => ({ x: pt.x * a + pt.y * c + dx, y: pt.x * b + pt.y * d + dy, on: pt.on })));
113
+ more = (flags & 0x20) !== 0;
114
+ }
115
+ return out;
116
+ }
117
+ function glyphContours(font, gid) {
118
+ const face = font.face;
119
+ if (!face || !face.font.tables.has('glyf'))
120
+ return null;
121
+ let perFont = cache.get(face.font);
122
+ if (!perFont) {
123
+ perFont = new Map();
124
+ cache.set(face.font, perFont);
125
+ }
126
+ let contours = perFont.get(gid);
127
+ if (contours === undefined) {
128
+ try {
129
+ contours = readGlyph(face.font, gid, 0);
130
+ }
131
+ catch {
132
+ contours = null;
133
+ }
134
+ perFont.set(gid, contours);
135
+ }
136
+ return contours;
137
+ }
138
+ /** Whether rotated text can be drawn in this font. */
139
+ export function hasOutlines(font) {
140
+ return font.face !== undefined && font.face.font.tables.has('glyf');
141
+ }
142
+ /**
143
+ * Outline of a run of text as path commands. `place(u, v)` maps text space (u along the baseline from
144
+ * the run's start, v downward from the baseline, in points) to page space.
145
+ */
146
+ export function textOutline(chars, font, size, place) {
147
+ const face = font.face;
148
+ if (!face)
149
+ return undefined;
150
+ const scale = size / face.font.unitsPerEm;
151
+ const slant = font.syntheticItalic ? 0.2 : 0;
152
+ const cmds = [];
153
+ let pen = 0;
154
+ for (const ch of chars) {
155
+ const cp = ch.codePointAt(0);
156
+ const contours = glyphContours(font, font.glyphId(cp));
157
+ if (contours === null)
158
+ return undefined;
159
+ const map = (pt) => place(pen + (pt.x + pt.y * slant) * scale, -pt.y * scale);
160
+ for (const contour of contours) {
161
+ if (contour.length === 0)
162
+ continue;
163
+ // Start on an on-curve point (or the midpoint of two off-curve points).
164
+ const n = contour.length;
165
+ let startIdx = contour.findIndex((q) => q.on);
166
+ let start;
167
+ if (startIdx < 0) {
168
+ const a = contour[0];
169
+ const b = contour[n - 1];
170
+ start = { x: (a.x + b.x) / 2, y: (a.y + b.y) / 2 };
171
+ startIdx = 0; // all off-curve: begin between the last and first points
172
+ }
173
+ else
174
+ start = contour[startIdx];
175
+ const s = map(start);
176
+ cmds.push({ op: 'M', x: s.x, y: s.y });
177
+ let cur = start;
178
+ let ctrl;
179
+ const allOff = !contour[startIdx].on;
180
+ const total = allOff ? n : n - 1;
181
+ const quad = (c, to) => {
182
+ const p0 = map(cur);
183
+ const pc = map(c);
184
+ const p1 = map(to);
185
+ cmds.push({ op: 'C', x1: p0.x + (2 / 3) * (pc.x - p0.x), y1: p0.y + (2 / 3) * (pc.y - p0.y), x2: p1.x + (2 / 3) * (pc.x - p1.x), y2: p1.y + (2 / 3) * (pc.y - p1.y), x: p1.x, y: p1.y });
186
+ cur = to;
187
+ };
188
+ for (let k = 1; k <= total + 1; k++) {
189
+ const pt = k <= total ? contour[(startIdx + k + (allOff ? -1 : 0) + n) % n] : undefined;
190
+ const target = pt ?? { x: start.x, y: start.y, on: true };
191
+ if (target.on) {
192
+ if (ctrl)
193
+ quad(ctrl, target);
194
+ else {
195
+ const t = map(target);
196
+ cmds.push({ op: 'L', x: t.x, y: t.y });
197
+ cur = target;
198
+ }
199
+ ctrl = undefined;
200
+ }
201
+ else if (ctrl) {
202
+ const mid = { x: (ctrl.x + target.x) / 2, y: (ctrl.y + target.y) / 2 };
203
+ quad(ctrl, mid);
204
+ ctrl = target;
205
+ }
206
+ else
207
+ ctrl = target;
208
+ }
209
+ cmds.push({ op: 'Z' });
210
+ }
211
+ pen += font.advance(cp) * size;
212
+ }
213
+ return cmds;
214
+ }
@@ -0,0 +1,20 @@
1
+ import type { DisplayItem, FontProvider } from '../layout/types.js';
2
+ import type { XmlElement } from '../xml/dom.js';
3
+ import { type ChartModel } from './model.js';
4
+ export interface ChartFrame {
5
+ x: number;
6
+ y: number;
7
+ w: number;
8
+ h: number;
9
+ }
10
+ export interface RenderChartOptions {
11
+ fonts: FontProvider;
12
+ /** Theme colours by scheme name (accent1, tx1, bg1, …) → RRGGBB. */
13
+ schemeColor(name: string): string | undefined;
14
+ /** Font for chart text that names none (default Calibri, the Office theme's body font). */
15
+ defaultFont?: string;
16
+ }
17
+ /** Read a c:chartSpace and draw it into `frame`. */
18
+ export declare function renderChart(chartSpace: XmlElement, frame: ChartFrame, options: RenderChartOptions): DisplayItem[];
19
+ /** Draw an already-read chart model into `frame`. */
20
+ export declare function drawChart(model: ChartModel, frame: ChartFrame, options: RenderChartOptions): DisplayItem[];