@monolith-forensics/monolith-ui 1.9.1-dev.0 → 1.9.1-dev.1

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.
@@ -60,13 +60,41 @@ const getImageFilename = (image) => {
60
60
  return "image.png";
61
61
  };
62
62
  const getImageBlob = (src) => __awaiter(void 0, void 0, void 0, function* () {
63
- const response = yield fetch(src);
63
+ const response = yield fetch(src, {
64
+ mode: "cors",
65
+ credentials: "omit",
66
+ });
64
67
  if (!response.ok) {
65
68
  throw new Error("Unable to load image.");
66
69
  }
67
- return response.blob();
70
+ return {
71
+ blob: yield response.blob(),
72
+ contentType: response.headers.get("content-type") || "",
73
+ };
68
74
  });
69
75
  const clipboardPngType = "image/png";
76
+ const imageMimeTypesByExtension = {
77
+ gif: "image/gif",
78
+ jpg: "image/jpeg",
79
+ jpeg: "image/jpeg",
80
+ png: clipboardPngType,
81
+ svg: "image/svg+xml",
82
+ webp: "image/webp",
83
+ };
84
+ const normalizeMimeType = (type) => type.toLowerCase().split(";")[0].trim();
85
+ const getImageMimeTypeFromSource = (src) => {
86
+ var _a;
87
+ try {
88
+ const url = new URL(src);
89
+ const filename = url.pathname.split("/").filter(Boolean).pop();
90
+ const extension = (_a = filename === null || filename === void 0 ? void 0 : filename.split(".").pop()) === null || _a === void 0 ? void 0 : _a.toLowerCase();
91
+ return extension ? imageMimeTypesByExtension[extension] || "" : "";
92
+ }
93
+ catch (_b) {
94
+ const dataUrlMatch = src.match(/^data:([^;,]+)/);
95
+ return (dataUrlMatch === null || dataUrlMatch === void 0 ? void 0 : dataUrlMatch[1]) || "";
96
+ }
97
+ };
70
98
  const canWriteClipboardType = (ClipboardItemCtor, type) => {
71
99
  if (!type)
72
100
  return false;
@@ -126,10 +154,15 @@ const convertBlobToClipboardPng = (blob, fallbackSrc) => __awaiter(void 0, void
126
154
  });
127
155
  const getClipboardImageBlob = (image, ClipboardItemCtor) => __awaiter(void 0, void 0, void 0, function* () {
128
156
  const src = image.currentSrc || image.src;
129
- const blob = yield getImageBlob(src);
130
- const type = blob.type || "";
157
+ const { blob, contentType } = yield getImageBlob(src);
158
+ const type = normalizeMimeType(blob.type) ||
159
+ normalizeMimeType(contentType) ||
160
+ getImageMimeTypeFromSource(src);
131
161
  if (canWriteClipboardType(ClipboardItemCtor, type)) {
132
- return { blob, type };
162
+ return {
163
+ blob: blob.type === type ? blob : new Blob([blob], { type }),
164
+ type,
165
+ };
133
166
  }
134
167
  return {
135
168
  blob: yield convertBlobToClipboardPng(blob, src),
@@ -155,7 +188,7 @@ const downloadImage = (image) => __awaiter(void 0, void 0, void 0, function* ()
155
188
  let href = image.src;
156
189
  let objectUrl = null;
157
190
  try {
158
- const blob = yield getImageBlob(image.src);
191
+ const { blob } = yield getImageBlob(image.src);
159
192
  objectUrl = URL.createObjectURL(blob);
160
193
  href = objectUrl;
161
194
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@monolith-forensics/monolith-ui",
3
- "version": "1.9.1-dev.0",
3
+ "version": "1.9.1-dev.1",
4
4
  "main": "./dist/index.js",
5
5
  "types": "./dist/index.d.ts",
6
6
  "author": "Matt Danner (Monolith Forensics LLC)",