3.1 KiB
WASM Playground
We've created an isolated playground environment for rapid rendering testing. There are two types of playgrounds:
- Shapes Playground
- Text Editor Playground
File Structure
The playground files are located in:
frontend/resources/wasm-playground/
├── clips.html
├── comparison.html
├── index.html
├── masks.html
├── paths.html
├── plus.html
├── rects.html
├── texts.html
└── js/
Each HTML file is a separate playground demo. The js/ directory contains shared JavaScript modules and utilities.
Shapes Playground
- Run penpot locally
- Go to http://localhost:3449/wasm-playground/
- The
index.htmlpage lists all available playgrounds for easy navigation.
For the different kinds of shape playgrounds, you can set the amount of shapes you want to render each time by passing a query parameter. For example:
http://localhost:3449/wasm-playground/texts.html?texts=300
This will render 300 text shapes. You can adjust the parameter for other playgrounds as well to control the number of shapes rendered.
How to Add a New Playground Test
- Create a new HTML file in
frontend/resources/wasm-playground/(e.g.,mytest.html). - Use one of the existing playground HTML files as a template (such as
clips.htmlorcomparison.html). - Import the necessary modules from
js/lib.jsor other shared scripts. - Add your test logic in a
<script type="module">block. - Add the file to the home page (
index.html)
How It Works
- Each playground HTML file loads the required JavaScript modules and sets up a canvas or test environment.
- You can use utility functions from
js/lib.jsfor rendering shapes, assigning canvases, and running performance comparisons. - The playground is isolated, so you can rapidly prototype and test rendering features without affecting the main application.
Text Editor Playground
The Text Editor Playground provides an isolated environment to test the new renderer integrated with the text editor.
How to Run
-
Open a terminal and navigate to the playground directory:
cd frontend/text-editor -
Start the development server:
yarn dev -
Open your browser and go to:
http://localhost:5173/wasm.html
This will launch the playground interface where you can interactively test text editing features with the latest renderer.
Updating the WASM Renderer
To update the render_wasm.wasm and render_wasm.js files used by the playground:
-
Make sure you have the latest compiled WASM files in
frontend/resources/public/js/. -
From the
frontend/text-editordirectory, run:yarn wasm:updateThis script will copy the latest
render_wasm.wasmandrender_wasm.jsinto the playground’ssrc/wasm/directory, ensuring the playground uses the most recent build.
How It Works
- The playground integrates the new renderer via the WASM and JS files, allowing you to test text editing, rendering, and styling in isolation from the main Penpot application.
