@litecanvas/plugin-migrate 0.9.0 → 0.10.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/dist.js CHANGED
@@ -1,3 +1,3 @@
1
- (()=>{var _=(r,u,p,m,n,f,b,x)=>r<n+b&&r+p>n&&u<f+x&&u+m>f;var y=(r,u,p,m,n,f)=>(m-r)*(m-r)+(n-u)*(n-u)<=(p+f)*(p+f);var Dt=2*Math.PI;var N=(r,u,p,m=Math.sin)=>r+(m(p)+1)/2*(u-r);var Er=Math.PI/2;var rt={warnings:!0};function w(r,u={}){if(r.stat(1))throw'Plugin Migrate should be loaded before the "init" event';u=Object.assign({},rt,u);let m={def:c,seed:f,print:T,clear:R,setfps:O,setvar:Y,textstyle:x,textmetrics:k,cliprect:F,clipcirc:S,blendmode:C,transform:L,getcolor:v,mousepos:z,resize:H,path:X,fill:W,stroke:U,clip:Z,paint:j,colrect:(...t)=>(g("colrect()"),_(...t)),colcirc:(...t)=>(g("colrect()"),y(...t)),wave:(...t)=>(g("wave()"),N(...t))},n=r.stat(0);function f(t){return s("seed()","rseed()"),t&&r.rseed(t),r.stat(9)}let b="";function x(t){s("textstyle()","the 5th param of text()"),b=t}function T(t,e,a,i){s("print()","text()"),r.text(t,e,a,i)}function k(t,e){s("textmetrics()","ctx().measureText()");let a=r.ctx(),i=r.stat(10),l=r.stat(11);a.font=`${b||""} ${~~(e||i)}px ${l}`;let h=a.measureText(t);return h.height=h.actualBoundingBoxAscent+h.actualBoundingBoxDescent,h}function F(t,e,a,i){s("cliprect()","clip()");let l=r.ctx();l.beginPath(),l.rect(t,e,a,i),l.clip()}function S(t,e,a){s("clipcirc()","clip()");let i=r.ctx();i.beginPath(),i.arc(t,e,a,0,r.TWO_PI),i.clip()}function v(t){s("getcolor()","stat(5)");let e=stat(5);return e[~~t%e.length]}function C(t){s("blendmode()","ctx().globalCompositeOperation");let e=r.ctx();e.globalCompositeOperation=t}function R(t){s("clear()","cls()"),r.cls(t)}function L(t,e,a,i,l,h,G=!0){return s("transform()","ctx().setTransform() or ctx().transform()"),r.ctx()[G?"setTransform":"transform"](t,e,a,i,l,h)}function z(){return s("mousepos()","MX and MY"),[MX,MY]}function O(t){s("setfps()","framerate()"),r.framerate(t)}let o=r.def;function c(t,e){switch(t){case"W":case"WIDTH":o("W",e),o("WIDTH",e);break;case"H":case"HEIGHT":o("H",e),o("HEIGHT",e);break;case"T":case"ELAPSED":o("T",e),o("ELAPSED",e);break;case"CX":case"CENTERX":o("CX",e),o("CENTERX",e);break;case"CY":case"CENTERY":o("CY",e),o("CENTERY",e);break;case"MX":case"MOUSEX":o("MX",e),o("MOUSEX",e);break;case"MY":case"MOUSEY":o("MY",e),o("MOUSEY",e);break;default:o(t,e);break}}function Y(t,e){s("setvar()","def()"),c(t,e)}r.listen("resized",E);function E(){c("CX",r.W/2),c("CY",r.H/2)}E(),c("CANVAS",r.canvas());function H(t,e){if(n.autoscale)throw"resize() don't works with autoscale enabled";s("resize()",null,"Avoid changing the canvas dimensions at runtime."),r.CANVAS.width=t,c("W",t),r.CANVAS.height=e,c("H",e),r.emit("resized",1)}for(let t of["W","H","T","CX","CY","MX","MY"])r[t]!=null&&c(t,r[t]);s("FPS","","but you can use our plugin to measure the fps: https://github.com/litecanvas/plugin-frame-rate-meter"),o("FPS",""),n.fps&&r.framerate(n.fps),n.background!=null&&(s('"background" option',"You must update your canvas CSS"),r.listen("after:init",()=>{r.canvas().style.background=v(~~n.background)}));function X(t){return s("path()","`new Path2D()`","See https://developer.mozilla.org/en-US/docs/Web/API/Path2D"),new Path2D(t)}let B=r.fill;function W(t,e){if(e instanceof Path2D){s("fill(color, path)");let a=r.stat(5),i=r.ctx();i.fillStyle=a[~~t%a.length],r.ctx().fill(e)}else B(t)}let D=r.stroke;function U(t,e){if(e instanceof Path2D){s("stroke(color, path)");let a=r.stat(5),i=r.ctx();i.strokeStyle=a[~~t%a.length],r.ctx().stroke(e)}else D(t)}let V=r.clip;function Z(t){s("clip(path)","clip(callback)","E.g: `clip((ctx) => ctx.rect(0, 0, 200, 200))`"),t instanceof Path2D?r.ctx().clip(t):V(t)}n.antialias&&s('"antialias" option','"pixelart" option'),n.pixelart===!1&&s('"pixelart" option'),n.animate===!1&&s('"animate" option',"pause() in the of your draw()");let $=r.paint;function j(t,e,a,i){let l=a;return r.spr&&Array.isArray(a)&&(l=()=>{r.spr(0,0,a.join(`
2
- `))}),$(t,e,l,i)}let d=r.spr;d&&d.length===3&&(m.spr=function(t,e,a,i,l){Number.isFinite(a)&&a>0?(s("spr() width and height","spr(x, y, pixels)"),d(t,e,l)):d(t,e,a)});let q=r.listen,M=r.unlisten;M&&(m.listen=(t,e)=>(q(t,e),()=>{I("listen() not returns a function anymore. Please use unlisten(event, callback) instead."),M(t,e)}));let A=r.ispaused;A&&(m.paused=()=>(s("paused()","ispaused()"),A()));function I(t){u.warnings&&console.warn(`[litecanvas/migrate] ${t}`)}function s(t,e,a=""){I(`${t} is removed. `+(e?`Please use ${e} instead. `:"")+a)}function g(t,e="function"){s(t,`This ${e} was moved to @litecanvas/utils package.`)}return m}window.pluginMigrate=w;})();
1
+ (()=>{var _=(e,l,c,m,o,h,b,g)=>e<o+b&&e+c>o&&l<h+g&&l+m>h;var y=(e,l,c,m,o,h)=>(m-e)*(m-e)+(o-l)*(o-l)<=(c+h)*(c+h);var Wt=2*Math.PI;var v=(e,l,c,m=Math.sin)=>e+(m(c)+1)/2*(l-e);var Ts=Math.PI/2;var et={warnings:!0};function w(e,l={}){if(e.stat(1))throw'Plugin Migrate should be loaded before the "init" event';l=Object.assign({},et,l);let m={def:p,seed:h,print:T,clear:C,setfps:O,setvar:X,textstyle:g,textmetrics:k,cliprect:F,clipcirc:S,blendmode:R,transform:L,getcolor:E,mousepos:Y,path:H,fill:D,stroke:z,clip:Z,paint:$,colrect:(...t)=>(x("colrect()"),_(...t)),colcirc:(...t)=>(x("colrect()"),y(...t)),wave:(...t)=>(x("wave()"),v(...t))};e.def("TWO_PI",e.PI*2),e.def("HALF_PI",e.PI/2);let o=e.stat(0);function h(t){return a("seed()","rseed()"),t&&e.rseed(t),e.stat(9)}let b="";function g(t){a("textstyle()","the 5th param of text()"),b=t}function T(t,s,r,n){a("print()","text()"),e.text(t,s,r,n)}function k(t,s){a("textmetrics()","ctx().measureText()");let r=e.ctx(),n=e.stat(10),u=e.stat(11);r.font=`${b||""} ${~~(s||n)}px ${u}`;let f=r.measureText(t);return f.height=f.actualBoundingBoxAscent+f.actualBoundingBoxDescent,f}function F(t,s,r,n){a("cliprect()","clip()");let u=e.ctx();u.beginPath(),u.rect(t,s,r,n),u.clip()}function S(t,s,r){a("clipcirc()","clip()");let n=e.ctx();n.beginPath(),n.arc(t,s,r,0,e.TWO_PI),n.clip()}function E(t){a("getcolor()","stat(5)");let s=stat(5);return s[~~t%s.length]}function R(t){a("blendmode()","ctx().globalCompositeOperation");let s=e.ctx();s.globalCompositeOperation=t}function C(t){a("clear()","cls()"),e.cls(t)}function L(t,s,r,n,u,f,q=!0){return a("transform()","ctx().setTransform() or ctx().transform()"),e.ctx()[q?"setTransform":"transform"](t,s,r,n,u,f)}function Y(){return a("mousepos()","MX and MY"),[MX,MY]}function O(t){a("setfps()","framerate()"),e.framerate(t)}let i=e.def;function p(t,s){switch(t){case"W":case"WIDTH":i("W",s),i("WIDTH",s);break;case"H":case"HEIGHT":i("H",s),i("HEIGHT",s);break;case"T":case"ELAPSED":i("T",s),i("ELAPSED",s);break;case"CX":case"CENTERX":i("CX",s),i("CENTERX",s);break;case"CY":case"CENTERY":i("CY",s),i("CENTERY",s);break;case"MX":case"MOUSEX":i("MX",s),i("MOUSEX",s);break;case"MY":case"MOUSEY":i("MY",s),i("MOUSEY",s);break;default:i(t,s);break}}function X(t,s){a("setvar()","def()"),p(t,s)}e.listen("resized",M);function M(){p("CX",e.W/2),p("CY",e.H/2)}M(),p("CANVAS",e.canvas());for(let t of["W","H","T","CX","CY","MX","MY"])e[t]!=null&&p(t,e[t]);a("FPS","","but you can use our plugin to measure the fps: https://github.com/litecanvas/plugin-frame-rate-meter"),i("FPS",""),o.fps&&e.framerate(o.fps),o.background!=null&&(a('"background" option',"You must update your canvas CSS"),e.listen("after:init",()=>{e.canvas().style.background=E(~~o.background)}));function H(t){return a("path()","`new Path2D()`","See https://developer.mozilla.org/en-US/docs/Web/API/Path2D"),new Path2D(t)}let B=e.fill;function D(t,s){if(s instanceof Path2D){a("fill(color, path)");let r=e.stat(5),n=e.ctx();n.fillStyle=r[~~t%r.length],e.ctx().fill(s)}else B(t)}let W=e.stroke;function z(t,s){if(s instanceof Path2D){a("stroke(color, path)");let r=e.stat(5),n=e.ctx();n.strokeStyle=r[~~t%r.length],e.ctx().stroke(s)}else W(t)}let U=e.clip;function Z(t){a("clip(path)","clip(callback)","E.g: `clip((ctx) => ctx.rect(0, 0, 200, 200))`"),t instanceof Path2D?e.ctx().clip(t):U(t)}o.antialias&&a('"antialias" option','"pixelart" option'),o.pixelart===!1&&a('"pixelart" option'),o.animate===!1&&a('"animate" option',"pause() in the of your draw()");let V=e.paint;function $(t,s,r,n){let u=r;return e.spr&&Array.isArray(r)&&(u=()=>{e.spr(0,0,r.join(`
2
+ `))}),V(t,s,u,n)}let d=e.spr;d&&d.length===3&&(m.spr=function(t,s,r,n,u){Number.isFinite(r)&&r>0?(a("spr() width and height","spr(x, y, pixels)"),d(t,s,u)):d(t,s,r)});let j=e.listen,I=e.unlisten;I&&(m.listen=(t,s)=>(j(t,s),()=>{P("listen() not returns a function anymore. Please use unlisten(event, callback) instead."),I(t,s)}));let A=e.ispaused;A&&(m.paused=()=>(a("paused()","ispaused()"),A()));function P(t){l.warnings&&console.warn(`[litecanvas/migrate] ${t}`)}function a(t,s,r=""){P(`${t} is removed. `+(s?`Please use ${s} instead. `:"")+r)}function x(t,s="function"){a(t,`This ${s} was moved to @litecanvas/utils package.`)}return m}window.pluginMigrate=w;})();
3
3
  /*! Migrate for litecanvas by Luiz Bills | MIT Licensed */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@litecanvas/plugin-migrate",
3
- "version": "0.9.0",
3
+ "version": "0.10.1",
4
4
  "description": "Sometimes upgrading litecanvas to a new version can be a lot of work. This plugin makes this easier, by restoring the Litecanvas APIs that were removed in newer versions, and additionally shows warnings in the browser console when removed and/or deprecated APIs are used.",
5
5
  "author": "Luiz Bills <luizbills@pm.me>",
6
6
  "license": "MIT",
package/src/index.js CHANGED
@@ -36,7 +36,6 @@ export default function plugin(engine, config = {}) {
36
36
  transform,
37
37
  getcolor,
38
38
  mousepos,
39
- resize,
40
39
  path,
41
40
  fill,
42
41
  stroke,
@@ -58,6 +57,10 @@ export default function plugin(engine, config = {}) {
58
57
  },
59
58
  }
60
59
 
60
+ // restore old PI constants
61
+ engine.def("TWO_PI", engine.PI * 2)
62
+ engine.def("HALF_PI", engine.PI / 2)
63
+
61
64
  /** @type {LitecanvasOptions} */
62
65
  const settings = engine.stat(0)
63
66
 
@@ -201,23 +204,6 @@ export default function plugin(engine, config = {}) {
201
204
  // restore CANVAS removed in v0.84
202
205
  _def("CANVAS", engine.canvas())
203
206
 
204
- // restore a semi-version of the `resize()`
205
- function resize(width, height) {
206
- if (settings.autoscale) {
207
- throw "resize() don't works with autoscale enabled"
208
- }
209
-
210
- warn("resize()", null, "Avoid changing the canvas dimensions at runtime.")
211
-
212
- engine.CANVAS.width = width
213
- _def("W", width)
214
-
215
- engine.CANVAS.height = height
216
- _def("H", height)
217
-
218
- engine.emit("resized", 1)
219
- }
220
-
221
207
  for (const key of ["W", "H", "T", "CX", "CY", "MX", "MY"]) {
222
208
  if (null != engine[key]) {
223
209
  _def(key, engine[key])