UNPKG

sign-pad

Version:

sign-pad web component provides a signature drawing surface and related services

1 lines 1.02 kB
export{t as roundTo,e as extractSvgRawData,c as svgToCanvas};function t(t,e=2){const c=Math.pow(10,e);return Math.floor(t*c+Number.EPSILON)/c}function e(t){const e={hops:[],fullRect:{},drawRect:{}};for(const c of t.children)"path"===c.localName&&e.hops.push(c.cloneNode());const c=t.getBoundingClientRect();e.fullRect.x=0,e.fullRect.y=0,e.fullRect.w=c.width,e.fullRect.h=c.height;const l=t.getBBox();return e.drawRect.x=Math.floor(l.x),e.drawRect.y=Math.floor(l.y),e.drawRect.w=Math.ceil(l.width)+1,e.drawRect.h=Math.ceil(l.height)+1,e}function c(t,e,c,l){let o=document.createElement("canvas");o.width=t.fullRect.w,o.height=t.fullRect.h;let a=o.getContext("2d");a.fillStyle=c,a.fillRect(0,0,t.fullRect.w,t.fullRect.h),a.fillStyle=e;for(const e of t.hops){const t=new Path2D(e.getAttribute("d"));a.fill(t)}if(l){const e=a.getImageData(t.drawRect.x,t.drawRect.y,t.drawRect.w,t.drawRect.h);(o=document.createElement("canvas")).width=t.drawRect.w,o.height=t.drawRect.h,(a=o.getContext("2d")).putImageData(e,0,0)}return o}