UNPKG

geoiq-frontend-ui-kit

Version:

This project is a UI kit for GeoIQ's frontend. It's built with React, TypeScript, and Vite.

75 lines (74 loc) 1.94 kB
import { useCallback as x } from "react"; import o from "konva"; const S = ({ transformerRef: r, setEditorState: g, onAssetUpload: s }) => ({ handleDownload: x(async () => { g((t) => ({ ...t, isDrawingMode: !1 })); try { const t = r.current?.getStage(); if (!t) { console.error("Stage not found."); return; } r.current?.nodes([]), t.batchDraw(); const u = new o.Stage({ container: document.createElement("div"), width: t.width(), height: t.height() }), c = new o.Layer(); u.add(c); const i = t.findOne("Group"); if (!i) { console.error("Main group not found"); return; } const n = i.clone({ x: 0, y: 0, scaleX: 1, scaleY: 1, rotation: 0 }); n.children?.forEach((e) => { if (e.getClassName() === "Image" && e === i.findOne("Image")) return; const p = e.getAbsolutePosition(), b = e.getAbsoluteRotation(); e.x(p.x), e.y(p.y), e.rotation(b), e.scaleX(1), e.scaleY(1); }), c.add(n), c.draw(); const a = n.getClientRect(), d = new o.Stage({ container: document.createElement("div"), width: a.width, height: a.height }), l = new o.Layer(); d.add(l); const w = new o.Group({ x: -a.x, y: -a.y }); w.add(n.clone()), l.add(w), l.draw(); const m = d.toDataURL({ mimeType: "image/png", quality: 1, pixelRatio: 2 }); u.destroy(), d.destroy(); const y = await fetch(m).then((e) => e.blob()), h = new File([y], "canvas-export.png", { type: "image/png" }); if (s) return await s(h); } catch (t) { throw console.error("Download failed:", t), t; } }, [r, g, s]) }); export { S as useDownloadHandlers }; //# sourceMappingURL=index.es91.js.map