@litecanvas/plugin-migrate 0.6.1 → 0.8.0

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 Bt=2*Math.PI;var N=(r,u,p,m=Math.sin)=>r+(m(p)+1)/2*(u-r);var vr=Math.PI/2;var tt={warnings:!0};function v(r,u={}){if(r.stat(1))throw'Plugin Migrate should be loaded before the "init" event';u=Object.assign({},tt,u);let m={def:c,seed:f,print:T,clear:R,setfps:z,setvar:Y,textstyle:x,textmetrics:I,cliprect:k,clipcirc:F,blendmode:S,transform:C,getcolor:w,mousepos:L,resize:O,path:H,fill:B,stroke:D,clip:V,paint:$,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 a("seed()","rseed()"),t&&r.rseed(t),r.stat(9)}let b="";function x(t){a("textstyle()","the 5th param of text()"),b=t}function T(t,e,s,i){a("print()","text()"),r.text(t,e,s,i)}function I(t,e){a("textmetrics()","ctx().measureText()");let s=r.ctx(),i=r.stat(10),l=r.stat(11);s.font=`${b||""} ${~~(e||i)}px ${l}`;let h=s.measureText(t);return h.height=h.actualBoundingBoxAscent+h.actualBoundingBoxDescent,h}function k(t,e,s,i){a("cliprect()","clip()");let l=r.ctx();l.beginPath(),l.rect(t,e,s,i),l.clip()}function F(t,e,s){a("clipcirc()","clip()");let i=r.ctx();i.beginPath(),i.arc(t,e,s,0,r.TWO_PI),i.clip()}function w(t){a("getcolor()","stat(5)");let e=stat(5);return e[~~t%e.length]}function S(t){a("blendmode()","ctx().globalCompositeOperation");let e=r.ctx();e.globalCompositeOperation=t}function R(t){a("clear()","cls()"),r.cls(t)}function C(t,e,s,i,l,h,j=!0){return a("transform()","ctx().setTransform() or ctx().transform()"),r.ctx()[j?"setTransform":"transform"](t,e,s,i,l,h)}function L(){return a("mousepos()","MX and MY"),[MX,MY]}function z(t){a("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){a("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 O(t,e){if(n.autoscale)throw"resize() don't works with autoscale enabled";a("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]);a("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&&(a('"background" option',"You must update your canvas CSS"),r.listen("after:init",()=>{r.canvas().style.background=w(~~n.background)}));function H(t){return a("path()","`new Path2D()`","See https://developer.mozilla.org/en-US/docs/Web/API/Path2D"),new Path2D(t)}let X=r.fill;function B(t,e){if(e instanceof Path2D){a("fill(color, path)");let s=r.stat(5),i=r.ctx();i.fillStyle=s[~~t%s.length],r.ctx().fill(e)}else X(t)}let W=r.stroke;function D(t,e){if(e instanceof Path2D){a("stroke(color, path)");let s=r.stat(5),i=r.ctx();i.strokeStyle=s[~~t%s.length],r.ctx().stroke(e)}else W(t)}let U=r.clip;function V(t){a("clip(path)","clip(callback)","E.g: `clip((ctx) => ctx.rect(0, 0, 200, 200))`"),t instanceof Path2D?r.ctx().clip(t):U(t)}n.antialias&&a('"antialias" option','"pixelart" option'),n.pixelart===!1&&a('"pixelart" option'),n.animate===!1&&a('"animate" option',"pause() in the of your draw()");let Z=r.paint;function $(t,e,s,i){let l=s;return r.spr&&Array.isArray(s)&&(l=()=>{r.spr(0,0,s.join(`
2
- `))}),Z(t,e,l,i)}let d=r.spr;d&&d.length===3&&(m.spr=function(t,e,s,i,l){Number.isFinite(s)&&s>0?(a("spr() width and height","spr(x, y, pixels)"),d(t,e,l)):d(t,e,s)});let M=r.unlisten;if(M){let t=r.listen;m.listen=(e,s)=>(t(e,s),()=>{A("listen() not returns a function anymore. Please use unlisten(event, callback) instead"),M(e,s)})}function A(t){u.warnings&&console.warn(`[litecanvas/migrate] ${t}.`)}function a(t,e,s=""){A(`${t} is removed. `+(e?`Please use ${e} instead. `:"")+s)}function g(t,e="function"){a(t,`This ${e} was moved to @litecanvas/utils package.`)}return m}window.pluginMigrate=v;})();
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:k,clear:L,setfps:Y,setvar:H,textstyle:x,textmetrics:F,cliprect:S,clipcirc:C,blendmode:R,transform:z,getcolor:v,mousepos:O,resize:X,path:B,fill:D,stroke:V,clip:$,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 a("seed()","rseed()"),t&&r.rseed(t),r.stat(9)}let b="";function x(t){a("textstyle()","the 5th param of text()"),b=t}function k(t,e,s,i){a("print()","text()"),r.text(t,e,s,i)}function F(t,e){a("textmetrics()","ctx().measureText()");let s=r.ctx(),i=r.stat(10),l=r.stat(11);s.font=`${b||""} ${~~(e||i)}px ${l}`;let h=s.measureText(t);return h.height=h.actualBoundingBoxAscent+h.actualBoundingBoxDescent,h}function S(t,e,s,i){a("cliprect()","clip()");let l=r.ctx();l.beginPath(),l.rect(t,e,s,i),l.clip()}function C(t,e,s){a("clipcirc()","clip()");let i=r.ctx();i.beginPath(),i.arc(t,e,s,0,r.TWO_PI),i.clip()}function v(t){a("getcolor()","stat(5)");let e=stat(5);return e[~~t%e.length]}function R(t){a("blendmode()","ctx().globalCompositeOperation");let e=r.ctx();e.globalCompositeOperation=t}function L(t){a("clear()","cls()"),r.cls(t)}function z(t,e,s,i,l,h,G=!0){return a("transform()","ctx().setTransform() or ctx().transform()"),r.ctx()[G?"setTransform":"transform"](t,e,s,i,l,h)}function O(){return a("mousepos()","MX and MY"),[MX,MY]}function Y(t){a("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 H(t,e){a("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 X(t,e){if(n.autoscale)throw"resize() don't works with autoscale enabled";a("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]);a("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&&(a('"background" option',"You must update your canvas CSS"),r.listen("after:init",()=>{r.canvas().style.background=v(~~n.background)}));function B(t){return a("path()","`new Path2D()`","See https://developer.mozilla.org/en-US/docs/Web/API/Path2D"),new Path2D(t)}let W=r.fill;function D(t,e){if(e instanceof Path2D){a("fill(color, path)");let s=r.stat(5),i=r.ctx();i.fillStyle=s[~~t%s.length],r.ctx().fill(e)}else W(t)}let U=r.stroke;function V(t,e){if(e instanceof Path2D){a("stroke(color, path)");let s=r.stat(5),i=r.ctx();i.strokeStyle=s[~~t%s.length],r.ctx().stroke(e)}else U(t)}let Z=r.clip;function $(t){a("clip(path)","clip(callback)","E.g: `clip((ctx) => ctx.rect(0, 0, 200, 200))`"),t instanceof Path2D?r.ctx().clip(t):Z(t)}n.antialias&&a('"antialias" option','"pixelart" option'),n.pixelart===!1&&a('"pixelart" option'),n.animate===!1&&a('"animate" option',"pause() in the of your draw()");let q=r.paint;function j(t,e,s,i){let l=s;return r.spr&&Array.isArray(s)&&(l=()=>{r.spr(0,0,s.join(`
2
+ `))}),q(t,e,l,i)}let d=r.spr;d&&d.length===3&&(m.spr=function(t,e,s,i,l){Number.isFinite(s)&&s>0?(a("spr() width and height","spr(x, y, pixels)"),d(t,e,l)):d(t,e,s)});let M=r.listen,A=r.unlisten;m.listen=(t,e)=>{let s;return A&&(t==="quit"&&(a('since v0.203, "quit" event','"shutdown" event'),M("shutdown",e)),s=()=>{T("listen() not returns a function anymore. Please use unlisten(event, callback) instead"),A(t,e)}),M(t,e),s};let I=r.ispaused;I&&(m.paused=()=>(a("paused()","ispaused()"),I()));function T(t){u.warnings&&console.warn(`[litecanvas/migrate] ${t}.`)}function a(t,e,s=""){T(`${t} is removed. `+(e?`Please use ${e} instead. `:"")+s)}function g(t,e="function"){a(t,`This ${e} 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.6.1",
3
+ "version": "0.8.0",
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
@@ -227,7 +227,7 @@ export default function plugin(engine, config = {}) {
227
227
  warn(
228
228
  "FPS",
229
229
  "",
230
- "but you can use our plugin to measure the fps: https://github.com/litecanvas/plugin-frame-rate-meter"
230
+ "but you can use our plugin to measure the fps: https://github.com/litecanvas/plugin-frame-rate-meter",
231
231
  )
232
232
  _core_def("FPS", "")
233
233
 
@@ -248,7 +248,7 @@ export default function plugin(engine, config = {}) {
248
248
  warn(
249
249
  "path()",
250
250
  "`new Path2D()`",
251
- "See https://developer.mozilla.org/en-US/docs/Web/API/Path2D"
251
+ "See https://developer.mozilla.org/en-US/docs/Web/API/Path2D",
252
252
  )
253
253
  return new Path2D(arg)
254
254
  }
@@ -284,7 +284,7 @@ export default function plugin(engine, config = {}) {
284
284
  warn(
285
285
  "clip(path)",
286
286
  "clip(callback)",
287
- "E.g: `clip((ctx) => ctx.rect(0, 0, 200, 200))`"
287
+ "E.g: `clip((ctx) => ctx.rect(0, 0, 200, 200))`",
288
288
  )
289
289
  if (pathOrCallback instanceof Path2D) {
290
290
  const _ctx = engine.ctx()
@@ -329,19 +329,38 @@ export default function plugin(engine, config = {}) {
329
329
  }
330
330
  }
331
331
 
332
- // restore `listen()` pre v0.200
332
+ // restore `listen()` and some old events like "quit" pre v0.200
333
+ const _core_listen = engine.listen
333
334
  const _core_unlisten = engine.unlisten
334
- if (_core_unlisten) {
335
- const _core_listen = engine.listen
336
- replacements.listen = (eventName, callback) => {
337
- _core_listen(eventName, callback)
338
- return () => {
335
+ replacements.listen = (eventName, callback) => {
336
+ let ret
337
+
338
+ if (_core_unlisten) {
339
+ if (eventName === "quit") {
340
+ warn('since v0.203, "quit" event', '"shutdown" event')
341
+ _core_listen("shutdown", callback)
342
+ }
343
+
344
+ ret = () => {
339
345
  warnMessage(
340
- "listen() not returns a function anymore. Please use unlisten(event, callback) instead"
346
+ "listen() not returns a function anymore. Please use unlisten(event, callback) instead",
341
347
  )
342
348
  _core_unlisten(eventName, callback)
343
349
  }
344
350
  }
351
+
352
+ _core_listen(eventName, callback)
353
+
354
+ return ret
355
+ }
356
+
357
+ // restore `paused()`
358
+ const _core_ispaused = engine.ispaused
359
+ if (_core_ispaused) {
360
+ replacements.paused = () => {
361
+ warn("paused()", "ispaused()")
362
+ return _core_ispaused()
363
+ }
345
364
  }
346
365
 
347
366
  function warnMessage(message) {
@@ -354,7 +373,7 @@ export default function plugin(engine, config = {}) {
354
373
  warnMessage(
355
374
  `${old} is removed. ` +
356
375
  (current ? `Please use ${current} instead. ` : "") +
357
- extra
376
+ extra,
358
377
  )
359
378
  }
360
379