Skip to content

Commit f840bc3

Browse files
Update p5.js to v2.1.0
1 parent ee8e155 commit f840bc3

File tree

679 files changed

+7739
-10704
lines changed

Some content is hidden

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

679 files changed

+7739
-10704
lines changed

public/reference/data.json

Lines changed: 4071 additions & 4778 deletions
Large diffs are not rendered by default.

public/search-indices/en.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

public/search-indices/es.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

public/search-indices/hi.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

public/search-indices/ko.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

public/search-indices/zh-Hans.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

src/content/contributor-docs/en/contributing_to_the_p5js_reference.mdx

Lines changed: 8 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ Finally, for every example you add, you are required to use the p5.js function `
305305
* </div>
306306
```
307307

308-
For more on `describe()` visit the [web accessibility contributor documentation](../web_accessibility/#describe).
308+
For more on `describe()` visit the [web accessibility contributor documentation](../web_accessibility/#describe), and the [Writing Accessible Canvas Descriptions](https://p5js.org/tutorials/writing-accessible-canvas-descriptions/) tutorial.
309309

310310
With all the above you should have most of the tools needed to write and edit p5.js reference comments. However, there are a few more specialized usage of JSDoc style reference comments that you may come across in p5.js. These are situationally useful and not something that you need often.
311311

@@ -380,36 +380,22 @@ Class constructors are defined with the `@class` tag and the `@constructor` tag.
380380

381381
The p5.js repository is set up so that you can generate and preview the reference without needing to build and run the p5.js website as well.
382382

383-
To do so, make sure you have committed and pushed your changes to a branch of your fork of p5.js.
384-
385-
**Important:** Make sure you're working with compatible branches:
386-
387-
- Use the `2.0` branch of p5.js-website with the `dev-2.0` branch of p5.js
388-
- Use the `main` branch of p5.js-website with the `main` branch of p5.js
389-
390-
* First, ensure you have the necessary dependencies installed in the p5.js-website repository:
383+
* The main command to generate the reference from the reference comments in the source code is to run the following command.
391384

392385
```
393-
npm install
386+
npm run docs
394387
```
395388

396-
* Then, in the p5.js-website repo, run the following command, using the URL of your fork of p5 before the `#`, and the name of your branch after the `#`:
389+
This will generate the necessary preview files and the main `docs/reference/data.json` file, which is the same file (after minification) that will be used to render the reference page on the website.
397390

398-
```
399-
npm run custom:dev https://github.com/yourUsername/p5.js.git#yourBranch
400-
```
401-
402-
This will build the reference from your branch and start a development preview of the website. A URL will be logged in the console that you can go to in your browser to test out your changes.
403-
404-
If everything is working correctly, your terminal output should look similar to this:
405-
![Terminal output showing successful npm run custom:dev execution](src/content/contributor-docs/images/custom-dev-terminal-output.png)
406-
407-
* When you're done, you can run this command to reset your changes:
391+
* For continuous work on the reference, you can run the following command.
408392

409393
```
410-
npm run custom:cleanup
394+
npm run docs:dev
411395
```
412396

397+
This will launch a live preview of the rendered reference that will update each time you make changes (you will need to refresh the page after making changes to see them appear). This is useful, especially for previewing example code running in the browser.
398+
413399
* The main template files are stored in the `docs/` folder and, in most cases, you should not make changes directly to files in this folder, except to add new asset files in the `docs/yuidoc-p5-theme/assets` folder.
414400

415401
## Next steps

src/content/contributor-docs/en/contributor_guidelines.mdx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,6 @@ Some of the key files and folders you will be in the p5.js folder are as follows
275275
* `src` - Where all the code that eventually gets combined into the final p5.js and p5.min.js files lives
276276
* [`test`](../unit_testing/) - Where unit tests and code for testing all documentation examples lives
277277
* `tasks` - Where detailed and custom build code lives
278-
* `Gruntfile.js` - This is the main build configuration file
279278
* `contributor_docs` - Where the documentation and all other contributor documentation lives
280279

281280
The other files and folders are either configurations or other kinds of support files; in most cases, you shouldn't need to make any modifications.

src/content/contributor-docs/en/creating_libraries.mdx

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,37 @@ if (typeof p5 !== undefined) {
283283

284284
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.
285285

286+
## Accessing custom actions
287+
288+
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.
289+
290+
The following addon snippet listens to the `click` event on a custom button element.
291+
292+
```js
293+
function myAddon(p5, fn, lifecycles){
294+
lifecycles.presetup = function(){
295+
let customButton = this.createButton('click me');
296+
customButton.elt.addEventListener('click', this._customActions.myAddonButtonClicked);
297+
};
298+
}
299+
```
300+
301+
In a sketch that uses the above addon, a user can define the following:
302+
303+
```js
304+
function setup(){
305+
createCanvas(400, 400);
306+
}
307+
308+
function myAddonButtonClicked(){
309+
// This function will be run each time the button created by the addon is clicked
310+
}
311+
```
312+
313+
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.
314+
315+
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.
316+
286317
## Next steps
287318

288319
Below are some extra tips about authoring your addon library.
@@ -315,6 +346,21 @@ fn.myMethod = function(){
315346

316347
**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.
317348

349+
**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:
350+
351+
```js
352+
function myAddon(p5, fn, lifecycles){
353+
lifecycles.presetup = function(){
354+
// ... Define `target` ...
355+
target.addEventListener('click', function() { }, {
356+
signal: this._removeSignal
357+
});
358+
};
359+
}
360+
```
361+
362+
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.
363+
318364
**Packaging**
319365

320366
**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.

src/content/contributor-docs/en/documentation_style_guide.mdx

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ Our community is large and diverse. Many people learn to code using p5.js, and a
3434

3535
* [Code Samples](#code-samples)
3636
* [Comments](#comments)
37+
* [Accessible Canvas Labels](#accessible-canvas-labels)
3738
* [Whitespace](#whitespace)
3839
* [Semicolons](#semicolons)
3940
* [Naming Conventions](#naming-conventions)
@@ -241,6 +242,47 @@ let magicWord = 'Please';
241242

242243
**[⬆ back to top](#table-of-contents)**
243244

245+
## Accessible Canvas Labels
246+
247+
* Use `describe()` to in p5.js example code, to add labels to your canvas so that it’s readable for screen readers.
248+
249+
> Why? It makes examples accessible to screen readers, and models how to write good canvas labels.
250+
251+
```javascript
252+
// Good.
253+
function setup() {
254+
createCanvas(100, 100);
255+
describe('A red heart in the bottom right corner of a pink background.');
256+
}
257+
258+
// Bad.
259+
function setup() {
260+
createCanvas(100, 100);
261+
describe('heart shape');
262+
}
263+
264+
// Good.
265+
function draw() {
266+
background(220);
267+
fill(0, 255, 0);
268+
ellipse(mouseX, 50, 40, 40);
269+
// Label updates with shape's translation.
270+
describe(`A green circle at x pos ${round(mouseX)} moving with the mouse pointer.`, LABEL);
271+
}
272+
```
273+
274+
* Don’t use screen reader labels as a way of commenting your code. Labels should only summarize the resulting visual elements within a canvas.
275+
276+
* Don’t overuse screen reader labels, as you may end up complicating the screen reader’s interpretation of the canvas rather than helping it.
277+
278+
* Do make your label descriptions short and accurate. The recommended length for label descriptions is one to two sentences. Use full sentences for your labels, and write in the present tense when describing elements.
279+
280+
The above examples and suggestions are based on the [Writing Accessible Canvas Descriptions tutorial](https://p5js.org/tutorials/writing-accessible-canvas-descriptions/). This tutorial gives more detailed guidance, and includes other ways to label your canvas, in addition to `describe()`: `describeElement()`, `textOutput()`, and `gridOutput()`.
281+
282+
To understand the structure of p5.js’ web accessibility features for contributors, see the [Web Accessibility Contributor Doc](../web_accessibility.md#user-generated-accessible-canvas-descriptions).
283+
284+
**[⬆ back to top](#table-of-contents)**
285+
244286
## Whitespace
245287

246288
* Indent blocks 2 spaces.

0 commit comments

Comments
 (0)