wasm-html-to-image 1.0.19 → 1.0.21

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.
@@ -29,6 +29,8 @@ export interface Orchestration {
29
29
  */
30
30
  animationLoop: number;
31
31
  width: number;
32
+ /** The caller's explicit `width` (image input skips resize when width/height are both omitted). */
33
+ widthOption: number | undefined;
32
34
  height: number | undefined;
33
35
  crop: HtmlToImageOptions["crop"];
34
36
  fit: HtmlToImageOptions["fit"];
@@ -34,7 +34,7 @@ export function defaultSpeed(format) {
34
34
  }
35
35
  /** Build per-call orchestration state (log gate, timings, diag, resolve ctx). */
36
36
  export function createOrchestration(module, options) {
37
- const { format = "png", quality = 85, speed: speedOption, width, height, crop, fit, value, url, baseUrl, fontMap, userAgent, fallbackFonts, logLevel = LogLevel.None, onLog, diagnostics = false, onDiagnostics, onLayout, resolveResource, mediaType = "screen", textToPaths, css, fonts: preloadFonts, limits = {}, pdfTitle, pdfAuthor, pdfSubject, pdfKeywords, pdfCreator, pdfProducer, pdfMargin, pdfHeader, pdfFooter, } = options;
37
+ const { format = "png", quality = 85, speed: speedOption, height, crop, fit, value, url, baseUrl, fontMap, userAgent, fallbackFonts, logLevel = LogLevel.None, onLog, diagnostics = false, onDiagnostics, onLayout, resolveResource, mediaType = "screen", textToPaths, css, fonts: preloadFonts, limits = {}, pdfTitle, pdfAuthor, pdfSubject, pdfKeywords, pdfCreator, pdfProducer, pdfMargin, pdfHeader, pdfFooter, } = options;
38
38
  // `animation` accepts a boolean (image input: keep frames) or, for HTML
39
39
  // input, an object requesting keyframe sampling. The object form turns on
40
40
  // the boolean flag for the encode stage and enables the frame path.
@@ -47,6 +47,10 @@ export function createOrchestration(module, options) {
47
47
  const animationLoop = Math.max(0, Math.trunc(animationFrames?.loop ?? 0));
48
48
  const speed = speedOption ?? defaultSpeed(format);
49
49
  const colorSpace = options.colorSpace === "cmyk" ? "cmyk" : "srgb";
50
+ const width = options.width ?? 800;
51
+ if (!Number.isFinite(width) || width <= 0) {
52
+ throw new Error(`wasm-html-to-image: width must be a positive finite number, got ${String(options.width)}`);
53
+ }
50
54
  const scale = options.scale ?? 1;
51
55
  if (!Number.isFinite(scale) || scale <= 0 || scale > 16) {
52
56
  throw new Error(`wasm-html-to-image: scale must be a number in (0, 16], got ${String(options.scale)}`);
@@ -154,6 +158,7 @@ export function createOrchestration(module, options) {
154
158
  animationFrames,
155
159
  animationLoop,
156
160
  width,
161
+ widthOption: options.width,
157
162
  height,
158
163
  crop,
159
164
  fit,
@@ -262,7 +267,7 @@ export async function resolveHtmlSource(orch) {
262
267
  * `imageBytesFromUnknown` (`unknown` in, no `as` casts).
263
268
  */
264
269
  export async function runImageInput(module, value, orch) {
265
- const { format, quality, speed, animation, animationLoop, width, height, crop, fit, fmtInt, colorSpace, dpiOption, t0, emitLog, logged, loggedBinding, addTime, deliverReport, } = orch;
270
+ const { format, quality, speed, animation, animationLoop, widthOption, height, crop, fit, fmtInt, colorSpace, dpiOption, t0, emitLog, logged, loggedBinding, addTime, deliverReport, } = orch;
266
271
  // Narrowed here: caller selected this branch via `isImageInput(value)`.
267
272
  const loadImage = module.converter_load_image;
268
273
  if (typeof loadImage !== "function")
@@ -296,10 +301,10 @@ export async function runImageInput(module, value, orch) {
296
301
  if (crop) {
297
302
  module.converter_crop(inst, crop.x, crop.y, crop.width, crop.height);
298
303
  }
299
- if (width !== undefined || height !== undefined) {
300
- module.converter_resize(inst, width ?? 0, height ?? 0, FIT_INT[fit ?? "contain"]);
304
+ if (widthOption !== undefined || height !== undefined) {
305
+ module.converter_resize(inst, widthOption ?? 0, height ?? 0, FIT_INT[fit ?? "contain"]);
301
306
  }
302
- const outWidth = module.converter_get_width?.(inst) ?? width ?? originalWidth;
307
+ const outWidth = module.converter_get_width?.(inst) ?? widthOption ?? originalWidth;
303
308
  const outHeight = module.converter_get_height?.(inst) ?? height ?? originalHeight;
304
309
  const outAnimation = module.converter_is_animation?.(inst) ?? animation;
305
310
  const outFormat = module.converter_get_format?.(inst) || format;
package/dist/core.d.ts CHANGED
@@ -48,7 +48,8 @@ export interface RenderOptions {
48
48
  value?: string | string[] | Uint8Array | ArrayBuffer;
49
49
  url?: string;
50
50
  baseUrl?: string;
51
- width: number;
51
+ /** Layout viewport width in CSS px (HTML) or target width (image resize). Defaults to 800. */
52
+ width?: number;
52
53
  height?: number;
53
54
  format?: OutputFormat;
54
55
  }