@office-kit/pptx-preview 0.16.0 → 0.18.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
@@ -117,7 +117,7 @@ const measureText = buildFontkitMeasurer({
117
117
  });
118
118
 
119
119
  const issues = auditTextLayout(pres, { measureText, reportSoftWraps: true });
120
- // → [{ kind: 'overflow-y', slideIndex: 2, shapeName: 'Title 1', overflowPx: 14.3, approximate: false }, …]
120
+ // → [{ kind: 'overflow-y', slideIndex: 2, shapeName: 'Title 1', overflowPx: 14.3, shapeOverflowPx: 9.5, lineHeightPx: 52.8, approximate: false }, …]
121
121
  ```
122
122
 
123
123
  `auditTextLayout` measures every shape's text body — placeholders, text boxes,
@@ -125,11 +125,20 @@ autoshapes, shapes inside groups — with the same engine the preview renders
125
125
  with, honouring the effective bodyPr cascade (insets, wrap, anchor, vertical
126
126
  text, columns) and `normAutofit` shrinking. It returns one issue per finding:
127
127
 
128
- | `kind` | Meaning | Extra fields |
129
- | ------------ | ----------------------------------------------------------------------------- | ------------------------------ |
130
- | `overflow-x` | Text ink escapes the box horizontally (typically `wrap="none"`) | `overflowPx` |
131
- | `overflow-y` | Wrapped text is taller than the box (or escapes the top when bottom-anchored) | `overflowPx` |
132
- | `soft-wrap` | A paragraph wrapped onto more lines than its authored `<a:br>` count (段落ち) | `paragraphIndex`, `extraLines` |
128
+ | `kind` | Meaning | Extra fields |
129
+ | ----------------- | ----------------------------------------------------------------------------------- | ------------------------------ |
130
+ | `overflow-x` | Text ink escapes the box horizontally (typically `wrap="none"`) | `overflowPx` and the two below |
131
+ | `overflow-y` | Wrapped text is taller than the box (or escapes the top when bottom-anchored) | `overflowPx` and the two below |
132
+ | `soft-wrap` | A paragraph wrapped onto more lines than its authored `<a:br>` count (段落ち) | `paragraphIndex`, `extraLines` |
133
+ | `word-break` | A wrap split a word (Latin / Greek / Cyrillic letters or digits, or a katakana run) | `paragraphIndex`, `text` |
134
+ | `short-last-line` | A wrapped paragraph ends on a line of one or two characters (泣き別れ) | `paragraphIndex`, `text` |
135
+ | `small-font` | The shape draws text below `minFontSizePt`, after autofit shrinking | `sizePt` |
136
+
137
+ `overflowPx` is measured against the text area (the box minus its insets);
138
+ `shapeOverflowPx` is how much ink lies outside the shape itself, both sides
139
+ added (a centre-anchored body spills above and below; 0 while the spill stays
140
+ inside the insets, where nobody sees it); `lineHeightPx` is the
141
+ tallest line's height, about how far one misjudged wrap moves the text.
133
142
 
134
143
  Every issue also carries `slideIndex`, `shapeName`, and `approximate` —
135
144
  `true` when a width had to be estimated (the heuristic measurer, or glyphs the
@@ -146,6 +155,13 @@ Options:
146
155
  - `reportSoftWraps` — opt into `soft-wrap` issues. Off by default because
147
156
  wrapping is normal for body text; turn it on when auditing titles or labels
148
157
  meant to stay on one line.
158
+ - `reportBadWraps` — opt into `word-break` and `short-last-line` issues
159
+ (horizontal text only). A word inside a kanji compound cannot be told apart
160
+ from its neighbours, so only the scripts listed above are checked.
161
+ A `word-break` issue is reported once per word; its `text` is the word with
162
+ `|` at each line break. `short-last-line` counts characters, not words, so a
163
+ Latin last line of `to` is reported and one of `the` is not.
164
+ - `minFontSizePt` — report `small-font` for shapes with text below this size.
149
165
 
150
166
  Accuracy: the bundled fonts are metric-compatible with the common default fonts, so
151
167
  verdicts for Calibri / Cambria / Arial / Times / Courier decks match real glyph
@@ -108,14 +108,29 @@ interface IssueBase {
108
108
  readonly approximate: boolean;
109
109
  }
110
110
  type TextAuditIssue = (IssueBase & {
111
- readonly kind: 'overflow-x' | 'overflow-y'; /** How far the text ink escapes the box, in px at 96 DPI. */
111
+ readonly kind: 'overflow-x' | 'overflow-y'; /** How far the text ink escapes the text area (the box minus its insets), in px at 96 DPI. */
112
112
  readonly overflowPx: number;
113
+ /** How much ink lies outside the shape itself along that axis, both sides added
114
+ * (a centred body spills half above, half below); 0 while it stays within the insets. */
115
+ readonly shapeOverflowPx: number; /** The tallest line's height in px: about how far one misjudged wrap moves the text. */
116
+ readonly lineHeightPx: number;
113
117
  }) | (IssueBase & {
114
118
  readonly kind: 'soft-wrap';
115
119
  readonly paragraphIndex: number;
116
120
  /** Lines beyond the paragraph's authored line count (1 + explicit
117
121
  * breaks) — i.e. how many times the text wrapped on its own. */
118
122
  readonly extraLines: number;
123
+ }) | (IssueBase & {
124
+ /** A wrap split a word: Latin / Greek / Cyrillic letters or digits, or a katakana run. */readonly kind: 'word-break';
125
+ readonly paragraphIndex: number; /** The split word, with `|` where the line breaks. */
126
+ readonly text: string;
127
+ }) | (IssueBase & {
128
+ /** A wrapped paragraph whose last line holds only a character or two (泣き別れ). */readonly kind: 'short-last-line';
129
+ readonly paragraphIndex: number; /** The text of that last line. */
130
+ readonly text: string;
131
+ }) | (IssueBase & {
132
+ readonly kind: 'small-font'; /** The smallest font size drawn in the shape, after autofit shrinking. */
133
+ readonly sizePt: number;
119
134
  });
120
135
  interface AuditTextLayoutOptions {
121
136
  /** Measurer for run widths / vertical metrics. Defaults to the heuristic
@@ -129,11 +144,19 @@ interface AuditTextLayoutOptions {
129
144
  * breaks author (段落ち). Off by default: wrapping is normal for body
130
145
  * text, so this is opt-in for single-line-intent content like titles. */
131
146
  readonly reportSoftWraps?: boolean;
147
+ /** Also report wraps that split a word (`word-break`) and wrapped
148
+ * paragraphs that end on a line of one or two characters
149
+ * (`short-last-line`). Horizontal text only. */
150
+ readonly reportBadWraps?: boolean;
151
+ /** Report shapes drawing text below this size in points (`small-font`). */
152
+ readonly minFontSizePt?: number;
132
153
  }
133
154
  /**
134
155
  * Measures every text body in the deck and reports text that escapes its box
135
156
  * (`overflow-x` / `overflow-y`) and, opt-in, paragraphs that soft-wrap
136
- * (`soft-wrap`, 段落ち).
157
+ * (`soft-wrap`, 段落ち), wraps that split a word or strand a line of one or
158
+ * two characters (`word-break`, `short-last-line`), and text below a minimum
159
+ * size (`small-font`).
137
160
  *
138
161
  * Table cell text is not audited (v1 covers shape text bodies, including
139
162
  * placeholders and shapes inside groups).
@@ -272,4 +295,4 @@ declare function shapeTextAnchorOffset(pres: PresentationData, shape: SlideShape
272
295
  declare function textUnderlineStyle(underline: TextFormat['underline'], color: string, includeDecorationColor?: boolean): string;
273
296
  //#endregion
274
297
  export { substituteFamily as A, RenderSlideOptions as C, TextLayoutMode as D, TIMES as E, TextMeasurer as O, MeasureResult as S, SERIF as T, renderSlideSvg as _, VerticalTextStyle as a, FontSpec as b, TextRectFractions as c, decimalSeparatorOf as d, paragraphNumberLabels as f, renderSlideLayoutSvg as g, auditTextLayout as h, shapeTextAnchorOffset as i, defaultMeasurer as k, resolveTextBodyRect as l, TextAuditIssue as m, ShapeAutoFitScaleOptions as n, textColumnsStyle as o, AuditTextLayoutOptions as p, shapeAutoFitScale as r, verticalTextStyle as s, textUnderlineStyle as t, shapeTextRect as u, renderTextEffectsSvg as v, SANS as w, MONO as x, ARIAL as y };
275
- //# sourceMappingURL=index-D1r4NkUr.d.ts.map
298
+ //# sourceMappingURL=index-C8dvep3H.d.ts.map
package/dist/index.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- import { A as substituteFamily, C as RenderSlideOptions, D as TextLayoutMode, E as TIMES, O as TextMeasurer, S as MeasureResult, T as SERIF, _ as renderSlideSvg, a as VerticalTextStyle, b as FontSpec, c as TextRectFractions, d as decimalSeparatorOf, f as paragraphNumberLabels, g as renderSlideLayoutSvg, h as auditTextLayout, i as shapeTextAnchorOffset, k as defaultMeasurer, l as resolveTextBodyRect, m as TextAuditIssue, n as ShapeAutoFitScaleOptions, o as textColumnsStyle, p as AuditTextLayoutOptions, r as shapeAutoFitScale, s as verticalTextStyle, t as textUnderlineStyle, u as shapeTextRect, v as renderTextEffectsSvg, w as SANS, x as MONO, y as ARIAL } from "./index-D1r4NkUr.js";
1
+ import { A as substituteFamily, C as RenderSlideOptions, D as TextLayoutMode, E as TIMES, O as TextMeasurer, S as MeasureResult, T as SERIF, _ as renderSlideSvg, a as VerticalTextStyle, b as FontSpec, c as TextRectFractions, d as decimalSeparatorOf, f as paragraphNumberLabels, g as renderSlideLayoutSvg, h as auditTextLayout, i as shapeTextAnchorOffset, k as defaultMeasurer, l as resolveTextBodyRect, m as TextAuditIssue, n as ShapeAutoFitScaleOptions, o as textColumnsStyle, p as AuditTextLayoutOptions, r as shapeAutoFitScale, s as verticalTextStyle, t as textUnderlineStyle, u as shapeTextRect, v as renderTextEffectsSvg, w as SANS, x as MONO, y as ARIAL } from "./index-C8dvep3H.js";
2
2
  export { ARIAL, type AuditTextLayoutOptions, type FontSpec, MONO, type MeasureResult, type RenderSlideOptions, SANS, SERIF, type ShapeAutoFitScaleOptions, TIMES, type TextAuditIssue, type TextLayoutMode, type TextMeasurer, type TextRectFractions, type VerticalTextStyle, auditTextLayout, decimalSeparatorOf, defaultMeasurer, paragraphNumberLabels, renderSlideLayoutSvg as renderSlideLayoutToSvg, renderSlideSvg as renderSlideToSvg, renderTextEffectsSvg, resolveTextBodyRect, shapeAutoFitScale, shapeTextAnchorOffset, shapeTextRect, substituteFamily, textColumnsStyle, textUnderlineStyle, verticalTextStyle };
package/dist/index.js CHANGED
@@ -1,2 +1,2 @@
1
- import { S as shapeTextRect, _ as paragraphNumberLabels, a as renderSlideSvg, b as verticalTextStyle, d as SERIF, f as TIMES, g as decimalSeparatorOf, h as substituteFamily, i as renderSlideLayoutSvg, l as MONO, n as shapeTextAnchorOffset, o as renderTextEffectsSvg, p as defaultMeasurer, r as auditTextLayout, s as ARIAL, t as shapeAutoFitScale, u as SANS, v as textUnderlineStyle, x as resolveTextBodyRect, y as textColumnsStyle } from "./src-u1-ERSHC.js";
1
+ import { S as shapeTextRect, _ as paragraphNumberLabels, a as renderSlideSvg, b as verticalTextStyle, d as SERIF, f as TIMES, g as decimalSeparatorOf, h as substituteFamily, i as renderSlideLayoutSvg, l as MONO, n as shapeTextAnchorOffset, o as renderTextEffectsSvg, p as defaultMeasurer, r as auditTextLayout, s as ARIAL, t as shapeAutoFitScale, u as SANS, v as textUnderlineStyle, x as resolveTextBodyRect, y as textColumnsStyle } from "./src-BGzSNWjt.js";
2
2
  export { ARIAL, MONO, SANS, SERIF, TIMES, auditTextLayout, decimalSeparatorOf, defaultMeasurer, paragraphNumberLabels, renderSlideLayoutSvg as renderSlideLayoutToSvg, renderSlideSvg as renderSlideToSvg, renderTextEffectsSvg, resolveTextBodyRect, shapeAutoFitScale, shapeTextAnchorOffset, shapeTextRect, substituteFamily, textColumnsStyle, textUnderlineStyle, verticalTextStyle };
package/dist/node.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { A as substituteFamily, C as RenderSlideOptions, D as TextLayoutMode, E as TIMES, O as TextMeasurer, S as MeasureResult, T as SERIF, _ as renderSlideSvg, a as VerticalTextStyle, b as FontSpec, c as TextRectFractions, d as decimalSeparatorOf, f as paragraphNumberLabels, g as renderSlideLayoutSvg, h as auditTextLayout, i as shapeTextAnchorOffset, k as defaultMeasurer, l as resolveTextBodyRect, m as TextAuditIssue, n as ShapeAutoFitScaleOptions, o as textColumnsStyle, p as AuditTextLayoutOptions, r as shapeAutoFitScale, s as verticalTextStyle, t as textUnderlineStyle, u as shapeTextRect, v as renderTextEffectsSvg, w as SANS, x as MONO, y as ARIAL } from "./index-D1r4NkUr.js";
1
+ import { A as substituteFamily, C as RenderSlideOptions, D as TextLayoutMode, E as TIMES, O as TextMeasurer, S as MeasureResult, T as SERIF, _ as renderSlideSvg, a as VerticalTextStyle, b as FontSpec, c as TextRectFractions, d as decimalSeparatorOf, f as paragraphNumberLabels, g as renderSlideLayoutSvg, h as auditTextLayout, i as shapeTextAnchorOffset, k as defaultMeasurer, l as resolveTextBodyRect, m as TextAuditIssue, n as ShapeAutoFitScaleOptions, o as textColumnsStyle, p as AuditTextLayoutOptions, r as shapeAutoFitScale, s as verticalTextStyle, t as textUnderlineStyle, u as shapeTextRect, v as renderTextEffectsSvg, w as SANS, x as MONO, y as ARIAL } from "./index-C8dvep3H.js";
2
2
  import { PresentationData, SlideData } from "@office-kit/pptx";
3
3
 
4
4
  //#region src/measure.d.ts
package/dist/node.js CHANGED
@@ -1,4 +1,4 @@
1
- import { S as shapeTextRect, _ as paragraphNumberLabels, a as renderSlideSvg, b as verticalTextStyle, c as AVG_GLYPH_W_RATIO, d as SERIF, f as TIMES, g as decimalSeparatorOf, h as substituteFamily, i as renderSlideLayoutSvg, l as MONO, m as isCjk, n as shapeTextAnchorOffset, o as renderTextEffectsSvg, p as defaultMeasurer, r as auditTextLayout, s as ARIAL, t as shapeAutoFitScale, u as SANS, v as textUnderlineStyle, x as resolveTextBodyRect, y as textColumnsStyle } from "./src-u1-ERSHC.js";
1
+ import { S as shapeTextRect, _ as paragraphNumberLabels, a as renderSlideSvg, b as verticalTextStyle, c as AVG_GLYPH_W_RATIO, d as SERIF, f as TIMES, g as decimalSeparatorOf, h as substituteFamily, i as renderSlideLayoutSvg, l as MONO, m as isCjk, n as shapeTextAnchorOffset, o as renderTextEffectsSvg, p as defaultMeasurer, r as auditTextLayout, s as ARIAL, t as shapeAutoFitScale, u as SANS, v as textUnderlineStyle, x as resolveTextBodyRect, y as textColumnsStyle } from "./src-BGzSNWjt.js";
2
2
  import { getSlideSize } from "@office-kit/pptx";
3
3
  import { Resvg } from "@resvg/resvg-js";
4
4
  import * as fontkit from "fontkit";