@litecanvas/plugin-migrate 0.8.0 → 0.10.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 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;})();
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.TWO_PI=e.PI*2,e.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.8.0",
3
+ "version": "0.10.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
@@ -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 TWO_PI constant
61
+ engine.TWO_PI = engine.PI * 2
62
+ engine.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])
@@ -227,7 +213,7 @@ export default function plugin(engine, config = {}) {
227
213
  warn(
228
214
  "FPS",
229
215
  "",
230
- "but you can use our plugin to measure the fps: https://github.com/litecanvas/plugin-frame-rate-meter",
216
+ "but you can use our plugin to measure the fps: https://github.com/litecanvas/plugin-frame-rate-meter"
231
217
  )
232
218
  _core_def("FPS", "")
233
219
 
@@ -248,7 +234,7 @@ export default function plugin(engine, config = {}) {
248
234
  warn(
249
235
  "path()",
250
236
  "`new Path2D()`",
251
- "See https://developer.mozilla.org/en-US/docs/Web/API/Path2D",
237
+ "See https://developer.mozilla.org/en-US/docs/Web/API/Path2D"
252
238
  )
253
239
  return new Path2D(arg)
254
240
  }
@@ -284,7 +270,7 @@ export default function plugin(engine, config = {}) {
284
270
  warn(
285
271
  "clip(path)",
286
272
  "clip(callback)",
287
- "E.g: `clip((ctx) => ctx.rect(0, 0, 200, 200))`",
273
+ "E.g: `clip((ctx) => ctx.rect(0, 0, 200, 200))`"
288
274
  )
289
275
  if (pathOrCallback instanceof Path2D) {
290
276
  const _ctx = engine.ctx()
@@ -332,26 +318,17 @@ export default function plugin(engine, config = {}) {
332
318
  // restore `listen()` and some old events like "quit" pre v0.200
333
319
  const _core_listen = engine.listen
334
320
  const _core_unlisten = engine.unlisten
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
- }
321
+ if (_core_unlisten) {
322
+ replacements.listen = (eventName, callback) => {
323
+ _core_listen(eventName, callback)
343
324
 
344
- ret = () => {
325
+ return () => {
345
326
  warnMessage(
346
- "listen() not returns a function anymore. Please use unlisten(event, callback) instead",
327
+ "listen() not returns a function anymore. Please use unlisten(event, callback) instead."
347
328
  )
348
329
  _core_unlisten(eventName, callback)
349
330
  }
350
331
  }
351
-
352
- _core_listen(eventName, callback)
353
-
354
- return ret
355
332
  }
356
333
 
357
334
  // restore `paused()`
@@ -365,7 +342,7 @@ export default function plugin(engine, config = {}) {
365
342
 
366
343
  function warnMessage(message) {
367
344
  if (config.warnings) {
368
- console.warn(`[litecanvas/migrate] ${message}.`)
345
+ console.warn(`[litecanvas/migrate] ${message}`)
369
346
  }
370
347
  }
371
348
 
@@ -373,7 +350,7 @@ export default function plugin(engine, config = {}) {
373
350
  warnMessage(
374
351
  `${old} is removed. ` +
375
352
  (current ? `Please use ${current} instead. ` : "") +
376
- extra,
353
+ extra
377
354
  )
378
355
  }
379
356