pptxgenjs-plus-std 4.1.20 → 4.2.1

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
@@ -1,10 +1,10 @@
1
1
  # pptxgenjs-plus-std
2
2
 
3
- Layout and diagram helpers for [pptxgenjs-plus](https://github.com/lofcz/pptxgenjs-plus). These helpers compose the public `addChart` / position APIs — they do not replace the core library.
3
+ Layout, text-measure, table-paging, and diagram helpers for [pptxgenjs-plus](https://github.com/lofcz/pptxgenjs-plus). These helpers compose the public `addChart` / `addTable` / position APIs — they do not replace the core library.
4
4
 
5
5
  ```ts
6
6
  import pptxgen from 'pptxgenjs-plus'
7
- import { grid, waterfall } from 'pptxgenjs-plus-std'
7
+ import { grid, waterfall, measureText, paginateTable, cm } from 'pptxgenjs-plus-std'
8
8
 
9
9
  const pptx = new pptxgen()
10
10
  const slide = pptx.addSlide()
@@ -21,8 +21,12 @@ waterfall(slide, {
21
21
  ## Helpers
22
22
 
23
23
  - `grid()` / `gridFor(pres)` — place objects on a column/row grid; throws instead of drifting off-slide
24
+ - `row(area, slots)` / `column(area, slots)` — split any `{ x, y, w, h }` by count or weights
25
+ - `cm()` / `pt()` — centimetres and points as the inches every `addX` option takes
26
+ - `measureText` / `fitText` / `checkOverflow` / `registerFontMetrics` — wrap and size text from canvas, bundled Calibri (Carlito) widths, or a flat estimate
27
+ - `paginateTable` / `tableFromHtml` — page tables by measured cell height (an additional pager alongside core `autoPage` / `tableToSlides`)
24
28
  - `waterfall(slide, props, options?)` — stacked-bar waterfall (transparent riser + signed per-point labels)
25
29
 
26
- Category subpaths: `pptxgenjs-plus-std/layout`, `pptxgenjs-plus-std/charts`.
30
+ Category subpaths: `pptxgenjs-plus-std/layout`, `pptxgenjs-plus-std/charts`, `pptxgenjs-plus-std/text`, `pptxgenjs-plus-std/tables`.
27
31
 
28
32
  `pptxgenjs-plus` is a peer dependency at the same version as this package, so helpers act on the caller's own presentation instance.
package/dist/index.d.ts CHANGED
@@ -1,2 +1,4 @@
1
1
  export * from './layout';
2
2
  export * from './charts';
3
+ export * from './text';
4
+ export * from './tables';
package/dist/index.js CHANGED
@@ -1,3 +1,5 @@
1
1
  export * from './layout';
2
2
  export * from './charts';
3
+ export * from './text';
4
+ export * from './tables';
3
5
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAA;AACxB,cAAc,UAAU,CAAA"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAA;AACxB,cAAc,UAAU,CAAA;AACxB,cAAc,QAAQ,CAAA;AACtB,cAAc,UAAU,CAAA"}
@@ -1,2 +1,5 @@
1
1
  export { grid, gridFor } from './grid';
2
2
  export type { GridProps, GridArea } from './grid';
3
+ export { row, column } from './split';
4
+ export type { Slots } from './split';
5
+ export { cm, pt } from './units';
@@ -1,2 +1,4 @@
1
1
  export { grid, gridFor } from './grid';
2
+ export { row, column } from './split';
3
+ export { cm, pt } from './units';
2
4
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/layout/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAA"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/layout/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAA;AAEtC,OAAO,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,SAAS,CAAA;AAErC,OAAO,EAAE,EAAE,EAAE,EAAE,EAAE,MAAM,SAAS,CAAA"}
@@ -0,0 +1,24 @@
1
+ import type { GridArea } from './grid';
2
+ /**
3
+ * Weights per slot, or a slot count for equal shares.
4
+ * `3` and `[1, 1, 1]` mean the same thing.
5
+ */
6
+ export type Slots = number | number[];
7
+ /**
8
+ * Divide an area into side-by-side slots.
9
+ *
10
+ * Takes the placement arithmetic off the caller: pass a count or weights, get areas ready to
11
+ * spread into any `addX` options. Output is the same shape as the input, so slots nest.
12
+ *
13
+ * @example
14
+ * const [left, right] = row(at(0, 0, 12, 6), [1, 2])
15
+ * const [a, b, c] = row(left, 3, 0.1)
16
+ */
17
+ export declare function row(area: GridArea, slots: Slots, gap?: number): GridArea[];
18
+ /**
19
+ * Divide an area into stacked slots.
20
+ *
21
+ * @example
22
+ * const [header, body] = column(at(0, 0, 12, 6), [1, 4])
23
+ */
24
+ export declare function column(area: GridArea, slots: Slots, gap?: number): GridArea[];
@@ -0,0 +1,52 @@
1
+ function resolve(slots, label) {
2
+ if (typeof slots === 'number') {
3
+ if (!Number.isInteger(slots) || slots < 1)
4
+ throw new Error(`${label}: slot count must be an integer >= 1 (got ${slots})`);
5
+ return Array.from({ length: slots }, () => 1);
6
+ }
7
+ if (slots.length === 0)
8
+ throw new Error(`${label}: weights must not be empty`);
9
+ if (slots.some(weight => !(weight > 0)))
10
+ throw new Error(`${label}: every weight must be > 0 (got [${slots.join(', ')}])`);
11
+ return slots;
12
+ }
13
+ function split(area, slots, gap, axis, label) {
14
+ const weights = resolve(slots, label);
15
+ if (gap < 0)
16
+ throw new Error(`${label}: gap must be >= 0 (got ${gap})`);
17
+ const total = area[axis] - gap * (weights.length - 1);
18
+ if (!(total > 0))
19
+ throw new Error(`${label}: gap ${gap} leaves no room across ${area[axis]}`);
20
+ const sum = weights.reduce((a, b) => a + b, 0);
21
+ const offset = axis === 'w' ? 'x' : 'y';
22
+ let at = area[offset];
23
+ return weights.map(weight => {
24
+ const size = (total * weight) / sum;
25
+ const slot = { ...area, [offset]: at, [axis]: size };
26
+ at += size + gap;
27
+ return slot;
28
+ });
29
+ }
30
+ /**
31
+ * Divide an area into side-by-side slots.
32
+ *
33
+ * Takes the placement arithmetic off the caller: pass a count or weights, get areas ready to
34
+ * spread into any `addX` options. Output is the same shape as the input, so slots nest.
35
+ *
36
+ * @example
37
+ * const [left, right] = row(at(0, 0, 12, 6), [1, 2])
38
+ * const [a, b, c] = row(left, 3, 0.1)
39
+ */
40
+ export function row(area, slots, gap = 0.2) {
41
+ return split(area, slots, gap, 'w', 'row');
42
+ }
43
+ /**
44
+ * Divide an area into stacked slots.
45
+ *
46
+ * @example
47
+ * const [header, body] = column(at(0, 0, 12, 6), [1, 4])
48
+ */
49
+ export function column(area, slots, gap = 0.2) {
50
+ return split(area, slots, gap, 'h', 'column');
51
+ }
52
+ //# sourceMappingURL=split.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"split.js","sourceRoot":"","sources":["../../src/layout/split.ts"],"names":[],"mappings":"AAQA,SAAS,OAAO,CAAE,KAAY,EAAE,KAAa;IAC5C,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QAC/B,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,KAAK,CAAC,IAAI,KAAK,GAAG,CAAC;YAAE,MAAM,IAAI,KAAK,CAAC,GAAG,KAAK,6CAA6C,KAAK,GAAG,CAAC,CAAA;QACzH,OAAO,KAAK,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE,EAAE,GAAG,EAAE,CAAC,CAAC,CAAC,CAAA;IAC9C,CAAC;IACD,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC;QAAE,MAAM,IAAI,KAAK,CAAC,GAAG,KAAK,6BAA6B,CAAC,CAAA;IAC9E,IAAI,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;QAAE,MAAM,IAAI,KAAK,CAAC,GAAG,KAAK,oCAAoC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;IAC1H,OAAO,KAAK,CAAA;AACb,CAAC;AAED,SAAS,KAAK,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C3D,OAAO,KAAK,CAAC,IAAI,EAAE,KAAK,EAAE,GAAG,EAAE,GAAG,EAAE,KAAK,CAAC,CAAA;AAC3C,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,MAAM,CAAE,IAAc,EAAE,KAAY,EAAE,GAAG,GAAG,GAAG;IAC9D,OAAO,KAAK,CAAC,IAAI,EAAE,KAAK,EAAE,GAAG,EAAE,GAAG,EAAE,QAAQ,CAAC,CAAA;AAC9C,CAAC"}
@@ -0,0 +1,21 @@
1
+ /**
2
+ * Centimetres as inches.
3
+ *
4
+ * Every `addX` option is in inches, so a design specified in centimetres - which is most of
5
+ * them outside the US - gets divided by 2.54 at every call site until someone gets it wrong.
6
+ *
7
+ * @example
8
+ * slide.addText('Titel', { x: cm(2.5), y: cm(1.8), w: cm(20), h: cm(2) })
9
+ * const at = grid({ w: cm(33.87), h: cm(19.05), margin: cm(1.27) })
10
+ */
11
+ export declare function cm(value: number): number;
12
+ /**
13
+ * Points as inches.
14
+ *
15
+ * For lengths given in points - line widths, optical offsets, anything sized to match a font -
16
+ * where the option itself wants inches.
17
+ *
18
+ * @example
19
+ * slide.addShape('line', { x: 1, y: pt(18), w: 4, h: 0 })
20
+ */
21
+ export declare function pt(value: number): number;
@@ -0,0 +1,35 @@
1
+ /** Centimetres per inch - the whole reason this file exists */
2
+ const CM_PER_IN = 2.54;
3
+ /** Points per inch. Font sizes are already in points; positions are not. */
4
+ const PT_PER_IN = 72;
5
+ function convert(value, per, label) {
6
+ if (!Number.isFinite(value))
7
+ throw new Error(`${label}: value must be a finite number (got ${value})`);
8
+ return value / per;
9
+ }
10
+ /**
11
+ * Centimetres as inches.
12
+ *
13
+ * Every `addX` option is in inches, so a design specified in centimetres - which is most of
14
+ * them outside the US - gets divided by 2.54 at every call site until someone gets it wrong.
15
+ *
16
+ * @example
17
+ * slide.addText('Titel', { x: cm(2.5), y: cm(1.8), w: cm(20), h: cm(2) })
18
+ * const at = grid({ w: cm(33.87), h: cm(19.05), margin: cm(1.27) })
19
+ */
20
+ export function cm(value) {
21
+ return convert(value, CM_PER_IN, 'cm');
22
+ }
23
+ /**
24
+ * Points as inches.
25
+ *
26
+ * For lengths given in points - line widths, optical offsets, anything sized to match a font -
27
+ * where the option itself wants inches.
28
+ *
29
+ * @example
30
+ * slide.addShape('line', { x: 1, y: pt(18), w: 4, h: 0 })
31
+ */
32
+ export function pt(value) {
33
+ return convert(value, PT_PER_IN, 'pt');
34
+ }
35
+ //# sourceMappingURL=units.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"units.js","sourceRoot":"","sources":["../../src/layout/units.ts"],"names":[],"mappings":"AAAA,+DAA+D;AAC/D,MAAM,SAAS,GAAG,IAAI,CAAA;AAEtB,4EAA4E;AAC5E,MAAM,SAAS,GAAG,EAAE,CAAA;AAEpB,SAAS,OAAO,CAAE,KAAa,EAAE,GAAW,EAAE,KAAa;IAC1D,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC;QAAE,MAAM,IAAI,KAAK,CAAC,GAAG,KAAK,wCAAwC,KAAK,GAAG,CAAC,CAAA;IACtG,OAAO,KAAK,GAAG,GAAG,CAAA;AACnB,CAAC;AAED;;;;;;;;;GASG;AACH,MAAM,UAAU,EAAE,CAAE,KAAa;IAChC,OAAO,OAAO,CAAC,KAAK,EAAE,SAAS,EAAE,IAAI,CAAC,CAAA;AACvC,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,EAAE,CAAE,KAAa;IAChC,OAAO,OAAO,CAAC,KAAK,EAAE,SAAS,EAAE,IAAI,CAAC,CAAA;AACvC,CAAC"}
@@ -0,0 +1,54 @@
1
+ import type PptxGenJS from 'pptxgenjs-plus';
2
+ import { type PaginateTableProps, type PaginateTableResult, type TablePresentation, type TableSlide } from './paginate';
3
+ /**
4
+ * The slice of the DOM this helper reads.
5
+ *
6
+ * Structural rather than `HTMLTableElement` so it works without DOM lib types in scope and can be
7
+ * driven by a plain object in tests. A real `<table>` conforms as-is.
8
+ */
9
+ export interface HtmlCell {
10
+ textContent?: string | null;
11
+ colSpan?: number;
12
+ rowSpan?: number;
13
+ tagName?: string;
14
+ }
15
+ export interface HtmlRow {
16
+ cells: ArrayLike<HtmlCell>;
17
+ }
18
+ export interface HtmlTable {
19
+ rows: ArrayLike<HtmlRow>;
20
+ }
21
+ /** The cell styling this helper carries over to PowerPoint */
22
+ export interface CellStyle {
23
+ color?: string;
24
+ fill?: string;
25
+ bold?: boolean;
26
+ italic?: boolean;
27
+ fontSize?: number;
28
+ fontFace?: string;
29
+ align?: 'left' | 'center' | 'right';
30
+ }
31
+ export interface TableFromHtmlProps extends PaginateTableProps {
32
+ /**
33
+ * Style lookup per cell. Defaults to reading `window.getComputedStyle` when a DOM is present,
34
+ * and to no styling otherwise - pass this to style cells from anything else.
35
+ */
36
+ styleOf?: (cell: HtmlCell) => CellStyle;
37
+ /**
38
+ * Treat leading rows made entirely of `<th>` as repeated headers.
39
+ * Ignored when `repeatHeaderRows` is set explicitly. @default true
40
+ */
41
+ detectHeaderRows?: boolean;
42
+ }
43
+ /** `rgb(r, g, b)` / `rgba(...)` / `#rgb` / `#rrggbb` to a bare pptx hex, or undefined */
44
+ export declare function cssColorToHex(value: string | null | undefined): string | undefined;
45
+ /**
46
+ * Reproduce an HTML table as a PowerPoint table, across as many slides as it needs.
47
+ *
48
+ * A measured counterpart to the core `tableToSlides`: this one measures the text, and takes the
49
+ * table as an object rather than an element id so it is not tied to a live document.
50
+ *
51
+ * @example
52
+ * tableFromHtml(pres, document.getElementById('report'), { x: 0.5, y: 0.5, w: 9, fontSize: 10 })
53
+ */
54
+ export declare function tableFromHtml<S extends TableSlide<PptxGenJS.TableRow>>(pres: TablePresentation<S, PptxGenJS.TableRow>, table: HtmlTable, props?: TableFromHtmlProps): PaginateTableResult<S>;
@@ -0,0 +1,89 @@
1
+ import { paginateTable } from './paginate';
2
+ /** `rgb(r, g, b)` / `rgba(...)` / `#rgb` / `#rrggbb` to a bare pptx hex, or undefined */
3
+ export function cssColorToHex(value) {
4
+ if (!value)
5
+ return undefined;
6
+ const text = value.trim();
7
+ const rgb = /^rgba?\(\s*(\d+)[,\s]+(\d+)[,\s]+(\d+)\s*(?:[,/]\s*([\d.]+)\s*)?\)$/i.exec(text);
8
+ if (rgb) {
9
+ // Fully transparent is "no fill", not black
10
+ if (rgb[4] !== undefined && Number(rgb[4]) === 0)
11
+ return undefined;
12
+ return [rgb[1], rgb[2], rgb[3]].map(part => Number(part).toString(16).padStart(2, '0')).join('').toUpperCase();
13
+ }
14
+ const hex = /^#?([0-9a-f]{3}|[0-9a-f]{6})$/i.exec(text);
15
+ if (!hex)
16
+ return undefined;
17
+ const digits = hex[1];
18
+ return (digits.length === 3 ? [...digits].map(d => d + d).join('') : digits).toUpperCase();
19
+ }
20
+ /** Reads the styles a browser computed, when there is a browser */
21
+ function computedStyleReader() {
22
+ if (typeof window === 'undefined' || typeof window.getComputedStyle !== 'function')
23
+ return undefined;
24
+ return function styleOf(cell) {
25
+ // The one cast in this file: `HtmlCell` is deliberately not `Element` so the public signature
26
+ // needs no DOM types, and the guard above already proved there is a real DOM behind it.
27
+ const style = window.getComputedStyle(cell);
28
+ const weight = style.fontWeight;
29
+ const align = style.textAlign;
30
+ const size = Number.parseFloat(style.fontSize);
31
+ return {
32
+ color: cssColorToHex(style.color),
33
+ fill: cssColorToHex(style.backgroundColor),
34
+ bold: weight === 'bold' || Number(weight) >= 600,
35
+ italic: style.fontStyle === 'italic',
36
+ // CSS reports px; PowerPoint wants points
37
+ fontSize: Number.isFinite(size) && size > 0 ? Math.round((size * 72) / 96) : undefined,
38
+ fontFace: style.fontFamily ? style.fontFamily.split(',')[0].replace(/["']/g, '').trim() : undefined,
39
+ align: align === 'center' || align === 'right' ? align : 'left',
40
+ };
41
+ };
42
+ }
43
+ function isHeaderRow(row) {
44
+ const cells = Array.from({ length: row.cells.length }, (_, i) => row.cells[i]);
45
+ return cells.length > 0 && cells.every(cell => (cell.tagName ?? '').toUpperCase() === 'TH');
46
+ }
47
+ /**
48
+ * Reproduce an HTML table as a PowerPoint table, across as many slides as it needs.
49
+ *
50
+ * A measured counterpart to the core `tableToSlides`: this one measures the text, and takes the
51
+ * table as an object rather than an element id so it is not tied to a live document.
52
+ *
53
+ * @example
54
+ * tableFromHtml(pres, document.getElementById('report'), { x: 0.5, y: 0.5, w: 9, fontSize: 10 })
55
+ */
56
+ export function tableFromHtml(pres, table, props = {}) {
57
+ const { styleOf = computedStyleReader(), detectHeaderRows = true, ...paginateProps } = props;
58
+ if (!table || !table.rows || table.rows.length === 0)
59
+ throw new Error('tableFromHtml: the table has no rows');
60
+ const htmlRows = Array.from({ length: table.rows.length }, (_, i) => table.rows[i]);
61
+ const rows = htmlRows.map(htmlRow => {
62
+ const cells = Array.from({ length: htmlRow.cells.length }, (_, i) => htmlRow.cells[i]);
63
+ return cells.map((cell) => {
64
+ const style = styleOf ? styleOf(cell) : {};
65
+ const isHeader = (cell.tagName ?? '').toUpperCase() === 'TH';
66
+ const options = {
67
+ ...(style.color ? { color: style.color } : {}),
68
+ ...(style.fill ? { fill: { color: style.fill } } : {}),
69
+ ...(style.bold ?? isHeader ? { bold: true } : {}),
70
+ ...(style.italic ? { italic: true } : {}),
71
+ ...(style.fontSize ? { fontSize: style.fontSize } : {}),
72
+ ...(style.fontFace ? { fontFace: style.fontFace } : {}),
73
+ ...(style.align ? { align: style.align } : {}),
74
+ ...(cell.colSpan && cell.colSpan > 1 ? { colspan: cell.colSpan } : {}),
75
+ ...(cell.rowSpan && cell.rowSpan > 1 ? { rowspan: cell.rowSpan } : {}),
76
+ };
77
+ return { text: (cell.textContent ?? '').trim(), options };
78
+ });
79
+ });
80
+ let repeatHeaderRows = paginateProps.repeatHeaderRows;
81
+ if (repeatHeaderRows === undefined && detectHeaderRows) {
82
+ let leading = 0;
83
+ while (leading < htmlRows.length - 1 && isHeaderRow(htmlRows[leading]))
84
+ leading++;
85
+ repeatHeaderRows = leading;
86
+ }
87
+ return paginateTable(pres, rows, { ...paginateProps, repeatHeaderRows });
88
+ }
89
+ //# sourceMappingURL=from-html.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"from-html.js","sourceRoot":"","sources":["../../src/tables/from-html.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAA8F,MAAM,YAAY,CAAA;AA+CtI,yFAAyF;AACzF,MAAM,UAAU,aAAa,CAAE,KAAgC;IAC9D,IAAI,CAAC,KAAK;QAAE,OAAO,SAAS,CAAA;IAC5B,MAAM,IAAI,GAAG,KAAK,CAAC,IAAI,EAAE,CAAA;IAEzB,MAAM,GAAG,GAAG,sEAAsE,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;IAC7F,IAAI,GAAG,EAAE,CAAC;QACT,4CAA4C;QAC5C,IAAI,GAAG,CAAC,CAAC,CAAC,KAAK,SAAS,IAAI,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC;YAAE,OAAO,SAAS,CAAA;QAClE,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,WAAW,EAAE,CAAA;IAC/G,CAAC;IAED,MAAM,GAAG,GAAG,gCAAgC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;IACvD,IAAI,CAAC,GAAG;QAAE,OAAO,SAAS,CAAA;IAC1B,MAAM,MAAM,GAAG,GAAG,CAAC,CAAC,CAAC,CAAA;IACrB,OAAO,CAAC,MAAM,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,C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AC,CAAC,CAAC,EAAE,CAAC;gBACvD,GAAG,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,KAAK,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;gBAC9C,GAAG,CAAC,IAAI,CAAC,OAAO,IAAI,IAAI,CAAC,OAAO,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,IAAI,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;gBACtE,GAAG,CAAC,IAAI,CAAC,OAAO,IAAI,IAAI,CAAC,OAAO,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,IAAI,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;aACtE,CAAA;YACD,OAAO,EAAE,IAAI,EAAE,CAAC,IAAI,CAAC,WAAW,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,EAAE,OAAO,EAAE,CAAA;QAC1D,CAAC,CAAC,CAAA;IACH,CAAC,CAAC,CAAA;IAEF,IAAI,gBAAgB,GAAG,aAAa,CAAC,gBAAgB,CAAA;IACrD,IAAI,gBAAgB,KAAK,SAAS,IAAI,gBAAgB,EAAE,CAAC;QACxD,IAAI,OAAO,GAAG,CAAC,CAAA;QACf,OAAO,OAAO,GAAG,QAAQ,CAAC,MAAM,GAAG,CAAC,IAAI,WAAW,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;YAAE,OAAO,EAAE,CAAA;QACjF,gBAAgB,GAAG,OAAO,CAAA;IAC3B,CAAC;IAED,OAAO,aAAa,CAAC,IAAI,EAAE,IAAI,EAAE,EAAE,GAAG,aAAa,EAAE,gBAAgB,EAAE,CAAC,CAAA;AACzE,CAAC"}
@@ -0,0 +1,4 @@
1
+ export { paginateTable } from './paginate';
2
+ export type { PaginateTableProps, PaginateTableResult, TableSlide, TablePresentation } from './paginate';
3
+ export { tableFromHtml, cssColorToHex } from './from-html';
4
+ export type { TableFromHtmlProps, HtmlTable, HtmlRow, HtmlCell, CellStyle } from './from-html';
@@ -0,0 +1,3 @@
1
+ export { paginateTable } from './paginate';
2
+ export { tableFromHtml, cssColorToHex } from './from-html';
3
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/tables/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,YAAY,CAAA;AAE1C,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA"}
@@ -0,0 +1,59 @@
1
+ import type PptxGenJS from 'pptxgenjs-plus';
2
+ /**
3
+ * The slice of `Slide` this helper needs.
4
+ *
5
+ * Structural rather than `PptxGenJS.Slide` so any object with a conforming `addTable` works,
6
+ * including a test double.
7
+ */
8
+ export interface TableSlide<R = PptxGenJS.TableRow> {
9
+ addTable: (rows: R[], options?: PptxGenJS.TableProps) => unknown;
10
+ }
11
+ /**
12
+ * The slice of `PptxGenJS` this helper needs: somewhere to put the slides it creates.
13
+ *
14
+ * The row type is a parameter so the rows come back out the way they went in, and so a slide whose
15
+ * `addTable` is stricter than the published `TableRow` still conforms.
16
+ */
17
+ export interface TablePresentation<S extends TableSlide<R>, R = PptxGenJS.TableRow> {
18
+ addSlide: (options?: {
19
+ masterName?: string;
20
+ sectionTitle?: string;
21
+ }) => S;
22
+ presLayout?: {
23
+ width: number;
24
+ height: number;
25
+ };
26
+ }
27
+ export interface PaginateTableProps extends Omit<PptxGenJS.TableProps, 'h' | 'autoPage'> {
28
+ /** Rows repeated at the top of every slide @default 0 */
29
+ repeatHeaderRows?: number;
30
+ /** `y` for tables on the slides after the first, inches @default the initial `y` */
31
+ continueY?: number;
32
+ /** Master slide applied to every slide this creates */
33
+ masterName?: string;
34
+ /** Bottom of the usable area, measured from the slide bottom, inches @default 0.5 */
35
+ bottomMargin?: number;
36
+ /** Slide height override, inches - taken from `presLayout` when available @default 5.625 */
37
+ slideHeight?: number;
38
+ }
39
+ export interface PaginateTableResult<S> {
40
+ /** Every slide created, in order */
41
+ slides: S[];
42
+ /** Rows placed on each slide, header repeats included */
43
+ rowsPerSlide: number[];
44
+ /** Whether any measurement fell back to a guess - see `measureText`'s `source` */
45
+ estimated: boolean;
46
+ }
47
+ /**
48
+ * Add a table across as many slides as its rows need, measuring the text instead of estimating it.
49
+ *
50
+ * An additional pager alongside the core `autoPage`: that path guesses wraps from a per-character
51
+ * constant (`autoPageCharWeight`). This wraps each cell with {@link measureText} - real advance
52
+ * widths where they are known - so the row heights it adds up are the ones PowerPoint will lay out.
53
+ *
54
+ * Options other than the paging ones are passed straight through to `addTable`, once per slide.
55
+ *
56
+ * @example
57
+ * paginateTable(pres, rows, { x: 0.5, y: 0.5, w: 9, repeatHeaderRows: 1, fontSize: 11 })
58
+ */
59
+ export declare function paginateTable<R extends PptxGenJS.TableRow, S extends TableSlide<R>>(pres: TablePresentation<S, R>, rows: R[], props?: PaginateTableProps): PaginateTableResult<S>;
@@ -0,0 +1,135 @@
1
+ import { measureText } from '../text/measure';
2
+ /** Default slide size (LAYOUT_16x9), inches */
3
+ const DEFAULT_SLIDE = { w: 10, h: 5.625 };
4
+ /** The core's "Normal" cell margins in PowerPoint 2021, inches - TRBL */
5
+ const DEFAULT_CELL_MARGIN = [0.05, 0.1, 0.05, 0.1];
6
+ const EMU_PER_IN = 914400;
7
+ /** Cell text flattened to a string; nested runs concatenate, as they render on one line flow */
8
+ function cellText(cell) {
9
+ if (typeof cell.text === 'string')
10
+ return cell.text;
11
+ if (Array.isArray(cell.text))
12
+ return cell.text.map(cellText).join('');
13
+ return cell.text === undefined ? '' : String(cell.text);
14
+ }
15
+ function resolveMargin(margin) {
16
+ if (margin === undefined)
17
+ return DEFAULT_CELL_MARGIN;
18
+ if (typeof margin === 'number')
19
+ return [margin, margin, margin, margin];
20
+ if (Array.isArray(margin) && margin.length === 4)
21
+ return margin.map(Number);
22
+ return DEFAULT_CELL_MARGIN;
23
+ }
24
+ /** Column widths in inches: explicit `colW` if given, otherwise the table width split evenly */
25
+ function resolveColumnWidths(rows, tableW, colW) {
26
+ const columns = rows.reduce((max, row) => Math.max(max, row.reduce((n, cell) => n + (cell.options?.colspan ?? 1), 0)), 0);
27
+ if (columns === 0)
28
+ throw new Error('paginateTable: rows have no cells');
29
+ if (typeof colW === 'number')
30
+ return Array.from({ length: columns }, () => colW);
31
+ if (Array.isArray(colW) && colW.length > 0) {
32
+ if (colW.length !== columns)
33
+ throw new Error(`paginateTable: colW has ${colW.length} widths for ${columns} columns`);
34
+ return colW.map(Number);
35
+ }
36
+ return Array.from({ length: columns }, () => tableW / columns);
37
+ }
38
+ /**
39
+ * Add a table across as many slides as its rows need, measuring the text instead of estimating it.
40
+ *
41
+ * An additional pager alongside the core `autoPage`: that path guesses wraps from a per-character
42
+ * constant (`autoPageCharWeight`). This wraps each cell with {@link measureText} - real advance
43
+ * widths where they are known - so the row heights it adds up are the ones PowerPoint will lay out.
44
+ *
45
+ * Options other than the paging ones are passed straight through to `addTable`, once per slide.
46
+ *
47
+ * @example
48
+ * paginateTable(pres, rows, { x: 0.5, y: 0.5, w: 9, repeatHeaderRows: 1, fontSize: 11 })
49
+ */
50
+ export function paginateTable(pres, rows, props = {}) {
51
+ const { repeatHeaderRows = 0, continueY, masterName, bottomMargin = 0.5, slideHeight, ...tableProps } = props;
52
+ if (!Array.isArray(rows) || rows.length === 0)
53
+ throw new Error('paginateTable: at least one row is required');
54
+ if (!Number.isInteger(repeatHeaderRows) || repeatHeaderRows < 0)
55
+ throw new Error(`paginateTable: repeatHeaderRows must be an integer >= 0 (got ${repeatHeaderRows})`);
56
+ if (repeatHeaderRows >= rows.length)
57
+ throw new Error(`paginateTable: repeatHeaderRows ${repeatHeaderRows} leaves no body rows`);
58
+ const layoutH = slideHeight ?? (pres.presLayout ? pres.presLayout.height / EMU_PER_IN : DEFAULT_SLIDE.h);
59
+ const layoutW = pres.presLayout ? pres.presLayout.width / EMU_PER_IN : DEFAULT_SLIDE.w;
60
+ const x = typeof tableProps.x === 'number' ? tableProps.x : 0.5;
61
+ const y = typeof tableProps.y === 'number' ? tableProps.y : 0.5;
62
+ const tableW = typeof tableProps.w === 'number' ? tableProps.w : layoutW - x * 2;
63
+ if (!(tableW > 0))
64
+ throw new Error(`paginateTable: table width must be > 0 (got ${tableW})`);
65
+ const startY = continueY ?? y;
66
+ const columnWidths = resolveColumnWidths(rows, tableW, tableProps.colW);
67
+ const [marginTop, marginRight, marginBottom, marginLeft] = resolveMargin(tableProps.margin);
68
+ let estimated = false;
69
+ /** `rowH` is a table-level floor, per row or one value for all of them */
70
+ const minHeightOf = (index) => {
71
+ const rowH = tableProps.rowH;
72
+ if (typeof rowH === 'number')
73
+ return rowH;
74
+ if (Array.isArray(rowH))
75
+ return rowH[index] ?? 0;
76
+ return 0;
77
+ };
78
+ /** Height one row occupies: its tallest cell, measured at that cell's column width */
79
+ const heightOf = (row, index) => {
80
+ let tallest = minHeightOf(index);
81
+ let column = 0;
82
+ for (const cell of row) {
83
+ const span = cell.options?.colspan ?? 1;
84
+ const width = columnWidths.slice(column, column + span).reduce((a, b) => a + b, 0);
85
+ column += span;
86
+ const usable = width - marginLeft - marginRight;
87
+ const measured = measureText(cellText(cell), {
88
+ fontFace: cell.options?.fontFace ?? tableProps.fontFace,
89
+ fontSize: cell.options?.fontSize ?? tableProps.fontSize ?? 12,
90
+ bold: cell.options?.bold ?? tableProps.bold,
91
+ italic: cell.options?.italic ?? tableProps.italic,
92
+ // A column narrower than its own margins cannot be measured; fall back to one line
93
+ w: usable > 0 ? usable : undefined,
94
+ });
95
+ if (measured.source === 'estimate')
96
+ estimated = true;
97
+ tallest = Math.max(tallest, measured.h + marginTop + marginBottom);
98
+ }
99
+ return tallest;
100
+ };
101
+ const header = rows.slice(0, repeatHeaderRows);
102
+ const body = rows.slice(repeatHeaderRows);
103
+ const headerHeight = header.reduce((total, row, index) => total + heightOf(row, index), 0);
104
+ // Chunk body rows by measured height. The first slide starts at `y`, the rest at `continueY`.
105
+ const chunks = [];
106
+ let current = [];
107
+ let used = 0;
108
+ let available = layoutH - y - bottomMargin - headerHeight;
109
+ body.forEach((row, index) => {
110
+ const height = heightOf(row, repeatHeaderRows + index);
111
+ if (current.length > 0 && used + height > available) {
112
+ chunks.push(current);
113
+ current = [];
114
+ used = 0;
115
+ available = layoutH - startY - bottomMargin - headerHeight;
116
+ }
117
+ current.push(row);
118
+ used += height;
119
+ });
120
+ if (current.length > 0)
121
+ chunks.push(current);
122
+ if (available <= 0 && chunks.length === 0)
123
+ throw new Error(`paginateTable: no usable height on a ${layoutH}" slide below y ${y}`);
124
+ const slides = [];
125
+ const rowsPerSlide = [];
126
+ chunks.forEach((chunk, index) => {
127
+ const slide = pres.addSlide(masterName ? { masterName } : undefined);
128
+ const slideRows = [...header, ...chunk];
129
+ slide.addTable(slideRows, { ...tableProps, x, y: index === 0 ? y : startY, w: tableW, colW: columnWidths });
130
+ slides.push(slide);
131
+ rowsPerSlide.push(slideRows.length);
132
+ });
133
+ return { slides, rowsPerSlide, estimated };
134
+ }
135
+ //# sourceMappingURL=paginate.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"paginate.js","sourceRoot":"","sources":["../../src/tables/paginate.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAA;AAE7C,+CAA+C;AAC/C,MAAM,aAAa,GAAG,EAAE,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,KAAK,EAAE,CAAA;AACzC,yEAAyE;AACzE,MAAM,mBAAmB,GAAqC,CAAC,IAAI,EAAE,GAAG,EAAE,IAAI,EAAE,GAAG,CAAC,CAAA;AACpF,MAAM,UAAU,GAAG,MAAM,CAAA;AA6CzB,gGAAgG;AAChG,SAAS,QAAQ,CAAE,IAAyB;IAC3C,IAAI,OAAO,IAAI,CAAC,IAAI,KAAK,QAAQ;QAAE,OAAO,IAAI,CAAC,IAAI,CAAA;IACnD,IAAI,KAAK,CAAC,OA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,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;IAE5C,IAAI,SAAS,IAAI,CAAC,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC;QAAE,MAAM,IAAI,KAAK,CAAC,wCAAwC,OAAO,mBAAmB,CAAC,EAAE,CAAC,CAAA;IAEjI,MAAM,MAAM,GAAQ,EAAE,CAAA;IACtB,MAAM,YAAY,GAAa,EAAE,CAAA;IACjC,MAAM,CAAC,OAAO,CAAC,CAAC,KAAK,EAAE,KAAK,EAAE,EAAE;QAC/B,MAAM,KAAK,GAAG,IAAI,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC,CAAC,EAAE,UAAU,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC,CAAA;QACpE,MAAM,SAAS,GAAG,CAAC,GAAG,MAAM,EAAE,GAAG,KAAK,CAAC,CAAA;QACvC,KAAK,CAAC,QAAQ,CAAC,SAAS,EAAE,EAAE,GAAG,UAAU,EAAE,CAAC,EAAE,CAAC,EAAE,KAAK,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,IAAI,EAAE,YAAY,EAAE,CAAC,CAAA;QAC3G,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;QAClB,YAAY,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,CAAA;IACpC,CAAC,CAAC,CAAA;IAEF,OAAO,EAAE,MAAM,EAAE,YAAY,EAAE,SAAS,EAAE,CAAA;AAC3C,CAAC"}
@@ -0,0 +1,63 @@
1
+ import { type MeasureProps, type Measurement } from './measure';
2
+ export interface FitTextArea {
3
+ /** Available width, inches */
4
+ w: number;
5
+ /** Available height, inches */
6
+ h: number;
7
+ }
8
+ export interface FitTextProps extends Omit<MeasureProps, 'w' | 'fontSize'> {
9
+ /** Smallest size to consider, points @default 8 */
10
+ min?: number;
11
+ /** Largest size to consider, points @default 40 */
12
+ max?: number;
13
+ /**
14
+ * Text-box margin subtracted from the area before fitting, inches.
15
+ * The core's default cell margin is 0.05 vertical / 0.1 horizontal. @default 0
16
+ */
17
+ margin?: number | [number, number, number, number];
18
+ }
19
+ export interface FitTextResult extends Measurement {
20
+ /** The largest size in range whose wrapped text fits the area, points */
21
+ fontSize: number;
22
+ /** True when even `min` overflows - the text is too long for the area at any size in range */
23
+ overflows: boolean;
24
+ }
25
+ /**
26
+ * Largest font size at which text fits a box.
27
+ *
28
+ * `fit: 'shrink'` makes PowerPoint do this at render time, but the result is not readable back -
29
+ * so it cannot inform anything else on the slide. This computes it up front.
30
+ *
31
+ * @example
32
+ * const { fontSize, h } = fitText({ w: 4, h: 2 }, headline)
33
+ * slide.addText(headline, { x: 1, y: 1, w: 4, h: 2, fontSize })
34
+ */
35
+ export declare function fitText(area: FitTextArea, text: string, props?: FitTextProps): FitTextResult;
36
+ export interface CheckOverflowProps extends Omit<MeasureProps, 'w'> {
37
+ /**
38
+ * Text-box margin subtracted from the area before measuring, inches.
39
+ * The core's default cell margin is 0.05 vertical / 0.1 horizontal. @default 0
40
+ */
41
+ margin?: number | [number, number, number, number];
42
+ }
43
+ export interface OverflowResult extends Measurement {
44
+ /** True when the wrapped text does not fit the area at this size */
45
+ overflows: boolean;
46
+ /** Inches the wrapped text exceeds the area height by, 0 when it fits */
47
+ overflowBy: number;
48
+ }
49
+ /**
50
+ * Whether text fits a box at a given size, and by how much it does not.
51
+ *
52
+ * `fitText` answers "what size fits"; this answers "does this size fit", which is the question a
53
+ * QA pass over an already-built deck asks. PowerPoint silently spills text past a shape, so an
54
+ * overflowing box looks correct in the file and wrong on the screen.
55
+ *
56
+ * Height only: `measureText` breaks a word too long for the line, so measured width never exceeds
57
+ * the box. PowerPoint spills such a word instead - `lines` shows where the break was assumed.
58
+ *
59
+ * @example
60
+ * const { overflows, overflowBy } = checkOverflow(box, body, { fontSize: 11 })
61
+ * if (overflows) findings.push(`text exceeds its box by ${overflowBy.toFixed(2)}in`)
62
+ */
63
+ export declare function checkOverflow(area: FitTextArea, text: string, props?: CheckOverflowProps): OverflowResult;
@@ -0,0 +1,82 @@
1
+ import { measureText } from './measure';
2
+ /** TRBL inches, from a number or an explicit tuple */
3
+ function resolveMargin(margin) {
4
+ if (margin === undefined)
5
+ return [0, 0, 0, 0];
6
+ if (typeof margin === 'number')
7
+ return [margin, margin, margin, margin];
8
+ return margin;
9
+ }
10
+ /**
11
+ * Largest font size at which text fits a box.
12
+ *
13
+ * `fit: 'shrink'` makes PowerPoint do this at render time, but the result is not readable back -
14
+ * so it cannot inform anything else on the slide. This computes it up front.
15
+ *
16
+ * @example
17
+ * const { fontSize, h } = fitText({ w: 4, h: 2 }, headline)
18
+ * slide.addText(headline, { x: 1, y: 1, w: 4, h: 2, fontSize })
19
+ */
20
+ export function fitText(area, text, props = {}) {
21
+ const { min = 8, max = 40, margin, ...measureProps } = props;
22
+ if (!(area.w > 0) || !(area.h > 0))
23
+ throw new Error(`fitText: area must have positive w and h (got ${area.w}x${area.h})`);
24
+ if (!(min > 0))
25
+ throw new Error(`fitText: min must be > 0 (got ${min})`);
26
+ if (max < min)
27
+ throw new Error(`fitText: max ${max} is below min ${min}`);
28
+ const [top, right, bottom, left] = resolveMargin(margin);
29
+ const w = area.w - left - right;
30
+ const h = area.h - top - bottom;
31
+ if (!(w > 0) || !(h > 0))
32
+ throw new Error(`fitText: margin leaves no room in ${area.w}x${area.h}`);
33
+ const measure = (fontSize) => measureText(text, { ...measureProps, fontSize, w });
34
+ const fits = (fontSize) => {
35
+ const result = measure(fontSize);
36
+ return result.h <= h && result.w <= w;
37
+ };
38
+ // Whole points only, which is what the PowerPoint UI offers. Binary search over the range: the
39
+ // fits/does-not-fit boundary is monotonic in font size.
40
+ let low = Math.ceil(min);
41
+ let high = Math.floor(max);
42
+ if (!fits(low)) {
43
+ const result = measure(low);
44
+ return { ...result, fontSize: low, overflows: true };
45
+ }
46
+ while (low < high) {
47
+ const mid = Math.ceil((low + high) / 2);
48
+ if (fits(mid))
49
+ low = mid;
50
+ else
51
+ high = mid - 1;
52
+ }
53
+ return { ...measure(low), fontSize: low, overflows: false };
54
+ }
55
+ /**
56
+ * Whether text fits a box at a given size, and by how much it does not.
57
+ *
58
+ * `fitText` answers "what size fits"; this answers "does this size fit", which is the question a
59
+ * QA pass over an already-built deck asks. PowerPoint silently spills text past a shape, so an
60
+ * overflowing box looks correct in the file and wrong on the screen.
61
+ *
62
+ * Height only: `measureText` breaks a word too long for the line, so measured width never exceeds
63
+ * the box. PowerPoint spills such a word instead - `lines` shows where the break was assumed.
64
+ *
65
+ * @example
66
+ * const { overflows, overflowBy } = checkOverflow(box, body, { fontSize: 11 })
67
+ * if (overflows) findings.push(`text exceeds its box by ${overflowBy.toFixed(2)}in`)
68
+ */
69
+ export function checkOverflow(area, text, props = {}) {
70
+ const { margin, ...measureProps } = props;
71
+ if (!(area.w > 0) || !(area.h > 0))
72
+ throw new Error(`checkOverflow: area must have positive w and h (got ${area.w}x${area.h})`);
73
+ const [top, right, bottom, left] = resolveMargin(margin);
74
+ const w = area.w - left - right;
75
+ const h = area.h - top - bottom;
76
+ if (!(w > 0) || !(h > 0))
77
+ throw new Error(`checkOverflow: margin leaves no room in ${area.w}x${area.h}`);
78
+ const result = measureText(text, { ...measureProps, w });
79
+ const overflowBy = Math.max(0, result.h - h);
80
+ return { ...result, overflows: overflowBy > 0, overflowBy };
81
+ }
82
+ //# sourceMappingURL=fit.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fit.js","sourceRoot":"","sources":["../../src/text/fit.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAuC,MAAM,WAAW,CAAA;AA4B5E,sDAAsD;AACtD,SAAS,aAAa,CAAE,MAA8B;IACrD,IAAI,MAAM,KAAK,SAAS;QAAE,OAAO,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAA;IAC7C,IAAI,OAAO,MAAM,KAAK,QAAQ;QAAE,OAAO,CAAC,MAAM,E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CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC;QAAE,MAAM,IAAI,KAAK,CAAC,uDAAuD,IAAI,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC,GAAG,CAAC,CAAA;IAE/H,MAAM,CAAC,GAAG,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,CAAC,GAAG,aAAa,CAAC,MAAM,CAAC,CAAA;IACxD,MAAM,CAAC,GAAG,IAAI,CAAC,CAAC,GAAG,IAAI,GAAG,KAAK,CAAA;IAC/B,MAAM,CAAC,GAAG,IAAI,CAAC,CAAC,GAAG,GAAG,GAAG,MAAM,CAAA;IAC/B,IAAI,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;QAAE,MAAM,IAAI,KAAK,CAAC,2CAA2C,IAAI,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC,EAAE,CAAC,CAAA;IAExG,MAAM,MAAM,GAAG,WAAW,CAAC,IAAI,EAAE,EAAE,GAAG,YAAY,EAAE,CAAC,EAAE,CAAC,CAAA;IACxD,MAAM,UAAU,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC,GAAG,CAAC,CAAC,CAAA;IAE5C,OAAO,EAAE,GAAG,MAAM,EAAE,SAAS,EAAE,UAAU,GAAG,CAAC,EAAE,UAAU,EAAE,CAAA;AAC5D,CAAC"}
@@ -0,0 +1,4 @@
1
+ export { measureText, registerFontMetrics } from './measure';
2
+ export type { MeasureProps, Measurement, FontMetrics, RegisterFontMetricsProps } from './measure';
3
+ export { fitText, checkOverflow } from './fit';
4
+ export type { FitTextArea, FitTextProps, FitTextResult, CheckOverflowProps, OverflowResult } from './fit';
@@ -0,0 +1,3 @@
1
+ export { measureText, registerFontMetrics } from './measure';
2
+ export { fitText, checkOverflow } from './fit';
3
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/text/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,mBAAmB,EAAE,MAAM,WAAW,CAAA;AAE5D,OAAO,EAAE,OAAO,EAAE,aAAa,EAAE,MAAM,OAAO,CAAA"}
@@ -0,0 +1,78 @@
1
+ export interface FontMetrics {
2
+ /** Advance width per codepoint, in ems */
3
+ widths: Map<number, number>;
4
+ /** Advance width for a codepoint the font does not cover, in ems */
5
+ fallbackWidth: number;
6
+ /** Distance from baseline to the top of the line box, in ems */
7
+ ascent: number;
8
+ /** Distance from baseline to the bottom of the line box, in ems (negative) */
9
+ descent: number;
10
+ /** Extra leading between lines, in ems */
11
+ lineGap: number;
12
+ }
13
+ export interface MeasureProps {
14
+ /** Typeface name, matched case-insensitively @default 'Calibri' */
15
+ fontFace?: string;
16
+ /** Font size in points @default 12 */
17
+ fontSize?: number;
18
+ bold?: boolean;
19
+ italic?: boolean;
20
+ /**
21
+ * Wrap width in inches. Omit to measure the text as a single unbroken line.
22
+ * Text boxes reduce this by their `margin`; pass the width you actually have for text.
23
+ */
24
+ w?: number;
25
+ /** Line spacing as a multiple of the single-line height @default 1 */
26
+ lineSpacingMultiple?: number;
27
+ }
28
+ export interface Measurement {
29
+ /** Width of the widest line, inches */
30
+ w: number;
31
+ /** Total height of every line, inches */
32
+ h: number;
33
+ /** The text as it wraps at the given width */
34
+ lines: string[];
35
+ /** Height of one line, inches */
36
+ lineHeight: number;
37
+ /** Where the numbers came from - `'estimate'` means no metrics were available */
38
+ source: 'canvas' | 'metrics' | 'estimate';
39
+ }
40
+ export interface RegisterFontMetricsProps {
41
+ /** Advance width per character, in ems - `{ ' ': 0.226, M: 0.855 }` or codepoint keys */
42
+ widths: Record<string, number> | Map<number, number>;
43
+ /** Advance width for uncovered characters, in ems @default the width of a space, else 0.5 */
44
+ fallbackWidth?: number;
45
+ /** Baseline to line-box top, in ems @default 1 */
46
+ ascent?: number;
47
+ /** Baseline to line-box bottom, in ems, negative @default -0.25 */
48
+ descent?: number;
49
+ /** Extra leading, in ems @default 0 */
50
+ lineGap?: number;
51
+ }
52
+ /**
53
+ * Teach `measureText` a font it does not ship metrics for.
54
+ *
55
+ * Bundled metrics cover Calibri (via the metric-compatible Carlito) in all four styles. Register
56
+ * a style by its full name as used in text options plus the style suffix - `'Aptos Bold'` - so
57
+ * `measureText('...', { fontFace: 'Aptos', bold: true })` finds it.
58
+ *
59
+ * @example
60
+ * registerFontMetrics('Aptos', { widths: { ' ': 0.22, a: 0.5 }, ascent: 0.94, descent: -0.27 })
61
+ */
62
+ export declare function registerFontMetrics(fontFace: string, props: RegisterFontMetricsProps): void;
63
+ /**
64
+ * Measure text the way a renderer would, in inches.
65
+ *
66
+ * Uses the best source available: a browser 2D canvas, then bundled advance widths (Calibri via
67
+ * the metric-compatible Carlito), then a flat per-character estimate. Check `source` on the result
68
+ * when it matters - `'estimate'` means the numbers are a guess, and
69
+ * {@link registerFontMetrics} is how to fix that.
70
+ *
71
+ * PowerPoint substitutes a different font when the viewer's machine lacks yours and re-wraps with
72
+ * its metrics, so treat the result as accurate-for-this-font rather than guaranteed.
73
+ *
74
+ * @example
75
+ * const { h, lines } = measureText('a long paragraph...', { w: 4, fontSize: 14 })
76
+ * slide.addText(text, { x: 1, y: 1, w: 4, h })
77
+ */
78
+ export declare function measureText(text: string, props?: MeasureProps): Measurement;
@@ -0,0 +1,192 @@
1
+ import { RAW_METRICS } from './metrics-data';
2
+ /** Points per inch - every `addX` option is in inches, every font size is in points */
3
+ const PT_PER_IN = 72;
4
+ /**
5
+ * Average advance width, in ems, used when nothing better is available.
6
+ *
7
+ * The core's own auto-paging constant works out to roughly this, and it is the reason
8
+ * `autoPageCharWeight` exists: one number cannot describe a proportional font. Kept only so
9
+ * `measureText` always returns something, and reported as `source: 'estimate'` so callers can
10
+ * tell they are getting a guess.
11
+ */
12
+ const ESTIMATED_CHAR_WIDTH = 0.5;
13
+ /** Line height in ems when the font's own ascent/descent are unknown */
14
+ const ESTIMATED_LINE_HEIGHT = 1.2;
15
+ /** Parsed `RAW_METRICS` plus anything `registerFontMetrics` added, keyed by lowercased name */
16
+ const registry = new Map();
17
+ /** `codepoint:count:width` runs, per-mille of the em */
18
+ function decodeWidths(encoded) {
19
+ const widths = new Map();
20
+ for (const run of encoded.split(',')) {
21
+ const [start, count, width] = run.split(':').map(Number);
22
+ for (let i = 0; i < count; i++)
23
+ widths.set(start + i, width / 1000);
24
+ }
25
+ return widths;
26
+ }
27
+ for (const [name, raw] of Object.entries(RAW_METRICS)) {
28
+ registry.set(name, {
29
+ widths: decodeWidths(raw.widths),
30
+ fallbackWidth: raw.fallbackWidth / 1000,
31
+ ascent: raw.ascent / 1000,
32
+ descent: raw.descent / 1000,
33
+ lineGap: raw.lineGap / 1000,
34
+ });
35
+ }
36
+ /**
37
+ * Teach `measureText` a font it does not ship metrics for.
38
+ *
39
+ * Bundled metrics cover Calibri (via the metric-compatible Carlito) in all four styles. Register
40
+ * a style by its full name as used in text options plus the style suffix - `'Aptos Bold'` - so
41
+ * `measureText('...', { fontFace: 'Aptos', bold: true })` finds it.
42
+ *
43
+ * @example
44
+ * registerFontMetrics('Aptos', { widths: { ' ': 0.22, a: 0.5 }, ascent: 0.94, descent: -0.27 })
45
+ */
46
+ export function registerFontMetrics(fontFace, props) {
47
+ if (!fontFace || typeof fontFace !== 'string')
48
+ throw new Error('registerFontMetrics: fontFace is required');
49
+ const widths = new Map();
50
+ if (props.widths instanceof Map) {
51
+ for (const [code, width] of props.widths)
52
+ widths.set(code, width);
53
+ }
54
+ else {
55
+ for (const [key, width] of Object.entries(props.widths)) {
56
+ const code = key.length === 1 ? key.codePointAt(0) : Number(key);
57
+ if (code === undefined || !Number.isInteger(code))
58
+ throw new Error(`registerFontMetrics: "${key}" is neither a single character nor a codepoint`);
59
+ widths.set(code, width);
60
+ }
61
+ }
62
+ if (widths.size === 0)
63
+ throw new Error('registerFontMetrics: widths is empty');
64
+ registry.set(fontFace.toLowerCase(), {
65
+ widths,
66
+ fallbackWidth: props.fallbackWidth ?? widths.get(0x20) ?? ESTIMATED_CHAR_WIDTH,
67
+ ascent: props.ascent ?? 1,
68
+ descent: props.descent ?? -0.25,
69
+ lineGap: props.lineGap ?? 0,
70
+ });
71
+ }
72
+ /** Metrics for the requested face+style, or undefined when none are registered */
73
+ function lookup(fontFace, bold, italic) {
74
+ const suffix = `${bold ? ' bold' : ''}${italic ? ' italic' : ''}`;
75
+ // Fall back to the regular weight rather than to nothing: right glyph set, wrong weight beats a
76
+ // flat 0.5em guess for every character.
77
+ return registry.get(`${fontFace.toLowerCase()}${suffix}`) ?? registry.get(fontFace.toLowerCase());
78
+ }
79
+ /** A 2D canvas is the only accurate measurement available in a browser, and it needs no data */
80
+ function canvasContext() {
81
+ if (typeof document === 'undefined' || typeof document.createElement !== 'function')
82
+ return undefined;
83
+ try {
84
+ const context = document.createElement('canvas').getContext('2d');
85
+ return context ?? undefined;
86
+ }
87
+ catch {
88
+ return undefined;
89
+ }
90
+ }
91
+ function ruler(fontFace, fontSize, bold, italic) {
92
+ const metrics = lookup(fontFace, bold, italic);
93
+ const context = canvasContext();
94
+ if (context) {
95
+ // Measure at a fixed size and divide, so the ruler stays in ems like the other tiers
96
+ const probe = 100;
97
+ const style = `${italic ? 'italic ' : ''}${bold ? 'bold ' : ''}${probe}px "${fontFace}"`;
98
+ context.font = style;
99
+ return {
100
+ widthOf: text => context.measureText(text).width / probe,
101
+ lineHeight: metrics ? metrics.ascent - metrics.descent + metrics.lineGap : ESTIMATED_LINE_HEIGHT,
102
+ source: 'canvas',
103
+ };
104
+ }
105
+ if (metrics) {
106
+ return {
107
+ widthOf: text => {
108
+ let total = 0;
109
+ for (const char of text)
110
+ total += metrics.widths.get(char.codePointAt(0) ?? 0) ?? metrics.fallbackWidth;
111
+ return total;
112
+ },
113
+ lineHeight: metrics.ascent - metrics.descent + metrics.lineGap,
114
+ source: 'metrics',
115
+ };
116
+ }
117
+ return {
118
+ widthOf: text => [...text].length * ESTIMATED_CHAR_WIDTH,
119
+ lineHeight: ESTIMATED_LINE_HEIGHT,
120
+ source: 'estimate',
121
+ };
122
+ }
123
+ /** Greedy word wrap: the same algorithm every renderer uses, over whichever ruler is available */
124
+ function wrap(text, maxEm, widthOf) {
125
+ const lines = [];
126
+ for (const paragraph of text.split('\n')) {
127
+ if (paragraph === '') {
128
+ lines.push('');
129
+ continue;
130
+ }
131
+ let line = '';
132
+ for (const word of paragraph.split(' ')) {
133
+ const candidate = line === '' ? word : `${line} ${word}`;
134
+ if (widthOf(candidate) <= maxEm || line === '') {
135
+ // A word wider than the box still starts its own line, then gets broken below
136
+ line = candidate;
137
+ }
138
+ else {
139
+ lines.push(line);
140
+ line = word;
141
+ }
142
+ // Break a word that cannot fit on a line of its own, so nothing silently overflows
143
+ while (widthOf(line) > maxEm && [...line].length > 1) {
144
+ const chars = [...line];
145
+ let cut = chars.length - 1;
146
+ while (cut > 1 && widthOf(chars.slice(0, cut).join('')) > maxEm)
147
+ cut--;
148
+ lines.push(chars.slice(0, cut).join(''));
149
+ line = chars.slice(cut).join('');
150
+ }
151
+ }
152
+ lines.push(line);
153
+ }
154
+ return lines;
155
+ }
156
+ /**
157
+ * Measure text the way a renderer would, in inches.
158
+ *
159
+ * Uses the best source available: a browser 2D canvas, then bundled advance widths (Calibri via
160
+ * the metric-compatible Carlito), then a flat per-character estimate. Check `source` on the result
161
+ * when it matters - `'estimate'` means the numbers are a guess, and
162
+ * {@link registerFontMetrics} is how to fix that.
163
+ *
164
+ * PowerPoint substitutes a different font when the viewer's machine lacks yours and re-wraps with
165
+ * its metrics, so treat the result as accurate-for-this-font rather than guaranteed.
166
+ *
167
+ * @example
168
+ * const { h, lines } = measureText('a long paragraph...', { w: 4, fontSize: 14 })
169
+ * slide.addText(text, { x: 1, y: 1, w: 4, h })
170
+ */
171
+ export function measureText(text, props = {}) {
172
+ const { fontFace = 'Calibri', fontSize = 12, bold = false, italic = false, w, lineSpacingMultiple = 1 } = props;
173
+ if (fontSize <= 0)
174
+ throw new Error(`measureText: fontSize must be > 0 (got ${fontSize})`);
175
+ if (w !== undefined && !(w > 0))
176
+ throw new Error(`measureText: w must be > 0 when given (got ${w})`);
177
+ if (!(lineSpacingMultiple > 0))
178
+ throw new Error(`measureText: lineSpacingMultiple must be > 0 (got ${lineSpacingMultiple})`);
179
+ const { widthOf, lineHeight, source } = ruler(fontFace, fontSize, bold, italic);
180
+ const emToInch = fontSize / PT_PER_IN;
181
+ const lines = w === undefined ? String(text).split('\n') : wrap(String(text), w / emToInch, widthOf);
182
+ const widest = lines.reduce((max, line) => Math.max(max, widthOf(line)), 0);
183
+ const lineHeightIn = lineHeight * emToInch * lineSpacingMultiple;
184
+ return {
185
+ w: widest * emToInch,
186
+ h: lines.length * lineHeightIn,
187
+ lines,
188
+ lineHeight: lineHeightIn,
189
+ source,
190
+ };
191
+ }
192
+ //# sourceMappingURL=measure.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"measure.js","sourceRoot":"","sources":["../../src/text/measure.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAA;AAE5C,uFAAuF;AACvF,MAAM,SAAS,GAAG,EAAE,CAAA;AAEpB;;;;;;;GAOG;AACH,MAAM,oBAAoB,GAAG,GAAG,CAAA;AAEhC,wEAAwE;AACxE,MAAM,qBAAqB,GAAG,GAAG,CAAA;AA4CjC,+FAA+F;AAC/F,MAAM,QAAQ,GAAG,IAAI,GAAG,EAAuB,CAAA;AAE/C,wDAAwD;AACxD,SAAS,YAAY,CAAE,OAAe;IACrC,MAAM,MAAM,GAAG,IAAI,GAAG,EAAkB,CAAA;IACxC,KAAK,MAAM,GAAG,IAAI,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,EAAE,CAAC;QACtC,MAAM,CAAC,KAAK,EAAE,KAAK,EAAE,KAAK,CAAC,GAAG,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,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AI,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;QAAE,MAAM,IAAI,KAAK,CAAC,8CAA8C,CAAC,GAAG,CAAC,CAAA;IACpG,IAAI,CAAC,CAAC,mBAAmB,GAAG,CAAC,CAAC;QAAE,MAAM,IAAI,KAAK,CAAC,qDAAqD,mBAAmB,GAAG,CAAC,CAAA;IAE5H,MAAM,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,EAAE,GAAG,KAAK,CAAC,QAAQ,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,CAAC,CAAA;IAC/E,MAAM,QAAQ,GAAG,QAAQ,GAAG,SAAS,CAAA;IAErC,MAAM,KAAK,GAAG,CAAC,KAAK,SAAS,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,GAAG,QAAQ,EAAE,OAAO,CAAC,CAAA;IACpG,MAAM,MAAM,GAAG,KAAK,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,OAAO,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC,CAAC,CAAA;IAC3E,MAAM,YAAY,GAAG,UAAU,GAAG,QAAQ,GAAG,mBAAmB,CAAA;IAEhE,OAAO;QACN,CAAC,EAAE,MAAM,GAAG,QAAQ;QACpB,CAAC,EAAE,KAAK,CAAC,MAAM,GAAG,YAAY;QAC9B,KAAK;QACL,UAAU,EAAE,YAAY;QACxB,MAAM;KACN,CAAA;AACF,CAAC"}
@@ -0,0 +1,18 @@
1
+ /**
2
+ * GENERATED by scripts/extract-font-metrics.mjs - do not edit by hand.
3
+ *
4
+ * Advance widths in per-mille of the em, run-length encoded as `codepoint:count:width`.
5
+ * No kerning or ligature data, so a measured run is marginally wider than a real renderer's -
6
+ * the safe direction for overflow checks.
7
+ *
8
+ * Carlito (c) 2013 The Carlito Project Authors, SIL Open Font License 1.1. Carlito is
9
+ * metric-compatible with Calibri, so it stands in for it here; no glyph outlines are included.
10
+ */
11
+ export interface RawFontMetrics {
12
+ ascent: number;
13
+ descent: number;
14
+ lineGap: number;
15
+ fallbackWidth: number;
16
+ widths: string;
17
+ }
18
+ export declare const RAW_METRICS: Record<string, RawFontMetrics>;
@@ -0,0 +1,31 @@
1
+ export const RAW_METRICS = {
2
+ 'calibri': {
3
+ ascent: 952,
4
+ descent: -269,
5
+ lineGap: 0,
6
+ fallbackWidth: 226,
7
+ widths: '32:1:226,33:1:326,34:1:401,35:1:498,36:1:507,37:1:715,38:1:682,39:1:221,40:2:303,42:2:498,44:1:250,45:1:306,46:1:252,47:1:386,48:10:507,58:2:268,60:3:498,63:1:463,64:1:894,65:1:579,66:1:544,67:1:533,68:1:615,69:1:488,70:1:459,71:1:631,72:1:623,73:1:252,74:1:319,75:1:520,76:1:420,77:1:855,78:1:646,79:1:662,80:1:517,81:1:673,82:1:543,83:1:459,84:1:487,85:1:642,86:1:567,87:1:890,88:1:519,89:1:487,90:1:468,91:1:307,92:1:386,93:1:307,94:2:498,96:1:291,97:1:479,98:1:525,99:1:423,100:1:525,101:1:498,102:1:305,103:1:471,104:1:525,105:1:229,106:1:239,107:1:455,108:1:229,109:1:799,110:1:525,111:1:527,112:2:525,114:1:349,115:1:391,116:1:335,117:1:525,118:1:452,119:1:715,120:1:433,121:1:453,122:1:395,123:1:314,124:1:460,125:1:314,126:1:498,160:1:226,161:1:326,162:1:498,163:1:507,164:1:498,165:1:507,166:2:498,168:1:393,169:1:834,170:1:402,171:1:512,172:1:498,174:1:507,175:1:394,176:1:339,177:1:498,178:1:336,179:1:334,180:1:292,181:1:550,182:1:586,183:1:252,184:1:307,185:1:246,186:1:422,187:1:512,188:1:636,189:1:671,190:1:675,191:1:463,192:6:579,198:1:763,199:1:533,200:4:488,204:4:252,208:1:625,209:1:646,210:5:662,215:1:498,216:1:664,217:4:642,221:1:487,222:1:517,223:1:527,224:6:479,230:1:773,231:1:423,232:4:498,236:4:229,240:2:525,242:5:527,247:1:498,248:1:529,249:4:525,253:1:453,254:1:525,255:1:453,8211:1:498,8212:1:905,8216:4:250,8220:2:418,8230:1:690,8364:1:507',
8
+ },
9
+ 'calibri bold': {
10
+ ascent: 952,
11
+ descent: -269,
12
+ lineGap: 0,
13
+ fallbackWidth: 226,
14
+ widths: '32:1:226,33:1:326,34:1:438,35:1:498,36:1:507,37:1:729,38:1:705,39:1:233,40:2:312,42:2:498,44:1:258,45:1:306,46:1:267,47:1:430,48:10:507,58:2:276,60:3:498,63:1:463,64:1:898,65:1:606,66:1:561,67:1:529,68:1:630,69:1:488,70:1:459,71:1:637,72:1:631,73:1:267,74:1:331,75:1:547,76:1:423,77:1:874,78:1:659,79:1:676,80:1:532,81:1:686,82:1:563,83:1:473,84:1:495,85:1:653,86:1:591,87:1:906,88:1:551,89:1:520,90:1:478,91:1:325,92:1:430,93:1:325,94:2:498,96:1:300,97:1:494,98:1:537,99:1:418,100:1:537,101:1:503,102:1:316,103:1:474,104:1:537,105:1:246,106:1:255,107:1:480,108:1:246,109:1:813,110:1:537,111:1:538,112:2:537,114:1:355,115:1:399,116:1:347,117:1:537,118:1:473,119:1:745,120:1:459,121:1:474,122:1:397,123:1:344,124:1:475,125:1:344,126:1:498,160:1:226,161:1:326,162:1:498,163:1:507,164:1:498,165:1:507,166:2:498,168:1:415,169:1:834,170:1:416,171:1:539,172:1:498,174:1:507,175:1:390,176:1:342,177:1:498,178:1:338,179:1:336,180:1:301,181:1:563,182:1:598,183:1:268,184:1:303,185:1:252,186:1:435,187:1:539,188:1:658,189:1:691,190:1:702,191:1:463,192:6:606,198:1:775,199:1:529,200:4:488,204:4:267,208:1:639,209:1:659,210:5:676,215:1:498,216:1:681,217:4:653,221:1:520,222:1:532,223:1:555,224:6:494,230:1:775,231:1:418,232:4:503,236:4:246,240:2:537,242:5:538,247:1:498,248:1:544,249:4:537,253:1:474,254:1:537,255:1:474,8211:1:498,8212:1:905,8216:4:258,8220:2:435,8230:1:711,8364:1:507',
15
+ },
16
+ 'calibri italic': {
17
+ ascent: 952,
18
+ descent: -269,
19
+ lineGap: 0,
20
+ fallbackWidth: 226,
21
+ widths: '32:1:226,33:1:326,34:1:401,35:1:498,36:1:507,37:1:715,38:1:682,39:1:221,40:2:303,42:2:498,44:1:250,45:1:306,46:1:252,47:1:388,48:10:507,58:2:268,60:3:498,63:1:463,64:1:894,65:1:579,66:1:544,67:1:522,68:1:615,69:1:488,70:1:459,71:1:631,72:1:623,73:1:252,74:1:319,75:1:520,76:1:420,77:1:855,78:1:645,79:1:654,80:1:517,81:1:664,82:1:543,83:1:452,84:1:487,85:1:642,86:1:567,87:1:890,88:1:519,89:1:487,90:1:468,91:1:307,92:1:384,93:1:307,94:2:498,96:1:291,97:2:514,99:1:416,100:1:514,101:1:478,102:1:305,103:2:514,105:1:229,106:1:239,107:1:455,108:1:229,109:1:791,110:1:514,111:1:513,112:2:514,114:1:343,115:1:389,116:1:335,117:1:514,118:1:446,119:1:715,120:1:433,121:1:447,122:1:395,123:1:314,124:1:460,125:1:314,126:1:498,160:1:226,161:1:326,162:1:498,163:1:507,164:1:498,165:1:507,166:2:498,168:1:393,169:1:834,170:1:431,171:1:512,172:1:498,174:1:507,175:1:394,176:1:339,177:1:498,178:1:336,179:1:334,180:1:292,181:1:538,182:1:586,183:1:252,184:1:307,185:1:246,186:1:422,187:1:512,188:1:636,189:1:671,190:1:675,191:1:463,192:6:579,198:1:763,199:1:522,200:4:488,204:4:252,208:1:625,209:1:645,210:5:654,215:1:498,216:1:658,217:4:642,221:1:487,222:1:517,223:1:527,224:6:514,230:1:754,231:1:416,232:4:478,236:4:229,240:1:525,241:1:514,242:5:513,247:1:498,248:1:529,249:4:514,253:1:447,254:1:514,255:1:447,8211:1:498,8212:1:905,8216:4:250,8220:2:418,8230:1:690,8364:1:507',
22
+ },
23
+ 'calibri bold italic': {
24
+ ascent: 952,
25
+ descent: -269,
26
+ lineGap: 0,
27
+ fallbackWidth: 226,
28
+ widths: '32:1:226,33:1:326,34:1:438,35:1:498,36:1:507,37:1:729,38:1:705,39:1:233,40:2:312,42:2:498,44:1:258,45:1:306,46:1:267,47:1:434,48:10:507,58:2:276,60:3:498,63:1:463,64:1:898,65:1:606,66:1:561,67:1:519,68:1:630,69:1:488,70:1:459,71:1:637,72:1:631,73:1:267,74:1:331,75:1:547,76:1:423,77:1:874,78:1:656,79:1:668,80:1:532,81:1:677,82:1:563,83:1:465,84:1:495,85:1:653,86:1:591,87:1:907,88:1:551,89:1:520,90:1:478,91:1:325,92:1:425,93:1:325,94:2:498,96:1:300,97:2:528,99:1:412,100:1:528,101:1:491,102:1:316,103:1:528,104:1:527,105:1:246,106:1:255,107:1:480,108:1:246,109:1:804,110:2:527,112:2:528,114:1:352,115:1:394,116:1:347,117:1:527,118:1:469,119:1:745,120:1:459,121:1:470,122:1:397,123:1:344,124:1:475,125:1:344,126:1:498,160:1:226,161:1:326,162:1:498,163:1:507,164:1:498,165:1:507,166:2:498,168:1:415,169:1:834,170:1:441,171:1:539,172:1:498,174:1:507,175:1:390,176:1:342,177:1:498,178:1:338,179:1:336,180:1:301,181:1:554,182:1:598,183:1:268,184:1:303,185:1:252,186:1:435,187:1:539,188:1:658,189:1:691,190:1:702,191:1:463,192:6:606,198:1:775,199:1:519,200:4:488,204:4:267,208:1:639,209:1:656,210:5:668,215:1:498,216:1:677,217:4:653,221:1:520,222:1:532,223:1:555,224:6:528,230:1:764,231:1:412,232:4:491,236:4:246,240:1:537,241:6:527,247:1:498,248:1:544,249:4:527,253:1:470,254:1:528,255:1:470,8211:1:498,8212:1:905,8216:3:258,8219:1:250,8220:2:435,8230:1:711,8364:1:507',
29
+ },
30
+ };
31
+ //# sourceMappingURL=metrics-data.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"metrics-data.js","sourceRoot":"","sources":["../../src/text/metrics-data.ts"],"names":[],"mappings":"AAkBA,MAAM,CAAC,MAAM,WAAW,GAAmC;IAC1D,SAAS,EAAE;QACV,MAAM,EAAE,GAAG;QACX,OAAO,EAAE,CAAC,GAAG;QACb,OAAO,EAAE,CAAC;QACV,aAAa,EAAE,GAAG;QAClB,MAAM,EAAE,+1CAA+1C;KACv2C;IACD,cAAc,EAAE;QACf,MAAM,EAAE,GAAG;QACX,OAAO,EAAE,CAAC,GAAG;QACb,OAAO,EAAE,CAAC;QACV,aAAa,EAAE,GAAG;QAClB,MAAM,EAAE,+1CAA+1C;KACv2C;IACD,gBAAgB,EAAE;QACjB,MAAM,EAAE,GAAG;QACX,OAAO,EAAE,CAAC,GAAG;QACb,OAAO,EAAE,CAAC;QACV,aAAa,EAAE,GAAG;QAClB,MAAM,EAAE,s1CAAs1C;KAC91C;IACD,qBAAqB,EAAE;QACtB,MAAM,EAAE,GAAG;QACX,OAAO,EAAE,CAAC,GAAG;QACb,OAAO,EAAE,CAAC;QACV,aAAa,EAAE,GAAG;QAClB,MAAM,EAAE,u1CAAu1C;KAC/1C;CACD,CAAA"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "pptxgenjs-plus-std",
3
- "version": "4.1.20",
4
- "description": "Layout and diagram helpers for pptxgenjs-plus",
3
+ "version": "4.2.1",
4
+ "description": "Layout, text-measure, table-paging, and diagram helpers for pptxgenjs-plus",
5
5
  "homepage": "https://github.com/lofcz/pptxgenjs-plus/tree/next/packages/pptxgenjs-std#readme",
6
6
  "bugs": {
7
7
  "url": "https://github.com/lofcz/pptxgenjs-plus/issues"
@@ -22,7 +22,9 @@
22
22
  "pptxgenjs-plus",
23
23
  "powerpoint",
24
24
  "waterfall-chart",
25
- "slide-layout"
25
+ "slide-layout",
26
+ "text-measure",
27
+ "table-paginate"
26
28
  ],
27
29
  "files": [
28
30
  "dist",
@@ -46,6 +48,14 @@
46
48
  "./charts": {
47
49
  "types": "./dist/charts/index.d.ts",
48
50
  "default": "./dist/charts/index.js"
51
+ },
52
+ "./text": {
53
+ "types": "./dist/text/index.d.ts",
54
+ "default": "./dist/text/index.js"
55
+ },
56
+ "./tables": {
57
+ "types": "./dist/tables/index.d.ts",
58
+ "default": "./dist/tables/index.js"
49
59
  }
50
60
  },
51
61
  "scripts": {
@@ -61,10 +71,10 @@
61
71
  "node": ">=24"
62
72
  },
63
73
  "peerDependencies": {
64
- "pptxgenjs-plus": "4.1.20"
74
+ "pptxgenjs-plus": "4.2.1"
65
75
  },
66
76
  "devDependencies": {
67
- "pptxgenjs-plus": "4.1.20",
77
+ "pptxgenjs-plus": "4.2.1",
68
78
  "@types/node": "^26.2.0",
69
79
  "typescript": "^6.0.3"
70
80
  }