diff --git a/src/undom.js b/src/undom.js index a11f04b..2187979 100644 --- a/src/undom.js +++ b/src/undom.js @@ -152,9 +152,32 @@ function createEnvironment() { } + class Event { + constructor(type, opts) { + this.type = type; + this.bubbles = !!(opts && opts.bubbles); + this.cancelable = !!(opts && opts.cancelable); + } + stopPropagation() { + this._stop = true; + } + stopImmediatePropagation() { + this._end = this._stop = true; + } + preventDefault() { + this.defaultPrevented = true; + } + } + + class Document extends Element { constructor() { super(9, '#document'); // DOCUMENT_NODE + this.defaultView = new DefaultView(this); + } + + get document() { + return this; } createElement(type) { @@ -167,37 +190,28 @@ function createEnvironment() { return element; } - createTextNode(text) { return new Text(text); } } + assign(Document.prototype, { Document, Node, Text, Element, SVGElement: Element, Event }); - class Event { - constructor(type, opts) { - this.type = type; - this.bubbles = !!(opts && opts.bubbles); - this.cancelable = !!(opts && opts.cancelable); - } - stopPropagation() { - this._stop = true; - } - stopImmediatePropagation() { - this._end = this._stop = true; - } - preventDefault() { - this.defaultPrevented = true; + + class DefaultView { + constructor(document) { + this.document = document; } } + assign(DefaultView.prototype, { Document, Node, Text, Element, SVGElement: Element, Event }); + /** Create a minimally viable DOM Document - * @returns {Document} document - */ + * @returns {Document} document + */ function createDocument() { let document = new Document(); - assign(document, document.defaultView = { document, Document, Node, Text, Element, SVGElement: Element, Event }); document.appendChild( document.documentElement = document.createElement('html') );