https://github.com/tomokimiyauci/dom
The DOM reference implementation
https://github.com/tomokimiyauci/dom
dom reference-implementation whatwg
Last synced: about 1 year ago
JSON representation
The DOM reference implementation
- Host: GitHub
- URL: https://github.com/tomokimiyauci/dom
- Owner: TomokiMiyauci
- License: mit
- Created: 2023-10-11T01:31:52.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2023-10-18T08:38:24.000Z (over 2 years ago)
- Last Synced: 2025-03-10T14:58:27.968Z (about 1 year ago)
- Topics: dom, reference-implementation, whatwg
- Language: TypeScript
- Homepage:
- Size: 1.37 MB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
- Code of conduct: .github/CODE_OF_CONDUCT.md
- Security: .github/SECURITY.md
Awesome Lists containing this project
README
# dom
The DOM reference implementation.
This is an implementation that strictly adheres to the DOM specifications
([whatwg/dom](https://dom.spec.whatwg.org/) and
[wpt/dom](https://github.com/web-platform-tests/wpt/tree/master/dom)).
Current status: test pass 46219/?
## Background
No library has been found that attempts to be compliant with the `DOM`
specification. Of the several libraries available,
[jsdom](https://github.com/jsdom/jsdom) is the closest to the specification, but
it does not behave as specified.
The `DOM` has a [specification](https://dom.spec.whatwg.org/). Therefore, an
implementation that adheres to the specification is required.
[Web platform test(wpt)](https://github.com/web-platform-tests/wpt) is a testing
platform for any Web API, including the `DOM`.
For this project, passing wpt tests is considered conformance to the
specification.
## Install
```ts
import * as mod from "https://deno.land/x/dom_std/mod.ts";
```
TODO: npm publish
npm:
```bash
npm i dom-std
```
## Usage
Use a stand-alone `Document` object.
```ts
import { Document, Element } from "https://deno.land/x/dom_std/mod.ts";
import { assertEquals } from "https://deno.land/std/assert/assert_equals.ts";
import { assert } from "https://deno.land/std/assert/assert.ts";
const document = new Document();
const div = document.createElement("div");
assertEquals(div.namespaceURI, null);
assert(div instanceof Element);
```
### Private data
The specification defines each member's private data with the expression
"associate".
To access private data, use the `$` accessor.
Example of accessing
[`type`](https://dom.spec.whatwg.org/#concept-document-type) private data in
`Document`:
```ts
import { $, Document } from "https://deno.land/x/dom_std/mod.ts";
import { assertEquals } from "https://deno.land/std/assert/assert_equals.ts";
const document = new Document();
$(document).type = "html";
const div = document.createElement("div");
assertEquals(div.namespaceURI, "http://www.w3.org/1999/xhtml");
```
Normally this is done by the User Agent.
### Extension
Only [whatwg/dom](https://dom.spec.whatwg.org/) is implemented. If you want to
use features extended by other specifications, import them.
[whatwg/html](https://html.spec.whatwg.org/multipage/):
```ts
"https://deno.land/x/html_std/extends/all.ts";
import { HTMLElement } from "https://deno.land/x/html_std/mod.ts";
import { $, Document } from "https://deno.land/x/dom_std/mod.ts";
import { assert } from "https://deno.land/std/assert/assert_equals.ts";
const document = new Document();
$(document).type = "html";
const div = document.createElement("div");
assert(div instanceof HTMLElement);
```
## Document
- [Requirement](./docs/requirement.md)
## License
[MIT](LICENSE) © 2023 Tomoki Miyauchi