diff --git a/dist/dom.d.ts b/dist/dom.d.ts index bc4404d..d3011f3 100644 --- a/dist/dom.d.ts +++ b/dist/dom.d.ts @@ -28,14 +28,14 @@ export interface IDom { * @param callback The function that receives a notification when an event of the specified type occurs. * @param capture If true, useCapture indicates that the user wishes to initiate capture. */ - addEventListener(eventName: string, callback: EventListener, capture: boolean): void; + addEventListener(eventName: string, callback: EventListenerOrEventListenerObject, capture: boolean): void; /** * Remove an event listener from the document. * @param eventName A string representing the event type to listen for. * @param callback The function to remove from the event. * @param capture Specifies whether the listener to be removed was registered as a capturing listener or not. */ - removeEventListener(eventName: string, callback: EventListener, capture: boolean): void; + removeEventListener(eventName: string, callback: EventListenerOrEventListenerObject, capture: boolean): void; /** * Adopts a node from an external document. * @param node The node to be adopted. @@ -47,7 +47,8 @@ export interface IDom { * @param tagName A string that specifies the type of element to be created. * @return The created element. */ - createElement(tagName: string): Element; + createElement(tagName: T): HTMLElementTagNameMap[T]; + createElement(tagName: string): HTMLElement; /** * Creates the specified HTML attribute * @param name A string that specifies the name of attribute to be created. @@ -102,11 +103,17 @@ export interface IDom { */ getElementById(id: string): Element; /** + * Performs a query selector on the document and returns first matched element, depth first. + * @param query The query to use in searching the document. + * @return A list of all matched elements in the document. + */ + querySelector(selectors: string): E | null; + /** * Performs a query selector on the document and returns all located matches. * @param query The query to use in searching the document. * @return A list of all matched elements in the document. */ - querySelectorAll(query: string): NodeList; + querySelectorAll(selectors: string): NodeListOf; /** * Gets the element that is the next sibling of the provided element. * @param element The element whose next sibling is being located. @@ -118,7 +125,7 @@ export interface IDom { * @param markup A string containing the markup to turn into a template. Note: This string must contain the template element as well. * @return The instance of HTMLTemplateElement that was created from the provided markup. */ - createTemplateFromMarkup(markup: string): Element; + createTemplateFromMarkup(markup: string): HTMLTemplateElement; /** * Appends a node to the parent, if provided, or the document.body otherwise. * @param newNode The node to append. diff --git a/dist/index.js.map b/dist/index.js.map index 3a52f88..09cb05c 100644 --- a/dist/index.js.map +++ b/dist/index.js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CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC;YAC5C,CAAC;YAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;gBACX,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;YAC3B,CAAC;QACH,CAAC;KACF,CAAC;IACF,MAAM,CAAC,GAAG,GAAG;QACX,GAAG,EAAH,iBAAG,EAAE,QAAQ,EAAR,sBAAQ,EAAE,OAAO,EAAP,qBAAO;KACvB,CAAC;IACF,MAAM,CAAC,MAAM,CAAC;AAChB,CAAC;AAxBD,8BAwBC;AAED,eAAsB,MAAe;IACnC,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC;QACX,MAAM,CAAC,KAAK,EAAE,CAAC;IACjB,CAAC;IAED,oCAAgB,CAAC,WAAW,EAAE,CAAC,QAAQ,EAAE,CAAC;AAC5C,CAAC;AAND,sBAMC","file":"index.js","sourcesContent":["/// \n\nimport { initializePAL, DOM, PLATFORM, FEATURE, isInitialized } from 'aurelia-pal';\nimport { buildPal } from './nodejs-pal-builder';\nimport { MutationNotifier } from './polyfills/mutation-observer';\n\n/**\n* Initializes the PAL with the NodeJS-targeted implementation.\n*/\nexport function initialize(): void {\n if (isInitialized) {\n return;\n }\n\n let pal = buildPal();\n\n initializePAL((platform, feature, dom) => {\n Object.assign(platform, pal.platform);\n Object.setPrototypeOf(platform, pal.platform.constructor.prototype);\n\n Object.assign(dom, pal.dom);\n Object.setPrototypeOf(dom, pal.dom.constructor.prototype);\n\n Object.assign(feature, pal.feature);\n Object.setPrototypeOf(feature, pal.feature.constructor.prototype);\n\n (function (global) {\n global.console = global.console || {};\n let con = global.console;\n let prop;\n let method;\n let empty = {};\n let dummy = function () { };\n let properties = 'memory'.split(',');\n let methods = ('assert,clear,count,debug,dir,dirxml,error,exception,group,' +\n 'groupCollapsed,groupEnd,info,log,markTimeline,profile,profiles,profileEnd,' +\n 'show,table,time,timeEnd,timeline,timelineEnd,timeStamp,trace,warn').split(',');\n while (prop = properties.pop()) if (!con[prop]) con[prop] = empty;\n while (method = methods.pop()) if (!con[method]) con[method] = dummy;\n })(platform.global);\n\n if (platform.global.console && typeof console.log === 'object') {\n if (typeof console['debug'] === 'undefined') {\n console['debug'] = this.bind(console['log'], console);\n }\n ['log', 'info', 'warn', 'error', 'assert', 'dir', 'clear', 'profile', 'profileEnd'].forEach(function (method) {\n console[method] = this.bind(console[method], console);\n }, Function.prototype.call);\n }\n\n Object.defineProperty(dom, 'title', {\n get: function () {\n return pal.global.document.title;\n },\n set: function (value) {\n pal.global.document.title = value;\n }\n });\n\n Object.defineProperty(dom, 'activeElement', {\n get: function () {\n return pal.global.document.activeElement;\n }\n });\n\n Object.defineProperty(platform, 'XMLHttpRequest', {\n get: function () {\n return pal.global.XMLHttpRequest;\n }\n });\n });\n}\n\n/**\n * @description initializes and makes variables like 'window' into NodeJS globals\n */\nexport function globalize() {\n initialize();\n global.window = global.self = PLATFORM.global;\n global.document = PLATFORM.global.document;\n global.Element = DOM.Element;\n global.NodeList = PLATFORM.global.NodeList;\n global.SVGElement = DOM.SVGElement;\n global.HTMLElement = PLATFORM.global.HTMLElement;\n global.requestAnimationFrame = PLATFORM.global.requestAnimationFrame;\n global.location = PLATFORM.location;\n global.history = PLATFORM.history;\n global.System = {\n import(moduleId: string) {\n try {\n return Promise.resolve(require(moduleId));\n } catch (e) {\n return Promise.reject(e);\n }\n }\n };\n global.PAL = {\n DOM, PLATFORM, FEATURE\n };\n return global;\n}\n\nexport function reset(window?: Window) {\n if (window) {\n window.close();\n }\n\n MutationNotifier.getInstance().destruct();\n}"],"sourceRoot":"../src/"} \ No newline at end of file +{"version":3,"sources":["index.ts"],"names":[],"mappings":";AAAA,2CAA2C;;AAE3C,6CAAmF;AACnF,6DAAgD;AAChD,qEAAiE;AAEjE;;EAEE;AACF;IACE,IAAI,2BAAa,EAAE;QACjB,OAAO;KACR;IAED,IAAI,GAAG,GAAG,6BAAQ,EAAE,CAAC;IAEr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ACV,MAAM,CAAC,KAAK,EAAE,CAAC;KAChB;IAED,oCAAgB,CAAC,WAAW,EAAE,CAAC,QAAQ,EAAE,CAAC;AAC5C,CAAC;AAND,sBAMC","file":"index.js","sourcesContent":["/// \n\nimport { initializePAL, DOM, PLATFORM, FEATURE, isInitialized } from 'aurelia-pal';\nimport { buildPal } from './nodejs-pal-builder';\nimport { MutationNotifier } from './polyfills/mutation-observer';\n\n/**\n* Initializes the PAL with the NodeJS-targeted implementation.\n*/\nexport function initialize(): void {\n if (isInitialized) {\n return;\n }\n\n let pal = buildPal();\n\n initializePAL((platform, feature, dom) => {\n Object.assign(platform, pal.platform);\n Object.setPrototypeOf(platform, pal.platform.constructor.prototype);\n\n Object.assign(dom, pal.dom);\n Object.setPrototypeOf(dom, pal.dom.constructor.prototype);\n\n Object.assign(feature, pal.feature);\n Object.setPrototypeOf(feature, pal.feature.constructor.prototype);\n\n (function (global) {\n global.console = global.console || {};\n let con = global.console;\n let prop;\n let method;\n let empty = {};\n let dummy = function () { };\n let properties = 'memory'.split(',');\n let methods = ('assert,clear,count,debug,dir,dirxml,error,exception,group,' +\n 'groupCollapsed,groupEnd,info,log,markTimeline,profile,profiles,profileEnd,' +\n 'show,table,time,timeEnd,timeline,timelineEnd,timeStamp,trace,warn').split(',');\n while (prop = properties.pop()) if (!con[prop]) con[prop] = empty;\n while (method = methods.pop()) if (!con[method]) con[method] = dummy;\n })(platform.global);\n\n if (platform.global.console && typeof console.log === 'object') {\n if (typeof console['debug'] === 'undefined') {\n console['debug'] = this.bind(console['log'], console);\n }\n ['log', 'info', 'warn', 'error', 'assert', 'dir', 'clear', 'profile', 'profileEnd'].forEach(function (method) {\n console[method] = this.bind(console[method], console);\n }, Function.prototype.call);\n }\n\n Object.defineProperty(dom, 'title', {\n get: function () {\n return pal.global.document.title;\n },\n set: function (value) {\n pal.global.document.title = value;\n }\n });\n\n Object.defineProperty(dom, 'activeElement', {\n get: function () {\n return pal.global.document.activeElement;\n }\n });\n\n Object.defineProperty(platform, 'XMLHttpRequest', {\n get: function () {\n return pal.global.XMLHttpRequest;\n }\n });\n });\n}\n\n/**\n * @description initializes and makes variables like 'window' into NodeJS globals\n */\nexport function globalize() {\n initialize();\n global.window = global.self = PLATFORM.global;\n global.document = PLATFORM.global.document;\n global.Element = DOM.Element;\n global.NodeList = PLATFORM.global.NodeList;\n global.SVGElement = DOM.SVGElement;\n global.HTMLElement = PLATFORM.global.HTMLElement;\n global.requestAnimationFrame = PLATFORM.global.requestAnimationFrame;\n global.location = PLATFORM.location;\n global.history = PLATFORM.history;\n global.System = {\n import(moduleId: string) {\n try {\n return Promise.resolve(require(moduleId));\n } catch (e) {\n return Promise.reject(e);\n }\n }\n };\n global.PAL = {\n DOM, PLATFORM, FEATURE\n };\n return global;\n}\n\nexport function reset(window?: Window) {\n if (window) {\n window.close();\n }\n\n MutationNotifier.getInstance().destruct();\n}"],"sourceRoot":"../src/"} \ No newline at end of file diff --git a/dist/nodejs-dom.d.ts b/dist/nodejs-dom.d.ts index 6a9fa11..8c95900 100644 --- a/dist/nodejs-dom.d.ts +++ b/dist/nodejs-dom.d.ts @@ -1,5 +1,11 @@ import { IDom } from './dom'; import { IGlobal } from './global'; +declare module './global' { + interface IGlobal { + window: any; + document: any; + } +} /** * Represents the core APIs of the DOM. */ @@ -12,22 +18,23 @@ export declare class NodeJsDom implements IDom { boundary: string; title: string; activeElement: Element; - addEventListener(eventName: string, callback: EventListener, capture: boolean): void; - removeEventListener(eventName: string, callback: EventListener, capture: boolean): void; - createElement(tagName: string): Element; + addEventListener(eventName: string, callback: EventListenerOrEventListenerObject, capture: boolean): void; + removeEventListener(eventName: string, callback: EventListenerOrEventListenerObject, capture: boolean): void; + createElement(tagName: T): HTMLElementTagNameMap[T]; createAttribute(name: string): Attr; createTextNode(text: string): Text; createComment(text: string): Comment; createDocumentFragment(): DocumentFragment; createTemplateElement(): HTMLTemplateElement; createMutationObserver(callback: (changes: MutationRecord[], instance: MutationObserver) => void): MutationObserver; - createCustomEvent(eventType: string, options: Object): CustomEvent; + createCustomEvent(eventType: string, options?: Object): CustomEvent; dispatchEvent(evt: Event): void; getComputedStyle(element: Element): CSSStyleDeclaration; getElementById(id: string): Element; - querySelectorAll(query: string): NodeList; + querySelector(query: string): E | null; + querySelectorAll(query: string): NodeListOf; nextElementSibling(element: Element): Element; - createTemplateFromMarkup(markup: string): Element; + createTemplateFromMarkup(markup: string): HTMLTemplateElement; injectStyles(styles: string, destination?: Element, prepend?: boolean): Node; adoptNode(node: Node): Node; appendNode(newNode: Node, parentNode?: Node): void; diff --git a/dist/nodejs-dom.js b/dist/nodejs-dom.js index b7a6fa2..1879553 100644 --- a/dist/nodejs-dom.js +++ b/dist/nodejs-dom.js @@ -53,6 +53,9 @@ class NodeJsDom { getElementById(id) { return this.global.document.getElementById(id); } + querySelector(query) { + return this.global.document.querySelector(query); + } querySelectorAll(query) { return this.global.document.querySelectorAll(query); } diff --git a/dist/nodejs-dom.js.map b/dist/nodejs-dom.js.map index 2370f77..ef3c978 100644 --- a/dist/nodejs-dom.js.map +++ b/dist/nodejs-dom.js.map @@ -1 +1 @@ -{"version":3,"sources":["nodejs-dom.ts"],"names":[],"mappings":";;AAGA;;EAEE;AACF;IAEE,YAAmB,MAAe;QAAf,WAAM,GAAN,MAAM,CAAS;QASlC,aAAQ,GAAW,sBAAsB,CAAC;QAC1C,UAAK,GAAW,EAAE,CAAC;QACnB,kBAAa,GAAY,IAAI,CAAC;QAV5B,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC,OAAO,CAAC;QAC9B,IAAI,CAAC,QAAQ,GAAG,MAAM,CAAC,QAAQ,CAAC;QAChC,IAAI,CAAC,UAAU,GAAG,MAAM,CAAC,UAAU,IAAI,gBAAiB,SAAQ,MAAM,CAAC,OAAO;SAAI,CAAC;IACrF,CAAC;IASD,gBAAgB,CAAC,SAAiB,EAAE,QAAuB,EAAE,OAAgB;QAC3E,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,QAAQ,CA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","file":"nodejs-dom.js","sourcesContent":["import { IDom } from './dom';\nimport { IGlobal } from './global';\n\n/**\n* Represents the core APIs of the DOM.\n*/\nexport class NodeJsDom implements IDom {\n\n constructor(public global: IGlobal) {\n this.Element = global.Element;\n this.NodeList = global.NodeList;\n this.SVGElement = global.SVGElement || class SVGElement extends global.Element { };\n }\n\n Element: typeof Element;\n NodeList: typeof NodeList;\n SVGElement: typeof SVGElement /* until a proper implementation is ready: */ | any;\n boundary: string = 'aurelia-dom-boundary';\n title: string = \"\";\n activeElement: Element = null;\n\n addEventListener(eventName: string, callback: EventListener, capture: boolean): void {\n return this.global.document.addEventListener(eventName, callback, capture);\n }\n removeEventListener(eventName: string, callback: EventListener, capture: boolean): void {\n return this.global.document.removeEventListener(eventName, callback, capture);\n }\n createElement(tagName: string): Element {\n return this.global.document.createElement(tagName);\n }\n createAttribute(name: string): Attr {\n return this.global.document.createAttribute(name);\n }\n createTextNode(text: string): Text {\n return this.global.document.createTextNode(text);\n }\n createComment(text: string): Comment {\n return this.global.document.createComment(text);\n }\n createDocumentFragment(): DocumentFragment {\n return this.global.document.createDocumentFragment();\n }\n createTemplateElement(): HTMLTemplateElement {\n return this.global.document.createElement('template');\n }\n createMutationObserver(callback: (changes: MutationRecord[], instance: MutationObserver) => void): MutationObserver {\n return new ((this.global.window).MutationObserver)(callback);\n }\n createCustomEvent(eventType: string, options: Object): CustomEvent {\n return new this.global.CustomEvent(eventType, options);\n }\n dispatchEvent(evt: Event): void {\n this.global.window.dispatchEvent(evt);\n }\n getComputedStyle(element: Element): CSSStyleDeclaration {\n return this.global.window.getComputedStyle(element);\n }\n getElementById(id: string): Element {\n return this.global.document.getElementById(id);\n }\n querySelectorAll(query: string): NodeList {\n return this.global.document.querySelectorAll(query);\n }\n nextElementSibling(element: Element): Element {\n return element.nextElementSibling;\n }\n createTemplateFromMarkup(markup: string): Element {\n let parser = this.global.document.createElement('div');\n parser.innerHTML = markup;\n\n let temp = parser.firstElementChild;\n if (!temp || temp.nodeName !== 'TEMPLATE') {\n throw new Error('Template markup must be wrapped in a