UNPKG

geoiq-frontend-ui-kit

Version:

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

68 lines (67 loc) 2.03 kB
import k, { useRef as c, useState as y, useEffect as f } from "react"; import { createRoot as I } from "./index132.es.js"; import { ImageEditorModal as w } from "./index133.es.js"; import { notifyNativeImageEditorState as m } from "./index134.es.js"; import U from "./index135.es.js"; function A(u) { const s = c(u); s.current = u; const n = c(null), [p, v] = y(null), [d, g] = y(!1); if (!n.current && typeof window < "u") { const e = s.current; n.current = U.create({ ...e, image: e.image ?? e.backgroundImage, onSave: async (t, o) => { const a = s.current; if (a.onAssetUpload) { const R = t.type === "image/jpeg" ? "jpg" : "png", E = new File([t.blob], `edit.${R}`, { type: t.type }), b = await a.onAssetUpload(E); a.onSave({ ...t, ...b }, o); return; } a.onSave(t, o); }, onUiChange: v }); } f(() => { const e = n.current; if (!e) return; const t = () => { g(!0), m(!0); }, o = () => { g(!1), m(!1); }; return e.on("open", t), e.on("close", o), () => { e.off("open", t), e.off("close", o), m(!1), e.destroy(); }; }, []); const l = (u.stickers ?? []).join(" "), S = c(null); f(() => { const e = n.current; !e || S.current === l || (S.current = l, e.setStickers(u.stickers ?? [])); }, [l]); const i = c(null), r = c(null); return f(() => () => { i.current?.unmount(), r.current?.remove(), i.current = null, r.current = null; }, []), f(() => { const e = n.current; e && (r.current || (r.current = document.createElement("div"), document.body.appendChild(r.current), i.current = I(r.current)), i.current.render( /* @__PURE__ */ k.createElement( w, { engine: e, ui: p, isOpen: d, saveLabel: s.current.saveLabel || "Save" } ) )); }, [p, d]), n.current; } export { A as useImageEditor }; //# sourceMappingURL=index45.es.js.map