@officedk/pptxdk 0.0.0-stage → 0.1.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 (194) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +48 -2
  3. package/dist/build.d.ts +94 -0
  4. package/dist/build.js +148 -0
  5. package/dist/capabilities/dist/all.js +32 -0
  6. package/dist/capabilities/dist/box/box-codegen.js +51 -0
  7. package/dist/capabilities/dist/box/box-declaration.js +31 -0
  8. package/dist/capabilities/dist/box/box-elements.js +17 -0
  9. package/dist/capabilities/dist/box/box.js +138 -0
  10. package/dist/capabilities/dist/chart/chart-codegen.js +77 -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 +2272 -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 +1078 -0
  17. package/dist/capabilities/dist/chart/chart-xml.js +788 -0
  18. package/dist/capabilities/dist/chart/chart.js +1124 -0
  19. package/dist/capabilities/dist/chart/preview/axes-and-grid.js +298 -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 +190 -0
  24. package/dist/capabilities/dist/chart/preview/layout.js +519 -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 +48 -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 +148 -0
  37. package/dist/capabilities/dist/font/font-embedding.js +289 -0
  38. package/dist/capabilities/dist/font/font-family.js +10 -0
  39. package/dist/capabilities/dist/font/font-import.js +302 -0
  40. package/dist/capabilities/dist/font/font-subset.js +55 -0
  41. package/dist/capabilities/dist/font/font.js +25 -0
  42. package/dist/capabilities/dist/group/group-codegen.js +51 -0
  43. package/dist/capabilities/dist/group/group-declaration.js +42 -0
  44. package/dist/capabilities/dist/group/group-elements.js +12 -0
  45. package/dist/capabilities/dist/group/group-import.js +319 -0
  46. package/dist/capabilities/dist/group/group-xml.js +7 -0
  47. package/dist/capabilities/dist/group/group.js +211 -0
  48. package/dist/capabilities/dist/image/gif-decoder.js +244 -0
  49. package/dist/capabilities/dist/image/image-codegen.js +94 -0
  50. package/dist/capabilities/dist/image/image-declaration.js +8 -0
  51. package/dist/capabilities/dist/image/image-decode.js +221 -0
  52. package/dist/capabilities/dist/image/image-elements.js +12 -0
  53. package/dist/capabilities/dist/image/image-import.js +778 -0
  54. package/dist/capabilities/dist/image/image-schemas.js +149 -0
  55. package/dist/capabilities/dist/image/image-xml.js +12 -0
  56. package/dist/capabilities/dist/image/image.js +472 -0
  57. package/dist/capabilities/dist/masters/footer-placeholder.js +685 -0
  58. package/dist/capabilities/dist/masters/masters-codegen.js +21 -0
  59. package/dist/capabilities/dist/masters/masters.js +250 -0
  60. package/dist/capabilities/dist/motion/motion-api.js +527 -0
  61. package/dist/capabilities/dist/motion/motion-codegen.js +340 -0
  62. package/dist/capabilities/dist/motion/motion-elements.js +43 -0
  63. package/dist/capabilities/dist/motion/motion-import.js +1033 -0
  64. package/dist/capabilities/dist/motion/motion-plan.js +2189 -0
  65. package/dist/capabilities/dist/motion/motion-query.js +420 -0
  66. package/dist/capabilities/dist/motion/motion-schemas.js +216 -0
  67. package/dist/capabilities/dist/motion/motion.js +1372 -0
  68. package/dist/capabilities/dist/notes/notes-codegen.js +20 -0
  69. package/dist/capabilities/dist/notes/notes-declaration.js +8 -0
  70. package/dist/capabilities/dist/notes/notes-elements.js +12 -0
  71. package/dist/capabilities/dist/notes/notes-import.js +292 -0
  72. package/dist/capabilities/dist/notes/notes-schemas.js +35 -0
  73. package/dist/capabilities/dist/notes/notes-xml.js +38 -0
  74. package/dist/capabilities/dist/notes/notes.js +191 -0
  75. package/dist/capabilities/dist/placeholder/placeholder-codegen.js +23 -0
  76. package/dist/capabilities/dist/placeholder/placeholder-elements.js +12 -0
  77. package/dist/capabilities/dist/placeholder/placeholder.js +292 -0
  78. package/dist/capabilities/dist/shape/shape-codegen.js +166 -0
  79. package/dist/capabilities/dist/shape/shape-declaration.js +57 -0
  80. package/dist/capabilities/dist/shape/shape-elements.js +12 -0
  81. package/dist/capabilities/dist/shape/shape-import.js +579 -0
  82. package/dist/capabilities/dist/shape/shape-xml.js +6 -0
  83. package/dist/capabilities/dist/shape/shape.js +337 -0
  84. package/dist/capabilities/dist/shared/geometry.js +1423 -0
  85. package/dist/capabilities/dist/shared/identity.js +205 -0
  86. package/dist/capabilities/dist/shared/morph-api.js +11 -0
  87. package/dist/capabilities/dist/shared/placeholder-import.js +113 -0
  88. package/dist/capabilities/dist/shared/preset-definitions.js +21390 -0
  89. package/dist/capabilities/dist/shared/style-inheritance.js +166 -0
  90. package/dist/capabilities/dist/shared/style-parse.js +11 -0
  91. package/dist/capabilities/dist/shared/text-schemas.js +216 -0
  92. package/dist/capabilities/dist/shared/text-service.js +1883 -0
  93. package/dist/capabilities/dist/shared/visual.js +918 -0
  94. package/dist/capabilities/dist/slide-background/slide-background-codegen.js +44 -0
  95. package/dist/capabilities/dist/slide-background/slide-background-import.js +161 -0
  96. package/dist/capabilities/dist/slide-background/slide-background-xml.js +21 -0
  97. package/dist/capabilities/dist/slide-background/slide-background.js +221 -0
  98. package/dist/capabilities/dist/table/table-codegen.js +81 -0
  99. package/dist/capabilities/dist/table/table-declaration.js +15 -0
  100. package/dist/capabilities/dist/table/table-elements.js +27 -0
  101. package/dist/capabilities/dist/table/table-import.js +539 -0
  102. package/dist/capabilities/dist/table/table-schemas.js +279 -0
  103. package/dist/capabilities/dist/table/table-xml.js +37 -0
  104. package/dist/capabilities/dist/table/table.js +662 -0
  105. package/dist/capabilities/dist/text/text-codegen.js +129 -0
  106. package/dist/capabilities/dist/text/text-declaration.js +19 -0
  107. package/dist/capabilities/dist/text/text-elements.js +38 -0
  108. package/dist/capabilities/dist/text/text-import.js +1077 -0
  109. package/dist/capabilities/dist/text/text-xml.js +9 -0
  110. package/dist/capabilities/dist/text/text.js +335 -0
  111. package/dist/capabilities/dist/transition/transition-api.js +139 -0
  112. package/dist/capabilities/dist/transition/transition-codegen.js +45 -0
  113. package/dist/capabilities/dist/transition/transition-import.js +477 -0
  114. package/dist/capabilities/dist/transition/transition.js +260 -0
  115. package/dist/capability-D_xeNVIw.d.ts +29496 -0
  116. package/dist/cli.js +20 -0
  117. package/dist/codegen/dist/assets.js +78 -0
  118. package/dist/codegen/dist/codegen.js +611 -0
  119. package/dist/codegen/dist/identifiers.js +193 -0
  120. package/dist/codegen/dist/index.js +3 -0
  121. package/dist/codegen/dist/printer.js +143 -0
  122. package/dist/codegen/dist/types.js +49 -0
  123. package/dist/core/dist/author-ids.js +48 -0
  124. package/dist/core/dist/author-schemas.js +313 -0
  125. package/dist/core/dist/block-flex-layout.js +749 -0
  126. package/dist/core/dist/build.js +4 -0
  127. package/dist/core/dist/capability.js +13 -0
  128. package/dist/core/dist/declaration.js +15 -0
  129. package/dist/core/dist/diagnostics.js +21 -0
  130. package/dist/core/dist/document-internals.js +13 -0
  131. package/dist/core/dist/document.js +408 -0
  132. package/dist/core/dist/geometry-schemas.js +249 -0
  133. package/dist/core/dist/grid-layout.js +445 -0
  134. package/dist/core/dist/host.js +40 -0
  135. package/dist/core/dist/index.js +15 -0
  136. package/dist/core/dist/input-values.js +45 -0
  137. package/dist/core/dist/layout-protocol.js +66 -0
  138. package/dist/core/dist/layout-schemas.js +208 -0
  139. package/dist/core/dist/layout.js +299 -0
  140. package/dist/core/dist/masters.js +169 -0
  141. package/dist/core/dist/morph.js +30 -0
  142. package/dist/core/dist/placeholders.js +213 -0
  143. package/dist/core/dist/query.js +155 -0
  144. package/dist/core/dist/resolution.js +11 -0
  145. package/dist/core/dist/resolve.js +1827 -0
  146. package/dist/core/dist/stage-options.js +67 -0
  147. package/dist/core/dist/theme.js +931 -0
  148. package/dist/document-BHPUODPP.d.ts +27759 -0
  149. package/dist/emit/dist/emit.js +936 -0
  150. package/dist/emit/dist/index.js +5 -0
  151. package/dist/emit/dist/ooxml.js +606 -0
  152. package/dist/emit/dist/shape-tree.js +12 -0
  153. package/dist/import/dist/alternate-content.js +54 -0
  154. package/dist/import/dist/diagnostics.js +153 -0
  155. package/dist/import/dist/fonts.js +250 -0
  156. package/dist/import/dist/import.js +504 -0
  157. package/dist/import/dist/index.js +16 -0
  158. package/dist/import/dist/masters.js +1153 -0
  159. package/dist/import/dist/mechanism.js +10 -0
  160. package/dist/import/dist/namespaces.js +60 -0
  161. package/dist/import/dist/notes-masters.js +300 -0
  162. package/dist/import/dist/opc.js +233 -0
  163. package/dist/import/dist/resources.js +166 -0
  164. package/dist/import/dist/sections.js +139 -0
  165. package/dist/import/dist/themes.js +671 -0
  166. package/dist/import/dist/visual.js +761 -0
  167. package/dist/import/dist/xml-fragments.js +36 -0
  168. package/dist/import/dist/xml-reader.js +267 -0
  169. package/dist/index-B5m3hqjC.d.ts +7 -0
  170. package/dist/index-CCy-Yo8G.d.ts +1208 -0
  171. package/dist/index-DpxcZ4Gs.d.ts +725 -0
  172. package/dist/index.d.ts +7 -0
  173. package/dist/index.js +70 -0
  174. package/dist/node.d.ts +53 -0
  175. package/dist/node.js +194 -0
  176. package/dist/pptxdk/src/cli-commands.js +913 -0
  177. package/dist/pptxdk/src/compose.js +44 -0
  178. package/dist/pptxdk/src/slide.js +9 -0
  179. package/dist/preview/dist/index.js +240 -0
  180. package/dist/preview/dist/options.js +53 -0
  181. package/dist/preview-Cfw0QdMM.d.ts +86 -0
  182. package/dist/preview.d.ts +3 -0
  183. package/dist/preview.js +27 -0
  184. package/dist/react/dist/append.js +66 -0
  185. package/dist/react/dist/document-adapter.js +65 -0
  186. package/dist/react/dist/elements.js +59 -0
  187. package/dist/react/dist/index.js +68 -0
  188. package/dist/react/dist/reconciler.js +290 -0
  189. package/dist/react.d.ts +145 -0
  190. package/dist/react.js +27 -0
  191. package/dist/transition-Cips9wma.d.ts +82 -0
  192. package/dist/vanilla.d.ts +4 -0
  193. package/dist/vanilla.js +14 -0
  194. package/package.json +78 -3
@@ -0,0 +1,273 @@
1
+ import { renderMarkerSvg, resolveEffectiveMarker } from "./markers.js";
2
+ import { resolveChartLineStroke, resolveSeriesColor } from "./style.js";
3
+ import { measureChartText, renderChartTextSvg } from "./text-render.js";
4
+ import { assertNever } from "./types.js";
5
+ // ../capabilities/dist/chart/preview/legend.js
6
+ function toLegendMarker(resolved) {
7
+ if (resolved === void 0) return void 0;
8
+ return {
9
+ symbol: resolved.symbol,
10
+ fillHex: resolved.fillHex,
11
+ fillAlpha: resolved.fillAlpha,
12
+ ...resolved.stroke === void 0 ? {} : {
13
+ strokeHex: resolved.stroke.hex,
14
+ strokeAlpha: resolved.stroke.alpha,
15
+ strokeWidth: resolved.stroke.width
16
+ }
17
+ };
18
+ }
19
+ function collectLegendEntries(parsed, theme) {
20
+ const entries = [];
21
+ for (const group of parsed.groups) switch (group.kind) {
22
+ case "column":
23
+ case "bar":
24
+ case "area":
25
+ for (const series of group.series) {
26
+ const color = resolveSeriesColor(series.color, series.seriesIndex, theme);
27
+ const stroke = series.line === void 0 ? void 0 : resolveChartLineStroke(series.line, theme, {
28
+ color: "dk1",
29
+ width: 1
30
+ });
31
+ entries.push({
32
+ label: series.name,
33
+ colorHex: color.hex,
34
+ colorAlpha: color.alpha ?? 1,
35
+ kind: "swatch",
36
+ ...stroke === void 0 ? {} : {
37
+ strokeHex: stroke.hex,
38
+ strokeAlpha: stroke.alpha,
39
+ strokeWidth: stroke.width,
40
+ ...stroke.dashArray === void 0 ? {} : { dashArray: stroke.dashArray }
41
+ }
42
+ });
43
+ }
44
+ break;
45
+ case "pie":
46
+ case "doughnut": {
47
+ const firstSeries = group.series[0];
48
+ if (firstSeries === void 0) break;
49
+ for (let j = 0; j < firstSeries.categories.length; j += 1) {
50
+ const point = firstSeries.points?.[j];
51
+ const color = resolveSeriesColor(point?.color ?? firstSeries.color, j, theme);
52
+ const lineSpec = point?.line ?? firstSeries.line;
53
+ const stroke = lineSpec === void 0 ? void 0 : resolveChartLineStroke(lineSpec, theme, {
54
+ color: "dk1",
55
+ width: 1
56
+ });
57
+ entries.push({
58
+ label: firstSeries.categories[j] ?? "",
59
+ colorHex: color.hex,
60
+ colorAlpha: color.alpha ?? 1,
61
+ kind: "swatch",
62
+ ...stroke === void 0 ? {} : {
63
+ strokeHex: stroke.hex,
64
+ strokeAlpha: stroke.alpha,
65
+ strokeWidth: stroke.width,
66
+ ...stroke.dashArray === void 0 ? {} : { dashArray: stroke.dashArray }
67
+ }
68
+ });
69
+ }
70
+ break;
71
+ }
72
+ case "line":
73
+ for (const series of group.series) {
74
+ const fallbackColor = series.line?.color ?? series.color ?? `accent${series.seriesIndex % 6 + 1}`;
75
+ const stroke = resolveChartLineStroke(series.line, theme, {
76
+ color: fallbackColor,
77
+ width: 2
78
+ });
79
+ const marker = toLegendMarker(resolveEffectiveMarker({
80
+ groupDefaultEnabled: false,
81
+ seriesMarker: series.marker,
82
+ pointMarker: void 0,
83
+ seriesColor: series.color,
84
+ pointColor: void 0,
85
+ seriesIndex: series.seriesIndex,
86
+ theme
87
+ }));
88
+ entries.push({
89
+ label: series.name,
90
+ colorHex: stroke.hex,
91
+ colorAlpha: stroke.alpha,
92
+ kind: "line",
93
+ strokeWidth: stroke.width,
94
+ ...stroke.dashArray === void 0 ? {} : { dashArray: stroke.dashArray },
95
+ ...marker === void 0 ? {} : { marker }
96
+ });
97
+ }
98
+ break;
99
+ case "scatter": {
100
+ const hasLine = group.line !== false;
101
+ for (const series of group.series) {
102
+ const fallbackColor = series.line?.color ?? series.color ?? `accent${series.seriesIndex % 6 + 1}`;
103
+ const stroke = hasLine ? resolveChartLineStroke(series.line, theme, {
104
+ color: fallbackColor,
105
+ width: 2
106
+ }) : void 0;
107
+ const color = resolveSeriesColor(series.color, series.seriesIndex, theme);
108
+ const marker = toLegendMarker(group.markers ? resolveEffectiveMarker({
109
+ groupDefaultEnabled: true,
110
+ seriesMarker: series.marker,
111
+ pointMarker: void 0,
112
+ seriesColor: series.color,
113
+ pointColor: void 0,
114
+ seriesIndex: series.seriesIndex,
115
+ theme
116
+ }) : void 0);
117
+ entries.push({
118
+ label: series.name,
119
+ colorHex: stroke?.hex ?? marker?.fillHex ?? color.hex,
120
+ colorAlpha: stroke?.alpha ?? marker?.fillAlpha ?? color.alpha ?? 1,
121
+ kind: hasLine ? "line" : "marker",
122
+ ...stroke === void 0 ? {} : {
123
+ strokeWidth: stroke.width,
124
+ ...stroke.dashArray === void 0 ? {} : { dashArray: stroke.dashArray }
125
+ },
126
+ ...marker === void 0 ? {} : { marker }
127
+ });
128
+ }
129
+ break;
130
+ }
131
+ default: assertNever(group);
132
+ }
133
+ return entries;
134
+ }
135
+ function measureLegend(options) {
136
+ const { entries, position, maxWidth, fontSizePx, style, theme, slideNumber } = options;
137
+ const swatchSize = Math.max(5, Math.min(fontSizePx * .72, 12));
138
+ const iconWidth = entries.some((entry) => entry.kind === "line") ? Math.max(swatchSize, Math.min(fontSizePx * 1.3, 18)) : swatchSize;
139
+ const swatchGap = Math.max(3, swatchSize * .45);
140
+ const itemGapX = Math.max(8, fontSizePx * .75);
141
+ const rowGapY = Math.max(2, fontSizePx * .25);
142
+ const items = entries.map((entry) => {
143
+ const measured = measureChartText({
144
+ text: entry.label,
145
+ style,
146
+ theme,
147
+ slideNumber,
148
+ labelPath: "Chart.legend"
149
+ });
150
+ return {
151
+ entry,
152
+ itemWidth: iconWidth + swatchGap + measured.width,
153
+ textHeight: Math.max(swatchSize, measured.height)
154
+ };
155
+ });
156
+ const rowHeight = Math.max(swatchSize, ...items.map((item) => item.textHeight));
157
+ if (position === "top" || position === "bottom") {
158
+ const rows = [];
159
+ let currentRow = [];
160
+ let currentWidth = 0;
161
+ const limit = Math.max(20, maxWidth);
162
+ for (const item of items) {
163
+ const nextWidth = currentRow.length === 0 ? item.itemWidth : currentWidth + itemGapX + item.itemWidth;
164
+ if (currentRow.length > 0 && nextWidth > limit) {
165
+ rows.push(currentRow);
166
+ currentRow = [item];
167
+ currentWidth = item.itemWidth;
168
+ } else {
169
+ currentRow.push(item);
170
+ currentWidth = nextWidth;
171
+ }
172
+ }
173
+ if (currentRow.length > 0) rows.push(currentRow);
174
+ const maxRowWidth = Math.max(0, ...rows.map((row) => row.reduce((sum, item, idx) => sum + item.itemWidth + (idx > 0 ? itemGapX : 0), 0)));
175
+ const totalHeight = rows.length === 0 ? 0 : rows.length * rowHeight + (rows.length - 1) * rowGapY;
176
+ return {
177
+ width: Math.min(maxWidth, maxRowWidth),
178
+ height: totalHeight,
179
+ swatchSize,
180
+ iconWidth,
181
+ swatchGap,
182
+ itemGapX,
183
+ rowGapY,
184
+ rowHeight,
185
+ rows
186
+ };
187
+ }
188
+ const rows = items.map((item) => [item]);
189
+ return {
190
+ width: Math.max(0, ...items.map((item) => item.itemWidth)),
191
+ height: rows.length === 0 ? 0 : rows.length * rowHeight + (rows.length - 1) * rowGapY,
192
+ swatchSize,
193
+ iconWidth,
194
+ swatchGap,
195
+ itemGapX,
196
+ rowGapY,
197
+ rowHeight,
198
+ rows
199
+ };
200
+ }
201
+ function renderLegendIconSvg(entry, x, rowY, measured) {
202
+ const cy = rowY + measured.rowHeight / 2;
203
+ const cx = x + measured.iconWidth / 2;
204
+ if (entry.kind === "swatch") {
205
+ const size = measured.swatchSize;
206
+ const swatchX = cx - size / 2;
207
+ const swatchY = cy - size / 2;
208
+ const dashAttr = entry.dashArray === void 0 ? "" : ` stroke-dasharray="${entry.dashArray}"`;
209
+ const strokeAttr = entry.strokeWidth === void 0 ? "" : ` stroke="#${entry.strokeHex ?? entry.colorHex}" stroke-opacity="${entry.strokeAlpha ?? 1}" stroke-width="${Math.min(1.5, entry.strokeWidth)}"${dashAttr}`;
210
+ return `<rect x="${swatchX}" y="${swatchY}" width="${size}" height="${size}" fill="#${entry.colorHex}" fill-opacity="${entry.colorAlpha}"${strokeAttr}/>`;
211
+ }
212
+ const parts = [];
213
+ if (entry.kind === "line") {
214
+ const strokeW = Math.min(2.5, Math.max(1.25, entry.strokeWidth ?? 2));
215
+ const dashAttr = entry.dashArray === void 0 ? "" : ` stroke-dasharray="${entry.dashArray}"`;
216
+ parts.push(`<line x1="${x}" y1="${cy}" x2="${x + measured.iconWidth}" y2="${cy}" stroke="#${entry.colorHex}" stroke-opacity="${entry.colorAlpha}" stroke-width="${strokeW}"${dashAttr} stroke-linecap="round"/>`);
217
+ }
218
+ if (entry.marker !== void 0) {
219
+ const r = Math.min(measured.swatchSize * .42, 4);
220
+ parts.push(renderMarkerSvg(cx, cy, {
221
+ symbol: entry.marker.symbol,
222
+ radius: r,
223
+ fillHex: entry.marker.fillHex,
224
+ fillAlpha: entry.marker.fillAlpha,
225
+ ...entry.marker.strokeHex === void 0 ? {} : { stroke: {
226
+ hex: entry.marker.strokeHex,
227
+ alpha: entry.marker.strokeAlpha ?? 1,
228
+ width: Math.min(1.5, entry.marker.strokeWidth ?? 1)
229
+ } }
230
+ }));
231
+ }
232
+ return parts.join("");
233
+ }
234
+ function renderLegendSvg(options) {
235
+ const { measured, position, legendBox, style, theme, slideNumber, clipAllocator } = options;
236
+ if (measured.rows.length === 0 || legendBox.width <= 0 || legendBox.height <= 0) return "";
237
+ const parts = [];
238
+ const totalContentHeight = measured.rows.length * measured.rowHeight + Math.max(0, measured.rows.length - 1) * measured.rowGapY;
239
+ const startY = position === "topRight" ? legendBox.y : legendBox.y + Math.max(0, (legendBox.height - totalContentHeight) / 2);
240
+ for (let r = 0; r < measured.rows.length; r += 1) {
241
+ const row = measured.rows[r];
242
+ const rowY = startY + r * (measured.rowHeight + measured.rowGapY);
243
+ if (rowY >= legendBox.y + legendBox.height) break;
244
+ const rowWidth = row.reduce((sum, item, idx) => sum + item.itemWidth + (idx > 0 ? measured.itemGapX : 0), 0);
245
+ let cursorX = position === "top" || position === "bottom" ? legendBox.x + Math.max(0, (legendBox.width - rowWidth) / 2) : legendBox.x;
246
+ for (const item of row) {
247
+ parts.push(renderLegendIconSvg(item.entry, cursorX, rowY, measured));
248
+ const textX = cursorX + measured.iconWidth + measured.swatchGap;
249
+ const availableTextWidth = Math.max(1, Math.min(item.itemWidth - measured.iconWidth - measured.swatchGap, legendBox.x + legendBox.width - textX));
250
+ parts.push(renderChartTextSvg({
251
+ text: item.entry.label,
252
+ box: {
253
+ x: textX,
254
+ y: rowY,
255
+ width: availableTextWidth,
256
+ height: measured.rowHeight
257
+ },
258
+ style,
259
+ theme,
260
+ slideNumber,
261
+ labelPath: "Chart.legend",
262
+ align: "left",
263
+ verticalAlign: "middle",
264
+ wrap: false,
265
+ clipBox: legendBox,
266
+ clipAllocator
267
+ }));
268
+ cursorX += item.itemWidth + measured.itemGapX;
269
+ }
270
+ }
271
+ return parts.join("");
272
+ }
273
+ export { collectLegendEntries, measureLegend, renderLegendSvg };
@@ -0,0 +1,404 @@
1
+ import { renderMarkerSvg, resolveEffectiveMarker } from "./markers.js";
2
+ import { resolveChartLineStroke, resolveSeriesColor, strokeAttrs } from "./style.js";
3
+ // ../capabilities/dist/chart/preview/line-area.js
4
+ /**
5
+ * Computes Catmull-Rom cubic Bezier control points (tension = 1/6) for segment `pCurr -> pNext`.
6
+ */
7
+ function catmullRomControlPoints(pPrev, pCurr, pNext, pNext2) {
8
+ return {
9
+ c1: {
10
+ x: pCurr.x + (pNext.x - pPrev.x) / 6,
11
+ y: pCurr.y + (pNext.y - pPrev.y) / 6
12
+ },
13
+ c2: {
14
+ x: pNext.x - (pNext2.x - pCurr.x) / 6,
15
+ y: pNext.y - (pNext2.y - pCurr.y) / 6
16
+ }
17
+ };
18
+ }
19
+ /**
20
+ * Builds an SVG polyline or Catmull-Rom cubic Bezier path for a contiguous point sequence.
21
+ */
22
+ function buildSmoothOrLinearPath(points, smooth) {
23
+ if (points.length === 0) return "";
24
+ const first = points[0];
25
+ if (points.length === 1) return `M${first.x} ${first.y}`;
26
+ if (!smooth || points.length === 2) return `M${first.x} ${first.y}` + points.slice(1).map((p) => `L${p.x} ${p.y}`).join("");
27
+ const cmds = [`M${first.x} ${first.y}`];
28
+ for (let i = 0; i < points.length - 1; i += 1) {
29
+ const pPrev = points[Math.max(0, i - 1)];
30
+ const pCurr = points[i];
31
+ const pNext = points[i + 1];
32
+ const pNext2 = points[Math.min(points.length - 1, i + 2)];
33
+ const { c1, c2 } = catmullRomControlPoints(pPrev, pCurr, pNext, pNext2);
34
+ cmds.push(`C${c1.x} ${c1.y} ${c2.x} ${c2.y} ${pNext.x} ${pNext.y}`);
35
+ }
36
+ return cmds.join("");
37
+ }
38
+ function strokesEqual(a, b) {
39
+ return a.hex === b.hex && a.alpha === b.alpha && a.width === b.width && a.dashArray === b.dashArray;
40
+ }
41
+ /**
42
+ * Renders a contiguous line run while respecting per-point line/color overrides on incoming segments.
43
+ */
44
+ function renderStyledLineRun(options) {
45
+ const { run, smooth, baseStroke, segmentStrokeOf } = options;
46
+ if (run.length === 0) return "";
47
+ if (run.length === 1) return "";
48
+ const segStrokes = run.slice(1).map((pt) => segmentStrokeOf(pt));
49
+ if (segStrokes.every((st) => strokesEqual(st, baseStroke))) return `<path d="${buildSmoothOrLinearPath(run, smooth)}" fill="none" ${strokeAttrs(baseStroke)} stroke-linejoin="round" stroke-linecap="round"/>`;
50
+ const parts = [];
51
+ let segIdx = 0;
52
+ while (segIdx < segStrokes.length) {
53
+ const st = segStrokes[segIdx];
54
+ const startSeg = segIdx;
55
+ while (segIdx < segStrokes.length && strokesEqual(segStrokes[segIdx], st)) segIdx += 1;
56
+ const endSeg = segIdx;
57
+ const cmds = [`M${run[startSeg].x} ${run[startSeg].y}`];
58
+ for (let i = startSeg; i < endSeg; i += 1) {
59
+ const pCurr = run[i];
60
+ const pNext = run[i + 1];
61
+ if (!smooth || run.length === 2) cmds.push(`L${pNext.x} ${pNext.y}`);
62
+ else {
63
+ const pPrev = run[Math.max(0, i - 1)];
64
+ const pNext2 = run[Math.min(run.length - 1, i + 2)];
65
+ const { c1, c2 } = catmullRomControlPoints(pPrev, pCurr, pNext, pNext2);
66
+ cmds.push(`C${c1.x} ${c1.y} ${c2.x} ${c2.y} ${pNext.x} ${pNext.y}`);
67
+ }
68
+ }
69
+ parts.push(`<path d="${cmds.join("")}" fill="none" ${strokeAttrs(st)} stroke-linejoin="round" stroke-linecap="round"/>`);
70
+ }
71
+ return parts.join("");
72
+ }
73
+ function resolvePointSegmentStroke(options) {
74
+ const { pointLine, pointColor, seriesLine, seriesColor, seriesIndex, baseStroke, theme } = options;
75
+ if (pointLine === void 0 && pointColor === void 0) return baseStroke;
76
+ const mergedLine = pointLine !== void 0 ? {
77
+ ...pointLine,
78
+ ...pointLine.color === void 0 && pointColor !== void 0 ? { color: pointColor } : {}
79
+ } : {
80
+ ...seriesLine,
81
+ color: pointColor
82
+ };
83
+ return resolveChartLineStroke(mergedLine, theme, {
84
+ color: pointColor ?? seriesLine?.color ?? seriesColor ?? `accent${seriesIndex % 6 + 1}`,
85
+ width: baseStroke.width,
86
+ alpha: baseStroke.alpha
87
+ });
88
+ }
89
+ function renderLineGroup(options) {
90
+ const { group, groupIndex, scales, plotRect, displayBlanksAs, theme } = options;
91
+ const catScale = scales.get(group.axes.category.name);
92
+ const valScale = scales.get(group.axes.value.name);
93
+ if (catScale?.kind !== "category" || valScale?.kind !== "value") return {
94
+ svg: "",
95
+ anchors: []
96
+ };
97
+ const categories = group.data.categories;
98
+ const seriesCount = group.series.length;
99
+ if (categories.length === 0 || seriesCount === 0) return {
100
+ svg: "",
101
+ anchors: []
102
+ };
103
+ const isStacked = group.stacking !== "standard";
104
+ const isPercent = group.stacking === "percent";
105
+ const effectiveBlanks = isStacked ? "zero" : displayBlanksAs ?? "gap";
106
+ const percentTotals = isPercent ? categories.map((_, catIdx) => {
107
+ let sum = 0;
108
+ for (const s of group.series) {
109
+ const v = s.values[catIdx];
110
+ if (v !== null && v !== void 0 && Number.isFinite(v)) sum += Math.abs(v);
111
+ }
112
+ return sum;
113
+ }) : [];
114
+ const posAcc = Array.from({ length: categories.length }, () => 0);
115
+ const negAcc = Array.from({ length: categories.length }, () => 0);
116
+ const parts = [];
117
+ const anchors = [];
118
+ for (let s = 0; s < seriesCount; s += 1) {
119
+ const series = group.series[s];
120
+ const baseStroke = resolveChartLineStroke(series.line, theme, {
121
+ color: series.color ?? `accent${series.seriesIndex % 6 + 1}`,
122
+ width: 2
123
+ });
124
+ const runs = [];
125
+ let currentRun = [];
126
+ const markerQueue = [];
127
+ for (let catIdx = 0; catIdx < categories.length; catIdx += 1) {
128
+ const raw = series.values[catIdx];
129
+ const isMissing = raw === null || raw === void 0 || !Number.isFinite(raw);
130
+ let plotted;
131
+ let percent;
132
+ if (isMissing) {
133
+ if (effectiveBlanks === "zero") plotted = 0;
134
+ else if (effectiveBlanks === "span") continue;
135
+ else {
136
+ if (currentRun.length > 0) {
137
+ runs.push(currentRun);
138
+ currentRun = [];
139
+ }
140
+ continue;
141
+ }
142
+ } else if (isPercent) {
143
+ const totalAbs = percentTotals[catIdx] ?? 0;
144
+ plotted = totalAbs === 0 ? 0 : raw / totalAbs;
145
+ percent = totalAbs === 0 ? 0 : Math.abs(raw) / totalAbs;
146
+ } else plotted = raw;
147
+ let stackedVal = plotted;
148
+ if (isStacked) {
149
+ if (plotted >= 0) {
150
+ posAcc[catIdx] = (posAcc[catIdx] ?? 0) + plotted;
151
+ stackedVal = posAcc[catIdx];
152
+ } else {
153
+ negAcc[catIdx] = (negAcc[catIdx] ?? 0) + plotted;
154
+ stackedVal = negAcc[catIdx];
155
+ }
156
+ }
157
+ if (valScale.logBase !== void 0 && stackedVal <= 0) {
158
+ if (effectiveBlanks === "gap" && currentRun.length > 0) {
159
+ runs.push(currentRun);
160
+ currentRun = [];
161
+ }
162
+ continue;
163
+ }
164
+ const x = catScale.indexToScreen(catIdx, plotRect);
165
+ const y = valScale.valueToScreen(stackedVal, plotRect);
166
+ const point = series.points?.[catIdx];
167
+ const marker = resolveEffectiveMarker({
168
+ groupDefaultEnabled: false,
169
+ seriesMarker: series.marker,
170
+ pointMarker: point?.marker,
171
+ seriesColor: series.color,
172
+ pointColor: point?.color,
173
+ seriesIndex: series.seriesIndex,
174
+ theme
175
+ });
176
+ const segmentStroke = resolvePointSegmentStroke({
177
+ pointLine: point?.line,
178
+ pointColor: point?.color,
179
+ seriesLine: series.line,
180
+ seriesColor: series.color,
181
+ seriesIndex: series.seriesIndex,
182
+ baseStroke,
183
+ theme
184
+ });
185
+ currentRun.push({
186
+ x,
187
+ y,
188
+ pointIndex: catIdx,
189
+ marker,
190
+ segmentStroke
191
+ });
192
+ if (!isMissing) anchors.push({
193
+ kind: "point",
194
+ groupIndex,
195
+ seriesIndex: series.seriesIndex,
196
+ groupSeriesIndex: s,
197
+ pointIndex: catIdx,
198
+ value: raw,
199
+ plottedValue: stackedVal,
200
+ category: categories[catIdx] ?? "",
201
+ seriesName: series.name,
202
+ x,
203
+ y,
204
+ ...marker === void 0 ? {} : { markerRadius: marker.radius },
205
+ ...percent === void 0 ? {} : { percent }
206
+ });
207
+ }
208
+ if (currentRun.length > 0) runs.push(currentRun);
209
+ for (const run of runs) {
210
+ if (run.length >= 2) parts.push(renderStyledLineRun({
211
+ run,
212
+ smooth: series.smooth === true,
213
+ baseStroke,
214
+ segmentStrokeOf: (pt) => pt.segmentStroke
215
+ }));
216
+ for (const node of run) markerQueue.push({
217
+ x: node.x,
218
+ y: node.y,
219
+ marker: node.marker,
220
+ isolated: run.length === 1
221
+ });
222
+ }
223
+ for (const item of markerQueue) if (item.marker !== void 0) parts.push(renderMarkerSvg(item.x, item.y, item.marker));
224
+ else if (item.isolated) {
225
+ const dotColor = resolveSeriesColor(series.line?.color ?? series.color, series.seriesIndex, theme);
226
+ parts.push(`<circle cx="${item.x}" cy="${item.y}" r="${Math.max(1.5, baseStroke.width * .75)}" fill="#${dotColor.hex}" fill-opacity="${dotColor.alpha ?? 1}"/>`);
227
+ }
228
+ }
229
+ return {
230
+ svg: parts.join(""),
231
+ anchors
232
+ };
233
+ }
234
+ function renderAreaGroup(options) {
235
+ const { group, groupIndex, scales, plotRect, displayBlanksAs, theme } = options;
236
+ const catScale = scales.get(group.axes.category.name);
237
+ const valScale = scales.get(group.axes.value.name);
238
+ if (catScale?.kind !== "category" || valScale?.kind !== "value") return {
239
+ svg: "",
240
+ anchors: []
241
+ };
242
+ const categories = group.data.categories;
243
+ const seriesCount = group.series.length;
244
+ if (categories.length === 0 || seriesCount === 0) return {
245
+ svg: "",
246
+ anchors: []
247
+ };
248
+ const isStacked = group.stacking !== "standard";
249
+ const isPercent = group.stacking === "percent";
250
+ const effectiveBlanks = isStacked || displayBlanksAs === "zero" ? "zero" : "gap";
251
+ const percentTotals = isPercent ? categories.map((_, catIdx) => {
252
+ let sum = 0;
253
+ for (const s of group.series) {
254
+ const v = s.values[catIdx];
255
+ if (v !== null && v !== void 0 && Number.isFinite(v)) sum += Math.abs(v);
256
+ }
257
+ return sum;
258
+ }) : [];
259
+ const posAcc = Array.from({ length: categories.length }, () => 0);
260
+ const negAcc = Array.from({ length: categories.length }, () => 0);
261
+ const parts = [];
262
+ const anchors = [];
263
+ const baseY = valScale.zeroScreen(plotRect);
264
+ for (let s = 0; s < seriesCount; s += 1) {
265
+ const series = group.series[s];
266
+ const fill = resolveSeriesColor(series.color, series.seriesIndex, theme);
267
+ const stroke = series.line === void 0 ? void 0 : resolveChartLineStroke(series.line, theme, {
268
+ color: "dk1",
269
+ width: 1
270
+ });
271
+ const strokeAttr = stroke === void 0 ? "" : ` ${strokeAttrs(stroke)}`;
272
+ const fillAttr = `fill="#${fill.hex}" fill-opacity="${fill.alpha ?? 1}"`;
273
+ if (!isStacked) {
274
+ const runs = [];
275
+ let currentRun = [];
276
+ for (let catIdx = 0; catIdx < categories.length; catIdx += 1) {
277
+ const raw = series.values[catIdx];
278
+ const isMissing = raw === null || raw === void 0 || !Number.isFinite(raw);
279
+ if (isMissing && effectiveBlanks === "gap") {
280
+ if (currentRun.length > 0) {
281
+ runs.push(currentRun);
282
+ currentRun = [];
283
+ }
284
+ continue;
285
+ }
286
+ const plotted = isMissing ? 0 : raw;
287
+ if (valScale.logBase !== void 0 && plotted <= 0) {
288
+ if (currentRun.length > 0) {
289
+ runs.push(currentRun);
290
+ currentRun = [];
291
+ }
292
+ continue;
293
+ }
294
+ const x = catScale.indexToScreen(catIdx, plotRect);
295
+ const y = valScale.valueToScreen(plotted, plotRect);
296
+ currentRun.push({
297
+ x,
298
+ y,
299
+ pointIndex: catIdx,
300
+ rawValue: plotted,
301
+ isMissing
302
+ });
303
+ }
304
+ if (currentRun.length > 0) runs.push(currentRun);
305
+ for (const run of runs) {
306
+ if (run.length >= 2) {
307
+ const first = run[0];
308
+ const last = run[run.length - 1];
309
+ const topSegs = run.map((pt) => `L${pt.x} ${pt.y}`).join("");
310
+ parts.push(`<path d="M${first.x} ${baseY}${topSegs}L${last.x} ${baseY}Z" ${fillAttr}${strokeAttr} stroke-linejoin="round"/>`);
311
+ } else if (run.length === 1 && stroke !== void 0) {
312
+ const pt = run[0];
313
+ parts.push(`<path d="M${pt.x} ${baseY}V${pt.y}" fill="none" ${strokeAttrs(stroke)}/>`);
314
+ }
315
+ for (const node of run) if (!node.isMissing) anchors.push({
316
+ kind: "point",
317
+ groupIndex,
318
+ seriesIndex: series.seriesIndex,
319
+ groupSeriesIndex: s,
320
+ pointIndex: node.pointIndex,
321
+ value: node.rawValue,
322
+ category: categories[node.pointIndex] ?? "",
323
+ seriesName: series.name,
324
+ x: node.x,
325
+ y: node.y
326
+ });
327
+ }
328
+ } else {
329
+ const topPts = [];
330
+ const botPts = [];
331
+ for (let catIdx = 0; catIdx < categories.length; catIdx += 1) {
332
+ const raw = series.values[catIdx];
333
+ const isMissing = raw === null || raw === void 0 || !Number.isFinite(raw);
334
+ let plotted;
335
+ let percent;
336
+ if (isMissing) plotted = 0;
337
+ else if (isPercent) {
338
+ const totalAbs = percentTotals[catIdx] ?? 0;
339
+ plotted = totalAbs === 0 ? 0 : raw / totalAbs;
340
+ percent = totalAbs === 0 ? 0 : Math.abs(raw) / totalAbs;
341
+ } else plotted = raw;
342
+ let botVal;
343
+ let topVal;
344
+ if (plotted >= 0) {
345
+ botVal = posAcc[catIdx] ?? 0;
346
+ topVal = botVal + plotted;
347
+ posAcc[catIdx] = topVal;
348
+ } else {
349
+ botVal = negAcc[catIdx] ?? 0;
350
+ topVal = botVal + plotted;
351
+ negAcc[catIdx] = topVal;
352
+ }
353
+ if (valScale.logBase !== void 0 && topVal <= 0) continue;
354
+ const safeBotVal = valScale.logBase !== void 0 ? Math.max(valScale.min, botVal) : botVal;
355
+ const x = catScale.indexToScreen(catIdx, plotRect);
356
+ const topY = valScale.valueToScreen(topVal, plotRect);
357
+ const botY = valScale.valueToScreen(safeBotVal, plotRect);
358
+ topPts.push({
359
+ x,
360
+ y: topY
361
+ });
362
+ botPts.push({
363
+ x,
364
+ y: botY
365
+ });
366
+ if (!isMissing) anchors.push({
367
+ kind: "point",
368
+ groupIndex,
369
+ seriesIndex: series.seriesIndex,
370
+ groupSeriesIndex: s,
371
+ pointIndex: catIdx,
372
+ value: raw,
373
+ plottedValue: topVal,
374
+ category: categories[catIdx] ?? "",
375
+ seriesName: series.name,
376
+ x,
377
+ y: topY,
378
+ ...percent === void 0 ? {} : { percent }
379
+ });
380
+ }
381
+ if (topPts.length >= 2) {
382
+ const firstTop = topPts[0];
383
+ const topCmds = topPts.slice(1).map((pt) => `L${pt.x} ${pt.y}`).join("");
384
+ const botCmds = botPts.toReversed().map((pt) => `L${pt.x} ${pt.y}`).join("");
385
+ parts.push(`<path d="M${firstTop.x} ${firstTop.y}${topCmds}${botCmds}Z" ${fillAttr}${strokeAttr} stroke-linejoin="round"/>`);
386
+ }
387
+ }
388
+ }
389
+ return {
390
+ svg: parts.join(""),
391
+ anchors
392
+ };
393
+ }
394
+ function renderLineOrAreaGroup(options) {
395
+ if (options.group.kind === "line") return renderLineGroup({
396
+ ...options,
397
+ group: options.group
398
+ });
399
+ return renderAreaGroup({
400
+ ...options,
401
+ group: options.group
402
+ });
403
+ }
404
+ export { buildSmoothOrLinearPath, catmullRomControlPoints, renderLineOrAreaGroup, renderStyledLineRun, resolvePointSegmentStroke };