@bendyline/squisq-cli 2.8.4 → 2.8.6

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.
@@ -11,12 +11,13 @@ import {
11
11
  extractThumbnails,
12
12
  prepareConversion,
13
13
  readInput,
14
+ renderDocCoverToPng,
14
15
  renderDocToDashboardPng,
15
16
  renderDocToGif,
16
17
  renderDocToMp4,
17
18
  resolveDashboardDimensions,
18
19
  validateDashboardImageDimensions
19
- } from "./chunk-W7GAUNLT.js";
20
+ } from "./chunk-EVE74NYB.js";
20
21
  import {
21
22
  GIF_EXPORT_DEFAULTS,
22
23
  framesToGifNative,
@@ -41,6 +42,7 @@ export {
41
42
  framesToMp4NativeBytes,
42
43
  prepareConversion,
43
44
  readInput,
45
+ renderDocCoverToPng,
44
46
  renderDocToDashboardPng,
45
47
  renderDocToGif,
46
48
  renderDocToMp4,
package/dist/api.d.ts CHANGED
@@ -380,6 +380,24 @@ interface RenderDashboardPngResult {
380
380
  /** Absolute path written, when `outputPath` was requested. */
381
381
  outputPath?: string;
382
382
  }
383
+ /** Options for rendering the managed cover as a standalone PNG. */
384
+ interface RenderCoverPngOptions {
385
+ signal?: AbortSignal;
386
+ outputPath?: string;
387
+ width?: number;
388
+ height?: number;
389
+ animationsEnabled?: boolean;
390
+ onProgress?: (phase: string, percent: number) => void;
391
+ }
392
+ /** Result returned by {@link renderDocCoverToPng}. */
393
+ interface RenderCoverPngResult {
394
+ bytes: Uint8Array;
395
+ width: number;
396
+ height: number;
397
+ outputPath?: string;
398
+ }
399
+ /** Render a Doc's managed cover to a PNG with the canonical headless renderer. */
400
+ declare function renderDocCoverToPng(doc: Doc, container: ContentContainer, options?: RenderCoverPngOptions): Promise<RenderCoverPngResult>;
383
401
  /**
384
402
  * Render a Doc's Dashboard rendition to a single PNG image.
385
403
  *
@@ -424,4 +442,4 @@ interface ExtractThumbnailsOptions {
424
442
  */
425
443
  declare function extractThumbnails(options: ExtractThumbnailsOptions): Promise<void>;
426
444
 
427
- export { CapturedFrameBudgetError, type CliConvertOptions, type ExtractThumbnailsOptions, GIF_EXPORT_DEFAULTS, type GifExportOptions, type GifFormatOptions, MAX_CAPTURED_FRAME_BYTES, type Mp4FormatOptions, type NativeVideoExportOptions, type PngFormatOptions, type ReadInputResult, type RenderDashboardPngOptions, type RenderDashboardPngResult, type RenderDocToGifOptions, type RenderDocToGifResult, type RenderDocToMp4Options, type RenderDocToMp4Result, type ThumbnailSpec, convert, createCliRegistry, extractThumbnails, framesToGifNative, framesToGifNativeBytes, framesToMp4Native, framesToMp4NativeBytes, prepareConversion, readInput, renderDocToDashboardPng, renderDocToGif, renderDocToMp4 };
445
+ export { CapturedFrameBudgetError, type CliConvertOptions, type ExtractThumbnailsOptions, GIF_EXPORT_DEFAULTS, type GifExportOptions, type GifFormatOptions, MAX_CAPTURED_FRAME_BYTES, type Mp4FormatOptions, type NativeVideoExportOptions, type PngFormatOptions, type ReadInputResult, type RenderCoverPngOptions, type RenderCoverPngResult, type RenderDashboardPngOptions, type RenderDashboardPngResult, type RenderDocToGifOptions, type RenderDocToGifResult, type RenderDocToMp4Options, type RenderDocToMp4Result, type ThumbnailSpec, convert, createCliRegistry, extractThumbnails, framesToGifNative, framesToGifNativeBytes, framesToMp4Native, framesToMp4NativeBytes, prepareConversion, readInput, renderDocCoverToPng, renderDocToDashboardPng, renderDocToGif, renderDocToMp4 };
package/dist/api.js CHANGED
@@ -1118,6 +1118,45 @@ async function captureDocFrames(doc, container, options) {
1118
1118
  throw err;
1119
1119
  }
1120
1120
  }
1121
+ async function renderDocCoverToPng(doc, container, options = {}) {
1122
+ const width = options.width ?? 1920;
1123
+ const height = options.height ?? 1080;
1124
+ if (!doc.startBlock) throw new Error("Document has no managed cover to render");
1125
+ if (!Number.isInteger(width) || !Number.isInteger(height) || width < 64 || height < 64) {
1126
+ throw new Error("Cover PNG dimensions must be integers of at least 64 pixels");
1127
+ }
1128
+ options.signal?.throwIfAborted();
1129
+ const bytes = await withRenderPage(
1130
+ doc,
1131
+ container,
1132
+ {
1133
+ signal: options.signal,
1134
+ width,
1135
+ height,
1136
+ includeAudio: false,
1137
+ animationsEnabled: options.animationsEnabled ?? false,
1138
+ displayMode: "slideshow",
1139
+ onProgress: options.onProgress
1140
+ },
1141
+ async ({ page, renderAPI }) => {
1142
+ options.onProgress?.("rendering cover", 50);
1143
+ await renderAPI.evaluate((api) => api.showCover());
1144
+ await page.waitForTimeout(100);
1145
+ options.signal?.throwIfAborted();
1146
+ options.onProgress?.("capturing image", 85);
1147
+ return page.screenshot({ type: "png" });
1148
+ }
1149
+ );
1150
+ let writtenPath;
1151
+ if (options.outputPath) {
1152
+ const absolute = resolvePath(options.outputPath);
1153
+ await mkdir(dirname2(absolute), { recursive: true });
1154
+ await writeFile(absolute, bytes);
1155
+ writtenPath = absolute;
1156
+ }
1157
+ options.onProgress?.("done", 100);
1158
+ return { bytes, width, height, ...writtenPath ? { outputPath: writtenPath } : {} };
1159
+ }
1121
1160
  async function renderDocToDashboardPng(doc, container, options = {}) {
1122
1161
  const {
1123
1162
  signal,
@@ -1368,6 +1407,7 @@ export {
1368
1407
  framesToMp4NativeBytes,
1369
1408
  prepareConversion,
1370
1409
  readInput,
1410
+ renderDocCoverToPng,
1371
1411
  renderDocToDashboardPng,
1372
1412
  renderDocToGif,
1373
1413
  renderDocToMp4,
@@ -331,7 +331,7 @@ function mp4Format() {
331
331
  const animationsEnabled = typeof mp4Opts.animationsEnabled === "boolean" ? mp4Opts.animationsEnabled : MP4_DEFAULTS.animationsEnabled;
332
332
  const outputPath = join(tmpdir(), `squisq-mp4-${randomBytes(8).toString("hex")}.mp4`);
333
333
  try {
334
- const { renderDocToMp4: renderDocToMp42 } = await import("./api-OK3YGUA4.js");
334
+ const { renderDocToMp4: renderDocToMp42 } = await import("./api-FHTG2OCX.js");
335
335
  await renderDocToMp42(input.doc, input.container, {
336
336
  outputPath,
337
337
  fps,
@@ -372,7 +372,7 @@ function gifFormat() {
372
372
  const defaultHeight = portrait ? GIF_DEFAULTS.width : GIF_DEFAULTS.height;
373
373
  const outputPath = join(tmpdir(), `squisq-gif-${randomBytes(8).toString("hex")}.gif`);
374
374
  try {
375
- const { renderDocToGif: renderDocToGif2 } = await import("./api-OK3YGUA4.js");
375
+ const { renderDocToGif: renderDocToGif2 } = await import("./api-FHTG2OCX.js");
376
376
  const result = await renderDocToGif2(input.doc, input.container, {
377
377
  outputPath,
378
378
  fps: typeof gifOpts.fps === "number" ? gifOpts.fps : GIF_DEFAULTS.fps,
@@ -415,7 +415,7 @@ function pngFormat() {
415
415
  async exportDoc(input, options) {
416
416
  options.signal?.throwIfAborted();
417
417
  const pngOpts = options.formatOptions?.png ?? {};
418
- const { renderDocToDashboardPng: renderDocToDashboardPng2 } = await import("./api-OK3YGUA4.js");
418
+ const { renderDocToDashboardPng: renderDocToDashboardPng2 } = await import("./api-FHTG2OCX.js");
419
419
  const result = await renderDocToDashboardPng2(input.doc, input.container, {
420
420
  resolution: pngOpts.resolution,
421
421
  width: pngOpts.width,
@@ -1115,6 +1115,45 @@ async function captureDocFrames(doc, container, options) {
1115
1115
  throw err;
1116
1116
  }
1117
1117
  }
1118
+ async function renderDocCoverToPng(doc, container, options = {}) {
1119
+ const width = options.width ?? 1920;
1120
+ const height = options.height ?? 1080;
1121
+ if (!doc.startBlock) throw new Error("Document has no managed cover to render");
1122
+ if (!Number.isInteger(width) || !Number.isInteger(height) || width < 64 || height < 64) {
1123
+ throw new Error("Cover PNG dimensions must be integers of at least 64 pixels");
1124
+ }
1125
+ options.signal?.throwIfAborted();
1126
+ const bytes = await withRenderPage(
1127
+ doc,
1128
+ container,
1129
+ {
1130
+ signal: options.signal,
1131
+ width,
1132
+ height,
1133
+ includeAudio: false,
1134
+ animationsEnabled: options.animationsEnabled ?? false,
1135
+ displayMode: "slideshow",
1136
+ onProgress: options.onProgress
1137
+ },
1138
+ async ({ page, renderAPI }) => {
1139
+ options.onProgress?.("rendering cover", 50);
1140
+ await renderAPI.evaluate((api) => api.showCover());
1141
+ await page.waitForTimeout(100);
1142
+ options.signal?.throwIfAborted();
1143
+ options.onProgress?.("capturing image", 85);
1144
+ return page.screenshot({ type: "png" });
1145
+ }
1146
+ );
1147
+ let writtenPath;
1148
+ if (options.outputPath) {
1149
+ const absolute = resolvePath(options.outputPath);
1150
+ await mkdir(dirname2(absolute), { recursive: true });
1151
+ await writeFile(absolute, bytes);
1152
+ writtenPath = absolute;
1153
+ }
1154
+ options.onProgress?.("done", 100);
1155
+ return { bytes, width, height, ...writtenPath ? { outputPath: writtenPath } : {} };
1156
+ }
1118
1157
  async function renderDocToDashboardPng(doc, container, options = {}) {
1119
1158
  const {
1120
1159
  signal,
@@ -1358,6 +1397,7 @@ export {
1358
1397
  CapturedFrameBudgetError,
1359
1398
  convert,
1360
1399
  prepareConversion,
1400
+ renderDocCoverToPng,
1361
1401
  renderDocToDashboardPng,
1362
1402
  renderDocToMp4,
1363
1403
  renderDocToGif,
package/dist/index.js CHANGED
@@ -9,7 +9,7 @@ import {
9
9
  renderDocToDashboardPng,
10
10
  renderDocToGif,
11
11
  renderDocToMp4
12
- } from "./chunk-W7GAUNLT.js";
12
+ } from "./chunk-EVE74NYB.js";
13
13
  import "./chunk-GGVASRPG.js";
14
14
 
15
15
  // src/index.ts