q5 3.6.4 → 3.6.8
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/defs/q5-c2d.d.ts +52 -40
- package/deno.json +1 -1
- package/package.json +1 -1
- package/q5.d.ts +52 -40
- package/q5.js +57 -32
- package/q5.min.js +1 -1
package/q5.js
CHANGED
|
@@ -276,7 +276,6 @@ function Q5(scope, parent, renderer) {
|
|
|
276
276
|
let t = globalScope || $;
|
|
277
277
|
|
|
278
278
|
let userFns = [
|
|
279
|
-
'preload',
|
|
280
279
|
'postProcess',
|
|
281
280
|
'mouseMoved',
|
|
282
281
|
'mousePressed',
|
|
@@ -291,13 +290,18 @@ function Q5(scope, parent, renderer) {
|
|
|
291
290
|
'touchStarted',
|
|
292
291
|
'touchMoved',
|
|
293
292
|
'touchEnded',
|
|
294
|
-
'windowResized'
|
|
293
|
+
'windowResized',
|
|
294
|
+
'preload'
|
|
295
295
|
];
|
|
296
296
|
// shim if undefined
|
|
297
297
|
for (let name of userFns) $[name] ??= () => {};
|
|
298
298
|
|
|
299
|
+
userFns.pop();
|
|
300
|
+
|
|
301
|
+
let allUserFns = ['update', 'draw', 'drawFrame', ...userFns];
|
|
302
|
+
|
|
299
303
|
if ($._isGlobal) {
|
|
300
|
-
for (let name of
|
|
304
|
+
for (let name of allUserFns) {
|
|
301
305
|
if (Q5[name]) $[name] = Q5[name];
|
|
302
306
|
else {
|
|
303
307
|
Object.defineProperty(Q5, name, {
|
|
@@ -460,7 +464,7 @@ Q5.version = Q5.VERSION = '3.6';
|
|
|
460
464
|
if (typeof document == 'object') {
|
|
461
465
|
document.addEventListener('DOMContentLoaded', () => {
|
|
462
466
|
if (!Q5._hasGlobal) {
|
|
463
|
-
if (Q5.
|
|
467
|
+
if (Q5.update || Q5.draw) {
|
|
464
468
|
Q5.WebGPU();
|
|
465
469
|
} else {
|
|
466
470
|
new Q5('auto');
|
|
@@ -1424,7 +1428,6 @@ Q5.renderers.c2d.image = ($, q) => {
|
|
|
1424
1428
|
|
|
1425
1429
|
g.promise = new Promise((resolve, reject) => {
|
|
1426
1430
|
img.onload = () => {
|
|
1427
|
-
delete g.promise;
|
|
1428
1431
|
delete g.then;
|
|
1429
1432
|
if (g._usedAwait) g = $.createImage(1, 1, opt);
|
|
1430
1433
|
|
|
@@ -1659,7 +1662,7 @@ Q5.renderers.c2d.image = ($, q) => {
|
|
|
1659
1662
|
img.ctx.drawImage(c, x, y, w * pd, h * pd, 0, 0, w, h);
|
|
1660
1663
|
img.width = w;
|
|
1661
1664
|
img.height = h;
|
|
1662
|
-
if (
|
|
1665
|
+
if ($?._owner._makeDrawable) $._owner._makeDrawable(img);
|
|
1663
1666
|
return img;
|
|
1664
1667
|
};
|
|
1665
1668
|
|
|
@@ -1674,15 +1677,29 @@ Q5.renderers.c2d.image = ($, q) => {
|
|
|
1674
1677
|
$._tint = old;
|
|
1675
1678
|
return;
|
|
1676
1679
|
}
|
|
1680
|
+
|
|
1677
1681
|
if (!pixels) $.loadPixels();
|
|
1678
|
-
|
|
1682
|
+
|
|
1683
|
+
let mod = $._pixelDensity || 1,
|
|
1684
|
+
r = val.r,
|
|
1685
|
+
g = val.g,
|
|
1686
|
+
b = val.b,
|
|
1687
|
+
a = val.a;
|
|
1688
|
+
|
|
1689
|
+
if (($._colorFormat || $._owner?._colorFormat) == 1) {
|
|
1690
|
+
r *= 255;
|
|
1691
|
+
g *= 255;
|
|
1692
|
+
b *= 255;
|
|
1693
|
+
a *= 255;
|
|
1694
|
+
}
|
|
1695
|
+
|
|
1679
1696
|
for (let i = 0; i < mod; i++) {
|
|
1680
1697
|
for (let j = 0; j < mod; j++) {
|
|
1681
1698
|
let idx = 4 * ((y * mod + i) * c.width + x * mod + j);
|
|
1682
|
-
pixels[idx] =
|
|
1683
|
-
pixels[idx + 1] =
|
|
1684
|
-
pixels[idx + 2] =
|
|
1685
|
-
pixels[idx + 3] =
|
|
1699
|
+
pixels[idx] = r;
|
|
1700
|
+
pixels[idx + 1] = g;
|
|
1701
|
+
pixels[idx + 2] = b;
|
|
1702
|
+
pixels[idx + 3] = a;
|
|
1686
1703
|
}
|
|
1687
1704
|
}
|
|
1688
1705
|
};
|
|
@@ -1916,7 +1933,6 @@ Q5.renderers.c2d.text = ($, q) => {
|
|
|
1916
1933
|
f.promise = new Promise((resolve, reject) => {
|
|
1917
1934
|
ff.load()
|
|
1918
1935
|
.then(() => {
|
|
1919
|
-
delete f.promise;
|
|
1920
1936
|
delete f.then;
|
|
1921
1937
|
if (cb) cb(ff);
|
|
1922
1938
|
resolve(ff);
|
|
@@ -2004,7 +2020,6 @@ Q5.renderers.c2d.text = ($, q) => {
|
|
|
2004
2020
|
}
|
|
2005
2021
|
|
|
2006
2022
|
f.faces = loadedFaces;
|
|
2007
|
-
delete f.promise;
|
|
2008
2023
|
delete f.then;
|
|
2009
2024
|
if (cb) cb(f);
|
|
2010
2025
|
return f;
|
|
@@ -3178,7 +3193,6 @@ Q5.modules.dom = ($, q) => {
|
|
|
3178
3193
|
if (src) {
|
|
3179
3194
|
el.promise = new Promise((resolve) => {
|
|
3180
3195
|
el.addEventListener('loadeddata', () => {
|
|
3181
|
-
delete el.promise;
|
|
3182
3196
|
delete el.then;
|
|
3183
3197
|
if (el._usedAwait) {
|
|
3184
3198
|
el = $.createEl('video');
|
|
@@ -3233,7 +3247,6 @@ Q5.modules.dom = ($, q) => {
|
|
|
3233
3247
|
throw e;
|
|
3234
3248
|
}
|
|
3235
3249
|
|
|
3236
|
-
delete vid.promise;
|
|
3237
3250
|
delete vid.then;
|
|
3238
3251
|
if (vid._usedAwait) {
|
|
3239
3252
|
vid = $.createVideo();
|
|
@@ -4437,7 +4450,6 @@ Q5.modules.sound = ($, q) => {
|
|
|
4437
4450
|
} catch (e) {
|
|
4438
4451
|
err = e;
|
|
4439
4452
|
}
|
|
4440
|
-
delete s.promise;
|
|
4441
4453
|
delete s.then;
|
|
4442
4454
|
if (err) throw err;
|
|
4443
4455
|
if (cb) cb(s);
|
|
@@ -4459,7 +4471,6 @@ Q5.modules.sound = ($, q) => {
|
|
|
4459
4471
|
a.promise = new Promise((resolve, reject) => {
|
|
4460
4472
|
function loaded() {
|
|
4461
4473
|
if (!a.loaded) {
|
|
4462
|
-
delete a.promise;
|
|
4463
4474
|
delete a.then;
|
|
4464
4475
|
if (a._usedAwait) {
|
|
4465
4476
|
a = new Audio(url);
|
|
@@ -4559,32 +4570,47 @@ Q5.Sound = class {
|
|
|
4559
4570
|
source.start(0, source._offset, source._duration);
|
|
4560
4571
|
|
|
4561
4572
|
this.sources.add(source);
|
|
4562
|
-
|
|
4563
|
-
|
|
4564
|
-
|
|
4565
|
-
if (this.
|
|
4566
|
-
|
|
4567
|
-
|
|
4568
|
-
|
|
4573
|
+
|
|
4574
|
+
source.promise = new Promise((resolve) => {
|
|
4575
|
+
source.onended = () => {
|
|
4576
|
+
if (!this.paused) {
|
|
4577
|
+
this.ended = true;
|
|
4578
|
+
if (this._onended) this._onended();
|
|
4579
|
+
this.sources.delete(source);
|
|
4580
|
+
resolve();
|
|
4581
|
+
}
|
|
4582
|
+
};
|
|
4583
|
+
});
|
|
4584
|
+
|
|
4585
|
+
return source;
|
|
4569
4586
|
}
|
|
4570
4587
|
|
|
4571
4588
|
play(time = 0, duration) {
|
|
4572
4589
|
if (!this.loaded) return;
|
|
4573
4590
|
|
|
4591
|
+
let source;
|
|
4592
|
+
|
|
4574
4593
|
if (!this.paused) {
|
|
4575
|
-
this._newSource(time, duration);
|
|
4594
|
+
source = this._newSource(time, duration);
|
|
4576
4595
|
} else {
|
|
4577
4596
|
let timings = [];
|
|
4578
4597
|
for (let source of this.sources) {
|
|
4579
|
-
timings.push(source._offset, source._duration);
|
|
4598
|
+
timings.push({ offset: source._offset, duration: source._duration });
|
|
4580
4599
|
this.sources.delete(source);
|
|
4581
4600
|
}
|
|
4582
|
-
|
|
4583
|
-
this.
|
|
4601
|
+
timings.sort((a, b) => {
|
|
4602
|
+
let durA = a.duration ?? this.buffer.duration - a.offset;
|
|
4603
|
+
let durB = b.duration ?? this.buffer.duration - b.offset;
|
|
4604
|
+
return durA - durB;
|
|
4605
|
+
});
|
|
4606
|
+
for (let t of timings) {
|
|
4607
|
+
source = this._newSource(t.offset, t.duration);
|
|
4584
4608
|
}
|
|
4585
4609
|
}
|
|
4586
4610
|
|
|
4587
4611
|
this.paused = this.ended = false;
|
|
4612
|
+
|
|
4613
|
+
return source.promise;
|
|
4588
4614
|
}
|
|
4589
4615
|
|
|
4590
4616
|
pause() {
|
|
@@ -4679,7 +4705,6 @@ Q5.modules.util = ($, q) => {
|
|
|
4679
4705
|
if (typeof f == 'string') ret.text = f;
|
|
4680
4706
|
else Object.assign(ret, f);
|
|
4681
4707
|
|
|
4682
|
-
delete ret.promise;
|
|
4683
4708
|
delete ret.then;
|
|
4684
4709
|
if (cb) cb(f);
|
|
4685
4710
|
return f;
|
|
@@ -4703,7 +4728,6 @@ Q5.modules.util = ($, q) => {
|
|
|
4703
4728
|
.then((text) => {
|
|
4704
4729
|
let xml = new DOMParser().parseFromString(text, 'application/xml');
|
|
4705
4730
|
ret.DOM = xml;
|
|
4706
|
-
delete ret.promise;
|
|
4707
4731
|
delete ret.then;
|
|
4708
4732
|
if (cb) cb(xml);
|
|
4709
4733
|
return xml;
|
|
@@ -5745,6 +5769,7 @@ fn fragMain(f: FragParams ) -> @location(0) vec4f {
|
|
|
5745
5769
|
doStroke,
|
|
5746
5770
|
fillSet,
|
|
5747
5771
|
strokeSet,
|
|
5772
|
+
globalAlpha,
|
|
5748
5773
|
tintIdx,
|
|
5749
5774
|
_textSize,
|
|
5750
5775
|
_textAlign,
|
|
@@ -5775,6 +5800,7 @@ fn fragMain(f: FragParams ) -> @location(0) vec4f {
|
|
|
5775
5800
|
doStroke,
|
|
5776
5801
|
fillSet,
|
|
5777
5802
|
strokeSet,
|
|
5803
|
+
globalAlpha,
|
|
5778
5804
|
tintIdx,
|
|
5779
5805
|
_textSize,
|
|
5780
5806
|
_textAlign,
|
|
@@ -7508,7 +7534,7 @@ fn fragMain(f: FragParams) -> @location(0) vec4f {
|
|
|
7508
7534
|
|
|
7509
7535
|
$._makeDrawable = (g) => {
|
|
7510
7536
|
$._addTexture(g);
|
|
7511
|
-
g.
|
|
7537
|
+
g._owner = $;
|
|
7512
7538
|
};
|
|
7513
7539
|
|
|
7514
7540
|
$.createImage = (w, h, opt) => {
|
|
@@ -7990,7 +8016,6 @@ fn fragMain(f : FragParams) -> @location(0) vec4f {
|
|
|
7990
8016
|
let fontName = url.slice(url.lastIndexOf('/') + 1, url.lastIndexOf('-'));
|
|
7991
8017
|
let f = { family: fontName };
|
|
7992
8018
|
f.promise = createFont(url, fontName, () => {
|
|
7993
|
-
delete f.promise;
|
|
7994
8019
|
delete f.then;
|
|
7995
8020
|
if (f._usedAwait) f = { family: fontName };
|
|
7996
8021
|
if (cb) cb(f);
|