Skip to content

Commit 7c1fc12

Browse files
merge: upstream/dev-2.0 -> v2/style/format-utils
2 parents 9f52129 + a4fbdaa commit 7c1fc12

File tree

111 files changed

+5789
-4150
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

111 files changed

+5789
-4150
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
name: Close Linked Issues on PR Merge
2+
3+
on:
4+
pull_request:
5+
types: [closed]
6+
branches:
7+
- dev-2.0
8+
9+
jobs:
10+
close_issues:
11+
if: github.event.pull_request.merged == true
12+
runs-on: ubuntu-latest
13+
steps:
14+
- name: Close linked issues on non-default branches
15+
uses: processing/branch-pr-close-issue@v1
16+
with:
17+
token: ${{ secrets.GITHUB_TOKEN }}
18+
branch: dev-2.0

contributor_docs/creating_libraries.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,33 @@ if (typeof p5 !== undefined) {
282282

283283
In the above snippet, an additional `if` condition is added around the call to `p5.registerAddon()`. This is done to support both direct usage in ESM modules (where users can directly import your addon function then call `p5.registerAddon()` themselves) and after bundling support regular `<script>` tag usage without your users needing to call `p5.registerAddon()` directly as long as they have included the addon `<script>` tag after the `<script>` tag including p5.js itself.
284284

285+
## Accessing custom actions
286+
In certain circumstances, such as when you have a library that listens to a certain browser event, you may wish to run a function that your user defined on the global scope, much like how a `click` event triggers a user defined `mouseClicked()` function. We call these functions "custom actions" and your addon can access any of them through `this._customActions` object.
287+
288+
The following addon snippet listens to the `click` event on a custom button element.
289+
```js
290+
function myAddon(p5, fn, lifecycles){
291+
lifecycles.presetup = function(){
292+
let customButton = this.createButton('click me');
293+
customButton.elt.addEventListener('click', this._customActions.myAddonButtonClicked);
294+
};
295+
}
296+
```
297+
298+
In a sketch that uses the above addon, a user can define the following:
299+
```js
300+
function setup(){
301+
createCanvas(400, 400);
302+
}
303+
304+
function myAddonButtonClicked(){
305+
// This function will be run each time the button created by the addon is clicked
306+
}
307+
```
308+
309+
Please note that in the above example, if the user does not define `function myAddonButtonClicked()` in their code, `this._customActions.myAddonButtonClicked` will return `undefined`. This means that if you are planning to call the custom action function directly in your code, you should include an `if` statement check to make sure that `this._customActions.myAddonButtonClicked` is defined.
310+
311+
Overall, this custom actions approach supports accessing the custom action functions in both global mode and instance mode with the same code, simplifying your code from what it otherwise may need to be.
285312

286313
## Next steps
287314

@@ -315,6 +342,19 @@ fn.myMethod = function(){
315342

316343
**p5.js library filenames are also prefixed with p5, but the next word is lowercase** to distinguish them from classes. For example, p5.sound.js. You are encouraged to follow this format for naming your file.
317344

345+
**In some cases, you will need to make sure your addon cleans up after itself after a p5.js sketch is removed** by the user calling `remove()`. This means adding relevant clean up code in the `lifecycles.remove` hook. In most circumstances, you don't need to do this with the main exception being cleaning up event handlers: if you are using event handlers (ie. calling `addEventListeners`), you will need to make sure those event handlers are also removed when a sketch is removed. p5.js provides a handy method to automatically remove any registered event handlers with and internal property `this._removeSignal`. When registering an event handler, include `this._removeSignal` as follow:
346+
```js
347+
function myAddon(p5, fn, lifecycles){
348+
lifecycles.presetup = function(){
349+
// ... Define `target` ...
350+
target.addEventListener('click', function() { }, {
351+
signal: this._removeSignal
352+
});
353+
};
354+
}
355+
```
356+
With this you will not need to manually define a clean up actions for event handlers in `lifecycles.remove` and all event handlers associated with the `this._removeSignal` property as above will be automtically cleaned up on sketch removal.
357+
318358
**Packaging**
319359

320360
**Create a single JS file that contains your library.** This makes it easy for users to add it to their projects. We suggest using a [bundler](https://rollupjs.org/) for your library. You may want to provide options for both the normal JavaScript file for sketching/debugging and a [minified](https://terser.org/) version for faster loading.

docs/parameterData.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@
325325
"windowResized": {
326326
"overloads": [
327327
[
328-
"UIEvent?"
328+
"Event?"
329329
]
330330
]
331331
},

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
"test/**/*.js": "eslint",
1919
"utils/**/*.{js,mjs}": "eslint"
2020
},
21-
"version": "2.0.5-rc.0",
21+
"version": "2.0.5",
2222
"dependencies": {
2323
"@davepagurek/bezier-path": "^0.0.2",
2424
"@japont/unicode-range": "^1.0.0",

rollup.config.mjs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ const bundleSize = (name, sourcemap) => {
3838

3939
const modules = ['math'];
4040
const generateModuleBuild = () => {
41-
return modules.map((module) => {
41+
return modules.map(module => {
4242
return {
4343
input: `src/${module}/index.js`,
4444
output: [
@@ -83,7 +83,7 @@ const generateModuleBuild = () => {
8383
});
8484
};
8585

86-
rmSync("./dist", {
86+
rmSync('./dist', {
8787
force: true,
8888
recursive: true
8989
});

src/accessibility/describe.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,11 @@ function describe(p5, fn){
7575
*
7676
* <div>
7777
* <code>
78-
*
78+
*
7979
* function setup(){
8080
* createCanvas(100, 100);
8181
* };
82-
*
82+
*
8383
* function draw() {
8484
* background(200);
8585
*
@@ -101,11 +101,11 @@ function describe(p5, fn){
101101
*
102102
* <div>
103103
* <code>
104-
*
104+
*
105105
* function setup(){
106106
* createCanvas(100, 100);
107107
* }
108-
*
108+
*
109109
* function draw() {
110110
* background(200);
111111
*

src/accessibility/gridOutput.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,8 @@ function gridOutput(p5, fn){
7171
//if empty cell of location of shape is undefined
7272
if (!cells[ingredients[x][y].loc.locY][ingredients[x][y].loc.locX]) {
7373
//fill it with shape info
74-
cells[ingredients[x][y].loc.locY][ingredients[x][y].loc.locX] = fill;
74+
cells[ingredients[x][y].loc.locY][ingredients[x][y].loc.locX] =
75+
fill;
7576
//if a shape is already in that location
7677
} else {
7778
//add it

src/accessibility/outputs.js

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -81,11 +81,11 @@ function outputs(p5, fn){
8181
*
8282
* <div>
8383
* <code>
84-
*
84+
*
8585
* function setup(){
8686
* createCanvas(100, 100);
8787
* }
88-
*
88+
*
8989
* function draw() {
9090
* // Add the text description.
9191
* textOutput();
@@ -106,11 +106,11 @@ function outputs(p5, fn){
106106
*
107107
* <div>
108108
* <code>
109-
*
109+
*
110110
* function setup(){
111111
* createCanvas(100, 100);
112112
* }
113-
*
113+
*
114114
* function draw() {
115115
* // Add the text description and
116116
* // display it for debugging.
@@ -225,11 +225,11 @@ function outputs(p5, fn){
225225
*
226226
* <div>
227227
* <code>
228-
*
228+
*
229229
* function setup() {
230230
* createCanvas(100, 100);
231231
* }
232-
*
232+
*
233233
* function draw() {
234234
* // Add the grid description.
235235
* gridOutput();
@@ -250,11 +250,11 @@ function outputs(p5, fn){
250250
*
251251
* <div>
252252
* <code>
253-
*
253+
*
254254
* function setup(){
255255
* createCanvas(100, 100);
256256
* }
257-
*
257+
*
258258
* function draw() {
259259
* // Add the grid description and
260260
* // display it for debugging.
@@ -561,7 +561,8 @@ function outputs(p5, fn){
561561

562562
//gets position of shape in the canvas
563563
fn._getPos = function (x, y) {
564-
const { x: transformedX, y: transformedY } = this.worldToScreen(new p5.Vector(x, y));
564+
const { x: transformedX, y: transformedY } =
565+
this.worldToScreen(new p5.Vector(x, y));
565566
const canvasWidth = this.width;
566567
const canvasHeight = this.height;
567568
if (transformedX < 0.4 * canvasWidth) {

src/app.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ import webgl from './webgl';
5151
webgl(p5);
5252

5353
// typography
54-
import type from './type'
54+
import type from './type';
5555
type(p5);
5656

5757
import { waitForDocumentReady, waitingForTranslator, _globalInit } from './core/init';

0 commit comments

Comments
 (0)