pseudo-dom 0.6.0 → 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 +432 -13
  2. package/browser/pseudo-dom.js +3364 -603
  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 +20 -7
  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 -23
  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 +13 -0
  86. package/dist/services/ElementService.js +20 -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 +11 -6
  95. package/dist/services/HTMLCollectionService.js +25 -8
  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 +26 -0
  110. package/dist/services/NodeService.js +42 -0
  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;
@@ -143,6 +143,19 @@ export declare class ElementService extends NodeService implements Partial<Pseud
143
143
  * @throws {Error}
144
144
  */
145
145
  insertAdjacentHTML(position: string, text: string): void;
146
+ /**
147
+ * Whether this element itself (not its descendants) matches the given CSS selector.
148
+ * @param {string} selectors A CSS selector
149
+ * @returns {boolean}
150
+ */
151
+ matches(selectors: string): boolean;
152
+ /**
153
+ * The nearest ancestor of this element (starting with this element itself) which matches the CSS selector, or
154
+ * null when none of them do.
155
+ * @param {string} selectors A CSS selector
156
+ * @returns {PseudoElement|null}
157
+ */
158
+ closest(selectors: string): PseudoElement | null;
146
159
  applyDefaultEvent(): Function;
147
160
  /**
148
161
  * An element which is added as a child gets its default events (for example a submit button submits its form).
@@ -26,6 +26,7 @@ const getParentNodesFromAttribute_1 = __importDefault(require('../functions/getP
26
26
  const HTMLCollectionService_1 = require('./HTMLCollectionService')
27
27
  const cloneObject_1 = __importDefault(require('si-funciona/dist/helpers/objects/cloneObject'))
28
28
  const isEqual_1 = __importDefault(require('si-funciona/dist/helpers/objects/isEqual'))
29
+ const query_1 = require('../factories/query')
29
30
  /**
30
31
  * Simulate the behaviour of the Element Class when there is no DOM available.
31
32
  * @author Joshua Heagle <joshuaheagle@gmail.com>
@@ -307,6 +308,25 @@ class ElementService extends NodeService_1.NodeService {
307
308
  throw new Error('ElementService.insertAdjacentHTML() is not implemented yet.')
308
309
  }
309
310
 
311
+ /**
312
+ * Whether this element itself (not its descendants) matches the given CSS selector.
313
+ * @param {string} selectors A CSS selector
314
+ * @returns {boolean}
315
+ */
316
+ matches (selectors) {
317
+ return (0, query_1.matches)(this, selectors)
318
+ }
319
+
320
+ /**
321
+ * The nearest ancestor of this element (starting with this element itself) which matches the CSS selector, or
322
+ * null when none of them do.
323
+ * @param {string} selectors A CSS selector
324
+ * @returns {PseudoElement|null}
325
+ */
326
+ closest (selectors) {
327
+ return (0, query_1.closest)(this, selectors)
328
+ }
329
+
310
330
  applyDefaultEvent () {
311
331
  let callback = event => undefined
312
332
  if (this.defaultEventApplied) {
@@ -1 +1 @@
1
- "use strict";require("core-js/modules/esnext.iterator.constructor.js"),require("core-js/modules/esnext.iterator.every.js"),require("core-js/modules/esnext.iterator.find.js"),require("core-js/modules/esnext.iterator.for-each.js"),require("core-js/modules/esnext.iterator.map.js"),require("core-js/modules/esnext.iterator.some.js");var __importDefault=function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.ElementService=void 0;const createEvent_1=__importDefault(require("../factories/createEvent")),NodeService_1=require("./NodeService"),AttrService_1=require("./AttrService"),DOMTokenListService_1=require("./DOMTokenListService"),NamedNodeMapService_1=require("./NamedNodeMapService"),getParentNodesFromAttribute_1=__importDefault(require("../functions/getParentNodesFromAttribute")),HTMLCollectionService_1=require("./HTMLCollectionService"),cloneObject_1=__importDefault(require("si-funciona/dist/helpers/objects/cloneObject")),isEqual_1=__importDefault(require("si-funciona/dist/helpers/objects/isEqual"));class ElementService extends NodeService_1.NodeService{constructor({tagName:e="",attributes:t=[],parent:r=null,children:i=[]}={}){super(),this.defaultEventApplied=!1,this.tokenList=new DOMTokenListService_1.DOMTokenListService,this.tag=e,this.attributeList=t.concat([{name:"className",value:""},{name:"id",value:""},{name:"innerHTML",value:""}]),this.propertyAttributes=this.attributeList.map(({name:e})=>e),this.attributeList.forEach(({name:e,value:t})=>{this[e]=t}),i.forEach(e=>{if(!e||"number"!=typeof e.nodeType)throw new TypeError("The children of an element must be nodes.");this.appendChild(e)}),r&&r.appendChild(this)}currentAttributes(){return this.attributeList.map(({name:e,value:t})=>({name:e,value:this.propertyAttributes.indexOf(e)>=0?this[e]:t}))}get nodeName(){return this.tag}cloneShallow(){const e=new this.constructor({tagName:this.tag});return e.attributeList.length=0,this.currentAttributes().forEach(({name:t,value:r})=>{const i="object"==typeof r&&null!==r?(0,cloneObject_1.default)(r):r;e.attributeList.push({name:t,value:i}),e.propertyAttributes.indexOf(t)>=0&&(e[t]=i)}),e.ownerDocumentStore=this.ownerDocumentStore,e}equalsShallow(e){const t=this.currentAttributes(),r=e.currentAttributes();return this.nodeName===e.nodeName&&t.length===r.length&&t.every(({name:e,value:t})=>{const i=r.find(t=>t.name===e);return void 0!==i&&(0,isEqual_1.default)(t,i.value)})}get tagName(){return this.tag}get nodeType(){return NodeService_1.NodeService.ELEMENT_NODE}get attributes(){return new NamedNodeMapService_1.NamedNodeMapService(this.currentAttributes().map(({name:e,value:t})=>new AttrService_1.AttrService(e,String(t),this)))}get classList(){return this.tokenList}get className(){return this.tokenList.value}set className(e){this.tokenList.value=e}get children(){return new HTMLCollectionService_1.HTMLCollectionService(this)}get childElementCount(){return this.children.length}get firstElementChild(){return this.children.item(0)}get lastElementChild(){const e=this.children;return e.item(e.length-1)}get nextElementSibling(){let e=this.nextSibling;for(;e&&e.nodeType!==NodeService_1.NodeService.ELEMENT_NODE;)e=e.nextSibling;return e}get previousElementSibling(){let e=this.previousSibling;for(;e&&e.nodeType!==NodeService_1.NodeService.ELEMENT_NODE;)e=e.previousSibling;return e}insertAdjacentElement(e,t){return this.insertAdjacent(e,t)}insertAdjacentText(e,t){this.insertAdjacent(e,t)}insertAdjacent(e,t){switch(e){case"beforebegin":return this.parentNode?(this.before(t),t):null;case"afterbegin":return this.prepend(t),t;case"beforeend":return this.append(t),t;case"afterend":return this.parentNode?(this.after(t),t):null;default:throw new Error(`"${e}" is not one of beforebegin, afterbegin, beforeend or afterend.`)}}insertAdjacentHTML(e,t){throw new Error("ElementService.insertAdjacentHTML() is not implemented yet.")}applyDefaultEvent(){let e=e=>{};if(this.defaultEventApplied)return e;switch(this.tagName){case"button":case"input":e=e=>{const t=String(this.getAttribute("type")||this.type||"").toLowerCase(),r="button"===this.tagName?"button"!==t&&"reset"!==t:/^(submit|image)$/.test(t),i=(0,getParentNodesFromAttribute_1.default)("tagName","form",this);r&&i.length&&!this.hasAttribute("disabled")&&i[i.length-1].dispatchEvent((0,createEvent_1.default)("submit",{},{browser:!0,trusted:e.isTrusted}))},super.setDefaultEvent("click",e),this.defaultEventApplied=!0}return e}childInserted(e){"function"==typeof e.applyDefaultEvent&&e.applyDefaultEvent()}hasAttribute(e){return this.attributeList.some(({name:t})=>t===e)}setAttribute(e,t){const r=this.attributeList.find(({name:t})=>t===e);r?r.value=t:this.attributeList.push({name:e,value:t}),this.propertyAttributes.indexOf(e)>=0&&(this[e]=t)}getAttribute(e){const t=this.currentAttributes().find(({name:t})=>t===e);return t?t.value:null}removeAttribute(e){const t=this.attributeList.findIndex(({name:t})=>t===e);t>=0&&this.attributeList.splice(t,1)}}exports.ElementService=ElementService;
1
+ "use strict";require("core-js/modules/esnext.iterator.constructor.js"),require("core-js/modules/esnext.iterator.every.js"),require("core-js/modules/esnext.iterator.find.js"),require("core-js/modules/esnext.iterator.for-each.js"),require("core-js/modules/esnext.iterator.map.js"),require("core-js/modules/esnext.iterator.some.js");var __importDefault=function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.ElementService=void 0;const createEvent_1=__importDefault(require("../factories/createEvent")),NodeService_1=require("./NodeService"),AttrService_1=require("./AttrService"),DOMTokenListService_1=require("./DOMTokenListService"),NamedNodeMapService_1=require("./NamedNodeMapService"),getParentNodesFromAttribute_1=__importDefault(require("../functions/getParentNodesFromAttribute")),HTMLCollectionService_1=require("./HTMLCollectionService"),cloneObject_1=__importDefault(require("si-funciona/dist/helpers/objects/cloneObject")),isEqual_1=__importDefault(require("si-funciona/dist/helpers/objects/isEqual")),query_1=require("../factories/query");class ElementService extends NodeService_1.NodeService{constructor({tagName:e="",attributes:t=[],parent:r=null,children:i=[]}={}){super(),this.defaultEventApplied=!1,this.tokenList=new DOMTokenListService_1.DOMTokenListService,this.tag=e,this.attributeList=t.concat([{name:"className",value:""},{name:"id",value:""},{name:"innerHTML",value:""}]),this.propertyAttributes=this.attributeList.map(({name:e})=>e),this.attributeList.forEach(({name:e,value:t})=>{this[e]=t}),i.forEach(e=>{if(!e||"number"!=typeof e.nodeType)throw new TypeError("The children of an element must be nodes.");this.appendChild(e)}),r&&r.appendChild(this)}currentAttributes(){return this.attributeList.map(({name:e,value:t})=>({name:e,value:this.propertyAttributes.indexOf(e)>=0?this[e]:t}))}get nodeName(){return this.tag}cloneShallow(){const e=new this.constructor({tagName:this.tag});return e.attributeList.length=0,this.currentAttributes().forEach(({name:t,value:r})=>{const i="object"==typeof r&&null!==r?(0,cloneObject_1.default)(r):r;e.attributeList.push({name:t,value:i}),e.propertyAttributes.indexOf(t)>=0&&(e[t]=i)}),e.ownerDocumentStore=this.ownerDocumentStore,e}equalsShallow(e){const t=this.currentAttributes(),r=e.currentAttributes();return this.nodeName===e.nodeName&&t.length===r.length&&t.every(({name:e,value:t})=>{const i=r.find(t=>t.name===e);return void 0!==i&&(0,isEqual_1.default)(t,i.value)})}get tagName(){return this.tag}get nodeType(){return NodeService_1.NodeService.ELEMENT_NODE}get attributes(){return new NamedNodeMapService_1.NamedNodeMapService(this.currentAttributes().map(({name:e,value:t})=>new AttrService_1.AttrService(e,String(t),this)))}get classList(){return this.tokenList}get className(){return this.tokenList.value}set className(e){this.tokenList.value=e}get children(){return new HTMLCollectionService_1.HTMLCollectionService(this)}get childElementCount(){return this.children.length}get firstElementChild(){return this.children.item(0)}get lastElementChild(){const e=this.children;return e.item(e.length-1)}get nextElementSibling(){let e=this.nextSibling;for(;e&&e.nodeType!==NodeService_1.NodeService.ELEMENT_NODE;)e=e.nextSibling;return e}get previousElementSibling(){let e=this.previousSibling;for(;e&&e.nodeType!==NodeService_1.NodeService.ELEMENT_NODE;)e=e.previousSibling;return e}insertAdjacentElement(e,t){return this.insertAdjacent(e,t)}insertAdjacentText(e,t){this.insertAdjacent(e,t)}insertAdjacent(e,t){switch(e){case"beforebegin":return this.parentNode?(this.before(t),t):null;case"afterbegin":return this.prepend(t),t;case"beforeend":return this.append(t),t;case"afterend":return this.parentNode?(this.after(t),t):null;default:throw new Error(`"${e}" is not one of beforebegin, afterbegin, beforeend or afterend.`)}}insertAdjacentHTML(e,t){throw new Error("ElementService.insertAdjacentHTML() is not implemented yet.")}matches(e){return(0,query_1.matches)(this,e)}closest(e){return(0,query_1.closest)(this,e)}applyDefaultEvent(){let e=e=>{};if(this.defaultEventApplied)return e;switch(this.tagName){case"button":case"input":e=e=>{const t=String(this.getAttribute("type")||this.type||"").toLowerCase(),r="button"===this.tagName?"button"!==t&&"reset"!==t:/^(submit|image)$/.test(t),i=(0,getParentNodesFromAttribute_1.default)("tagName","form",this);r&&i.length&&!this.hasAttribute("disabled")&&i[i.length-1].dispatchEvent((0,createEvent_1.default)("submit",{},{browser:!0,trusted:e.isTrusted}))},super.setDefaultEvent("click",e),this.defaultEventApplied=!0}return e}childInserted(e){"function"==typeof e.applyDefaultEvent&&e.applyDefaultEvent()}hasAttribute(e){return this.attributeList.some(({name:t})=>t===e)}setAttribute(e,t){const r=this.attributeList.find(({name:t})=>t===e);r?r.value=t:this.attributeList.push({name:e,value:t}),this.propertyAttributes.indexOf(e)>=0&&(this[e]=t)}getAttribute(e){const t=this.currentAttributes().find(({name:t})=>t===e);return t?t.value:null}removeAttribute(e){const t=this.attributeList.findIndex(({name:t})=>t===e);t>=0&&this.attributeList.splice(t,1)}}exports.ElementService=ElementService;