pseudo-dom 0.8.0 → 0.9.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 (30) hide show
  1. package/README.md +206 -1
  2. package/browser/pseudo-dom.js +813 -470
  3. package/browser/pseudo-dom.min.js +1 -1
  4. package/dist/classes/PseudoHTMLDocument.d.ts +41 -41
  5. package/dist/classes/PseudoHTMLDocument.js +74 -74
  6. package/dist/factories/createDataset.d.ts +10 -0
  7. package/dist/factories/createDataset.js +78 -0
  8. package/dist/factories/createDataset.min.js +1 -0
  9. package/dist/factories/createStyleDeclaration.d.ts +30 -0
  10. package/dist/factories/createStyleDeclaration.js +64 -0
  11. package/dist/factories/createStyleDeclaration.min.js +1 -0
  12. package/dist/functions/getElementById.d.ts +13 -13
  13. package/dist/functions/getElementById.js +33 -33
  14. package/dist/interfaces/PseudoCSSStyleDeclaration.d.ts +14 -0
  15. package/dist/interfaces/PseudoCSSStyleDeclaration.js +5 -0
  16. package/dist/interfaces/PseudoCSSStyleDeclaration.min.js +1 -0
  17. package/dist/interfaces/PseudoDocument.d.ts +35 -35
  18. package/dist/interfaces/PseudoDocumentFragment.d.ts +10 -10
  19. package/dist/interfaces/PseudoHTMLElement.d.ts +33 -22
  20. package/dist/services/CSSStyleDeclarationService.d.ts +73 -0
  21. package/dist/services/CSSStyleDeclarationService.js +156 -0
  22. package/dist/services/CSSStyleDeclarationService.min.js +1 -0
  23. package/dist/services/DocumentFragmentService.d.ts +21 -21
  24. package/dist/services/DocumentFragmentService.js +42 -42
  25. package/dist/services/DocumentService.d.ts +46 -46
  26. package/dist/services/DocumentService.js +95 -95
  27. package/dist/services/HTMLElementService.d.ts +87 -57
  28. package/dist/services/HTMLElementService.js +202 -163
  29. package/dist/services/HTMLElementService.min.js +1 -1
  30. package/package.json +1 -1
@@ -1,95 +1,95 @@
1
- 'use strict'
2
-
3
- const __importDefault = void 0 && (void 0).__importDefault || function (mod) {
4
- return mod && mod.__esModule
5
- ? mod
6
- : {
7
- default: mod
8
- }
9
- }
10
- Object.defineProperty(exports, '__esModule', {
11
- value: true
12
- })
13
- exports.DocumentService = void 0
14
- const NodeService_1 = require('./NodeService')
15
- const HTMLElementService_1 = require('./HTMLElementService')
16
- const DocumentFragmentService_1 = require('./DocumentFragmentService')
17
- const getElementById_1 = __importDefault(require('../functions/getElementById'))
18
- /**
19
- * Simulate the behaviour of the Document Class when there is no DOM available.
20
- * @author Joshua Heagle <joshuaheagle@gmail.com>
21
- * @class
22
- * @augments NodeService
23
- */
24
- class DocumentService extends NodeService_1.NodeService {
25
- get nodeName () {
26
- return '#document'
27
- }
28
-
29
- get nodeType () {
30
- return NodeService_1.NodeService.DOCUMENT_NODE
31
- }
32
-
33
- // A document has no text of its own, and setting it does nothing
34
- get textContent () {
35
- return null
36
- }
37
-
38
- set textContent (text) {}
39
- /**
40
- * The first element, in tree order, whose id matches the given value, or null when there is none.
41
- * @param {string} id
42
- * @returns {PseudoElement|null}
43
- */
44
- getElementById (id) {
45
- return (0, getElementById_1.default)(this, id)
46
- }
47
-
48
- /**
49
- * Make an element of the given type which belongs to this document but is not added anywhere until it is appended.
50
- * @param {string} [tagName='div'] The type of element to create
51
- * @returns {PseudoElement}
52
- */
53
- createElement (tagName = 'div') {
54
- // Like the DOM, the new element is not added anywhere: it has no parent until it is appended
55
- const element = new HTMLElementService_1.HTMLElementService({
56
- tagName
57
- })
58
- element.ownerDocumentStore = this
59
- return element
60
- }
61
-
62
- /**
63
- * Make a text node which belongs to this document.
64
- * @param {string} [data=''] The text
65
- * @returns {TextService}
66
- */
67
- createTextNode (data = '') {
68
- const text = new NodeService_1.TextService(data)
69
- text.ownerDocumentStore = this
70
- return text
71
- }
72
-
73
- /**
74
- * Make a comment which belongs to this document.
75
- * @param {string} [data=''] The comment
76
- * @returns {CommentService}
77
- */
78
- createComment (data = '') {
79
- const comment = new NodeService_1.CommentService(data)
80
- comment.ownerDocumentStore = this
81
- return comment
82
- }
83
-
84
- /**
85
- * Make an empty document fragment which belongs to this document, a container for nodes which can be built up and
86
- * then inserted in one go.
87
- * @returns {DocumentFragmentService}
88
- */
89
- createDocumentFragment () {
90
- const fragment = new DocumentFragmentService_1.DocumentFragmentService()
91
- fragment.ownerDocumentStore = this
92
- return fragment
93
- }
94
- }
95
- exports.DocumentService = DocumentService
1
+ 'use strict'
2
+
3
+ const __importDefault = void 0 && (void 0).__importDefault || function (mod) {
4
+ return mod && mod.__esModule
5
+ ? mod
6
+ : {
7
+ default: mod
8
+ }
9
+ }
10
+ Object.defineProperty(exports, '__esModule', {
11
+ value: true
12
+ })
13
+ exports.DocumentService = void 0
14
+ const NodeService_1 = require('./NodeService')
15
+ const HTMLElementService_1 = require('./HTMLElementService')
16
+ const DocumentFragmentService_1 = require('./DocumentFragmentService')
17
+ const getElementById_1 = __importDefault(require('../functions/getElementById'))
18
+ /**
19
+ * Simulate the behaviour of the Document Class when there is no DOM available.
20
+ * @author Joshua Heagle <joshuaheagle@gmail.com>
21
+ * @class
22
+ * @augments NodeService
23
+ */
24
+ class DocumentService extends NodeService_1.NodeService {
25
+ get nodeName () {
26
+ return '#document'
27
+ }
28
+
29
+ get nodeType () {
30
+ return NodeService_1.NodeService.DOCUMENT_NODE
31
+ }
32
+
33
+ // A document has no text of its own, and setting it does nothing
34
+ get textContent () {
35
+ return null
36
+ }
37
+
38
+ set textContent (text) {}
39
+ /**
40
+ * The first element, in tree order, whose id matches the given value, or null when there is none.
41
+ * @param {string} id
42
+ * @returns {PseudoElement|null}
43
+ */
44
+ getElementById (id) {
45
+ return (0, getElementById_1.default)(this, id)
46
+ }
47
+
48
+ /**
49
+ * Make an element of the given type which belongs to this document but is not added anywhere until it is appended.
50
+ * @param {string} [tagName='div'] The type of element to create
51
+ * @returns {PseudoElement}
52
+ */
53
+ createElement (tagName = 'div') {
54
+ // Like the DOM, the new element is not added anywhere: it has no parent until it is appended
55
+ const element = new HTMLElementService_1.HTMLElementService({
56
+ tagName
57
+ })
58
+ element.ownerDocumentStore = this
59
+ return element
60
+ }
61
+
62
+ /**
63
+ * Make a text node which belongs to this document.
64
+ * @param {string} [data=''] The text
65
+ * @returns {TextService}
66
+ */
67
+ createTextNode (data = '') {
68
+ const text = new NodeService_1.TextService(data)
69
+ text.ownerDocumentStore = this
70
+ return text
71
+ }
72
+
73
+ /**
74
+ * Make a comment which belongs to this document.
75
+ * @param {string} [data=''] The comment
76
+ * @returns {CommentService}
77
+ */
78
+ createComment (data = '') {
79
+ const comment = new NodeService_1.CommentService(data)
80
+ comment.ownerDocumentStore = this
81
+ return comment
82
+ }
83
+
84
+ /**
85
+ * Make an empty document fragment which belongs to this document, a container for nodes which can be built up and
86
+ * then inserted in one go.
87
+ * @returns {DocumentFragmentService}
88
+ */
89
+ createDocumentFragment () {
90
+ const fragment = new DocumentFragmentService_1.DocumentFragmentService()
91
+ fragment.ownerDocumentStore = this
92
+ return fragment
93
+ }
94
+ }
95
+ exports.DocumentService = DocumentService
@@ -1,57 +1,87 @@
1
- /**
2
- * @file Substitute for the DOM HTMLElement Class.
3
- * @author Joshua Heagle <joshuaheagle@gmail.com>
4
- * @version 1.0.0
5
- */
6
- import { PseudoHTMLElement } from '../interfaces/PseudoHTMLElement';
7
- import { PseudoNode } from '../interfaces/PseudoNode';
8
- import { ElementService } from './ElementService';
9
- /**
10
- * Simulate the behaviour of the HTMLElement Class when there is no DOM available.
11
- * @author Joshua Heagle <joshuaheagle@gmail.com>
12
- * @class
13
- * @augments PseudoElement
14
- * @property {boolean} hidden - State of whether element is visible
15
- * @property {number} offsetHeight - The height of the element as offset by the parent element
16
- * @property {number} offsetLeft - The position of the left side of the element based on the parent element
17
- * @property {PseudoHTMLElement} offsetParent - A reference to the closest positioned parent element
18
- * @property {number} offsetTop - The position of the top side of the element based on the parent element
19
- * @property {number} offsetWidth - The width of the element as offset by the parent element
20
- * @property {Object} style - A container to define all applied inline-styles
21
- * @property {string} title - The title attribute which affects the text visible on hover
22
- */
23
- export declare class HTMLElementService extends ElementService implements Partial<PseudoHTMLElement> {
24
- /**
25
- * Simulate the HTMLElement object when the Dom is not available
26
- * @param {Object} [elementOptions={}]
27
- * @param {string} [elementOptions.tagName='']
28
- * @param {PseudoNode|Object} [elementOptions.parent={}]
29
- * @param {Array} [elementOptions.children=[]]
30
- * @constructor
31
- */
32
- constructor({ tagName, parent, children }?: {
33
- tagName?: string;
34
- parent?: PseudoNode | null;
35
- children?: Array<any>;
36
- });
37
- /**
38
- * Whether this element can have the focus: form controls and links which are not disabled, and anything with a tabindex.
39
- * @returns {boolean}
40
- */
41
- get canFocus(): boolean;
42
- /**
43
- * Click the element: a click event is sent to it, which bubbles and can be cancelled, like one from a user but a
44
- * script made it (so it is not trusted). A disabled element does nothing.
45
- */
46
- click(): void;
47
- /**
48
- * Give the element the focus. The element which had it gets blur then focusout, and this one gets focus then
49
- * focusin (blur and focus do not bubble, focusin and focusout do). Nothing happens when the element cannot have the
50
- * focus or already has it.
51
- */
52
- focus(): void;
53
- /**
54
- * Take the focus away from the element, when it has it: it gets blur then focusout.
55
- */
56
- blur(): void;
57
- }
1
+ /**
2
+ * @file Substitute for the DOM HTMLElement Class.
3
+ * @author Joshua Heagle <joshuaheagle@gmail.com>
4
+ * @version 1.0.0
5
+ */
6
+ import { PseudoHTMLElement } from '../interfaces/PseudoHTMLElement';
7
+ import { PseudoNode } from '../interfaces/PseudoNode';
8
+ import { NodeService } from './NodeService';
9
+ import { ElementService } from './ElementService';
10
+ import { CSSStyleDeclarationService } from './CSSStyleDeclarationService';
11
+ /**
12
+ * Simulate the behaviour of the HTMLElement Class when there is no DOM available.
13
+ * @author Joshua Heagle <joshuaheagle@gmail.com>
14
+ * @class
15
+ * @augments PseudoElement
16
+ * @property {boolean} hidden - State of whether element is visible
17
+ * @property {number} offsetHeight - The height of the element as offset by the parent element
18
+ * @property {number} offsetLeft - The position of the left side of the element based on the parent element
19
+ * @property {PseudoHTMLElement} offsetParent - A reference to the closest positioned parent element
20
+ * @property {number} offsetTop - The position of the top side of the element based on the parent element
21
+ * @property {number} offsetWidth - The width of the element as offset by the parent element
22
+ * @property {CSSStyleDeclarationService} style - The element's inline styles, live and settable per property
23
+ * @property {Object.<string, string>} dataset - The element's data-* attributes, live, under their camelCase names
24
+ * @property {string} title - The title attribute which affects the text visible on hover
25
+ */
26
+ export declare class HTMLElementService extends ElementService implements Partial<PseudoHTMLElement> {
27
+ private readonly styleDeclaration;
28
+ private readonly datasetProxy;
29
+ /**
30
+ * Simulate the HTMLElement object when the Dom is not available
31
+ * @param {Object} [elementOptions={}]
32
+ * @param {string} [elementOptions.tagName='']
33
+ * @param {PseudoNode|Object} [elementOptions.parent={}]
34
+ * @param {Array} [elementOptions.children=[]]
35
+ * @constructor
36
+ */
37
+ constructor({ tagName, parent, children }?: {
38
+ tagName?: string;
39
+ parent?: PseudoNode | null;
40
+ children?: Array<any>;
41
+ });
42
+ /**
43
+ * The element's inline styles: a live CSSStyleDeclaration-like object, so both style.setProperty('color', 'red')
44
+ * and style.color = 'red' work.
45
+ * @returns {CSSStyleDeclarationService}
46
+ */
47
+ get style(): CSSStyleDeclarationService;
48
+ /**
49
+ * The element's data-* attributes, live, under their camelCase names (data-foo-bar <-> dataset.fooBar). Backed
50
+ * directly by getAttribute / setAttribute, so it is never out of sync with the attributes themselves.
51
+ * @returns {Object.<string, string>}
52
+ */
53
+ get dataset(): {
54
+ [key: string]: string;
55
+ };
56
+ /**
57
+ * Style is not attribute-backed like most properties (see the constructor), so cloneNode needs its own copy of it.
58
+ * @returns {NodeService}
59
+ */
60
+ protected cloneShallow(): NodeService;
61
+ /**
62
+ * Style is not attribute-backed like most properties, so isEqualNode needs to compare it separately too.
63
+ * @param {NodeService} other The node to compare with
64
+ * @returns {boolean}
65
+ */
66
+ protected equalsShallow(other: NodeService): boolean;
67
+ /**
68
+ * Whether this element can have the focus: form controls and links which are not disabled, and anything with a tabindex.
69
+ * @returns {boolean}
70
+ */
71
+ get canFocus(): boolean;
72
+ /**
73
+ * Click the element: a click event is sent to it, which bubbles and can be cancelled, like one from a user but a
74
+ * script made it (so it is not trusted). A disabled element does nothing.
75
+ */
76
+ click(): void;
77
+ /**
78
+ * Give the element the focus. The element which had it gets blur then focusout, and this one gets focus then
79
+ * focusin (blur and focus do not bubble, focusin and focusout do). Nothing happens when the element cannot have the
80
+ * focus or already has it.
81
+ */
82
+ focus(): void;
83
+ /**
84
+ * Take the focus away from the element, when it has it: it gets blur then focusout.
85
+ */
86
+ blur(): void;
87
+ }