Comparing version 0.1.38 to 0.1.39
'use strict'; | ||
(m => { | ||
exports.DOMParser = m.DOMParser; | ||
})(require('./dom-parser.js')); | ||
const {DOMParser} = require('./dom-parser.js'); | ||
(m => { | ||
exports.Node = m.Node; | ||
})(require('./node.js')); | ||
const {Node} = require('./node.js'); | ||
const {HTMLElement} = require('./html/html-element.js'); | ||
(m => { | ||
exports.HTMLElement = m.HTMLElement; | ||
})(require('./html/html-element.js')); | ||
const {EventTarget, Event, CustomEvent} = require('./interfaces.js'); | ||
(m => { | ||
exports.EventTarget = m.EventTarget; | ||
exports.Event = m.Event; | ||
exports.CustomEvent = m.CustomEvent; | ||
})(require('./interfaces.js')); | ||
exports.DOMParser = DOMParser; | ||
exports.Node = Node; | ||
exports.HTMLElement = HTMLElement; | ||
exports.EventTarget = EventTarget; | ||
exports.Event = Event; | ||
exports.CustomEvent = CustomEvent; | ||
const parseHTML = html => { | ||
const document = (new DOMParser).parseFromString(html, 'text/html'); | ||
const {defaultView: window} = document; | ||
return { | ||
Node, HTMLElement, | ||
EventTarget, Event, CustomEvent, | ||
customElements: window.customElements, | ||
window, document | ||
}; | ||
}; | ||
exports.parseHTML = parseHTML; |
@@ -1,7 +0,23 @@ | ||
export {DOMParser} from './dom-parser.js'; | ||
import {DOMParser} from './dom-parser.js'; | ||
export {Node} from './node.js'; | ||
import {Node} from './node.js'; | ||
import {HTMLElement} from './html/html-element.js'; | ||
export {HTMLElement} from './html/html-element.js'; | ||
import {EventTarget, Event, CustomEvent} from './interfaces.js'; | ||
export {EventTarget, Event, CustomEvent} from './interfaces.js'; | ||
export { | ||
DOMParser, | ||
Node, HTMLElement, | ||
EventTarget, Event, CustomEvent | ||
}; | ||
export const parseHTML = html => { | ||
const document = (new DOMParser).parseFromString(html, 'text/html'); | ||
const {defaultView: window} = document; | ||
return { | ||
Node, HTMLElement, | ||
EventTarget, Event, CustomEvent, | ||
customElements: window.customElements, | ||
window, document | ||
}; | ||
}; |
{ | ||
"name": "linkedom", | ||
"version": "0.1.38", | ||
"version": "0.1.39", | ||
"description": "A triple-linked lists based DOM implementation", | ||
@@ -5,0 +5,0 @@ "main": "./cjs/index.js", |
@@ -21,5 +21,15 @@ # 🔗 linkedom | ||
```js | ||
import {DOMParser} from 'linkedom'; | ||
import {DOMParser, parseHTML} from 'linkedom'; | ||
const document = (new DOMParser).parseFromString(` | ||
// Standard way: text/html, text/xml, image/svg+xml, etc... | ||
// const document = (new DOMParser).parseFromString(html, 'text/html'); | ||
// Simplified way for HTML | ||
const { | ||
// note, these are *not* globals | ||
window, document, customElements, | ||
HTMLElement, | ||
Event, CustomEvent | ||
// other exports .. | ||
} = parseHTML(` | ||
<!doctype html> | ||
@@ -39,22 +49,4 @@ <html lang="en"> | ||
</html> | ||
`, | ||
'text/html' | ||
); | ||
`); | ||
// retrieve the document.defaultView, a global proxy that does *not* | ||
// pollute the global environment (you are in charge of doing it) | ||
const {defaultView: window} = document; | ||
// the window proxy exposes all globals + classes from this module | ||
const { | ||
// provided by this module, could be native too | ||
Event, CustomEvent, | ||
// all HTML classes, such as HTMLButtonElement and others, are available | ||
HTMLElement, | ||
// the CustomElementRegistry is defined once *per document* | ||
// multiple documents require multiple custom elements definition | ||
// but classes can be reused | ||
customElements | ||
} = window; | ||
// builtin extends compatible too 👍 | ||
@@ -61,0 +53,0 @@ customElements.define('custom-element', class extends HTMLElement { |
1590341
7087
166