From 7b3aeee90f84a3a2307e9650ae77c34f026d99c9 Mon Sep 17 00:00:00 2001
From: Edo <0xe1216@gmail.com>
Date: Fri, 19 Sep 2025 14:43:28 +0400
Subject: [PATCH 1/2] feat: update demo
---
react_app_demo/README.md | 110 +-
react_app_demo/config-overrides.js | 25 -
react_app_demo/index.html | 17 +
react_app_demo/package.json | 45 +-
react_app_demo/src/App.css | 160 +--
react_app_demo/src/App.js | 26 -
react_app_demo/src/App.test.js | 9 -
react_app_demo/src/App.tsx | 33 +
.../src/components/Canvas/Canvas.css | 167 +++
.../src/components/Canvas/Canvas.js | 136 --
.../src/components/Canvas/Canvas.tsx | 241 ++++
.../src/components/Canvas/package.json | 6 -
react_app_demo/src/index.css | 29 +-
react_app_demo/src/index.js | 12 -
react_app_demo/src/main.tsx | 10 +
react_app_demo/src/serviceWorker.js | 135 --
react_app_demo/src/types.d.ts | 4 +
react_app_demo/src/vite-env.d.ts | 1 +
react_app_demo/tsconfig.json | 19 +
react_app_demo/vite.config.ts | 17 +
site/src/demo.html | 76 +-
site/src/scripts/demo.js | 1209 ++++++++++-------
site/src/scripts/script.js | 760 +++++++----
webpack_demo/README.md | 14 +-
webpack_demo/index.html | 372 +++--
webpack_demo/js/index.js | 368 -----
webpack_demo/package.json | 37 +-
.../{js => src/assets}/blue_metro.jpg | Bin
.../{js => src/assets}/daisies_fuji.jpg | Bin
.../{js => src/assets}/daisies_med.jpg | Bin
.../{js => src/assets}/nine_yards.jpg | Bin
.../{js => src/assets}/underground.jpg | Bin
webpack_demo/{js => src/assets}/wasm_logo.png | Bin
webpack_demo/src/global.d.ts | 14 +
webpack_demo/src/index.ts | 507 +++++++
webpack_demo/tsconfig.json | 14 +
webpack_demo/webpack.config.js | 112 +-
37 files changed, 2599 insertions(+), 2086 deletions(-)
delete mode 100644 react_app_demo/config-overrides.js
create mode 100644 react_app_demo/index.html
delete mode 100644 react_app_demo/src/App.js
delete mode 100644 react_app_demo/src/App.test.js
create mode 100644 react_app_demo/src/App.tsx
delete mode 100644 react_app_demo/src/components/Canvas/Canvas.js
create mode 100644 react_app_demo/src/components/Canvas/Canvas.tsx
delete mode 100644 react_app_demo/src/components/Canvas/package.json
delete mode 100644 react_app_demo/src/index.js
create mode 100644 react_app_demo/src/main.tsx
delete mode 100644 react_app_demo/src/serviceWorker.js
create mode 100644 react_app_demo/src/types.d.ts
create mode 100644 react_app_demo/src/vite-env.d.ts
create mode 100644 react_app_demo/tsconfig.json
create mode 100644 react_app_demo/vite.config.ts
delete mode 100644 webpack_demo/js/index.js
rename webpack_demo/{js => src/assets}/blue_metro.jpg (100%)
rename webpack_demo/{js => src/assets}/daisies_fuji.jpg (100%)
rename webpack_demo/{js => src/assets}/daisies_med.jpg (100%)
rename webpack_demo/{js => src/assets}/nine_yards.jpg (100%)
rename webpack_demo/{js => src/assets}/underground.jpg (100%)
rename webpack_demo/{js => src/assets}/wasm_logo.png (100%)
create mode 100644 webpack_demo/src/global.d.ts
create mode 100644 webpack_demo/src/index.ts
create mode 100644 webpack_demo/tsconfig.json
diff --git a/react_app_demo/README.md b/react_app_demo/README.md
index d2d55c1..e1de96b 100644
--- a/react_app_demo/README.md
+++ b/react_app_demo/README.md
@@ -3,120 +3,56 @@
#### Instructions for Running
1. Clone this repo.
-```sh
-git clone https://github.com/silvia-odwyer/photon
-```
-
-2. Navigate to `crate` and run `wasm-pack build`. Ensure you have wasm-pack installed.
-
-```sh
-cd crate
-wasm-pack build
-```
-
-This will create an npm package, which can be found in `crate/pkg`.
-
-3. Navigate to pkg, and run `npm link`.
-
```sh
-cd pkg
-npm link
+git clone https://github.com/silvia-odwyer/photon
```
-5. Then, navigate to this dir, and install dependencies.
-
+2. Install the demo dependencies.
```sh
-cd ../../react_app_demo
+cd react_app_demo
npm install
```
-This app also requires changing the project's webpack.config.js to load WASM files; however this can't be done
-without ejecting, so to combat this, I used react-app-rewired to allow for overriding the webpack config.
-
-Install react-app-rewired and wasm-loader:
-
+3. Start a development server at localhost:5173.
```sh
-npm install react-app-rewired wasm-loader -D
+npm run dev
```
+Vite will open the app in your browser and hot-reload when you edit sources.
-4. Run `npm link photon`.
-```sh
-npm link photon
-```
-
-6. Start a development server at localhost:3000
-
+4. Build an optimised production bundle.
```sh
-npm run start
+npm run build
```
+Use `npm run preview` to verify the build locally, or `npm run lint` to run TypeScript in no-emit mode.
-### Create React App Notes
+> Want to test against a locally compiled Photon crate? Run `wasm-pack build` inside `crate/` and point the demo at the generated `crate/pkg` output (e.g. via `npm link`).
-This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app).
+### Vite + React Notes
+
+This project is bootstrapped with [Vite](https://vitejs.dev/) and React 19 with TypeScript. The Photon WebAssembly package is loaded directly from npm and initialised before the UI becomes interactive.
## Available Scripts
In the project directory, you can run:
-### `npm start`
-
-Runs the app in the development mode.
-Open [http://localhost:3000](http://localhost:3000) to view it in the browser.
+### `npm run dev`
-The page will reload if you make edits.
-You will also see any lint errors in the console.
-
-### `npm test`
-
-Launches the test runner in the interactive watch mode.
-See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information.
+Runs the app in development mode at [http://localhost:5173](http://localhost:5173) with hot module replacement.
### `npm run build`
-Builds the app for production to the `build` folder.
-It correctly bundles React in production mode and optimizes the build for the best performance.
-
-The build is minified and the filenames include the hashes.
-Your app is ready to be deployed!
-
-See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information.
-
-### `npm run eject`
+Generates a production-ready bundle in `dist/` and runs the TypeScript compiler as part of the build pipeline.
-**Note: this is a one-way operation. Once you `eject`, you can’t go back!**
+### `npm run preview`
-If you aren’t satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project.
+Serves the production bundle locally so you can sanity-check the optimised output.
-Instead, it will copy all the configuration files and the transitive dependencies (Webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you’re on your own.
+### `npm run lint`
-You don’t have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn’t feel obligated to use this feature. However we understand that this tool wouldn’t be useful if you couldn’t customize it when you are ready for it.
+Type-checks the project (`tsc --noEmit`) without writing any build artifacts.
## Learn More
-You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started).
-
-To learn React, check out the [React documentation](https://reactjs.org/).
-
-### Code Splitting
-
-This section has moved here: https://facebook.github.io/create-react-app/docs/code-splitting
-
-### Analyzing the Bundle Size
-
-This section has moved here: https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size
-
-### Making a Progressive Web App
-
-This section has moved here: https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app
-
-### Advanced Configuration
-
-This section has moved here: https://facebook.github.io/create-react-app/docs/advanced-configuration
-
-### Deployment
-
-This section has moved here: https://facebook.github.io/create-react-app/docs/deployment
-
-### `npm run build` fails to minify
-
-This section has moved here: https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify
+- [Photon documentation](https://silvia-odwyer.github.io/photon/docs/photon/index.html)
+- [Vite documentation](https://vitejs.dev/guide/)
+- [React documentation](https://react.dev/)
diff --git a/react_app_demo/config-overrides.js b/react_app_demo/config-overrides.js
deleted file mode 100644
index 559c4cd..0000000
--- a/react_app_demo/config-overrides.js
+++ /dev/null
@@ -1,25 +0,0 @@
-const path = require('path');
-
-module.exports = function override(config, env) {
- const wasmExtensionRegExp = /\.wasm$/;
-
- config.resolve.extensions.push('.wasm');
-
- config.module.rules.forEach(rule => {
- (rule.oneOf || []).forEach(oneOf => {
- if (oneOf.loader && oneOf.loader.indexOf('file-loader') >= 0) {
- // Make file-loader ignore WASM files
- oneOf.exclude.push(wasmExtensionRegExp);
- }
- });
- });
-
- // Add a dedicated loader for WASM
- config.module.rules.push({
- test: wasmExtensionRegExp,
- include: path.resolve(__dirname, 'src'),
- use: [{ loader: require.resolve('wasm-loader'), options: {} }]
- });
-
- return config;
-};
\ No newline at end of file
diff --git a/react_app_demo/index.html b/react_app_demo/index.html
new file mode 100644
index 0000000..5578b48
--- /dev/null
+++ b/react_app_demo/index.html
@@ -0,0 +1,17 @@
+
+
+