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,758 @@
1
+ /**
2
+ * Reads a chart part (c:chartSpace) into a plain model: plots and their series with the cached
3
+ * values (there is no spreadsheet engine), axes, title, legend, data labels and resolved colours.
4
+ * Automatic formatting (series palette, default line widths) is resolved here so the renderer and
5
+ * any other consumer see the colours Office would show.
6
+ */
7
+ import { attr, elements, firstChild, textContent } from '../xml/dom.js';
8
+ import { adjustLightness, fillOf, lineOf, lookupScheme, schemeVariant } from './color.js';
9
+ import { formatNumber } from './format.js';
10
+ // ---------------------------------------------------------------------------------------------
11
+ // Small readers
12
+ /** CT_Boolean: an element without `val` means true. */
13
+ function bool(parent, name, dflt) {
14
+ const node = firstChild(parent, name);
15
+ if (!node)
16
+ return dflt;
17
+ const v = attr(node, 'val');
18
+ return v === undefined || v === '1' || v === 'true';
19
+ }
20
+ function num(parent, name) {
21
+ const v = attr(firstChild(parent, name), 'val');
22
+ if (v === undefined)
23
+ return undefined;
24
+ const n = Number.parseFloat(v);
25
+ return Number.isFinite(n) ? n : undefined;
26
+ }
27
+ function str(parent, name) {
28
+ return attr(firstChild(parent, name), 'val');
29
+ }
30
+ /** Elements may sit inside mc:AlternateContent; take the fallback (it uses the c: namespace). */
31
+ function childOrFallback(parent, name) {
32
+ const direct = firstChild(parent, name);
33
+ if (direct || !parent)
34
+ return direct;
35
+ for (const alt of elements(parent, 'mc:AlternateContent')) {
36
+ for (const branch of [...elements(alt, 'mc:Choice'), ...elements(alt, 'mc:Fallback')]) {
37
+ const found = firstChild(branch, name);
38
+ if (found)
39
+ return found;
40
+ }
41
+ }
42
+ return undefined;
43
+ }
44
+ function readLayout(parent) {
45
+ const m = firstChild(firstChild(parent, 'c:layout'), 'c:manualLayout');
46
+ if (!m)
47
+ return undefined;
48
+ const mode = (name) => (str(m, name) === 'edge' ? 'edge' : 'factor');
49
+ const layout = {
50
+ target: str(m, 'c:layoutTarget') === 'inner' ? 'inner' : 'outer',
51
+ xMode: mode('c:xMode'),
52
+ yMode: mode('c:yMode'),
53
+ wMode: mode('c:wMode'),
54
+ hMode: mode('c:hMode'),
55
+ };
56
+ const x = num(m, 'c:x');
57
+ const y = num(m, 'c:y');
58
+ const w = num(m, 'c:w');
59
+ const h = num(m, 'c:h');
60
+ if (x !== undefined)
61
+ layout.x = x;
62
+ if (y !== undefined)
63
+ layout.y = y;
64
+ if (w !== undefined)
65
+ layout.w = w;
66
+ if (h !== undefined)
67
+ layout.h = h;
68
+ return layout.x === undefined && layout.y === undefined && layout.w === undefined && layout.h === undefined ? undefined : layout;
69
+ }
70
+ function resolveLine(props, dflt) {
71
+ const out = { paint: props.paint === undefined ? dflt.paint : props.paint, width: props.width ?? dflt.width };
72
+ const dash = props.dash ?? dflt.dash;
73
+ if (dash)
74
+ out.dash = dash;
75
+ const cap = props.cap ?? dflt.cap;
76
+ if (cap)
77
+ out.cap = cap;
78
+ const join = props.join ?? dflt.join;
79
+ if (join)
80
+ out.join = join;
81
+ return out;
82
+ }
83
+ /** Character properties (a:defRPr / a:rPr) over a base style. */
84
+ function applyRunProps(base, rPr, scheme) {
85
+ if (!rPr)
86
+ return base;
87
+ const out = { ...base };
88
+ const sz = attr(rPr, 'sz');
89
+ if (sz !== undefined && Number.isFinite(Number(sz)))
90
+ out.size = Number(sz) / 100;
91
+ const b = attr(rPr, 'b');
92
+ if (b !== undefined)
93
+ out.bold = b === '1' || b === 'true';
94
+ const i = attr(rPr, 'i');
95
+ if (i !== undefined)
96
+ out.italic = i === '1' || i === 'true';
97
+ const fill = fillOf(rPr, scheme);
98
+ if (fill)
99
+ out.color = fill.color;
100
+ const typeface = attr(firstChild(rPr, 'a:latin'), 'typeface');
101
+ // "+mn-lt"/"+mj-lt" are theme font references; the chart's default font stands in for them.
102
+ if (typeface && !typeface.startsWith('+'))
103
+ out.font = typeface;
104
+ return out;
105
+ }
106
+ /** Text properties of a c:txPr or c:rich: body rotation plus the first paragraph's defaults. */
107
+ function readTextProps(txPr, base, scheme) {
108
+ if (!txPr)
109
+ return base;
110
+ let style = { ...base };
111
+ const bodyPr = firstChild(txPr, 'a:bodyPr');
112
+ const rot = attr(bodyPr, 'rot');
113
+ const vert = attr(bodyPr, 'vert');
114
+ if (rot !== undefined && Number.isFinite(Number(rot)))
115
+ style.rotation = Number(rot) / 60000;
116
+ else if (vert === 'vert270')
117
+ style.rotation = -90;
118
+ else if (vert === 'vert' || vert === 'eaVert')
119
+ style.rotation = 90;
120
+ const p = firstChild(txPr, 'a:p');
121
+ style = applyRunProps(style, firstChild(firstChild(p, 'a:pPr'), 'a:defRPr'), scheme);
122
+ return style;
123
+ }
124
+ function richText(rich) {
125
+ const lines = [];
126
+ for (const p of elements(rich, 'a:p')) {
127
+ let line = '';
128
+ for (const c of elements(p)) {
129
+ if (c.name === 'a:r' || c.name === 'a:fld')
130
+ line += textContent(firstChild(c, 'a:t') ?? c);
131
+ else if (c.name === 'a:br') {
132
+ lines.push(line);
133
+ line = '';
134
+ }
135
+ }
136
+ lines.push(line);
137
+ }
138
+ return lines;
139
+ }
140
+ function readPoints(cache) {
141
+ const out = { count: 0, values: [], formats: new Map(), formatCode: undefined };
142
+ if (!cache)
143
+ return out;
144
+ const fc = firstChild(cache, 'c:formatCode');
145
+ if (fc)
146
+ out.formatCode = textContent(fc);
147
+ const count = num(cache, 'c:ptCount');
148
+ let max = -1;
149
+ for (const pt of elements(cache, 'c:pt')) {
150
+ const idx = Number.parseInt(attr(pt, 'idx') ?? '-1', 10);
151
+ if (!(idx >= 0))
152
+ continue;
153
+ out.values[idx] = textContent(firstChild(pt, 'c:v') ?? pt);
154
+ const f = attr(pt, 'formatCode');
155
+ if (f)
156
+ out.formats.set(idx, f);
157
+ max = Math.max(max, idx);
158
+ }
159
+ out.count = Math.max(count ?? 0, max + 1);
160
+ return out;
161
+ }
162
+ /** Read c:cat / c:val / c:xVal / c:yVal / c:tx / c:bubbleSize from whichever cache or literal it carries. */
163
+ function readData(node) {
164
+ const empty = { kind: 'none', count: 0, numbers: [], strings: [] };
165
+ if (!node)
166
+ return empty;
167
+ const numCache = firstChild(firstChild(node, 'c:numRef'), 'c:numCache') ?? firstChild(node, 'c:numLit');
168
+ if (numCache) {
169
+ const p = readPoints(numCache);
170
+ const numbers = [];
171
+ for (let i = 0; i < p.count; i++) {
172
+ const v = p.values[i];
173
+ const n = v === undefined || v.trim() === '' ? Number.NaN : Number(v);
174
+ numbers.push(Number.isFinite(n) ? n : null);
175
+ }
176
+ const ref = { kind: 'num', count: p.count, numbers, strings: p.values };
177
+ if (p.formatCode !== undefined)
178
+ ref.formatCode = p.formatCode;
179
+ return ref;
180
+ }
181
+ const strCache = firstChild(firstChild(node, 'c:strRef'), 'c:strCache') ?? firstChild(node, 'c:strLit');
182
+ if (strCache) {
183
+ const p = readPoints(strCache);
184
+ return { kind: 'str', count: p.count, numbers: p.values.map((v) => (v !== undefined && v.trim() !== '' && Number.isFinite(Number(v)) ? Number(v) : null)), strings: p.values };
185
+ }
186
+ const multi = firstChild(firstChild(node, 'c:multiLvlStrRef'), 'c:multiLvlStrCache');
187
+ if (multi) {
188
+ const count = num(multi, 'c:ptCount') ?? 0;
189
+ const levels = elements(multi, 'c:lvl').map((lvl) => readPoints(lvl).values);
190
+ const leaf = levels[0] ?? [];
191
+ return { kind: 'multi', count: Math.max(count, leaf.length), numbers: [], strings: leaf, levels };
192
+ }
193
+ // c:tx can hold the text directly.
194
+ const v = firstChild(node, 'c:v');
195
+ if (v)
196
+ return { kind: 'str', count: 1, numbers: [], strings: [textContent(v)] };
197
+ return empty;
198
+ }
199
+ // ---------------------------------------------------------------------------------------------
200
+ // Automatic colours
201
+ /** The chart colour style's variations for series 7+ (Office's colors1.xml, cycling the accents). */
202
+ const VARIATIONS = [
203
+ [1, 0],
204
+ [0.6, 0],
205
+ [0.8, 0.2],
206
+ [0.8, 0],
207
+ [0.6, 0.4],
208
+ [0.5, 0],
209
+ [0.7, 0.3],
210
+ [0.7, 0],
211
+ [0.5, 0.5],
212
+ ];
213
+ /** Automatic colour of series (or point) `i` of `count`, for chart style `style`. */
214
+ export function autoColor(i, count, style, scheme) {
215
+ const column = style >= 1 && style <= 48 ? (style - 1) % 8 : 1;
216
+ if (column === 1) {
217
+ const [lumMod, lumOff] = VARIATIONS[Math.floor(i / 6) % VARIATIONS.length];
218
+ return schemeVariant(`accent${(i % 6) + 1}`, scheme, lumMod, lumOff);
219
+ }
220
+ // Grayscale (column 0) and single-accent styles spread shades from dark to light.
221
+ const base = column === 0 ? '808080' : lookupScheme(`accent${column - 1}`, scheme);
222
+ if (count <= 1)
223
+ return base;
224
+ const t = i / (count - 1) - 0.5; // -0.5 … 0.5
225
+ return t < 0 ? adjustLightness(base, 1 + t * 0.9) : adjustLightness(base, 1 - t * 0.9, t * 0.9);
226
+ }
227
+ // ---------------------------------------------------------------------------------------------
228
+ // Data labels, markers, series
229
+ function readLabelFlags(node, base, scheme, inherit) {
230
+ const b = (name, key) => bool(node, name, inherit ? Boolean(inherit[key]) : false);
231
+ const flags = {
232
+ showVal: b('c:showVal', 'showVal'),
233
+ showPercent: b('c:showPercent', 'showPercent'),
234
+ showCatName: b('c:showCatName', 'showCatName'),
235
+ showSerName: b('c:showSerName', 'showSerName'),
236
+ showLegendKey: b('c:showLegendKey', 'showLegendKey'),
237
+ showBubbleSize: b('c:showBubbleSize', 'showBubbleSize'),
238
+ style: readTextProps(firstChild(node, 'c:txPr'), inherit?.style ?? base, scheme),
239
+ deleted: bool(node, 'c:delete', false),
240
+ };
241
+ const sep = firstChild(node, 'c:separator');
242
+ if (sep)
243
+ flags.separator = textContent(sep);
244
+ else if (inherit?.separator !== undefined)
245
+ flags.separator = inherit.separator;
246
+ const pos = str(node, 'c:dLblPos') ?? inherit?.position;
247
+ if (pos)
248
+ flags.position = pos;
249
+ const nf = firstChild(node, 'c:numFmt');
250
+ if (nf)
251
+ flags.numFmt = { code: attr(nf, 'formatCode') ?? 'General', sourceLinked: attr(nf, 'sourceLinked') === '1' };
252
+ else if (inherit?.numFmt)
253
+ flags.numFmt = inherit.numFmt;
254
+ const fill = fillOf(firstChild(node, 'c:spPr'), scheme);
255
+ if (fill !== undefined)
256
+ flags.fill = fill;
257
+ else if (inherit?.fill !== undefined)
258
+ flags.fill = inherit.fill;
259
+ return flags;
260
+ }
261
+ function readDataLabels(node, base, scheme) {
262
+ if (!node)
263
+ return undefined;
264
+ const flags = readLabelFlags(node, base, scheme);
265
+ const points = new Map();
266
+ for (const d of elements(node, 'c:dLbl')) {
267
+ const idx = num(d, 'c:idx');
268
+ if (idx !== undefined)
269
+ points.set(idx, readLabelFlags(d, base, scheme, flags));
270
+ }
271
+ return { ...flags, points };
272
+ }
273
+ const SYMBOLS = new Set(['circle', 'square', 'diamond', 'triangle', 'x', 'star', 'plus', 'dash', 'dot', 'picture', 'none']);
274
+ /** Excel's automatic marker sequence. */
275
+ const AUTO_SYMBOLS = ['diamond', 'square', 'triangle', 'x', 'star', 'circle', 'plus'];
276
+ function readMarker(node, auto, scheme) {
277
+ if (!node)
278
+ return auto;
279
+ const sym = str(node, 'c:symbol');
280
+ const spPr = firstChild(node, 'c:spPr');
281
+ const fill = fillOf(spPr, scheme);
282
+ const ln = lineOf(spPr, scheme);
283
+ return {
284
+ symbol: sym && SYMBOLS.has(sym) ? sym : auto.symbol,
285
+ size: num(node, 'c:size') ?? auto.size,
286
+ fill: fill === undefined ? auto.fill : fill,
287
+ line: ln.paint === undefined ? auto.line : ln.paint,
288
+ lineWidth: ln.width ?? auto.lineWidth,
289
+ };
290
+ }
291
+ function readSeries(ser, ctx, position) {
292
+ const { scheme, type } = ctx;
293
+ const index = num(ser, 'c:idx') ?? position;
294
+ const order = num(ser, 'c:order') ?? index;
295
+ const tx = readData(firstChild(ser, 'c:tx'));
296
+ const name = tx.strings[0] ?? tx.numbers[0]?.toString() ?? `Series ${index + 1}`;
297
+ const xy = type === 'scatter' || type === 'bubble';
298
+ const catRef = readData(firstChild(ser, xy ? 'c:xVal' : 'c:cat'));
299
+ const valRef = readData(firstChild(ser, xy ? 'c:yVal' : 'c:val'));
300
+ const values = valRef.numbers.slice();
301
+ const count = Math.max(valRef.count, catRef.count);
302
+ while (values.length < valRef.count)
303
+ values.push(null);
304
+ const categories = [];
305
+ let categoryNumbers;
306
+ let categoryFormat;
307
+ if (catRef.kind === 'num') {
308
+ categoryNumbers = catRef.numbers;
309
+ categoryFormat = catRef.formatCode;
310
+ for (let i = 0; i < catRef.count; i++) {
311
+ const n = catRef.numbers[i];
312
+ categories.push(n === null || n === undefined ? '' : formatNumber(n, catRef.formatCode));
313
+ }
314
+ }
315
+ else if (catRef.kind !== 'none') {
316
+ for (let i = 0; i < catRef.count; i++)
317
+ categories.push(catRef.strings[i] ?? '');
318
+ }
319
+ else {
320
+ // No categories: Excel numbers the points from 1.
321
+ for (let i = 0; i < count; i++)
322
+ categories.push(String(i + 1));
323
+ }
324
+ // Automatic colour: per series, or per point when the plot varies colours.
325
+ const color = autoColor(index, ctx.seriesCount, ctx.style, scheme);
326
+ const spPr = firstChild(ser, 'c:spPr');
327
+ const explicitFill = fillOf(spPr, scheme);
328
+ const lineProps = lineOf(spPr, scheme);
329
+ const lineLike = type === 'line' || type === 'scatter' || (type === 'radar' && ctx.radarStyle !== 'filled');
330
+ let main = color;
331
+ let fill;
332
+ let line;
333
+ if (lineLike) {
334
+ line = resolveLine(lineProps, { paint: { color, opacity: 1 }, width: 2.25, cap: 'round', join: 'round' });
335
+ if (line.paint)
336
+ main = line.paint.color;
337
+ fill = explicitFill === undefined ? { color: main, opacity: 1 } : explicitFill;
338
+ }
339
+ else {
340
+ fill = explicitFill === undefined ? { color, opacity: 1 } : explicitFill;
341
+ if (fill)
342
+ main = fill.color;
343
+ // Slices get a thin white edge by default, as Office draws them; bars and areas have none.
344
+ const dfltPaint = type === 'pie' || type === 'doughnut' ? { color: lookupScheme('lt1', scheme), opacity: 1 } : null;
345
+ line = resolveLine(lineProps, { paint: dfltPaint, width: 0.75 });
346
+ }
347
+ // Markers: line/scatter/radar series; automatic when the plot asks for markers and the series is silent.
348
+ const markerNode = firstChild(ser, 'c:marker');
349
+ let autoSymbol = 'none';
350
+ if (type === 'line' && ctx.markers)
351
+ autoSymbol = AUTO_SYMBOLS[index % AUTO_SYMBOLS.length];
352
+ if (type === 'scatter' && !['line', 'smooth'].includes(ctx.scatterStyle ?? ''))
353
+ autoSymbol = AUTO_SYMBOLS[index % AUTO_SYMBOLS.length];
354
+ if (type === 'radar' && ctx.radarStyle === 'marker')
355
+ autoSymbol = AUTO_SYMBOLS[index % AUTO_SYMBOLS.length];
356
+ const marker = readMarker(markerNode, { symbol: autoSymbol, size: 5, fill: { color: main, opacity: 1 }, line: { color: main, opacity: 1 }, lineWidth: 0.75 }, scheme);
357
+ const series = {
358
+ index,
359
+ order,
360
+ name,
361
+ categories,
362
+ values,
363
+ formatCode: valRef.formatCode ?? 'General',
364
+ color: main,
365
+ fill,
366
+ line,
367
+ marker,
368
+ smooth: bool(ser, 'c:smooth', type === 'scatter' && (ctx.scatterStyle === 'smooth' || ctx.scatterStyle === 'smoothMarker')),
369
+ explosion: num(ser, 'c:explosion') ?? 0,
370
+ invertIfNegative: bool(ser, 'c:invertIfNegative', false),
371
+ points: [],
372
+ };
373
+ // A scatter series with style "marker" has no line unless it sets one.
374
+ if (type === 'scatter' && ctx.scatterStyle === 'marker' && lineProps.paint === undefined)
375
+ series.line = { ...series.line, paint: null };
376
+ if (categoryNumbers)
377
+ series.categoryNumbers = categoryNumbers;
378
+ if (categoryFormat !== undefined)
379
+ series.categoryFormat = categoryFormat;
380
+ if (catRef.levels && catRef.levels.length > 1)
381
+ series.categoryGroups = catRef.levels.slice(1).reverse();
382
+ const bubble = readData(firstChild(ser, 'c:bubbleSize'));
383
+ if (type === 'bubble')
384
+ series.bubbleSizes = bubble.kind === 'none' ? values.map(() => 1) : bubble.numbers;
385
+ // Explicit series formatting wins over per-point automatic colours.
386
+ if (ctx.varyColors && explicitFill === undefined) {
387
+ const n = Math.max(values.length, categories.length);
388
+ series.pointColors = Array.from({ length: n }, (_, i) => autoColor(i, n, ctx.style, scheme));
389
+ }
390
+ for (const dPt of elements(ser, 'c:dPt')) {
391
+ const idx = num(dPt, 'c:idx');
392
+ if (idx === undefined)
393
+ continue;
394
+ const pSpPr = firstChild(dPt, 'c:spPr');
395
+ const point = { index: idx };
396
+ const pf = fillOf(pSpPr, scheme);
397
+ if (pf !== undefined)
398
+ point.fill = pf;
399
+ const pl = lineOf(pSpPr, scheme);
400
+ if (pl.paint !== undefined || pl.width !== undefined)
401
+ point.line = resolveLine(pl, series.line);
402
+ const ex = num(dPt, 'c:explosion');
403
+ if (ex !== undefined)
404
+ point.explosion = ex;
405
+ const mk = firstChild(dPt, 'c:marker');
406
+ if (mk)
407
+ point.marker = readMarker(mk, series.marker, scheme);
408
+ if (firstChild(dPt, 'c:invertIfNegative'))
409
+ point.invertIfNegative = bool(dPt, 'c:invertIfNegative', false);
410
+ series.points.push(point);
411
+ }
412
+ const dl = readDataLabels(firstChild(ser, 'c:dLbls'), ctx.text, scheme);
413
+ if (dl)
414
+ series.dataLabels = dl;
415
+ return series;
416
+ }
417
+ // ---------------------------------------------------------------------------------------------
418
+ // Plots, axes, titles, legend
419
+ const PLOT_TYPES = {
420
+ 'c:barChart': 'bar',
421
+ 'c:bar3DChart': 'bar',
422
+ 'c:lineChart': 'line',
423
+ 'c:line3DChart': 'line',
424
+ 'c:stockChart': 'line',
425
+ 'c:areaChart': 'area',
426
+ 'c:area3DChart': 'area',
427
+ 'c:pieChart': 'pie',
428
+ 'c:pie3DChart': 'pie',
429
+ 'c:ofPieChart': 'pie',
430
+ 'c:doughnutChart': 'doughnut',
431
+ 'c:scatterChart': 'scatter',
432
+ 'c:radarChart': 'radar',
433
+ 'c:bubbleChart': 'bubble',
434
+ 'c:surfaceChart': 'surface',
435
+ 'c:surface3DChart': 'surface',
436
+ };
437
+ function readTitle(node, base, scheme, fallbackText) {
438
+ if (!node)
439
+ return undefined;
440
+ const tx = firstChild(node, 'c:tx');
441
+ const rich = firstChild(tx, 'c:rich');
442
+ let lines;
443
+ let auto = false;
444
+ let style = readTextProps(firstChild(node, 'c:txPr'), base, scheme);
445
+ if (rich) {
446
+ lines = richText(rich);
447
+ style = readTextProps(rich, style, scheme);
448
+ // The first run's own properties win over the paragraph defaults.
449
+ const firstRun = elements(rich, 'a:p').flatMap((p) => elements(p, 'a:r'))[0];
450
+ style = applyRunProps(style, firstChild(firstRun, 'a:rPr'), scheme);
451
+ }
452
+ else if (tx) {
453
+ const data = readData(tx);
454
+ lines = [data.strings[0] ?? ''];
455
+ }
456
+ else {
457
+ if (fallbackText === undefined)
458
+ return undefined;
459
+ lines = [fallbackText];
460
+ auto = true;
461
+ }
462
+ const text = lines.join('\n');
463
+ const title = { text, lines, style, overlay: bool(node, 'c:overlay', false), auto };
464
+ const layout = readLayout(node);
465
+ if (layout)
466
+ title.layout = layout;
467
+ const spPr = firstChild(node, 'c:spPr');
468
+ const fill = fillOf(spPr, scheme);
469
+ if (fill !== undefined)
470
+ title.fill = fill;
471
+ const ln = lineOf(spPr, scheme);
472
+ if (ln.paint)
473
+ title.line = resolveLine(ln, { paint: null, width: 0.75 });
474
+ return title;
475
+ }
476
+ function readAxis(node, base, scheme) {
477
+ const kind = node.name === 'c:valAx' ? 'val' : node.name === 'c:dateAx' ? 'date' : node.name === 'c:serAx' ? 'ser' : 'cat';
478
+ const scaling = firstChild(node, 'c:scaling');
479
+ const pos = str(node, 'c:axPos');
480
+ const textStyle = readTextProps(firstChild(node, 'c:txPr'), base, scheme);
481
+ const spPr = firstChild(node, 'c:spPr');
482
+ const axis = {
483
+ id: str(node, 'c:axId') ?? '',
484
+ kind,
485
+ position: pos === 't' || pos === 'l' || pos === 'r' ? pos : 'b',
486
+ deleted: bool(node, 'c:delete', false),
487
+ orientation: str(scaling, 'c:orientation') === 'maxMin' ? 'maxMin' : 'minMax',
488
+ majorTickMark: str(node, 'c:majorTickMark') ?? 'out',
489
+ minorTickMark: str(node, 'c:minorTickMark') ?? 'none',
490
+ tickLblPos: str(node, 'c:tickLblPos') ?? 'nextTo',
491
+ crosses: str(node, 'c:crosses') ?? 'autoZero',
492
+ line: resolveLine(lineOf(spPr, scheme), { paint: { color: '868686', opacity: 1 }, width: 0.75 }),
493
+ textStyle,
494
+ };
495
+ const min = num(scaling, 'c:min');
496
+ const max = num(scaling, 'c:max');
497
+ const logBase = num(scaling, 'c:logBase');
498
+ if (min !== undefined)
499
+ axis.min = min;
500
+ if (max !== undefined)
501
+ axis.max = max;
502
+ if (logBase !== undefined && logBase >= 2)
503
+ axis.logBase = logBase;
504
+ const major = num(node, 'c:majorUnit');
505
+ const minor = num(node, 'c:minorUnit');
506
+ if (major !== undefined && major > 0)
507
+ axis.majorUnit = major;
508
+ if (minor !== undefined && minor > 0)
509
+ axis.minorUnit = minor;
510
+ const nf = firstChild(node, 'c:numFmt');
511
+ if (nf)
512
+ axis.numFmt = { code: attr(nf, 'formatCode') ?? 'General', sourceLinked: attr(nf, 'sourceLinked') === '1' };
513
+ const crossAx = str(node, 'c:crossAx');
514
+ if (crossAx)
515
+ axis.crossAx = crossAx;
516
+ const crossesAt = num(node, 'c:crossesAt');
517
+ if (crossesAt !== undefined)
518
+ axis.crossesAt = crossesAt;
519
+ const cb = str(node, 'c:crossBetween');
520
+ if (cb === 'between' || cb === 'midCat')
521
+ axis.crossBetween = cb;
522
+ const skip = num(node, 'c:tickLblSkip');
523
+ if (skip !== undefined && skip >= 1)
524
+ axis.tickLblSkip = Math.floor(skip);
525
+ const gridDefault = { paint: { color: 'D9D9D9', opacity: 1 }, width: 0.75 };
526
+ const major$ = firstChild(node, 'c:majorGridlines');
527
+ if (major$)
528
+ axis.majorGridlines = resolveLine(lineOf(firstChild(major$, 'c:spPr'), scheme), gridDefault);
529
+ const minor$ = firstChild(node, 'c:minorGridlines');
530
+ if (minor$)
531
+ axis.minorGridlines = resolveLine(lineOf(firstChild(minor$, 'c:spPr'), scheme), { ...gridDefault, paint: { color: 'F2F2F2', opacity: 1 } });
532
+ const titleBase = { ...textStyle, rotation: undefined, bold: true };
533
+ // An axis title element without text shows Office's placeholder "Axis Title".
534
+ const title = readTitle(firstChild(node, 'c:title'), titleBase, scheme, 'Axis Title');
535
+ if (title)
536
+ axis.title = title;
537
+ const du = firstChild(node, 'c:dispUnits');
538
+ if (du) {
539
+ const custom = num(du, 'c:custUnit');
540
+ const builtIn = str(du, 'c:builtInUnit');
541
+ const units = { hundreds: 1e2, thousands: 1e3, tenThousands: 1e4, hundredThousands: 1e5, millions: 1e6, tenMillions: 1e7, hundredMillions: 1e8, billions: 1e9, trillions: 1e12 };
542
+ const divisor = custom ?? (builtIn ? units[builtIn] : undefined);
543
+ if (divisor && divisor > 0)
544
+ axis.dispUnits = divisor;
545
+ }
546
+ return axis;
547
+ }
548
+ /** Read a c:chartSpace into a chart model. */
549
+ export function readChart(chartSpace, options = {}) {
550
+ const scheme = options.schemeColor;
551
+ const chart = firstChild(chartSpace, 'c:chart');
552
+ const plotArea = firstChild(chart, 'c:plotArea');
553
+ const styleValue = Number(attr(childOrFallback(chartSpace, 'c:style'), 'val') ?? '2');
554
+ const style = Number.isFinite(styleValue) && styleValue >= 1 ? styleValue : 2;
555
+ const baseText = readTextProps(firstChild(chartSpace, 'c:txPr'), { size: 10, bold: false, italic: false, color: '000000' }, scheme);
556
+ // Plots in document order, each with its series sorted by c:order.
557
+ const plots = [];
558
+ for (const node of plotArea ? elements(plotArea) : []) {
559
+ const type = PLOT_TYPES[node.name];
560
+ if (!type)
561
+ continue;
562
+ const barDir = str(node, 'c:barDir') === 'bar' ? 'bar' : 'col';
563
+ const groupingRaw = str(node, 'c:grouping');
564
+ let grouping;
565
+ if (type === 'bar')
566
+ grouping = groupingRaw === 'stacked' || groupingRaw === 'percentStacked' || groupingRaw === 'standard' ? groupingRaw : 'clustered';
567
+ else
568
+ grouping = groupingRaw === 'stacked' || groupingRaw === 'percentStacked' ? groupingRaw : 'standard';
569
+ const sers = elements(node, 'c:ser');
570
+ // Office writes varyColors explicitly; for pies the visible default is one colour per slice.
571
+ const varyDefault = type === 'pie' || type === 'doughnut';
572
+ const varyColors = bool(node, 'c:varyColors', varyDefault) && (type === 'pie' || type === 'doughnut' || sers.length === 1);
573
+ const scatterStyle = str(node, 'c:scatterStyle');
574
+ const radarStyle = str(node, 'c:radarStyle');
575
+ const plotLabels = readDataLabels(firstChild(node, 'c:dLbls'), baseText, scheme);
576
+ const ctx = {
577
+ type,
578
+ varyColors,
579
+ seriesCount: sers.length,
580
+ markers: bool(node, 'c:marker', true),
581
+ style,
582
+ scheme,
583
+ text: plotLabels?.style ?? baseText,
584
+ };
585
+ if (scatterStyle)
586
+ ctx.scatterStyle = scatterStyle;
587
+ if (radarStyle)
588
+ ctx.radarStyle = radarStyle;
589
+ const series = sers.map((s, i) => readSeries(s, ctx, i)).sort((a, b) => a.order - b.order);
590
+ // Series without their own c:dLbls follow the plot's.
591
+ if (plotLabels)
592
+ for (const s of series)
593
+ s.dataLabels ??= plotLabels;
594
+ const plot = {
595
+ type,
596
+ element: node.name,
597
+ is3D: node.name.includes('3D'),
598
+ barDir,
599
+ grouping,
600
+ varyColors,
601
+ gapWidth: num(node, 'c:gapWidth') ?? 150,
602
+ overlap: num(node, 'c:overlap') ?? (grouping === 'stacked' || grouping === 'percentStacked' ? 100 : 0),
603
+ firstSliceAng: num(node, 'c:firstSliceAng') ?? 0,
604
+ holeSize: num(node, 'c:holeSize') ?? (type === 'doughnut' ? 50 : 0),
605
+ markers: ctx.markers,
606
+ bubbleScale: num(node, 'c:bubbleScale') ?? 100,
607
+ axisIds: elements(node, 'c:axId').map((a) => attr(a, 'val') ?? ''),
608
+ series,
609
+ };
610
+ if (scatterStyle)
611
+ plot.scatterStyle = scatterStyle;
612
+ if (radarStyle)
613
+ plot.radarStyle = radarStyle;
614
+ if (plotLabels)
615
+ plot.dataLabels = plotLabels;
616
+ plots.push(plot);
617
+ }
618
+ const axes = plotArea ? elements(plotArea).filter((e) => ['c:catAx', 'c:valAx', 'c:dateAx', 'c:serAx'].includes(e.name)).map((a) => readAxis(a, baseText, scheme)) : [];
619
+ // Title: explicit, or the single series' name when the chart shows exactly one series (Office's auto title).
620
+ const allSeries = plots.flatMap((p) => p.series);
621
+ const autoTitleDeleted = bool(chart, 'c:autoTitleDeleted', false);
622
+ const titleNode = firstChild(chart, 'c:title');
623
+ const titleBase = { ...baseText, size: Math.round(baseText.size * 1.4 * 2) / 2 };
624
+ let title;
625
+ const single = allSeries.length === 1 ? allSeries[0].name : undefined;
626
+ if (titleNode)
627
+ title = readTitle(titleNode, titleBase, scheme, single ?? 'Chart Title');
628
+ else if (!autoTitleDeleted && single !== undefined)
629
+ title = { text: single, lines: [single], style: titleBase, overlay: false, auto: true };
630
+ let legend;
631
+ const legendNode = firstChild(chart, 'c:legend');
632
+ if (legendNode) {
633
+ const pos = str(legendNode, 'c:legendPos');
634
+ legend = {
635
+ position: pos === 'l' || pos === 't' || pos === 'b' || pos === 'tr' ? pos : 'r',
636
+ overlay: bool(legendNode, 'c:overlay', false),
637
+ deletedEntries: elements(legendNode, 'c:legendEntry')
638
+ .filter((e) => bool(e, 'c:delete', false))
639
+ .map((e) => num(e, 'c:idx') ?? -1),
640
+ style: readTextProps(firstChild(legendNode, 'c:txPr'), baseText, scheme),
641
+ };
642
+ const layout = readLayout(legendNode);
643
+ if (layout)
644
+ legend.layout = layout;
645
+ const spPr = firstChild(legendNode, 'c:spPr');
646
+ const fill = fillOf(spPr, scheme);
647
+ if (fill !== undefined)
648
+ legend.fill = fill;
649
+ const ln = lineOf(spPr, scheme);
650
+ if (ln.paint)
651
+ legend.line = resolveLine(ln, { paint: null, width: 0.75 });
652
+ }
653
+ const blanks = str(chart, 'c:dispBlanksAs');
654
+ const csSpPr = firstChild(chartSpace, 'c:spPr');
655
+ const csFill = fillOf(csSpPr, scheme);
656
+ const paSpPr = firstChild(plotArea, 'c:spPr');
657
+ const paFill = fillOf(paSpPr, scheme);
658
+ const model = {
659
+ plots,
660
+ axes,
661
+ dispBlanksAs: blanks === 'zero' || blanks === 'span' ? blanks : 'gap',
662
+ style,
663
+ textStyle: baseText,
664
+ chartArea: {
665
+ fill: csFill === undefined ? { color: 'FFFFFF', opacity: 1 } : csFill,
666
+ line: resolveLine(lineOf(csSpPr, scheme), { paint: csSpPr ? null : { color: '868686', opacity: 1 }, width: 0.75 }),
667
+ roundedCorners: bool(chartSpace, 'c:roundedCorners', false),
668
+ },
669
+ plotArea: {
670
+ fill: paFill === undefined ? null : paFill,
671
+ line: resolveLine(lineOf(paSpPr, scheme), { paint: null, width: 0.75 }),
672
+ },
673
+ };
674
+ const paLayout = readLayout(plotArea);
675
+ if (paLayout)
676
+ model.plotArea.layout = paLayout;
677
+ if (title)
678
+ model.title = title;
679
+ if (legend)
680
+ model.legend = legend;
681
+ return model;
682
+ }
683
+ // ---------------------------------------------------------------------------------------------
684
+ // Description
685
+ function plotName(plot) {
686
+ const dir = plot.barDir === 'bar' ? 'bar' : 'column';
687
+ const g = plot.grouping;
688
+ const prefix = g === 'stacked' ? 'stacked ' : g === 'percentStacked' ? '100% stacked ' : '';
689
+ let name;
690
+ switch (plot.type) {
691
+ case 'bar':
692
+ name = `${g === 'clustered' || g === 'standard' ? 'clustered ' : prefix}${dir}`;
693
+ break;
694
+ case 'line':
695
+ name = plot.element === 'c:stockChart' ? 'stock' : `${prefix}line`;
696
+ break;
697
+ case 'area':
698
+ name = `${prefix}area`;
699
+ break;
700
+ case 'scatter':
701
+ name = 'scatter';
702
+ break;
703
+ default:
704
+ name = plot.type;
705
+ }
706
+ return (plot.is3D ? '3-D ' : '') + name;
707
+ }
708
+ function capitalize(s) {
709
+ return s.charAt(0).toUpperCase() + s.slice(1);
710
+ }
711
+ const MAX_POINTS = 12;
712
+ /** One short plain-text description of the chart, for screen readers and AI tools. */
713
+ export function describeChart(model) {
714
+ const plots = model.plots;
715
+ let kind;
716
+ if (plots.length === 0)
717
+ kind = 'Chart';
718
+ else if (plots.length === 1)
719
+ kind = `${capitalize(plotName(plots[0]))} chart`;
720
+ else
721
+ kind = `Combination chart (${[...new Set(plots.map(plotName))].join(', ')})`;
722
+ let out = kind;
723
+ if (model.title && model.title.text.trim())
724
+ out += ` "${model.title.text.replace(/\s*\n\s*/g, ' ').trim()}"`;
725
+ const seriesParts = [];
726
+ for (const plot of plots) {
727
+ for (const s of plot.series) {
728
+ const fmt = (v) => formatNumber(v, s.formatCode);
729
+ const total = s.values.reduce((a, v) => a + Math.abs(v ?? 0), 0);
730
+ const pts = [];
731
+ const n = s.values.length;
732
+ for (let i = 0; i < Math.min(n, MAX_POINTS); i++) {
733
+ const v = s.values[i];
734
+ const shown = v === null || v === undefined ? 'blank' : fmt(v);
735
+ if (plot.type === 'scatter' || plot.type === 'bubble') {
736
+ const x = s.categoryNumbers?.[i];
737
+ const xs = x === null || x === undefined ? (s.categories[i] ?? String(i + 1)) : formatNumber(x, s.categoryFormat);
738
+ pts.push(`(${xs}, ${shown})`);
739
+ }
740
+ else {
741
+ const cat = s.categories[i] ?? String(i + 1);
742
+ const pct = (plot.type === 'pie' || plot.type === 'doughnut') && total > 0 && v !== null && v !== undefined ? ` (${Math.round((Math.abs(v) / total) * 100)}%)` : '';
743
+ pts.push(`${cat} ${shown}${pct}`);
744
+ }
745
+ }
746
+ if (n > MAX_POINTS)
747
+ pts.push(`… ${n - MAX_POINTS} more`);
748
+ seriesParts.push(`${s.name} (${pts.join(', ')})`);
749
+ }
750
+ }
751
+ if (seriesParts.length)
752
+ out += `: series ${seriesParts.join(', ')}`;
753
+ const used = new Set(plots.flatMap((p) => p.axisIds));
754
+ const axisTitles = model.axes.filter((a) => used.has(a.id) && !a.deleted && a.title && !a.title.auto).map((a) => `${a.position === 'b' || a.position === 't' ? 'horizontal' : 'vertical'} axis "${a.title.text.replace(/\s*\n\s*/g, ' ')}"`);
755
+ if (axisTitles.length)
756
+ out += `; ${axisTitles.join(', ')}`;
757
+ return out;
758
+ }