geoiq-frontend-ui-kit
Version:
This project is a UI kit for GeoIQ's frontend. It's built with React, TypeScript, and Vite.
148 lines (147 loc) • 5.57 kB
JavaScript
import { supportsContextFilter as v, rasterizeWithFilter as C } from "./index162.es.js";
import { syncCanvasSize as m, render as g, baseFilter as p, paintLayer as w } from "./index152.es.js";
import { emit as l, emitChange as f, getState as y, resetAdjValues as S } from "./index151.es.js";
import { loadStickerImage as I } from "./index157.es.js";
function L(e) {
const n = (e.type || "").toLowerCase();
if (n === "image/heic" || n === "image/heif") return !0;
const i = e instanceof File ? e.name.toLowerCase() : "";
return i.endsWith(".heic") || i.endsWith(".heif");
}
function d(e, n) {
n(URL.createObjectURL(e));
}
function h(e, n) {
import("heic2any").then(
({ default: i }) => i({ blob: e, toType: "image/jpeg", quality: 0.8 })
).then(
(i) => d(Array.isArray(i) ? i[0] : i, n)
).catch(() => d(e, n));
}
function B(e, n, i) {
if (e.isLoadingImage = !0, e.notify(), !n) {
i(null);
return;
}
if (n instanceof HTMLCanvasElement) {
i(n.toDataURL());
return;
}
if (typeof Blob < "u" && (n instanceof Blob || n instanceof File)) {
if (L(n)) {
if (typeof createImageBitmap == "function") {
createImageBitmap(n).then((r) => {
r.close(), d(n, i);
}).catch(() => h(n, i));
return;
}
h(n, i);
return;
}
d(n, i);
return;
}
i(n);
}
function T(e, n) {
const i = () => {
typeof n == "string" && n.startsWith("blob:") && URL.revokeObjectURL(n);
}, r = new Image();
r.crossOrigin = "anonymous", r.onload = () => {
let o = r.naturalWidth, a = r.naturalHeight;
const c = 2e3;
if (Math.max(o, a) > c) {
const t = c / Math.max(o, a);
o = Math.round(o * t), a = Math.round(a * t);
}
e.sourceCanvas.width = o, e.sourceCanvas.height = a, e.sourceCanvas.getContext("2d").drawImage(r, 0, 0, o, a), e.originalCanvas = document.createElement("canvas"), e.originalCanvas.width = o, e.originalCanvas.height = a, e.originalCanvas.getContext("2d").drawImage(e.sourceCanvas, 0, 0), i(), e.layers = [], e.selectedId = null, e.undoStack = [], e.redoStack = [], e.zoom = 1, S(e), e.mounted && m(e), g(e), e.mode = "select", e.isLoadingImage = !1, e.statusText = "Image loaded", l(e, "load", { width: o, height: a }), f(e);
}, r.onerror = () => {
i(), e.isLoadingImage = !1, e.statusText = "Could not load that image (CORS?)", console.warn(
"[ImageEditor] Failed to load image (likely a CORS issue on the source URL). Reset stays disabled since there is nothing to revert to.",
typeof n == "string" ? n.slice(0, 80) : n
), e.notify();
}, r.src = n;
}
function F(e, n) {
if (!n || !n.image) return;
const i = new Image();
i.onload = () => {
e.sourceCanvas.width = n.width || i.naturalWidth, e.sourceCanvas.height = n.height || i.naturalHeight, e.sourceCanvas.getContext("2d").drawImage(i, 0, 0, e.sourceCanvas.width, e.sourceCanvas.height), e.originalCanvas = document.createElement("canvas"), e.originalCanvas.width = e.sourceCanvas.width, e.originalCanvas.height = e.sourceCanvas.height, e.originalCanvas.getContext("2d").drawImage(i, 0, 0, e.sourceCanvas.width, e.sourceCanvas.height), e.layers = JSON.parse(JSON.stringify(n.layers || [])), e.layers.forEach((o) => {
o.id >= e.nextId && (e.nextId = o.id + 1);
}), Object.assign(e.adj, n.adjustments || {}), e.selectedId = null, e.undoStack = [], e.redoStack = [], e.zoom = 1, e.mounted && m(e), g(e), e.mode = "select", e.statusText = "State restored", l(e, "load", { restored: !0 }), f(e);
const r = [
...new Set(
e.layers.filter((o) => o.type === "sticker").map((o) => o.src)
)
];
r.length && Promise.all(
r.map((o) => I(e, o).catch(() => {
}))
).then(() => g(e));
}, i.src = n.image;
}
async function x(e) {
const n = document.createElement("canvas");
n.width = e.sourceCanvas.width, n.height = e.sourceCanvas.height;
const i = n.getContext("2d"), r = p(e);
if (v())
i.filter = r, i.drawImage(e.sourceCanvas, 0, 0), i.filter = "none";
else
try {
const o = await C(e.sourceCanvas, r);
i.drawImage(o, 0, 0);
} catch {
i.drawImage(e.sourceCanvas, 0, 0);
}
return e.layers.forEach((o) => {
o._editing || w(e, i, o);
}), n;
}
function k(e, n, i, r) {
const o = n.toDataURL(r), a = {
blob: i,
dataURL: o,
canvas: n,
width: n.width,
height: n.height,
type: i && i.type || r || "image/png",
state: y(e),
getBlob: (c, t) => new Promise((u) => n.toBlob((s) => u(s), c || "image/png", t)),
download: (c) => {
const t = URL.createObjectURL(i), u = document.createElement("a");
return u.href = t, u.download = c || "picture-studio.png", u.click(), setTimeout(() => URL.revokeObjectURL(t), 1e3), a;
}
};
return a;
}
function O(e, n, i) {
return x(e).then(
(r) => new Promise((o) => {
r.toBlob(
(a) => o(k(e, r, a, n || "image/png")),
n || "image/png",
i
);
})
);
}
function M(e, n) {
if (!e.isSaving)
return e.isSaving = !0, e.notify(), O(e, "image/jpeg", 0.92).then((i) => {
l(e, "save", i);
const r = typeof e.config.onSave == "function" ? e.config.onSave(i, n) : void 0;
return Promise.resolve(r).finally(() => {
e.isSaving = !1, e.notify(), e.config.keepOpenOnSave || n.close();
});
}).catch(() => {
e.isSaving = !1, e.notify();
});
}
export {
T as doLoadImage,
M as doSave,
F as loadState,
B as normalizeSource,
O as produce
};
//# sourceMappingURL=index159.es.js.map