@highlight-run/rrweb 2.0.8 → 2.0.11

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 (41) hide show
  1. package/dist/plugins/console-record.js +5 -5
  2. package/dist/plugins/console-record.min.js +5 -5
  3. package/dist/plugins/console-record.min.js.map +1 -1
  4. package/dist/plugins/console-replay.js +3 -3
  5. package/dist/plugins/console-replay.min.js +3 -3
  6. package/dist/plugins/console-replay.min.js.map +1 -1
  7. package/dist/record/rrweb-record-pack.js +2 -2
  8. package/dist/record/rrweb-record-pack.min.js +2 -2
  9. package/dist/record/rrweb-record-pack.min.js.map +1 -1
  10. package/dist/record/rrweb-record.js +3 -3
  11. package/dist/record/rrweb-record.min.js +3 -3
  12. package/dist/record/rrweb-record.min.js.map +1 -1
  13. package/dist/replay/rrweb-replay-unpack.js +3 -4
  14. package/dist/replay/rrweb-replay-unpack.min.js +3 -4
  15. package/dist/replay/rrweb-replay-unpack.min.js.map +1 -1
  16. package/dist/replay/rrweb-replay.js +3 -4
  17. package/dist/replay/rrweb-replay.min.js +3 -4
  18. package/dist/replay/rrweb-replay.min.js.map +1 -1
  19. package/dist/rrweb-all.js +24 -25
  20. package/dist/rrweb-all.min.js +24 -25
  21. package/dist/rrweb-all.min.js.map +1 -1
  22. package/dist/rrweb.js +14 -15
  23. package/dist/rrweb.min.js +14 -15
  24. package/dist/rrweb.min.js.map +1 -1
  25. package/es/rrweb/packages/rrdom/es/virtual-dom.js +51 -90
  26. package/es/rrweb/packages/rrweb/src/index.js +1 -1
  27. package/es/rrweb/packages/rrweb/src/record/index.js +6 -3
  28. package/es/rrweb/packages/rrweb/src/record/mutation.js +1 -1
  29. package/es/rrweb/packages/rrweb/src/record/observer.js +1 -1
  30. package/es/rrweb/packages/rrweb/src/replay/index.js +1 -1
  31. package/es/rrweb/packages/rrweb/src/utils.js +1 -1
  32. package/lib/plugins/console-record.js +1 -9
  33. package/lib/plugins/console-replay.js +1 -9
  34. package/lib/record/rrweb-record-pack.js +3 -9
  35. package/lib/record/rrweb-record.js +21 -1061
  36. package/lib/replay/rrweb-replay-unpack.js +96 -1015
  37. package/lib/replay/rrweb-replay.js +96 -1015
  38. package/lib/rrweb-all.js +141 -2034
  39. package/lib/rrweb.js +141 -2034
  40. package/package.json +4 -4
  41. package/es/rrweb/packages/rrweb-snapshot/es/rrweb-snapshot.js +0 -1858
package/lib/rrweb.js CHANGED
@@ -2,1862 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var NodeType$2;
6
- (function (NodeType) {
7
- NodeType[NodeType["Document"] = 0] = "Document";
8
- NodeType[NodeType["DocumentType"] = 1] = "DocumentType";
9
- NodeType[NodeType["Element"] = 2] = "Element";
10
- NodeType[NodeType["Text"] = 3] = "Text";
11
- NodeType[NodeType["CDATA"] = 4] = "CDATA";
12
- NodeType[NodeType["Comment"] = 5] = "Comment";
13
- })(NodeType$2 || (NodeType$2 = {}));
14
-
15
- function isElement(n) {
16
- return n.nodeType === n.ELEMENT_NODE;
17
- }
18
- function isShadowRoot(n) {
19
- var _a;
20
- var host = (_a = n) === null || _a === void 0 ? void 0 : _a.host;
21
- return Boolean((host === null || host === void 0 ? void 0 : host.shadowRoot) === n);
22
- }
23
- var Mirror$2 = (function () {
24
- function Mirror() {
25
- this.idNodeMap = new Map();
26
- this.nodeMetaMap = new WeakMap();
27
- }
28
- Mirror.prototype.getId = function (n) {
29
- var _a;
30
- if (!n)
31
- return -1;
32
- var id = (_a = this.getMeta(n)) === null || _a === void 0 ? void 0 : _a.id;
33
- return id !== null && id !== void 0 ? id : -1;
34
- };
35
- Mirror.prototype.getNode = function (id) {
36
- return this.idNodeMap.get(id) || null;
37
- };
38
- Mirror.prototype.getIds = function () {
39
- return Array.from(this.idNodeMap.keys());
40
- };
41
- Mirror.prototype.getMeta = function (n) {
42
- return this.nodeMetaMap.get(n) || null;
43
- };
44
- Mirror.prototype.removeNodeFromMap = function (n) {
45
- var _this = this;
46
- var id = this.getId(n);
47
- this.idNodeMap["delete"](id);
48
- if (n.childNodes) {
49
- n.childNodes.forEach(function (childNode) {
50
- return _this.removeNodeFromMap(childNode);
51
- });
52
- }
53
- };
54
- Mirror.prototype.has = function (id) {
55
- return this.idNodeMap.has(id);
56
- };
57
- Mirror.prototype.hasNode = function (node) {
58
- return this.nodeMetaMap.has(node);
59
- };
60
- Mirror.prototype.add = function (n, meta) {
61
- var id = meta.id;
62
- this.idNodeMap.set(id, n);
63
- this.nodeMetaMap.set(n, meta);
64
- };
65
- Mirror.prototype.replace = function (id, n) {
66
- this.idNodeMap.set(id, n);
67
- };
68
- Mirror.prototype.reset = function () {
69
- this.idNodeMap = new Map();
70
- this.nodeMetaMap = new WeakMap();
71
- };
72
- return Mirror;
73
- }());
74
- function createMirror$2() {
75
- return new Mirror$2();
76
- }
77
- function maskInputValue(_a) {
78
- var maskInputOptions = _a.maskInputOptions, tagName = _a.tagName, type = _a.type, value = _a.value, maskInputFn = _a.maskInputFn;
79
- var text = value || '';
80
- if (maskInputOptions[tagName.toLowerCase()] ||
81
- maskInputOptions[type]) {
82
- if (maskInputFn) {
83
- text = maskInputFn(text);
84
- }
85
- else {
86
- text = '*'.repeat(text.length);
87
- }
88
- }
89
- return text;
90
- }
91
- var ORIGINAL_ATTRIBUTE_NAME = '__rrweb_original__';
92
- function is2DCanvasBlank(canvas) {
93
- var ctx = canvas.getContext('2d');
94
- if (!ctx)
95
- return true;
96
- var chunkSize = 50;
97
- for (var x = 0; x < canvas.width; x += chunkSize) {
98
- for (var y = 0; y < canvas.height; y += chunkSize) {
99
- var getImageData = ctx.getImageData;
100
- var originalGetImageData = ORIGINAL_ATTRIBUTE_NAME in getImageData
101
- ? getImageData[ORIGINAL_ATTRIBUTE_NAME]
102
- : getImageData;
103
- var pixelBuffer = new Uint32Array(originalGetImageData.call(ctx, x, y, Math.min(chunkSize, canvas.width - x), Math.min(chunkSize, canvas.height - y)).data.buffer);
104
- if (pixelBuffer.some(function (pixel) { return pixel !== 0; }))
105
- return false;
106
- }
107
- }
108
- return true;
109
- }
110
- function obfuscateText(text) {
111
- text = text.replace(/[^ -~]+/g, '');
112
- text =
113
- (text === null || text === void 0 ? void 0 : text.split(' ').map(function (word) { return Math.random().toString(20).substr(2, word.length); }).join(' ')) || '';
114
- return text;
115
- }
116
-
117
- var _id = 1;
118
- var tagNameRegex = new RegExp('[^a-z0-9-_:]');
119
- var IGNORED_NODE = -2;
120
- function genId() {
121
- return _id++;
122
- }
123
- function getValidTagName$1(element) {
124
- if (element instanceof HTMLFormElement) {
125
- return 'form';
126
- }
127
- var processedTagName = element.tagName.toLowerCase().trim();
128
- if (tagNameRegex.test(processedTagName)) {
129
- return 'div';
130
- }
131
- return processedTagName;
132
- }
133
- function getCssRulesString(s) {
134
- try {
135
- var rules = s.rules || s.cssRules;
136
- return rules ? Array.from(rules).map(getCssRuleString).join('') : null;
137
- }
138
- catch (error) {
139
- return null;
140
- }
141
- }
142
- function getCssRuleString(rule) {
143
- var cssStringified = rule.cssText;
144
- if (isCSSImportRule(rule)) {
145
- try {
146
- cssStringified = getCssRulesString(rule.styleSheet) || cssStringified;
147
- }
148
- catch (_a) {
149
- }
150
- }
151
- return cssStringified;
152
- }
153
- function isCSSImportRule(rule) {
154
- return 'styleSheet' in rule;
155
- }
156
- function stringifyStyleSheet(sheet) {
157
- return sheet.cssRules
158
- ? Array.from(sheet.cssRules)
159
- .map(function (rule) { return rule.cssText || ''; })
160
- .join('')
161
- : '';
162
- }
163
- function extractOrigin(url) {
164
- var origin = '';
165
- if (url.indexOf('//') > -1) {
166
- origin = url.split('/').slice(0, 3).join('/');
167
- }
168
- else {
169
- origin = url.split('/')[0];
170
- }
171
- origin = origin.split('?')[0];
172
- return origin;
173
- }
174
- var canvasService;
175
- var canvasCtx;
176
- var URL_IN_CSS_REF = /url\((?:(')([^']*)'|(")(.*?)"|([^)]*))\)/gm;
177
- var RELATIVE_PATH = /^(?!www\.|(?:http|ftp)s?:\/\/|[A-Za-z]:\\|\/\/|#).*/;
178
- var DATA_URI = /^(data:)([^,]*),(.*)/i;
179
- function absoluteToStylesheet(cssText, href) {
180
- return (cssText || '').replace(URL_IN_CSS_REF, function (origin, quote1, path1, quote2, path2, path3) {
181
- var filePath = path1 || path2 || path3;
182
- var maybeQuote = quote1 || quote2 || '';
183
- if (!filePath) {
184
- return origin;
185
- }
186
- if (!RELATIVE_PATH.test(filePath)) {
187
- return "url(" + maybeQuote + filePath + maybeQuote + ")";
188
- }
189
- if (DATA_URI.test(filePath)) {
190
- return "url(" + maybeQuote + filePath + maybeQuote + ")";
191
- }
192
- if (filePath[0] === '/') {
193
- return "url(" + maybeQuote + (extractOrigin(href) + filePath) + maybeQuote + ")";
194
- }
195
- var stack = href.split('/');
196
- var parts = filePath.split('/');
197
- stack.pop();
198
- for (var _i = 0, parts_1 = parts; _i < parts_1.length; _i++) {
199
- var part = parts_1[_i];
200
- if (part === '.') {
201
- continue;
202
- }
203
- else if (part === '..') {
204
- stack.pop();
205
- }
206
- else {
207
- stack.push(part);
208
- }
209
- }
210
- return "url(" + maybeQuote + stack.join('/') + maybeQuote + ")";
211
- });
212
- }
213
- var SRCSET_NOT_SPACES = /^[^ \t\n\r\u000c]+/;
214
- var SRCSET_COMMAS_OR_SPACES = /^[, \t\n\r\u000c]+/;
215
- function getAbsoluteSrcsetString(doc, attributeValue) {
216
- if (attributeValue.trim() === '') {
217
- return attributeValue;
218
- }
219
- var pos = 0;
220
- function collectCharacters(regEx) {
221
- var chars;
222
- var match = regEx.exec(attributeValue.substring(pos));
223
- if (match) {
224
- chars = match[0];
225
- pos += chars.length;
226
- return chars;
227
- }
228
- return '';
229
- }
230
- var output = [];
231
- while (true) {
232
- collectCharacters(SRCSET_COMMAS_OR_SPACES);
233
- if (pos >= attributeValue.length) {
234
- break;
235
- }
236
- var url = collectCharacters(SRCSET_NOT_SPACES);
237
- if (url.slice(-1) === ',') {
238
- url = absoluteToDoc(doc, url.substring(0, url.length - 1));
239
- output.push(url);
240
- }
241
- else {
242
- var descriptorsStr = '';
243
- url = absoluteToDoc(doc, url);
244
- var inParens = false;
245
- while (true) {
246
- var c = attributeValue.charAt(pos);
247
- if (c === '') {
248
- output.push((url + descriptorsStr).trim());
249
- break;
250
- }
251
- else if (!inParens) {
252
- if (c === ',') {
253
- pos += 1;
254
- output.push((url + descriptorsStr).trim());
255
- break;
256
- }
257
- else if (c === '(') {
258
- inParens = true;
259
- }
260
- }
261
- else {
262
- if (c === ')') {
263
- inParens = false;
264
- }
265
- }
266
- descriptorsStr += c;
267
- pos += 1;
268
- }
269
- }
270
- }
271
- return output.join(', ');
272
- }
273
- function absoluteToDoc(doc, attributeValue) {
274
- if (!attributeValue || attributeValue.trim() === '') {
275
- return attributeValue;
276
- }
277
- var a = doc.createElement('a');
278
- a.href = attributeValue;
279
- return a.href;
280
- }
281
- function isSVGElement(el) {
282
- return Boolean(el.tagName === 'svg' || el.ownerSVGElement);
283
- }
284
- function getHref() {
285
- var a = document.createElement('a');
286
- a.href = '';
287
- return a.href;
288
- }
289
- function transformAttribute(doc, tagName, name, value) {
290
- if (name === 'src' || (name === 'href' && value)) {
291
- return absoluteToDoc(doc, value);
292
- }
293
- else if (name === 'xlink:href' && value && value[0] !== '#') {
294
- return absoluteToDoc(doc, value);
295
- }
296
- else if (name === 'background' &&
297
- value &&
298
- (tagName === 'table' || tagName === 'td' || tagName === 'th')) {
299
- return absoluteToDoc(doc, value);
300
- }
301
- else if (name === 'srcset' && value) {
302
- return getAbsoluteSrcsetString(doc, value);
303
- }
304
- else if (name === 'style' && value) {
305
- return absoluteToStylesheet(value, getHref());
306
- }
307
- else if (tagName === 'object' && name === 'data' && value) {
308
- return absoluteToDoc(doc, value);
309
- }
310
- else {
311
- return value;
312
- }
313
- }
314
- function _isBlockedElement(element, blockClass, blockSelector) {
315
- if (typeof blockClass === 'string') {
316
- if (element.classList.contains(blockClass)) {
317
- return true;
318
- }
319
- }
320
- else {
321
- for (var eIndex = element.classList.length; eIndex--;) {
322
- var className = element.classList[eIndex];
323
- if (blockClass.test(className)) {
324
- return true;
325
- }
326
- }
327
- }
328
- if (blockSelector) {
329
- return element.matches(blockSelector);
330
- }
331
- return false;
332
- }
333
- function classMatchesRegex(node, regex, checkAncestors) {
334
- if (!node)
335
- return false;
336
- if (node.nodeType !== node.ELEMENT_NODE) {
337
- if (!checkAncestors)
338
- return false;
339
- return classMatchesRegex(node.parentNode, regex, checkAncestors);
340
- }
341
- for (var eIndex = node.classList.length; eIndex--;) {
342
- var className = node.classList[eIndex];
343
- if (regex.test(className)) {
344
- return true;
345
- }
346
- }
347
- if (!checkAncestors)
348
- return false;
349
- return classMatchesRegex(node.parentNode, regex, checkAncestors);
350
- }
351
- function needMaskingText(node, maskTextClass, maskTextSelector) {
352
- var el = node.nodeType === node.ELEMENT_NODE
353
- ? node
354
- : node.parentElement;
355
- if (el === null)
356
- return false;
357
- if (typeof maskTextClass === 'string') {
358
- if (el.classList.contains(maskTextClass))
359
- return true;
360
- if (el.closest("." + maskTextClass))
361
- return true;
362
- }
363
- else {
364
- if (classMatchesRegex(el, maskTextClass, true))
365
- return true;
366
- }
367
- if (maskTextSelector) {
368
- if (el.matches(maskTextSelector))
369
- return true;
370
- if (el.closest(maskTextSelector))
371
- return true;
372
- }
373
- return false;
374
- }
375
- function onceIframeLoaded(iframeEl, listener, iframeLoadTimeout) {
376
- var win = iframeEl.contentWindow;
377
- if (!win) {
378
- return;
379
- }
380
- var fired = false;
381
- var readyState;
382
- try {
383
- readyState = win.document.readyState;
384
- }
385
- catch (error) {
386
- return;
387
- }
388
- if (readyState !== 'complete') {
389
- var timer_1 = setTimeout(function () {
390
- if (!fired) {
391
- listener();
392
- fired = true;
393
- }
394
- }, iframeLoadTimeout);
395
- iframeEl.addEventListener('load', function () {
396
- clearTimeout(timer_1);
397
- fired = true;
398
- listener();
399
- });
400
- return;
401
- }
402
- var blankUrl = 'about:blank';
403
- if (win.location.href !== blankUrl ||
404
- iframeEl.src === blankUrl ||
405
- iframeEl.src === '') {
406
- setTimeout(listener, 0);
407
- return;
408
- }
409
- iframeEl.addEventListener('load', listener);
410
- }
411
- function isStylesheetLoaded(link) {
412
- if (!link.getAttribute('href'))
413
- return true;
414
- return link.sheet !== null;
415
- }
416
- function onceStylesheetLoaded(link, listener, iframeLoadTimeout) {
417
- var fired = false;
418
- var styleSheetLoaded;
419
- try {
420
- styleSheetLoaded = link.sheet;
421
- }
422
- catch (error) {
423
- return;
424
- }
425
- if (styleSheetLoaded)
426
- return;
427
- var timer = setTimeout(function () {
428
- if (!fired) {
429
- listener();
430
- fired = true;
431
- }
432
- }, iframeLoadTimeout);
433
- link.addEventListener('load', function () {
434
- clearTimeout(timer);
435
- fired = true;
436
- listener();
437
- });
438
- }
439
- function serializeNode(n, options) {
440
- var doc = options.doc, mirror = options.mirror, blockClass = options.blockClass, blockSelector = options.blockSelector, maskTextClass = options.maskTextClass, maskTextSelector = options.maskTextSelector, inlineStylesheet = options.inlineStylesheet, _a = options.maskInputOptions, maskInputOptions = _a === void 0 ? {} : _a, maskTextFn = options.maskTextFn, maskInputFn = options.maskInputFn, _b = options.dataURLOptions, dataURLOptions = _b === void 0 ? {} : _b, inlineImages = options.inlineImages, recordCanvas = options.recordCanvas, keepIframeSrcFn = options.keepIframeSrcFn, _c = options.newlyAddedElement, newlyAddedElement = _c === void 0 ? false : _c, enableStrictPrivacy = options.enableStrictPrivacy;
441
- var rootId = getRootId(doc, mirror);
442
- switch (n.nodeType) {
443
- case n.DOCUMENT_NODE:
444
- if (n.compatMode !== 'CSS1Compat') {
445
- return {
446
- type: NodeType$2.Document,
447
- childNodes: [],
448
- compatMode: n.compatMode,
449
- rootId: rootId
450
- };
451
- }
452
- else {
453
- return {
454
- type: NodeType$2.Document,
455
- childNodes: [],
456
- rootId: rootId
457
- };
458
- }
459
- case n.DOCUMENT_TYPE_NODE:
460
- return {
461
- type: NodeType$2.DocumentType,
462
- name: n.name,
463
- publicId: n.publicId,
464
- systemId: n.systemId,
465
- rootId: rootId
466
- };
467
- case n.ELEMENT_NODE:
468
- return serializeElementNode(n, {
469
- doc: doc,
470
- blockClass: blockClass,
471
- blockSelector: blockSelector,
472
- inlineStylesheet: inlineStylesheet,
473
- maskInputOptions: maskInputOptions,
474
- maskInputFn: maskInputFn,
475
- dataURLOptions: dataURLOptions,
476
- inlineImages: inlineImages,
477
- recordCanvas: recordCanvas,
478
- keepIframeSrcFn: keepIframeSrcFn,
479
- newlyAddedElement: newlyAddedElement,
480
- enableStrictPrivacy: enableStrictPrivacy,
481
- rootId: rootId
482
- });
483
- case n.TEXT_NODE:
484
- return serializeTextNode(n, {
485
- maskTextClass: maskTextClass,
486
- maskTextSelector: maskTextSelector,
487
- maskTextFn: maskTextFn,
488
- enableStrictPrivacy: enableStrictPrivacy,
489
- rootId: rootId
490
- });
491
- case n.CDATA_SECTION_NODE:
492
- return {
493
- type: NodeType$2.CDATA,
494
- textContent: '',
495
- rootId: rootId
496
- };
497
- case n.COMMENT_NODE:
498
- return {
499
- type: NodeType$2.Comment,
500
- textContent: n.textContent || '',
501
- rootId: rootId
502
- };
503
- default:
504
- return false;
505
- }
506
- }
507
- function getRootId(doc, mirror) {
508
- if (!mirror.hasNode(doc))
509
- return undefined;
510
- var docId = mirror.getId(doc);
511
- return docId === 1 ? undefined : docId;
512
- }
513
- function serializeTextNode(n, options) {
514
- var _a;
515
- var maskTextClass = options.maskTextClass, maskTextSelector = options.maskTextSelector, maskTextFn = options.maskTextFn, enableStrictPrivacy = options.enableStrictPrivacy, rootId = options.rootId;
516
- var parentTagName = n.parentNode && n.parentNode.tagName;
517
- var textContent = n.textContent;
518
- var isStyle = parentTagName === 'STYLE' ? true : undefined;
519
- var isScript = parentTagName === 'SCRIPT' ? true : undefined;
520
- var textContentHandled = false;
521
- if (isStyle && textContent) {
522
- try {
523
- if (n.nextSibling || n.previousSibling) {
524
- }
525
- else if ((_a = n.parentNode.sheet) === null || _a === void 0 ? void 0 : _a.cssRules) {
526
- textContent = stringifyStyleSheet(n.parentNode.sheet);
527
- }
528
- }
529
- catch (err) {
530
- console.warn("Cannot get CSS styles from text's parentNode. Error: " + err, n);
531
- }
532
- textContent = absoluteToStylesheet(textContent, getHref());
533
- textContentHandled = true;
534
- }
535
- if (isScript) {
536
- textContent = 'SCRIPT_PLACEHOLDER';
537
- textContentHandled = true;
538
- }
539
- else if (parentTagName === 'NOSCRIPT') {
540
- textContent = '';
541
- textContentHandled = true;
542
- }
543
- if (!isStyle &&
544
- !isScript &&
545
- textContent &&
546
- needMaskingText(n, maskTextClass, maskTextSelector)) {
547
- textContent = maskTextFn
548
- ? maskTextFn(textContent)
549
- : textContent.replace(/[\S]/g, '*');
550
- }
551
- if (enableStrictPrivacy && !textContentHandled && parentTagName) {
552
- var IGNORE_TAG_NAMES = new Set([
553
- 'HEAD',
554
- 'TITLE',
555
- 'STYLE',
556
- 'SCRIPT',
557
- 'HTML',
558
- 'BODY',
559
- 'NOSCRIPT',
560
- ]);
561
- if (!IGNORE_TAG_NAMES.has(parentTagName) && textContent) {
562
- textContent = obfuscateText(textContent);
563
- }
564
- }
565
- return {
566
- type: NodeType$2.Text,
567
- textContent: textContent || '',
568
- isStyle: isStyle,
569
- rootId: rootId
570
- };
571
- }
572
- function serializeElementNode(n, options) {
573
- var doc = options.doc, blockClass = options.blockClass, blockSelector = options.blockSelector, inlineStylesheet = options.inlineStylesheet, _a = options.maskInputOptions, maskInputOptions = _a === void 0 ? {} : _a, maskInputFn = options.maskInputFn, _b = options.dataURLOptions, dataURLOptions = _b === void 0 ? {} : _b, inlineImages = options.inlineImages, recordCanvas = options.recordCanvas, keepIframeSrcFn = options.keepIframeSrcFn, _c = options.newlyAddedElement, newlyAddedElement = _c === void 0 ? false : _c, enableStrictPrivacy = options.enableStrictPrivacy, rootId = options.rootId;
574
- var needBlock = _isBlockedElement(n, blockClass, blockSelector);
575
- var tagName = getValidTagName$1(n);
576
- var attributes = {};
577
- var len = n.attributes.length;
578
- for (var i = 0; i < len; i++) {
579
- var attr = n.attributes[i];
580
- attributes[attr.name] = transformAttribute(doc, tagName, attr.name, attr.value);
581
- }
582
- if (tagName === 'link' && inlineStylesheet) {
583
- var stylesheet = Array.from(doc.styleSheets).find(function (s) {
584
- return s.href === n.href;
585
- });
586
- var cssText = null;
587
- if (stylesheet) {
588
- cssText = getCssRulesString(stylesheet);
589
- }
590
- if (cssText) {
591
- delete attributes.rel;
592
- delete attributes.href;
593
- attributes._cssText = absoluteToStylesheet(cssText, stylesheet.href);
594
- }
595
- }
596
- if (tagName === 'style' &&
597
- n.sheet &&
598
- !(n.innerText || n.textContent || '').trim().length) {
599
- var cssText = getCssRulesString(n.sheet);
600
- if (cssText) {
601
- attributes._cssText = absoluteToStylesheet(cssText, getHref());
602
- }
603
- }
604
- if (tagName === 'input' || tagName === 'textarea' || tagName === 'select') {
605
- var value = n.value;
606
- if (attributes.type !== 'radio' &&
607
- attributes.type !== 'checkbox' &&
608
- attributes.type !== 'submit' &&
609
- attributes.type !== 'button' &&
610
- value) {
611
- attributes.value = maskInputValue({
612
- type: attributes.type,
613
- tagName: tagName,
614
- value: value,
615
- maskInputOptions: maskInputOptions,
616
- maskInputFn: maskInputFn
617
- });
618
- }
619
- else if (n.checked) {
620
- attributes.checked = n.checked;
621
- }
622
- }
623
- if (tagName === 'option') {
624
- if (n.selected && !maskInputOptions['select']) {
625
- attributes.selected = true;
626
- }
627
- else {
628
- delete attributes.selected;
629
- }
630
- }
631
- if (tagName === 'canvas' && recordCanvas) {
632
- if (n.__context === '2d') {
633
- if (!is2DCanvasBlank(n)) {
634
- attributes.rr_dataURL = n.toDataURL(dataURLOptions.type, dataURLOptions.quality);
635
- }
636
- }
637
- else if (!('__context' in n)) {
638
- var canvasDataURL = n.toDataURL(dataURLOptions.type, dataURLOptions.quality);
639
- var blankCanvas = document.createElement('canvas');
640
- blankCanvas.width = n.width;
641
- blankCanvas.height = n.height;
642
- var blankCanvasDataURL = blankCanvas.toDataURL(dataURLOptions.type, dataURLOptions.quality);
643
- if (canvasDataURL !== blankCanvasDataURL) {
644
- attributes.rr_dataURL = canvasDataURL;
645
- }
646
- }
647
- }
648
- if (tagName === 'img' && inlineImages) {
649
- if (!canvasService) {
650
- canvasService = doc.createElement('canvas');
651
- canvasCtx = canvasService.getContext('2d');
652
- }
653
- var image_1 = n;
654
- var oldValue_1 = image_1.crossOrigin;
655
- image_1.crossOrigin = 'anonymous';
656
- var recordInlineImage = function () {
657
- try {
658
- canvasService.width = image_1.naturalWidth;
659
- canvasService.height = image_1.naturalHeight;
660
- canvasCtx.drawImage(image_1, 0, 0);
661
- attributes.rr_dataURL = canvasService.toDataURL(dataURLOptions.type, dataURLOptions.quality);
662
- }
663
- catch (err) {
664
- console.warn("Cannot inline img src=" + image_1.currentSrc + "! Error: " + err);
665
- }
666
- oldValue_1
667
- ? (attributes.crossOrigin = oldValue_1)
668
- : image_1.removeAttribute('crossorigin');
669
- };
670
- if (image_1.complete && image_1.naturalWidth !== 0)
671
- recordInlineImage();
672
- else
673
- image_1.onload = recordInlineImage;
674
- }
675
- if (tagName === 'audio' || tagName === 'video') {
676
- attributes.rr_mediaState = n.paused
677
- ? 'paused'
678
- : 'played';
679
- attributes.rr_mediaCurrentTime = n.currentTime;
680
- }
681
- if (!newlyAddedElement) {
682
- if (n.scrollLeft) {
683
- attributes.rr_scrollLeft = n.scrollLeft;
684
- }
685
- if (n.scrollTop) {
686
- attributes.rr_scrollTop = n.scrollTop;
687
- }
688
- }
689
- if (needBlock || (tagName === 'img' && enableStrictPrivacy)) {
690
- var _d = n.getBoundingClientRect(), width = _d.width, height = _d.height;
691
- attributes = {
692
- "class": attributes["class"],
693
- rr_width: width + "px",
694
- rr_height: height + "px"
695
- };
696
- needBlock = true;
697
- }
698
- if (tagName === 'iframe' && !keepIframeSrcFn(attributes.src)) {
699
- if (!n.contentDocument) {
700
- attributes.rr_src = attributes.src;
701
- }
702
- delete attributes.src;
703
- }
704
- return {
705
- type: NodeType$2.Element,
706
- tagName: tagName,
707
- attributes: attributes,
708
- childNodes: [],
709
- isSVG: isSVGElement(n) || undefined,
710
- needBlock: needBlock,
711
- rootId: rootId
712
- };
713
- }
714
- function lowerIfExists(maybeAttr) {
715
- if (maybeAttr === undefined) {
716
- return '';
717
- }
718
- else {
719
- return maybeAttr.toLowerCase();
720
- }
721
- }
722
- function slimDOMExcluded(sn, slimDOMOptions) {
723
- if (slimDOMOptions.comment && sn.type === NodeType$2.Comment) {
724
- return true;
725
- }
726
- else if (sn.type === NodeType$2.Element) {
727
- if (slimDOMOptions.script &&
728
- (sn.tagName === 'script' ||
729
- (sn.tagName === 'link' &&
730
- sn.attributes.rel === 'preload' &&
731
- sn.attributes.as === 'script') ||
732
- (sn.tagName === 'link' &&
733
- sn.attributes.rel === 'prefetch' &&
734
- typeof sn.attributes.href === 'string' &&
735
- sn.attributes.href.endsWith('.js')))) {
736
- return true;
737
- }
738
- else if (slimDOMOptions.headFavicon &&
739
- ((sn.tagName === 'link' && sn.attributes.rel === 'shortcut icon') ||
740
- (sn.tagName === 'meta' &&
741
- (lowerIfExists(sn.attributes.name).match(/^msapplication-tile(image|color)$/) ||
742
- lowerIfExists(sn.attributes.name) === 'application-name' ||
743
- lowerIfExists(sn.attributes.rel) === 'icon' ||
744
- lowerIfExists(sn.attributes.rel) === 'apple-touch-icon' ||
745
- lowerIfExists(sn.attributes.rel) === 'shortcut icon')))) {
746
- return true;
747
- }
748
- else if (sn.tagName === 'meta') {
749
- if (slimDOMOptions.headMetaDescKeywords &&
750
- lowerIfExists(sn.attributes.name).match(/^description|keywords$/)) {
751
- return true;
752
- }
753
- else if (slimDOMOptions.headMetaSocial &&
754
- (lowerIfExists(sn.attributes.property).match(/^(og|twitter|fb):/) ||
755
- lowerIfExists(sn.attributes.name).match(/^(og|twitter):/) ||
756
- lowerIfExists(sn.attributes.name) === 'pinterest')) {
757
- return true;
758
- }
759
- else if (slimDOMOptions.headMetaRobots &&
760
- (lowerIfExists(sn.attributes.name) === 'robots' ||
761
- lowerIfExists(sn.attributes.name) === 'googlebot' ||
762
- lowerIfExists(sn.attributes.name) === 'bingbot')) {
763
- return true;
764
- }
765
- else if (slimDOMOptions.headMetaHttpEquiv &&
766
- sn.attributes['http-equiv'] !== undefined) {
767
- return true;
768
- }
769
- else if (slimDOMOptions.headMetaAuthorship &&
770
- (lowerIfExists(sn.attributes.name) === 'author' ||
771
- lowerIfExists(sn.attributes.name) === 'generator' ||
772
- lowerIfExists(sn.attributes.name) === 'framework' ||
773
- lowerIfExists(sn.attributes.name) === 'publisher' ||
774
- lowerIfExists(sn.attributes.name) === 'progid' ||
775
- lowerIfExists(sn.attributes.property).match(/^article:/) ||
776
- lowerIfExists(sn.attributes.property).match(/^product:/))) {
777
- return true;
778
- }
779
- else if (slimDOMOptions.headMetaVerification &&
780
- (lowerIfExists(sn.attributes.name) === 'google-site-verification' ||
781
- lowerIfExists(sn.attributes.name) === 'yandex-verification' ||
782
- lowerIfExists(sn.attributes.name) === 'csrf-token' ||
783
- lowerIfExists(sn.attributes.name) === 'p:domain_verify' ||
784
- lowerIfExists(sn.attributes.name) === 'verify-v1' ||
785
- lowerIfExists(sn.attributes.name) === 'verification' ||
786
- lowerIfExists(sn.attributes.name) === 'shopify-checkout-api-token')) {
787
- return true;
788
- }
789
- }
790
- }
791
- return false;
792
- }
793
- function serializeNodeWithId(n, options) {
794
- var doc = options.doc, mirror = options.mirror, blockClass = options.blockClass, blockSelector = options.blockSelector, maskTextClass = options.maskTextClass, maskTextSelector = options.maskTextSelector, _a = options.skipChild, skipChild = _a === void 0 ? false : _a, _b = options.inlineStylesheet, inlineStylesheet = _b === void 0 ? true : _b, _c = options.maskInputOptions, maskInputOptions = _c === void 0 ? {} : _c, maskTextFn = options.maskTextFn, maskInputFn = options.maskInputFn, slimDOMOptions = options.slimDOMOptions, _d = options.dataURLOptions, dataURLOptions = _d === void 0 ? {} : _d, _e = options.inlineImages, inlineImages = _e === void 0 ? false : _e, _f = options.recordCanvas, recordCanvas = _f === void 0 ? false : _f, onSerialize = options.onSerialize, onIframeLoad = options.onIframeLoad, _g = options.iframeLoadTimeout, iframeLoadTimeout = _g === void 0 ? 5000 : _g, onStylesheetLoad = options.onStylesheetLoad, _h = options.stylesheetLoadTimeout, stylesheetLoadTimeout = _h === void 0 ? 5000 : _h, _j = options.keepIframeSrcFn, keepIframeSrcFn = _j === void 0 ? function () { return false; } : _j, _k = options.newlyAddedElement, newlyAddedElement = _k === void 0 ? false : _k, enableStrictPrivacy = options.enableStrictPrivacy;
795
- var _l = options.preserveWhiteSpace, preserveWhiteSpace = _l === void 0 ? true : _l;
796
- var _serializedNode = serializeNode(n, {
797
- doc: doc,
798
- mirror: mirror,
799
- blockClass: blockClass,
800
- blockSelector: blockSelector,
801
- maskTextClass: maskTextClass,
802
- maskTextSelector: maskTextSelector,
803
- inlineStylesheet: inlineStylesheet,
804
- maskInputOptions: maskInputOptions,
805
- maskTextFn: maskTextFn,
806
- maskInputFn: maskInputFn,
807
- dataURLOptions: dataURLOptions,
808
- inlineImages: inlineImages,
809
- recordCanvas: recordCanvas,
810
- keepIframeSrcFn: keepIframeSrcFn,
811
- newlyAddedElement: newlyAddedElement,
812
- enableStrictPrivacy: enableStrictPrivacy
813
- });
814
- if (!_serializedNode) {
815
- console.warn(n, 'not serialized');
816
- return null;
817
- }
818
- var id;
819
- if (mirror.hasNode(n)) {
820
- id = mirror.getId(n);
821
- }
822
- else if (slimDOMExcluded(_serializedNode, slimDOMOptions) ||
823
- (!preserveWhiteSpace &&
824
- _serializedNode.type === NodeType$2.Text &&
825
- !_serializedNode.isStyle &&
826
- !_serializedNode.textContent.replace(/^\s+|\s+$/gm, '').length)) {
827
- id = IGNORED_NODE;
828
- }
829
- else {
830
- id = genId();
831
- }
832
- if (id === IGNORED_NODE) {
833
- return null;
834
- }
835
- var serializedNode = Object.assign(_serializedNode, { id: id });
836
- mirror.add(n, serializedNode);
837
- if (onSerialize) {
838
- onSerialize(n);
839
- }
840
- var recordChild = !skipChild;
841
- if (serializedNode.type === NodeType$2.Element) {
842
- recordChild = recordChild && !serializedNode.needBlock;
843
- if (serializedNode.needBlock && serializedNode.tagName === 'img') {
844
- var clone = n.cloneNode();
845
- clone.src = '';
846
- mirror.add(clone, serializedNode);
847
- }
848
- delete serializedNode.needBlock;
849
- if (n.shadowRoot)
850
- serializedNode.isShadowHost = true;
851
- }
852
- if ((serializedNode.type === NodeType$2.Document ||
853
- serializedNode.type === NodeType$2.Element) &&
854
- recordChild) {
855
- if (slimDOMOptions.headWhitespace &&
856
- serializedNode.type === NodeType$2.Element &&
857
- serializedNode.tagName === 'head') {
858
- preserveWhiteSpace = false;
859
- }
860
- var bypassOptions = {
861
- doc: doc,
862
- mirror: mirror,
863
- blockClass: blockClass,
864
- blockSelector: blockSelector,
865
- maskTextClass: maskTextClass,
866
- maskTextSelector: maskTextSelector,
867
- skipChild: skipChild,
868
- inlineStylesheet: inlineStylesheet,
869
- maskInputOptions: maskInputOptions,
870
- maskTextFn: maskTextFn,
871
- maskInputFn: maskInputFn,
872
- slimDOMOptions: slimDOMOptions,
873
- dataURLOptions: dataURLOptions,
874
- inlineImages: inlineImages,
875
- recordCanvas: recordCanvas,
876
- preserveWhiteSpace: preserveWhiteSpace,
877
- onSerialize: onSerialize,
878
- onIframeLoad: onIframeLoad,
879
- iframeLoadTimeout: iframeLoadTimeout,
880
- onStylesheetLoad: onStylesheetLoad,
881
- stylesheetLoadTimeout: stylesheetLoadTimeout,
882
- keepIframeSrcFn: keepIframeSrcFn,
883
- enableStrictPrivacy: enableStrictPrivacy
884
- };
885
- for (var _i = 0, _m = Array.from(n.childNodes); _i < _m.length; _i++) {
886
- var childN = _m[_i];
887
- var serializedChildNode = serializeNodeWithId(childN, bypassOptions);
888
- if (serializedChildNode) {
889
- serializedNode.childNodes.push(serializedChildNode);
890
- }
891
- }
892
- if (isElement(n) && n.shadowRoot) {
893
- for (var _o = 0, _p = Array.from(n.shadowRoot.childNodes); _o < _p.length; _o++) {
894
- var childN = _p[_o];
895
- var serializedChildNode = serializeNodeWithId(childN, bypassOptions);
896
- if (serializedChildNode) {
897
- serializedChildNode.isShadow = true;
898
- serializedNode.childNodes.push(serializedChildNode);
899
- }
900
- }
901
- }
902
- }
903
- if (n.parentNode && isShadowRoot(n.parentNode)) {
904
- serializedNode.isShadow = true;
905
- }
906
- if (serializedNode.type === NodeType$2.Element &&
907
- serializedNode.tagName === 'iframe') {
908
- onceIframeLoaded(n, function () {
909
- var iframeDoc = n.contentDocument;
910
- if (iframeDoc && onIframeLoad) {
911
- var serializedIframeNode = serializeNodeWithId(iframeDoc, {
912
- doc: iframeDoc,
913
- mirror: mirror,
914
- blockClass: blockClass,
915
- blockSelector: blockSelector,
916
- maskTextClass: maskTextClass,
917
- maskTextSelector: maskTextSelector,
918
- skipChild: false,
919
- inlineStylesheet: inlineStylesheet,
920
- maskInputOptions: maskInputOptions,
921
- maskTextFn: maskTextFn,
922
- maskInputFn: maskInputFn,
923
- slimDOMOptions: slimDOMOptions,
924
- dataURLOptions: dataURLOptions,
925
- inlineImages: inlineImages,
926
- recordCanvas: recordCanvas,
927
- preserveWhiteSpace: preserveWhiteSpace,
928
- onSerialize: onSerialize,
929
- onIframeLoad: onIframeLoad,
930
- iframeLoadTimeout: iframeLoadTimeout,
931
- keepIframeSrcFn: keepIframeSrcFn,
932
- enableStrictPrivacy: enableStrictPrivacy
933
- });
934
- if (serializedIframeNode) {
935
- onIframeLoad(n, serializedIframeNode);
936
- }
937
- }
938
- }, iframeLoadTimeout);
939
- }
940
- if (serializedNode.type === NodeType$2.Element &&
941
- serializedNode.tagName === 'link' &&
942
- serializedNode.attributes.rel === 'stylesheet') {
943
- onceStylesheetLoaded(n, function () {
944
- if (onStylesheetLoad) {
945
- var serializedLinkNode = serializeNodeWithId(n, {
946
- doc: doc,
947
- mirror: mirror,
948
- blockClass: blockClass,
949
- blockSelector: blockSelector,
950
- maskTextClass: maskTextClass,
951
- maskTextSelector: maskTextSelector,
952
- skipChild: false,
953
- inlineStylesheet: inlineStylesheet,
954
- maskInputOptions: maskInputOptions,
955
- maskTextFn: maskTextFn,
956
- maskInputFn: maskInputFn,
957
- slimDOMOptions: slimDOMOptions,
958
- dataURLOptions: dataURLOptions,
959
- inlineImages: inlineImages,
960
- recordCanvas: recordCanvas,
961
- preserveWhiteSpace: preserveWhiteSpace,
962
- onSerialize: onSerialize,
963
- onIframeLoad: onIframeLoad,
964
- onStylesheetLoad: onStylesheetLoad,
965
- iframeLoadTimeout: iframeLoadTimeout,
966
- keepIframeSrcFn: keepIframeSrcFn,
967
- enableStrictPrivacy: enableStrictPrivacy
968
- });
969
- if (serializedLinkNode) {
970
- onStylesheetLoad(n, serializedLinkNode);
971
- }
972
- }
973
- }, stylesheetLoadTimeout);
974
- if (isStylesheetLoaded(n) === false)
975
- return null;
976
- }
977
- return serializedNode;
978
- }
979
- function snapshot(n, options) {
980
- var _a = options || {}, _b = _a.mirror, mirror = _b === void 0 ? new Mirror$2() : _b, _c = _a.blockClass, blockClass = _c === void 0 ? 'highlight-block' : _c, _d = _a.blockSelector, blockSelector = _d === void 0 ? null : _d, _e = _a.maskTextClass, maskTextClass = _e === void 0 ? 'highlight-mask' : _e, _f = _a.maskTextSelector, maskTextSelector = _f === void 0 ? null : _f, _g = _a.inlineStylesheet, inlineStylesheet = _g === void 0 ? true : _g, _h = _a.inlineImages, inlineImages = _h === void 0 ? false : _h, _j = _a.recordCanvas, recordCanvas = _j === void 0 ? false : _j, _k = _a.maskAllInputs, maskAllInputs = _k === void 0 ? false : _k, maskTextFn = _a.maskTextFn, maskInputFn = _a.maskInputFn, _l = _a.slimDOM, slimDOM = _l === void 0 ? false : _l, dataURLOptions = _a.dataURLOptions, preserveWhiteSpace = _a.preserveWhiteSpace, onSerialize = _a.onSerialize, onIframeLoad = _a.onIframeLoad, iframeLoadTimeout = _a.iframeLoadTimeout, onStylesheetLoad = _a.onStylesheetLoad, stylesheetLoadTimeout = _a.stylesheetLoadTimeout, _m = _a.keepIframeSrcFn, keepIframeSrcFn = _m === void 0 ? function () { return false; } : _m, _o = _a.enableStrictPrivacy, enableStrictPrivacy = _o === void 0 ? false : _o;
981
- var maskInputOptions = maskAllInputs === true
982
- ? {
983
- color: true,
984
- date: true,
985
- 'datetime-local': true,
986
- email: true,
987
- month: true,
988
- number: true,
989
- range: true,
990
- search: true,
991
- tel: true,
992
- text: true,
993
- time: true,
994
- url: true,
995
- week: true,
996
- textarea: true,
997
- select: true,
998
- password: true
999
- }
1000
- : maskAllInputs === false
1001
- ? {
1002
- password: true
1003
- }
1004
- : maskAllInputs;
1005
- var slimDOMOptions = slimDOM === true || slimDOM === 'all'
1006
- ?
1007
- {
1008
- script: true,
1009
- comment: true,
1010
- headFavicon: true,
1011
- headWhitespace: true,
1012
- headMetaDescKeywords: slimDOM === 'all',
1013
- headMetaSocial: true,
1014
- headMetaRobots: true,
1015
- headMetaHttpEquiv: true,
1016
- headMetaAuthorship: true,
1017
- headMetaVerification: true
1018
- }
1019
- : slimDOM === false
1020
- ? {}
1021
- : slimDOM;
1022
- return serializeNodeWithId(n, {
1023
- doc: n,
1024
- mirror: mirror,
1025
- blockClass: blockClass,
1026
- blockSelector: blockSelector,
1027
- maskTextClass: maskTextClass,
1028
- maskTextSelector: maskTextSelector,
1029
- skipChild: false,
1030
- inlineStylesheet: inlineStylesheet,
1031
- maskInputOptions: maskInputOptions,
1032
- maskTextFn: maskTextFn,
1033
- maskInputFn: maskInputFn,
1034
- slimDOMOptions: slimDOMOptions,
1035
- dataURLOptions: dataURLOptions,
1036
- inlineImages: inlineImages,
1037
- recordCanvas: recordCanvas,
1038
- preserveWhiteSpace: preserveWhiteSpace,
1039
- onSerialize: onSerialize,
1040
- onIframeLoad: onIframeLoad,
1041
- iframeLoadTimeout: iframeLoadTimeout,
1042
- onStylesheetLoad: onStylesheetLoad,
1043
- stylesheetLoadTimeout: stylesheetLoadTimeout,
1044
- keepIframeSrcFn: keepIframeSrcFn,
1045
- newlyAddedElement: false,
1046
- enableStrictPrivacy: enableStrictPrivacy
1047
- });
1048
- }
1049
-
1050
- var commentre = /\/\*[^*]*\*+([^/*][^*]*\*+)*\//g;
1051
- function parse(css, options) {
1052
- if (options === void 0) { options = {}; }
1053
- var lineno = 1;
1054
- var column = 1;
1055
- function updatePosition(str) {
1056
- var lines = str.match(/\n/g);
1057
- if (lines) {
1058
- lineno += lines.length;
1059
- }
1060
- var i = str.lastIndexOf('\n');
1061
- column = i === -1 ? column + str.length : str.length - i;
1062
- }
1063
- function position() {
1064
- var start = { line: lineno, column: column };
1065
- return function (node) {
1066
- node.position = new Position(start);
1067
- whitespace();
1068
- return node;
1069
- };
1070
- }
1071
- var Position = (function () {
1072
- function Position(start) {
1073
- this.start = start;
1074
- this.end = { line: lineno, column: column };
1075
- this.source = options.source;
1076
- }
1077
- return Position;
1078
- }());
1079
- Position.prototype.content = css;
1080
- var errorsList = [];
1081
- function error(msg) {
1082
- var err = new Error(options.source + ':' + lineno + ':' + column + ': ' + msg);
1083
- err.reason = msg;
1084
- err.filename = options.source;
1085
- err.line = lineno;
1086
- err.column = column;
1087
- err.source = css;
1088
- if (options.silent) {
1089
- errorsList.push(err);
1090
- }
1091
- else {
1092
- throw err;
1093
- }
1094
- }
1095
- function stylesheet() {
1096
- var rulesList = rules();
1097
- return {
1098
- type: 'stylesheet',
1099
- stylesheet: {
1100
- source: options.source,
1101
- rules: rulesList,
1102
- parsingErrors: errorsList
1103
- }
1104
- };
1105
- }
1106
- function open() {
1107
- return match(/^{\s*/);
1108
- }
1109
- function close() {
1110
- return match(/^}/);
1111
- }
1112
- function rules() {
1113
- var node;
1114
- var rules = [];
1115
- whitespace();
1116
- comments(rules);
1117
- while (css.length && css.charAt(0) !== '}' && (node = atrule() || rule())) {
1118
- if (node !== false) {
1119
- rules.push(node);
1120
- comments(rules);
1121
- }
1122
- }
1123
- return rules;
1124
- }
1125
- function match(re) {
1126
- var m = re.exec(css);
1127
- if (!m) {
1128
- return;
1129
- }
1130
- var str = m[0];
1131
- updatePosition(str);
1132
- css = css.slice(str.length);
1133
- return m;
1134
- }
1135
- function whitespace() {
1136
- match(/^\s*/);
1137
- }
1138
- function comments(rules) {
1139
- if (rules === void 0) { rules = []; }
1140
- var c;
1141
- while ((c = comment())) {
1142
- if (c !== false) {
1143
- rules.push(c);
1144
- }
1145
- c = comment();
1146
- }
1147
- return rules;
1148
- }
1149
- function comment() {
1150
- var pos = position();
1151
- if ('/' !== css.charAt(0) || '*' !== css.charAt(1)) {
1152
- return;
1153
- }
1154
- var i = 2;
1155
- while ('' !== css.charAt(i) &&
1156
- ('*' !== css.charAt(i) || '/' !== css.charAt(i + 1))) {
1157
- ++i;
1158
- }
1159
- i += 2;
1160
- if ('' === css.charAt(i - 1)) {
1161
- return error('End of comment missing');
1162
- }
1163
- var str = css.slice(2, i - 2);
1164
- column += 2;
1165
- updatePosition(str);
1166
- css = css.slice(i);
1167
- column += 2;
1168
- return pos({
1169
- type: 'comment',
1170
- comment: str
1171
- });
1172
- }
1173
- function selector() {
1174
- var m = match(/^([^{]+)/);
1175
- if (!m) {
1176
- return;
1177
- }
1178
- return trim(m[0])
1179
- .replace(/\/\*([^*]|[\r\n]|(\*+([^*/]|[\r\n])))*\*\/+/g, '')
1180
- .replace(/"(?:\\"|[^"])*"|'(?:\\'|[^'])*'/g, function (m) {
1181
- return m.replace(/,/g, '\u200C');
1182
- })
1183
- .split(/\s*(?![^(]*\)),\s*/)
1184
- .map(function (s) {
1185
- return s.replace(/\u200C/g, ',');
1186
- });
1187
- }
1188
- function declaration() {
1189
- var pos = position();
1190
- var propMatch = match(/^(\*?[-#\/\*\\\w]+(\[[0-9a-z_-]+\])?)\s*/);
1191
- if (!propMatch) {
1192
- return;
1193
- }
1194
- var prop = trim(propMatch[0]);
1195
- if (!match(/^:\s*/)) {
1196
- return error("property missing ':'");
1197
- }
1198
- var val = match(/^((?:'(?:\\'|.)*?'|"(?:\\"|.)*?"|\([^\)]*?\)|[^};])+)/);
1199
- var ret = pos({
1200
- type: 'declaration',
1201
- property: prop.replace(commentre, ''),
1202
- value: val ? trim(val[0]).replace(commentre, '') : ''
1203
- });
1204
- match(/^[;\s]*/);
1205
- return ret;
1206
- }
1207
- function declarations() {
1208
- var decls = [];
1209
- if (!open()) {
1210
- return error("missing '{'");
1211
- }
1212
- comments(decls);
1213
- var decl;
1214
- while ((decl = declaration())) {
1215
- if (decl !== false) {
1216
- decls.push(decl);
1217
- comments(decls);
1218
- }
1219
- decl = declaration();
1220
- }
1221
- if (!close()) {
1222
- return error("missing '}'");
1223
- }
1224
- return decls;
1225
- }
1226
- function keyframe() {
1227
- var m;
1228
- var vals = [];
1229
- var pos = position();
1230
- while ((m = match(/^((\d+\.\d+|\.\d+|\d+)%?|[a-z]+)\s*/))) {
1231
- vals.push(m[1]);
1232
- match(/^,\s*/);
1233
- }
1234
- if (!vals.length) {
1235
- return;
1236
- }
1237
- return pos({
1238
- type: 'keyframe',
1239
- values: vals,
1240
- declarations: declarations()
1241
- });
1242
- }
1243
- function atkeyframes() {
1244
- var pos = position();
1245
- var m = match(/^@([-\w]+)?keyframes\s*/);
1246
- if (!m) {
1247
- return;
1248
- }
1249
- var vendor = m[1];
1250
- m = match(/^([-\w]+)\s*/);
1251
- if (!m) {
1252
- return error('@keyframes missing name');
1253
- }
1254
- var name = m[1];
1255
- if (!open()) {
1256
- return error("@keyframes missing '{'");
1257
- }
1258
- var frame;
1259
- var frames = comments();
1260
- while ((frame = keyframe())) {
1261
- frames.push(frame);
1262
- frames = frames.concat(comments());
1263
- }
1264
- if (!close()) {
1265
- return error("@keyframes missing '}'");
1266
- }
1267
- return pos({
1268
- type: 'keyframes',
1269
- name: name,
1270
- vendor: vendor,
1271
- keyframes: frames
1272
- });
1273
- }
1274
- function atsupports() {
1275
- var pos = position();
1276
- var m = match(/^@supports *([^{]+)/);
1277
- if (!m) {
1278
- return;
1279
- }
1280
- var supports = trim(m[1]);
1281
- if (!open()) {
1282
- return error("@supports missing '{'");
1283
- }
1284
- var style = comments().concat(rules());
1285
- if (!close()) {
1286
- return error("@supports missing '}'");
1287
- }
1288
- return pos({
1289
- type: 'supports',
1290
- supports: supports,
1291
- rules: style
1292
- });
1293
- }
1294
- function athost() {
1295
- var pos = position();
1296
- var m = match(/^@host\s*/);
1297
- if (!m) {
1298
- return;
1299
- }
1300
- if (!open()) {
1301
- return error("@host missing '{'");
1302
- }
1303
- var style = comments().concat(rules());
1304
- if (!close()) {
1305
- return error("@host missing '}'");
1306
- }
1307
- return pos({
1308
- type: 'host',
1309
- rules: style
1310
- });
1311
- }
1312
- function atmedia() {
1313
- var pos = position();
1314
- var m = match(/^@media *([^{]+)/);
1315
- if (!m) {
1316
- return;
1317
- }
1318
- var media = trim(m[1]);
1319
- if (!open()) {
1320
- return error("@media missing '{'");
1321
- }
1322
- var style = comments().concat(rules());
1323
- if (!close()) {
1324
- return error("@media missing '}'");
1325
- }
1326
- return pos({
1327
- type: 'media',
1328
- media: media,
1329
- rules: style
1330
- });
1331
- }
1332
- function atcustommedia() {
1333
- var pos = position();
1334
- var m = match(/^@custom-media\s+(--[^\s]+)\s*([^{;]+);/);
1335
- if (!m) {
1336
- return;
1337
- }
1338
- return pos({
1339
- type: 'custom-media',
1340
- name: trim(m[1]),
1341
- media: trim(m[2])
1342
- });
1343
- }
1344
- function atpage() {
1345
- var pos = position();
1346
- var m = match(/^@page */);
1347
- if (!m) {
1348
- return;
1349
- }
1350
- var sel = selector() || [];
1351
- if (!open()) {
1352
- return error("@page missing '{'");
1353
- }
1354
- var decls = comments();
1355
- var decl;
1356
- while ((decl = declaration())) {
1357
- decls.push(decl);
1358
- decls = decls.concat(comments());
1359
- }
1360
- if (!close()) {
1361
- return error("@page missing '}'");
1362
- }
1363
- return pos({
1364
- type: 'page',
1365
- selectors: sel,
1366
- declarations: decls
1367
- });
1368
- }
1369
- function atdocument() {
1370
- var pos = position();
1371
- var m = match(/^@([-\w]+)?document *([^{]+)/);
1372
- if (!m) {
1373
- return;
1374
- }
1375
- var vendor = trim(m[1]);
1376
- var doc = trim(m[2]);
1377
- if (!open()) {
1378
- return error("@document missing '{'");
1379
- }
1380
- var style = comments().concat(rules());
1381
- if (!close()) {
1382
- return error("@document missing '}'");
1383
- }
1384
- return pos({
1385
- type: 'document',
1386
- document: doc,
1387
- vendor: vendor,
1388
- rules: style
1389
- });
1390
- }
1391
- function atfontface() {
1392
- var pos = position();
1393
- var m = match(/^@font-face\s*/);
1394
- if (!m) {
1395
- return;
1396
- }
1397
- if (!open()) {
1398
- return error("@font-face missing '{'");
1399
- }
1400
- var decls = comments();
1401
- var decl;
1402
- while ((decl = declaration())) {
1403
- decls.push(decl);
1404
- decls = decls.concat(comments());
1405
- }
1406
- if (!close()) {
1407
- return error("@font-face missing '}'");
1408
- }
1409
- return pos({
1410
- type: 'font-face',
1411
- declarations: decls
1412
- });
1413
- }
1414
- var atimport = _compileAtrule('import');
1415
- var atcharset = _compileAtrule('charset');
1416
- var atnamespace = _compileAtrule('namespace');
1417
- function _compileAtrule(name) {
1418
- var re = new RegExp('^@' + name + '\\s*([^;]+);');
1419
- return function () {
1420
- var pos = position();
1421
- var m = match(re);
1422
- if (!m) {
1423
- return;
1424
- }
1425
- var ret = { type: name };
1426
- ret[name] = m[1].trim();
1427
- return pos(ret);
1428
- };
1429
- }
1430
- function atrule() {
1431
- if (css[0] !== '@') {
1432
- return;
1433
- }
1434
- return (atkeyframes() ||
1435
- atmedia() ||
1436
- atcustommedia() ||
1437
- atsupports() ||
1438
- atimport() ||
1439
- atcharset() ||
1440
- atnamespace() ||
1441
- atdocument() ||
1442
- atpage() ||
1443
- athost() ||
1444
- atfontface());
1445
- }
1446
- function rule() {
1447
- var pos = position();
1448
- var sel = selector();
1449
- if (!sel) {
1450
- return error('selector missing');
1451
- }
1452
- comments();
1453
- return pos({
1454
- type: 'rule',
1455
- selectors: sel,
1456
- declarations: declarations()
1457
- });
1458
- }
1459
- return addParent(stylesheet());
1460
- }
1461
- function trim(str) {
1462
- return str ? str.replace(/^\s+|\s+$/g, '') : '';
1463
- }
1464
- function addParent(obj, parent) {
1465
- var isNode = obj && typeof obj.type === 'string';
1466
- var childParent = isNode ? obj : parent;
1467
- for (var _i = 0, _a = Object.keys(obj); _i < _a.length; _i++) {
1468
- var k = _a[_i];
1469
- var value = obj[k];
1470
- if (Array.isArray(value)) {
1471
- value.forEach(function (v) {
1472
- addParent(v, childParent);
1473
- });
1474
- }
1475
- else if (value && typeof value === 'object') {
1476
- addParent(value, childParent);
1477
- }
1478
- }
1479
- if (isNode) {
1480
- Object.defineProperty(obj, 'parent', {
1481
- configurable: true,
1482
- writable: true,
1483
- enumerable: false,
1484
- value: parent || null
1485
- });
1486
- }
1487
- return obj;
1488
- }
1489
-
1490
- var tagMap = {
1491
- script: 'noscript',
1492
- altglyph: 'altGlyph',
1493
- altglyphdef: 'altGlyphDef',
1494
- altglyphitem: 'altGlyphItem',
1495
- animatecolor: 'animateColor',
1496
- animatemotion: 'animateMotion',
1497
- animatetransform: 'animateTransform',
1498
- clippath: 'clipPath',
1499
- feblend: 'feBlend',
1500
- fecolormatrix: 'feColorMatrix',
1501
- fecomponenttransfer: 'feComponentTransfer',
1502
- fecomposite: 'feComposite',
1503
- feconvolvematrix: 'feConvolveMatrix',
1504
- fediffuselighting: 'feDiffuseLighting',
1505
- fedisplacementmap: 'feDisplacementMap',
1506
- fedistantlight: 'feDistantLight',
1507
- fedropshadow: 'feDropShadow',
1508
- feflood: 'feFlood',
1509
- fefunca: 'feFuncA',
1510
- fefuncb: 'feFuncB',
1511
- fefuncg: 'feFuncG',
1512
- fefuncr: 'feFuncR',
1513
- fegaussianblur: 'feGaussianBlur',
1514
- feimage: 'feImage',
1515
- femerge: 'feMerge',
1516
- femergenode: 'feMergeNode',
1517
- femorphology: 'feMorphology',
1518
- feoffset: 'feOffset',
1519
- fepointlight: 'fePointLight',
1520
- fespecularlighting: 'feSpecularLighting',
1521
- fespotlight: 'feSpotLight',
1522
- fetile: 'feTile',
1523
- feturbulence: 'feTurbulence',
1524
- foreignobject: 'foreignObject',
1525
- glyphref: 'glyphRef',
1526
- lineargradient: 'linearGradient',
1527
- radialgradient: 'radialGradient'
1528
- };
1529
- function getTagName(n) {
1530
- var tagName = tagMap[n.tagName] ? tagMap[n.tagName] : n.tagName;
1531
- if (tagName === 'link' && n.attributes._cssText) {
1532
- tagName = 'style';
1533
- }
1534
- return tagName;
1535
- }
1536
- function escapeRegExp(str) {
1537
- return str.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
1538
- }
1539
- var HOVER_SELECTOR = /([^\\]):hover/;
1540
- var HOVER_SELECTOR_GLOBAL = new RegExp(HOVER_SELECTOR.source, 'g');
1541
- function addHoverClass(cssText, cache) {
1542
- var _a;
1543
- if (!((_a = window === null || window === void 0 ? void 0 : window.HIG_CONFIGURATION) === null || _a === void 0 ? void 0 : _a.enableOnHoverClass)) {
1544
- return cssText;
1545
- }
1546
- var cachedStyle = cache === null || cache === void 0 ? void 0 : cache.stylesWithHoverClass.get(cssText);
1547
- if (cachedStyle)
1548
- return cachedStyle;
1549
- var ast = parse(cssText, {
1550
- silent: true
1551
- });
1552
- if (!ast.stylesheet) {
1553
- return cssText;
1554
- }
1555
- var selectors = [];
1556
- ast.stylesheet.rules.forEach(function (rule) {
1557
- if ('selectors' in rule) {
1558
- (rule.selectors || []).forEach(function (selector) {
1559
- if (HOVER_SELECTOR.test(selector)) {
1560
- selectors.push(selector);
1561
- }
1562
- });
1563
- }
1564
- });
1565
- if (selectors.length === 0) {
1566
- return cssText;
1567
- }
1568
- var selectorMatcher = new RegExp(selectors
1569
- .filter(function (selector, index) { return selectors.indexOf(selector) === index; })
1570
- .sort(function (a, b) { return b.length - a.length; })
1571
- .map(function (selector) {
1572
- return escapeRegExp(selector);
1573
- })
1574
- .join('|'), 'g');
1575
- var result = cssText.replace(selectorMatcher, function (selector) {
1576
- var newSelector = selector.replace(HOVER_SELECTOR_GLOBAL, '$1.\\:hover');
1577
- return selector + ", " + newSelector;
1578
- });
1579
- cache === null || cache === void 0 ? void 0 : cache.stylesWithHoverClass.set(cssText, result);
1580
- return result;
1581
- }
1582
- function createCache() {
1583
- var stylesWithHoverClass = new Map();
1584
- return {
1585
- stylesWithHoverClass: stylesWithHoverClass
1586
- };
1587
- }
1588
- function buildNode(n, options) {
1589
- var doc = options.doc, hackCss = options.hackCss, cache = options.cache;
1590
- switch (n.type) {
1591
- case NodeType$2.Document:
1592
- return doc.implementation.createDocument(null, '', null);
1593
- case NodeType$2.DocumentType:
1594
- return doc.implementation.createDocumentType(n.name || 'html', n.publicId, n.systemId);
1595
- case NodeType$2.Element:
1596
- var tagName = getTagName(n);
1597
- var node_1;
1598
- if (n.isSVG) {
1599
- node_1 = doc.createElementNS('http://www.w3.org/2000/svg', tagName);
1600
- }
1601
- else {
1602
- node_1 = doc.createElement(tagName);
1603
- }
1604
- var _loop_1 = function (name_1) {
1605
- if (!n.attributes.hasOwnProperty(name_1)) {
1606
- return "continue";
1607
- }
1608
- var value = n.attributes[name_1];
1609
- if (tagName === 'option' && name_1 === 'selected' && value === false) {
1610
- return "continue";
1611
- }
1612
- value =
1613
- typeof value === 'boolean' || typeof value === 'number' ? '' : value;
1614
- if (!name_1.startsWith('rr_')) {
1615
- var isTextarea = tagName === 'textarea' && name_1 === 'value';
1616
- var isRemoteOrDynamicCss = tagName === 'style' && name_1 === '_cssText';
1617
- if (isRemoteOrDynamicCss && hackCss) {
1618
- value = addHoverClass(value, cache);
1619
- if (typeof value === 'string') {
1620
- var regex = /url\(\"https:\/\/\S*(.eot|.woff2|.ttf|.woff)\S*\"\)/gm;
1621
- var m = void 0;
1622
- var fontUrls_1 = [];
1623
- var PROXY_URL_1 = 'https://replay-cors-proxy.highlightrun.workers.dev';
1624
- while ((m = regex.exec(value)) !== null) {
1625
- if (m.index === regex.lastIndex) {
1626
- regex.lastIndex++;
1627
- }
1628
- m.forEach(function (match, groupIndex) {
1629
- if (groupIndex === 0) {
1630
- var url = match.slice(5, match.length - 2);
1631
- fontUrls_1.push({
1632
- originalUrl: url,
1633
- proxyUrl: url.replace(url, PROXY_URL_1 + "?url=" + url)
1634
- });
1635
- }
1636
- });
1637
- }
1638
- fontUrls_1.forEach(function (urlPair) {
1639
- value = value.replace(urlPair.originalUrl, urlPair.proxyUrl);
1640
- });
1641
- }
1642
- }
1643
- if (isTextarea || isRemoteOrDynamicCss) {
1644
- var child = doc.createTextNode(value);
1645
- for (var _i = 0, _a = Array.from(node_1.childNodes); _i < _a.length; _i++) {
1646
- var c = _a[_i];
1647
- if (c.nodeType === node_1.TEXT_NODE) {
1648
- node_1.removeChild(c);
1649
- }
1650
- }
1651
- node_1.appendChild(child);
1652
- return "continue";
1653
- }
1654
- try {
1655
- if (n.isSVG && name_1 === 'xlink:href') {
1656
- node_1.setAttributeNS('http://www.w3.org/1999/xlink', name_1, value);
1657
- }
1658
- else if (name_1 === 'onload' ||
1659
- name_1 === 'onclick' ||
1660
- name_1.substring(0, 7) === 'onmouse') {
1661
- node_1.setAttribute('_' + name_1, value);
1662
- }
1663
- else if (tagName === 'meta' &&
1664
- n.attributes['http-equiv'] === 'Content-Security-Policy' &&
1665
- name_1 === 'content') {
1666
- node_1.setAttribute('csp-content', value);
1667
- return "continue";
1668
- }
1669
- else if (tagName === 'link' &&
1670
- n.attributes.rel === 'preload' &&
1671
- n.attributes.as === 'script') {
1672
- }
1673
- else if (tagName === 'link' &&
1674
- n.attributes.rel === 'prefetch' &&
1675
- typeof n.attributes.href === 'string' &&
1676
- n.attributes.href.endsWith('.js')) {
1677
- }
1678
- else if (tagName === 'img' &&
1679
- n.attributes.srcset &&
1680
- n.attributes.rr_dataURL) {
1681
- node_1.setAttribute('rrweb-original-srcset', n.attributes.srcset);
1682
- }
1683
- else {
1684
- node_1.setAttribute(name_1, value);
1685
- }
1686
- }
1687
- catch (error) {
1688
- }
1689
- }
1690
- else {
1691
- if (tagName === 'canvas' && name_1 === 'rr_dataURL') {
1692
- var image_1 = document.createElement('img');
1693
- image_1.src = value;
1694
- image_1.onload = function () {
1695
- var ctx = node_1.getContext('2d');
1696
- if (ctx) {
1697
- ctx.drawImage(image_1, 0, 0, image_1.width, image_1.height);
1698
- }
1699
- };
1700
- }
1701
- else if (tagName === 'img' && name_1 === 'rr_dataURL') {
1702
- var image = node_1;
1703
- if (!image.currentSrc.startsWith('data:')) {
1704
- image.setAttribute('rrweb-original-src', n.attributes.src);
1705
- image.src = value;
1706
- }
1707
- }
1708
- if (name_1 === 'rr_width') {
1709
- node_1.style.width = value;
1710
- }
1711
- else if (name_1 === 'rr_height') {
1712
- node_1.style.height = value;
1713
- }
1714
- else if (name_1 === 'rr_mediaCurrentTime') {
1715
- node_1.currentTime = n.attributes
1716
- .rr_mediaCurrentTime;
1717
- }
1718
- else if (name_1 === 'rr_mediaState') {
1719
- switch (value) {
1720
- case 'played':
1721
- node_1
1722
- .play()["catch"](function (e) { return console.warn('media playback error', e); });
1723
- break;
1724
- case 'paused':
1725
- node_1.pause();
1726
- break;
1727
- }
1728
- }
1729
- }
1730
- };
1731
- for (var name_1 in n.attributes) {
1732
- _loop_1(name_1);
1733
- }
1734
- if (n.isShadowHost) {
1735
- if (!node_1.shadowRoot) {
1736
- node_1.attachShadow({ mode: 'open' });
1737
- }
1738
- else {
1739
- while (node_1.shadowRoot.firstChild) {
1740
- node_1.shadowRoot.removeChild(node_1.shadowRoot.firstChild);
1741
- }
1742
- }
1743
- }
1744
- return node_1;
1745
- case NodeType$2.Text:
1746
- return doc.createTextNode(n.isStyle && hackCss
1747
- ? addHoverClass(n.textContent, cache)
1748
- : n.textContent);
1749
- case NodeType$2.CDATA:
1750
- return doc.createCDATASection(n.textContent);
1751
- case NodeType$2.Comment:
1752
- return doc.createComment(n.textContent);
1753
- default:
1754
- return null;
1755
- }
1756
- }
1757
- function buildNodeWithSN(n, options) {
1758
- var doc = options.doc, mirror = options.mirror, _a = options.skipChild, skipChild = _a === void 0 ? false : _a, _b = options.hackCss, hackCss = _b === void 0 ? true : _b, afterAppend = options.afterAppend, cache = options.cache;
1759
- var node = buildNode(n, { doc: doc, hackCss: hackCss, cache: cache });
1760
- if (!node) {
1761
- return null;
1762
- }
1763
- if (n.rootId) {
1764
- console.assert(mirror.getNode(n.rootId) === doc, 'Target document should have the same root id.');
1765
- }
1766
- if (n.type === NodeType$2.Document) {
1767
- doc.close();
1768
- doc.open();
1769
- if (n.compatMode === 'BackCompat' &&
1770
- n.childNodes &&
1771
- n.childNodes[0].type !== NodeType$2.DocumentType) {
1772
- if (n.childNodes[0].type === NodeType$2.Element &&
1773
- 'xmlns' in n.childNodes[0].attributes &&
1774
- n.childNodes[0].attributes.xmlns === 'http://www.w3.org/1999/xhtml') {
1775
- doc.write('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">');
1776
- }
1777
- else {
1778
- doc.write('<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "">');
1779
- }
1780
- }
1781
- node = doc;
1782
- }
1783
- mirror.add(node, n);
1784
- if ((n.type === NodeType$2.Document || n.type === NodeType$2.Element) &&
1785
- !skipChild) {
1786
- for (var _i = 0, _c = n.childNodes; _i < _c.length; _i++) {
1787
- var childN = _c[_i];
1788
- var childNode = buildNodeWithSN(childN, {
1789
- doc: doc,
1790
- mirror: mirror,
1791
- skipChild: false,
1792
- hackCss: hackCss,
1793
- afterAppend: afterAppend,
1794
- cache: cache
1795
- });
1796
- if (!childNode) {
1797
- console.warn('Failed to rebuild', childN);
1798
- continue;
1799
- }
1800
- if (childN.isShadow && isElement(node) && node.shadowRoot) {
1801
- node.shadowRoot.appendChild(childNode);
1802
- }
1803
- else {
1804
- node.appendChild(childNode);
1805
- }
1806
- if (afterAppend) {
1807
- afterAppend(childNode);
1808
- }
1809
- }
1810
- }
1811
- return node;
1812
- }
1813
- function visit(mirror, onVisit) {
1814
- function walk(node) {
1815
- onVisit(node);
1816
- }
1817
- for (var _i = 0, _a = mirror.getIds(); _i < _a.length; _i++) {
1818
- var id = _a[_i];
1819
- if (mirror.has(id)) {
1820
- walk(mirror.getNode(id));
1821
- }
1822
- }
1823
- }
1824
- function handleScroll(node, mirror) {
1825
- var n = mirror.getMeta(node);
1826
- if ((n === null || n === void 0 ? void 0 : n.type) !== NodeType$2.Element) {
1827
- return;
1828
- }
1829
- var el = node;
1830
- for (var name_2 in n.attributes) {
1831
- if (!(n.attributes.hasOwnProperty(name_2) && name_2.startsWith('rr_'))) {
1832
- continue;
1833
- }
1834
- var value = n.attributes[name_2];
1835
- if (name_2 === 'rr_scrollLeft') {
1836
- el.scrollLeft = value;
1837
- }
1838
- if (name_2 === 'rr_scrollTop') {
1839
- el.scrollTop = value;
1840
- }
1841
- }
1842
- }
1843
- function rebuild(n, options) {
1844
- var doc = options.doc, onVisit = options.onVisit, _a = options.hackCss, hackCss = _a === void 0 ? true : _a, afterAppend = options.afterAppend, cache = options.cache, _b = options.mirror, mirror = _b === void 0 ? new Mirror$2() : _b;
1845
- var node = buildNodeWithSN(n, {
1846
- doc: doc,
1847
- mirror: mirror,
1848
- skipChild: false,
1849
- hackCss: hackCss,
1850
- afterAppend: afterAppend,
1851
- cache: cache
1852
- });
1853
- visit(mirror, function (visitedNode) {
1854
- if (onVisit) {
1855
- onVisit(visitedNode);
1856
- }
1857
- handleScroll(visitedNode, mirror);
1858
- });
1859
- return node;
1860
- }
5
+ var rrwebSnapshot = require('@highlight-run/rrweb-snapshot');
1861
6
 
1862
7
  function on(type, fn, target = document) {
1863
8
  const options = { capture: true, passive: true };
@@ -2006,7 +151,7 @@ function isBlocked(node, blockClass, checkAncestors) {
2006
151
  return true;
2007
152
  }
2008
153
  else {
2009
- if (classMatchesRegex(el, blockClass, checkAncestors))
154
+ if (rrwebSnapshot.classMatchesRegex(el, blockClass, checkAncestors))
2010
155
  return true;
2011
156
  }
2012
157
  return false;
@@ -2015,10 +160,10 @@ function isSerialized(n, mirror) {
2015
160
  return mirror.getId(n) !== -1;
2016
161
  }
2017
162
  function isIgnored(n, mirror) {
2018
- return mirror.getId(n) === IGNORED_NODE;
163
+ return mirror.getId(n) === rrwebSnapshot.IGNORED_NODE;
2019
164
  }
2020
165
  function isAncestorRemoved(target, mirror) {
2021
- if (isShadowRoot(target)) {
166
+ if (rrwebSnapshot.isShadowRoot(target)) {
2022
167
  return false;
2023
168
  }
2024
169
  const id = mirror.getId(target);
@@ -2165,30 +310,30 @@ function uniqueTextMutations(mutations) {
2165
310
  }
2166
311
 
2167
312
  var utils = /*#__PURE__*/Object.freeze({
2168
- __proto__: null,
2169
- on: on,
2170
- get _mirror () { return exports.mirror; },
2171
- throttle: throttle,
2172
- hookSetter: hookSetter,
2173
- patch: patch,
2174
- getWindowHeight: getWindowHeight,
2175
- getWindowWidth: getWindowWidth,
2176
- isCanvasNode: isCanvasNode,
2177
- isBlocked: isBlocked,
2178
- isSerialized: isSerialized,
2179
- isIgnored: isIgnored,
2180
- isAncestorRemoved: isAncestorRemoved,
2181
- isTouchEvent: isTouchEvent,
2182
- polyfill: polyfill$1,
2183
- queueToResolveTrees: queueToResolveTrees,
2184
- iterateResolveTree: iterateResolveTree,
2185
- isSerializedIframe: isSerializedIframe,
2186
- isSerializedStylesheet: isSerializedStylesheet,
2187
- getBaseDimension: getBaseDimension,
2188
- hasShadowRoot: hasShadowRoot,
2189
- getNestedRule: getNestedRule$1,
2190
- getPositionsAndIndex: getPositionsAndIndex$1,
2191
- uniqueTextMutations: uniqueTextMutations
313
+ __proto__: null,
314
+ on: on,
315
+ get _mirror () { return exports.mirror; },
316
+ throttle: throttle,
317
+ hookSetter: hookSetter,
318
+ patch: patch,
319
+ getWindowHeight: getWindowHeight,
320
+ getWindowWidth: getWindowWidth,
321
+ isCanvasNode: isCanvasNode,
322
+ isBlocked: isBlocked,
323
+ isSerialized: isSerialized,
324
+ isIgnored: isIgnored,
325
+ isAncestorRemoved: isAncestorRemoved,
326
+ isTouchEvent: isTouchEvent,
327
+ polyfill: polyfill$1,
328
+ queueToResolveTrees: queueToResolveTrees,
329
+ iterateResolveTree: iterateResolveTree,
330
+ isSerializedIframe: isSerializedIframe,
331
+ isSerializedStylesheet: isSerializedStylesheet,
332
+ getBaseDimension: getBaseDimension,
333
+ hasShadowRoot: hasShadowRoot,
334
+ getNestedRule: getNestedRule$1,
335
+ getPositionsAndIndex: getPositionsAndIndex$1,
336
+ uniqueTextMutations: uniqueTextMutations
2192
337
  });
2193
338
 
2194
339
  exports.EventType = void 0;
@@ -2367,8 +512,8 @@ class MutationBuffer {
2367
512
  const addList = new DoubleLinkedList();
2368
513
  const getNextId = (n) => {
2369
514
  let ns = n;
2370
- let nextId = IGNORED_NODE;
2371
- while (nextId === IGNORED_NODE) {
515
+ let nextId = rrwebSnapshot.IGNORED_NODE;
516
+ while (nextId === rrwebSnapshot.IGNORED_NODE) {
2372
517
  ns = ns && ns.nextSibling;
2373
518
  nextId = ns && this.mirror.getId(ns);
2374
519
  }
@@ -2389,14 +534,14 @@ class MutationBuffer {
2389
534
  if (!n.parentNode || notInDoc) {
2390
535
  return;
2391
536
  }
2392
- const parentId = isShadowRoot(n.parentNode)
537
+ const parentId = rrwebSnapshot.isShadowRoot(n.parentNode)
2393
538
  ? this.mirror.getId(shadowHost)
2394
539
  : this.mirror.getId(n.parentNode);
2395
540
  const nextId = getNextId(n);
2396
541
  if (parentId === -1 || nextId === -1) {
2397
542
  return addList.addNode(n);
2398
543
  }
2399
- const sn = serializeNodeWithId(n, {
544
+ const sn = rrwebSnapshot.serializeNodeWithId(n, {
2400
545
  doc: this.doc,
2401
546
  mirror: this.mirror,
2402
547
  blockClass: this.blockClass,
@@ -2500,7 +645,7 @@ class MutationBuffer {
2500
645
  .map((text) => {
2501
646
  let value = text.value;
2502
647
  if (this.enableStrictPrivacy && value) {
2503
- value = obfuscateText(value);
648
+ value = rrwebSnapshot.obfuscateText(value);
2504
649
  }
2505
650
  return {
2506
651
  id: this.mirror.getId(text.node),
@@ -2542,7 +687,7 @@ class MutationBuffer {
2542
687
  if (!isBlocked(m.target, this.blockClass, false) &&
2543
688
  value !== m.oldValue) {
2544
689
  this.texts.push({
2545
- value: needMaskingText(m.target, this.maskTextClass, this.maskTextSelector) && value
690
+ value: rrwebSnapshot.needMaskingText(m.target, this.maskTextClass, this.maskTextSelector) && value
2546
691
  ? this.maskTextFn
2547
692
  ? this.maskTextFn(value)
2548
693
  : value.replace(/[\S]/g, '*')
@@ -2556,7 +701,7 @@ class MutationBuffer {
2556
701
  const target = m.target;
2557
702
  let value = m.target.getAttribute(m.attributeName);
2558
703
  if (m.attributeName === 'value') {
2559
- value = maskInputValue({
704
+ value = rrwebSnapshot.maskInputValue({
2560
705
  maskInputOptions: this.maskInputOptions,
2561
706
  tagName: m.target.tagName,
2562
707
  type: m.target.getAttribute('type'),
@@ -2614,7 +759,7 @@ class MutationBuffer {
2614
759
  break;
2615
760
  }
2616
761
  }
2617
- item.attributes[m.attributeName] = transformAttribute(this.doc, m.target.tagName, m.attributeName, value);
762
+ item.attributes[m.attributeName] = rrwebSnapshot.transformAttribute(this.doc, m.target.tagName, m.attributeName, value);
2618
763
  }
2619
764
  break;
2620
765
  }
@@ -2624,7 +769,7 @@ class MutationBuffer {
2624
769
  m.addedNodes.forEach((n) => this.genAdds(n, m.target));
2625
770
  m.removedNodes.forEach((n) => {
2626
771
  const nodeId = this.mirror.getId(n);
2627
- const parentId = isShadowRoot(m.target)
772
+ const parentId = rrwebSnapshot.isShadowRoot(m.target)
2628
773
  ? this.mirror.getId(m.target.host)
2629
774
  : this.mirror.getId(m.target);
2630
775
  if (isBlocked(m.target, this.blockClass, false) ||
@@ -2646,7 +791,7 @@ class MutationBuffer {
2646
791
  this.removes.push({
2647
792
  parentId,
2648
793
  id: nodeId,
2649
- isShadow: isShadowRoot(m.target) ? true : undefined,
794
+ isShadow: rrwebSnapshot.isShadowRoot(m.target) ? true : undefined,
2650
795
  });
2651
796
  }
2652
797
  this.mapRemoves.push(n);
@@ -2975,7 +1120,7 @@ function initInputObserver({ inputCb, doc, mirror, blockClass, ignoreClass, mask
2975
1120
  }
2976
1121
  else if (maskInputOptions[target.tagName.toLowerCase()] ||
2977
1122
  maskInputOptions[type]) {
2978
- text = maskInputValue({
1123
+ text = rrwebSnapshot.maskInputValue({
2979
1124
  maskInputOptions,
2980
1125
  tagName: target.tagName,
2981
1126
  type,
@@ -4011,7 +2156,7 @@ function wrapEvent(e) {
4011
2156
  }
4012
2157
  let wrappedEmit;
4013
2158
  let takeFullSnapshot;
4014
- const mirror = createMirror$2();
2159
+ const mirror = rrwebSnapshot.createMirror();
4015
2160
  function record(options = {}) {
4016
2161
  const { emit, checkoutEveryNms, checkoutEveryNth, blockClass = 'highlight-block', blockSelector = null, ignoreClass = 'highlight-ignore', maskTextClass = 'highlight-mask', maskTextSelector = null, inlineStylesheet = true, maskAllInputs, maskInputOptions: _maskInputOptions, slimDOMOptions: _slimDOMOptions, maskInputFn, maskTextFn, hooks, packFn, sampling = {}, mousemoveWait, recordCanvas = false, userTriggeredOnInput = false, collectFonts = false, inlineImages = false, plugins, keepIframeSrcFn = () => false, enableStrictPrivacy = false, } = options;
4017
2162
  if (!emit) {
@@ -4162,7 +2307,7 @@ function record(options = {}) {
4162
2307
  },
4163
2308
  }), isCheckout);
4164
2309
  mutationBuffers.forEach((buf) => buf.lock());
4165
- const node = snapshot(document, {
2310
+ const node = rrwebSnapshot.snapshot(document, {
4166
2311
  mirror,
4167
2312
  blockClass,
4168
2313
  blockSelector,
@@ -4179,6 +2324,9 @@ function record(options = {}) {
4179
2324
  if (isSerializedIframe(n, mirror)) {
4180
2325
  iframeManager.addIframe(n);
4181
2326
  }
2327
+ if (isSerializedStylesheet(n, mirror)) {
2328
+ stylesheetManager.addStylesheet(n);
2329
+ }
4182
2330
  if (hasShadowRoot(n)) {
4183
2331
  shadowDomManager.addShadowRoot(n.shadowRoot, document);
4184
2332
  }
@@ -4188,7 +2336,7 @@ function record(options = {}) {
4188
2336
  shadowDomManager.observeAttachShadow(iframe);
4189
2337
  },
4190
2338
  onStylesheetLoad: (linkEl, childSn) => {
4191
- this.stylesheetManager.attachStylesheet(linkEl, childSn, this.mirror);
2339
+ stylesheetManager.attachStylesheet(linkEl, childSn, mirror);
4192
2340
  },
4193
2341
  keepIframeSrcFn,
4194
2342
  });
@@ -4352,70 +2500,6 @@ record.takeFullSnapshot = (isCheckout) => {
4352
2500
  };
4353
2501
  record.mirror = mirror;
4354
2502
 
4355
- var NodeType$1;
4356
- (function (NodeType) {
4357
- NodeType[NodeType["Document"] = 0] = "Document";
4358
- NodeType[NodeType["DocumentType"] = 1] = "DocumentType";
4359
- NodeType[NodeType["Element"] = 2] = "Element";
4360
- NodeType[NodeType["Text"] = 3] = "Text";
4361
- NodeType[NodeType["CDATA"] = 4] = "CDATA";
4362
- NodeType[NodeType["Comment"] = 5] = "Comment";
4363
- })(NodeType$1 || (NodeType$1 = {}));
4364
- var Mirror$1 = (function () {
4365
- function Mirror() {
4366
- this.idNodeMap = new Map();
4367
- this.nodeMetaMap = new WeakMap();
4368
- }
4369
- Mirror.prototype.getId = function (n) {
4370
- var _a;
4371
- if (!n)
4372
- return -1;
4373
- var id = (_a = this.getMeta(n)) === null || _a === void 0 ? void 0 : _a.id;
4374
- return id !== null && id !== void 0 ? id : -1;
4375
- };
4376
- Mirror.prototype.getNode = function (id) {
4377
- return this.idNodeMap.get(id) || null;
4378
- };
4379
- Mirror.prototype.getIds = function () {
4380
- return Array.from(this.idNodeMap.keys());
4381
- };
4382
- Mirror.prototype.getMeta = function (n) {
4383
- return this.nodeMetaMap.get(n) || null;
4384
- };
4385
- Mirror.prototype.removeNodeFromMap = function (n) {
4386
- var _this = this;
4387
- var id = this.getId(n);
4388
- this.idNodeMap["delete"](id);
4389
- if (n.childNodes) {
4390
- n.childNodes.forEach(function (childNode) {
4391
- return _this.removeNodeFromMap(childNode);
4392
- });
4393
- }
4394
- };
4395
- Mirror.prototype.has = function (id) {
4396
- return this.idNodeMap.has(id);
4397
- };
4398
- Mirror.prototype.hasNode = function (node) {
4399
- return this.nodeMetaMap.has(node);
4400
- };
4401
- Mirror.prototype.add = function (n, meta) {
4402
- var id = meta.id;
4403
- this.idNodeMap.set(id, n);
4404
- this.nodeMetaMap.set(n, meta);
4405
- };
4406
- Mirror.prototype.replace = function (id, n) {
4407
- this.idNodeMap.set(id, n);
4408
- };
4409
- Mirror.prototype.reset = function () {
4410
- this.idNodeMap = new Map();
4411
- this.nodeMetaMap = new WeakMap();
4412
- };
4413
- return Mirror;
4414
- }());
4415
- function createMirror$1() {
4416
- return new Mirror$1();
4417
- }
4418
-
4419
2503
  function parseCSSText(cssText) {
4420
2504
  const res = {};
4421
2505
  const listDelimiter = /;(?![^(]*\))/g;
@@ -4506,21 +2590,21 @@ function BaseRRDocumentImpl(RRNodeClass) {
4506
2590
  this.nodeType = NodeType.DOCUMENT_NODE;
4507
2591
  this.nodeName = '#document';
4508
2592
  this.compatMode = 'CSS1Compat';
4509
- this.RRNodeType = NodeType$1.Document;
2593
+ this.RRNodeType = rrwebSnapshot.NodeType.Document;
4510
2594
  this.textContent = null;
4511
2595
  }
4512
2596
  get documentElement() {
4513
- return (this.childNodes.find((node) => node.RRNodeType === NodeType$1.Element &&
2597
+ return (this.childNodes.find((node) => node.RRNodeType === rrwebSnapshot.NodeType.Element &&
4514
2598
  node.tagName === 'HTML') || null);
4515
2599
  }
4516
2600
  get body() {
4517
2601
  var _a;
4518
- return (((_a = this.documentElement) === null || _a === void 0 ? void 0 : _a.childNodes.find((node) => node.RRNodeType === NodeType$1.Element &&
2602
+ return (((_a = this.documentElement) === null || _a === void 0 ? void 0 : _a.childNodes.find((node) => node.RRNodeType === rrwebSnapshot.NodeType.Element &&
4519
2603
  node.tagName === 'BODY')) || null);
4520
2604
  }
4521
2605
  get head() {
4522
2606
  var _a;
4523
- return (((_a = this.documentElement) === null || _a === void 0 ? void 0 : _a.childNodes.find((node) => node.RRNodeType === NodeType$1.Element &&
2607
+ return (((_a = this.documentElement) === null || _a === void 0 ? void 0 : _a.childNodes.find((node) => node.RRNodeType === rrwebSnapshot.NodeType.Element &&
4524
2608
  node.tagName === 'HEAD')) || null);
4525
2609
  }
4526
2610
  get implementation() {
@@ -4531,10 +2615,10 @@ function BaseRRDocumentImpl(RRNodeClass) {
4531
2615
  }
4532
2616
  appendChild(childNode) {
4533
2617
  const nodeType = childNode.RRNodeType;
4534
- if (nodeType === NodeType$1.Element ||
4535
- nodeType === NodeType$1.DocumentType) {
2618
+ if (nodeType === rrwebSnapshot.NodeType.Element ||
2619
+ nodeType === rrwebSnapshot.NodeType.DocumentType) {
4536
2620
  if (this.childNodes.some((s) => s.RRNodeType === nodeType)) {
4537
- throw new Error(`RRDomException: Failed to execute 'appendChild' on 'RRNode': Only one ${nodeType === NodeType$1.Element ? 'RRElement' : 'RRDoctype'} on RRDocument allowed.`);
2621
+ throw new Error(`RRDomException: Failed to execute 'appendChild' on 'RRNode': Only one ${nodeType === rrwebSnapshot.NodeType.Element ? 'RRElement' : 'RRDoctype'} on RRDocument allowed.`);
4538
2622
  }
4539
2623
  }
4540
2624
  childNode.parentElement = null;
@@ -4544,10 +2628,10 @@ function BaseRRDocumentImpl(RRNodeClass) {
4544
2628
  }
4545
2629
  insertBefore(newChild, refChild) {
4546
2630
  const nodeType = newChild.RRNodeType;
4547
- if (nodeType === NodeType$1.Element ||
4548
- nodeType === NodeType$1.DocumentType) {
2631
+ if (nodeType === rrwebSnapshot.NodeType.Element ||
2632
+ nodeType === rrwebSnapshot.NodeType.DocumentType) {
4549
2633
  if (this.childNodes.some((s) => s.RRNodeType === nodeType)) {
4550
- throw new Error(`RRDomException: Failed to execute 'insertBefore' on 'RRNode': Only one ${nodeType === NodeType$1.Element ? 'RRElement' : 'RRDoctype'} on RRDocument allowed.`);
2634
+ throw new Error(`RRDomException: Failed to execute 'insertBefore' on 'RRNode': Only one ${nodeType === rrwebSnapshot.NodeType.Element ? 'RRElement' : 'RRDoctype'} on RRDocument allowed.`);
4551
2635
  }
4552
2636
  }
4553
2637
  if (refChild === null)
@@ -4629,7 +2713,7 @@ function BaseRRDocumentTypeImpl(RRNodeClass) {
4629
2713
  constructor(qualifiedName, publicId, systemId) {
4630
2714
  super();
4631
2715
  this.nodeType = NodeType.DOCUMENT_TYPE_NODE;
4632
- this.RRNodeType = NodeType$1.DocumentType;
2716
+ this.RRNodeType = rrwebSnapshot.NodeType.DocumentType;
4633
2717
  this.textContent = null;
4634
2718
  this.name = qualifiedName;
4635
2719
  this.publicId = publicId;
@@ -4646,7 +2730,7 @@ function BaseRRElementImpl(RRNodeClass) {
4646
2730
  constructor(tagName) {
4647
2731
  super();
4648
2732
  this.nodeType = NodeType.ELEMENT_NODE;
4649
- this.RRNodeType = NodeType$1.Element;
2733
+ this.RRNodeType = rrwebSnapshot.NodeType.Element;
4650
2734
  this.attributes = {};
4651
2735
  this.shadowRoot = null;
4652
2736
  this.tagName = tagName.toUpperCase();
@@ -4773,7 +2857,7 @@ function BaseRRTextImpl(RRNodeClass) {
4773
2857
  super();
4774
2858
  this.nodeType = NodeType.TEXT_NODE;
4775
2859
  this.nodeName = '#text';
4776
- this.RRNodeType = NodeType$1.Text;
2860
+ this.RRNodeType = rrwebSnapshot.NodeType.Text;
4777
2861
  this.data = data;
4778
2862
  }
4779
2863
  get textContent() {
@@ -4793,7 +2877,7 @@ function BaseRRCommentImpl(RRNodeClass) {
4793
2877
  super();
4794
2878
  this.nodeType = NodeType.COMMENT_NODE;
4795
2879
  this.nodeName = '#comment';
4796
- this.RRNodeType = NodeType$1.Comment;
2880
+ this.RRNodeType = rrwebSnapshot.NodeType.Comment;
4797
2881
  this.data = data;
4798
2882
  }
4799
2883
  get textContent() {
@@ -4813,7 +2897,7 @@ function BaseRRCDATASectionImpl(RRNodeClass) {
4813
2897
  super();
4814
2898
  this.nodeName = '#cdata-section';
4815
2899
  this.nodeType = NodeType.CDATA_SECTION_NODE;
4816
- this.RRNodeType = NodeType$1.CDATA;
2900
+ this.RRNodeType = rrwebSnapshot.NodeType.CDATA;
4817
2901
  this.data = data;
4818
2902
  }
4819
2903
  get textContent() {
@@ -4883,13 +2967,13 @@ function diff(oldTree, newTree, replayer, rrnodeMirror) {
4883
2967
  }
4884
2968
  let inputDataToApply = null, scrollDataToApply = null;
4885
2969
  switch (newTree.RRNodeType) {
4886
- case NodeType$1.Document: {
2970
+ case rrwebSnapshot.NodeType.Document: {
4887
2971
  const newRRDocument = newTree;
4888
2972
  scrollDataToApply = newRRDocument.scrollData;
4889
2973
  break;
4890
2974
  }
4891
- case NodeType$1.Element: {
4892
- const oldElement = (oldTree);
2975
+ case rrwebSnapshot.NodeType.Element: {
2976
+ const oldElement = oldTree;
4893
2977
  const newRRElement = newTree;
4894
2978
  diffProps(oldElement, newRRElement, rrnodeMirror);
4895
2979
  scrollDataToApply = newRRElement.scrollData;
@@ -4897,7 +2981,7 @@ function diff(oldTree, newTree, replayer, rrnodeMirror) {
4897
2981
  switch (newRRElement.tagName) {
4898
2982
  case 'AUDIO':
4899
2983
  case 'VIDEO': {
4900
- const oldMediaElement = (oldTree);
2984
+ const oldMediaElement = oldTree;
4901
2985
  const newMediaRRElement = newRRElement;
4902
2986
  if (newMediaRRElement.paused !== undefined)
4903
2987
  newMediaRRElement.paused
@@ -4912,7 +2996,7 @@ function diff(oldTree, newTree, replayer, rrnodeMirror) {
4912
2996
  break;
4913
2997
  }
4914
2998
  case 'CANVAS':
4915
- newTree.canvasMutations.forEach((canvasMutation) => replayer.applyCanvas(canvasMutation.event, canvasMutation.mutation, (oldTree)));
2999
+ newTree.canvasMutations.forEach((canvasMutation) => replayer.applyCanvas(canvasMutation.event, canvasMutation.mutation, oldTree));
4916
3000
  break;
4917
3001
  case 'STYLE':
4918
3002
  applyVirtualStyleRulesToNode(oldElement, newTree.rules);
@@ -4928,9 +3012,9 @@ function diff(oldTree, newTree, replayer, rrnodeMirror) {
4928
3012
  }
4929
3013
  break;
4930
3014
  }
4931
- case NodeType$1.Text:
4932
- case NodeType$1.Comment:
4933
- case NodeType$1.CDATA:
3015
+ case rrwebSnapshot.NodeType.Text:
3016
+ case rrwebSnapshot.NodeType.Comment:
3017
+ case rrwebSnapshot.NodeType.CDATA:
4934
3018
  if (oldTree.textContent !==
4935
3019
  newTree.data)
4936
3020
  oldTree.textContent = newTree.data;
@@ -4939,8 +3023,7 @@ function diff(oldTree, newTree, replayer, rrnodeMirror) {
4939
3023
  scrollDataToApply && replayer.applyScroll(scrollDataToApply, true);
4940
3024
  inputDataToApply && replayer.applyInput(inputDataToApply);
4941
3025
  if (newTree.nodeName === 'IFRAME') {
4942
- const oldContentDocument = (oldTree)
4943
- .contentDocument;
3026
+ const oldContentDocument = oldTree.contentDocument;
4944
3027
  const newIFrameElement = newTree;
4945
3028
  if (oldContentDocument) {
4946
3029
  const sn = rrnodeMirror.getMeta(newIFrameElement.contentDocument);
@@ -4979,7 +3062,7 @@ function diffProps(oldTree, newTree, rrnodeMirror) {
4979
3062
  newTree.scrollTop && (oldTree.scrollTop = newTree.scrollTop);
4980
3063
  }
4981
3064
  function diffChildren(oldChildren, newChildren, parentNode, replayer, rrnodeMirror) {
4982
- var _a, _b;
3065
+ var _a;
4983
3066
  let oldStartIndex = 0, oldEndIndex = oldChildren.length - 1, newStartIndex = 0, newEndIndex = newChildren.length - 1;
4984
3067
  let oldStartNode = oldChildren[oldStartIndex], oldEndNode = oldChildren[oldEndIndex], newStartNode = newChildren[newStartIndex], newEndNode = newChildren[newEndIndex];
4985
3068
  let oldIdToIndex = undefined, indexInOld;
@@ -5001,16 +3084,26 @@ function diffChildren(oldChildren, newChildren, parentNode, replayer, rrnodeMirr
5001
3084
  newEndNode = newChildren[--newEndIndex];
5002
3085
  }
5003
3086
  else if (replayer.mirror.getId(oldStartNode) === rrnodeMirror.getId(newEndNode)) {
5004
- parentNode.insertBefore(oldStartNode, oldEndNode.nextSibling);
5005
- diff(oldStartNode, newEndNode, replayer, rrnodeMirror);
5006
- oldStartNode = oldChildren[++oldStartIndex];
5007
- newEndNode = newChildren[--newEndIndex];
3087
+ try {
3088
+ parentNode.insertBefore(oldStartNode, oldEndNode.nextSibling);
3089
+ diff(oldStartNode, newEndNode, replayer, rrnodeMirror);
3090
+ oldStartNode = oldChildren[++oldStartIndex];
3091
+ newEndNode = newChildren[--newEndIndex];
3092
+ }
3093
+ catch (e) {
3094
+ console.error(e, parentNode, oldStartNode, oldEndNode);
3095
+ }
5008
3096
  }
5009
3097
  else if (replayer.mirror.getId(oldEndNode) === rrnodeMirror.getId(newStartNode)) {
5010
- parentNode.insertBefore(oldEndNode, oldStartNode);
5011
- diff(oldEndNode, newStartNode, replayer, rrnodeMirror);
5012
- oldEndNode = oldChildren[--oldEndIndex];
5013
- newStartNode = newChildren[++newStartIndex];
3098
+ try {
3099
+ parentNode.insertBefore(oldEndNode, oldStartNode);
3100
+ diff(oldEndNode, newStartNode, replayer, rrnodeMirror);
3101
+ oldEndNode = oldChildren[--oldEndIndex];
3102
+ newStartNode = newChildren[++newStartIndex];
3103
+ }
3104
+ catch (e) {
3105
+ console.error(e, parentNode, oldEndNode, oldStartNode);
3106
+ }
5014
3107
  }
5015
3108
  else {
5016
3109
  if (!oldIdToIndex) {
@@ -5024,21 +3117,31 @@ function diffChildren(oldChildren, newChildren, parentNode, replayer, rrnodeMirr
5024
3117
  indexInOld = oldIdToIndex[rrnodeMirror.getId(newStartNode)];
5025
3118
  if (indexInOld) {
5026
3119
  const nodeToMove = oldChildren[indexInOld];
5027
- parentNode.insertBefore(nodeToMove, oldStartNode);
5028
- diff(nodeToMove, newStartNode, replayer, rrnodeMirror);
5029
- oldChildren[indexInOld] = undefined;
3120
+ try {
3121
+ parentNode.insertBefore(nodeToMove, oldStartNode);
3122
+ diff(nodeToMove, newStartNode, replayer, rrnodeMirror);
3123
+ oldChildren[indexInOld] = undefined;
3124
+ }
3125
+ catch (e) {
3126
+ console.error(e, parentNode, nodeToMove, oldStartNode);
3127
+ }
5030
3128
  }
5031
3129
  else {
5032
3130
  const newNode = createOrGetNode(newStartNode, replayer.mirror, rrnodeMirror);
5033
- if (((_a = replayer.mirror.getMeta(parentNode)) === null || _a === void 0 ? void 0 : _a.type) === NodeType$1.Document &&
5034
- ((_b = replayer.mirror.getMeta(newNode)) === null || _b === void 0 ? void 0 : _b.type) === NodeType$1.Element &&
5035
- (parentNode).documentElement) {
5036
- parentNode.removeChild((parentNode).documentElement);
3131
+ if (parentNode.nodeName === '#document' &&
3132
+ ((_a = replayer.mirror.getMeta(newNode)) === null || _a === void 0 ? void 0 : _a.type) === rrwebSnapshot.NodeType.Element &&
3133
+ parentNode.documentElement) {
3134
+ parentNode.removeChild(parentNode.documentElement);
5037
3135
  oldChildren[oldStartIndex] = undefined;
5038
3136
  oldStartNode = undefined;
5039
3137
  }
5040
- parentNode.insertBefore(newNode, oldStartNode || null);
5041
- diff(newNode, newStartNode, replayer, rrnodeMirror);
3138
+ try {
3139
+ parentNode.insertBefore(newNode, oldStartNode || null);
3140
+ diff(newNode, newStartNode, replayer, rrnodeMirror);
3141
+ }
3142
+ catch (e) {
3143
+ console.error(e, parentNode, newNode, oldStartNode || null);
3144
+ }
5042
3145
  }
5043
3146
  newStartNode = newChildren[++newStartIndex];
5044
3147
  }
@@ -5053,8 +3156,13 @@ function diffChildren(oldChildren, newChildren, parentNode, replayer, rrnodeMirr
5053
3156
  });
5054
3157
  for (; newStartIndex <= newEndIndex; ++newStartIndex) {
5055
3158
  const newNode = createOrGetNode(newChildren[newStartIndex], replayer.mirror, rrnodeMirror);
5056
- parentNode.insertBefore(newNode, referenceNode);
5057
- diff(newNode, newChildren[newStartIndex], replayer, rrnodeMirror);
3159
+ try {
3160
+ parentNode.insertBefore(newNode, referenceNode);
3161
+ diff(newNode, newChildren[newStartIndex], replayer, rrnodeMirror);
3162
+ }
3163
+ catch (e) {
3164
+ console.error(e, parentNode, newNode, referenceNode);
3165
+ }
5058
3166
  }
5059
3167
  }
5060
3168
  else if (newStartIndex > newEndIndex) {
@@ -5073,13 +3181,13 @@ function createOrGetNode(rrNode, domMirror, rrnodeMirror) {
5073
3181
  if (node !== null)
5074
3182
  return node;
5075
3183
  switch (rrNode.RRNodeType) {
5076
- case NodeType$1.Document:
3184
+ case rrwebSnapshot.NodeType.Document:
5077
3185
  node = new Document();
5078
3186
  break;
5079
- case NodeType$1.DocumentType:
3187
+ case rrwebSnapshot.NodeType.DocumentType:
5080
3188
  node = document.implementation.createDocumentType(rrNode.name, rrNode.publicId, rrNode.systemId);
5081
3189
  break;
5082
- case NodeType$1.Element: {
3190
+ case rrwebSnapshot.NodeType.Element: {
5083
3191
  rrNode.tagName.toLowerCase();
5084
3192
  if (sn && 'isSVG' in sn && (sn === null || sn === void 0 ? void 0 : sn.isSVG)) {
5085
3193
  node = document.createElementNS(NAMESPACES['svg'], rrNode.tagName.toLowerCase());
@@ -5088,13 +3196,13 @@ function createOrGetNode(rrNode, domMirror, rrnodeMirror) {
5088
3196
  node = document.createElement(rrNode.tagName);
5089
3197
  break;
5090
3198
  }
5091
- case NodeType$1.Text:
3199
+ case rrwebSnapshot.NodeType.Text:
5092
3200
  node = document.createTextNode(rrNode.data);
5093
3201
  break;
5094
- case NodeType$1.Comment:
3202
+ case rrwebSnapshot.NodeType.Comment:
5095
3203
  node = document.createComment(rrNode.data);
5096
3204
  break;
5097
- case NodeType$1.CDATA:
3205
+ case rrwebSnapshot.NodeType.CDATA:
5098
3206
  node = document.createCDATASection(rrNode.data);
5099
3207
  break;
5100
3208
  }
@@ -5108,8 +3216,7 @@ function getNestedRule(rules, position) {
5108
3216
  return rule;
5109
3217
  }
5110
3218
  else {
5111
- return getNestedRule((rule).cssRules[position[1]]
5112
- .cssRules, position.slice(2));
3219
+ return getNestedRule(rule.cssRules[position[1]].cssRules, position.slice(2));
5113
3220
  }
5114
3221
  }
5115
3222
  var StyleRuleType;
@@ -5328,7 +3435,7 @@ function buildFromNode(node, rrdom, domMirror, parentRRNode) {
5328
3435
  }
5329
3436
  return rrNode;
5330
3437
  }
5331
- function buildFromDom(dom, domMirror = createMirror$1(), rrdom = new RRDocument()) {
3438
+ function buildFromDom(dom, domMirror = rrwebSnapshot.createMirror(), rrdom = new RRDocument()) {
5332
3439
  function walk(node, parentRRNode) {
5333
3440
  const rrNode = buildFromNode(node, rrdom, domMirror, parentRRNode);
5334
3441
  if (rrNode === null)
@@ -5406,13 +3513,13 @@ class Mirror {
5406
3513
  }
5407
3514
  function getDefaultSN(node, id) {
5408
3515
  switch (node.RRNodeType) {
5409
- case NodeType$1.Document:
3516
+ case rrwebSnapshot.NodeType.Document:
5410
3517
  return {
5411
3518
  id,
5412
3519
  type: node.RRNodeType,
5413
3520
  childNodes: [],
5414
3521
  };
5415
- case NodeType$1.DocumentType:
3522
+ case rrwebSnapshot.NodeType.DocumentType:
5416
3523
  const doctype = node;
5417
3524
  return {
5418
3525
  id,
@@ -5421,7 +3528,7 @@ function getDefaultSN(node, id) {
5421
3528
  publicId: doctype.publicId,
5422
3529
  systemId: doctype.systemId,
5423
3530
  };
5424
- case NodeType$1.Element:
3531
+ case rrwebSnapshot.NodeType.Element:
5425
3532
  return {
5426
3533
  id,
5427
3534
  type: node.RRNodeType,
@@ -5429,19 +3536,19 @@ function getDefaultSN(node, id) {
5429
3536
  attributes: {},
5430
3537
  childNodes: [],
5431
3538
  };
5432
- case NodeType$1.Text:
3539
+ case rrwebSnapshot.NodeType.Text:
5433
3540
  return {
5434
3541
  id,
5435
3542
  type: node.RRNodeType,
5436
3543
  textContent: node.textContent || '',
5437
3544
  };
5438
- case NodeType$1.Comment:
3545
+ case rrwebSnapshot.NodeType.Comment:
5439
3546
  return {
5440
3547
  id,
5441
3548
  type: node.RRNodeType,
5442
3549
  textContent: node.textContent || '',
5443
3550
  };
5444
- case NodeType$1.CDATA:
3551
+ case rrwebSnapshot.NodeType.CDATA:
5445
3552
  return {
5446
3553
  id,
5447
3554
  type: node.RRNodeType,
@@ -5513,8 +3620,8 @@ function mitt$1(all ) {
5513
3620
  }
5514
3621
 
5515
3622
  var mittProxy = /*#__PURE__*/Object.freeze({
5516
- __proto__: null,
5517
- 'default': mitt$1
3623
+ __proto__: null,
3624
+ 'default': mitt$1
5518
3625
  });
5519
3626
 
5520
3627
  function polyfill(w = window, d = document) {
@@ -6332,10 +4439,10 @@ class Replayer {
6332
4439
  this.emitter = mitt();
6333
4440
  this.activityIntervals = [];
6334
4441
  this.legacy_missingNodeRetryMap = {};
6335
- this.cache = createCache();
4442
+ this.cache = rrwebSnapshot.createCache();
6336
4443
  this.imageMap = new Map();
6337
4444
  this.canvasEventMap = new Map();
6338
- this.mirror = createMirror$2();
4445
+ this.mirror = rrwebSnapshot.createMirror();
6339
4446
  this.firstFullSnapshot = null;
6340
4447
  this.newDocumentQueue = [];
6341
4448
  this.mousePos = null;
@@ -6677,7 +4784,7 @@ class Replayer {
6677
4784
  this.iframe.style.pointerEvents = 'none';
6678
4785
  }
6679
4786
  resetCache() {
6680
- this.cache = createCache();
4787
+ this.cache = rrwebSnapshot.createCache();
6681
4788
  }
6682
4789
  setupDom() {
6683
4790
  this.wrapper = document.createElement('div');
@@ -6879,7 +4986,7 @@ class Replayer {
6879
4986
  }
6880
4987
  this.legacy_missingNodeRetryMap = {};
6881
4988
  const collected = [];
6882
- rebuild(event.data.node, {
4989
+ rrwebSnapshot.rebuild(event.data.node, {
6883
4990
  doc: this.iframe.contentDocument,
6884
4991
  afterAppend: (builtNode) => {
6885
4992
  this.collectIframeAndAttachDocument(collected, builtNode);
@@ -6936,7 +5043,7 @@ class Replayer {
6936
5043
  ? this.virtualDom.mirror
6937
5044
  : this.mirror;
6938
5045
  const collected = [];
6939
- buildNodeWithSN(mutation.node, {
5046
+ rrwebSnapshot.buildNodeWithSN(mutation.node, {
6940
5047
  doc: iframeEl.contentDocument,
6941
5048
  mirror: mirror,
6942
5049
  hackCss: true,
@@ -6944,7 +5051,7 @@ class Replayer {
6944
5051
  afterAppend: (builtNode) => {
6945
5052
  this.collectIframeAndAttachDocument(collected, builtNode);
6946
5053
  const sn = mirror.getMeta(builtNode);
6947
- if ((sn === null || sn === void 0 ? void 0 : sn.type) === NodeType$2.Element &&
5054
+ if ((sn === null || sn === void 0 ? void 0 : sn.type) === rrwebSnapshot.NodeType.Element &&
6948
5055
  (sn === null || sn === void 0 ? void 0 : sn.tagName.toUpperCase()) === 'HTML') {
6949
5056
  const { documentElement, head } = iframeEl.contentDocument;
6950
5057
  this.insertStyleRules(documentElement, head);
@@ -7498,7 +5605,7 @@ class Replayer {
7498
5605
  }
7499
5606
  let parent = mirror.getNode(mutation.parentId);
7500
5607
  if (!parent) {
7501
- if (mutation.node.type === NodeType$2.Document) {
5608
+ if (mutation.node.type === rrwebSnapshot.NodeType.Document) {
7502
5609
  return this.newDocumentQueue.push(mutation);
7503
5610
  }
7504
5611
  return queue.push(mutation);
@@ -7534,7 +5641,7 @@ class Replayer {
7534
5641
  this.attachDocumentToIframe(mutation, parent);
7535
5642
  return;
7536
5643
  }
7537
- const target = buildNodeWithSN(mutation.node, {
5644
+ const target = rrwebSnapshot.buildNodeWithSN(mutation.node, {
7538
5645
  doc: targetDoc,
7539
5646
  mirror: mirror,
7540
5647
  skipChild: true,
@@ -7550,9 +5657,9 @@ class Replayer {
7550
5657
  }
7551
5658
  const parentSn = mirror.getMeta(parent);
7552
5659
  if (parentSn &&
7553
- parentSn.type === NodeType$2.Element &&
5660
+ parentSn.type === rrwebSnapshot.NodeType.Element &&
7554
5661
  parentSn.tagName === 'textarea' &&
7555
- mutation.node.type === NodeType$2.Text) {
5662
+ mutation.node.type === rrwebSnapshot.NodeType.Text) {
7556
5663
  const childNodeArray = Array.isArray(parent.childNodes)
7557
5664
  ? parent.childNodes
7558
5665
  : Array.from(parent.childNodes);
@@ -7695,7 +5802,7 @@ class Replayer {
7695
5802
  behavior: isSync ? 'auto' : 'smooth',
7696
5803
  });
7697
5804
  }
7698
- else if ((sn === null || sn === void 0 ? void 0 : sn.type) === NodeType$2.Document) {
5805
+ else if ((sn === null || sn === void 0 ? void 0 : sn.type) === rrwebSnapshot.NodeType.Document) {
7699
5806
  target.defaultView.scrollTo({
7700
5807
  top: d.y,
7701
5808
  left: d.x,