@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,1119 @@
1
+ import { CapabilityError } from "../../../core/dist/diagnostics.js";
2
+ import { parseLinkTarget } from "../../../core/dist/author-schemas.js";
3
+ import { parseCapabilityLayoutContract } from "../../../core/dist/layout.js";
4
+ import "../../../core/dist/capability.js";
5
+ import "../../../import/dist/index.js";
6
+ import { defineCanvasMechanism } from "../../../import/dist/mechanism.js";
7
+ import { fontPresentationContributions } from "../font/font-embedding.js";
8
+ import { motionAnnotations, pickMotionProps } from "../motion/motion-api.js";
9
+ import { parseMorphKey, parseOptionalName } from "../shared/identity.js";
10
+ import { resolvePlaceholderGeometry } from "../shared/style-inheritance.js";
11
+ import { writeChartTextProperties, writeChartTitle } from "../shared/text-service.js";
12
+ import { chartCodegen } from "./chart-codegen.js";
13
+ import { chartImportHandler, chartPlaceholderImportHandler } from "./chart-import.js";
14
+ import { mergeDataLabels } from "./chart-labels.js";
15
+ import { textOnlyChartStyle } from "./chart-model.js";
16
+ import { chartAllowedPropKeys, chartStyleKeys, parseChartAxisBySchema, parseChartCoordinateBySchema, parseChartDisplayBlanksAsBySchema, parseChartExtentBySchema, parseChartGroupBySchema, parseChartLegendBySchema, parseChartPlotAreaBySchema, parseChartTitleBySchema, parseChartXmlTextBySchema } from "./chart-schemas.js";
17
+ import { chartFrameXml, chartPartXml, chartUsesCategoryLabelRange, chartWorkbook } from "./chart-xml.js";
18
+ import { drawChartPreview } from "./preview/index.js";
19
+ import "./chart-declaration.js";
20
+ // ../capabilities/dist/chart/chart.js
21
+ const chartRelationship = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/chart";
22
+ const packageRelationship = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/package";
23
+ const chartContentType = "application/vnd.openxmlformats-officedocument.drawingml.chart+xml";
24
+ const workbookContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
25
+ const horizontalAxisPositions = ["bottom", "top"];
26
+ const verticalAxisPositions = ["left", "right"];
27
+ const nativeAxisIds = [
28
+ 111111,
29
+ 222222,
30
+ 333333,
31
+ 444444
32
+ ];
33
+ function fail(code, message, path) {
34
+ throw new CapabilityError(code, message, path);
35
+ }
36
+ function isRecord(value) {
37
+ return typeof value === "object" && value !== null && !Array.isArray(value);
38
+ }
39
+ function hasVisibleDataLabels(value) {
40
+ return value !== void 0 && value !== false && (value.value === true || value.percent === true || value.category === true || value.xValue === true || value.seriesName === true);
41
+ }
42
+ function hasLeaderLinesWithoutVisibleLabels(groupLabels, series) {
43
+ return series.some((item) => {
44
+ const labels = mergeDataLabels(groupLabels, item.dataLabels);
45
+ return labels !== void 0 && labels !== false && labels.leaderLines !== void 0 && labels.leaderLines !== false && !hasVisibleDataLabels(labels);
46
+ });
47
+ }
48
+ function chartGroupDrafts(value) {
49
+ if (!Array.isArray(value) || value.length === 0) fail("invalid-chart-groups", "Chart.groups must contain at least one group");
50
+ return value.map((rawItem, groupIndex) => {
51
+ const label = `Chart.groups[${groupIndex}]`;
52
+ const group = parseChartGroupBySchema(rawItem, label);
53
+ if (group.kind === "scatter") return {
54
+ kind: "scatter",
55
+ data: group.data,
56
+ series: group.series,
57
+ markers: group.markers ?? true,
58
+ ...group.axes === void 0 ? {} : { axes: group.axes },
59
+ ...group.dataLabels === void 0 ? {} : { dataLabels: group.dataLabels },
60
+ ...group.line === void 0 ? {} : { line: group.line }
61
+ };
62
+ const categoriesForSeries = (item) => group.data.kind === "independent-categories" ? item.categories : group.data.categories;
63
+ const series = group.series.map((item) => ({
64
+ ...item,
65
+ categories: categoriesForSeries(item)
66
+ }));
67
+ if ((group.kind === "pie" || group.kind === "doughnut") && hasLeaderLinesWithoutVisibleLabels(group.dataLabels, series)) fail("invalid-data-labels", "leaderLines requires at least one visible data label value, percent, or category");
68
+ if (group.kind === "column" || group.kind === "bar") return {
69
+ kind: group.kind,
70
+ data: group.data,
71
+ series,
72
+ ...group.axes === void 0 ? {} : { axes: group.axes },
73
+ ...group.dataLabels === void 0 ? {} : { dataLabels: group.dataLabels },
74
+ ...group.stacking === void 0 ? {} : { stacking: group.stacking },
75
+ ...group.gapWidth === void 0 ? {} : { gapWidth: group.gapWidth },
76
+ ...group.overlap === void 0 ? {} : { overlap: group.overlap }
77
+ };
78
+ if (group.kind === "line" || group.kind === "area") return {
79
+ kind: group.kind,
80
+ data: group.data,
81
+ series,
82
+ ...group.axes === void 0 ? {} : { axes: group.axes },
83
+ ...group.dataLabels === void 0 ? {} : { dataLabels: group.dataLabels },
84
+ ...group.stacking === void 0 ? {} : { stacking: group.stacking }
85
+ };
86
+ if (group.kind === "pie") return {
87
+ kind: "pie",
88
+ data: group.data,
89
+ series,
90
+ ...group.dataLabels === void 0 ? {} : { dataLabels: group.dataLabels },
91
+ ...group.explosion === void 0 ? {} : { explosion: group.explosion },
92
+ ...group.firstSliceAngle === void 0 ? {} : { firstSliceAngle: group.firstSliceAngle }
93
+ };
94
+ if (group.kind !== "doughnut") throw new Error(`Unexpected chart group kind: ${String(group.kind)}`);
95
+ return {
96
+ kind: "doughnut",
97
+ data: group.data,
98
+ series,
99
+ ...group.dataLabels === void 0 ? {} : { dataLabels: group.dataLabels },
100
+ ...group.explosion === void 0 ? {} : { explosion: group.explosion },
101
+ ...group.firstSliceAngle === void 0 ? {} : { firstSliceAngle: group.firstSliceAngle },
102
+ ...group.holeSize === void 0 ? {} : { holeSize: group.holeSize }
103
+ };
104
+ });
105
+ }
106
+ const nativeAxisIdLimit = nativeAxisIds.length;
107
+ function axisEntries(value, groups) {
108
+ const scatterOnly = groups.every((group) => group.kind === "scatter");
109
+ if (groups.every((group) => group.kind === "pie" || group.kind === "doughnut")) {
110
+ if (groups.length !== 1) fail("unsupported-chart-group-combination", "Pie and doughnut charts support one chart group");
111
+ if (value !== void 0) fail("invalid-chart-axes", "Pie and doughnut charts do not use category or value axes");
112
+ return {
113
+ entries: [],
114
+ axisless: true
115
+ };
116
+ }
117
+ if (groups.some((group) => group.kind === "pie" || group.kind === "doughnut")) fail("unsupported-chart-group-combination", "Pie and doughnut charts support one chart group");
118
+ if (value === void 0 && !scatterOnly && new Set(groups.map((group) => group.kind)).size > 1) fail("invalid-chart-axes", "Charts that combine different group kinds must declare chart-level axes and explicit group references");
119
+ let entries;
120
+ if (value === void 0) entries = scatterOnly ? [{
121
+ name: "x",
122
+ spec: { kind: "value" }
123
+ }, {
124
+ name: "y",
125
+ spec: { kind: "value" }
126
+ }] : [{
127
+ name: "category",
128
+ spec: { kind: "category" }
129
+ }, {
130
+ name: "value",
131
+ spec: { kind: "value" }
132
+ }];
133
+ else {
134
+ if (!isRecord(value)) fail("invalid-axis", "Chart.axes must be an object");
135
+ entries = Object.entries(value).map(([name, spec]) => {
136
+ if (name.trim() === "") fail("invalid-axis", "Chart.axes names must be non-empty strings");
137
+ if (!isRecord(spec)) fail("invalid-axis", `Chart.axes.${name} must be an object`);
138
+ const kind = spec["kind"];
139
+ if (kind !== "category" && kind !== "value") fail("invalid-chart-axis-role", `Chart.axes.${name}.kind must be "category" or "value"`);
140
+ return {
141
+ name,
142
+ spec: parseChartAxisBySchema(spec, `Chart.axes.${name}`, kind)
143
+ };
144
+ });
145
+ }
146
+ if (entries.length === 0) fail("invalid-axis", "Chart.axes must define at least one axis");
147
+ if (entries.length > nativeAxisIdLimit) fail("unsupported-chart-axis", "Office supports at most four chart axes per chart");
148
+ return {
149
+ entries,
150
+ axisless: false
151
+ };
152
+ }
153
+ function parsedAxes(value, groups) {
154
+ const { entries, axisless } = axisEntries(value, groups);
155
+ if (axisless) return {
156
+ axes: [],
157
+ groupAxes: groups.map(() => void 0)
158
+ };
159
+ const entryByName = new Map(entries.map((entry) => [entry.name, entry]));
160
+ const draftByName = /* @__PURE__ */ new Map();
161
+ const firstUse = [];
162
+ const resolvedGroups = [];
163
+ const resolve = (name, expected, label) => {
164
+ const entry = entryByName.get(name);
165
+ if (entry === void 0) fail("unknown-chart-axis", `${label} references unknown axis "${name}"`);
166
+ if (entry.spec.kind !== expected) fail("invalid-chart-axis-role", `${label} references "${name}", which is not a ${expected} axis`);
167
+ let draft = draftByName.get(name);
168
+ if (draft === void 0) {
169
+ draft = {
170
+ name,
171
+ spec: entry.spec
172
+ };
173
+ draftByName.set(name, draft);
174
+ }
175
+ if (!firstUse.includes(draft)) firstUse.push(draft);
176
+ return draft;
177
+ };
178
+ const assignDirection = (axis, direction) => {
179
+ if (axis.direction !== void 0 && axis.direction !== direction) fail("invalid-chart-axes", `Chart axis "${axis.name}" cannot be both horizontal and vertical`);
180
+ axis.direction = direction;
181
+ };
182
+ const defaultPair = (first, second, kind) => entries.length === 2 && entryByName.get(first)?.spec.kind === kind && entryByName.get(second)?.spec.kind === "value";
183
+ for (const [groupIndex, group] of groups.entries()) {
184
+ const label = `Chart.groups[${groupIndex}]`;
185
+ if (group.kind === "scatter") {
186
+ let references = group.axes;
187
+ if (references === void 0) {
188
+ if (!defaultPair("x", "y", "value")) fail("invalid-chart-axes", `${label} must reference chart-level X and Y axes`);
189
+ references = {
190
+ x: "x",
191
+ y: "y"
192
+ };
193
+ }
194
+ const x = resolve(references.x, "value", `${label} X`);
195
+ const y = resolve(references.y, "value", `${label} Y`);
196
+ if (x === y) fail("invalid-chart-axes", `${label} must reference distinct X and Y value axes`);
197
+ assignDirection(x, "horizontal");
198
+ assignDirection(y, "vertical");
199
+ resolvedGroups.push({
200
+ kind: "scatter",
201
+ x,
202
+ y
203
+ });
204
+ continue;
205
+ }
206
+ let references = group.axes;
207
+ if (references === void 0) {
208
+ if (!defaultPair("category", "value", "category")) fail("invalid-chart-axes", `${label} must reference chart-level category and value axes`);
209
+ references = {
210
+ category: "category",
211
+ value: "value"
212
+ };
213
+ }
214
+ const category = resolve(references.category, "category", `${label} category axis`);
215
+ const valueAxis = resolve(references.value, "value", `${label} value axis`);
216
+ if (category === valueAxis) fail("invalid-chart-axes", `${label} must reference distinct category and value axes`);
217
+ if (group.kind === "bar") {
218
+ assignDirection(category, "vertical");
219
+ assignDirection(valueAxis, "horizontal");
220
+ } else {
221
+ assignDirection(category, "horizontal");
222
+ assignDirection(valueAxis, "vertical");
223
+ }
224
+ resolvedGroups.push({
225
+ kind: "category",
226
+ category,
227
+ value: valueAxis
228
+ });
229
+ }
230
+ for (const entry of entries) if (!firstUse.some((axis) => axis.name === entry.name)) fail("invalid-chart-axes", `Chart axis "${entry.name}" is not referenced by any chart group`);
231
+ const partnersByAxis = /* @__PURE__ */ new Map();
232
+ const addPartner = (left, right) => {
233
+ const leftPartners = partnersByAxis.get(left);
234
+ if (leftPartners === void 0) partnersByAxis.set(left, [right]);
235
+ else if (!leftPartners.includes(right)) leftPartners.push(right);
236
+ };
237
+ for (const group of resolvedGroups) {
238
+ const first = group.kind === "category" ? group.category : group.x;
239
+ const second = group.kind === "category" ? group.value : group.y;
240
+ addPartner(first, second);
241
+ addPartner(second, first);
242
+ }
243
+ const partnersOf = (axis) => partnersByAxis.get(axis) ?? [];
244
+ const sharesPartner = (left, right) => partnersOf(left).some((partner) => partnersOf(right).includes(partner));
245
+ const explicitCrossing = (axis) => {
246
+ if (axis.spec.crossesAt !== void 0) return {
247
+ kind: "crossesAt",
248
+ value: axis.spec.crossesAt
249
+ };
250
+ if (axis.spec.crosses !== void 0) return {
251
+ kind: "crosses",
252
+ value: axis.spec.crosses
253
+ };
254
+ };
255
+ const positionAxes = /* @__PURE__ */ new Map();
256
+ const claimPosition = (axis, position) => {
257
+ const occupants = positionAxes.get(position) ?? [];
258
+ axis.position = position;
259
+ if (occupants.length === 0) positionAxes.set(position, [axis]);
260
+ else occupants.push(axis);
261
+ };
262
+ for (const axis of firstUse) {
263
+ const position = axis.spec.position;
264
+ if (position === void 0) continue;
265
+ if (!(axis.direction === "horizontal" ? horizontalAxisPositions : verticalAxisPositions).includes(position)) fail("invalid-chart-axes", `Chart axis "${axis.name}" position "${position}" does not match its ${axis.direction} direction`);
266
+ claimPosition(axis, position);
267
+ }
268
+ for (const axis of firstUse) {
269
+ if (axis.position !== void 0) continue;
270
+ const allowed = axis.direction === "horizontal" ? horizontalAxisPositions : verticalAxisPositions;
271
+ const shared = firstUse.find((other) => other !== axis && other.position !== void 0 && other.direction === axis.direction && sharesPartner(axis, other));
272
+ if (shared !== void 0) {
273
+ claimPosition(axis, shared.position);
274
+ continue;
275
+ }
276
+ const position = allowed.find((item) => !positionAxes.has(item));
277
+ if (position === void 0) fail("unsupported-chart-axis", `Office supports at most two independent ${axis.direction} axes per chart`);
278
+ claimPosition(axis, position);
279
+ }
280
+ const maxSide = (direction) => direction === "vertical" ? "right" : "top";
281
+ const rawCrossingForPosition = (axis, partner, position) => {
282
+ if (!(axis.spec.position !== void 0 || position === maxSide(axis.direction))) return {
283
+ kind: "crosses",
284
+ value: "autoZero"
285
+ };
286
+ const partnerReversed = partner.spec.reversed === true;
287
+ if (axis.direction === "vertical") {
288
+ const rightIsMax = !partnerReversed;
289
+ return {
290
+ kind: "crosses",
291
+ value: position === "right" ? rightIsMax ? "max" : "min" : rightIsMax ? "min" : "max"
292
+ };
293
+ }
294
+ const topIsMax = !partnerReversed;
295
+ return {
296
+ kind: "crosses",
297
+ value: position === "top" ? topIsMax ? "max" : "min" : topIsMax ? "min" : "max"
298
+ };
299
+ };
300
+ const positionForRawCrossing = (crossing, partner, direction) => {
301
+ if (crossing.kind !== "crosses" || crossing.value === "autoZero") return;
302
+ const maxAtFarEnd = partner.spec.reversed !== true;
303
+ if (direction === "vertical") return crossing.value === "max" === maxAtFarEnd ? "right" : "left";
304
+ return crossing.value === "max" === maxAtFarEnd ? "top" : "bottom";
305
+ };
306
+ const knownValueEndpoint = (crossing, partner) => {
307
+ if (partner.spec.kind !== "value") return void 0;
308
+ const min = partner.spec.min;
309
+ const max = partner.spec.max;
310
+ if (min === void 0 || max === void 0 || min === max) return void 0;
311
+ if (crossing.kind === "crossesAt") {
312
+ if (crossing.value === min) return "min";
313
+ if (crossing.value === max) return "max";
314
+ return;
315
+ }
316
+ if (crossing.kind !== "crosses" || crossing.value !== "autoZero") return;
317
+ if (min === 0) return "min";
318
+ if (max === 0) return "max";
319
+ };
320
+ const crossesKnownValueInterior = (crossing, partner) => {
321
+ if (partner.spec.kind !== "value") return false;
322
+ const min = partner.spec.min;
323
+ const max = partner.spec.max;
324
+ if (min === void 0 || max === void 0) return false;
325
+ const low = Math.min(min, max);
326
+ const high = Math.max(min, max);
327
+ if (crossing.kind === "crossesAt") return crossing.value > low && crossing.value < high;
328
+ return crossing.kind === "crosses" && crossing.value === "autoZero" && low < 0 && high > 0;
329
+ };
330
+ const sameCrossing = (left, right) => left.kind === right.kind && (left.kind === "crossesAt" ? right.kind === "crossesAt" && left.value === right.value : right.kind === "crosses" && left.value === right.value);
331
+ for (const axis of firstUse) {
332
+ const desired = /* @__PURE__ */ new Set();
333
+ for (const partner of partnersOf(axis)) {
334
+ const crossing = explicitCrossing(partner);
335
+ if (crossing === void 0) continue;
336
+ if (axis.spec.position !== void 0) {
337
+ if (crossesKnownValueInterior(crossing, partner)) fail("invalid-chart-axes", `Chart axis "${axis.name}" position "${axis.spec.position}" conflicts with the known interior crossing on "${partner.name}"`);
338
+ const endpoint = knownValueEndpoint(crossing, partner);
339
+ if (endpoint !== void 0) {
340
+ const edge = positionForRawCrossing({
341
+ kind: "crosses",
342
+ value: endpoint
343
+ }, partner, axis.direction);
344
+ if (edge !== void 0 && edge !== axis.spec.position) fail("invalid-chart-axes", `Chart axis "${axis.name}" position "${axis.spec.position}" conflicts with the known crossing endpoint on "${partner.name}"`);
345
+ }
346
+ }
347
+ const position = positionForRawCrossing(crossing, partner, axis.direction);
348
+ if (position !== void 0) desired.add(position);
349
+ }
350
+ if (desired.size > 1) fail("invalid-chart-axes", `Explicit crossings on axes crossing "${axis.name}" disagree on its physical side`);
351
+ const wanted = [...desired][0];
352
+ if (wanted === void 0) continue;
353
+ if (axis.spec.position !== void 0 && axis.spec.position !== wanted) fail("invalid-chart-axes", `Chart axis "${axis.name}" position "${axis.spec.position}" conflicts with its explicit crossing controls`);
354
+ axis.position = wanted;
355
+ }
356
+ for (const axis of firstUse) {
357
+ let crossing;
358
+ for (const partner of partnersOf(axis)) {
359
+ const candidate = explicitCrossing(partner) ?? rawCrossingForPosition(axis, partner, axis.position);
360
+ if (crossing === void 0) {
361
+ crossing = candidate;
362
+ continue;
363
+ }
364
+ if (!sameCrossing(crossing, candidate)) fail("invalid-chart-axes", `Shared crossing controls for axis "${axis.name}" disagree; use an explicit position or separate axes`);
365
+ }
366
+ if (crossing === void 0) fail("invalid-chart-axes", `Chart axis "${axis.name}" is not crossed by another axis`);
367
+ axis.crossing = crossing;
368
+ }
369
+ for (const [index, axis] of firstUse.entries()) axis.id = nativeAxisIds[index];
370
+ for (const group of resolvedGroups) {
371
+ const first = group.kind === "category" ? group.category : group.x;
372
+ const second = group.kind === "category" ? group.value : group.y;
373
+ first.crossAxisId ??= second.id;
374
+ second.crossAxisId ??= first.id;
375
+ }
376
+ const parsed = firstUse.map((axis) => {
377
+ const titleRotationDegrees = axis.direction === "vertical" ? -90 : void 0;
378
+ return axis.spec.kind === "category" ? {
379
+ kind: "category",
380
+ name: axis.name,
381
+ id: axis.id,
382
+ crossAxisId: axis.crossAxisId,
383
+ direction: axis.direction,
384
+ position: axis.position,
385
+ crossing: axis.crossing,
386
+ ...titleRotationDegrees === void 0 ? {} : { titleRotationDegrees },
387
+ spec: axis.spec
388
+ } : {
389
+ kind: "value",
390
+ name: axis.name,
391
+ id: axis.id,
392
+ crossAxisId: axis.crossAxisId,
393
+ direction: axis.direction,
394
+ position: axis.position,
395
+ crossing: axis.crossing,
396
+ ...titleRotationDegrees === void 0 ? {} : { titleRotationDegrees },
397
+ spec: axis.spec
398
+ };
399
+ });
400
+ const parsedByDraft = new Map(firstUse.map((axis, index) => [axis, parsed[index]]));
401
+ return {
402
+ axes: parsed,
403
+ groupAxes: resolvedGroups.map((group) => group.kind === "category" ? {
404
+ kind: "category",
405
+ category: parsedByDraft.get(group.category),
406
+ value: parsedByDraft.get(group.value)
407
+ } : {
408
+ kind: "scatter",
409
+ x: parsedByDraft.get(group.x),
410
+ y: parsedByDraft.get(group.y)
411
+ })
412
+ };
413
+ }
414
+ function displayBlanksAs(value, groups) {
415
+ const requested = parseChartDisplayBlanksAsBySchema(value);
416
+ if (requested === void 0) return void 0;
417
+ const unsupported = groups.find((group) => {
418
+ if (group.kind === "scatter") return requested === "span" && (group.line === void 0 || group.line === false);
419
+ if (group.kind === "line") return group.stacking === void 0 ? ![
420
+ "gap",
421
+ "zero",
422
+ "span"
423
+ ].includes(requested) : requested !== "zero";
424
+ if (group.kind === "area") return group.stacking === void 0 ? !["gap", "zero"].includes(requested) : requested !== "zero";
425
+ return !["gap", "zero"].includes(requested);
426
+ });
427
+ if (unsupported !== void 0) fail("invalid-chart-missing-values", unsupported.kind === "scatter" ? `scatter chart group without a connecting line does not support displayBlanksAs "${requested}"` : `${unsupported.kind}${unsupported.stacking === void 0 ? "" : ` ${unsupported.stacking}`} chart does not support displayBlanksAs "${requested}"`);
428
+ return requested;
429
+ }
430
+ function emitChartModel(model, emitContext) {
431
+ const embedFonts = emitContext.options.embedFonts;
432
+ if ((embedFonts === "full" || embedFonts === "subset") && model.missingGlyphErrors.length > 0) {
433
+ const issue = model.missingGlyphErrors[0];
434
+ throw new CapabilityError("font-missing-glyph", issue.message, void 0, {
435
+ font: issue.font,
436
+ characters: issue.characters
437
+ });
438
+ }
439
+ const workbook = chartWorkbook(model.parsed);
440
+ const relationshipId = emitContext.registerPackagePart({
441
+ part: {
442
+ pathTemplate: "ppt/charts/chart{n}.xml",
443
+ contentType: chartContentType
444
+ },
445
+ relationshipType: chartRelationship,
446
+ content(relatedRelationshipIds) {
447
+ const [workbookRelationshipId] = relatedRelationshipIds;
448
+ if (workbookRelationshipId === void 0) fail("invalid-part", "Chart part requires embedded workbook relationship");
449
+ return chartPartXml(model.parsed, model.box, workbookRelationshipId, model.textStyles, emitContext.theme);
450
+ },
451
+ relatedParts: [{
452
+ pathTemplate: "ppt/embeddings/Microsoft_Excel_Worksheet{n}.xlsx",
453
+ contentType: workbookContentType,
454
+ relationshipType: packageRelationship,
455
+ bytes: workbook
456
+ }]
457
+ });
458
+ const presentationContributions = fontPresentationContributions(model.fontUses, embedFonts);
459
+ return {
460
+ xml: chartFrameXml(emitContext.id, model.name, model.box, relationshipId, emitContext.nativeLink, model.placeholder),
461
+ ...presentationContributions.length === 0 ? {} : { presentationContributions }
462
+ };
463
+ }
464
+ function paintChartModel(model, paintContext) {
465
+ const paintBox = paintContext.box ?? model.box;
466
+ return drawChartPreview(model.parsed, paintBox, paintContext);
467
+ }
468
+ function defineChartCanvasMechanism(key) {
469
+ return defineCanvasMechanism({
470
+ key,
471
+ role: "canvas",
472
+ emit: emitChartModel,
473
+ paint: paintChartModel,
474
+ import: chartImportHandler
475
+ });
476
+ }
477
+ const chartColumnMechanism = defineChartCanvasMechanism("chart-column");
478
+ const chartBarMechanism = defineChartCanvasMechanism("chart-bar");
479
+ const chartLineMechanism = defineChartCanvasMechanism("chart-line");
480
+ const chartAreaMechanism = defineChartCanvasMechanism("chart-area");
481
+ const chartPieMechanism = defineChartCanvasMechanism("chart-pie");
482
+ const chartDoughnutMechanism = defineChartCanvasMechanism("chart-doughnut");
483
+ const chartScatterMechanism = defineChartCanvasMechanism("chart-scatter");
484
+ /** Typed native canvas mechanism connecting emit, paint, and import for `chart-placeholder`. */
485
+ const chartPlaceholderMechanism = defineCanvasMechanism({
486
+ key: "chart-placeholder",
487
+ role: "canvas",
488
+ emit: emitChartModel,
489
+ paint: paintChartModel,
490
+ import: chartPlaceholderImportHandler
491
+ });
492
+ const chartCompatiblePlaceholderRoles = /* @__PURE__ */ new Set(["chart", "obj"]);
493
+ const chartDataLabelsMechanism = defineChartCanvasMechanism("chart-data-labels");
494
+ const chartTrendlineMechanism = defineChartCanvasMechanism("chart-trendline");
495
+ const chartErrorBarsMechanism = defineChartCanvasMechanism("chart-error-bars");
496
+ const chartMarkersAndPointsMechanism = defineChartCanvasMechanism("chart-markers-and-points");
497
+ const chartMechanismsByKind = {
498
+ column: chartColumnMechanism,
499
+ bar: chartBarMechanism,
500
+ line: chartLineMechanism,
501
+ area: chartAreaMechanism,
502
+ pie: chartPieMechanism,
503
+ doughnut: chartDoughnutMechanism,
504
+ scatter: chartScatterMechanism
505
+ };
506
+ /** Chart module validates input and resolves chart data/configuration for native emit and static paint. */
507
+ const chartCapability = {
508
+ declaration: "chart",
509
+ codegen: chartCodegen,
510
+ mechanisms: [
511
+ chartColumnMechanism,
512
+ chartBarMechanism,
513
+ chartLineMechanism,
514
+ chartAreaMechanism,
515
+ chartPieMechanism,
516
+ chartDoughnutMechanism,
517
+ chartScatterMechanism,
518
+ chartPlaceholderMechanism,
519
+ chartDataLabelsMechanism,
520
+ chartTrendlineMechanism,
521
+ chartErrorBarsMechanism,
522
+ chartMarkersAndPointsMechanism
523
+ ],
524
+ bind(input, context) {
525
+ const placeholder = context.placeholder;
526
+ if (placeholder !== void 0) {
527
+ const role = placeholder.layoutPlaceholder?.type ?? placeholder.nativeRef.type;
528
+ if (!chartCompatiblePlaceholderRoles.has(role)) fail("incompatible-placeholder-content", `Chart cannot be bound to ${role} placeholder`);
529
+ }
530
+ if (input.children.length > 0) fail("unsupported-children", "Chart does not accept children; chart text and data should be passed in groups");
531
+ const unknown = Object.keys(input.props).find((key) => !chartAllowedPropKeys.includes(key));
532
+ if (unknown !== void 0) fail("unknown-parameter", `Chart contains unimplemented parameter ${unknown}`);
533
+ const allowedStyleKeys = new Set(chartStyleKeys);
534
+ const contract = parseCapabilityLayoutContract({
535
+ nativeKind: "graphicFrame",
536
+ props: input.props,
537
+ allowedStyleKeys,
538
+ allowPadding: false,
539
+ path: context.path
540
+ });
541
+ const requestedName = parseOptionalName(input.props["name"]);
542
+ if (requestedName !== void 0) parseChartXmlTextBySchema(requestedName, "Chart.name");
543
+ const morphKey = parseMorphKey(input.props["morphKey"]);
544
+ const link = parseLinkTarget(input.props["link"]);
545
+ const drafts = chartGroupDrafts(input.props["groups"]);
546
+ const { axes, groupAxes } = parsedAxes(input.props["axes"], drafts);
547
+ const categoryDomains = /* @__PURE__ */ new Map();
548
+ for (const [groupIndex, draft] of drafts.entries()) {
549
+ if (draft.kind === "scatter") continue;
550
+ if (draft.data.kind !== "shared-categories") continue;
551
+ const resolved = groupAxes[groupIndex];
552
+ if (resolved === void 0 || resolved.kind !== "category") continue;
553
+ const domain = draft.data.categories;
554
+ const existing = categoryDomains.get(resolved.category.name);
555
+ if (existing === void 0) {
556
+ categoryDomains.set(resolved.category.name, domain);
557
+ continue;
558
+ }
559
+ if (existing.length !== domain.length || existing.some((category, index) => category !== domain[index])) fail("chart-category-domain-mismatch", `Chart groups sharing category axis "${resolved.category.name}" must have the same ordered category domain`);
560
+ }
561
+ let seriesIndex = 0;
562
+ const groups = drafts.map((draft, groupIndex) => {
563
+ const resolvedAxes = groupAxes[groupIndex];
564
+ if (draft.kind === "scatter") {
565
+ if (resolvedAxes === void 0 || resolvedAxes.kind !== "scatter") fail("invalid-chart-axes", `Chart.groups[${groupIndex}] is missing resolved X and Y axes`);
566
+ const series = draft.series.map((item, groupSeriesIndex) => ({
567
+ ...item,
568
+ groupIndex,
569
+ groupSeriesIndex,
570
+ seriesIndex: seriesIndex++
571
+ }));
572
+ return {
573
+ kind: "scatter",
574
+ data: draft.data,
575
+ series,
576
+ axes: {
577
+ x: resolvedAxes.x,
578
+ y: resolvedAxes.y
579
+ },
580
+ line: draft.line ?? false,
581
+ markers: draft.markers,
582
+ ...draft.dataLabels === void 0 ? {} : { dataLabels: draft.dataLabels }
583
+ };
584
+ }
585
+ const series = draft.series.map((item, groupSeriesIndex) => ({
586
+ ...item,
587
+ groupIndex,
588
+ groupSeriesIndex,
589
+ seriesIndex: seriesIndex++
590
+ }));
591
+ if (draft.kind === "pie") {
592
+ const firstSeries = series[0];
593
+ if (firstSeries === void 0 || series.length !== 1) fail("invalid-data", "pie chart currently only supports a single data series");
594
+ return {
595
+ kind: "pie",
596
+ data: draft.data,
597
+ series: [firstSeries],
598
+ firstSliceAngle: draft.firstSliceAngle ?? 0,
599
+ ...draft.explosion === void 0 ? {} : { explosion: draft.explosion },
600
+ ...draft.dataLabels === void 0 ? {} : { dataLabels: draft.dataLabels }
601
+ };
602
+ }
603
+ if (draft.kind === "doughnut") return {
604
+ kind: "doughnut",
605
+ data: draft.data,
606
+ series,
607
+ firstSliceAngle: draft.firstSliceAngle ?? 0,
608
+ holeSize: draft.holeSize ?? 50,
609
+ ...draft.explosion === void 0 ? {} : { explosion: draft.explosion },
610
+ ...draft.dataLabels === void 0 ? {} : { dataLabels: draft.dataLabels }
611
+ };
612
+ if (resolvedAxes === void 0 || resolvedAxes.kind !== "category") fail("invalid-chart-axes", `Chart.groups[${groupIndex}] is missing resolved category and value axes`);
613
+ const cartesianAxes = {
614
+ category: resolvedAxes.category,
615
+ value: resolvedAxes.value
616
+ };
617
+ if (draft.kind === "column" || draft.kind === "bar") return {
618
+ kind: draft.kind,
619
+ data: draft.data,
620
+ series,
621
+ axes: cartesianAxes,
622
+ stacking: draft.stacking ?? "clustered",
623
+ gapWidth: draft.gapWidth ?? 150,
624
+ ...draft.overlap === void 0 ? {} : { overlap: draft.overlap },
625
+ ...draft.dataLabels === void 0 ? {} : { dataLabels: draft.dataLabels }
626
+ };
627
+ return {
628
+ kind: draft.kind,
629
+ data: draft.data,
630
+ series,
631
+ axes: cartesianAxes,
632
+ stacking: draft.stacking ?? "standard",
633
+ ...draft.dataLabels === void 0 ? {} : { dataLabels: draft.dataLabels }
634
+ };
635
+ });
636
+ const series = groups.flatMap((group) => group.series);
637
+ const categorySeries = series.filter((item) => "categories" in item);
638
+ const categories = categorySeries[0]?.categories ?? [];
639
+ const categoryCount = Math.max(0, ...categorySeries.map((item) => item.categories.length));
640
+ const placeholderGeometry = placeholder === void 0 ? void 0 : resolvePlaceholderGeometry(placeholder, input.props);
641
+ const placeholderWidth = typeof placeholderGeometry?.width === "number" ? placeholderGeometry.width : void 0;
642
+ const placeholderHeight = typeof placeholderGeometry?.height === "number" ? placeholderGeometry.height : void 0;
643
+ const declaredWidth = placeholderWidth ?? contract.explicitPixelSize?.width;
644
+ const declaredHeight = placeholderHeight ?? contract.explicitPixelSize?.height;
645
+ const rawX = placeholderGeometry?.x;
646
+ const rawY = placeholderGeometry?.y;
647
+ const declaredX = rawX !== void 0 ? parseChartCoordinateBySchema(rawX, "x") : void 0;
648
+ const declaredY = rawY !== void 0 ? parseChartCoordinateBySchema(rawY, "y") : void 0;
649
+ const legend = parseChartLegendBySchema(input.props["legend"]);
650
+ const checkedPlotArea = parseChartPlotAreaBySchema(input.props["plotArea"]);
651
+ const title = parseChartTitleBySchema(input.props["title"], "Chart.title");
652
+ const blanks = displayBlanksAs(input.props["displayBlanksAs"], drafts);
653
+ const parsed = {
654
+ axes,
655
+ hasExplicitAxes: input.props["axes"] !== void 0,
656
+ groups,
657
+ series,
658
+ categories,
659
+ categoryCount,
660
+ contract,
661
+ ...requestedName === void 0 ? {} : { name: requestedName },
662
+ ...title === void 0 ? {} : { title },
663
+ ...blanks === void 0 ? {} : { displayBlanksAs: blanks },
664
+ ...morphKey === void 0 ? {} : { morphKey },
665
+ ...link === void 0 ? {} : { link },
666
+ ...declaredX === void 0 ? {} : { declaredX },
667
+ ...declaredY === void 0 ? {} : { declaredY },
668
+ ...declaredWidth === void 0 ? {} : { declaredWidth },
669
+ ...declaredHeight === void 0 ? {} : { declaredHeight },
670
+ ...legend === void 0 ? {} : { legend },
671
+ ...checkedPlotArea === void 0 ? {} : { plotArea: checkedPlotArea },
672
+ ...input.props["style"] === void 0 ? {} : { style: input.props["style"] }
673
+ };
674
+ const authorId = typeof input.props["id"] === "string" ? input.props["id"] : void 0;
675
+ const motionProps = pickMotionProps(input.props);
676
+ const native = {
677
+ ...morphKey === void 0 ? {} : { morphKey },
678
+ ...requestedName === void 0 ? {} : { hasExplicitName: true },
679
+ ...link === void 0 ? {} : { link }
680
+ };
681
+ return {
682
+ contract,
683
+ ...morphKey !== void 0 || requestedName !== void 0 || link !== void 0 ? { native } : {},
684
+ measureLayout(request) {
685
+ const width = request.availableWidth ?? declaredWidth ?? (declaredHeight === void 0 ? 320 : declaredHeight * (16 / 9));
686
+ return {
687
+ width,
688
+ height: declaredHeight ?? width * (9 / 16),
689
+ minContentWidth: declaredWidth ?? 0,
690
+ minContentHeight: declaredHeight ?? 0
691
+ };
692
+ },
693
+ resolve(resolveContext) {
694
+ const x = parseChartCoordinateBySchema(resolveContext.layoutBox?.x ?? declaredX ?? 0, "x");
695
+ const y = parseChartCoordinateBySchema(resolveContext.layoutBox?.y ?? declaredY ?? 0, "y");
696
+ const rawBoxWidth = resolveContext.layoutBox?.width ?? declaredWidth ?? (declaredHeight === void 0 ? 320 : declaredHeight * (16 / 9));
697
+ const rawBoxHeight = resolveContext.layoutBox?.height ?? declaredHeight ?? rawBoxWidth * (9 / 16);
698
+ const box = {
699
+ x,
700
+ y,
701
+ width: parseChartExtentBySchema(rawBoxWidth, "width"),
702
+ height: parseChartExtentBySchema(rawBoxHeight, "height")
703
+ };
704
+ if (parsed.plotArea !== void 0) {
705
+ if (parsed.plotArea.left < 0 || parsed.plotArea.top < 0 || parsed.plotArea.width <= 0 || parsed.plotArea.height <= 0 || parsed.plotArea.left + parsed.plotArea.width > box.width || parsed.plotArea.top + parsed.plotArea.height > box.height) fail("invalid-plot-area", "Chart.plotArea must be inside chart box with positive width and height");
706
+ }
707
+ const name = resolveContext.morphName ?? requestedName ?? placeholder?.layoutPlaceholder?.name ?? `Chart ${resolveContext.id - 1}`;
708
+ parseChartXmlTextBySchema(name, "Chart.name");
709
+ const annotations = motionAnnotations(motionProps, {
710
+ kind: "chart",
711
+ name,
712
+ ...authorId === void 0 ? {} : { authorId },
713
+ textBody: false,
714
+ filled: false,
715
+ box,
716
+ rotationDegrees: 0,
717
+ chartSeriesPointCounts: parsed.series.map((item) => "x" in item ? item.x.length : item.values.length)
718
+ });
719
+ const { textStyles, resourceClaims, fontUses, fontUsages, missingGlyphErrors } = chartResourceClaims(parsed, resolveContext.theme);
720
+ validateChartColors(parsed, resolveContext.theme);
721
+ const usesCategoryLabelRange = chartUsesCategoryLabelRange(parsed);
722
+ const primaryMechanism = placeholder !== void 0 ? chartPlaceholderMechanism : chartMechanismsByKind[parsed.groups[0]?.kind ?? "column"];
723
+ const resolvedModel = {
724
+ parsed,
725
+ box,
726
+ name,
727
+ textStyles,
728
+ fontUses,
729
+ missingGlyphErrors,
730
+ ...placeholder === void 0 ? {} : { placeholder: placeholder.nativeRef }
731
+ };
732
+ return {
733
+ observation: {
734
+ id: resolveContext.id,
735
+ kind: "chart",
736
+ name,
737
+ box
738
+ },
739
+ extensions: usesCategoryLabelRange ? ["c15"] : [],
740
+ ...annotations.length === 0 ? {} : { annotations },
741
+ resourceClaims,
742
+ ...fontUsages.length === 0 ? {} : { fontUsages },
743
+ emit(emitContext) {
744
+ return primaryMechanism.emit(resolvedModel, emitContext);
745
+ },
746
+ paint(paintContext) {
747
+ return primaryMechanism.paint(resolvedModel, paintContext);
748
+ }
749
+ };
750
+ }
751
+ };
752
+ }
753
+ };
754
+ const generalNumberCharacters = "0123456789.,-+eE";
755
+ const dateNameCharacters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
756
+ const dateNameCharactersByLocale = { "0804": "星期日一二三四五六七八九十年月" };
757
+ const numberFormatLiteralCharacters = /* @__PURE__ */ new Set("$+():^'{}<=>-/!&~ ");
758
+ function dateNameCharactersForLocale(locale) {
759
+ if (locale === void 0) return dateNameCharacters;
760
+ const languageId = /^(?:0x)?([\da-f]{1,4})(?:,.*)?$/iu.exec(locale)?.[1];
761
+ if (languageId === void 0) return void 0;
762
+ const normalizedLanguageId = languageId.padStart(4, "0").toUpperCase();
763
+ if (normalizedLanguageId === "0409") return dateNameCharacters;
764
+ return dateNameCharactersByLocale[normalizedLanguageId];
765
+ }
766
+ function hasDigitPlaceholderAfter(format, start) {
767
+ for (let index = start; index < format.length; index += 1) {
768
+ const character = format[index];
769
+ if (character === ";") return false;
770
+ if (character === "\"") {
771
+ index += 1;
772
+ while (index < format.length && format[index] !== "\"") index += 1;
773
+ continue;
774
+ }
775
+ if (character === "\\" || character === "_") {
776
+ index += 1;
777
+ continue;
778
+ }
779
+ if (character === "[") {
780
+ while (index < format.length && format[index] !== "]") index += 1;
781
+ continue;
782
+ }
783
+ if (character === "0" || character === "#" || character === "?") return true;
784
+ }
785
+ return false;
786
+ }
787
+ /** Claims glyphs that chart number formatting might display, without simulating application-level number formatting at build time. */
788
+ function numberLabelCharacters(numberFormat, percent = false) {
789
+ const characters = /* @__PURE__ */ new Set();
790
+ const add = (value) => {
791
+ for (const character of value) characters.add(character);
792
+ };
793
+ const format = Array.from(numberFormat ?? "");
794
+ const defaultFormat = numberFormat === void 0 || numberFormat.trim().toLocaleLowerCase("en-US") === "general";
795
+ let hasNumericValue = defaultFormat;
796
+ let hasGeneralValue = defaultFormat;
797
+ let sectionLocale;
798
+ let sectionCount = 1;
799
+ if (defaultFormat) add(generalNumberCharacters);
800
+ for (let index = 0; index < format.length; index += 1) {
801
+ const character = format[index];
802
+ if (character === "\"") {
803
+ for (index += 1; index < format.length; index += 1) {
804
+ if (format[index] === "\"") break;
805
+ characters.add(format[index]);
806
+ }
807
+ continue;
808
+ }
809
+ if (character === "\\" || character === "*") {
810
+ const following = format[index + 1];
811
+ if (following !== void 0) {
812
+ characters.add(following);
813
+ index += 1;
814
+ }
815
+ continue;
816
+ }
817
+ if (character === "_") {
818
+ index += 1;
819
+ continue;
820
+ }
821
+ if (character === "[") {
822
+ const end = format.indexOf("]", index + 1);
823
+ if (end < 0) continue;
824
+ const directive = format.slice(index + 1, end).join("");
825
+ if (directive.startsWith("$")) {
826
+ const currencyAndLocale = directive.slice(1);
827
+ const separator = currencyAndLocale.indexOf("-");
828
+ add(separator < 0 ? currencyAndLocale : currencyAndLocale.slice(0, separator));
829
+ sectionLocale = separator < 0 ? void 0 : currencyAndLocale.slice(separator + 1);
830
+ } else if (/^[hms]+$/iu.test(directive)) hasNumericValue = true;
831
+ index = end;
832
+ continue;
833
+ }
834
+ if (character === ";") {
835
+ sectionCount += 1;
836
+ if (sectionCount > 3) break;
837
+ sectionLocale = void 0;
838
+ continue;
839
+ }
840
+ if (character === "0" || character === "#" || character === "?") {
841
+ if (character === "?") characters.add(" ");
842
+ hasNumericValue = true;
843
+ continue;
844
+ }
845
+ if (character === ",") {
846
+ if (hasDigitPlaceholderAfter(format, index + 1)) characters.add(character);
847
+ continue;
848
+ }
849
+ if (character === "." || character === "%") {
850
+ characters.add(character);
851
+ continue;
852
+ }
853
+ if (character === "A" || character === "a") {
854
+ const amPm = format.slice(index, index + 5).join("");
855
+ const amPmHalf = format.slice(index, index + 3).join("");
856
+ if (/^am\/pm$/iu.test(amPm)) {
857
+ add(amPm.replace("/", ""));
858
+ index += 4;
859
+ continue;
860
+ }
861
+ if (/^a\/p$/iu.test(amPmHalf)) {
862
+ add(amPmHalf.replace("/", ""));
863
+ index += 2;
864
+ continue;
865
+ }
866
+ }
867
+ if (/[yYmdDhHsS]/u.test(character)) {
868
+ let end = index + 1;
869
+ while (end < format.length && format[end].toLocaleLowerCase("en-US") === character.toLocaleLowerCase("en-US")) end += 1;
870
+ const width = end - index;
871
+ hasNumericValue = true;
872
+ if ((character.toLocaleLowerCase("en-US") === "m" || character.toLocaleLowerCase("en-US") === "d") && width >= 3) {
873
+ const dateNames = dateNameCharactersForLocale(sectionLocale);
874
+ if (dateNames !== void 0) add(dateNames);
875
+ }
876
+ index = end - 1;
877
+ continue;
878
+ }
879
+ if (character === "G" || character === "g") {
880
+ if (format.slice(index, index + 7).join("").toLocaleLowerCase("en-US") === "general" && (format[index + 7] === void 0 || !/[a-z]/iu.test(format[index + 7]))) {
881
+ add(generalNumberCharacters);
882
+ hasNumericValue = true;
883
+ hasGeneralValue = true;
884
+ index += 6;
885
+ continue;
886
+ }
887
+ }
888
+ if (character === "E" || character === "e") {
889
+ const sign = format[index + 1];
890
+ if ((sign === "+" || sign === "-") && hasDigitPlaceholderAfter(format, index + 2)) {
891
+ add(character + sign);
892
+ hasNumericValue = true;
893
+ index += 1;
894
+ continue;
895
+ }
896
+ }
897
+ if (numberFormatLiteralCharacters.has(character)) {
898
+ characters.add(character);
899
+ continue;
900
+ }
901
+ if (/[1-9]/u.test(character) || character.codePointAt(0) > 127) characters.add(character);
902
+ }
903
+ if (hasNumericValue) {
904
+ add("0123456789");
905
+ if (sectionCount === 1) characters.add("-");
906
+ }
907
+ if (hasGeneralValue) add("+eE");
908
+ if (percent && numberFormat === void 0) characters.add("%");
909
+ return [...characters].join("");
910
+ }
911
+ function effectiveSeriesLabels(group, series) {
912
+ return mergeDataLabels(group.dataLabels, series.dataLabels);
913
+ }
914
+ function effectivePointLabels(group, series, index) {
915
+ return mergeDataLabels(effectiveSeriesLabels(group, series), series.points?.[index]?.dataLabels);
916
+ }
917
+ function pointDataLabelTexts(group, series, labels, index) {
918
+ if (group.kind === "scatter") {
919
+ const scatter = series;
920
+ const texts = [];
921
+ const numericText = () => numberLabelCharacters(labels.numberFormat, labels.percent === true);
922
+ if (labels.seriesName === true) texts.push(scatter.name);
923
+ if ((labels.value === true || labels.percent === true) && scatter.y[index] !== null && scatter.y[index] !== void 0) texts.push(numericText());
924
+ if (labels.xValue === true && scatter.x[index] !== null && scatter.x[index] !== void 0) texts.push(numericText());
925
+ if (labels.separator !== void 0) texts.push(labels.separator);
926
+ return texts;
927
+ }
928
+ const value = series.values[index];
929
+ if (value === null || value === void 0) return [];
930
+ const texts = [];
931
+ if (labels.seriesName === true) texts.push(series.name);
932
+ if (labels.value === true || labels.percent === true) texts.push(numberLabelCharacters(labels.numberFormat, labels.percent === true));
933
+ if (labels.category === true) texts.push(series.categories[index]);
934
+ if (labels.separator !== void 0) texts.push(labels.separator);
935
+ return texts;
936
+ }
937
+ function groupDataLabelTexts(group) {
938
+ const texts = [];
939
+ for (const series of group.series) {
940
+ const count = group.kind === "scatter" ? series.x.length : series.values.length;
941
+ for (let index = 0; index < count; index += 1) {
942
+ const labels = effectivePointLabels(group, series, index);
943
+ if (labels === void 0 || labels === false) continue;
944
+ texts.push(...pointDataLabelTexts(group, series, labels, index));
945
+ }
946
+ }
947
+ return texts;
948
+ }
949
+ function mergeTextStyle(base, override) {
950
+ return {
951
+ ...base,
952
+ ...override
953
+ };
954
+ }
955
+ function titleParts(value) {
956
+ if (value === void 0) return void 0;
957
+ if (typeof value === "string") return { text: value };
958
+ return {
959
+ text: value.text,
960
+ ...value.style === void 0 ? {} : { style: value.style }
961
+ };
962
+ }
963
+ function validateChartColors(parsed, theme) {
964
+ const checkColor = (color) => {
965
+ if (color !== void 0) theme.resolveColor(color);
966
+ };
967
+ const checkLine = (line) => {
968
+ if (typeof line === "object") checkColor(line.color);
969
+ };
970
+ const checkMarker = (marker) => {
971
+ if (typeof marker === "object") {
972
+ checkColor(marker.fill);
973
+ checkLine(marker.line);
974
+ }
975
+ };
976
+ const checkLabels = (dataLabels) => {
977
+ if (typeof dataLabels === "object") checkLine(dataLabels.leaderLines);
978
+ };
979
+ const checkCommonSeries = (series) => {
980
+ checkColor(series.color);
981
+ checkLine(series.line);
982
+ checkMarker(series.marker);
983
+ for (const point of Object.values(series.points ?? {})) {
984
+ checkColor(point.color);
985
+ checkLine(point.line);
986
+ checkMarker(point.marker);
987
+ checkColor(point.labelColor);
988
+ }
989
+ for (const trendline of series.trendlines ?? []) checkLine(trendline.line);
990
+ };
991
+ for (const { spec } of parsed.axes) {
992
+ checkLine(spec.line);
993
+ checkLine(spec.gridlines);
994
+ checkLine(spec.minorGridlines);
995
+ }
996
+ for (const group of parsed.groups) {
997
+ checkLabels(group.dataLabels);
998
+ if (group.kind === "scatter") for (const series of group.series) {
999
+ checkCommonSeries(series);
1000
+ checkLine(series.errorBars?.x?.line);
1001
+ checkLine(series.errorBars?.y?.line);
1002
+ }
1003
+ else for (const series of group.series) {
1004
+ checkCommonSeries(series);
1005
+ checkLabels(series.dataLabels);
1006
+ checkLine(series.errorBars?.line);
1007
+ }
1008
+ }
1009
+ }
1010
+ function chartResourceClaims(parsed, theme) {
1011
+ const categoryLabels = /* @__PURE__ */ new Map();
1012
+ for (const group of parsed.groups) {
1013
+ if (group.kind === "scatter" || group.kind === "pie" || group.kind === "doughnut") continue;
1014
+ categoryLabels.set(group.axes.category.name, group.data.categories);
1015
+ }
1016
+ const dataLabelText = parsed.groups.flatMap((group) => group.dataLabels !== void 0 && group.dataLabels !== false && group.dataLabels.style !== void 0 ? [] : groupDataLabelTexts(group));
1017
+ const chartText = [
1018
+ ...parsed.series.flatMap((item) => "categories" in item ? item.categories : []),
1019
+ ...parsed.series.map(({ name }) => name),
1020
+ ...dataLabelText
1021
+ ];
1022
+ const percentStacked = parsed.groups.some((group) => (group.kind === "column" || group.kind === "bar" || group.kind === "line" || group.kind === "area") && group.stacking === "percent");
1023
+ const axisCharacters = (spec) => spec.visible === false ? [] : [numberLabelCharacters(spec.kind === "value" ? spec.numberFormat : void 0, percentStacked)];
1024
+ for (const { spec } of parsed.axes) if (spec.kind === "value" && spec.visible !== false && spec.style === void 0) chartText.push(...axisCharacters(spec));
1025
+ const chartStyle = textOnlyChartStyle(parsed.style);
1026
+ const chart = writeChartTextProperties(chartStyle, chartText, "Chart.style", theme);
1027
+ const resourceClaims = [...chart.resourceClaims];
1028
+ const fontUses = chart.fontUses.map((use) => ({
1029
+ ...use,
1030
+ path: "Chart.style"
1031
+ }));
1032
+ const fontUsages = [...chart.fontUsages];
1033
+ const missingGlyphErrors = [...chart.missingGlyphErrors];
1034
+ const textStyles = { chart: chart.xml };
1035
+ const chartTitle = titleParts(parsed.title);
1036
+ if (chartTitle !== void 0) {
1037
+ const output = writeChartTitle(chartTitle.text, mergeTextStyle(chartStyle, chartTitle.style ?? {}), "Chart.title", theme);
1038
+ textStyles.title = output.xml;
1039
+ resourceClaims.push(...output.resourceClaims);
1040
+ fontUses.push(...output.fontUses.map((use) => ({
1041
+ ...use,
1042
+ path: "Chart.title"
1043
+ })));
1044
+ fontUsages.push(...output.fontUsages);
1045
+ missingGlyphErrors.push(...output.missingGlyphErrors);
1046
+ }
1047
+ for (const { name, spec, titleRotationDegrees } of parsed.axes) {
1048
+ if (spec.style !== void 0) {
1049
+ const output = writeChartTextProperties(mergeTextStyle(chartStyle, spec.style), spec.kind === "category" ? categoryLabels.get(name) ?? [] : axisCharacters(spec), `Chart.axes.${name}.style`, theme);
1050
+ textStyles.axisStyles ??= /* @__PURE__ */ new Map();
1051
+ textStyles.axisStyles.set(name, output.xml);
1052
+ resourceClaims.push(...output.resourceClaims);
1053
+ fontUses.push(...output.fontUses.map((use) => ({
1054
+ ...use,
1055
+ path: `Chart.axes.${name}.style`
1056
+ })));
1057
+ fontUsages.push(...output.fontUsages);
1058
+ missingGlyphErrors.push(...output.missingGlyphErrors);
1059
+ }
1060
+ const axisTitle = titleParts(spec.title);
1061
+ if (axisTitle !== void 0) {
1062
+ const output = writeChartTitle(axisTitle.text, mergeTextStyle(mergeTextStyle(chartStyle, spec.style ?? {}), axisTitle.style ?? {}), `Chart.axes.${name}.title`, theme, titleRotationDegrees);
1063
+ textStyles.axisTitles ??= /* @__PURE__ */ new Map();
1064
+ textStyles.axisTitles.set(name, output.xml);
1065
+ resourceClaims.push(...output.resourceClaims);
1066
+ fontUses.push(...output.fontUses.map((use) => ({
1067
+ ...use,
1068
+ path: `Chart.axes.${name}.title`
1069
+ })));
1070
+ fontUsages.push(...output.fontUsages);
1071
+ missingGlyphErrors.push(...output.missingGlyphErrors);
1072
+ }
1073
+ }
1074
+ for (const [groupIndex, group] of parsed.groups.entries()) {
1075
+ const groupLabels = group.dataLabels;
1076
+ if (groupLabels !== void 0 && groupLabels !== false && groupLabels.style !== void 0) {
1077
+ const output = writeChartTextProperties(mergeTextStyle(chartStyle, groupLabels.style), groupDataLabelTexts(group), `Chart.groups[${groupIndex}].dataLabels.style`, theme);
1078
+ textStyles.groupDataLabels ??= /* @__PURE__ */ new Map();
1079
+ textStyles.groupDataLabels.set(groupIndex, output.xml);
1080
+ resourceClaims.push(...output.resourceClaims);
1081
+ fontUses.push(...output.fontUses.map((use) => ({
1082
+ ...use,
1083
+ path: `Chart.groups[${groupIndex}].dataLabels.style`
1084
+ })));
1085
+ fontUsages.push(...output.fontUsages);
1086
+ missingGlyphErrors.push(...output.missingGlyphErrors);
1087
+ }
1088
+ const groupLabelStyle = groupLabels !== void 0 && groupLabels !== false ? groupLabels.style : void 0;
1089
+ for (const series of group.series) for (const [pointIndex, point] of Object.entries(series.points ?? {})) {
1090
+ if (point.labelColor === void 0) continue;
1091
+ const index = Number(pointIndex);
1092
+ const pointLabels = effectivePointLabels(group, series, index);
1093
+ if (pointLabels === void 0 || pointLabels === false) continue;
1094
+ const pointText = pointDataLabelTexts(group, series, pointLabels, index);
1095
+ if (pointText.length === 0) continue;
1096
+ const output = writeChartTextProperties(mergeTextStyle(chartStyle, {
1097
+ ...groupLabelStyle,
1098
+ color: point.labelColor
1099
+ }), pointText, "Chart.dataLabels.point.style", theme);
1100
+ textStyles.pointLabels ??= /* @__PURE__ */ new Map();
1101
+ textStyles.pointLabels.set(`${series.seriesIndex}:${pointIndex}`, output.xml);
1102
+ resourceClaims.push(...output.resourceClaims);
1103
+ fontUses.push(...output.fontUses.map((use) => ({
1104
+ ...use,
1105
+ path: "Chart.dataLabels.point.style"
1106
+ })));
1107
+ fontUsages.push(...output.fontUsages);
1108
+ missingGlyphErrors.push(...output.missingGlyphErrors);
1109
+ }
1110
+ }
1111
+ return {
1112
+ textStyles,
1113
+ resourceClaims,
1114
+ fontUses,
1115
+ fontUsages,
1116
+ missingGlyphErrors
1117
+ };
1118
+ }
1119
+ export { chartAreaMechanism, chartBarMechanism, chartCapability, chartColumnMechanism, chartDataLabelsMechanism, chartDoughnutMechanism, chartErrorBarsMechanism, chartLineMechanism, chartMarkersAndPointsMechanism, chartPieMechanism, chartPlaceholderMechanism, chartScatterMechanism, chartTrendlineMechanism };