-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProcessingCanvas.min.js
1 lines (1 loc) · 6.38 KB
/
ProcessingCanvas.min.js
1
var t={d:(i,e)=>{for(var s in e)t.o(e,s)&&!t.o(i,s)&&Object.defineProperty(i,s,{enumerable:!0,get:e[s]})},o:(t,i)=>Object.prototype.hasOwnProperty.call(t,i)},i={};function e(t,i,s,h){if(!isNaN(i)&&!isNaN(s))return isNaN(h)?`rgb(${t},${i},${s})`:`rgba(${t},${i},${s},${Number.isInteger(h)?h/255:h})`;if("number"==typeof t)return"#"+Number(t).toString(16).padStart(6,"0");if("string"==typeof t){if(!t.startsWith("#"))return parseInt(t)?e(parseInt(t)):t;switch(t.length){case 4:case 5:return"#"+t[1]+t[1]+t[2]+t[2]+t[3]+t[3]+(5==t.length?t[4]+t[4]:"");case 7:case 9:return t;default:return"#000000"}}}t.d(i,{A:()=>s});class s{constructor(t,i=window.devicePixelRatio,e=null){this.cv=t,this.cx=t.getContext("2d"),this.#t=i,this.#i=e||((t,i)=>(t*=this.#t,i*=this.#t,t<0&&(t=this.cv.width-t),i<0&&(i=this.cv.height-i),[t,i])),this.setDefaults()}setDefaults(){let t=this.cx;t.fillStyle="white",t.strokeStyle="black",t.lineWidth=this.#t,t.lineCap="round",t.lineJoin="miter",t.textBaseline="alphabetic",t.textAlign="left",t.font=Math.round(20*this.#t)+"px Arial",this.#e=this.#s(),this.#h=[]}width(){return Math.round(this.#r()[0]/this.#t)}height(){return Math.round(this.#r()[1]/this.#t)}scale(){return this.#t}size(t,i){let e={};["fillStyle","strokeStyle","lineWidth","lineCap","lineJoin","textBaseline","textAlign","font"].forEach((t=>e[t]=this.cx[t])),this.cv.width=t*this.#t,this.cv.height=i*this.#t;for(let t in e)this.cx[t]=e[t];this.cv.style.width=t+"px",this.cv.style.height=i+"px"}clip(t,i,e,s){this.#e.x0=t*this.#t,this.#e.y0=i*this.#t,this.#e.w=e*this.#t,this.#e.h=s*this.#t,this.cx.beginPath(),this.cx.rect(this.#e.x0,this.#e.y0,...this.#r()),this.cx.clip()}unclip(){this.clip(0,0,0,0)}clear(t,i,e,s){isNaN(t)?this.cx.clearRect(this.#e.x0,this.#e.y0,...this.#r()):this.cx.clearRect(...this.#c(t,i),e*this.#t,s*this.#t)}rotate(t){this.cx.rotate(t)}translate(t,i){this.cx.translate(...this.#c(t,i))}push(){this.cx.save(),this.#h.push(this.#e)}pop(){this.cx.restore(),this.#h.length&&(this.#e=this.#h.pop())}beginShape(){this.#e.shapeF=1,this.cx.beginPath()}endShape(t=!1){t&&this.cx.closePath(),this.#a()}vertex(t,i){this.#e.shapeF?(this.#e.shapeF=0,this.cx.moveTo(...this.#c(t,i))):this.cx.lineTo(...this.#c(t,i))}background(t,i,s,h){let r=this.cx.fillStyle;this.cx.fillStyle=e(t,i,s,h),this.cx.fillRect(this.#e.x0,this.#e.y0,...this.#r()),this.cx.fillStyle=r}fill(t,i,s,h){this.#e.fillF=1,this.cx.fillStyle=e(t,i,s,h)}noFill(){this.#e.fillF=0}stroke(t,i,s,h){this.#e.strokeF=1,this.cx.strokeStyle=e(t,i,s,h)}noStroke(){this.#e.strokeF=0}strokeWeight(t){this.cx.lineWidth=t*this.#t}strokeJoin(t){this.cx.lineJoin=(()=>{switch(t){case"MITER":return"miter";case"BEVEL":return"bevel";case"ROUND":return"round"}return"miter"})()}strokeCap(t){this.cx.lineCap=(()=>{switch(t){case"ROUND":return"round";case"SQUARE":return"butt";case"PROJECT":return"square"}return"round"})()}rectMode(t){this.#e.rectMode=t}ellipseMode(t){this.#e.elMode=t}imageMode(t){this.#e.imgMode=t}textFont(t){this.cx.font=this.cx.font.split("px ")[0]+"px "+t}textSize(t){this.cx.font=Math.round(t*this.#t)+"px "+this.cx.font.split("px ")[1]}textAlign(t,i){t&&(this.cx.textAlign=(()=>{switch(t){case"LEFT":return"left";case"CENTER":return"center";case"RIGHT":return"right"}return"left"})()),i&&(this.cx.textBaseline=(()=>{switch(i){case"BASELINE":return"alphabetic";case"TOP":return"top";case"BOTTOM":return"bottom";case"CENTER":return"middle"}return"alphabetic"})())}textWidth(t){return this.textBounds(t).width}textHeight(t){return this.textBounds(t).height}textBounds(t){let i=this.cx.measureText(t);return{width:(i.actualBoundingBoxRight+i.actualBoundingBoxLeft)/this.#t,height:(i.actualBoundingBoxDescent+i.actualBoundingBoxAscent)/this.#t}}text(t,i,e){this.#e.fillF&&this.cx.fillText(t,...this.#c(i,e)),this.#e.strokeF&&this.cx.strokeText(t,...this.#c(i,e))}point(t,i){this.cx.beginPath(),this.cx.fillRect(...this.#c(t,i),this.#t,this.#t)}line(t,i,e,s){this.#e.strokeF&&(this.cx.beginPath(),this.cx.moveTo(...this.#c(t,i)),this.cx.lineTo(...this.#c(e,s)),this.cx.stroke())}rect(t,i,e,s,...h){this.cx.beginPath();let r=this.#c(t,i),c=[e*this.#t,s*this.#t];switch(this.#e.rectMode){case"CENTER":r=[r[0]-c[0]/2,r[1]-c[1]/2];break;case"RADIUS":r=[r[0]-c[0],r[1]-c[1]],c=[2*c[0],2*c[1]];break;case"CORNERS":let t=this.#c(e,s);c=[t[0]-r[0],t[1]-r[1]]}if(h[0]){let t=[h[0]*this.#t];isNaN(h[3])||(t=t.concat([h[1]*this.#t,h[2]*this.#t,h[3]*this.#t])),this.cx.roundRect(r[0],r[1],c[0],c[1],t),this.#a()}else this.#e.fillF&&this.cx.fillRect(r[0],r[1],c[0],c[1]),this.#e.strokeF&&this.cx.strokeRect(r[0],r[1],c[0],c[1])}square(t,i,e){this.rect(t,i,e,e)}arc(t,i,e,s,h,r){this.cx.beginPath(),this.cx.ellipse(...this.#c(t,i),e*this.#t,s*this.#t,0,h,r),this.#a()}ellipse(t,i,e,s){this.#o(t,i,e,s)}circle(t,i,e){this.#o(t,i,e,e)}bezier(t,i,e,s,h,r,c,a){this.#e.strokeF&&(this.cx.beginPath(),this.cx.moveTo(...this.#c(t,i)),this.cx.bezierCurveTo(...this.#c(e,s),...this.#c(h,r),...this.#c(c,a)),this.cx.stroke())}triangle(t,i,e,s,h,r){this.polygon(t,i,e,s,h,r)}quad(t,i,e,s,h,r,c,a){this.polygon(t,i,e,s,h,r,c,a)}polygon(...t){this.cx.beginPath(),this.cx.moveTo(...this.#c(t[0],t[1]));for(let i=2;i<t.length;i+=2)this.cx.lineTo(...this.#c(t[i],t[i+1]));this.cx.closePath(),this.#a()}bezierVertex(t,i,e,s,h,r){this.#e.shapeF&&(this.#e.shapeF=0,this.cx.moveTo(...this.#c(h,r))),this.cx.bezierCurveTo(...this.#c(t,i),...this.#c(e,s),...this.#c(h,r))}image(t,i,e,s,h){let r=this.#c(i,e);switch(isNaN(s)?s=t.width*this.#t:s*=this.#t,isNaN(h)?h=s*t.height/t.width:h*=this.#t,this.#e.imgMode){case"CORNER":this.cx.drawImage(t,...r,s,h);break;case"CORNERS":this.cx.drawImage(t,...r,s-r[0],h-r[1]);break;case"CENTER":this.cx.drawImage(t,r[0]-s/2,r[1]-h/2,s,h)}}async loadImage(t){return new Promise((i=>{let e=new Image;e.src=t,e.onerror=()=>i(null),e.onload=()=>i(e)}))}#e=this.#s();#t;#i;#h=[];#c(t,i){let e=this.#i(t,i);return[e[0]+this.#e.x0,e[1]+this.#e.y0]}#r(){return[this.#e.w?this.#e.w:this.cv.width,this.#e.h?this.#e.h:this.cv.height]}#o(t,i,e,s){this.cx.beginPath();let h=this.#c(t,i),r=[e*this.#t/2,s*this.#t/2];switch(this.#e.elMode){case"RADIUS":r=[2*r[0],2*r[1]];break;case"CORNER":h=[h[0]+r[0],h[1]+r[1]];break;case"CORNERS":let t=this.#c(e,s);r=[(t[0]-h[0])/2,(t[1]-h[1])/2],h=[h[0]+r[0],h[1]+r[1]]}this.cx.ellipse(h[0],h[1],r[0],r[1],0,0,2*Math.PI),this.#a()}#a(){this.#e.fillF&&this.cx.fill(),this.#e.strokeF&&this.cx.stroke()}#s(){return{fillF:1,strokeF:1,shapeF:0,elMode:"CENTER",rectMode:"CORNER",imgMode:"CORNER",x0:0,y0:0,w:0,h:0}}}var h=i.A;export{h as default};