2025-01-02 02:48:44 +01:00
# About

2025-03-25 20:52:25 +01:00
Crafter.CppDOM is a C++ library that exposes the browser DOM api's to C++ WebAssembly.
2025-01-02 02:48:44 +01:00
# How to use
2025-11-09 20:11:22 +01:00
Please view the examples folder, this is a snippit from the HelloElement example:
2025-02-21 03:52:46 +01:00
```cpp
import Crafter.CppDOM;
using namespace Crafter::CppDOM;
int main(){
HtmlElement body("body");
body.SetInnerHTML("Hello World!");
}
```
You can also view the wiki for more detailed information.
2025-01-02 02:48:44 +01:00
2025-11-09 20:11:22 +01:00
It is highly recommended to use this with [Crafter.Build ](https://forgejo.catcrafts.net/Catcrafts/Crafter.Build ), but it is not strictly required if the same way of injecting the env is followed. The following instructions will be for Crafter.Build.
2025-01-02 02:48:44 +01:00
## Quickstart
create a ``project.json` ` in an empty folder, open it in your preferred text editor.
Create a basic project file, that describes your web project.
```JSON
{
2025-11-09 20:11:22 +01:00
"name": "main",
2025-01-02 02:48:44 +01:00
"configurations": [
{
2025-11-09 20:11:22 +01:00
"name": "executable",
"implementations": ["main"],
"target": "wasm32-wasi",
"debug" : true,
2025-01-02 02:48:44 +01:00
"dependencies": [
{
2025-11-09 20:11:22 +01:00
"path":"https://forgejo.catcrafts.net/Catcrafts/Crafter.CppDOM.git",
"configuration":"lib-debug"
2025-01-02 02:48:44 +01:00
}
2025-11-09 20:11:22 +01:00
],
2025-01-02 02:48:44 +01:00
}
]
}
2025-02-21 03:53:03 +01:00
```
2025-02-21 03:52:46 +01:00
2025-01-02 02:48:44 +01:00
Save and close the file, create a ``main.cpp` `
```cpp
2025-02-12 22:22:06 +01:00
import Crafter.CppDOM;
2025-02-12 23:06:56 +01:00
using namespace Crafter::CppDOM;
2025-01-02 02:48:44 +01:00
2025-02-12 22:22:06 +01:00
int main(){
2025-02-12 23:06:56 +01:00
HtmlElement body("body");
body.SetInnerHTML("Hello World!");
2025-01-02 02:48:44 +01:00
}
```
2025-02-21 03:52:46 +01:00
2025-11-09 20:11:22 +01:00
Save and close, then run ``crafter-build build executable && caddy file-server --listen :8080 --root bin/executable` `. if you have caddy installed, if not use your favorite static file server instead. Now you can open the browser at ` `http://localhost:8080` ` and ` `Hello World!` ` will appear in the browser.
2025-02-12 22:22:06 +01:00
2025-11-10 21:53:49 +01:00
This sample can also be viewed in the [HelloElement example ](https://forgejo.catcrafts.net/Catcrafts/Crafter.CppDOM/src/branch/master/examples )