pseudo-dom 0.7.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 (57) hide show
  1. package/README.md +468 -237
  2. package/browser/pseudo-dom.js +986 -563
  3. package/browser/pseudo-dom.min.js +1 -1
  4. package/dist/classes/PseudoHTMLDocument.d.ts +17 -43
  5. package/dist/classes/PseudoHTMLDocument.js +24 -94
  6. package/dist/classes/PseudoHTMLDocument.min.js +1 -1
  7. package/dist/factories/createDataset.d.ts +10 -0
  8. package/dist/factories/createDataset.js +78 -0
  9. package/dist/factories/createDataset.min.js +1 -0
  10. package/dist/factories/createStyleDeclaration.d.ts +30 -0
  11. package/dist/factories/createStyleDeclaration.js +64 -0
  12. package/dist/factories/createStyleDeclaration.min.js +1 -0
  13. package/dist/factories/cssSelectAdapter.d.ts +23 -23
  14. package/dist/factories/cssSelectAdapter.js +87 -87
  15. package/dist/factories/query.d.ts +33 -33
  16. package/dist/factories/query.js +66 -66
  17. package/dist/functions/getElementById.d.ts +13 -0
  18. package/dist/functions/getElementById.js +33 -0
  19. package/dist/functions/getElementById.min.js +1 -0
  20. package/dist/interfaces/PseudoCSSStyleDeclaration.d.ts +14 -0
  21. package/dist/interfaces/PseudoCSSStyleDeclaration.js +5 -0
  22. package/dist/interfaces/PseudoCSSStyleDeclaration.min.js +1 -0
  23. package/dist/interfaces/PseudoDocument.d.ts +35 -10
  24. package/dist/interfaces/PseudoDocumentFragment.d.ts +7 -0
  25. package/dist/interfaces/PseudoElement.d.ts +702 -702
  26. package/dist/interfaces/PseudoHTMLElement.d.ts +33 -22
  27. package/dist/services/CSSStyleDeclarationService.d.ts +73 -0
  28. package/dist/services/CSSStyleDeclarationService.js +156 -0
  29. package/dist/services/CSSStyleDeclarationService.min.js +1 -0
  30. package/dist/services/DocumentFragmentService.d.ts +8 -0
  31. package/dist/services/DocumentFragmentService.js +18 -0
  32. package/dist/services/DocumentFragmentService.min.js +1 -1
  33. package/dist/services/DocumentService.d.ts +46 -19
  34. package/dist/services/DocumentService.js +95 -46
  35. package/dist/services/DocumentService.min.js +1 -1
  36. package/dist/services/ElementService.d.ts +191 -191
  37. package/dist/services/ElementService.js +426 -426
  38. package/dist/services/HTMLCollectionService.d.ts +54 -54
  39. package/dist/services/HTMLCollectionService.js +92 -92
  40. package/dist/services/HTMLElementService.d.ts +87 -57
  41. package/dist/services/HTMLElementService.js +202 -163
  42. package/dist/services/HTMLElementService.min.js +1 -1
  43. package/dist/services/NodeService.d.ts +297 -297
  44. package/dist/services/NodeService.js +721 -721
  45. package/package.json +2 -2
  46. package/dist/classes.d.ts +0 -20
  47. package/dist/classes.js +0 -31
  48. package/dist/classes.min.js +0 -1
  49. package/dist/factories/generateNode.d.ts +0 -32
  50. package/dist/factories/generateNode.js +0 -85
  51. package/dist/factories/generateNode.min.js +0 -1
  52. package/dist/factories.d.ts +0 -11
  53. package/dist/factories.js +0 -27
  54. package/dist/factories.min.js +0 -1
  55. package/dist/functions.d.ts +0 -5
  56. package/dist/functions.js +0 -23
  57. package/dist/functions.min.js +0 -1
@@ -1,22 +1,33 @@
1
- /**
2
- * @file Substitute for the DOM HTMLElement Class.
3
- * @author Joshua Heagle <joshuaheagle@gmail.com>
4
- * @version 1.0.0
5
- */
6
- import { PseudoElement } from './PseudoElement';
7
- /**
8
- * Simulate the behaviour of the HTMLElement Class when there is no DOM available.
9
- * @author Joshua Heagle <joshuaheagle@gmail.com>
10
- * @class
11
- * @augments PseudoElement
12
- * @property {boolean} hidden - State of whether element is visible
13
- * @property {number} offsetHeight - The height of the element as offset by the parent element
14
- * @property {number} offsetLeft - The position of the left side of the element based on the parent element
15
- * @property {PseudoHTMLElement} offsetParent - A reference to the closest positioned parent element
16
- * @property {number} offsetTop - The position of the top side of the element based on the parent element
17
- * @property {number} offsetWidth - The width of the element as offset by the parent element
18
- * @property {Object} style - A container to define all applied inline-styles
19
- * @property {string} title - The title attribute which affects the text visible on hover
20
- */
21
- export interface PseudoHTMLElement extends PseudoElement {
22
- }
1
+ /**
2
+ * @file Substitute for the DOM HTMLElement Class.
3
+ * @author Joshua Heagle <joshuaheagle@gmail.com>
4
+ * @version 1.0.0
5
+ */
6
+ import { PseudoElement } from './PseudoElement';
7
+ import { PseudoCSSStyleDeclaration } from './PseudoCSSStyleDeclaration';
8
+ /**
9
+ * Simulate the behaviour of the HTMLElement Class when there is no DOM available.
10
+ * @author Joshua Heagle <joshuaheagle@gmail.com>
11
+ * @class
12
+ * @augments PseudoElement
13
+ * @property {boolean} hidden - State of whether element is visible
14
+ * @property {number} offsetHeight - The height of the element as offset by the parent element
15
+ * @property {number} offsetLeft - The position of the left side of the element based on the parent element
16
+ * @property {PseudoHTMLElement} offsetParent - A reference to the closest positioned parent element
17
+ * @property {number} offsetTop - The position of the top side of the element based on the parent element
18
+ * @property {number} offsetWidth - The width of the element as offset by the parent element
19
+ * @property {string} title - The title attribute which affects the text visible on hover
20
+ */
21
+ export interface PseudoHTMLElement extends PseudoElement {
22
+ /**
23
+ * The element's inline styles, live and settable per property (style.color = 'red') as well as through the real
24
+ * CSSStyleDeclaration methods (getPropertyValue, setProperty, removeProperty, cssText).
25
+ */
26
+ get style(): PseudoCSSStyleDeclaration;
27
+ /**
28
+ * The element's data-* attributes, live, under their camelCase names (data-foo-bar <-> dataset.fooBar).
29
+ */
30
+ get dataset(): {
31
+ [key: string]: string;
32
+ };
33
+ }
@@ -0,0 +1,73 @@
1
+ /**
2
+ * @file Substitute for the DOM CSSStyleDeclaration Class (the object behind Element.style).
3
+ * @author Joshua Heagle <joshuaheagle@gmail.com>
4
+ * @version 1.0.0
5
+ */
6
+ /**
7
+ * Simulate the behaviour of the CSSStyleDeclaration Class when there is no DOM available: an ordered map of CSS
8
+ * property/value pairs, parsed from and serialized back to a cssText string. Values are stored and returned as
9
+ * given, with no unit conversion, shorthand expansion or validation - this is a data structure, not a real CSS
10
+ * engine. Named property access (declaration.backgroundColor, camelCase) is added on top of this by
11
+ * createStyleDeclaration, which wraps an instance of this class in a Proxy.
12
+ * @author Joshua Heagle <joshuaheagle@gmail.com>
13
+ * @class
14
+ */
15
+ export declare class CSSStyleDeclarationService {
16
+ private readonly properties;
17
+ /**
18
+ * @param {string} [cssText=''] Initial declarations, as CSS text ("color: red; font-size: 12px;")
19
+ * @constructor
20
+ */
21
+ constructor(cssText?: string);
22
+ /**
23
+ * How many properties are currently set.
24
+ * @returns {number}
25
+ */
26
+ get length(): number;
27
+ /**
28
+ * The name of the property at the given index, in the order it was set, or '' when there is none (matches the
29
+ * DOM's CSSStyleDeclaration, which is array-like).
30
+ * @param {number} index
31
+ * @returns {string}
32
+ */
33
+ item(index: number): string;
34
+ /**
35
+ * The value of the given property, or '' when it is not set.
36
+ * @param {string} property A CSS property name (kebab-case, e.g. "background-color")
37
+ * @returns {string}
38
+ */
39
+ getPropertyValue(property: string): string;
40
+ /**
41
+ * "important" when the property was set with !important, otherwise ''.
42
+ * @param {string} property A CSS property name (kebab-case)
43
+ * @returns {string}
44
+ */
45
+ getPropertyPriority(property: string): string;
46
+ /**
47
+ * Set a property's value (and optionally its priority). An empty, null or undefined value removes the property
48
+ * instead, like the DOM.
49
+ * @param {string} property A CSS property name (kebab-case)
50
+ * @param {string} value The value, or '' to remove the property
51
+ * @param {string} [priority=''] "important" to mark it !important
52
+ * @returns {undefined}
53
+ */
54
+ setProperty(property: string, value: string, priority?: string): void;
55
+ /**
56
+ * Remove a property, returning the value it had (or '' when it was not set).
57
+ * @param {string} property A CSS property name (kebab-case)
58
+ * @returns {string}
59
+ */
60
+ removeProperty(property: string): string;
61
+ /**
62
+ * All the declarations as one CSS text string.
63
+ * @returns {string}
64
+ */
65
+ get cssText(): string;
66
+ /**
67
+ * Replace every declaration by parsing a CSS text string ("color: red; font-size: 12px !important;").
68
+ * @param {string} cssText
69
+ * @returns {undefined}
70
+ */
71
+ set cssText(cssText: string);
72
+ }
73
+ export default CSSStyleDeclarationService;
@@ -0,0 +1,156 @@
1
+ 'use strict'
2
+
3
+ /**
4
+ * @file Substitute for the DOM CSSStyleDeclaration Class (the object behind Element.style).
5
+ * @author Joshua Heagle <joshuaheagle@gmail.com>
6
+ * @version 1.0.0
7
+ */
8
+ require('core-js/modules/esnext.iterator.constructor.js')
9
+ require('core-js/modules/esnext.iterator.for-each.js')
10
+ require('core-js/modules/esnext.iterator.map.js')
11
+ require('core-js/modules/esnext.map.delete-all.js')
12
+ require('core-js/modules/esnext.map.every.js')
13
+ require('core-js/modules/esnext.map.filter.js')
14
+ require('core-js/modules/esnext.map.find.js')
15
+ require('core-js/modules/esnext.map.find-key.js')
16
+ require('core-js/modules/esnext.map.includes.js')
17
+ require('core-js/modules/esnext.map.key-of.js')
18
+ require('core-js/modules/esnext.map.map-keys.js')
19
+ require('core-js/modules/esnext.map.map-values.js')
20
+ require('core-js/modules/esnext.map.merge.js')
21
+ require('core-js/modules/esnext.map.reduce.js')
22
+ require('core-js/modules/esnext.map.some.js')
23
+ require('core-js/modules/esnext.map.update.js')
24
+ Object.defineProperty(exports, '__esModule', {
25
+ value: true
26
+ })
27
+ exports.CSSStyleDeclarationService = void 0
28
+ /**
29
+ * Simulate the behaviour of the CSSStyleDeclaration Class when there is no DOM available: an ordered map of CSS
30
+ * property/value pairs, parsed from and serialized back to a cssText string. Values are stored and returned as
31
+ * given, with no unit conversion, shorthand expansion or validation - this is a data structure, not a real CSS
32
+ * engine. Named property access (declaration.backgroundColor, camelCase) is added on top of this by
33
+ * createStyleDeclaration, which wraps an instance of this class in a Proxy.
34
+ * @author Joshua Heagle <joshuaheagle@gmail.com>
35
+ * @class
36
+ */
37
+ class CSSStyleDeclarationService {
38
+ /**
39
+ * @param {string} [cssText=''] Initial declarations, as CSS text ("color: red; font-size: 12px;")
40
+ * @constructor
41
+ */
42
+ constructor (cssText = '') {
43
+ this.properties = new Map()
44
+ this.cssText = cssText
45
+ }
46
+
47
+ /**
48
+ * How many properties are currently set.
49
+ * @returns {number}
50
+ */
51
+ get length () {
52
+ return this.properties.size
53
+ }
54
+
55
+ /**
56
+ * The name of the property at the given index, in the order it was set, or '' when there is none (matches the
57
+ * DOM's CSSStyleDeclaration, which is array-like).
58
+ * @param {number} index
59
+ * @returns {string}
60
+ */
61
+ item (index) {
62
+ return Array.from(this.properties.keys())[index] || ''
63
+ }
64
+
65
+ /**
66
+ * The value of the given property, or '' when it is not set.
67
+ * @param {string} property A CSS property name (kebab-case, e.g. "background-color")
68
+ * @returns {string}
69
+ */
70
+ getPropertyValue (property) {
71
+ const entry = this.properties.get(property)
72
+ return entry ? entry.value : ''
73
+ }
74
+
75
+ /**
76
+ * "important" when the property was set with !important, otherwise ''.
77
+ * @param {string} property A CSS property name (kebab-case)
78
+ * @returns {string}
79
+ */
80
+ getPropertyPriority (property) {
81
+ const entry = this.properties.get(property)
82
+ return entry ? entry.priority : ''
83
+ }
84
+
85
+ /**
86
+ * Set a property's value (and optionally its priority). An empty, null or undefined value removes the property
87
+ * instead, like the DOM.
88
+ * @param {string} property A CSS property name (kebab-case)
89
+ * @param {string} value The value, or '' to remove the property
90
+ * @param {string} [priority=''] "important" to mark it !important
91
+ * @returns {undefined}
92
+ */
93
+ setProperty (property, value, priority = '') {
94
+ if (value === '' || value === null || typeof value === 'undefined') {
95
+ this.removeProperty(property)
96
+ return
97
+ }
98
+ this.properties.set(property, {
99
+ value: String(value),
100
+ priority
101
+ })
102
+ }
103
+
104
+ /**
105
+ * Remove a property, returning the value it had (or '' when it was not set).
106
+ * @param {string} property A CSS property name (kebab-case)
107
+ * @returns {string}
108
+ */
109
+ removeProperty (property) {
110
+ const value = this.getPropertyValue(property)
111
+ this.properties.delete(property)
112
+ return value
113
+ }
114
+
115
+ /**
116
+ * All the declarations as one CSS text string.
117
+ * @returns {string}
118
+ */
119
+ get cssText () {
120
+ return Array.from(this.properties.entries()).map(([property, {
121
+ value,
122
+ priority
123
+ }]) => `${property}: ${value}${priority ? ` !${priority}` : ''};`).join(' ')
124
+ }
125
+
126
+ /**
127
+ * Replace every declaration by parsing a CSS text string ("color: red; font-size: 12px !important;").
128
+ * @param {string} cssText
129
+ * @returns {undefined}
130
+ */
131
+ set cssText (cssText) {
132
+ this.properties.clear()
133
+ String(cssText || '').split(';').forEach(declaration => {
134
+ const colon = declaration.indexOf(':')
135
+ if (colon < 0) {
136
+ return
137
+ }
138
+ const property = declaration.slice(0, colon).trim()
139
+ let value = declaration.slice(colon + 1).trim()
140
+ let priority = ''
141
+ const important = value.match(/!\s*important\s*$/i)
142
+ if (important && typeof important.index === 'number') {
143
+ priority = 'important'
144
+ value = value.slice(0, important.index).trim()
145
+ }
146
+ if (property && value) {
147
+ this.properties.set(property, {
148
+ value,
149
+ priority
150
+ })
151
+ }
152
+ })
153
+ }
154
+ }
155
+ exports.CSSStyleDeclarationService = CSSStyleDeclarationService
156
+ exports.default = CSSStyleDeclarationService
@@ -0,0 +1 @@
1
+ "use strict";require("core-js/modules/esnext.iterator.constructor.js"),require("core-js/modules/esnext.iterator.for-each.js"),require("core-js/modules/esnext.iterator.map.js"),require("core-js/modules/esnext.map.delete-all.js"),require("core-js/modules/esnext.map.every.js"),require("core-js/modules/esnext.map.filter.js"),require("core-js/modules/esnext.map.find.js"),require("core-js/modules/esnext.map.find-key.js"),require("core-js/modules/esnext.map.includes.js"),require("core-js/modules/esnext.map.key-of.js"),require("core-js/modules/esnext.map.map-keys.js"),require("core-js/modules/esnext.map.map-values.js"),require("core-js/modules/esnext.map.merge.js"),require("core-js/modules/esnext.map.reduce.js"),require("core-js/modules/esnext.map.some.js"),require("core-js/modules/esnext.map.update.js"),Object.defineProperty(exports,"__esModule",{value:!0}),exports.CSSStyleDeclarationService=void 0;class CSSStyleDeclarationService{constructor(e=""){this.properties=new Map,this.cssText=e}get length(){return this.properties.size}item(e){return Array.from(this.properties.keys())[e]||""}getPropertyValue(e){const r=this.properties.get(e);return r?r.value:""}getPropertyPriority(e){const r=this.properties.get(e);return r?r.priority:""}setProperty(e,r,s=""){""!==r&&null!=r?this.properties.set(e,{value:String(r),priority:s}):this.removeProperty(e)}removeProperty(e){const r=this.getPropertyValue(e);return this.properties.delete(e),r}get cssText(){return Array.from(this.properties.entries()).map(([e,{value:r,priority:s}])=>`${e}: ${r}${s?` !${s}`:""};`).join(" ")}set cssText(e){this.properties.clear(),String(e||"").split(";").forEach(e=>{const r=e.indexOf(":");if(r<0)return;const s=e.slice(0,r).trim();let t=e.slice(r+1).trim(),o="";const i=t.match(/!\s*important\s*$/i);i&&"number"==typeof i.index&&(o="important",t=t.slice(0,i.index).trim()),s&&t&&this.properties.set(s,{value:t,priority:o})})}}exports.CSSStyleDeclarationService=CSSStyleDeclarationService,exports.default=CSSStyleDeclarationService;
@@ -1,5 +1,6 @@
1
1
  import { NodeService } from './NodeService';
2
2
  import { PseudoDocumentFragment } from '../interfaces/PseudoDocumentFragment';
3
+ import { PseudoElement } from '../interfaces/PseudoElement';
3
4
  /**
4
5
  * Simulate the behaviour of the DocumentFragment Class when there is no DOM available: a container for nodes which is
5
6
  * not part of a tree, when it is inserted its children are moved into the tree instead.
@@ -10,4 +11,11 @@ import { PseudoDocumentFragment } from '../interfaces/PseudoDocumentFragment';
10
11
  export declare class DocumentFragmentService extends NodeService implements PseudoDocumentFragment {
11
12
  get nodeName(): string;
12
13
  get nodeType(): number;
14
+ /**
15
+ * The first element, in tree order, whose id matches the given value, or null when there is none (the DOM's
16
+ * NonElementParentNode mixin, which Document and DocumentFragment both implement).
17
+ * @param {string} id
18
+ * @returns {PseudoElement|null}
19
+ */
20
+ getElementById(id: string): PseudoElement | null;
13
21
  }
@@ -1,10 +1,18 @@
1
1
  'use strict'
2
2
 
3
+ const __importDefault = void 0 && (void 0).__importDefault || function (mod) {
4
+ return mod && mod.__esModule
5
+ ? mod
6
+ : {
7
+ default: mod
8
+ }
9
+ }
3
10
  Object.defineProperty(exports, '__esModule', {
4
11
  value: true
5
12
  })
6
13
  exports.DocumentFragmentService = void 0
7
14
  const NodeService_1 = require('./NodeService')
15
+ const getElementById_1 = __importDefault(require('../functions/getElementById'))
8
16
  /**
9
17
  * Simulate the behaviour of the DocumentFragment Class when there is no DOM available: a container for nodes which is
10
18
  * not part of a tree, when it is inserted its children are moved into the tree instead.
@@ -20,5 +28,15 @@ class DocumentFragmentService extends NodeService_1.NodeService {
20
28
  get nodeType () {
21
29
  return NodeService_1.NodeService.DOCUMENT_FRAGMENT_NODE
22
30
  }
31
+
32
+ /**
33
+ * The first element, in tree order, whose id matches the given value, or null when there is none (the DOM's
34
+ * NonElementParentNode mixin, which Document and DocumentFragment both implement).
35
+ * @param {string} id
36
+ * @returns {PseudoElement|null}
37
+ */
38
+ getElementById (id) {
39
+ return (0, getElementById_1.default)(this, id)
40
+ }
23
41
  }
24
42
  exports.DocumentFragmentService = DocumentFragmentService
@@ -1 +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{get nodeName(){return"#document-fragment"}get nodeType(){return NodeService_1.NodeService.DOCUMENT_FRAGMENT_NODE}}exports.DocumentFragmentService=DocumentFragmentService;
1
+ "use strict";var __importDefault=function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.DocumentFragmentService=void 0;const NodeService_1=require("./NodeService"),getElementById_1=__importDefault(require("../functions/getElementById"));class DocumentFragmentService extends NodeService_1.NodeService{get nodeName(){return"#document-fragment"}get nodeType(){return NodeService_1.NodeService.DOCUMENT_FRAGMENT_NODE}getElementById(e){return(0,getElementById_1.default)(this,e)}}exports.DocumentFragmentService=DocumentFragmentService;
@@ -1,19 +1,46 @@
1
- import { NodeService } from './NodeService';
2
- import { PseudoDocument } from '../interfaces/PseudoDocument';
3
- import { PseudoElement } from '../interfaces/PseudoElement';
4
- /**
5
- * Simulate the behaviour of the Document Class when there is no DOM available.
6
- * @author Joshua Heagle <joshuaheagle@gmail.com>
7
- * @class
8
- * @augments NodeService
9
- */
10
- export declare class DocumentService extends NodeService implements PseudoDocument {
11
- get nodeName(): string;
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;
19
- }
1
+ import { NodeService, TextService, CommentService } from './NodeService';
2
+ import { PseudoDocument } from '../interfaces/PseudoDocument';
3
+ import { PseudoElement } from '../interfaces/PseudoElement';
4
+ import { DocumentFragmentService } from './DocumentFragmentService';
5
+ /**
6
+ * Simulate the behaviour of the Document Class when there is no DOM available.
7
+ * @author Joshua Heagle <joshuaheagle@gmail.com>
8
+ * @class
9
+ * @augments NodeService
10
+ */
11
+ export declare class DocumentService extends NodeService implements PseudoDocument {
12
+ get nodeName(): string;
13
+ get nodeType(): number;
14
+ get textContent(): string | null;
15
+ set textContent(text: string | null);
16
+ /**
17
+ * The first element, in tree order, whose id matches the given value, or null when there is none.
18
+ * @param {string} id
19
+ * @returns {PseudoElement|null}
20
+ */
21
+ getElementById(id: string): PseudoElement | null;
22
+ /**
23
+ * Make an element of the given type which belongs to this document but is not added anywhere until it is appended.
24
+ * @param {string} [tagName='div'] The type of element to create
25
+ * @returns {PseudoElement}
26
+ */
27
+ createElement(tagName?: string): PseudoElement;
28
+ /**
29
+ * Make a text node which belongs to this document.
30
+ * @param {string} [data=''] The text
31
+ * @returns {TextService}
32
+ */
33
+ createTextNode(data?: string): TextService;
34
+ /**
35
+ * Make a comment which belongs to this document.
36
+ * @param {string} [data=''] The comment
37
+ * @returns {CommentService}
38
+ */
39
+ createComment(data?: string): CommentService;
40
+ /**
41
+ * Make an empty document fragment which belongs to this document, a container for nodes which can be built up and
42
+ * then inserted in one go.
43
+ * @returns {DocumentFragmentService}
44
+ */
45
+ createDocumentFragment(): DocumentFragmentService;
46
+ }
@@ -1,46 +1,95 @@
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
- /**
9
- * Simulate the behaviour of the Document Class when there is no DOM available.
10
- * @author Joshua Heagle <joshuaheagle@gmail.com>
11
- * @class
12
- * @augments NodeService
13
- */
14
- class DocumentService extends NodeService_1.NodeService {
15
- get nodeName () {
16
- return '#document'
17
- }
18
-
19
- get nodeType () {
20
- return NodeService_1.NodeService.DOCUMENT_NODE
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
- }
45
- }
46
- 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 +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}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;
1
+ "use strict";var __importDefault=function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.DocumentService=void 0;const NodeService_1=require("./NodeService"),HTMLElementService_1=require("./HTMLElementService"),DocumentFragmentService_1=require("./DocumentFragmentService"),getElementById_1=__importDefault(require("../functions/getElementById"));class DocumentService extends NodeService_1.NodeService{get nodeName(){return"#document"}get nodeType(){return NodeService_1.NodeService.DOCUMENT_NODE}get textContent(){return null}set textContent(e){}getElementById(e){return(0,getElementById_1.default)(this,e)}createElement(e="div"){const t=new HTMLElementService_1.HTMLElementService({tagName:e});return t.ownerDocumentStore=this,t}createTextNode(e=""){const t=new NodeService_1.TextService(e);return t.ownerDocumentStore=this,t}createComment(e=""){const t=new NodeService_1.CommentService(e);return t.ownerDocumentStore=this,t}createDocumentFragment(){const e=new DocumentFragmentService_1.DocumentFragmentService;return e.ownerDocumentStore=this,e}}exports.DocumentService=DocumentService;