pseudo-dom 0.1.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 (125) hide show
  1. package/LICENSE +674 -0
  2. package/README.md +1029 -0
  3. package/browser/pseudo-dom.js +5219 -0
  4. package/browser/pseudo-dom.min.js +1 -0
  5. package/dist/classes/PseudoEventListener.d.ts +96 -0
  6. package/dist/classes/PseudoEventListener.js +148 -0
  7. package/dist/classes/PseudoEventListener.min.js +1 -0
  8. package/dist/classes/PseudoHTMLDocument.d.ts +35 -0
  9. package/dist/classes/PseudoHTMLDocument.js +77 -0
  10. package/dist/classes/PseudoHTMLDocument.min.js +1 -0
  11. package/dist/classes/PseudoNodeList.d.ts +34 -0
  12. package/dist/classes/PseudoNodeList.js +65 -0
  13. package/dist/classes/PseudoNodeList.min.js +1 -0
  14. package/dist/classes.d.ts +20 -0
  15. package/dist/classes.js +31 -0
  16. package/dist/classes.min.js +1 -0
  17. package/dist/factories/generateDocument.d.ts +11 -0
  18. package/dist/factories/generateDocument.js +65 -0
  19. package/dist/factories/generateDocument.min.js +1 -0
  20. package/dist/factories/generateNode.d.ts +40 -0
  21. package/dist/factories/generateNode.js +118 -0
  22. package/dist/factories/generateNode.min.js +1 -0
  23. package/dist/factories/generateNodeList.d.ts +9 -0
  24. package/dist/factories/generateNodeList.js +13 -0
  25. package/dist/factories/generateNodeList.min.js +1 -0
  26. package/dist/factories.d.ts +5 -0
  27. package/dist/factories.js +23 -0
  28. package/dist/factories.min.js +1 -0
  29. package/dist/functions/getParentNodes.d.ts +9 -0
  30. package/dist/functions/getParentNodes.js +15 -0
  31. package/dist/functions/getParentNodes.min.js +1 -0
  32. package/dist/functions/getParentNodesFromAttribute.d.ts +14 -0
  33. package/dist/functions/getParentNodesFromAttribute.js +9 -0
  34. package/dist/functions/getParentNodesFromAttribute.min.js +1 -0
  35. package/dist/functions.d.ts +5 -0
  36. package/dist/functions.js +23 -0
  37. package/dist/functions.min.js +1 -0
  38. package/dist/interfaces/PseudoAnimation.d.ts +3 -0
  39. package/dist/interfaces/PseudoAnimation.js +5 -0
  40. package/dist/interfaces/PseudoAnimation.min.js +1 -0
  41. package/dist/interfaces/PseudoAttr.d.ts +11 -0
  42. package/dist/interfaces/PseudoAttr.js +5 -0
  43. package/dist/interfaces/PseudoAttr.min.js +1 -0
  44. package/dist/interfaces/PseudoDOMTokenList.d.ts +16 -0
  45. package/dist/interfaces/PseudoDOMTokenList.js +5 -0
  46. package/dist/interfaces/PseudoDOMTokenList.min.js +1 -0
  47. package/dist/interfaces/PseudoDocument.d.ts +3 -0
  48. package/dist/interfaces/PseudoDocument.js +5 -0
  49. package/dist/interfaces/PseudoDocument.min.js +1 -0
  50. package/dist/interfaces/PseudoDocumentFragment.d.ts +3 -0
  51. package/dist/interfaces/PseudoDocumentFragment.js +5 -0
  52. package/dist/interfaces/PseudoDocumentFragment.min.js +1 -0
  53. package/dist/interfaces/PseudoElement.d.ts +678 -0
  54. package/dist/interfaces/PseudoElement.js +5 -0
  55. package/dist/interfaces/PseudoElement.min.js +1 -0
  56. package/dist/interfaces/PseudoEvent.d.ts +79 -0
  57. package/dist/interfaces/PseudoEvent.js +10 -0
  58. package/dist/interfaces/PseudoEvent.min.js +1 -0
  59. package/dist/interfaces/PseudoEventTarget.d.ts +46 -0
  60. package/dist/interfaces/PseudoEventTarget.js +5 -0
  61. package/dist/interfaces/PseudoEventTarget.min.js +1 -0
  62. package/dist/interfaces/PseudoHTMLCollection.d.ts +2 -0
  63. package/dist/interfaces/PseudoHTMLCollection.js +5 -0
  64. package/dist/interfaces/PseudoHTMLCollection.min.js +1 -0
  65. package/dist/interfaces/PseudoHTMLElement.d.ts +22 -0
  66. package/dist/interfaces/PseudoHTMLElement.js +5 -0
  67. package/dist/interfaces/PseudoHTMLElement.min.js +1 -0
  68. package/dist/interfaces/PseudoHTMLSlotElement.d.ts +3 -0
  69. package/dist/interfaces/PseudoHTMLSlotElement.js +5 -0
  70. package/dist/interfaces/PseudoHTMLSlotElement.min.js +1 -0
  71. package/dist/interfaces/PseudoNamedNodeMap.d.ts +11 -0
  72. package/dist/interfaces/PseudoNamedNodeMap.js +5 -0
  73. package/dist/interfaces/PseudoNamedNodeMap.min.js +1 -0
  74. package/dist/interfaces/PseudoNode.d.ts +179 -0
  75. package/dist/interfaces/PseudoNode.js +5 -0
  76. package/dist/interfaces/PseudoNode.min.js +1 -0
  77. package/dist/interfaces/PseudoShadowRoot.d.ts +3 -0
  78. package/dist/interfaces/PseudoShadowRoot.js +5 -0
  79. package/dist/interfaces/PseudoShadowRoot.min.js +1 -0
  80. package/dist/main.d.ts +29 -0
  81. package/dist/main.js +75 -0
  82. package/dist/main.min.js +1 -0
  83. package/dist/services/AnimationService.d.ts +4 -0
  84. package/dist/services/AnimationService.js +16 -0
  85. package/dist/services/AnimationService.min.js +1 -0
  86. package/dist/services/AttrService.d.ts +31 -0
  87. package/dist/services/AttrService.js +57 -0
  88. package/dist/services/AttrService.min.js +1 -0
  89. package/dist/services/DOMTokenListService.d.ts +33 -0
  90. package/dist/services/DOMTokenListService.js +117 -0
  91. package/dist/services/DOMTokenListService.min.js +1 -0
  92. package/dist/services/DocumentFragmentService.d.ts +4 -0
  93. package/dist/services/DocumentFragmentService.js +9 -0
  94. package/dist/services/DocumentFragmentService.min.js +1 -0
  95. package/dist/services/DocumentService.d.ts +4 -0
  96. package/dist/services/DocumentService.js +9 -0
  97. package/dist/services/DocumentService.min.js +1 -0
  98. package/dist/services/ElementService.d.ts +95 -0
  99. package/dist/services/ElementService.js +205 -0
  100. package/dist/services/ElementService.min.js +1 -0
  101. package/dist/services/EventService.d.ts +106 -0
  102. package/dist/services/EventService.js +216 -0
  103. package/dist/services/EventService.min.js +1 -0
  104. package/dist/services/EventTargetService.d.ts +52 -0
  105. package/dist/services/EventTargetService.js +163 -0
  106. package/dist/services/EventTargetService.min.js +1 -0
  107. package/dist/services/HTMLCollectionService.d.ts +3 -0
  108. package/dist/services/HTMLCollectionService.js +8 -0
  109. package/dist/services/HTMLCollectionService.min.js +1 -0
  110. package/dist/services/HTMLElementService.d.ts +37 -0
  111. package/dist/services/HTMLElementService.js +68 -0
  112. package/dist/services/HTMLElementService.min.js +1 -0
  113. package/dist/services/HTMLSlotElementService.d.ts +4 -0
  114. package/dist/services/HTMLSlotElementService.js +9 -0
  115. package/dist/services/HTMLSlotElementService.min.js +1 -0
  116. package/dist/services/NamedNodeMapService.d.ts +23 -0
  117. package/dist/services/NamedNodeMapService.js +77 -0
  118. package/dist/services/NamedNodeMapService.min.js +1 -0
  119. package/dist/services/NodeService.d.ts +111 -0
  120. package/dist/services/NodeService.js +230 -0
  121. package/dist/services/NodeService.min.js +1 -0
  122. package/dist/services/ShadowRootService.d.ts +4 -0
  123. package/dist/services/ShadowRootService.js +9 -0
  124. package/dist/services/ShadowRootService.min.js +1 -0
  125. package/package.json +58 -0
@@ -0,0 +1,57 @@
1
+ 'use strict'
2
+
3
+ Object.defineProperty(exports, '__esModule', {
4
+ value: true
5
+ })
6
+ exports.AttrService = void 0
7
+ const NodeService_1 = require('./NodeService')
8
+ /**
9
+ * Simulate the behaviour of the Attr Class when there is no DOM available.
10
+ * @author Joshua Heagle <joshuaheagle@gmail.com>
11
+ * @class
12
+ * @augments NodeService
13
+ */
14
+ class AttrService extends NodeService_1.NodeService {
15
+ /**
16
+ * @param {string} name The name of the attribute
17
+ * @param {string} [value=''] The value of the attribute
18
+ * @param {PseudoElement|null} [ownerElement=null] The element which has this attribute
19
+ * @param {string} [namespaceURI=''] The namespace of the attribute
20
+ * @param {string|null} [prefix=null] The namespace prefix of the attribute
21
+ * @constructor
22
+ */
23
+ constructor (name = '', value = '', ownerElement = null, namespaceURI = '', prefix = null) {
24
+ super()
25
+ this.attributeName = name
26
+ this.value = value
27
+ this.element = ownerElement
28
+ this.namespace = namespaceURI
29
+ this.namespacePrefix = prefix
30
+ this.nodeNameValue = name
31
+ }
32
+
33
+ get nodeType () {
34
+ return NodeService_1.NodeService.ATTRIBUTE_NODE
35
+ }
36
+
37
+ get localName () {
38
+ return this.attributeName
39
+ }
40
+
41
+ get name () {
42
+ return this.namespacePrefix ? `${this.namespacePrefix}:${this.attributeName}` : this.attributeName
43
+ }
44
+
45
+ get namespaceURI () {
46
+ return this.namespace
47
+ }
48
+
49
+ get ownerElement () {
50
+ return this.element
51
+ }
52
+
53
+ get prefix () {
54
+ return this.namespacePrefix
55
+ }
56
+ }
57
+ exports.AttrService = AttrService
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.AttrService=void 0;const NodeService_1=require("./NodeService");class AttrService extends NodeService_1.NodeService{constructor(e="",t="",r=null,i="",s=null){super(),this.attributeName=e,this.value=t,this.element=r,this.namespace=i,this.namespacePrefix=s,this.nodeNameValue=e}get nodeType(){return NodeService_1.NodeService.ATTRIBUTE_NODE}get localName(){return this.attributeName}get name(){return this.namespacePrefix?`${this.namespacePrefix}:${this.attributeName}`:this.attributeName}get namespaceURI(){return this.namespace}get ownerElement(){return this.element}get prefix(){return this.namespacePrefix}}exports.AttrService=AttrService;
@@ -0,0 +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
+ }
@@ -0,0 +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
@@ -0,0 +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.for-each.js"),require("core-js/modules/esnext.iterator.map.js"),Object.defineProperty(exports,"__esModule",{value:!0}),exports.DOMTokenListService=void 0;class DOMTokenListService{constructor(e="",t=()=>{}){this.tokens=DOMTokenListService.parse(e),this.onChange=t}static parse(e){return(e||"").split(/\s+/).filter((e,t,s)=>""!==e&&s.indexOf(e)===t)}update(e){this.tokens=e,this.onChange(this.value)}static validate(e){if(""===e)throw new SyntaxError("The token provided must not be empty.");if(/\s/.test(e))throw new Error("The token provided contains whitespace.")}get length(){return this.tokens.length}get value(){return this.tokens.join(" ")}set value(e){this.update(DOMTokenListService.parse(e))}item(e){return e>=0&&e<this.tokens.length?this.tokens[e]:null}contains(e){return this.tokens.indexOf(e)>=0}add(...e){e.forEach(DOMTokenListService.validate),this.update(this.tokens.concat(e).filter((e,t,s)=>s.indexOf(e)===t))}remove(...e){e.forEach(DOMTokenListService.validate),this.update(this.tokens.filter(t=>e.indexOf(t)<0))}replace(e,t){return DOMTokenListService.validate(e),DOMTokenListService.validate(t),!!this.contains(e)&&(this.update(this.tokens.map(s=>s===e?t:s).filter((e,t,s)=>s.indexOf(e)===t)),!0)}supports(e){throw new TypeError(`Failed to execute 'supports' on 'DOMTokenList': DOMTokenList has no supported tokens (${e}).`)}toggle(e,t){DOMTokenListService.validate(e);const s="boolean"==typeof t?t:!this.contains(e);return s?this.add(e):this.remove(e),s}entries(){return this.tokens.map((e,t)=>[t,e])[Symbol.iterator]()}forEach(e,t){this.tokens.forEach((s,r)=>e.call(t,s,r,this))}keys(){return this.tokens.map((e,t)=>t)[Symbol.iterator]()}values(){return this.tokens.slice()[Symbol.iterator]()}}exports.DOMTokenListService=DOMTokenListService;
@@ -0,0 +1,4 @@
1
+ import { NodeService } from './NodeService';
2
+ import { PseudoDocumentFragment } from '../interfaces/PseudoDocumentFragment';
3
+ export declare class DocumentFragmentService extends NodeService implements PseudoDocumentFragment {
4
+ }
@@ -0,0 +1,9 @@
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
+ class DocumentFragmentService extends NodeService_1.NodeService {}
9
+ exports.DocumentFragmentService = DocumentFragmentService
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.DocumentFragmentService=void 0;const NodeService_1=require("./NodeService");class DocumentFragmentService extends NodeService_1.NodeService{}exports.DocumentFragmentService=DocumentFragmentService;
@@ -0,0 +1,4 @@
1
+ import { NodeService } from './NodeService';
2
+ import { PseudoDocument } from '../interfaces/PseudoDocument';
3
+ export declare class DocumentService extends NodeService implements PseudoDocument {
4
+ }
@@ -0,0 +1,9 @@
1
+ 'use strict'
2
+
3
+ Object.defineProperty(exports, '__esModule', {
4
+ value: true
5
+ })
6
+ exports.DocumentService = void 0
7
+ const NodeService_1 = require('./NodeService')
8
+ class DocumentService extends NodeService_1.NodeService {}
9
+ exports.DocumentService = DocumentService
@@ -0,0 +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{}exports.DocumentService=DocumentService;
@@ -0,0 +1,95 @@
1
+ /**
2
+ * @file Substitute for the DOM Element Class.
3
+ * @author Joshua Heagle <joshuaheagle@gmail.com>
4
+ * @version 1.0.0
5
+ */
6
+ import { PseudoNode } from '../interfaces/PseudoNode';
7
+ import { NodeService } from './NodeService';
8
+ import { PseudoElement } from '../interfaces/PseudoElement';
9
+ import { PseudoNamedNodeMap } from '../interfaces/PseudoNamedNodeMap';
10
+ import { PseudoDOMTokenList } from '../interfaces/PseudoDOMTokenList';
11
+ type attribute = {
12
+ name: string;
13
+ value: any;
14
+ };
15
+ /**
16
+ * Simulate the behaviour of the Element Class when there is no DOM available.
17
+ * @author Joshua Heagle <joshuaheagle@gmail.com>
18
+ * @class
19
+ * @augments PseudoNode
20
+ * @property {string} tagName
21
+ * @property {string} className
22
+ * @property {string} id
23
+ * @property {string} innerHtml
24
+ * @property {Array} attributes
25
+ * @property {function} hasAttribute
26
+ * @property {function} setAttribute
27
+ * @property {function} getAttribute
28
+ * @property {function} removeAttribute
29
+ */
30
+ export declare class ElementService extends NodeService implements Partial<PseudoElement> {
31
+ id: string;
32
+ innerHTML: string;
33
+ type: string;
34
+ private readonly tag;
35
+ private readonly attributeList;
36
+ private readonly propertyAttributes;
37
+ private readonly tokenList;
38
+ /**
39
+ * @param {Object} [settings={}]
40
+ * @param {string} [settings.tagName=''] The name of the tag this element represents
41
+ * @param {Array<{name: string, value: *}>} [settings.attributes=[]] The attributes (also assigned as properties) to start with
42
+ * @param {PseudoNode|null} [settings.parent=null] The parent node
43
+ * @param {Array} [settings.children=[]] The values or nodes to start as children
44
+ * @constructor
45
+ */
46
+ constructor({ tagName, attributes, parent, children }?: {
47
+ tagName?: string;
48
+ attributes?: Array<attribute>;
49
+ parent?: PseudoNode | null;
50
+ children?: Array<any>;
51
+ });
52
+ get tagName(): string;
53
+ get nodeType(): number;
54
+ get attributes(): PseudoNamedNodeMap;
55
+ get classList(): PseudoDOMTokenList;
56
+ get className(): string;
57
+ set className(className: string);
58
+ /**
59
+ * Some elements have default behaviour, this registers it when the element is added.
60
+ * @returns {Function}
61
+ */
62
+ applyDefaultEvent(): Function;
63
+ /**
64
+ *
65
+ * @param {PseudoNode|ElementService} childElement
66
+ * @returns {PseudoNode}
67
+ */
68
+ appendChild(childElement: ElementService): PseudoNode;
69
+ /**
70
+ * Check whether the element has an attribute by that name.
71
+ * @param {string} attributeName
72
+ * @returns {boolean}
73
+ */
74
+ hasAttribute(attributeName: string): boolean;
75
+ /**
76
+ * Set the value of an attribute, adding the attribute if it did not exist.
77
+ * @param {string} attributeName
78
+ * @param {string} attributeValue
79
+ * @returns {undefined}
80
+ */
81
+ setAttribute(attributeName: string, attributeValue: string): void;
82
+ /**
83
+ * Retrieve the value of an attribute.
84
+ * @param {string} attributeName
85
+ * @returns {string|null} The value, or null when there is no such attribute
86
+ */
87
+ getAttribute(attributeName: string): string | null;
88
+ /**
89
+ * Remove an attribute from the element.
90
+ * @param {string} attributeName
91
+ * @returns {undefined}
92
+ */
93
+ removeAttribute(attributeName: string): void;
94
+ }
95
+ export {};
@@ -0,0 +1,205 @@
1
+ 'use strict'
2
+
3
+ require('core-js/modules/esnext.iterator.constructor.js')
4
+ require('core-js/modules/esnext.iterator.find.js')
5
+ require('core-js/modules/esnext.iterator.for-each.js')
6
+ require('core-js/modules/esnext.iterator.map.js')
7
+ require('core-js/modules/esnext.iterator.some.js')
8
+ const __importDefault = void 0 && (void 0).__importDefault || function (mod) {
9
+ return mod && mod.__esModule
10
+ ? mod
11
+ : {
12
+ default: mod
13
+ }
14
+ }
15
+ Object.defineProperty(exports, '__esModule', {
16
+ value: true
17
+ })
18
+ exports.ElementService = void 0
19
+ const generateNodeList_1 = __importDefault(require('../factories/generateNodeList'))
20
+ const TreeLinker_1 = require('collect-your-stuff/dist/collections/linked-tree-list/TreeLinker')
21
+ const NodeService_1 = require('./NodeService')
22
+ const AttrService_1 = require('./AttrService')
23
+ const DOMTokenListService_1 = require('./DOMTokenListService')
24
+ const NamedNodeMapService_1 = require('./NamedNodeMapService')
25
+ const getParentNodesFromAttribute_1 = __importDefault(require('../functions/getParentNodesFromAttribute'))
26
+ /**
27
+ * Simulate the behaviour of the Element Class when there is no DOM available.
28
+ * @author Joshua Heagle <joshuaheagle@gmail.com>
29
+ * @class
30
+ * @augments PseudoNode
31
+ * @property {string} tagName
32
+ * @property {string} className
33
+ * @property {string} id
34
+ * @property {string} innerHtml
35
+ * @property {Array} attributes
36
+ * @property {function} hasAttribute
37
+ * @property {function} setAttribute
38
+ * @property {function} getAttribute
39
+ * @property {function} removeAttribute
40
+ */
41
+ class ElementService extends NodeService_1.NodeService {
42
+ /**
43
+ * @param {Object} [settings={}]
44
+ * @param {string} [settings.tagName=''] The name of the tag this element represents
45
+ * @param {Array<{name: string, value: *}>} [settings.attributes=[]] The attributes (also assigned as properties) to start with
46
+ * @param {PseudoNode|null} [settings.parent=null] The parent node
47
+ * @param {Array} [settings.children=[]] The values or nodes to start as children
48
+ * @constructor
49
+ */
50
+ constructor ({
51
+ tagName = '',
52
+ attributes = [],
53
+ parent = null,
54
+ children = []
55
+ } = {}) {
56
+ super()
57
+ this.tokenList = new DOMTokenListService_1.DOMTokenListService()
58
+ this.parent = parent
59
+ this.children = (0, generateNodeList_1.default)(TreeLinker_1.TreeLinker.fromArray(children).head)
60
+ this.tag = tagName
61
+ this.attributeList = attributes.concat([{
62
+ name: 'className',
63
+ value: ''
64
+ }, {
65
+ name: 'id',
66
+ value: ''
67
+ }, {
68
+ name: 'innerHTML',
69
+ value: ''
70
+ }])
71
+ this.propertyAttributes = this.attributeList.map(({
72
+ name
73
+ }) => name)
74
+ this.attributeList.forEach(({
75
+ name,
76
+ value
77
+ }) => {
78
+ this[name] = value
79
+ })
80
+ }
81
+
82
+ get tagName () {
83
+ return this.tag
84
+ }
85
+
86
+ get nodeType () {
87
+ return NodeService_1.NodeService.ELEMENT_NODE
88
+ }
89
+
90
+ get attributes () {
91
+ return new NamedNodeMapService_1.NamedNodeMapService(this.attributeList.map(({
92
+ name,
93
+ value
94
+ }) => new AttrService_1.AttrService(name, String(value), this)))
95
+ }
96
+
97
+ get classList () {
98
+ return this.tokenList
99
+ }
100
+
101
+ get className () {
102
+ return this.tokenList.value
103
+ }
104
+
105
+ set className (className) {
106
+ this.tokenList.value = className
107
+ }
108
+
109
+ /**
110
+ * Some elements have default behaviour, this registers it when the element is added.
111
+ * @returns {Function}
112
+ */
113
+ applyDefaultEvent () {
114
+ let callback = event => undefined
115
+ switch (this.tagName) {
116
+ case 'form':
117
+ this.addEventListener('submit', callback)
118
+ break
119
+ case 'button':
120
+ case 'input':
121
+ if (/^(submit|image)$/i.test(this.type || '')) {
122
+ callback = event => {
123
+ const forms = (0, getParentNodesFromAttribute_1.default)('tagName', 'form', this)
124
+ if (forms.length) {
125
+ forms[0].submit()
126
+ }
127
+ }
128
+ super.setDefaultEvent('click', callback)
129
+ }
130
+ }
131
+ return callback
132
+ }
133
+
134
+ /**
135
+ *
136
+ * @param {PseudoNode|ElementService} childElement
137
+ * @returns {PseudoNode}
138
+ */
139
+ appendChild (childElement) {
140
+ super.appendChild(childElement)
141
+ childElement.applyDefaultEvent()
142
+ return childElement
143
+ }
144
+
145
+ /**
146
+ * Check whether the element has an attribute by that name.
147
+ * @param {string} attributeName
148
+ * @returns {boolean}
149
+ */
150
+ hasAttribute (attributeName) {
151
+ return this.attributeList.some(({
152
+ name
153
+ }) => name === attributeName)
154
+ }
155
+
156
+ /**
157
+ * Set the value of an attribute, adding the attribute if it did not exist.
158
+ * @param {string} attributeName
159
+ * @param {string} attributeValue
160
+ * @returns {undefined}
161
+ */
162
+ setAttribute (attributeName, attributeValue) {
163
+ const existing = this.attributeList.find(({
164
+ name
165
+ }) => name === attributeName)
166
+ if (existing) {
167
+ existing.value = attributeValue
168
+ } else {
169
+ this.attributeList.push({
170
+ name: attributeName,
171
+ value: attributeValue
172
+ })
173
+ }
174
+ if (this.propertyAttributes.indexOf(attributeName) >= 0) {
175
+ this[attributeName] = attributeValue
176
+ }
177
+ }
178
+
179
+ /**
180
+ * Retrieve the value of an attribute.
181
+ * @param {string} attributeName
182
+ * @returns {string|null} The value, or null when there is no such attribute
183
+ */
184
+ getAttribute (attributeName) {
185
+ const found = this.attributeList.find(({
186
+ name
187
+ }) => name === attributeName)
188
+ return found ? found.value : null
189
+ }
190
+
191
+ /**
192
+ * Remove an attribute from the element.
193
+ * @param {string} attributeName
194
+ * @returns {undefined}
195
+ */
196
+ removeAttribute (attributeName) {
197
+ const index = this.attributeList.findIndex(({
198
+ name
199
+ }) => name === attributeName)
200
+ if (index >= 0) {
201
+ this.attributeList.splice(index, 1)
202
+ }
203
+ }
204
+ }
205
+ exports.ElementService = ElementService
@@ -0,0 +1 @@
1
+ "use strict";require("core-js/modules/esnext.iterator.constructor.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 generateNodeList_1=__importDefault(require("../factories/generateNodeList")),TreeLinker_1=require("collect-your-stuff/dist/collections/linked-tree-list/TreeLinker"),NodeService_1=require("./NodeService"),AttrService_1=require("./AttrService"),DOMTokenListService_1=require("./DOMTokenListService"),NamedNodeMapService_1=require("./NamedNodeMapService"),getParentNodesFromAttribute_1=__importDefault(require("../functions/getParentNodesFromAttribute"));class ElementService extends NodeService_1.NodeService{constructor({tagName:e="",attributes:t=[],parent:r=null,children:i=[]}={}){super(),this.tokenList=new DOMTokenListService_1.DOMTokenListService,this.parent=r,this.children=(0,generateNodeList_1.default)(TreeLinker_1.TreeLinker.fromArray(i).head),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})}get tagName(){return this.tag}get nodeType(){return NodeService_1.NodeService.ELEMENT_NODE}get attributes(){return new NamedNodeMapService_1.NamedNodeMapService(this.attributeList.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}applyDefaultEvent(){let e=e=>{};switch(this.tagName){case"form":this.addEventListener("submit",e);break;case"button":case"input":/^(submit|image)$/i.test(this.type||"")&&(e=e=>{const t=(0,getParentNodesFromAttribute_1.default)("tagName","form",this);t.length&&t[0].submit()},super.setDefaultEvent("click",e))}return e}appendChild(e){return super.appendChild(e),e.applyDefaultEvent(),e}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.attributeList.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;
@@ -0,0 +1,106 @@
1
+ /**
2
+ * @file Substitute for the DOM Event Class.
3
+ * @author Joshua Heagle <joshuaheagle@gmail.com>
4
+ * @version 1.0.0
5
+ */
6
+ import { PseudoEventTarget } from '../interfaces/PseudoEventTarget';
7
+ import { PseudoEvent } from '../interfaces/PseudoEvent';
8
+ export type EventInner = {
9
+ currentTarget: PseudoEventTarget;
10
+ eventPhase: number;
11
+ target: PseudoEventTarget;
12
+ immediatePropagationStopped: boolean;
13
+ propagationStopped: boolean;
14
+ };
15
+ /**
16
+ * Simulate the behaviour of the Event Class when there is no DOM available.
17
+ * @author Joshua Heagle <joshuaheagle@gmail.com>
18
+ * @class
19
+ * @property {number} NONE
20
+ * @property {number} CAPTURING_PHASE
21
+ * @property {number} AT_TARGET
22
+ * @property {number} BUBBLING_PHASE
23
+ * @property {boolean} bubbles - A Boolean indicating whether the event bubbles up through the Dom or not.
24
+ * @property {boolean} cancelable - A Boolean indicating whether the event is cancelable.
25
+ * @property {boolean} composed - A Boolean value indicating whether the event can bubble across the boundary
26
+ * between the shadow Dom and the regular Dom.
27
+ * @property {function|PseudoEventTarget} currentTarget - A reference to the currently registered target for the event. This
28
+ * is the object to which the event is currently slated to be sent; it's possible this has been changed along the way
29
+ * through re-targeting.
30
+ * @property {boolean} defaultPrevented - Indicates whether event.preventDefault() has been called on the event.
31
+ * @property {boolean} immediatePropagationStopped - Flag that no further propagation should occur, including on current
32
+ * target.
33
+ * @property {boolean} propagationStopped - Flag that no further propagation should occur.
34
+ * @property {int} eventPhase - Indicates which phase of the event flow is being processed. Uses EventService constants.
35
+ * @property {EventTarget|PseudoEventTarget} target - A reference to the target to which the event was originally
36
+ * dispatched.
37
+ * @property {int} timeStamp - The time at which the event was created (in milliseconds). By specification, this
38
+ * value is time since epoch, but in reality browsers' definitions vary; in addition, work is underway to change this
39
+ * to be a DomHighResTimeStamp instead.
40
+ * @property {string} type - The name of the event (case-insensitive).
41
+ * @property {boolean} isTrusted - Indicates whether the event was initiated by the browser (after a user
42
+ * click for instance) or by a script (using an event creation method, like event.initEvent)
43
+ */
44
+ export declare class EventService implements PseudoEvent {
45
+ static readonly NONE = 0;
46
+ static readonly CAPTURING_PHASE = 1;
47
+ static readonly AT_TARGET = 2;
48
+ static readonly BUBBLING_PHASE = 3;
49
+ private properties;
50
+ /**
51
+ *
52
+ * @param {string} typeArg
53
+ * @param {Object} [eventOptions={}]
54
+ * @param {boolean} [eventOptions.bubbles=true]
55
+ * @param {boolean} [eventOptions.cancelable=true]
56
+ * @param {boolean} [eventOptions.composed=true]
57
+ * @constructor
58
+ */
59
+ constructor(typeArg?: string, { bubbles, cancelable, composed }?: {
60
+ bubbles?: boolean;
61
+ cancelable?: boolean;
62
+ composed?: boolean;
63
+ });
64
+ get bubbles(): boolean;
65
+ get cancelable(): boolean;
66
+ get composed(): boolean;
67
+ get currentTarget(): PseudoEventTarget;
68
+ get defaultPrevented(): boolean;
69
+ get eventPhase(): number;
70
+ get isTrusted(): boolean;
71
+ get target(): PseudoEventTarget;
72
+ get timeStamp(): number;
73
+ get type(): string;
74
+ /**
75
+ * Scope several accessors inside the inner object. These are only intended for usage by other DOM classes.
76
+ * @returns {EventInner}
77
+ */
78
+ get inner(): EventInner;
79
+ /**
80
+ * Return an array of targets that will have the event executed open them. The order is based on the eventPhase
81
+ * @method
82
+ * @returns {Array.<PseudoEventTarget>}
83
+ */
84
+ composedPath(): Array<PseudoEventTarget>;
85
+ /**
86
+ * Cancels the event (if it is cancelable).
87
+ * @method
88
+ * @returns {null}
89
+ */
90
+ preventDefault(): null;
91
+ /**
92
+ * For this particular event, no other listener will be called.
93
+ * Neither those attached on the same element, nor those attached on elements which will be traversed later (in
94
+ * capture phase, for instance)
95
+ * @method
96
+ * @returns {null}
97
+ */
98
+ stopImmediatePropagation(): null;
99
+ /**
100
+ * Stops the propagation of events further along in the Dom.
101
+ * @method
102
+ * @returns {null}
103
+ */
104
+ stopPropagation(): null;
105
+ private setReadOnlyProperties;
106
+ }