@pptx-studio/cli 0.1.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.
@@ -0,0 +1,232 @@
1
+ import { PackageCensus } from "@pptx-studio/census";
2
+ import { FaceBoxProbe, TextMeasurer } from "@pptx-studio/text";
3
+ //#region src/main.d.ts
4
+ interface Streams {
5
+ readonly out: (text: string) => void;
6
+ readonly err: (text: string) => void;
7
+ }
8
+ /** Parse, dispatch, and return an exit code. Never calls `process.exit`. */
9
+ declare function main(argv: readonly string[], streams?: Streams): number;
10
+ //#endregion
11
+ //#region src/inspect.d.ts
12
+ /**
13
+ * `pptx-studio inspect deck.pptx`
14
+ *
15
+ * Everything this command knows about `.pptx` lives in `@pptx-studio/census`,
16
+ * which is a browser package with no Node in it. That split is deliberate and
17
+ * it is the reason the census exists as a package at all: the browser explorer
18
+ * in `apps/studio` computes exactly the same object in a Web Worker, so a
19
+ * question answered here and a question answered in a tab cannot drift.
20
+ *
21
+ * What is left for this file is the two things a browser cannot do - read a
22
+ * path off the filesystem, and write to a stream - plus argument handling.
23
+ */
24
+ interface InspectOptions {
25
+ readonly json: boolean;
26
+ readonly parts: boolean;
27
+ readonly namespaces: boolean;
28
+ readonly top: number;
29
+ /** Write to this path instead of stdout. */
30
+ readonly out: string | null;
31
+ }
32
+ declare const INSPECT_DEFAULTS: InspectOptions;
33
+ interface InspectResult {
34
+ readonly census: PackageCensus;
35
+ readonly output: string;
36
+ /**
37
+ * Process exit code.
38
+ *
39
+ * `1` when the census found something it classes as an error, `0` otherwise -
40
+ * a warning or a note never fails the command. That distinction is what makes
41
+ * `inspect` usable in a script: "did this deck load, and is anything in it
42
+ * structurally broken" is a yes/no question, while "is anything in it
43
+ * unusual" is not.
44
+ */
45
+ readonly exitCode: number;
46
+ }
47
+ /** Run a census over one file and render it. Does no I/O of its own beyond the read. */
48
+ declare function inspectFile(path: string, options?: InspectOptions): InspectResult;
49
+ /** Run `inspectFile` and put the result where the options say. */
50
+ declare function runInspect(path: string, options: InspectOptions, write: (text: string) => void): number;
51
+ //#endregion
52
+ //#region src/render/sfnt.d.ts
53
+ /**
54
+ * The four tables a measurement needs, read out of a font file.
55
+ *
56
+ * Not a font library: nothing here decodes an outline, and a CFF font is read
57
+ * as happily as a glyf one because advances live in `hmtx` either way. What it
58
+ * answers is the question the browser answers with `measureText`, which is the
59
+ * one thing `render-svg` cannot get in Node. Every reading below was measured
60
+ * against Chromium in experiment T13 rather than taken from the specification.
61
+ * ADR 0042.
62
+ */
63
+ interface FaceMetrics {
64
+ /** `head.unitsPerEm`, the denominator of every number here. */
65
+ readonly unitsPerEm: number;
66
+ /** Above the baseline, in font units. */
67
+ readonly ascent: number;
68
+ /** Below the baseline, in font units, positive. */
69
+ readonly descent: number;
70
+ /** Which table `ascent` and `descent` came out of, for the diagnostics. */
71
+ readonly source: 'usWin' | 'sTypo';
72
+ }
73
+ interface Face {
74
+ /** `name` ID 1, which is what PowerPoint matches a typeface on. */
75
+ readonly family: string;
76
+ /** `name` ID 2: `Regular`, `Bold`, `Italic`, `Bold Italic`, or a style name. */
77
+ readonly subfamily: string;
78
+ /** `name` ID 16, present when the family splits into more than four styles. */
79
+ readonly typographicFamily: string | undefined;
80
+ readonly metrics: FaceMetrics;
81
+ readonly bold: boolean;
82
+ readonly italic: boolean;
83
+ /** Code point to advance, in font units. */
84
+ advanceOf(codePoint: number): number | undefined;
85
+ /** The adjustment between two code points, in font units. Usually zero. */
86
+ kernBetween(left: number, right: number): number;
87
+ }
88
+ /** Every face in a file, which is one unless the file is a collection. */
89
+ declare function facesIn(bytes: Uint8Array, subject: string): readonly Face[];
90
+ //#endregion
91
+ //#region src/render/faces.d.ts
92
+ /** Where fonts live on this platform, whether or not the directories exist. */
93
+ declare function systemFontDirectories(platform?: string): readonly string[];
94
+ interface IndexedFace {
95
+ readonly face: Face;
96
+ readonly file: string;
97
+ }
98
+ /** What the library found for a typeface the deck named. */
99
+ interface Resolved {
100
+ readonly face: Face;
101
+ /** The typeface the deck asked for. */
102
+ readonly asked: string;
103
+ /** The family actually drawn in, which differs when a substitute was used. */
104
+ readonly drawn: string;
105
+ readonly file: string;
106
+ readonly substituted: boolean;
107
+ }
108
+ interface FontLibrary {
109
+ /** Every face found, for the diagnostics and for a test to count. */
110
+ readonly indexed: readonly IndexedFace[];
111
+ /** The directories that were scanned, in order. */
112
+ readonly directories: readonly string[];
113
+ resolve(family: string, bold: boolean, italic: boolean): Resolved | undefined;
114
+ }
115
+ interface IndexOptions {
116
+ /** Directories to scan before the system ones. Each must exist. */
117
+ readonly extra?: readonly string[];
118
+ /** Whether to scan this platform's own font directories. Default true. */
119
+ readonly system?: boolean;
120
+ readonly platform?: string;
121
+ }
122
+ /**
123
+ * Read every font file under the given directories, once.
124
+ *
125
+ * A file that will not parse is skipped rather than fatal: a font directory on
126
+ * a real machine holds `.ttf` files that are bitmap-only, damaged, or not fonts
127
+ * at all, and one of them must not stop a deck from rendering.
128
+ */
129
+ declare function indexFonts(options?: IndexOptions): FontLibrary;
130
+ //#endregion
131
+ //#region src/render/measure.d.ts
132
+ interface FaceUse {
133
+ readonly asked: string;
134
+ readonly drawn: string;
135
+ readonly file: string;
136
+ readonly substituted: boolean;
137
+ }
138
+ interface FontMeasurer {
139
+ readonly measurer: TextMeasurer;
140
+ readonly faceBox: FaceBoxProbe;
141
+ /** Every typeface asked for, and what it was drawn in. */
142
+ used(): readonly FaceUse[];
143
+ /** Code points no face in the library could draw. */
144
+ missing(): readonly number[];
145
+ }
146
+ /**
147
+ * A measurer bound to one library.
148
+ *
149
+ * Both probes cache by family, because a slide asks for the same handful of
150
+ * typefaces thousands of times and nothing can change between two asks.
151
+ */
152
+ declare function createFontMeasurer(library: FontLibrary): FontMeasurer;
153
+ //#endregion
154
+ //#region src/render/render.d.ts
155
+ /** What a slide is drawn at when the caller says nothing. PowerPoint's own. */
156
+ declare const DEFAULT_WIDTH = 1920;
157
+ interface RenderOptions {
158
+ /** 1-based, or `null` for every slide. */
159
+ readonly slide: number | null;
160
+ readonly width: number;
161
+ /** A directory for many slides, a file for one, or `null` for stdout. */
162
+ readonly out: string | null;
163
+ readonly fontDirs: readonly string[];
164
+ readonly systemFonts: boolean;
165
+ readonly text: boolean;
166
+ readonly json: boolean;
167
+ readonly quiet: boolean;
168
+ }
169
+ declare const RENDER_DEFAULTS: {
170
+ readonly width: 1920;
171
+ readonly systemFonts: true;
172
+ readonly text: true;
173
+ };
174
+ interface RenderedSlide {
175
+ /** 1-based, as the flag and the file name spell it. */
176
+ readonly number: number;
177
+ readonly svg: string;
178
+ }
179
+ interface RenderResult {
180
+ readonly slides: readonly RenderedSlide[];
181
+ readonly width: number;
182
+ readonly height: number;
183
+ /** Every typeface the deck asked for, and what drew it. Empty with `--no-text`. */
184
+ readonly fonts: readonly FaceUse[];
185
+ /** Code points no indexed face could draw. */
186
+ readonly missing: readonly number[];
187
+ readonly fontDirectories: readonly string[];
188
+ readonly facesIndexed: number;
189
+ }
190
+ /**
191
+ * Render a deck that is already in memory.
192
+ *
193
+ * Separate from `runRender` so that the whole pipeline is exercised by the test
194
+ * suite without a file system, a process or a captured stdout.
195
+ */
196
+ declare function renderDeck(bytes: Uint8Array, options: RenderOptions): RenderResult;
197
+ /** Read, render, write, and return an exit code. Never calls `process.exit`. */
198
+ declare function runRender(file: string, options: RenderOptions, out: (text: string) => void): number;
199
+ //#endregion
200
+ //#region src/render/errors.d.ts
201
+ /**
202
+ * Typed failures for rendering outside a browser.
203
+ *
204
+ * The browser renderer cannot produce any of these: it is handed a measuring
205
+ * canvas and a font stack, and the platform answers. In Node both of those are
206
+ * ours to find, so both are ours to fail at. ADR 0042.
207
+ */
208
+ type RenderErrorCode =
209
+ /** Bytes that are not an SFNT font, or a table the reader needs is absent. */
210
+ 'CLI_FONT_UNREADABLE' |
211
+ /** A font directory that was named on the command line and does not exist. */
212
+ 'CLI_FONT_DIR' |
213
+ /** No face on this machine can stand in for a typeface the deck names. */
214
+ 'CLI_NO_FACE' |
215
+ /** A run whose resolved size is not a positive number of hundredths of a point. */
216
+ 'CLI_FONT_SIZE' |
217
+ /** A slide index outside the deck. */
218
+ 'CLI_NO_SLIDE' |
219
+ /** An output path that names no directory, or a directory that is a file. */
220
+ 'CLI_OUTPUT_PATH';
221
+ declare const RENDER_ERROR_CODES: readonly RenderErrorCode[];
222
+ declare class RenderError extends Error {
223
+ readonly name = "RenderError";
224
+ readonly code: RenderErrorCode;
225
+ /** The font file, deck path or typeface the failure is about. */
226
+ readonly subject: string;
227
+ constructor(code: RenderErrorCode, message: string, subject: string);
228
+ }
229
+ declare function isRenderError(error: unknown): error is RenderError;
230
+ //#endregion
231
+ export { DEFAULT_WIDTH, type Face, type FaceUse, type FontLibrary, type FontMeasurer, INSPECT_DEFAULTS, type InspectOptions, type InspectResult, RENDER_DEFAULTS, RENDER_ERROR_CODES, RenderError, type RenderErrorCode, type RenderOptions, type RenderResult, type RenderedSlide, type Streams, createFontMeasurer, facesIn, indexFonts, inspectFile, isRenderError, main, renderDeck, runInspect, runRender, systemFontDirectories };
232
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","names":[],"sources":["../src/main.ts","../src/inspect.ts","../src/render/sfnt.ts","../src/render/faces.ts","../src/render/measure.ts","../src/render/render.ts","../src/render/errors.ts"],"mappings":";;;UA0HiB;WACN,MAAM;WACN,MAAM;;;iBASD,KAAK,yBAAyB,UAAS;;;;;;;;;;;;;;;UCrHtC;WACN;WACA;WACA;WACA;;WAEA;;cAGE,kBAAkB;UAQd;WACN,QAAQ;WACR;;;;;;;;;;WAUA;;;iBAIK,YACd,cACA,UAAS,iBACR;;iBAiBa,WACd,cACA,SAAS,gBACT,QAAQ;;;;;;;;;;;;;UCpDO;;WAEN;;WAEA;;WAEA;;WAEA;;UAGM;;WAEN;;WAEA;;WAEA;WACA,SAAS;WACT;WACA;;EAET,UAAU;;EAEV,YAAY,cAAc;;;iBAqdZ,QAAQ,OAAO,YAAY,2BAA2B;;;;iBCnetD,sBAAsB;UAuCrB;WACN,MAAM;WACN;;;UAIM;WACN,MAAM;;WAEN;;WAEA;WACA;WACA;;UAGM;;WAEN,kBAAkB;;WAElB;EACT,QAAQ,gBAAgB,eAAe,kBAAkB;;UAG1C;;WAEN;;WAEA;WACA;;;;;;;;;iBAoBK,WAAW,UAAS,eAAoB;;;UCxEvC;WACN;WACA;WACA;WACA;;UAGM;WACN,UAAU;WACV,SAAS;;EAElB,iBAAiB;;EAEjB;;;;;;;;iBASc,mBAAmB,SAAS,cAAc;;;;cC9C7C;UAEI;;WAEN;WACA;;WAEA;WACA;WACA;WACA;WACA;WACA;;cAGE;;;;;UAMI;;WAEN;WACA;;UAGM;WACN,iBAAiB;WACjB;WACA;;WAEA,gBAAgB;;WAEhB;WACA;WACA;;;;;;;;iBAoBK,WAAW,OAAO,YAAY,SAAS,gBAAgB;;iBAuIvD,UACd,cACA,SAAS,eACT,MAAM;;;;;;;;;;KCjNI;;;;;;;;;;;;;cAcC,6BAA6B;cAS7B,oBAAoB;WACb;WACT,MAAM;;WAEN;EAEG,YAAA,MAAM,iBAAiB,iBAAiB;;iBAOtC,cAAc,iBAAiB,SAAS"}
package/dist/index.js ADDED
@@ -0,0 +1,2 @@
1
+ import { a as runRender, c as systemFontDirectories, d as RenderError, f as isRenderError, h as runInspect, i as renderDeck, l as facesIn, m as inspectFile, n as DEFAULT_WIDTH, o as createFontMeasurer, p as INSPECT_DEFAULTS, r as RENDER_DEFAULTS, s as indexFonts, t as main, u as RENDER_ERROR_CODES } from "./main-DLx2onii.js";
2
+ export { DEFAULT_WIDTH, INSPECT_DEFAULTS, RENDER_DEFAULTS, RENDER_ERROR_CODES, RenderError, createFontMeasurer, facesIn, indexFonts, inspectFile, isRenderError, main, renderDeck, runInspect, runRender, systemFontDirectories };