@jianghh/canvas-graffiti
Version:
canvas涂鸦库,支持手写、笔写、鼠标,选中元素,并且移动、删除等功能。集成撤销重做操作。
51 lines (50 loc) • 1.69 kB
JavaScript
var s = Object.defineProperty;
var r = (e, t, i) => t in e ? s(e, t, { enumerable: !0, configurable: !0, writable: !0, value: i }) : e[t] = i;
var l = (e, t, i) => (r(e, typeof t != "symbol" ? t + "" : t, i), i);
import { roundToNDecimalPlaces as o } from "../utils/index.js";
class y {
constructor(t) {
l(this, "tool");
l(this, "left");
l(this, "top");
l(this, "right");
l(this, "bottom");
l(this, "width");
l(this, "height");
l(this, "points");
l(this, "lineWidth");
l(this, "shadowBlur");
l(this, "shadowColor");
l(this, "strokeStyle");
l(this, "fillStyle");
l(this, "isDeleted", !1);
for (let i in t)
i === "tool" ? this.tool = t.tool : i === "points" ? this.points = t.points : i === "shadowColor" ? this.shadowColor = t.shadowColor : i === "strokeStyle" ? this.strokeStyle = t.strokeStyle : i === "fillStyle" ? this.fillStyle = t.fillStyle : this[i] = t[i];
this.width = this.right - this.left, this.height = this.bottom - this.top;
}
moveEle(t, i) {
this.left = o(this.left + t), this.right = o(this.right + t), this.top = o(this.top + i), this.bottom = o(this.bottom + i), this.points = this.points.map((h) => ({ x: o(h.x + t), y: o(h.y + i) }));
}
// moveFinish() {
// return deepClone(this)
// }
deleteEle() {
this.isDeleted = !0;
}
}
function f(e, t) {
return !(t.left > e.right || t.right < e.left || t.top > e.bottom || t.bottom < e.top);
}
function n(e, t) {
return {
left: Math.min(e.x, t.x),
top: Math.min(e.y, t.y),
right: Math.max(e.x, t.x),
bottom: Math.max(e.y, t.y)
};
}
export {
y as GraffitiEle,
n as genRectByTwoPoint,
f as isRectIntersect
};