@office-kit/pptx-preview 0.9.7 → 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-BCN48I0D.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-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-BCN48I0D.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-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 = para.bulletDetail.color ? resolveColor(para.bulletDetail.color, a.theme, "#000000") : a.defaultColor;
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 {
@@ -2618,6 +2623,7 @@ const renderTextBody = (pres, shape, bounds, theme, phType, ctx) => {
2618
2623
  const model = resolveTextBodyModel(pres, shape, bounds, theme, phType, ctx.measure, activeDeckTextColor);
2619
2624
  if (model === null) return "";
2620
2625
  const { paraData, numberLabels, authoredAutofit, autoFitScale, defaultPt, themeFace, effectiveDefaultFont, effectiveBody, anchor, innerX, innerY, innerW, innerH, svgTextRect } = model;
2626
+ const defaultColor = activeDeckTextColor;
2621
2627
  const paragraphs = [];
2622
2628
  for (let pi = 0; pi < paraData.length; pi++) {
2623
2629
  const para = paraData[pi];
@@ -2673,7 +2679,7 @@ const renderTextBody = (pres, shape, bounds, theme, phType, ctx) => {
2673
2679
  } else if (showBullet) {
2674
2680
  const char = para.bulletIsPicture ? "■" : numberLabel ?? explicitChar ?? bulletChar(para.level);
2675
2681
  const bulletStyles = [`margin-right:${(.4 * defaultPt * PX_PER_PT * autoFitScale).toFixed(2)}px`];
2676
- if (para.bulletDetail.color) bulletStyles.push(`color:${resolveColor(para.bulletDetail.color, theme, "#000000")}`);
2682
+ bulletStyles.push(`color:${bulletFillOf(para, theme, defaultColor)}`);
2677
2683
  if (para.bulletDetail.sizePct !== null) bulletStyles.push(`font-size:${(para.bulletDetail.sizePct * 100).toFixed(1)}%`);
2678
2684
  else if (para.bulletDetail.sizePts !== null) bulletStyles.push(`font-size:${(para.bulletDetail.sizePts * PX_PER_PT * autoFitScale).toFixed(2)}px`);
2679
2685
  else bulletStyles.push(`font-size:${baseBulletPx.toFixed(2)}px`);
@@ -2683,7 +2689,6 @@ const renderTextBody = (pres, shape, bounds, theme, phType, ctx) => {
2683
2689
  paragraphs.push(`<p style="${pStyles.join(";")}">${prefix}${runHtmls.join("") || "&#8203;"}</p>`);
2684
2690
  }
2685
2691
  const justify = ANCHOR_TO_CSS[anchor] ?? "flex-start";
2686
- const defaultColor = activeDeckTextColor;
2687
2692
  if (ctx.mode === "svg") {
2688
2693
  const svgLineScale = 1 - (authoredAutofit?.lnSpcReduction ?? 0);
2689
2694
  const svgVert = verticalLayoutOf(effectiveBody.vert ?? getShapeTextDirection(shape));
@@ -4405,12 +4410,21 @@ const renderShape = (shape, pres, theme, ctx) => {
4405
4410
  const transform = transforms.length > 0 ? ` transform="${transforms.join(" ")}"` : "";
4406
4411
  const textRotation = (flip.vertical ? rotation + 180 : rotation) % 360;
4407
4412
  const textTransform = textRotation !== 0 ? ` transform="rotate(${textRotation} ${E(cx)} ${E(cy)})"` : "";
4408
- const textOverlay = kind === "shape" || kind === "graphicFrame" ? renderTextBody(pres, shape, {
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
+ } : {
4409
4421
  x,
4410
4422
  y,
4411
4423
  w,
4412
4424
  h
4413
- }, theme, phType, ctx) : "";
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;
4414
4428
  if (kind === "picture") return renderPicture(shape, pres, x, y, w, h, transform, textOverlay, getShapeImageBytes(shape), getShapeImageFormat(shape));
4415
4429
  if (kind === "shape" && fill.kind === "image") return renderPicture(shape, pres, x, y, w, h, transform, textOverlay, getShapeImageFillBytes(shape), getShapeImageFormat(shape));
4416
4430
  if (kind === "connector") {
@@ -4467,6 +4481,8 @@ const renderShape = (shape, pres, theme, ctx) => {
4467
4481
  const children = getGroupChildren(shape);
4468
4482
  if (children.length === 0) return "";
4469
4483
  const tParts = [];
4484
+ let groupScaleX = 1;
4485
+ let groupScaleY = 1;
4470
4486
  if (xform && rotation !== 0) {
4471
4487
  const cxG = (xform.outer.x + xform.outer.w / 2) / EMU_PER_PX;
4472
4488
  const cyG = (xform.outer.y + xform.outer.h / 2) / EMU_PER_PX;
@@ -4489,13 +4505,23 @@ const renderShape = (shape, pres, theme, ctx) => {
4489
4505
  const iy = xform.inner.y;
4490
4506
  const iw = xform.inner.w || 1;
4491
4507
  const ih = xform.inner.h || 1;
4492
- const sx = (ow / iw).toFixed(6);
4493
- const sy = (oh / ih).toFixed(6);
4508
+ groupScaleX = ow / iw;
4509
+ groupScaleY = oh / ih;
4510
+ const sx = groupScaleX.toFixed(6);
4511
+ const sy = groupScaleY.toFixed(6);
4494
4512
  const tx = ((ox - ix * (ow / iw)) / EMU_PER_PX).toFixed(2);
4495
4513
  const ty = ((oy - iy * (oh / ih)) / EMU_PER_PX).toFixed(2);
4496
4514
  tParts.push(`translate(${tx} ${ty})`, `scale(${sx} ${sy})`);
4497
4515
  }
4498
- return `<g${tParts.length > 0 ? ` transform="${tParts.join(" ")}"` : ""}>${children.map((c) => renderShape(c, pres, theme, ctx)).join("")}</g>`;
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>`;
4499
4525
  }
4500
4526
  const p = paint(shape, fill, stroke, theme, phType !== null, pres);
4501
4527
  if (kind === "graphicFrame") {
@@ -4714,6 +4740,10 @@ const renderSlideSvg = (pres, slide, opts = {}) => {
4714
4740
  activeColorMap = getEffectiveColorMap(slide);
4715
4741
  activeDeckTextColor = resolveDeckBodyTextColor(slide) ?? "#000000";
4716
4742
  const ctx = {
4743
+ groupScale: {
4744
+ sx: 1,
4745
+ sy: 1
4746
+ },
4717
4747
  mode: opts.textLayout ?? "foreignObject",
4718
4748
  measure: opts.measureText ?? defaultMeasurer
4719
4749
  };
@@ -4961,4 +4991,4 @@ const auditTextLayout = (pres, options = {}) => {
4961
4991
  //#endregion
4962
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 };
4963
4993
 
4964
- //# sourceMappingURL=src-BCN48I0D.js.map
4994
+ //# sourceMappingURL=src-B73Pj0gv.js.map