pptx-ts 3.7.0 → 4.0.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 +116 -269
- package/dist/autopage-odPz7zZO.js +536 -0
- package/dist/autopage-odPz7zZO.js.map +1 -0
- package/dist/binary-string-CKVAYI3M.js +24 -0
- package/dist/binary-string-CKVAYI3M.js.map +1 -0
- package/dist/body-insets-Dw_BeWD_.js +54 -0
- package/dist/body-insets-Dw_BeWD_.js.map +1 -0
- package/dist/browser.d.ts +29 -9
- package/dist/browser.d.ts.map +1 -1
- package/dist/browser.js +41 -14
- package/dist/browser.js.map +1 -1
- package/dist/clip-Bl01BPcN.d.ts +67 -0
- package/dist/clip-Bl01BPcN.d.ts.map +1 -0
- package/dist/diagnostics-D8ot4Ei7.d.ts +244 -0
- package/dist/diagnostics-D8ot4Ei7.d.ts.map +1 -0
- package/dist/embedded-fonts-DarT9aoa.d.ts +20 -0
- package/dist/embedded-fonts-DarT9aoa.d.ts.map +1 -0
- package/dist/entry-compose-DCnvBZz2.d.ts +1046 -0
- package/dist/entry-compose-DCnvBZz2.d.ts.map +1 -0
- package/dist/{enums-CvRYniUA.d.ts → enums-BUKTUB6V.d.ts} +21 -13
- package/dist/{enums-CvRYniUA.d.ts.map → enums-BUKTUB6V.d.ts.map} +1 -1
- package/dist/{errors-Bvln0H-7.js → errors-C4oENPcu.js} +92 -2
- package/dist/errors-C4oENPcu.js.map +1 -0
- package/dist/families.d.ts +260 -0
- package/dist/families.d.ts.map +1 -0
- package/dist/families.js +57 -0
- package/dist/families.js.map +1 -0
- package/dist/{fit-BKs0zxMI.js → fit-Cb7naFj6.js} +249 -167
- package/dist/fit-Cb7naFj6.js.map +1 -0
- package/dist/font-metrics-v5fn7s7e.d.ts +613 -0
- package/dist/font-metrics-v5fn7s7e.d.ts.map +1 -0
- package/dist/grid-DikTjFey.js +187 -0
- package/dist/grid-DikTjFey.js.map +1 -0
- package/dist/{html-dom-B0I0QSbU.js → html-dom-Iuog2wdK.js} +121 -91
- package/dist/html-dom-Iuog2wdK.js.map +1 -0
- package/dist/html.d.ts +6 -6
- package/dist/html.d.ts.map +1 -1
- package/dist/html.js +7 -6
- package/dist/html.js.map +1 -1
- package/dist/image-size-CvN2iCA4.js +1611 -0
- package/dist/image-size-CvN2iCA4.js.map +1 -0
- package/dist/index.d.ts +24 -10
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +31 -11
- package/dist/index.js.map +1 -1
- package/dist/inspect.d.ts +40 -31
- package/dist/inspect.d.ts.map +1 -1
- package/dist/inspect.js +40 -48
- package/dist/inspect.js.map +1 -1
- package/dist/math.d.ts +7 -5
- package/dist/math.d.ts.map +1 -1
- package/dist/math.js +16 -7
- package/dist/math.js.map +1 -1
- package/dist/measure.d.ts +12 -225
- package/dist/measure.d.ts.map +1 -1
- package/dist/measure.js +3 -3
- package/dist/node.d.ts +22 -8
- package/dist/node.d.ts.map +1 -1
- package/dist/node.js +27 -7
- package/dist/node.js.map +1 -1
- package/dist/notes-Dh12JAbn.js +3264 -0
- package/dist/notes-Dh12JAbn.js.map +1 -0
- package/dist/options-internal-WqgMf720.js +43 -0
- package/dist/options-internal-WqgMf720.js.map +1 -0
- package/dist/{package-CaOLXSNi.d.ts → package-J49Ck6S2.d.ts} +27 -12
- package/dist/package-J49Ck6S2.d.ts.map +1 -0
- package/dist/playbtn-CUqQdoDf.js +22 -0
- package/dist/playbtn-CUqQdoDf.js.map +1 -0
- package/dist/{slide-ZqAdVvHV.d.ts → pres-C6qgOFAa.d.ts} +1021 -1423
- package/dist/pres-C6qgOFAa.d.ts.map +1 -0
- package/dist/{presentation-DrJtj3-C.js → presentation-DGYlAWhl.js} +3208 -2727
- package/dist/presentation-DGYlAWhl.js.map +1 -0
- package/dist/{presentation-types-CDjScsev.d.ts → presentation-types-8jLQHI4M.d.ts} +1070 -683
- package/dist/presentation-types-8jLQHI4M.d.ts.map +1 -0
- package/dist/read.d.ts +9 -9
- package/dist/read.d.ts.map +1 -1
- package/dist/read.js +4 -4
- package/dist/script.d.ts +80 -66
- package/dist/script.d.ts.map +1 -1
- package/dist/script.js +2399 -1139
- package/dist/script.js.map +1 -1
- package/dist/{shapes-BemroU-z.js → shapes-re0KyQk_.js} +2807 -1609
- package/dist/shapes-re0KyQk_.js.map +1 -0
- package/dist/slide-Dx2ZeVZ6.d.ts +1256 -0
- package/dist/slide-Dx2ZeVZ6.d.ts.map +1 -0
- package/dist/slide-size-BalTjFuv.js +88 -0
- package/dist/slide-size-BalTjFuv.js.map +1 -0
- package/dist/{units-internal-Dg95w_YD.js → table-cell-margins-EVg0EwxT.js} +235 -273
- package/dist/table-cell-margins-EVg0EwxT.js.map +1 -0
- package/dist/table-dom-BTDP3lEP.js +21 -0
- package/dist/table-dom-BTDP3lEP.js.map +1 -0
- package/dist/text-KnLOtEEu.js +3980 -0
- package/dist/text-KnLOtEEu.js.map +1 -0
- package/dist/text-anchor-CrYXAfUu.js +176 -0
- package/dist/text-anchor-CrYXAfUu.js.map +1 -0
- package/dist/transition-speed-kUEWDWTx.js +14 -0
- package/dist/transition-speed-kUEWDWTx.js.map +1 -0
- package/dist/units-internal-XJlf-hOl.js +649 -0
- package/dist/units-internal-XJlf-hOl.js.map +1 -0
- package/dist/zip-C0leZZMj.d.ts +67 -0
- package/dist/zip-C0leZZMj.d.ts.map +1 -0
- package/dist/zip-CKd8ihcf.js +177 -0
- package/dist/zip-CKd8ihcf.js.map +1 -0
- package/dist/zip.d.ts +3 -68
- package/dist/zip.js +3 -163
- package/dist/zoom-cX9sllpH.js +8865 -0
- package/dist/zoom-cX9sllpH.js.map +1 -0
- package/package.json +106 -19
- package/skills/ts-pptx-upstream/SKILL.md +58 -57
- package/dist/autopage-DkjYZUFD.js +0 -423
- package/dist/autopage-DkjYZUFD.js.map +0 -1
- package/dist/diagnostics-DfBdDHre.d.ts +0 -829
- package/dist/diagnostics-DfBdDHre.d.ts.map +0 -1
- package/dist/errors-Bvln0H-7.js.map +0 -1
- package/dist/errors-PflMPWBn.d.ts +0 -182
- package/dist/errors-PflMPWBn.d.ts.map +0 -1
- package/dist/fit-BKs0zxMI.js.map +0 -1
- package/dist/html-dom-B0I0QSbU.js.map +0 -1
- package/dist/namespaces-BVnNu7sg.js +0 -666
- package/dist/namespaces-BVnNu7sg.js.map +0 -1
- package/dist/notes-CJFJaG6M.js +0 -1724
- package/dist/notes-CJFJaG6M.js.map +0 -1
- package/dist/package-CaOLXSNi.d.ts.map +0 -1
- package/dist/pres-BcBR3CSM.d.ts +0 -202
- package/dist/pres-BcBR3CSM.d.ts.map +0 -1
- package/dist/presentation-DrJtj3-C.js.map +0 -1
- package/dist/presentation-types-CDjScsev.d.ts.map +0 -1
- package/dist/shapes-BemroU-z.js.map +0 -1
- package/dist/slide-ZqAdVvHV.d.ts.map +0 -1
- package/dist/text-B8SLEaZx.js +0 -11327
- package/dist/text-B8SLEaZx.js.map +0 -1
- package/dist/units-1kRzYShk.js +0 -231
- package/dist/units-1kRzYShk.js.map +0 -1
- package/dist/units-internal-Dg95w_YD.js.map +0 -1
- package/dist/zip.d.ts.map +0 -1
- package/dist/zip.js.map +0 -1
package/dist/inspect.d.ts
CHANGED
|
@@ -1,25 +1,25 @@
|
|
|
1
|
-
import { n as
|
|
2
|
-
import {
|
|
1
|
+
import { _ as PackageReadErrorCode, a as InternalError, c as PackageReadError, d as UnsupportedFeatureError, f as DiagnosticCode, g as MediaErrorCode, h as InvalidOptionErrorCode, i as setDiagnosticHandler, l as TsPptxError, m as InternalErrorCode, n as DiagnosticHandler, o as InvalidOptionError, p as ErrorCode, r as resetDiagnosticState, s as MediaError, t as Diagnostic, u as TsPptxErrorOptions, v as TsPptxCode, y as UnsupportedFeatureErrorCode } from "./diagnostics-D8ot4Ei7.js";
|
|
2
|
+
import { n as OpcPackage } from "./package-J49Ck6S2.js";
|
|
3
3
|
//#region src/inspect.d.ts
|
|
4
4
|
/**
|
|
5
5
|
* Input to the inspect surface. A `string` is a **filesystem path** (Node) read
|
|
6
6
|
* from disk; pass `Uint8Array`/`ArrayBuffer`/`Blob`/`number[]` for an in-memory
|
|
7
7
|
* archive. (A string is a path, not JSZip's latin1 binary content — see
|
|
8
|
-
*
|
|
8
|
+
* `ZipInput`.)
|
|
9
9
|
*/
|
|
10
|
-
type PptxInspectInputValue = string | number[] | Uint8Array | ArrayBuffer | Blob;
|
|
11
|
-
type PptxInspectInput = PptxInspectInputValue | Promise<PptxInspectInputValue>;
|
|
12
|
-
interface PptxSlideSize {
|
|
10
|
+
export type PptxInspectInputValue = string | number[] | Uint8Array | ArrayBuffer | Blob;
|
|
11
|
+
export type PptxInspectInput = PptxInspectInputValue | Promise<PptxInspectInputValue>;
|
|
12
|
+
export interface PptxSlideSize {
|
|
13
13
|
widthIn: number;
|
|
14
14
|
heightIn: number;
|
|
15
15
|
}
|
|
16
|
-
interface PptxBox {
|
|
16
|
+
export interface PptxBox {
|
|
17
17
|
x: number;
|
|
18
18
|
y: number;
|
|
19
19
|
w: number;
|
|
20
20
|
h: number;
|
|
21
21
|
}
|
|
22
|
-
interface PptxTextRun {
|
|
22
|
+
export interface PptxTextRun {
|
|
23
23
|
text: string;
|
|
24
24
|
fontSizePt: number | null;
|
|
25
25
|
color: string | null;
|
|
@@ -41,7 +41,7 @@ interface PptxTextRun {
|
|
|
41
41
|
* boundaries that the flat {@link PptxSlideElement.textRuns} list discards — needed
|
|
42
42
|
* to measure a `wrap="none"` frame line-by-line (each paragraph is one unwrapped line).
|
|
43
43
|
*/
|
|
44
|
-
interface PptxParagraph {
|
|
44
|
+
export interface PptxParagraph {
|
|
45
45
|
runs: PptxTextRun[];
|
|
46
46
|
}
|
|
47
47
|
/**
|
|
@@ -52,7 +52,7 @@ interface PptxParagraph {
|
|
|
52
52
|
* says which, and it keeps that kind even when it carries text (a `'text'` element is
|
|
53
53
|
* always a `p:sp`).
|
|
54
54
|
*/
|
|
55
|
-
type PptxSlideElementKind = 'text' | 'image' | 'shape' | 'group' | 'graphicFrame';
|
|
55
|
+
export type PptxSlideElementKind = 'text' | 'image' | 'shape' | 'group' | 'graphicFrame';
|
|
56
56
|
/**
|
|
57
57
|
* What a `'graphicFrame'` element hosts, read from its `a:graphicData/@uri`:
|
|
58
58
|
* a table (`a:tbl`), a classic chart (`c:chart`), a 2016-family chart
|
|
@@ -60,7 +60,7 @@ type PptxSlideElementKind = 'text' | 'image' | 'shape' | 'group' | 'graphicFrame
|
|
|
60
60
|
* is a frame whose URI matches none of those — an OLE object, an ink part, a 3D
|
|
61
61
|
* model — reported as a box so it is not silently missing from the slide.
|
|
62
62
|
*/
|
|
63
|
-
type PptxGraphicKind = 'table' | 'chart' | 'chartEx' | 'diagram' | 'other';
|
|
63
|
+
export type PptxGraphicKind = 'table' | 'chart' | 'chartEx' | 'diagram' | 'other';
|
|
64
64
|
/**
|
|
65
65
|
* Vertical-autofit mode of a text frame, read from the `a:bodyPr` child element:
|
|
66
66
|
* - `'none'`: no autofit (`a:noAutofit`, or no autofit child at all). The box has a
|
|
@@ -70,20 +70,21 @@ type PptxGraphicKind = 'table' | 'chart' | 'chartEx' | 'diagram' | 'other';
|
|
|
70
70
|
* - `'spAutoFit'`: resize shape to fit text (`a:spAutoFit`, ts-pptx `fit: 'resize'`).
|
|
71
71
|
* The authored height is an output, not a constraint, so the box cannot overflow.
|
|
72
72
|
*/
|
|
73
|
-
type PptxAutofitMode = 'none' | 'normAutofit' | 'spAutoFit';
|
|
73
|
+
export type PptxAutofitMode = 'none' | 'normAutofit' | 'spAutoFit';
|
|
74
74
|
/**
|
|
75
75
|
* Text-frame body insets in inches (`a:bodyPr` `lIns`/`tIns`/`rIns`/`bIns`), with
|
|
76
76
|
* PowerPoint defaults applied when an attribute is absent (0.1in left/right,
|
|
77
77
|
* 0.05in top/bottom). Subtract these from {@link PptxBox} to get the inner text box.
|
|
78
78
|
*/
|
|
79
|
-
interface PptxBodyInsets {
|
|
79
|
+
export interface PptxBodyInsets {
|
|
80
80
|
left: number;
|
|
81
81
|
top: number;
|
|
82
82
|
right: number;
|
|
83
83
|
bottom: number;
|
|
84
84
|
}
|
|
85
|
-
interface PptxSlideElement {
|
|
86
|
-
id
|
|
85
|
+
export interface PptxSlideElement {
|
|
86
|
+
/** `p:cNvPr/@id`, or `zIndex + 1` when the attribute is missing. */
|
|
87
|
+
id: number;
|
|
87
88
|
name: string;
|
|
88
89
|
kind: PptxSlideElementKind;
|
|
89
90
|
/**
|
|
@@ -146,7 +147,7 @@ interface PptxSlideElement {
|
|
|
146
147
|
line: string | null;
|
|
147
148
|
shapeType: string | null;
|
|
148
149
|
}
|
|
149
|
-
interface PptxSlideInspection {
|
|
150
|
+
export interface PptxSlideInspection {
|
|
150
151
|
index: number;
|
|
151
152
|
name: string;
|
|
152
153
|
path: string;
|
|
@@ -155,43 +156,51 @@ interface PptxSlideInspection {
|
|
|
155
156
|
text: string;
|
|
156
157
|
wordCount: number;
|
|
157
158
|
}
|
|
158
|
-
interface PptxInspection {
|
|
159
|
+
export interface PptxInspection {
|
|
159
160
|
slideSize: PptxSlideSize;
|
|
160
161
|
slides: PptxSlideInspection[];
|
|
161
162
|
}
|
|
162
|
-
type PptxBoxAxis = 'x' | 'y';
|
|
163
|
-
type PptxBoxAnchor = 'left' | 'center' | 'right' | 'top' | 'middle' | 'bottom';
|
|
164
|
-
declare const DEFAULT_INSPECT_SLIDE_SIZE: PptxSlideSize;
|
|
163
|
+
export type PptxBoxAxis = 'x' | 'y';
|
|
164
|
+
export type PptxBoxAnchor = 'left' | 'center' | 'right' | 'top' | 'middle' | 'bottom';
|
|
165
165
|
/**
|
|
166
|
-
*
|
|
166
|
+
* The size reported for a deck that declares no `p:sldSz`: the 10in × 7.5in PowerPoint opens such
|
|
167
|
+
* a deck at, which is also what the script converter assumes. It was the widescreen size, so the
|
|
168
|
+
* two readers disagreed about the same deck. See `ABSENT_SLIDE_SIZE_EMU`.
|
|
169
|
+
*/
|
|
170
|
+
export declare const DEFAULT_INSPECT_SLIDE_SIZE: PptxSlideSize;
|
|
171
|
+
/**
|
|
172
|
+
* Load a `.pptx` as an {@link OpcPackage} — the same package model `pptx-ts/read`
|
|
167
173
|
* uses, so a caller that starts here can hand the result straight to
|
|
168
174
|
* `Presentation.fromPackage()` without re-reading the bytes.
|
|
169
175
|
*
|
|
170
176
|
* The input must be a real OPC package: a zip that merely contains some slide XML
|
|
171
177
|
* but no `[Content_Types].xml` is rejected with a `PackageReadError`.
|
|
172
178
|
*/
|
|
173
|
-
declare function loadPptxPackage(input: PptxInspectInput): Promise<OpcPackage>;
|
|
179
|
+
export declare function loadPptxPackage(input: PptxInspectInput): Promise<OpcPackage>;
|
|
174
180
|
/** Every part in the package, as zip paths (`ppt/slides/slide1.xml`), sorted. */
|
|
175
|
-
declare function listPptxParts(pptxPackage: OpcPackage): string[];
|
|
181
|
+
export declare function listPptxParts(pptxPackage: OpcPackage): string[];
|
|
176
182
|
/** Read a package part as UTF-8 text, or `null` when the part is absent. */
|
|
177
|
-
declare function readPptxTextPart(pptxPackage: OpcPackage, path: string): Promise<string | null>;
|
|
183
|
+
export declare function readPptxTextPart(pptxPackage: OpcPackage, path: string): Promise<string | null>;
|
|
178
184
|
/**
|
|
179
185
|
* Read a package part as raw bytes — the binary sibling of {@link readPptxTextPart}
|
|
180
186
|
* for embedded media (SVG/PNG/EMF blobs, fonts, …) that must not be UTF-8 decoded.
|
|
181
187
|
* Returns `null` when the part is absent. The `Uint8Array` is browser-isomorphic;
|
|
182
188
|
* Node consumers can wrap it with `Buffer.from(...)` if they need Buffer methods.
|
|
189
|
+
*
|
|
190
|
+
* The part's current body, so a package also opened as a `Presentation` and edited
|
|
191
|
+
* reads back with its edits.
|
|
183
192
|
*/
|
|
184
|
-
declare function readPptxBinaryPart(pptxPackage: OpcPackage, path: string): Promise<Uint8Array | null>;
|
|
185
|
-
declare function inspectPptx(input: PptxInspectInput): Promise<PptxInspection>;
|
|
186
|
-
declare function readPresentationSize(pptxPackage: OpcPackage, fallback?: PptxSlideSize): Promise<PptxSlideSize>;
|
|
193
|
+
export declare function readPptxBinaryPart(pptxPackage: OpcPackage, path: string): Promise<Uint8Array | null>;
|
|
194
|
+
export declare function inspectPptx(input: PptxInspectInput): Promise<PptxInspection>;
|
|
195
|
+
export declare function readPresentationSize(pptxPackage: OpcPackage, fallback?: PptxSlideSize): Promise<PptxSlideSize>;
|
|
187
196
|
/**
|
|
188
197
|
* Every slide in the deck, in **presentation order** (`p:sldIdLst`) — the order
|
|
189
198
|
* PowerPoint shows them in, which is not the order their parts are named once a
|
|
190
199
|
* deck has been reordered.
|
|
191
200
|
*/
|
|
192
|
-
declare function extractSlides(pptxPackage: OpcPackage, size?: PptxSlideSize): Promise<PptxSlideInspection[]>;
|
|
193
|
-
declare function overlapArea(a: PptxBox, b: PptxBox): number;
|
|
194
|
-
declare function boxAnchor(box: PptxBox, anchor: PptxBoxAnchor, axis: PptxBoxAxis): number;
|
|
201
|
+
export declare function extractSlides(pptxPackage: OpcPackage, size?: PptxSlideSize): Promise<PptxSlideInspection[]>;
|
|
202
|
+
export declare function overlapArea(a: PptxBox, b: PptxBox): number;
|
|
203
|
+
export declare function boxAnchor(box: PptxBox, anchor: PptxBoxAnchor, axis: PptxBoxAxis): number;
|
|
195
204
|
//#endregion
|
|
196
|
-
export {
|
|
205
|
+
export { type Diagnostic, type DiagnosticCode, type DiagnosticHandler, type ErrorCode, InternalError, type InternalErrorCode, InvalidOptionError, type InvalidOptionErrorCode, MediaError, type MediaErrorCode, PackageReadError, type PackageReadErrorCode, type TsPptxCode, TsPptxError, type TsPptxErrorOptions, UnsupportedFeatureError, type UnsupportedFeatureErrorCode, resetDiagnosticState, setDiagnosticHandler };
|
|
197
206
|
//# sourceMappingURL=inspect.d.ts.map
|
package/dist/inspect.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"inspect.d.ts","names":[],"sources":["../src/inspect.ts"],"mappings":";;;;;;;;;
|
|
1
|
+
{"version":3,"file":"inspect.d.ts","names":[],"sources":["../src/inspect.ts"],"mappings":";;;;;;;;;YA0CY,4CAA4C,aAAa,cAAc;YAEvE,mBAAmB,wBAAwB,QAAQ;iBAE9C;EAChB;EACA;;iBAGgB;EAChB;EACA;EACA;EACA;;iBAGgB;EAChB;EACA;EACA;;EAEA;;EAEA;;EAEA;;EAEA;;EAEA;;EAEA;;;;;;;iBAQgB;EAChB,MAAM;;;;;;;;;;YAWK;;;;;;;;YASA;;;;;;;;;;YAWA;;;;;;iBAOK;EAChB;EACA;EACA;EACA;;iBAGgB;;EAEhB;EACA;EACA,MAAM;;;;;EAKN,aAAa;;;;;;;;EAQb;;;;;;;EAOA,KAAK;;;;;EAKL;;EAEA;;EAEA;;EAEA;;EAEA;;;;;;;;;EASA;EACA;EACA,SAAS;;;;;;EAMT;EACA,YAAY;EACZ,UAAU;;EAEV,YAAY;EACZ;EACA;EACA;EACA;EACA;;iBAGgB;EAChB;EACA;EACA;EACA,MAAM;EACN,UAAU;EACV;EACA;;iBAGgB;EAChB,WAAW;EACX,QAAQ;;YAGG;YACA;;;;;;qBAOC,4BAA4B;;;;;;;;;wBAsBnB,gBAAgB,OAAO,mBAAmB,QAAQ;;wBAKxD,cAAc,aAAa;;wBAKrB,iBAAiB,aAAa,YAAY,eAAe;;;;;;;;;;wBAczD,mBAAmB,aAAa,YAAY,eAAe,QAAQ;wBAmBnE,YAAY,OAAO,mBAAmB,QAAQ;wBAO9C,qBACrB,aAAa,YACb,WAAU,gBACR,QAAQ;;;;;;wBAWW,cAAc,aAAa,YAAY,OAAO,gBAAgB,QAAQ;wBA2C5E,YAAY,GAAG,SAAS,GAAG;wBAM3B,UAAU,KAAK,SAAS,QAAQ,eAAe,MAAM"}
|
package/dist/inspect.js
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
1
|
+
import { a as TsPptxError, c as setDiagnosticHandler, i as PackageReadError, l as warn, n as InvalidOptionError, o as UnsupportedFeatureError, r as MediaError, s as resetDiagnosticState, t as InternalError } from "./errors-C4oENPcu.js";
|
|
2
|
+
import { D as emuToInches } from "./table-cell-margins-EVg0EwxT.js";
|
|
3
|
+
import { r as BODY_INSET_DEFAULTS_PT } from "./body-insets-Dw_BeWD_.js";
|
|
4
|
+
import { t as ABSENT_SLIDE_SIZE_EMU } from "./slide-size-BalTjFuv.js";
|
|
5
|
+
import { p as OpcPackage, t as Presentation } from "./presentation-DGYlAWhl.js";
|
|
6
6
|
//#region src/inspect.ts
|
|
7
7
|
/**
|
|
8
8
|
* A cheap, flat snapshot of what a `.pptx` contains: every element on every
|
|
9
9
|
* slide, with its slide-absolute box and the handful of text/fill properties a
|
|
10
10
|
* layout audit asks about.
|
|
11
11
|
*
|
|
12
|
-
* It is a **projection over `ts
|
|
12
|
+
* It is a **projection over `pptx-ts/read`**, not a second reader. `read` gives a
|
|
13
13
|
* navigable, mutable model of a package and answers questions in the shape of the
|
|
14
14
|
* OOXML tree; this answers one flat question — "what is on the slides, and where"
|
|
15
15
|
* — in the shape a linter, an overlap check, or a diffing tool wants. The two used
|
|
@@ -26,14 +26,21 @@ import { f as OpcPackage, t as Presentation } from "./presentation-DrJtj3-C.js";
|
|
|
26
26
|
* - **A `p:graphicFrame` is a box, not its contents.** A table, chart or SmartArt
|
|
27
27
|
* graphic is reported as one element with its box, its kind, and the text a
|
|
28
28
|
* reader sees on the slide, but its structure is not flattened: no per-run
|
|
29
|
-
* formatting, no cells, no series. Walk `ts
|
|
29
|
+
* formatting, no cells, no series. Walk `pptx-ts/read` for what is inside one.
|
|
30
|
+
*
|
|
31
|
+
* @module
|
|
32
|
+
*/
|
|
33
|
+
/**
|
|
34
|
+
* The size reported for a deck that declares no `p:sldSz`: the 10in × 7.5in PowerPoint opens such
|
|
35
|
+
* a deck at, which is also what the script converter assumes. It was the widescreen size, so the
|
|
36
|
+
* two readers disagreed about the same deck. See `ABSENT_SLIDE_SIZE_EMU`.
|
|
30
37
|
*/
|
|
31
38
|
const DEFAULT_INSPECT_SLIDE_SIZE = Object.freeze({
|
|
32
|
-
widthIn: round(
|
|
33
|
-
heightIn:
|
|
39
|
+
widthIn: round(emuToInches(ABSENT_SLIDE_SIZE_EMU.widthEmu), 3),
|
|
40
|
+
heightIn: round(emuToInches(ABSENT_SLIDE_SIZE_EMU.heightEmu), 3)
|
|
34
41
|
});
|
|
35
42
|
/**
|
|
36
|
-
* Load a `.pptx` as an {@link OpcPackage} — the same package model `ts
|
|
43
|
+
* Load a `.pptx` as an {@link OpcPackage} — the same package model `pptx-ts/read`
|
|
37
44
|
* uses, so a caller that starts here can hand the result straight to
|
|
38
45
|
* `Presentation.fromPackage()` without re-reading the bytes.
|
|
39
46
|
*
|
|
@@ -57,9 +64,12 @@ async function readPptxTextPart(pptxPackage, path) {
|
|
|
57
64
|
* for embedded media (SVG/PNG/EMF blobs, fonts, …) that must not be UTF-8 decoded.
|
|
58
65
|
* Returns `null` when the part is absent. The `Uint8Array` is browser-isomorphic;
|
|
59
66
|
* Node consumers can wrap it with `Buffer.from(...)` if they need Buffer methods.
|
|
67
|
+
*
|
|
68
|
+
* The part's current body, so a package also opened as a `Presentation` and edited
|
|
69
|
+
* reads back with its edits.
|
|
60
70
|
*/
|
|
61
71
|
async function readPptxBinaryPart(pptxPackage, path) {
|
|
62
|
-
return pptxPackage.part(partNameOf(path))?.
|
|
72
|
+
return pptxPackage.part(partNameOf(path))?.serialize() ?? null;
|
|
63
73
|
}
|
|
64
74
|
const textDecoder = new TextDecoder("utf-8");
|
|
65
75
|
/** OPC partnames are absolute (`/ppt/…`); this surface speaks zip paths (`ppt/…`). */
|
|
@@ -178,7 +188,7 @@ function toElement(entry, zIndex, slidePath) {
|
|
|
178
188
|
const textFrame = shape.textFrame;
|
|
179
189
|
const paragraphs = textFrame ? textFrame.paragraphs.map((p) => ({ runs: p.runs.map(toRun) })) : [];
|
|
180
190
|
const textRuns = paragraphs.flatMap((paragraph) => paragraph.runs);
|
|
181
|
-
const runText =
|
|
191
|
+
const runText = paragraphs.map((paragraph) => paragraph.runs.map((run) => run.text).join("")).join("\n");
|
|
182
192
|
const text = (shape.shapeType === "graphicFrame" ? graphicFrameText(shape) : runText).replace(/\s+/g, " ").trim();
|
|
183
193
|
const kind = shape.shapeType === "group" ? "group" : shape.shapeType === "graphicFrame" ? "graphicFrame" : text ? "text" : shape.shapeType === "picture" ? "image" : "shape";
|
|
184
194
|
return {
|
|
@@ -256,54 +266,36 @@ function toRun(run) {
|
|
|
256
266
|
charSpacingPt: run.charSpacingPt
|
|
257
267
|
};
|
|
258
268
|
}
|
|
259
|
-
const DEFAULT_INSET_LR_IN = .1;
|
|
260
|
-
const DEFAULT_INSET_TB_IN = .05;
|
|
261
|
-
const POINTS_PER_INCH = 72;
|
|
262
269
|
function readBodyInsets(textFrame) {
|
|
263
270
|
const insets = textFrame?.bodyProperties?.insetsPt;
|
|
264
271
|
if (!insets) return null;
|
|
265
|
-
const inches = (pt,
|
|
272
|
+
const inches = (pt, fallbackPt) => (pt === void 0 ? fallbackPt : pt) / 72;
|
|
266
273
|
return {
|
|
267
|
-
left: inches(insets.left,
|
|
268
|
-
top: inches(insets.top,
|
|
269
|
-
right: inches(insets.right,
|
|
270
|
-
bottom: inches(insets.bottom,
|
|
274
|
+
left: inches(insets.left, BODY_INSET_DEFAULTS_PT.left),
|
|
275
|
+
top: inches(insets.top, BODY_INSET_DEFAULTS_PT.top),
|
|
276
|
+
right: inches(insets.right, BODY_INSET_DEFAULTS_PT.right),
|
|
277
|
+
bottom: inches(insets.bottom, BODY_INSET_DEFAULTS_PT.bottom)
|
|
271
278
|
};
|
|
272
279
|
}
|
|
273
|
-
/**
|
|
280
|
+
/**
|
|
281
|
+
* Warn about a shape whose slide position cannot be resolved, unless it never
|
|
282
|
+
* claimed one.
|
|
283
|
+
*
|
|
284
|
+
* `absoluteFrame` is `null` for three different situations and only two of them
|
|
285
|
+
* are worth telling the caller about; `absoluteFrameFailure` is the read model
|
|
286
|
+
* naming which, so this surface does not walk the ancestry a second time to
|
|
287
|
+
* re-derive it.
|
|
288
|
+
*/
|
|
274
289
|
function reportUnresolvable(shape, zIndex, slidePath) {
|
|
275
|
-
const
|
|
276
|
-
if (
|
|
290
|
+
const failure = shape.absoluteFrameFailure;
|
|
291
|
+
if (failure === null || failure === "no-own-transform") return;
|
|
277
292
|
const who = shape.name ? `"${shape.name}"` : `the element at zIndex ${zIndex}`;
|
|
278
|
-
if (
|
|
293
|
+
if (failure === "group-transform-missing") {
|
|
279
294
|
warn("inspect/group-transform-missing", `inspect: skipped ${who} on ${slidePath} — an enclosing group has no usable a:xfrm, so its slide position cannot be resolved.`);
|
|
280
295
|
return;
|
|
281
296
|
}
|
|
282
297
|
warn("inspect/group-transform-degenerate", `inspect: skipped ${who} on ${slidePath} — an enclosing group has a degenerate transform (zero a:chExt), so its slide position cannot be resolved.`);
|
|
283
298
|
}
|
|
284
|
-
/** The element's own `a:xfrm` — on `p:grpSpPr` for a group, `p:spPr` for every other kind. */
|
|
285
|
-
function ownTransform(element) {
|
|
286
|
-
const props = firstChild(element, element.localName === "grpSp" ? "p:grpSpPr" : "p:spPr");
|
|
287
|
-
return props && firstChild(props, "a:xfrm");
|
|
288
|
-
}
|
|
289
|
-
/** Whether any enclosing `p:grpSp` fails to state a complete child-space mapping. */
|
|
290
|
-
function enclosingGroupLacksTransform(element) {
|
|
291
|
-
for (let node = element.parentNode; node && node.nodeType === 1; node = node.parentNode) {
|
|
292
|
-
const parent = node;
|
|
293
|
-
if (parent.namespaceURI !== OOXML_NS.p || parent.localName !== "grpSp") return false;
|
|
294
|
-
const xfrm = ownTransform(parent);
|
|
295
|
-
if (!hasBox(xfrm, "a:off", "a:ext") || !hasBox(xfrm, "a:chOff", "a:chExt")) return true;
|
|
296
|
-
}
|
|
297
|
-
return false;
|
|
298
|
-
}
|
|
299
|
-
/** Whether a transform states a complete position + extent pair. */
|
|
300
|
-
function hasBox(xfrm, offName, extName) {
|
|
301
|
-
if (!xfrm) return false;
|
|
302
|
-
const off = firstChild(xfrm, offName);
|
|
303
|
-
const ext = firstChild(xfrm, extName);
|
|
304
|
-
if (!off || !ext) return false;
|
|
305
|
-
return intValue(attr(off, "x")) !== null && intValue(attr(off, "y")) !== null && intValue(attr(ext, "cx")) !== null && intValue(attr(ext, "cy")) !== null;
|
|
306
|
-
}
|
|
307
299
|
function countWords(text) {
|
|
308
300
|
return text.split(/\s+/).filter(Boolean).length;
|
|
309
301
|
}
|
|
@@ -312,6 +304,6 @@ function round(value, digits) {
|
|
|
312
304
|
return Math.round(value * factor) / factor;
|
|
313
305
|
}
|
|
314
306
|
//#endregion
|
|
315
|
-
export { DEFAULT_INSPECT_SLIDE_SIZE, InternalError, InvalidOptionError, MediaError, PackageReadError, TsPptxError, UnsupportedFeatureError, boxAnchor, extractSlides, inspectPptx, listPptxParts, loadPptxPackage, overlapArea, readPptxBinaryPart, readPptxTextPart, readPresentationSize };
|
|
307
|
+
export { DEFAULT_INSPECT_SLIDE_SIZE, InternalError, InvalidOptionError, MediaError, PackageReadError, TsPptxError, UnsupportedFeatureError, boxAnchor, extractSlides, inspectPptx, listPptxParts, loadPptxPackage, overlapArea, readPptxBinaryPart, readPptxTextPart, readPresentationSize, resetDiagnosticState, setDiagnosticHandler };
|
|
316
308
|
|
|
317
309
|
//# sourceMappingURL=inspect.js.map
|
package/dist/inspect.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"inspect.js","names":[],"sources":["../src/inspect.ts"],"sourcesContent":["/**\n * A cheap, flat snapshot of what a `.pptx` contains: every element on every\n * slide, with its slide-absolute box and the handful of text/fill properties a\n * layout audit asks about.\n *\n * It is a **projection over `ts-pptx/read`**, not a second reader. `read` gives a\n * navigable, mutable model of a package and answers questions in the shape of the\n * OOXML tree; this answers one flat question — \"what is on the slides, and where\"\n * — in the shape a linter, an overlap check, or a diffing tool wants. The two used\n * to be independent implementations over two different XML parsers, which meant\n * every read-side fix had to be made twice and a divergence between them was\n * invisible to every test. Now the model below is the only reader, and this file\n * is the flattening.\n *\n * What it deliberately does NOT do, and why the projection is not just\n * `Presentation` re-exported:\n * - **Only geometry a shape carries itself.** A placeholder that inherits its box\n * from the layout is omitted rather than resolved (`absoluteFrame`, not\n * `resolvedFrame`) — the snapshot reports what the slide states.\n * - **A `p:graphicFrame` is a box, not its contents.** A table, chart or SmartArt\n * graphic is reported as one element with its box, its kind, and the text a\n * reader sees on the slide, but its structure is not flattened: no per-run\n * formatting, no cells, no series. Walk `ts-pptx/read` for what is inside one.\n */\nimport { warn } from './diagnostics.js'\nimport { OpcPackage } from './read/opc/package.js'\nimport { Presentation } from './read/api/presentation.js'\nimport type { AnyShape } from './read/api/shapes.js'\nimport type { GraphicFrame } from './read/api/shapes/graphic-frame.js'\nimport type { Run, TextFrame } from './read/api/text.js'\nimport { ELEMENT_NODE, OOXML_NS, attr, firstChild, intValue, type Element } from './read/oxml/dom.js'\nimport { STANDARD_LAYOUTS, emuToInches } from './units.js'\n\n/**\n * Input to the inspect surface. A `string` is a **filesystem path** (Node) read\n * from disk; pass `Uint8Array`/`ArrayBuffer`/`Blob`/`number[]` for an in-memory\n * archive. (A string is a path, not JSZip's latin1 binary content — see\n * {@link ZipInput}.)\n */\ntype PptxInspectInputValue = string | number[] | Uint8Array | ArrayBuffer | Blob\n\nexport type PptxInspectInput = PptxInspectInputValue | Promise<PptxInspectInputValue>\n\nexport interface PptxSlideSize {\n\twidthIn: number\n\theightIn: number\n}\n\nexport interface PptxBox {\n\tx: number\n\ty: number\n\tw: number\n\th: number\n}\n\nexport interface PptxTextRun {\n\ttext: string\n\tfontSizePt: number | null\n\tcolor: string | null\n\t/** Run font face (`a:rPr > a:latin@typeface`), or null when it inherits from the theme/placeholder. */\n\tfontFace: string | null\n\t/** Bold (`a:rPr@b`). */\n\tbold: boolean\n\t/** Italic (`a:rPr@i`). */\n\titalic: boolean\n\t/** Strikethrough token (`a:rPr@strike`: `noStrike`/`sngStrike`/`dblStrike`), or null when unset. */\n\tstrike: string | null\n\t/** Highlight colour hex (`a:rPr > a:highlight`), or null when unset. A theme token is resolved against the slide's theme. */\n\thighlight: string | null\n\t/** Character spacing in points (`a:rPr@spc`, authored in hundredths of a point), or null when unset. */\n\tcharSpacingPt: number | null\n}\n\n/**\n * One paragraph (`a:p`): its runs in document order. Preserves the paragraph/line\n * boundaries that the flat {@link PptxSlideElement.textRuns} list discards — needed\n * to measure a `wrap=\"none\"` frame line-by-line (each paragraph is one unwrapped line).\n */\nexport interface PptxParagraph {\n\truns: PptxTextRun[]\n}\n\n/**\n * What an element is. `'group'` is a `p:grpSp` container: it has its own identity,\n * box, and fill, but no text of its own — its content is the elements that name it\n * in {@link PptxSlideElement.parentZIndex}. `'graphicFrame'` is a `p:graphicFrame`\n * hosting a table, a chart or a SmartArt graphic; {@link PptxSlideElement.graphicKind}\n * says which, and it keeps that kind even when it carries text (a `'text'` element is\n * always a `p:sp`).\n */\nexport type PptxSlideElementKind = 'text' | 'image' | 'shape' | 'group' | 'graphicFrame'\n\n/**\n * What a `'graphicFrame'` element hosts, read from its `a:graphicData/@uri`:\n * a table (`a:tbl`), a classic chart (`c:chart`), a 2016-family chart\n * (`cx:chartSpace`: waterfall/funnel/treemap/…), or a SmartArt diagram. `'other'`\n * is a frame whose URI matches none of those — an OLE object, an ink part, a 3D\n * model — reported as a box so it is not silently missing from the slide.\n */\nexport type PptxGraphicKind = 'table' | 'chart' | 'chartEx' | 'diagram' | 'other'\n\n/**\n * Vertical-autofit mode of a text frame, read from the `a:bodyPr` child element:\n * - `'none'`: no autofit (`a:noAutofit`, or no autofit child at all). The box has a\n * fixed height the text must fit inside — a genuine overflow candidate.\n * - `'normAutofit'`: shrink text to fit (`a:normAutofit`, ts-pptx `fit: 'shrink'`).\n * Text is downscaled rather than overflowing.\n * - `'spAutoFit'`: resize shape to fit text (`a:spAutoFit`, ts-pptx `fit: 'resize'`).\n * The authored height is an output, not a constraint, so the box cannot overflow.\n */\nexport type PptxAutofitMode = 'none' | 'normAutofit' | 'spAutoFit'\n\n/**\n * Text-frame body insets in inches (`a:bodyPr` `lIns`/`tIns`/`rIns`/`bIns`), with\n * PowerPoint defaults applied when an attribute is absent (0.1in left/right,\n * 0.05in top/bottom). Subtract these from {@link PptxBox} to get the inner text box.\n */\nexport interface PptxBodyInsets {\n\tleft: number\n\ttop: number\n\tright: number\n\tbottom: number\n}\n\nexport interface PptxSlideElement {\n\tid: string | number\n\tname: string\n\tkind: PptxSlideElementKind\n\t/**\n\t * What a `'graphicFrame'` element hosts, or `null` for every other kind. See\n\t * {@link PptxGraphicKind}.\n\t */\n\tgraphicKind: PptxGraphicKind | null\n\t/**\n\t * Paint order on the slide, `0`-based: the element's position in a depth-first\n\t * walk of `p:spTree` in document order. A group is immediately followed by its\n\t * own children, which is also the order PowerPoint paints them, so a higher\n\t * `zIndex` draws on top. Unique within a slide, which is what\n\t * {@link parentZIndex} / {@link childZIndices} key on.\n\t */\n\tzIndex: number\n\t/**\n\t * Position and size in **slide-absolute** inches, composing every enclosing\n\t * group transform — directly comparable across elements whether or not they are\n\t * grouped. For a rotated element this is the unrotated placement box (the box\n\t * PowerPoint writes after Ungroup); see {@link rotation}.\n\t */\n\tbox: PptxBox\n\t/**\n\t * Effective clockwise rotation in degrees, normalised to `[0, 360)`, after\n\t * composing the element's own `a:xfrm@rot` with every enclosing group rotation.\n\t */\n\trotation: number\n\t/** Effective horizontal flip, XOR-composing the element's own `@flipH` with enclosing group flips. */\n\tflipH: boolean\n\t/** Effective vertical flip, XOR-composing the element's own `@flipV` with enclosing group flips. */\n\tflipV: boolean\n\t/** {@link zIndex} of the enclosing `'group'` element, or `null` when the element sits at slide level. */\n\tparentZIndex: number | null\n\t/** {@link zIndex} of each direct child, in document order. Empty unless {@link kind} is `'group'`. */\n\tchildZIndices: number[]\n\t/**\n\t * The element's text, whitespace-collapsed to one line. For a `'graphicFrame'`\n\t * this is the text the structure puts on the slide (table cells in row order,\n\t * SmartArt node text), which is what {@link PptxSlideInspection.text} and\n\t * `wordCount` then count; a chart contributes nothing, matching `Slide.text` on\n\t * the read model. That text has no {@link textRuns} or {@link paragraphs} here —\n\t * per-run formatting inside a structure is what this surface does not flatten.\n\t */\n\ttext: string\n\ttextWrap: string | null\n\tautofit: PptxAutofitMode | null\n\t/**\n\t * Baked shrink scale from `<a:normAutofit@fontScale>` as a percent (62.5 = 62.5%),\n\t * or null when the frame has no `normAutofit` or bakes no scale (a bare\n\t * `<a:normAutofit/>`, which PowerPoint draws at 100% until edited).\n\t */\n\tautofitFontScale: number | null\n\tbodyInsets: PptxBodyInsets | null\n\ttextRuns: PptxTextRun[]\n\t/** Runs grouped by their source paragraph (`a:p`), in document order. */\n\tparagraphs: PptxParagraph[]\n\tfontSizes: number[]\n\tcolors: string[]\n\tfill: string | null\n\tline: string | null\n\tshapeType: string | null\n}\n\nexport interface PptxSlideInspection {\n\tindex: number\n\tname: string\n\tpath: string\n\tsize: PptxSlideSize\n\telements: PptxSlideElement[]\n\ttext: string\n\twordCount: number\n}\n\nexport interface PptxInspection {\n\tslideSize: PptxSlideSize\n\tslides: PptxSlideInspection[]\n}\n\nexport type PptxBoxAxis = 'x' | 'y'\nexport type PptxBoxAnchor = 'left' | 'center' | 'right' | 'top' | 'middle' | 'bottom'\n\nexport const DEFAULT_INSPECT_SLIDE_SIZE: PptxSlideSize = Object.freeze({\n\twidthIn: round(STANDARD_LAYOUTS.LAYOUT_WIDE.widthIn, 3),\n\theightIn: STANDARD_LAYOUTS.LAYOUT_WIDE.heightIn,\n})\n\n/* ────────────────────────────────────────────────────────────────────────────\n * Package layer\n *\n * Thin conveniences over `OpcPackage`, kept because this surface speaks zip\n * paths (`ppt/slides/slide1.xml`) while OPC speaks partnames (`/ppt/...`), and\n * because reaching a part's bytes is the one thing a caller of a *flat* surface\n * still routinely needs.\n * ──────────────────────────────────────────────────────────────────────────── */\n\n/**\n * Load a `.pptx` as an {@link OpcPackage} — the same package model `ts-pptx/read`\n * uses, so a caller that starts here can hand the result straight to\n * `Presentation.fromPackage()` without re-reading the bytes.\n *\n * The input must be a real OPC package: a zip that merely contains some slide XML\n * but no `[Content_Types].xml` is rejected with a `PackageReadError`.\n */\nexport async function loadPptxPackage(input: PptxInspectInput): Promise<OpcPackage> {\n\treturn OpcPackage.load(await input)\n}\n\n/** Every part in the package, as zip paths (`ppt/slides/slide1.xml`), sorted. */\nexport function listPptxParts(pptxPackage: OpcPackage): string[] {\n\treturn [...pptxPackage.parts.keys()].map(zipPathOf).sort()\n}\n\n/** Read a package part as UTF-8 text, or `null` when the part is absent. */\nexport async function readPptxTextPart(pptxPackage: OpcPackage, path: string): Promise<string | null> {\n\tconst bytes = await readPptxBinaryPart(pptxPackage, path)\n\treturn bytes ? textDecoder.decode(bytes) : null\n}\n\n/**\n * Read a package part as raw bytes — the binary sibling of {@link readPptxTextPart}\n * for embedded media (SVG/PNG/EMF blobs, fonts, …) that must not be UTF-8 decoded.\n * Returns `null` when the part is absent. The `Uint8Array` is browser-isomorphic;\n * Node consumers can wrap it with `Buffer.from(...)` if they need Buffer methods.\n */\nexport async function readPptxBinaryPart(pptxPackage: OpcPackage, path: string): Promise<Uint8Array | null> {\n\treturn pptxPackage.part(partNameOf(path))?.bytes ?? null\n}\n\nconst textDecoder = new TextDecoder('utf-8')\n\n/** OPC partnames are absolute (`/ppt/…`); this surface speaks zip paths (`ppt/…`). */\nfunction zipPathOf(partName: string): string {\n\treturn partName.startsWith('/') ? partName.slice(1) : partName\n}\n\nfunction partNameOf(zipPath: string): string {\n\treturn zipPath.startsWith('/') ? zipPath : `/${zipPath}`\n}\n\n/* ────────────────────────────────────────────────────────────────────────────\n * The surface\n * ──────────────────────────────────────────────────────────────────────────── */\n\nexport async function inspectPptx(input: PptxInspectInput): Promise<PptxInspection> {\n\tconst pptxPackage = await loadPptxPackage(input)\n\tconst slideSize = await readPresentationSize(pptxPackage)\n\tconst slides = await extractSlides(pptxPackage, slideSize)\n\treturn { slideSize, slides }\n}\n\nexport async function readPresentationSize(\n\tpptxPackage: OpcPackage,\n\tfallback: PptxSlideSize = DEFAULT_INSPECT_SLIDE_SIZE\n): Promise<PptxSlideSize> {\n\tconst size = presentationOf(pptxPackage)?.slideSize\n\tif (!size) return fallback\n\treturn { widthIn: round(size.widthIn, 3), heightIn: round(size.heightIn, 3) }\n}\n\n/**\n * Every slide in the deck, in **presentation order** (`p:sldIdLst`) — the order\n * PowerPoint shows them in, which is not the order their parts are named once a\n * deck has been reordered.\n */\nexport async function extractSlides(pptxPackage: OpcPackage, size?: PptxSlideSize): Promise<PptxSlideInspection[]> {\n\tconst slideSize = size || (await readPresentationSize(pptxPackage))\n\tconst presentation = presentationOf(pptxPackage)\n\tif (!presentation) return []\n\n\treturn presentation.slides.map((slide, index) => {\n\t\tconst path = zipPathOf(slide.partName)\n\t\tconst harvested: HarvestedShape[] = []\n\t\tharvest(slide.shapes, null, harvested) // slide level: no enclosing group\n\t\tconst elements = flatten(harvested, path)\n\t\tconst text = elements\n\t\t\t.map((el) => el.text)\n\t\t\t.filter(Boolean)\n\t\t\t.join(' ')\n\n\t\treturn {\n\t\t\tindex,\n\t\t\tname: slide.name || `Slide ${index + 1}`,\n\t\t\tpath,\n\t\t\tsize: slideSize,\n\t\t\telements,\n\t\t\ttext,\n\t\t\twordCount: countWords(text),\n\t\t}\n\t})\n}\n\n/**\n * The deck's `Presentation`, or `null` when the package holds no readable\n * `presentation.xml`. Callers here are auditing files they did not author, so a\n * package that is a valid OPC container but not a presentation reports an empty\n * deck rather than throwing. `presentationPart` is the throw site: it rejects a\n * package with no — or more than one — office-document relationship.\n */\nfunction presentationOf(pptxPackage: OpcPackage): Presentation | null {\n\tconst presentation = Presentation.fromPackage(pptxPackage)\n\ttry {\n\t\treturn presentation.presentationPart.isXmlPart ? presentation : null\n\t} catch {\n\t\treturn null\n\t}\n}\n\nexport function overlapArea(a: PptxBox, b: PptxBox): number {\n\tconst x = Math.max(0, Math.min(a.x + a.w, b.x + b.w) - Math.max(a.x, b.x))\n\tconst y = Math.max(0, Math.min(a.y + a.h, b.y + b.h) - Math.max(a.y, b.y))\n\treturn x * y\n}\n\nexport function boxAnchor(box: PptxBox, anchor: PptxBoxAnchor, axis: PptxBoxAxis): number {\n\tif (axis === 'x') {\n\t\tif (anchor === 'left') return box.x\n\t\tif (anchor === 'right') return box.x + box.w\n\t\treturn box.x + box.w / 2\n\t}\n\tif (anchor === 'top') return box.y\n\tif (anchor === 'bottom') return box.y + box.h\n\treturn box.y + box.h / 2\n}\n\n/* ────────────────────────────────────────────────────────────────────────────\n * Shape-tree harvest\n * ──────────────────────────────────────────────────────────────────────────── */\n\n/** One harvested shape, before it is flattened into a {@link PptxSlideElement}. */\ninterface HarvestedShape {\n\tshape: AnyShape\n\tparentZIndex: number | null\n\tchildZIndices: number[]\n}\n\n/**\n * Flatten a shape list depth-first in document order: each shape is followed by\n * its descendants, which is both paint order and the order the\n * {@link PptxSlideElement.zIndex} contract promises. Every entry's index in `out`\n * is its zIndex. Returns the zIndices assigned at this level, which is what the\n * enclosing group records as its {@link PptxSlideElement.childZIndices}.\n */\nfunction harvest(shapes: AnyShape[], parentZIndex: number | null, out: HarvestedShape[]): number[] {\n\tconst zIndices: number[] = []\n\tfor (const shape of shapes) {\n\t\tconst entry: HarvestedShape = { shape, parentZIndex, childZIndices: [] }\n\t\tconst zIndex = out.push(entry) - 1\n\t\tzIndices.push(zIndex)\n\t\tif (shape.shapeType === 'group') entry.childZIndices = harvest(shape.shapes, zIndex, out)\n\t}\n\treturn zIndices\n}\n\n/**\n * Turn harvested shapes into elements, dropping the ones with no resolvable slide\n * position. A dropped shape keeps its zIndex — the numbers are positions in the\n * shape tree, and renumbering them would silently repoint every `parentZIndex`.\n */\nfunction flatten(harvested: HarvestedShape[], slidePath: string): PptxSlideElement[] {\n\treturn harvested\n\t\t.map((entry, zIndex) => toElement(entry, zIndex, slidePath))\n\t\t.filter((element): element is PptxSlideElement => Boolean(element))\n}\n\nfunction toElement(entry: HarvestedShape, zIndex: number, slidePath: string): PptxSlideElement | null {\n\tconst { shape } = entry\n\tconst frame = shape.absoluteFrame\n\tif (!frame) {\n\t\treportUnresolvable(shape, zIndex, slidePath)\n\t\treturn null\n\t}\n\n\t// Only `p:sp` holds a text body, so every other kind projects as an empty frame.\n\tconst textFrame = shape.textFrame\n\tconst paragraphs = textFrame ? textFrame.paragraphs.map((p) => ({ runs: p.runs.map(toRun) })) : []\n\tconst textRuns = paragraphs.flatMap((paragraph) => paragraph.runs)\n\t// A graphic frame has no text body of its own; its text comes from the structure\n\t// it hosts, and arrives as a plain string with no runs behind it.\n\tconst runText = textRuns.map((run) => run.text).join('')\n\tconst raw = shape.shapeType === 'graphicFrame' ? graphicFrameText(shape) : runText\n\t// Deliberately not `TextFrame.text`: this is one whitespace-collapsed line for\n\t// matching and word-counting, not the frame's text with its line structure.\n\tconst text = raw.replace(/\\s+/g, ' ').trim()\n\tconst kind: PptxSlideElementKind =\n\t\tshape.shapeType === 'group'\n\t\t\t? 'group'\n\t\t\t: shape.shapeType === 'graphicFrame'\n\t\t\t\t? 'graphicFrame'\n\t\t\t\t: text\n\t\t\t\t\t? 'text'\n\t\t\t\t\t: shape.shapeType === 'picture'\n\t\t\t\t\t\t? 'image'\n\t\t\t\t\t\t: 'shape'\n\n\treturn {\n\t\tid: shape.id ?? zIndex + 1,\n\t\tname: shape.name || `${kind} ${zIndex + 1}`,\n\t\tkind,\n\t\tgraphicKind: shape.shapeType === 'graphicFrame' ? graphicKindOf(shape) : null,\n\t\tzIndex,\n\t\tbox: {\n\t\t\tx: emuToInches(frame.left),\n\t\t\ty: emuToInches(frame.top),\n\t\t\tw: emuToInches(frame.width),\n\t\t\th: emuToInches(frame.height),\n\t\t},\n\t\trotation: frame.rotation,\n\t\tflipH: frame.flipH,\n\t\tflipV: frame.flipV,\n\t\tparentZIndex: entry.parentZIndex,\n\t\tchildZIndices: entry.childZIndices,\n\t\ttext,\n\t\ttextWrap: textFrame?.bodyProperties?.wrap ?? null,\n\t\tautofit: textFrame?.autofit ?? null,\n\t\tautofitFontScale: textFrame?.autofitFontScale ?? null,\n\t\tbodyInsets: readBodyInsets(textFrame),\n\t\ttextRuns,\n\t\tparagraphs,\n\t\tfontSizes: [...new Set(textRuns.map((run) => run.fontSizePt).filter((size): size is number => size !== null))],\n\t\tcolors: [...new Set(textRuns.map((run) => run.color).filter((color): color is string => Boolean(color)))],\n\t\tfill: shape.fillColor,\n\t\tline: shape.lineColor,\n\t\tshapeType: shape.presetGeometry,\n\t}\n}\n\n/**\n * What a graphic frame hosts, from the same `a:graphicData/@uri` the read model's\n * `has*` predicates compare against. A frame that answers none of them is `'other'`\n * rather than dropped: a box the deck's author placed is on the slide whether or not\n * this library models its payload, and an overlap or coverage check that skipped it\n * would report a gap where a 3D model or an OLE object sits.\n */\nfunction graphicKindOf(frame: GraphicFrame): PptxGraphicKind {\n\tif (frame.hasTable) return 'table'\n\tif (frame.hasChart) return 'chart'\n\tif (frame.hasChartEx) return 'chartEx'\n\tif (frame.hasDiagram) return 'diagram'\n\treturn 'other'\n}\n\n/**\n * The text a graphic frame puts on the slide: table cells in row order, or SmartArt\n * node text. Charts contribute nothing, matching `Slide.text` on the read model — a\n * chart's strings are data labels and axis titles that PowerPoint itself does not\n * treat as slide body text.\n *\n * Separators are single spaces rather than the read model's `\t`/`\n`, because the\n * caller collapses whitespace anyway; the point here is only that cells do not run\n * together into one word.\n */\nfunction graphicFrameText(frame: GraphicFrame): string {\n\tconst table = frame.table\n\tif (table) return table.rows.map((row) => row.cells.map((cell) => cell.text).join(' ')).join(' ')\n\treturn frame.diagram?.text ?? ''\n}\n\n/** Project one read-model {@link Run} onto the flat run shape. */\nfunction toRun(run: Run): PptxTextRun {\n\treturn {\n\t\ttext: run.text,\n\t\tfontSizePt: run.fontSizePt,\n\t\tcolor: run.color,\n\t\tfontFace: run.fontName,\n\t\t// The read model distinguishes \"explicitly not bold\" from \"unset, inherits\";\n\t\t// this surface reports what renders, so an unset flag is `false`.\n\t\tbold: run.bold ?? false,\n\t\titalic: run.italic ?? false,\n\t\tstrike: run.strike,\n\t\thighlight: run.highlight?.hex ?? null,\n\t\tcharSpacingPt: run.charSpacingPt,\n\t}\n}\n\n// PowerPoint body-inset defaults (ECMA-376 §21.1.2.1.1 prose; the XSD leaves\n// lIns/tIns/rIns/bIns optional with no schema default): 0.1in left/right,\n// 0.05in top/bottom. The read model reports only the explicitly-set sides.\nconst DEFAULT_INSET_LR_IN = 0.1\nconst DEFAULT_INSET_TB_IN = 0.05\nconst POINTS_PER_INCH = 72\n\nfunction readBodyInsets(textFrame: TextFrame | null): PptxBodyInsets | null {\n\tconst insets = textFrame?.bodyProperties?.insetsPt\n\tif (!insets) return null\n\tconst inches = (pt: number | undefined, fallback: number): number =>\n\t\tpt === undefined ? fallback : pt / POINTS_PER_INCH\n\treturn {\n\t\tleft: inches(insets.left, DEFAULT_INSET_LR_IN),\n\t\ttop: inches(insets.top, DEFAULT_INSET_TB_IN),\n\t\tright: inches(insets.right, DEFAULT_INSET_LR_IN),\n\t\tbottom: inches(insets.bottom, DEFAULT_INSET_TB_IN),\n\t}\n}\n\n/* ────────────────────────────────────────────────────────────────────────────\n * Unresolvable positions\n *\n * `absoluteFrame` reports `null` for three different situations, and only two of\n * them are worth telling the caller about. The distinction is not recoverable\n * from the `null`, so it is re-derived here from the same ancestry the read model\n * walks.\n * ──────────────────────────────────────────────────────────────────────────── */\n\n/** Warn about a shape whose slide position cannot be resolved, unless it never claimed one. */\nfunction reportUnresolvable(shape: AnyShape, zIndex: number, slidePath: string): void {\n\tconst element = shape.element_\n\t// No own `a:xfrm` at all: the shape inherits its geometry from a layout\n\t// placeholder, which this surface deliberately does not resolve. Nothing is\n\t// wrong with the deck, so nothing is reported.\n\tif (!hasBox(ownTransform(element), 'a:off', 'a:ext')) return\n\n\tconst who = shape.name ? `\"${shape.name}\"` : `the element at zIndex ${zIndex}`\n\tif (enclosingGroupLacksTransform(element)) {\n\t\twarn(\n\t\t\t'inspect/group-transform-missing',\n\t\t\t`inspect: skipped ${who} on ${slidePath} — an enclosing group has no usable a:xfrm, so its slide position cannot be resolved.`\n\t\t)\n\t\treturn\n\t}\n\twarn(\n\t\t'inspect/group-transform-degenerate',\n\t\t`inspect: skipped ${who} on ${slidePath} — an enclosing group has a degenerate transform (zero a:chExt), so its slide position cannot be resolved.`\n\t)\n}\n\n/** The element's own `a:xfrm` — on `p:grpSpPr` for a group, `p:spPr` for every other kind. */\nfunction ownTransform(element: Element): Element | null {\n\tconst props = firstChild(element, element.localName === 'grpSp' ? 'p:grpSpPr' : 'p:spPr')\n\treturn props && firstChild(props, 'a:xfrm')\n}\n\n/** Whether any enclosing `p:grpSp` fails to state a complete child-space mapping. */\nfunction enclosingGroupLacksTransform(element: Element): boolean {\n\tfor (let node = element.parentNode; node && node.nodeType === ELEMENT_NODE; node = node.parentNode) {\n\t\tconst parent = node as Element\n\t\tif (parent.namespaceURI !== OOXML_NS.p || parent.localName !== 'grpSp') return false // reached the shape tree\n\t\tconst xfrm = ownTransform(parent)\n\t\tif (!hasBox(xfrm, 'a:off', 'a:ext') || !hasBox(xfrm, 'a:chOff', 'a:chExt')) return true\n\t}\n\treturn false\n}\n\n/** Whether a transform states a complete position + extent pair. */\nfunction hasBox(xfrm: Element | null, offName: string, extName: string): boolean {\n\tif (!xfrm) return false\n\tconst off = firstChild(xfrm, offName)\n\tconst ext = firstChild(xfrm, extName)\n\tif (!off || !ext) return false\n\treturn (\n\t\tintValue(attr(off, 'x')) !== null &&\n\t\tintValue(attr(off, 'y')) !== null &&\n\t\tintValue(attr(ext, 'cx')) !== null &&\n\t\tintValue(attr(ext, 'cy')) !== null\n\t)\n}\n\nfunction countWords(text: string): number {\n\treturn text.split(/\\s+/).filter(Boolean).length\n}\n\nfunction round(value: number, digits: number): number {\n\tconst factor = 10 ** digits\n\treturn Math.round(value * factor) / factor\n}\n\n// Error taxonomy — see `entry-errors.ts`. Re-exported from every entry so `instanceof`\n// works whichever subpath a consumer imports.\nexport * from './entry-errors.js'\n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AAS,KAAK,OAAO,cAAc,SAAS,OAAO;EAC/E,MAAM,OAAO,aAAa,MAAM;EAChC,IAAI,CAAC,OAAO,MAAM,SAAS,OAAO,KAAK,CAAC,OAAO,MAAM,WAAW,SAAS,GAAG,OAAO;CACpF;CACA,OAAO;AACR;;AAGA,SAAS,OAAO,MAAsB,SAAiB,SAA0B;CAChF,IAAI,CAAC,MAAM,OAAO;CAClB,MAAM,MAAM,WAAW,MAAM,OAAO;CACpC,MAAM,MAAM,WAAW,MAAM,OAAO;CACpC,IAAI,CAAC,OAAO,CAAC,KAAK,OAAO;CACzB,OACC,SAAS,KAAK,KAAK,GAAG,CAAC,MAAM,QAC7B,SAAS,KAAK,KAAK,GAAG,CAAC,MAAM,QAC7B,SAAS,KAAK,KAAK,IAAI,CAAC,MAAM,QAC9B,SAAS,KAAK,KAAK,IAAI,CAAC,MAAM;AAEhC;AAEA,SAAS,WAAW,MAAsB;CACzC,OAAO,KAAK,MAAM,KAAK,CAAC,CAAC,OAAO,OAAO,CAAC,CAAC;AAC1C;AAEA,SAAS,MAAM,OAAe,QAAwB;CACrD,MAAM,SAAS,MAAM;CACrB,OAAO,KAAK,MAAM,QAAQ,MAAM,IAAI;AACrC"}
|
|
1
|
+
{"version":3,"file":"inspect.js","names":[],"sources":["../src/inspect.ts"],"sourcesContent":["/**\n * A cheap, flat snapshot of what a `.pptx` contains: every element on every\n * slide, with its slide-absolute box and the handful of text/fill properties a\n * layout audit asks about.\n *\n * It is a **projection over `pptx-ts/read`**, not a second reader. `read` gives a\n * navigable, mutable model of a package and answers questions in the shape of the\n * OOXML tree; this answers one flat question — \"what is on the slides, and where\"\n * — in the shape a linter, an overlap check, or a diffing tool wants. The two used\n * to be independent implementations over two different XML parsers, which meant\n * every read-side fix had to be made twice and a divergence between them was\n * invisible to every test. Now the model below is the only reader, and this file\n * is the flattening.\n *\n * What it deliberately does NOT do, and why the projection is not just\n * `Presentation` re-exported:\n * - **Only geometry a shape carries itself.** A placeholder that inherits its box\n * from the layout is omitted rather than resolved (`absoluteFrame`, not\n * `resolvedFrame`) — the snapshot reports what the slide states.\n * - **A `p:graphicFrame` is a box, not its contents.** A table, chart or SmartArt\n * graphic is reported as one element with its box, its kind, and the text a\n * reader sees on the slide, but its structure is not flattened: no per-run\n * formatting, no cells, no series. Walk `pptx-ts/read` for what is inside one.\n *\n * @module\n */\nimport { warn } from './diagnostics.js'\nimport { OpcPackage } from './read/opc/package.js'\nimport { Presentation } from './read/api/presentation.js'\nimport type { AnyShape } from './read/api/shapes.js'\nimport type { GraphicFrame } from './read/api/shapes/graphic-frame.js'\nimport type { Run, TextFrame } from './read/api/text.js'\nimport { POINTS_PER_INCH, emuToInches } from './units.js'\nimport { BODY_INSET_DEFAULTS_PT } from './ooxml/body-insets.js'\nimport { ABSENT_SLIDE_SIZE_EMU } from './ooxml/slide-size.js'\n\n/**\n * Input to the inspect surface. A `string` is a **filesystem path** (Node) read\n * from disk; pass `Uint8Array`/`ArrayBuffer`/`Blob`/`number[]` for an in-memory\n * archive. (A string is a path, not JSZip's latin1 binary content — see\n * `ZipInput`.)\n */\nexport type PptxInspectInputValue = string | number[] | Uint8Array | ArrayBuffer | Blob\n\nexport type PptxInspectInput = PptxInspectInputValue | Promise<PptxInspectInputValue>\n\nexport interface PptxSlideSize {\n\twidthIn: number\n\theightIn: number\n}\n\nexport interface PptxBox {\n\tx: number\n\ty: number\n\tw: number\n\th: number\n}\n\nexport interface PptxTextRun {\n\ttext: string\n\tfontSizePt: number | null\n\tcolor: string | null\n\t/** Run font face (`a:rPr > a:latin@typeface`), or null when it inherits from the theme/placeholder. */\n\tfontFace: string | null\n\t/** Bold (`a:rPr@b`). */\n\tbold: boolean\n\t/** Italic (`a:rPr@i`). */\n\titalic: boolean\n\t/** Strikethrough token (`a:rPr@strike`: `noStrike`/`sngStrike`/`dblStrike`), or null when unset. */\n\tstrike: string | null\n\t/** Highlight colour hex (`a:rPr > a:highlight`), or null when unset. A theme token is resolved against the slide's theme. */\n\thighlight: string | null\n\t/** Character spacing in points (`a:rPr@spc`, authored in hundredths of a point), or null when unset. */\n\tcharSpacingPt: number | null\n}\n\n/**\n * One paragraph (`a:p`): its runs in document order. Preserves the paragraph/line\n * boundaries that the flat {@link PptxSlideElement.textRuns} list discards — needed\n * to measure a `wrap=\"none\"` frame line-by-line (each paragraph is one unwrapped line).\n */\nexport interface PptxParagraph {\n\truns: PptxTextRun[]\n}\n\n/**\n * What an element is. `'group'` is a `p:grpSp` container: it has its own identity,\n * box, and fill, but no text of its own — its content is the elements that name it\n * in {@link PptxSlideElement.parentZIndex}. `'graphicFrame'` is a `p:graphicFrame`\n * hosting a table, a chart or a SmartArt graphic; {@link PptxSlideElement.graphicKind}\n * says which, and it keeps that kind even when it carries text (a `'text'` element is\n * always a `p:sp`).\n */\nexport type PptxSlideElementKind = 'text' | 'image' | 'shape' | 'group' | 'graphicFrame'\n\n/**\n * What a `'graphicFrame'` element hosts, read from its `a:graphicData/@uri`:\n * a table (`a:tbl`), a classic chart (`c:chart`), a 2016-family chart\n * (`cx:chartSpace`: waterfall/funnel/treemap/…), or a SmartArt diagram. `'other'`\n * is a frame whose URI matches none of those — an OLE object, an ink part, a 3D\n * model — reported as a box so it is not silently missing from the slide.\n */\nexport type PptxGraphicKind = 'table' | 'chart' | 'chartEx' | 'diagram' | 'other'\n\n/**\n * Vertical-autofit mode of a text frame, read from the `a:bodyPr` child element:\n * - `'none'`: no autofit (`a:noAutofit`, or no autofit child at all). The box has a\n * fixed height the text must fit inside — a genuine overflow candidate.\n * - `'normAutofit'`: shrink text to fit (`a:normAutofit`, ts-pptx `fit: 'shrink'`).\n * Text is downscaled rather than overflowing.\n * - `'spAutoFit'`: resize shape to fit text (`a:spAutoFit`, ts-pptx `fit: 'resize'`).\n * The authored height is an output, not a constraint, so the box cannot overflow.\n */\nexport type PptxAutofitMode = 'none' | 'normAutofit' | 'spAutoFit'\n\n/**\n * Text-frame body insets in inches (`a:bodyPr` `lIns`/`tIns`/`rIns`/`bIns`), with\n * PowerPoint defaults applied when an attribute is absent (0.1in left/right,\n * 0.05in top/bottom). Subtract these from {@link PptxBox} to get the inner text box.\n */\nexport interface PptxBodyInsets {\n\tleft: number\n\ttop: number\n\tright: number\n\tbottom: number\n}\n\nexport interface PptxSlideElement {\n\t/** `p:cNvPr/@id`, or `zIndex + 1` when the attribute is missing. */\n\tid: number\n\tname: string\n\tkind: PptxSlideElementKind\n\t/**\n\t * What a `'graphicFrame'` element hosts, or `null` for every other kind. See\n\t * {@link PptxGraphicKind}.\n\t */\n\tgraphicKind: PptxGraphicKind | null\n\t/**\n\t * Paint order on the slide, `0`-based: the element's position in a depth-first\n\t * walk of `p:spTree` in document order. A group is immediately followed by its\n\t * own children, which is also the order PowerPoint paints them, so a higher\n\t * `zIndex` draws on top. Unique within a slide, which is what\n\t * {@link parentZIndex} / {@link childZIndices} key on.\n\t */\n\tzIndex: number\n\t/**\n\t * Position and size in **slide-absolute** inches, composing every enclosing\n\t * group transform — directly comparable across elements whether or not they are\n\t * grouped. For a rotated element this is the unrotated placement box (the box\n\t * PowerPoint writes after Ungroup); see {@link rotation}.\n\t */\n\tbox: PptxBox\n\t/**\n\t * Effective clockwise rotation in degrees, normalised to `[0, 360)`, after\n\t * composing the element's own `a:xfrm@rot` with every enclosing group rotation.\n\t */\n\trotation: number\n\t/** Effective horizontal flip, XOR-composing the element's own `@flipH` with enclosing group flips. */\n\tflipH: boolean\n\t/** Effective vertical flip, XOR-composing the element's own `@flipV` with enclosing group flips. */\n\tflipV: boolean\n\t/** {@link zIndex} of the enclosing `'group'` element, or `null` when the element sits at slide level. */\n\tparentZIndex: number | null\n\t/** {@link zIndex} of each direct child, in document order. Empty unless {@link kind} is `'group'`. */\n\tchildZIndices: number[]\n\t/**\n\t * The element's text, whitespace-collapsed to one line. For a `'graphicFrame'`\n\t * this is the text the structure puts on the slide (table cells in row order,\n\t * SmartArt node text), which is what {@link PptxSlideInspection.text} and\n\t * `wordCount` then count; a chart contributes nothing, matching `Slide.text` on\n\t * the read model. That text has no {@link textRuns} or {@link paragraphs} here —\n\t * per-run formatting inside a structure is what this surface does not flatten.\n\t */\n\ttext: string\n\ttextWrap: string | null\n\tautofit: PptxAutofitMode | null\n\t/**\n\t * Baked shrink scale from `<a:normAutofit@fontScale>` as a percent (62.5 = 62.5%),\n\t * or null when the frame has no `normAutofit` or bakes no scale (a bare\n\t * `<a:normAutofit/>`, which PowerPoint draws at 100% until edited).\n\t */\n\tautofitFontScale: number | null\n\tbodyInsets: PptxBodyInsets | null\n\ttextRuns: PptxTextRun[]\n\t/** Runs grouped by their source paragraph (`a:p`), in document order. */\n\tparagraphs: PptxParagraph[]\n\tfontSizes: number[]\n\tcolors: string[]\n\tfill: string | null\n\tline: string | null\n\tshapeType: string | null\n}\n\nexport interface PptxSlideInspection {\n\tindex: number\n\tname: string\n\tpath: string\n\tsize: PptxSlideSize\n\telements: PptxSlideElement[]\n\ttext: string\n\twordCount: number\n}\n\nexport interface PptxInspection {\n\tslideSize: PptxSlideSize\n\tslides: PptxSlideInspection[]\n}\n\nexport type PptxBoxAxis = 'x' | 'y'\nexport type PptxBoxAnchor = 'left' | 'center' | 'right' | 'top' | 'middle' | 'bottom'\n\n/**\n * The size reported for a deck that declares no `p:sldSz`: the 10in × 7.5in PowerPoint opens such\n * a deck at, which is also what the script converter assumes. It was the widescreen size, so the\n * two readers disagreed about the same deck. See `ABSENT_SLIDE_SIZE_EMU`.\n */\nexport const DEFAULT_INSPECT_SLIDE_SIZE: PptxSlideSize = Object.freeze({\n\twidthIn: round(emuToInches(ABSENT_SLIDE_SIZE_EMU.widthEmu), 3),\n\theightIn: round(emuToInches(ABSENT_SLIDE_SIZE_EMU.heightEmu), 3),\n})\n\n/* ────────────────────────────────────────────────────────────────────────────\n * Package layer\n *\n * Thin conveniences over `OpcPackage`, kept because this surface speaks zip\n * paths (`ppt/slides/slide1.xml`) while OPC speaks partnames (`/ppt/...`), and\n * because reaching a part's bytes is the one thing a caller of a *flat* surface\n * still routinely needs.\n * ──────────────────────────────────────────────────────────────────────────── */\n\n/**\n * Load a `.pptx` as an {@link OpcPackage} — the same package model `pptx-ts/read`\n * uses, so a caller that starts here can hand the result straight to\n * `Presentation.fromPackage()` without re-reading the bytes.\n *\n * The input must be a real OPC package: a zip that merely contains some slide XML\n * but no `[Content_Types].xml` is rejected with a `PackageReadError`.\n */\nexport async function loadPptxPackage(input: PptxInspectInput): Promise<OpcPackage> {\n\treturn OpcPackage.load(await input)\n}\n\n/** Every part in the package, as zip paths (`ppt/slides/slide1.xml`), sorted. */\nexport function listPptxParts(pptxPackage: OpcPackage): string[] {\n\treturn [...pptxPackage.parts.keys()].map(zipPathOf).sort()\n}\n\n/** Read a package part as UTF-8 text, or `null` when the part is absent. */\nexport async function readPptxTextPart(pptxPackage: OpcPackage, path: string): Promise<string | null> {\n\tconst bytes = await readPptxBinaryPart(pptxPackage, path)\n\treturn bytes ? textDecoder.decode(bytes) : null\n}\n\n/**\n * Read a package part as raw bytes — the binary sibling of {@link readPptxTextPart}\n * for embedded media (SVG/PNG/EMF blobs, fonts, …) that must not be UTF-8 decoded.\n * Returns `null` when the part is absent. The `Uint8Array` is browser-isomorphic;\n * Node consumers can wrap it with `Buffer.from(...)` if they need Buffer methods.\n *\n * The part's current body, so a package also opened as a `Presentation` and edited\n * reads back with its edits.\n */\nexport async function readPptxBinaryPart(pptxPackage: OpcPackage, path: string): Promise<Uint8Array | null> {\n\treturn pptxPackage.part(partNameOf(path))?.serialize() ?? null\n}\n\nconst textDecoder = new TextDecoder('utf-8')\n\n/** OPC partnames are absolute (`/ppt/…`); this surface speaks zip paths (`ppt/…`). */\nfunction zipPathOf(partName: string): string {\n\treturn partName.startsWith('/') ? partName.slice(1) : partName\n}\n\nfunction partNameOf(zipPath: string): string {\n\treturn zipPath.startsWith('/') ? zipPath : `/${zipPath}`\n}\n\n/* ────────────────────────────────────────────────────────────────────────────\n * The surface\n * ──────────────────────────────────────────────────────────────────────────── */\n\nexport async function inspectPptx(input: PptxInspectInput): Promise<PptxInspection> {\n\tconst pptxPackage = await loadPptxPackage(input)\n\tconst slideSize = await readPresentationSize(pptxPackage)\n\tconst slides = await extractSlides(pptxPackage, slideSize)\n\treturn { slideSize, slides }\n}\n\nexport async function readPresentationSize(\n\tpptxPackage: OpcPackage,\n\tfallback: PptxSlideSize = DEFAULT_INSPECT_SLIDE_SIZE\n): Promise<PptxSlideSize> {\n\tconst size = presentationOf(pptxPackage)?.slideSize\n\tif (!size) return fallback\n\treturn { widthIn: round(size.widthIn, 3), heightIn: round(size.heightIn, 3) }\n}\n\n/**\n * Every slide in the deck, in **presentation order** (`p:sldIdLst`) — the order\n * PowerPoint shows them in, which is not the order their parts are named once a\n * deck has been reordered.\n */\nexport async function extractSlides(pptxPackage: OpcPackage, size?: PptxSlideSize): Promise<PptxSlideInspection[]> {\n\tconst slideSize = size || (await readPresentationSize(pptxPackage))\n\tconst presentation = presentationOf(pptxPackage)\n\tif (!presentation) return []\n\n\treturn presentation.slides.map((slide, index) => {\n\t\tconst path = zipPathOf(slide.partName)\n\t\tconst harvested: HarvestedShape[] = []\n\t\tharvest(slide.shapes, null, harvested) // slide level: no enclosing group\n\t\tconst elements = flatten(harvested, path)\n\t\tconst text = elements\n\t\t\t.map((el) => el.text)\n\t\t\t.filter(Boolean)\n\t\t\t.join(' ')\n\n\t\treturn {\n\t\t\tindex,\n\t\t\tname: slide.name || `Slide ${index + 1}`,\n\t\t\tpath,\n\t\t\tsize: slideSize,\n\t\t\telements,\n\t\t\ttext,\n\t\t\twordCount: countWords(text),\n\t\t}\n\t})\n}\n\n/**\n * The deck's `Presentation`, or `null` when the package holds no readable\n * `presentation.xml`. Callers here are auditing files they did not author, so a\n * package that is a valid OPC container but not a presentation reports an empty\n * deck rather than throwing. `presentationPart` is the throw site: it rejects a\n * package with no — or more than one — office-document relationship.\n */\nfunction presentationOf(pptxPackage: OpcPackage): Presentation | null {\n\tconst presentation = Presentation.fromPackage(pptxPackage)\n\ttry {\n\t\treturn presentation.presentationPart.isXmlPart ? presentation : null\n\t} catch {\n\t\treturn null\n\t}\n}\n\nexport function overlapArea(a: PptxBox, b: PptxBox): number {\n\tconst x = Math.max(0, Math.min(a.x + a.w, b.x + b.w) - Math.max(a.x, b.x))\n\tconst y = Math.max(0, Math.min(a.y + a.h, b.y + b.h) - Math.max(a.y, b.y))\n\treturn x * y\n}\n\nexport function boxAnchor(box: PptxBox, anchor: PptxBoxAnchor, axis: PptxBoxAxis): number {\n\tif (axis === 'x') {\n\t\tif (anchor === 'left') return box.x\n\t\tif (anchor === 'right') return box.x + box.w\n\t\treturn box.x + box.w / 2\n\t}\n\tif (anchor === 'top') return box.y\n\tif (anchor === 'bottom') return box.y + box.h\n\treturn box.y + box.h / 2\n}\n\n/* ────────────────────────────────────────────────────────────────────────────\n * Shape-tree harvest\n * ──────────────────────────────────────────────────────────────────────────── */\n\n/** One harvested shape, before it is flattened into a {@link PptxSlideElement}. */\ninterface HarvestedShape {\n\tshape: AnyShape\n\tparentZIndex: number | null\n\tchildZIndices: number[]\n}\n\n/**\n * Flatten a shape list depth-first in document order: each shape is followed by\n * its descendants, which is both paint order and the order the\n * {@link PptxSlideElement.zIndex} contract promises. Every entry's index in `out`\n * is its zIndex. Returns the zIndices assigned at this level, which is what the\n * enclosing group records as its {@link PptxSlideElement.childZIndices}.\n */\nfunction harvest(shapes: AnyShape[], parentZIndex: number | null, out: HarvestedShape[]): number[] {\n\tconst zIndices: number[] = []\n\tfor (const shape of shapes) {\n\t\tconst entry: HarvestedShape = { shape, parentZIndex, childZIndices: [] }\n\t\tconst zIndex = out.push(entry) - 1\n\t\tzIndices.push(zIndex)\n\t\tif (shape.shapeType === 'group') entry.childZIndices = harvest(shape.shapes, zIndex, out)\n\t}\n\treturn zIndices\n}\n\n/**\n * Turn harvested shapes into elements, dropping the ones with no resolvable slide\n * position. A dropped shape keeps its zIndex — the numbers are positions in the\n * shape tree, and renumbering them would silently repoint every `parentZIndex`.\n */\nfunction flatten(harvested: HarvestedShape[], slidePath: string): PptxSlideElement[] {\n\treturn harvested\n\t\t.map((entry, zIndex) => toElement(entry, zIndex, slidePath))\n\t\t.filter((element): element is PptxSlideElement => Boolean(element))\n}\n\nfunction toElement(entry: HarvestedShape, zIndex: number, slidePath: string): PptxSlideElement | null {\n\tconst { shape } = entry\n\tconst frame = shape.absoluteFrame\n\tif (!frame) {\n\t\treportUnresolvable(shape, zIndex, slidePath)\n\t\treturn null\n\t}\n\n\t// Only `p:sp` holds a text body, so every other kind projects as an empty frame.\n\tconst textFrame = shape.textFrame\n\tconst paragraphs = textFrame ? textFrame.paragraphs.map((p) => ({ runs: p.runs.map(toRun) })) : []\n\tconst textRuns = paragraphs.flatMap((paragraph) => paragraph.runs)\n\t// A graphic frame has no text body of its own; its text comes from the structure\n\t// it hosts, and arrives as a plain string with no runs behind it.\n\t// Paragraphs are joined by a line break, so the last word of one and the first of the next stay\n\t// two words once the whitespace collapses below.\n\tconst runText = paragraphs.map((paragraph) => paragraph.runs.map((run) => run.text).join('')).join('\\n')\n\tconst raw = shape.shapeType === 'graphicFrame' ? graphicFrameText(shape) : runText\n\t// Deliberately not `TextFrame.text`: this is one whitespace-collapsed line for\n\t// matching and word-counting, not the frame's text with its line structure.\n\tconst text = raw.replace(/\\s+/g, ' ').trim()\n\tconst kind: PptxSlideElementKind =\n\t\tshape.shapeType === 'group'\n\t\t\t? 'group'\n\t\t\t: shape.shapeType === 'graphicFrame'\n\t\t\t\t? 'graphicFrame'\n\t\t\t\t: text\n\t\t\t\t\t? 'text'\n\t\t\t\t\t: shape.shapeType === 'picture'\n\t\t\t\t\t\t? 'image'\n\t\t\t\t\t\t: 'shape'\n\n\treturn {\n\t\tid: shape.id ?? zIndex + 1,\n\t\tname: shape.name || `${kind} ${zIndex + 1}`,\n\t\tkind,\n\t\tgraphicKind: shape.shapeType === 'graphicFrame' ? graphicKindOf(shape) : null,\n\t\tzIndex,\n\t\tbox: {\n\t\t\tx: emuToInches(frame.left),\n\t\t\ty: emuToInches(frame.top),\n\t\t\tw: emuToInches(frame.width),\n\t\t\th: emuToInches(frame.height),\n\t\t},\n\t\trotation: frame.rotation,\n\t\tflipH: frame.flipH,\n\t\tflipV: frame.flipV,\n\t\tparentZIndex: entry.parentZIndex,\n\t\tchildZIndices: entry.childZIndices,\n\t\ttext,\n\t\ttextWrap: textFrame?.bodyProperties?.wrap ?? null,\n\t\tautofit: textFrame?.autofit ?? null,\n\t\tautofitFontScale: textFrame?.autofitFontScale ?? null,\n\t\tbodyInsets: readBodyInsets(textFrame),\n\t\ttextRuns,\n\t\tparagraphs,\n\t\tfontSizes: [...new Set(textRuns.map((run) => run.fontSizePt).filter((size): size is number => size !== null))],\n\t\tcolors: [...new Set(textRuns.map((run) => run.color).filter((color): color is string => Boolean(color)))],\n\t\tfill: shape.fillColor,\n\t\tline: shape.lineColor,\n\t\tshapeType: shape.presetGeometry,\n\t}\n}\n\n/**\n * What a graphic frame hosts, from the same `a:graphicData/@uri` the read model's\n * `has*` predicates compare against. A frame that answers none of them is `'other'`\n * rather than dropped: a box the deck's author placed is on the slide whether or not\n * this library models its payload, and an overlap or coverage check that skipped it\n * would report a gap where a 3D model or an OLE object sits.\n */\nfunction graphicKindOf(frame: GraphicFrame): PptxGraphicKind {\n\tif (frame.hasTable) return 'table'\n\tif (frame.hasChart) return 'chart'\n\tif (frame.hasChartEx) return 'chartEx'\n\tif (frame.hasDiagram) return 'diagram'\n\treturn 'other'\n}\n\n/**\n * The text a graphic frame puts on the slide: table cells in row order, or SmartArt\n * node text. Charts contribute nothing, matching `Slide.text` on the read model — a\n * chart's strings are data labels and axis titles that PowerPoint itself does not\n * treat as slide body text.\n *\n * Separators are single spaces rather than the read model's `\t`/`\n`, because the\n * caller collapses whitespace anyway; the point here is only that cells do not run\n * together into one word.\n */\nfunction graphicFrameText(frame: GraphicFrame): string {\n\tconst table = frame.table\n\tif (table) return table.rows.map((row) => row.cells.map((cell) => cell.text).join(' ')).join(' ')\n\treturn frame.diagram?.text ?? ''\n}\n\n/** Project one read-model {@link Run} onto the flat run shape. */\nfunction toRun(run: Run): PptxTextRun {\n\treturn {\n\t\ttext: run.text,\n\t\tfontSizePt: run.fontSizePt,\n\t\tcolor: run.color,\n\t\tfontFace: run.fontName,\n\t\t// The read model distinguishes \"explicitly not bold\" from \"unset, inherits\";\n\t\t// this surface reports what renders, so an unset flag is `false`.\n\t\tbold: run.bold ?? false,\n\t\titalic: run.italic ?? false,\n\t\tstrike: run.strike,\n\t\thighlight: run.highlight?.hex ?? null,\n\t\tcharSpacingPt: run.charSpacingPt,\n\t}\n}\n\nfunction readBodyInsets(textFrame: TextFrame | null): PptxBodyInsets | null {\n\tconst insets = textFrame?.bodyProperties?.insetsPt\n\tif (!insets) return null\n\t// The read model reports only the explicitly-set sides; an omitted one takes PowerPoint's\n\t// own default rather than zero.\n\tconst inches = (pt: number | undefined, fallbackPt: number): number =>\n\t\t(pt === undefined ? fallbackPt : pt) / POINTS_PER_INCH\n\treturn {\n\t\tleft: inches(insets.left, BODY_INSET_DEFAULTS_PT.left),\n\t\ttop: inches(insets.top, BODY_INSET_DEFAULTS_PT.top),\n\t\tright: inches(insets.right, BODY_INSET_DEFAULTS_PT.right),\n\t\tbottom: inches(insets.bottom, BODY_INSET_DEFAULTS_PT.bottom),\n\t}\n}\n\n/**\n * Warn about a shape whose slide position cannot be resolved, unless it never\n * claimed one.\n *\n * `absoluteFrame` is `null` for three different situations and only two of them\n * are worth telling the caller about; `absoluteFrameFailure` is the read model\n * naming which, so this surface does not walk the ancestry a second time to\n * re-derive it.\n */\nfunction reportUnresolvable(shape: AnyShape, zIndex: number, slidePath: string): void {\n\tconst failure = shape.absoluteFrameFailure\n\t// No own `a:xfrm` at all: the shape inherits its geometry from a layout\n\t// placeholder, which this surface deliberately does not resolve. Nothing is\n\t// wrong with the deck, so nothing is reported. (`null` cannot reach here — the\n\t// caller only calls this for a shape whose frame did not resolve.)\n\tif (failure === null || failure === 'no-own-transform') return\n\n\tconst who = shape.name ? `\"${shape.name}\"` : `the element at zIndex ${zIndex}`\n\tif (failure === 'group-transform-missing') {\n\t\twarn(\n\t\t\t'inspect/group-transform-missing',\n\t\t\t`inspect: skipped ${who} on ${slidePath} — an enclosing group has no usable a:xfrm, so its slide position cannot be resolved.`\n\t\t)\n\t\treturn\n\t}\n\twarn(\n\t\t'inspect/group-transform-degenerate',\n\t\t`inspect: skipped ${who} on ${slidePath} — an enclosing group has a degenerate transform (zero a:chExt), so its slide position cannot be resolved.`\n\t)\n}\n\nfunction countWords(text: string): number {\n\treturn text.split(/\\s+/).filter(Boolean).length\n}\n\nfunction round(value: number, digits: number): number {\n\tconst factor = 10 ** digits\n\treturn Math.round(value * factor) / factor\n}\n\n// Error taxonomy — see `entry-errors.ts`. Re-exported from every entry so `instanceof`\n// works whichever subpath a consumer imports.\nexport * from './entry-errors.js'\n\n// Diagnostics — see `entry-diagnostics.ts`. Re-exported from every entry so a consumer of any\n// subpath can install a handler for the warnings that subpath emits.\nexport * from './entry-diagnostics.js'\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAwNA,MAAa,6BAA4C,OAAO,OAAO;CACtE,SAAS,MAAM,YAAY,sBAAsB,QAAQ,GAAG,CAAC;CAC7D,UAAU,MAAM,YAAY,sBAAsB,SAAS,GAAG,CAAC;AAChE,CAAC;;;;;;;;;AAmBD,eAAsB,gBAAgB,OAA8C;CACnF,OAAO,WAAW,KAAK,MAAM,KAAK;AACnC;;AAGA,SAAgB,cAAc,aAAmC;CAChE,OAAO,CAAC,GAAG,YAAY,MAAM,KAAK,CAAC,CAAC,CAAC,IAAI,SAAS,CAAC,CAAC,KAAK;AAC1D;;AAGA,eAAsB,iBAAiB,aAAyB,MAAsC;CACrG,MAAM,QAAQ,MAAM,mBAAmB,aAAa,IAAI;CACxD,OAAO,QAAQ,YAAY,OAAO,KAAK,IAAI;AAC5C;;;;;;;;;;AAWA,eAAsB,mBAAmB,aAAyB,MAA0C;CAC3G,OAAO,YAAY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K;EACxD,QAAQ,OAAO,OAAO,QAAQ,uBAAuB,MAAM;CAC5D;AACD;;;;;;;;;;AAWA,SAAS,mBAAmB,OAAiB,QAAgB,WAAyB;CACrF,MAAM,UAAU,MAAM;CAKtB,IAAI,YAAY,QAAQ,YAAY,oBAAoB;CAExD,MAAM,MAAM,MAAM,OAAO,IAAI,MAAM,KAAK,KAAK,yBAAyB;CACtE,IAAI,YAAY,2BAA2B;EAC1C,KACC,mCACA,oBAAoB,IAAI,MAAM,UAAU,sFACzC;EACA;CACD;CACA,KACC,sCACA,oBAAoB,IAAI,MAAM,UAAU,2GACzC;AACD;AAEA,SAAS,WAAW,MAAsB;CACzC,OAAO,KAAK,MAAM,KAAK,CAAC,CAAC,OAAO,OAAO,CAAC,CAAC;AAC1C;AAEA,SAAS,MAAM,OAAe,QAAwB;CACrD,MAAM,SAAS,MAAM;CACrB,OAAO,KAAK,MAAM,QAAQ,MAAM,IAAI;AACrC"}
|
package/dist/math.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as
|
|
1
|
+
import { _ as PackageReadErrorCode, a as InternalError, c as PackageReadError, d as UnsupportedFeatureError, f as DiagnosticCode, g as MediaErrorCode, h as InvalidOptionErrorCode, i as setDiagnosticHandler, l as TsPptxError, m as InternalErrorCode, n as DiagnosticHandler, o as InvalidOptionError, p as ErrorCode, r as resetDiagnosticState, s as MediaError, t as Diagnostic, u as TsPptxErrorOptions, v as TsPptxCode, y as UnsupportedFeatureErrorCode } from "./diagnostics-D8ot4Ei7.js";
|
|
2
2
|
//#region src/math.d.ts
|
|
3
3
|
/**
|
|
4
4
|
* Convert a MathML string to OMML for the `math:` option on `addText`.
|
|
@@ -8,9 +8,11 @@ import { a as TsPptxError, d as InvalidOptionErrorCode, f as MediaErrorCode, h a
|
|
|
8
8
|
*
|
|
9
9
|
* @param mathml - a MathML string (e.g. `<math>…</math>`)
|
|
10
10
|
* @returns OMML `<m:oMath>…</m:oMath>`
|
|
11
|
+
* @throws {InvalidOptionError} `math/invalid-mathml` when the input has no `<math>` element, or
|
|
12
|
+
* does not convert to an equation. The converter returns the string `'undefined'` for such input.
|
|
11
13
|
*/
|
|
12
|
-
declare function mathmlToOmml(mathml: string): string;
|
|
13
|
-
interface LatexToOmmlOptions {
|
|
14
|
+
export declare function mathmlToOmml(mathml: string): string;
|
|
15
|
+
export interface LatexToOmmlOptions {
|
|
14
16
|
/**
|
|
15
17
|
* Display (block) math: render in `displayMode` and wrap the result in
|
|
16
18
|
* `<m:oMathPara>` (a centered display-math paragraph). Default `true`. When `false`,
|
|
@@ -31,7 +33,7 @@ interface LatexToOmmlOptions {
|
|
|
31
33
|
* @returns OMML `<m:oMathPara>…</m:oMathPara>` (display) or `<m:oMath>…</m:oMath>` (inline)
|
|
32
34
|
* @throws {Error} if the LaTeX cannot be parsed
|
|
33
35
|
*/
|
|
34
|
-
declare function latexToOmml(latex: string, opts?: LatexToOmmlOptions): string;
|
|
36
|
+
export declare function latexToOmml(latex: string, opts?: LatexToOmmlOptions): string;
|
|
35
37
|
//#endregion
|
|
36
|
-
export { type ErrorCode, InternalError, type InternalErrorCode, InvalidOptionError, type InvalidOptionErrorCode,
|
|
38
|
+
export { type Diagnostic, type DiagnosticCode, type DiagnosticHandler, type ErrorCode, InternalError, type InternalErrorCode, InvalidOptionError, type InvalidOptionErrorCode, MediaError, type MediaErrorCode, PackageReadError, type PackageReadErrorCode, type TsPptxCode, TsPptxError, type TsPptxErrorOptions, UnsupportedFeatureError, type UnsupportedFeatureErrorCode, resetDiagnosticState, setDiagnosticHandler };
|
|
37
39
|
//# sourceMappingURL=math.d.ts.map
|
package/dist/math.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"math.d.ts","names":[],"sources":["../src/math.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"math.d.ts","names":[],"sources":["../src/math.ts"],"mappings":";;;;;;;;;;;;;wBA0MgB,aAAa;iBAkBZ;;;;;;EAMhB;;;;;;;;;;;;;;;wBAgBe,YAAY,eAAe,OAAM"}
|
package/dist/math.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { a as TsPptxError, i as PackageReadError, n as InvalidOptionError, o as UnsupportedFeatureError, r as MediaError, t as InternalError } from "./errors-
|
|
1
|
+
import { a as TsPptxError, c as setDiagnosticHandler, i as PackageReadError, n as InvalidOptionError, o as UnsupportedFeatureError, r as MediaError, s as resetDiagnosticState, t as InternalError } from "./errors-C4oENPcu.js";
|
|
2
2
|
import { createRequire } from "node:module";
|
|
3
3
|
//#region src/math.ts
|
|
4
4
|
/**
|
|
5
|
-
*
|
|
6
|
-
* OMML for the `math:` option on `addText` (see
|
|
5
|
+
* Author display equations in LaTeX or MathML and get
|
|
6
|
+
* OMML for the `math:` option on `addText` (see `TextProps.math`).
|
|
7
7
|
*
|
|
8
8
|
* Pipeline: LaTeX --temml--> MathML --mathml2omml--> OMML.
|
|
9
9
|
*
|
|
@@ -20,12 +20,12 @@ import { createRequire } from "node:module";
|
|
|
20
20
|
* default `latexToOmml()` returns a centered display `<m:oMathPara>`, while
|
|
21
21
|
* `latexToOmml(tex, { display: false })` (and `mathmlToOmml()`) return the bare
|
|
22
22
|
* `<m:oMath>` form you pass to a text item with `inline: true` to flow it
|
|
23
|
-
* mid-paragraph (see
|
|
23
|
+
* mid-paragraph (see `TextProps.inline`).
|
|
24
24
|
*
|
|
25
25
|
* @module
|
|
26
26
|
*/
|
|
27
27
|
const nodeRequire = createRequire(import.meta.url);
|
|
28
|
-
const MISSING_DEPS_MESSAGE = "
|
|
28
|
+
const MISSING_DEPS_MESSAGE = "pptx-ts/math requires the optional peer dependencies 'temml' and 'mathml2omml'. Install them with: npm install temml mathml2omml";
|
|
29
29
|
/** Require an optional peer, remapping a not-found error to the install hint. */
|
|
30
30
|
function requirePeer(id) {
|
|
31
31
|
try {
|
|
@@ -163,9 +163,18 @@ function markAccentedMovers(mathml) {
|
|
|
163
163
|
*
|
|
164
164
|
* @param mathml - a MathML string (e.g. `<math>…</math>`)
|
|
165
165
|
* @returns OMML `<m:oMath>…</m:oMath>`
|
|
166
|
+
* @throws {InvalidOptionError} `math/invalid-mathml` when the input has no `<math>` element, or
|
|
167
|
+
* does not convert to an equation. The converter returns the string `'undefined'` for such input.
|
|
166
168
|
*/
|
|
167
169
|
function mathmlToOmml(mathml) {
|
|
168
|
-
|
|
170
|
+
const mml2omml = loadMml2omml();
|
|
171
|
+
if (typeof mathml !== "string" || !/<(?:[\w-]+:)?math[\s>]/.test(mathml)) {
|
|
172
|
+
const got = typeof mathml === "string" ? JSON.stringify(mathml.slice(0, 40)) : typeof mathml;
|
|
173
|
+
throw new InvalidOptionError("math/invalid-mathml", `mathmlToOmml: expected MathML with a <math> element, got ${got}`);
|
|
174
|
+
}
|
|
175
|
+
const omml = stripOMathNamespaces(String(mml2omml(mathml)).trim());
|
|
176
|
+
if (/^<([\w:]+)/.exec(omml)?.[1] !== "m:oMath") throw new InvalidOptionError("math/invalid-mathml", "mathmlToOmml: the MathML did not convert to an OMML equation");
|
|
177
|
+
return omml;
|
|
169
178
|
}
|
|
170
179
|
/**
|
|
171
180
|
* Convert a LaTeX string to OMML for the `math:` option on `addText`.
|
|
@@ -198,6 +207,6 @@ function latexToOmml(latex, opts = {}) {
|
|
|
198
207
|
return display ? `<m:oMathPara>${DISPLAY_PARA_PR}${oMath}</m:oMathPara>` : oMath;
|
|
199
208
|
}
|
|
200
209
|
//#endregion
|
|
201
|
-
export { InternalError, InvalidOptionError, MediaError, PackageReadError, TsPptxError, UnsupportedFeatureError, latexToOmml, mathmlToOmml };
|
|
210
|
+
export { InternalError, InvalidOptionError, MediaError, PackageReadError, TsPptxError, UnsupportedFeatureError, latexToOmml, mathmlToOmml, resetDiagnosticState, setDiagnosticHandler };
|
|
202
211
|
|
|
203
212
|
//# sourceMappingURL=math.js.map
|