@litecanvas/plugin-migrate 0.8.0 → 0.9.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 +2 -2
- package/package.json +1 -1
- package/src/index.js +10 -19
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:
|
|
2
|
-
`))})
|
|
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;})();
|
|
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.
|
|
3
|
+
"version": "0.9.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()
|
|
@@ -332,26 +332,17 @@ export default function plugin(engine, config = {}) {
|
|
|
332
332
|
// restore `listen()` and some old events like "quit" pre v0.200
|
|
333
333
|
const _core_listen = engine.listen
|
|
334
334
|
const _core_unlisten = engine.unlisten
|
|
335
|
-
|
|
336
|
-
|
|
335
|
+
if (_core_unlisten) {
|
|
336
|
+
replacements.listen = (eventName, callback) => {
|
|
337
|
+
_core_listen(eventName, callback)
|
|
337
338
|
|
|
338
|
-
|
|
339
|
-
if (eventName === "quit") {
|
|
340
|
-
warn('since v0.203, "quit" event', '"shutdown" event')
|
|
341
|
-
_core_listen("shutdown", callback)
|
|
342
|
-
}
|
|
343
|
-
|
|
344
|
-
ret = () => {
|
|
339
|
+
return () => {
|
|
345
340
|
warnMessage(
|
|
346
|
-
"listen() not returns a function anymore. Please use unlisten(event, callback) instead"
|
|
341
|
+
"listen() not returns a function anymore. Please use unlisten(event, callback) instead."
|
|
347
342
|
)
|
|
348
343
|
_core_unlisten(eventName, callback)
|
|
349
344
|
}
|
|
350
345
|
}
|
|
351
|
-
|
|
352
|
-
_core_listen(eventName, callback)
|
|
353
|
-
|
|
354
|
-
return ret
|
|
355
346
|
}
|
|
356
347
|
|
|
357
348
|
// restore `paused()`
|
|
@@ -365,7 +356,7 @@ export default function plugin(engine, config = {}) {
|
|
|
365
356
|
|
|
366
357
|
function warnMessage(message) {
|
|
367
358
|
if (config.warnings) {
|
|
368
|
-
console.warn(`[litecanvas/migrate] ${message}
|
|
359
|
+
console.warn(`[litecanvas/migrate] ${message}`)
|
|
369
360
|
}
|
|
370
361
|
}
|
|
371
362
|
|
|
@@ -373,7 +364,7 @@ export default function plugin(engine, config = {}) {
|
|
|
373
364
|
warnMessage(
|
|
374
365
|
`${old} is removed. ` +
|
|
375
366
|
(current ? `Please use ${current} instead. ` : "") +
|
|
376
|
-
extra
|
|
367
|
+
extra
|
|
377
368
|
)
|
|
378
369
|
}
|
|
379
370
|
|