🍂 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 Discord Chat

Example Usage

use std::sync::Arc;

use rdom::config::ScreenMetrics;
use rdom::sandbox::Sandbox;
use rdom::node::raw::element::{HtmlHtmlElement, HtmlBodyElement};
use rdom::node::raw::AnyRawNode;

fn main() {
    let metrics: ScreenMetrics = Default::default();
    let sbox = Sandbox::new(metrics);
    let doc = sbox.clone().window().document();
    let document_element = HtmlHtmlElement::new(Arc::downgrade(&sbox), ());
    doc.append_child(document_element);

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

    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
Philip Peterson
Co-maintainer of Trunk, contributor to Yew and other things
Philip Peterson
A modern replacement for ‘ls’.

exa exa is a modern replacement for ls. README Sections: Options — Installation — Development exa is a modern replacement for the venerable file-listi

Benjamin Sago 20.3k Jan 6, 2023
desktop automation, screen capture, input listen/simulation, asar compress, color picker for nodejs and electron based on rust

desktop automation, screen capture, input listen/simulation, asar compress, color picker for nodejs and electron based on rust. 基于 Rust / WASM 提供截图、取色、键鼠事件监听模拟、压缩解压、图像处理、获取已安装应用等跨平台功能的现代异步 Nodejs 模块,占用空间小, 安装便捷, 使用简单, 高性能, 资源占用极小, 可取代 iohook 和 robotjs

null 48 Dec 15, 2022
A simple rust-based tool for fetching system information

?? azf a simple rust-based tool for fetching system information you need a patched nerd font and the material design icons font ?? compiling you can c

Pedro Henrique 3 Dec 17, 2022
minimalistic command launcher in rust

rrun Note: Apart from the occasional fix, this project is not actively developed anymore. rrun works fine and should run/compile for the time being on

null 105 Nov 18, 2022
Yet another fancy watcher. (Rust)

funzzy Yet another fancy watcher. (Inspired by antr / entr) Configure execution of different commands using semantic yaml. # .watch.yaml # list here a

Cristian Oliveira 188 Dec 12, 2022
A more intuitive version of du in rust

Dust du + rust = dust. Like du but more intuitive. Why Because I want an easy way to see where my disk is being used. Demo Install Cargo cargo install

andy.boot 5.5k Jan 8, 2023
Blazing 💥 fast terminal-ui for git written in rust 🦀

Blazing fast terminal client for git written in Rust Features Fast and intuitive keyboard only control Context based help (no need to memorize tons of

Stephan Dilly 11.8k Jan 5, 2023
A simple and fast download accelerator, written in Rust

zou A simple and fast download accelerator, written in Rust Zou is a Snatch fork by @k0pernicus. Snatch is a fast and interruptable download accelerat

Antonin Carette 173 Dec 4, 2022
Fuzzy Finder in rust!

Life is short, skim! Half of our life is spent on navigation: files, lines, commands… You need skim! It is a general fuzzy finder that saves you time.

Jinzhou Zhang 3.7k Jan 4, 2023
A bash-like Unix shell written in Rust

Cicada Unix Shell Cicada is a simple Unix shell written in Rust. Documents Install cicada Environment Variables Cicada Builtins Completion RC File His

Hugo Wang 921 Dec 28, 2022
Performs distributed command execution, written in Rust w/ Tokio

Concurr: Distributed and Concurrent Command Execution, in Rust This project is dual licensed under MIT and Apache 2.0. Originally inspired by the GNU

Michael Murphy 93 Dec 18, 2022
A library to listen to global hotkeys in Rust

Rust Hotkey A library to listen to global hotkeys in Rust How to use See the examples folder for how to use this library. OS Support This lib aims to

James Birtles 44 Dec 12, 2022
🔮 Futuristic take on hexdump, made in Rust.

hex (hx) Futuristic take on hexdump. hx accepts a file path as input and outputs a hexadecimal colorized view to stdout. $ hx tests/files/alphanumeric

Julian Sitkevich 387 Dec 27, 2022
Cross-platform Rust rewrite of the GNU coreutils

uutils coreutils uutils is an attempt at writing universal (as in cross-platform) CLI utilities in Rust. This repository is intended to aggregate GNU

null 13k Dec 30, 2022
A TUI system monitor written in Rust

NO LONGER MAINTAINED. For a similar program, check out https://github.com/ClementTsang/bottom. ytop Another TUI based system monitor, this time in Rus

Caleb Bassi 2.1k Jan 3, 2023
A rust layered configuration loader with zero-boilerplate configuration management.

salak A layered configuration loader with zero-boilerplate configuration management. About Features Placeholder Key Convension Cargo Features Default

Daniel YU 28 Sep 20, 2022
Untrusted IPC with maximum performance and minimum latency. On Rust, on Linux.

Untrusted IPC with maximum performance and minimum latency. On Rust, on Linux. When is this Rust crate useful? Performance or latency is crucial, and

null 72 Jan 3, 2023
An over-engineered rewrite of pipes.sh in Rust

pipes-rs An over-engineered rewrite of pipes.sh in Rust Installlation macOS Install using Homebrew or download manually from releases. $ brew install

Lucas 301 Dec 30, 2022
Trup-rewrite in rust! Finally!

Trup, but Rust! A Discord bot for the Unixporn community Now written in a good language! Dependencies Rust nightly sqlx-cli (if you need to change the

r/unixporn 106 Dec 22, 2022