@litecanvas/plugin-migrate 0.0.2 → 0.0.3

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/README.md CHANGED
@@ -1,6 +1,6 @@
1
- # Migrate Plugin for Litecanvas
1
+ # Plugin Migrate for Litecanvas
2
2
 
3
- Migrate 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.
3
+ 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.
4
4
 
5
5
  ## Install
6
6
 
@@ -10,6 +10,8 @@ Migrate Plugin makes this easier, by restoring the Litecanvas APIs that were rem
10
10
 
11
11
  ## Usage
12
12
 
13
+ In that example, `clear` and `print` will not cause errors, because this plugin restores these old functions that no longer exist in the latest versions of Litecanvas.
14
+
13
15
  ```js
14
16
  litecanvas({
15
17
  loop: { init, draw },
@@ -18,8 +20,7 @@ litecanvas({
18
20
  use(pluginMigrate)
19
21
 
20
22
  function draw() {
21
- clear(0) // clear() was a alias for cls()
22
-
23
- print(0, 0, "Hello World") // print() was a alias for text()
23
+ clear(0)
24
+ print(0, 0, "Hello World")
24
25
  }
25
26
  ```
package/dist/dist.js CHANGED
@@ -1,2 +1,2 @@
1
- (()=>{var v={mute:!1};function p(a,b=v){if(a.stat(1))throw'Plugin Migrate should be loaded before the "init" event';let l=a.stat(0);function n(t,e,s=""){b.mute||console.warn(`[Migrate] warning: ${t} is removed. `+(e?`Use ${e} instead. `:"")+s)}function d(t){return n("seed()","rseed()"),t&&a.rseed(t),a.stat(9)}let c="";function h(t){n("textstyle()","the 5th param of text()"),c=t}let g=a.text;function f(t,e,s,o=3,i=c){g(t,e,s,o,i)}function w(t,e,s,o){n("print()","text()"),f(t,e,s,o)}function _(t,e){n("textmetrics()","ctx().measureText()");let s=a.ctx(),o=a.stat(10),i=a.stat(11);s.font=`${c||""} ${~~(e||o)}px ${i}`;let m=s.measureText(t);return m.height=m.actualBoundingBoxAscent+m.actualBoundingBoxDescent,m}function A(t,e,s,o){n("cliprect()","clip()");let i=a.ctx();i.beginPath(),i.rect(t,e,s,o),i.clip()}function E(t,e,s){n("clipcirc()","clip()");let o=a.ctx();o.beginPath(),o.arc(t,e,s,0,a.TWO_PI),o.clip()}function C(t){n("getcolor()","stat(5)");let e=stat(5);return e[~~t%e.length]}function T(t){n("blendmode()","ctx().globalCompositeOperation");let e=a.ctx();e.globalCompositeOperation=t}function k(t){n("clear()","cls()"),a.cls(x,y,str,t)}function M(t,e,s,o,i,m,D=!0){return n("transform()","ctx().setTransform() or ctx().transform()"),a.ctx()[D?"setTransform":"transform"](t,e,s,o,i,m)}function Y(){return n("mousepos()","MX and MY"),[MX,MY]}function S(t){n("setfps()","framerate()"),a.framerate(t)}let r=a.def;function u(t,e){switch(t){case"W":case"WIDTH":r("W",e),r("WIDTH",e);break;case"H":case"HEIGHT":r("H",e),r("HEIGHT",e);break;case"T":case"ELAPSED":r("T",e),r("ELAPSED",e);break;case"CX":case"CENTERX":r("CX",e),r("CENTERX",e);break;case"CY":case"CENTERY":r("CY",e),r("CENTERY",e);break;case"MX":case"MOUSEX":r("MX",e),r("MOUSEX",e);break;case"MY":case"MOUSEY":r("MY",e),r("MOUSEY",e);break;default:r(t,e);break}}function X(t,e){n("setvar()","def()"),u(t,e)}function P(t,e){if(l.autoscale)throw"resize() don't works with autoscale enabled";n("resize()",null,"Avoid changing the canvas dimensions at runtime."),a.CANVAS.width=t,u("W",t),u("CX",t/2),a.CANVAS.height=e,u("H",e),u("CY",e/2),a.emit("resized",1)}for(let t of["W","H","T","CX","CY","MX","MY"])a[t]!=null&&u(t,a[t]);if(n("FPS","some library to measure the FPS","Recommendation: https://github.com/mrdoob/stats.js/"),r("FPS",""),l.fps&&a.framerate(l.fps),l.background>=0){let t=stat(5);a.CANVAS.style.backgroundColor=t[~~l.background%t.length]}return{def:u,seed:d,print:w,clear:k,setfps:S,setvar:X,textstyle:h,textmetrics:_,text:f,cliprect:A,clipcirc:E,blendmode:T,transform:M,getcolor:C,mousepos:Y,resize:P}}window.pluginMigrate=p;})();
1
+ (()=>{var v={mute:!1};function f(a,c={}){if(c=Object.assign({},v,c),a.stat(1))throw'Plugin Migrate should be loaded before the "init" event';let l=a.stat(0);function n(t,e,s=""){c.mute||console.warn(`[Migrate] warning: ${t} is removed. `+(e?`Use ${e} instead. `:"")+s)}function d(t){return n("seed()","rseed()"),t&&a.rseed(t),a.stat(9)}let p="";function h(t){n("textstyle()","the 5th param of text()"),p=t}let g=a.text;function b(t,e,s,o=3,i=p){g(t,e,s,o,i)}function w(t,e,s,o){n("print()","text()"),b(t,e,s,o)}function _(t,e){n("textmetrics()","ctx().measureText()");let s=a.ctx(),o=a.stat(10),i=a.stat(11);s.font=`${p||""} ${~~(e||o)}px ${i}`;let m=s.measureText(t);return m.height=m.actualBoundingBoxAscent+m.actualBoundingBoxDescent,m}function A(t,e,s,o){n("cliprect()","clip()");let i=a.ctx();i.beginPath(),i.rect(t,e,s,o),i.clip()}function E(t,e,s){n("clipcirc()","clip()");let o=a.ctx();o.beginPath(),o.arc(t,e,s,0,a.TWO_PI),o.clip()}function C(t){n("getcolor()","stat(5)");let e=stat(5);return e[~~t%e.length]}function T(t){n("blendmode()","ctx().globalCompositeOperation");let e=a.ctx();e.globalCompositeOperation=t}function k(t){n("clear()","cls()"),a.cls(x,y,str,t)}function M(t,e,s,o,i,m,D=!0){return n("transform()","ctx().setTransform() or ctx().transform()"),a.ctx()[D?"setTransform":"transform"](t,e,s,o,i,m)}function S(){return n("mousepos()","MX and MY"),[MX,MY]}function Y(t){n("setfps()","framerate()"),a.framerate(t)}let r=a.def;function u(t,e){switch(t){case"W":case"WIDTH":r("W",e),r("WIDTH",e);break;case"H":case"HEIGHT":r("H",e),r("HEIGHT",e);break;case"T":case"ELAPSED":r("T",e),r("ELAPSED",e);break;case"CX":case"CENTERX":r("CX",e),r("CENTERX",e);break;case"CY":case"CENTERY":r("CY",e),r("CENTERY",e);break;case"MX":case"MOUSEX":r("MX",e),r("MOUSEX",e);break;case"MY":case"MOUSEY":r("MY",e),r("MOUSEY",e);break;default:r(t,e);break}}function X(t,e){n("setvar()","def()"),u(t,e)}function P(t,e){if(l.autoscale)throw"resize() don't works with autoscale enabled";n("resize()",null,"Avoid changing the canvas dimensions at runtime."),a.CANVAS.width=t,u("W",t),u("CX",t/2),a.CANVAS.height=e,u("H",e),u("CY",e/2),a.emit("resized",1)}for(let t of["W","H","T","CX","CY","MX","MY"])a[t]!=null&&u(t,a[t]);if(n("FPS","some library to measure the FPS","Recommendation: https://github.com/mrdoob/stats.js/"),r("FPS",""),l.fps&&a.framerate(l.fps),l.background>=0){let t=stat(5);a.CANVAS.style.backgroundColor=t[~~l.background%t.length]}return{def:u,seed:d,print:w,clear:k,setfps:Y,setvar:X,textstyle:h,textmetrics:_,text:b,cliprect:A,clipcirc:E,blendmode:T,transform:M,getcolor:C,mousepos:S,resize:P}}window.pluginMigrate=f;})();
2
2
  /*! pluginMigrate for litecanvas v0.0.1 by Luiz Bills | MIT Licensed */
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@litecanvas/plugin-migrate",
3
- "version": "0.0.2",
4
- "description": "Migrate 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.",
3
+ "version": "0.0.3",
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",
7
7
  "homepage": "https://github.com/litecanvas/plugin-migrate",
package/src/index.js CHANGED
@@ -7,10 +7,11 @@ const defaults = {
7
7
  /**
8
8
  *
9
9
  * @param {LitecanvasInstance} engine
10
- * @param {object} config
10
+ * @param {typeof defaults} config
11
11
  * @returns any
12
12
  */
13
- export default function plugin(engine, config = defaults) {
13
+ export default function plugin(engine, config = {}) {
14
+ config = Object.assign({}, defaults, config)
14
15
  const initialized = engine.stat(1)
15
16
 
16
17
  if (initialized) {