diff --git a/.github/workflows/demo.yml b/.github/workflows/docs+demo.yml similarity index 100% rename from .github/workflows/demo.yml rename to .github/workflows/docs+demo.yml diff --git a/.gitignore b/.gitignore index d53184c..c52bd06 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,6 @@ node_modules dist -docs +docs/(!demo) *.log tmp build \ No newline at end of file diff --git a/example/demo.css b/docs/demo/demo.css similarity index 100% rename from example/demo.css rename to docs/demo/demo.css diff --git a/example/demo.ts b/docs/demo/demo.js similarity index 51% rename from example/demo.ts rename to docs/demo/demo.js index a8fd11e..2e781dd 100644 --- a/example/demo.ts +++ b/docs/demo/demo.js @@ -1,35 +1,39 @@ -import { configure, fs, type DeviceFS } from '@zenfs/core'; +import { configure, fs } from '@zenfs/core'; import { framebuffer, dsp } from '@zenfs/devices'; // this is optional, but I set them, so I have control -const canvas = document.querySelector('#fb')!; +const canvas = document.querySelector('#fb'); +const { width, height } = canvas; + const audioContext = new AudioContext(); // add initial devices like /dev/null, etc await configure({ addDevices: true }); -const devfs = fs.mounts.get('/dev') as DeviceFS; +const devfs = fs.mounts.get('/dev'); // mount framebuffer & dsp devfs.createDevice('/fb0', framebuffer({ canvas })); devfs.createDevice('/dsp', await dsp({ audioContext })); // example: write static to framebuffer -const screen = new Uint8Array(canvas.width * canvas.height * 4); -function makestaticFb() { - for (let i = 0; i < screen.byteLength; i += 4) { - screen[i] = Math.random() * 255; - screen[i + 1] = Math.random() * 255; - screen[i + 2] = Math.random() * 255; - screen[i + 3] = 255; +const screen = new Uint8Array(width * height * 4); + +function makeGradientFb() { + for (let y = 0; y < height; y++) { + for (let x = 0; x < width; x++) { + const index = (y * width + x) * 4; + const gradientValue = (x / width) * 255; + screen.set([gradientValue, gradientValue, 255 - gradientValue, 255], index); + } } fs.promises.writeFile('/dev/fb0', screen); - requestAnimationFrame(makestaticFb); + requestAnimationFrame(makeGradientFb); } -makestaticFb(); +makeGradientFb(); // example: write static to audio -const audioBuffer = new Float32Array(new ArrayBuffer(audioContext.sampleRate * 4)); +const audioBuffer = new Float32Array(audioContext.sampleRate * 4); setInterval(() => { for (let i in audioBuffer) { audioBuffer[i] = Math.random() * 2 - 1; diff --git a/example/index.html b/docs/demo/index.html similarity index 58% rename from example/index.html rename to docs/demo/index.html index 9a471f7..de3215f 100644 --- a/example/index.html +++ b/docs/demo/index.html @@ -6,6 +6,13 @@

This will demonstrate drawing to a framebuffer & creating audio:

- + + diff --git a/example/tsconfig.json b/example/tsconfig.json deleted file mode 100644 index 08dddad..0000000 --- a/example/tsconfig.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "extends": "../tsconfig.json", - "compilerOptions": { - "noEmit": true - }, - "include": ["*.ts", "demo.ts"], - "exclude": ["node_modules"] -} diff --git a/package.json b/package.json index 0a3392d..c98ac3f 100644 --- a/package.json +++ b/package.json @@ -44,7 +44,7 @@ "format:check": "prettier --check .", "lint": "eslint src", "build": "tsc -p tsconfig.json", - "build:docs": "vite build", + "build:docs": "typedoc", "test": "tsx --test --experimental-test-coverage", "prepublishOnly": "npm run build", "start": "vite", diff --git a/vite.config.js b/vite.config.js deleted file mode 100644 index 2a59f63..0000000 --- a/vite.config.js +++ /dev/null @@ -1,15 +0,0 @@ -import { defineConfig } from 'vite'; - -export default defineConfig({ - base: './', - root: './example', - build: { - outDir: '../docs/demo', - emptyOutDir: true, - }, - resolve: { - alias: { - '@zenfs/devices': '../src/index.ts', - }, - }, -});