geoiq-frontend-ui-kit
Version:
This project is a UI kit for GeoIQ's frontend. It's built with React, TypeScript, and Vite.
119 lines (118 loc) • 3.55 kB
JavaScript
const C = (n, h, o) => {
const s = -h.bgRotation * (Math.PI / 180), i = o.width / 2, e = o.height / 2, g = n.x - i, d = n.y - e, w = Math.cos(s), a = Math.sin(s);
return {
x: g * w - d * a + i,
y: g * a + d * w + e
};
}, S = (n, h, o) => {
const { bgImagePosition: s, bgImageSize: i } = o;
return n >= s.x && n <= s.x + i.width && h >= s.y && h <= s.y + i.height;
}, P = (n, h, o, s, i) => {
if (!i.width || !i.height) return !0;
const e = n + o, g = h + s, d = i.x + i.width, w = i.y + i.height;
return n < d && e > i.x && h < w && g > i.y;
}, b = (n, h, o) => new Promise((s, i) => {
if (!h.bgImage || n.width === 0 || n.height === 0) {
i(new Error("Invalid crop parameters"));
return;
}
const e = document.createElement("canvas");
e.width = n.width, e.height = n.height;
const g = e.getContext("2d");
if (!g) {
i(new Error("Could not get canvas context"));
return;
}
const d = h.bgImage.width / o.bgImageSize.width, w = h.bgImage.height / o.bgImageSize.height, a = (n.x - o.bgImagePosition.x) * d, m = (n.y - o.bgImagePosition.y) * w, I = n.width * d, x = n.height * w;
g.drawImage(
h.bgImage,
a,
m,
I,
x,
0,
0,
e.width,
e.height
);
const f = new window.Image();
f.src = e.toDataURL("image/png"), f.onload = () => {
const Y = n.width / n.height;
let t = o.originalBgSize.width, r = o.originalBgSize.width / Y;
r > o.originalBgSize.height && (r = o.originalBgSize.height, t = o.originalBgSize.height * Y), s({
croppedImage: f,
newWidth: t,
newHeight: r,
scaleX: t / n.width,
scaleY: r / n.height
});
}, f.onerror = () => {
i(new Error("Failed to load cropped image"));
};
}), A = (n, h, o, s, i, e, g, d) => {
const w = Math.cos(s), a = Math.sin(s), m = i.width / 2, I = i.height / 2, x = d.squares.filter(
(t) => P(
t.x,
t.y,
t.width,
t.height,
n
)
).map((t) => {
const r = t.x - m, l = t.y - I, y = r * w - l * a, u = r * a + l * w, c = y - (n.x - m), z = u - (n.y - I);
return {
...t,
x: c * h + (i.width - e) / 2 + e / 2,
y: z * o + (i.height - g) / 2 + g / 2,
width: t.width * h,
height: t.height * o
};
}), f = d.textBoxes.filter(
(t) => P(
t.x,
t.y,
t.width,
t.fontSize * 1.5,
n
)
).map((t) => {
const r = t.x - m, l = t.y - I, y = r * w - l * a, u = r * a + l * w, c = y - (n.x - m), z = u - (n.y - I);
return {
...t,
x: c * h + (i.width - e) / 2 + e / 2,
y: z * o + (i.height - g) / 2 + g / 2,
width: t.width * h,
fontSize: t.fontSize * Math.min(h, o)
};
}), Y = d.lines.filter((t) => {
for (let r = 0; r < t.points.length; r += 2) {
const l = t.points[r], y = t.points[r + 1];
if (P(l, y, 1, 1, n))
return !0;
}
return !1;
}).map((t) => {
const r = t.points.map((l, y) => {
const u = l - m, c = t.points[y + 1] - I, z = u * w - c * a, X = u * a + c * w, M = z - (n.x - m), p = X - (n.y - I);
return y % 2 === 0 ? M * h + (i.width - e) / 2 + e / 2 : p * o + (i.height - g) / 2 + g / 2;
});
return {
...t,
points: r,
strokeWidth: t.strokeWidth * Math.min(h, o)
};
});
return {
newSquares: x,
newTextBoxes: f,
newLines: Y
};
};
export {
b as applyCrop,
C as getRotatedPointerPosition,
P as isElementInCropArea,
S as isPointInImage,
A as transformElementsAfterCrop
};
//# sourceMappingURL=index.es139.js.map