pptx-ts 0.0.1 → 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-js0QpRV-.d.ts → pres-C6qgOFAa.d.ts} +1021 -1370
- package/dist/pres-C6qgOFAa.d.ts.map +1 -0
- package/dist/{presentation-Cp7vzlAw.js → presentation-DGYlAWhl.js} +3208 -2727
- package/dist/presentation-DGYlAWhl.js.map +1 -0
- package/dist/{presentation-types-DP_8jog7.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-Du_s75MT.d.ts +0 -829
- package/dist/diagnostics-Du_s75MT.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-RLCwdlTE.js +0 -1703
- package/dist/notes-RLCwdlTE.js.map +0 -1
- package/dist/package-CaOLXSNi.d.ts.map +0 -1
- package/dist/pres-C5__xkDh.d.ts +0 -202
- package/dist/pres-C5__xkDh.d.ts.map +0 -1
- package/dist/presentation-Cp7vzlAw.js.map +0 -1
- package/dist/presentation-types-DP_8jog7.d.ts.map +0 -1
- package/dist/shapes-BemroU-z.js.map +0 -1
- package/dist/slide-js0QpRV-.d.ts.map +0 -1
- package/dist/text-CyetbF6p.js +0 -11278
- package/dist/text-CyetbF6p.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
|
@@ -0,0 +1,1046 @@
|
|
|
1
|
+
import { d as SHAPE_NAME, i as CHART_NAME, m as SlideObjectType, v as WRITE_OUTPUT_TYPE } from "./enums-BUKTUB6V.js";
|
|
2
|
+
import { Bt as TextMeasurement, Ft as TableLayoutResult, Ht as TextPropsOptions, Kt as ImageProps, Nt as SlideComment, Ot as MeasureTextOptions, Q as ChartOpts, S as HexColor, Vt as TextProps, Z as ChartMulti, c as WriteFileProps, d as ThemeProps, f as BackgroundOption, i as PresLayout, jt as OverflowBoxOptions, kt as NotesProps, l as WriteProps, n as PackagePart, nn as ShapeProps, o as SectionProps, r as PartsProps, s as WriteBaseProps, t as CustomPropertyValue, xt as OptsChartData } from "./pres-C6qgOFAa.js";
|
|
3
|
+
import { L as TableToSlidesProps, M as TableProps, N as TableRow, S as AnimationProps, T as TransitionProps, a as Slide, b as SlideMasterProps, n as GroupChildProps, o as SlideLayout, r as GroupProps, s as SlideObjectInfo, t as AddSlideProps, x as SlideNumberProps, y as SlideMasterObject } from "./slide-Dx2ZeVZ6.js";
|
|
4
|
+
import { r as EmbeddedFontSlot } from "./embedded-fonts-DarT9aoa.js";
|
|
5
|
+
import { A as SlideObject, D as SectionInternalProps, E as PresentationPropsInternal, M as SlideRelChart, N as SlideRelMedia, O as SlideLayoutInternal, T as PresSlideInternal, j as SlideRel, k as SlideMasterInternal, n as FontMetricsRegistry, w as ObjectOptionsInternal } from "./font-metrics-v5fn7s7e.js";
|
|
6
|
+
import { s as MediaError } from "./diagnostics-D8ot4Ei7.js";
|
|
7
|
+
import { c as ExtractedSlides, s as ExtractedSlide } from "./presentation-types-8jLQHI4M.js";
|
|
8
|
+
import { r as ZipWriter } from "./zip-C0leZZMj.js";
|
|
9
|
+
//#region src/runtime/types.d.ts
|
|
10
|
+
type RuntimeAdapter = {
|
|
11
|
+
readonly writeFileOutputType: WRITE_OUTPUT_TYPE | null;
|
|
12
|
+
/**
|
|
13
|
+
* Load a media file into a base64 payload for `rel.data`.
|
|
14
|
+
*
|
|
15
|
+
* **Two encodings are accepted, deliberately.** Either raw base64 (`iVBORw0…`) or a full
|
|
16
|
+
* data URI (`data:image/png;base64,iVBORw0…`). The browser adapter returns the second
|
|
17
|
+
* because `FileReader.readAsDataURL` is what decodes a blob without blocking; Node and the
|
|
18
|
+
* neutral adapter return the first because neither has a `FileReader`. So an adapter may
|
|
19
|
+
* return whichever its host makes cheap: `gen/media.ts` puts the result through
|
|
20
|
+
* {@link toMediaDataUri} on the way into `rel.data`, and everything past that point sees one
|
|
21
|
+
* form. Do not add a third: that helper recognizes exactly these two.
|
|
22
|
+
*/
|
|
23
|
+
loadMedia: (rel: SlideRelMedia & {
|
|
24
|
+
path: string;
|
|
25
|
+
}) => Promise<string>;
|
|
26
|
+
/**
|
|
27
|
+
* Write the PNG fallback an SVG rel needs into `rel.data`.
|
|
28
|
+
*
|
|
29
|
+
* Resolves with the failure rather than rejecting, having stamped the placeholder either way:
|
|
30
|
+
* whether a failed preview fails the export is `onMediaError`'s decision, and `gen/media.ts`
|
|
31
|
+
* makes it once for every adapter and every way the SVG arrived. `null` means nothing failed,
|
|
32
|
+
* which includes a runtime with no rasterizer, whose placeholder is its only output.
|
|
33
|
+
*/
|
|
34
|
+
createSvgPngPreview: (rel: SlideRelMedia) => Promise<MediaError | null>;
|
|
35
|
+
writeFile: (fileName: string, data: string | ArrayBuffer | Blob | Uint8Array) => Promise<string>;
|
|
36
|
+
/**
|
|
37
|
+
* Load a font file into raw bytes for `registerFontMetrics`.
|
|
38
|
+
*
|
|
39
|
+
* An `http:`/`https:` URL is fetched by every adapter. Anything else is a filesystem path,
|
|
40
|
+
* which only the Node adapter can read; elsewhere it is a load failure naming the path.
|
|
41
|
+
*/
|
|
42
|
+
loadFontData: (source: string) => Promise<Uint8Array>;
|
|
43
|
+
};
|
|
44
|
+
//#endregion
|
|
45
|
+
//#region src/units.d.ts
|
|
46
|
+
/**
|
|
47
|
+
* DrawingML angle unit. `ST_Angle` (`rot`, shadow `dir`, gradient `ang`, …) is measured in
|
|
48
|
+
* sixtieths-of-a-thousandth of a degree, i.e. 60000 units per degree. Multiply a value in
|
|
49
|
+
* degrees by this to get the OOXML integer.
|
|
50
|
+
*/
|
|
51
|
+
declare const ANGLE_UNITS_PER_DEGREE = 60000;
|
|
52
|
+
/**
|
|
53
|
+
* DrawingML fixed-point percentage scale. `ST_Percentage` / `ST_PositiveFixedPercentage` and
|
|
54
|
+
* related types (`<a:alpha>`, `<a:spcPct>`, shape adjustment guides, `<p:tav tm>`, …) encode
|
|
55
|
+
* 100% as the integer 100000. Multiply a 0-1 fraction by this to get the OOXML value.
|
|
56
|
+
*/
|
|
57
|
+
declare const PERCENT_SCALE = 100000;
|
|
58
|
+
/**
|
|
59
|
+
* Scale for a percentage supplied as 0-100 (rather than a 0-1 fraction) into the same
|
|
60
|
+
* fixed-point percentage integer as {@link PERCENT_SCALE} (1% = 1000 units, i.e. thousandths
|
|
61
|
+
* of a percent). Use for inputs documented as percents: transparency/alpha, image crop insets,
|
|
62
|
+
* gradient stops, bullet size, connector adjust, etc.
|
|
63
|
+
*/
|
|
64
|
+
declare const FIXED_PCT_PER_PERCENT: number;
|
|
65
|
+
/**
|
|
66
|
+
* DrawingML text measures font size (`sz`), character spacing (`spc`) and point line/paragraph
|
|
67
|
+
* spacing (`<a:spcPts val>`) in hundredths of a point. Multiply a value in points by this to get
|
|
68
|
+
* the OOXML integer.
|
|
69
|
+
*/
|
|
70
|
+
declare const HUNDREDTHS_PER_POINT = 100;
|
|
71
|
+
/**
|
|
72
|
+
* Convert a value in points to hundredths of a point (rounded), the integer unit DrawingML uses
|
|
73
|
+
* for `sz`, `spc`, and `<a:spcPts val>`. See {@link HUNDREDTHS_PER_POINT}.
|
|
74
|
+
*/
|
|
75
|
+
declare function ptToHundredths(pt: number): number;
|
|
76
|
+
/**
|
|
77
|
+
* English Metric Units — the integer unit OOXML serializes geometry in (914400 per inch).
|
|
78
|
+
*
|
|
79
|
+
* Branded so a value that has already been resolved to EMU cannot be silently fed back into a
|
|
80
|
+
* unit converter: {@link coordToEmu} only accepts a user `Coord`, so passing an `Emu` into it is
|
|
81
|
+
* a compile-time error. This replaces the old runtime "a number ≥ 100 must already be EMU"
|
|
82
|
+
* magnitude guess, which silently mis-rendered values near the threshold.
|
|
83
|
+
*/
|
|
84
|
+
type Emu = number & {
|
|
85
|
+
readonly __unit: 'emu';
|
|
86
|
+
};
|
|
87
|
+
/** Default pixel density for the `"<n>px"` coordinate unit: CSS reference pixels, also the
|
|
88
|
+
* density ts-pptx assumes when reading an image header's pixel dimensions. */
|
|
89
|
+
declare const DEFAULT_PX_PER_INCH = 96;
|
|
90
|
+
/**
|
|
91
|
+
* The largest DrawingML coordinate, in EMU: the `maxInclusive` of `ST_Coordinate`, the type of
|
|
92
|
+
* every shape offset and extent. The range is not symmetric; see {@link MIN_COORDINATE_EMU}.
|
|
93
|
+
*/
|
|
94
|
+
declare const MAX_COORDINATE_EMU = 27273042316900;
|
|
95
|
+
/** The smallest DrawingML coordinate, in EMU: the `minInclusive` of `ST_Coordinate`. */
|
|
96
|
+
declare const MIN_COORDINATE_EMU = -27273042329600;
|
|
97
|
+
type StandardLayoutName = 'LAYOUT_4x3' | 'LAYOUT_16x9' | 'LAYOUT_16x10' | 'LAYOUT_WIDE';
|
|
98
|
+
interface StandardLayout {
|
|
99
|
+
/** ts-pptx layout key used with `pptx.layout`. */
|
|
100
|
+
readonly layout: StandardLayoutName;
|
|
101
|
+
/** PresentationML slide-size preset name, or `custom` for PowerPoint widescreen. */
|
|
102
|
+
readonly name: string;
|
|
103
|
+
/** Slide width in inches — inches is ts-pptx's default coordinate unit, so this is the value to use for `addText`/`addShape` math. */
|
|
104
|
+
readonly widthIn: number;
|
|
105
|
+
/** Slide height in inches. */
|
|
106
|
+
readonly heightIn: number;
|
|
107
|
+
/** Slide width in English Metric Units. */
|
|
108
|
+
readonly widthEmu: number;
|
|
109
|
+
/** Slide height in English Metric Units. */
|
|
110
|
+
readonly heightEmu: number;
|
|
111
|
+
}
|
|
112
|
+
declare function inchesToEmu(inches: number): Emu;
|
|
113
|
+
declare function pointsToEmu(points: number): Emu;
|
|
114
|
+
declare function pixelsToEmu(pixels: number, dpi: number): Emu;
|
|
115
|
+
/**
|
|
116
|
+
* Resolve a percentage of an axis length to EMU.
|
|
117
|
+
*
|
|
118
|
+
* **Published for consumers, and reached from one place inside `src/` on purpose.** Internally
|
|
119
|
+
* only `parseCoord` needs it, because every `'50%'` a caller writes comes through there; it is
|
|
120
|
+
* exported because a consumer computing its own geometry against a slide axis needs the same
|
|
121
|
+
* arithmetic, and it belongs with the rest of the conversion set beside it rather than hidden
|
|
122
|
+
* behind the one caller. Left exported deliberately rather than by oversight — this note is the
|
|
123
|
+
* difference between the two, as it is on {@link emuToPixels}.
|
|
124
|
+
* @param percent - percentage value (e.g. `50` for 50%)
|
|
125
|
+
* @param axisEmu - the axis length in EMU (slide width for x/w, height for y/h)
|
|
126
|
+
*/
|
|
127
|
+
declare function percentToEmu(percent: number, axisEmu: number): Emu;
|
|
128
|
+
/**
|
|
129
|
+
* The single user-coordinate → EMU boundary. Convert each user-supplied coordinate exactly once.
|
|
130
|
+
*
|
|
131
|
+
* Accepts (see {@link Coord}):
|
|
132
|
+
* - a bare `number` → **always inches** (the documented unit); no magnitude guessing
|
|
133
|
+
* - `"<n>%"` → percentage of `axisEmu`
|
|
134
|
+
* - `"<n>in"` / `"<n>pt"` / `"<n>px"` / `"<n>emu"` → explicit units (the escape hatch for non-inch
|
|
135
|
+
* values). `px` is resolved at {@link DEFAULT_PX_PER_INCH} (96), for authoring against a known
|
|
136
|
+
* web/source canvas size.
|
|
137
|
+
*
|
|
138
|
+
* Throws on non-finite or unparseable input rather than silently emitting a degenerate 0-size.
|
|
139
|
+
* @param value - user coordinate
|
|
140
|
+
* @param axisEmu - axis length in EMU, used only to resolve percentages
|
|
141
|
+
*/
|
|
142
|
+
declare function coordToEmu(value: number | string, axisEmu: number): Emu;
|
|
143
|
+
declare function emuToInches(emu: number): number;
|
|
144
|
+
/**
|
|
145
|
+
* EMU → points, the unit the write API states line widths, font sizes and text insets in.
|
|
146
|
+
*
|
|
147
|
+
* The one conversion, for the library as well as for a consumer: three private forms of
|
|
148
|
+
* `emu / EMU_PER_POINT` had grown around it — the read model's `null`-propagating `ptFromEmu`,
|
|
149
|
+
* the script mapper's `points`, and a dozen inline divisions — while this stayed published and
|
|
150
|
+
* uncalled.
|
|
151
|
+
*
|
|
152
|
+
* **The policy, and its one exception.** Every EMU→points conversion goes through here or through
|
|
153
|
+
* `ptFromEmu` in `src/read/api/coords.ts`, which is this with a `null` passed along. (Named rather
|
|
154
|
+
* than linked: it is internal, so a reference link to it resolves to nothing in the published
|
|
155
|
+
* reference.) The exception is
|
|
156
|
+
* `measure/*` — `fit.ts`, `paragraphs.ts`, `table-fit.ts` — where an inner box is computed as
|
|
157
|
+
* `(extent - inset - inset) / EMU_PER_POINT` and then guarded with `!(x > 0)`. That guard is
|
|
158
|
+
* written NaN-first on purpose: a box that cannot be measured is skipped, not reported. This
|
|
159
|
+
* function asserts a finite input and throws instead, which is the right answer for a caller
|
|
160
|
+
* stating a value and the wrong one for a pass whose whole job is to degrade quietly. Those
|
|
161
|
+
* sites keep the division; nothing else may.
|
|
162
|
+
*/
|
|
163
|
+
declare function emuToPoints(emu: number): number;
|
|
164
|
+
/**
|
|
165
|
+
* EMU → whole pixels at a stated DPI.
|
|
166
|
+
*
|
|
167
|
+
* **Published for consumers, and used nowhere in `src/` on purpose.** Nothing inside the
|
|
168
|
+
* library thinks in pixels: it is the unit a caller placing library output on a canvas or in a
|
|
169
|
+
* `<img>` needs, and the DPI is theirs to choose. Left exported deliberately rather than by
|
|
170
|
+
* oversight — this note is the difference between the two.
|
|
171
|
+
*/
|
|
172
|
+
declare function emuToPixels(emu: number, dpi: number): number;
|
|
173
|
+
declare const STANDARD_LAYOUTS: Readonly<Record<StandardLayoutName, StandardLayout>>;
|
|
174
|
+
//#endregion
|
|
175
|
+
//#region src/gen/oxml/el.d.ts
|
|
176
|
+
/** Attribute values; `undefined`/`null` omit the attribute entirely. */
|
|
177
|
+
type XmlAttrs = Record<string, string | number | null | undefined>;
|
|
178
|
+
//#endregion
|
|
179
|
+
//#region src/gen/slide/objects/shared.d.ts
|
|
180
|
+
/**
|
|
181
|
+
* Everything the dispatch in `gen/slide/object.ts` has already resolved for one slide object,
|
|
182
|
+
* handed to whichever renderer that object's `_type` selects.
|
|
183
|
+
*
|
|
184
|
+
* One object rather than a positional prefix because the prefix was not actually shared: `slide`
|
|
185
|
+
* sat in position 3 for two of the nine renderers and was absent from the other seven, and
|
|
186
|
+
* `renderImageObject` took six adjacent `number` parameters that no type could tell apart.
|
|
187
|
+
* Transposing `cx` and `cy` there compiled, shipped, and produced a stretched picture that
|
|
188
|
+
* nothing outside a rendered slide would have flagged. Named fields make that transposition
|
|
189
|
+
* impossible to write.
|
|
190
|
+
*
|
|
191
|
+
* Everything a renderer needs is here, and that is now a requirement rather than an observation:
|
|
192
|
+
* a renderer is called through {@link RendererTable}, so it takes this and nothing else. Two used
|
|
193
|
+
* to take a second argument. The connector's `shapeIds` map is genuine context and moved onto this
|
|
194
|
+
* interface; the image's `{ imgWidth, imgHeight }` was `frame.cx`/`frame.cy` under another name —
|
|
195
|
+
* the dispatch captured them from the same two variables the frame is built from, two statements
|
|
196
|
+
* apart — so it reads the frame instead.
|
|
197
|
+
*/
|
|
198
|
+
interface RenderContext {
|
|
199
|
+
/** The slide object being emitted. */
|
|
200
|
+
obj: SlideObject;
|
|
201
|
+
/**
|
|
202
|
+
* Its `<p:cNvPr>` id, from the one allocator (`collectSlideShapeIds`).
|
|
203
|
+
*
|
|
204
|
+
* Every renderer used to recompute it as `idx + 2` off the walk index, and the group walk
|
|
205
|
+
* kept a second counter for children — so the map that answers a forward reference (a
|
|
206
|
+
* connector's `a:stCxn`, an animation's `p:spTgt spid`) and the ids actually emitted were two
|
|
207
|
+
* derivations that had to be kept in step by hand.
|
|
208
|
+
*/
|
|
209
|
+
shapeId: number;
|
|
210
|
+
/**
|
|
211
|
+
* Every object's id, not just this one's — the whole map `shapeId` was read out of.
|
|
212
|
+
*
|
|
213
|
+
* A forward reference resolves through it: a connector names its endpoints by `objectName`
|
|
214
|
+
* and has to answer with the id the target will be emitted with, which the walk has not
|
|
215
|
+
* reached yet.
|
|
216
|
+
*/
|
|
217
|
+
shapeIds: ReadonlyMap<SlideObject, number>;
|
|
218
|
+
/** The page it belongs to — a slide, a layout or the master. */
|
|
219
|
+
slide: PresSlideInternal | SlideLayoutInternal | SlideMasterInternal;
|
|
220
|
+
/** The resolved box in EMU: normalized for negative extents, then overridden by a placeholder. */
|
|
221
|
+
frame: {
|
|
222
|
+
x: number;
|
|
223
|
+
y: number;
|
|
224
|
+
cx: number;
|
|
225
|
+
cy: number;
|
|
226
|
+
};
|
|
227
|
+
/** The layout placeholder this object inherits from, or `null`. */
|
|
228
|
+
placeholder: SlideObject | null;
|
|
229
|
+
/** `<a:xfrm>` placement attributes (`flipH`, `flipV`, `rot`); attribute order is byte-significant. */
|
|
230
|
+
locationAttrs: XmlAttrs;
|
|
231
|
+
/**
|
|
232
|
+
* The object's options, already normalized by the dispatch. Read these rather than
|
|
233
|
+
* re-narrowing `obj.options`: each renderer has exactly one call site, and a contract stated
|
|
234
|
+
* there beats a defensive re-assignment in every callee.
|
|
235
|
+
*/
|
|
236
|
+
itemOpts: ObjectOptionsInternal;
|
|
237
|
+
}
|
|
238
|
+
/**
|
|
239
|
+
* The `SlideObjectType` members that a renderer emits a shape for.
|
|
240
|
+
*
|
|
241
|
+
* Not every member is one. `group` recurses back into the walk and owns the frame and bounds
|
|
242
|
+
* logic that belongs to the dispatch, so it stays there; `notes`, `tablecell`, `hyperlink` and
|
|
243
|
+
* `online` are not shapes at all and emit nothing. Those five are spelled out in the dispatch
|
|
244
|
+
* beside this union's members, which is what makes a new enum member fail to compile until
|
|
245
|
+
* someone says which kind it is.
|
|
246
|
+
*/
|
|
247
|
+
type RenderedObjectType = SlideObjectType.chart | SlideObjectType.connector | SlideObjectType.image | SlideObjectType.media | SlideObjectType.model3d | SlideObjectType.oleObject | SlideObjectType.placeholder | SlideObjectType.table | SlideObjectType.text | SlideObjectType.zoom;
|
|
248
|
+
/** One shape family's emitter: everything it needs is in the {@link RenderContext}. */
|
|
249
|
+
type ObjectRenderer = (ctx: RenderContext) => string;
|
|
250
|
+
/**
|
|
251
|
+
* Which renderer emits each shape family — the dispatch's whole knowledge of what a family's XML
|
|
252
|
+
* looks like, supplied to it from outside.
|
|
253
|
+
*
|
|
254
|
+
* It has to come from outside. A named import inside a reachable function body is retained
|
|
255
|
+
* unconditionally, so a `switch` that calls `renderChartObject` links the chart emitter into every
|
|
256
|
+
* program that writes a slide, text-only ones included; a table built in the dispatch module would
|
|
257
|
+
* import the same ten names and change nothing. Passed down the write path alongside the deck
|
|
258
|
+
* state rather than registered into a module-level map: a mutable global populated at import time
|
|
259
|
+
* is how the same input came to produce different bytes once already (see the chart-part-id
|
|
260
|
+
* counter in `package/assemble.ts`), and it would also stop two decks built from different sets of
|
|
261
|
+
* families in one process from each getting their own.
|
|
262
|
+
*
|
|
263
|
+
* `Partial` because a caller may legitimately supply fewer than ten. An object whose family is
|
|
264
|
+
* absent is a routing bug rather than a silent omission, and the dispatch throws.
|
|
265
|
+
*/
|
|
266
|
+
type RendererTable = Partial<Record<RenderedObjectType, ObjectRenderer>>;
|
|
267
|
+
//#endregion
|
|
268
|
+
//#region src/gen/opc/content-types.d.ts
|
|
269
|
+
/** One `Default` entry: a file extension, and the content type every part named with it carries. */
|
|
270
|
+
interface ContentTypeDefault {
|
|
271
|
+
readonly extension: string;
|
|
272
|
+
readonly contentType: string;
|
|
273
|
+
}
|
|
274
|
+
/**
|
|
275
|
+
* One `Override` entry: an absolute part name and its content type. `leadingSpace` asks for the
|
|
276
|
+
* historic insignificant space before the tag — see {@link LEADING_SPACE}; which entries carry it
|
|
277
|
+
* is a fact about the bytes already shipped, not a style choice.
|
|
278
|
+
*/
|
|
279
|
+
interface ContentTypeOverride {
|
|
280
|
+
readonly partName: string;
|
|
281
|
+
readonly contentType: string;
|
|
282
|
+
readonly leadingSpace?: boolean;
|
|
283
|
+
}
|
|
284
|
+
//#endregion
|
|
285
|
+
//#region src/package/parts/shared.d.ts
|
|
286
|
+
/** A slide, a layout, or the master — anything carrying the rel arrays a part can be derived from. */
|
|
287
|
+
type PartTarget = PresSlideInternal | SlideLayoutInternal | SlideMasterInternal;
|
|
288
|
+
/**
|
|
289
|
+
* One construct family's contribution to the package.
|
|
290
|
+
*
|
|
291
|
+
* Every hook is optional and every hook is called at one fixed point in the emission order, which
|
|
292
|
+
* is what keeps zip part order and `[Content_Types].xml` byte-identical no matter which families a
|
|
293
|
+
* program links.
|
|
294
|
+
*/
|
|
295
|
+
interface PartContributor {
|
|
296
|
+
/**
|
|
297
|
+
* Rank among contributors that write into the same slot. Fixed here, with the family, rather
|
|
298
|
+
* than taken from the order a caller happens to list contributors in: the list is a tier's
|
|
299
|
+
* business, and the same deck has to come out byte-identical from every tier that can write it.
|
|
300
|
+
* Spaced by ten so a family can be slotted between two others without renumbering.
|
|
301
|
+
*/
|
|
302
|
+
readonly order: number;
|
|
303
|
+
/** Parts this family writes into the package. */
|
|
304
|
+
readonly parts?: ContributedParts;
|
|
305
|
+
/** Content-type entries this family's parts need to resolve. */
|
|
306
|
+
readonly contentTypes?: ContributedContentTypes;
|
|
307
|
+
}
|
|
308
|
+
/** Where a family's parts go into the zip. Order within each hook is the order they are added. */
|
|
309
|
+
interface ContributedParts {
|
|
310
|
+
/** Written right after slide `slideNumber`'s own part and its rels, inside the slide loop. */
|
|
311
|
+
readonly withEachSlide?: (slide: PresSlideInternal, slideNumber: number, zip: ZipWriter) => void;
|
|
312
|
+
/** Written once, after the slide master and its rels. */
|
|
313
|
+
readonly afterMaster?: (pres: PresentationPropsInternal, zip: ZipWriter) => void;
|
|
314
|
+
/**
|
|
315
|
+
* Written from one target's rel arrays, for every layout, then every slide, then the master —
|
|
316
|
+
* last, alongside the media parts. Any promises returned join the single pool the packager
|
|
317
|
+
* awaits, so a family with async part work does not serialize the write.
|
|
318
|
+
*/
|
|
319
|
+
readonly fromTargetRels?: (target: PartTarget, zip: ZipWriter) => Promise<unknown>[] | void;
|
|
320
|
+
}
|
|
321
|
+
/**
|
|
322
|
+
* Which `[Content_Types].xml` entries a family needs. Each hook names the slot its entries land
|
|
323
|
+
* in; see {@link ContentTypeContributions} for where those slots sit in the emitted order.
|
|
324
|
+
*/
|
|
325
|
+
interface ContributedContentTypes {
|
|
326
|
+
readonly defaults?: (pres: PresentationPropsInternal) => ContentTypeDefault[];
|
|
327
|
+
readonly presentation?: (pres: PresentationPropsInternal) => ContentTypeOverride[];
|
|
328
|
+
readonly perSlide?: (slide: PresSlideInternal, slideNumber: number) => ContentTypeOverride[];
|
|
329
|
+
readonly perLayout?: (layout: SlideLayoutInternal, layoutNumber: number) => ContentTypeOverride[];
|
|
330
|
+
readonly trailing?: (pres: PresentationPropsInternal) => ContentTypeOverride[];
|
|
331
|
+
}
|
|
332
|
+
//#endregion
|
|
333
|
+
//#region src/slide.d.ts
|
|
334
|
+
declare class SlideBuilder {
|
|
335
|
+
#private;
|
|
336
|
+
private readonly _setSlideNum;
|
|
337
|
+
addSlide: (layout: SlideLayoutInternal | null) => PresSlideInternal;
|
|
338
|
+
getSlide: (slideNum: number) => PresSlideInternal | undefined;
|
|
339
|
+
getSections: () => SectionInternalProps[];
|
|
340
|
+
_name: string;
|
|
341
|
+
_presLayout: PresLayout;
|
|
342
|
+
_rels: SlideRel[];
|
|
343
|
+
_relsChart: SlideRelChart[];
|
|
344
|
+
_relsMedia: SlideRelMedia[];
|
|
345
|
+
_rId: number;
|
|
346
|
+
_slideId: number;
|
|
347
|
+
_slideLayout: SlideLayoutInternal | null;
|
|
348
|
+
_slideNum: number;
|
|
349
|
+
_slideNumberProps: SlideNumberProps | null;
|
|
350
|
+
_slideObjects: SlideObject[];
|
|
351
|
+
_comments: SlideComment[];
|
|
352
|
+
_newAutoPagedSlides: PresSlideInternal[];
|
|
353
|
+
_animations: AnimationProps[];
|
|
354
|
+
/**
|
|
355
|
+
* The child-descriptor authors this presentation was composed with, for the group family: a
|
|
356
|
+
* group's children resolve through the same table a slide master's `objects` do, so a group can
|
|
357
|
+
* hold exactly the kinds this presentation can author.
|
|
358
|
+
*/
|
|
359
|
+
readonly _childAuthors: ChildAuthors;
|
|
360
|
+
/**
|
|
361
|
+
* The authoring methods, one per construct family, bound in the constructor.
|
|
362
|
+
*
|
|
363
|
+
* Declared here and assigned there: the signature each one keeps is the public one on
|
|
364
|
+
* {@link Slide}, and a method the presentation was not composed with still answers — with the
|
|
365
|
+
* name of the family it needs, rather than `undefined is not a function`.
|
|
366
|
+
*/
|
|
367
|
+
addAnimation: Slide['addAnimation'];
|
|
368
|
+
addChart: Slide['addChart'];
|
|
369
|
+
addComment: Slide['addComment'];
|
|
370
|
+
addConnector: Slide['addConnector'];
|
|
371
|
+
addGroup: Slide['addGroup'];
|
|
372
|
+
addImage: Slide['addImage'];
|
|
373
|
+
addMedia: Slide['addMedia'];
|
|
374
|
+
addModel3d: Slide['addModel3d'];
|
|
375
|
+
addNotes: Slide['addNotes'];
|
|
376
|
+
addOleObject: Slide['addOleObject'];
|
|
377
|
+
addSectionZoom: Slide['addSectionZoom'];
|
|
378
|
+
addShape: Slide['addShape'];
|
|
379
|
+
addSlideZoom: Slide['addSlideZoom'];
|
|
380
|
+
addSummaryZoom: Slide['addSummaryZoom'];
|
|
381
|
+
addTable: Slide['addTable'];
|
|
382
|
+
addText: Slide['addText'];
|
|
383
|
+
groupObjects: Slide['groupObjects'];
|
|
384
|
+
constructor(params: {
|
|
385
|
+
addSlide: (layout: SlideLayoutInternal | null) => PresSlideInternal;
|
|
386
|
+
getSlide: (slideNum: number) => PresSlideInternal | undefined;
|
|
387
|
+
getSections?: () => SectionInternalProps[];
|
|
388
|
+
presLayout: PresLayout;
|
|
389
|
+
setSlideNum: (value: SlideNumberProps) => void;
|
|
390
|
+
slideId: number;
|
|
391
|
+
slideRId: number;
|
|
392
|
+
slideNumber: number;
|
|
393
|
+
slideLayout?: SlideLayoutInternal;
|
|
394
|
+
authors: SlideAuthors;
|
|
395
|
+
childAuthors: ChildAuthors;
|
|
396
|
+
});
|
|
397
|
+
/**
|
|
398
|
+
* Background color or image
|
|
399
|
+
* @type {BackgroundProps}
|
|
400
|
+
* @example solid color `background: { color:'FF0000' }`
|
|
401
|
+
* @example color+trans `background: { color:'FF0000', transparency:0.5 }`
|
|
402
|
+
* @example base64 `background: { data:'image/png;base64,ABC[...]123' }`
|
|
403
|
+
* @example url `background: { path:'https://some.url/image.jpg'}`
|
|
404
|
+
*/
|
|
405
|
+
private _background?;
|
|
406
|
+
set background(props: BackgroundOption | undefined);
|
|
407
|
+
get background(): BackgroundOption | undefined;
|
|
408
|
+
/**
|
|
409
|
+
* Default font color
|
|
410
|
+
* @type {HexColor}
|
|
411
|
+
*/
|
|
412
|
+
private _color?;
|
|
413
|
+
set color(value: HexColor);
|
|
414
|
+
get color(): HexColor | undefined;
|
|
415
|
+
/**
|
|
416
|
+
* @type {boolean}
|
|
417
|
+
*/
|
|
418
|
+
private _hidden;
|
|
419
|
+
set hidden(value: boolean);
|
|
420
|
+
get hidden(): boolean;
|
|
421
|
+
/**
|
|
422
|
+
* Slide-show transition (`p:transition`) played when advancing to this slide.
|
|
423
|
+
* @type {TransitionProps}
|
|
424
|
+
*/
|
|
425
|
+
private _transition?;
|
|
426
|
+
set transition(value: TransitionProps | undefined);
|
|
427
|
+
get transition(): TransitionProps | undefined;
|
|
428
|
+
/**
|
|
429
|
+
* @type {SlideNumberProps}
|
|
430
|
+
*/
|
|
431
|
+
set slideNumber(value: SlideNumberProps);
|
|
432
|
+
get slideNumber(): SlideNumberProps | undefined;
|
|
433
|
+
/**
|
|
434
|
+
* Every continuation slide this slide's tables have spilled onto, in call order, each once.
|
|
435
|
+
*
|
|
436
|
+
* Across calls, not per call: a slide can carry more than one `addTable`, and each auto-paging
|
|
437
|
+
* one appends whatever it spilled onto. The list was assigned rather than appended, so a second
|
|
438
|
+
* table erased the first table's report while its slides stayed in the deck. "Spilled onto"
|
|
439
|
+
* rather than "created" because a later table lands on the earlier one's continuations instead
|
|
440
|
+
* of making its own, and those are reported once.
|
|
441
|
+
*/
|
|
442
|
+
get newAutoPagedSlides(): Slide[];
|
|
443
|
+
/**
|
|
444
|
+
* The objects authored on this slide so far, bottom-to-top in z-order.
|
|
445
|
+
*
|
|
446
|
+
* Built fresh on every access rather than cached: the underlying list is mutated in place by
|
|
447
|
+
* `addGroup`/`groupObjects` as well as appended to, so a cache would have to be invalidated from
|
|
448
|
+
* every authoring path and would go stale the first time one was added without remembering.
|
|
449
|
+
* Building it costs a walk of a list a slide-sized deck keeps in the dozens.
|
|
450
|
+
*/
|
|
451
|
+
get objects(): readonly SlideObjectInfo[];
|
|
452
|
+
/** Slide width in inches (resolved from the active presentation layout). */
|
|
453
|
+
get width(): number;
|
|
454
|
+
/** Slide height in inches (resolved from the active presentation layout). */
|
|
455
|
+
get height(): number;
|
|
456
|
+
}
|
|
457
|
+
//#endregion
|
|
458
|
+
//#region src/families/shared.d.ts
|
|
459
|
+
/**
|
|
460
|
+
* Every construct family, by name. A name is what a diagnostic can say about a family that is not
|
|
461
|
+
* composed, so it exists even for the families every tier carries.
|
|
462
|
+
*/
|
|
463
|
+
type FamilyName = 'animations' | 'chart' | 'comments' | 'connector' | 'group' | 'image' | 'measure' | 'media' | 'model3d' | 'notes' | 'ole' | 'shape' | 'table' | 'text' | 'zoom';
|
|
464
|
+
/** The `Slide` methods that come from a family rather than from the slide itself. */
|
|
465
|
+
type SlideAuthorMethod = 'addAnimation' | 'addChart' | 'addComment' | 'addConnector' | 'addGroup' | 'addImage' | 'addMedia' | 'addModel3d' | 'addNotes' | 'addOleObject' | 'addSectionZoom' | 'addShape' | 'addSlideZoom' | 'addSummaryZoom' | 'addTable' | 'addText' | 'groupObjects';
|
|
466
|
+
/**
|
|
467
|
+
* One family method's author: the public signature, with the slide it authors onto in front and
|
|
468
|
+
* the return dropped. Chaining is not the author's business — `SlideBuilder` returns the slide
|
|
469
|
+
* from every bound method, so an author that returned one could only return the same one.
|
|
470
|
+
*/
|
|
471
|
+
type Author<M extends SlideAuthorMethod> = (slide: SlideBuilder, ...args: Parameters<Slide[M]>) => void;
|
|
472
|
+
/**
|
|
473
|
+
* The slide methods a list of families supplies between them, each optional because a program
|
|
474
|
+
* composed without a family does not have its methods.
|
|
475
|
+
*
|
|
476
|
+
* Derived from {@link Slide} rather than restated, so an author cannot drift from the method it
|
|
477
|
+
* backs. `addChart` is written out because it is the one overloaded member: `Parameters` reads the
|
|
478
|
+
* last overload only, which would let a family that handles just the combo form type-check while
|
|
479
|
+
* the public method promises both.
|
|
480
|
+
*/
|
|
481
|
+
type SlideAuthors = { [M in Exclude<SlideAuthorMethod, 'addChart'>]?: Author<M>; } & {
|
|
482
|
+
addChart?: (slide: SlideBuilder, arg1: OptsChartData[] | ChartMulti[], arg2?: ChartOpts & {
|
|
483
|
+
type?: CHART_NAME;
|
|
484
|
+
}) => void;
|
|
485
|
+
};
|
|
486
|
+
/**
|
|
487
|
+
* What a presentation-level author is given: the deck it is authoring onto, and the write-side
|
|
488
|
+
* font metrics, which the presentation keeps private and a family cannot reach through the class.
|
|
489
|
+
*/
|
|
490
|
+
interface PresentationAuthorContext {
|
|
491
|
+
readonly pres: PresentationCore;
|
|
492
|
+
readonly fontMetrics: FontMetricsRegistry;
|
|
493
|
+
}
|
|
494
|
+
/**
|
|
495
|
+
* The presentation methods that come from a family rather than from the presentation itself.
|
|
496
|
+
*
|
|
497
|
+
* Written out with their signatures rather than derived from the class, because the class is what
|
|
498
|
+
* they are being lifted out of. Each returns its own answer, so unlike a slide author there is
|
|
499
|
+
* nothing generic to apply on the way back.
|
|
500
|
+
*/
|
|
501
|
+
interface PresentationAuthors {
|
|
502
|
+
measureText?: (ctx: PresentationAuthorContext, text: string | TextProps[], opts: MeasureTextOptions) => TextMeasurement;
|
|
503
|
+
overflowsBox?: (ctx: PresentationAuthorContext, text: string | TextProps[], opts: OverflowBoxOptions) => boolean;
|
|
504
|
+
tableLayout?: (ctx: PresentationAuthorContext, rows: TableRow[], opts: TableProps) => TableLayoutResult;
|
|
505
|
+
tableToSlides?: (ctx: PresentationAuthorContext, eleId: string, options: TableToSlidesProps) => void;
|
|
506
|
+
}
|
|
507
|
+
/**
|
|
508
|
+
* The key-tagged child descriptors a slide master's `objects` and a group's `children` are written
|
|
509
|
+
* with (`{ text: … }`, `{ rect: … }`, …). `placeholder` is not one: it is master-specific and needs
|
|
510
|
+
* the object's index, so `createSlideMaster` handles it itself.
|
|
511
|
+
*/
|
|
512
|
+
type ChildDescriptorKey = 'chart' | 'image' | 'line' | 'rect' | 'roundRect' | 'shape' | 'text';
|
|
513
|
+
/** The payload behind one descriptor key, taken from the descriptor union so it cannot drift. */
|
|
514
|
+
type ChildDescriptor<K extends ChildDescriptorKey> = Extract<SlideMasterObject, Record<K, unknown>>[K];
|
|
515
|
+
/**
|
|
516
|
+
* The child descriptors a list of families recognises. A descriptor whose key is missing is one
|
|
517
|
+
* nothing composed can author, and both walks warn — naming the family behind the key when
|
|
518
|
+
* {@link CHILD_DESCRIPTOR_FAMILIES} has one, so a `{ chart: … }` in a master's `objects` on a
|
|
519
|
+
* chartless presentation says what to compose rather than disappearing from the deck.
|
|
520
|
+
*/
|
|
521
|
+
type ChildAuthors = { [K in ChildDescriptorKey]?: (target: PresSlideInternal, child: ChildDescriptor<K>) => void; };
|
|
522
|
+
/**
|
|
523
|
+
* What a family contributes to an *extraction* -- the second emission path, which serializes a
|
|
524
|
+
* slide for injection into a deck read from bytes rather than for a package of its own.
|
|
525
|
+
*
|
|
526
|
+
* One slot so far. Extraction re-emits a slide's shapes through the same renderer table a write
|
|
527
|
+
* uses, so a family with only shapes to draw needs nothing here; charts are the exception because
|
|
528
|
+
* an extracted chart carries its part XML and its workbook alongside the slide body.
|
|
529
|
+
*/
|
|
530
|
+
interface SlideExtractors {
|
|
531
|
+
readonly charts?: (slide: PresSlideInternal) => ExtractedSlide['charts'];
|
|
532
|
+
}
|
|
533
|
+
/** One construct family. Every slot is optional; a family fills the ones it has something to say about. */
|
|
534
|
+
interface ConstructFamily {
|
|
535
|
+
/** This family's name, for the diagnostic a program without it raises. */
|
|
536
|
+
readonly name: FamilyName;
|
|
537
|
+
/** Methods this family adds to a slide. */
|
|
538
|
+
readonly authors?: SlideAuthors;
|
|
539
|
+
/** Child descriptors this family recognises inside a slide master or a group. */
|
|
540
|
+
readonly children?: ChildAuthors;
|
|
541
|
+
/** The shape kinds this family emits XML for, keyed by `SlideObjectType`. */
|
|
542
|
+
readonly renderers?: RendererTable;
|
|
543
|
+
/** The parts this family puts in the written package. */
|
|
544
|
+
readonly parts?: PartContributor;
|
|
545
|
+
/** Methods this family adds to the presentation itself. */
|
|
546
|
+
readonly presentationAuthors?: PresentationAuthors;
|
|
547
|
+
/** What this family adds to an extracted slide, beyond the shape XML its renderer emits. */
|
|
548
|
+
readonly extract?: SlideExtractors;
|
|
549
|
+
}
|
|
550
|
+
/**
|
|
551
|
+
* A presentation author with its context already supplied — what a method on the presentation
|
|
552
|
+
* calls, having nothing left to pass but its own arguments.
|
|
553
|
+
*/
|
|
554
|
+
type BoundPresentationAuthor<F> = F extends ((ctx: PresentationAuthorContext, ...args: infer A) => infer R) ? (...args: A) => R : never;
|
|
555
|
+
//#endregion
|
|
556
|
+
//#region src/presentation.d.ts
|
|
557
|
+
/**
|
|
558
|
+
* Main presentation class and package export flow — the public entry point consumers
|
|
559
|
+
* instantiate (`new TsPptx()`). Owns presentation-level state and metadata, collects
|
|
560
|
+
* slides, and drives `write`/`writeFile`/`stream`. The actual OOXML string building is
|
|
561
|
+
* delegated to the `gen-*` modules; runtime file/stream output goes through the injected
|
|
562
|
+
* `RuntimeAdapter`. Enums (`AlignH`, `ChartType`, `ShapeType`, …) are imported from the
|
|
563
|
+
* package entry, not read off the instance.
|
|
564
|
+
*
|
|
565
|
+
* Rough layout of the class body:
|
|
566
|
+
* - Metadata accessors layout / author / company / title / theme / sections getters+setters
|
|
567
|
+
* - Private slide helpers addNewSlide, getSlide, setSlideNumber
|
|
568
|
+
* - Public export methods stream / write / writeFile — delegate packaging to `writePackage`
|
|
569
|
+
* - Public authoring methods addSlide / defineLayout / defineSlideMaster / defineTableStyle
|
|
570
|
+
*
|
|
571
|
+
* Package assembly (`[Content_Types].xml`, the rels graph, per-part XML, the ZIP) lives in
|
|
572
|
+
* `package/assemble.ts`; this class provides the deck state via {@link PresentationCore.packageSource}.
|
|
573
|
+
* The live-DOM `tableToSlides()` is NOT here — it is added by the browser entry subclass
|
|
574
|
+
* (`browser.ts`) so it stays out of the Node build and out of the core chunk.
|
|
575
|
+
*/
|
|
576
|
+
declare class PresentationCore {
|
|
577
|
+
#private;
|
|
578
|
+
/**
|
|
579
|
+
* Presentation layout name
|
|
580
|
+
* Standard layouts:
|
|
581
|
+
* - 'LAYOUT_4x3' (10" x 7.5")
|
|
582
|
+
* - 'LAYOUT_16x9' (10" x 5.625")
|
|
583
|
+
* - 'LAYOUT_16x10' (10" x 6.25")
|
|
584
|
+
* - 'LAYOUT_WIDE' (13.333" x 7.5")
|
|
585
|
+
* Custom layouts:
|
|
586
|
+
* Use `pptx.defineLayout()` to create custom layouts (e.g.: 'A4')
|
|
587
|
+
* @type {string}
|
|
588
|
+
* @see https://support.office.com/en-us/article/Change-the-size-of-your-slides-040a811c-be43-40b9-8d04-0de5ed79987e
|
|
589
|
+
*/
|
|
590
|
+
private _layout;
|
|
591
|
+
set layout(value: string | StandardLayout);
|
|
592
|
+
get layout(): string;
|
|
593
|
+
/**
|
|
594
|
+
* ts-pptx Library Version
|
|
595
|
+
*/
|
|
596
|
+
private readonly _version;
|
|
597
|
+
get version(): string;
|
|
598
|
+
/**
|
|
599
|
+
* @type {string}
|
|
600
|
+
*/
|
|
601
|
+
private _author;
|
|
602
|
+
set author(value: string);
|
|
603
|
+
get author(): string;
|
|
604
|
+
/**
|
|
605
|
+
* @type {string}
|
|
606
|
+
*/
|
|
607
|
+
private _company;
|
|
608
|
+
set company(value: string);
|
|
609
|
+
get company(): string;
|
|
610
|
+
/**
|
|
611
|
+
* @type {string}
|
|
612
|
+
* @note the `revision` value must be a whole number only (without "." or "," - otherwise, PPT will throw errors upon opening!)
|
|
613
|
+
*/
|
|
614
|
+
private _revision;
|
|
615
|
+
set revision(value: string);
|
|
616
|
+
get revision(): string;
|
|
617
|
+
/**
|
|
618
|
+
* @type {string}
|
|
619
|
+
*/
|
|
620
|
+
private _subject;
|
|
621
|
+
set subject(value: string);
|
|
622
|
+
get subject(): string;
|
|
623
|
+
/**
|
|
624
|
+
* @type {ThemeProps}
|
|
625
|
+
*/
|
|
626
|
+
private _theme;
|
|
627
|
+
set theme(value: ThemeProps);
|
|
628
|
+
get theme(): ThemeProps;
|
|
629
|
+
/**
|
|
630
|
+
* @type {string}
|
|
631
|
+
*/
|
|
632
|
+
private _title;
|
|
633
|
+
set title(value: string);
|
|
634
|
+
get title(): string;
|
|
635
|
+
/**
|
|
636
|
+
* Slide number shown on the first slide (maps to firstSlideNum in presentation.xml)
|
|
637
|
+
* @throws {InvalidOptionError} when the value is not an integer `xsd:int` can hold
|
|
638
|
+
*/
|
|
639
|
+
private _firstSlideNum;
|
|
640
|
+
set firstSlideNum(value: number);
|
|
641
|
+
get firstSlideNum(): number;
|
|
642
|
+
/**
|
|
643
|
+
* Whether Right-to-Left (RTL) mode is enabled
|
|
644
|
+
* @type {boolean}
|
|
645
|
+
*/
|
|
646
|
+
private _rtlMode;
|
|
647
|
+
set rtlMode(value: boolean);
|
|
648
|
+
get rtlMode(): boolean;
|
|
649
|
+
/** the slide master the deck's master part is written from; not a `Slide`, so not handed out */
|
|
650
|
+
private readonly _masterSlide;
|
|
651
|
+
/** this Presentation's Slide objects */
|
|
652
|
+
private readonly _slides;
|
|
653
|
+
get slides(): Slide[];
|
|
654
|
+
/** this Presentation's sections */
|
|
655
|
+
private readonly _sections;
|
|
656
|
+
get sections(): SectionProps[];
|
|
657
|
+
/** custom document properties stored in docProps/custom.xml */
|
|
658
|
+
private _customProperties;
|
|
659
|
+
/**
|
|
660
|
+
* slide layout definition objects, used for generating slide layout files.
|
|
661
|
+
* `protected` (not `private`) so the browser entry subclass can resolve
|
|
662
|
+
* `tableToSlides({ masterTitle })` against them — that method lives on the
|
|
663
|
+
* browser build only (it reads a live DOM), see `browser.ts`.
|
|
664
|
+
*/
|
|
665
|
+
protected readonly _slideLayouts: SlideLayoutInternal[];
|
|
666
|
+
get slideLayouts(): SlideLayout[];
|
|
667
|
+
private get internalPresentation();
|
|
668
|
+
private LAYOUTS;
|
|
669
|
+
private _presLayout;
|
|
670
|
+
get presLayout(): PresLayout;
|
|
671
|
+
private readonly _runtime;
|
|
672
|
+
/** Write-side font metrics for measured text fit (`fit:'shrink'`). @see registerFontMetrics */
|
|
673
|
+
private readonly _fontMetrics;
|
|
674
|
+
/** Author-side embedded font faces, accumulated by {@link embedFont} and emitted at write time. */
|
|
675
|
+
private readonly _embeddedFonts;
|
|
676
|
+
constructor(runtime: RuntimeAdapter, families: readonly ConstructFamily[]);
|
|
677
|
+
/**
|
|
678
|
+
* Provides an API for `addTableDefinition` to create slides as needed for auto-paging
|
|
679
|
+
* @param layout - the layout of the slide the table is paged from
|
|
680
|
+
* @return {Slide} new Slide
|
|
681
|
+
*/
|
|
682
|
+
private readonly addNewSlide;
|
|
683
|
+
/**
|
|
684
|
+
* Provides an API for `addTableDefinition` to get slide reference by number
|
|
685
|
+
* @param {number} slideNum - slide number
|
|
686
|
+
* @return {Slide} Slide
|
|
687
|
+
*/
|
|
688
|
+
private readonly getSlide;
|
|
689
|
+
/**
|
|
690
|
+
* Provides the live section list to the `Slide` class so Section/Summary Zoom can resolve
|
|
691
|
+
* a section title to its stable GUID and enumerate sections in order.
|
|
692
|
+
* @return {SectionInternalProps[]} the presentation's sections
|
|
693
|
+
*/
|
|
694
|
+
private readonly getSections;
|
|
695
|
+
/**
|
|
696
|
+
* Enables the `Slide` class to set ts-pptx [Presentation] master/layout slidenumbers
|
|
697
|
+
* @param {SlideNumberProps} slideNum - slide number config
|
|
698
|
+
*/
|
|
699
|
+
private readonly setSlideNumber;
|
|
700
|
+
/**
|
|
701
|
+
* Assemble the slice of internal state the packaging layer reads. `PresentationCore` owns the
|
|
702
|
+
* authored deck; `writePackage` (in `package/assemble.ts`) turns it into OOXML parts.
|
|
703
|
+
*/
|
|
704
|
+
private packageSource;
|
|
705
|
+
/**
|
|
706
|
+
* Author + serialize this presentation's slides as injectable descriptors,
|
|
707
|
+
* WITHOUT producing a `.pptx` package. Runs the same media-encode, placeholder
|
|
708
|
+
* backfill, and measured-fit passes `write()` uses, then serializes each slide
|
|
709
|
+
* body and resolves its image media to decoded bytes — so a loaded deck can
|
|
710
|
+
* splice the slides in via `Presentation.appendSlides()` (see `pptx-ts/read`)
|
|
711
|
+
* while keeping its own masters/layouts/theme byte-identical.
|
|
712
|
+
*
|
|
713
|
+
* Returns the deck's slide size (EMU, for the destination size check) and one
|
|
714
|
+
* descriptor per authored slide. Charts, audio/video media, online media, and
|
|
715
|
+
* internal slide-to-slide hyperlinks are surfaced as descriptors alongside the
|
|
716
|
+
* serialized body — this method does not resolve them into a package; the append
|
|
717
|
+
* path consumes each descriptor to reserve the parts and rebuild the rel graph.
|
|
718
|
+
*/
|
|
719
|
+
extractSlides: (opts?: {
|
|
720
|
+
onMediaError?: 'throw' | 'placeholder';
|
|
721
|
+
}) => Promise<ExtractedSlides>;
|
|
722
|
+
/**
|
|
723
|
+
* One of this presentation's family-supplied methods, or the failure that names the family it
|
|
724
|
+
* would have come from. The methods that call it stay on the class because their signatures are
|
|
725
|
+
* the public contract; what they reach is what a family owns.
|
|
726
|
+
*
|
|
727
|
+
* `protected` for the browser entry, whose `tableToSlides` is one of these and is declared on
|
|
728
|
+
* the subclass so that a Node build never links the DOM reader.
|
|
729
|
+
*/
|
|
730
|
+
protected familyAuthor<M extends keyof PresentationAuthors>(method: M): BoundPresentationAuthor<NonNullable<PresentationAuthors[M]>>;
|
|
731
|
+
/**
|
|
732
|
+
* Register a font's metrics so `fit:'shrink'` and `fit:'resize'` text is measured at
|
|
733
|
+
* export time: `'shrink'` bakes a real `fontScale` and `'resize'` a real box height, so
|
|
734
|
+
* the text renders fitted in headless renderers and on plain file-open, with no manual
|
|
735
|
+
* edit/resize.
|
|
736
|
+
*
|
|
737
|
+
* Without registered metrics, both write the bare flag (`<a:normAutofit/>` or
|
|
738
|
+
* `<a:spAutoFit/>`) that only PowerPoint recomputes on edit. Register the same
|
|
739
|
+
* face once per weight/style you use; bold/italic advances differ.
|
|
740
|
+
*
|
|
741
|
+
* **Font collections** (`.ttc`/`.otc`, how MS Gothic, Yu Gothic, SimSun, Microsoft
|
|
742
|
+
* YaHei and Cambria ship on Windows) hold several fonts in one file, so one has to be
|
|
743
|
+
* chosen. With no `font` option, `face` is used as the selector, which is usually what
|
|
744
|
+
* you meant; a `face` that names no font in the collection throws rather than falling
|
|
745
|
+
* back to the first, since measuring the wrong member is invisible downstream. Pass
|
|
746
|
+
* `font` when the deck-side name differs from the name inside the file, and use
|
|
747
|
+
* `listFontFaces` from `pptx-ts/measure` to see what a file holds.
|
|
748
|
+
* @param {string} face - font family name as used in `fontFace` (e.g. 'Aptos')
|
|
749
|
+
* @param {string | Uint8Array | ArrayBuffer} source - font file path/URL (Node/web) or raw TTF/OTF/TTC
|
|
750
|
+
* bytes. A string is always a path or URL here; base64 text is `embedFont`'s `data`, not this.
|
|
751
|
+
* @param {object} [opts] - variant flags (advances differ per weight/style) and collection selection
|
|
752
|
+
* @param {boolean} [opts.bold] - these are the bold advances
|
|
753
|
+
* @param {boolean} [opts.italic] - these are the italic advances
|
|
754
|
+
* @param {number | string} [opts.font] - which font inside a collection: 0-based index, or a name
|
|
755
|
+
* @example await pptx.registerFontMetrics('Aptos', '/usr/share/fonts/Aptos.ttf')
|
|
756
|
+
* @example await pptx.registerFontMetrics('Aptos', aptosBoldBytes, { bold: true })
|
|
757
|
+
* @example await pptx.registerFontMetrics('MS PGothic', 'C:/Windows/Fonts/msgothic.ttc')
|
|
758
|
+
* @example await pptx.registerFontMetrics('Cambria Math', 'C:/Windows/Fonts/cambria.ttc', { font: 1 })
|
|
759
|
+
*/
|
|
760
|
+
registerFontMetrics(face: string, source: string | Uint8Array | ArrayBuffer, opts?: {
|
|
761
|
+
bold?: boolean;
|
|
762
|
+
italic?: boolean;
|
|
763
|
+
font?: number | string;
|
|
764
|
+
}): Promise<void>;
|
|
765
|
+
/**
|
|
766
|
+
* Embed a font face so the deck renders with it even on machines that do not
|
|
767
|
+
* have it installed. The **whole** face is embedded (not glyph-subset) under
|
|
768
|
+
* `/ppt/fonts/` and wired into `presentation.xml` (`p:embeddedFontLst` +
|
|
769
|
+
* `embedTrueTypeFonts="1"`), exactly as PowerPoint's "Embed fonts in the file"
|
|
770
|
+
* does. Call once per face/weight you use.
|
|
771
|
+
*
|
|
772
|
+
* The declared `typeface` MUST match the family name used in your run/`fontFace`
|
|
773
|
+
* typefaces (e.g. `addText('hi', { fontFace: 'Silkscreen' })`) or PowerPoint
|
|
774
|
+
* will not bind the embedded bytes to the text. Repeated calls with the same
|
|
775
|
+
* `typeface` and different `style` accumulate into one `p:embeddedFont` entry.
|
|
776
|
+
*
|
|
777
|
+
* Font licensing is the caller's responsibility: the bytes are embedded as
|
|
778
|
+
* handed over; `OS/2.fsType` embedding-permission bits are not enforced.
|
|
779
|
+
* @param {object} opts - font source + identity
|
|
780
|
+
* @param {string} [opts.path] - font file path (Node) or URL (web) to a `.ttf`/`.otf`
|
|
781
|
+
* @param {ArrayBuffer | Uint8Array | string} [opts.data] - raw font bytes, or a base64 string (bare or a
|
|
782
|
+
* whole `data:` URL), in lieu of `path`. Unlike `registerFontMetrics`, a string here is never a path.
|
|
783
|
+
* @param {string} opts.typeface - family name as referenced by run/`fontFace` typefaces
|
|
784
|
+
* @param {EmbeddedFontSlot} [opts.style] - face slot; defaults to `'regular'`
|
|
785
|
+
* @example await pptx.embedFont({ path: '/fonts/Silkscreen-Regular.ttf', typeface: 'Silkscreen' })
|
|
786
|
+
* @example await pptx.embedFont({ path: '/fonts/Silkscreen-Bold.ttf', typeface: 'Silkscreen', style: 'bold' })
|
|
787
|
+
*/
|
|
788
|
+
embedFont(opts: {
|
|
789
|
+
path?: string;
|
|
790
|
+
data?: ArrayBuffer | Uint8Array | string;
|
|
791
|
+
typeface: string;
|
|
792
|
+
style?: EmbeddedFontSlot;
|
|
793
|
+
}): Promise<void>;
|
|
794
|
+
/**
|
|
795
|
+
* Measure how tall text wraps at a given width, using the **same** calibrated wrap
|
|
796
|
+
* model the export-time autofit bake uses — so a layout-time prediction matches the
|
|
797
|
+
* value `fit:'shrink'`/`'resize'` would bake. Synchronous: register the face's metrics
|
|
798
|
+
* first with {@link TsPptx.registerFontMetrics} (lookup is sync).
|
|
799
|
+
*
|
|
800
|
+
* Lets a consumer size its own geometry before export — grow a card to fit its text,
|
|
801
|
+
* reflow a grid, or detect overflow at layout time. Heights err **tall** (conservative),
|
|
802
|
+
* so the returned height is ≥ what PowerPoint/LibreOffice render.
|
|
803
|
+
* @param {string | TextProps[]} text - a string or run array (per-run options override the defaults in `opts`)
|
|
804
|
+
* @param {MeasureTextOptions} opts - width (inches), font size/face (points), and spacing
|
|
805
|
+
* @returns {TextMeasurement} laid-out height + line count + fit helpers
|
|
806
|
+
* @example const m = pptx.measureText('Long heading…', { wIn: 3, fontSize: 18, fontFace: 'Aptos' })
|
|
807
|
+
* @example if (pptx.measureText(runs, { wIn, fontSize, fontFace }).heightIn > cardHeightIn) growCard()
|
|
808
|
+
*/
|
|
809
|
+
measureText(text: string | TextProps[], opts: MeasureTextOptions): TextMeasurement;
|
|
810
|
+
/**
|
|
811
|
+
* Convenience overflow check: `true` if `text` does not fit a box of inner size
|
|
812
|
+
* `wIn`×`hIn` (inches) at full size. Because the model errs tall, this is a
|
|
813
|
+
* **conservative** (slightly over-reporting) check — appropriate for a build-time
|
|
814
|
+
* warning, not a hard gate. An unmeasurable (unnamed theme-default) face reports
|
|
815
|
+
* `false` (no overflow) so the linter does not false-positive on faces it cannot measure.
|
|
816
|
+
* @param {string | TextProps[]} text - a string or run array
|
|
817
|
+
* @param {OverflowBoxOptions} opts - {@link MeasureTextOptions} plus the box inner height `hIn`
|
|
818
|
+
* @returns {boolean} true if the text overflows the box
|
|
819
|
+
*/
|
|
820
|
+
overflowsBox(text: string | TextProps[], opts: OverflowBoxOptions): boolean;
|
|
821
|
+
/**
|
|
822
|
+
* Compute the per-cell geometry of a table laid out at `opts.x`/`y`/`w`, without
|
|
823
|
+
* adding it to a slide — so a consumer can place images or shapes precisely over
|
|
824
|
+
* cells. Column widths (cell `x`/`w`) are exact, derived from the same logic the
|
|
825
|
+
* writer uses. Row heights (`y`/`h`) are exact when pinned by `rowH` (array or
|
|
826
|
+
* scalar) or table `h`; an auto-height row is estimated with the same conservative
|
|
827
|
+
* (tall) text model as {@link TsPptx.measureText} and flagged `heightExact:false`
|
|
828
|
+
* (register the cell font via {@link TsPptx.registerFontMetrics} for an exact
|
|
829
|
+
* estimate). Geometry is for a single, un-paginated table — `autoPage` paging is
|
|
830
|
+
* not modeled.
|
|
831
|
+
* @param {TableRow[]} rows - the same `rows` passed to `slide.addTable`
|
|
832
|
+
* @param {TableProps} opts - the same table options (`x`, `y`, `w`, `colW`, `rowH`, `h`, …)
|
|
833
|
+
* @returns {TableLayoutResult} per-cell rectangles (inches) plus overall table bounds
|
|
834
|
+
* @example
|
|
835
|
+
* const g = pptx.tableLayout(rows, { x: 1, y: 1, w: 8, colW: [2, 3, 3] })
|
|
836
|
+
* const c = g.cells.find(c => c.row === 0 && c.col === 2)
|
|
837
|
+
* slide.addImage({ path: 'logo.png', x: c.xIn, y: c.yIn, w: c.wIn, h: c.hIn })
|
|
838
|
+
*/
|
|
839
|
+
tableLayout(rows: TableRow[], opts: TableProps): TableLayoutResult;
|
|
840
|
+
/**
|
|
841
|
+
* Export the current presentation as portable ZIP bytes. Unlike the former
|
|
842
|
+
* `stream()` method, this does not imply incremental output or convert the
|
|
843
|
+
* archive to a Node `Buffer`: package assembly is synchronous and the returned
|
|
844
|
+
* `Uint8Array` works unchanged in Node, browsers, and workers.
|
|
845
|
+
* @param {WriteBaseProps} props - output properties
|
|
846
|
+
* @returns {Promise<Uint8Array>} complete `.pptx` archive bytes
|
|
847
|
+
*/
|
|
848
|
+
toBytes(props?: WriteBaseProps): Promise<Uint8Array>;
|
|
849
|
+
/**
|
|
850
|
+
* Export the current Presentation as ZIP content with the selected type
|
|
851
|
+
* @param {WriteProps} props output properties
|
|
852
|
+
* @returns {Promise<string | ArrayBuffer | Blob | Uint8Array>} file content in selected type
|
|
853
|
+
*/
|
|
854
|
+
write(props?: WriteProps): Promise<string | ArrayBuffer | Blob | Uint8Array>;
|
|
855
|
+
/**
|
|
856
|
+
* Assemble the current Presentation into its OOXML package parts WITHOUT zipping — the raw
|
|
857
|
+
* `path → bytes` contents `write()` would compress into the `.pptx`. Use this to stream parts
|
|
858
|
+
* into a custom container, inspect individual parts, or feed a pipeline that does its own
|
|
859
|
+
* archiving. To produce a real `.pptx` file, use {@link write} / {@link writeFile} instead.
|
|
860
|
+
*
|
|
861
|
+
* The returned parts are byte-identical, per part, to what `write()` emits for the same deck,
|
|
862
|
+
* and their order is the package's emission order. Both are a stability-guaranteed observable
|
|
863
|
+
* contract: adding a new part in a later release is backward-compatible as long as existing
|
|
864
|
+
* part paths and their relative order do not shift; renaming or reordering an existing part is
|
|
865
|
+
* a breaking change. Each call returns fresh `Uint8Array` views over per-call buffers (a new
|
|
866
|
+
* assembly runs each time), so callers may retain or transfer them without defensive copying.
|
|
867
|
+
* @param {PartsProps} props - assembly options (`onMediaError` only; compression/output shape
|
|
868
|
+
* are zip concerns that do not apply to unzipped parts)
|
|
869
|
+
* @returns {Promise<PackagePart[]>} the package parts in emission order
|
|
870
|
+
*/
|
|
871
|
+
toParts(props?: PartsProps): Promise<PackagePart[]>;
|
|
872
|
+
/**
|
|
873
|
+
* Export the current Presentation.
|
|
874
|
+
* Write the generated presentation to disk (Node) or trigger a download (browser).
|
|
875
|
+
* @param {WriteFileProps} props - output file properties
|
|
876
|
+
* @returns {Promise<string>} the presentation name
|
|
877
|
+
*/
|
|
878
|
+
writeFile(props?: WriteFileProps): Promise<string>;
|
|
879
|
+
/**
|
|
880
|
+
* Set a custom document property stored in `docProps/custom.xml`.
|
|
881
|
+
* Calling with the same name replaces the existing value.
|
|
882
|
+
* @param name - property name
|
|
883
|
+
* @param value - string, integer/float number, boolean, or Date
|
|
884
|
+
*/
|
|
885
|
+
setCustomProperty(name: string, value: CustomPropertyValue): void;
|
|
886
|
+
/**
|
|
887
|
+
* Add a new Section to Presentation
|
|
888
|
+
* @param {SectionProps} section - section properties
|
|
889
|
+
* @example pptx.addSection({ title:'Charts' });
|
|
890
|
+
*/
|
|
891
|
+
addSection(section: SectionProps): void;
|
|
892
|
+
/**
|
|
893
|
+
* Add a new Slide to Presentation
|
|
894
|
+
* @param {AddSlideProps} options - slide options
|
|
895
|
+
* @returns {Slide} the new Slide
|
|
896
|
+
*/
|
|
897
|
+
addSlide(options?: AddSlideProps): Slide;
|
|
898
|
+
/**
|
|
899
|
+
* Create a custom Slide Layout in any size
|
|
900
|
+
* @param {PresLayout} layout - layout properties
|
|
901
|
+
* @example pptx.defineLayout({ name:'A3', width:16.5, height:11.7 });
|
|
902
|
+
*/
|
|
903
|
+
defineLayout(layout: PresLayout): void;
|
|
904
|
+
/**
|
|
905
|
+
* Create a new slide master [layout] for the Presentation
|
|
906
|
+
* @param {SlideMasterProps} props - layout properties
|
|
907
|
+
*/
|
|
908
|
+
defineSlideMaster(props: SlideMasterProps): void;
|
|
909
|
+
}
|
|
910
|
+
//#endregion
|
|
911
|
+
//#region src/gen/slide/objects/text.d.ts
|
|
912
|
+
/**
|
|
913
|
+
* Render a `text` / `placeholder` slide object to its `<p:sp>` XML.
|
|
914
|
+
*/
|
|
915
|
+
declare function renderTextObject(ctx: RenderContext): string;
|
|
916
|
+
//#endregion
|
|
917
|
+
//#region src/gen/slide/objects/image.d.ts
|
|
918
|
+
/**
|
|
919
|
+
* Render an `image` slide object to its `<p:pic>` XML (sizing/crop, rounding, hyperlink, shadow).
|
|
920
|
+
*/
|
|
921
|
+
declare function renderImageObject(ctx: RenderContext): string;
|
|
922
|
+
//#endregion
|
|
923
|
+
//#region src/families/core.d.ts
|
|
924
|
+
/**
|
|
925
|
+
* ts-pptx: the construct families every presentation carries
|
|
926
|
+
*
|
|
927
|
+
* The core tier. A composed presentation gets these whether it asks for them or not, so
|
|
928
|
+
* `createPresentation()` with no families still authors text, shapes, images, groups and speaker
|
|
929
|
+
* notes -- a deck, rather than a slide-shaped hole.
|
|
930
|
+
*
|
|
931
|
+
* The line is a judgement rather than a measurement: these five are what "a slide" means to most
|
|
932
|
+
* callers, they are cheap, and a surface that made someone compose `text` before it could write a
|
|
933
|
+
* word would be a worse default than one that costs a few kilobytes more. A family is core when
|
|
934
|
+
* leaving it out would make the result something other than a deck; everything else is asked for.
|
|
935
|
+
*/
|
|
936
|
+
/** Every family a composed presentation carries without being asked. */
|
|
937
|
+
declare const CORE_CONSTRUCT_FAMILIES: readonly [{
|
|
938
|
+
name: "text";
|
|
939
|
+
authors: {
|
|
940
|
+
addText(slide: SlideBuilder, text: string | number | TextProps[], options: TextPropsOptions | undefined): void;
|
|
941
|
+
};
|
|
942
|
+
children: {
|
|
943
|
+
text(target: PresSlideInternal, child: {
|
|
944
|
+
text: string | number | TextProps[];
|
|
945
|
+
options?: TextPropsOptions;
|
|
946
|
+
}): void;
|
|
947
|
+
};
|
|
948
|
+
renderers: {
|
|
949
|
+
placeholder: typeof renderTextObject;
|
|
950
|
+
text: typeof renderTextObject;
|
|
951
|
+
};
|
|
952
|
+
}, {
|
|
953
|
+
name: "shape";
|
|
954
|
+
authors: {
|
|
955
|
+
addShape(slide: SlideBuilder, shapeName: SHAPE_NAME, options: ShapeProps | undefined): void;
|
|
956
|
+
};
|
|
957
|
+
children: {
|
|
958
|
+
line(target: PresSlideInternal, child: ShapeProps): void;
|
|
959
|
+
rect(target: PresSlideInternal, child: ShapeProps): void;
|
|
960
|
+
roundRect(target: PresSlideInternal, child: ShapeProps): void;
|
|
961
|
+
shape(target: PresSlideInternal, child: {
|
|
962
|
+
type: SHAPE_NAME;
|
|
963
|
+
options?: ShapeProps;
|
|
964
|
+
}): void;
|
|
965
|
+
};
|
|
966
|
+
}, {
|
|
967
|
+
name: "image";
|
|
968
|
+
authors: {
|
|
969
|
+
addImage(slide: SlideBuilder, options: ImageProps): void;
|
|
970
|
+
};
|
|
971
|
+
children: {
|
|
972
|
+
image(target: PresSlideInternal, child: ImageProps): void;
|
|
973
|
+
};
|
|
974
|
+
renderers: {
|
|
975
|
+
image: typeof renderImageObject;
|
|
976
|
+
};
|
|
977
|
+
}, {
|
|
978
|
+
name: "group";
|
|
979
|
+
authors: {
|
|
980
|
+
addGroup(slide: SlideBuilder, children: GroupChildProps[], options: GroupProps | undefined): void;
|
|
981
|
+
groupObjects(slide: SlideBuilder, objectNames: string[], options: GroupProps | undefined): void;
|
|
982
|
+
};
|
|
983
|
+
}, {
|
|
984
|
+
name: "notes";
|
|
985
|
+
authors: {
|
|
986
|
+
addNotes(slide: SlideBuilder, notes: string | NotesProps[] | NotesProps): void;
|
|
987
|
+
};
|
|
988
|
+
parts: PartContributor;
|
|
989
|
+
}];
|
|
990
|
+
//#endregion
|
|
991
|
+
//#region src/entry-compose.d.ts
|
|
992
|
+
/** Turn a union into the intersection of its members. */
|
|
993
|
+
type UnionToIntersection<U> = (U extends unknown ? (k: U) => void : never) extends ((k: infer I) => void) ? I : never;
|
|
994
|
+
/** One method's public signature, re-pointed at the slide type the caller actually holds. */
|
|
995
|
+
type Chained<F, S> = F extends ((...args: infer A) => unknown) ? (...args: A) => S : never;
|
|
996
|
+
/**
|
|
997
|
+
* The overloaded methods, re-pointed by hand.
|
|
998
|
+
*
|
|
999
|
+
* `Chained` reads one call signature, and TypeScript hands a conditional type the *last* overload,
|
|
1000
|
+
* so `addChart` would come out taking a combo array and nothing else. There is one such method, and
|
|
1001
|
+
* writing it out is cheaper than a generic that unrolls an arbitrary overload list.
|
|
1002
|
+
*/
|
|
1003
|
+
interface ChainedOverloads<S> {
|
|
1004
|
+
addChart: {
|
|
1005
|
+
(data: OptsChartData[], options: ChartOpts & {
|
|
1006
|
+
type: CHART_NAME;
|
|
1007
|
+
}): S;
|
|
1008
|
+
(charts: ChartMulti[], options?: ChartOpts): S;
|
|
1009
|
+
};
|
|
1010
|
+
}
|
|
1011
|
+
/** The slide methods a family list supplies between them. */
|
|
1012
|
+
type SlideMethodsOf<Fs extends readonly ConstructFamily[]> = Extract<keyof UnionToIntersection<Extract<Fs[number], {
|
|
1013
|
+
authors: object;
|
|
1014
|
+
}>['authors']>, SlideAuthorMethod>;
|
|
1015
|
+
/** The presentation methods a family list supplies between them. */
|
|
1016
|
+
type PresentationMethodsOf<Fs extends readonly ConstructFamily[]> = Extract<keyof UnionToIntersection<Extract<Fs[number], {
|
|
1017
|
+
presentationAuthors: object;
|
|
1018
|
+
}>['presentationAuthors']>, keyof PresentationAuthors>;
|
|
1019
|
+
/**
|
|
1020
|
+
* A slide from a composed presentation: everything a slide is, plus exactly the authoring methods
|
|
1021
|
+
* `M` names.
|
|
1022
|
+
*
|
|
1023
|
+
* Parameterized by method name rather than by the family list, so what an editor shows a caller is
|
|
1024
|
+
* the list of calls this slide takes. The methods answer this same type, so a chain cannot widen
|
|
1025
|
+
* back to the full surface and offer a call the deck was not composed for.
|
|
1026
|
+
*/
|
|
1027
|
+
type ComposedSlide<M extends SlideAuthorMethod> = Omit<Slide, SlideAuthorMethod> & { [K in M]: K extends keyof ChainedOverloads<unknown> ? ChainedOverloads<ComposedSlide<M>>[K] : Chained<Slide[K], ComposedSlide<M>>; };
|
|
1028
|
+
/** Every presentation method a family can supply, as the presentation exposes it. */
|
|
1029
|
+
type PresentationFamilyMethods = { [K in keyof PresentationAuthors]-?: BoundPresentationAuthor<NonNullable<PresentationAuthors[K]>>; };
|
|
1030
|
+
/**
|
|
1031
|
+
* A composed presentation: the whole deck-level API, with `addSlide` answering a slide that carries
|
|
1032
|
+
* only `M`, and only the presentation-level methods `P` names.
|
|
1033
|
+
*/
|
|
1034
|
+
type ComposedPresentation<M extends SlideAuthorMethod, P extends keyof PresentationAuthors> = Omit<PresentationCore, 'addSlide' | keyof PresentationAuthors> & Pick<PresentationFamilyMethods, P> & {
|
|
1035
|
+
addSlide: (options?: AddSlideProps) => ComposedSlide<M>;
|
|
1036
|
+
};
|
|
1037
|
+
/** What `createPresentation` takes: the families this deck needs beyond the core tier. */
|
|
1038
|
+
interface ComposeOptions<Fs extends readonly ConstructFamily[]> {
|
|
1039
|
+
/** Construct families to compose in, from `pptx-ts/families`. Listing one twice is harmless. */
|
|
1040
|
+
use?: Fs;
|
|
1041
|
+
}
|
|
1042
|
+
/** What a family list composes to once the core tier is in front of it. */
|
|
1043
|
+
type Composed<Fs extends readonly ConstructFamily[]> = ComposedPresentation<SlideMethodsOf<[...typeof CORE_CONSTRUCT_FAMILIES, ...Fs]>, PresentationMethodsOf<[...typeof CORE_CONSTRUCT_FAMILIES, ...Fs]>>;
|
|
1044
|
+
//#endregion
|
|
1045
|
+
export { pixelsToEmu as A, StandardLayoutName as C, emuToPoints as D, emuToPixels as E, ptToHundredths as M, inchesToEmu as O, StandardLayout as S, emuToInches as T, HUNDREDTHS_PER_POINT as _, renderImageObject as a, PERCENT_SCALE as b, ConstructFamily as c, PartContributor as d, RenderContext as f, FIXED_PCT_PER_PERCENT as g, Emu as h, ComposedSlide as i, pointsToEmu as j, percentToEmu as k, PresentationAuthorContext as l, DEFAULT_PX_PER_INCH as m, Composed as n, renderTextObject as o, ANGLE_UNITS_PER_DEGREE as p, ComposedPresentation as r, PresentationCore as s, ComposeOptions as t, SlideBuilder as u, MAX_COORDINATE_EMU as v, coordToEmu as w, STANDARD_LAYOUTS as x, MIN_COORDINATE_EMU as y };
|
|
1046
|
+
//# sourceMappingURL=entry-compose-DCnvBZz2.d.ts.map
|