Skip to content

Commit a43196d

Browse files
authored
Merge branch 'main' into issue887-branch
2 parents ad46a78 + 90261ed commit a43196d

Some content is hidden

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

42 files changed

+272
-119
lines changed

public/reference/data.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"project": {
33
"name": "p5",
44
"description": "[![npm version](https://badge.fury.io/js/p5.svg)](https://www.npmjs.com/package/p5)",
5-
"version": "1.11.8",
5+
"version": "1.11.9",
66
"url": "https://github.com/processing/p5.js#readme"
77
},
88
"files": {
@@ -11233,7 +11233,7 @@
1123311233
"type": "p5.File"
1123411234
},
1123511235
"example": [
11236-
"\n<div>\n<code>\n// Use the file input to select an image to\n// load and display.\nlet input;\nlet img;\n\nfunction setup() {\n createCanvas(100, 100);\n\n // Create a file input and place it beneath\n // the canvas.\n input = createFileInput(handleImage);\n input.position(0, 100);\n\n describe('A gray square with a file input beneath it. If the user selects an image file to load, it is displayed on the square.');\n}\n\nfunction draw() {\n background(200);\n\n // Draw the image if loaded.\n if (img) {\n image(img, 0, 0, width, height);\n }\n}\n\n// Create an image if the file is an image.\nfunction handleImage(file) {\n if (file.type === 'image') {\n img = createImg(file.data, '');\n img.hide();\n } else {\n img = null;\n }\n}\n</code>\n</div>\n\n<div>\n<code>\n// Use the file input to select multiple images\n// to load and display.\nlet input;\nlet images = [];\n\nfunction setup() {\n // Create a file input and place it beneath\n // the canvas. Allow it to load multiple files.\n input = createFileInput(handleImage, true);\n input.position(0, 100);\n}\n\nfunction draw() {\n background(200);\n\n // Draw the images if loaded. Each image\n // is drawn 20 pixels lower than the\n // previous image.\n for (let i = 0; i < images.length; i += 1) {\n // Calculate the y-coordinate.\n let y = i * 20;\n\n // Draw the image.\n image(img, 0, y, 100, 100);\n }\n\n describe('A gray square with a file input beneath it. If the user selects multiple image files to load, they are displayed on the square.');\n}\n\n// Create an image if the file is an image,\n// then add it to the images array.\nfunction handleImage(file) {\n if (file.type === 'image') {\n let img = createImg(file.data, '');\n img.hide();\n images.push(img);\n }\n}\n</code>\n</div>"
11236+
"\n<div>\n<code>\n// Use the file input to select an image to\n// load and display.\nlet input;\nlet img;\n\nfunction setup() {\n createCanvas(100, 100);\n\n // Create a file input and place it beneath\n // the canvas.\n input = createFileInput(handleImage);\n input.position(0, 100);\n\n describe('A gray square with a file input beneath it. If the user selects an image file to load, it is displayed on the square.');\n}\n\nfunction draw() {\n background(200);\n\n // Draw the image if loaded.\n if (img) {\n image(img, 0, 0, width, height);\n }\n}\n\n// Create an image if the file is an image.\nfunction handleImage(file) {\n if (file.type === 'image') {\n img = createImg(file.data, '');\n img.hide();\n } else {\n img = null;\n }\n}\n</code>\n</div>\n\n<div>\n<code>\n// Use the file input to select multiple images\n// to load and display.\nlet input;\nlet images = [];\n\nfunction setup() {\n // Create a file input and place it beneath\n // the canvas. Allow it to load multiple files.\n input = createFileInput(handleImage, true);\n input.position(0, 100);\n}\n\nfunction draw() {\n background(200);\n\n // Draw the images if loaded. Each image\n // is drawn 20 pixels lower than the\n // previous image.\n for (let i = 0; i < images.length; i += 1) {\n // Calculate the y-coordinate.\n let y = i * 20;\n\n // Draw the image.\n image(images[i], 0, y, 100, 100);\n }\n\n describe('A gray square with a file input beneath it. If the user selects multiple image files to load, they are displayed on the square.');\n}\n\n// Create an image if the file is an image,\n// then add it to the images array.\nfunction handleImage(file) {\n if (file.type === 'image') {\n let img = createImg(file.data, '');\n img.hide();\n images.push(img);\n }\n}\n</code>\n</div>"
1123711237
],
1123811238
"class": "p5",
1123911239
"module": "DOM",
@@ -13468,7 +13468,7 @@
1346813468
{
1346913469
"file": "src/image/loading_displaying.js",
1347013470
"line": 888,
13471-
"description": "<p>Draws an image to the canvas.</p>\n<p>The first parameter, <code>img</code>, is the source image to be drawn. <code>img</code> can be\nany of the following objects:</p>\n<ul>\n<li><a href=\"#/p5.Image\">p5.Image</a></li>\n<li><a href=\"#/p5.Element\">p5.Element</a></li>\n<li><a href=\"#/p5.Texture\">p5.Texture</a></li>\n<li><a href=\"#/p5.Framebuffer\">p5.Framebuffer</a></li>\n<li><a href=\"#/p5.FramebufferTexture\">p5.FramebufferTexture</a></li>\n</ul>\n<p>The second and third parameters, <code>dx</code> and <code>dy</code>, set the coordinates of the\ndestination image's top left corner. See\n<a href=\"#/p5/imageMode\">imageMode()</a> for other ways to position images.</p>\n<p>Here's a diagram that explains how optional parameters work in <code>image()</code>:</p>\n<p><img src=\"assets/drawImage.png\"></img></p>\n<p>The fourth and fifth parameters, <code>dw</code> and <code>dh</code>, are optional. They set the\nthe width and height to draw the destination image. By default, <code>image()</code>\ndraws the full source image at its original size.</p>\n<p>The sixth and seventh parameters, <code>sx</code> and <code>sy</code>, are also optional.\nThese coordinates define the top left corner of a subsection to draw from\nthe source image.</p>\n<p>The eighth and ninth parameters, <code>sw</code> and <code>sh</code>, are also optional.\nThey define the width and height of a subsection to draw from the source\nimage. By default, <code>image()</code> draws the full subsection that begins at\n<code>(sx, sy)</code> and extends to the edges of the source image.</p>\n<p>The ninth parameter, <code>fit</code>, is also optional. It enables a subsection of\nthe source image to be drawn without affecting its aspect ratio. If\n<code>CONTAIN</code> is passed, the full subsection will appear within the destination\nrectangle. If <code>COVER</code> is passed, the subsection will completely cover the\ndestination rectangle. This may have the effect of zooming into the\nsubsection.</p>\n<p>The tenth and eleventh paremeters, <code>xAlign</code> and <code>yAlign</code>, are also\noptional. They determine how to align the fitted subsection. <code>xAlign</code> can\nbe set to either <code>LEFT</code>, <code>RIGHT</code>, or <code>CENTER</code>. <code>yAlign</code> can be set to\neither <code>TOP</code>, <code>BOTTOM</code>, or <code>CENTER</code>. By default, both <code>xAlign</code> and <code>yAlign</code>\nare set to <code>CENTER</code>.</p>\n",
13471+
"description": "<p>Draws an image to the canvas.</p>\n<p>The first parameter, <code>img</code>, is the source image to be drawn. <code>img</code> can be\nany of the following objects:</p>\n<ul>\n<li><a href=\"#/p5.Image\">p5.Image</a></li>\n<li><a href=\"#/p5.Element\">p5.Element</a></li>\n<li><a href=\"#/p5.Texture\">p5.Texture</a></li>\n<li><a href=\"#/p5.Framebuffer\">p5.Framebuffer</a></li>\n<li><a href=\"#/p5.FramebufferTexture\">p5.FramebufferTexture</a></li>\n</ul>\n<p>The second and third parameters, <code>dx</code> and <code>dy</code>, set the coordinates of the\ndestination image's top left corner. See\n<a href=\"#/p5/imageMode\">imageMode()</a> for other ways to position images.</p>\n<p>Here's a diagram that explains how optional parameters work in <code>image()</code>:</p>\n<p><img src=\"assets/drawImage.png\"></img></p>\n<p>The fourth and fifth parameters, <code>dw</code> and <code>dh</code>, are optional. They set the\nthe width and height to draw the destination image. By default, <code>image()</code>\ndraws the full source image at its original size.</p>\n<p>The sixth and seventh parameters, <code>sx</code> and <code>sy</code>, are also optional.\nThese coordinates define the top left corner of a subsection to draw from\nthe source image.</p>\n<p>The eighth and ninth parameters, <code>sw</code> and <code>sh</code>, are also optional.\nThey define the width and height of a subsection to draw from the source\nimage. By default, <code>image()</code> draws the full subsection that begins at\n<code>(sx, sy)</code> and extends to the edges of the source image.</p>\n<p>The ninth parameter, <code>fit</code>, is also optional. It enables a subsection of\nthe source image to be drawn without affecting its aspect ratio. If\n<code>CONTAIN</code> is passed, the full subsection will appear within the destination\nrectangle. If <code>COVER</code> is passed, the subsection will completely cover the\ndestination rectangle. This may have the effect of zooming into the\nsubsection.</p>\n<p>The tenth and eleventh parameters, <code>xAlign</code> and <code>yAlign</code>, are also\noptional. They determine how to align the fitted subsection. <code>xAlign</code> can\nbe set to either <code>LEFT</code>, <code>RIGHT</code>, or <code>CENTER</code>. <code>yAlign</code> can be set to\neither <code>TOP</code>, <code>BOTTOM</code>, or <code>CENTER</code>. By default, both <code>xAlign</code> and <code>yAlign</code>\nare set to <code>CENTER</code>.</p>\n",
1347213472
"itemtype": "method",
1347313473
"name": "image",
1347413474
"example": [
@@ -19728,7 +19728,7 @@
1972819728
"type": "Number"
1972919729
},
1973019730
"example": [
19731-
"\n<div>\n<code>\nfunction setup() {\n createCanvas(100, 100);\n\n background(200);\n\n // Caclulate the angle conversion.\n let deg = 45;\n let rad = radians(deg);\n\n // Display the angle conversion.\n text(`${deg}˚ = ${round(rad, 3)} rad`, 10, 50);\n\n describe('The text \"45˚ = 0.785 rad\".');\n}\n</code>\n</div>"
19731+
"\n<div>\n<code>\nfunction setup() {\n createCanvas(100, 100);\n\n background(200);\n\n // Calculate the angle conversion.\n let deg = 45;\n let rad = radians(deg);\n\n // Display the angle conversion.\n text(`${deg}˚ = ${round(rad, 3)} rad`, 10, 50);\n\n describe('The text \"45˚ = 0.785 rad\".');\n}\n</code>\n</div>"
1973219732
],
1973319733
"class": "p5",
1973419734
"module": "Math",

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/components/Banner/index.astro

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const { link, title } = entry.data;
99
<a class="banner-content" href={link} target="_blank">
1010
<Content />
1111
</a>
12-
<button id="hideBanner"><Icon kind="close"></button>
12+
<button id="hideBanner" aria-label="Hide banner"><Icon kind="close" /></button>
1313
</div>
1414

1515
<script>

src/components/CodeEmbed/index.jsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { useState, useEffect, useRef } from "preact/hooks";
2+
import { useLiveRegion } from '../hooks/useLiveRegion';
23
import CodeMirror, { EditorView } from "@uiw/react-codemirror";
34
import { javascript } from "@codemirror/lang-javascript";
45
import { cdnLibraryUrl, cdnSoundUrl } from "@/src/globals/globals";
@@ -25,6 +26,7 @@ import { Icon } from "../Icon";
2526
* }
2627
*/
2728
export const CodeEmbed = (props) => {
29+
const { ref: liveRegionRef, announce } = useLiveRegion();
2830
const [rendered, setRendered] = useState(false);
2931
const initialCode = props.initialValue ?? "";
3032
// Source code from Google Docs sometimes uses a unicode non-breaking space
@@ -59,6 +61,7 @@ export const CodeEmbed = (props) => {
5961
} else {
6062
setPreviewCodeString(codeString);
6163
}
64+
announce("Sketch is running");
6265
};
6366

6467
const [previewCodeString, setPreviewCodeString] = useState(codeString);
@@ -108,6 +111,7 @@ export const CodeEmbed = (props) => {
108111
className="bg-bg-gray-40"
109112
onClick={() => {
110113
setPreviewCodeString("");
114+
announce("Sketch stopped");
111115
}}
112116
ariaLabel="Stop sketch"
113117
>
@@ -148,6 +152,7 @@ export const CodeEmbed = (props) => {
148152
onClick={() => {
149153
setCodeString(initialCode);
150154
setPreviewCodeString(initialCode);
155+
announce("Code reset to initial value.");
151156
}}
152157
ariaLabel="Reset code to initial value"
153158
className="bg-white text-black"
@@ -156,6 +161,7 @@ export const CodeEmbed = (props) => {
156161
</CircleButton>
157162
</div>
158163
</div>
164+
<span ref={liveRegionRef} aria-live="polite" class="sr-only" />
159165
</div>
160166
);
161167
};
Lines changed: 62 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,20 @@
11
import { useState } from 'preact/hooks';
2+
import { useLiveRegion } from '../hooks/useLiveRegion';
23
import CircleButton from "../CircleButton";
34

45
interface CopyCodeButtonProps {
56
textToCopy: string;
7+
announceOnCopy?: string;
68
}
79

8-
export const CopyCodeButton = ({ textToCopy }: CopyCodeButtonProps) => {
10+
export const CopyCodeButton = ({
11+
textToCopy,
12+
announceOnCopy = 'Code copied to clipboard'
13+
}: CopyCodeButtonProps) => {
914
const [isCopied, setIsCopied] = useState(false);
1015

16+
const { ref: liveRegionRef, announce } = useLiveRegion<HTMLSpanElement>();
17+
1118
const copyTextToClipboard = async () => {
1219
console.log('Copy button clicked');
1320
console.log('Text to copy:', textToCopy);
@@ -16,6 +23,9 @@ export const CopyCodeButton = ({ textToCopy }: CopyCodeButtonProps) => {
1623
console.log('Using Clipboard API');
1724
await navigator.clipboard.writeText(textToCopy);
1825
console.log('Text copied successfully');
26+
27+
announce(announceOnCopy);
28+
1929
setIsCopied(true);
2030
setTimeout(() => {
2131
setIsCopied(false);
@@ -29,52 +39,56 @@ export const CopyCodeButton = ({ textToCopy }: CopyCodeButtonProps) => {
2939
console.log('Component rendered, isCopied:', isCopied);
3040

3141
return (
32-
<CircleButton
33-
onClick={() => {
34-
console.log('CircleButton clicked');
35-
copyTextToClipboard();
36-
}}
37-
ariaLabel="Copy code to clipboard"
38-
className={`bg-white ${isCopied ? 'text-green-600' : 'text-black'} transition-colors duration-200`}
39-
>
40-
{isCopied ? (
41-
<svg
42-
width="18"
43-
height="22"
44-
viewBox="0 0 24 24"
45-
fill="none"
46-
xmlns="http://www.w3.org/2000/svg"
47-
>
48-
<path
49-
d="M20 6L9 17L4 12"
50-
stroke="currentColor"
51-
strokeWidth="2"
52-
strokeLinecap="round"
53-
strokeLinejoin="round"
54-
/>
55-
</svg>
56-
) : (
57-
<svg
58-
width="18"
59-
height="22"
60-
viewBox="4 7 18 23"
61-
fill="none"
62-
xmlns="http://www.w3.org/2000/svg"
63-
>
64-
<path
65-
fillRule="evenodd"
66-
clipRule="evenodd"
67-
d="M 4.054 12.141 C 4.054 11.865 4.877 11.877 5.153 11.877 L 9.073 11.953 C 9.2 11.953 8.791 22.207 9.006 23.531 C 11.73 24.182 17.631 24.022 17.631 24.171 L 17.638 28.083 C 17.638 28.359 17.414 28.583 17.138 28.583 L 4.554 28.583 C 4.278 28.583 4.054 28.359 4.054 28.083 L 4.054 12.141 Z M 5.054 12.641 L 5.054 27.583 L 16.638 27.583 L 16.735 24.024 L 8.623 24.051 L 8.195 12.679 L 5.054 12.641 Z"
68-
fill="currentColor"
69-
/>
70-
<path
71-
fillRule="evenodd"
72-
clipRule="evenodd"
73-
d="M 8.14 8.083 C 8.14 7.807 8.364 7.583 8.64 7.583 L 21.224 7.583 C 21.5 7.583 21.724 7.807 21.724 8.083 L 21.724 24.025 C 21.724 24.301 21.5 24.525 21.224 24.525 L 8.64 24.525 C 8.364 24.525 8.14 24.301 8.14 24.025 L 8.14 8.083 Z M 9.14 8.583 L 9.14 23.525 L 20.724 23.525 L 20.724 8.583 L 9.14 8.583 Z"
74-
fill="currentColor"
75-
/>
76-
</svg>
77-
)}
78-
</CircleButton>
42+
<>
43+
<CircleButton
44+
onClick={() => {
45+
console.log('CircleButton clicked');
46+
copyTextToClipboard();
47+
}}
48+
ariaLabel="Copy code to clipboard"
49+
className={`bg-white ${isCopied ? 'text-green-600' : 'text-black'} transition-colors duration-200`}
50+
>
51+
{isCopied ? (
52+
<svg
53+
width="18"
54+
height="22"
55+
viewBox="0 0 24 24"
56+
fill="none"
57+
xmlns="http://www.w3.org/2000/svg"
58+
>
59+
<path
60+
d="M20 6L9 17L4 12"
61+
stroke="currentColor"
62+
strokeWidth="2"
63+
strokeLinecap="round"
64+
strokeLinejoin="round"
65+
/>
66+
</svg>
67+
) : (
68+
<svg
69+
width="18"
70+
height="22"
71+
viewBox="4 7 18 23"
72+
fill="none"
73+
xmlns="http://www.w3.org/2000/svg"
74+
>
75+
<path
76+
fillRule="evenodd"
77+
clipRule="evenodd"
78+
d="M 4.054 12.141 C 4.054 11.865 4.877 11.877 5.153 11.877 L 9.073 11.953 C 9.2 11.953 8.791 22.207 9.006 23.531 C 11.73 24.182 17.631 24.022 17.631 24.171 L 17.638 28.083 C 17.638 28.359 17.414 28.583 17.138 28.583 L 4.554 28.583 C 4.278 28.583 4.054 28.359 4.054 28.083 L 4.054 12.141 Z M 5.054 12.641 L 5.054 27.583 L 16.638 27.583 L 16.735 24.024 L 8.623 24.051 L 8.195 12.679 L 5.054 12.641 Z"
79+
fill="currentColor"
80+
/>
81+
<path
82+
fillRule="evenodd"
83+
clipRule="evenodd"
84+
d="M 8.14 8.083 C 8.14 7.807 8.364 7.583 8.64 7.583 L 21.224 7.583 C 21.5 7.583 21.724 7.807 21.724 8.083 L 21.724 24.025 C 21.724 24.301 21.5 24.525 21.224 24.525 L 8.64 24.525 C 8.364 24.525 8.14 24.301 8.14 24.025 L 8.14 8.083 Z M 9.14 8.583 L 9.14 23.525 L 20.724 23.525 L 20.724 8.583 L 9.14 8.583 Z"
85+
fill="currentColor"
86+
/>
87+
</svg>
88+
)}
89+
</CircleButton>
90+
{/* Visually hidden live region for accessibility announcements */}
91+
<span ref={liveRegionRef} aria-live="polite" class="sr-only" />
92+
</>
7993
);
8094
};

src/components/LinkButton/index.astro

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ switch (variant) {
2020
---
2121

2222
<a
23-
class={"button-link outline outline-1 outline-type-color py-2 px-4 flex flex-nowrap w-fit items-center justify-between rounded-full hover:bg-sidebar-type-color hover:text-bg-color hover:no-underline " +
23+
class={"button-link border border-1 border-sidebar-type-color py-2 px-4 flex flex-nowrap w-fit items-center justify-between rounded-full hover:bg-sidebar-type-color hover:text-bg-color hover:no-underline " +
2424
Astro.props.class}
2525
href={url}
2626
>

0 commit comments

Comments
 (0)