Skip to content

Commit 229269f

Browse files
committed
Support WebGPU reference items/examples
1 parent 35a287c commit 229269f

File tree

6 files changed

+27
-2
lines changed

6 files changed

+27
-2
lines changed

src/components/CodeEmbed/index.jsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { useState, useEffect, useRef } from "preact/hooks";
22
import { useLiveRegion } from '../hooks/useLiveRegion';
33
import CodeMirror, { EditorView } from "@uiw/react-codemirror";
44
import { javascript } from "@codemirror/lang-javascript";
5-
import { cdnLibraryUrl, cdnSoundUrl } from "@/src/globals/globals";
5+
import { cdnLibraryUrl, cdnSoundUrl, cdnWebGPUUrl } from "@/src/globals/globals";
66

77
import { CodeFrame } from "./frame";
88
import { CopyCodeButton } from "../CopyCodeButton";
@@ -99,6 +99,7 @@ export const CodeEmbed = (props) => {
9999
lazyLoad={props.lazyLoad}
100100
scripts={[
101101
...(props.includeSound ? [cdnSoundUrl] : []),
102+
...(props.includeWebGPU ? [cdnWebGPUUrl] : []),
102103
...(props.scripts ?? []),
103104
]}
104105
/>

src/content/reference/config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ export const referenceSchema = z.object({
8686
.or(z.literal("true").transform(() => true))
8787
.or(z.literal("false").transform(() => false))
8888
.optional(),
89+
webgpu: z.coerce.boolean().optional(),
8990
});
9091

9192
export const referenceCollection = defineCollection({

src/content/ui/en.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,7 @@ LibrariesLayout:
198198
experimentalApi:
199199
title: This API is experimental
200200
description: Its behavior may change in a future version of p5.js.
201+
webgpuAddon: This feature requires the p5.webgpu.js addon.
201202
attribution:
202203
Remixed by: Remixed by
203204
Revised in 2023 by: Revised in 2023 by

src/globals/globals.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,6 @@ export const cdnSoundUrl =
2626
(!!import.meta.env?.PUBLIC_P5_LIBRARY_PATH || p5Version.startsWith('2'))
2727
? `https://cdn.jsdelivr.net/npm/p5.sound@${p5SoundVersion}/dist/p5.sound.min.js` as const
2828
: `https://cdn.jsdelivr.net/npm/p5@${p5Version}/lib/addons/p5.sound.min.js` as const
29+
export const cdnWebGPUUrl =
30+
import.meta.env?.PUBLIC_P5_WEBGPU_LIBRARY_PATH ||
31+
(`https://cdn.jsdelivr.net/npm/p5@${p5Version}/lib/p5.webgpu.min.js` as const);

src/layouts/ReferenceItemLayout.astro

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,17 @@ function normalizeP5ReferenceLinks(html: string | undefined): string | undefined
125125
<p>{t('experimentalApi', 'description')}</p>
126126
</div>
127127
)}
128+
{entry.data.webgpu && (
129+
<div class="experimental">
130+
<p>
131+
<div
132+
class="inline-block mr-2 w-[20px] h-[20px] mb-[-2px]"
133+
set:html={flask}
134+
/>
135+
{t('webgpuAddon')}
136+
</p>
137+
</div>
138+
)}
128139
{entry.data.deprecated && (
129140
<div class="deprecated">
130141
<h5>
@@ -152,6 +163,7 @@ function normalizeP5ReferenceLinks(html: string | undefined): string | undefined
152163
lazyLoad={false}
153164
allowSideBySide={true}
154165
includeSound={entry.data.module === 'p5.sound'}
166+
includeWebGPU={entry.data.webgpu}
155167
/>
156168
)
157169
} else if (part.startsWith('<pre>')) {
@@ -187,6 +199,7 @@ function normalizeP5ReferenceLinks(html: string | undefined): string | undefined
187199
lazyLoad={false}
188200
allowSideBySide={true}
189201
includeSound={entry.data.module === 'p5.sound'}
202+
includeWebGPU={entry.data.webgpu}
190203
/>
191204
);
192205
})}

src/scripts/parsers/reference.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,13 @@ export const parseLibraryReference =
4444
// If we're using a custom build of p5 instead of a public release, create
4545
// a build and copy it to the specified path
4646
if (process.env.PUBLIC_P5_LIBRARY_PATH) {
47-
await createP5Build('p5.js', `../../../public${ process.env.PUBLIC_P5_LIBRARY_PATH}`);
47+
await createP5Build('p5.js', `../../../public${process.env.PUBLIC_P5_LIBRARY_PATH}`);
48+
}
49+
if (process.env.PUBLIC_P5_WEBGPU_LIBRARY_PATH) {
50+
await fs.cp(
51+
path.join(__dirname, 'in', 'p5.js', 'lib', 'p5.webgpu.js'),
52+
path.join(__dirname, `../../../public${process.env.PUBLIC_P5_WEBGPU_LIBRARY_PATH}`),
53+
);
4854
}
4955

5056
// Copy the reference output so we can process it

0 commit comments

Comments
 (0)