@office-kit/pptx-preview 0.9.3 → 0.9.5
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/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as MONO, c as TIMES, d as substituteFamily, l as defaultMeasurer, n as renderSlideSvg, o as SANS, r as ARIAL, s as SERIF, t as auditTextLayout } from "./src-
|
|
1
|
+
import { a as MONO, c as TIMES, d as substituteFamily, l as defaultMeasurer, n as renderSlideSvg, o as SANS, r as ARIAL, s as SERIF, t as auditTextLayout } from "./src-BqJTKEQf.js";
|
|
2
2
|
export { ARIAL, MONO, SANS, SERIF, TIMES, auditTextLayout, defaultMeasurer, renderSlideSvg as renderSlideToSvg, substituteFamily };
|
package/dist/node.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as MONO, c as TIMES, d as substituteFamily, i as AVG_GLYPH_W_RATIO, l as defaultMeasurer, n as renderSlideSvg, o as SANS, r as ARIAL, s as SERIF, t as auditTextLayout, u as isCjk } from "./src-
|
|
1
|
+
import { a as MONO, c as TIMES, d as substituteFamily, i as AVG_GLYPH_W_RATIO, l as defaultMeasurer, n as renderSlideSvg, o as SANS, r as ARIAL, s as SERIF, t as auditTextLayout, u as isCjk } from "./src-BqJTKEQf.js";
|
|
2
2
|
import { getSlideSize } from "@office-kit/pptx";
|
|
3
3
|
import { Resvg } from "@resvg/resvg-js";
|
|
4
4
|
import * as fontkit from "fontkit";
|
|
@@ -3060,7 +3060,7 @@ const approxLegendTextPx = (text, fontPx) => {
|
|
|
3060
3060
|
for (const ch of text) units += FULLWIDTH_CHAR_PATTERN.test(ch) ? 1 : .55;
|
|
3061
3061
|
return units * fontPx;
|
|
3062
3062
|
};
|
|
3063
|
-
const renderChartLegend = (f, names, colors, position = "b", textStyle,
|
|
3063
|
+
const renderChartLegend = (f, names, colors, position = "b", textStyle, markers) => {
|
|
3064
3064
|
if (names.length === 0) return "";
|
|
3065
3065
|
const sz = textStyle?.sizePt ?? 11;
|
|
3066
3066
|
const fill = textStyle?.color ?? "#374151";
|
|
@@ -3069,10 +3069,10 @@ const renderChartLegend = (f, names, colors, position = "b", textStyle, markerSy
|
|
|
3069
3069
|
const textAttrs = `font-family="sans-serif" font-size="${chartFontPx(sz)}" fill="${fill}"${weight}${italic}`;
|
|
3070
3070
|
const swatch = (i, swatchX, swatchY) => {
|
|
3071
3071
|
const color = colors[i % colors.length];
|
|
3072
|
-
const
|
|
3073
|
-
if (
|
|
3072
|
+
const marker = markers?.[i];
|
|
3073
|
+
if (marker !== void 0 && marker.markerSymbol !== "none") {
|
|
3074
3074
|
const r = 4.5;
|
|
3075
|
-
return seriesMarker(autoMarkerSymbol(
|
|
3075
|
+
return seriesMarker(autoMarkerSymbol(marker.markerSymbol, i), swatchX + r, swatchY + r, r, ...markerColors(marker, color));
|
|
3076
3076
|
}
|
|
3077
3077
|
return `<rect x="${px(swatchX)}" y="${px(swatchY)}" width="9" height="9" fill="${color}"/>`;
|
|
3078
3078
|
};
|
|
@@ -3164,7 +3164,7 @@ const renderColumnChart = (f, spec, colors) => {
|
|
|
3164
3164
|
const top = f.plotY + f.plotH - (v - min) / range * f.plotH;
|
|
3165
3165
|
const y0 = Math.min(top, baseY);
|
|
3166
3166
|
const h = Math.abs(top - baseY);
|
|
3167
|
-
const baseColor = spec.varyColors && spec.series.length === 1 ? colors[c % colors.length] : spec.series[s]?.color ?? colors[s % colors.length];
|
|
3167
|
+
const baseColor = spec.series[s]?.pointColors?.[c] ?? (spec.varyColors && spec.series.length === 1 ? colors[c % colors.length] : spec.series[s]?.color ?? colors[s % colors.length]);
|
|
3168
3168
|
const fillColor = v < 0 && spec.series[s]?.invertIfNegative ? mixHex(baseColor, "#000000", .55) : baseColor;
|
|
3169
3169
|
out.push(`<rect x="${px(x0)}" y="${px(y0)}" width="${px(barW)}" height="${px(h)}" fill="${fillColor}"/>`);
|
|
3170
3170
|
if (showLabelFor(s)) {
|
|
@@ -3308,11 +3308,12 @@ const AUTO_MARKER_SYMBOLS = [
|
|
|
3308
3308
|
"dash"
|
|
3309
3309
|
];
|
|
3310
3310
|
const autoMarkerSymbol = (symbol, seriesIdx) => symbol !== void 0 && symbol !== "auto" ? symbol : AUTO_MARKER_SYMBOLS[seriesIdx % AUTO_MARKER_SYMBOLS.length];
|
|
3311
|
-
const seriesMarker = (symbol, cx, cy, r, color) => {
|
|
3311
|
+
const seriesMarker = (symbol, cx, cy, r, color, lineColor = color) => {
|
|
3312
|
+
const paint = lineColor === color ? `fill="${color}"` : `fill="${color}" stroke="${lineColor}" stroke-width="1"`;
|
|
3312
3313
|
switch (symbol) {
|
|
3313
|
-
case "square": return `<rect x="${px(cx - r)}" y="${px(cy - r)}" width="${px(r * 2)}" height="${px(r * 2)}"
|
|
3314
|
-
case "diamond": return `<polygon points="${px(cx)},${px(cy - r)} ${px(cx + r)},${px(cy)} ${px(cx)},${px(cy + r)} ${px(cx - r)},${px(cy)}"
|
|
3315
|
-
case "triangle": return `<polygon points="${px(cx)},${px(cy - r)} ${px(cx + r)},${px(cy + r)} ${px(cx - r)},${px(cy + r)}"
|
|
3314
|
+
case "square": return `<rect x="${px(cx - r)}" y="${px(cy - r)}" width="${px(r * 2)}" height="${px(r * 2)}" ${paint}/>`;
|
|
3315
|
+
case "diamond": return `<polygon points="${px(cx)},${px(cy - r)} ${px(cx + r)},${px(cy)} ${px(cx)},${px(cy + r)} ${px(cx - r)},${px(cy)}" ${paint}/>`;
|
|
3316
|
+
case "triangle": return `<polygon points="${px(cx)},${px(cy - r)} ${px(cx + r)},${px(cy + r)} ${px(cx - r)},${px(cy + r)}" ${paint}/>`;
|
|
3316
3317
|
case "star": return `<polygon points="${(() => {
|
|
3317
3318
|
const pts = [];
|
|
3318
3319
|
for (let i = 0; i < 10; i++) {
|
|
@@ -3321,14 +3322,18 @@ const seriesMarker = (symbol, cx, cy, r, color) => {
|
|
|
3321
3322
|
pts.push(`${px(cx + rr * Math.cos(ang))},${px(cy + rr * Math.sin(ang))}`);
|
|
3322
3323
|
}
|
|
3323
3324
|
return pts.join(" ");
|
|
3324
|
-
})()}"
|
|
3325
|
-
case "x": return `<g stroke="${
|
|
3326
|
-
case "plus": return `<g stroke="${
|
|
3327
|
-
case "dash": return `<line x1="${px(cx - r)}" y1="${px(cy)}" x2="${px(cx + r)}" y2="${px(cy)}" stroke="${
|
|
3328
|
-
case "dot": return `<circle cx="${px(cx)}" cy="${px(cy)}" r="${(r * .6).toFixed(2)}"
|
|
3329
|
-
default: return `<circle cx="${px(cx)}" cy="${px(cy)}" r="${px(r)}"
|
|
3325
|
+
})()}" ${paint}/>`;
|
|
3326
|
+
case "x": return `<g stroke="${lineColor}" stroke-width="1.2" stroke-linecap="round"><line x1="${px(cx - r)}" y1="${px(cy - r)}" x2="${px(cx + r)}" y2="${px(cy + r)}"/><line x1="${px(cx - r)}" y1="${px(cy + r)}" x2="${px(cx + r)}" y2="${px(cy - r)}"/></g>`;
|
|
3327
|
+
case "plus": return `<g stroke="${lineColor}" stroke-width="1.2" stroke-linecap="round"><line x1="${px(cx - r)}" y1="${px(cy)}" x2="${px(cx + r)}" y2="${px(cy)}"/><line x1="${px(cx)}" y1="${px(cy - r)}" x2="${px(cx)}" y2="${px(cy + r)}"/></g>`;
|
|
3328
|
+
case "dash": return `<line x1="${px(cx - r)}" y1="${px(cy)}" x2="${px(cx + r)}" y2="${px(cy)}" stroke="${lineColor}" stroke-width="${Math.max(1.5, r * .6).toFixed(2)}" stroke-linecap="round"/>`;
|
|
3329
|
+
case "dot": return `<circle cx="${px(cx)}" cy="${px(cy)}" r="${(r * .6).toFixed(2)}" ${paint}/>`;
|
|
3330
|
+
default: return `<circle cx="${px(cx)}" cy="${px(cy)}" r="${px(r)}" ${paint}/>`;
|
|
3330
3331
|
}
|
|
3331
3332
|
};
|
|
3333
|
+
const markerColors = (series, seriesColor) => {
|
|
3334
|
+
const fill = series.markerColor ?? seriesColor;
|
|
3335
|
+
return [fill, series.markerLineColor ?? fill];
|
|
3336
|
+
};
|
|
3332
3337
|
const formatChartValue = (v) => {
|
|
3333
3338
|
if (!Number.isFinite(v)) return "";
|
|
3334
3339
|
if (Number.isInteger(v)) return String(v);
|
|
@@ -3402,7 +3407,7 @@ const renderBarChart = (f, spec, colors) => {
|
|
|
3402
3407
|
const tip = f.plotX + (v - min) / range * f.plotW;
|
|
3403
3408
|
const x0 = Math.min(tip, baseX);
|
|
3404
3409
|
const w = Math.abs(tip - baseX);
|
|
3405
|
-
const baseColor = spec.varyColors && spec.series.length === 1 ? colors[c % colors.length] : spec.series[s]?.color ?? colors[s % colors.length];
|
|
3410
|
+
const baseColor = spec.series[s]?.pointColors?.[c] ?? (spec.varyColors && spec.series.length === 1 ? colors[c % colors.length] : spec.series[s]?.color ?? colors[s % colors.length]);
|
|
3406
3411
|
const fillColor = v < 0 && spec.series[s]?.invertIfNegative ? mixHex(baseColor, "#000000", .55) : baseColor;
|
|
3407
3412
|
out.push(`<rect x="${px(x0)}" y="${px(y0)}" width="${px(w)}" height="${px(barH)}" fill="${fillColor}"/>`);
|
|
3408
3413
|
if (showLabelForBar(s)) {
|
|
@@ -3518,14 +3523,14 @@ const renderLineChart = (f, spec, colors, fill) => {
|
|
|
3518
3523
|
if (!pat) return "";
|
|
3519
3524
|
return ` stroke-dasharray="${pat.split(" ").map((n) => (Number.parseFloat(n) * sw).toFixed(2)).join(" ")}"`;
|
|
3520
3525
|
})() : "";
|
|
3521
|
-
out.push(`<path d="${dPath}" fill="none" stroke="${color}" stroke-width="${lineWPx.toFixed(2)}" stroke-linejoin="round" stroke-linecap="round"${dashAttr}/>`);
|
|
3526
|
+
out.push(`<path d="${dPath}" fill="none" stroke="${series.lineColor ?? color}" stroke-width="${lineWPx.toFixed(2)}" stroke-linejoin="round" stroke-linecap="round"${dashAttr}/>`);
|
|
3522
3527
|
if (!isStacked) {
|
|
3523
3528
|
const explicitSymbol = series.markerSymbol !== void 0 && series.markerSymbol !== "auto" && series.markerSymbol !== "none";
|
|
3524
3529
|
if (series.markerSymbol !== "none" && !fill && (spec.lineMarkers === true || explicitSymbol)) {
|
|
3525
3530
|
const symbol = autoMarkerSymbol(series.markerSymbol, s);
|
|
3526
3531
|
const size = series.markerSizePt ?? 5;
|
|
3527
3532
|
const r = Math.max(1, size * .5);
|
|
3528
|
-
for (const [xp, yp] of pts) out.push(seriesMarker(symbol, xp, yp, r, color));
|
|
3533
|
+
for (const [xp, yp] of pts) out.push(seriesMarker(symbol, xp, yp, r, ...markerColors(series, color)));
|
|
3529
3534
|
}
|
|
3530
3535
|
}
|
|
3531
3536
|
if (series.dataLabels?.showValue ?? spec.dataLabels?.showValue ?? false) {
|
|
@@ -3760,13 +3765,14 @@ const renderScatterChart = (f, spec, colors) => {
|
|
|
3760
3765
|
if (showLine && proj.length >= 2) {
|
|
3761
3766
|
const d = smooth && proj.length > 2 ? smoothPath(proj) : proj.map(([xp, yp], i) => `${i === 0 ? "M" : "L"}${px(xp)},${px(yp)}`).join(" ");
|
|
3762
3767
|
const lineWPx = series.lineWidthEmu ? Math.max(.3, series.lineWidthEmu / EMU_PER_PX) : 1.5;
|
|
3763
|
-
out.push(`<path d="${d}" fill="none" stroke="${color}" stroke-width="${lineWPx.toFixed(2)}" stroke-linejoin="round" stroke-linecap="round"/>`);
|
|
3768
|
+
out.push(`<path d="${d}" fill="none" stroke="${series.lineColor ?? color}" stroke-width="${lineWPx.toFixed(2)}" stroke-linejoin="round" stroke-linecap="round"/>`);
|
|
3764
3769
|
}
|
|
3765
3770
|
const sym = series.markerSymbol;
|
|
3766
3771
|
if (sym === "none" ? false : showMarker || sym !== void 0 && sym !== "auto") {
|
|
3767
3772
|
const r = Math.max(1.5, (series.markerSizePt ?? 5) * .5);
|
|
3768
3773
|
const glyph = autoMarkerSymbol(sym, s);
|
|
3769
|
-
|
|
3774
|
+
const [markerFill, markerLine] = markerColors(series, color);
|
|
3775
|
+
for (const [xp, yp] of proj) out.push(seriesMarker(glyph, xp, yp, r, markerFill, markerLine));
|
|
3770
3776
|
}
|
|
3771
3777
|
}
|
|
3772
3778
|
return out.join("");
|
|
@@ -3867,11 +3873,12 @@ const renderRadarChart = (f, spec, colors) => {
|
|
|
3867
3873
|
if (proj.length < 2) continue;
|
|
3868
3874
|
const ptsStr = proj.map(([xp, yp]) => `${px(xp)},${px(yp)}`).join(" ");
|
|
3869
3875
|
const lineWPx = series.lineWidthEmu ? Math.max(.3, series.lineWidthEmu / EMU_PER_PX) : 1.8;
|
|
3870
|
-
out.push(filled ? `<polygon points="${ptsStr}" fill="${color}" fill-opacity="0.3" stroke="${color}" stroke-width="${lineWPx.toFixed(2)}" stroke-linejoin="round"/>` : `<polygon points="${ptsStr}" fill="none" stroke="${color}" stroke-width="${lineWPx.toFixed(2)}" stroke-linejoin="round"/>`);
|
|
3876
|
+
out.push(filled ? `<polygon points="${ptsStr}" fill="${color}" fill-opacity="0.3" stroke="${series.lineColor ?? color}" stroke-width="${lineWPx.toFixed(2)}" stroke-linejoin="round"/>` : `<polygon points="${ptsStr}" fill="none" stroke="${series.lineColor ?? color}" stroke-width="${lineWPx.toFixed(2)}" stroke-linejoin="round"/>`);
|
|
3871
3877
|
if (showMarker) {
|
|
3872
3878
|
const r = Math.max(1.5, (series.markerSizePt ?? 5) * .5);
|
|
3873
3879
|
const glyph = autoMarkerSymbol(series.markerSymbol, s);
|
|
3874
|
-
|
|
3880
|
+
const [markerFill, markerLine] = markerColors(series, color);
|
|
3881
|
+
for (const [xp, yp] of proj) out.push(seriesMarker(glyph, xp, yp, r, markerFill, markerLine));
|
|
3875
3882
|
}
|
|
3876
3883
|
}
|
|
3877
3884
|
return out.join("");
|
|
@@ -3895,7 +3902,7 @@ const renderChart = (shape, x, y, w, h, transform, theme) => {
|
|
|
3895
3902
|
const seriesNamesForLegend = allNamesForLegend.filter((_, i) => !hiddenSet.has(i));
|
|
3896
3903
|
const seriesColorsForLegend = allColorsForLegend.filter((_, i) => !hiddenSet.has(i));
|
|
3897
3904
|
const explicitMarker = (sym) => sym !== void 0 && sym !== "auto" && sym !== "none";
|
|
3898
|
-
const
|
|
3905
|
+
const markersForLegend = spec.kind === "line" && (spec.lineMarkers === true || spec.series.some((s) => explicitMarker(s.markerSymbol))) ? spec.series.filter((_, i) => !hiddenSet.has(i)) : void 0;
|
|
3899
3906
|
let finiteCount = 0;
|
|
3900
3907
|
for (const s of spec.series) for (const v of s.values) if (v !== null && Number.isFinite(v)) finiteCount++;
|
|
3901
3908
|
let plot = "";
|
|
@@ -4052,7 +4059,7 @@ const renderChart = (shape, x, y, w, h, transform, theme) => {
|
|
|
4052
4059
|
categoryAxisTitleSvg,
|
|
4053
4060
|
plot,
|
|
4054
4061
|
emptyHint,
|
|
4055
|
-
hasLegend ? renderChartLegend(f, seriesNamesForLegend, seriesColorsForLegend, spec.legend?.position ?? "b", spec.legend?.textStyle,
|
|
4062
|
+
hasLegend ? renderChartLegend(f, seriesNamesForLegend, seriesColorsForLegend, spec.legend?.position ?? "b", spec.legend?.textStyle, markersForLegend) : "",
|
|
4056
4063
|
"</g>"
|
|
4057
4064
|
].join("");
|
|
4058
4065
|
};
|
|
@@ -4944,4 +4951,4 @@ const auditTextLayout = (pres, options = {}) => {
|
|
|
4944
4951
|
//#endregion
|
|
4945
4952
|
export { MONO as a, TIMES as c, substituteFamily as d, AVG_GLYPH_W_RATIO as i, defaultMeasurer as l, renderSlideSvg as n, SANS as o, ARIAL as r, SERIF as s, auditTextLayout as t, isCjk as u };
|
|
4946
4953
|
|
|
4947
|
-
//# sourceMappingURL=src-
|
|
4954
|
+
//# sourceMappingURL=src-BqJTKEQf.js.map
|