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.
@@ -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 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
- * @param root
22
- * @param context
23
- */
24
- const generateDocument = (root, context = {}) => {
25
- const newWindow = typeof root.document === 'undefined' ? root : new EventTargetService_1.default()
26
- /**
27
- * The Node class itself (matching the DOM's window.Node), not an instance - the right-hand side of `instanceof`
28
- * must be a constructor, so `x instanceof Node` needs this, not `new PseudoNode()`.
29
- */
30
- const Node = root.Node || NodeService_1.NodeService
31
- if (typeof newWindow.Node === 'undefined') {
32
- newWindow.Node = Node
33
- }
34
- /**
35
- * The Element class itself, for the same reason as Node.
36
- */
37
- const Element = root.Element || ElementService_1.ElementService
38
- if (typeof newWindow.Element === 'undefined') {
39
- newWindow.Element = Element
40
- }
41
- /**
42
- * The HTMLElement class itself, for the same reason as Node.
43
- */
44
- const HTMLElement = root.HTMLElement || HTMLElementService_1.HTMLElementService
45
- if (typeof newWindow.HTMLElement === 'undefined') {
46
- newWindow.HTMLElement = HTMLElement
47
- }
48
- /**
49
- * The HTMLDocument class itself, for the same reason as Node (so `document instanceof HTMLDocument`, a common
50
- * real-DOM-detection check, works).
51
- */
52
- const HTMLDocument = root.HTMLDocument || PseudoHTMLDocument_1.default
53
- if (typeof newWindow.HTMLDocument === 'undefined') {
54
- newWindow.HTMLDocument = HTMLDocument
55
- }
56
- /**
57
- * Define document when not available - a real instance, unlike the classes above (window.document IS an object,
58
- * not a constructor).
59
- */
60
- const document = root.document || new PseudoHTMLDocument_1.default()
61
- if (typeof newWindow.document === 'undefined') {
62
- newWindow.document = document
63
- }
64
- // When there was no real document, newWindow is root itself (see above), so every assignment above already
65
- // mutated it directly. If context is also that same object (root and context given as one and the same, as
66
- // installGlobal does) merging is already done - doing it again would be Object.assign(target, target), which
67
- // throws on any getter-only own property target already has (globalThis.crypto, in Node).
68
- const mergeInto = context || root
69
- return newWindow === mergeInto ? newWindow : Object.assign(mergeInto, newWindow)
70
- }
71
- exports.default = generateDocument
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 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
+ "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
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "pseudo-dom",
3
3
  "description": "Mock the DOM on the server side for managing state and testing",
4
- "version": "1.0.0",
4
+ "version": "1.0.1",
5
5
  "main": "dist/main.js",
6
6
  "types": "dist/main.d.ts",
7
7
  "unpkg": "browser/pseudo-dom.min.js",