tldraw
Version:
A tiny little drawing editor.
64 lines (63 loc) • 2.23 kB
JavaScript
;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var export_exports = {};
__export(export_exports, {
exportToImagePromiseForClipboard: () => exportToImagePromiseForClipboard,
exportToString: () => exportToString
});
module.exports = __toCommonJS(export_exports);
var import_editor = require("@tldraw/editor");
async function getSvgString(editor, ids, opts) {
const svg = await editor.getSvgString(ids, opts);
if (!svg) {
throw new Error("Could not construct SVG.");
}
return svg;
}
async function exportToString(editor, ids, format, opts = {}) {
switch (format) {
case "svg": {
return (await getSvgString(editor, ids, opts))?.svg;
}
case "json": {
const data = await editor.resolveAssetsInContent(editor.getContentFromCurrentPage(ids));
return JSON.stringify(data);
}
default: {
(0, import_editor.exhaustiveSwitchError)(format);
}
}
}
const clipboardMimeTypesByFormat = {
jpeg: "image/jpeg",
png: "image/png",
webp: "image/webp",
svg: "text/plain"
};
function exportToImagePromiseForClipboard(editor, ids, opts = {}) {
const idsToUse = ids?.length ? ids : [...editor.getCurrentPageShapeIds()];
const format = opts.format ?? "png";
return {
blobPromise: editor.toImage(idsToUse, opts).then(
(result) => import_editor.FileHelpers.rewriteMimeType(result.blob, clipboardMimeTypesByFormat[format])
),
mimeType: clipboardMimeTypesByFormat[format]
};
}
//# sourceMappingURL=export.js.map