diff --git a/dist/dom.d.ts b/dist/dom.d.ts index c767411..bc4404d 100644 --- a/dist/dom.d.ts +++ b/dist/dom.d.ts @@ -49,6 +49,12 @@ export interface IDom { */ createElement(tagName: string): Element; /** + * Creates the specified HTML attribute + * @param name A string that specifies the name of attribute to be created. + * @return The created attribute. + */ + createAttribute(name: string): Attr; + /** * Creates a new Text node. * @param text A string to populate the new Text node. * @return A Text node. diff --git a/dist/dom.js b/dist/dom.js index 3f1cffb..fea3d1b 100644 --- a/dist/dom.js +++ b/dist/dom.js @@ -1,3 +1,4 @@ "use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); //# sourceMappingURL=dom.js.map diff --git a/dist/feature.js b/dist/feature.js index 5f1f695..defefb9 100644 --- a/dist/feature.js +++ b/dist/feature.js @@ -1,3 +1,4 @@ "use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); //# sourceMappingURL=feature.js.map diff --git a/dist/global.d.ts b/dist/global.d.ts index 0f5b582..e3b71c5 100644 --- a/dist/global.d.ts +++ b/dist/global.d.ts @@ -1,6 +1,8 @@ -export interface IGlobal extends Window { +import { DOMWindow, JSDOM } from 'jsdom'; +export interface IGlobal extends DOMWindow { MutationObserver: typeof MutationObserver; Element: typeof Element; + jsdom: typeof JSDOM; SVGElement: typeof SVGElement; XMLHttpRequest: typeof XMLHttpRequest; CustomEvent: typeof CustomEvent; diff --git a/dist/global.js b/dist/global.js index d9c9594..ec9e79b 100644 --- a/dist/global.js +++ b/dist/global.js @@ -1,3 +1,4 @@ "use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); //# sourceMappingURL=global.js.map diff --git a/dist/index.d.ts b/dist/index.d.ts index 195d9d4..7d921bf 100644 --- a/dist/index.d.ts +++ b/dist/index.d.ts @@ -1,5 +1,4 @@ /// -/// /** * Initializes the PAL with the NodeJS-targeted implementation. */ @@ -8,3 +7,4 @@ export declare function initialize(): void; * @description initializes and makes variables like 'window' into NodeJS globals */ export declare function globalize(): NodeJS.Global; +export declare function reset(window?: Window): void; diff --git a/dist/index.js b/dist/index.js index 35deb4f..72e6b5e 100644 --- a/dist/index.js +++ b/dist/index.js @@ -1,7 +1,9 @@ -/// "use strict"; +/// +Object.defineProperty(exports, "__esModule", { value: true }); const aurelia_pal_1 = require("aurelia-pal"); const nodejs_pal_builder_1 = require("./nodejs-pal-builder"); +const mutation_observer_1 = require("./polyfills/mutation-observer"); /** * Initializes the PAL with the NodeJS-targeted implementation. */ @@ -93,5 +95,12 @@ function globalize() { return global; } exports.globalize = globalize; +function reset(window) { + if (window) { + window.close(); + } + mutation_observer_1.MutationNotifier.getInstance().destruct(); +} +exports.reset = reset; //# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map index a6fd885..93285f7 100644 --- a/dist/index.js.map +++ b/dist/index.js.map @@ -1 +1 @@ -{"version":3,"sources":["index.ts"],"names":[],"mappings":"AAAA,2CAA2C;;AAE3C,6CAAmF;AACnF,6DAAgD;AAEhD;;EAEE;AACF;IACE,EAAE,CAAC,CAAC,2BAAa,CAAC,CAAC,CAAC;QAClB,MAAM,CAAC;IACT,CAAC;IAED,IAAI,GAAG,GAAG,6BAAQ,EAAE,CAAC;IAErB,2BAAa,CAAC,CAAC,QAAQ,EAAE,OAAO,EAAE,GAAG;QACnC,MAAM,CAAC,MAAM,CAAC,QAAQ,EAAE,GAAG,CAAC,QAAQ,CAAC,CAAC;QACtC,MAAM,CAAC,cAAc,CAAC,QAAQ,EAAE,GAAG,CAAC,QAAQ,CAAC,WAAW,CAAC,SAAS,CAAC,CAAC;QAEpE,MAAM,CAAC,MAAM,CAAC,GAAG,EAAE,GAAG,CAAC,GAAG,CAAC,CAAC;QAC5B,MAAM,CAAC,cAAc,CAAC,GAAG,EAAE,GAAG,CAAC,GAAG,CAAC,WAAW,CAAC,SAAS,CAAC,CAAC;QAE1D,MAAM,CAAC,MAAM,CAAC,OAAO,EAAE,GAAG,CAAC,OAAO,CAAC,CAAC;QACpC,MAAM,CAAC,cAAc,CAAC,OAAO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U,GAAG,iBAAG,CAAC,UAAU,CAAC;IACnC,MAAM,CAAC,WAAW,GAAG,sBAAQ,CAAC,MAAM,CAAC,WAAW,CAAC;IACjD,MAAM,CAAC,qBAAqB,GAAG,sBAAQ,CAAC,MAAM,CAAC,qBAAqB,CAAC;IACrE,MAAM,CAAC,QAAQ,GAAG,sBAAQ,CAAC,QAAQ,CAAC;IACpC,MAAM,CAAC,OAAO,GAAG,sBAAQ,CAAC,OAAO,CAAC;IAClC,MAAM,CAAC,MAAM,GAAG;QACd,MAAM,CAAC,QAAgB;YACrB,IAAI,CAAC;gBACH,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC;YAC5C,CAAE;YAAA,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;AAvBD,8BAuBC","file":"index.js","sourcesContent":["/// \n\nimport { initializePAL, DOM, PLATFORM, FEATURE, isInitialized } from 'aurelia-pal';\nimport { buildPal } from './nodejs-pal-builder';\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.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}"],"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,EAAE,C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,GAAG,GAAG;QACX,GAAG,EAAH,iBAAG,EAAE,QAAQ,EAAR,sBAAQ,EAAE,OAAO,EAAP,qBAAO;KACvB,CAAC;IACF,MAAM,CAAC,MAAM,CAAC;AAChB,CAAC;AAvBD,8BAuBC;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.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 862e8ef..b5f9abe 100644 --- a/dist/nodejs-dom.d.ts +++ b/dist/nodejs-dom.d.ts @@ -14,9 +14,11 @@ export declare class NodeJsDom implements IDom { addEventListener(eventName: string, callback: EventListener, capture: boolean): void; removeEventListener(eventName: string, callback: EventListener, capture: boolean): void; createElement(tagName: string): Element; + 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; dispatchEvent(evt: Event): void; diff --git a/dist/nodejs-dom.js b/dist/nodejs-dom.js index e06626e..b8ab914 100644 --- a/dist/nodejs-dom.js +++ b/dist/nodejs-dom.js @@ -1,4 +1,5 @@ "use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); /** * Represents the core APIs of the DOM. */ @@ -21,6 +22,9 @@ class NodeJsDom { createElement(tagName) { return this.global.document.createElement(tagName); } + createAttribute(name) { + return this.global.document.createAttribute(name); + } createTextNode(text) { return this.global.document.createTextNode(text); } @@ -30,6 +34,9 @@ class NodeJsDom { createDocumentFragment() { return this.global.document.createDocumentFragment(); } + createTemplateElement() { + return this.global.document.createElement('template'); + } createMutationObserver(callback) { return new (this.global.window.MutationObserver)(callback); } diff --git a/dist/nodejs-dom.js.map b/dist/nodejs-dom.js.map index 9f84631..7df2a7e 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;QAOlC,aAAQ,GAAW,sBAAsB,CAAC;QAC1C,UAAK,GAAW,EAAE,CAAC;QACnB,kBAAa,GAAY,IAAI,CAAC;QAR5B,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC,OAAO,CAAC;QAC9B,IAAI,CAAC,UAAU,GAAG,MAAM,CAAC,UAAU,IAAI,gBAAiB,SAAQ,MAAM,CAAC,OAAO;SAAI,CAAC;IACrF,CAAC;IAQD,gBAAgB,CAAC,SAAiB,EAAE,QAAuB,EAAE,OAAgB;QAC3E,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,gBAAgB,CAAC,SAAS,EAAE,QAAQ,EAAE,OAAO,CAAC,CAAC;IAC7E,CAAC;IACD,mBAAmB,CAAC,SAAiB,EAAE,QAAuB,EAAE,OAAgB;QAC9E,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,mBAAmB,CAAC,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AAC,QAAQ,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;IAC9C,CAAC;IAED,UAAU,CAAC,OAAa,EAAE,UAAiB;QACzC,CAAC,UAAU,IAAI,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC;IACjE,CAAC;IAED,WAAW,CAAC,OAAa,EAAE,IAAU,EAAE,UAAiB;QACtD,EAAE,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC;YACpB,IAAI,CAAC,UAAU,CAAC,YAAY,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;QAC9C,CAAC;QAAC,IAAI,CAAC,CAAC;YACN,UAAU,CAAC,YAAY,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;QACzC,CAAC;IACH,CAAC;IAED,UAAU,CAAC,IAAU,EAAE,UAAiB;QACtC,EAAE,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC;YACpB,IAAI,CAAC,UAAU,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC;QACpC,CAAC;QACD,IAAI,CAAC,CAAC;YACJ,UAAU,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC;QAC/B,CAAC;IACH,CAAC;CACF;AAtGD,8BAsGC","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.SVGElement = global.SVGElement || class SVGElement extends global.Element { };\n }\n\n Element: typeof Element;\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 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 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