pseudo-dom 0.5.1 → 0.7.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.
Files changed (122) hide show
  1. package/README.md +1495 -119
  2. package/browser/pseudo-dom.js +3539 -482
  3. package/browser/pseudo-dom.min.js +1 -1
  4. package/dist/classes/PseudoEventListener.d.ts +96 -96
  5. package/dist/classes/PseudoEventListener.js +151 -151
  6. package/dist/classes/PseudoHTMLDocument.d.ts +67 -67
  7. package/dist/classes/PseudoHTMLDocument.js +144 -144
  8. package/dist/classes/PseudoNodeList.d.ts +34 -34
  9. package/dist/classes/PseudoNodeList.js +71 -71
  10. package/dist/classes.d.ts +20 -20
  11. package/dist/classes.js +31 -31
  12. package/dist/factories/createEvent.d.ts +28 -28
  13. package/dist/factories/createEvent.js +56 -56
  14. package/dist/factories/cssSelectAdapter.d.ts +23 -0
  15. package/dist/factories/cssSelectAdapter.js +87 -0
  16. package/dist/factories/cssSelectAdapter.min.js +1 -0
  17. package/dist/factories/eventDefaults.d.ts +31 -31
  18. package/dist/factories/eventDefaults.js +105 -105
  19. package/dist/factories/generateDocument.d.ts +11 -11
  20. package/dist/factories/generateDocument.js +65 -65
  21. package/dist/factories/generateNode.d.ts +32 -32
  22. package/dist/factories/generateNode.js +85 -85
  23. package/dist/factories/generateNodeList.d.ts +9 -9
  24. package/dist/factories/generateNodeList.js +13 -13
  25. package/dist/factories/query.d.ts +33 -0
  26. package/dist/factories/query.js +66 -0
  27. package/dist/factories/query.min.js +1 -0
  28. package/dist/factories.d.ts +11 -11
  29. package/dist/factories.js +27 -27
  30. package/dist/functions/activeElement.d.ts +14 -14
  31. package/dist/functions/activeElement.js +33 -33
  32. package/dist/functions/getParentNodes.d.ts +11 -11
  33. package/dist/functions/getParentNodes.js +22 -22
  34. package/dist/functions/getParentNodesFromAttribute.d.ts +14 -14
  35. package/dist/functions/getParentNodesFromAttribute.js +29 -29
  36. package/dist/functions/modifierState.d.ts +29 -29
  37. package/dist/functions/modifierState.js +41 -41
  38. package/dist/functions.d.ts +5 -5
  39. package/dist/functions.js +23 -23
  40. package/dist/interfaces/PseudoAnimation.d.ts +3 -3
  41. package/dist/interfaces/PseudoAnimation.js +5 -5
  42. package/dist/interfaces/PseudoAttr.d.ts +11 -11
  43. package/dist/interfaces/PseudoAttr.js +5 -5
  44. package/dist/interfaces/PseudoDOMTokenList.d.ts +16 -16
  45. package/dist/interfaces/PseudoDOMTokenList.js +5 -5
  46. package/dist/interfaces/PseudoDocument.d.ts +7 -0
  47. package/dist/interfaces/PseudoDocument.js +5 -5
  48. package/dist/interfaces/PseudoDocumentFragment.d.ts +3 -3
  49. package/dist/interfaces/PseudoDocumentFragment.js +5 -5
  50. package/dist/interfaces/PseudoElement.d.ts +48 -24
  51. package/dist/interfaces/PseudoElement.js +5 -5
  52. package/dist/interfaces/PseudoEvent.d.ts +79 -79
  53. package/dist/interfaces/PseudoEvent.js +10 -10
  54. package/dist/interfaces/PseudoEventTarget.d.ts +46 -46
  55. package/dist/interfaces/PseudoEventTarget.js +5 -5
  56. package/dist/interfaces/PseudoHTMLCollection.d.ts +23 -2
  57. package/dist/interfaces/PseudoHTMLCollection.js +5 -5
  58. package/dist/interfaces/PseudoHTMLElement.d.ts +22 -22
  59. package/dist/interfaces/PseudoHTMLElement.js +5 -5
  60. package/dist/interfaces/PseudoHTMLSlotElement.d.ts +3 -3
  61. package/dist/interfaces/PseudoHTMLSlotElement.js +5 -5
  62. package/dist/interfaces/PseudoNamedNodeMap.d.ts +11 -11
  63. package/dist/interfaces/PseudoNamedNodeMap.js +5 -5
  64. package/dist/interfaces/PseudoNode.d.ts +179 -179
  65. package/dist/interfaces/PseudoNode.js +5 -5
  66. package/dist/interfaces/PseudoShadowRoot.d.ts +3 -3
  67. package/dist/interfaces/PseudoShadowRoot.js +5 -5
  68. package/dist/main.d.ts +63 -63
  69. package/dist/main.js +155 -155
  70. package/dist/services/AnimationService.d.ts +4 -4
  71. package/dist/services/AnimationService.js +16 -16
  72. package/dist/services/AttrService.d.ts +37 -37
  73. package/dist/services/AttrService.js +81 -81
  74. package/dist/services/CommentService.d.ts +1 -1
  75. package/dist/services/CommentService.js +13 -13
  76. package/dist/services/CustomEventService.d.ts +37 -37
  77. package/dist/services/CustomEventService.js +35 -35
  78. package/dist/services/DOMTokenListService.d.ts +33 -33
  79. package/dist/services/DOMTokenListService.js +117 -117
  80. package/dist/services/DocumentFragmentService.d.ts +13 -13
  81. package/dist/services/DocumentFragmentService.js +24 -24
  82. package/dist/services/DocumentService.d.ts +7 -0
  83. package/dist/services/DocumentService.js +23 -0
  84. package/dist/services/DocumentService.min.js +1 -1
  85. package/dist/services/ElementService.d.ts +77 -1
  86. package/dist/services/ElementService.js +143 -0
  87. package/dist/services/ElementService.min.js +1 -1
  88. package/dist/services/EventService.d.ts +120 -120
  89. package/dist/services/EventService.js +250 -250
  90. package/dist/services/EventTargetService.d.ts +84 -84
  91. package/dist/services/EventTargetService.js +232 -232
  92. package/dist/services/FocusEventService.d.ts +32 -32
  93. package/dist/services/FocusEventService.js +35 -35
  94. package/dist/services/HTMLCollectionService.d.ts +51 -0
  95. package/dist/services/HTMLCollectionService.js +85 -1
  96. package/dist/services/HTMLCollectionService.min.js +1 -1
  97. package/dist/services/HTMLElementService.d.ts +57 -57
  98. package/dist/services/HTMLElementService.js +163 -163
  99. package/dist/services/HTMLSlotElementService.d.ts +4 -4
  100. package/dist/services/HTMLSlotElementService.js +9 -9
  101. package/dist/services/InputEventService.d.ts +41 -41
  102. package/dist/services/InputEventService.js +47 -47
  103. package/dist/services/KeyboardEventService.d.ts +70 -70
  104. package/dist/services/KeyboardEventService.js +86 -86
  105. package/dist/services/MouseEventService.d.ts +80 -80
  106. package/dist/services/MouseEventService.js +108 -108
  107. package/dist/services/NamedNodeMapService.d.ts +23 -23
  108. package/dist/services/NamedNodeMapService.js +77 -77
  109. package/dist/services/NodeService.d.ts +75 -1
  110. package/dist/services/NodeService.js +145 -7
  111. package/dist/services/NodeService.min.js +1 -1
  112. package/dist/services/PointerEventService.d.ts +51 -51
  113. package/dist/services/PointerEventService.js +67 -67
  114. package/dist/services/ShadowRootService.d.ts +4 -4
  115. package/dist/services/ShadowRootService.js +9 -9
  116. package/dist/services/TextService.d.ts +1 -1
  117. package/dist/services/TextService.js +13 -13
  118. package/dist/services/UIEventService.d.ts +43 -43
  119. package/dist/services/UIEventService.js +42 -42
  120. package/dist/simulate.d.ts +32 -32
  121. package/dist/simulate.js +115 -115
  122. package/package.json +3 -2
@@ -1,37 +1,37 @@
1
- /**
2
- * @file Substitute for the DOM CustomEvent Class.
3
- * @author Joshua Heagle <joshuaheagle@gmail.com>
4
- * @version 1.0.0
5
- */
6
- import { EventService } from './EventService';
7
- /**
8
- * The options for creating a custom event.
9
- * @typedef {Object} CustomEventInit
10
- * @property {boolean} [bubbles=false]
11
- * @property {boolean} [cancelable=false]
12
- * @property {boolean} [composed=false]
13
- * @property {*} [detail=null] Whatever data the event should carry
14
- */
15
- export type CustomEventInit = {
16
- bubbles?: boolean;
17
- cancelable?: boolean;
18
- composed?: boolean;
19
- detail?: any;
20
- };
21
- /**
22
- * Simulate the behaviour of the CustomEvent Class when there is no DOM available: an event which carries data.
23
- * @author Joshua Heagle <joshuaheagle@gmail.com>
24
- * @class
25
- * @augments EventService
26
- * @property {*} detail
27
- */
28
- export declare class CustomEventService extends EventService {
29
- private readonly eventDetail;
30
- /**
31
- * @param {string} [typeArg=''] The type of the event
32
- * @param {CustomEventInit} [init={}] The options for the event
33
- * @constructor
34
- */
35
- constructor(typeArg?: string, init?: CustomEventInit);
36
- get detail(): any;
37
- }
1
+ /**
2
+ * @file Substitute for the DOM CustomEvent Class.
3
+ * @author Joshua Heagle <joshuaheagle@gmail.com>
4
+ * @version 1.0.0
5
+ */
6
+ import { EventService } from './EventService';
7
+ /**
8
+ * The options for creating a custom event.
9
+ * @typedef {Object} CustomEventInit
10
+ * @property {boolean} [bubbles=false]
11
+ * @property {boolean} [cancelable=false]
12
+ * @property {boolean} [composed=false]
13
+ * @property {*} [detail=null] Whatever data the event should carry
14
+ */
15
+ export type CustomEventInit = {
16
+ bubbles?: boolean;
17
+ cancelable?: boolean;
18
+ composed?: boolean;
19
+ detail?: any;
20
+ };
21
+ /**
22
+ * Simulate the behaviour of the CustomEvent Class when there is no DOM available: an event which carries data.
23
+ * @author Joshua Heagle <joshuaheagle@gmail.com>
24
+ * @class
25
+ * @augments EventService
26
+ * @property {*} detail
27
+ */
28
+ export declare class CustomEventService extends EventService {
29
+ private readonly eventDetail;
30
+ /**
31
+ * @param {string} [typeArg=''] The type of the event
32
+ * @param {CustomEventInit} [init={}] The options for the event
33
+ * @constructor
34
+ */
35
+ constructor(typeArg?: string, init?: CustomEventInit);
36
+ get detail(): any;
37
+ }
@@ -1,35 +1,35 @@
1
- 'use strict'
2
-
3
- Object.defineProperty(exports, '__esModule', {
4
- value: true
5
- })
6
- exports.CustomEventService = void 0
7
- /**
8
- * @file Substitute for the DOM CustomEvent Class.
9
- * @author Joshua Heagle <joshuaheagle@gmail.com>
10
- * @version 1.0.0
11
- */
12
- const EventService_1 = require('./EventService')
13
- /**
14
- * Simulate the behaviour of the CustomEvent Class when there is no DOM available: an event which carries data.
15
- * @author Joshua Heagle <joshuaheagle@gmail.com>
16
- * @class
17
- * @augments EventService
18
- * @property {*} detail
19
- */
20
- class CustomEventService extends EventService_1.EventService {
21
- /**
22
- * @param {string} [typeArg=''] The type of the event
23
- * @param {CustomEventInit} [init={}] The options for the event
24
- * @constructor
25
- */
26
- constructor (typeArg = '', init = {}) {
27
- super(typeArg, init)
28
- this.eventDetail = typeof init.detail === 'undefined' ? null : init.detail
29
- }
30
-
31
- get detail () {
32
- return this.eventDetail
33
- }
34
- }
35
- exports.CustomEventService = CustomEventService
1
+ 'use strict'
2
+
3
+ Object.defineProperty(exports, '__esModule', {
4
+ value: true
5
+ })
6
+ exports.CustomEventService = void 0
7
+ /**
8
+ * @file Substitute for the DOM CustomEvent Class.
9
+ * @author Joshua Heagle <joshuaheagle@gmail.com>
10
+ * @version 1.0.0
11
+ */
12
+ const EventService_1 = require('./EventService')
13
+ /**
14
+ * Simulate the behaviour of the CustomEvent Class when there is no DOM available: an event which carries data.
15
+ * @author Joshua Heagle <joshuaheagle@gmail.com>
16
+ * @class
17
+ * @augments EventService
18
+ * @property {*} detail
19
+ */
20
+ class CustomEventService extends EventService_1.EventService {
21
+ /**
22
+ * @param {string} [typeArg=''] The type of the event
23
+ * @param {CustomEventInit} [init={}] The options for the event
24
+ * @constructor
25
+ */
26
+ constructor (typeArg = '', init = {}) {
27
+ super(typeArg, init)
28
+ this.eventDetail = typeof init.detail === 'undefined' ? null : init.detail
29
+ }
30
+
31
+ get detail () {
32
+ return this.eventDetail
33
+ }
34
+ }
35
+ exports.CustomEventService = CustomEventService
@@ -1,33 +1,33 @@
1
- import { PseudoDOMTokenList } from '../interfaces/PseudoDOMTokenList';
2
- /**
3
- * Simulate the behaviour of the DOMTokenList Class when there is no DOM available.
4
- * @author Joshua Heagle <joshuaheagle@gmail.com>
5
- * @class
6
- */
7
- export declare class DOMTokenListService implements PseudoDOMTokenList {
8
- private tokens;
9
- private readonly onChange;
10
- /**
11
- * @param {string} [value=''] The space separated tokens to start with
12
- * @param {function(string): void} [onChange] Called with the new value whenever the tokens change
13
- * @constructor
14
- */
15
- constructor(value?: string, onChange?: (value: string) => void);
16
- private static parse;
17
- private update;
18
- private static validate;
19
- get length(): number;
20
- get value(): string;
21
- set value(value: string);
22
- item(index: number): string | null;
23
- contains(token: string): boolean;
24
- add(...tokens: string[]): void;
25
- remove(...tokens: string[]): void;
26
- replace(oldToken: string, newToken: string): boolean;
27
- supports(token: string): boolean;
28
- toggle(token: string, force?: boolean): boolean;
29
- entries(): Iterator<[number, string]>;
30
- forEach(callback: Function, thisArg?: any): void;
31
- keys(): Iterator<number>;
32
- values(): Iterator<string>;
33
- }
1
+ import { PseudoDOMTokenList } from '../interfaces/PseudoDOMTokenList';
2
+ /**
3
+ * Simulate the behaviour of the DOMTokenList Class when there is no DOM available.
4
+ * @author Joshua Heagle <joshuaheagle@gmail.com>
5
+ * @class
6
+ */
7
+ export declare class DOMTokenListService implements PseudoDOMTokenList {
8
+ private tokens;
9
+ private readonly onChange;
10
+ /**
11
+ * @param {string} [value=''] The space separated tokens to start with
12
+ * @param {function(string): void} [onChange] Called with the new value whenever the tokens change
13
+ * @constructor
14
+ */
15
+ constructor(value?: string, onChange?: (value: string) => void);
16
+ private static parse;
17
+ private update;
18
+ private static validate;
19
+ get length(): number;
20
+ get value(): string;
21
+ set value(value: string);
22
+ item(index: number): string | null;
23
+ contains(token: string): boolean;
24
+ add(...tokens: string[]): void;
25
+ remove(...tokens: string[]): void;
26
+ replace(oldToken: string, newToken: string): boolean;
27
+ supports(token: string): boolean;
28
+ toggle(token: string, force?: boolean): boolean;
29
+ entries(): Iterator<[number, string]>;
30
+ forEach(callback: Function, thisArg?: any): void;
31
+ keys(): Iterator<number>;
32
+ values(): Iterator<string>;
33
+ }
@@ -1,117 +1,117 @@
1
- 'use strict'
2
-
3
- require('core-js/modules/esnext.iterator.constructor.js')
4
- require('core-js/modules/esnext.iterator.filter.js')
5
- require('core-js/modules/esnext.iterator.for-each.js')
6
- require('core-js/modules/esnext.iterator.map.js')
7
- Object.defineProperty(exports, '__esModule', {
8
- value: true
9
- })
10
- exports.DOMTokenListService = void 0
11
- /**
12
- * Simulate the behaviour of the DOMTokenList Class when there is no DOM available.
13
- * @author Joshua Heagle <joshuaheagle@gmail.com>
14
- * @class
15
- */
16
- class DOMTokenListService {
17
- /**
18
- * @param {string} [value=''] The space separated tokens to start with
19
- * @param {function(string): void} [onChange] Called with the new value whenever the tokens change
20
- * @constructor
21
- */
22
- constructor (value = '', onChange = () => undefined) {
23
- this.tokens = DOMTokenListService.parse(value)
24
- this.onChange = onChange
25
- }
26
-
27
- static parse (value) {
28
- return (value || '').split(/\s+/).filter((token, index, tokens) => token !== '' && tokens.indexOf(token) === index)
29
- }
30
-
31
- update (tokens) {
32
- this.tokens = tokens
33
- this.onChange(this.value)
34
- }
35
-
36
- static validate (token) {
37
- if (token === '') {
38
- throw new SyntaxError('The token provided must not be empty.')
39
- }
40
- if (/\s/.test(token)) {
41
- throw new Error('The token provided contains whitespace.')
42
- }
43
- }
44
-
45
- get length () {
46
- return this.tokens.length
47
- }
48
-
49
- get value () {
50
- return this.tokens.join(' ')
51
- }
52
-
53
- set value (value) {
54
- this.update(DOMTokenListService.parse(value))
55
- }
56
-
57
- item (index) {
58
- return index >= 0 && index < this.tokens.length ? this.tokens[index] : null
59
- }
60
-
61
- contains (token) {
62
- return this.tokens.indexOf(token) >= 0
63
- }
64
-
65
- add (...tokens) {
66
- tokens.forEach(DOMTokenListService.validate)
67
- this.update(this.tokens.concat(tokens).filter((token, index, all) => all.indexOf(token) === index))
68
- }
69
-
70
- remove (...tokens) {
71
- tokens.forEach(DOMTokenListService.validate)
72
- this.update(this.tokens.filter(token => tokens.indexOf(token) < 0))
73
- }
74
-
75
- replace (oldToken, newToken) {
76
- DOMTokenListService.validate(oldToken)
77
- DOMTokenListService.validate(newToken)
78
- if (!this.contains(oldToken)) {
79
- return false
80
- }
81
- this.update(this.tokens.map(token => token === oldToken ? newToken : token).filter((token, index, all) => all.indexOf(token) === index))
82
- return true
83
- }
84
-
85
- supports (token) {
86
- // There is no list of supported tokens for arbitrary attributes, so like the DOM (for those) this is unsupported
87
- throw new TypeError(`Failed to execute 'supports' on 'DOMTokenList': DOMTokenList has no supported tokens (${token}).`)
88
- }
89
-
90
- toggle (token, force) {
91
- DOMTokenListService.validate(token)
92
- const shouldHave = typeof force === 'boolean' ? force : !this.contains(token)
93
- if (shouldHave) {
94
- this.add(token)
95
- } else {
96
- this.remove(token)
97
- }
98
- return shouldHave
99
- }
100
-
101
- entries () {
102
- return this.tokens.map((token, index) => [index, token])[Symbol.iterator]()
103
- }
104
-
105
- forEach (callback, thisArg) {
106
- this.tokens.forEach((token, index) => callback.call(thisArg, token, index, this))
107
- }
108
-
109
- keys () {
110
- return this.tokens.map((token, index) => index)[Symbol.iterator]()
111
- }
112
-
113
- values () {
114
- return this.tokens.slice()[Symbol.iterator]()
115
- }
116
- }
117
- exports.DOMTokenListService = DOMTokenListService
1
+ 'use strict'
2
+
3
+ require('core-js/modules/esnext.iterator.constructor.js')
4
+ require('core-js/modules/esnext.iterator.filter.js')
5
+ require('core-js/modules/esnext.iterator.for-each.js')
6
+ require('core-js/modules/esnext.iterator.map.js')
7
+ Object.defineProperty(exports, '__esModule', {
8
+ value: true
9
+ })
10
+ exports.DOMTokenListService = void 0
11
+ /**
12
+ * Simulate the behaviour of the DOMTokenList Class when there is no DOM available.
13
+ * @author Joshua Heagle <joshuaheagle@gmail.com>
14
+ * @class
15
+ */
16
+ class DOMTokenListService {
17
+ /**
18
+ * @param {string} [value=''] The space separated tokens to start with
19
+ * @param {function(string): void} [onChange] Called with the new value whenever the tokens change
20
+ * @constructor
21
+ */
22
+ constructor (value = '', onChange = () => undefined) {
23
+ this.tokens = DOMTokenListService.parse(value)
24
+ this.onChange = onChange
25
+ }
26
+
27
+ static parse (value) {
28
+ return (value || '').split(/\s+/).filter((token, index, tokens) => token !== '' && tokens.indexOf(token) === index)
29
+ }
30
+
31
+ update (tokens) {
32
+ this.tokens = tokens
33
+ this.onChange(this.value)
34
+ }
35
+
36
+ static validate (token) {
37
+ if (token === '') {
38
+ throw new SyntaxError('The token provided must not be empty.')
39
+ }
40
+ if (/\s/.test(token)) {
41
+ throw new Error('The token provided contains whitespace.')
42
+ }
43
+ }
44
+
45
+ get length () {
46
+ return this.tokens.length
47
+ }
48
+
49
+ get value () {
50
+ return this.tokens.join(' ')
51
+ }
52
+
53
+ set value (value) {
54
+ this.update(DOMTokenListService.parse(value))
55
+ }
56
+
57
+ item (index) {
58
+ return index >= 0 && index < this.tokens.length ? this.tokens[index] : null
59
+ }
60
+
61
+ contains (token) {
62
+ return this.tokens.indexOf(token) >= 0
63
+ }
64
+
65
+ add (...tokens) {
66
+ tokens.forEach(DOMTokenListService.validate)
67
+ this.update(this.tokens.concat(tokens).filter((token, index, all) => all.indexOf(token) === index))
68
+ }
69
+
70
+ remove (...tokens) {
71
+ tokens.forEach(DOMTokenListService.validate)
72
+ this.update(this.tokens.filter(token => tokens.indexOf(token) < 0))
73
+ }
74
+
75
+ replace (oldToken, newToken) {
76
+ DOMTokenListService.validate(oldToken)
77
+ DOMTokenListService.validate(newToken)
78
+ if (!this.contains(oldToken)) {
79
+ return false
80
+ }
81
+ this.update(this.tokens.map(token => token === oldToken ? newToken : token).filter((token, index, all) => all.indexOf(token) === index))
82
+ return true
83
+ }
84
+
85
+ supports (token) {
86
+ // There is no list of supported tokens for arbitrary attributes, so like the DOM (for those) this is unsupported
87
+ throw new TypeError(`Failed to execute 'supports' on 'DOMTokenList': DOMTokenList has no supported tokens (${token}).`)
88
+ }
89
+
90
+ toggle (token, force) {
91
+ DOMTokenListService.validate(token)
92
+ const shouldHave = typeof force === 'boolean' ? force : !this.contains(token)
93
+ if (shouldHave) {
94
+ this.add(token)
95
+ } else {
96
+ this.remove(token)
97
+ }
98
+ return shouldHave
99
+ }
100
+
101
+ entries () {
102
+ return this.tokens.map((token, index) => [index, token])[Symbol.iterator]()
103
+ }
104
+
105
+ forEach (callback, thisArg) {
106
+ this.tokens.forEach((token, index) => callback.call(thisArg, token, index, this))
107
+ }
108
+
109
+ keys () {
110
+ return this.tokens.map((token, index) => index)[Symbol.iterator]()
111
+ }
112
+
113
+ values () {
114
+ return this.tokens.slice()[Symbol.iterator]()
115
+ }
116
+ }
117
+ exports.DOMTokenListService = DOMTokenListService
@@ -1,13 +1,13 @@
1
- import { NodeService } from './NodeService';
2
- import { PseudoDocumentFragment } from '../interfaces/PseudoDocumentFragment';
3
- /**
4
- * Simulate the behaviour of the DocumentFragment Class when there is no DOM available: a container for nodes which is
5
- * not part of a tree, when it is inserted its children are moved into the tree instead.
6
- * @author Joshua Heagle <joshuaheagle@gmail.com>
7
- * @class
8
- * @augments NodeService
9
- */
10
- export declare class DocumentFragmentService extends NodeService implements PseudoDocumentFragment {
11
- get nodeName(): string;
12
- get nodeType(): number;
13
- }
1
+ import { NodeService } from './NodeService';
2
+ import { PseudoDocumentFragment } from '../interfaces/PseudoDocumentFragment';
3
+ /**
4
+ * Simulate the behaviour of the DocumentFragment Class when there is no DOM available: a container for nodes which is
5
+ * not part of a tree, when it is inserted its children are moved into the tree instead.
6
+ * @author Joshua Heagle <joshuaheagle@gmail.com>
7
+ * @class
8
+ * @augments NodeService
9
+ */
10
+ export declare class DocumentFragmentService extends NodeService implements PseudoDocumentFragment {
11
+ get nodeName(): string;
12
+ get nodeType(): number;
13
+ }
@@ -1,24 +1,24 @@
1
- 'use strict'
2
-
3
- Object.defineProperty(exports, '__esModule', {
4
- value: true
5
- })
6
- exports.DocumentFragmentService = void 0
7
- const NodeService_1 = require('./NodeService')
8
- /**
9
- * Simulate the behaviour of the DocumentFragment Class when there is no DOM available: a container for nodes which is
10
- * not part of a tree, when it is inserted its children are moved into the tree instead.
11
- * @author Joshua Heagle <joshuaheagle@gmail.com>
12
- * @class
13
- * @augments NodeService
14
- */
15
- class DocumentFragmentService extends NodeService_1.NodeService {
16
- get nodeName () {
17
- return '#document-fragment'
18
- }
19
-
20
- get nodeType () {
21
- return NodeService_1.NodeService.DOCUMENT_FRAGMENT_NODE
22
- }
23
- }
24
- exports.DocumentFragmentService = DocumentFragmentService
1
+ 'use strict'
2
+
3
+ Object.defineProperty(exports, '__esModule', {
4
+ value: true
5
+ })
6
+ exports.DocumentFragmentService = void 0
7
+ const NodeService_1 = require('./NodeService')
8
+ /**
9
+ * Simulate the behaviour of the DocumentFragment Class when there is no DOM available: a container for nodes which is
10
+ * not part of a tree, when it is inserted its children are moved into the tree instead.
11
+ * @author Joshua Heagle <joshuaheagle@gmail.com>
12
+ * @class
13
+ * @augments NodeService
14
+ */
15
+ class DocumentFragmentService extends NodeService_1.NodeService {
16
+ get nodeName () {
17
+ return '#document-fragment'
18
+ }
19
+
20
+ get nodeType () {
21
+ return NodeService_1.NodeService.DOCUMENT_FRAGMENT_NODE
22
+ }
23
+ }
24
+ exports.DocumentFragmentService = DocumentFragmentService
@@ -1,5 +1,6 @@
1
1
  import { NodeService } from './NodeService';
2
2
  import { PseudoDocument } from '../interfaces/PseudoDocument';
3
+ import { PseudoElement } from '../interfaces/PseudoElement';
3
4
  /**
4
5
  * Simulate the behaviour of the Document Class when there is no DOM available.
5
6
  * @author Joshua Heagle <joshuaheagle@gmail.com>
@@ -9,4 +10,10 @@ import { PseudoDocument } from '../interfaces/PseudoDocument';
9
10
  export declare class DocumentService extends NodeService implements PseudoDocument {
10
11
  get nodeName(): string;
11
12
  get nodeType(): number;
13
+ /**
14
+ * The first element, in tree order, whose id matches the given value, or null when there is none.
15
+ * @param {string} id
16
+ * @returns {PseudoElement|null}
17
+ */
18
+ getElementById(id: string): PseudoElement | null;
12
19
  }
@@ -19,5 +19,28 @@ class DocumentService extends NodeService_1.NodeService {
19
19
  get nodeType () {
20
20
  return NodeService_1.NodeService.DOCUMENT_NODE
21
21
  }
22
+
23
+ /**
24
+ * The first element, in tree order, whose id matches the given value, or null when there is none.
25
+ * @param {string} id
26
+ * @returns {PseudoElement|null}
27
+ */
28
+ getElementById (id) {
29
+ const search = node => {
30
+ for (const child of Array.from(node.childNodes)) {
31
+ if (child.nodeType === NodeService_1.NodeService.ELEMENT_NODE) {
32
+ if (child.id === id) {
33
+ return child
34
+ }
35
+ const found = search(child)
36
+ if (found) {
37
+ return found
38
+ }
39
+ }
40
+ }
41
+ return null
42
+ }
43
+ return search(this)
44
+ }
22
45
  }
23
46
  exports.DocumentService = DocumentService
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.DocumentService=void 0;const NodeService_1=require("./NodeService");class DocumentService extends NodeService_1.NodeService{get nodeName(){return"#document"}get nodeType(){return NodeService_1.NodeService.DOCUMENT_NODE}}exports.DocumentService=DocumentService;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.DocumentService=void 0;const NodeService_1=require("./NodeService");class DocumentService extends NodeService_1.NodeService{get nodeName(){return"#document"}get nodeType(){return NodeService_1.NodeService.DOCUMENT_NODE}getElementById(e){const r=o=>{for(const t of Array.from(o.childNodes))if(t.nodeType===NodeService_1.NodeService.ELEMENT_NODE){if(t.id===e)return t;const o=r(t);if(o)return o}return null};return r(this)}}exports.DocumentService=DocumentService;