@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 +2 -2
- package/package.json +1 -1
- package/src/index.js +14 -37
package/dist/dist.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
(()=>{var _=(
|
|
2
|
-
`))}),
|
|
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.
|
|
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
|
-
|
|
336
|
-
|
|
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
|
-
|
|
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
|
|