@monolith-forensics/monolith-ui 1.9.1-dev.1 → 1.9.1-dev.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.
@@ -2,7 +2,7 @@ import TiptapImage from "@tiptap/extension-image";
2
2
  import StarterKit from "@tiptap/starter-kit";
3
3
  import HorizontalRule from "@tiptap/extension-horizontal-rule";
4
4
  import TextAlign from "@tiptap/extension-text-align";
5
- import { Table, TableCell, TableHeader, TableRow } from "@tiptap/extension-table";
5
+ import { Table, TableCell, TableHeader, TableRow, } from "@tiptap/extension-table";
6
6
  import { Focus, Placeholder } from "@tiptap/extensions";
7
7
  import { Color } from "@tiptap/extension-color";
8
8
  import { TextStyle } from "@tiptap/extension-text-style";
@@ -17,6 +17,8 @@ const CustomImage = TiptapImage.extend({
17
17
  var _a;
18
18
  return Object.assign(Object.assign({}, (_a = this.parent) === null || _a === void 0 ? void 0 : _a.call(this)), { "data-uuid": {
19
19
  default: null,
20
+ }, crossorigin: {
21
+ default: "anonymous",
20
22
  } });
21
23
  },
22
24
  addProseMirrorPlugins() {
@@ -60,123 +60,20 @@ 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, {
64
- mode: "cors",
65
- credentials: "omit",
66
- });
63
+ const response = yield fetch(src);
67
64
  if (!response.ok) {
68
65
  throw new Error("Unable to load image.");
69
66
  }
70
- return {
71
- blob: yield response.blob(),
72
- contentType: response.headers.get("content-type") || "",
73
- };
74
- });
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
- };
98
- const canWriteClipboardType = (ClipboardItemCtor, type) => {
99
- if (!type)
100
- return false;
101
- if (typeof ClipboardItemCtor.supports === "function") {
102
- return ClipboardItemCtor.supports(type);
103
- }
104
- return type === clipboardPngType;
105
- };
106
- const loadImageSource = (src) => new Promise((resolve, reject) => {
107
- const image = new Image();
108
- image.crossOrigin = "anonymous";
109
- image.onload = () => resolve(image);
110
- image.onerror = () => {
111
- reject(new Error("Unable to prepare image for clipboard."));
112
- };
113
- image.src = src;
114
- });
115
- const renderImageSourceToPngBlob = (src) => __awaiter(void 0, void 0, void 0, function* () {
116
- const image = yield loadImageSource(src);
117
- const width = image.naturalWidth || image.width;
118
- const height = image.naturalHeight || image.height;
119
- if (!width || !height) {
120
- throw new Error("Unable to prepare image for clipboard.");
121
- }
122
- const canvas = document.createElement("canvas");
123
- canvas.width = width;
124
- canvas.height = height;
125
- const context = canvas.getContext("2d");
126
- if (!context) {
127
- throw new Error("Unable to prepare image for clipboard.");
128
- }
129
- context.drawImage(image, 0, 0, width, height);
130
- return new Promise((resolve, reject) => {
131
- canvas.toBlob((blob) => {
132
- if (blob) {
133
- resolve(blob);
134
- }
135
- else {
136
- reject(new Error("Unable to prepare image for clipboard."));
137
- }
138
- }, clipboardPngType);
139
- });
140
- });
141
- const convertBlobToClipboardPng = (blob, fallbackSrc) => __awaiter(void 0, void 0, void 0, function* () {
142
- const objectUrl = URL.createObjectURL(blob);
143
- try {
144
- return yield renderImageSourceToPngBlob(objectUrl);
145
- }
146
- catch (error) {
147
- if (!fallbackSrc || fallbackSrc === objectUrl)
148
- throw error;
149
- return renderImageSourceToPngBlob(fallbackSrc);
150
- }
151
- finally {
152
- URL.revokeObjectURL(objectUrl);
153
- }
154
- });
155
- const getClipboardImageBlob = (image, ClipboardItemCtor) => __awaiter(void 0, void 0, void 0, function* () {
156
- const src = image.currentSrc || image.src;
157
- const { blob, contentType } = yield getImageBlob(src);
158
- const type = normalizeMimeType(blob.type) ||
159
- normalizeMimeType(contentType) ||
160
- getImageMimeTypeFromSource(src);
161
- if (canWriteClipboardType(ClipboardItemCtor, type)) {
162
- return {
163
- blob: blob.type === type ? blob : new Blob([blob], { type }),
164
- type,
165
- };
166
- }
167
- return {
168
- blob: yield convertBlobToClipboardPng(blob, src),
169
- type: clipboardPngType,
170
- };
67
+ return response.blob();
171
68
  });
172
69
  const copyImage = (image) => __awaiter(void 0, void 0, void 0, function* () {
173
70
  var _a;
174
- const ClipboardItemCtor = window
175
- .ClipboardItem;
71
+ const ClipboardItemCtor = window.ClipboardItem;
176
72
  if (!((_a = navigator.clipboard) === null || _a === void 0 ? void 0 : _a.write) || !ClipboardItemCtor) {
177
73
  throw new Error("Image copying is not supported by this browser.");
178
74
  }
179
- const { blob, type } = yield getClipboardImageBlob(image, ClipboardItemCtor);
75
+ const blob = yield getImageBlob(image.src);
76
+ const type = blob.type || "image/png";
180
77
  yield navigator.clipboard.write([
181
78
  new ClipboardItemCtor({
182
79
  [type]: blob,
@@ -188,7 +85,7 @@ const downloadImage = (image) => __awaiter(void 0, void 0, void 0, function* ()
188
85
  let href = image.src;
189
86
  let objectUrl = null;
190
87
  try {
191
- const { blob } = yield getImageBlob(image.src);
88
+ const blob = yield getImageBlob(image.src);
192
89
  objectUrl = URL.createObjectURL(blob);
193
90
  href = objectUrl;
194
91
  }
@@ -113,6 +113,7 @@ export const startImageUpload = (file, view, pos, handleImageUpload) => {
113
113
  src: imageSrc,
114
114
  alt: `${id}.png`,
115
115
  "data-uuid": id,
116
+ crossorigin: "anonymous",
116
117
  title: `Filename: ${id}.png`,
117
118
  });
118
119
  const insertTransaction = view.state.tr
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@monolith-forensics/monolith-ui",
3
- "version": "1.9.1-dev.1",
3
+ "version": "1.9.1-dev.6",
4
4
  "main": "./dist/index.js",
5
5
  "types": "./dist/index.d.ts",
6
6
  "author": "Matt Danner (Monolith Forensics LLC)",