q5 4.8.0 → 4.8.3
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 +1 -1
- package/package.json +1 -1
- package/q5.d.ts +4 -0
- package/q5.js +45 -14
package/deno.json
CHANGED
package/package.json
CHANGED
package/q5.d.ts
CHANGED
|
@@ -4586,6 +4586,10 @@ declare global {
|
|
|
4586
4586
|
interface Image {
|
|
4587
4587
|
width: number;
|
|
4588
4588
|
height: number;
|
|
4589
|
+
defaultWidth: number;
|
|
4590
|
+
defaultHeight: number;
|
|
4591
|
+
mirrorX: boolean;
|
|
4592
|
+
mirrorY: boolean;
|
|
4589
4593
|
copy(): Q5.Image;
|
|
4590
4594
|
get(x: number, y: number, w?: number, h?: number): Q5.Image | number[];
|
|
4591
4595
|
set(x: number, y: number, val: any): void;
|
package/q5.js
CHANGED
|
@@ -180,11 +180,11 @@ function Q5(scope, parent, renderer) {
|
|
|
180
180
|
}
|
|
181
181
|
$._redraw = false;
|
|
182
182
|
};
|
|
183
|
-
$.remove =
|
|
183
|
+
$.remove = () => {
|
|
184
184
|
$._removed = true;
|
|
185
185
|
$.noLoop();
|
|
186
186
|
if ($.canvas.remove) $.canvas.remove();
|
|
187
|
-
|
|
187
|
+
return runHooks('remove');
|
|
188
188
|
};
|
|
189
189
|
|
|
190
190
|
$.frameRate = (hz) => {
|
|
@@ -1551,14 +1551,15 @@ Q5.renderers.c2d.image = ($, q) => {
|
|
|
1551
1551
|
drawable = img._tintImg.canvas;
|
|
1552
1552
|
}
|
|
1553
1553
|
|
|
1554
|
-
|
|
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 (
|
|
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
|
|
|
@@ -2496,6 +2499,7 @@ Q5.modules.color = ($, q) => {
|
|
|
2496
2499
|
|
|
2497
2500
|
$._namedColors = {
|
|
2498
2501
|
aqua: [0, 255, 255],
|
|
2502
|
+
beige: [245, 245, 220],
|
|
2499
2503
|
black: [0, 0, 0],
|
|
2500
2504
|
blue: [0, 0, 255],
|
|
2501
2505
|
brown: [165, 42, 42],
|
|
@@ -3387,7 +3391,7 @@ Q5.modules.dom = ($, q) => {
|
|
|
3387
3391
|
function extendVideo(vid) {
|
|
3388
3392
|
vid.playsinline = vid.autoplay = true;
|
|
3389
3393
|
if (flipped) {
|
|
3390
|
-
vid.
|
|
3394
|
+
vid.mirrorX = true;
|
|
3391
3395
|
vid.style.transform = 'scale(-1, 1)';
|
|
3392
3396
|
}
|
|
3393
3397
|
vid.loadPixels = () => {
|
|
@@ -3658,9 +3662,20 @@ Q5.modules.input = ($, q) => {
|
|
|
3658
3662
|
$._updateMouse(e);
|
|
3659
3663
|
$.mouseReleased(e);
|
|
3660
3664
|
}
|
|
3661
|
-
if
|
|
3662
|
-
|
|
3663
|
-
|
|
3665
|
+
// if pointer is a touch or the event type is pointercancel or mousecancel
|
|
3666
|
+
if (e.pointerType == 'touch' || e.type.at(-1) == 'l') {
|
|
3667
|
+
removePointer(e);
|
|
3668
|
+
}
|
|
3669
|
+
};
|
|
3670
|
+
|
|
3671
|
+
function removePointer(e) {
|
|
3672
|
+
let p = $.pointers.find((p) => p.id === e.pointerId);
|
|
3673
|
+
if (p) p._ended = true;
|
|
3674
|
+
}
|
|
3675
|
+
|
|
3676
|
+
$._onpointerleave = (e) => {
|
|
3677
|
+
if (e.pointerType == 'pen') {
|
|
3678
|
+
removePointer(e);
|
|
3664
3679
|
}
|
|
3665
3680
|
};
|
|
3666
3681
|
|
|
@@ -3800,6 +3815,7 @@ Q5.modules.input = ($, q) => {
|
|
|
3800
3815
|
l(pointer + 'move', (e) => $._onpointermove(e), false);
|
|
3801
3816
|
l(pointer + 'up', (e) => $._onpointerup(e));
|
|
3802
3817
|
l(pointer + 'cancel', (e) => $._onpointerup(e));
|
|
3818
|
+
l(pointer + 'leave', (e) => $._onpointerleave(e));
|
|
3803
3819
|
l('touchstart', (e) => $._updateTouches(e));
|
|
3804
3820
|
l('touchmove', (e) => $._updateTouches(e));
|
|
3805
3821
|
l('touchend', (e) => $._updateTouches(e));
|
|
@@ -8035,7 +8051,6 @@ fn fragMain(f: FragParams) -> @location(0) vec4f {
|
|
|
8035
8051
|
if (img._texture == undefined) {
|
|
8036
8052
|
isVideo = img.tagName == 'VIDEO';
|
|
8037
8053
|
if (!isVideo || !img.currentTime) return;
|
|
8038
|
-
if (img.flipped) $.scale(-1, 1);
|
|
8039
8054
|
}
|
|
8040
8055
|
|
|
8041
8056
|
if (matrixDirty) saveMatrix();
|
|
@@ -8075,6 +8090,18 @@ fn fragMain(f: FragParams) -> @location(0) vec4f {
|
|
|
8075
8090
|
u1 = (sx + sw) / w,
|
|
8076
8091
|
v1 = (sy + sh) / h;
|
|
8077
8092
|
|
|
8093
|
+
if (img.mirrorX) {
|
|
8094
|
+
let temp = u0;
|
|
8095
|
+
u0 = u1;
|
|
8096
|
+
u1 = temp;
|
|
8097
|
+
}
|
|
8098
|
+
|
|
8099
|
+
if (img.mirrorY) {
|
|
8100
|
+
let temp = v0;
|
|
8101
|
+
v0 = v1;
|
|
8102
|
+
v1 = temp;
|
|
8103
|
+
}
|
|
8104
|
+
|
|
8078
8105
|
let ti = matrixIdx,
|
|
8079
8106
|
ci = tintIdx,
|
|
8080
8107
|
ia = globalAlpha;
|
|
@@ -8109,8 +8136,6 @@ fn fragMain(f: FragParams) -> @location(0) vec4f {
|
|
|
8109
8136
|
);
|
|
8110
8137
|
|
|
8111
8138
|
drawStack.push(videoPL, $._textureBindGroups.length - 1);
|
|
8112
|
-
|
|
8113
|
-
if (img.flipped) $.scale(-1, 1);
|
|
8114
8139
|
}
|
|
8115
8140
|
};
|
|
8116
8141
|
|
|
@@ -8996,7 +9021,7 @@ fn fragMain(f : FragParams) -> @location(0) vec4f {
|
|
|
8996
9021
|
for (let b of $._buffers) b.destroy();
|
|
8997
9022
|
$._buffers = [];
|
|
8998
9023
|
|
|
8999
|
-
_remove();
|
|
9024
|
+
return _remove();
|
|
9000
9025
|
};
|
|
9001
9026
|
};
|
|
9002
9027
|
|
|
@@ -9060,8 +9085,14 @@ Q5._requestGPU = async () => {
|
|
|
9060
9085
|
Q5.MAX_TEXTS = min(Q5.MAX_TEXTS, floor(maxStorage / 32));
|
|
9061
9086
|
|
|
9062
9087
|
device.lost.then((e) => {
|
|
9063
|
-
|
|
9088
|
+
// if purposefully destroyed, do nothing.
|
|
9089
|
+
if (e.reason == 'destroyed') return;
|
|
9090
|
+
// else attempt restart
|
|
9064
9091
|
console.error(e);
|
|
9092
|
+
requestAnimationFrame(async () => {
|
|
9093
|
+
Q5.device = Q5._gpuTask = null;
|
|
9094
|
+
await Q5.initWebGPU();
|
|
9095
|
+
});
|
|
9065
9096
|
});
|
|
9066
9097
|
|
|
9067
9098
|
Q5.device = device;
|