@antv/g 5.0.15 → 5.0.16

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 (224) hide show
  1. package/dist/index.umd.min.js +18 -2
  2. package/es/Canvas.d.ts +3 -0
  3. package/es/Canvas.js +8 -9
  4. package/es/camera/Camera.d.ts +3 -2
  5. package/es/camera/Camera.js +16 -8
  6. package/es/canvas-module.js +4 -2
  7. package/es/components/Transform.d.ts +0 -1
  8. package/es/components/Transform.js +0 -1
  9. package/es/display-objects/Circle.d.ts +1 -1
  10. package/es/display-objects/Circle.js +8 -3
  11. package/es/display-objects/CustomElement.d.ts +3 -2
  12. package/es/display-objects/CustomElement.js +9 -6
  13. package/es/display-objects/DisplayObject.d.ts +4 -3
  14. package/es/display-objects/DisplayObject.js +77 -50
  15. package/es/display-objects/Ellipse.d.ts +1 -1
  16. package/es/display-objects/Ellipse.js +8 -3
  17. package/es/display-objects/Group.d.ts +18 -2
  18. package/es/display-objects/Group.js +11 -9
  19. package/es/display-objects/HTML.d.ts +1 -1
  20. package/es/display-objects/HTML.js +9 -4
  21. package/es/display-objects/Image.d.ts +5 -3
  22. package/es/display-objects/Image.js +8 -3
  23. package/es/display-objects/Line.d.ts +1 -1
  24. package/es/display-objects/Line.js +12 -4
  25. package/es/display-objects/Path.d.ts +3 -2
  26. package/es/display-objects/Path.js +10 -5
  27. package/es/display-objects/Polygon.d.ts +1 -1
  28. package/es/display-objects/Polygon.js +9 -3
  29. package/es/display-objects/Polyline.d.ts +1 -1
  30. package/es/display-objects/Polyline.js +10 -5
  31. package/es/display-objects/Rect.d.ts +1 -1
  32. package/es/display-objects/Rect.js +8 -3
  33. package/es/display-objects/Text.d.ts +9 -4
  34. package/es/display-objects/Text.js +14 -9
  35. package/es/dom/Animation.js +1 -1
  36. package/es/dom/AnimationTimeline.js +1 -2
  37. package/es/dom/CustomElementRegistry.js +12 -12
  38. package/es/dom/Document.d.ts +1 -0
  39. package/es/dom/Document.js +21 -1
  40. package/es/dom/Element.d.ts +10 -5
  41. package/es/dom/Element.js +41 -15
  42. package/es/dom/EventTarget.d.ts +2 -2
  43. package/es/dom/EventTarget.js +4 -3
  44. package/es/dom/KeyframeList.js +1 -1
  45. package/es/dom/MutationEvent.d.ts +15 -0
  46. package/es/dom/MutationEvent.js +29 -0
  47. package/es/dom/MutationObserver.d.ts +36 -0
  48. package/es/dom/MutationObserver.js +413 -0
  49. package/es/dom/MutationRecord.d.ts +14 -0
  50. package/es/dom/MutationRecord.js +31 -0
  51. package/es/dom/Node.d.ts +35 -3
  52. package/es/dom/Node.js +184 -17
  53. package/es/dom/index.d.ts +3 -0
  54. package/es/dom/index.js +3 -0
  55. package/es/dom/interfaces.d.ts +36 -8
  56. package/es/dom/interfaces.js +23 -5
  57. package/es/global-module.d.ts +1 -0
  58. package/es/global-module.js +11 -13
  59. package/es/index.d.ts +1 -0
  60. package/es/index.js +1 -0
  61. package/es/plugins/CullingPlugin.d.ts +0 -2
  62. package/es/plugins/CullingPlugin.js +3 -24
  63. package/es/plugins/DirtyCheckPlugin.js +2 -2
  64. package/es/plugins/FrustumCullingStrategy.d.ts +1 -0
  65. package/es/plugins/FrustumCullingStrategy.js +40 -33
  66. package/es/plugins/PrepareRendererPlugin.js +21 -5
  67. package/es/property-handlers/aabb.js +19 -20
  68. package/es/property-handlers/color.js +5 -2
  69. package/es/property-handlers/dimension.d.ts +15 -3
  70. package/es/property-handlers/dimension.js +50 -9
  71. package/es/property-handlers/index.d.ts +3 -0
  72. package/es/property-handlers/index.js +4 -1
  73. package/es/property-handlers/inherit.d.ts +6 -0
  74. package/es/property-handlers/inherit.js +25 -0
  75. package/es/property-handlers/interfaces.d.ts +2 -2
  76. package/es/property-handlers/lineDash.d.ts +6 -1
  77. package/es/property-handlers/lineDash.js +23 -4
  78. package/es/property-handlers/offsetDistance.js +2 -2
  79. package/es/property-handlers/text.d.ts +2 -0
  80. package/es/property-handlers/text.js +3 -0
  81. package/es/property-handlers/textTransform.d.ts +6 -0
  82. package/es/property-handlers/textTransform.js +19 -0
  83. package/es/services/EventService.js +3 -5
  84. package/es/services/RenderingContext.d.ts +5 -8
  85. package/es/services/RenderingContext.js +6 -7
  86. package/es/services/RenderingService.js +2 -8
  87. package/es/services/SceneGraphSelector.d.ts +3 -2
  88. package/es/services/SceneGraphSelector.js +8 -4
  89. package/es/services/SceneGraphService.d.ts +0 -7
  90. package/es/services/SceneGraphService.js +9 -77
  91. package/es/services/aabb/CircleUpdater.js +3 -3
  92. package/es/services/aabb/EllipseUpdater.js +2 -2
  93. package/es/services/aabb/LineUpdater.js +2 -2
  94. package/es/services/aabb/PathUpdater.js +2 -2
  95. package/es/services/aabb/PolylineUpdater.js +3 -3
  96. package/es/services/aabb/RectUpdater.js +4 -4
  97. package/es/services/aabb/TextUpdater.js +19 -10
  98. package/es/services/text/index.js +19 -21
  99. package/es/types.d.ts +48 -24
  100. package/es/types.js +50 -31
  101. package/es/utils/custom-easing.js +1 -1
  102. package/es/utils/event.js +5 -3
  103. package/es/utils/index.d.ts +1 -0
  104. package/es/utils/index.js +2 -1
  105. package/es/utils/interpolation.d.ts +1 -0
  106. package/es/utils/interpolation.js +41 -8
  107. package/es/utils/path.js +11 -11
  108. package/es/utils/raf.d.ts +1 -1
  109. package/es/utils/raf.js +0 -2
  110. package/es/utils/string.d.ts +1 -0
  111. package/es/utils/string.js +9 -0
  112. package/es/utils/text.js +3 -3
  113. package/lib/Canvas.d.ts +3 -0
  114. package/lib/Canvas.js +6 -7
  115. package/lib/camera/Camera.d.ts +3 -2
  116. package/lib/camera/Camera.js +20 -10
  117. package/lib/canvas-module.js +3 -1
  118. package/lib/components/Transform.d.ts +0 -1
  119. package/lib/components/Transform.js +0 -1
  120. package/lib/display-objects/Circle.d.ts +1 -1
  121. package/lib/display-objects/Circle.js +7 -2
  122. package/lib/display-objects/CustomElement.d.ts +3 -2
  123. package/lib/display-objects/CustomElement.js +9 -6
  124. package/lib/display-objects/DisplayObject.d.ts +4 -3
  125. package/lib/display-objects/DisplayObject.js +76 -47
  126. package/lib/display-objects/Ellipse.d.ts +1 -1
  127. package/lib/display-objects/Ellipse.js +7 -2
  128. package/lib/display-objects/Group.d.ts +18 -2
  129. package/lib/display-objects/Group.js +10 -9
  130. package/lib/display-objects/HTML.d.ts +1 -1
  131. package/lib/display-objects/HTML.js +8 -4
  132. package/lib/display-objects/Image.d.ts +5 -3
  133. package/lib/display-objects/Image.js +7 -2
  134. package/lib/display-objects/Line.d.ts +1 -1
  135. package/lib/display-objects/Line.js +11 -3
  136. package/lib/display-objects/Path.d.ts +3 -2
  137. package/lib/display-objects/Path.js +9 -4
  138. package/lib/display-objects/Polygon.d.ts +1 -1
  139. package/lib/display-objects/Polygon.js +8 -2
  140. package/lib/display-objects/Polyline.d.ts +1 -1
  141. package/lib/display-objects/Polyline.js +9 -4
  142. package/lib/display-objects/Rect.d.ts +1 -1
  143. package/lib/display-objects/Rect.js +7 -2
  144. package/lib/display-objects/Text.d.ts +9 -4
  145. package/lib/display-objects/Text.js +13 -8
  146. package/lib/dom/Animation.js +1 -1
  147. package/lib/dom/AnimationTimeline.js +1 -2
  148. package/lib/dom/CustomElementRegistry.js +11 -11
  149. package/lib/dom/Document.d.ts +1 -0
  150. package/lib/dom/Document.js +22 -1
  151. package/lib/dom/Element.d.ts +10 -5
  152. package/lib/dom/Element.js +43 -15
  153. package/lib/dom/EventTarget.d.ts +2 -2
  154. package/lib/dom/EventTarget.js +4 -3
  155. package/lib/dom/KeyframeList.js +1 -1
  156. package/lib/dom/MutationEvent.d.ts +15 -0
  157. package/lib/dom/MutationEvent.js +37 -0
  158. package/lib/dom/MutationObserver.d.ts +36 -0
  159. package/lib/dom/MutationObserver.js +424 -0
  160. package/lib/dom/MutationRecord.d.ts +14 -0
  161. package/lib/dom/MutationRecord.js +38 -0
  162. package/lib/dom/Node.d.ts +35 -3
  163. package/lib/dom/Node.js +185 -16
  164. package/lib/dom/index.d.ts +3 -0
  165. package/lib/dom/index.js +39 -0
  166. package/lib/dom/interfaces.d.ts +36 -8
  167. package/lib/dom/interfaces.js +23 -5
  168. package/lib/global-module.d.ts +1 -0
  169. package/lib/global-module.js +12 -8
  170. package/lib/index.d.ts +1 -0
  171. package/lib/index.js +3 -1
  172. package/lib/plugins/CullingPlugin.d.ts +0 -2
  173. package/lib/plugins/CullingPlugin.js +2 -23
  174. package/lib/plugins/DirtyCheckPlugin.js +1 -1
  175. package/lib/plugins/FrustumCullingStrategy.d.ts +1 -0
  176. package/lib/plugins/FrustumCullingStrategy.js +41 -33
  177. package/lib/plugins/PrepareRendererPlugin.js +24 -4
  178. package/lib/property-handlers/aabb.js +18 -19
  179. package/lib/property-handlers/color.js +6 -3
  180. package/lib/property-handlers/dimension.d.ts +15 -3
  181. package/lib/property-handlers/dimension.js +50 -8
  182. package/lib/property-handlers/index.d.ts +3 -0
  183. package/lib/property-handlers/index.js +39 -0
  184. package/lib/property-handlers/inherit.d.ts +6 -0
  185. package/lib/property-handlers/inherit.js +34 -0
  186. package/lib/property-handlers/interfaces.d.ts +2 -2
  187. package/lib/property-handlers/lineDash.d.ts +6 -1
  188. package/lib/property-handlers/lineDash.js +25 -4
  189. package/lib/property-handlers/offsetDistance.js +1 -1
  190. package/lib/property-handlers/text.d.ts +2 -0
  191. package/lib/property-handlers/text.js +10 -0
  192. package/lib/property-handlers/textTransform.d.ts +6 -0
  193. package/lib/property-handlers/textTransform.js +27 -0
  194. package/lib/services/EventService.js +3 -5
  195. package/lib/services/RenderingContext.d.ts +5 -8
  196. package/lib/services/RenderingContext.js +8 -9
  197. package/lib/services/RenderingService.js +1 -7
  198. package/lib/services/SceneGraphSelector.d.ts +3 -2
  199. package/lib/services/SceneGraphSelector.js +10 -3
  200. package/lib/services/SceneGraphService.d.ts +0 -7
  201. package/lib/services/SceneGraphService.js +10 -77
  202. package/lib/services/aabb/CircleUpdater.js +2 -2
  203. package/lib/services/aabb/EllipseUpdater.js +1 -1
  204. package/lib/services/aabb/LineUpdater.js +1 -1
  205. package/lib/services/aabb/PathUpdater.js +1 -1
  206. package/lib/services/aabb/PolylineUpdater.js +2 -2
  207. package/lib/services/aabb/RectUpdater.js +3 -3
  208. package/lib/services/aabb/TextUpdater.js +18 -9
  209. package/lib/services/text/index.js +19 -21
  210. package/lib/types.d.ts +48 -24
  211. package/lib/types.js +56 -35
  212. package/lib/utils/custom-easing.js +1 -1
  213. package/lib/utils/event.js +5 -3
  214. package/lib/utils/index.d.ts +1 -0
  215. package/lib/utils/index.js +13 -0
  216. package/lib/utils/interpolation.d.ts +1 -0
  217. package/lib/utils/interpolation.js +43 -7
  218. package/lib/utils/path.js +10 -10
  219. package/lib/utils/raf.d.ts +1 -1
  220. package/lib/utils/raf.js +0 -2
  221. package/lib/utils/string.d.ts +1 -0
  222. package/lib/utils/string.js +16 -0
  223. package/lib/utils/text.js +3 -3
  224. package/package.json +5 -3
@@ -0,0 +1,424 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.Registration = exports.MutationObserver = void 0;
7
+
8
+ require("setimmediate");
9
+
10
+ var _ = require("..");
11
+
12
+ var _MutationEvent = require("./MutationEvent");
13
+
14
+ var _MutationRecord = require("./MutationRecord");
15
+
16
+ var uidCounter = 0;
17
+ var registrationsTable = new WeakMap();
18
+
19
+ var Registration =
20
+ /** @class */
21
+ function () {
22
+ function Registration(observer, target, options) {
23
+ this.observer = observer;
24
+ this.target = target;
25
+ this.options = options;
26
+ this.transientObservedNodes = [];
27
+ }
28
+
29
+ Registration.prototype.enqueue = function (record) {
30
+ var records = this.observer.records;
31
+ var length = records.length; // There are cases where we replace the last record with the new record.
32
+ // For example if the record represents the same mutation we need to use
33
+ // the one with the oldValue. If we get same record (this can happen as we
34
+ // walk up the tree) we ignore the new record.
35
+
36
+ if (records.length > 0) {
37
+ var lastRecord = records[length - 1];
38
+ var recordToReplaceLast = selectRecord(lastRecord, record);
39
+
40
+ if (recordToReplaceLast) {
41
+ records[length - 1] = recordToReplaceLast;
42
+ return;
43
+ }
44
+ } else {
45
+ scheduleCallback(this.observer);
46
+ }
47
+
48
+ records[length] = record;
49
+ };
50
+
51
+ Registration.prototype.addListeners = function () {
52
+ this.addListeners_(this.target);
53
+ };
54
+
55
+ Registration.prototype.addListeners_ = function (node) {
56
+ var options = this.options;
57
+ if (options.attributes) node.addEventListener(_.ElementEvent.ATTR_MODIFIED, this, true); // if (options.characterData) node.addEventListener('DOMCharacterDataModified', this, true);
58
+
59
+ if (options.childList) node.addEventListener(_.ElementEvent.INSERTED, this, true);
60
+ if (options.childList || options.subtree) node.addEventListener(_.ElementEvent.REMOVED, this, true);
61
+ };
62
+
63
+ Registration.prototype.removeListeners = function () {
64
+ this.removeListeners_(this.target);
65
+ };
66
+
67
+ Registration.prototype.removeListeners_ = function (node) {
68
+ var options = this.options;
69
+ if (options.attributes) node.removeEventListener(_.ElementEvent.ATTR_MODIFIED, this, true); // if (options.characterData) node.removeEventListener('DOMCharacterDataModified', this, true);
70
+
71
+ if (options.childList) node.removeEventListener(_.ElementEvent.INSERTED, this, true);
72
+ if (options.childList || options.subtree) node.removeEventListener(_.ElementEvent.REMOVED, this, true);
73
+ };
74
+ /**
75
+ * Adds a transient observer on node. The transient observer gets removed
76
+ * next time we deliver the change records.
77
+ */
78
+ // addTransientObserver(node: IElement) {
79
+ // // Don't add transient observers on the target itself. We already have all
80
+ // // the required listeners set up on the target.
81
+ // if (node === this.target) return;
82
+ // this.addListeners_(node);
83
+ // this.transientObservedNodes.push(node);
84
+ // let registrations = registrationsTable.get(node);
85
+ // if (!registrations) registrationsTable.set(node, (registrations = []));
86
+ // // We know that registrations does not contain this because we already
87
+ // // checked if node === this.target.
88
+ // registrations.push(this);
89
+ // }
90
+
91
+
92
+ Registration.prototype.removeTransientObservers = function () {
93
+ var transientObservedNodes = this.transientObservedNodes;
94
+ this.transientObservedNodes = [];
95
+ transientObservedNodes.forEach(function (node) {
96
+ // Transient observers are never added to the target.
97
+ this.removeListeners_(node);
98
+ var registrations = registrationsTable.get(node);
99
+
100
+ for (var i = 0; i < registrations.length; i++) {
101
+ if (registrations[i] === this) {
102
+ registrations.splice(i, 1); // Each node can only have one registered observer associated with
103
+ // this observer.
104
+
105
+ break;
106
+ }
107
+ }
108
+ }, this);
109
+ };
110
+
111
+ Registration.prototype.handleEvent = function (e) {
112
+ // Stop propagation since we are managing the propagation manually.
113
+ // This means that other mutation events on the page will not work
114
+ // correctly but that is by design.
115
+ e.stopImmediatePropagation();
116
+ var record;
117
+ var target;
118
+
119
+ switch (e.type) {
120
+ case _.ElementEvent.ATTR_MODIFIED:
121
+ // http://dom.spec.whatwg.org/#concept-mo-queue-attributes
122
+ var name_1 = e.attrName; // @ts-ignore
123
+
124
+ var namespace_1 = e.relatedNode.namespaceURI;
125
+ target = e.target; // 1.
126
+
127
+ record = getRecord('attributes', target);
128
+ record.attributeName = name_1;
129
+ record.attributeNamespace = namespace_1; // 2.
130
+
131
+ var oldValue_1 = e.attrChange === _MutationEvent.MutationEvent.ADDITION ? null : e.prevValue;
132
+ forEachAncestorAndObserverEnqueueRecord(target, function (options) {
133
+ // 3.1, 4.2
134
+ if (!options.attributes) return; // 3.2, 4.3
135
+
136
+ if (options.attributeFilter && options.attributeFilter.length && options.attributeFilter.indexOf(name_1) === -1 && options.attributeFilter.indexOf(namespace_1) === -1) {
137
+ return;
138
+ } // 3.3, 4.4
139
+
140
+
141
+ if (options.attributeOldValue) return getRecordWithOldValue(oldValue_1); // 3.4, 4.5
142
+
143
+ return record;
144
+ });
145
+ break;
146
+ // case 'DOMCharacterDataModified':
147
+ // // http://dom.spec.whatwg.org/#concept-mo-queue-characterdata
148
+ // var target = e.target;
149
+ // // 1.
150
+ // var record = getRecord('characterData', target);
151
+ // // 2.
152
+ // var oldValue = e.prevValue;
153
+ // forEachAncestorAndObserverEnqueueRecord(target, function(options) {
154
+ // // 3.1, 4.2
155
+ // if (!options.characterData)
156
+ // return;
157
+ // // 3.2, 4.3
158
+ // if (options.characterDataOldValue)
159
+ // return getRecordWithOldValue(oldValue);
160
+ // // 3.3, 4.4
161
+ // return record;
162
+ // });
163
+ // break;
164
+
165
+ case _.ElementEvent.REMOVED: // this.addTransientObserver(e.target as IElement);
166
+ // Fall through.
167
+
168
+ case _.ElementEvent.INSERTED:
169
+ // http://dom.spec.whatwg.org/#concept-mo-queue-childlist
170
+ target = e.relatedNode;
171
+ var changedNode = e.target;
172
+ var addedNodes = void 0;
173
+ var removedNodes = void 0;
174
+
175
+ if (e.type === _.ElementEvent.INSERTED) {
176
+ addedNodes = [changedNode];
177
+ removedNodes = [];
178
+ } else {
179
+ addedNodes = [];
180
+ removedNodes = [changedNode];
181
+ }
182
+
183
+ var previousSibling = changedNode.previousSibling;
184
+ var nextSibling = changedNode.nextSibling; // 1.
185
+
186
+ record = getRecord('childList', target);
187
+ record.addedNodes = addedNodes;
188
+ record.removedNodes = removedNodes;
189
+ record.previousSibling = previousSibling;
190
+ record.nextSibling = nextSibling;
191
+ forEachAncestorAndObserverEnqueueRecord(target, function (options) {
192
+ // 2.1, 3.2
193
+ if (!options.childList) return; // 2.2, 3.3
194
+
195
+ return record;
196
+ });
197
+ }
198
+
199
+ clearRecords();
200
+ };
201
+
202
+ return Registration;
203
+ }();
204
+
205
+ exports.Registration = Registration;
206
+
207
+ /**
208
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/MutationObserver
209
+ * @see https://github.com/googlearchive/MutationObservers/blob/master/MutationObserver.js
210
+ */
211
+ var MutationObserver =
212
+ /** @class */
213
+ function () {
214
+ function MutationObserver(callback) {
215
+ this.callback = callback;
216
+ this.nodes = [];
217
+ this.records = [];
218
+ this.uid = uidCounter++;
219
+ }
220
+
221
+ MutationObserver.prototype.observe = function (target, options) {
222
+ // 1.1
223
+ if (!options.childList && !options.attributes && !options.characterData || // 1.2
224
+ options.attributeOldValue && !options.attributes || // 1.3
225
+ options.attributeFilter && options.attributeFilter.length && !options.attributes || // 1.4
226
+ options.characterDataOldValue && !options.characterData) {
227
+ throw new SyntaxError();
228
+ }
229
+
230
+ var registrations = registrationsTable.get(target);
231
+ if (!registrations) registrationsTable.set(target, registrations = []); // 2
232
+ // If target's list of registered observers already includes a registered
233
+ // observer associated with the context object, replace that registered
234
+ // observer's options with options.
235
+
236
+ var registration;
237
+
238
+ for (var i = 0; i < registrations.length; i++) {
239
+ if (registrations[i].observer === this) {
240
+ registration = registrations[i];
241
+ registration.removeListeners();
242
+ registration.options = options;
243
+ break;
244
+ }
245
+ } // 3.
246
+ // Otherwise, add a new registered observer to target's list of registered
247
+ // observers with the context object as the observer and options as the
248
+ // options, and add target to context object's list of nodes on which it
249
+ // is registered.
250
+
251
+
252
+ if (!registration) {
253
+ registration = new Registration(this, target, options);
254
+ registrations.push(registration);
255
+ this.nodes.push(target);
256
+ }
257
+
258
+ registration.addListeners();
259
+ };
260
+
261
+ MutationObserver.prototype.disconnect = function () {
262
+ var _this = this;
263
+
264
+ this.nodes.forEach(function (node) {
265
+ var registrations = registrationsTable.get(node);
266
+
267
+ for (var i = 0; i < registrations.length; i++) {
268
+ var registration = registrations[i];
269
+
270
+ if (registration.observer === _this) {
271
+ registration.removeListeners();
272
+ registrations.splice(i, 1); // Each node can only have one registered observer associated with
273
+ // this observer.
274
+
275
+ break;
276
+ }
277
+ }
278
+ }, this);
279
+ this.records = [];
280
+ };
281
+
282
+ MutationObserver.prototype.takeRecords = function () {
283
+ var copyOfRecords = this.records;
284
+ this.records = [];
285
+ return copyOfRecords;
286
+ };
287
+
288
+ return MutationObserver;
289
+ }();
290
+
291
+ exports.MutationObserver = MutationObserver;
292
+ // We keep track of the two (possibly one) records used in a single mutation.
293
+ var currentRecord;
294
+ var recordWithOldValue;
295
+ /**
296
+ * Creates a record without |oldValue| and caches it as |currentRecord| for
297
+ * later use.
298
+ */
299
+
300
+ function getRecord(type, target) {
301
+ return currentRecord = new _MutationRecord.MutationRecord(type, target);
302
+ }
303
+ /**
304
+ * Gets or creates a record with |oldValue| based in the |currentRecord|
305
+ */
306
+
307
+
308
+ function getRecordWithOldValue(oldValue) {
309
+ if (recordWithOldValue) return recordWithOldValue;
310
+ recordWithOldValue = _MutationRecord.MutationRecord.copy(currentRecord);
311
+ recordWithOldValue.oldValue = oldValue;
312
+ return recordWithOldValue;
313
+ }
314
+
315
+ function clearRecords() {
316
+ currentRecord = recordWithOldValue = undefined;
317
+ }
318
+ /**
319
+ * Whether the record represents a record from the current
320
+ * mutation event.
321
+ */
322
+
323
+
324
+ function recordRepresentsCurrentMutation(record) {
325
+ return record === recordWithOldValue || record === currentRecord;
326
+ }
327
+ /**
328
+ * Selects which record, if any, to replace the last record in the queue.
329
+ * This returns |null| if no record should be replaced.
330
+ */
331
+
332
+
333
+ function selectRecord(lastRecord, newRecord) {
334
+ if (lastRecord === newRecord) return lastRecord; // Check if the the record we are adding represents the same record. If
335
+ // so, we keep the one with the oldValue in it.
336
+
337
+ if (recordWithOldValue && recordRepresentsCurrentMutation(lastRecord)) return recordWithOldValue;
338
+ return null;
339
+ }
340
+
341
+ function removeTransientObserversFor(observer) {
342
+ observer.nodes.forEach(function (node) {
343
+ var registrations = registrationsTable.get(node);
344
+ if (!registrations) return;
345
+ registrations.forEach(function (registration) {
346
+ if (registration.observer === observer) registration.removeTransientObservers();
347
+ });
348
+ });
349
+ }
350
+ /**
351
+ * This function is used for the "For each registered observer observer (with
352
+ * observer's options as options) in target's list of registered observers,
353
+ * run these substeps:" and the "For each ancestor ancestor of target, and for
354
+ * each registered observer observer (with options options) in ancestor's list
355
+ * of registered observers, run these substeps:" part of the algorithms. The
356
+ * |options.subtree| is checked to ensure that the callback is called
357
+ * correctly.
358
+ *
359
+ * @param {Node} target
360
+ * @param {function(MutationObserverInit):MutationRecord} callback
361
+ */
362
+
363
+
364
+ function forEachAncestorAndObserverEnqueueRecord(target, callback) {
365
+ for (var node = target; node; node = node.parentNode) {
366
+ var registrations = registrationsTable.get(node);
367
+
368
+ if (registrations) {
369
+ for (var j = 0; j < registrations.length; j++) {
370
+ var registration = registrations[j];
371
+ var options = registration.options; // Only target ignores subtree.
372
+
373
+ if (node !== target && !options.subtree) continue;
374
+ var record = callback(options);
375
+ if (record) registration.enqueue(record);
376
+ }
377
+ }
378
+ }
379
+ } // This is used to ensure that we never schedule 2 callas to setImmediate
380
+
381
+
382
+ var isScheduled = false; // Keep track of observers that needs to be notified next time.
383
+
384
+ var scheduledObservers = [];
385
+ /**
386
+ * Schedules |dispatchCallback| to be called in the future.
387
+ */
388
+
389
+ function scheduleCallback(observer) {
390
+ scheduledObservers.push(observer);
391
+
392
+ if (!isScheduled) {
393
+ isScheduled = true; // @ts-ignore
394
+
395
+ setImmediate(dispatchCallbacks);
396
+ }
397
+ }
398
+
399
+ function dispatchCallbacks() {
400
+ // http://dom.spec.whatwg.org/#mutation-observers
401
+ isScheduled = false; // Used to allow a new setImmediate call above.
402
+
403
+ var observers = scheduledObservers;
404
+ scheduledObservers = []; // Sort observers based on their creation UID (incremental).
405
+
406
+ observers.sort(function (o1, o2) {
407
+ return o1.uid - o2.uid;
408
+ });
409
+ var anyNonEmpty = false;
410
+ observers.forEach(function (observer) {
411
+ // 2.1, 2.2
412
+ var queue = observer.takeRecords(); // 2.3. Remove all transient registered observers whose observer is mo.
413
+
414
+ removeTransientObserversFor(observer); // 2.4
415
+
416
+ if (queue.length) {
417
+ // @ts-ignore
418
+ observer.callback(queue, observer);
419
+ anyNonEmpty = true;
420
+ }
421
+ }); // 3.
422
+
423
+ if (anyNonEmpty) dispatchCallbacks();
424
+ }
@@ -0,0 +1,14 @@
1
+ import type { IElement } from '..';
2
+ export declare class MutationRecord {
3
+ type: MutationRecordType;
4
+ target: IElement;
5
+ static copy(original: MutationRecord): MutationRecord;
6
+ addedNodes: IElement[];
7
+ attributeName: string;
8
+ attributeNamespace: string;
9
+ nextSibling: IElement;
10
+ oldValue: string;
11
+ previousSibling: IElement;
12
+ removedNodes: IElement[];
13
+ constructor(type: MutationRecordType, target: IElement);
14
+ }
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.MutationRecord = void 0;
7
+
8
+ var MutationRecord =
9
+ /** @class */
10
+ function () {
11
+ function MutationRecord(type, target) {
12
+ this.type = type;
13
+ this.target = target;
14
+ this.addedNodes = [];
15
+ this.attributeName = null;
16
+ this.attributeNamespace = null;
17
+ this.nextSibling = null;
18
+ this.oldValue = null;
19
+ this.previousSibling = null;
20
+ this.removedNodes = [];
21
+ }
22
+
23
+ MutationRecord.copy = function (original) {
24
+ var record = new MutationRecord(original.type, original.target);
25
+ record.addedNodes = original.addedNodes.slice();
26
+ record.removedNodes = original.removedNodes.slice();
27
+ record.previousSibling = original.previousSibling;
28
+ record.nextSibling = original.nextSibling;
29
+ record.attributeName = original.attributeName;
30
+ record.attributeNamespace = original.attributeNamespace;
31
+ record.oldValue = original.oldValue;
32
+ return record;
33
+ };
34
+
35
+ return MutationRecord;
36
+ }();
37
+
38
+ exports.MutationRecord = MutationRecord;
package/lib/dom/Node.d.ts CHANGED
@@ -4,6 +4,31 @@ import type { IEventTarget, IElement, INode, IChildNode, IParentNode, IDocument
4
4
  * @see https://developer.mozilla.org/en-US/docs/Web/API/Node
5
5
  */
6
6
  export declare abstract class Node extends EventTarget implements INode {
7
+ /**
8
+ * Both nodes are in different documents or different trees in the same document.
9
+ */
10
+ static DOCUMENT_POSITION_DISCONNECTED: number;
11
+ /**
12
+ * otherNode precedes the node in either a pre-order depth-first traversal
13
+ * of a tree containing both (e.g., as an ancestor or previous sibling or a descendant of a previous sibling or previous sibling of an ancestor) or (if they are disconnected) in an arbitrary but consistent ordering.
14
+ */
15
+ static DOCUMENT_POSITION_PRECEDING: number;
16
+ /**
17
+ * otherNode follows the node in either a pre-order depth-first traversal of a tree containing both (e.g., as a descendant or following sibling or a descendant of a following sibling or following sibling of an ancestor) or (if they are disconnected) in an arbitrary but consistent ordering.
18
+ */
19
+ static DOCUMENT_POSITION_FOLLOWING: number;
20
+ /**
21
+ * otherNode is an ancestor of the node.
22
+ */
23
+ static DOCUMENT_POSITION_CONTAINS: number;
24
+ /**
25
+ * otherNode is a descendant of the node.
26
+ */
27
+ static DOCUMENT_POSITION_CONTAINED_BY: number;
28
+ /**
29
+ * The result relies upon arbitrary and/or implementation-specific behavior and is not guaranteed to be portable.
30
+ */
31
+ static DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC: number;
7
32
  static isNode(target: IEventTarget | INode): target is INode;
8
33
  shadow: boolean;
9
34
  /**
@@ -44,14 +69,16 @@ export declare abstract class Node extends EventTarget implements INode {
44
69
  /**
45
70
  * @see https://developer.mozilla.org/zh-CN/docs/Web/API/Node/textContent
46
71
  */
47
- textContent: string | null;
72
+ get textContent(): string;
73
+ set textContent(content: string);
48
74
  /**
49
75
  * @see https://developer.mozilla.org/zh-CN/docs/Web/API/Node/getRootNode
50
76
  */
51
- getRootNode(): INode;
77
+ getRootNode(opts?: {
78
+ composed?: boolean;
79
+ }): INode;
52
80
  hasChildNodes(): boolean;
53
81
  isDefaultNamespace(namespace: string | null): boolean;
54
- compareDocumentPosition(other: INode): number;
55
82
  lookupNamespaceURI(prefix: string | null): string | null;
56
83
  lookupPrefix(namespace: string | null): string | null;
57
84
  normalize(): void;
@@ -74,6 +101,11 @@ export declare abstract class Node extends EventTarget implements INode {
74
101
  get previousSibling(): IChildNode | null;
75
102
  get firstChild(): IChildNode | null;
76
103
  get lastChild(): IChildNode | null;
104
+ /**
105
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/Node/compareDocumentPosition
106
+ * @see https://github.com/b-fuze/deno-dom/blob/master/src/dom/node.ts#L338
107
+ */
108
+ compareDocumentPosition(other: INode): number;
77
109
  /**
78
110
  * @see https://developer.mozilla.org/en-US/docs/Web/API/Node/cloneNode
79
111
  */