q5 3.7.7 → 3.8.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/defs/q5-c2d-es.d.ts +926 -174
- package/defs/q5-c2d.d.ts +9 -9
- package/defs/q5-es.d.ts +963 -207
- package/deno.json +1 -1
- package/package.json +1 -1
- package/q5.d.ts +9 -9
- package/q5.js +135 -30
- package/q5.min.js +2 -2
package/deno.json
CHANGED
package/package.json
CHANGED
package/q5.d.ts
CHANGED
|
@@ -545,7 +545,7 @@ declare global {
|
|
|
545
545
|
/** 🌆
|
|
546
546
|
* Array of pixel color data from a canvas or image.
|
|
547
547
|
*
|
|
548
|
-
* Empty by default,
|
|
548
|
+
* Empty by default, get the data by running `loadPixels`.
|
|
549
549
|
*
|
|
550
550
|
* Each pixel is represented by four consecutive values in the array,
|
|
551
551
|
* corresponding to its red, green, blue, and alpha channels.
|
|
@@ -677,13 +677,6 @@ declare global {
|
|
|
677
677
|
*/
|
|
678
678
|
function createGraphics(w: number, h: number, opt?: any): Q5;
|
|
679
679
|
|
|
680
|
-
namespace Q5 {
|
|
681
|
-
interface Image {
|
|
682
|
-
width: number;
|
|
683
|
-
height: number;
|
|
684
|
-
}
|
|
685
|
-
}
|
|
686
|
-
|
|
687
680
|
// 📘 text
|
|
688
681
|
|
|
689
682
|
/** 📘
|
|
@@ -3168,7 +3161,7 @@ declare global {
|
|
|
3168
3161
|
* @example
|
|
3169
3162
|
* createCanvas(200, 100);
|
|
3170
3163
|
*
|
|
3171
|
-
* let sel = createSelect('Select
|
|
3164
|
+
* let sel = createSelect('Select an option');
|
|
3172
3165
|
* sel.option('Red', '#f55').option('Green', '#5f5');
|
|
3173
3166
|
*
|
|
3174
3167
|
* sel.addEventListener('change', () => {
|
|
@@ -3954,6 +3947,13 @@ declare global {
|
|
|
3954
3947
|
|
|
3955
3948
|
}
|
|
3956
3949
|
|
|
3950
|
+
namespace Q5 {
|
|
3951
|
+
interface Image {
|
|
3952
|
+
width: number;
|
|
3953
|
+
height: number;
|
|
3954
|
+
}
|
|
3955
|
+
}
|
|
3956
|
+
|
|
3957
3957
|
}
|
|
3958
3958
|
|
|
3959
3959
|
export {};
|
package/q5.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* q5.js
|
|
3
|
-
* @version 3.
|
|
3
|
+
* @version 3.8
|
|
4
4
|
* @author quinton-ashley
|
|
5
5
|
* @contributors evanalulu, Tezumie, ormaq, Dukemz, LingDong-
|
|
6
6
|
* @license LGPL-3.0
|
|
@@ -464,7 +464,7 @@ if (typeof window == 'object') {
|
|
|
464
464
|
window.WEBGPU = 'webgpu';
|
|
465
465
|
} else global.window = 0;
|
|
466
466
|
|
|
467
|
-
Q5.version = Q5.VERSION = '3.
|
|
467
|
+
Q5.version = Q5.VERSION = '3.8';
|
|
468
468
|
|
|
469
469
|
if (typeof document == 'object') {
|
|
470
470
|
document.addEventListener('DOMContentLoaded', () => {
|
|
@@ -619,8 +619,6 @@ Q5.modules.canvas = ($, q) => {
|
|
|
619
619
|
|
|
620
620
|
c.w = w = Math.ceil(w);
|
|
621
621
|
c.h = h = Math.ceil(h);
|
|
622
|
-
q.halfWidth = c.hw = w / 2;
|
|
623
|
-
q.halfHeight = c.hh = h / 2;
|
|
624
622
|
|
|
625
623
|
// changes the actual size of the canvas
|
|
626
624
|
c.width = Math.ceil(w * $._pixelDensity);
|
|
@@ -628,6 +626,17 @@ Q5.modules.canvas = ($, q) => {
|
|
|
628
626
|
|
|
629
627
|
q.width = w;
|
|
630
628
|
q.height = h;
|
|
629
|
+
q.halfWidth = c.hw = w / 2;
|
|
630
|
+
q.halfHeight = c.hh = h / 2;
|
|
631
|
+
|
|
632
|
+
let m = Q5._libMap;
|
|
633
|
+
|
|
634
|
+
if (m.width) {
|
|
635
|
+
q[m.width] = w;
|
|
636
|
+
q[m.height] = h;
|
|
637
|
+
q[m.halfWidth] = q.halfWidth;
|
|
638
|
+
q[m.halfHeight] = q.halfHeight;
|
|
639
|
+
}
|
|
631
640
|
|
|
632
641
|
if ($.displayMode && !c.displayMode) $.displayMode();
|
|
633
642
|
else $._adjustDisplay(true);
|
|
@@ -903,6 +912,7 @@ Q5.renderers.c2d.canvas = ($, q) => {
|
|
|
903
912
|
|
|
904
913
|
$.strokeWeight = (n) => {
|
|
905
914
|
if (!n) $._doStroke = false;
|
|
915
|
+
else $._doStroke = true;
|
|
906
916
|
$.ctx.lineWidth = $._strokeWeight = n || 0.0001;
|
|
907
917
|
};
|
|
908
918
|
|
|
@@ -1583,7 +1593,13 @@ Q5.renderers.c2d.image = ($, q) => {
|
|
|
1583
1593
|
$.ctx.clearRect(0, 0, c.width, c.height);
|
|
1584
1594
|
$.ctx.drawImage(o, 0, 0, c.width, c.height);
|
|
1585
1595
|
|
|
1586
|
-
$.
|
|
1596
|
+
$._retint = true;
|
|
1597
|
+
|
|
1598
|
+
if ($._owner?._makeDrawable) {
|
|
1599
|
+
$._texture.destroy();
|
|
1600
|
+
delete $._texture;
|
|
1601
|
+
$._owner._makeDrawable($);
|
|
1602
|
+
}
|
|
1587
1603
|
};
|
|
1588
1604
|
}
|
|
1589
1605
|
|
|
@@ -1752,6 +1768,26 @@ Q5.Image = class {
|
|
|
1752
1768
|
$.defaultHeight = h * scale;
|
|
1753
1769
|
delete $.createCanvas;
|
|
1754
1770
|
$._loop = false;
|
|
1771
|
+
|
|
1772
|
+
let libMap = Q5._libMap;
|
|
1773
|
+
let imgFns = [
|
|
1774
|
+
'copy',
|
|
1775
|
+
'filter',
|
|
1776
|
+
'get',
|
|
1777
|
+
'set',
|
|
1778
|
+
'resize',
|
|
1779
|
+
'mask',
|
|
1780
|
+
'trim',
|
|
1781
|
+
'inset',
|
|
1782
|
+
'pixels',
|
|
1783
|
+
'loadPixels',
|
|
1784
|
+
'updatePixels',
|
|
1785
|
+
'smooth',
|
|
1786
|
+
'noSmooth'
|
|
1787
|
+
];
|
|
1788
|
+
for (let name of imgFns) {
|
|
1789
|
+
if (libMap[name]) $[libMap[name]] = $[name];
|
|
1790
|
+
}
|
|
1755
1791
|
}
|
|
1756
1792
|
get w() {
|
|
1757
1793
|
return this.width;
|
|
@@ -5540,10 +5576,10 @@ fn fragMain(f: FragParams ) -> @location(0) vec4f {
|
|
|
5540
5576
|
|
|
5541
5577
|
$.strokeWeight = (v) => {
|
|
5542
5578
|
if (v === undefined) return sw;
|
|
5543
|
-
|
|
5544
|
-
|
|
5545
|
-
|
|
5546
|
-
|
|
5579
|
+
|
|
5580
|
+
if (!v) return (doStroke = false);
|
|
5581
|
+
else doStroke = true;
|
|
5582
|
+
|
|
5547
5583
|
v = Math.abs(v);
|
|
5548
5584
|
sw = v;
|
|
5549
5585
|
hsw = v / 2;
|
|
@@ -8608,8 +8644,8 @@ shearX -> es:cizallarX
|
|
|
8608
8644
|
shearY -> es:cizallarY
|
|
8609
8645
|
applyMatrix -> es:aplicarMatriz
|
|
8610
8646
|
resetMatrix -> es:reiniciarMatriz
|
|
8611
|
-
push -> es:
|
|
8612
|
-
pop -> es:
|
|
8647
|
+
push -> es:apilar
|
|
8648
|
+
pop -> es:desapilar
|
|
8613
8649
|
pushMatrix -> es:guardarMatriz
|
|
8614
8650
|
popMatrix -> es:recuperarMatriz
|
|
8615
8651
|
|
|
@@ -8731,6 +8767,7 @@ RIGHT -> es:DERECHA
|
|
|
8731
8767
|
TOP -> es:ARRIBA
|
|
8732
8768
|
BOTTOM -> es:ABAJO
|
|
8733
8769
|
BASELINE -> es:LINEA_BASE
|
|
8770
|
+
MIDDLE -> es:MEDIO
|
|
8734
8771
|
RGB -> es:RGB
|
|
8735
8772
|
OKLCH -> es:OKLCH
|
|
8736
8773
|
HSL -> es:HSL
|
|
@@ -8743,6 +8780,9 @@ PIXELATED -> es:PIXELADO
|
|
|
8743
8780
|
TWO_PI -> es:DOS_PI
|
|
8744
8781
|
HALF_PI -> es:MEDIO_PI
|
|
8745
8782
|
QUARTER_PI -> es:CUARTO_PI
|
|
8783
|
+
|
|
8784
|
+
# vector
|
|
8785
|
+
createVector -> es:crearVector
|
|
8746
8786
|
`;
|
|
8747
8787
|
|
|
8748
8788
|
const userLangs = `
|
|
@@ -8762,6 +8802,45 @@ touchMoved -> es:alMoverToque
|
|
|
8762
8802
|
mouseWheel -> es:ruedaRatón
|
|
8763
8803
|
`;
|
|
8764
8804
|
|
|
8805
|
+
const classLangs = {
|
|
8806
|
+
Vector: `
|
|
8807
|
+
add -> es:sumar
|
|
8808
|
+
sub -> es:restar
|
|
8809
|
+
mult -> es:multiplicar
|
|
8810
|
+
div -> es:dividir
|
|
8811
|
+
mag -> es:magnitud
|
|
8812
|
+
magSq -> es:magnitudCuad
|
|
8813
|
+
dist -> es:distancia
|
|
8814
|
+
normalize -> es:normalizar
|
|
8815
|
+
limit -> es:limitar
|
|
8816
|
+
setMag -> es:establecerMagnitud
|
|
8817
|
+
heading -> es:rumbo
|
|
8818
|
+
rotate -> es:rotar
|
|
8819
|
+
lerp -> es:interpolar
|
|
8820
|
+
array -> es:arreglo
|
|
8821
|
+
copy -> es:copiar
|
|
8822
|
+
dot -> es:punto
|
|
8823
|
+
cross -> es:cruz
|
|
8824
|
+
angleBetween -> es:anguloEntre
|
|
8825
|
+
reflect -> es:reflejar
|
|
8826
|
+
`,
|
|
8827
|
+
Sound: `
|
|
8828
|
+
load -> es:cargar
|
|
8829
|
+
play -> es:reproducir
|
|
8830
|
+
stop -> es:parar
|
|
8831
|
+
pause -> es:pausar
|
|
8832
|
+
loop -> es:bucle
|
|
8833
|
+
setVolume -> es:establecerVolumen
|
|
8834
|
+
setPan -> es:establecerPan
|
|
8835
|
+
setLoop -> es:establecerBucle
|
|
8836
|
+
isLoaded -> es:estaCargado
|
|
8837
|
+
isPlaying -> es:estaReproduciendo
|
|
8838
|
+
isPaused -> es:estaPausado
|
|
8839
|
+
isLooping -> es:estaEnBucle
|
|
8840
|
+
onended -> es:alTerminar
|
|
8841
|
+
`
|
|
8842
|
+
};
|
|
8843
|
+
|
|
8765
8844
|
const parseLangs = function (data, lang) {
|
|
8766
8845
|
let map = {};
|
|
8767
8846
|
for (let l of data.split('\n')) {
|
|
@@ -8773,8 +8852,6 @@ const parseLangs = function (data, lang) {
|
|
|
8773
8852
|
return map;
|
|
8774
8853
|
};
|
|
8775
8854
|
|
|
8776
|
-
Q5._lang = 'en';
|
|
8777
|
-
|
|
8778
8855
|
Object.defineProperty(Q5, 'lang', {
|
|
8779
8856
|
get: () => Q5._lang,
|
|
8780
8857
|
set: (val) => {
|
|
@@ -8784,15 +8861,15 @@ Object.defineProperty(Q5, 'lang', {
|
|
|
8784
8861
|
|
|
8785
8862
|
if (val == 'en') {
|
|
8786
8863
|
// reset to English only user functions
|
|
8787
|
-
Q5._userFns = Q5._userFns.slice(0,
|
|
8864
|
+
Q5._userFns = Q5._userFns.slice(0, 19);
|
|
8788
8865
|
Q5._libMap = Q5._userFnsMap = {};
|
|
8789
8866
|
return;
|
|
8790
8867
|
}
|
|
8791
8868
|
|
|
8792
|
-
let
|
|
8869
|
+
let m = parseLangs(libLangs, val);
|
|
8793
8870
|
|
|
8794
8871
|
if (typeof window == 'object') {
|
|
8795
|
-
window[
|
|
8872
|
+
window[m.createCanvas] = createCanvas;
|
|
8796
8873
|
}
|
|
8797
8874
|
|
|
8798
8875
|
let userFnsMap = parseLangs(userLangs, val);
|
|
@@ -8806,12 +8883,33 @@ Object.defineProperty(Q5, 'lang', {
|
|
|
8806
8883
|
});
|
|
8807
8884
|
}
|
|
8808
8885
|
|
|
8809
|
-
|
|
8886
|
+
for (let className in classLangs) {
|
|
8887
|
+
if (Q5[className]) {
|
|
8888
|
+
let map = parseLangs(classLangs[className], val);
|
|
8889
|
+
let proto = Q5[className].prototype;
|
|
8890
|
+
for (let name in map) {
|
|
8891
|
+
let translatedName = map[name];
|
|
8892
|
+
if (proto.hasOwnProperty(translatedName)) continue;
|
|
8893
|
+
Object.defineProperty(proto, translatedName, {
|
|
8894
|
+
get: function () {
|
|
8895
|
+
return this[name];
|
|
8896
|
+
},
|
|
8897
|
+
set: function (v) {
|
|
8898
|
+
this[name] = v;
|
|
8899
|
+
}
|
|
8900
|
+
});
|
|
8901
|
+
}
|
|
8902
|
+
}
|
|
8903
|
+
}
|
|
8904
|
+
|
|
8905
|
+
Q5._libMap = m;
|
|
8810
8906
|
Q5._userFnsMap = userFnsMap;
|
|
8811
8907
|
Q5._userFns.push(...Object.values(userFnsMap));
|
|
8812
8908
|
}
|
|
8813
8909
|
});
|
|
8814
8910
|
|
|
8911
|
+
Q5.lang = 'en';
|
|
8912
|
+
|
|
8815
8913
|
Q5.modules.lang = ($) => {
|
|
8816
8914
|
let userFnsMap = Q5._userFnsMap;
|
|
8817
8915
|
|
|
@@ -8823,29 +8921,36 @@ Q5.modules.lang = ($) => {
|
|
|
8823
8921
|
});
|
|
8824
8922
|
}
|
|
8825
8923
|
|
|
8826
|
-
let
|
|
8924
|
+
let m = Q5._libMap;
|
|
8827
8925
|
|
|
8828
|
-
if (
|
|
8829
|
-
$[
|
|
8926
|
+
if (m.createCanvas) {
|
|
8927
|
+
$[m.createCanvas] = $.createCanvas;
|
|
8830
8928
|
}
|
|
8831
8929
|
};
|
|
8832
8930
|
|
|
8833
8931
|
Q5.addHook('init', (q) => {
|
|
8834
|
-
let
|
|
8932
|
+
let m = Q5._libMap;
|
|
8835
8933
|
|
|
8836
|
-
for (let name in
|
|
8837
|
-
let translatedName =
|
|
8934
|
+
for (let name in m) {
|
|
8935
|
+
let translatedName = m[name];
|
|
8838
8936
|
q[translatedName] = q[name];
|
|
8839
8937
|
}
|
|
8840
8938
|
});
|
|
8841
8939
|
|
|
8842
8940
|
Q5.addHook('predraw', (q) => {
|
|
8843
|
-
let
|
|
8941
|
+
let m = Q5._libMap;
|
|
8844
8942
|
|
|
8845
|
-
|
|
8846
|
-
|
|
8847
|
-
|
|
8848
|
-
|
|
8849
|
-
|
|
8850
|
-
|
|
8943
|
+
if (!m.mouseX) return;
|
|
8944
|
+
|
|
8945
|
+
q[m.frameCount] = q.frameCount;
|
|
8946
|
+
|
|
8947
|
+
// update user input
|
|
8948
|
+
q[m.mouseX] = q.mouseX;
|
|
8949
|
+
q[m.mouseY] = q.mouseY;
|
|
8950
|
+
q[m.mouseIsPressed] = q.mouseIsPressed;
|
|
8951
|
+
q[m.mouseButton] = q.mouseButton;
|
|
8952
|
+
q[m.key] = q.key;
|
|
8953
|
+
q[m.keyIsPressed] = q.keyIsPressed;
|
|
8954
|
+
q[m.touches] = q.touches;
|
|
8955
|
+
q[m.pointers] = q.pointers;
|
|
8851
8956
|
});
|