@office-kit/pptx-preview 0.9.6 → 0.9.8
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-B73Pj0gv.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-B73Pj0gv.js";
|
|
2
2
|
import { getSlideSize } from "@office-kit/pptx";
|
|
3
3
|
import { Resvg } from "@resvg/resvg-js";
|
|
4
4
|
import * as fontkit from "fontkit";
|
|
@@ -2298,7 +2298,7 @@ const buildBullet = (a, para, pi) => {
|
|
|
2298
2298
|
const char = para.bulletIsPicture ? "■" : numberLabel ?? explicitChar ?? bulletChar(para.level);
|
|
2299
2299
|
const baseSizePx = (para.runs.find((r) => r.text !== "\n" && r.text !== "")?.sizePt ?? a.defaultPt) * PX_PER_PT * a.autoFitScale;
|
|
2300
2300
|
const sizePx = para.bulletDetail.sizePct !== null ? baseSizePx * para.bulletDetail.sizePct : para.bulletDetail.sizePts !== null ? para.bulletDetail.sizePts * PX_PER_PT * a.autoFitScale : baseSizePx;
|
|
2301
|
-
const fillHex =
|
|
2301
|
+
const fillHex = bulletFillOf(para, a.theme, a.defaultColor);
|
|
2302
2302
|
return {
|
|
2303
2303
|
text: char,
|
|
2304
2304
|
family: (a.resolveFamily ?? substituteFamily)(para.bulletDetail.font ?? DEFAULT_BULLET_FONT),
|
|
@@ -2307,6 +2307,11 @@ const buildBullet = (a, para, pi) => {
|
|
|
2307
2307
|
...para.bulletImageHref ? { imageHref: para.bulletImageHref } : {}
|
|
2308
2308
|
};
|
|
2309
2309
|
};
|
|
2310
|
+
const bulletFillOf = (para, theme, defaultColor) => {
|
|
2311
|
+
if (para.bulletDetail.color) return resolveColor(para.bulletDetail.color, theme, "#000000");
|
|
2312
|
+
const runColor = para.runs.find((r) => r.text !== "\n" && r.text !== "")?.fmt?.color;
|
|
2313
|
+
return runColor === void 0 || runColor === null ? defaultColor : resolveColor(runColor, theme, defaultColor);
|
|
2314
|
+
};
|
|
2310
2315
|
const presetTextRect = (preset) => {
|
|
2311
2316
|
switch (preset) {
|
|
2312
2317
|
case "triangle": return {
|
|
@@ -2539,24 +2544,22 @@ const resolveTextBodyModel = (pres, shape, bounds, theme, phType, measure, defau
|
|
|
2539
2544
|
LINE_HEIGHT * lineHeightScale;
|
|
2540
2545
|
const numberLabels = Array.from({ length: paraData.length }, () => null);
|
|
2541
2546
|
{
|
|
2542
|
-
|
|
2543
|
-
|
|
2544
|
-
let activeType = null;
|
|
2547
|
+
const counters = [];
|
|
2548
|
+
const types = [];
|
|
2545
2549
|
for (let i = 0; i < paraData.length; i++) {
|
|
2546
2550
|
const para = paraData[i];
|
|
2547
2551
|
const num = bulletAutoNumType(para.bulletStyle);
|
|
2548
|
-
|
|
2549
|
-
|
|
2550
|
-
|
|
2551
|
-
|
|
2552
|
-
continue;
|
|
2552
|
+
const level = Math.max(0, para.level);
|
|
2553
|
+
for (let l = num === null ? level : level + 1; l < counters.length; l++) {
|
|
2554
|
+
counters[l] = 0;
|
|
2555
|
+
types[l] = null;
|
|
2553
2556
|
}
|
|
2554
|
-
if (
|
|
2555
|
-
|
|
2556
|
-
|
|
2557
|
-
|
|
2558
|
-
} else
|
|
2559
|
-
numberLabels[i] = formatAutoNum(num,
|
|
2557
|
+
if (num === null) continue;
|
|
2558
|
+
if (types[level] !== num) {
|
|
2559
|
+
counters[level] = 1;
|
|
2560
|
+
types[level] = num;
|
|
2561
|
+
} else counters[level] = (counters[level] ?? 0) + 1;
|
|
2562
|
+
numberLabels[i] = formatAutoNum(num, counters[level]);
|
|
2560
2563
|
}
|
|
2561
2564
|
}
|
|
2562
2565
|
if (authoredAutofit && autoFitScale === 1) {
|
|
@@ -2620,6 +2623,7 @@ const renderTextBody = (pres, shape, bounds, theme, phType, ctx) => {
|
|
|
2620
2623
|
const model = resolveTextBodyModel(pres, shape, bounds, theme, phType, ctx.measure, activeDeckTextColor);
|
|
2621
2624
|
if (model === null) return "";
|
|
2622
2625
|
const { paraData, numberLabels, authoredAutofit, autoFitScale, defaultPt, themeFace, effectiveDefaultFont, effectiveBody, anchor, innerX, innerY, innerW, innerH, svgTextRect } = model;
|
|
2626
|
+
const defaultColor = activeDeckTextColor;
|
|
2623
2627
|
const paragraphs = [];
|
|
2624
2628
|
for (let pi = 0; pi < paraData.length; pi++) {
|
|
2625
2629
|
const para = paraData[pi];
|
|
@@ -2675,7 +2679,7 @@ const renderTextBody = (pres, shape, bounds, theme, phType, ctx) => {
|
|
|
2675
2679
|
} else if (showBullet) {
|
|
2676
2680
|
const char = para.bulletIsPicture ? "■" : numberLabel ?? explicitChar ?? bulletChar(para.level);
|
|
2677
2681
|
const bulletStyles = [`margin-right:${(.4 * defaultPt * PX_PER_PT * autoFitScale).toFixed(2)}px`];
|
|
2678
|
-
|
|
2682
|
+
bulletStyles.push(`color:${bulletFillOf(para, theme, defaultColor)}`);
|
|
2679
2683
|
if (para.bulletDetail.sizePct !== null) bulletStyles.push(`font-size:${(para.bulletDetail.sizePct * 100).toFixed(1)}%`);
|
|
2680
2684
|
else if (para.bulletDetail.sizePts !== null) bulletStyles.push(`font-size:${(para.bulletDetail.sizePts * PX_PER_PT * autoFitScale).toFixed(2)}px`);
|
|
2681
2685
|
else bulletStyles.push(`font-size:${baseBulletPx.toFixed(2)}px`);
|
|
@@ -2685,7 +2689,6 @@ const renderTextBody = (pres, shape, bounds, theme, phType, ctx) => {
|
|
|
2685
2689
|
paragraphs.push(`<p style="${pStyles.join(";")}">${prefix}${runHtmls.join("") || "​"}</p>`);
|
|
2686
2690
|
}
|
|
2687
2691
|
const justify = ANCHOR_TO_CSS[anchor] ?? "flex-start";
|
|
2688
|
-
const defaultColor = activeDeckTextColor;
|
|
2689
2692
|
if (ctx.mode === "svg") {
|
|
2690
2693
|
const svgLineScale = 1 - (authoredAutofit?.lnSpcReduction ?? 0);
|
|
2691
2694
|
const svgVert = verticalLayoutOf(effectiveBody.vert ?? getShapeTextDirection(shape));
|
|
@@ -4407,12 +4410,21 @@ const renderShape = (shape, pres, theme, ctx) => {
|
|
|
4407
4410
|
const transform = transforms.length > 0 ? ` transform="${transforms.join(" ")}"` : "";
|
|
4408
4411
|
const textRotation = (flip.vertical ? rotation + 180 : rotation) % 360;
|
|
4409
4412
|
const textTransform = textRotation !== 0 ? ` transform="rotate(${textRotation} ${E(cx)} ${E(cy)})"` : "";
|
|
4410
|
-
const
|
|
4413
|
+
const { sx: gsx, sy: gsy } = ctx.groupScale;
|
|
4414
|
+
const groupScaled = gsx !== 1 || gsy !== 1;
|
|
4415
|
+
const textBounds = groupScaled ? {
|
|
4416
|
+
x: x * gsx,
|
|
4417
|
+
y: y * gsy,
|
|
4418
|
+
w: w * gsx,
|
|
4419
|
+
h: h * gsy
|
|
4420
|
+
} : {
|
|
4411
4421
|
x,
|
|
4412
4422
|
y,
|
|
4413
4423
|
w,
|
|
4414
4424
|
h
|
|
4415
|
-
}
|
|
4425
|
+
};
|
|
4426
|
+
const rawTextOverlay = kind === "shape" || kind === "graphicFrame" ? renderTextBody(pres, shape, textBounds, theme, phType, ctx) : "";
|
|
4427
|
+
const textOverlay = rawTextOverlay !== "" && groupScaled ? `<g transform="scale(${(1 / gsx).toFixed(6)} ${(1 / gsy).toFixed(6)})">${rawTextOverlay}</g>` : rawTextOverlay;
|
|
4416
4428
|
if (kind === "picture") return renderPicture(shape, pres, x, y, w, h, transform, textOverlay, getShapeImageBytes(shape), getShapeImageFormat(shape));
|
|
4417
4429
|
if (kind === "shape" && fill.kind === "image") return renderPicture(shape, pres, x, y, w, h, transform, textOverlay, getShapeImageFillBytes(shape), getShapeImageFormat(shape));
|
|
4418
4430
|
if (kind === "connector") {
|
|
@@ -4469,6 +4481,8 @@ const renderShape = (shape, pres, theme, ctx) => {
|
|
|
4469
4481
|
const children = getGroupChildren(shape);
|
|
4470
4482
|
if (children.length === 0) return "";
|
|
4471
4483
|
const tParts = [];
|
|
4484
|
+
let groupScaleX = 1;
|
|
4485
|
+
let groupScaleY = 1;
|
|
4472
4486
|
if (xform && rotation !== 0) {
|
|
4473
4487
|
const cxG = (xform.outer.x + xform.outer.w / 2) / EMU_PER_PX;
|
|
4474
4488
|
const cyG = (xform.outer.y + xform.outer.h / 2) / EMU_PER_PX;
|
|
@@ -4491,13 +4505,23 @@ const renderShape = (shape, pres, theme, ctx) => {
|
|
|
4491
4505
|
const iy = xform.inner.y;
|
|
4492
4506
|
const iw = xform.inner.w || 1;
|
|
4493
4507
|
const ih = xform.inner.h || 1;
|
|
4494
|
-
|
|
4495
|
-
|
|
4508
|
+
groupScaleX = ow / iw;
|
|
4509
|
+
groupScaleY = oh / ih;
|
|
4510
|
+
const sx = groupScaleX.toFixed(6);
|
|
4511
|
+
const sy = groupScaleY.toFixed(6);
|
|
4496
4512
|
const tx = ((ox - ix * (ow / iw)) / EMU_PER_PX).toFixed(2);
|
|
4497
4513
|
const ty = ((oy - iy * (oh / ih)) / EMU_PER_PX).toFixed(2);
|
|
4498
4514
|
tParts.push(`translate(${tx} ${ty})`, `scale(${sx} ${sy})`);
|
|
4499
4515
|
}
|
|
4500
|
-
|
|
4516
|
+
const groupTransform = tParts.length > 0 ? ` transform="${tParts.join(" ")}"` : "";
|
|
4517
|
+
const childCtx = groupScaleX === 1 && groupScaleY === 1 ? ctx : {
|
|
4518
|
+
...ctx,
|
|
4519
|
+
groupScale: {
|
|
4520
|
+
sx: ctx.groupScale.sx * groupScaleX,
|
|
4521
|
+
sy: ctx.groupScale.sy * groupScaleY
|
|
4522
|
+
}
|
|
4523
|
+
};
|
|
4524
|
+
return `<g${groupTransform}>${children.map((c) => renderShape(c, pres, theme, childCtx)).join("")}</g>`;
|
|
4501
4525
|
}
|
|
4502
4526
|
const p = paint(shape, fill, stroke, theme, phType !== null, pres);
|
|
4503
4527
|
if (kind === "graphicFrame") {
|
|
@@ -4716,6 +4740,10 @@ const renderSlideSvg = (pres, slide, opts = {}) => {
|
|
|
4716
4740
|
activeColorMap = getEffectiveColorMap(slide);
|
|
4717
4741
|
activeDeckTextColor = resolveDeckBodyTextColor(slide) ?? "#000000";
|
|
4718
4742
|
const ctx = {
|
|
4743
|
+
groupScale: {
|
|
4744
|
+
sx: 1,
|
|
4745
|
+
sy: 1
|
|
4746
|
+
},
|
|
4719
4747
|
mode: opts.textLayout ?? "foreignObject",
|
|
4720
4748
|
measure: opts.measureText ?? defaultMeasurer
|
|
4721
4749
|
};
|
|
@@ -4963,4 +4991,4 @@ const auditTextLayout = (pres, options = {}) => {
|
|
|
4963
4991
|
//#endregion
|
|
4964
4992
|
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 };
|
|
4965
4993
|
|
|
4966
|
-
//# sourceMappingURL=src-
|
|
4994
|
+
//# sourceMappingURL=src-B73Pj0gv.js.map
|