q5 2.27.3 → 2.27.4
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/package.json +1 -1
- package/q5.d.ts +106 -61
package/package.json
CHANGED
package/q5.d.ts
CHANGED
|
@@ -271,24 +271,19 @@ function draw() {
|
|
|
271
271
|
/** ⭐️
|
|
272
272
|
* By default, q5 supports the p5.js v1
|
|
273
273
|
* [preload](https://q5js.org/learn/#preload)
|
|
274
|
-
* system
|
|
275
|
-
* before the `setup` and `draw` functions are run.
|
|
276
|
-
*
|
|
277
|
-
* q5's preload system is promise based and uses
|
|
274
|
+
* system, which uses
|
|
278
275
|
* [`Promise.all`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise/all)
|
|
279
|
-
* to load assets
|
|
276
|
+
* behind the scenes to load assets in parallel.
|
|
280
277
|
*
|
|
281
278
|
* To match p5.js v2 behavior, q5 automatically makes
|
|
282
279
|
* load* functions, such as `loadImage`, return promises
|
|
283
|
-
*
|
|
280
|
+
* in `setup` if it's defined as an async function.
|
|
284
281
|
*
|
|
285
282
|
* This function can be used at any point in your sketch
|
|
286
|
-
* to make load* functions return promises or not.
|
|
287
|
-
*
|
|
288
|
-
* Consider simply using
|
|
289
|
-
* [`load`](https://q5js.org/learn/#load) instead.
|
|
283
|
+
* to make load* functions return promises or not. Yet, consider
|
|
284
|
+
* using [`load`](https://q5js.org/learn/#load) instead.
|
|
290
285
|
*
|
|
291
|
-
* @param {boolean} [val]
|
|
286
|
+
* @param {boolean} [val] Whether load* functions should return promises or not. If this parameter is undefined the value is set to true.
|
|
292
287
|
* @example
|
|
293
288
|
createCanvas(200);
|
|
294
289
|
|
|
@@ -420,7 +415,7 @@ q.draw = () => {
|
|
|
420
415
|
* q5 functions. The origin of a WebGPU canvas is at its center.
|
|
421
416
|
* @param {number} [w] width or size of the canvas
|
|
422
417
|
* @param {number} [h] height of the canvas
|
|
423
|
-
* @param {
|
|
418
|
+
* @param {object} [opt] options for the canvas
|
|
424
419
|
* @param {boolean} [opt.alpha] whether the canvas should have an alpha channel that allows it to be seen through, default is false
|
|
425
420
|
* @param {string} [opt.colorSpace] color space of the canvas, either "srgb" or "display-p3", default is "display-p3" for devices that support HDR colors
|
|
426
421
|
* @returns {HTMLCanvasElement} created canvas element
|
|
@@ -879,7 +874,7 @@ rect(20, 20, 60, 60);
|
|
|
879
874
|
* See issue [#104](https://github.com/q5js/q5.js/issues/104) for details.
|
|
880
875
|
* @param {number} w width
|
|
881
876
|
* @param {number} h height
|
|
882
|
-
* @param {
|
|
877
|
+
* @param {object} [opt] options
|
|
883
878
|
* @returns {Q5} a new Q5 graphics buffer
|
|
884
879
|
*/
|
|
885
880
|
function createGraphics(w: number, h: number, opt?: any): Q5;
|
|
@@ -1415,70 +1410,78 @@ triangle(50, 130, 150, 180, 50, 180);
|
|
|
1415
1410
|
function strokeJoin(val: CanvasLineJoin): void;
|
|
1416
1411
|
|
|
1417
1412
|
/** 🧑🎨
|
|
1418
|
-
* Set to `CORNER
|
|
1413
|
+
* Set to `CORNER` (default), `CENTER`, `RADIUS`, or `CORNERS`.
|
|
1419
1414
|
*
|
|
1420
1415
|
* Changes how the first four inputs to
|
|
1421
1416
|
* `rect` and `square` are interpreted.
|
|
1422
|
-
* @param {string}
|
|
1417
|
+
* @param {string} mode
|
|
1423
1418
|
* @example
|
|
1424
1419
|
createCanvas(200, 100);
|
|
1425
1420
|
background(200);
|
|
1426
|
-
|
|
1427
1421
|
rectMode(CORNER);
|
|
1422
|
+
|
|
1423
|
+
// ( x, y, w, h)
|
|
1428
1424
|
rect(50, 25, 100, 50);
|
|
1429
1425
|
* @example
|
|
1430
1426
|
createCanvas(200, 100);
|
|
1431
1427
|
background(200);
|
|
1432
|
-
|
|
1433
1428
|
rectMode(CENTER);
|
|
1429
|
+
|
|
1430
|
+
// ( cX, cY, w, h)
|
|
1434
1431
|
rect(100, 50, 100, 50);
|
|
1435
1432
|
* @example
|
|
1436
1433
|
createCanvas(200, 100);
|
|
1437
1434
|
background(200);
|
|
1438
|
-
|
|
1439
1435
|
rectMode(RADIUS);
|
|
1436
|
+
|
|
1437
|
+
// ( cX, cY, rX, rY)
|
|
1440
1438
|
rect(100, 50, 50, 25);
|
|
1441
1439
|
* @example
|
|
1442
1440
|
createCanvas(200, 100);
|
|
1443
1441
|
background(200);
|
|
1444
|
-
|
|
1445
1442
|
rectMode(CORNERS);
|
|
1443
|
+
|
|
1444
|
+
// ( x1, y1, x2, y2)
|
|
1446
1445
|
rect(50, 25, 150, 75);
|
|
1447
1446
|
*/
|
|
1448
|
-
function rectMode(
|
|
1447
|
+
function rectMode(mode: string): void;
|
|
1449
1448
|
|
|
1450
1449
|
/** 🧑🎨
|
|
1451
|
-
* Set to `CENTER
|
|
1450
|
+
* Set to `CENTER` (default), `RADIUS`, `CORNER`, or `CORNERS`.
|
|
1452
1451
|
*
|
|
1453
1452
|
* Changes how the first four inputs to
|
|
1454
1453
|
* `ellipse`, `circle`, and `arc` are interpreted.
|
|
1455
|
-
* @param {string}
|
|
1454
|
+
* @param {string} mode
|
|
1456
1455
|
* @example
|
|
1457
1456
|
createCanvas(200, 100);
|
|
1458
1457
|
background(200);
|
|
1459
|
-
|
|
1460
1458
|
ellipseMode(CENTER);
|
|
1459
|
+
|
|
1460
|
+
// ( x, y, w, h)
|
|
1461
1461
|
ellipse(100, 50, 100, 50);
|
|
1462
1462
|
* @example
|
|
1463
1463
|
createCanvas(200, 100);
|
|
1464
1464
|
background(200);
|
|
1465
|
-
|
|
1466
1465
|
ellipseMode(RADIUS);
|
|
1466
|
+
|
|
1467
|
+
// ( x, y, rX, rY)
|
|
1467
1468
|
ellipse(100, 50, 50, 25);
|
|
1468
1469
|
* @example
|
|
1469
1470
|
createCanvas(200, 100);
|
|
1470
1471
|
background(200);
|
|
1471
|
-
|
|
1472
1472
|
ellipseMode(CORNER);
|
|
1473
|
+
|
|
1474
|
+
// (lX, tY, w, h)
|
|
1473
1475
|
ellipse(50, 25, 100, 50);
|
|
1474
1476
|
* @example
|
|
1475
1477
|
createCanvas(200, 100);
|
|
1476
1478
|
background(200);
|
|
1477
|
-
|
|
1478
1479
|
ellipseMode(CORNERS);
|
|
1480
|
+
|
|
1481
|
+
// ( x1, y1, x2, y2)
|
|
1479
1482
|
ellipse(50, 25, 150, 75);
|
|
1480
1483
|
*/
|
|
1481
|
-
function ellipseMode(
|
|
1484
|
+
function ellipseMode(mode: string): void;
|
|
1482
1485
|
|
|
1483
1486
|
|
|
1484
1487
|
/** 🧑🎨
|
|
@@ -1640,15 +1643,15 @@ curve(-100, -200, -50, 0, 50, 0, 100, -200);
|
|
|
1640
1643
|
*/
|
|
1641
1644
|
const CORNERS: 'corners';
|
|
1642
1645
|
|
|
1643
|
-
|
|
1644
1646
|
// 🌆 image
|
|
1645
1647
|
|
|
1646
1648
|
/** 🌆
|
|
1647
1649
|
* Loads an image from a URL and optionally runs a callback function.
|
|
1650
|
+
*
|
|
1651
|
+
* Returns a promise if used in `async setup`.
|
|
1652
|
+
*
|
|
1648
1653
|
* @param {string} url url of the image to load
|
|
1649
|
-
* @
|
|
1650
|
-
* @param {any} [opt] optional parameters for loading the image
|
|
1651
|
-
* @returns {Q5.Image} image
|
|
1654
|
+
* @returns {Q5.Image | Promise<Q5.Image>} image or promise
|
|
1652
1655
|
* @example
|
|
1653
1656
|
createCanvas(200);
|
|
1654
1657
|
|
|
@@ -1667,11 +1670,11 @@ q.draw = () => {
|
|
|
1667
1670
|
background(logo);
|
|
1668
1671
|
};
|
|
1669
1672
|
*/
|
|
1670
|
-
function loadImage(url: string
|
|
1673
|
+
function loadImage(url: string): Q5.Image | Promise<Q5.Image>;
|
|
1671
1674
|
|
|
1672
1675
|
/** 🌆
|
|
1673
|
-
* Draws an image to the canvas.
|
|
1674
|
-
* @param {
|
|
1676
|
+
* Draws an image or video frame to the canvas.
|
|
1677
|
+
* @param {Q5.Image | HTMLVideoElement} img image or video to draw
|
|
1675
1678
|
* @param {number} dx x position to draw the image at
|
|
1676
1679
|
* @param {number} dy y position to draw the image at
|
|
1677
1680
|
* @param {number} [dw] width of the destination image
|
|
@@ -1697,23 +1700,42 @@ function draw() {
|
|
|
1697
1700
|
image(logo, 0, 0, 200, 200, 256, 256, 512, 512);
|
|
1698
1701
|
}
|
|
1699
1702
|
*/
|
|
1700
|
-
function image(img:
|
|
1703
|
+
function image(img: Q5.Image | HTMLVideoElement, dx: number, dy: number, dw?: number, dh?: number, sx?: number, sy?: number, sw?: number, sh?: number): void;
|
|
1701
1704
|
|
|
1702
1705
|
/** 🌆
|
|
1703
|
-
*
|
|
1706
|
+
* Set to `CORNER` (default), `CORNERS`, or `CENTER`.
|
|
1704
1707
|
*
|
|
1705
|
-
*
|
|
1706
|
-
* - `CORNERS`: images will be drawn from the top-left to the bottom-right corner
|
|
1707
|
-
* - `CENTER`: images will be drawn centered at (dx, dy)
|
|
1708
|
+
* Changes how inputs to `image` are interpreted.
|
|
1708
1709
|
* @param {string} mode
|
|
1709
1710
|
* @example
|
|
1710
1711
|
createCanvas(200);
|
|
1712
|
+
let logo = loadImage('/q5js_logo.webp');
|
|
1711
1713
|
|
|
1714
|
+
function draw() {
|
|
1715
|
+
imageMode(CORNER);
|
|
1716
|
+
|
|
1717
|
+
// ( img, x, y, w, h)
|
|
1718
|
+
image(logo, 50, 50, 100, 100);
|
|
1719
|
+
}
|
|
1720
|
+
* @example
|
|
1721
|
+
createCanvas(200);
|
|
1712
1722
|
let logo = loadImage('/q5js_logo.webp');
|
|
1713
1723
|
|
|
1714
1724
|
function draw() {
|
|
1715
1725
|
imageMode(CENTER);
|
|
1716
|
-
|
|
1726
|
+
|
|
1727
|
+
// ( img, cX, cY, w, h)
|
|
1728
|
+
image(logo, 100, 100, 100, 100);
|
|
1729
|
+
}
|
|
1730
|
+
* @example
|
|
1731
|
+
createCanvas(200);
|
|
1732
|
+
let logo = loadImage('/q5js_logo.webp');
|
|
1733
|
+
|
|
1734
|
+
function draw() {
|
|
1735
|
+
imageMode(CORNERS);
|
|
1736
|
+
|
|
1737
|
+
// ( img, x1, y1, x2, y2)
|
|
1738
|
+
image(logo, 50, 50, 100, 100);
|
|
1717
1739
|
}
|
|
1718
1740
|
*/
|
|
1719
1741
|
function imageMode(mode: string): void;
|
|
@@ -2046,9 +2068,11 @@ text(info, 12, 30, 20, 6);
|
|
|
2046
2068
|
* with the file ending "-msdf.json" can be used to render text with
|
|
2047
2069
|
* the `text` function. Fonts in other formats can be used with the
|
|
2048
2070
|
* [`textImage`](https://q5js.org/learn/#textImage) function.
|
|
2049
|
-
*
|
|
2050
|
-
*
|
|
2051
|
-
*
|
|
2071
|
+
*
|
|
2072
|
+
* Returns a promise if used in `async setup`.
|
|
2073
|
+
*
|
|
2074
|
+
* @param {string} url URL of the font to load
|
|
2075
|
+
* @returns {FontFace | Promise<FontFace>} font or promise
|
|
2052
2076
|
* @example
|
|
2053
2077
|
createCanvas(200, 56);
|
|
2054
2078
|
|
|
@@ -2072,7 +2096,7 @@ function setup() {
|
|
|
2072
2096
|
text('Hello!', 2, 68);
|
|
2073
2097
|
}
|
|
2074
2098
|
*/
|
|
2075
|
-
function loadFont(url: string
|
|
2099
|
+
function loadFont(url: string): FontFace | Promise<FontFace>
|
|
2076
2100
|
|
|
2077
2101
|
/** ✍️
|
|
2078
2102
|
* Sets the current font to be used for rendering text.
|
|
@@ -3086,8 +3110,11 @@ function draw() {
|
|
|
3086
3110
|
* For backwards compatibility with the p5.sound API, the functions
|
|
3087
3111
|
* `setVolume`, `setLoop`, `setPan`, `isLoaded`, and `isPlaying`
|
|
3088
3112
|
* are also implemented, but their use is deprecated.
|
|
3113
|
+
*
|
|
3114
|
+
* Returns a promise if used in `async setup`.
|
|
3115
|
+
*
|
|
3089
3116
|
* @param {string} url sound file
|
|
3090
|
-
* @returns {Sound} a new `Sound` object
|
|
3117
|
+
* @returns {Sound | Promise<Sound>} a new `Sound` object or promise
|
|
3091
3118
|
* @example
|
|
3092
3119
|
createCanvas(200);
|
|
3093
3120
|
|
|
@@ -3098,7 +3125,7 @@ function mousePressed() {
|
|
|
3098
3125
|
sound.play();
|
|
3099
3126
|
}
|
|
3100
3127
|
*/
|
|
3101
|
-
function loadSound(url: string): Sound
|
|
3128
|
+
function loadSound(url: string): Sound | Promise<Sound>;
|
|
3102
3129
|
|
|
3103
3130
|
/**
|
|
3104
3131
|
* Loads audio data from a file and returns an [HTMLAudioElement](https://developer.mozilla.org/docs/Web/API/HTMLMediaElement).
|
|
@@ -3107,8 +3134,11 @@ function mousePressed() {
|
|
|
3107
3134
|
*
|
|
3108
3135
|
* Note that audio can only be played after the first user
|
|
3109
3136
|
* interaction with the page!
|
|
3137
|
+
*
|
|
3138
|
+
* Returns a promise if used in `async setup`.
|
|
3139
|
+
*
|
|
3110
3140
|
* @param url audio file
|
|
3111
|
-
* @returns {HTMLAudioElement} an HTMLAudioElement
|
|
3141
|
+
* @returns {HTMLAudioElement | Promise<HTMLAudioElement>} an HTMLAudioElement or promise
|
|
3112
3142
|
* @example
|
|
3113
3143
|
createCanvas(200);
|
|
3114
3144
|
|
|
@@ -3119,7 +3149,7 @@ function mousePressed() {
|
|
|
3119
3149
|
audio.play();
|
|
3120
3150
|
}
|
|
3121
3151
|
*/
|
|
3122
|
-
function loadAudio(url: string): HTMLAudioElement
|
|
3152
|
+
function loadAudio(url: string): HTMLAudioElement | Promise<HTMLAudioElement>;
|
|
3123
3153
|
|
|
3124
3154
|
/** 🔊
|
|
3125
3155
|
* Returns the AudioContext in use or undefined if it doesn't exist.
|
|
@@ -3437,7 +3467,11 @@ function draw() {
|
|
|
3437
3467
|
*
|
|
3438
3468
|
* The video element can be hidden and its content can be
|
|
3439
3469
|
* displayed on the canvas using the `image` function.
|
|
3470
|
+
*
|
|
3471
|
+
* Returns a promise if used in `async setup`.
|
|
3472
|
+
*
|
|
3440
3473
|
* @param {string} src url of the video
|
|
3474
|
+
* @returns {HTMLVideoElement | Promise<HTMLVideoElement>} a new video element or promise
|
|
3441
3475
|
* @example
|
|
3442
3476
|
createCanvas(0);
|
|
3443
3477
|
|
|
@@ -3460,7 +3494,7 @@ function draw() {
|
|
|
3460
3494
|
filter(HUE_ROTATE, 90);
|
|
3461
3495
|
}
|
|
3462
3496
|
*/
|
|
3463
|
-
function createVideo(src: string): HTMLVideoElement
|
|
3497
|
+
function createVideo(src: string): HTMLVideoElement | Promise<HTMLVideoElement>;
|
|
3464
3498
|
|
|
3465
3499
|
/** 📑
|
|
3466
3500
|
* Creates a capture from a connected camera, such as a webcam.
|
|
@@ -3475,9 +3509,12 @@ function draw() {
|
|
|
3475
3509
|
* by default. The first parameter to this function can be used to
|
|
3476
3510
|
* specify the constraints for the capture. See [`getUserMedia`](https://developer.mozilla.org/docs/Web/API/MediaDevices/getUserMedia)
|
|
3477
3511
|
* for more info.
|
|
3512
|
+
*
|
|
3513
|
+
* Returns a promise if used in `async setup`.
|
|
3514
|
+
*
|
|
3478
3515
|
* @param {string} [type] type of capture, can be only `VIDEO` or only `AUDIO`, the default is to use both video and audio
|
|
3479
3516
|
* @param {boolean} [flipped] whether to mirror the video horizontally, true by default
|
|
3480
|
-
* @
|
|
3517
|
+
* @returns {HTMLVideoElement | Promise<HTMLVideoElement>} a new video element or promise
|
|
3481
3518
|
* @example
|
|
3482
3519
|
createCanvas(200);
|
|
3483
3520
|
|
|
@@ -3510,7 +3547,7 @@ function mousePressed() {
|
|
|
3510
3547
|
canvas.remove();
|
|
3511
3548
|
}
|
|
3512
3549
|
*/
|
|
3513
|
-
function createCapture(type?: string, flipped?: boolean
|
|
3550
|
+
function createCapture(type?: string, flipped?: boolean): HTMLVideoElement | Promise<HTMLVideoElement>;
|
|
3514
3551
|
|
|
3515
3552
|
/** 📑
|
|
3516
3553
|
* Finds the first element in the DOM that matches the given [CSS selector](https://developer.mozilla.org/docs/Learn_web_development/Core/Styling_basics/Basic_selectors).
|
|
@@ -3687,26 +3724,34 @@ function mousePressed() {
|
|
|
3687
3724
|
function save(data?: object, fileName?: string): void;
|
|
3688
3725
|
|
|
3689
3726
|
/** 🛠️
|
|
3690
|
-
* Loads a text file from the specified url.
|
|
3727
|
+
* Loads a text file from the specified url.
|
|
3728
|
+
*
|
|
3729
|
+
* Returns a promise if used in `async setup`.
|
|
3730
|
+
*
|
|
3691
3731
|
* @param {string} url text file
|
|
3692
|
-
* @
|
|
3732
|
+
* @returns {object | Promise} an object containing the loaded text in the property `obj.text` or a promise
|
|
3693
3733
|
*/
|
|
3694
|
-
function loadText(url: string
|
|
3734
|
+
function loadText(url: string): object | Promise<object>;
|
|
3695
3735
|
|
|
3696
3736
|
/** 🛠️
|
|
3697
|
-
* Loads a JSON file from the specified url.
|
|
3698
|
-
*
|
|
3737
|
+
* Loads a JSON file from the specified url.
|
|
3738
|
+
*
|
|
3739
|
+
* Returns a promise if used in `async setup`.
|
|
3740
|
+
*
|
|
3699
3741
|
* @param {string} url JSON file
|
|
3700
|
-
* @
|
|
3742
|
+
* @returns {any | Promise} an object or array containing the loaded JSON or a promise
|
|
3701
3743
|
*/
|
|
3702
|
-
function loadJSON(url: string
|
|
3744
|
+
function loadJSON(url: string): any | Promise<any>;
|
|
3703
3745
|
|
|
3704
3746
|
/** 🛠️
|
|
3705
|
-
* Loads a CSV file from the specified url.
|
|
3747
|
+
* Loads a CSV file from the specified url.
|
|
3748
|
+
*
|
|
3749
|
+
* Returns a promise if used in `async setup`.
|
|
3750
|
+
*
|
|
3706
3751
|
* @param {string} url CSV file
|
|
3707
|
-
* @
|
|
3752
|
+
* @returns {object[] | Promise<object[]>} an array of objects containing the loaded CSV or a promise
|
|
3708
3753
|
*/
|
|
3709
|
-
function loadCSV(url: string
|
|
3754
|
+
function loadCSV(url: string): object[] | Promise<object[]>;
|
|
3710
3755
|
|
|
3711
3756
|
/** 🛠️
|
|
3712
3757
|
* nf is short for number format. It formats a number
|