@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,100 @@
1
+ import { resolveChartLineStroke, resolveSeriesColor, strokeAttrs } from "./style.js";
2
+ import { assertNever } from "./types.js";
3
+ // ../capabilities/dist/chart/preview/markers.js
4
+ const DEFAULT_MARKER_SIZE_PT = 5;
5
+ const AUTO_MARKER_SYMBOLS = [
6
+ "diamond",
7
+ "square",
8
+ "triangle",
9
+ "x",
10
+ "star",
11
+ "circle",
12
+ "plus",
13
+ "dot",
14
+ "dash"
15
+ ];
16
+ function asMarkerObject(value) {
17
+ return typeof value === "object" && value !== null ? value : void 0;
18
+ }
19
+ /**
20
+ * Resolves effective marker geometry and styling by merging point-level overrides over series
21
+ * and group defaults, converting size from points to pixel radius.
22
+ */
23
+ function resolveEffectiveMarker(options) {
24
+ const { groupDefaultEnabled, seriesMarker, pointMarker, seriesColor, pointColor, seriesIndex, theme } = options;
25
+ let enabled;
26
+ if (pointMarker === false) enabled = false;
27
+ else if (pointMarker !== void 0) enabled = true;
28
+ else if (seriesMarker === false) enabled = false;
29
+ else if (seriesMarker !== void 0) enabled = true;
30
+ else enabled = groupDefaultEnabled;
31
+ if (!enabled) return void 0;
32
+ const seriesObj = asMarkerObject(seriesMarker);
33
+ const pointObj = asMarkerObject(pointMarker);
34
+ const rawSymbol = pointMarker === true ? seriesObj?.symbol ?? "circle" : pointObj?.symbol ?? seriesObj?.symbol ?? "circle";
35
+ if (rawSymbol === "none") return void 0;
36
+ const symbol = rawSymbol === "auto" ? AUTO_MARKER_SYMBOLS[seriesIndex % AUTO_MARKER_SYMBOLS.length] : rawSymbol;
37
+ const radius = (pointObj?.size ?? seriesObj?.size ?? DEFAULT_MARKER_SIZE_PT) * (4 / 3) / 2;
38
+ const fillColor = resolveSeriesColor(pointObj?.fill ?? seriesObj?.fill ?? pointColor ?? seriesColor, seriesIndex, theme);
39
+ const fillHex = fillColor.hex;
40
+ const fillAlpha = fillColor.alpha ?? 1;
41
+ const lineSpec = pointObj?.line ?? seriesObj?.line;
42
+ const explicitStroke = lineSpec === void 0 ? void 0 : resolveChartLineStroke(lineSpec, theme, {
43
+ color: "dk1",
44
+ width: 1
45
+ });
46
+ const stroke = symbol === "plus" || symbol === "x" || symbol === "star" ? explicitStroke ?? {
47
+ hex: fillHex,
48
+ alpha: fillAlpha,
49
+ width: Math.max(1.25, radius * .35)
50
+ } : explicitStroke;
51
+ return {
52
+ symbol,
53
+ radius,
54
+ fillHex,
55
+ fillAlpha,
56
+ ...stroke === void 0 ? {} : { stroke }
57
+ };
58
+ }
59
+ /**
60
+ * Renders one SVG marker glyph centered at `(cx, cy)` covering all 11 OOXML marker symbols.
61
+ */
62
+ function renderMarkerSvg(cx, cy, marker) {
63
+ const r = marker.radius;
64
+ const fillAttr = `fill="#${marker.fillHex}" fill-opacity="${marker.fillAlpha}"`;
65
+ const strokeAttr = marker.stroke === void 0 ? "" : ` ${strokeAttrs(marker.stroke)}`;
66
+ switch (marker.symbol) {
67
+ case "circle": return `<circle cx="${cx}" cy="${cy}" r="${r}" ${fillAttr}${strokeAttr}/>`;
68
+ case "square": return `<rect x="${cx - r}" y="${cy - r}" width="${2 * r}" height="${2 * r}" ${fillAttr}${strokeAttr}/>`;
69
+ case "diamond": return `<path d="M${cx} ${cy - r}L${cx + r} ${cy}L${cx} ${cy + r}L${cx - r} ${cy}Z" ${fillAttr}${strokeAttr}/>`;
70
+ case "triangle": return `<path d="M${cx} ${cy - r}L${cx + r} ${cy + r}L${cx - r} ${cy + r}Z" ${fillAttr}${strokeAttr}/>`;
71
+ case "plus": {
72
+ const stroke = marker.stroke ?? {
73
+ hex: marker.fillHex,
74
+ alpha: marker.fillAlpha,
75
+ width: Math.max(1.25, r * .35)
76
+ };
77
+ return `<path d="M${cx - r} ${cy}H${cx + r}M${cx} ${cy - r}V${cy + r}" fill="none" ${strokeAttrs(stroke)} stroke-linecap="round"/>`;
78
+ }
79
+ case "x": {
80
+ const stroke = marker.stroke ?? {
81
+ hex: marker.fillHex,
82
+ alpha: marker.fillAlpha,
83
+ width: Math.max(1.25, r * .35)
84
+ };
85
+ return `<path d="M${cx - r} ${cy - r}L${cx + r} ${cy + r}M${cx - r} ${cy + r}L${cx + r} ${cy - r}" fill="none" ${strokeAttrs(stroke)} stroke-linecap="round"/>`;
86
+ }
87
+ case "star": {
88
+ const stroke = marker.stroke ?? {
89
+ hex: marker.fillHex,
90
+ alpha: marker.fillAlpha,
91
+ width: Math.max(1.25, r * .35)
92
+ };
93
+ return `<path d="M${cx - r} ${cy - r}L${cx + r} ${cy + r}M${cx - r} ${cy + r}L${cx + r} ${cy - r}M${cx} ${cy - r}V${cy + r}" fill="none" ${strokeAttrs(stroke)} stroke-linecap="round"/>`;
94
+ }
95
+ case "dot": return `<rect x="${cx}" y="${cy - r * .25}" width="${r}" height="${r * .5}" ${fillAttr}${strokeAttr}/>`;
96
+ case "dash": return `<rect x="${cx - r}" y="${cy - r * .25}" width="${2 * r}" height="${r * .5}" ${fillAttr}${strokeAttr}/>`;
97
+ default: return assertNever(marker.symbol);
98
+ }
99
+ }
100
+ export { renderMarkerSvg, resolveEffectiveMarker };
@@ -0,0 +1,247 @@
1
+ // ../capabilities/dist/chart/preview/number-format.js
2
+ function splitSections(formatCode) {
3
+ const sections = [];
4
+ let current = "";
5
+ let inQuotes = false;
6
+ let inBracket = false;
7
+ for (let i = 0; i < formatCode.length; i += 1) {
8
+ const ch = formatCode[i];
9
+ if (inQuotes) {
10
+ current += ch;
11
+ if (ch === "\"") inQuotes = false;
12
+ continue;
13
+ }
14
+ if (ch === "\\" || ch === "_") {
15
+ current += ch + (formatCode[i + 1] ?? "");
16
+ i += 1;
17
+ continue;
18
+ }
19
+ if (ch === "[") {
20
+ inBracket = true;
21
+ current += ch;
22
+ continue;
23
+ }
24
+ if (inBracket) {
25
+ current += ch;
26
+ if (ch === "]") inBracket = false;
27
+ continue;
28
+ }
29
+ if (ch === "\"") {
30
+ inQuotes = true;
31
+ current += ch;
32
+ continue;
33
+ }
34
+ if (ch === ";") {
35
+ sections.push(current);
36
+ current = "";
37
+ if (sections.length === 3) {
38
+ sections.push(formatCode.slice(i + 1));
39
+ return sections;
40
+ }
41
+ continue;
42
+ }
43
+ current += ch;
44
+ }
45
+ sections.push(current);
46
+ return sections;
47
+ }
48
+ function tokenizeSection(section) {
49
+ const tokens = [];
50
+ for (let i = 0; i < section.length; i += 1) {
51
+ const ch = section[i];
52
+ if (ch === "\"") {
53
+ let literal = "";
54
+ for (i += 1; i < section.length; i += 1) {
55
+ if (section[i] === "\"") break;
56
+ literal += section[i];
57
+ }
58
+ if (literal !== "") tokens.push({
59
+ kind: "literal",
60
+ text: literal
61
+ });
62
+ continue;
63
+ }
64
+ if (ch === "\\" || ch === "*") {
65
+ const next = section[i + 1];
66
+ if (next !== void 0) {
67
+ tokens.push({
68
+ kind: "literal",
69
+ text: next
70
+ });
71
+ i += 1;
72
+ }
73
+ continue;
74
+ }
75
+ if (ch === "_") {
76
+ i += 1;
77
+ continue;
78
+ }
79
+ if (ch === "[") {
80
+ const end = section.indexOf("]", i + 1);
81
+ if (end >= 0) {
82
+ const directive = section.slice(i + 1, end);
83
+ if (directive.startsWith("$")) {
84
+ const rest = directive.slice(1);
85
+ const dash = rest.indexOf("-");
86
+ const currency = dash < 0 ? rest : rest.slice(0, dash);
87
+ if (currency !== "") tokens.push({
88
+ kind: "literal",
89
+ text: currency
90
+ });
91
+ }
92
+ i = end;
93
+ continue;
94
+ }
95
+ }
96
+ if (ch === "0" || ch === "#" || ch === "?") {
97
+ tokens.push({
98
+ kind: "digit",
99
+ ch
100
+ });
101
+ continue;
102
+ }
103
+ if (ch === ".") {
104
+ tokens.push({ kind: "dot" });
105
+ continue;
106
+ }
107
+ if (ch === ",") {
108
+ tokens.push({ kind: "comma" });
109
+ continue;
110
+ }
111
+ if (ch === "%") {
112
+ tokens.push({ kind: "percent" });
113
+ continue;
114
+ }
115
+ if (ch === "E" || ch === "e") {
116
+ const next = section[i + 1];
117
+ if (next === "+" || next === "-") {
118
+ tokens.push({
119
+ kind: "exp",
120
+ sign: next
121
+ });
122
+ i += 1;
123
+ continue;
124
+ }
125
+ }
126
+ if ((ch === "G" || ch === "g") && section.slice(i, i + 7).toLowerCase() === "general" && (section[i + 7] === void 0 || !/[a-z]/iu.test(section[i + 7]))) {
127
+ tokens.push({ kind: "general" });
128
+ i += 6;
129
+ continue;
130
+ }
131
+ tokens.push({
132
+ kind: "literal",
133
+ text: ch
134
+ });
135
+ }
136
+ return tokens;
137
+ }
138
+ function formatGeneral(value) {
139
+ if (Object.is(value, -0) || value === 0) return "0";
140
+ const clean = Number(value.toPrecision(12));
141
+ return String(clean);
142
+ }
143
+ function addGrouping(intStr) {
144
+ if (intStr.length <= 3) return intStr;
145
+ return intStr.replace(/\B(?=(\d{3})+(?!\d))/g, ",");
146
+ }
147
+ function formatFixedParts(absValue, minInt, minFrac, maxFrac, useGrouping) {
148
+ const clampedFrac = Math.min(Math.max(0, maxFrac), 20);
149
+ const fixed = absValue.toFixed(clampedFrac);
150
+ const dotIdx = fixed.indexOf(".");
151
+ let intPart = dotIdx < 0 ? fixed : fixed.slice(0, dotIdx);
152
+ let fracPart = dotIdx < 0 ? "" : fixed.slice(dotIdx + 1);
153
+ if (intPart === "0" && minInt === 0) intPart = "";
154
+ else if (intPart.length < minInt) intPart = intPart.padStart(minInt, "0");
155
+ if (useGrouping && intPart.length > 3) intPart = addGrouping(intPart);
156
+ while (fracPart.length > minFrac && fracPart.endsWith("0")) fracPart = fracPart.slice(0, -1);
157
+ if (intPart === "" && fracPart === "" && minFrac === 0) return "";
158
+ return fracPart.length > 0 ? `${intPart}.${fracPart}` : intPart;
159
+ }
160
+ function formatSection(absValue, section) {
161
+ if (section === "") return "";
162
+ const tokens = tokenizeSection(section);
163
+ if (tokens.some((token) => token.kind === "general")) return tokens.map((token) => {
164
+ if (token.kind === "general") return formatGeneral(absValue);
165
+ if (token.kind === "literal") return token.text;
166
+ if (token.kind === "percent") return "%";
167
+ return "";
168
+ }).join("");
169
+ let firstNumIdx = -1;
170
+ let lastNumIdx = -1;
171
+ let lastDigitIdx = -1;
172
+ let expIdx = -1;
173
+ let expSignToken = "+";
174
+ for (let i = 0; i < tokens.length; i += 1) {
175
+ const token = tokens[i];
176
+ if (token.kind === "digit" || token.kind === "dot") {
177
+ if (firstNumIdx < 0) firstNumIdx = i;
178
+ lastNumIdx = i;
179
+ }
180
+ if (token.kind === "digit") lastDigitIdx = i;
181
+ if (token.kind === "exp" && expIdx < 0) {
182
+ expIdx = i;
183
+ expSignToken = token.sign;
184
+ }
185
+ }
186
+ let scaled = absValue;
187
+ let percentCount = 0;
188
+ for (const token of tokens) if (token.kind === "percent") percentCount += 1;
189
+ if (percentCount > 0) scaled *= 100 ** percentCount;
190
+ let trailingCommas = 0;
191
+ if (lastDigitIdx >= 0) for (let i = lastDigitIdx + 1; i < tokens.length; i += 1) {
192
+ const token = tokens[i];
193
+ if (token.kind === "comma") {
194
+ trailingCommas += 1;
195
+ lastNumIdx = Math.max(lastNumIdx, i);
196
+ } else if (token.kind === "literal" || token.kind === "percent") break;
197
+ }
198
+ if (trailingCommas > 0 && expIdx < 0) scaled /= 1e3 ** trailingCommas;
199
+ if (firstNumIdx < 0) return tokens.map((token) => token.kind === "literal" ? token.text : token.kind === "percent" ? "%" : "").join("");
200
+ const prefix = tokens.slice(0, firstNumIdx).map((token) => token.kind === "literal" ? token.text : token.kind === "percent" ? "%" : "").join("");
201
+ const suffix = tokens.slice(lastNumIdx + 1).map((token) => token.kind === "literal" ? token.text : token.kind === "percent" ? "%" : "").join("");
202
+ if (expIdx >= 0 && expIdx > firstNumIdx) {
203
+ const mantissaTokens = tokens.slice(firstNumIdx, expIdx);
204
+ const expTokens = tokens.slice(expIdx + 1, lastNumIdx + 1);
205
+ const dotPos = mantissaTokens.findIndex((token) => token.kind === "dot");
206
+ const intDigits = (dotPos < 0 ? mantissaTokens : mantissaTokens.slice(0, dotPos)).filter((token) => token.kind === "digit");
207
+ const fracDigits = (dotPos < 0 ? [] : mantissaTokens.slice(dotPos + 1)).filter((token) => token.kind === "digit");
208
+ const expMinDigits = expTokens.filter((token) => token.kind === "digit" && token.ch === "0").length;
209
+ const minInt = intDigits.filter((token) => token.ch === "0").length;
210
+ const minFrac = fracDigits.filter((token) => token.ch === "0").length;
211
+ const maxFrac = fracDigits.length;
212
+ let expVal = 0;
213
+ let mantissa = 0;
214
+ if (scaled > 0) {
215
+ const leadDigits = Math.max(1, intDigits.length);
216
+ expVal = Math.floor(Math.log10(scaled)) - (leadDigits - 1);
217
+ mantissa = scaled / 10 ** expVal;
218
+ }
219
+ return `${prefix}${formatFixedParts(mantissa, Math.max(1, minInt), minFrac, maxFrac, false)}E${expVal < 0 ? "-" : expSignToken === "+" ? "+" : ""}${String(Math.abs(expVal)).padStart(Math.max(1, expMinDigits), "0")}${suffix}`;
220
+ }
221
+ const numTokens = tokens.slice(firstNumIdx, lastNumIdx + 1);
222
+ const dotPos = numTokens.findIndex((token) => token.kind === "dot");
223
+ const intTokens = dotPos < 0 ? numTokens : numTokens.slice(0, dotPos);
224
+ const fracTokens = dotPos < 0 ? [] : numTokens.slice(dotPos + 1);
225
+ const minInt = intTokens.filter((token) => token.kind === "digit" && token.ch === "0").length;
226
+ const useGrouping = intTokens.some((token) => token.kind === "comma");
227
+ const fracDigits = fracTokens.filter((token) => token.kind === "digit");
228
+ const minFrac = fracDigits.filter((token) => token.kind === "digit" && token.ch === "0").length;
229
+ const maxFrac = fracDigits.length;
230
+ return `${prefix}${formatFixedParts(scaled, minInt, minFrac, maxFrac, useGrouping)}${numTokens.filter((token) => token.kind === "percent").map(() => "%").join("")}${suffix}`;
231
+ }
232
+ /**
233
+ * Formats a numeric chart value using an Excel/OOXML number format string.
234
+ */
235
+ function formatChartNumber(value, formatCode) {
236
+ if (!Number.isFinite(value)) return String(value);
237
+ if (formatCode === void 0 || formatCode.trim().toLowerCase() === "general") return formatGeneral(value);
238
+ const sections = splitSections(formatCode);
239
+ const normalized = Object.is(value, -0) ? 0 : value;
240
+ if (normalized === 0 && sections.length >= 3) return formatSection(0, sections[2]);
241
+ if (normalized < 0) {
242
+ if (sections.length >= 2) return formatSection(Math.abs(normalized), sections[1]);
243
+ return `-${formatSection(Math.abs(normalized), sections[0])}`;
244
+ }
245
+ return formatSection(normalized, sections[0]);
246
+ }
247
+ export { formatChartNumber };
@@ -0,0 +1,159 @@
1
+ import { mergeDataLabels } from "../chart-labels.js";
2
+ import { resolveChartLineStroke, resolveSeriesColor, strokeAttrs } from "./style.js";
3
+ // ../capabilities/dist/chart/preview/pie-doughnut.js
4
+ function toScreenRadians(degreesClockwiseFromTop) {
5
+ return (degreesClockwiseFromTop - 90) * Math.PI / 180;
6
+ }
7
+ function hasOuterSliceLabels(group) {
8
+ if (group.kind === "doughnut") return false;
9
+ const series = group.series[0];
10
+ for (let i = 0; i < series.values.length; i += 1) {
11
+ const val = series.values[i];
12
+ if (val === null || val === void 0 || !Number.isFinite(val) || val <= 0) continue;
13
+ const eff = mergeDataLabels(mergeDataLabels(group.dataLabels, series.dataLabels), series.points?.[i]?.dataLabels);
14
+ if (eff === void 0 || eff === false) continue;
15
+ if (!(eff.value === true || eff.percent === true || eff.category === true || eff.seriesName === true)) continue;
16
+ const pos = eff.position ?? "bestFit";
17
+ if (pos === "outsideEnd" || pos === "bestFit") return true;
18
+ }
19
+ return false;
20
+ }
21
+ function buildSlicePath(options) {
22
+ const { ox, oy, innerR, outerR, startRad, endRad, spanDeg } = options;
23
+ if (spanDeg >= 359.999) {
24
+ const oppRad = startRad + Math.PI;
25
+ const ox1 = ox + outerR * Math.cos(startRad);
26
+ const oy1 = oy + outerR * Math.sin(startRad);
27
+ const ox2 = ox + outerR * Math.cos(oppRad);
28
+ const oy2 = oy + outerR * Math.sin(oppRad);
29
+ if (innerR <= .001) return {
30
+ d: `M${ox1} ${oy1}A${outerR} ${outerR} 0 1 1 ${ox2} ${oy2}A${outerR} ${outerR} 0 1 1 ${ox1} ${oy1}Z`,
31
+ fullCircle: true
32
+ };
33
+ const ix1 = ox + innerR * Math.cos(startRad);
34
+ const iy1 = oy + innerR * Math.sin(startRad);
35
+ return {
36
+ d: `M${ox1} ${oy1}A${outerR} ${outerR} 0 1 1 ${ox2} ${oy2}A${outerR} ${outerR} 0 1 1 ${ox1} ${oy1}M${ix1} ${iy1}A${innerR} ${innerR} 0 1 0 ${ox + innerR * Math.cos(oppRad)} ${oy + innerR * Math.sin(oppRad)}A${innerR} ${innerR} 0 1 0 ${ix1} ${iy1}Z`,
37
+ fullCircle: true
38
+ };
39
+ }
40
+ const largeArc = spanDeg > 180 ? 1 : 0;
41
+ const x1 = ox + outerR * Math.cos(startRad);
42
+ const y1 = oy + outerR * Math.sin(startRad);
43
+ const x2 = ox + outerR * Math.cos(endRad);
44
+ const y2 = oy + outerR * Math.sin(endRad);
45
+ if (innerR <= .001) return {
46
+ d: `M${ox} ${oy}L${x1} ${y1}A${outerR} ${outerR} 0 ${largeArc} 1 ${x2} ${y2}Z`,
47
+ fullCircle: false
48
+ };
49
+ return {
50
+ d: `M${x1} ${y1}A${outerR} ${outerR} 0 ${largeArc} 1 ${x2} ${y2}L${ox + innerR * Math.cos(endRad)} ${oy + innerR * Math.sin(endRad)}A${innerR} ${innerR} 0 ${largeArc} 0 ${ox + innerR * Math.cos(startRad)} ${oy + innerR * Math.sin(startRad)}Z`,
51
+ fullCircle: false
52
+ };
53
+ }
54
+ /**
55
+ * Renders pie and single/multi-ring doughnut chart groups with explosion, holeSize,
56
+ * custom starting angle, and slice anchors for data labels and leader lines.
57
+ */
58
+ function renderPieOrDoughnutGroup(options) {
59
+ const { group, groupIndex, plotRect, theme } = options;
60
+ if (group.series.length === 0 || plotRect.width <= 0 || plotRect.height <= 0) return {
61
+ svg: "",
62
+ anchors: []
63
+ };
64
+ let maxExpRatio = 0;
65
+ for (const series of group.series) for (let j = 0; j < series.values.length; j += 1) {
66
+ const val = series.values[j];
67
+ if (val === null || val === void 0 || !Number.isFinite(val) || val <= 0) continue;
68
+ const exp = series.points?.[j]?.explosion ?? series.explosion ?? group.explosion ?? 0;
69
+ const ratio = Math.min(Math.max(0, exp), 100) / 100;
70
+ if (ratio > maxExpRatio) maxExpRatio = ratio;
71
+ }
72
+ const radiusScale = hasOuterSliceLabels(group) ? .68 : .88;
73
+ const rAvail = Math.min(plotRect.width, plotRect.height) / 2 * radiusScale;
74
+ const rOuterTotal = Math.max(2, rAvail / (1 + maxExpRatio));
75
+ const cx = plotRect.x + plotRect.width / 2;
76
+ const cy = plotRect.y + plotRect.height / 2;
77
+ const ringCount = group.kind === "pie" ? 1 : group.series.length;
78
+ const rHole = rOuterTotal * (group.kind === "doughnut" ? Math.max(.1, Math.min(.9, group.holeSize / 100)) : 0);
79
+ const ringThickness = (rOuterTotal - rHole) / Math.max(1, ringCount);
80
+ const parts = [];
81
+ const anchors = [];
82
+ for (let s = 0; s < group.series.length; s += 1) {
83
+ const series = group.series[s];
84
+ const rIn = group.kind === "pie" ? 0 : rHole + s * ringThickness;
85
+ const rOut = group.kind === "pie" ? rOuterTotal : rHole + (s + 1) * ringThickness;
86
+ let ringTotal = 0;
87
+ let positiveCount = 0;
88
+ for (const v of series.values) if (v !== null && v !== void 0 && Number.isFinite(v) && v > 0) {
89
+ ringTotal += v;
90
+ positiveCount += 1;
91
+ }
92
+ if (ringTotal <= 0) continue;
93
+ let currentDeg = group.firstSliceAngle;
94
+ for (let j = 0; j < series.values.length; j += 1) {
95
+ const val = series.values[j];
96
+ if (val === null || val === void 0 || !Number.isFinite(val) || val <= 0) continue;
97
+ const spanDeg = val / ringTotal * 360;
98
+ const startDeg = currentDeg;
99
+ const endDeg = startDeg + spanDeg;
100
+ const midDeg = startDeg + spanDeg / 2;
101
+ currentDeg = endDeg;
102
+ const startRad = toScreenRadians(startDeg);
103
+ const endRad = toScreenRadians(endDeg);
104
+ const midRad = toScreenRadians(midDeg);
105
+ const point = series.points?.[j];
106
+ const exp = point?.explosion ?? series.explosion ?? group.explosion ?? 0;
107
+ const expOffset = rOuterTotal * (Math.min(Math.max(0, exp), 100) / 100);
108
+ const ox = cx + expOffset * Math.cos(midRad);
109
+ const oy = cy + expOffset * Math.sin(midRad);
110
+ const { d, fullCircle } = buildSlicePath({
111
+ ox,
112
+ oy,
113
+ innerR: rIn,
114
+ outerR: rOut,
115
+ startRad,
116
+ endRad,
117
+ spanDeg
118
+ });
119
+ const fill = resolveSeriesColor(point?.color ?? series.color, j, theme);
120
+ const lineSpec = point?.line ?? series.line;
121
+ const stroke = lineSpec !== void 0 ? resolveChartLineStroke(lineSpec, theme, {
122
+ color: "dk1",
123
+ width: 1
124
+ }) : positiveCount > 1 || ringCount > 1 ? {
125
+ hex: "FFFFFF",
126
+ alpha: .9,
127
+ width: 1
128
+ } : void 0;
129
+ const strokeAttr = stroke === void 0 ? "" : ` ${strokeAttrs(stroke)}`;
130
+ const fillRuleAttr = fullCircle && rIn > .001 ? " fill-rule=\"evenodd\"" : "";
131
+ parts.push(`<path d="${d}" fill="#${fill.hex}" fill-opacity="${fill.alpha ?? 1}"${fillRuleAttr}${strokeAttr}/>`);
132
+ anchors.push({
133
+ kind: "slice",
134
+ groupIndex,
135
+ seriesIndex: series.seriesIndex,
136
+ groupSeriesIndex: s,
137
+ pointIndex: j,
138
+ value: val,
139
+ category: series.categories[j] ?? "",
140
+ seriesName: series.name,
141
+ cx: ox,
142
+ cy: oy,
143
+ innerR: rIn,
144
+ outerR: rOut,
145
+ startAngleRad: startRad,
146
+ endAngleRad: endRad,
147
+ midAngleRad: midRad,
148
+ sliceSum: ringTotal,
149
+ percent: val / ringTotal,
150
+ spanDeg
151
+ });
152
+ }
153
+ }
154
+ return {
155
+ svg: parts.join(""),
156
+ anchors
157
+ };
158
+ }
159
+ export { renderPieOrDoughnutGroup };