Skip to content

Commit 9a71404

Browse files
authored
Use iframes (#369)
* Use iframes This PR removes react and next. It allows a sample to be pure JavaScript (though there are none at the moment). It allows samples to be standalone so that they run separate from the sample selection menu.
1 parent bcba0c6 commit 9a71404

File tree

224 files changed

+12551
-12331
lines changed

Some content is hidden

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

224 files changed

+12551
-12331
lines changed

.eslintrc.cjs

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
module.exports = {
2+
parser: '@typescript-eslint/parser',
3+
extends: [
4+
'plugin:@typescript-eslint/recommended',
5+
'plugin:prettier/recommended',
6+
],
7+
plugins: ['@typescript-eslint', 'eslint-plugin-html', 'prettier'],
8+
rules: {
9+
'@typescript-eslint/no-unused-vars': [
10+
'error',
11+
{ vars: 'all', args: 'after-used', ignoreRestSiblings: true },
12+
],
13+
},
14+
};

.eslintrc.js

-27
This file was deleted.

.github/workflows/build-and-deploy.yml

-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ jobs:
2929
npm ci
3030
npm run-script lint
3131
npm run-script build
32-
npm run-script export
3332
touch out/.nojekyll
3433
3534
- name: Deploy 🚀

.github/workflows/build.yml

-1
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,3 @@ jobs:
3232
npm ci
3333
npm run-script lint
3434
npm run-script build
35-
npm run-script export

.prettierrc.js .prettierrc.cjs

File renamed without changes.

build/lib/copyAndWatch.js

+62
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
import chokidar from 'chokidar';
2+
import fs from 'fs';
3+
import path from 'path';
4+
5+
const debug = console.log; //() => {};
6+
const removeLeadingSlash = (s) => s.replace(/^\//, '');
7+
8+
/**
9+
* Recursively copies files and watches for changes.
10+
*
11+
* Example:
12+
*
13+
* copyAndWatch([
14+
* {src: "src\/**\/*.js", srcPrefix: "src", dst: "out"}, // would copy src/bar/moo.js -> out/bar/moo.js
15+
* {src: "index.html", dst: "out"}, // copies index.html -> out/index.html
16+
* ]);
17+
*
18+
* @param {*} paths [{src: glob, srcPrefix: string, dst: string }]
19+
* @param {*} options { watch: true/false } // watch: false = just copy and exit.
20+
*/
21+
export function copyAndWatch(paths, { watch } = { watch: true }) {
22+
for (const { src, srcPrefix, dst } of paths) {
23+
const watcher = chokidar.watch(src, {
24+
ignored: /(^|[\/\\])\../, // ignore dot files
25+
persistent: watch,
26+
});
27+
28+
const makeDstPath = (path, dst) =>
29+
`${dst}/${removeLeadingSlash(
30+
path.startsWith(srcPrefix) ? path.substring(srcPrefix.length) : path
31+
)}`;
32+
33+
watcher
34+
.on('addDir', (srcPath) => {
35+
const dstPath = makeDstPath(srcPath, dst);
36+
debug('addDir:', srcPath, dstPath);
37+
fs.mkdirSync(dstPath, { recursive: true });
38+
})
39+
.on('add', (srcPath) => {
40+
const dstPath = makeDstPath(srcPath, dst);
41+
const dir = path.dirname(dstPath);
42+
fs.mkdirSync(dir, { recursive: true });
43+
debug('add:', srcPath, dstPath);
44+
fs.copyFileSync(srcPath, dstPath);
45+
})
46+
.on('change', (srcPath) => {
47+
const dstPath = makeDstPath(srcPath, dst);
48+
debug('change:', srcPath, dstPath);
49+
fs.copyFileSync(srcPath, dstPath);
50+
})
51+
.on('unlink', (srcPath) => {
52+
const dstPath = makeDstPath(srcPath, dst);
53+
debug('unlink:', srcPath, dstPath);
54+
fs.unlinkSync(dstPath);
55+
})
56+
.on('ready', () => {
57+
if (!watch) {
58+
watcher.close();
59+
}
60+
});
61+
}
62+
}

build/lib/readdir.js

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import fs from 'fs';
2+
import path from 'path';
3+
4+
// not needed in node v20+
5+
export function readDirSyncRecursive(dir) {
6+
const basename = path.basename(dir);
7+
const entries = fs.readdirSync(dir, { withFileTypes: true });
8+
return entries
9+
.map((entry) =>
10+
entry.isDirectory()
11+
? readDirSyncRecursive(`${dir}/${entry.name}`)
12+
: entry.name
13+
)
14+
.flat()
15+
.map((name) => `${basename}/${name}`);
16+
}

build/tools/build.js

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { spawn } from 'child_process';
2+
import { mkdirSync } from 'fs';
3+
4+
mkdirSync('out', { recursive: true });
5+
6+
spawn('node', ['build/tools/copy.js'], {
7+
shell: true,
8+
stdio: 'inherit',
9+
});
10+
11+
spawn('./node_modules/.bin/rollup', ['-c'], {
12+
shell: true,
13+
stdio: 'inherit',
14+
});

build/tools/copy.js

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { copyAndWatch } from '../lib/copyAndWatch.js';
2+
3+
const watch = !!process.argv[2];
4+
5+
copyAndWatch(
6+
[
7+
{ src: 'public/**/*', srcPrefix: 'public', dst: 'out' },
8+
{ src: 'meshes/**/*', dst: 'out' },
9+
{ src: 'sample/**/*', dst: 'out' },
10+
{ src: 'shaders/**/*', dst: 'out' },
11+
{ src: 'index.html', dst: 'out' },
12+
],
13+
{ watch }
14+
);

build/tools/serve.js

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { spawn } from 'child_process';
2+
import { mkdirSync } from 'fs';
3+
4+
mkdirSync('out', { recursive: true });
5+
6+
spawn('npm', ['run', 'watch'], {
7+
shell: true,
8+
stdio: 'inherit',
9+
});
10+
11+
spawn('node', ['build/tools/copy.js', '1'], {
12+
shell: true,
13+
stdio: 'inherit',
14+
});
15+
16+
spawn('./node_modules/.bin/servez', ['out'], {
17+
shell: true,
18+
stdio: 'inherit',
19+
});

index.html

+86
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta charset="utf-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
6+
<title>WebGPU Samples</title>
7+
<meta
8+
name="description"
9+
content="The WebGPU Samples are a set of samples demonstrating the use of the WebGPU API."
10+
/>
11+
<meta
12+
name="viewport"
13+
content="width=device-width, initial-scale=1, shrink-to-fit=no"
14+
/>
15+
16+
<link
17+
href="https://fonts.googleapis.com/css?family=Inconsolata&display=swap"
18+
rel="stylesheet"
19+
/>
20+
<link
21+
rel="icon"
22+
type="image/x-icon"
23+
href="favicon.ico"
24+
/>
25+
26+
<link href="css/styles.css" rel="stylesheet">
27+
28+
</head>
29+
<script defer type="module" src="main.js"></script>
30+
<body>
31+
<div class="wrapper">
32+
<nav class="panel container">
33+
<h1>
34+
<a href="./">WebGPU Samples</a>
35+
</h1>
36+
<input type="checkbox" id="menuToggle">
37+
<label class="expand" for="menuToggle"></label>
38+
<div class="panelContents">
39+
<a href="https://github.com/webgpu/webpgu-samples">
40+
Github
41+
</a>
42+
<hr>
43+
<div id="samplelist"></div>
44+
<hr>
45+
<h3 style="margin-bottom: 5px">Other Pages</h3>
46+
<ul class="exampleList">
47+
<li>
48+
<a
49+
rel="noreferrer"
50+
target="_blank"
51+
href="./workload-simulator.html"
52+
>
53+
Workload Simulator ↗️
54+
</a>
55+
</li>
56+
</ul>
57+
</div>
58+
</nav>
59+
60+
<main>
61+
<div id="intro">
62+
<p>
63+
The WebGPU Samples are a set of samples and demos demonstrating the use
64+
of the <a href="//webgpu.dev">WebGPU API</a>. Please see the current
65+
implementation status and how to run WebGPU in your browser at
66+
<a href="//webgpu.io">webgpu.io</a>.
67+
</p>
68+
</div>
69+
<div id="sample" style="display: none;">
70+
<div>
71+
<h1 id="title"></h1>
72+
<a id="src" target="_blank" rel="noreferrer" href="">See it on Github!</a>
73+
<p id="description"></p>
74+
<div class="sampleContainer"></div>
75+
</div>
76+
</div>
77+
<nav id="code" class="sourceFileNav">
78+
<div>
79+
<ul id="codeTabs"></ul>
80+
</div>
81+
</nav>
82+
<div id="sources"></div>
83+
</main>
84+
</div>
85+
</body>
86+
</html>

src/meshes/box.ts meshes/box.ts

File renamed without changes.

src/meshes/cube.ts meshes/cube.ts

File renamed without changes.

src/meshes/mesh.ts meshes/mesh.ts

File renamed without changes.
File renamed without changes.

src/meshes/stanfordDragon.ts meshes/stanfordDragon.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import dragonRawData from 'stanford-dragon/4';
1+
import dragonRawData from './stanfordDragonData';
22
import { computeSurfaceNormals, computeProjectedPlaneUVs } from './utils';
33

44
export const mesh = {

meshes/stanfordDragonData.ts

+5
Large diffs are not rendered by default.
File renamed without changes.
File renamed without changes.

next-env.d.ts

-5
This file was deleted.

next.config.js

-46
This file was deleted.

0 commit comments

Comments
 (0)