pseudo-dom 1.0.0 → 1.0.1
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/browser/pseudo-dom.js +14902 -14887
- package/browser/pseudo-dom.min.js +1 -1
- package/dist/factories/generateDocument.js +86 -71
- package/dist/factories/generateDocument.min.js +1 -1
- package/package.json +1 -1
|
@@ -1,71 +1,86 @@
|
|
|
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
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
* @param
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
*
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
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
|
-
}
|
|
71
|
-
|
|
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 EventService_1 = require('../services/EventService')
|
|
18
|
+
const PseudoHTMLDocument_1 = __importDefault(require('../classes/PseudoHTMLDocument'))
|
|
19
|
+
/**
|
|
20
|
+
* Construct the Pseudo Dom to provide access to Dom objects which are otherwise not available outside the browser
|
|
21
|
+
* context.
|
|
22
|
+
* @param root
|
|
23
|
+
* @param context
|
|
24
|
+
*/
|
|
25
|
+
const generateDocument = (root, context = {}) => {
|
|
26
|
+
const newWindow = typeof root.document === 'undefined' ? root : new EventTargetService_1.default()
|
|
27
|
+
/**
|
|
28
|
+
* The Node class itself (matching the DOM's window.Node), not an instance - the right-hand side of `instanceof`
|
|
29
|
+
* must be a constructor, so `x instanceof Node` needs this, not `new PseudoNode()`.
|
|
30
|
+
*/
|
|
31
|
+
const Node = root.Node || NodeService_1.NodeService
|
|
32
|
+
if (typeof newWindow.Node === 'undefined') {
|
|
33
|
+
newWindow.Node = Node
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* The Element class itself, for the same reason as Node.
|
|
37
|
+
*/
|
|
38
|
+
const Element = root.Element || ElementService_1.ElementService
|
|
39
|
+
if (typeof newWindow.Element === 'undefined') {
|
|
40
|
+
newWindow.Element = Element
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* The HTMLElement class itself, for the same reason as Node.
|
|
44
|
+
*/
|
|
45
|
+
const HTMLElement = root.HTMLElement || HTMLElementService_1.HTMLElementService
|
|
46
|
+
if (typeof newWindow.HTMLElement === 'undefined') {
|
|
47
|
+
newWindow.HTMLElement = HTMLElement
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* The HTMLDocument class itself, for the same reason as Node (so `document instanceof HTMLDocument`, a common
|
|
51
|
+
* real-DOM-detection check, works).
|
|
52
|
+
*/
|
|
53
|
+
const HTMLDocument = root.HTMLDocument || PseudoHTMLDocument_1.default
|
|
54
|
+
if (typeof newWindow.HTMLDocument === 'undefined') {
|
|
55
|
+
newWindow.HTMLDocument = HTMLDocument
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* The Event class itself, so code which does `new Event(type)` then `target.dispatchEvent(...)` - the standard,
|
|
59
|
+
* environment-agnostic way to synthesize and dispatch an event - works the same as it would against a real DOM.
|
|
60
|
+
* Unlike Node/Element/HTMLElement/HTMLDocument above, this is NOT `root.Event || PseudoEvent`: Node.js itself has
|
|
61
|
+
* had a global Event/EventTarget since v15, unrelated to this module and incompatible with it (dispatchEvent
|
|
62
|
+
* below expects the inner/dispatching bookkeeping only this module's own instances carry) - so by the time this
|
|
63
|
+
* function is reached (no real document, meaning no real browser or jsdom either), any Event already on root can
|
|
64
|
+
* only be that unrelated native one, or this module's own from an earlier install (functionally identical to
|
|
65
|
+
* reinstalling it) - never a real browser's. Preferring root.Event the way the others do would keep Node's
|
|
66
|
+
* incompatible one every time, since it is never actually undefined.
|
|
67
|
+
*/
|
|
68
|
+
if (newWindow.Event !== EventService_1.EventService) {
|
|
69
|
+
newWindow.Event = EventService_1.EventService
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Define document when not available - a real instance, unlike the classes above (window.document IS an object,
|
|
73
|
+
* not a constructor).
|
|
74
|
+
*/
|
|
75
|
+
const document = root.document || new PseudoHTMLDocument_1.default()
|
|
76
|
+
if (typeof newWindow.document === 'undefined') {
|
|
77
|
+
newWindow.document = document
|
|
78
|
+
}
|
|
79
|
+
// When there was no real document, newWindow is root itself (see above), so every assignment above already
|
|
80
|
+
// mutated it directly. If context is also that same object (root and context given as one and the same, as
|
|
81
|
+
// installGlobal does) merging is already done - doing it again would be Object.assign(target, target), which
|
|
82
|
+
// throws on any getter-only own property target already has (globalThis.crypto, in Node).
|
|
83
|
+
const mergeInto = context || root
|
|
84
|
+
return newWindow === mergeInto ? newWindow : Object.assign(mergeInto, newWindow)
|
|
85
|
+
}
|
|
86
|
+
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"),EventService_1=require("../services/EventService"),PseudoHTMLDocument_1=__importDefault(require("../classes/PseudoHTMLDocument")),generateDocument=(e,t={})=>{const r=void 0===e.document?e:new EventTargetService_1.default,n=e.Node||NodeService_1.NodeService;void 0===r.Node&&(r.Node=n);const c=e.Element||ElementService_1.ElementService;void 0===r.Element&&(r.Element=c);const o=e.HTMLElement||HTMLElementService_1.HTMLElementService;void 0===r.HTMLElement&&(r.HTMLElement=o);const i=e.HTMLDocument||PseudoHTMLDocument_1.default;void 0===r.HTMLDocument&&(r.HTMLDocument=i),r.Event!==EventService_1.EventService&&(r.Event=EventService_1.EventService);const v=e.document||new PseudoHTMLDocument_1.default;void 0===r.document&&(r.document=v);const u=t||e;return r===u?r:Object.assign(u,r)};exports.default=generateDocument;
|
package/package.json
CHANGED