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