@litecanvas/plugin-migrate 0.5.0 → 0.6.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 v=(s,c,p,u,n,h,d,x)=>s<n+d&&s+p>n&&c<h+x&&c+u>h;var y=(s,c,p,u,n,h)=>(u-s)*(u-s)+(n-c)*(n-c)<=(p+h)*(p+h);var Ct=2*Math.PI;var g=(s,c,p,u=Math.sin)=>s+(u(p)+1)/2*(c-s);var He=Math.PI/2;var G={warnings:!0};function w(s,c={}){if(s.stat(1))throw'Plugin Migrate should be loaded before the "init" event';c=Object.assign({},G,c);let u={def:m,seed:h,print:M,clear:P,setfps:C,setvar:L,textstyle:x,textmetrics:T,cliprect:A,clipcirc:I,blendmode:k,transform:S,getcolor:N,mousepos:R,resize:z,path:F,fill:O,stroke:X,clip:H,paint:U,colrect:(...t)=>(_("colrect()"),v(...t)),colcirc:(...t)=>(_("colrect()"),y(...t)),wave:(...t)=>(_("wave()"),g(...t))},n=s.stat(0);function h(t){return a("seed()","rseed()"),t&&s.rseed(t),s.stat(9)}let d="";function x(t){a("textstyle()","the 5th param of text()"),d=t}function M(t,e,r,i){a("print()","text()"),s.text(t,e,r,i)}function T(t,e){a("textmetrics()","ctx().measureText()");let r=s.ctx(),i=s.stat(10),l=s.stat(11);r.font=`${d||""} ${~~(e||i)}px ${l}`;let f=r.measureText(t);return f.height=f.actualBoundingBoxAscent+f.actualBoundingBoxDescent,f}function A(t,e,r,i){a("cliprect()","clip()");let l=s.ctx();l.beginPath(),l.rect(t,e,r,i),l.clip()}function I(t,e,r){a("clipcirc()","clip()");let i=s.ctx();i.beginPath(),i.arc(t,e,r,0,s.TWO_PI),i.clip()}function N(t){a("getcolor()","stat(5)");let e=stat(5);return e[~~t%e.length]}function k(t){a("blendmode()","ctx().globalCompositeOperation");let e=s.ctx();e.globalCompositeOperation=t}function P(t){a("clear()","cls()"),s.cls(t)}function S(t,e,r,i,l,f,Z=!0){return a("transform()","ctx().setTransform() or ctx().transform()"),s.ctx()[Z?"setTransform":"transform"](t,e,r,i,l,f)}function R(){return a("mousepos()","MX and MY"),[MX,MY]}function C(t){a("setfps()","framerate()"),s.framerate(t)}let o=s.def;function m(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 L(t,e){a("setvar()","def()"),m(t,e)}s.listen("resized",E);function E(){m("CX",s.W/2),m("CY",s.H/2)}E(),m("CANVAS",s.canvas());function z(t,e){if(n.autoscale)throw"resize() don't works with autoscale enabled";a("resize()",null,"Avoid changing the canvas dimensions at runtime."),s.CANVAS.width=t,m("W",t),s.CANVAS.height=e,m("H",e),s.emit("resized",1)}for(let t of["W","H","T","CX","CY","MX","MY"])s[t]!=null&&m(t,s[t]);if(a("FPS","","but you can use our plugin to measure the fps: https://github.com/litecanvas/plugin-frame-rate-meter"),o("FPS",""),n.fps&&s.framerate(n.fps),n.background!=null){a('"background" option',"You must update your canvas CSS");let t=s.listen("before:draw",()=>{s.canvas().style.background=N(~~n.background),t()})}function F(t){return a("path()","`new Path2D()`","See https://developer.mozilla.org/en-US/docs/Web/API/Path2D"),new Path2D(t)}let Y=s.fill;function O(t,e){if(e instanceof Path2D){a("fill(color, path)");let r=s.stat(5),i=s.ctx();i.fillStyle=r[~~t%r.length],s.ctx().fill(e)}else Y(t)}let D=s.stroke;function X(t,e){if(e instanceof Path2D){a("stroke(color, path)");let r=s.stat(5),i=s.ctx();i.strokeStyle=r[~~t%r.length],s.ctx().stroke(e)}else D(t)}let B=s.clip;function H(t){a("clip(path)","clip(callback)","E.g: `clip((ctx) => ctx.rect(0, 0, 200, 200))`"),t instanceof Path2D?s.ctx().clip(t):B(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 W=s.paint;function U(t,e,r,i){let l=r;return s.spr&&Array.isArray(r)&&(l=()=>{s.spr(0,0,r.join(`
2
- `))}),W(t,e,l,i)}let b=s.spr;b&&b.length===3&&(u.spr=function(t,e,r,i,l){Number.isFinite(r)&&r>0?(a("spr() width and height","spr(x, y, pixels)"),b(t,e,l)):b(t,e,r)});function a(t,e,r=""){c.warnings&&console.warn(`[litecanvas/migrate] ${t} is removed. `+(e?`Use ${e} instead. `:"")+r)}function _(t,e="function"){a(t,`This ${e} was moved to @litecanvas/utils package.`)}return u}window.pluginMigrate=w;})();
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]);if(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");let t=r.listen("before:draw",()=>{r.canvas().style.background=w(~~n.background),t()})}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;})();
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.5.0",
3
+ "version": "0.6.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",
@@ -18,7 +18,8 @@
18
18
  "browser": "./dist/dist.js",
19
19
  "keywords": [
20
20
  "litecanvas",
21
- "migration"
21
+ "migration",
22
+ "compatibility"
22
23
  ],
23
24
  "scripts": {
24
25
  "dev": "esbuild src/_web.js --bundle --watch --outfile=dist/dist.js --servedir=.",
package/src/index.js CHANGED
@@ -330,13 +330,33 @@ export default function plugin(engine, config = {}) {
330
330
  }
331
331
  }
332
332
 
333
+ // restore `listen()` pre v0.200
334
+ const _core_unlisten = engine.unlisten
335
+ if (_core_unlisten) {
336
+ const _core_listen = engine.listen
337
+ replacements.listen = (eventName, callback) => {
338
+ _core_listen(eventName, callback)
339
+ return () => {
340
+ warnMessage(
341
+ "listen() not returns a function anymore. Please use unlisten(event, callback) instead"
342
+ )
343
+ _core_unlisten(eventName, callback)
344
+ }
345
+ }
346
+ }
347
+
348
+ function warnMessage(message) {
349
+ if (config.warnings) {
350
+ console.warn(`[litecanvas/migrate] ${message}.`)
351
+ }
352
+ }
353
+
333
354
  function warn(old, current, extra = "") {
334
- if (config.warnings)
335
- console.warn(
336
- `[litecanvas/migrate] ${old} is removed. ` +
337
- (current ? `Use ${current} instead. ` : "") +
338
- extra
339
- )
355
+ warnMessage(
356
+ `${old} is removed. ` +
357
+ (current ? `Please use ${current} instead. ` : "") +
358
+ extra
359
+ )
340
360
  }
341
361
 
342
362
  function warnUtils(func, type = "function") {