@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.
- package/LICENSE +21 -0
- package/dist/build-zrZuX4fK.d.ts +3 -0
- package/dist/build.d.ts +35 -0
- package/dist/build.js +128 -0
- package/dist/capabilities/dist/all.js +34 -0
- package/dist/capabilities/dist/box/box-codegen.js +84 -0
- package/dist/capabilities/dist/box/box-declaration.js +32 -0
- package/dist/capabilities/dist/box/box-elements.js +17 -0
- package/dist/capabilities/dist/box/box.js +142 -0
- package/dist/capabilities/dist/chart/chart-codegen.js +79 -0
- package/dist/capabilities/dist/chart/chart-declaration.js +7 -0
- package/dist/capabilities/dist/chart/chart-elements.js +12 -0
- package/dist/capabilities/dist/chart/chart-import.js +2403 -0
- package/dist/capabilities/dist/chart/chart-labels.js +86 -0
- package/dist/capabilities/dist/chart/chart-model.js +9 -0
- package/dist/capabilities/dist/chart/chart-schemas.js +1088 -0
- package/dist/capabilities/dist/chart/chart-xml.js +788 -0
- package/dist/capabilities/dist/chart/chart.js +1119 -0
- package/dist/capabilities/dist/chart/preview/axes-and-grid.js +311 -0
- package/dist/capabilities/dist/chart/preview/bar-column.js +143 -0
- package/dist/capabilities/dist/chart/preview/data-labels.js +334 -0
- package/dist/capabilities/dist/chart/preview/error-bars.js +213 -0
- package/dist/capabilities/dist/chart/preview/index.js +192 -0
- package/dist/capabilities/dist/chart/preview/layout.js +592 -0
- package/dist/capabilities/dist/chart/preview/legend.js +273 -0
- package/dist/capabilities/dist/chart/preview/line-area.js +404 -0
- package/dist/capabilities/dist/chart/preview/markers.js +100 -0
- package/dist/capabilities/dist/chart/preview/number-format.js +247 -0
- package/dist/capabilities/dist/chart/preview/pie-doughnut.js +159 -0
- package/dist/capabilities/dist/chart/preview/scales.js +365 -0
- package/dist/capabilities/dist/chart/preview/scatter.js +131 -0
- package/dist/capabilities/dist/chart/preview/style.js +60 -0
- package/dist/capabilities/dist/chart/preview/text-render.js +116 -0
- package/dist/capabilities/dist/chart/preview/trendlines.js +537 -0
- package/dist/capabilities/dist/chart/preview/types.js +5 -0
- package/dist/capabilities/dist/document.js +168 -0
- package/dist/capabilities/dist/font/font-embedding.js +119 -0
- package/dist/capabilities/dist/font/font-engine.js +834 -0
- package/dist/capabilities/dist/font/font-import.js +766 -0
- package/dist/capabilities/dist/font/font-subset.js +55 -0
- package/dist/capabilities/dist/font/font.js +72 -0
- package/dist/capabilities/dist/group/group-codegen.js +74 -0
- package/dist/capabilities/dist/group/group-declaration.js +41 -0
- package/dist/capabilities/dist/group/group-elements.js +12 -0
- package/dist/capabilities/dist/group/group-import.js +649 -0
- package/dist/capabilities/dist/group/group-xml.js +8 -0
- package/dist/capabilities/dist/group/group.js +260 -0
- package/dist/capabilities/dist/image/gif-decoder.js +244 -0
- package/dist/capabilities/dist/image/image-codegen.js +164 -0
- package/dist/capabilities/dist/image/image-declaration.js +8 -0
- package/dist/capabilities/dist/image/image-decode.js +244 -0
- package/dist/capabilities/dist/image/image-elements.js +12 -0
- package/dist/capabilities/dist/image/image-import.js +984 -0
- package/dist/capabilities/dist/image/image-schemas.js +147 -0
- package/dist/capabilities/dist/image/image-xml.js +12 -0
- package/dist/capabilities/dist/image/image.js +552 -0
- package/dist/capabilities/dist/line/line-codegen.js +89 -0
- package/dist/capabilities/dist/line/line-declaration.js +72 -0
- package/dist/capabilities/dist/line/line-elements.js +12 -0
- package/dist/capabilities/dist/line/line-import.js +504 -0
- package/dist/capabilities/dist/line/line-xml.js +9 -0
- package/dist/capabilities/dist/line/line.js +331 -0
- package/dist/capabilities/dist/masters/footer-placeholder.js +683 -0
- package/dist/capabilities/dist/masters/masters-codegen.js +69 -0
- package/dist/capabilities/dist/masters/masters.js +250 -0
- package/dist/capabilities/dist/motion/motion-api.js +757 -0
- package/dist/capabilities/dist/motion/motion-codegen.js +406 -0
- package/dist/capabilities/dist/motion/motion-elements.js +43 -0
- package/dist/capabilities/dist/motion/motion-import.js +1568 -0
- package/dist/capabilities/dist/motion/motion-plan.js +2340 -0
- package/dist/capabilities/dist/motion/motion-query.js +423 -0
- package/dist/capabilities/dist/motion/motion-schemas.js +339 -0
- package/dist/capabilities/dist/motion/motion.js +1617 -0
- package/dist/capabilities/dist/notes/notes-codegen.js +19 -0
- package/dist/capabilities/dist/notes/notes-declaration.js +8 -0
- package/dist/capabilities/dist/notes/notes-elements.js +12 -0
- package/dist/capabilities/dist/notes/notes-import.js +292 -0
- package/dist/capabilities/dist/notes/notes-schemas.js +38 -0
- package/dist/capabilities/dist/notes/notes-xml.js +38 -0
- package/dist/capabilities/dist/notes/notes.js +194 -0
- package/dist/capabilities/dist/placeholder/placeholder-codegen.js +54 -0
- package/dist/capabilities/dist/placeholder/placeholder-elements.js +13 -0
- package/dist/capabilities/dist/placeholder/placeholder-schemas.js +33 -0
- package/dist/capabilities/dist/placeholder/placeholder.js +451 -0
- package/dist/capabilities/dist/shape/shape-codegen.js +236 -0
- package/dist/capabilities/dist/shape/shape-declaration.js +45 -0
- package/dist/capabilities/dist/shape/shape-elements.js +12 -0
- package/dist/capabilities/dist/shape/shape-import.js +628 -0
- package/dist/capabilities/dist/shape/shape-xml.js +6 -0
- package/dist/capabilities/dist/shape/shape.js +320 -0
- package/dist/capabilities/dist/shared/geometry.js +1681 -0
- package/dist/capabilities/dist/shared/identity.js +205 -0
- package/dist/capabilities/dist/shared/morph-api.js +11 -0
- package/dist/capabilities/dist/shared/placeholder-import.js +238 -0
- package/dist/capabilities/dist/shared/preset-definitions.js +22423 -0
- package/dist/capabilities/dist/shared/style-inheritance.js +161 -0
- package/dist/capabilities/dist/shared/text-schemas.js +241 -0
- package/dist/capabilities/dist/shared/text-service.js +2252 -0
- package/dist/capabilities/dist/shared/visual.js +1197 -0
- package/dist/capabilities/dist/slide-background/slide-background-codegen.js +44 -0
- package/dist/capabilities/dist/slide-background/slide-background-import.js +166 -0
- package/dist/capabilities/dist/slide-background/slide-background-xml.js +34 -0
- package/dist/capabilities/dist/slide-background/slide-background.js +238 -0
- package/dist/capabilities/dist/table/table-codegen.js +125 -0
- package/dist/capabilities/dist/table/table-declaration.js +15 -0
- package/dist/capabilities/dist/table/table-elements.js +27 -0
- package/dist/capabilities/dist/table/table-import.js +606 -0
- package/dist/capabilities/dist/table/table-schemas.js +334 -0
- package/dist/capabilities/dist/table/table-xml.js +30 -0
- package/dist/capabilities/dist/table/table.js +739 -0
- package/dist/capabilities/dist/text/text-codegen.js +198 -0
- package/dist/capabilities/dist/text/text-declaration.js +27 -0
- package/dist/capabilities/dist/text/text-elements.js +54 -0
- package/dist/capabilities/dist/text/text-import.js +1224 -0
- package/dist/capabilities/dist/text/text-xml.js +9 -0
- package/dist/capabilities/dist/text/text.js +320 -0
- package/dist/capabilities/dist/transition/transition-api.js +136 -0
- package/dist/capabilities/dist/transition/transition-codegen.js +45 -0
- package/dist/capabilities/dist/transition/transition-import.js +477 -0
- package/dist/capabilities/dist/transition/transition.js +260 -0
- package/dist/capability-BbKW9w4O.d.ts +2131 -0
- package/dist/cli.js +20 -0
- package/dist/codegen/dist/assets.js +79 -0
- package/dist/codegen/dist/codegen.js +691 -0
- package/dist/codegen/dist/identifiers.js +203 -0
- package/dist/codegen/dist/index.js +3 -0
- package/dist/codegen/dist/printer.js +143 -0
- package/dist/codegen/dist/types.js +77 -0
- package/dist/core/dist/author-ids.js +51 -0
- package/dist/core/dist/author-schemas.js +330 -0
- package/dist/core/dist/block-flex-layout.js +801 -0
- package/dist/core/dist/build.js +4 -0
- package/dist/core/dist/capability.js +15 -0
- package/dist/core/dist/declaration.js +16 -0
- package/dist/core/dist/diagnostics.js +353 -0
- package/dist/core/dist/document-internals.js +26 -0
- package/dist/core/dist/document.js +417 -0
- package/dist/core/dist/font-seal.js +204 -0
- package/dist/core/dist/geometry-schemas.js +256 -0
- package/dist/core/dist/grid-layout.js +449 -0
- package/dist/core/dist/host.js +40 -0
- package/dist/core/dist/index.js +15 -0
- package/dist/core/dist/input-values.js +61 -0
- package/dist/core/dist/layout-protocol.js +61 -0
- package/dist/core/dist/layout-schemas.js +201 -0
- package/dist/core/dist/layout.js +340 -0
- package/dist/core/dist/masters.js +194 -0
- package/dist/core/dist/morph.js +30 -0
- package/dist/core/dist/placeholders.js +275 -0
- package/dist/core/dist/query.js +190 -0
- package/dist/core/dist/resolution.js +12 -0
- package/dist/core/dist/resolve.js +2246 -0
- package/dist/core/dist/stage-options.js +300 -0
- package/dist/core/dist/theme.js +1023 -0
- package/dist/core/dist/transform-geometry.js +72 -0
- package/dist/document-41spD7bq.d.ts +1350 -0
- package/dist/emit/dist/emit.js +957 -0
- package/dist/emit/dist/index.js +5 -0
- package/dist/emit/dist/ooxml.js +661 -0
- package/dist/emit/dist/shape-tree.js +12 -0
- package/dist/import/dist/alternate-content.js +54 -0
- package/dist/import/dist/diagnostics.js +157 -0
- package/dist/import/dist/fonts.js +309 -0
- package/dist/import/dist/import.js +513 -0
- package/dist/import/dist/index.js +16 -0
- package/dist/import/dist/masters.js +1293 -0
- package/dist/import/dist/mechanism.js +10 -0
- package/dist/import/dist/namespaces.js +61 -0
- package/dist/import/dist/notes-masters.js +300 -0
- package/dist/import/dist/opc.js +233 -0
- package/dist/import/dist/resources.js +166 -0
- package/dist/import/dist/sections.js +139 -0
- package/dist/import/dist/themes.js +777 -0
- package/dist/import/dist/visual.js +821 -0
- package/dist/import/dist/xml-fragments.js +277 -0
- package/dist/import/dist/xml-reader.js +267 -0
- package/dist/index-1ag7U9Jt.d.ts +63 -0
- package/dist/index-BEwhk7c8.d.ts +72 -0
- package/dist/index-cK2KtukZ.d.ts +161 -0
- package/dist/index-v77CTJev.d.ts +55 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +82 -0
- package/dist/node.d.ts +53 -0
- package/dist/node.js +225 -0
- package/dist/pptxdk/src/cli-commands.js +907 -0
- package/dist/pptxdk/src/compose.js +53 -0
- package/dist/pptxdk/src/slide.js +9 -0
- package/dist/preview/dist/index.js +342 -0
- package/dist/preview/dist/options.js +40 -0
- package/dist/preview/dist/svg-guard.js +1089 -0
- package/dist/preview.d.ts +12 -0
- package/dist/preview.js +29 -0
- package/dist/react/dist/append.js +66 -0
- package/dist/react/dist/document-adapter.js +404 -0
- package/dist/react/dist/elements.js +82 -0
- package/dist/react/dist/from-vanilla.js +57 -0
- package/dist/react/dist/index.js +89 -0
- package/dist/react/dist/mount.js +34 -0
- package/dist/react/dist/reconciler.js +290 -0
- package/dist/react.d.ts +235 -0
- package/dist/react.js +31 -0
- package/dist/transition-6n8GZxSg.d.ts +9 -0
- package/dist/vanilla.d.ts +4 -0
- package/dist/vanilla.js +15 -0
- package/package.json +79 -3
- package/README.md +0 -3
|
@@ -0,0 +1,365 @@
|
|
|
1
|
+
import { computeErrorBarBounds } from "./error-bars.js";
|
|
2
|
+
import { collectCategoryFitPoints, collectScatterFitPoints, fitTrendline } from "./trendlines.js";
|
|
3
|
+
import { assertNever } from "./types.js";
|
|
4
|
+
// ../capabilities/dist/chart/preview/scales.js
|
|
5
|
+
function cleanNumber(value) {
|
|
6
|
+
if (Object.is(value, -0) || value === 0) return 0;
|
|
7
|
+
return Number(value.toPrecision(12));
|
|
8
|
+
}
|
|
9
|
+
function niceStep(span) {
|
|
10
|
+
const rough = (span > 0 && Number.isFinite(span) ? span : 1) / 5;
|
|
11
|
+
const mag = 10 ** Math.floor(Math.log10(rough));
|
|
12
|
+
return cleanNumber(([
|
|
13
|
+
1,
|
|
14
|
+
2,
|
|
15
|
+
2.5,
|
|
16
|
+
5,
|
|
17
|
+
10
|
|
18
|
+
].find((c) => c * mag >= rough - 1e-12) ?? 10) * mag);
|
|
19
|
+
}
|
|
20
|
+
function generateLinearTicks(min, max, step, maxCount = 50) {
|
|
21
|
+
if (!Number.isFinite(step) || step <= 0 || max <= min) return [cleanNumber(min), cleanNumber(max)];
|
|
22
|
+
const effectiveStep = Math.floor((max - min) / step + 1e-9) + 1 > maxCount ? cleanNumber((max - min) / (maxCount - 1)) : step;
|
|
23
|
+
const ticks = [];
|
|
24
|
+
const limit = max + effectiveStep * 1e-6;
|
|
25
|
+
for (let i = 0; i <= maxCount + 1; i += 1) {
|
|
26
|
+
const val = cleanNumber(min + i * effectiveStep);
|
|
27
|
+
if (val > limit) break;
|
|
28
|
+
ticks.push(val);
|
|
29
|
+
}
|
|
30
|
+
if (ticks.length === 0) ticks.push(cleanNumber(min), cleanNumber(max));
|
|
31
|
+
return ticks;
|
|
32
|
+
}
|
|
33
|
+
function collectAxisValues(axis, groups, displayBlanksAs) {
|
|
34
|
+
const values = [];
|
|
35
|
+
let hasPercent = false;
|
|
36
|
+
let hasBaselineZero = false;
|
|
37
|
+
for (const group of groups) switch (group.kind) {
|
|
38
|
+
case "column":
|
|
39
|
+
case "bar":
|
|
40
|
+
case "line":
|
|
41
|
+
case "area": {
|
|
42
|
+
if (group.axes.value !== axis) continue;
|
|
43
|
+
if (group.kind === "column" || group.kind === "bar" || group.kind === "area") hasBaselineZero = true;
|
|
44
|
+
const catCount = group.data.categories.length;
|
|
45
|
+
if (group.stacking === "percent") {
|
|
46
|
+
hasPercent = true;
|
|
47
|
+
for (let i = 0; i < catCount; i += 1) {
|
|
48
|
+
let posSum = 0;
|
|
49
|
+
let negAbsSum = 0;
|
|
50
|
+
for (const series of group.series) {
|
|
51
|
+
const v = series.values[i];
|
|
52
|
+
if (v === null || v === void 0 || !Number.isFinite(v)) continue;
|
|
53
|
+
if (v >= 0) posSum += v;
|
|
54
|
+
else negAbsSum += -v;
|
|
55
|
+
}
|
|
56
|
+
const totalAbs = posSum + negAbsSum;
|
|
57
|
+
if (totalAbs > 0) values.push(posSum / totalAbs, -negAbsSum / totalAbs);
|
|
58
|
+
}
|
|
59
|
+
} else if (group.stacking === "stacked") for (let i = 0; i < catCount; i += 1) {
|
|
60
|
+
let posSum = 0;
|
|
61
|
+
let negSum = 0;
|
|
62
|
+
let hasAny = false;
|
|
63
|
+
for (const series of group.series) {
|
|
64
|
+
const v = series.values[i];
|
|
65
|
+
if (v === null || v === void 0 || !Number.isFinite(v)) continue;
|
|
66
|
+
hasAny = true;
|
|
67
|
+
if (v >= 0) posSum += v;
|
|
68
|
+
else negSum += v;
|
|
69
|
+
}
|
|
70
|
+
if (hasAny) values.push(posSum, negSum);
|
|
71
|
+
}
|
|
72
|
+
else for (const series of group.series) {
|
|
73
|
+
for (const v of series.values) if (v !== null && v !== void 0 && Number.isFinite(v)) values.push(v);
|
|
74
|
+
else if (v === null && displayBlanksAs === "zero") values.push(0);
|
|
75
|
+
for (const tl of series.trendlines ?? []) {
|
|
76
|
+
if (tl.forward === void 0 && tl.backward === void 0) continue;
|
|
77
|
+
const model = fitTrendline(collectCategoryFitPoints(series.values), tl);
|
|
78
|
+
if (model?.kind === "curve") for (const xSample of [model.xMin, model.xMax]) {
|
|
79
|
+
const ySample = model.evalY(xSample);
|
|
80
|
+
if (Number.isFinite(ySample)) values.push(ySample);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
if (series.errorBars !== void 0) {
|
|
84
|
+
const bounds = computeErrorBarBounds(series.errorBars, series.values);
|
|
85
|
+
for (const b of bounds) {
|
|
86
|
+
if (b.hasMinus && Number.isFinite(b.low)) values.push(b.low);
|
|
87
|
+
if (b.hasPlus && Number.isFinite(b.high)) values.push(b.high);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
break;
|
|
92
|
+
}
|
|
93
|
+
case "scatter": {
|
|
94
|
+
const isX = group.axes.x === axis;
|
|
95
|
+
const isY = group.axes.y === axis;
|
|
96
|
+
if (!isX && !isY) continue;
|
|
97
|
+
const blanksZero = displayBlanksAs === "zero";
|
|
98
|
+
for (const series of group.series) {
|
|
99
|
+
for (let i = 0; i < series.x.length; i += 1) {
|
|
100
|
+
const xVal = series.x[i];
|
|
101
|
+
const yVal = series.y[i];
|
|
102
|
+
if (blanksZero) {
|
|
103
|
+
const coord = isX ? xVal ?? 0 : yVal ?? 0;
|
|
104
|
+
if (Number.isFinite(coord)) values.push(coord);
|
|
105
|
+
} else if (xVal !== null && xVal !== void 0 && Number.isFinite(xVal) && yVal !== null && yVal !== void 0 && Number.isFinite(yVal)) values.push(isX ? xVal : yVal);
|
|
106
|
+
}
|
|
107
|
+
for (const tl of series.trendlines ?? []) {
|
|
108
|
+
if (tl.forward === void 0 && tl.backward === void 0) continue;
|
|
109
|
+
const model = fitTrendline(collectScatterFitPoints(series.x, series.y), tl);
|
|
110
|
+
if (model?.kind === "curve") {
|
|
111
|
+
if (isX) {
|
|
112
|
+
if (Number.isFinite(model.xMin)) values.push(model.xMin);
|
|
113
|
+
if (Number.isFinite(model.xMax)) values.push(model.xMax);
|
|
114
|
+
}
|
|
115
|
+
if (isY) for (const xSample of [model.xMin, model.xMax]) {
|
|
116
|
+
const ySample = model.evalY(xSample);
|
|
117
|
+
if (Number.isFinite(ySample)) values.push(ySample);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
const skipMask = series.x.map((xv, i) => {
|
|
122
|
+
const yv = series.y[i];
|
|
123
|
+
if (blanksZero) return false;
|
|
124
|
+
return xv === null || xv === void 0 || !Number.isFinite(xv) || yv === null || yv === void 0 || !Number.isFinite(yv);
|
|
125
|
+
});
|
|
126
|
+
if (isX && series.errorBars?.x !== void 0) {
|
|
127
|
+
const bounds = computeErrorBarBounds(series.errorBars.x, series.x.map((v) => v === null && blanksZero ? 0 : v), { skipMask });
|
|
128
|
+
for (const b of bounds) {
|
|
129
|
+
if (b.hasMinus && Number.isFinite(b.low)) values.push(b.low);
|
|
130
|
+
if (b.hasPlus && Number.isFinite(b.high)) values.push(b.high);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
if (isY && series.errorBars?.y !== void 0) {
|
|
134
|
+
const bounds = computeErrorBarBounds(series.errorBars.y, series.y.map((v) => v === null && blanksZero ? 0 : v), { skipMask });
|
|
135
|
+
for (const b of bounds) {
|
|
136
|
+
if (b.hasMinus && Number.isFinite(b.low)) values.push(b.low);
|
|
137
|
+
if (b.hasPlus && Number.isFinite(b.high)) values.push(b.high);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
break;
|
|
142
|
+
}
|
|
143
|
+
case "pie":
|
|
144
|
+
case "doughnut": break;
|
|
145
|
+
default: assertNever(group);
|
|
146
|
+
}
|
|
147
|
+
return {
|
|
148
|
+
values,
|
|
149
|
+
hasPercent,
|
|
150
|
+
hasBaselineZero
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
function buildCategoryAxisScale(axis, groups) {
|
|
154
|
+
let categories = [];
|
|
155
|
+
let hasCategoryGroup = false;
|
|
156
|
+
let allArea = true;
|
|
157
|
+
for (const group of groups) {
|
|
158
|
+
if (group.kind === "scatter" || group.kind === "pie" || group.kind === "doughnut") continue;
|
|
159
|
+
if (group.axes.category !== axis) continue;
|
|
160
|
+
if (!hasCategoryGroup) categories = group.data.categories;
|
|
161
|
+
hasCategoryGroup = true;
|
|
162
|
+
if (group.kind !== "area") allArea = false;
|
|
163
|
+
}
|
|
164
|
+
const count = Math.max(1, categories.length);
|
|
165
|
+
const crossBetween = hasCategoryGroup && allArea && count > 1 ? "midCat" : "between";
|
|
166
|
+
const reversed = axis.spec.reversed === true;
|
|
167
|
+
const horizontal = axis.direction === "horizontal";
|
|
168
|
+
const mapIndex = (index) => {
|
|
169
|
+
const rawT = crossBetween === "midCat" && count > 1 ? index / (count - 1) : (index + .5) / count;
|
|
170
|
+
return reversed ? 1 - rawT : rawT;
|
|
171
|
+
};
|
|
172
|
+
const mapBoundary = (boundary) => {
|
|
173
|
+
const rawT = boundary / count;
|
|
174
|
+
return reversed ? 1 - rawT : rawT;
|
|
175
|
+
};
|
|
176
|
+
const mapScreen = (t, plot) => horizontal ? plot.x + t * plot.width : plot.y + (1 - t) * plot.height;
|
|
177
|
+
return {
|
|
178
|
+
kind: "category",
|
|
179
|
+
axis,
|
|
180
|
+
categories,
|
|
181
|
+
count,
|
|
182
|
+
crossBetween,
|
|
183
|
+
reversed,
|
|
184
|
+
mapIndex,
|
|
185
|
+
mapBoundary,
|
|
186
|
+
mapScreen,
|
|
187
|
+
indexToScreen(index, plot) {
|
|
188
|
+
return mapScreen(mapIndex(index), plot);
|
|
189
|
+
},
|
|
190
|
+
slotSpan(plot) {
|
|
191
|
+
return (horizontal ? plot.width : plot.height) / count;
|
|
192
|
+
}
|
|
193
|
+
};
|
|
194
|
+
}
|
|
195
|
+
function buildValueAxisScale(axis, groups, displayBlanksAs) {
|
|
196
|
+
const { values, hasPercent, hasBaselineZero } = collectAxisValues(axis, groups, displayBlanksAs);
|
|
197
|
+
const spec = axis.spec;
|
|
198
|
+
const reversed = spec.reversed === true;
|
|
199
|
+
const horizontal = axis.direction === "horizontal";
|
|
200
|
+
const numberFormat = spec.numberFormat ?? (hasPercent ? "0%" : void 0);
|
|
201
|
+
if (spec.logBase !== void 0) {
|
|
202
|
+
const base = spec.logBase;
|
|
203
|
+
const positive = values.filter((v) => v > 0);
|
|
204
|
+
const rawMin = positive.length > 0 ? Math.min(...positive) : 1;
|
|
205
|
+
const rawMax = positive.length > 0 ? Math.max(...positive) : base * base;
|
|
206
|
+
const minExp = Math.floor(Math.log(rawMin) / Math.log(base) + 1e-12);
|
|
207
|
+
const maxExp = Math.ceil(Math.log(rawMax) / Math.log(base) - 1e-12);
|
|
208
|
+
let min = spec.min !== void 0 && spec.min > 0 ? spec.min : cleanNumber(base ** minExp);
|
|
209
|
+
if (min <= 0 || !Number.isFinite(min)) min = 1;
|
|
210
|
+
let max = spec.max !== void 0 && spec.max > min ? spec.max : cleanNumber(base ** maxExp);
|
|
211
|
+
if (max <= min || !Number.isFinite(max)) max = cleanNumber(min * base);
|
|
212
|
+
const startExp = Math.floor(Math.log(min) / Math.log(base) + 1e-9);
|
|
213
|
+
const endExp = Math.ceil(Math.log(max) / Math.log(base) - 1e-9);
|
|
214
|
+
const spanExp = Math.max(1, endExp - startExp + 1);
|
|
215
|
+
const stride = spanExp > 10 ? Math.ceil(spanExp / 8) : 1;
|
|
216
|
+
const majorTicks = [];
|
|
217
|
+
const minorTicks = [];
|
|
218
|
+
for (let e = startExp; e <= endExp; e += 1) {
|
|
219
|
+
const tick = cleanNumber(base ** e);
|
|
220
|
+
if ((e - startExp) % stride === 0) {
|
|
221
|
+
if (tick >= min * (1 - 1e-9) && tick <= max * (1 + 1e-9)) majorTicks.push(tick);
|
|
222
|
+
}
|
|
223
|
+
const subMax = Math.min(9, Math.floor(base) - 1);
|
|
224
|
+
for (let m = 2; m <= subMax; m += 1) {
|
|
225
|
+
const sub = cleanNumber(m * base ** e);
|
|
226
|
+
if (sub > min * (1 + 1e-9) && sub < max * (1 - 1e-9)) minorTicks.push(sub);
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
if (majorTicks.length < 2) majorTicks.splice(0, majorTicks.length, min, max);
|
|
230
|
+
const logSpan = Math.log(max / min);
|
|
231
|
+
const mapValue = (v) => {
|
|
232
|
+
if (v <= 0 || !Number.isFinite(v)) return reversed ? 1 : 0;
|
|
233
|
+
const rawT = Math.log(v / min) / logSpan;
|
|
234
|
+
return reversed ? 1 - rawT : rawT;
|
|
235
|
+
};
|
|
236
|
+
const mapScreen = (t, plot) => horizontal ? plot.x + t * plot.width : plot.y + (1 - t) * plot.height;
|
|
237
|
+
return {
|
|
238
|
+
kind: "value",
|
|
239
|
+
axis,
|
|
240
|
+
min,
|
|
241
|
+
max,
|
|
242
|
+
logBase: base,
|
|
243
|
+
majorTicks,
|
|
244
|
+
minorTicks,
|
|
245
|
+
reversed,
|
|
246
|
+
numberFormat,
|
|
247
|
+
mapValue,
|
|
248
|
+
mapScreen,
|
|
249
|
+
valueToScreen(v, plot) {
|
|
250
|
+
return mapScreen(mapValue(v), plot);
|
|
251
|
+
},
|
|
252
|
+
zeroValue() {
|
|
253
|
+
return min;
|
|
254
|
+
},
|
|
255
|
+
zeroScreen(plot) {
|
|
256
|
+
return mapScreen(mapValue(min), plot);
|
|
257
|
+
}
|
|
258
|
+
};
|
|
259
|
+
}
|
|
260
|
+
let rawMin = values.length > 0 ? Math.min(...values) : 0;
|
|
261
|
+
let rawMax = values.length > 0 ? Math.max(...values) : 1;
|
|
262
|
+
if (hasBaselineZero || values.length === 0) {
|
|
263
|
+
rawMin = Math.min(0, rawMin);
|
|
264
|
+
rawMax = Math.max(0, rawMax);
|
|
265
|
+
}
|
|
266
|
+
if (rawMin === rawMax) {
|
|
267
|
+
if (rawMax === 0) {
|
|
268
|
+
rawMin = 0;
|
|
269
|
+
rawMax = 1;
|
|
270
|
+
} else if (rawMax > 0) rawMin = 0;
|
|
271
|
+
else rawMax = 0;
|
|
272
|
+
}
|
|
273
|
+
let majorUnit;
|
|
274
|
+
let min;
|
|
275
|
+
let max;
|
|
276
|
+
if (hasPercent && spec.min === void 0 && spec.max === void 0) {
|
|
277
|
+
majorUnit = spec.majorUnit ?? .2;
|
|
278
|
+
min = rawMin >= 0 ? 0 : Math.max(-1, cleanNumber(Math.floor(rawMin / majorUnit + 1e-12) * majorUnit));
|
|
279
|
+
max = rawMax <= 1 ? 1 : Math.min(1, cleanNumber(Math.ceil(rawMax / majorUnit - 1e-12) * majorUnit));
|
|
280
|
+
if (min >= max) max = cleanNumber(min + majorUnit);
|
|
281
|
+
} else {
|
|
282
|
+
const initialSpan = (spec.max ?? rawMax) - (spec.min ?? rawMin);
|
|
283
|
+
majorUnit = spec.majorUnit ?? niceStep(initialSpan);
|
|
284
|
+
min = spec.min ?? cleanNumber(Math.floor(rawMin / majorUnit + 1e-12) * majorUnit);
|
|
285
|
+
max = spec.max ?? cleanNumber(Math.ceil(rawMax / majorUnit - 1e-12) * majorUnit);
|
|
286
|
+
if (min >= max) max = cleanNumber(min + majorUnit);
|
|
287
|
+
if (spec.majorUnit === void 0 && (spec.min !== void 0 || spec.max !== void 0)) {
|
|
288
|
+
const tickEstimate = (max - min) / majorUnit;
|
|
289
|
+
if (tickEstimate < 2 || tickEstimate > 12) majorUnit = niceStep(max - min);
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
const minorUnit = spec.minorUnit ?? cleanNumber(majorUnit / 5);
|
|
293
|
+
const majorTicks = generateLinearTicks(min, max, majorUnit, 40);
|
|
294
|
+
const minorTicks = minorUnit > 0 ? generateLinearTicks(min, max, minorUnit, 200).filter((t) => !majorTicks.some((m) => Math.abs(m - t) <= majorUnit * 1e-6)) : [];
|
|
295
|
+
const span = max - min;
|
|
296
|
+
const mapValue = (v) => {
|
|
297
|
+
const rawT = (v - min) / span;
|
|
298
|
+
return reversed ? 1 - rawT : rawT;
|
|
299
|
+
};
|
|
300
|
+
const mapScreen = (t, plot) => horizontal ? plot.x + t * plot.width : plot.y + (1 - t) * plot.height;
|
|
301
|
+
const zeroVal = Math.max(min, Math.min(max, 0));
|
|
302
|
+
return {
|
|
303
|
+
kind: "value",
|
|
304
|
+
axis,
|
|
305
|
+
min,
|
|
306
|
+
max,
|
|
307
|
+
majorTicks,
|
|
308
|
+
minorTicks,
|
|
309
|
+
reversed,
|
|
310
|
+
numberFormat,
|
|
311
|
+
mapValue,
|
|
312
|
+
mapScreen,
|
|
313
|
+
valueToScreen(v, plot) {
|
|
314
|
+
return mapScreen(mapValue(v), plot);
|
|
315
|
+
},
|
|
316
|
+
zeroValue() {
|
|
317
|
+
return zeroVal;
|
|
318
|
+
},
|
|
319
|
+
zeroScreen(plot) {
|
|
320
|
+
return mapScreen(mapValue(zeroVal), plot);
|
|
321
|
+
}
|
|
322
|
+
};
|
|
323
|
+
}
|
|
324
|
+
/** Computes axis scales for all axes in the parsed chart. */
|
|
325
|
+
function buildAxisScales(parsed) {
|
|
326
|
+
const result = /* @__PURE__ */ new Map();
|
|
327
|
+
for (const axis of parsed.axes) switch (axis.kind) {
|
|
328
|
+
case "category":
|
|
329
|
+
result.set(axis.name, buildCategoryAxisScale(axis, parsed.groups));
|
|
330
|
+
break;
|
|
331
|
+
case "value":
|
|
332
|
+
result.set(axis.name, buildValueAxisScale(axis, parsed.groups, parsed.displayBlanksAs));
|
|
333
|
+
break;
|
|
334
|
+
default: assertNever(axis);
|
|
335
|
+
}
|
|
336
|
+
return result;
|
|
337
|
+
}
|
|
338
|
+
/** Resolves the normalized unreversed/reversed position of `axis` inside `crossScale`. */
|
|
339
|
+
function resolveAxisCrossingNormalized(axis, crossScale) {
|
|
340
|
+
const crossing = axis.crossing;
|
|
341
|
+
switch (crossScale.kind) {
|
|
342
|
+
case "value":
|
|
343
|
+
if (crossing.kind === "crossesAt") {
|
|
344
|
+
const clamped = Math.max(crossScale.min, Math.min(crossScale.max, crossing.value));
|
|
345
|
+
return crossScale.mapValue(clamped);
|
|
346
|
+
}
|
|
347
|
+
if (crossing.value === "min") return crossScale.mapValue(crossScale.min);
|
|
348
|
+
if (crossing.value === "max") return crossScale.mapValue(crossScale.max);
|
|
349
|
+
return crossScale.mapValue(crossScale.zeroValue());
|
|
350
|
+
case "category": {
|
|
351
|
+
let rawT;
|
|
352
|
+
if (crossing.kind === "crossesAt") rawT = crossScale.crossBetween === "midCat" && crossScale.count > 1 ? Math.max(0, Math.min(1, (crossing.value - 1) / (crossScale.count - 1))) : Math.max(0, Math.min(1, (crossing.value - 1) / crossScale.count));
|
|
353
|
+
else if (crossing.value === "max") rawT = 1;
|
|
354
|
+
else rawT = 0;
|
|
355
|
+
return crossScale.reversed ? 1 - rawT : rawT;
|
|
356
|
+
}
|
|
357
|
+
default: return assertNever(crossScale);
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
/** Resolves the screen coordinate of `axis` inside `crossScale` and `plot`. */
|
|
361
|
+
function resolveAxisCrossingScreen(axis, crossScale, plot) {
|
|
362
|
+
const t = resolveAxisCrossingNormalized(axis, crossScale);
|
|
363
|
+
return crossScale.mapScreen(t, plot);
|
|
364
|
+
}
|
|
365
|
+
export { buildAxisScales, resolveAxisCrossingNormalized, resolveAxisCrossingScreen };
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import { renderStyledLineRun, resolvePointSegmentStroke } from "./line-area.js";
|
|
2
|
+
import { renderMarkerSvg, resolveEffectiveMarker } from "./markers.js";
|
|
3
|
+
import { chartAccentSlot, resolveChartLineStroke, resolveSeriesColor } from "./style.js";
|
|
4
|
+
// ../capabilities/dist/chart/preview/scatter.js
|
|
5
|
+
function renderScatterGroup(options) {
|
|
6
|
+
const { group, groupIndex, scales, plotRect, displayBlanksAs, theme } = options;
|
|
7
|
+
const xScale = scales.get(group.axes.x.name);
|
|
8
|
+
const yScale = scales.get(group.axes.y.name);
|
|
9
|
+
if (xScale?.kind !== "value" || yScale?.kind !== "value") return {
|
|
10
|
+
svg: "",
|
|
11
|
+
anchors: []
|
|
12
|
+
};
|
|
13
|
+
if (group.series.length === 0) return {
|
|
14
|
+
svg: "",
|
|
15
|
+
anchors: []
|
|
16
|
+
};
|
|
17
|
+
const hasLine = group.line !== false;
|
|
18
|
+
const isSmooth = group.line === "smooth";
|
|
19
|
+
const blanksMode = displayBlanksAs ?? "gap";
|
|
20
|
+
const parts = [];
|
|
21
|
+
const anchors = [];
|
|
22
|
+
for (let s = 0; s < group.series.length; s += 1) {
|
|
23
|
+
const series = group.series[s];
|
|
24
|
+
if (series.x.length === 0 || series.y.length === 0) continue;
|
|
25
|
+
const baseStroke = resolveChartLineStroke(series.line, theme, {
|
|
26
|
+
color: series.color ?? chartAccentSlot(series.seriesIndex),
|
|
27
|
+
width: 2
|
|
28
|
+
});
|
|
29
|
+
const runs = [];
|
|
30
|
+
let currentRun = [];
|
|
31
|
+
const markerQueue = [];
|
|
32
|
+
for (let i = 0; i < series.x.length; i += 1) {
|
|
33
|
+
const rawX = series.x[i];
|
|
34
|
+
const rawY = series.y[i];
|
|
35
|
+
const missingX = rawX === null || rawX === void 0 || !Number.isFinite(rawX);
|
|
36
|
+
const missingY = rawY === null || rawY === void 0 || !Number.isFinite(rawY);
|
|
37
|
+
const isMissing = missingX || missingY;
|
|
38
|
+
let xVal;
|
|
39
|
+
let yVal;
|
|
40
|
+
if (isMissing) {
|
|
41
|
+
if (blanksMode === "zero") {
|
|
42
|
+
xVal = missingX ? 0 : rawX;
|
|
43
|
+
yVal = missingY ? 0 : rawY;
|
|
44
|
+
} else if (blanksMode === "span") continue;
|
|
45
|
+
else {
|
|
46
|
+
if (currentRun.length > 0) {
|
|
47
|
+
runs.push(currentRun);
|
|
48
|
+
currentRun = [];
|
|
49
|
+
}
|
|
50
|
+
continue;
|
|
51
|
+
}
|
|
52
|
+
} else {
|
|
53
|
+
xVal = rawX;
|
|
54
|
+
yVal = rawY;
|
|
55
|
+
}
|
|
56
|
+
if (xScale.logBase !== void 0 && xVal <= 0 || yScale.logBase !== void 0 && yVal <= 0) {
|
|
57
|
+
if (blanksMode === "gap" && currentRun.length > 0) {
|
|
58
|
+
runs.push(currentRun);
|
|
59
|
+
currentRun = [];
|
|
60
|
+
}
|
|
61
|
+
continue;
|
|
62
|
+
}
|
|
63
|
+
const x = xScale.valueToScreen(xVal, plotRect);
|
|
64
|
+
const y = yScale.valueToScreen(yVal, plotRect);
|
|
65
|
+
const point = series.points?.[i];
|
|
66
|
+
const marker = group.markers ? resolveEffectiveMarker({
|
|
67
|
+
groupDefaultEnabled: true,
|
|
68
|
+
seriesMarker: series.marker,
|
|
69
|
+
pointMarker: point?.marker,
|
|
70
|
+
seriesColor: series.color,
|
|
71
|
+
pointColor: point?.color,
|
|
72
|
+
seriesIndex: series.seriesIndex,
|
|
73
|
+
theme
|
|
74
|
+
}) : void 0;
|
|
75
|
+
const segmentStroke = resolvePointSegmentStroke({
|
|
76
|
+
pointLine: point?.line,
|
|
77
|
+
pointColor: point?.color,
|
|
78
|
+
seriesLine: series.line,
|
|
79
|
+
seriesColor: series.color,
|
|
80
|
+
seriesIndex: series.seriesIndex,
|
|
81
|
+
baseStroke,
|
|
82
|
+
theme
|
|
83
|
+
});
|
|
84
|
+
currentRun.push({
|
|
85
|
+
x,
|
|
86
|
+
y,
|
|
87
|
+
pointIndex: i,
|
|
88
|
+
marker,
|
|
89
|
+
segmentStroke
|
|
90
|
+
});
|
|
91
|
+
if (!isMissing) anchors.push({
|
|
92
|
+
kind: "point",
|
|
93
|
+
groupIndex,
|
|
94
|
+
seriesIndex: series.seriesIndex,
|
|
95
|
+
groupSeriesIndex: s,
|
|
96
|
+
pointIndex: i,
|
|
97
|
+
value: rawY,
|
|
98
|
+
xValue: rawX,
|
|
99
|
+
seriesName: series.name,
|
|
100
|
+
x,
|
|
101
|
+
y,
|
|
102
|
+
...marker === void 0 ? {} : { markerRadius: marker.radius }
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
if (currentRun.length > 0) runs.push(currentRun);
|
|
106
|
+
for (const run of runs) {
|
|
107
|
+
if (hasLine && run.length >= 2) parts.push(renderStyledLineRun({
|
|
108
|
+
run,
|
|
109
|
+
smooth: isSmooth,
|
|
110
|
+
baseStroke,
|
|
111
|
+
segmentStrokeOf: (pt) => pt.segmentStroke
|
|
112
|
+
}));
|
|
113
|
+
for (const node of run) markerQueue.push({
|
|
114
|
+
x: node.x,
|
|
115
|
+
y: node.y,
|
|
116
|
+
marker: node.marker,
|
|
117
|
+
isolated: hasLine && run.length === 1
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
for (const item of markerQueue) if (item.marker !== void 0) parts.push(renderMarkerSvg(item.x, item.y, item.marker));
|
|
121
|
+
else if (item.isolated) {
|
|
122
|
+
const dotColor = resolveSeriesColor(series.line?.color ?? series.color, series.seriesIndex, theme);
|
|
123
|
+
parts.push(`<circle cx="${item.x}" cy="${item.y}" r="${Math.max(1.5, baseStroke.width * .75)}" fill="#${dotColor.hex}" fill-opacity="${dotColor.alpha ?? 1}"/>`);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
return {
|
|
127
|
+
svg: parts.join(""),
|
|
128
|
+
anchors
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
export { renderScatterGroup };
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { assertNever } from "./types.js";
|
|
2
|
+
// ../capabilities/dist/chart/preview/style.js
|
|
3
|
+
const chartAccentCycle = [
|
|
4
|
+
"accent1",
|
|
5
|
+
"accent2",
|
|
6
|
+
"accent3",
|
|
7
|
+
"accent4",
|
|
8
|
+
"accent5",
|
|
9
|
+
"accent6"
|
|
10
|
+
];
|
|
11
|
+
/** Returns the cycling DrawingML `accent1..accent6` scheme slot for a zero-based series index. */
|
|
12
|
+
function chartAccentSlot(seriesIndex) {
|
|
13
|
+
return chartAccentCycle[seriesIndex % chartAccentCycle.length];
|
|
14
|
+
}
|
|
15
|
+
/** Resolves a series or point fill color, falling back to the theme accent cycle. */
|
|
16
|
+
function resolveSeriesColor(color, seriesIndex, theme) {
|
|
17
|
+
return theme.resolveColor(color ?? chartAccentSlot(seriesIndex));
|
|
18
|
+
}
|
|
19
|
+
/** Maps an OOXML preset chart line dash pattern to an SVG stroke-dasharray string. */
|
|
20
|
+
function chartLineDashArray(dash, width) {
|
|
21
|
+
if (dash === void 0) return void 0;
|
|
22
|
+
const w = Math.max(1, width);
|
|
23
|
+
switch (dash) {
|
|
24
|
+
case "solid": return;
|
|
25
|
+
case "dash": return `${4 * w} ${3 * w}`;
|
|
26
|
+
case "dot": return `${w} ${2 * w}`;
|
|
27
|
+
case "dashDot": return `${4 * w} ${2 * w} ${w} ${2 * w}`;
|
|
28
|
+
case "longDash": return `${8 * w} ${3 * w}`;
|
|
29
|
+
case "longDashDot": return `${8 * w} ${2 * w} ${w} ${2 * w}`;
|
|
30
|
+
case "longDashDotDot": return `${8 * w} ${2 * w} ${w} ${2 * w} ${w} ${2 * w}`;
|
|
31
|
+
default: return assertNever(dash);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
/** Resolves a ChartLine declaration into SVG stroke attributes. */
|
|
35
|
+
function resolveChartLineStroke(line, theme, defaults = {}) {
|
|
36
|
+
if (line === false) return void 0;
|
|
37
|
+
if (line === void 0 || line === true) {
|
|
38
|
+
const resolved = theme.resolveColor(defaults.color ?? "dk1");
|
|
39
|
+
return {
|
|
40
|
+
hex: resolved.hex,
|
|
41
|
+
alpha: (resolved.alpha ?? 1) * (defaults.alpha ?? 1),
|
|
42
|
+
width: defaults.width ?? 1
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
const resolved = theme.resolveColor(line.color ?? defaults.color ?? "dk1");
|
|
46
|
+
const width = line.width ?? defaults.width ?? 1;
|
|
47
|
+
const dashArray = chartLineDashArray(line.dash, width);
|
|
48
|
+
return {
|
|
49
|
+
hex: resolved.hex,
|
|
50
|
+
alpha: resolved.alpha ?? 1,
|
|
51
|
+
width,
|
|
52
|
+
...dashArray === void 0 ? {} : { dashArray }
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
/** Formats SVG stroke attributes string from a resolved stroke. */
|
|
56
|
+
function strokeAttrs(stroke) {
|
|
57
|
+
const dash = stroke.dashArray === void 0 ? "" : ` stroke-dasharray="${stroke.dashArray}"`;
|
|
58
|
+
return `stroke="#${stroke.hex}" stroke-opacity="${stroke.alpha}" stroke-width="${stroke.width}"${dash}`;
|
|
59
|
+
}
|
|
60
|
+
export { chartAccentSlot, chartLineDashArray, resolveChartLineStroke, resolveSeriesColor, strokeAttrs };
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { measureTextLayoutFromParagraphs, parseTextContent, renderTextOutlinesSvg, withPreviewFontBoundary } from "../../shared/text-service.js";
|
|
2
|
+
// ../capabilities/dist/chart/preview/text-render.js
|
|
3
|
+
function createChartClipAllocator(slideNumber, objectId) {
|
|
4
|
+
let seq = 0;
|
|
5
|
+
return {
|
|
6
|
+
defs: [],
|
|
7
|
+
nextClipId() {
|
|
8
|
+
seq += 1;
|
|
9
|
+
return `rp-chart-clip-${slideNumber}-${objectId}-${seq}`;
|
|
10
|
+
}
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
/** Converts a FontSize token into CSS/SVG pixels, falling back to 14px when omitted. */
|
|
14
|
+
function resolveChartFontSizePixels(fontSize) {
|
|
15
|
+
if (fontSize === void 0) return 14;
|
|
16
|
+
if (typeof fontSize === "number") return fontSize;
|
|
17
|
+
const parsed = Number.parseFloat(fontSize);
|
|
18
|
+
if (!Number.isFinite(parsed) || parsed <= 0) return 14;
|
|
19
|
+
return fontSize.endsWith("pt") ? parsed * 4 / 3 : parsed;
|
|
20
|
+
}
|
|
21
|
+
function mergeChartTextStyle(base, override) {
|
|
22
|
+
if (base === void 0) return override;
|
|
23
|
+
if (override === void 0) return base;
|
|
24
|
+
return {
|
|
25
|
+
...base,
|
|
26
|
+
...override
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
/** Measures text using the shared text-service without mutating or inventing glyphs. */
|
|
30
|
+
function measureChartText(options) {
|
|
31
|
+
const { paragraphs, style: resolvedStyle } = parseTextContent([{
|
|
32
|
+
type: "#text",
|
|
33
|
+
text: options.text
|
|
34
|
+
}], options.style, options.theme, { slideNumber: options.slideNumber }, options.labelPath);
|
|
35
|
+
const measured = withPreviewFontBoundary(() => measureTextLayoutFromParagraphs(paragraphs, resolvedStyle, options.availableWidth));
|
|
36
|
+
return {
|
|
37
|
+
paragraphs,
|
|
38
|
+
resolvedStyle,
|
|
39
|
+
width: measured.width,
|
|
40
|
+
height: measured.height,
|
|
41
|
+
minContentWidth: measured.minContentWidth
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Renders vector glyph outlines inside `box`, adapting cleanly via optional line wrapping
|
|
46
|
+
* and SVG clipPath bounds without ever emitting overflow errors or synthetic ellipsis glyphs.
|
|
47
|
+
*/
|
|
48
|
+
function renderChartTextSvg(options) {
|
|
49
|
+
if (options.text === "") return "";
|
|
50
|
+
const align = options.align ?? options.style?.align ?? "center";
|
|
51
|
+
const verticalAlign = options.verticalAlign ?? options.style?.verticalAlign ?? "middle";
|
|
52
|
+
const effectiveStyle = {
|
|
53
|
+
...options.style,
|
|
54
|
+
align,
|
|
55
|
+
verticalAlign
|
|
56
|
+
};
|
|
57
|
+
const { paragraphs, style: resolvedStyle } = parseTextContent([{
|
|
58
|
+
type: "#text",
|
|
59
|
+
text: options.text
|
|
60
|
+
}], effectiveStyle, options.theme, { slideNumber: options.slideNumber }, options.labelPath);
|
|
61
|
+
const rawWidth = Math.max(1, options.box.width);
|
|
62
|
+
const rawHeight = Math.max(1, options.box.height);
|
|
63
|
+
let layoutBox;
|
|
64
|
+
if (options.rotationDegrees !== void 0) {
|
|
65
|
+
const cx = options.box.x + options.box.width / 2;
|
|
66
|
+
const cy = options.box.y + options.box.height / 2;
|
|
67
|
+
layoutBox = {
|
|
68
|
+
x: cx - rawHeight / 2,
|
|
69
|
+
y: cy - rawWidth / 2,
|
|
70
|
+
width: rawHeight,
|
|
71
|
+
height: rawWidth
|
|
72
|
+
};
|
|
73
|
+
} else layoutBox = {
|
|
74
|
+
x: options.box.x,
|
|
75
|
+
y: options.box.y,
|
|
76
|
+
width: rawWidth,
|
|
77
|
+
height: rawHeight
|
|
78
|
+
};
|
|
79
|
+
const singleLineMeasure = withPreviewFontBoundary(() => measureTextLayoutFromParagraphs(paragraphs, resolvedStyle));
|
|
80
|
+
const allowWrap = options.wrap ?? false;
|
|
81
|
+
let effectiveLayoutBox = layoutBox;
|
|
82
|
+
if (!allowWrap && singleLineMeasure.width > layoutBox.width) {
|
|
83
|
+
const neededWidth = singleLineMeasure.width + 1;
|
|
84
|
+
const delta = neededWidth - layoutBox.width;
|
|
85
|
+
const shiftedX = align === "right" ? layoutBox.x - delta : align === "center" ? layoutBox.x - delta / 2 : layoutBox.x;
|
|
86
|
+
effectiveLayoutBox = {
|
|
87
|
+
...layoutBox,
|
|
88
|
+
x: shiftedX,
|
|
89
|
+
width: neededWidth
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
const wrappedMeasure = allowWrap ? withPreviewFontBoundary(() => measureTextLayoutFromParagraphs(paragraphs, resolvedStyle, effectiveLayoutBox.width)) : singleLineMeasure;
|
|
93
|
+
const idPrefix = options.clipAllocator !== void 0 && resolvedStyle.textShadow !== void 0 ? options.clipAllocator.nextClipId() : `rp-chart-txt-${options.slideNumber}`;
|
|
94
|
+
let content = withPreviewFontBoundary(() => renderTextOutlinesSvg({
|
|
95
|
+
paragraphs,
|
|
96
|
+
box: effectiveLayoutBox,
|
|
97
|
+
verticalAlign,
|
|
98
|
+
theme: options.theme,
|
|
99
|
+
idPrefix,
|
|
100
|
+
rotate: options.rotationDegrees ?? 0
|
|
101
|
+
}));
|
|
102
|
+
if (content === "") return "";
|
|
103
|
+
if (options.rotationDegrees !== void 0) {
|
|
104
|
+
const cx = options.box.x + options.box.width / 2;
|
|
105
|
+
const cy = options.box.y + options.box.height / 2;
|
|
106
|
+
content = `<g transform="rotate(${options.rotationDegrees} ${cx} ${cy})">${content}</g>`;
|
|
107
|
+
}
|
|
108
|
+
const clipTarget = options.clipBox ?? options.box;
|
|
109
|
+
if ((options.rotationDegrees === void 0 ? wrappedMeasure.width > clipTarget.width + .5 || wrappedMeasure.height > clipTarget.height + .5 : wrappedMeasure.width > clipTarget.height + .5 || wrappedMeasure.height > clipTarget.width + .5) && options.clipAllocator !== void 0 && Number.isFinite(clipTarget.x) && Number.isFinite(clipTarget.y) && Number.isFinite(clipTarget.width) && Number.isFinite(clipTarget.height) && clipTarget.width > 1e-6 && clipTarget.height > 1e-6) {
|
|
110
|
+
const clipId = options.clipAllocator.nextClipId();
|
|
111
|
+
options.clipAllocator.defs.push(`<clipPath id="${clipId}" clipPathUnits="userSpaceOnUse"><rect x="${clipTarget.x}" y="${clipTarget.y}" width="${clipTarget.width}" height="${clipTarget.height}"/></clipPath>`);
|
|
112
|
+
return `<g clip-path="url(#${clipId})">${content}</g>`;
|
|
113
|
+
}
|
|
114
|
+
return content;
|
|
115
|
+
}
|
|
116
|
+
export { createChartClipAllocator, measureChartText, mergeChartTextStyle, renderChartTextSvg, resolveChartFontSizePixels };
|