@jianghh/canvas-graffiti
Version:
canvas涂鸦库,支持手写、笔写、鼠标,选中元素,并且移动、删除等功能。集成撤销重做操作。
2 lines (1 loc) • 1.48 kB
JavaScript
"use strict";var h=Object.defineProperty;var r=(i,t,e)=>t in i?h(i,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):i[t]=e;var l=(i,t,e)=>(r(i,typeof t!="symbol"?t+"":t,e),e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("../utils/index.js");class a{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 e in t)e==="tool"?this.tool=t.tool:e==="points"?this.points=t.points:e==="shadowColor"?this.shadowColor=t.shadowColor:e==="strokeStyle"?this.strokeStyle=t.strokeStyle:e==="fillStyle"?this.fillStyle=t.fillStyle:this[e]=t[e];this.width=this.right-this.left,this.height=this.bottom-this.top}moveEle(t,e){this.left=o.roundToNDecimalPlaces(this.left+t),this.right=o.roundToNDecimalPlaces(this.right+t),this.top=o.roundToNDecimalPlaces(this.top+e),this.bottom=o.roundToNDecimalPlaces(this.bottom+e),this.points=this.points.map(s=>({x:o.roundToNDecimalPlaces(s.x+t),y:o.roundToNDecimalPlaces(s.y+e)}))}deleteEle(){this.isDeleted=!0}}function n(i,t){return!(t.left>i.right||t.right<i.left||t.top>i.bottom||t.bottom<i.top)}function c(i,t){return{left:Math.min(i.x,t.x),top:Math.min(i.y,t.y),right:Math.max(i.x,t.x),bottom:Math.max(i.y,t.y)}}exports.GraffitiEle=a;exports.genRectByTwoPoint=c;exports.isRectIntersect=n;