image-exporter 1.2.0 → 1.2.2

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/dist/index.d.ts CHANGED
@@ -2,4 +2,6 @@ import { capture } from "./capture";
2
2
  import { downloadImages } from "./capture/download-images";
3
3
  /** Exports for use as an imported package */
4
4
  export { capture, downloadImages };
5
+ /** Type exports */
6
+ export type { ImageOptions, Config, ParsedImageOptions, Image, Label, Format, Scale, Quality, IncludeScaleInLabel, LoggingLevel, } from "./types";
5
7
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAQ3D,6CAA6C;AAC7C,OAAO,EAAE,OAAO,EAAE,cAAc,EAAE,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAQ3D,6CAA6C;AAC7C,OAAO,EAAE,OAAO,EAAE,cAAc,EAAE,CAAC;AAEnC,mBAAmB;AACnB,YAAY,EACV,YAAY,EACZ,MAAM,EACN,kBAAkB,EAClB,KAAK,EACL,KAAK,EACL,MAAM,EACN,KAAK,EACL,OAAO,EACP,mBAAmB,EACnB,YAAY,GACb,MAAM,SAAS,CAAC"}
package/dist/index.js CHANGED
@@ -41,130 +41,6 @@ var __export = (target, all) => {
41
41
  };
42
42
  var __esm = (fn, res) => () => (fn && (res = fn(fn = 0)), res);
43
43
 
44
- // node_modules/downloadjs/download.js
45
- var require_download = __commonJS((exports, module) => {
46
- (function(root, factory) {
47
- if (typeof define === "function" && define.amd) {
48
- define([], factory);
49
- } else if (typeof exports === "object") {
50
- module.exports = factory();
51
- } else {
52
- root.download = factory();
53
- }
54
- })(exports, function() {
55
- return function download(data, strFileName, strMimeType) {
56
- var self2 = window, defaultMime = "application/octet-stream", mimeType = strMimeType || defaultMime, payload = data, url = !strFileName && !strMimeType && payload, anchor = document.createElement("a"), toString = function(a) {
57
- return String(a);
58
- }, myBlob = self2.Blob || self2.MozBlob || self2.WebKitBlob || toString, fileName = strFileName || "download", blob, reader;
59
- myBlob = myBlob.call ? myBlob.bind(self2) : Blob;
60
- if (String(this) === "true") {
61
- payload = [payload, mimeType];
62
- mimeType = payload[0];
63
- payload = payload[1];
64
- }
65
- if (url && url.length < 2048) {
66
- fileName = url.split("/").pop().split("?")[0];
67
- anchor.href = url;
68
- if (anchor.href.indexOf(url) !== -1) {
69
- var ajax = new XMLHttpRequest;
70
- ajax.open("GET", url, true);
71
- ajax.responseType = "blob";
72
- ajax.onload = function(e) {
73
- download(e.target.response, fileName, defaultMime);
74
- };
75
- setTimeout(function() {
76
- ajax.send();
77
- }, 0);
78
- return ajax;
79
- }
80
- }
81
- if (/^data:([\w+-]+\/[\w+.-]+)?[,;]/.test(payload)) {
82
- if (payload.length > 1024 * 1024 * 1.999 && myBlob !== toString) {
83
- payload = dataUrlToBlob(payload);
84
- mimeType = payload.type || defaultMime;
85
- } else {
86
- return navigator.msSaveBlob ? navigator.msSaveBlob(dataUrlToBlob(payload), fileName) : saver(payload);
87
- }
88
- } else {
89
- if (/([\x80-\xff])/.test(payload)) {
90
- var i = 0, tempUiArr = new Uint8Array(payload.length), mx = tempUiArr.length;
91
- for (i;i < mx; ++i)
92
- tempUiArr[i] = payload.charCodeAt(i);
93
- payload = new myBlob([tempUiArr], { type: mimeType });
94
- }
95
- }
96
- blob = payload instanceof myBlob ? payload : new myBlob([payload], { type: mimeType });
97
- function dataUrlToBlob(strUrl) {
98
- var parts = strUrl.split(/[:;,]/), type = parts[1], decoder = parts[2] == "base64" ? atob : decodeURIComponent, binData = decoder(parts.pop()), mx2 = binData.length, i2 = 0, uiArr = new Uint8Array(mx2);
99
- for (i2;i2 < mx2; ++i2)
100
- uiArr[i2] = binData.charCodeAt(i2);
101
- return new myBlob([uiArr], { type });
102
- }
103
- function saver(url2, winMode) {
104
- if ("download" in anchor) {
105
- anchor.href = url2;
106
- anchor.setAttribute("download", fileName);
107
- anchor.className = "download-js-link";
108
- anchor.innerHTML = "downloading...";
109
- anchor.style.display = "none";
110
- document.body.appendChild(anchor);
111
- setTimeout(function() {
112
- anchor.click();
113
- document.body.removeChild(anchor);
114
- if (winMode === true) {
115
- setTimeout(function() {
116
- self2.URL.revokeObjectURL(anchor.href);
117
- }, 250);
118
- }
119
- }, 66);
120
- return true;
121
- }
122
- if (/(Version)\/(\d+)\.(\d+)(?:\.(\d+))?.*Safari\//.test(navigator.userAgent)) {
123
- if (/^data:/.test(url2))
124
- url2 = "data:" + url2.replace(/^data:([\w\/\-\+]+)/, defaultMime);
125
- if (!window.open(url2)) {
126
- if (confirm(`Displaying New Document
127
-
128
- Use Save As... to download, then click back to return to this page.`)) {
129
- location.href = url2;
130
- }
131
- }
132
- return true;
133
- }
134
- var f = document.createElement("iframe");
135
- document.body.appendChild(f);
136
- if (!winMode && /^data:/.test(url2)) {
137
- url2 = "data:" + url2.replace(/^data:([\w\/\-\+]+)/, defaultMime);
138
- }
139
- f.src = url2;
140
- setTimeout(function() {
141
- document.body.removeChild(f);
142
- }, 333);
143
- }
144
- if (navigator.msSaveBlob) {
145
- return navigator.msSaveBlob(blob, fileName);
146
- }
147
- if (self2.URL) {
148
- saver(self2.URL.createObjectURL(blob), true);
149
- } else {
150
- if (typeof blob === "string" || blob.constructor === toString) {
151
- try {
152
- return saver("data:" + mimeType + ";base64," + self2.btoa(blob));
153
- } catch (y) {
154
- return saver("data:" + mimeType + "," + encodeURIComponent(blob));
155
- }
156
- }
157
- reader = new FileReader;
158
- reader.onload = function(e) {
159
- saver(this.result);
160
- };
161
- reader.readAsDataURL(blob);
162
- }
163
- return true;
164
- };
165
- });
166
- });
167
-
168
44
  // node:buffer
169
45
  var exports_buffer = {};
170
46
  __export(exports_buffer, {
@@ -177,7 +53,7 @@ __export(exports_buffer, {
177
53
  default: () => buffer_default,
178
54
  constants: () => constants,
179
55
  btoa: () => btoa,
180
- atob: () => atob2,
56
+ atob: () => atob,
181
57
  INSPECT_MAX_BYTES: () => INSPECT_MAX_BYTES,
182
58
  File: () => File,
183
59
  Buffer: () => Buffer2,
@@ -850,7 +726,7 @@ function notimpl(name) {
850
726
  throw Error(name + " is not implemented for node:buffer browser polyfill");
851
727
  };
852
728
  }
853
- var lookup, revLookup, code = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/", i, len, customInspectSymbol, INSPECT_MAX_BYTES = 50, kMaxLength = 2147483647, kStringMaxLength = 536870888, btoa, atob2, File, Blob2, constants, ERR_BUFFER_OUT_OF_BOUNDS, ERR_INVALID_ARG_TYPE, ERR_OUT_OF_RANGE, MAX_ARGUMENTS_LENGTH = 4096, INVALID_BASE64_RE, hexSliceLookupTable, resolveObjectURL, isUtf8, isAscii = (str) => {
729
+ var lookup, revLookup, code = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/", i, len, customInspectSymbol, INSPECT_MAX_BYTES = 50, kMaxLength = 2147483647, kStringMaxLength = 536870888, btoa, atob, File, Blob2, constants, ERR_BUFFER_OUT_OF_BOUNDS, ERR_INVALID_ARG_TYPE, ERR_OUT_OF_RANGE, MAX_ARGUMENTS_LENGTH = 4096, INVALID_BASE64_RE, hexSliceLookupTable, resolveObjectURL, isUtf8, isAscii = (str) => {
854
730
  for (let char of str)
855
731
  if (char.charCodeAt(0) > 127)
856
732
  return false;
@@ -865,7 +741,7 @@ var init_buffer = __esm(() => {
865
741
  revLookup[95] = 63;
866
742
  customInspectSymbol = typeof Symbol === "function" && typeof Symbol.for === "function" ? Symbol.for("nodejs.util.inspect.custom") : null;
867
743
  btoa = globalThis.btoa;
868
- atob2 = globalThis.atob;
744
+ atob = globalThis.atob;
869
745
  File = globalThis.File;
870
746
  Blob2 = globalThis.Blob;
871
747
  constants = { MAX_LENGTH: kMaxLength, MAX_STRING_LENGTH: kStringMaxLength };
@@ -12972,6 +12848,7 @@ var IN_FIREFOX = USER_AGENT.includes("Firefox");
12972
12848
  var isContext = (value) => value && ("__CONTEXT__" in value);
12973
12849
  var isCssFontFaceRule = (rule) => rule.constructor.name === "CSSFontFaceRule";
12974
12850
  var isCSSImportRule = (rule) => rule.constructor.name === "CSSImportRule";
12851
+ var isLayerBlockRule = (rule) => rule.constructor.name === "CSSLayerBlockRule";
12975
12852
  var isElementNode = (node) => node.nodeType === 1;
12976
12853
  var isSVGElementNode = (node) => typeof node.className === "object";
12977
12854
  var isSVGImageElementNode = (node) => node.tagName === "image";
@@ -14133,7 +14010,10 @@ async function embedWebFont(clone, context) {
14133
14010
  }
14134
14011
  });
14135
14012
  }));
14136
- const cssRules = styleSheets.flatMap((styleSheet) => Array.from(styleSheet.cssRules));
14013
+ const cssRules = [];
14014
+ styleSheets.forEach((sheet) => {
14015
+ unwrapCssLayers(sheet.cssRules, cssRules);
14016
+ });
14137
14017
  cssRules.filter((cssRule) => isCssFontFaceRule(cssRule) && hasCssUrl(cssRule.style.getPropertyValue("src")) && splitFontFamily(cssRule.style.getPropertyValue("font-family"))?.some((val) => fontFamilies.has(val))).forEach((value) => {
14138
14018
  const rule = value;
14139
14019
  const cssText = fontCssTexts.get(rule.cssText);
@@ -14198,6 +14078,18 @@ function filterPreferredFormat(str, context) {
14198
14078
  }
14199
14079
  }) : str;
14200
14080
  }
14081
+ function unwrapCssLayers(rules, out = []) {
14082
+ for (const rule of Array.from(rules)) {
14083
+ if (isLayerBlockRule(rule)) {
14084
+ out.push(...unwrapCssLayers(rule.cssRules));
14085
+ } else if ("cssRules" in rule) {
14086
+ unwrapCssLayers(rule.cssRules, out);
14087
+ } else {
14088
+ out.push(rule);
14089
+ }
14090
+ }
14091
+ return out;
14092
+ }
14201
14093
  async function domToForeignObjectSvg(node, options) {
14202
14094
  const context = await orCreateContext(node, options);
14203
14095
  if (isElementNode(context.node) && isSVGElementNode(context.node))
@@ -14397,7 +14289,6 @@ var filter = (node) => {
14397
14289
  };
14398
14290
 
14399
14291
  // src/capture/download-images.ts
14400
- var import_downloadjs = __toESM(require_download(), 1);
14401
14292
  var import_jszip = __toESM(require_lib(), 1);
14402
14293
 
14403
14294
  // src/config.ts
@@ -14424,11 +14315,24 @@ async function downloadImages(images, userConfig = defaultConfig) {
14424
14315
  const uniqueImages = ensureUniqueFileNames(images);
14425
14316
  if (uniqueImages.length === 1) {
14426
14317
  const image = uniqueImages[0];
14427
- await import_downloadjs.default(image.dataURL, image.fileName);
14318
+ triggerDownload(image.dataURL, image.fileName);
14428
14319
  } else if (uniqueImages.length > 1) {
14429
14320
  const imagesBlob = await zipUpImages(uniqueImages);
14430
14321
  if (imagesBlob)
14431
- await import_downloadjs.default(imagesBlob, parseLabel(config));
14322
+ triggerDownload(imagesBlob, parseLabel(config));
14323
+ }
14324
+ }
14325
+ function triggerDownload(data, fileName) {
14326
+ const url = typeof data === "string" ? data : URL.createObjectURL(data);
14327
+ const a = document.createElement("a");
14328
+ a.href = url;
14329
+ a.download = fileName;
14330
+ a.style.display = "none";
14331
+ document.body.appendChild(a);
14332
+ a.click();
14333
+ document.body.removeChild(a);
14334
+ if (typeof data !== "string") {
14335
+ setTimeout(() => URL.revokeObjectURL(url), 250);
14432
14336
  }
14433
14337
  }
14434
14338
  async function zipUpImages(images) {
@@ -14866,4 +14770,4 @@ export {
14866
14770
  capture
14867
14771
  };
14868
14772
 
14869
- //# debugId=FC121A3F68B566F464756E2164756E21
14773
+ //# debugId=156298500FD95FA864756E2164756E21