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