@litecanvas/plugin-migrate 0.1.0 → 0.1.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=(r,a="Assertion failed")=>{if(!r)throw new Error(a)};var _=(r,a,c,n,s,p,f,b)=>(o(isFinite(r),"colrect: 1st param must be a number"),o(isFinite(a),"colrect: 2nd param must be a number"),o(isFinite(c),"colrect: 3rd param must be a number"),o(isFinite(n),"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"),r<s+f&&r+c>s&&a<p+b&&a+n>p);var x=(r,a,c,n,s,p)=>(o(isFinite(r),"colcirc: 1st param must be a number"),o(isFinite(a),"colcirc: 2nd param must be a number"),o(isFinite(c),"colcirc: 3rd param must be a number"),o(isFinite(n),"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"),(n-r)*(n-r)+(s-a)*(s-a)<=(c+p)*(c+p));var dt=2*Math.PI;var N=advance=(r,a,c,n=1)=>{c&&(a.x+=c.x*n,a.y+=c.y*n),r.x+=a.x*n,r.y+=a.y*n};var ee=Math.PI/2;var D=4,ae=1<<D,z=8,ne=1<<z;var B={warnings:!0};function g(r,a={}){if(a=Object.assign({},B,a),r.stat(1))throw'Plugin Migrate should be loaded before the "init" event';let n=r.stat(0);function s(t,e,u=""){a.warnings&&console.warn(`[Migrate] warning: ${t} is removed. `+(e?`Use ${e} instead. `:"")+u)}function p(t){return s("seed()","rseed()"),t&&r.rseed(t),r.stat(9)}let f="";function b(t){s("textstyle()","the 5th param of text()"),f=t}let M=r.text;function y(t,e,u,h=3,m=f){M(t,e,u,h,m)}function E(t,e,u,h){s("print()","text()"),y(t,e,u,h)}function T(t,e){s("textmetrics()","ctx().measureText()");let u=r.ctx(),h=r.stat(10),m=r.stat(11);u.font=`${f||""} ${~~(e||h)}px ${m}`;let d=u.measureText(t);return d.height=d.actualBoundingBoxAscent+d.actualBoundingBoxDescent,d}function A(t,e,u,h){s("cliprect()","clip()");let m=r.ctx();m.beginPath(),m.rect(t,e,u,h),m.clip()}function C(t,e,u){s("clipcirc()","clip()");let h=r.ctx();h.beginPath(),h.arc(t,e,u,0,r.TWO_PI),h.clip()}function I(t){s("getcolor()","stat(5)");let e=stat(5);return e[~~t%e.length]}function k(t){s("blendmode()","ctx().globalCompositeOperation");let e=r.ctx();e.globalCompositeOperation=t}function P(t){s("clear()","cls()"),r.cls(t)}function S(t,e,u,h,m,d,X=!0){return s("transform()","ctx().setTransform() or ctx().transform()"),r.ctx()[X?"setTransform":"transform"](t,e,u,h,m,d)}function O(){return s("mousepos()","MX and MY"),[MX,MY]}function L(t){s("setfps()","framerate()"),r.framerate(t)}let i=r.def;function l(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 Y(t,e){s("setvar()","def()"),l(t,e)}r.listen("resized",w);function w(){l("CX",r.W/2),l("CY",r.H/2)}w(),l("CANVAS",r.canvas());function R(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,l("W",t),l("CX",t/2),r.CANVAS.height=e,l("H",e),l("CY",e/2),r.emit("resized",1)}for(let t of["W","H","T","CX","CY","MX","MY"])r[t]!=null&&l(t,r[t]);if(s("FPS","some library to measure the FPS","Recommendation: https://github.com/mrdoob/stats.js/"),i("FPS",""),n.fps&&r.framerate(n.fps),n.background>=0){let t=stat(5);r.CANVAS.style.backgroundColor=t[~~n.background%t.length]}return{def:l,seed:p,print:E,clear:P,setfps:L,setvar:Y,textstyle:b,textmetrics:T,text:y,cliprect:A,clipcirc:C,blendmode:k,transform:S,getcolor:I,mousepos:O,resize:R,colrect:_,colcirc:x}}window.pluginMigrate=g;})();
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] warning: ${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 R(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 F(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","some library to measure the FPS","Recommendation: https://github.com/mrdoob/stats.js/"),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 L(t){return s("path()","`new Path2D`","See https://developer.mozilla.org/en-US/docs/Web/API/Path2D"),new Path2D(t)}let Y=a.fill;function z(t,e){if(s("fill(color, path)"),e instanceof Path2D){let r=a.stat(5),i=a.ctx();i.fillStyle=r[~~t%r.length],a.ctx().fill(e)}else Y(t)}let N=a.stroke;function X(t,e){if(s("stroke(color, path)"),e instanceof Path2D){let r=a.stat(5),i=a.ctx();i.strokeStyle=r[~~t%r.length],a.ctx().stroke(e)}else N(t)}let H=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):H(t)}return{def:u,seed:h,print:M,clear:I,setfps:O,setvar:R,textstyle:b,textmetrics:E,text:y,cliprect:T,clipcirc:A,blendmode:k,transform:S,getcolor:C,mousepos:P,resize:F,path:L,fill:z,stroke:X,clip:D,colrect:_,colcirc:x}}window.pluginMigrate=g;})();
2
2
  /*! pluginMigrate for litecanvas v0.0.1 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.0",
3
+ "version": "0.1.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",
@@ -12,6 +12,7 @@
12
12
  "type": "git",
13
13
  "url": "git+https://github.com/litecanvas/plugin-migrate.git#main"
14
14
  },
15
+ "type": "module",
15
16
  "main": "src/index.js",
16
17
  "keywords": [
17
18
  "litecanvas"
@@ -19,17 +20,30 @@
19
20
  "scripts": {
20
21
  "dev": "esbuild src/_web.js --bundle --watch --outfile=dist/dist.js --servedir=.",
21
22
  "build": "esbuild src/_web.js --bundle --minify --outfile=dist/dist.js",
22
- "prepare": "npm run build"
23
+ "prepare": "npm run build",
24
+ "test": "ava --tap | tap-min"
23
25
  },
24
26
  "devDependencies": {
25
- "esbuild": "^0.25.5"
27
+ "esbuild": "^0.25.5",
28
+ "@litecanvas/jsdom-extras": "^1.1.0",
29
+ "@types/jsdom": "^21.1.7",
30
+ "ava": "^6.4.0",
31
+ "jsdom": "^26.1.0",
32
+ "tap-min": "^3.0.0"
26
33
  },
27
- "peerDependencies": {
28
- "litecanvas": "latest",
34
+ "dependencies": {
29
35
  "@litecanvas/utils": "latest"
30
36
  },
37
+ "peerDependencies": {
38
+ "litecanvas": "latest"
39
+ },
31
40
  "files": [
32
41
  "dist",
33
42
  "src"
34
- ]
43
+ ],
44
+ "ava": {
45
+ "files": [
46
+ "tests/**/*.js"
47
+ ]
48
+ }
35
49
  }
package/src/index.js CHANGED
@@ -216,6 +216,57 @@ export default function plugin(engine, config = {}) {
216
216
  colors[~~settings.background % colors.length]
217
217
  }
218
218
 
219
+ // restore path()
220
+ function path(arg) {
221
+ warn(
222
+ "path()",
223
+ "`new Path2D`",
224
+ "See https://developer.mozilla.org/en-US/docs/Web/API/Path2D"
225
+ )
226
+ return new Path2D(arg)
227
+ }
228
+
229
+ const _core_fill = engine.fill
230
+ function fill(color, path) {
231
+ warn("fill(color, path)")
232
+ if (path instanceof Path2D) {
233
+ const colors = engine.stat(5)
234
+ const _ctx = engine.ctx()
235
+ _ctx.fillStyle = colors[~~color % colors.length]
236
+ engine.ctx().fill(path)
237
+ } else {
238
+ _core_fill(color)
239
+ }
240
+ }
241
+
242
+ const _core_stroke = engine.stroke
243
+ function stroke(color, path) {
244
+ warn("stroke(color, path)")
245
+ if (path instanceof Path2D) {
246
+ const colors = engine.stat(5)
247
+ const _ctx = engine.ctx()
248
+ _ctx.strokeStyle = colors[~~color % colors.length]
249
+ engine.ctx().stroke(path)
250
+ } else {
251
+ _core_stroke(color)
252
+ }
253
+ }
254
+
255
+ const _core_clip = engine.clip
256
+ function clip(pathOrCallback) {
257
+ warn(
258
+ "clip(path)",
259
+ "clip(callback)",
260
+ "E.g: `clip((ctx) => ctx.rect(0, 0, 200, 200))`"
261
+ )
262
+ if (pathOrCallback instanceof Path2D) {
263
+ const _ctx = engine.ctx()
264
+ _ctx.clip(pathOrCallback)
265
+ } else {
266
+ _core_clip(pathOrCallback)
267
+ }
268
+ }
269
+
219
270
  return {
220
271
  def: _def,
221
272
  seed,
@@ -233,6 +284,10 @@ export default function plugin(engine, config = {}) {
233
284
  getcolor,
234
285
  mousepos,
235
286
  resize,
287
+ path,
288
+ fill,
289
+ stroke,
290
+ clip,
236
291
 
237
292
  // restore collision utils
238
293
  colrect,