q5 4.7.5 → 4.8.2

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/deno.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@q5/q5",
3
- "version": "4.7.5",
3
+ "version": "4.8.2",
4
4
  "license": "LGPL-3.0-only",
5
5
  "description": "Beginner friendly graphics powered by WebGPU, optimized for interactive art!",
6
6
  "author": "quinton-ashley",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "q5",
3
- "version": "4.7.5",
3
+ "version": "4.8.2",
4
4
  "description": "Beginner friendly graphics powered by WebGPU, optimized for interactive art!",
5
5
  "author": "quinton-ashley",
6
6
  "license": "LGPL-3.0-only",
package/q5-deno-server.js CHANGED
@@ -28,6 +28,8 @@ Q5._createServerCanvas = function () {
28
28
  let skiaCanvas = createCanvas(...arguments);
29
29
  let domCanvas = document.createElement('canvas');
30
30
 
31
+ skiaCanvas.save = skiaCanvas.toFileSync;
32
+
31
33
  return new Proxy(skiaCanvas, {
32
34
  get: function (target, prop) {
33
35
  let t = prop in target ? target : domCanvas;
package/q5-server.js CHANGED
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * @module q5-server
3
- * @description Run q5 with node.js using node-canvas and jsdom
3
+ * @description Run q5 with node.js using skia-canvas and jsdom
4
4
  */
5
5
 
6
6
  let depsLoaded = false;
@@ -36,7 +36,7 @@ if (depsLoaded) {
36
36
  let skiaCanvas = new SkiaCanvas.Canvas(...arguments);
37
37
  let domCanvas = document.createElement('canvas');
38
38
 
39
- skiaCanvas.save = skiaCanvas.saveAsSync;
39
+ skiaCanvas.save = skiaCanvas.toFileSync;
40
40
 
41
41
  return new Proxy(skiaCanvas, {
42
42
  get: function (target, prop) {
package/q5.d.ts CHANGED
@@ -1,3 +1,7 @@
1
+ /**
2
+ * @module q5
3
+ */
4
+
1
5
  declare global {
2
6
 
3
7
  // ⭐ core
@@ -4582,6 +4586,10 @@ declare global {
4582
4586
  interface Image {
4583
4587
  width: number;
4584
4588
  height: number;
4589
+ defaultWidth: number;
4590
+ defaultHeight: number;
4591
+ mirrorX: boolean;
4592
+ mirrorY: boolean;
4585
4593
  copy(): Q5.Image;
4586
4594
  get(x: number, y: number, w?: number, h?: number): Q5.Image | number[];
4587
4595
  set(x: number, y: number, val: any): void;
package/q5.js CHANGED
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * q5.js
3
- * @version 4.7
3
+ * @version 4.8
4
4
  * @author quinton-ashley
5
5
  * @contributors evanalulu, Tezumie, keturn, ormaq, bertubi, RedWilly, Dukemz, LingDong-
6
6
  * @license LGPL-3.0
@@ -494,7 +494,7 @@ if (typeof window == 'object') {
494
494
  window.addEventListener('pagehide', cleanup);
495
495
  } else global.window = 0;
496
496
 
497
- Q5.version = Q5.VERSION = '4.7';
497
+ Q5.version = Q5.VERSION = '4.8';
498
498
 
499
499
  if (typeof document == 'object') {
500
500
  function init() {
@@ -1551,14 +1551,15 @@ Q5.renderers.c2d.image = ($, q) => {
1551
1551
  drawable = img._tintImg.canvas;
1552
1552
  }
1553
1553
 
1554
- if (img.flipped) {
1554
+ let mirrored = img.mirrorX || img.mirrorY;
1555
+ if (mirrored) {
1555
1556
  $.ctx.save();
1556
1557
  $.ctx.translate(dx + dw, 0);
1557
- $.ctx.scale(-1, 1);
1558
+ $.ctx.scale(img.mirrorX ? -1 : 1, img.mirrorY ? -1 : 1);
1558
1559
  dx = 0;
1559
1560
  }
1560
1561
  $.ctx.drawImage(drawable, sx * pd, sy * pd, sw, sh, dx, dy, dw, dh);
1561
- if (img.flipped) $.ctx.restore();
1562
+ if (mirrored) $.ctx.restore();
1562
1563
  };
1563
1564
 
1564
1565
  $.filter = (type, value) => {
@@ -1800,6 +1801,8 @@ Q5.Image = class {
1800
1801
  let scale = $._pixelDensity * $._defaultImageScale;
1801
1802
  $.defaultWidth = w * scale;
1802
1803
  $.defaultHeight = h * scale;
1804
+ $.mirrorX = false;
1805
+ $.mirrorY = false;
1803
1806
  delete $.createCanvas;
1804
1807
  $._loop = false;
1805
1808
 
@@ -3387,7 +3390,7 @@ Q5.modules.dom = ($, q) => {
3387
3390
  function extendVideo(vid) {
3388
3391
  vid.playsinline = vid.autoplay = true;
3389
3392
  if (flipped) {
3390
- vid.flipped = true;
3393
+ vid.mirrorX = true;
3391
3394
  vid.style.transform = 'scale(-1, 1)';
3392
3395
  }
3393
3396
  vid.loadPixels = () => {
@@ -3658,9 +3661,20 @@ Q5.modules.input = ($, q) => {
3658
3661
  $._updateMouse(e);
3659
3662
  $.mouseReleased(e);
3660
3663
  }
3661
- if (e.pointerType == 'touch' || e.pointerType == 'pen') {
3662
- let p = $.pointers.find((p) => p.id === e.pointerId);
3663
- if (p) p._ended = true;
3664
+ // if pointer is a touch or the event type is pointercancel or mousecancel
3665
+ if (e.pointerType == 'touch' || e.type.at(-1) == 'l') {
3666
+ removePointer(e);
3667
+ }
3668
+ };
3669
+
3670
+ function removePointer(e) {
3671
+ let p = $.pointers.find((p) => p.id === e.pointerId);
3672
+ if (p) p._ended = true;
3673
+ }
3674
+
3675
+ $._onpointerleave = (e) => {
3676
+ if (e.pointerType == 'pen') {
3677
+ removePointer(e);
3664
3678
  }
3665
3679
  };
3666
3680
 
@@ -3800,6 +3814,7 @@ Q5.modules.input = ($, q) => {
3800
3814
  l(pointer + 'move', (e) => $._onpointermove(e), false);
3801
3815
  l(pointer + 'up', (e) => $._onpointerup(e));
3802
3816
  l(pointer + 'cancel', (e) => $._onpointerup(e));
3817
+ l(pointer + 'leave', (e) => $._onpointerleave(e));
3803
3818
  l('touchstart', (e) => $._updateTouches(e));
3804
3819
  l('touchmove', (e) => $._updateTouches(e));
3805
3820
  l('touchend', (e) => $._updateTouches(e));
@@ -8035,7 +8050,6 @@ fn fragMain(f: FragParams) -> @location(0) vec4f {
8035
8050
  if (img._texture == undefined) {
8036
8051
  isVideo = img.tagName == 'VIDEO';
8037
8052
  if (!isVideo || !img.currentTime) return;
8038
- if (img.flipped) $.scale(-1, 1);
8039
8053
  }
8040
8054
 
8041
8055
  if (matrixDirty) saveMatrix();
@@ -8075,6 +8089,18 @@ fn fragMain(f: FragParams) -> @location(0) vec4f {
8075
8089
  u1 = (sx + sw) / w,
8076
8090
  v1 = (sy + sh) / h;
8077
8091
 
8092
+ if (img.mirrorX) {
8093
+ let temp = u0;
8094
+ u0 = u1;
8095
+ u1 = temp;
8096
+ }
8097
+
8098
+ if (img.mirrorY) {
8099
+ let temp = v0;
8100
+ v0 = v1;
8101
+ v1 = temp;
8102
+ }
8103
+
8078
8104
  let ti = matrixIdx,
8079
8105
  ci = tintIdx,
8080
8106
  ia = globalAlpha;
@@ -8109,8 +8135,6 @@ fn fragMain(f: FragParams) -> @location(0) vec4f {
8109
8135
  );
8110
8136
 
8111
8137
  drawStack.push(videoPL, $._textureBindGroups.length - 1);
8112
-
8113
- if (img.flipped) $.scale(-1, 1);
8114
8138
  }
8115
8139
  };
8116
8140