https://github.com/timluq/fallback-dom
Lightweight DOM/selector implementing the most basic operations
https://github.com/timluq/fallback-dom
dom javascript
Last synced: about 2 months ago
JSON representation
Lightweight DOM/selector implementing the most basic operations
- Host: GitHub
- URL: https://github.com/timluq/fallback-dom
- Owner: TimLuq
- Created: 2022-03-14T08:21:45.000Z (about 4 years ago)
- Default Branch: main
- Last Pushed: 2023-02-20T03:05:25.000Z (over 3 years ago)
- Last Synced: 2025-06-13T06:09:57.253Z (12 months ago)
- Topics: dom, javascript
- Language: TypeScript
- Homepage:
- Size: 291 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# fallback-dom
A lightweight standalone partial DOM implementation written in TypeScript.
It should work in all modern environments without any hassle or external dependencies. (Feel free to open an issue and prove me wrong!)
This could be useful for tests and other scenarios where a DOM is required but not available per default.
This is not a full implementation of DOM, but the aim is to behave close to spec for every exposed API, and expose the most common or simple parts.
Notable exceptions to this are events and where the spec wants the returned value to be a live representation of matched nodes as long as the object lives, currently in this implementation they are computed at call time.
These special cases includes `Element.prototype.childNodes`, `Element.prototype.querySelectorAll`, etc.
Supports namespaces and a partial version of `CustomElements`.
This package has three module files available for use:
- `fallback-dom` (has a dependency on `query-selector`.)
- `query-selector`
- `xml-serializer`
This repo contains pre-built JS files to be able to be used as a git dependency without extra build steps. The only real source files are the ones matching `./*.ts`.
## Module: fallback-dom
Main module that exposes the partial DOM implementation.
### Imports
```js
import { querySel } from "./query-selector.js";
```
### Base classes
These should never be extended or initialized. An exception to this rule is `Element` which may be extended if the extended class then is registered on `Document.prototype.customElements`.
```js
export { CDATASection, Comment, DocumentType, Element, Node, ProcessingInstruction, Text };
```
Functions:
```js
export { createDocument, createDocumentType, createHTMLDocument };
```
## Module: query-selector
Helper module that applies a subset of CSS selectors to find matching elements.
Functions:
```js
export { querySel };
```
## Module: xml-serializer
Extension module that can be used to serialize the DOM to a string.
Functions:
```js
export { serializeToString };
```