@office-kit/pptx-preview 0.10.0 → 0.12.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/README.md CHANGED
@@ -151,6 +151,23 @@ the label text:
151
151
  Example: `svg.querySelectorAll('[data-pptx-fallback]')` lists every shape that
152
152
  did not fully render.
153
153
 
154
+ ### Mapping the SVG back to the deck
155
+
156
+ Slide shapes, and the paragraphs and table cells inside them, carry attributes
157
+ that tie a click on the SVG back to the presentation. Master and layout
158
+ decoration carries none.
159
+
160
+ | Attribute | On | Value |
161
+ | --------------------- | --------------------------------------------------------- | ---------------------------------------------------- |
162
+ | `data-pptx-shape-id` | A `<g>` wrapping each shape; groups and each member alike | `getShapeId(shape)` |
163
+ | `data-pptx-paragraph` | `<p>` (foreignObject), each line's `<text>` (`svg` mode) | 0-based paragraph index |
164
+ | `data-pptx-cell` | A `<g>` wrapping each table cell's fill and text | `row,col`, 0-based; paragraphs count within the cell |
165
+
166
+ ```ts
167
+ const shape = target.closest('[data-pptx-shape-id]')?.getAttribute('data-pptx-shape-id');
168
+ const paragraph = target.closest('[data-pptx-paragraph]')?.getAttribute('data-pptx-paragraph');
169
+ ```
170
+
154
171
  ## License
155
172
 
156
173
  MIT (code). Bundled fonts: OFL-1.1 / Apache-2.0 — see `fonts/LICENSES.md`.
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-DC6HxO-i.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-C2HIGS1C.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-DC6HxO-i.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-C2HIGS1C.js";
2
2
  import { getSlideSize } from "@office-kit/pptx";
3
3
  import { Resvg } from "@resvg/resvg-js";
4
4
  import * as fontkit from "fontkit";
@@ -1,4 +1,4 @@
1
- import { getEffectiveColorMap, getGroupChildren, getGroupTransform, getParagraphAlignment, getParagraphBullet, getParagraphBulletImageBytes, getParagraphBulletStyle, getParagraphIndent, getParagraphLevel, getParagraphPropertiesEffective, getParagraphSpacing, getPresentationFonts, getPresentationTheme, getShapeAdjustValues, getShapeAltTitle, getShapeBodyPrEffective, getShapeBoundsResolved, getShapeChartSpec, getShapeClickAction, getShapeCustomGeometry, getShapeDescription, getShapeEffectsEffective, getShapeFillColorResolved, getShapeFillEffective, getShapeFillOpacity, getShapeFlip, getShapeGradientFill, getShapeGradientFillEffective, getShapeHyperlink, getShapeHyperlinkTooltip, getShapeImageBiLevelThreshold, getShapeImageBrightness, getShapeImageBytes, getShapeImageContrast, getShapeImageCrop, getShapeImageDuotone, getShapeImageFillBytes, getShapeImageFormat, getShapeImageLinkUrl, getShapeImageOpacity, getShapeImagePartName, getShapeKind, getShapeName, getShapeParagraphCount, getShapeParagraphElements, getShapePatternFill, getShapePlaceholderType, getShapePreset, getShapeRotation, getShapeRunClickAction, getShapeRunFormat, getShapeRunFormatEffective, getShapeRunHyperlink, getShapeRunHyperlinkTooltip, getShapeStrokeArrow, getShapeStrokeCap, getShapeStrokeColorResolved, getShapeStrokeCompound, getShapeStrokeDash, getShapeStrokeEffective, getShapeStrokeJoin, getShapeStrokeOpacity, getShapeTextAnchor, getShapeTextAutoFitParams, getShapeTextBodyRotationDeg, getShapeTextColumns, getShapeTextDirection, getShapeTextMargins, getShapeXmlString, getSlideBackground, getSlideBackgroundGradientFill, getSlideBackgroundImageBytes, getSlideBackgroundPatternFill, getSlideIndex, getSlideLayout, getSlideLayoutBackground, getSlideLayoutBackgroundGradientFill, getSlideLayoutBackgroundImageBytes, getSlideLayoutBackgroundPatternFill, getSlideLayoutShapes, getSlideMasterBackground, getSlideMasterBackgroundGradientFill, getSlideMasterBackgroundImageBytes, getSlideMasterBackgroundPatternFill, getSlideMasterShapes, getSlideShapes, getSlideSize, getSlides, getTableCellAnchor, getTableCellBorders, getTableCellFill, getTableCellMargins, getTableCellParagraphs, getTableCellSpan, getTableCells, getTableColumnWidths, getTableDimensions, getTableRowHeights, getTableStyleFlags, isChartShape, isParagraphBulletPicture, isShapeImageGrayscale, isShapePlaceholder, isShapeTextBox, isTableShape, resolveDeckBodyTextColor } from "@office-kit/pptx";
1
+ import { getEffectiveColorMap, getGroupChildren, getGroupTransform, getParagraphAlignment, getParagraphBullet, getParagraphBulletImageBytes, getParagraphBulletStyle, getParagraphIndent, getParagraphLevel, getParagraphPropertiesEffective, getParagraphSpacing, getPresentationFonts, getPresentationTheme, getShapeAdjustValues, getShapeAltTitle, getShapeBodyPrEffective, getShapeBoundsResolved, getShapeChartSpec, getShapeClickAction, getShapeCustomGeometry, getShapeDescription, getShapeEffectsEffective, getShapeFillColorResolved, getShapeFillEffective, getShapeFillOpacity, getShapeFlip, getShapeGradientFill, getShapeGradientFillEffective, getShapeHyperlink, getShapeHyperlinkTooltip, getShapeId, getShapeImageBiLevelThreshold, getShapeImageBrightness, getShapeImageBytes, getShapeImageContrast, getShapeImageCrop, getShapeImageDuotone, getShapeImageFillBytes, getShapeImageFormat, getShapeImageLinkUrl, getShapeImageOpacity, getShapeImagePartName, getShapeKind, getShapeName, getShapeParagraphCount, getShapeParagraphElements, getShapePatternFill, getShapePlaceholderType, getShapePreset, getShapeRotation, getShapeRunClickAction, getShapeRunFormat, getShapeRunFormatEffective, getShapeRunHyperlink, getShapeRunHyperlinkTooltip, getShapeStrokeArrow, getShapeStrokeCap, getShapeStrokeColorResolved, getShapeStrokeCompound, getShapeStrokeDash, getShapeStrokeEffective, getShapeStrokeJoin, getShapeStrokeOpacity, getShapeTextAnchor, getShapeTextAutoFitParams, getShapeTextBodyRotationDeg, getShapeTextColumns, getShapeTextDirection, getShapeTextMargins, getShapeXmlString, getSlideBackground, getSlideBackgroundGradientFill, getSlideBackgroundImageBytes, getSlideBackgroundPatternFill, getSlideIndex, getSlideLayout, getSlideLayoutBackground, getSlideLayoutBackgroundGradientFill, getSlideLayoutBackgroundImageBytes, getSlideLayoutBackgroundPatternFill, getSlideLayoutShapes, getSlideMasterBackground, getSlideMasterBackgroundGradientFill, getSlideMasterBackgroundImageBytes, getSlideMasterBackgroundPatternFill, getSlideMasterShapes, getSlideShapes, getSlideSize, getSlides, getTableCellAnchor, getTableCellBorders, getTableCellFill, getTableCellMargins, getTableCellParagraphs, getTableCellSpan, getTableCells, getTableColumnWidths, getTableDimensions, getTableRowHeights, getTableStyleFlags, isChartShape, isParagraphBulletPicture, isShapeImageGrayscale, isShapePlaceholder, isShapeTextBox, isTableShape, resolveDeckBodyTextColor } from "@office-kit/pptx";
2
2
  //#region src/emf.ts
3
3
  const WORD_BYTES = 4;
4
4
  const SHORT_BYTES = 2;
@@ -564,7 +564,7 @@ const emitPlacements = (placements) => {
564
564
  if (line.bullet) {
565
565
  const b = line.bullet.b;
566
566
  if (b.imageHref) parts.push(`<image x="${fmt(line.bullet.x + dx + GRID_NUDGE_X)}" y="${fmt(baselineY - b.sizePx)}" width="${fmt(b.sizePx)}" height="${fmt(b.sizePx)}" href="${b.imageHref}" xlink:href="${b.imageHref}" preserveAspectRatio="xMidYMid meet"/>`);
567
- else parts.push(`<text x="${fmt(line.bullet.x + dx + GRID_NUDGE_X)}" y="${fmt(baselineY)}" font-family="${escapeXml$1(b.family)}" font-size="${fmt(b.sizePx)}" fill="${b.fillHex}" xml:space="preserve">${escapeXml$1(b.text)}</text>`);
567
+ else parts.push(`<text x="${fmt(line.bullet.x + dx + GRID_NUDGE_X)}" y="${fmt(baselineY)}" font-family="${escapeXml$1(b.family)}" font-size="${fmt(b.sizePx)}" fill="${b.fillHex}" xml:space="preserve" data-pptx-paragraph="${line.paraIndex}">${escapeXml$1(b.text)}</text>`);
568
568
  }
569
569
  parts.push(emitLine(line, baselineY, dx));
570
570
  }
@@ -591,7 +591,7 @@ const emitLine = (line, baselineY, dx) => {
591
591
  const tspans = groups.map((g) => tspan(g)).join("");
592
592
  if (tspans === "") return "";
593
593
  const x0 = line.anchorX + dx + GRID_NUDGE_X;
594
- return `<text x="${fmt(x0)}" y="${fmt(baselineY)}" text-anchor="${line.textAnchor}" xml:space="preserve">${tspans}</text>` + emitWavyUnderlines(groups, line.textAnchor, x0, baselineY);
594
+ return `<text x="${fmt(x0)}" y="${fmt(baselineY)}" text-anchor="${line.textAnchor}" xml:space="preserve" data-pptx-paragraph="${line.paraIndex}">${tspans}</text>` + emitWavyUnderlines(groups, line.textAnchor, x0, baselineY);
595
595
  };
596
596
  const groupTokens = (toks) => {
597
597
  const groups = [];
@@ -2686,7 +2686,7 @@ const renderTextBody = (pres, shape, bounds, theme, phType, ctx) => {
2686
2686
  bulletStyles.push(para.bulletDetail.font ? `font-family:${escapeXml(para.bulletDetail.font)}, ${DEFAULT_FONT}` : `font-family:${DEFAULT_BULLET_FONT}, ${DEFAULT_FONT}`);
2687
2687
  prefix = `<span style="${bulletStyles.join(";")}">${escapeXml(char)}</span>`;
2688
2688
  }
2689
- paragraphs.push(`<p style="${pStyles.join(";")}">${prefix}${runHtmls.join("") || "&#8203;"}</p>`);
2689
+ paragraphs.push(`<p data-pptx-paragraph="${pi}" style="${pStyles.join(";")}">${prefix}${runHtmls.join("") || "&#8203;"}</p>`);
2690
2690
  }
2691
2691
  const justify = ANCHOR_TO_CSS[anchor] ?? "flex-start";
2692
2692
  if (ctx.mode === "svg") {
@@ -4174,9 +4174,9 @@ const renderTableCellText = (paragraphs, cx, cy, cw, ch, color, pres, shape, the
4174
4174
  });
4175
4175
  const justify = vAnchor === "top" ? "flex-start" : vAnchor === "bottom" ? "flex-end" : "center";
4176
4176
  const familyFont = themeFace ? `${escapeXml(themeFace)}, ${DEFAULT_FONT}` : DEFAULT_FONT;
4177
- const body = paraData.map((para) => {
4177
+ const body = paraData.map((para, index) => {
4178
4178
  const runHtml = para.runs.map((run) => renderRun(run.text, run.fmt, theme, run.sizePt, run.fmt?.size === void 0)).join("");
4179
- return `<p style="margin:0;padding:0;text-align:${ALIGNMENT_TO_CSS[para.align] ?? "left"};line-height:1.2">${runHtml || "&#8203;"}</p>`;
4179
+ return `<p data-pptx-paragraph="${index}" style="margin:0;padding:0;text-align:${ALIGNMENT_TO_CSS[para.align] ?? "left"};line-height:1.2">${runHtml || "&#8203;"}</p>`;
4180
4180
  }).join("");
4181
4181
  return `<foreignObject x="${px(innerX)}" y="${px(innerY)}" width="${px(innerW)}" height="${px(innerH)}"><div xmlns="http://www.w3.org/1999/xhtml" style="display:flex;flex-direction:column;justify-content:${justify};width:100%;height:100%;box-sizing:border-box;overflow:hidden;font-family:${familyFont};color:${color};word-break:break-word">${body}</div></foreignObject>`;
4182
4182
  };
@@ -4240,7 +4240,7 @@ const renderTable = (shape, pres, x, y, w, h, transform, theme, ctx) => {
4240
4240
  else if (flags.bandCol) resolvedFill = (c - (flags.firstCol ? 1 : 0)) % 2 === 0 ? bandFill : bandFill2;
4241
4241
  else resolvedFill = "none";
4242
4242
  const cellTextColor = resolvedFill === headerFill ? "#FFFFFF" : textColor;
4243
- out.push(`<rect x="${px(cx)}" y="${px(cy)}" width="${px(cw)}" height="${px(ch)}" fill="${resolvedFill}"/>`);
4243
+ out.push(`<g data-pptx-cell="${r},${c}"><rect x="${px(cx)}" y="${px(cy)}" width="${px(cw)}" height="${px(ch)}" fill="${resolvedFill}"/>`);
4244
4244
  const borders = getTableCellBorders(pres, typedCell);
4245
4245
  const dashAttr = (dash, widthPx) => {
4246
4246
  if (!dash || dash === "solid") return "";
@@ -4275,7 +4275,7 @@ const renderTable = (shape, pres, x, y, w, h, transform, theme, ctx) => {
4275
4275
  const cellParagraphs = getTableCellParagraphs(cell);
4276
4276
  const vAnchor = getTableCellAnchor(typedCell) ?? "top";
4277
4277
  const cellMargins = getTableCellMargins(typedCell);
4278
- out.push(renderTableCellText(cellParagraphs, cx, cy, cw, ch, cellTextColor, pres, shape, theme, tableThemeFace, ctx, vAnchor, cellMargins));
4278
+ out.push(renderTableCellText(cellParagraphs, cx, cy, cw, ch, cellTextColor, pres, shape, theme, tableThemeFace, ctx, vAnchor, cellMargins), "</g>");
4279
4279
  }
4280
4280
  out.push(borderEdges.join(""));
4281
4281
  out.push("</g>");
@@ -4398,6 +4398,10 @@ const customGeometryToSvg = (geom, x, y, w, h, fill, fillExtra, stroke, strokeWi
4398
4398
  return out.join("");
4399
4399
  };
4400
4400
  const renderShape = (shape, pres, theme, ctx) => {
4401
+ const svg = renderShapeMarkup(shape, pres, theme, ctx);
4402
+ return svg && ctx.tagShapes ? `<g data-pptx-shape-id="${escapeXml(String(getShapeId(shape)))}">${svg}</g>` : svg;
4403
+ };
4404
+ const renderShapeMarkup = (shape, pres, theme, ctx) => {
4401
4405
  const bounds = getShapeBoundsResolved(pres, shape);
4402
4406
  if (!bounds) return "";
4403
4407
  const x = bounds.x;
@@ -4758,7 +4762,8 @@ const renderSlideSvg = (pres, slide, opts = {}) => {
4758
4762
  sy: 1
4759
4763
  },
4760
4764
  mode: opts.textLayout ?? "foreignObject",
4761
- measure: opts.measureText ?? defaultMeasurer
4765
+ measure: opts.measureText ?? defaultMeasurer,
4766
+ tagShapes: false
4762
4767
  };
4763
4768
  let bg = getSlideBackground(slide);
4764
4769
  if (bg.kind === "inherit") {
@@ -4830,7 +4835,11 @@ const renderSlideSvg = (pres, slide, opts = {}) => {
4830
4835
  } catch {
4831
4836
  layoutBgShapes = "";
4832
4837
  }
4833
- const shapesSvg = topLevelShapes(getSlideShapes(slide), { dropPlaceholders: false }).map((s) => renderShape(s, pres, theme, ctx)).join("");
4838
+ const slideCtx = {
4839
+ ...ctx,
4840
+ tagShapes: true
4841
+ };
4842
+ const shapesSvg = topLevelShapes(getSlideShapes(slide), { dropPlaceholders: false }).map((s) => renderShape(s, pres, theme, slideCtx)).join("");
4834
4843
  return [
4835
4844
  `<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 0 ${E(W)} ${E(H)}" preserveAspectRatio="xMidYMid meet">`,
4836
4845
  bgGradientDefs,
@@ -5004,4 +5013,4 @@ const auditTextLayout = (pres, options = {}) => {
5004
5013
  //#endregion
5005
5014
  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 };
5006
5015
 
5007
- //# sourceMappingURL=src-DC6HxO-i.js.map
5016
+ //# sourceMappingURL=src-C2HIGS1C.js.map