@officedk/pptxdk 0.0.0-stage → 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 (206) hide show
  1. package/LICENSE +21 -0
  2. package/dist/build-zrZuX4fK.d.ts +3 -0
  3. package/dist/build.d.ts +35 -0
  4. package/dist/build.js +128 -0
  5. package/dist/capabilities/dist/all.js +34 -0
  6. package/dist/capabilities/dist/box/box-codegen.js +84 -0
  7. package/dist/capabilities/dist/box/box-declaration.js +32 -0
  8. package/dist/capabilities/dist/box/box-elements.js +17 -0
  9. package/dist/capabilities/dist/box/box.js +142 -0
  10. package/dist/capabilities/dist/chart/chart-codegen.js +79 -0
  11. package/dist/capabilities/dist/chart/chart-declaration.js +7 -0
  12. package/dist/capabilities/dist/chart/chart-elements.js +12 -0
  13. package/dist/capabilities/dist/chart/chart-import.js +2403 -0
  14. package/dist/capabilities/dist/chart/chart-labels.js +86 -0
  15. package/dist/capabilities/dist/chart/chart-model.js +9 -0
  16. package/dist/capabilities/dist/chart/chart-schemas.js +1088 -0
  17. package/dist/capabilities/dist/chart/chart-xml.js +788 -0
  18. package/dist/capabilities/dist/chart/chart.js +1119 -0
  19. package/dist/capabilities/dist/chart/preview/axes-and-grid.js +311 -0
  20. package/dist/capabilities/dist/chart/preview/bar-column.js +143 -0
  21. package/dist/capabilities/dist/chart/preview/data-labels.js +334 -0
  22. package/dist/capabilities/dist/chart/preview/error-bars.js +213 -0
  23. package/dist/capabilities/dist/chart/preview/index.js +192 -0
  24. package/dist/capabilities/dist/chart/preview/layout.js +592 -0
  25. package/dist/capabilities/dist/chart/preview/legend.js +273 -0
  26. package/dist/capabilities/dist/chart/preview/line-area.js +404 -0
  27. package/dist/capabilities/dist/chart/preview/markers.js +100 -0
  28. package/dist/capabilities/dist/chart/preview/number-format.js +247 -0
  29. package/dist/capabilities/dist/chart/preview/pie-doughnut.js +159 -0
  30. package/dist/capabilities/dist/chart/preview/scales.js +365 -0
  31. package/dist/capabilities/dist/chart/preview/scatter.js +131 -0
  32. package/dist/capabilities/dist/chart/preview/style.js +60 -0
  33. package/dist/capabilities/dist/chart/preview/text-render.js +116 -0
  34. package/dist/capabilities/dist/chart/preview/trendlines.js +537 -0
  35. package/dist/capabilities/dist/chart/preview/types.js +5 -0
  36. package/dist/capabilities/dist/document.js +168 -0
  37. package/dist/capabilities/dist/font/font-embedding.js +119 -0
  38. package/dist/capabilities/dist/font/font-engine.js +834 -0
  39. package/dist/capabilities/dist/font/font-import.js +766 -0
  40. package/dist/capabilities/dist/font/font-subset.js +55 -0
  41. package/dist/capabilities/dist/font/font.js +72 -0
  42. package/dist/capabilities/dist/group/group-codegen.js +74 -0
  43. package/dist/capabilities/dist/group/group-declaration.js +41 -0
  44. package/dist/capabilities/dist/group/group-elements.js +12 -0
  45. package/dist/capabilities/dist/group/group-import.js +649 -0
  46. package/dist/capabilities/dist/group/group-xml.js +8 -0
  47. package/dist/capabilities/dist/group/group.js +260 -0
  48. package/dist/capabilities/dist/image/gif-decoder.js +244 -0
  49. package/dist/capabilities/dist/image/image-codegen.js +164 -0
  50. package/dist/capabilities/dist/image/image-declaration.js +8 -0
  51. package/dist/capabilities/dist/image/image-decode.js +244 -0
  52. package/dist/capabilities/dist/image/image-elements.js +12 -0
  53. package/dist/capabilities/dist/image/image-import.js +984 -0
  54. package/dist/capabilities/dist/image/image-schemas.js +147 -0
  55. package/dist/capabilities/dist/image/image-xml.js +12 -0
  56. package/dist/capabilities/dist/image/image.js +552 -0
  57. package/dist/capabilities/dist/line/line-codegen.js +89 -0
  58. package/dist/capabilities/dist/line/line-declaration.js +72 -0
  59. package/dist/capabilities/dist/line/line-elements.js +12 -0
  60. package/dist/capabilities/dist/line/line-import.js +504 -0
  61. package/dist/capabilities/dist/line/line-xml.js +9 -0
  62. package/dist/capabilities/dist/line/line.js +331 -0
  63. package/dist/capabilities/dist/masters/footer-placeholder.js +683 -0
  64. package/dist/capabilities/dist/masters/masters-codegen.js +69 -0
  65. package/dist/capabilities/dist/masters/masters.js +250 -0
  66. package/dist/capabilities/dist/motion/motion-api.js +757 -0
  67. package/dist/capabilities/dist/motion/motion-codegen.js +406 -0
  68. package/dist/capabilities/dist/motion/motion-elements.js +43 -0
  69. package/dist/capabilities/dist/motion/motion-import.js +1568 -0
  70. package/dist/capabilities/dist/motion/motion-plan.js +2340 -0
  71. package/dist/capabilities/dist/motion/motion-query.js +423 -0
  72. package/dist/capabilities/dist/motion/motion-schemas.js +339 -0
  73. package/dist/capabilities/dist/motion/motion.js +1617 -0
  74. package/dist/capabilities/dist/notes/notes-codegen.js +19 -0
  75. package/dist/capabilities/dist/notes/notes-declaration.js +8 -0
  76. package/dist/capabilities/dist/notes/notes-elements.js +12 -0
  77. package/dist/capabilities/dist/notes/notes-import.js +292 -0
  78. package/dist/capabilities/dist/notes/notes-schemas.js +38 -0
  79. package/dist/capabilities/dist/notes/notes-xml.js +38 -0
  80. package/dist/capabilities/dist/notes/notes.js +194 -0
  81. package/dist/capabilities/dist/placeholder/placeholder-codegen.js +54 -0
  82. package/dist/capabilities/dist/placeholder/placeholder-elements.js +13 -0
  83. package/dist/capabilities/dist/placeholder/placeholder-schemas.js +33 -0
  84. package/dist/capabilities/dist/placeholder/placeholder.js +451 -0
  85. package/dist/capabilities/dist/shape/shape-codegen.js +236 -0
  86. package/dist/capabilities/dist/shape/shape-declaration.js +45 -0
  87. package/dist/capabilities/dist/shape/shape-elements.js +12 -0
  88. package/dist/capabilities/dist/shape/shape-import.js +628 -0
  89. package/dist/capabilities/dist/shape/shape-xml.js +6 -0
  90. package/dist/capabilities/dist/shape/shape.js +320 -0
  91. package/dist/capabilities/dist/shared/geometry.js +1681 -0
  92. package/dist/capabilities/dist/shared/identity.js +205 -0
  93. package/dist/capabilities/dist/shared/morph-api.js +11 -0
  94. package/dist/capabilities/dist/shared/placeholder-import.js +238 -0
  95. package/dist/capabilities/dist/shared/preset-definitions.js +22423 -0
  96. package/dist/capabilities/dist/shared/style-inheritance.js +161 -0
  97. package/dist/capabilities/dist/shared/text-schemas.js +241 -0
  98. package/dist/capabilities/dist/shared/text-service.js +2252 -0
  99. package/dist/capabilities/dist/shared/visual.js +1197 -0
  100. package/dist/capabilities/dist/slide-background/slide-background-codegen.js +44 -0
  101. package/dist/capabilities/dist/slide-background/slide-background-import.js +166 -0
  102. package/dist/capabilities/dist/slide-background/slide-background-xml.js +34 -0
  103. package/dist/capabilities/dist/slide-background/slide-background.js +238 -0
  104. package/dist/capabilities/dist/table/table-codegen.js +125 -0
  105. package/dist/capabilities/dist/table/table-declaration.js +15 -0
  106. package/dist/capabilities/dist/table/table-elements.js +27 -0
  107. package/dist/capabilities/dist/table/table-import.js +606 -0
  108. package/dist/capabilities/dist/table/table-schemas.js +334 -0
  109. package/dist/capabilities/dist/table/table-xml.js +30 -0
  110. package/dist/capabilities/dist/table/table.js +739 -0
  111. package/dist/capabilities/dist/text/text-codegen.js +198 -0
  112. package/dist/capabilities/dist/text/text-declaration.js +27 -0
  113. package/dist/capabilities/dist/text/text-elements.js +54 -0
  114. package/dist/capabilities/dist/text/text-import.js +1224 -0
  115. package/dist/capabilities/dist/text/text-xml.js +9 -0
  116. package/dist/capabilities/dist/text/text.js +320 -0
  117. package/dist/capabilities/dist/transition/transition-api.js +136 -0
  118. package/dist/capabilities/dist/transition/transition-codegen.js +45 -0
  119. package/dist/capabilities/dist/transition/transition-import.js +477 -0
  120. package/dist/capabilities/dist/transition/transition.js +260 -0
  121. package/dist/capability-BbKW9w4O.d.ts +2131 -0
  122. package/dist/cli.js +20 -0
  123. package/dist/codegen/dist/assets.js +79 -0
  124. package/dist/codegen/dist/codegen.js +691 -0
  125. package/dist/codegen/dist/identifiers.js +203 -0
  126. package/dist/codegen/dist/index.js +3 -0
  127. package/dist/codegen/dist/printer.js +143 -0
  128. package/dist/codegen/dist/types.js +77 -0
  129. package/dist/core/dist/author-ids.js +51 -0
  130. package/dist/core/dist/author-schemas.js +330 -0
  131. package/dist/core/dist/block-flex-layout.js +801 -0
  132. package/dist/core/dist/build.js +4 -0
  133. package/dist/core/dist/capability.js +15 -0
  134. package/dist/core/dist/declaration.js +16 -0
  135. package/dist/core/dist/diagnostics.js +353 -0
  136. package/dist/core/dist/document-internals.js +26 -0
  137. package/dist/core/dist/document.js +417 -0
  138. package/dist/core/dist/font-seal.js +204 -0
  139. package/dist/core/dist/geometry-schemas.js +256 -0
  140. package/dist/core/dist/grid-layout.js +449 -0
  141. package/dist/core/dist/host.js +40 -0
  142. package/dist/core/dist/index.js +15 -0
  143. package/dist/core/dist/input-values.js +61 -0
  144. package/dist/core/dist/layout-protocol.js +61 -0
  145. package/dist/core/dist/layout-schemas.js +201 -0
  146. package/dist/core/dist/layout.js +340 -0
  147. package/dist/core/dist/masters.js +194 -0
  148. package/dist/core/dist/morph.js +30 -0
  149. package/dist/core/dist/placeholders.js +275 -0
  150. package/dist/core/dist/query.js +190 -0
  151. package/dist/core/dist/resolution.js +12 -0
  152. package/dist/core/dist/resolve.js +2246 -0
  153. package/dist/core/dist/stage-options.js +300 -0
  154. package/dist/core/dist/theme.js +1023 -0
  155. package/dist/core/dist/transform-geometry.js +72 -0
  156. package/dist/document-41spD7bq.d.ts +1350 -0
  157. package/dist/emit/dist/emit.js +957 -0
  158. package/dist/emit/dist/index.js +5 -0
  159. package/dist/emit/dist/ooxml.js +661 -0
  160. package/dist/emit/dist/shape-tree.js +12 -0
  161. package/dist/import/dist/alternate-content.js +54 -0
  162. package/dist/import/dist/diagnostics.js +157 -0
  163. package/dist/import/dist/fonts.js +309 -0
  164. package/dist/import/dist/import.js +513 -0
  165. package/dist/import/dist/index.js +16 -0
  166. package/dist/import/dist/masters.js +1293 -0
  167. package/dist/import/dist/mechanism.js +10 -0
  168. package/dist/import/dist/namespaces.js +61 -0
  169. package/dist/import/dist/notes-masters.js +300 -0
  170. package/dist/import/dist/opc.js +233 -0
  171. package/dist/import/dist/resources.js +166 -0
  172. package/dist/import/dist/sections.js +139 -0
  173. package/dist/import/dist/themes.js +777 -0
  174. package/dist/import/dist/visual.js +821 -0
  175. package/dist/import/dist/xml-fragments.js +277 -0
  176. package/dist/import/dist/xml-reader.js +267 -0
  177. package/dist/index-1ag7U9Jt.d.ts +63 -0
  178. package/dist/index-BEwhk7c8.d.ts +72 -0
  179. package/dist/index-cK2KtukZ.d.ts +161 -0
  180. package/dist/index-v77CTJev.d.ts +55 -0
  181. package/dist/index.d.ts +8 -0
  182. package/dist/index.js +82 -0
  183. package/dist/node.d.ts +53 -0
  184. package/dist/node.js +225 -0
  185. package/dist/pptxdk/src/cli-commands.js +907 -0
  186. package/dist/pptxdk/src/compose.js +53 -0
  187. package/dist/pptxdk/src/slide.js +9 -0
  188. package/dist/preview/dist/index.js +342 -0
  189. package/dist/preview/dist/options.js +40 -0
  190. package/dist/preview/dist/svg-guard.js +1089 -0
  191. package/dist/preview.d.ts +12 -0
  192. package/dist/preview.js +29 -0
  193. package/dist/react/dist/append.js +66 -0
  194. package/dist/react/dist/document-adapter.js +404 -0
  195. package/dist/react/dist/elements.js +82 -0
  196. package/dist/react/dist/from-vanilla.js +57 -0
  197. package/dist/react/dist/index.js +89 -0
  198. package/dist/react/dist/mount.js +34 -0
  199. package/dist/react/dist/reconciler.js +290 -0
  200. package/dist/react.d.ts +235 -0
  201. package/dist/react.js +31 -0
  202. package/dist/transition-6n8GZxSg.d.ts +9 -0
  203. package/dist/vanilla.d.ts +4 -0
  204. package/dist/vanilla.js +15 -0
  205. package/package.json +79 -3
  206. package/README.md +0 -3
@@ -0,0 +1,592 @@
1
+ import { mergeDataLabels } from "../chart-labels.js";
2
+ import { collectLegendEntries, measureLegend } from "./legend.js";
3
+ import { formatChartNumber } from "./number-format.js";
4
+ import { resolveAxisCrossingNormalized } from "./scales.js";
5
+ import { measureChartText, mergeChartTextStyle, resolveChartFontSizePixels } from "./text-render.js";
6
+ // ../capabilities/dist/chart/preview/layout.js
7
+ function titleTextOf(title) {
8
+ return typeof title === "string" ? { text: title } : title;
9
+ }
10
+ function resolveAxisLabelSide(axis, crossScale) {
11
+ const tickPos = axis.spec.tickLabelPosition ?? "nextTo";
12
+ if (tickPos === "none") return "none";
13
+ if (tickPos === "low") return axis.direction === "horizontal" ? "bottom" : "left";
14
+ if (tickPos === "high") return axis.direction === "horizontal" ? "top" : "right";
15
+ if (crossScale !== void 0) {
16
+ const t = resolveAxisCrossingNormalized(axis, crossScale);
17
+ if (t > .02 && t < .98) return "interior";
18
+ if (axis.direction === "horizontal") return t >= .98 ? "top" : "bottom";
19
+ return t >= .98 ? "right" : "left";
20
+ }
21
+ return axis.position;
22
+ }
23
+ function resolveAxisTitleSide(axis, crossScale) {
24
+ const labelSide = resolveAxisLabelSide(axis, crossScale);
25
+ if (labelSide !== "none" && labelSide !== "interior") return labelSide;
26
+ return axis.position;
27
+ }
28
+ function hasOutsideEndBarLabels(parsed) {
29
+ let columnPos = false;
30
+ let columnNeg = false;
31
+ let barPos = false;
32
+ let barNeg = false;
33
+ for (const group of parsed.groups) {
34
+ if (group.kind !== "column" && group.kind !== "bar") continue;
35
+ for (const series of group.series) {
36
+ const serLabels = mergeDataLabels(group.dataLabels, series.dataLabels);
37
+ for (let i = 0; i < series.values.length; i += 1) {
38
+ const val = series.values[i];
39
+ if (val === null || val === void 0 || !Number.isFinite(val)) continue;
40
+ const ptOverride = series.points?.[i]?.dataLabels;
41
+ const eff = mergeDataLabels(serLabels, ptOverride);
42
+ if (eff === void 0 || eff === false) continue;
43
+ if (!eff.value && !eff.category && !eff.percent && !eff.seriesName) continue;
44
+ if ((eff.position ?? (group.stacking === "clustered" ? "outsideEnd" : "center")) !== "outsideEnd") continue;
45
+ if (group.kind === "column") {
46
+ if (val < 0) columnNeg = true;
47
+ else columnPos = true;
48
+ } else if (val < 0) barNeg = true;
49
+ else barPos = true;
50
+ }
51
+ }
52
+ }
53
+ return {
54
+ columnPos,
55
+ columnNeg,
56
+ barPos,
57
+ barNeg
58
+ };
59
+ }
60
+ function hasPointDataLabels(parsed) {
61
+ let top = false;
62
+ let bottom = false;
63
+ let left = false;
64
+ let right = false;
65
+ for (const group of parsed.groups) {
66
+ if (group.kind !== "line" && group.kind !== "area" && group.kind !== "scatter") continue;
67
+ const defaultPos = group.kind === "scatter" ? "right" : group.kind === "area" ? "center" : "top";
68
+ for (const series of group.series) {
69
+ const serLabels = mergeDataLabels(group.dataLabels, series.dataLabels);
70
+ const count = "x" in series ? series.x.length : series.values.length;
71
+ for (let i = 0; i < count; i += 1) {
72
+ const ptOverride = series.points?.[i]?.dataLabels;
73
+ const eff = mergeDataLabels(serLabels, ptOverride);
74
+ if (eff === void 0 || eff === false) continue;
75
+ if (!eff.value && !eff.category && !eff.percent && !eff.xValue && !eff.seriesName) continue;
76
+ const pos = eff.position ?? defaultPos;
77
+ if (pos === "top") top = true;
78
+ else if (pos === "bottom") bottom = true;
79
+ else if (pos === "left") left = true;
80
+ else if (pos === "right") right = true;
81
+ }
82
+ }
83
+ }
84
+ return {
85
+ top,
86
+ bottom,
87
+ left,
88
+ right
89
+ };
90
+ }
91
+ function computeChartLayout(options) {
92
+ const { parsed, box, scales, baseChartTextStyle, baseFontSizePx, theme, slideNumber } = options;
93
+ const legendEntries = parsed.legend !== void 0 && parsed.legend !== false ? collectLegendEntries(parsed, theme) : [];
94
+ if (parsed.plotArea !== void 0) {
95
+ const plotRect = {
96
+ x: box.x + parsed.plotArea.left,
97
+ y: box.y + parsed.plotArea.top,
98
+ width: parsed.plotArea.width,
99
+ height: parsed.plotArea.height
100
+ };
101
+ let titleBox;
102
+ if (parsed.title !== void 0) {
103
+ const topRoom = Math.max(0, parsed.plotArea.top - 4);
104
+ const t = titleTextOf(parsed.title);
105
+ const measured = measureChartText({
106
+ text: t.text,
107
+ style: mergeChartTextStyle(baseChartTextStyle, t.style),
108
+ theme,
109
+ slideNumber,
110
+ labelPath: "Chart.title",
111
+ availableWidth: Math.max(10, box.width - 16)
112
+ });
113
+ const h = Math.min(measured.height, Math.max(12, topRoom));
114
+ titleBox = {
115
+ x: box.x + 8,
116
+ y: box.y + 2,
117
+ width: Math.max(10, box.width - 16),
118
+ height: h
119
+ };
120
+ }
121
+ let measuredLegend;
122
+ let legendBox;
123
+ if (parsed.legend !== void 0 && parsed.legend !== false && legendEntries.length > 0) {
124
+ measuredLegend = measureLegend({
125
+ entries: legendEntries,
126
+ position: parsed.legend,
127
+ maxWidth: Math.max(20, box.width - 16),
128
+ fontSizePx: baseFontSizePx,
129
+ style: baseChartTextStyle,
130
+ theme,
131
+ slideNumber
132
+ });
133
+ const bottomRoom = Math.max(14, box.height - (parsed.plotArea.top + parsed.plotArea.height) - 4);
134
+ if (parsed.legend === "bottom") legendBox = {
135
+ x: box.x + 8,
136
+ y: box.y + box.height - bottomRoom - 2,
137
+ width: Math.max(10, box.width - 16),
138
+ height: bottomRoom
139
+ };
140
+ else if (parsed.legend === "top") legendBox = {
141
+ x: box.x + 8,
142
+ y: box.y + (titleBox ? titleBox.height + 4 : 2),
143
+ width: Math.max(10, box.width - 16),
144
+ height: Math.min(measuredLegend.height, Math.max(14, parsed.plotArea.top - 4))
145
+ };
146
+ else if (parsed.legend === "left") legendBox = {
147
+ x: box.x + 4,
148
+ y: plotRect.y,
149
+ width: Math.max(14, parsed.plotArea.left - 8),
150
+ height: plotRect.height
151
+ };
152
+ else {
153
+ const rightRoom = Math.max(14, box.width - (parsed.plotArea.left + parsed.plotArea.width) - 8);
154
+ legendBox = {
155
+ x: plotRect.x + plotRect.width + 4,
156
+ y: plotRect.y,
157
+ width: rightRoom,
158
+ height: parsed.legend === "topRight" ? Math.min(measuredLegend.height, plotRect.height) : plotRect.height
159
+ };
160
+ }
161
+ }
162
+ const axisTitleBoxes = /* @__PURE__ */ new Map();
163
+ const labelZones = /* @__PURE__ */ new Map();
164
+ for (const axis of parsed.axes) {
165
+ if (axis.spec.visible === false) continue;
166
+ const crossAxis = parsed.axes.find((a) => a.id === axis.crossAxisId);
167
+ const crossScale = crossAxis ? scales.get(crossAxis.name) : void 0;
168
+ const labelSide = resolveAxisLabelSide(axis, crossScale);
169
+ if (labelSide !== "none" && labelSide !== "interior") labelZones.set(axis.name, {
170
+ side: labelSide,
171
+ depth: 20,
172
+ offset: 0
173
+ });
174
+ if (axis.spec.title !== void 0) {
175
+ const titleSide = resolveAxisTitleSide(axis, crossScale);
176
+ const t = titleTextOf(axis.spec.title);
177
+ const titleStyle = mergeChartTextStyle(mergeChartTextStyle(baseChartTextStyle, axis.spec.style), t.style);
178
+ const thickness = resolveChartFontSizePixels(titleStyle?.fontSize) * 1.3;
179
+ if (titleSide === "bottom") axisTitleBoxes.set(axis.name, {
180
+ x: plotRect.x,
181
+ y: Math.min(box.y + box.height - thickness, plotRect.y + plotRect.height + 18),
182
+ width: plotRect.width,
183
+ height: thickness
184
+ });
185
+ else if (titleSide === "top") axisTitleBoxes.set(axis.name, {
186
+ x: plotRect.x,
187
+ y: Math.max(box.y, plotRect.y - 18 - thickness),
188
+ width: plotRect.width,
189
+ height: thickness
190
+ });
191
+ else if (titleSide === "left") axisTitleBoxes.set(axis.name, {
192
+ x: Math.max(box.x, plotRect.x - 24 - thickness),
193
+ y: plotRect.y,
194
+ width: thickness,
195
+ height: plotRect.height
196
+ });
197
+ else axisTitleBoxes.set(axis.name, {
198
+ x: Math.min(box.x + box.width - thickness, plotRect.x + plotRect.width + 24),
199
+ y: plotRect.y,
200
+ width: thickness,
201
+ height: plotRect.height
202
+ });
203
+ }
204
+ }
205
+ return {
206
+ plotRect,
207
+ ...titleBox === void 0 ? {} : { titleBox },
208
+ ...legendBox === void 0 ? {} : { legendBox },
209
+ ...measuredLegend === void 0 ? {} : { measuredLegend },
210
+ axisTitleBoxes,
211
+ labelZones
212
+ };
213
+ }
214
+ const padX = Math.min(8, box.width * .025);
215
+ const padY = Math.min(8, box.height * .025);
216
+ const avail = {
217
+ x: box.x + padX,
218
+ y: box.y + padY,
219
+ width: Math.max(4, box.width - 2 * padX),
220
+ height: Math.max(4, box.height - 2 * padY)
221
+ };
222
+ let titleBox;
223
+ if (parsed.title !== void 0) {
224
+ const t = titleTextOf(parsed.title);
225
+ const titleStyle = mergeChartTextStyle(baseChartTextStyle, t.style);
226
+ const measured = measureChartText({
227
+ text: t.text,
228
+ style: titleStyle,
229
+ theme,
230
+ slideNumber,
231
+ labelPath: "Chart.title",
232
+ availableWidth: avail.width
233
+ });
234
+ const gap = Math.min(6, avail.height * .03);
235
+ const maxTitleH = Math.max(4, avail.height * .25);
236
+ const h = Math.min(measured.height, maxTitleH);
237
+ titleBox = {
238
+ x: avail.x,
239
+ y: avail.y,
240
+ width: avail.width,
241
+ height: h
242
+ };
243
+ const consume = Math.min(h + gap, Math.max(0, avail.height - 4));
244
+ avail.y += consume;
245
+ avail.height = Math.max(4, avail.height - consume);
246
+ }
247
+ let measuredLegend;
248
+ let legendBox;
249
+ if (parsed.legend !== void 0 && parsed.legend !== false && legendEntries.length > 0) {
250
+ const pos = parsed.legend;
251
+ measuredLegend = measureLegend({
252
+ entries: legendEntries,
253
+ position: pos,
254
+ maxWidth: avail.width,
255
+ fontSizePx: baseFontSizePx,
256
+ style: baseChartTextStyle,
257
+ theme,
258
+ slideNumber
259
+ });
260
+ const gap = Math.min(6, Math.min(avail.width, avail.height) * .03);
261
+ if (pos === "top" || pos === "bottom") {
262
+ const h = Math.min(measuredLegend.height, Math.max(4, avail.height * .28));
263
+ const consume = Math.min(h + gap, Math.max(0, avail.height - 4));
264
+ if (pos === "top") {
265
+ legendBox = {
266
+ x: avail.x,
267
+ y: avail.y,
268
+ width: avail.width,
269
+ height: h
270
+ };
271
+ avail.y += consume;
272
+ } else legendBox = {
273
+ x: avail.x,
274
+ y: avail.y + avail.height - h,
275
+ width: avail.width,
276
+ height: h
277
+ };
278
+ avail.height = Math.max(4, avail.height - consume);
279
+ } else if (pos === "left" || pos === "right") {
280
+ const w = Math.min(measuredLegend.width, Math.max(4, avail.width * .32));
281
+ const consume = Math.min(w + gap, Math.max(0, avail.width - 4));
282
+ if (pos === "left") {
283
+ legendBox = {
284
+ x: avail.x,
285
+ y: avail.y,
286
+ width: w,
287
+ height: avail.height
288
+ };
289
+ avail.x += consume;
290
+ } else legendBox = {
291
+ x: avail.x + avail.width - w,
292
+ y: avail.y,
293
+ width: w,
294
+ height: avail.height
295
+ };
296
+ avail.width = Math.max(4, avail.width - consume);
297
+ } else {
298
+ const w = Math.min(measuredLegend.width, Math.max(4, avail.width * .32));
299
+ const h = Math.min(measuredLegend.height, Math.max(4, avail.height * .5));
300
+ const consume = Math.min(w + gap, Math.max(0, avail.width - 4));
301
+ legendBox = {
302
+ x: avail.x + avail.width - w,
303
+ y: avail.y,
304
+ width: w,
305
+ height: h
306
+ };
307
+ avail.width = Math.max(4, avail.width - consume);
308
+ }
309
+ }
310
+ const AXIS_TITLE_GAP = 6;
311
+ const AXIS_TITLE_BOX_PAD = 4;
312
+ const VERTICAL_VALUE_LABEL_PAD = 4;
313
+ const edges = {
314
+ top: 0,
315
+ bottom: 0,
316
+ left: 0,
317
+ right: 0
318
+ };
319
+ const overhang = {
320
+ top: 0,
321
+ bottom: 0,
322
+ left: 0,
323
+ right: 0
324
+ };
325
+ const labelDepths = /* @__PURE__ */ new Map();
326
+ const addLabelZone = (axisName, side, depth) => {
327
+ const existing = edges[side];
328
+ const offset = existing > 0 ? existing + 2 : 0;
329
+ edges[side] = offset + depth;
330
+ labelDepths.set(axisName, {
331
+ side,
332
+ depth,
333
+ offset
334
+ });
335
+ };
336
+ const pendingTitles = [];
337
+ for (const axis of parsed.axes) {
338
+ if (axis.spec.visible === false) continue;
339
+ const scale = scales.get(axis.name);
340
+ if (scale === void 0) continue;
341
+ const crossAxis = parsed.axes.find((a) => a.id === axis.crossAxisId);
342
+ const crossScale = crossAxis ? scales.get(crossAxis.name) : void 0;
343
+ const labelSide = resolveAxisLabelSide(axis, crossScale);
344
+ const axisTextStyle = mergeChartTextStyle(baseChartTextStyle, axis.spec.style);
345
+ const tickProtrusion = axis.spec.majorTickMark === "out" || axis.spec.majorTickMark === "cross" ? 4 : 0;
346
+ const labelGap = 4;
347
+ if (labelSide !== "none" && labelSide !== "interior") {
348
+ if (scale.kind === "value") {
349
+ const formattedTicks = scale.majorTicks.map((v) => formatChartNumber(v, scale.numberFormat));
350
+ let maxW = 0;
351
+ let maxH = 0;
352
+ let firstW = 0;
353
+ let lastW = 0;
354
+ for (let i = 0; i < formattedTicks.length; i += 1) {
355
+ const text = formattedTicks[i];
356
+ const m = measureChartText({
357
+ text,
358
+ style: axisTextStyle,
359
+ theme,
360
+ slideNumber,
361
+ labelPath: `Chart.axes.${axis.name}.style`
362
+ });
363
+ if (i === 0) firstW = m.width;
364
+ if (i === formattedTicks.length - 1) lastW = m.width;
365
+ maxW = Math.max(maxW, m.width);
366
+ maxH = Math.max(maxH, m.height);
367
+ }
368
+ if (axis.direction === "horizontal") {
369
+ const depth = Math.ceil(maxH) + labelGap + tickProtrusion;
370
+ addLabelZone(axis.name, labelSide, depth);
371
+ const leftTickW = scale.reversed ? lastW : firstW;
372
+ const rightTickW = scale.reversed ? firstW : lastW;
373
+ overhang.left = Math.max(overhang.left, Math.min(Math.ceil(leftTickW / 2) + 2, avail.width * .15));
374
+ overhang.right = Math.max(overhang.right, Math.min(Math.ceil(rightTickW / 2) + 2, avail.width * .15));
375
+ } else {
376
+ const depth = Math.min(Math.ceil(maxW) + VERTICAL_VALUE_LABEL_PAD + labelGap + tickProtrusion, avail.width * .42);
377
+ addLabelZone(axis.name, labelSide, depth);
378
+ const singleLineH = maxH > 0 ? maxH : measureChartText({
379
+ text: "",
380
+ style: axisTextStyle,
381
+ theme,
382
+ slideNumber,
383
+ labelPath: `Chart.axes.${axis.name}.style`
384
+ }).height;
385
+ const vOverhang = Math.min(Math.ceil(singleLineH / 2) + 2, avail.height * .15);
386
+ overhang.top = Math.max(overhang.top, vOverhang);
387
+ overhang.bottom = Math.max(overhang.bottom, vOverhang);
388
+ }
389
+ } else {
390
+ let maxW = 0;
391
+ let maxH = 0;
392
+ let firstW = 0;
393
+ let lastW = 0;
394
+ const estSlot = Math.max(12, avail.width * .8 / scale.count);
395
+ for (let i = 0; i < scale.categories.length; i += 1) {
396
+ const cat = scale.categories[i];
397
+ const m = measureChartText({
398
+ text: cat,
399
+ style: axisTextStyle,
400
+ theme,
401
+ slideNumber,
402
+ labelPath: `Chart.axes.${axis.name}.style`,
403
+ ...axis.direction === "horizontal" ? { availableWidth: estSlot } : {}
404
+ });
405
+ if (i === 0) firstW = m.width;
406
+ if (i === scale.categories.length - 1) lastW = m.width;
407
+ maxW = Math.max(maxW, m.width);
408
+ maxH = Math.max(maxH, m.height);
409
+ }
410
+ if (axis.direction === "horizontal") {
411
+ const singleLineH = measureChartText({
412
+ text: "",
413
+ style: axisTextStyle,
414
+ theme,
415
+ slideNumber,
416
+ labelPath: `Chart.axes.${axis.name}.style`
417
+ }).height;
418
+ const depth = Math.min(maxH, singleLineH * 2.2, avail.height * .25) + labelGap + tickProtrusion;
419
+ addLabelZone(axis.name, labelSide, depth);
420
+ if (scale.crossBetween === "midCat" && scale.categories.length > 1) {
421
+ const leftCatW = scale.reversed ? lastW : firstW;
422
+ const rightCatW = scale.reversed ? firstW : lastW;
423
+ overhang.left = Math.max(overhang.left, Math.min(Math.ceil(leftCatW / 2) + 2, avail.width * .15));
424
+ overhang.right = Math.max(overhang.right, Math.min(Math.ceil(rightCatW / 2) + 2, avail.width * .15));
425
+ }
426
+ } else {
427
+ const depth = Math.min(Math.ceil(maxW) + VERTICAL_VALUE_LABEL_PAD + labelGap + tickProtrusion, avail.width * .34);
428
+ addLabelZone(axis.name, labelSide, depth);
429
+ if (scale.crossBetween === "midCat" && scale.categories.length > 1) {
430
+ const vOverhang = Math.min(Math.ceil(maxH / 2) + 2, avail.height * .15);
431
+ overhang.top = Math.max(overhang.top, vOverhang);
432
+ overhang.bottom = Math.max(overhang.bottom, vOverhang);
433
+ }
434
+ }
435
+ }
436
+ } else if (tickProtrusion > 0) overhang[axis.position] = Math.max(overhang[axis.position], tickProtrusion);
437
+ if (axis.spec.title !== void 0) {
438
+ const titleSide = resolveAxisTitleSide(axis, crossScale);
439
+ const t = titleTextOf(axis.spec.title);
440
+ const titleStyle = mergeChartTextStyle(axisTextStyle, t.style);
441
+ pendingTitles.push({
442
+ axis,
443
+ side: titleSide,
444
+ text: t.text,
445
+ style: titleStyle
446
+ });
447
+ }
448
+ }
449
+ for (const side of [
450
+ "top",
451
+ "bottom",
452
+ "left",
453
+ "right"
454
+ ]) edges[side] = Math.max(edges[side], overhang[side]);
455
+ const axisTitleBoxes = /* @__PURE__ */ new Map();
456
+ const titleEdgeOffset = {
457
+ top: edges.top,
458
+ bottom: edges.bottom,
459
+ left: edges.left,
460
+ right: edges.right
461
+ };
462
+ let axisTitleSpecs = [];
463
+ if (pendingTitles.length > 0) {
464
+ let estEdges = { ...titleEdgeOffset };
465
+ for (let pass = 0; pass < 3; pass += 1) {
466
+ const estPlotW = Math.max(24, avail.width - estEdges.left - estEdges.right);
467
+ const estPlotH = Math.max(24, avail.height - estEdges.top - estEdges.bottom);
468
+ const nextSpecs = pendingTitles.map((item) => {
469
+ const availableWidth = item.side === "top" || item.side === "bottom" ? estPlotW : estPlotH;
470
+ const m = measureChartText({
471
+ text: item.text,
472
+ style: item.style,
473
+ theme,
474
+ slideNumber,
475
+ labelPath: `Chart.axes.${item.axis.name}.title`,
476
+ availableWidth
477
+ });
478
+ return {
479
+ axis: item.axis,
480
+ side: item.side,
481
+ thickness: Math.ceil(m.height) + AXIS_TITLE_BOX_PAD
482
+ };
483
+ });
484
+ const nextEdges = { ...titleEdgeOffset };
485
+ for (const item of nextSpecs) nextEdges[item.side] += AXIS_TITLE_GAP + item.thickness;
486
+ const converged = axisTitleSpecs.length === nextSpecs.length && nextSpecs.every((spec, idx) => spec.thickness === axisTitleSpecs[idx]?.thickness);
487
+ axisTitleSpecs = nextSpecs;
488
+ estEdges = nextEdges;
489
+ if (converged) break;
490
+ }
491
+ for (const side of [
492
+ "top",
493
+ "bottom",
494
+ "left",
495
+ "right"
496
+ ]) edges[side] = estEdges[side];
497
+ }
498
+ const outside = hasOutsideEndBarLabels(parsed);
499
+ const pointLabels = hasPointDataLabels(parsed);
500
+ if (outside.columnPos || pointLabels.top) edges.top = Math.max(edges.top, Math.min(baseFontSizePx * 1.4, avail.height * .16));
501
+ if (outside.columnNeg || pointLabels.bottom) edges.bottom = Math.max(edges.bottom, Math.min(baseFontSizePx * 1.4, avail.height * .16));
502
+ if (outside.barPos || pointLabels.right) edges.right = Math.max(edges.right, Math.min(baseFontSizePx * 2.5, avail.width * .16));
503
+ if (outside.barNeg || pointLabels.left) edges.left = Math.max(edges.left, Math.min(baseFontSizePx * 2.5, avail.width * .16));
504
+ for (const side of [
505
+ "top",
506
+ "bottom",
507
+ "left",
508
+ "right"
509
+ ]) if (edges[side] === 0) edges[side] = Math.min(6, (side === "left" || side === "right" ? avail.width : avail.height) * .03);
510
+ const maxHorizSum = Math.max(0, avail.width - 4);
511
+ const rawHorizSum = edges.left + edges.right;
512
+ const hRatio = rawHorizSum > maxHorizSum && rawHorizSum > 0 ? maxHorizSum / rawHorizSum : 1;
513
+ if (hRatio < 1) {
514
+ edges.left *= hRatio;
515
+ edges.right *= hRatio;
516
+ titleEdgeOffset.left *= hRatio;
517
+ titleEdgeOffset.right *= hRatio;
518
+ }
519
+ const maxVertSum = Math.max(0, avail.height - 4);
520
+ const rawVertSum = edges.top + edges.bottom;
521
+ const vRatio = rawVertSum > maxVertSum && rawVertSum > 0 ? maxVertSum / rawVertSum : 1;
522
+ if (vRatio < 1) {
523
+ edges.top *= vRatio;
524
+ edges.bottom *= vRatio;
525
+ titleEdgeOffset.top *= vRatio;
526
+ titleEdgeOffset.bottom *= vRatio;
527
+ }
528
+ const plotRect = {
529
+ x: avail.x + edges.left,
530
+ y: avail.y + edges.top,
531
+ width: Math.max(4, avail.width - edges.left - edges.right),
532
+ height: Math.max(4, avail.height - edges.top - edges.bottom)
533
+ };
534
+ const titleCursors = {
535
+ top: plotRect.y - titleEdgeOffset.top,
536
+ bottom: plotRect.y + plotRect.height + titleEdgeOffset.bottom,
537
+ left: plotRect.x - titleEdgeOffset.left,
538
+ right: plotRect.x + plotRect.width + titleEdgeOffset.right
539
+ };
540
+ const hTitleGap = AXIS_TITLE_GAP * hRatio;
541
+ const vTitleGap = AXIS_TITLE_GAP * vRatio;
542
+ for (const item of axisTitleSpecs) if (item.side === "top") {
543
+ const th = item.thickness * vRatio;
544
+ const y = titleCursors.top - vTitleGap - th;
545
+ axisTitleBoxes.set(item.axis.name, {
546
+ x: plotRect.x,
547
+ y,
548
+ width: plotRect.width,
549
+ height: th
550
+ });
551
+ titleCursors.top = y;
552
+ } else if (item.side === "bottom") {
553
+ const th = item.thickness * vRatio;
554
+ const y = titleCursors.bottom + vTitleGap;
555
+ axisTitleBoxes.set(item.axis.name, {
556
+ x: plotRect.x,
557
+ y,
558
+ width: plotRect.width,
559
+ height: th
560
+ });
561
+ titleCursors.bottom = y + th;
562
+ } else if (item.side === "left") {
563
+ const tw = item.thickness * hRatio;
564
+ const x = titleCursors.left - hTitleGap - tw;
565
+ axisTitleBoxes.set(item.axis.name, {
566
+ x,
567
+ y: plotRect.y,
568
+ width: tw,
569
+ height: plotRect.height
570
+ });
571
+ titleCursors.left = x;
572
+ } else {
573
+ const tw = item.thickness * hRatio;
574
+ const x = titleCursors.right + hTitleGap;
575
+ axisTitleBoxes.set(item.axis.name, {
576
+ x,
577
+ y: plotRect.y,
578
+ width: tw,
579
+ height: plotRect.height
580
+ });
581
+ titleCursors.right = x + tw;
582
+ }
583
+ return {
584
+ plotRect,
585
+ ...titleBox === void 0 ? {} : { titleBox },
586
+ ...legendBox === void 0 ? {} : { legendBox },
587
+ ...measuredLegend === void 0 ? {} : { measuredLegend },
588
+ axisTitleBoxes,
589
+ labelZones: labelDepths
590
+ };
591
+ }
592
+ export { computeChartLayout, resolveAxisLabelSide, resolveAxisTitleSide };