universal_html 0.1.0 universal_html: ^0.1.0 copied to clipboard
Supports a subset of 'dart:html' in all platforms (browser, VM, and Flutter).
Overview #
This package is a pure Dart implemention of a subset of dart:html. The package works in all platforms (VM, Flutter, and browser).
Licensed under the MIT license.
The project welcomes new contributors:
- Star the project at github.com/terrier989/dart-universal_html.
- Report issues at the Github issue tracker.
- Share contributions by creating a pull request.
Use cases #
- Parsing/scraping HTML in the server/Flutter + browser.
- Generating HTML in the server/Flutter + browser.
Features #
DOM APIs #
- Node classes (
Node
,Element
,CheckboxInputElement
, etc.) - Printing (
element.outerHtml
, etc.) - Parsing (
DomParser
) - Queries (
document.querySelector
,node.matchesSelector
) - Event handlers
Other APIs #
We have implemented various other APIs such as subsets ofwindow
and navigator
.
Non-implemented APIs either throw UnimplementedError
or fail silently when used in non-browser
environment.
Correctness #
We test that the APIs behave identically to dart:html code running in Chrome. There are some failing tests.
For parsing, we use:
Getting started #
In pubspec.yaml
:
name: example
dependencies:
universal_html: ^0.1.0
Now you can replace usage of "dart:html" with "package:universal_html/html.dart":
import "package:universal_html/html.dart";
void main() {
// Create a DOM tree
final element = new Element.tag("h1")..appendText("Hello world!");
// Print outer HTML
print(element.outerHtml);
}