@litecanvas/plugin-migrate 0.2.0 → 0.3.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 +1 -1
- package/package.json +2 -2
- package/src/index.js +29 -4
package/dist/dist.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
(()=>{var o=(a,
|
|
1
|
+
(()=>{var o=(a,l="Assertion failed")=>{if(!a)throw new Error(l)};var _=(a,l,m,c,s,p,f,b)=>(o(isFinite(a),"colrect: 1st param must be a number"),o(isFinite(l),"colrect: 2nd param must be a number"),o(isFinite(m),"colrect: 3rd param must be a number"),o(isFinite(c),"colrect: 4th param must be a number"),o(isFinite(s),"colrect: 5th param must be a number"),o(isFinite(p),"colrect: 6th param must be a number"),o(isFinite(f),"colrect: 7th param must be a number"),o(isFinite(b),"colrect: 8th param must be a number"),a<s+f&&a+m>s&&l<p+b&&l+c>p);var x=(a,l,m,c,s,p)=>(o(isFinite(a),"colcirc: 1st param must be a number"),o(isFinite(l),"colcirc: 2nd param must be a number"),o(isFinite(m),"colcirc: 3rd param must be a number"),o(isFinite(c),"colcirc: 4th param must be a number"),o(isFinite(s),"colcirc: 5th param must be a number"),o(isFinite(p),"colcirc: 6th param must be a number"),(c-a)*(c-a)+(s-l)*(s-l)<=(m+p)*(m+p));var Mt=2*Math.PI;var pe=Math.PI/2;var V={warnings:!0};function v(a,l={}){if(l=Object.assign({},V,l),a.stat(1))throw'Plugin Migrate should be loaded before the "init" event';let c=a.stat(0);function s(t,e,r=""){l.warnings&&console.warn(`[litecanvas/migrate] ${t} is removed. `+(e?`Use ${e} instead. `:"")+r)}function p(t){return s("seed()","rseed()"),t&&a.rseed(t),a.stat(9)}let f="";function b(t){s("textstyle()","the 5th param of text()"),f=t}let w=a.text;function g(t,e,r,n=3,u=f){w(t,e,r,n,u)}function E(t,e,r,n){s("print()","text()"),g(t,e,r,n)}function M(t,e){s("textmetrics()","ctx().measureText()");let r=a.ctx(),n=a.stat(10),u=a.stat(11);r.font=`${f||""} ${~~(e||n)}px ${u}`;let d=r.measureText(t);return d.height=d.actualBoundingBoxAscent+d.actualBoundingBoxDescent,d}function I(t,e,r,n){s("cliprect()","clip()");let u=a.ctx();u.beginPath(),u.rect(t,e,r,n),u.clip()}function T(t,e,r){s("clipcirc()","clip()");let n=a.ctx();n.beginPath(),n.arc(t,e,r,0,a.TWO_PI),n.clip()}function A(t){s("getcolor()","stat(5)");let e=stat(5);return e[~~t%e.length]}function P(t){s("blendmode()","ctx().globalCompositeOperation");let e=a.ctx();e.globalCompositeOperation=t}function R(t){s("clear()","cls()"),a.cls(t)}function S(t,e,r,n,u,d,U=!0){return s("transform()","ctx().setTransform() or ctx().transform()"),a.ctx()[U?"setTransform":"transform"](t,e,r,n,u,d)}function k(){return s("mousepos()","MX and MY"),[MX,MY]}function C(t){s("setfps()","framerate()"),a.framerate(t)}let i=a.def;function h(t,e){switch(t){case"W":case"WIDTH":i("W",e),i("WIDTH",e);break;case"H":case"HEIGHT":i("H",e),i("HEIGHT",e);break;case"T":case"ELAPSED":i("T",e),i("ELAPSED",e);break;case"CX":case"CENTERX":i("CX",e),i("CENTERX",e);break;case"CY":case"CENTERY":i("CY",e),i("CENTERY",e);break;case"MX":case"MOUSEX":i("MX",e),i("MOUSEX",e);break;case"MY":case"MOUSEY":i("MY",e),i("MOUSEY",e);break;default:i(t,e);break}}function L(t,e){s("setvar()","def()"),h(t,e)}a.listen("resized",y);function y(){h("CX",a.W/2),h("CY",a.H/2)}y(),h("CANVAS",a.canvas());function N(t,e){if(c.autoscale)throw"resize() don't works with autoscale enabled";s("resize()",null,"Avoid changing the canvas dimensions at runtime."),a.CANVAS.width=t,h("W",t),h("CX",t/2),a.CANVAS.height=e,h("H",e),h("CY",e/2),a.emit("resized",1)}for(let t of["W","H","T","CX","CY","MX","MY"])a[t]!=null&&h(t,a[t]);if(s("FPS","","but you can use our plugin to measure the fps: https://github.com/litecanvas/plugin-frame-rate-meter"),i("FPS",""),c.fps&&a.framerate(c.fps),c.background!=null){let t=a.listen("before:draw",()=>{let e=stat(5);a.canvas().style.background=e[~~c.background%e.length],t()})}function O(t){return s("path()","`new Path2D`","See https://developer.mozilla.org/en-US/docs/Web/API/Path2D"),new Path2D(t)}let F=a.fill;function z(t,e){if(e instanceof Path2D){s("fill(color, path)");let r=a.stat(5),n=a.ctx();n.fillStyle=r[~~t%r.length],a.ctx().fill(e)}else F(t)}let Y=a.stroke;function D(t,e){if(e instanceof Path2D){s("stroke(color, path)");let r=a.stat(5),n=a.ctx();n.strokeStyle=r[~~t%r.length],a.ctx().stroke(e)}else Y(t)}let H=a.clip;function W(t){s("clip(path)","clip(callback)","E.g: `clip((ctx) => ctx.rect(0, 0, 200, 200))`"),t instanceof Path2D?a.ctx().clip(t):H(t)}c.antialias&&s('"antialias" option','"pixelart" option'),c.pixelart===!1&&s('"pixelart" option'),c.animate===!1&&s('"animate" option',"pause() in the of your draw()");let B=a.paint;function X(t,e,r,n){let u=r;return a.spr&&Array.isArray(r)&&(u=()=>{a.spr(0,0,t,e,r.join("").replace(/ /g,"."))}),B(t,e,u,n)}return{def:h,seed:p,print:E,clear:R,setfps:C,setvar:L,textstyle:b,textmetrics:M,text:g,cliprect:I,clipcirc:T,blendmode:P,transform:S,getcolor:A,mousepos:k,resize:N,path:O,fill:z,stroke:D,clip:W,paint:X,colrect:_,colcirc:x}}window.pluginMigrate=v;})();
|
|
2
2
|
/*! 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.3.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",
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
"test": "ava --tap | tap-min"
|
|
25
25
|
},
|
|
26
26
|
"devDependencies": {
|
|
27
|
-
"esbuild": "^0.25.
|
|
27
|
+
"esbuild": "^0.25.8",
|
|
28
28
|
"@litecanvas/jsdom-extras": "^1.1.0",
|
|
29
29
|
"@types/jsdom": "^21.1.7",
|
|
30
30
|
"ava": "^6.4.1",
|
package/src/index.js
CHANGED
|
@@ -177,6 +177,7 @@ export default function plugin(engine, config = {}) {
|
|
|
177
177
|
// restore CANVAS removed in v0.84
|
|
178
178
|
_def("CANVAS", engine.canvas())
|
|
179
179
|
|
|
180
|
+
// restore a semi-version of the `resize()`
|
|
180
181
|
function resize(width, height) {
|
|
181
182
|
if (settings.autoscale) {
|
|
182
183
|
throw "resize() don't works with autoscale enabled"
|
|
@@ -211,10 +212,14 @@ export default function plugin(engine, config = {}) {
|
|
|
211
212
|
engine.framerate(settings.fps)
|
|
212
213
|
}
|
|
213
214
|
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
engine.
|
|
217
|
-
colors
|
|
215
|
+
// restore the "background" option
|
|
216
|
+
if (settings.background != null) {
|
|
217
|
+
const removeThisListener = engine.listen("before:draw", () => {
|
|
218
|
+
const colors = stat(5)
|
|
219
|
+
engine.canvas().style.background =
|
|
220
|
+
colors[~~settings.background % colors.length]
|
|
221
|
+
removeThisListener()
|
|
222
|
+
})
|
|
218
223
|
}
|
|
219
224
|
|
|
220
225
|
// restore path()
|
|
@@ -272,6 +277,25 @@ export default function plugin(engine, config = {}) {
|
|
|
272
277
|
warn('"antialias" option', '"pixelart" option')
|
|
273
278
|
}
|
|
274
279
|
|
|
280
|
+
if (false === settings.pixelart) {
|
|
281
|
+
warn('"pixelart" option')
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
if (false === settings.animate) {
|
|
285
|
+
warn('"animate" option', "pause() in the of your draw()")
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
const _core_paint = engine.paint
|
|
289
|
+
function paint(w, h, data, options) {
|
|
290
|
+
let cb = data
|
|
291
|
+
if (engine.spr && Array.isArray(data)) {
|
|
292
|
+
cb = () => {
|
|
293
|
+
engine.spr(0, 0, w, h, data.join("").replace(/ /g, "."))
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
return _core_paint(w, h, cb, options)
|
|
297
|
+
}
|
|
298
|
+
|
|
275
299
|
return {
|
|
276
300
|
def: _def,
|
|
277
301
|
seed,
|
|
@@ -293,6 +317,7 @@ export default function plugin(engine, config = {}) {
|
|
|
293
317
|
fill,
|
|
294
318
|
stroke,
|
|
295
319
|
clip,
|
|
320
|
+
paint,
|
|
296
321
|
|
|
297
322
|
// restore collision utils
|
|
298
323
|
colrect,
|