-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpalette.min.js
4 lines (4 loc) · 4.29 KB
/
palette.min.js
1
2
3
4
// palette.js v3.1.0
// Copyright (c) 2013 – 2022 Daniele Veneroni. All rights reserved.
// Licensed under the MIT License (X11 License)
!function(){"use strict";function t(t,e){t instanceof HTMLCanvasElement?this.canvas=t:this.canvas=document.querySelector(t),this.context=this.canvas.getContext("2d",e),this.width=this.canvas.width,this.height=this.canvas.height}t.prototype.size=function(t,e){this.width=t,this.height=e;const o=this.canvas,i=this.context,s=window.devicePixelRatio;return s>1?(o.style.width=t+"px",o.style.height=e+"px",o.width=t*s,o.height=e*s,i.setTransform(s,0,0,s,0,0)):(o.width=t,o.height=e),this},t.prototype.clear=function(t){const e=this.context;return t?e.clearRect(t.x,t.y,t.width,t.height):e.clearRect(0,0,this.canvas.width,this.canvas.height),this},t.prototype.style=function(t){const e=this.context;if(t.fill&&(e.fillStyle=t.fill),t.shadow){const o=t.shadow.split(" ");e.shadowOffsetX=parseInt(o[0],10),e.shadowOffsetY=parseInt(o[1],10),e.shadowBlur=parseInt(o[2],10),e.shadowColor=o[3]}return t.stroke&&(e.strokeStyle=t.stroke),t.cap&&(e.lineCap=t.cap),t.join&&(e.lineJoin=t.join),t.thickness&&(e.lineWidth=t.thickness),t.miterLimit&&(e.miterLimit=t.miterLimit),t.alpha&&(e.globalAlpha=t.alpha),t.composite&&(e.globalCompositeOperation=t.composite),this},t.prototype.image=function(t){const e=this.context,o=new Image;return o.onload=function(){t.width&&t.height?e.drawImage(o,t.x,t.y,t.width,t.height):e.drawImage(o,t.x,t.y)},o.src=t.src,this},t.prototype.text=function(t){const e=this.context;return e.save(),this.style(t),t.font&&(e.font=t.font),t.align&&(e.textAlign=t.align),t.baseline&&(e.textBaseline=t.baseline),t.direction&&(e.direction=t.direction),t.stroke?e.strokeText(t.text,t.x,t.y):e.fillText(t.text,t.x,t.y),e.restore(),this},t.prototype.line=function(t){const e=this.context;return e.save(),this.style(t),e.beginPath(),e.moveTo(t.x1,t.y1),e.lineTo(t.x2,t.y2),e.closePath(),e.stroke(),e.restore(),this},t.prototype.rect=function(t){const e=this.context;e.save(),this.style(t);const o=void 0!==t.degree?t.degree*Math.PI/180:null;if(o){const i=t.x+t.width/2,s=t.y+t.height/2;e.translate(i,s),e.rotate(o),e.translate(-i,-s)}return e.beginPath(),e.rect(t.x,t.y,t.width,t.height),e.closePath(),t.fill&&e.fill(),t.stroke&&e.stroke(),e.restore(),this},t.prototype.circle=function(t){const e=this.context;return e.save(),this.style(t),e.beginPath(),e.arc(t.x,t.y,t.r,0,2*Math.PI),e.closePath(),t.fill&&e.fill(),t.stroke&&e.stroke(),e.restore(),this},t.prototype.arc=function(t){const e=this.context;return e.save(),this.style(t),e.beginPath(),e.arc(t.x,t.y,t.r,t.start,t.stop),e.closePath(),t.fill&&e.fill(),t.stroke&&e.stroke(),e.restore(),this},t.prototype.polygon=function(t){const e=this.context;e.save(),this.style(t);const o=void 0!==t.degree?t.degree*Math.PI/180:0;e.translate(t.x,t.y),e.rotate(o),e.beginPath(),e.moveTo(t.size*Math.cos(0),t.size*Math.sin(0));for(let o=1;o<=t.sides;++o)e.lineTo(t.size*Math.cos(2*o*Math.PI/t.sides),t.size*Math.sin(2*o*Math.PI/t.sides));return e.closePath(),t.fill&&e.fill(),t.stroke&&e.stroke(),e.restore(),this},t.prototype.path=function(t){const e=this.context;return e.save(),this.style(t),e.beginPath(),t.path.split(" ").forEach(function(t){const o=t.split(",");"m"===o[0]||"M"===o[0]?e.moveTo(o[1],o[2]):"l"===o[0]||"L"===o[0]?e.lineTo(o[1],o[2]):"q"!==o[0]&&"Q"!==o[0]||e.quadraticCurveTo(o[1],o[2],o[3],o[4])}),e.closePath(),t.fill&&e.fill(),t.stroke&&e.stroke(),e.restore(),this},t.prototype.conic_gradient=function(t){const e=this.context.createConicGradient(t.degree*Math.PI/180,t.x,t.y);return t.stops.split(" ").forEach(function(t){const o=t.split(",");e.addColorStop(parseFloat(o[0]),o[1])}),e},t.prototype.linear_gradient=function(t){const e=this.context.createLinearGradient(t.x1,t.y1,t.x2,t.y2);return t.stops.split(" ").forEach(function(t){const o=t.split(",");e.addColorStop(parseFloat(o[0]),o[1])}),e},t.prototype.radial_gradient=function(t){const e=this.context.createRadialGradient(t.x1,t.y1,t.r1,t.x2,t.y2,t.r2);return t.stops.split(" ").forEach(function(t){const o=t.split(",");e.addColorStop(parseFloat(o[0]),o[1])}),e},t.prototype.toDataURL=function(t){const e=(t=t||{}).type||"image/png",o=t.quality||1;return this.canvas.toDataURL(e,o)},t.prototype.toBlob=function(t,e){const o=(t=t||{}).type||"image/png",i=t.quality||1;return this.canvas.toBlob(e,o,i)},window.Palette=t}();