@highlight-run/rrweb 1.2.1 → 2.0.4
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/plugins/console-record.js +454 -0
- package/dist/plugins/console-record.min.js +12 -15
- package/dist/plugins/console-record.min.js.map +1 -1
- package/dist/plugins/console-replay.js +164 -0
- package/dist/plugins/console-replay.min.js +5 -0
- package/dist/plugins/console-replay.min.js.map +1 -0
- package/dist/plugins/sequential-id-record.js +30 -0
- package/dist/plugins/sequential-id-record.min.js +2 -0
- package/dist/plugins/sequential-id-record.min.js.map +1 -0
- package/dist/plugins/sequential-id-replay.js +33 -0
- package/dist/plugins/sequential-id-replay.min.js +2 -0
- package/dist/plugins/sequential-id-replay.min.js.map +1 -0
- package/dist/record/rrweb-record-pack.js +664 -0
- package/dist/record/rrweb-record-pack.min.js +4 -0
- package/dist/record/rrweb-record-pack.min.js.map +1 -0
- package/dist/record/rrweb-record.js +3202 -0
- package/dist/record/rrweb-record.min.js +5 -0
- package/dist/record/rrweb-record.min.js.map +1 -0
- package/dist/replay/rrweb-replay-unpack.js +4926 -0
- package/dist/replay/rrweb-replay-unpack.min.js +18 -0
- package/dist/replay/rrweb-replay-unpack.min.js.map +1 -0
- package/dist/replay/rrweb-replay.js +4518 -0
- package/dist/replay/rrweb-replay.min.js +18 -0
- package/dist/replay/rrweb-replay.min.js.map +1 -0
- package/dist/rrweb-all.js +8889 -0
- package/dist/rrweb-all.min.js +29 -0
- package/dist/rrweb-all.min.js.map +1 -0
- package/dist/rrweb.js +7558 -0
- package/dist/rrweb.min.js +6 -17
- package/dist/rrweb.min.js.map +1 -1
- package/es/rrweb/_virtual/_rollup-plugin-web-worker-loader__helper__auto__createBase64WorkerFactory.js +12 -0
- package/es/rrweb/_virtual/_rollup-plugin-web-worker-loader__helper__auto__isNodeJS.js +7 -0
- package/es/rrweb/_virtual/_rollup-plugin-web-worker-loader__helper__browser__createBase64WorkerFactory.js +31 -0
- package/es/rrweb/_virtual/_rollup-plugin-web-worker-loader__helper__node__WorkerClass.js +11 -0
- package/es/rrweb/_virtual/_rollup-plugin-web-worker-loader__helper__node__createBase64WorkerFactory.js +18 -0
- package/es/rrweb/_virtual/image-bitmap-data-url-worker.js +6 -0
- package/es/rrweb/ext/@xstate/fsm/es/index.js +17 -0
- package/es/rrweb/ext/base64-arraybuffer/dist/base64-arraybuffer.es5.js +49 -0
- package/es/rrweb/ext/fflate/esm/browser.js +777 -0
- package/es/rrweb/ext/mitt/dist/mitt.es.js +63 -0
- package/es/rrweb/ext/tslib/tslib.es6.js +38 -0
- package/es/rrweb/packages/rrdom/es/virtual-dom.js +1099 -0
- package/es/rrweb/packages/rrweb/src/entries/all.js +13 -0
- package/es/rrweb/packages/rrweb/src/index.js +14 -0
- package/es/rrweb/packages/rrweb/src/packer/base.js +3 -0
- package/es/rrweb/packages/rrweb/src/packer/pack.js +9 -0
- package/es/rrweb/packages/rrweb/src/packer/unpack.js +29 -0
- package/es/rrweb/packages/rrweb/src/plugins/console/record/error-stack-parser.js +178 -0
- package/es/rrweb/packages/rrweb/src/plugins/console/record/index.js +115 -0
- package/es/rrweb/packages/rrweb/src/plugins/console/record/stringify.js +128 -0
- package/es/rrweb/packages/rrweb/src/plugins/console/replay/index.js +94 -0
- package/es/rrweb/packages/rrweb/src/plugins/sequential-id/record/index.js +22 -0
- package/es/rrweb/packages/rrweb/src/plugins/sequential-id/replay/index.js +28 -0
- package/es/rrweb/packages/rrweb/src/record/iframe-manager.js +31 -0
- package/es/rrweb/packages/rrweb/src/record/index.js +356 -0
- package/es/rrweb/packages/rrweb/src/record/mutation.js +491 -0
- package/es/rrweb/packages/rrweb/src/record/observer.js +590 -0
- package/es/rrweb/packages/rrweb/src/record/observers/canvas/2d.js +49 -0
- package/es/rrweb/packages/rrweb/src/record/observers/canvas/canvas-manager.js +172 -0
- package/es/rrweb/packages/rrweb/src/record/observers/canvas/canvas.js +25 -0
- package/es/rrweb/packages/rrweb/src/record/observers/canvas/serialize-args.js +123 -0
- package/es/rrweb/packages/rrweb/src/record/observers/canvas/webgl.js +59 -0
- package/es/rrweb/packages/rrweb/src/record/shadow-dom-manager.js +43 -0
- package/es/rrweb/packages/rrweb/src/record/stylesheet-manager.js +31 -0
- package/es/rrweb/packages/rrweb/src/replay/canvas/2d.js +29 -0
- package/es/rrweb/packages/rrweb/src/replay/canvas/deserialize-args.js +67 -0
- package/es/rrweb/packages/rrweb/src/replay/canvas/index.js +43 -0
- package/es/rrweb/packages/rrweb/src/replay/canvas/webgl.js +62 -0
- package/es/rrweb/packages/rrweb/src/replay/index.js +1555 -0
- package/es/rrweb/packages/rrweb/src/replay/machine.js +281 -0
- package/es/rrweb/packages/rrweb/src/replay/smoothscroll.js +219 -0
- package/es/rrweb/packages/rrweb/src/replay/styles/inject-style.js +8 -0
- package/es/rrweb/packages/rrweb/src/replay/timer.js +92 -0
- package/es/rrweb/packages/rrweb/src/types.js +75 -0
- package/es/rrweb/packages/rrweb/src/utils.js +315 -0
- package/es/rrweb/packages/rrweb-snapshot/es/rrweb-snapshot.js +1821 -0
- package/lib/plugins/console-record.js +492 -0
- package/lib/plugins/console-replay.js +218 -0
- package/lib/plugins/sequential-id-record.js +27 -0
- package/lib/plugins/sequential-id-replay.js +32 -0
- package/lib/record/rrweb-record-pack.js +787 -0
- package/lib/record/rrweb-record.js +3363 -0
- package/lib/replay/rrweb-replay-unpack.js +5075 -0
- package/lib/replay/rrweb-replay.js +4665 -0
- package/lib/rrweb-all.js +9181 -0
- package/lib/rrweb.js +7814 -0
- package/package.json +41 -42
- package/typings/entries/all.d.ts +6 -0
- package/{dist → typings}/entries/record-pack.d.ts +0 -0
- package/{dist → typings}/entries/replay-unpack.d.ts +0 -0
- package/{dist → typings}/index.d.ts +1 -2
- package/{dist → typings}/packer/base.d.ts +1 -1
- package/{dist → typings}/packer/index.d.ts +0 -0
- package/{dist → typings}/packer/pack.d.ts +0 -0
- package/{dist → typings}/packer/unpack.d.ts +0 -0
- package/{dist → typings}/plugins/console/record/error-stack-parser.d.ts +0 -0
- package/{dist → typings}/plugins/console/record/index.d.ts +4 -3
- package/{dist → typings}/plugins/console/record/stringify.d.ts +1 -1
- package/{dist → typings}/plugins/console/replay/index.d.ts +2 -2
- package/{dist → typings}/plugins/sequential-id/record/index.d.ts +1 -1
- package/{dist → typings}/plugins/sequential-id/replay/index.d.ts +1 -1
- package/{dist → typings}/record/iframe-manager.d.ts +3 -3
- package/{dist/plugins → typings}/record/index.d.ts +9 -9
- package/{dist → typings}/record/mutation.d.ts +6 -8
- package/typings/record/observer.d.ts +7 -0
- package/{dist/plugins → typings}/record/observers/canvas/2d.d.ts +3 -2
- package/{dist → typings}/record/observers/canvas/canvas-manager.d.ts +5 -2
- package/{dist/plugins → typings}/record/observers/canvas/canvas.d.ts +2 -2
- package/typings/record/observers/canvas/serialize-args.d.ts +6 -0
- package/{dist/plugins → typings}/record/observers/canvas/webgl.d.ts +3 -2
- package/typings/record/observers/canvas/webgl2.d.ts +2 -0
- package/typings/record/shadow-dom-manager.d.ts +22 -0
- package/typings/record/stylesheet-manager.d.ts +12 -0
- package/typings/record/workers/image-bitmap-data-url-worker.d.ts +5 -0
- package/{dist → typings}/replay/canvas/2d.d.ts +3 -3
- package/typings/replay/canvas/deserialize-args.d.ts +7 -0
- package/{dist/plugins → typings}/replay/canvas/index.d.ts +10 -9
- package/typings/replay/canvas/webgl.d.ts +9 -0
- package/{dist → typings}/replay/index.d.ts +7 -9
- package/{dist → typings}/replay/machine.d.ts +0 -0
- package/{dist → typings}/replay/smoothscroll.d.ts +0 -0
- package/{dist → typings}/replay/styles/inject-style.d.ts +0 -0
- package/{dist → typings}/replay/timer.d.ts +0 -0
- package/{dist → typings}/rrdom/index.d.ts +0 -0
- package/{dist → typings}/rrdom/tree-node.d.ts +0 -0
- package/{dist/plugins → typings}/types.d.ts +536 -509
- package/typings/utils.d.ts +43 -0
- package/CHANGELOG.md +0 -26
- package/README.md +0 -124
- package/README.zh_CN.md +0 -122
- package/dist/entries/all.d.ts +0 -4
- package/dist/index.css +0 -82
- package/dist/index.css.map +0 -1
- package/dist/index.js +0 -3
- package/dist/index.js.LICENSE.txt +0 -14
- package/dist/index.js.map +0 -1
- package/dist/plugins/entries/all.d.ts +0 -4
- package/dist/plugins/entries/record-pack.d.ts +0 -2
- package/dist/plugins/entries/replay-unpack.d.ts +0 -2
- package/dist/plugins/index.d.ts +0 -9
- package/dist/plugins/packer/base.d.ts +0 -7
- package/dist/plugins/packer/index.d.ts +0 -2
- package/dist/plugins/packer/pack.d.ts +0 -2
- package/dist/plugins/packer/unpack.d.ts +0 -2
- package/dist/plugins/plugins/console/record/error-stack-parser.d.ts +0 -37
- package/dist/plugins/plugins/console/record/index.d.ts +0 -41
- package/dist/plugins/plugins/console/record/stringify.d.ts +0 -2
- package/dist/plugins/plugins/console/replay/index.d.ts +0 -9
- package/dist/plugins/plugins/sequential-id/record/index.d.ts +0 -6
- package/dist/plugins/plugins/sequential-id/replay/index.d.ts +0 -7
- package/dist/plugins/record/iframe-manager.d.ts +0 -13
- package/dist/plugins/record/mutation.d.ts +0 -45
- package/dist/plugins/record/observer.d.ts +0 -11
- package/dist/plugins/record/observers/canvas/canvas-manager.d.ts +0 -32
- package/dist/plugins/record/observers/canvas/serialize-args.d.ts +0 -6
- package/dist/plugins/record/shadow-dom-manager.d.ts +0 -34
- package/dist/plugins/replay/canvas/2d.d.ts +0 -9
- package/dist/plugins/replay/canvas/webgl.d.ts +0 -11
- package/dist/plugins/replay/index.d.ts +0 -82
- package/dist/plugins/replay/machine.d.ts +0 -85
- package/dist/plugins/replay/smoothscroll.d.ts +0 -1
- package/dist/plugins/replay/styles/inject-style.d.ts +0 -2
- package/dist/plugins/replay/timer.d.ts +0 -19
- package/dist/plugins/replay/virtual-styles.d.ts +0 -43
- package/dist/plugins/rrdom/index.d.ts +0 -1
- package/dist/plugins/rrdom/tree-node.d.ts +0 -20
- package/dist/plugins/snapshot/css.d.ts +0 -92
- package/dist/plugins/snapshot/index.d.ts +0 -5
- package/dist/plugins/snapshot/rebuild.d.ts +0 -19
- package/dist/plugins/snapshot/snapshot.d.ts +0 -49
- package/dist/plugins/snapshot/types.d.ts +0 -99
- package/dist/plugins/snapshot/utils.d.ts +0 -11
- package/dist/plugins/utils.d.ts +0 -71
- package/dist/record/index.d.ts +0 -9
- package/dist/record/observer.d.ts +0 -11
- package/dist/record/observers/canvas/2d.d.ts +0 -2
- package/dist/record/observers/canvas/canvas.d.ts +0 -2
- package/dist/record/observers/canvas/serialize-args.d.ts +0 -6
- package/dist/record/observers/canvas/webgl.d.ts +0 -2
- package/dist/record/shadow-dom-manager.d.ts +0 -34
- package/dist/replay/canvas/index.d.ts +0 -9
- package/dist/replay/canvas/webgl.d.ts +0 -11
- package/dist/replay/virtual-styles.d.ts +0 -43
- package/dist/snapshot/css.d.ts +0 -92
- package/dist/snapshot/index.d.ts +0 -5
- package/dist/snapshot/rebuild.d.ts +0 -19
- package/dist/snapshot/snapshot.d.ts +0 -49
- package/dist/snapshot/types.d.ts +0 -99
- package/dist/snapshot/utils.d.ts +0 -11
- package/dist/types.d.ts +0 -509
- package/dist/utils.d.ts +0 -71
|
@@ -0,0 +1,491 @@
|
|
|
1
|
+
import { obfuscateText, isShadowRoot, maskInputValue, transformAttribute, needMaskingText, IGNORED_NODE, serializeNodeWithId } from '../../../rrweb-snapshot/es/rrweb-snapshot.js';
|
|
2
|
+
import { isIgnored, isBlocked, isSerialized, isAncestorRemoved, isSerializedIframe, isSerializedStylesheet, hasShadowRoot } from '../utils.js';
|
|
3
|
+
|
|
4
|
+
function isNodeInLinkedList(n) {
|
|
5
|
+
return '__ln' in n;
|
|
6
|
+
}
|
|
7
|
+
class DoubleLinkedList {
|
|
8
|
+
constructor() {
|
|
9
|
+
this.length = 0;
|
|
10
|
+
this.head = null;
|
|
11
|
+
}
|
|
12
|
+
get(position) {
|
|
13
|
+
if (position >= this.length) {
|
|
14
|
+
throw new Error('Position outside of list range');
|
|
15
|
+
}
|
|
16
|
+
let current = this.head;
|
|
17
|
+
for (let index = 0; index < position; index++) {
|
|
18
|
+
current = (current === null || current === void 0 ? void 0 : current.next) || null;
|
|
19
|
+
}
|
|
20
|
+
return current;
|
|
21
|
+
}
|
|
22
|
+
addNode(n) {
|
|
23
|
+
const node = {
|
|
24
|
+
value: n,
|
|
25
|
+
previous: null,
|
|
26
|
+
next: null,
|
|
27
|
+
};
|
|
28
|
+
n.__ln = node;
|
|
29
|
+
if (n.previousSibling && isNodeInLinkedList(n.previousSibling)) {
|
|
30
|
+
const current = n.previousSibling.__ln.next;
|
|
31
|
+
node.next = current;
|
|
32
|
+
node.previous = n.previousSibling.__ln;
|
|
33
|
+
n.previousSibling.__ln.next = node;
|
|
34
|
+
if (current) {
|
|
35
|
+
current.previous = node;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
else if (n.nextSibling &&
|
|
39
|
+
isNodeInLinkedList(n.nextSibling) &&
|
|
40
|
+
n.nextSibling.__ln.previous) {
|
|
41
|
+
const current = n.nextSibling.__ln.previous;
|
|
42
|
+
node.previous = current;
|
|
43
|
+
node.next = n.nextSibling.__ln;
|
|
44
|
+
n.nextSibling.__ln.previous = node;
|
|
45
|
+
if (current) {
|
|
46
|
+
current.next = node;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
if (this.head) {
|
|
51
|
+
this.head.previous = node;
|
|
52
|
+
}
|
|
53
|
+
node.next = this.head;
|
|
54
|
+
this.head = node;
|
|
55
|
+
}
|
|
56
|
+
this.length++;
|
|
57
|
+
}
|
|
58
|
+
removeNode(n) {
|
|
59
|
+
const current = n.__ln;
|
|
60
|
+
if (!this.head) {
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
if (!current.previous) {
|
|
64
|
+
this.head = current.next;
|
|
65
|
+
if (this.head) {
|
|
66
|
+
this.head.previous = null;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
else {
|
|
70
|
+
current.previous.next = current.next;
|
|
71
|
+
if (current.next) {
|
|
72
|
+
current.next.previous = current.previous;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
if (n.__ln) {
|
|
76
|
+
delete n.__ln;
|
|
77
|
+
}
|
|
78
|
+
this.length--;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
const moveKey = (id, parentId) => `${id}@${parentId}`;
|
|
82
|
+
class MutationBuffer {
|
|
83
|
+
constructor() {
|
|
84
|
+
this.frozen = false;
|
|
85
|
+
this.locked = false;
|
|
86
|
+
this.texts = [];
|
|
87
|
+
this.attributes = [];
|
|
88
|
+
this.removes = [];
|
|
89
|
+
this.mapRemoves = [];
|
|
90
|
+
this.movedMap = {};
|
|
91
|
+
this.addedSet = new Set();
|
|
92
|
+
this.movedSet = new Set();
|
|
93
|
+
this.droppedSet = new Set();
|
|
94
|
+
this.processMutations = (mutations) => {
|
|
95
|
+
mutations.forEach(this.processMutation);
|
|
96
|
+
this.emit();
|
|
97
|
+
};
|
|
98
|
+
this.emit = () => {
|
|
99
|
+
if (this.frozen || this.locked) {
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
const adds = [];
|
|
103
|
+
const addList = new DoubleLinkedList();
|
|
104
|
+
const getNextId = (n) => {
|
|
105
|
+
let ns = n;
|
|
106
|
+
let nextId = IGNORED_NODE;
|
|
107
|
+
while (nextId === IGNORED_NODE) {
|
|
108
|
+
ns = ns && ns.nextSibling;
|
|
109
|
+
nextId = ns && this.mirror.getId(ns);
|
|
110
|
+
}
|
|
111
|
+
return nextId;
|
|
112
|
+
};
|
|
113
|
+
const pushAdd = (n) => {
|
|
114
|
+
var _a, _b, _c, _d, _e;
|
|
115
|
+
const shadowHost = n.getRootNode
|
|
116
|
+
? (_a = n.getRootNode()) === null || _a === void 0 ? void 0 : _a.host
|
|
117
|
+
: null;
|
|
118
|
+
let rootShadowHost = shadowHost;
|
|
119
|
+
while ((_c = (_b = rootShadowHost === null || rootShadowHost === void 0 ? void 0 : rootShadowHost.getRootNode) === null || _b === void 0 ? void 0 : _b.call(rootShadowHost)) === null || _c === void 0 ? void 0 : _c.host)
|
|
120
|
+
rootShadowHost =
|
|
121
|
+
((_e = (_d = rootShadowHost === null || rootShadowHost === void 0 ? void 0 : rootShadowHost.getRootNode) === null || _d === void 0 ? void 0 : _d.call(rootShadowHost)) === null || _e === void 0 ? void 0 : _e.host) ||
|
|
122
|
+
null;
|
|
123
|
+
const notInDoc = !this.doc.contains(n) &&
|
|
124
|
+
(!rootShadowHost || !this.doc.contains(rootShadowHost));
|
|
125
|
+
if (!n.parentNode || notInDoc) {
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
const parentId = isShadowRoot(n.parentNode)
|
|
129
|
+
? this.mirror.getId(shadowHost)
|
|
130
|
+
: this.mirror.getId(n.parentNode);
|
|
131
|
+
const nextId = getNextId(n);
|
|
132
|
+
if (parentId === -1 || nextId === -1) {
|
|
133
|
+
return addList.addNode(n);
|
|
134
|
+
}
|
|
135
|
+
const sn = serializeNodeWithId(n, {
|
|
136
|
+
doc: this.doc,
|
|
137
|
+
mirror: this.mirror,
|
|
138
|
+
blockClass: this.blockClass,
|
|
139
|
+
blockSelector: this.blockSelector,
|
|
140
|
+
maskTextClass: this.maskTextClass,
|
|
141
|
+
maskTextSelector: this.maskTextSelector,
|
|
142
|
+
skipChild: true,
|
|
143
|
+
inlineStylesheet: this.inlineStylesheet,
|
|
144
|
+
maskInputOptions: this.maskInputOptions,
|
|
145
|
+
maskTextFn: this.maskTextFn,
|
|
146
|
+
maskInputFn: this.maskInputFn,
|
|
147
|
+
slimDOMOptions: this.slimDOMOptions,
|
|
148
|
+
recordCanvas: this.recordCanvas,
|
|
149
|
+
inlineImages: this.inlineImages,
|
|
150
|
+
enableStrictPrivacy: this.enableStrictPrivacy,
|
|
151
|
+
onSerialize: (currentN) => {
|
|
152
|
+
if (isSerializedIframe(currentN, this.mirror)) {
|
|
153
|
+
this.iframeManager.addIframe(currentN);
|
|
154
|
+
}
|
|
155
|
+
if (isSerializedStylesheet(currentN, this.mirror)) {
|
|
156
|
+
this.stylesheetManager.addStylesheet(currentN);
|
|
157
|
+
}
|
|
158
|
+
if (hasShadowRoot(n)) {
|
|
159
|
+
this.shadowDomManager.addShadowRoot(n.shadowRoot, document);
|
|
160
|
+
}
|
|
161
|
+
},
|
|
162
|
+
onIframeLoad: (iframe, childSn) => {
|
|
163
|
+
this.iframeManager.attachIframe(iframe, childSn, this.mirror);
|
|
164
|
+
this.shadowDomManager.observeAttachShadow(iframe);
|
|
165
|
+
},
|
|
166
|
+
onStylesheetLoad: (link, childSn) => {
|
|
167
|
+
this.stylesheetManager.attachStylesheet(link, childSn, this.mirror);
|
|
168
|
+
},
|
|
169
|
+
});
|
|
170
|
+
if (sn) {
|
|
171
|
+
adds.push({
|
|
172
|
+
parentId,
|
|
173
|
+
nextId,
|
|
174
|
+
node: sn,
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
};
|
|
178
|
+
while (this.mapRemoves.length) {
|
|
179
|
+
this.mirror.removeNodeFromMap(this.mapRemoves.shift());
|
|
180
|
+
}
|
|
181
|
+
for (const n of Array.from(this.movedSet.values())) {
|
|
182
|
+
if (isParentRemoved(this.removes, n, this.mirror) &&
|
|
183
|
+
!this.movedSet.has(n.parentNode)) {
|
|
184
|
+
continue;
|
|
185
|
+
}
|
|
186
|
+
pushAdd(n);
|
|
187
|
+
}
|
|
188
|
+
for (const n of Array.from(this.addedSet.values())) {
|
|
189
|
+
if (!isAncestorInSet(this.droppedSet, n) &&
|
|
190
|
+
!isParentRemoved(this.removes, n, this.mirror)) {
|
|
191
|
+
pushAdd(n);
|
|
192
|
+
}
|
|
193
|
+
else if (isAncestorInSet(this.movedSet, n)) {
|
|
194
|
+
pushAdd(n);
|
|
195
|
+
}
|
|
196
|
+
else {
|
|
197
|
+
this.droppedSet.add(n);
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
let candidate = null;
|
|
201
|
+
while (addList.length) {
|
|
202
|
+
let node = null;
|
|
203
|
+
if (candidate) {
|
|
204
|
+
const parentId = this.mirror.getId(candidate.value.parentNode);
|
|
205
|
+
const nextId = getNextId(candidate.value);
|
|
206
|
+
if (parentId !== -1 && nextId !== -1) {
|
|
207
|
+
node = candidate;
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
if (!node) {
|
|
211
|
+
for (let index = addList.length - 1; index >= 0; index--) {
|
|
212
|
+
const _node = addList.get(index);
|
|
213
|
+
if (_node) {
|
|
214
|
+
const parentId = this.mirror.getId(_node.value.parentNode);
|
|
215
|
+
const nextId = getNextId(_node.value);
|
|
216
|
+
if (parentId !== -1 && nextId !== -1) {
|
|
217
|
+
node = _node;
|
|
218
|
+
break;
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
if (!node) {
|
|
224
|
+
while (addList.head) {
|
|
225
|
+
addList.removeNode(addList.head.value);
|
|
226
|
+
}
|
|
227
|
+
break;
|
|
228
|
+
}
|
|
229
|
+
candidate = node.previous;
|
|
230
|
+
addList.removeNode(node.value);
|
|
231
|
+
pushAdd(node.value);
|
|
232
|
+
}
|
|
233
|
+
const payload = {
|
|
234
|
+
texts: this.texts
|
|
235
|
+
.map((text) => {
|
|
236
|
+
let value = text.value;
|
|
237
|
+
if (this.enableStrictPrivacy && value) {
|
|
238
|
+
value = obfuscateText(value);
|
|
239
|
+
}
|
|
240
|
+
return {
|
|
241
|
+
id: this.mirror.getId(text.node),
|
|
242
|
+
value,
|
|
243
|
+
};
|
|
244
|
+
})
|
|
245
|
+
.filter((text) => this.mirror.has(text.id)),
|
|
246
|
+
attributes: this.attributes
|
|
247
|
+
.map((attribute) => ({
|
|
248
|
+
id: this.mirror.getId(attribute.node),
|
|
249
|
+
attributes: attribute.attributes,
|
|
250
|
+
}))
|
|
251
|
+
.filter((attribute) => this.mirror.has(attribute.id)),
|
|
252
|
+
removes: this.removes,
|
|
253
|
+
adds,
|
|
254
|
+
};
|
|
255
|
+
if (!payload.texts.length &&
|
|
256
|
+
!payload.attributes.length &&
|
|
257
|
+
!payload.removes.length &&
|
|
258
|
+
!payload.adds.length) {
|
|
259
|
+
return;
|
|
260
|
+
}
|
|
261
|
+
this.texts = [];
|
|
262
|
+
this.attributes = [];
|
|
263
|
+
this.removes = [];
|
|
264
|
+
this.addedSet = new Set();
|
|
265
|
+
this.movedSet = new Set();
|
|
266
|
+
this.droppedSet = new Set();
|
|
267
|
+
this.movedMap = {};
|
|
268
|
+
this.mutationCb(payload);
|
|
269
|
+
};
|
|
270
|
+
this.processMutation = (m) => {
|
|
271
|
+
if (isIgnored(m.target, this.mirror)) {
|
|
272
|
+
return;
|
|
273
|
+
}
|
|
274
|
+
switch (m.type) {
|
|
275
|
+
case 'characterData': {
|
|
276
|
+
const value = m.target.textContent;
|
|
277
|
+
if (!isBlocked(m.target, this.blockClass) && value !== m.oldValue) {
|
|
278
|
+
this.texts.push({
|
|
279
|
+
value: needMaskingText(m.target, this.maskTextClass, this.maskTextSelector) && value
|
|
280
|
+
? this.maskTextFn
|
|
281
|
+
? this.maskTextFn(value)
|
|
282
|
+
: value.replace(/[\S]/g, '*')
|
|
283
|
+
: value,
|
|
284
|
+
node: m.target,
|
|
285
|
+
});
|
|
286
|
+
}
|
|
287
|
+
break;
|
|
288
|
+
}
|
|
289
|
+
case 'attributes': {
|
|
290
|
+
const target = m.target;
|
|
291
|
+
let value = m.target.getAttribute(m.attributeName);
|
|
292
|
+
if (m.attributeName === 'value') {
|
|
293
|
+
value = maskInputValue({
|
|
294
|
+
maskInputOptions: this.maskInputOptions,
|
|
295
|
+
tagName: m.target.tagName,
|
|
296
|
+
type: m.target.getAttribute('type'),
|
|
297
|
+
value,
|
|
298
|
+
maskInputFn: this.maskInputFn,
|
|
299
|
+
});
|
|
300
|
+
}
|
|
301
|
+
if (isBlocked(m.target, this.blockClass) || value === m.oldValue) {
|
|
302
|
+
return;
|
|
303
|
+
}
|
|
304
|
+
let item = this.attributes.find((a) => a.node === m.target);
|
|
305
|
+
if (!item) {
|
|
306
|
+
item = {
|
|
307
|
+
node: m.target,
|
|
308
|
+
attributes: {},
|
|
309
|
+
};
|
|
310
|
+
this.attributes.push(item);
|
|
311
|
+
}
|
|
312
|
+
if (m.attributeName === 'style') {
|
|
313
|
+
const old = this.doc.createElement('span');
|
|
314
|
+
if (m.oldValue) {
|
|
315
|
+
old.setAttribute('style', m.oldValue);
|
|
316
|
+
}
|
|
317
|
+
if (item.attributes.style === undefined ||
|
|
318
|
+
item.attributes.style === null) {
|
|
319
|
+
item.attributes.style = {};
|
|
320
|
+
}
|
|
321
|
+
const styleObj = item.attributes.style;
|
|
322
|
+
for (const pname of Array.from(target.style)) {
|
|
323
|
+
const newValue = target.style.getPropertyValue(pname);
|
|
324
|
+
const newPriority = target.style.getPropertyPriority(pname);
|
|
325
|
+
if (newValue !== old.style.getPropertyValue(pname) ||
|
|
326
|
+
newPriority !== old.style.getPropertyPriority(pname)) {
|
|
327
|
+
if (newPriority === '') {
|
|
328
|
+
styleObj[pname] = newValue;
|
|
329
|
+
}
|
|
330
|
+
else {
|
|
331
|
+
styleObj[pname] = [newValue, newPriority];
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
for (const pname of Array.from(old.style)) {
|
|
336
|
+
if (target.style.getPropertyValue(pname) === '') {
|
|
337
|
+
styleObj[pname] = false;
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
else {
|
|
342
|
+
const tagName = m.target.tagName;
|
|
343
|
+
if (tagName === 'INPUT') {
|
|
344
|
+
const node = m.target;
|
|
345
|
+
if (node.type === 'password') {
|
|
346
|
+
item.attributes['value'] = '*'.repeat(node.value.length);
|
|
347
|
+
break;
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
item.attributes[m.attributeName] = transformAttribute(this.doc, m.target.tagName, m.attributeName, value);
|
|
351
|
+
}
|
|
352
|
+
break;
|
|
353
|
+
}
|
|
354
|
+
case 'childList': {
|
|
355
|
+
m.addedNodes.forEach((n) => this.genAdds(n, m.target));
|
|
356
|
+
m.removedNodes.forEach((n) => {
|
|
357
|
+
const nodeId = this.mirror.getId(n);
|
|
358
|
+
const parentId = isShadowRoot(m.target)
|
|
359
|
+
? this.mirror.getId(m.target.host)
|
|
360
|
+
: this.mirror.getId(m.target);
|
|
361
|
+
if (isBlocked(m.target, this.blockClass) ||
|
|
362
|
+
isIgnored(n, this.mirror) ||
|
|
363
|
+
!isSerialized(n, this.mirror)) {
|
|
364
|
+
return;
|
|
365
|
+
}
|
|
366
|
+
if (this.addedSet.has(n)) {
|
|
367
|
+
deepDelete(this.addedSet, n);
|
|
368
|
+
this.droppedSet.add(n);
|
|
369
|
+
}
|
|
370
|
+
else if (this.addedSet.has(m.target) && nodeId === -1) ;
|
|
371
|
+
else if (isAncestorRemoved(m.target, this.mirror)) ;
|
|
372
|
+
else if (this.movedSet.has(n) &&
|
|
373
|
+
this.movedMap[moveKey(nodeId, parentId)]) {
|
|
374
|
+
deepDelete(this.movedSet, n);
|
|
375
|
+
}
|
|
376
|
+
else {
|
|
377
|
+
this.removes.push({
|
|
378
|
+
parentId,
|
|
379
|
+
id: nodeId,
|
|
380
|
+
isShadow: isShadowRoot(m.target) ? true : undefined,
|
|
381
|
+
});
|
|
382
|
+
}
|
|
383
|
+
this.mapRemoves.push(n);
|
|
384
|
+
});
|
|
385
|
+
break;
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
};
|
|
389
|
+
this.genAdds = (n, target) => {
|
|
390
|
+
if (target && isBlocked(target, this.blockClass)) {
|
|
391
|
+
return;
|
|
392
|
+
}
|
|
393
|
+
if (this.mirror.getMeta(n)) {
|
|
394
|
+
if (isIgnored(n, this.mirror)) {
|
|
395
|
+
return;
|
|
396
|
+
}
|
|
397
|
+
this.movedSet.add(n);
|
|
398
|
+
let targetId = null;
|
|
399
|
+
if (target && this.mirror.getMeta(target)) {
|
|
400
|
+
targetId = this.mirror.getId(target);
|
|
401
|
+
}
|
|
402
|
+
if (targetId && targetId !== -1) {
|
|
403
|
+
this.movedMap[moveKey(this.mirror.getId(n), targetId)] = true;
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
else {
|
|
407
|
+
this.addedSet.add(n);
|
|
408
|
+
this.droppedSet.delete(n);
|
|
409
|
+
}
|
|
410
|
+
if (!isBlocked(n, this.blockClass))
|
|
411
|
+
n.childNodes.forEach((childN) => this.genAdds(childN));
|
|
412
|
+
};
|
|
413
|
+
}
|
|
414
|
+
init(options) {
|
|
415
|
+
[
|
|
416
|
+
'mutationCb',
|
|
417
|
+
'blockClass',
|
|
418
|
+
'blockSelector',
|
|
419
|
+
'maskTextClass',
|
|
420
|
+
'maskTextSelector',
|
|
421
|
+
'inlineStylesheet',
|
|
422
|
+
'maskInputOptions',
|
|
423
|
+
'maskTextFn',
|
|
424
|
+
'maskInputFn',
|
|
425
|
+
'recordCanvas',
|
|
426
|
+
'inlineImages',
|
|
427
|
+
'slimDOMOptions',
|
|
428
|
+
'doc',
|
|
429
|
+
'mirror',
|
|
430
|
+
'iframeManager',
|
|
431
|
+
'stylesheetManager',
|
|
432
|
+
'shadowDomManager',
|
|
433
|
+
'canvasManager',
|
|
434
|
+
'enableStrictPrivacy',
|
|
435
|
+
].forEach((key) => {
|
|
436
|
+
this[key] = options[key];
|
|
437
|
+
});
|
|
438
|
+
}
|
|
439
|
+
freeze() {
|
|
440
|
+
this.frozen = true;
|
|
441
|
+
this.canvasManager.freeze();
|
|
442
|
+
}
|
|
443
|
+
unfreeze() {
|
|
444
|
+
this.frozen = false;
|
|
445
|
+
this.canvasManager.unfreeze();
|
|
446
|
+
this.emit();
|
|
447
|
+
}
|
|
448
|
+
isFrozen() {
|
|
449
|
+
return this.frozen;
|
|
450
|
+
}
|
|
451
|
+
lock() {
|
|
452
|
+
this.locked = true;
|
|
453
|
+
this.canvasManager.lock();
|
|
454
|
+
}
|
|
455
|
+
unlock() {
|
|
456
|
+
this.locked = false;
|
|
457
|
+
this.canvasManager.unlock();
|
|
458
|
+
this.emit();
|
|
459
|
+
}
|
|
460
|
+
reset() {
|
|
461
|
+
this.shadowDomManager.reset();
|
|
462
|
+
this.canvasManager.reset();
|
|
463
|
+
}
|
|
464
|
+
}
|
|
465
|
+
function deepDelete(addsSet, n) {
|
|
466
|
+
addsSet.delete(n);
|
|
467
|
+
n.childNodes.forEach((childN) => deepDelete(addsSet, childN));
|
|
468
|
+
}
|
|
469
|
+
function isParentRemoved(removes, n, mirror) {
|
|
470
|
+
const { parentNode } = n;
|
|
471
|
+
if (!parentNode) {
|
|
472
|
+
return false;
|
|
473
|
+
}
|
|
474
|
+
const parentId = mirror.getId(parentNode);
|
|
475
|
+
if (removes.some((r) => r.id === parentId)) {
|
|
476
|
+
return true;
|
|
477
|
+
}
|
|
478
|
+
return isParentRemoved(removes, parentNode, mirror);
|
|
479
|
+
}
|
|
480
|
+
function isAncestorInSet(set, n) {
|
|
481
|
+
const { parentNode } = n;
|
|
482
|
+
if (!parentNode) {
|
|
483
|
+
return false;
|
|
484
|
+
}
|
|
485
|
+
if (set.has(parentNode)) {
|
|
486
|
+
return true;
|
|
487
|
+
}
|
|
488
|
+
return isAncestorInSet(set, parentNode);
|
|
489
|
+
}
|
|
490
|
+
|
|
491
|
+
export { MutationBuffer as default };
|