UNPKG

@litecanvas/utils

Version:

Utilities to help build litecanvas games

2 lines (1 loc) 1.27 kB
(()=>{var f=Object.defineProperty;var d=(t,a)=>{for(var s in a)f(t,s,{get:a[s],enumerable:!0})};globalThis.utils=globalThis.utils||{};globalThis.utils.global=(t=!0)=>{for(let a in globalThis.utils)a!=="global"&&(t||globalThis[a]===void 0)&&(globalThis[a]=globalThis.utils[a])};var n={};d(n,{flipImage:()=>o,makeCircle:()=>u,makeRectangle:()=>p,scaleImage:()=>l,tintImage:()=>m});var o=(t,a=!0,s=!1,e=globalThis)=>e.paint(t.width,t.height,r=>{e.push(),e.scale(a?-1:1,s?-1:1),e.image(a?-t.width:0,s?-t.height:0,t),e.pop()});var l=(t,a,s=!0,e=globalThis)=>e.paint(t.width*a,t.height*a,r=>{e.push(),r.imageSmoothingEnabled=!s,e.scale(a),e.image(0,0,t),e.pop()});var m=(t,a,s=1,e=globalThis)=>e.paint(t.width,t.height,r=>{e.push(),e.alpha(s),e.rectfill(0,0,t.width,t.height,a),r.globalCompositeOperation="destination-atop",e.alpha(1),e.image(0,0,t),e.pop()});var u=(t,a,{borderWidth:s=0,borderColor:e=0,engine:r=globalThis}={})=>{let i=t*2+s;return r.paint(i,i,()=>{r.circfill(i/2,i/2,t,a),s>0&&(r.linewidth(s),r.stroke(e))})};var p=(t,a,s,{borderWidth:e=0,borderColor:r=0,engine:i=globalThis}={})=>{let c=t+e*2,b=a+e*2;return i.paint(c,b,()=>{i.rectfill(e>0?e:0,e>0?e:0,t,a,s),e>0&&(i.linewidth(e),i.stroke(r))})};globalThis.utils=Object.assign(globalThis.utils||{},n);})();