@litecanvas/plugin-migrate 0.1.4 → 0.2.1

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,2 +1,2 @@
1
- (()=>{var o=(a,c="Assertion failed")=>{if(!a)throw new Error(c)};var _=(a,c,m,l,s,h,f,b)=>(o(isFinite(a),"colrect: 1st param must be a number"),o(isFinite(c),"colrect: 2nd param must be a number"),o(isFinite(m),"colrect: 3rd param must be a number"),o(isFinite(l),"colrect: 4th param must be a number"),o(isFinite(s),"colrect: 5th param must be a number"),o(isFinite(h),"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&&c<h+b&&c+l>h);var x=(a,c,m,l,s,h)=>(o(isFinite(a),"colcirc: 1st param must be a number"),o(isFinite(c),"colcirc: 2nd param must be a number"),o(isFinite(m),"colcirc: 3rd param must be a number"),o(isFinite(l),"colcirc: 4th param must be a number"),o(isFinite(s),"colcirc: 5th param must be a number"),o(isFinite(h),"colcirc: 6th param must be a number"),(l-a)*(l-a)+(s-c)*(s-c)<=(m+h)*(m+h));var Et=2*Math.PI;var he=Math.PI/2;var $=4,fe=1<<$,V=8,de=1<<V;var j={warnings:!0};function g(a,c={}){if(c=Object.assign({},j,c),a.stat(1))throw'Plugin Migrate should be loaded before the "init" event';let l=a.stat(0);function s(t,e,r=""){c.warnings&&console.warn(`[migrate] ${t} is removed. `+(e?`Use ${e} instead. `:"")+r)}function h(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 y(t,e,r,i=3,p=f){w(t,e,r,i,p)}function M(t,e,r,i){s("print()","text()"),y(t,e,r,i)}function E(t,e){s("textmetrics()","ctx().measureText()");let r=a.ctx(),i=a.stat(10),p=a.stat(11);r.font=`${f||""} ${~~(e||i)}px ${p}`;let d=r.measureText(t);return d.height=d.actualBoundingBoxAscent+d.actualBoundingBoxDescent,d}function T(t,e,r,i){s("cliprect()","clip()");let p=a.ctx();p.beginPath(),p.rect(t,e,r,i),p.clip()}function A(t,e,r){s("clipcirc()","clip()");let i=a.ctx();i.beginPath(),i.arc(t,e,r,0,a.TWO_PI),i.clip()}function C(t){s("getcolor()","stat(5)");let e=stat(5);return e[~~t%e.length]}function k(t){s("blendmode()","ctx().globalCompositeOperation");let e=a.ctx();e.globalCompositeOperation=t}function I(t){s("clear()","cls()"),a.cls(t)}function S(t,e,r,i,p,d,B=!0){return s("transform()","ctx().setTransform() or ctx().transform()"),a.ctx()[B?"setTransform":"transform"](t,e,r,i,p,d)}function P(){return s("mousepos()","MX and MY"),[MX,MY]}function O(t){s("setfps()","framerate()"),a.framerate(t)}let n=a.def;function u(t,e){switch(t){case"W":case"WIDTH":n("W",e),n("WIDTH",e);break;case"H":case"HEIGHT":n("H",e),n("HEIGHT",e);break;case"T":case"ELAPSED":n("T",e),n("ELAPSED",e);break;case"CX":case"CENTERX":n("CX",e),n("CENTERX",e);break;case"CY":case"CENTERY":n("CY",e),n("CENTERY",e);break;case"MX":case"MOUSEX":n("MX",e),n("MOUSEX",e);break;case"MY":case"MOUSEY":n("MY",e),n("MOUSEY",e);break;default:n(t,e);break}}function L(t,e){s("setvar()","def()"),u(t,e)}a.listen("resized",v);function v(){u("CX",a.W/2),u("CY",a.H/2)}v(),u("CANVAS",a.canvas());function R(t,e){if(l.autoscale)throw"resize() don't works with autoscale enabled";s("resize()",null,"Avoid changing the canvas dimensions at runtime."),a.CANVAS.width=t,u("W",t),u("CX",t/2),a.CANVAS.height=e,u("H",e),u("CY",e/2),a.emit("resized",1)}for(let t of["W","H","T","CX","CY","MX","MY"])a[t]!=null&&u(t,a[t]);if(s("FPS","","but you can use our plugin to measure the fps: https://github.com/litecanvas/plugin-frame-rate-meter"),n("FPS",""),l.fps&&a.framerate(l.fps),l.background>=0){let t=stat(5);a.CANVAS.style.backgroundColor=t[~~l.background%t.length]}function F(t){return s("path()","`new Path2D`","See https://developer.mozilla.org/en-US/docs/Web/API/Path2D"),new Path2D(t)}let z=a.fill;function N(t,e){if(e instanceof Path2D){s("fill(color, path)");let r=a.stat(5),i=a.ctx();i.fillStyle=r[~~t%r.length],a.ctx().fill(e)}else z(t)}let Y=a.stroke;function H(t,e){if(e instanceof Path2D){s("stroke(color, path)");let r=a.stat(5),i=a.ctx();i.strokeStyle=r[~~t%r.length],a.ctx().stroke(e)}else Y(t)}let X=a.clip;function D(t){s("clip(path)","clip(callback)","E.g: `clip((ctx) => ctx.rect(0, 0, 200, 200))`"),t instanceof Path2D?a.ctx().clip(t):X(t)}return{def:u,seed:h,print:M,clear:I,setfps:O,setvar:L,textstyle:b,textmetrics:E,text:y,cliprect:T,clipcirc:A,blendmode:k,transform:S,getcolor:C,mousepos:P,resize:R,path:F,fill:N,stroke:H,clip:D,colrect:_,colcirc:x}}window.pluginMigrate=g;})();
2
- /*! pluginMigrate for litecanvas by Luiz Bills | MIT Licensed */
1
+ (()=>{var o=(a,c="Assertion failed")=>{if(!a)throw new Error(c)};var _=(a,c,m,l,s,h,f,b)=>(o(isFinite(a),"colrect: 1st param must be a number"),o(isFinite(c),"colrect: 2nd param must be a number"),o(isFinite(m),"colrect: 3rd param must be a number"),o(isFinite(l),"colrect: 4th param must be a number"),o(isFinite(s),"colrect: 5th param must be a number"),o(isFinite(h),"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&&c<h+b&&c+l>h);var x=(a,c,m,l,s,h)=>(o(isFinite(a),"colcirc: 1st param must be a number"),o(isFinite(c),"colcirc: 2nd param must be a number"),o(isFinite(m),"colcirc: 3rd param must be a number"),o(isFinite(l),"colcirc: 4th param must be a number"),o(isFinite(s),"colcirc: 5th param must be a number"),o(isFinite(h),"colcirc: 6th param must be a number"),(l-a)*(l-a)+(s-c)*(s-c)<=(m+h)*(m+h));var wt=2*Math.PI;var oe=Math.PI/2;var Z={warnings:!0};function v(a,c={}){if(c=Object.assign({},Z,c),a.stat(1))throw'Plugin Migrate should be loaded before the "init" event';let l=a.stat(0);function s(t,e,r=""){c.warnings&&console.warn(`[litecanvas/migrate] ${t} is removed. `+(e?`Use ${e} instead. `:"")+r)}function h(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,i=3,p=f){w(t,e,r,i,p)}function E(t,e,r,i){s("print()","text()"),g(t,e,r,i)}function M(t,e){s("textmetrics()","ctx().measureText()");let r=a.ctx(),i=a.stat(10),p=a.stat(11);r.font=`${f||""} ${~~(e||i)}px ${p}`;let d=r.measureText(t);return d.height=d.actualBoundingBoxAscent+d.actualBoundingBoxDescent,d}function I(t,e,r,i){s("cliprect()","clip()");let p=a.ctx();p.beginPath(),p.rect(t,e,r,i),p.clip()}function A(t,e,r){s("clipcirc()","clip()");let i=a.ctx();i.beginPath(),i.arc(t,e,r,0,a.TWO_PI),i.clip()}function T(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 C(t,e,r,i,p,d,D=!0){return s("transform()","ctx().setTransform() or ctx().transform()"),a.ctx()[D?"setTransform":"transform"](t,e,r,i,p,d)}function S(){return s("mousepos()","MX and MY"),[MX,MY]}function k(t){s("setfps()","framerate()"),a.framerate(t)}let n=a.def;function u(t,e){switch(t){case"W":case"WIDTH":n("W",e),n("WIDTH",e);break;case"H":case"HEIGHT":n("H",e),n("HEIGHT",e);break;case"T":case"ELAPSED":n("T",e),n("ELAPSED",e);break;case"CX":case"CENTERX":n("CX",e),n("CENTERX",e);break;case"CY":case"CENTERY":n("CY",e),n("CENTERY",e);break;case"MX":case"MOUSEX":n("MX",e),n("MOUSEX",e);break;case"MY":case"MOUSEY":n("MY",e),n("MOUSEY",e);break;default:n(t,e);break}}function L(t,e){s("setvar()","def()"),u(t,e)}a.listen("resized",y);function y(){u("CX",a.W/2),u("CY",a.H/2)}y(),u("CANVAS",a.canvas());function N(t,e){if(l.autoscale)throw"resize() don't works with autoscale enabled";s("resize()",null,"Avoid changing the canvas dimensions at runtime."),a.CANVAS.width=t,u("W",t),u("CX",t/2),a.CANVAS.height=e,u("H",e),u("CY",e/2),a.emit("resized",1)}for(let t of["W","H","T","CX","CY","MX","MY"])a[t]!=null&&u(t,a[t]);if(s("FPS","","but you can use our plugin to measure the fps: https://github.com/litecanvas/plugin-frame-rate-meter"),n("FPS",""),l.fps&&a.framerate(l.fps),l.background!=null){let t=a.listen("before:draw",()=>{let e=stat(5);a.canvas().style.background=e[~~l.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 z=a.fill;function F(t,e){if(e instanceof Path2D){s("fill(color, path)");let r=a.stat(5),i=a.ctx();i.fillStyle=r[~~t%r.length],a.ctx().fill(e)}else z(t)}let Y=a.stroke;function H(t,e){if(e instanceof Path2D){s("stroke(color, path)");let r=a.stat(5),i=a.ctx();i.strokeStyle=r[~~t%r.length],a.ctx().stroke(e)}else Y(t)}let W=a.clip;function B(t){s("clip(path)","clip(callback)","E.g: `clip((ctx) => ctx.rect(0, 0, 200, 200))`"),t instanceof Path2D?a.ctx().clip(t):W(t)}return l.antialias&&s('"antialias" option','"pixelart" option'),{def:u,seed:h,print:E,clear:R,setfps:k,setvar:L,textstyle:b,textmetrics:M,text:g,cliprect:I,clipcirc:A,blendmode:P,transform:C,getcolor:T,mousepos:S,resize:N,path:O,fill:F,stroke:H,clip:B,colrect:_,colcirc:x}}window.pluginMigrate=v;})();
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.1.4",
3
+ "version": "0.2.1",
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,10 +24,10 @@
24
24
  "test": "ava --tap | tap-min"
25
25
  },
26
26
  "devDependencies": {
27
- "esbuild": "^0.25.6",
27
+ "esbuild": "^0.25.8",
28
28
  "@litecanvas/jsdom-extras": "^1.1.0",
29
29
  "@types/jsdom": "^21.1.7",
30
- "ava": "^6.4.0",
30
+ "ava": "^6.4.1",
31
31
  "jsdom": "^26.1.0",
32
32
  "tap-min": "^3.0.0"
33
33
  },
package/src/_web.js CHANGED
@@ -1,4 +1,4 @@
1
1
  import plugin from "."
2
2
 
3
- /*! pluginMigrate for litecanvas by Luiz Bills | MIT Licensed */
3
+ /*! Migrate for litecanvas by Luiz Bills | MIT Licensed */
4
4
  window.pluginMigrate = plugin
package/src/index.js CHANGED
@@ -20,12 +20,13 @@ export default function plugin(engine, config = {}) {
20
20
  throw 'Plugin Migrate should be loaded before the "init" event'
21
21
  }
22
22
 
23
+ /** @type {LitecanvasOptions} */
23
24
  const settings = engine.stat(0)
24
25
 
25
26
  function warn(old, current, extra = "") {
26
27
  if (config.warnings)
27
28
  console.warn(
28
- `[migrate] ${old} is removed. ` +
29
+ `[litecanvas/migrate] ${old} is removed. ` +
29
30
  (current ? `Use ${current} instead. ` : "") +
30
31
  extra
31
32
  )
@@ -176,6 +177,7 @@ export default function plugin(engine, config = {}) {
176
177
  // restore CANVAS removed in v0.84
177
178
  _def("CANVAS", engine.canvas())
178
179
 
180
+ // restore a semi-version of the `resize()`
179
181
  function resize(width, height) {
180
182
  if (settings.autoscale) {
181
183
  throw "resize() don't works with autoscale enabled"
@@ -210,10 +212,14 @@ export default function plugin(engine, config = {}) {
210
212
  engine.framerate(settings.fps)
211
213
  }
212
214
 
213
- if (settings.background >= 0) {
214
- const colors = stat(5)
215
- engine.CANVAS.style.backgroundColor =
216
- colors[~~settings.background % colors.length]
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
+ })
217
223
  }
218
224
 
219
225
  // restore path()
@@ -267,6 +273,10 @@ export default function plugin(engine, config = {}) {
267
273
  }
268
274
  }
269
275
 
276
+ if (settings.antialias) {
277
+ warn('"antialias" option', '"pixelart" option')
278
+ }
279
+
270
280
  return {
271
281
  def: _def,
272
282
  seed,