|  | @@ -10,6 +10,11 @@ import { restore } from "../data/restore";
 | 
											
												
													
														|  |  import { MIME_TYPES } from "../constants";
 |  |  import { MIME_TYPES } from "../constants";
 | 
											
												
													
														|  |  import { encodePngMetadata } from "../data/image";
 |  |  import { encodePngMetadata } from "../data/image";
 | 
											
												
													
														|  |  import { serializeAsJSON } from "../data/json";
 |  |  import { serializeAsJSON } from "../data/json";
 | 
											
												
													
														|  | 
 |  | +import {
 | 
											
												
													
														|  | 
 |  | +  copyBlobToClipboardAsPng,
 | 
											
												
													
														|  | 
 |  | +  copyTextToSystemClipboard,
 | 
											
												
													
														|  | 
 |  | +  copyToClipboard,
 | 
											
												
													
														|  | 
 |  | +} from "../clipboard";
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  |  type ExportOpts = {
 |  |  type ExportOpts = {
 | 
											
												
													
														|  |    elements: readonly NonDeleted<ExcalidrawElement>[];
 |  |    elements: readonly NonDeleted<ExcalidrawElement>[];
 | 
											
										
											
												
													
														|  | @@ -81,7 +86,7 @@ export const exportToBlob = async (
 | 
											
												
													
														|  |      mimeType?: string;
 |  |      mimeType?: string;
 | 
											
												
													
														|  |      quality?: number;
 |  |      quality?: number;
 | 
											
												
													
														|  |    },
 |  |    },
 | 
											
												
													
														|  | -): Promise<Blob | null> => {
 |  | 
 | 
											
												
													
														|  | 
 |  | +): Promise<Blob> => {
 | 
											
												
													
														|  |    let { mimeType = MIME_TYPES.png, quality } = opts;
 |  |    let { mimeType = MIME_TYPES.png, quality } = opts;
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  |    if (mimeType === MIME_TYPES.png && typeof quality === "number") {
 |  |    if (mimeType === MIME_TYPES.png && typeof quality === "number") {
 | 
											
										
											
												
													
														|  | @@ -107,9 +112,12 @@ export const exportToBlob = async (
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  |    quality = quality ? quality : /image\/jpe?g/.test(mimeType) ? 0.92 : 0.8;
 |  |    quality = quality ? quality : /image\/jpe?g/.test(mimeType) ? 0.92 : 0.8;
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  | -  return new Promise((resolve) => {
 |  | 
 | 
											
												
													
														|  | 
 |  | +  return new Promise((resolve, reject) => {
 | 
											
												
													
														|  |      canvas.toBlob(
 |  |      canvas.toBlob(
 | 
											
												
													
														|  | -      async (blob: Blob | null) => {
 |  | 
 | 
											
												
													
														|  | 
 |  | +      async (blob) => {
 | 
											
												
													
														|  | 
 |  | +        if (!blob) {
 | 
											
												
													
														|  | 
 |  | +          return reject(new Error("couldn't export to blob"));
 | 
											
												
													
														|  | 
 |  | +        }
 | 
											
												
													
														|  |          if (
 |  |          if (
 | 
											
												
													
														|  |            blob &&
 |  |            blob &&
 | 
											
												
													
														|  |            mimeType === MIME_TYPES.png &&
 |  |            mimeType === MIME_TYPES.png &&
 | 
											
										
											
												
													
														|  | @@ -156,6 +164,33 @@ export const exportToSvg = async ({
 | 
											
												
													
														|  |    );
 |  |    );
 | 
											
												
													
														|  |  };
 |  |  };
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  | 
 |  | +export const exportToClipboard = async (
 | 
											
												
													
														|  | 
 |  | +  opts: ExportOpts & {
 | 
											
												
													
														|  | 
 |  | +    mimeType?: string;
 | 
											
												
													
														|  | 
 |  | +    quality?: number;
 | 
											
												
													
														|  | 
 |  | +    type: "png" | "svg" | "json";
 | 
											
												
													
														|  | 
 |  | +  },
 | 
											
												
													
														|  | 
 |  | +) => {
 | 
											
												
													
														|  | 
 |  | +  if (opts.type === "svg") {
 | 
											
												
													
														|  | 
 |  | +    const svg = await exportToSvg(opts);
 | 
											
												
													
														|  | 
 |  | +    await copyTextToSystemClipboard(svg.outerHTML);
 | 
											
												
													
														|  | 
 |  | +  } else if (opts.type === "png") {
 | 
											
												
													
														|  | 
 |  | +    await copyBlobToClipboardAsPng(exportToBlob(opts));
 | 
											
												
													
														|  | 
 |  | +  } else if (opts.type === "json") {
 | 
											
												
													
														|  | 
 |  | +    const appState = {
 | 
											
												
													
														|  | 
 |  | +      offsetTop: 0,
 | 
											
												
													
														|  | 
 |  | +      offsetLeft: 0,
 | 
											
												
													
														|  | 
 |  | +      width: 0,
 | 
											
												
													
														|  | 
 |  | +      height: 0,
 | 
											
												
													
														|  | 
 |  | +      ...getDefaultAppState(),
 | 
											
												
													
														|  | 
 |  | +      ...opts.appState,
 | 
											
												
													
														|  | 
 |  | +    };
 | 
											
												
													
														|  | 
 |  | +    await copyToClipboard(opts.elements, appState, opts.files);
 | 
											
												
													
														|  | 
 |  | +  } else {
 | 
											
												
													
														|  | 
 |  | +    throw new Error("Invalid export type");
 | 
											
												
													
														|  | 
 |  | +  }
 | 
											
												
													
														|  | 
 |  | +};
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  |  export { serializeAsJSON, serializeLibraryAsJSON } from "../data/json";
 |  |  export { serializeAsJSON, serializeLibraryAsJSON } from "../data/json";
 | 
											
												
													
														|  |  export { loadFromBlob, loadLibraryFromBlob } from "../data/blob";
 |  |  export { loadFromBlob, loadLibraryFromBlob } from "../data/blob";
 | 
											
												
													
														|  |  export { getFreeDrawSvgPath } from "../renderer/renderElement";
 |  |  export { getFreeDrawSvgPath } from "../renderer/renderElement";
 |