🍂 A Rust-based simulated DOM (browser-independent replacement for web_sys)

Overview

rdom logo

DOM in Rust without a browser

Hello and welcome. This library provides server-side or browserless simulation of a DOM.

docs.rs CI status Discord Chat

Example Usage

use std::sync::Arc;

use rdom::config::ScreenMetrics;
use rdom::node::concrete::*;
use rdom::node::contents::{CommentNodeStorage, NodeType, TextNodeStorage};
use rdom::node::element::{ElementNodeStorage, HtmlButtonElementStorage, HtmlHtmlElementStorage};
use rdom::node::{AnyNodeArc, NodeBehavior};
use rdom::sandbox::Sandbox;

fn main() {
    let metrics: ScreenMetrics = Default::default();
    let sbox = Sandbox::new(metrics);
    let doc = sbox.clone().window().document();

    let document_element = sbox
        .builder::<ElementNodeArc>()
        .build_html();

    // We don't use the text node, but those are available
    let _text = doc.create_text_node("Hello, world!".to_string());

    doc.append_child(document_element.into());

    println!("Doc has {} child node(s)", doc.child_nodes().length());
    // Prints out Doc has 1 child node(s)
}

Is this library ready yet?

No, it's still a pre-alpha work in progress. However, it is open to collaboration.

What's the difference between this library and say, web-sys or Dodrio?

Rdom tries to behave like web-sys as much as possible, in that it provides a DOM that looks and acts a lot like a DOM as a Rust programmer would see a DOM via interaction with web-sys.

The key difference is that there is no actual browser. I mean, you could have one, but it's not required.

Additionally, this library supports the concept of multiple sandboxes, so not all nodes belong to one big node pool like in web-sys. Instead, each sandbox contains a single document tree and some information about the window (like width and height).

Compared to Dodrio, this library is focused much more on the actual DOM element types. Dodrio is basically agnostic to what different types of tags are, and is more focused on the question of how to manipulate a DOM to match some ideal, like React's virtual DOM does. If that's still unclear, Dodrio targets web-sys as a backend (it's a dependency), and in theory, this library could also be a backend for Dodrio someday.

Not all of the DOM has been implemented. How did you decide what parts to implement?

The reason for developing this library was to enable SSR support for Yew. That was the entire purpose, so while it is built to be as versatile as reasonable, that is the main use case that we are serving right now, although applications to become a maintainer are certainly welcome.

Comments
  • Sourcegen rewrite

    Sourcegen rewrite

    With this PR I also want to open a conversation about some topics:

    • Is our goal to replace where possible macro calls with sourcegen?
    • I think mixin behavior is good, but traits are useful too, because of generalization. If we merge #41 we would need SandboxMemberBehavior for build and buildw methods. Or should we add them as mixins too? I mean, we can almost abandon trait if we refuse to use dyn trait objects, which might actually be a valid desicion, since we have moved to enum.
    opened by maksimil 5
  • Implement simple query selector

    Implement simple query selector

    This implementation is really basic, but can be scaled. However it returns Arc instead of Arc. Currently I don't think such downcasting is supported.

    Closes #1

    opened by maksimil 5
  • Creating behaviour implementing paradigm

    Creating behaviour implementing paradigm

    Currently we have separate structs for behaviours, I think that behaviours should be implememted with traits. But some behaviours have storages, so for them we can add the BehaviourNameStorage field to the implementing struct. Because behaviour is dependent on its storage and mostly nothing else implementation would be mostly the same for every implementor, so it could be done by macros to avoid code repetition.

    enhancement 
    opened by maksimil 3
  • Cyclic elements, NamedNodeMap

    Cyclic elements, NamedNodeMap

    Introduces a layer to elements to store common functionality like NamedNodeMap. In this we store a reference back up to the Node which owns the Element (Elements are always inside of Nodes because of our composition system which replaces the C++ inheritance model). Note that in order to do this we needed a new ConcreteNode constructor which can handle the cyclic nature. Fortunately, with the builders, this isn't so much an issue.

    Also fleshes out NamedNodeMap to lay foundations for support for attributes.

    opened by philip-peterson 2
  • Node polymorphism using enums

    Node polymorphism using enums

    We can see in mdn docs that there are only 11 types of nodes. I think that with that little types we can use an enum instead of a trait. This will also solve a problem of intertrait casting, since we really only needed it between Arc<dyn AnyNode> and Arc<dyn AnyElement>.

    opened by maksimil 2
  • Rename

    Rename "Raw Elements" and "Raw Nodes" to just Elements and Nodes

    Right now, there are references to Raw nodes and Raw elements everywhere. While the intention (supporting a friendly interface as an alternative to the raw interface) I still believe is a good idea, we can just call this interface something like mod friendly, and then there will be rdom::node::Node and rdom::node::friendly::Node.

    Related to #7

    good first issue 
    opened by philip-peterson 2
  • Proxy node behavior

    Proxy node behavior

    Achieves several things:

    • allows the user to not worry about importing the various behaviors we have, simplifying the interface
    • makes those underlying behaviors private
    opened by philip-peterson 1
  • Sourcegen rewrite

    Sourcegen rewrite

    Checklist for macros that need rewriting using sourcegen

    • [x] SandboxMember mixin
    • [ ] ParentNode
    • [ ] NodeBehavior
    • [ ] concrete nodes
    • [ ] node contents
    • [ ] html elements
    opened by maksimil 1
  • Support for setting and getting of attributes

    Support for setting and getting of attributes

    We just need to support string keys and values for now.

    Relevant links: https://developer.mozilla.org/en-US/docs/Web/API/Element/getAttribute https://developer.mozilla.org/en-US/docs/Web/API/Element/setAttribute https://developer.mozilla.org/en-US/docs/Web/API/Attr https://developer.mozilla.org/en-US/docs/Web/API/NamedNodeMap

    difficulty: hard 
    opened by philip-peterson 1
  • Ci actions

    Ci actions

    Created a. initial CI pipeline with GitHub Actions, currently builds with nightly-2021-03-23 on ubuntu-latest. It runs on PRs, pushes to master and nightly. Hope it's helpful!

    Ref #10

    opened by arcsi42 1
  • Rename {wrapped,raw} -> {common,nice}

    Rename {wrapped,raw} -> {common,nice}

    This renames raw nodes to nodes (or common nodes) and wrapped nodes to nice nodes. I started this PR off with high hopes, but I am afraid it may make things more confusing, especially that in some places what were previously called raw nodes are now called either nodes or common nodes, increasing the amount of vocab needed. I'll leave it to the team to decide if this is a good thing to merge or not. Thanks for taking a look!

    opened by philip-peterson 1
  • Milestone: support for silkenweb

    Milestone: support for silkenweb

    This list is a WIP.

    • Node#insert_before
    • append_child
    • remove_child
    • Document#get_element_by_id
    • Document#create_element
    • Document#create_element_ns
    • replace_with_with_node_1
    • HtmlElement::set_hidden
    • add_event_listener_with_callback
    • remove_event_listener_with_callback
    • window#local_storage
    • window#session_storage
    • CustomEvent
    • MouseEvent
    • HtmlAnchorElement
    • AnimationEvent
    • PointerEvent
    • InputEvent
    • Event
    • TransitionEvent
    • CompositionEvent
    • FocusEvent
    • TouchEvent
    • WheelEvent
    • current_target
    • query_selector
    • CustomEvent#detail
    opened by philip-peterson 0
  • Refactor ConcreteNodeArc et. al. into

    Refactor ConcreteNodeArc et. al. into "CoArc" functionality

    I fear the risk of having these structs that are expected to contain two related Arcs but which we have no static guarantees around. It would be nice if we could derive from some kind of macro CoArc which would do checks when constructing the arcs that each arc has a weak reference to the other one. It could also handle equivalence relations for us.

    difficulty: medium 
    opened by philip-peterson 1
  • Templates for node initialization

    Templates for node initialization

    I think it's easier to wrap your head around this api. The docs are simpler imo. Also this allows us to implement templates as Fn(Arc<Sandbox>) -> T (Haskell fanboying intestifies). also templates always check for validity of Weak<Sandbox>.

    opened by maksimil 1
  • Support for Event and EventListeners

    Support for Event and EventListeners

    Technically, all Nodes are EventTargets. We should have therefore another behavior axis (like NodeBehavior) which implements EventTarget behavior such as:

    https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/addEventListener

    difficulty: hard 
    opened by philip-peterson 0
  • Node::insert_before

    Node::insert_before

    Support for https://developer.mozilla.org/en-US/docs/Web/API/Node/insertBefore

    If the node being inserted already exists in the DOM, make sure to remove the node from wherever it already is first.

    good first issue 
    opened by philip-peterson 1
Owner
🍂 Organization for RDOM: Rust in the browser
null
The Bloat-Free Browser Game in Rust but in C and not in a Browser

rust-browser-game but native and rendered with SDL in C without the Browser The original idea of rust-browser-game is that the game.wasm module is com

Tsoding 12 Sep 26, 2022
Rust-based replacement for the default Minecraft renderer

wgpu-mc ?? A blazing fast alternative renderer for Minecraft Intro WebGPU is a new web specification designed to provide modern graphics and compute c

Birb 1 Jun 28, 2022
A visual novel engine that draws inspiration from RenPy and is meant to be a more performant replacement with feature parity.

VN Engine A visual novel engine that draws inspiration from RenPy and is meant to be a more performant replacement with feature parity. The engine is

Alexandros Panagiotakis 2 Sep 9, 2022
A visual novel engine that draws inspiration from RenPy and is meant to be a more performant replacement with feature parity.

VN Engine A visual novel engine that draws inspiration from RenPy and is meant to be a more performant replacement with feature parity. The engine is

Alexandros Panagiotakis 2 Sep 9, 2022
Bloat-Free Browser Game in Rust (rustc-only challenge)

Bloat-Free Browser Game in Rust (rustc-only challenge) Don't blame me if this code breaks in 1 year The idea is to make a simple game in Rust as bloat

Tsoding 25 Aug 24, 2022
The Bloat-Free Browser Game in Rust but in C and in UEFI

rust-browser-game but in UEFI instead of browser quick start deps rust gnu-efi gcc make build process $ make running after building everything you wil

bit6tream 12 Nov 7, 2022
Wein2D.js bindings for creating browser games in Rust using WebAssembly.

Wein2D.js-WASM Wein2D.js bindings for creating browser games in Rust using WebAssembly. Wein2D.js-WASM requires Wein2d.js to be loaded in the same doc

DevTaube 1 Apr 14, 2022
Visual Pathfinding running in the browser!

wasm_party Here is the code I made while learning to use WebAssembly. It runs and visualizes a pathfinding algorithm in the browser. Run online Click

Ask Sødal 3 Dec 15, 2022
2D and 3D physics engine based on Extended Position Based Dynamics for Bevy.

Bevy XPBD Bevy XPBD is a 2D and 3D physics engine based on Extended Position Based Dynamics (XPBD) for the Bevy game engine. Design Below are some of

Joona Aalto 203 Jul 6, 2023
unrust - A pure rust based (webgl 2.0 / native) game engine

unrust A pure rust based (webgl 2.0 / native) game engine Current Version : 0.1.1 This project is under heavily development, all api are very unstable

null 368 Jan 3, 2023
compare gdnative rust based physics against Godot built-in physics

Godot vs. Rapier Rapier is an open source physics framework written in Rust. This project pits godots built-in physics against Rapier. It uses godot-r

Stephan Dilly 75 Nov 17, 2022
A single-threaded polling-based Rust async executor suitable for use in games, embedded systems or WASM.

simple async local executor An Enlightware® software. Overview A single-threaded polling-based executor suitable for use in games, embedded systems or

Enlightware GmbH 16 Nov 15, 2022
2-player game made with Rust and "ggez" engine, based on "Conway's Game of Life"

fight-for-your-life A 2-player game based on the "Conway's Game of Life", made with Rust and the game engine "ggez". Create shapes on the grid that wi

Petros 3 Oct 25, 2021
Creative Coding Framework based on Entity Component System (ECS) written in Rust

creativity creativity is Creative Coding Framework based on Entity Component System (ECS) written in Rust. Key Features TBA Quick Start TBA How To Con

Chris Ohk 9 Nov 6, 2021
A cpu-based raytracer written in rust.

mini-raytracer A cpu-based raytracer written in rust. This project was written by me to learn about computer graphics, specifically rayracing. Feature

null 5 May 16, 2022
Terminal-based Snake game written in Rust without dependencies (for educational purposes).

RustSnake This is a simple terminal-based Snake game implemented in Rust without dependencies. To start the game type cargo run. Control the snake usi

Florian Wickert 88 Jan 6, 2023
A simple space shooter game. Runs in the terminal using characters-based UI. Fully written in Rust, using the "ruscii" library.

Thrust - a terminal shooter game Originally created as a project for the "Missing Semester" course at JKU Linz (338.006). The game is entirely written

Mathias Wöß 3 Jan 16, 2023
A safe, fast and cross-platform 2D component-based game framework written in rust

shura shura is a safe, fast and cross-platform 2D component-based game framework written in rust. shura helps you to manage big games with a component

Andri 28 Jan 17, 2023
A basic raytracer implementation in Rust based on the Ray Tracing in One Weekend book.

Raytracer A basic raytracer implementation in Rust based on the Ray Tracing in One Weekend book. Live Demo Result How to Run Standalone Binary $ cargo

Navin Mohan 19 Dec 13, 2022