q5 2.17.0 → 2.18.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.
Files changed (5) hide show
  1. package/deno.json +1 -1
  2. package/package.json +2 -2
  3. package/q5.d.ts +160 -33
  4. package/q5.js +351 -8
  5. package/q5.min.js +2 -2
package/deno.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@q5/q5",
3
- "version": "2.17.0",
3
+ "version": "2.18.1",
4
4
  "license": "LGPL-3.0",
5
5
  "description": "A sequel to p5.js that's 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": "2.17.0",
3
+ "version": "2.18.1",
4
4
  "description": "A sequel to p5.js that's optimized for interactive art",
5
5
  "author": "quinton-ashley",
6
6
  "contributors": [
@@ -11,7 +11,7 @@
11
11
  "homepage": "https://q5js.org/home",
12
12
  "main": "q5-server.js",
13
13
  "scripts": {
14
- "bundle": "cat src/q5-core.js src/q5-canvas.js src/q5-c2d-canvas.js src/q5-c2d-drawing.js src/q5-c2d-image.js src/q5-c2d-soft-filters.js src/q5-c2d-text.js src/q5-ai.js src/q5-color.js src/q5-display.js src/q5-dom.js src/q5-input.js src/q5-math.js src/q5-sound.js src/q5-util.js src/q5-vector.js src/q5-webgpu-canvas.js src/q5-webgpu-drawing.js src/q5-webgpu-image.js src/q5-webgpu-text.js > q5.js",
14
+ "bundle": "cat src/q5-core.js src/q5-canvas.js src/q5-c2d-canvas.js src/q5-c2d-drawing.js src/q5-c2d-image.js src/q5-c2d-soft-filters.js src/q5-c2d-text.js src/q5-ai.js src/q5-color.js src/q5-display.js src/q5-dom.js src/q5-input.js src/q5-math.js src/q5-record.js src/q5-sound.js src/q5-util.js src/q5-vector.js src/q5-webgpu-canvas.js src/q5-webgpu-drawing.js src/q5-webgpu-image.js src/q5-webgpu-text.js > q5.js",
15
15
  "min": "terser q5.js --compress ecma=2024 --mangle > q5.min.js",
16
16
  "dist": "bun bundle && bun min",
17
17
  "dist-p5play": "bun dist && cp q5.js ../../web/p5play-web/v3/q5.js && cp q5.min.js ../../web/p5play-web/v3/q5.min.js",
package/q5.d.ts CHANGED
@@ -7,6 +7,20 @@
7
7
  declare global {
8
8
  // ⭐️ core
9
9
 
10
+ /** ⭐️
11
+ * Welcome to q5's documentation! ☺️
12
+ *
13
+ * First time coding? Check out the [q5 Beginner's Guide to JavaScript](https://github.com/q5js/q5.js/wiki/q5-Beginner's-Guide-to-JavaScript).
14
+ *
15
+ * On these Learn pages you'll find concise descriptions for
16
+ * q5's functions and variables. Scroll through entire topics without
17
+ * needing to click between separate pages.
18
+ *
19
+ * Experiment with editing the code in the interactive mini examples,
20
+ * which are often only 8 lines of code or less. They automatically
21
+ * update as you type, so you can see results right away.
22
+ */
23
+
10
24
  /** ⭐️
11
25
  * The draw function is run 60 times per second by default.
12
26
  * @example
@@ -480,6 +494,8 @@ square(80, 80, 80);
480
494
  * Like the [`color`](https://q5js.org/learn/#color) function, this function
481
495
  * can accept colors in a wide range of formats: as a CSS color string,
482
496
  * a `Color` object, grayscale value, or color component values.
497
+ *
498
+ * Not available in q5 WebGPU.
483
499
  * @param {Color} color shadow color
484
500
  * @example
485
501
  createCanvas(200);
@@ -524,12 +540,14 @@ rect(104, 104, 80, 80);
524
540
  * @param {number} blur blur radius of the shadow, defaults to 0
525
541
  * @example
526
542
  createCanvas(200);
527
- background(200);
528
543
  noStroke();
529
- shadow('red');
544
+ shadow(50);
530
545
 
531
- shadowBox(-20, -8, 50);
532
- circle(100, 100, 80, 80);
546
+ function draw() {
547
+ background(200);
548
+ shadowBox(-20, mouseY, 10);
549
+ circle(100, 100, 80, 80);
550
+ }
533
551
  * @example
534
552
  createCanvas(200);
535
553
  background(200);
@@ -767,6 +785,8 @@ square(0, 0, 50);
767
785
  /** ⬜️
768
786
  * Any position coordinates or dimensions you use will be scaled based
769
787
  * on the unit provided to this function.
788
+ *
789
+ * Not available in q5 WebGPU.
770
790
  * @param {number} unit unit to scale by
771
791
  * @example
772
792
  createCanvas(200);
@@ -778,6 +798,8 @@ rect(20, 20, 60, 60);
778
798
 
779
799
  /** ⬜️
780
800
  * Creates a graphics buffer.
801
+ *
802
+ * Not available in q5 WebGPU.
781
803
  * @param {number} w width
782
804
  * @param {number} h height
783
805
  * @param {Object} [opt] options
@@ -786,7 +808,8 @@ rect(20, 20, 60, 60);
786
808
  function createGraphics(w: number, h: number, opt?: any): Q5;
787
809
 
788
810
  /** ⬜️
789
- * The 2D rendering context for the canvas.
811
+ * The 2D rendering context for the canvas, if using the Canvas2D
812
+ * renderer.
790
813
  */
791
814
  var ctx: CanvasRenderingContext2D;
792
815
 
@@ -798,7 +821,7 @@ rect(20, 20, 60, 60);
798
821
  // 💻 display
799
822
 
800
823
  /** 💻
801
- * The `displayMode` function lets you customize how your canvas is presented.
824
+ * Customize how your canvas is presented.
802
825
  * @param {string} mode
803
826
  * - "normal": (default) no styling to canvas or its parent element
804
827
  * - "centered": canvas will be centered horizontally and vertically within its parent and if the window is smaller than the canvas, the canvas will be resized to avoid clipping
@@ -830,7 +853,7 @@ createCanvas(200, 100);
830
853
  background('crimson');
831
854
  * @example
832
855
  function draw() {
833
- background(128, 20);
856
+ background(128, 100);
834
857
  circle(mouseX, mouseY, 20);
835
858
  }
836
859
  */
@@ -1109,22 +1132,34 @@ point(125, 50);
1109
1132
  // 📑 dom
1110
1133
 
1111
1134
  /** 📑
1112
- * Creates a new HTML element.
1135
+ * Creates a new HTML element and adds it to the page. `createEl` is
1136
+ * an alias.
1113
1137
  *
1114
- * q5 adds functions like `position` and `size` to the element
1115
- * that make it easy to position elements above the canvas.
1138
+ * The element is part of the DOM (Document Object Model), an interface for
1139
+ * creating and editing web pages with JavaScript.
1116
1140
  *
1117
1141
  * Modify the element's CSS [`style`](https://developer.mozilla.org/docs/Web/API/HTMLElement/style) to change its appearance.
1118
1142
  *
1119
- * `createEl` is an alias for this function.
1143
+ * Use [`addEventListener`](https://developer.mozilla.org/docs/Web/API/EventTarget/addEventListener) to respond to events such as:
1144
+ * - "click": when the element is clicked
1145
+ * - "mouseover": when the mouse hovers over the element
1146
+ * - "mouseout": when the mouse stops hovering over the element
1147
+ * - "input": when a form element's value changes
1148
+ *
1149
+ * q5 adds some extra functionality to the elements it creates:
1150
+ *
1151
+ * - the `position` function makes it easy to place the element
1152
+ * relative to the canvas
1153
+ * - the `size` function sets the width and height of the element
1154
+ * - alternatively, use the element's `x`, `y`, `width`, and `height` properties
1120
1155
  * @param {string} tag tag name of the element
1121
1156
  * @param {string} [content] content of the element
1122
- * @returns {HTMLElement} created DOM element
1157
+ * @returns {HTMLElement} element
1123
1158
  * @example
1124
1159
  createCanvas(200);
1125
1160
 
1126
1161
  let el = createEl('div', '*');
1127
- el.position(0, 0);
1162
+ el.position(50, 50);
1128
1163
  el.size(100, 100);
1129
1164
  el.style.fontSize = '136px';
1130
1165
  el.style.textAlign = 'center';
@@ -1139,18 +1174,20 @@ el.style.color = 'white';
1139
1174
  * @param {string} [text] text content
1140
1175
  * @param {boolean} [newTab] whether to open the link in a new tab
1141
1176
  * @example
1142
- createCanvas(200, 100);
1177
+ createCanvas(200);
1143
1178
 
1144
1179
  let link = createA('https://q5js.org', 'q5.js');
1145
- link.position(0, 0);
1180
+ link.position(16, 42);
1146
1181
  link.style.fontSize = '80px';
1182
+
1183
+ link.addEventListener('mouseover', () => {
1184
+ background('blue');
1185
+ });
1147
1186
  */
1148
1187
  function createA(href: string, text?: string): HTMLAnchorElement;
1149
1188
 
1150
1189
  /** 📑
1151
1190
  * Creates a button element.
1152
- *
1153
- * Use [`addEventListener`](https://developer.mozilla.org/docs/Web/API/EventTarget/addEventListener) to respond to button click events.
1154
1191
  * @param {string} [content] text content
1155
1192
  * @example
1156
1193
  createCanvas(200, 100);
@@ -1177,7 +1214,7 @@ createCanvas(200, 100);
1177
1214
  let box = createCheckbox('Check me!');
1178
1215
  box.label.style.color = 'lime';
1179
1216
 
1180
- box.addEventListener('change', () => {
1217
+ box.addEventListener('input', () => {
1181
1218
  if (box.checked) background('lime');
1182
1219
  else background('black');
1183
1220
  });
@@ -1202,7 +1239,7 @@ function draw() {
1202
1239
  function createColorPicker(value?: string): HTMLInputElement;
1203
1240
 
1204
1241
  /** 📑
1205
- * Creates an img element.
1242
+ * Creates an image element.
1206
1243
  * @param {string} src url of the image
1207
1244
  * @example
1208
1245
  createCanvas(200, 100);
@@ -1280,10 +1317,12 @@ function draw() {
1280
1317
  *
1281
1318
  * Set `multiple` to `true` to allow multiple options to be selected.
1282
1319
  *
1283
- * Use the `value` property to get or set the selected option.
1320
+ * Use the `value` property to get or set the selected option value.
1284
1321
  *
1285
- * Use the `selected` property to get the selected option or options.
1286
- * @param {boolean} [placeholder] optional placeholder text that appears when no option is selected
1322
+ * Use the `selected` property get the labels of the selected
1323
+ * options or set the selected options by label. Can be a single
1324
+ * string or an array of strings.
1325
+ * @param {string} [placeholder] optional placeholder text that appears before an option is selected
1287
1326
  * @example
1288
1327
  createCanvas(200, 100);
1289
1328
 
@@ -1326,12 +1365,27 @@ function draw() {
1326
1365
  * @example
1327
1366
  createCanvas(200, 100);
1328
1367
 
1368
+ // example coming soon
1329
1369
  // let vid = createVideo('/assets/q5js_video.mp4');
1330
1370
  // vid.controls = true;
1331
1371
  // vid.loop = true;
1332
1372
  */
1333
1373
  function createVideo(src: string): HTMLVideoElement;
1334
1374
 
1375
+ /** 📑
1376
+ * 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).
1377
+ * @param {string} selector
1378
+ * @returns {HTMLElement} element
1379
+ */
1380
+ function findElement(selector: string): HTMLElement;
1381
+
1382
+ /** 📑
1383
+ * Finds all elements in the DOM that match the given [CSS selector](https://developer.mozilla.org/docs/Learn_web_development/Core/Styling_basics/Basic_selectors).
1384
+ * @param {string} selector
1385
+ * @returns {HTMLElement[]} elements
1386
+ */
1387
+ function findElements(selector: string): HTMLElement[];
1388
+
1335
1389
  // 🌆 image
1336
1390
 
1337
1391
  /** 🌆
@@ -1679,8 +1733,8 @@ function setup() {
1679
1733
 
1680
1734
  /** 🌆
1681
1735
  * Creates a new image.
1682
- * @param {number} [w] character limit per line
1683
- * @param {number} [h] line limit
1736
+ * @param {number} w width
1737
+ * @param {number} h height
1684
1738
  * @param {any} [opt] optional settings for the image
1685
1739
  * @returns {Image}
1686
1740
  */
@@ -1710,6 +1764,7 @@ textSize(20);
1710
1764
  let info = "q5.js is a JavaScript library for creative coding. It's a sequel to p5.js that's optimized for interactive art.";
1711
1765
 
1712
1766
  text(info, 12, 30, 20, 6);
1767
+ //
1713
1768
  //
1714
1769
  */
1715
1770
  function text(str: string, x: number, y: number, wrapWidth?: number, lineLimit?: number): void;
@@ -1991,20 +2046,22 @@ createCanvas(200);
1991
2046
  * @returns {Color} a new `Color` object
1992
2047
  * @example
1993
2048
  createCanvas(200);
1994
- // (gray, alpha)
1995
- let darkGray = color(55, 100);
1996
- background(darkGray);
1997
- // (r, g, b, a)
1998
- let blueBottle = color(0, 0, 200, 20);
1999
- fill(blueBottle);
2000
- circle(100, 50, 50);
2049
+ rect(0, 0, 100, 200);
2050
+
2051
+ // ( r, g, b, a)
2052
+ let bottle = color(90, 100, 255, 100);
2053
+ fill(bottle);
2054
+ stroke(bottle);
2055
+ strokeWeight(30);
2056
+ circle(100, 100, 155);
2001
2057
  * @example
2002
2058
  createCanvas(200);
2003
-
2004
- let c = color('gray');
2059
+ // (gray, alpha)
2060
+ let c = color(200, 50);
2005
2061
 
2006
2062
  function draw() {
2007
2063
  background(c);
2064
+ circle(mouseX, mouseY, 50);
2008
2065
  c.g = (c.g + 1) % 255;
2009
2066
  }
2010
2067
  */
@@ -2037,6 +2094,7 @@ colorMode(OKLCH);
2037
2094
 
2038
2095
  fill(0.25, 0.15, 0);
2039
2096
  rect(0, 0, 100, 200);
2097
+
2040
2098
  fill(0.75, 0.15, 0)
2041
2099
  rect(100, 0, 100, 200);
2042
2100
  */
@@ -2405,6 +2463,75 @@ noCursor();
2405
2463
  */
2406
2464
  const TAU: number;
2407
2465
 
2466
+ // 🎞️ record
2467
+
2468
+ /** 🎞️
2469
+ * Creates a recorder. Simply hit record to start recording!
2470
+ *
2471
+ * Recording large canvases is an intensive process, so your
2472
+ * computer may not be able to do it in real time. That's okay,
2473
+ * the resulting video will playback at your sketch's target
2474
+ * frame rate.
2475
+ *
2476
+ * In cases where real time interaction is a priority, consider
2477
+ * reducing the canvas' size, frame rate, and/or recording
2478
+ * quality.
2479
+ *
2480
+ * `format` and `quality` properties are set
2481
+ * automatically based on the height of the canvas. They can be
2482
+ * changed via the UI or programmatically.
2483
+ *
2484
+ * The recorder uses the [`MediaRecorder`](https://developer.mozilla.org/docs/Web/API/MediaRecorder/MediaRecorder) API, which
2485
+ * unfortunately can't encode HDR video.
2486
+ * @returns {HTMLElement} a recorder, q5 DOM element
2487
+ * @example
2488
+ createCanvas(200);
2489
+
2490
+ createRecorder();
2491
+
2492
+ function draw() {
2493
+ circle(mouseX, random(canvas.h), 10);
2494
+ }
2495
+ */
2496
+ function createRecorder(): HTMLElement;
2497
+
2498
+ /** 🎞️
2499
+ * Starts recording the canvas or resumes recording if it was paused.
2500
+ *
2501
+ * If no recorder exists, one is created but not displayed.
2502
+ */
2503
+ function record(): void;
2504
+
2505
+ /** 🎞️
2506
+ * Pauses the canvas recording, if one is in progress.
2507
+ */
2508
+ function pauseRecording(): void;
2509
+
2510
+ /** 🎞️
2511
+ * Discards the current recording.
2512
+ */
2513
+ function deleteRecording(): void;
2514
+
2515
+ /** 🎞️
2516
+ * Saves the current recording as a video file.
2517
+ * @param {string} fileName
2518
+ * @example
2519
+ function draw() {
2520
+ square(mouseX, random(canvas.h), 10);
2521
+ }
2522
+
2523
+ function mousePressed() {
2524
+ if (!recording) record();
2525
+ else saveRecording('squares');
2526
+ }
2527
+ */
2528
+ function saveRecording(fileName): void;
2529
+
2530
+ /** 🎞️
2531
+ * True if the canvas is currently being recorded.
2532
+ */
2533
+ var recording: boolean;
2534
+
2408
2535
  // 🔊 sound
2409
2536
 
2410
2537
  /** 🔊