image-exporter 1.0.7 → 1.0.9

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "image-exporter",
3
- "version": "1.0.7",
3
+ "version": "1.0.9",
4
4
  "description": "Easily download one or more DOM elements as images",
5
5
  "main": "src/index.ts",
6
6
  "type": "module",
@@ -41,8 +41,8 @@
41
41
  "dependencies": {
42
42
  "@types/downloadjs": "^1.4.6",
43
43
  "downloadjs": "^1.4.7",
44
- "html-to-image": "^1.11.13",
45
- "jszip": "^3.10.1"
44
+ "jszip": "^3.10.1",
45
+ "modern-screenshot": "^4.6.0"
46
46
  },
47
47
  "devDependencies": {
48
48
  "concurrently": "^9.1.2",
@@ -1,7 +1,7 @@
1
- import * as htmlToImage from "html-to-image";
2
1
  import { Image, ParsedImageOptions } from "../types";
3
2
  import { handleFileNames } from "./handle-filenames";
4
- import { Options } from "html-to-image/lib/types";
3
+ import * as modernScreenshot from "modern-screenshot";
4
+
5
5
  /**
6
6
  * captureElement
7
7
  *
@@ -15,11 +15,11 @@ export async function captureElement(
15
15
  try {
16
16
  let dataURL = "";
17
17
  // Final settings for capturing images.
18
- let htmlToImageOptions: Options = {
18
+ let htmlToImageOptions: modernScreenshot.Options = {
19
19
  // Ensure quality is a number
20
20
  quality: imageOptions.quality,
21
21
  // Ensure scale is a number
22
- pixelRatio: imageOptions.scale,
22
+ scale: imageOptions.scale,
23
23
  // Ignores elements with data-ignore-capture attribute
24
24
  filter: filter,
25
25
  };
@@ -41,13 +41,16 @@ export async function captureElement(
41
41
  // Captures image based on format
42
42
  switch (imageOptions.format) {
43
43
  case "jpg":
44
- dataURL = await htmlToImage.toJpeg(element, htmlToImageOptions);
44
+ dataURL = await modernScreenshot.domToJpeg(element, htmlToImageOptions);
45
45
  break;
46
46
  case "png":
47
- dataURL = await htmlToImage.toPng(element, htmlToImageOptions);
47
+ dataURL = await modernScreenshot.domToPng(element, htmlToImageOptions);
48
48
  break;
49
49
  case "svg":
50
- dataURL = await htmlToImage.toSvg(element, htmlToImageOptions);
50
+ dataURL = await modernScreenshot.domToSvg(element, htmlToImageOptions);
51
+ break;
52
+ case "webp":
53
+ dataURL = await modernScreenshot.domToWebp(element, htmlToImageOptions);
51
54
  break;
52
55
  }
53
56
 
@@ -87,14 +87,14 @@ export async function getImageOptions(
87
87
  try {
88
88
  let format = element.dataset.format || config.format;
89
89
  format = format.trim().toLowerCase();
90
- if (format === "jpg" || format === "png" || format === "svg") {
90
+ if (format === "jpg" || format === "png" || format === "svg" || format === "webp") {
91
91
  return format;
92
92
  } else {
93
93
  throw new Error(
94
94
  `ImageExporter: provided format is not valid.
95
95
  Provided: ${format}
96
96
  Element: ${element}
97
- Accepted values: jpg, png, svg
97
+ Accepted values: jpg, png, svg,
98
98
  Defaulting to: ${config.format}`
99
99
  );
100
100
  }
package/src/types.d.ts CHANGED
@@ -44,7 +44,7 @@ export interface Image {
44
44
  }
45
45
 
46
46
  export type Label = string;
47
- export type Format = "jpg" | "png" | "svg";
47
+ export type Format = "jpg" | "png" | "svg" | "webp";
48
48
  export type Scale = number | number[];
49
49
  export type Quality = number;
50
50
  export type IncludeScaleInLabel = boolean;