@office-kit/pptx-preview 0.8.0 → 0.9.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/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-DPHsJGe1.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-DPHsJGe1.js";
|
|
2
2
|
import { getSlideSize } from "@office-kit/pptx";
|
|
3
3
|
import { Resvg } from "@resvg/resvg-js";
|
|
4
4
|
import * as fontkit from "fontkit";
|
|
@@ -16,11 +16,11 @@ const substituteFamily = (family) => {
|
|
|
16
16
|
return SANS;
|
|
17
17
|
};
|
|
18
18
|
const isCjk = (cp) => cp >= 12352 && cp <= 12447 || cp >= 12448 && cp <= 12543 || cp >= 19968 && cp <= 40959 || cp >= 44032 && cp <= 55215;
|
|
19
|
-
const AVG_GLYPH_W_RATIO
|
|
19
|
+
const AVG_GLYPH_W_RATIO = .55;
|
|
20
20
|
const defaultMeasurer = (text, spec) => {
|
|
21
21
|
let w = 0;
|
|
22
22
|
for (const ch of text) {
|
|
23
|
-
const ratio = isCjk(ch.codePointAt(0) ?? 0) ? 1 : AVG_GLYPH_W_RATIO
|
|
23
|
+
const ratio = isCjk(ch.codePointAt(0) ?? 0) ? 1 : AVG_GLYPH_W_RATIO;
|
|
24
24
|
w += spec.sizePx * ratio;
|
|
25
25
|
}
|
|
26
26
|
const n = [...text].length;
|
|
@@ -1876,7 +1876,6 @@ const renderRun = (text, format, theme, effectivePt, _wasDefault = false) => {
|
|
|
1876
1876
|
return `<span style="${styles.join(";")}">${content}</span>`;
|
|
1877
1877
|
};
|
|
1878
1878
|
const LINE_HEIGHT = 1.05;
|
|
1879
|
-
const AVG_GLYPH_W_RATIO = .55;
|
|
1880
1879
|
const AUTOFIT_FLOOR = .25;
|
|
1881
1880
|
const AUTOFIT_STEP = .05;
|
|
1882
1881
|
const underlineStyleOf = (fmt) => {
|
|
@@ -2254,33 +2253,7 @@ const resolveTextBodyModel = (pres, shape, bounds, theme, phType, measure, defau
|
|
|
2254
2253
|
if (!hasAnyText) return null;
|
|
2255
2254
|
const authoredAutofit = getShapeTextAutoFitParams(shape);
|
|
2256
2255
|
let autoFitScale = authoredAutofit?.fontScale ?? 1;
|
|
2257
|
-
|
|
2258
|
-
if (!authoredAutofit) {
|
|
2259
|
-
const innerWPx = innerW / EMU_PER_PX;
|
|
2260
|
-
const innerHPx = innerH / EMU_PER_PX;
|
|
2261
|
-
let totalH = 0;
|
|
2262
|
-
for (const para of paraData) {
|
|
2263
|
-
let maxSize = defaultPt;
|
|
2264
|
-
let totalChars = 0;
|
|
2265
|
-
let cjkChars = 0;
|
|
2266
|
-
for (const run of para.runs) {
|
|
2267
|
-
if (run.sizePt > maxSize) maxSize = run.sizePt;
|
|
2268
|
-
totalChars += run.text.length;
|
|
2269
|
-
for (let i = 0; i < run.text.length; i++) {
|
|
2270
|
-
const c = run.text.charCodeAt(i);
|
|
2271
|
-
if (c >= 12352 && c <= 12447 || c >= 12448 && c <= 12543 || c >= 19968 && c <= 40959 || c >= 44032 && c <= 55215) cjkChars++;
|
|
2272
|
-
}
|
|
2273
|
-
}
|
|
2274
|
-
if (totalChars === 0) totalChars = 1;
|
|
2275
|
-
const cjkRatio = cjkChars / totalChars;
|
|
2276
|
-
const glyphRatio = cjkRatio * 1 + (1 - cjkRatio) * AVG_GLYPH_W_RATIO;
|
|
2277
|
-
const sizePx = maxSize * PX_PER_PT;
|
|
2278
|
-
const charsPerLine = Math.max(1, Math.floor(innerWPx / Math.max(1, sizePx * glyphRatio)));
|
|
2279
|
-
const lineCount = Math.max(1, Math.ceil(totalChars / charsPerLine));
|
|
2280
|
-
totalH += sizePx * LINE_HEIGHT * lineCount;
|
|
2281
|
-
}
|
|
2282
|
-
if (totalH > innerHPx) autoFitScale = Math.max(.4, innerHPx / totalH);
|
|
2283
|
-
}
|
|
2256
|
+
const lineHeightScale = 1 - (authoredAutofit?.lnSpcReduction ?? 0);
|
|
2284
2257
|
LINE_HEIGHT * lineHeightScale;
|
|
2285
2258
|
const numberLabels = Array.from({ length: paraData.length }, () => null);
|
|
2286
2259
|
{
|
|
@@ -2655,16 +2628,20 @@ const renderValueAxis = (f, axis) => {
|
|
|
2655
2628
|
const tickLen = AXIS_TICK_LEN;
|
|
2656
2629
|
for (const t of ticks) if (axis.orientation === "vertical") {
|
|
2657
2630
|
const yp = f.plotY + f.plotH - (t - axis.min) / range * f.plotH;
|
|
2631
|
+
const onRight = axis.side === "right";
|
|
2632
|
+
const edgeX = onRight ? f.plotX + f.plotW : f.plotX;
|
|
2658
2633
|
if (showGrid) out.push(`<line x1="${px(f.plotX)}" y1="${px(yp)}" x2="${px(f.plotX + f.plotW)}" y2="${px(yp)}" stroke="${gridStroke}" stroke-width="0.5"/>`);
|
|
2659
2634
|
if (tickMark !== "none") {
|
|
2660
|
-
const
|
|
2661
|
-
const
|
|
2635
|
+
const outward = onRight ? tickLen : -5;
|
|
2636
|
+
const inward = onRight ? -5 : tickLen;
|
|
2637
|
+
const tx1 = tickMark === "in" ? edgeX : edgeX + outward;
|
|
2638
|
+
const tx2 = tickMark === "out" ? edgeX : edgeX + inward;
|
|
2662
2639
|
out.push(`<line x1="${px(tx1)}" y1="${px(yp)}" x2="${px(tx2)}" y2="${px(yp)}" stroke="${axisColor}" stroke-width="1"/>`);
|
|
2663
2640
|
}
|
|
2664
|
-
const labelX =
|
|
2641
|
+
const labelX = onRight ? edgeX + 4 : edgeX - 4;
|
|
2665
2642
|
const rot = axis.labelRotationDeg ?? 0;
|
|
2666
2643
|
const transform = rot ? ` transform="rotate(${rot} ${px(labelX)} ${px(yp)})"` : "";
|
|
2667
|
-
out.push(`<text x="${px(labelX)}" y="${px(yp)}" text-anchor="end" dominant-baseline="middle" ${axisTickAttrs(axis.labelStyle)}${transform}>${escapeXml(fmtTick(t))}</text>`);
|
|
2644
|
+
out.push(`<text x="${px(labelX)}" y="${px(yp)}" text-anchor="${onRight ? "start" : "end"}" dominant-baseline="middle" ${axisTickAttrs(axis.labelStyle)}${transform}>${escapeXml(fmtTick(t))}</text>`);
|
|
2668
2645
|
} else {
|
|
2669
2646
|
const xp = f.plotX + (t - axis.min) / range * f.plotW;
|
|
2670
2647
|
if (showGrid) out.push(`<line x1="${px(xp)}" y1="${px(f.plotY)}" x2="${px(xp)}" y2="${px(f.plotY + f.plotH)}" stroke="${gridStroke}" stroke-width="0.5"/>`);
|
|
@@ -3641,7 +3618,72 @@ const renderChart = (shape, x, y, w, h, transform, theme) => {
|
|
|
3641
3618
|
for (const s of spec.series) for (const v of s.values) if (v !== null && Number.isFinite(v)) finiteCount++;
|
|
3642
3619
|
let plot = "";
|
|
3643
3620
|
let axes = "";
|
|
3644
|
-
|
|
3621
|
+
const isCombo = isCartesian && spec.kind !== "bar" && spec.series.some((s) => s.chartKind !== void 0 && s.chartKind !== spec.kind || s.secondaryAxis === true);
|
|
3622
|
+
if (isCombo) {
|
|
3623
|
+
const baked = spec.series.map((s, i) => ({
|
|
3624
|
+
...s,
|
|
3625
|
+
color: s.color ?? colors[i % colors.length] ?? "#888"
|
|
3626
|
+
}));
|
|
3627
|
+
const primarySeries = baked.filter((s) => s.secondaryAxis !== true);
|
|
3628
|
+
const secondarySeries = baked.filter((s) => s.secondaryAxis === true);
|
|
3629
|
+
const primaryScale = seriesMinMax({
|
|
3630
|
+
...spec,
|
|
3631
|
+
series: primarySeries
|
|
3632
|
+
});
|
|
3633
|
+
const { valueAxis: _primaryOnlyAxis, ...specWithoutAxis } = spec;
|
|
3634
|
+
const secondaryScale = secondarySeries.length > 0 ? seriesMinMax({
|
|
3635
|
+
...specWithoutAxis,
|
|
3636
|
+
series: secondarySeries
|
|
3637
|
+
}) : null;
|
|
3638
|
+
const N = pointCount(spec);
|
|
3639
|
+
if (!spec.valueAxisHidden) axes = renderValueAxis(f, {
|
|
3640
|
+
orientation: "vertical",
|
|
3641
|
+
min: primaryScale.min,
|
|
3642
|
+
max: primaryScale.max,
|
|
3643
|
+
majorUnit: spec.valueAxis?.majorUnit ?? primaryScale.step,
|
|
3644
|
+
...spec.valueAxis?.numberFormat !== void 0 ? { numberFormat: spec.valueAxis.numberFormat } : {},
|
|
3645
|
+
...spec.valueAxisMajorGridlines !== void 0 ? { majorGridlines: spec.valueAxisMajorGridlines } : {},
|
|
3646
|
+
...spec.valueAxisLabelStyle !== void 0 ? { labelStyle: spec.valueAxisLabelStyle } : {}
|
|
3647
|
+
});
|
|
3648
|
+
if (secondaryScale) axes += renderValueAxis(f, {
|
|
3649
|
+
orientation: "vertical",
|
|
3650
|
+
side: "right",
|
|
3651
|
+
min: secondaryScale.min,
|
|
3652
|
+
max: secondaryScale.max,
|
|
3653
|
+
majorUnit: secondaryScale.step,
|
|
3654
|
+
majorGridlines: false,
|
|
3655
|
+
...spec.valueAxisLabelStyle !== void 0 ? { labelStyle: spec.valueAxisLabelStyle } : {}
|
|
3656
|
+
});
|
|
3657
|
+
if (N > 0 && !(spec.categoryAxisHidden || spec.categoryAxisTickLabelPos === "none")) axes += renderCategoryAxis(f, "horizontal", spec.categories, N, spec.categoryAxisTickLabelSkip ?? 1, spec.categoryAxisLabelStyle, spec.categoryAxisLabelRotationDeg, spec.categoryAxisLabelAlign, spec.categoryAxisLineColor);
|
|
3658
|
+
const groups = /* @__PURE__ */ new Map();
|
|
3659
|
+
for (const s of baked) {
|
|
3660
|
+
const kind = s.chartKind ?? spec.kind;
|
|
3661
|
+
const secondary = s.secondaryAxis === true;
|
|
3662
|
+
const key = `${kind}|${secondary ? "1" : "0"}`;
|
|
3663
|
+
const group = groups.get(key);
|
|
3664
|
+
if (group) group.series.push(s);
|
|
3665
|
+
else groups.set(key, {
|
|
3666
|
+
kind,
|
|
3667
|
+
secondary,
|
|
3668
|
+
series: [s]
|
|
3669
|
+
});
|
|
3670
|
+
}
|
|
3671
|
+
const paintOrder = (g) => (g.secondary ? 2 : 0) + (g.kind === "line" || g.kind === "area" ? 1 : 0);
|
|
3672
|
+
for (const group of [...groups.values()].sort((a, b) => paintOrder(a) - paintOrder(b))) {
|
|
3673
|
+
const scale = group.secondary && secondaryScale ? secondaryScale : primaryScale;
|
|
3674
|
+
const groupSpec = {
|
|
3675
|
+
...spec,
|
|
3676
|
+
series: group.series,
|
|
3677
|
+
valueAxis: {
|
|
3678
|
+
min: scale.min,
|
|
3679
|
+
max: scale.max
|
|
3680
|
+
}
|
|
3681
|
+
};
|
|
3682
|
+
if (group.kind === "line" || group.kind === "area") plot += renderLineChart(f, groupSpec, colors, group.kind === "area");
|
|
3683
|
+
else plot += renderColumnChart(f, groupSpec, colors);
|
|
3684
|
+
}
|
|
3685
|
+
}
|
|
3686
|
+
if (!isCombo && isCartesian) {
|
|
3645
3687
|
const { min, max, step } = seriesMinMax(spec);
|
|
3646
3688
|
const N = pointCount(spec);
|
|
3647
3689
|
const majorUnit = spec.valueAxis?.majorUnit ?? step;
|
|
@@ -3675,7 +3717,7 @@ const renderChart = (shape, x, y, w, h, transform, theme) => {
|
|
|
3675
3717
|
const labelsHidden = spec.categoryAxisHidden || spec.categoryAxisTickLabelPos === "none";
|
|
3676
3718
|
if (N > 0 && !labelsHidden) axes += renderCategoryAxis(f, spec.kind === "bar" ? "vertical" : "horizontal", spec.categories, N, spec.categoryAxisTickLabelSkip ?? 1, spec.categoryAxisLabelStyle, spec.categoryAxisLabelRotationDeg, spec.categoryAxisLabelAlign, spec.categoryAxisLineColor);
|
|
3677
3719
|
}
|
|
3678
|
-
switch (spec.kind) {
|
|
3720
|
+
if (!isCombo) switch (spec.kind) {
|
|
3679
3721
|
case "column":
|
|
3680
3722
|
case "bar":
|
|
3681
3723
|
plot = spec.kind === "column" ? renderColumnChart(f, spec, colors) : renderBarChart(f, spec, colors);
|
|
@@ -4616,6 +4658,6 @@ const auditTextLayout = (pres, options = {}) => {
|
|
|
4616
4658
|
return issues;
|
|
4617
4659
|
};
|
|
4618
4660
|
//#endregion
|
|
4619
|
-
export { MONO as a, TIMES as c, substituteFamily as d, AVG_GLYPH_W_RATIO
|
|
4661
|
+
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 };
|
|
4620
4662
|
|
|
4621
|
-
//# sourceMappingURL=src-
|
|
4663
|
+
//# sourceMappingURL=src-DPHsJGe1.js.map
|