pseudo-dom 0.12.0 → 0.14.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +40 -16
- package/browser/pseudo-dom.js +40 -20
- package/browser/pseudo-dom.min.js +1 -1
- package/dist/factories/generateDocument.js +82 -70
- package/dist/factories/generateDocument.min.js +1 -1
- package/dist/factories/installGlobal.d.ts +15 -14
- package/dist/factories/installGlobal.js +44 -40
- package/dist/factories/installGlobal.min.js +1 -1
- package/dist/factories/logElement.d.ts +9 -9
- package/dist/factories/logElement.js +23 -23
- package/dist/factories/serializeHTML.d.ts +25 -25
- package/dist/factories/serializeHTML.js +10 -6
- package/dist/factories/serializeHTML.min.js +1 -1
- package/dist/main.d.ts +69 -69
- package/dist/main.js +169 -169
- package/package.json +1 -1
|
@@ -1,70 +1,82 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
const __importDefault = void 0 && (void 0).__importDefault || function (mod) {
|
|
4
|
-
return mod && mod.__esModule
|
|
5
|
-
? mod
|
|
6
|
-
: {
|
|
7
|
-
default: mod
|
|
8
|
-
}
|
|
9
|
-
}
|
|
10
|
-
Object.defineProperty(exports, '__esModule', {
|
|
11
|
-
value: true
|
|
12
|
-
})
|
|
13
|
-
const EventTargetService_1 = __importDefault(require('../services/EventTargetService'))
|
|
14
|
-
const NodeService_1 = require('../services/NodeService')
|
|
15
|
-
const ElementService_1 = require('../services/ElementService')
|
|
16
|
-
const HTMLElementService_1 = require('../services/HTMLElementService')
|
|
17
|
-
const PseudoHTMLDocument_1 = __importDefault(require('../classes/PseudoHTMLDocument'))
|
|
18
|
-
/**
|
|
19
|
-
* Construct the Pseudo Dom to provide access to Dom objects which are otherwise not available outside the browser
|
|
20
|
-
* context.
|
|
21
|
-
* @function generateDocument
|
|
22
|
-
* @param {Object} root
|
|
23
|
-
* @param {Object} context
|
|
24
|
-
* @returns {Window|PseudoEventTarget}
|
|
25
|
-
*/
|
|
26
|
-
const generateDocument = (root, context = {}) => {
|
|
27
|
-
/**
|
|
28
|
-
*
|
|
29
|
-
* @type {Window|PseudoEventTarget}
|
|
30
|
-
*/
|
|
31
|
-
const newWindow = typeof root.document === 'undefined' ? root : new EventTargetService_1.default()
|
|
32
|
-
/**
|
|
33
|
-
*
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
}
|
|
70
|
-
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
const __importDefault = void 0 && (void 0).__importDefault || function (mod) {
|
|
4
|
+
return mod && mod.__esModule
|
|
5
|
+
? mod
|
|
6
|
+
: {
|
|
7
|
+
default: mod
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
Object.defineProperty(exports, '__esModule', {
|
|
11
|
+
value: true
|
|
12
|
+
})
|
|
13
|
+
const EventTargetService_1 = __importDefault(require('../services/EventTargetService'))
|
|
14
|
+
const NodeService_1 = require('../services/NodeService')
|
|
15
|
+
const ElementService_1 = require('../services/ElementService')
|
|
16
|
+
const HTMLElementService_1 = require('../services/HTMLElementService')
|
|
17
|
+
const PseudoHTMLDocument_1 = __importDefault(require('../classes/PseudoHTMLDocument'))
|
|
18
|
+
/**
|
|
19
|
+
* Construct the Pseudo Dom to provide access to Dom objects which are otherwise not available outside the browser
|
|
20
|
+
* context.
|
|
21
|
+
* @function generateDocument
|
|
22
|
+
* @param {Object} root
|
|
23
|
+
* @param {Object} context
|
|
24
|
+
* @returns {Window|PseudoEventTarget}
|
|
25
|
+
*/
|
|
26
|
+
const generateDocument = (root, context = {}) => {
|
|
27
|
+
/**
|
|
28
|
+
*
|
|
29
|
+
* @type {Window|PseudoEventTarget}
|
|
30
|
+
*/
|
|
31
|
+
const newWindow = typeof root.document === 'undefined' ? root : new EventTargetService_1.default()
|
|
32
|
+
/**
|
|
33
|
+
* The Node class itself (matching the DOM's window.Node), not an instance - the right-hand side of `instanceof`
|
|
34
|
+
* must be a constructor, so `x instanceof Node` needs this, not `new PseudoNode()`.
|
|
35
|
+
* @type {Function}
|
|
36
|
+
*/
|
|
37
|
+
const Node = root.Node || NodeService_1.NodeService
|
|
38
|
+
if (typeof newWindow.Node === 'undefined') {
|
|
39
|
+
newWindow.Node = Node
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* The Element class itself, for the same reason as Node.
|
|
43
|
+
* @type {Function}
|
|
44
|
+
*/
|
|
45
|
+
const Element = root.Element || ElementService_1.ElementService
|
|
46
|
+
if (typeof newWindow.Element === 'undefined') {
|
|
47
|
+
newWindow.Element = Element
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* The HTMLElement class itself, for the same reason as Node.
|
|
51
|
+
* @type {Function}
|
|
52
|
+
*/
|
|
53
|
+
const HTMLElement = root.HTMLElement || HTMLElementService_1.HTMLElementService
|
|
54
|
+
if (typeof newWindow.HTMLElement === 'undefined') {
|
|
55
|
+
newWindow.HTMLElement = HTMLElement
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* The HTMLDocument class itself, for the same reason as Node (so `document instanceof HTMLDocument`, a common
|
|
59
|
+
* real-DOM-detection check, works).
|
|
60
|
+
* @type {Function}
|
|
61
|
+
*/
|
|
62
|
+
const HTMLDocument = root.HTMLDocument || PseudoHTMLDocument_1.default
|
|
63
|
+
if (typeof newWindow.HTMLDocument === 'undefined') {
|
|
64
|
+
newWindow.HTMLDocument = HTMLDocument
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Define document when not available - a real instance, unlike the classes above (window.document IS an object,
|
|
68
|
+
* not a constructor).
|
|
69
|
+
* @type {Document|PseudoHTMLDocument}
|
|
70
|
+
*/
|
|
71
|
+
const document = root.document || new PseudoHTMLDocument_1.default()
|
|
72
|
+
if (typeof newWindow.document === 'undefined') {
|
|
73
|
+
newWindow.document = document
|
|
74
|
+
}
|
|
75
|
+
// When there was no real document, newWindow is root itself (see above), so every assignment above already
|
|
76
|
+
// mutated it directly. If context is also that same object (root and context given as one and the same, as
|
|
77
|
+
// installGlobal does) merging is already done - doing it again would be Object.assign(target, target), which
|
|
78
|
+
// throws on any getter-only own property target already has (globalThis.crypto, in Node).
|
|
79
|
+
const mergeInto = context || root
|
|
80
|
+
return newWindow === mergeInto ? newWindow : Object.assign(mergeInto, newWindow)
|
|
81
|
+
}
|
|
82
|
+
exports.default = generateDocument
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var __importDefault=function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0});const EventTargetService_1=__importDefault(require("../services/EventTargetService")),NodeService_1=require("../services/NodeService"),ElementService_1=require("../services/ElementService"),HTMLElementService_1=require("../services/HTMLElementService"),PseudoHTMLDocument_1=__importDefault(require("../classes/PseudoHTMLDocument")),generateDocument=(e,t={})=>{const
|
|
1
|
+
"use strict";var __importDefault=function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0});const EventTargetService_1=__importDefault(require("../services/EventTargetService")),NodeService_1=require("../services/NodeService"),ElementService_1=require("../services/ElementService"),HTMLElementService_1=require("../services/HTMLElementService"),PseudoHTMLDocument_1=__importDefault(require("../classes/PseudoHTMLDocument")),generateDocument=(e,t={})=>{const n=void 0===e.document?e:new EventTargetService_1.default,r=e.Node||NodeService_1.NodeService;void 0===n.Node&&(n.Node=r);const o=e.Element||ElementService_1.ElementService;void 0===n.Element&&(n.Element=o);const c=e.HTMLElement||HTMLElementService_1.HTMLElementService;void 0===n.HTMLElement&&(n.HTMLElement=c);const i=e.HTMLDocument||PseudoHTMLDocument_1.default;void 0===n.HTMLDocument&&(n.HTMLDocument=i);const u=e.document||new PseudoHTMLDocument_1.default;void 0===n.document&&(n.document=u);const m=t||e;return n===m?n:Object.assign(m,n)};exports.default=generateDocument;
|
|
@@ -1,14 +1,15 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* When there is no real DOM already available (a real browser, or a jsdom-based test environment - isBrowser is
|
|
3
|
-
* true for both, since jsdom's window has a document too, and a jsdom document should never be overwritten, real
|
|
4
|
-
* DOM behaviour is always closer to the real thing), populate the given global-like target with document / Node /
|
|
5
|
-
* Element / HTMLElement, generated by generateDocument,
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
* @
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
1
|
+
/**
|
|
2
|
+
* When there is no real DOM already available (a real browser, or a jsdom-based test environment - isBrowser is
|
|
3
|
+
* true for both, since jsdom's window has a document too, and a jsdom document should never be overwritten, real
|
|
4
|
+
* DOM behaviour is always closer to the real thing), populate the given global-like target with document / Node /
|
|
5
|
+
* Element / HTMLElement / HTMLDocument, generated by generateDocument, plus window (a self-reference, matching a
|
|
6
|
+
* real browser's global scope - some code checks for a bare `window` before falling back to `global`), so code
|
|
7
|
+
* written against a real DOM's globals works as-is. Does nothing when a real DOM is already there, matching
|
|
8
|
+
* generateDocument's own only-fill-what-is-missing behaviour - calling this is always safe, in any environment.
|
|
9
|
+
* @memberOf module:factories
|
|
10
|
+
* @param {*} [target] The object to add document / Node / Element / HTMLElement / window onto - defaults to
|
|
11
|
+
* globalThis, so bare `document`, `Node`, `window`, etc. resolve from anywhere once this has run
|
|
12
|
+
* @returns {*} The same target, for convenience
|
|
13
|
+
*/
|
|
14
|
+
declare const installGlobal: (target?: any) => any;
|
|
15
|
+
export default installGlobal;
|
|
@@ -1,40 +1,44 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
const __importDefault = void 0 && (void 0).__importDefault || function (mod) {
|
|
4
|
-
return mod && mod.__esModule
|
|
5
|
-
? mod
|
|
6
|
-
: {
|
|
7
|
-
default: mod
|
|
8
|
-
}
|
|
9
|
-
}
|
|
10
|
-
Object.defineProperty(exports, '__esModule', {
|
|
11
|
-
value: true
|
|
12
|
-
})
|
|
13
|
-
/**
|
|
14
|
-
* @file Makes pseudo-dom a drop-in swap for a real DOM: code written against bare globals (document.createElement,
|
|
15
|
-
* new Node(), ...) works unmodified, in the browser or in Node, without an if (typeof document === 'undefined')
|
|
16
|
-
* check at every call site.
|
|
17
|
-
* @author Joshua Heagle <joshuaheagle@gmail.com>
|
|
18
|
-
* @version 1.0.0
|
|
19
|
-
*/
|
|
20
|
-
const browser_or_node_1 = require('browser-or-node')
|
|
21
|
-
const generateDocument_1 = __importDefault(require('./generateDocument'))
|
|
22
|
-
/**
|
|
23
|
-
* When there is no real DOM already available (a real browser, or a jsdom-based test environment - isBrowser is
|
|
24
|
-
* true for both, since jsdom's window has a document too, and a jsdom document should never be overwritten, real
|
|
25
|
-
* DOM behaviour is always closer to the real thing), populate the given global-like target with document / Node /
|
|
26
|
-
* Element / HTMLElement, generated by generateDocument,
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
* @
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
const __importDefault = void 0 && (void 0).__importDefault || function (mod) {
|
|
4
|
+
return mod && mod.__esModule
|
|
5
|
+
? mod
|
|
6
|
+
: {
|
|
7
|
+
default: mod
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
Object.defineProperty(exports, '__esModule', {
|
|
11
|
+
value: true
|
|
12
|
+
})
|
|
13
|
+
/**
|
|
14
|
+
* @file Makes pseudo-dom a drop-in swap for a real DOM: code written against bare globals (document.createElement,
|
|
15
|
+
* new Node(), ...) works unmodified, in the browser or in Node, without an if (typeof document === 'undefined')
|
|
16
|
+
* check at every call site.
|
|
17
|
+
* @author Joshua Heagle <joshuaheagle@gmail.com>
|
|
18
|
+
* @version 1.0.0
|
|
19
|
+
*/
|
|
20
|
+
const browser_or_node_1 = require('browser-or-node')
|
|
21
|
+
const generateDocument_1 = __importDefault(require('./generateDocument'))
|
|
22
|
+
/**
|
|
23
|
+
* When there is no real DOM already available (a real browser, or a jsdom-based test environment - isBrowser is
|
|
24
|
+
* true for both, since jsdom's window has a document too, and a jsdom document should never be overwritten, real
|
|
25
|
+
* DOM behaviour is always closer to the real thing), populate the given global-like target with document / Node /
|
|
26
|
+
* Element / HTMLElement / HTMLDocument, generated by generateDocument, plus window (a self-reference, matching a
|
|
27
|
+
* real browser's global scope - some code checks for a bare `window` before falling back to `global`), so code
|
|
28
|
+
* written against a real DOM's globals works as-is. Does nothing when a real DOM is already there, matching
|
|
29
|
+
* generateDocument's own only-fill-what-is-missing behaviour - calling this is always safe, in any environment.
|
|
30
|
+
* @memberOf module:factories
|
|
31
|
+
* @param {*} [target] The object to add document / Node / Element / HTMLElement / window onto - defaults to
|
|
32
|
+
* globalThis, so bare `document`, `Node`, `window`, etc. resolve from anywhere once this has run
|
|
33
|
+
* @returns {*} The same target, for convenience
|
|
34
|
+
*/
|
|
35
|
+
const installGlobal = (target = typeof globalThis !== 'undefined' ? globalThis : {}) => {
|
|
36
|
+
if (!browser_or_node_1.isBrowser) {
|
|
37
|
+
(0, generateDocument_1.default)(target, target)
|
|
38
|
+
if (typeof target.window === 'undefined') {
|
|
39
|
+
target.window = target
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
return target
|
|
43
|
+
}
|
|
44
|
+
exports.default = installGlobal
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var __importDefault=function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0});const browser_or_node_1=require("browser-or-node"),generateDocument_1=__importDefault(require("./generateDocument")),installGlobal=(e=("undefined"!=typeof globalThis?globalThis:{}))=>(browser_or_node_1.isBrowser||(0,generateDocument_1.default)(e,e),e);exports.default=installGlobal;
|
|
1
|
+
"use strict";var __importDefault=function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0});const browser_or_node_1=require("browser-or-node"),generateDocument_1=__importDefault(require("./generateDocument")),installGlobal=(e=("undefined"!=typeof globalThis?globalThis:{}))=>(browser_or_node_1.isBrowser||((0,generateDocument_1.default)(e,e),void 0===e.window&&(e.window=e)),e);exports.default=installGlobal;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Print a node's markup to the console, indented for readability (see prettyPrint).
|
|
3
|
-
* @memberOf module:factories
|
|
4
|
-
* @param {*} node
|
|
5
|
-
* @param {string} [label=''] A label printed above the markup, to identify this log call
|
|
6
|
-
* @returns {undefined}
|
|
7
|
-
*/
|
|
8
|
-
declare const logElement: (node: any, label?: string) => void;
|
|
9
|
-
export default logElement;
|
|
1
|
+
/**
|
|
2
|
+
* Print a node's markup to the console, indented for readability (see prettyPrint).
|
|
3
|
+
* @memberOf module:factories
|
|
4
|
+
* @param {*} node
|
|
5
|
+
* @param {string} [label=''] A label printed above the markup, to identify this log call
|
|
6
|
+
* @returns {undefined}
|
|
7
|
+
*/
|
|
8
|
+
declare const logElement: (node: any, label?: string) => void;
|
|
9
|
+
export default logElement;
|
|
@@ -1,23 +1,23 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, '__esModule', {
|
|
4
|
-
value: true
|
|
5
|
-
})
|
|
6
|
-
/**
|
|
7
|
-
* @file Prints an element (or any node) to the console, readably - the point of pseudo-dom running headlessly is
|
|
8
|
-
* usually to watch what code does to a tree without a real browser to look at.
|
|
9
|
-
* @author Joshua Heagle <joshuaheagle@gmail.com>
|
|
10
|
-
* @version 1.0.0
|
|
11
|
-
*/
|
|
12
|
-
const serializeHTML_1 = require('./serializeHTML')
|
|
13
|
-
/**
|
|
14
|
-
* Print a node's markup to the console, indented for readability (see prettyPrint).
|
|
15
|
-
* @memberOf module:factories
|
|
16
|
-
* @param {*} node
|
|
17
|
-
* @param {string} [label=''] A label printed above the markup, to identify this log call
|
|
18
|
-
* @returns {undefined}
|
|
19
|
-
*/
|
|
20
|
-
const logElement = (node, label = '') => {
|
|
21
|
-
console.log(`${label ? `${label}\n` : ''}${(0, serializeHTML_1.prettyPrint)(node)}`)
|
|
22
|
-
}
|
|
23
|
-
exports.default = logElement
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', {
|
|
4
|
+
value: true
|
|
5
|
+
})
|
|
6
|
+
/**
|
|
7
|
+
* @file Prints an element (or any node) to the console, readably - the point of pseudo-dom running headlessly is
|
|
8
|
+
* usually to watch what code does to a tree without a real browser to look at.
|
|
9
|
+
* @author Joshua Heagle <joshuaheagle@gmail.com>
|
|
10
|
+
* @version 1.0.0
|
|
11
|
+
*/
|
|
12
|
+
const serializeHTML_1 = require('./serializeHTML')
|
|
13
|
+
/**
|
|
14
|
+
* Print a node's markup to the console, indented for readability (see prettyPrint).
|
|
15
|
+
* @memberOf module:factories
|
|
16
|
+
* @param {*} node
|
|
17
|
+
* @param {string} [label=''] A label printed above the markup, to identify this log call
|
|
18
|
+
* @returns {undefined}
|
|
19
|
+
*/
|
|
20
|
+
const logElement = (node, label = '') => {
|
|
21
|
+
console.log(`${label ? `${label}\n` : ''}${(0, serializeHTML_1.prettyPrint)(node)}`)
|
|
22
|
+
}
|
|
23
|
+
exports.default = logElement
|
|
@@ -1,25 +1,25 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* A node's children, serialized in order (this is what innerHTML returns).
|
|
3
|
-
* @memberOf module:factories
|
|
4
|
-
* @param {*} node
|
|
5
|
-
* @returns {string}
|
|
6
|
-
*/
|
|
7
|
-
declare const serializeChildren: (node: any) => string;
|
|
8
|
-
/**
|
|
9
|
-
* An element itself, serialized with its children (this is what outerHTML returns).
|
|
10
|
-
* @memberOf module:factories
|
|
11
|
-
* @param {*} element
|
|
12
|
-
* @returns {string}
|
|
13
|
-
*/
|
|
14
|
-
declare const serializeOuter: (element: any) => string;
|
|
15
|
-
/**
|
|
16
|
-
* A node's markup, indented one level per level of nesting - a real DOM's outerHTML / innerHTML has no line breaks
|
|
17
|
-
* at all, which does not read well for a whole tree (a board full of cells, say). Useful for watching pseudo-dom-
|
|
18
|
-
* driven code run headlessly, printed to a terminal - see also logElement, which does the printing too.
|
|
19
|
-
* @memberOf module:factories
|
|
20
|
-
* @param {*} node
|
|
21
|
-
* @param {string} [indent=' '] The indentation used per level of nesting
|
|
22
|
-
* @returns {string}
|
|
23
|
-
*/
|
|
24
|
-
declare const prettyPrint: (node: any, indent?: string) => string;
|
|
25
|
-
export { serializeChildren, serializeOuter, prettyPrint };
|
|
1
|
+
/**
|
|
2
|
+
* A node's children, serialized in order (this is what innerHTML returns).
|
|
3
|
+
* @memberOf module:factories
|
|
4
|
+
* @param {*} node
|
|
5
|
+
* @returns {string}
|
|
6
|
+
*/
|
|
7
|
+
declare const serializeChildren: (node: any) => string;
|
|
8
|
+
/**
|
|
9
|
+
* An element itself, serialized with its children (this is what outerHTML returns).
|
|
10
|
+
* @memberOf module:factories
|
|
11
|
+
* @param {*} element
|
|
12
|
+
* @returns {string}
|
|
13
|
+
*/
|
|
14
|
+
declare const serializeOuter: (element: any) => string;
|
|
15
|
+
/**
|
|
16
|
+
* A node's markup, indented one level per level of nesting - a real DOM's outerHTML / innerHTML has no line breaks
|
|
17
|
+
* at all, which does not read well for a whole tree (a board full of cells, say). Useful for watching pseudo-dom-
|
|
18
|
+
* driven code run headlessly, printed to a terminal - see also logElement, which does the printing too.
|
|
19
|
+
* @memberOf module:factories
|
|
20
|
+
* @param {*} node
|
|
21
|
+
* @param {string} [indent=' '] The indentation used per level of nesting
|
|
22
|
+
* @returns {string}
|
|
23
|
+
*/
|
|
24
|
+
declare const prettyPrint: (node: any, indent?: string) => string;
|
|
25
|
+
export { serializeChildren, serializeOuter, prettyPrint };
|
|
@@ -43,17 +43,21 @@ const ATTRIBUTE_NAME = {
|
|
|
43
43
|
// Boolean HTML attributes: present (with no value) when true, absent entirely when false
|
|
44
44
|
const BOOLEAN_ATTRIBUTES = new Set(['hidden'])
|
|
45
45
|
/**
|
|
46
|
-
* Escape text so it is safe inside HTML text content.
|
|
47
|
-
*
|
|
46
|
+
* Escape text so it is safe inside HTML text content. Coerces to a string first - unlike a real DOM, pseudo-dom's
|
|
47
|
+
* setAttribute does not itself coerce (see the same note on escapeAttributeValue), and nodeValue is not guaranteed
|
|
48
|
+
* to be a string either.
|
|
49
|
+
* @param {*} text
|
|
48
50
|
* @returns {string}
|
|
49
51
|
*/
|
|
50
|
-
const escapeText = text => text.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>')
|
|
52
|
+
const escapeText = text => String(text).replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>')
|
|
51
53
|
/**
|
|
52
|
-
* Escape a value so it is safe inside a double-quoted HTML attribute.
|
|
53
|
-
*
|
|
54
|
+
* Escape a value so it is safe inside a double-quoted HTML attribute. Coerces to a string first: a real DOM's
|
|
55
|
+
* setAttribute always stores a string, however pseudo-dom's does not coerce what it is given, so a value set via
|
|
56
|
+
* setAttribute(name, 5) is stored (and read back by getAttribute) as the number 5, not the string '5'.
|
|
57
|
+
* @param {*} value
|
|
54
58
|
* @returns {string}
|
|
55
59
|
*/
|
|
56
|
-
const escapeAttributeValue = value => value.replace(/&/g, '&').replace(/"/g, '"')
|
|
60
|
+
const escapeAttributeValue = value => String(value).replace(/&/g, '&').replace(/"/g, '"')
|
|
57
61
|
/**
|
|
58
62
|
* Every attribute of the element, serialized (class instead of className, boolean attributes bare, the never-real
|
|
59
63
|
* mock properties left out, style added from the live CSSStyleDeclaration when it is not empty).
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";require("core-js/modules/esnext.iterator.constructor.js"),require("core-js/modules/esnext.iterator.filter.js"),require("core-js/modules/esnext.iterator.map.js"),require("core-js/modules/esnext.set.add-all.js"),require("core-js/modules/esnext.set.delete-all.js"),require("core-js/modules/esnext.set.difference.js"),require("core-js/modules/esnext.set.every.js"),require("core-js/modules/esnext.set.filter.js"),require("core-js/modules/esnext.set.find.js"),require("core-js/modules/esnext.set.intersection.js"),require("core-js/modules/esnext.set.is-disjoint-from.js"),require("core-js/modules/esnext.set.is-subset-of.js"),require("core-js/modules/esnext.set.is-superset-of.js"),require("core-js/modules/esnext.set.join.js"),require("core-js/modules/esnext.set.map.js"),require("core-js/modules/esnext.set.reduce.js"),require("core-js/modules/esnext.set.some.js"),require("core-js/modules/esnext.set.symmetric-difference.js"),require("core-js/modules/esnext.set.union.js"),Object.defineProperty(exports,"__esModule",{value:!0}),exports.prettyPrint=exports.serializeOuter=exports.serializeChildren=void 0;const NodeService_1=require("../services/NodeService"),VOID_ELEMENTS=new Set(["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"]),NEVER_SERIALIZE=new Set(["innerHTML","clientHeight","clientLeft","clientTop","clientWidth","scrollHeight","scrollLeft","scrollTop","scrollWidth","offsetHeight","offsetLeft","offsetParent","offsetTop","offsetWidth"]),ATTRIBUTE_NAME={className:"class"},BOOLEAN_ATTRIBUTES=new Set(["hidden"]),escapeText=e=>e.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">"),escapeAttributeValue=e=>e.replace(/&/g,"&").replace(/"/g,"""),serializeAttributes=e=>{let r=(e.getAttributeNames?e.getAttributeNames():[]).filter(e=>!NEVER_SERIALIZE.has(e)).map(r=>{if(BOOLEAN_ATTRIBUTES.has(r))return e[r]?` ${r}`:"";const t=e.getAttribute(r);return""===t?"":` ${ATTRIBUTE_NAME[r]||r}="${escapeAttributeValue(t)}"`}).join("");const t=e.style;return t&&t.cssText&&(r+=` style="${escapeAttributeValue(t.cssText)}"`),r},serializeNode=e=>{if(e.nodeType===NodeService_1.NodeService.TEXT_NODE)return escapeText(e.nodeValue||"");if(e.nodeType===NodeService_1.NodeService.COMMENT_NODE)return`\x3c!--${e.nodeValue||""}--\x3e`;if(e.nodeType!==NodeService_1.NodeService.ELEMENT_NODE)return"";const r=e.tagName,t=serializeAttributes(e);return VOID_ELEMENTS.has(r)?`<${r}${t}>`:`<${r}${t}>${serializeChildren(e)}</${r}>`},serializeChildren=e=>Array.from(e.childNodes).map(serializeNode).join("");exports.serializeChildren=serializeChildren;const serializeOuter=e=>serializeNode(e);exports.serializeOuter=serializeOuter;const prettyPrintNode=(e,r,t)=>{const s=t.repeat(r);if(e.nodeType===NodeService_1.NodeService.TEXT_NODE){const r=escapeText((e.nodeValue||"").trim());return r?`${s}${r}`:""}if(e.nodeType===NodeService_1.NodeService.COMMENT_NODE)return`${s}\x3c!--${e.nodeValue||""}--\x3e`;if(e.nodeType!==NodeService_1.NodeService.ELEMENT_NODE)return"";const i=e.tagName,o=serializeAttributes(e);if(VOID_ELEMENTS.has(i))return`${s}<${i}${o}>`;const n=Array.from(e.childNodes).map(e=>prettyPrintNode(e,r+1,t)).filter(e=>""!==e);return 0===n.length?`${s}<${i}${o}></${i}>`:`${s}<${i}${o}>\n${n.join("\n")}\n${s}</${i}>`},prettyPrint=(e,r=" ")=>prettyPrintNode(e,0,r);exports.prettyPrint=prettyPrint;
|
|
1
|
+
"use strict";require("core-js/modules/esnext.iterator.constructor.js"),require("core-js/modules/esnext.iterator.filter.js"),require("core-js/modules/esnext.iterator.map.js"),require("core-js/modules/esnext.set.add-all.js"),require("core-js/modules/esnext.set.delete-all.js"),require("core-js/modules/esnext.set.difference.js"),require("core-js/modules/esnext.set.every.js"),require("core-js/modules/esnext.set.filter.js"),require("core-js/modules/esnext.set.find.js"),require("core-js/modules/esnext.set.intersection.js"),require("core-js/modules/esnext.set.is-disjoint-from.js"),require("core-js/modules/esnext.set.is-subset-of.js"),require("core-js/modules/esnext.set.is-superset-of.js"),require("core-js/modules/esnext.set.join.js"),require("core-js/modules/esnext.set.map.js"),require("core-js/modules/esnext.set.reduce.js"),require("core-js/modules/esnext.set.some.js"),require("core-js/modules/esnext.set.symmetric-difference.js"),require("core-js/modules/esnext.set.union.js"),Object.defineProperty(exports,"__esModule",{value:!0}),exports.prettyPrint=exports.serializeOuter=exports.serializeChildren=void 0;const NodeService_1=require("../services/NodeService"),VOID_ELEMENTS=new Set(["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"]),NEVER_SERIALIZE=new Set(["innerHTML","clientHeight","clientLeft","clientTop","clientWidth","scrollHeight","scrollLeft","scrollTop","scrollWidth","offsetHeight","offsetLeft","offsetParent","offsetTop","offsetWidth"]),ATTRIBUTE_NAME={className:"class"},BOOLEAN_ATTRIBUTES=new Set(["hidden"]),escapeText=e=>String(e).replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">"),escapeAttributeValue=e=>String(e).replace(/&/g,"&").replace(/"/g,"""),serializeAttributes=e=>{let r=(e.getAttributeNames?e.getAttributeNames():[]).filter(e=>!NEVER_SERIALIZE.has(e)).map(r=>{if(BOOLEAN_ATTRIBUTES.has(r))return e[r]?` ${r}`:"";const t=e.getAttribute(r);return""===t?"":` ${ATTRIBUTE_NAME[r]||r}="${escapeAttributeValue(t)}"`}).join("");const t=e.style;return t&&t.cssText&&(r+=` style="${escapeAttributeValue(t.cssText)}"`),r},serializeNode=e=>{if(e.nodeType===NodeService_1.NodeService.TEXT_NODE)return escapeText(e.nodeValue||"");if(e.nodeType===NodeService_1.NodeService.COMMENT_NODE)return`\x3c!--${e.nodeValue||""}--\x3e`;if(e.nodeType!==NodeService_1.NodeService.ELEMENT_NODE)return"";const r=e.tagName,t=serializeAttributes(e);return VOID_ELEMENTS.has(r)?`<${r}${t}>`:`<${r}${t}>${serializeChildren(e)}</${r}>`},serializeChildren=e=>Array.from(e.childNodes).map(serializeNode).join("");exports.serializeChildren=serializeChildren;const serializeOuter=e=>serializeNode(e);exports.serializeOuter=serializeOuter;const prettyPrintNode=(e,r,t)=>{const s=t.repeat(r);if(e.nodeType===NodeService_1.NodeService.TEXT_NODE){const r=escapeText((e.nodeValue||"").trim());return r?`${s}${r}`:""}if(e.nodeType===NodeService_1.NodeService.COMMENT_NODE)return`${s}\x3c!--${e.nodeValue||""}--\x3e`;if(e.nodeType!==NodeService_1.NodeService.ELEMENT_NODE)return"";const i=e.tagName,o=serializeAttributes(e);if(VOID_ELEMENTS.has(i))return`${s}<${i}${o}>`;const n=Array.from(e.childNodes).map(e=>prettyPrintNode(e,r+1,t)).filter(e=>""!==e);return 0===n.length?`${s}<${i}${o}></${i}>`:`${s}<${i}${o}>\n${n.join("\n")}\n${s}</${i}>`},prettyPrint=(e,r=" ")=>prettyPrintNode(e,0,r);exports.prettyPrint=prettyPrint;
|
package/dist/main.d.ts
CHANGED
|
@@ -1,69 +1,69 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @file All of the Pseudo Dom Helper Objects functions for simulating parts of the DOM when running scripts in NodeJs.
|
|
3
|
-
* @author Joshua Heagle <joshuaheagle@gmail.com>
|
|
4
|
-
* @version 1.0.0
|
|
5
|
-
*/
|
|
6
|
-
import { EventService as PseudoEvent } from './services/EventService';
|
|
7
|
-
import PseudoEventTarget from './services/EventTargetService';
|
|
8
|
-
import { NodeService as PseudoNode } from './services/NodeService';
|
|
9
|
-
import { ElementService as PseudoElement } from './services/ElementService';
|
|
10
|
-
import { HTMLElementService as PseudoHTMLElement } from './services/HTMLElementService';
|
|
11
|
-
import PseudoHTMLDocument from './classes/PseudoHTMLDocument';
|
|
12
|
-
import generateDocument from './factories/generateDocument';
|
|
13
|
-
import installGlobal from './factories/installGlobal';
|
|
14
|
-
import logElement from './factories/logElement';
|
|
15
|
-
import { prettyPrint } from './factories/serializeHTML';
|
|
16
|
-
import createEvent from './factories/createEvent';
|
|
17
|
-
import eventDefaults from './factories/eventDefaults';
|
|
18
|
-
import { UIEventService as PseudoUIEvent } from './services/UIEventService';
|
|
19
|
-
import { MouseEventService as PseudoMouseEvent } from './services/MouseEventService';
|
|
20
|
-
import { PointerEventService as PseudoPointerEvent } from './services/PointerEventService';
|
|
21
|
-
import { KeyboardEventService as PseudoKeyboardEvent } from './services/KeyboardEventService';
|
|
22
|
-
import { FocusEventService as PseudoFocusEvent } from './services/FocusEventService';
|
|
23
|
-
import { InputEventService as PseudoInputEvent } from './services/InputEventService';
|
|
24
|
-
import { CustomEventService as PseudoCustomEvent } from './services/CustomEventService';
|
|
25
|
-
import simulate from './simulate';
|
|
26
|
-
import { TextService as PseudoText, CommentService as PseudoComment } from './services/NodeService';
|
|
27
|
-
/**
|
|
28
|
-
* All methods exported from this module are encapsulated within pseudoDom.
|
|
29
|
-
* @author Joshua Heagle <joshuaheagle@gmail.com>
|
|
30
|
-
* @typedef {Object} pseudoDom
|
|
31
|
-
* @module pseudoDom/objects
|
|
32
|
-
*/
|
|
33
|
-
declare const pseudoDom: {
|
|
34
|
-
generateDocument: (root: Window | any, context?: object) => Window | PseudoEventTarget;
|
|
35
|
-
installGlobal: (target?: any) => any;
|
|
36
|
-
logElement: (node: any, label?: string) => void;
|
|
37
|
-
prettyPrint: (node: any, indent?: string) => string;
|
|
38
|
-
createEvent: (type: string, init?: {
|
|
39
|
-
[option: string]: any;
|
|
40
|
-
}, { browser, trusted }?: import("./factories/createEvent").CreateEventOptions) => PseudoEvent;
|
|
41
|
-
eventDefaults: {
|
|
42
|
-
[type: string]: import("./factories/eventDefaults").EventDefinition;
|
|
43
|
-
};
|
|
44
|
-
simulate: {
|
|
45
|
-
click: (element: any, init?: {
|
|
46
|
-
[option: string]: any;
|
|
47
|
-
}) => boolean;
|
|
48
|
-
keyPress: (element: any, key: string, init?: {
|
|
49
|
-
[option: string]: any;
|
|
50
|
-
}) => boolean;
|
|
51
|
-
};
|
|
52
|
-
PseudoEvent: typeof PseudoEvent;
|
|
53
|
-
PseudoUIEvent: typeof PseudoUIEvent;
|
|
54
|
-
PseudoMouseEvent: typeof PseudoMouseEvent;
|
|
55
|
-
PseudoPointerEvent: typeof PseudoPointerEvent;
|
|
56
|
-
PseudoKeyboardEvent: typeof PseudoKeyboardEvent;
|
|
57
|
-
PseudoFocusEvent: typeof PseudoFocusEvent;
|
|
58
|
-
PseudoInputEvent: typeof PseudoInputEvent;
|
|
59
|
-
PseudoCustomEvent: typeof PseudoCustomEvent;
|
|
60
|
-
PseudoEventTarget: typeof PseudoEventTarget;
|
|
61
|
-
PseudoNode: typeof PseudoNode;
|
|
62
|
-
PseudoText: typeof PseudoText;
|
|
63
|
-
PseudoComment: typeof PseudoComment;
|
|
64
|
-
PseudoElement: typeof PseudoElement;
|
|
65
|
-
PseudoHTMLElement: typeof PseudoHTMLElement;
|
|
66
|
-
PseudoHTMLDocument: typeof PseudoHTMLDocument;
|
|
67
|
-
};
|
|
68
|
-
export { generateDocument, installGlobal, logElement, prettyPrint, createEvent, eventDefaults, simulate, PseudoEvent, PseudoUIEvent, PseudoMouseEvent, PseudoPointerEvent, PseudoKeyboardEvent, PseudoFocusEvent, PseudoInputEvent, PseudoCustomEvent, PseudoEventTarget, PseudoNode, PseudoText, PseudoComment, PseudoElement, PseudoHTMLElement, PseudoHTMLDocument };
|
|
69
|
-
export default pseudoDom;
|
|
1
|
+
/**
|
|
2
|
+
* @file All of the Pseudo Dom Helper Objects functions for simulating parts of the DOM when running scripts in NodeJs.
|
|
3
|
+
* @author Joshua Heagle <joshuaheagle@gmail.com>
|
|
4
|
+
* @version 1.0.0
|
|
5
|
+
*/
|
|
6
|
+
import { EventService as PseudoEvent } from './services/EventService';
|
|
7
|
+
import PseudoEventTarget from './services/EventTargetService';
|
|
8
|
+
import { NodeService as PseudoNode } from './services/NodeService';
|
|
9
|
+
import { ElementService as PseudoElement } from './services/ElementService';
|
|
10
|
+
import { HTMLElementService as PseudoHTMLElement } from './services/HTMLElementService';
|
|
11
|
+
import PseudoHTMLDocument from './classes/PseudoHTMLDocument';
|
|
12
|
+
import generateDocument from './factories/generateDocument';
|
|
13
|
+
import installGlobal from './factories/installGlobal';
|
|
14
|
+
import logElement from './factories/logElement';
|
|
15
|
+
import { prettyPrint } from './factories/serializeHTML';
|
|
16
|
+
import createEvent from './factories/createEvent';
|
|
17
|
+
import eventDefaults from './factories/eventDefaults';
|
|
18
|
+
import { UIEventService as PseudoUIEvent } from './services/UIEventService';
|
|
19
|
+
import { MouseEventService as PseudoMouseEvent } from './services/MouseEventService';
|
|
20
|
+
import { PointerEventService as PseudoPointerEvent } from './services/PointerEventService';
|
|
21
|
+
import { KeyboardEventService as PseudoKeyboardEvent } from './services/KeyboardEventService';
|
|
22
|
+
import { FocusEventService as PseudoFocusEvent } from './services/FocusEventService';
|
|
23
|
+
import { InputEventService as PseudoInputEvent } from './services/InputEventService';
|
|
24
|
+
import { CustomEventService as PseudoCustomEvent } from './services/CustomEventService';
|
|
25
|
+
import simulate from './simulate';
|
|
26
|
+
import { TextService as PseudoText, CommentService as PseudoComment } from './services/NodeService';
|
|
27
|
+
/**
|
|
28
|
+
* All methods exported from this module are encapsulated within pseudoDom.
|
|
29
|
+
* @author Joshua Heagle <joshuaheagle@gmail.com>
|
|
30
|
+
* @typedef {Object} pseudoDom
|
|
31
|
+
* @module pseudoDom/objects
|
|
32
|
+
*/
|
|
33
|
+
declare const pseudoDom: {
|
|
34
|
+
generateDocument: (root: Window | any, context?: object) => Window | PseudoEventTarget;
|
|
35
|
+
installGlobal: (target?: any) => any;
|
|
36
|
+
logElement: (node: any, label?: string) => void;
|
|
37
|
+
prettyPrint: (node: any, indent?: string) => string;
|
|
38
|
+
createEvent: (type: string, init?: {
|
|
39
|
+
[option: string]: any;
|
|
40
|
+
}, { browser, trusted }?: import("./factories/createEvent").CreateEventOptions) => PseudoEvent;
|
|
41
|
+
eventDefaults: {
|
|
42
|
+
[type: string]: import("./factories/eventDefaults").EventDefinition;
|
|
43
|
+
};
|
|
44
|
+
simulate: {
|
|
45
|
+
click: (element: any, init?: {
|
|
46
|
+
[option: string]: any;
|
|
47
|
+
}) => boolean;
|
|
48
|
+
keyPress: (element: any, key: string, init?: {
|
|
49
|
+
[option: string]: any;
|
|
50
|
+
}) => boolean;
|
|
51
|
+
};
|
|
52
|
+
PseudoEvent: typeof PseudoEvent;
|
|
53
|
+
PseudoUIEvent: typeof PseudoUIEvent;
|
|
54
|
+
PseudoMouseEvent: typeof PseudoMouseEvent;
|
|
55
|
+
PseudoPointerEvent: typeof PseudoPointerEvent;
|
|
56
|
+
PseudoKeyboardEvent: typeof PseudoKeyboardEvent;
|
|
57
|
+
PseudoFocusEvent: typeof PseudoFocusEvent;
|
|
58
|
+
PseudoInputEvent: typeof PseudoInputEvent;
|
|
59
|
+
PseudoCustomEvent: typeof PseudoCustomEvent;
|
|
60
|
+
PseudoEventTarget: typeof PseudoEventTarget;
|
|
61
|
+
PseudoNode: typeof PseudoNode;
|
|
62
|
+
PseudoText: typeof PseudoText;
|
|
63
|
+
PseudoComment: typeof PseudoComment;
|
|
64
|
+
PseudoElement: typeof PseudoElement;
|
|
65
|
+
PseudoHTMLElement: typeof PseudoHTMLElement;
|
|
66
|
+
PseudoHTMLDocument: typeof PseudoHTMLDocument;
|
|
67
|
+
};
|
|
68
|
+
export { generateDocument, installGlobal, logElement, prettyPrint, createEvent, eventDefaults, simulate, PseudoEvent, PseudoUIEvent, PseudoMouseEvent, PseudoPointerEvent, PseudoKeyboardEvent, PseudoFocusEvent, PseudoInputEvent, PseudoCustomEvent, PseudoEventTarget, PseudoNode, PseudoText, PseudoComment, PseudoElement, PseudoHTMLElement, PseudoHTMLDocument };
|
|
69
|
+
export default pseudoDom;
|