@office-kit/pptx-preview 0.9.3 → 0.9.4

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-B2rbAoIa.js";
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-DI8o3Vmu.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-B2rbAoIa.js";
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-DI8o3Vmu.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, markerSymbols) => {
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 sym = markerSymbols?.[i];
3073
- if (markerSymbols !== void 0 && sym !== "none") {
3072
+ const marker = markers?.[i];
3073
+ if (marker !== void 0 && marker.markerSymbol !== "none") {
3074
3074
  const r = 4.5;
3075
- return seriesMarker(autoMarkerSymbol(sym, i), swatchX + r, swatchY + r, r, color);
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
  };
@@ -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)}" fill="${color}"/>`;
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)}" fill="${color}"/>`;
3315
- case "triangle": return `<polygon points="${px(cx)},${px(cy - r)} ${px(cx + r)},${px(cy + r)} ${px(cx - r)},${px(cy + r)}" fill="${color}"/>`;
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
- })()}" fill="${color}"/>`;
3325
- case "x": return `<g stroke="${color}" 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>`;
3326
- case "plus": return `<g stroke="${color}" 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>`;
3327
- case "dash": return `<line x1="${px(cx - r)}" y1="${px(cy)}" x2="${px(cx + r)}" y2="${px(cy)}" stroke="${color}" stroke-width="${Math.max(1.5, r * .6).toFixed(2)}" stroke-linecap="round"/>`;
3328
- case "dot": return `<circle cx="${px(cx)}" cy="${px(cy)}" r="${(r * .6).toFixed(2)}" fill="${color}"/>`;
3329
- default: return `<circle cx="${px(cx)}" cy="${px(cy)}" r="${px(r)}" fill="${color}"/>`;
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);
@@ -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
- for (const [xp, yp] of proj) out.push(seriesMarker(glyph, xp, yp, r, color));
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
- for (const [xp, yp] of proj) out.push(seriesMarker(glyph, xp, yp, r, color));
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 markerSymbolsForLegend = spec.kind === "line" && (spec.lineMarkers === true || spec.series.some((s) => explicitMarker(s.markerSymbol))) ? spec.series.map((s) => s.markerSymbol).filter((_, i) => !hiddenSet.has(i)) : void 0;
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, markerSymbolsForLegend) : "",
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-B2rbAoIa.js.map
4954
+ //# sourceMappingURL=src-DI8o3Vmu.js.map