@glodon-aiot/react-components
Version:
aiot react components
71 lines (70 loc) • 1.73 kB
JavaScript
import { GAP_SIZE_H as n, GAP_SIZE_V as u, ON_RIGHT as f, ON_LEFT as a, ON_BOTTOM as h, ON_TOP as g } from "./constant.mjs";
const c = (t) => {
const r = t || window.event, e = t.target || t.srcElement;
if (r.offsetX)
return r.offsetX;
{
const s = e.getBoundingClientRect();
return r.clientX - s.left;
}
}, O = (t) => {
const r = t || window.event, e = t.target || t.srcElement;
if (r.offsetY)
return r.offsetY;
{
const s = e.getBoundingClientRect();
return r.clientY - s.top;
}
}, w = (t) => {
const r = t.split("-");
let e = r.length > 1 || r[0] === "left" || r[0] === "right" ? r[0] : "center", s = r.length > 1 ? r[1] : r[0] === "top" || r[0] === "bottom" ? r[0] : "middle";
return [e, s];
}, m = (t, r, e = [n, u]) => {
const s = () => {
switch (t[0]) {
case "left":
return a;
case "right":
return f;
default:
return 0;
}
}, i = () => {
switch (t[1]) {
case "top":
return g;
case "bottom":
return h;
default:
return 0;
}
}, l = () => {
switch (t[0]) {
case "left":
return -((r == null ? void 0 : r.width) || 0) - e[0] - 2;
case "right":
return 0;
default:
return -((r == null ? void 0 : r.width) || 0) / 2;
}
}, o = () => {
switch (t[1]) {
case "top":
return -e[1] - 2;
case "bottom":
return (r == null ? void 0 : r.height) || 0;
default:
return ((r == null ? void 0 : r.height) || 0) / 2;
}
};
return {
x: e[0] * s() + l(),
y: e[1] * i() + o()
};
};
export {
c as getOffsetX,
O as getOffsetY,
m as getPlacementPosition,
w as placementStringToArr
};