@highlight-run/rrweb 2.0.10 → 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 +14 -76
  26. package/es/rrweb/packages/rrweb/src/index.js +1 -1
  27. package/es/rrweb/packages/rrweb/src/record/index.js +1 -1
  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 +17 -1063
  36. package/lib/replay/rrweb-replay-unpack.js +59 -1011
  37. package/lib/replay/rrweb-replay.js +59 -1011
  38. package/lib/rrweb-all.js +100 -2032
  39. package/lib/rrweb.js +100 -2032
  40. package/package.json +2 -2
  41. package/es/rrweb/packages/rrweb-snapshot/es/rrweb-snapshot.js +0 -1871
package/lib/rrweb-all.js CHANGED
@@ -2,1875 +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$1 = '__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$1 in getImageData
101
- ? getImageData[ORIGINAL_ATTRIBUTE_NAME$1]
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
- onStylesheetLoad: onStylesheetLoad,
932
- stylesheetLoadTimeout: stylesheetLoadTimeout,
933
- keepIframeSrcFn: keepIframeSrcFn,
934
- enableStrictPrivacy: enableStrictPrivacy
935
- });
936
- if (serializedIframeNode) {
937
- onIframeLoad(n, serializedIframeNode);
938
- }
939
- }
940
- }, iframeLoadTimeout);
941
- }
942
- if (serializedNode.type === NodeType$2.Element &&
943
- serializedNode.tagName === 'link' &&
944
- serializedNode.attributes.rel === 'stylesheet') {
945
- onceStylesheetLoaded(n, function () {
946
- if (onStylesheetLoad) {
947
- var serializedLinkNode = serializeNodeWithId(n, {
948
- doc: doc,
949
- mirror: mirror,
950
- blockClass: blockClass,
951
- blockSelector: blockSelector,
952
- maskTextClass: maskTextClass,
953
- maskTextSelector: maskTextSelector,
954
- skipChild: false,
955
- inlineStylesheet: inlineStylesheet,
956
- maskInputOptions: maskInputOptions,
957
- maskTextFn: maskTextFn,
958
- maskInputFn: maskInputFn,
959
- slimDOMOptions: slimDOMOptions,
960
- dataURLOptions: dataURLOptions,
961
- inlineImages: inlineImages,
962
- recordCanvas: recordCanvas,
963
- preserveWhiteSpace: preserveWhiteSpace,
964
- onSerialize: onSerialize,
965
- onIframeLoad: onIframeLoad,
966
- iframeLoadTimeout: iframeLoadTimeout,
967
- onStylesheetLoad: onStylesheetLoad,
968
- stylesheetLoadTimeout: stylesheetLoadTimeout,
969
- keepIframeSrcFn: keepIframeSrcFn,
970
- enableStrictPrivacy: enableStrictPrivacy
971
- });
972
- if (serializedLinkNode) {
973
- onStylesheetLoad(n, serializedLinkNode);
974
- }
975
- }
976
- }, stylesheetLoadTimeout);
977
- if (isStylesheetLoaded(n) === false)
978
- return null;
979
- }
980
- return serializedNode;
981
- }
982
- function snapshot(n, options) {
983
- 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;
984
- var maskInputOptions = maskAllInputs === true
985
- ? {
986
- color: true,
987
- date: true,
988
- 'datetime-local': true,
989
- email: true,
990
- month: true,
991
- number: true,
992
- range: true,
993
- search: true,
994
- tel: true,
995
- text: true,
996
- time: true,
997
- url: true,
998
- week: true,
999
- textarea: true,
1000
- select: true,
1001
- password: true
1002
- }
1003
- : maskAllInputs === false
1004
- ? {
1005
- password: true
1006
- }
1007
- : maskAllInputs;
1008
- var slimDOMOptions = slimDOM === true || slimDOM === 'all'
1009
- ?
1010
- {
1011
- script: true,
1012
- comment: true,
1013
- headFavicon: true,
1014
- headWhitespace: true,
1015
- headMetaDescKeywords: slimDOM === 'all',
1016
- headMetaSocial: true,
1017
- headMetaRobots: true,
1018
- headMetaHttpEquiv: true,
1019
- headMetaAuthorship: true,
1020
- headMetaVerification: true
1021
- }
1022
- : slimDOM === false
1023
- ? {}
1024
- : slimDOM;
1025
- return serializeNodeWithId(n, {
1026
- doc: n,
1027
- mirror: mirror,
1028
- blockClass: blockClass,
1029
- blockSelector: blockSelector,
1030
- maskTextClass: maskTextClass,
1031
- maskTextSelector: maskTextSelector,
1032
- skipChild: false,
1033
- inlineStylesheet: inlineStylesheet,
1034
- maskInputOptions: maskInputOptions,
1035
- maskTextFn: maskTextFn,
1036
- maskInputFn: maskInputFn,
1037
- slimDOMOptions: slimDOMOptions,
1038
- dataURLOptions: dataURLOptions,
1039
- inlineImages: inlineImages,
1040
- recordCanvas: recordCanvas,
1041
- preserveWhiteSpace: preserveWhiteSpace,
1042
- onSerialize: onSerialize,
1043
- onIframeLoad: onIframeLoad,
1044
- iframeLoadTimeout: iframeLoadTimeout,
1045
- onStylesheetLoad: onStylesheetLoad,
1046
- stylesheetLoadTimeout: stylesheetLoadTimeout,
1047
- keepIframeSrcFn: keepIframeSrcFn,
1048
- newlyAddedElement: false,
1049
- enableStrictPrivacy: enableStrictPrivacy
1050
- });
1051
- }
1052
-
1053
- var commentre = /\/\*[^*]*\*+([^/*][^*]*\*+)*\//g;
1054
- function parse(css, options) {
1055
- if (options === void 0) { options = {}; }
1056
- var lineno = 1;
1057
- var column = 1;
1058
- function updatePosition(str) {
1059
- var lines = str.match(/\n/g);
1060
- if (lines) {
1061
- lineno += lines.length;
1062
- }
1063
- var i = str.lastIndexOf('\n');
1064
- column = i === -1 ? column + str.length : str.length - i;
1065
- }
1066
- function position() {
1067
- var start = { line: lineno, column: column };
1068
- return function (node) {
1069
- node.position = new Position(start);
1070
- whitespace();
1071
- return node;
1072
- };
1073
- }
1074
- var Position = (function () {
1075
- function Position(start) {
1076
- this.start = start;
1077
- this.end = { line: lineno, column: column };
1078
- this.source = options.source;
1079
- }
1080
- return Position;
1081
- }());
1082
- Position.prototype.content = css;
1083
- var errorsList = [];
1084
- function error(msg) {
1085
- var err = new Error(options.source + ':' + lineno + ':' + column + ': ' + msg);
1086
- err.reason = msg;
1087
- err.filename = options.source;
1088
- err.line = lineno;
1089
- err.column = column;
1090
- err.source = css;
1091
- if (options.silent) {
1092
- errorsList.push(err);
1093
- }
1094
- else {
1095
- throw err;
1096
- }
1097
- }
1098
- function stylesheet() {
1099
- var rulesList = rules();
1100
- return {
1101
- type: 'stylesheet',
1102
- stylesheet: {
1103
- source: options.source,
1104
- rules: rulesList,
1105
- parsingErrors: errorsList
1106
- }
1107
- };
1108
- }
1109
- function open() {
1110
- return match(/^{\s*/);
1111
- }
1112
- function close() {
1113
- return match(/^}/);
1114
- }
1115
- function rules() {
1116
- var node;
1117
- var rules = [];
1118
- whitespace();
1119
- comments(rules);
1120
- while (css.length && css.charAt(0) !== '}' && (node = atrule() || rule())) {
1121
- if (node !== false) {
1122
- rules.push(node);
1123
- comments(rules);
1124
- }
1125
- }
1126
- return rules;
1127
- }
1128
- function match(re) {
1129
- var m = re.exec(css);
1130
- if (!m) {
1131
- return;
1132
- }
1133
- var str = m[0];
1134
- updatePosition(str);
1135
- css = css.slice(str.length);
1136
- return m;
1137
- }
1138
- function whitespace() {
1139
- match(/^\s*/);
1140
- }
1141
- function comments(rules) {
1142
- if (rules === void 0) { rules = []; }
1143
- var c;
1144
- while ((c = comment())) {
1145
- if (c !== false) {
1146
- rules.push(c);
1147
- }
1148
- c = comment();
1149
- }
1150
- return rules;
1151
- }
1152
- function comment() {
1153
- var pos = position();
1154
- if ('/' !== css.charAt(0) || '*' !== css.charAt(1)) {
1155
- return;
1156
- }
1157
- var i = 2;
1158
- while ('' !== css.charAt(i) &&
1159
- ('*' !== css.charAt(i) || '/' !== css.charAt(i + 1))) {
1160
- ++i;
1161
- }
1162
- i += 2;
1163
- if ('' === css.charAt(i - 1)) {
1164
- return error('End of comment missing');
1165
- }
1166
- var str = css.slice(2, i - 2);
1167
- column += 2;
1168
- updatePosition(str);
1169
- css = css.slice(i);
1170
- column += 2;
1171
- return pos({
1172
- type: 'comment',
1173
- comment: str
1174
- });
1175
- }
1176
- function selector() {
1177
- var m = match(/^([^{]+)/);
1178
- if (!m) {
1179
- return;
1180
- }
1181
- return trim(m[0])
1182
- .replace(/\/\*([^*]|[\r\n]|(\*+([^*/]|[\r\n])))*\*\/+/g, '')
1183
- .replace(/"(?:\\"|[^"])*"|'(?:\\'|[^'])*'/g, function (m) {
1184
- return m.replace(/,/g, '\u200C');
1185
- })
1186
- .split(/\s*(?![^(]*\)),\s*/)
1187
- .map(function (s) {
1188
- return s.replace(/\u200C/g, ',');
1189
- });
1190
- }
1191
- function declaration() {
1192
- var pos = position();
1193
- var propMatch = match(/^(\*?[-#\/\*\\\w]+(\[[0-9a-z_-]+\])?)\s*/);
1194
- if (!propMatch) {
1195
- return;
1196
- }
1197
- var prop = trim(propMatch[0]);
1198
- if (!match(/^:\s*/)) {
1199
- return error("property missing ':'");
1200
- }
1201
- var val = match(/^((?:'(?:\\'|.)*?'|"(?:\\"|.)*?"|\([^\)]*?\)|[^};])+)/);
1202
- var ret = pos({
1203
- type: 'declaration',
1204
- property: prop.replace(commentre, ''),
1205
- value: val ? trim(val[0]).replace(commentre, '') : ''
1206
- });
1207
- match(/^[;\s]*/);
1208
- return ret;
1209
- }
1210
- function declarations() {
1211
- var decls = [];
1212
- if (!open()) {
1213
- return error("missing '{'");
1214
- }
1215
- comments(decls);
1216
- var decl;
1217
- while ((decl = declaration())) {
1218
- if (decl !== false) {
1219
- decls.push(decl);
1220
- comments(decls);
1221
- }
1222
- decl = declaration();
1223
- }
1224
- if (!close()) {
1225
- return error("missing '}'");
1226
- }
1227
- return decls;
1228
- }
1229
- function keyframe() {
1230
- var m;
1231
- var vals = [];
1232
- var pos = position();
1233
- while ((m = match(/^((\d+\.\d+|\.\d+|\d+)%?|[a-z]+)\s*/))) {
1234
- vals.push(m[1]);
1235
- match(/^,\s*/);
1236
- }
1237
- if (!vals.length) {
1238
- return;
1239
- }
1240
- return pos({
1241
- type: 'keyframe',
1242
- values: vals,
1243
- declarations: declarations()
1244
- });
1245
- }
1246
- function atkeyframes() {
1247
- var pos = position();
1248
- var m = match(/^@([-\w]+)?keyframes\s*/);
1249
- if (!m) {
1250
- return;
1251
- }
1252
- var vendor = m[1];
1253
- m = match(/^([-\w]+)\s*/);
1254
- if (!m) {
1255
- return error('@keyframes missing name');
1256
- }
1257
- var name = m[1];
1258
- if (!open()) {
1259
- return error("@keyframes missing '{'");
1260
- }
1261
- var frame;
1262
- var frames = comments();
1263
- while ((frame = keyframe())) {
1264
- frames.push(frame);
1265
- frames = frames.concat(comments());
1266
- }
1267
- if (!close()) {
1268
- return error("@keyframes missing '}'");
1269
- }
1270
- return pos({
1271
- type: 'keyframes',
1272
- name: name,
1273
- vendor: vendor,
1274
- keyframes: frames
1275
- });
1276
- }
1277
- function atsupports() {
1278
- var pos = position();
1279
- var m = match(/^@supports *([^{]+)/);
1280
- if (!m) {
1281
- return;
1282
- }
1283
- var supports = trim(m[1]);
1284
- if (!open()) {
1285
- return error("@supports missing '{'");
1286
- }
1287
- var style = comments().concat(rules());
1288
- if (!close()) {
1289
- return error("@supports missing '}'");
1290
- }
1291
- return pos({
1292
- type: 'supports',
1293
- supports: supports,
1294
- rules: style
1295
- });
1296
- }
1297
- function athost() {
1298
- var pos = position();
1299
- var m = match(/^@host\s*/);
1300
- if (!m) {
1301
- return;
1302
- }
1303
- if (!open()) {
1304
- return error("@host missing '{'");
1305
- }
1306
- var style = comments().concat(rules());
1307
- if (!close()) {
1308
- return error("@host missing '}'");
1309
- }
1310
- return pos({
1311
- type: 'host',
1312
- rules: style
1313
- });
1314
- }
1315
- function atmedia() {
1316
- var pos = position();
1317
- var m = match(/^@media *([^{]+)/);
1318
- if (!m) {
1319
- return;
1320
- }
1321
- var media = trim(m[1]);
1322
- if (!open()) {
1323
- return error("@media missing '{'");
1324
- }
1325
- var style = comments().concat(rules());
1326
- if (!close()) {
1327
- return error("@media missing '}'");
1328
- }
1329
- return pos({
1330
- type: 'media',
1331
- media: media,
1332
- rules: style
1333
- });
1334
- }
1335
- function atcustommedia() {
1336
- var pos = position();
1337
- var m = match(/^@custom-media\s+(--[^\s]+)\s*([^{;]+);/);
1338
- if (!m) {
1339
- return;
1340
- }
1341
- return pos({
1342
- type: 'custom-media',
1343
- name: trim(m[1]),
1344
- media: trim(m[2])
1345
- });
1346
- }
1347
- function atpage() {
1348
- var pos = position();
1349
- var m = match(/^@page */);
1350
- if (!m) {
1351
- return;
1352
- }
1353
- var sel = selector() || [];
1354
- if (!open()) {
1355
- return error("@page missing '{'");
1356
- }
1357
- var decls = comments();
1358
- var decl;
1359
- while ((decl = declaration())) {
1360
- decls.push(decl);
1361
- decls = decls.concat(comments());
1362
- }
1363
- if (!close()) {
1364
- return error("@page missing '}'");
1365
- }
1366
- return pos({
1367
- type: 'page',
1368
- selectors: sel,
1369
- declarations: decls
1370
- });
1371
- }
1372
- function atdocument() {
1373
- var pos = position();
1374
- var m = match(/^@([-\w]+)?document *([^{]+)/);
1375
- if (!m) {
1376
- return;
1377
- }
1378
- var vendor = trim(m[1]);
1379
- var doc = trim(m[2]);
1380
- if (!open()) {
1381
- return error("@document missing '{'");
1382
- }
1383
- var style = comments().concat(rules());
1384
- if (!close()) {
1385
- return error("@document missing '}'");
1386
- }
1387
- return pos({
1388
- type: 'document',
1389
- document: doc,
1390
- vendor: vendor,
1391
- rules: style
1392
- });
1393
- }
1394
- function atfontface() {
1395
- var pos = position();
1396
- var m = match(/^@font-face\s*/);
1397
- if (!m) {
1398
- return;
1399
- }
1400
- if (!open()) {
1401
- return error("@font-face missing '{'");
1402
- }
1403
- var decls = comments();
1404
- var decl;
1405
- while ((decl = declaration())) {
1406
- decls.push(decl);
1407
- decls = decls.concat(comments());
1408
- }
1409
- if (!close()) {
1410
- return error("@font-face missing '}'");
1411
- }
1412
- return pos({
1413
- type: 'font-face',
1414
- declarations: decls
1415
- });
1416
- }
1417
- var atimport = _compileAtrule('import');
1418
- var atcharset = _compileAtrule('charset');
1419
- var atnamespace = _compileAtrule('namespace');
1420
- function _compileAtrule(name) {
1421
- var re = new RegExp('^@' + name + '\\s*([^;]+);');
1422
- return function () {
1423
- var pos = position();
1424
- var m = match(re);
1425
- if (!m) {
1426
- return;
1427
- }
1428
- var ret = { type: name };
1429
- ret[name] = m[1].trim();
1430
- return pos(ret);
1431
- };
1432
- }
1433
- function atrule() {
1434
- if (css[0] !== '@') {
1435
- return;
1436
- }
1437
- return (atkeyframes() ||
1438
- atmedia() ||
1439
- atcustommedia() ||
1440
- atsupports() ||
1441
- atimport() ||
1442
- atcharset() ||
1443
- atnamespace() ||
1444
- atdocument() ||
1445
- atpage() ||
1446
- athost() ||
1447
- atfontface());
1448
- }
1449
- function rule() {
1450
- var pos = position();
1451
- var sel = selector();
1452
- if (!sel) {
1453
- return error('selector missing');
1454
- }
1455
- comments();
1456
- return pos({
1457
- type: 'rule',
1458
- selectors: sel,
1459
- declarations: declarations()
1460
- });
1461
- }
1462
- return addParent(stylesheet());
1463
- }
1464
- function trim(str) {
1465
- return str ? str.replace(/^\s+|\s+$/g, '') : '';
1466
- }
1467
- function addParent(obj, parent) {
1468
- var isNode = obj && typeof obj.type === 'string';
1469
- var childParent = isNode ? obj : parent;
1470
- for (var _i = 0, _a = Object.keys(obj); _i < _a.length; _i++) {
1471
- var k = _a[_i];
1472
- var value = obj[k];
1473
- if (Array.isArray(value)) {
1474
- value.forEach(function (v) {
1475
- addParent(v, childParent);
1476
- });
1477
- }
1478
- else if (value && typeof value === 'object') {
1479
- addParent(value, childParent);
1480
- }
1481
- }
1482
- if (isNode) {
1483
- Object.defineProperty(obj, 'parent', {
1484
- configurable: true,
1485
- writable: true,
1486
- enumerable: false,
1487
- value: parent || null
1488
- });
1489
- }
1490
- return obj;
1491
- }
1492
-
1493
- var tagMap = {
1494
- script: 'noscript',
1495
- altglyph: 'altGlyph',
1496
- altglyphdef: 'altGlyphDef',
1497
- altglyphitem: 'altGlyphItem',
1498
- animatecolor: 'animateColor',
1499
- animatemotion: 'animateMotion',
1500
- animatetransform: 'animateTransform',
1501
- clippath: 'clipPath',
1502
- feblend: 'feBlend',
1503
- fecolormatrix: 'feColorMatrix',
1504
- fecomponenttransfer: 'feComponentTransfer',
1505
- fecomposite: 'feComposite',
1506
- feconvolvematrix: 'feConvolveMatrix',
1507
- fediffuselighting: 'feDiffuseLighting',
1508
- fedisplacementmap: 'feDisplacementMap',
1509
- fedistantlight: 'feDistantLight',
1510
- fedropshadow: 'feDropShadow',
1511
- feflood: 'feFlood',
1512
- fefunca: 'feFuncA',
1513
- fefuncb: 'feFuncB',
1514
- fefuncg: 'feFuncG',
1515
- fefuncr: 'feFuncR',
1516
- fegaussianblur: 'feGaussianBlur',
1517
- feimage: 'feImage',
1518
- femerge: 'feMerge',
1519
- femergenode: 'feMergeNode',
1520
- femorphology: 'feMorphology',
1521
- feoffset: 'feOffset',
1522
- fepointlight: 'fePointLight',
1523
- fespecularlighting: 'feSpecularLighting',
1524
- fespotlight: 'feSpotLight',
1525
- fetile: 'feTile',
1526
- feturbulence: 'feTurbulence',
1527
- foreignobject: 'foreignObject',
1528
- glyphref: 'glyphRef',
1529
- lineargradient: 'linearGradient',
1530
- radialgradient: 'radialGradient'
1531
- };
1532
- function getTagName(n) {
1533
- var tagName = tagMap[n.tagName] ? tagMap[n.tagName] : n.tagName;
1534
- if (tagName === 'link' && n.attributes._cssText) {
1535
- tagName = 'style';
1536
- }
1537
- return tagName;
1538
- }
1539
- function escapeRegExp(str) {
1540
- return str.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
1541
- }
1542
- var HOVER_SELECTOR = /([^\\]):hover/;
1543
- var HOVER_SELECTOR_GLOBAL = new RegExp(HOVER_SELECTOR.source, 'g');
1544
- function addHoverClass(cssText, cache) {
1545
- var _a;
1546
- if (!((_a = window === null || window === void 0 ? void 0 : window.HIG_CONFIGURATION) === null || _a === void 0 ? void 0 : _a.enableOnHoverClass)) {
1547
- return cssText;
1548
- }
1549
- var cachedStyle = cache === null || cache === void 0 ? void 0 : cache.stylesWithHoverClass.get(cssText);
1550
- if (cachedStyle)
1551
- return cachedStyle;
1552
- var ast = parse(cssText, {
1553
- silent: true
1554
- });
1555
- if (!ast.stylesheet) {
1556
- return cssText;
1557
- }
1558
- var selectors = [];
1559
- ast.stylesheet.rules.forEach(function (rule) {
1560
- if ('selectors' in rule) {
1561
- (rule.selectors || []).forEach(function (selector) {
1562
- if (HOVER_SELECTOR.test(selector)) {
1563
- selectors.push(selector);
1564
- }
1565
- });
1566
- }
1567
- });
1568
- if (selectors.length === 0) {
1569
- return cssText;
1570
- }
1571
- var selectorMatcher = new RegExp(selectors
1572
- .filter(function (selector, index) { return selectors.indexOf(selector) === index; })
1573
- .sort(function (a, b) { return b.length - a.length; })
1574
- .map(function (selector) {
1575
- return escapeRegExp(selector);
1576
- })
1577
- .join('|'), 'g');
1578
- var result = cssText.replace(selectorMatcher, function (selector) {
1579
- var newSelector = selector.replace(HOVER_SELECTOR_GLOBAL, '$1.\\:hover');
1580
- return selector + ", " + newSelector;
1581
- });
1582
- cache === null || cache === void 0 ? void 0 : cache.stylesWithHoverClass.set(cssText, result);
1583
- return result;
1584
- }
1585
- function createCache() {
1586
- var stylesWithHoverClass = new Map();
1587
- return {
1588
- stylesWithHoverClass: stylesWithHoverClass
1589
- };
1590
- }
1591
- function buildNode(n, options) {
1592
- var doc = options.doc, hackCss = options.hackCss, cache = options.cache;
1593
- switch (n.type) {
1594
- case NodeType$2.Document:
1595
- return doc.implementation.createDocument(null, '', null);
1596
- case NodeType$2.DocumentType:
1597
- return doc.implementation.createDocumentType(n.name || 'html', n.publicId, n.systemId);
1598
- case NodeType$2.Element:
1599
- var tagName = getTagName(n);
1600
- var node_1;
1601
- if (n.isSVG) {
1602
- node_1 = doc.createElementNS('http://www.w3.org/2000/svg', tagName);
1603
- }
1604
- else {
1605
- node_1 = doc.createElement(tagName);
1606
- }
1607
- var _loop_1 = function (name_1) {
1608
- if (!n.attributes.hasOwnProperty(name_1)) {
1609
- return "continue";
1610
- }
1611
- var value = n.attributes[name_1];
1612
- if (tagName === 'option' && name_1 === 'selected' && value === false) {
1613
- return "continue";
1614
- }
1615
- value =
1616
- typeof value === 'boolean' || typeof value === 'number' ? '' : value;
1617
- if (!name_1.startsWith('rr_')) {
1618
- var isTextarea = tagName === 'textarea' && name_1 === 'value';
1619
- var isRemoteOrDynamicCss = tagName === 'style' && name_1 === '_cssText';
1620
- if (isRemoteOrDynamicCss && hackCss) {
1621
- value = addHoverClass(value, cache);
1622
- if (typeof value === 'string') {
1623
- var regex = /url\(\"https:\/\/\S*(.eot|.woff2|.ttf|.woff)\S*\"\)/gm;
1624
- var m = void 0;
1625
- var fontUrls_1 = [];
1626
- var PROXY_URL_1 = 'https://replay-cors-proxy.highlightrun.workers.dev';
1627
- while ((m = regex.exec(value)) !== null) {
1628
- if (m.index === regex.lastIndex) {
1629
- regex.lastIndex++;
1630
- }
1631
- m.forEach(function (match, groupIndex) {
1632
- if (groupIndex === 0) {
1633
- var url = match.slice(5, match.length - 2);
1634
- fontUrls_1.push({
1635
- originalUrl: url,
1636
- proxyUrl: url.replace(url, PROXY_URL_1 + "?url=" + url)
1637
- });
1638
- }
1639
- });
1640
- }
1641
- fontUrls_1.forEach(function (urlPair) {
1642
- value = value.replace(urlPair.originalUrl, urlPair.proxyUrl);
1643
- });
1644
- }
1645
- }
1646
- if (isTextarea || isRemoteOrDynamicCss) {
1647
- var child = doc.createTextNode(value);
1648
- for (var _i = 0, _a = Array.from(node_1.childNodes); _i < _a.length; _i++) {
1649
- var c = _a[_i];
1650
- if (c.nodeType === node_1.TEXT_NODE) {
1651
- node_1.removeChild(c);
1652
- }
1653
- }
1654
- node_1.appendChild(child);
1655
- return "continue";
1656
- }
1657
- try {
1658
- if (n.isSVG && name_1 === 'xlink:href') {
1659
- node_1.setAttributeNS('http://www.w3.org/1999/xlink', name_1, value);
1660
- }
1661
- else if (name_1 === 'onload' ||
1662
- name_1 === 'onclick' ||
1663
- name_1.substring(0, 7) === 'onmouse') {
1664
- node_1.setAttribute('_' + name_1, value);
1665
- }
1666
- else if (tagName === 'meta' &&
1667
- n.attributes['http-equiv'] === 'Content-Security-Policy' &&
1668
- name_1 === 'content') {
1669
- node_1.setAttribute('csp-content', value);
1670
- return "continue";
1671
- }
1672
- else if (tagName === 'link' &&
1673
- n.attributes.rel === 'preload' &&
1674
- n.attributes.as === 'script') {
1675
- }
1676
- else if (tagName === 'link' &&
1677
- n.attributes.rel === 'prefetch' &&
1678
- typeof n.attributes.href === 'string' &&
1679
- n.attributes.href.endsWith('.js')) {
1680
- }
1681
- else if (tagName === 'img' &&
1682
- n.attributes.srcset &&
1683
- n.attributes.rr_dataURL) {
1684
- node_1.setAttribute('rrweb-original-srcset', n.attributes.srcset);
1685
- }
1686
- else {
1687
- node_1.setAttribute(name_1, value);
1688
- }
1689
- }
1690
- catch (error) {
1691
- }
1692
- }
1693
- else {
1694
- if (tagName === 'canvas' && name_1 === 'rr_dataURL') {
1695
- var image_1 = document.createElement('img');
1696
- image_1.src = value;
1697
- image_1.onload = function () {
1698
- var ctx = node_1.getContext('2d');
1699
- if (ctx) {
1700
- ctx.drawImage(image_1, 0, 0, image_1.width, image_1.height);
1701
- }
1702
- };
1703
- }
1704
- else if (tagName === 'img' && name_1 === 'rr_dataURL') {
1705
- var image = node_1;
1706
- if (!image.currentSrc.startsWith('data:')) {
1707
- image.setAttribute('rrweb-original-src', n.attributes.src);
1708
- image.src = value;
1709
- image.setAttribute('rrweb-inline-src', value);
1710
- }
1711
- }
1712
- if (name_1 === 'rr_width') {
1713
- node_1.style.width = value;
1714
- }
1715
- else if (name_1 === 'rr_height') {
1716
- node_1.style.height = value;
1717
- }
1718
- else if (name_1 === 'rr_mediaCurrentTime') {
1719
- node_1.currentTime = n.attributes
1720
- .rr_mediaCurrentTime;
1721
- }
1722
- else if (name_1 === 'rr_mediaState') {
1723
- switch (value) {
1724
- case 'played':
1725
- node_1
1726
- .play()["catch"](function (e) { return console.warn('media playback error', e); });
1727
- break;
1728
- case 'paused':
1729
- node_1.pause();
1730
- break;
1731
- }
1732
- }
1733
- }
1734
- };
1735
- for (var name_1 in n.attributes) {
1736
- _loop_1(name_1);
1737
- }
1738
- if (tagName === 'img') {
1739
- var image = node_1;
1740
- if (!image.currentSrc.startsWith('data:')) {
1741
- var inlineSrc = image.getAttribute('rrweb-inline-src');
1742
- if (inlineSrc === null || inlineSrc === void 0 ? void 0 : inlineSrc.startsWith('data:')) {
1743
- image.src = inlineSrc;
1744
- }
1745
- }
1746
- }
1747
- if (n.isShadowHost) {
1748
- if (!node_1.shadowRoot) {
1749
- node_1.attachShadow({ mode: 'open' });
1750
- }
1751
- else {
1752
- while (node_1.shadowRoot.firstChild) {
1753
- node_1.shadowRoot.removeChild(node_1.shadowRoot.firstChild);
1754
- }
1755
- }
1756
- }
1757
- return node_1;
1758
- case NodeType$2.Text:
1759
- return doc.createTextNode(n.isStyle && hackCss
1760
- ? addHoverClass(n.textContent, cache)
1761
- : n.textContent);
1762
- case NodeType$2.CDATA:
1763
- return doc.createCDATASection(n.textContent);
1764
- case NodeType$2.Comment:
1765
- return doc.createComment(n.textContent);
1766
- default:
1767
- return null;
1768
- }
1769
- }
1770
- function buildNodeWithSN(n, options) {
1771
- 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;
1772
- var node = buildNode(n, { doc: doc, hackCss: hackCss, cache: cache });
1773
- if (!node) {
1774
- return null;
1775
- }
1776
- if (n.rootId) {
1777
- console.assert(mirror.getNode(n.rootId) === doc, 'Target document should have the same root id.');
1778
- }
1779
- if (n.type === NodeType$2.Document) {
1780
- doc.close();
1781
- doc.open();
1782
- if (n.compatMode === 'BackCompat' &&
1783
- n.childNodes &&
1784
- n.childNodes[0].type !== NodeType$2.DocumentType) {
1785
- if (n.childNodes[0].type === NodeType$2.Element &&
1786
- 'xmlns' in n.childNodes[0].attributes &&
1787
- n.childNodes[0].attributes.xmlns === 'http://www.w3.org/1999/xhtml') {
1788
- doc.write('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">');
1789
- }
1790
- else {
1791
- doc.write('<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "">');
1792
- }
1793
- }
1794
- node = doc;
1795
- }
1796
- mirror.add(node, n);
1797
- if ((n.type === NodeType$2.Document || n.type === NodeType$2.Element) &&
1798
- !skipChild) {
1799
- for (var _i = 0, _c = n.childNodes; _i < _c.length; _i++) {
1800
- var childN = _c[_i];
1801
- var childNode = buildNodeWithSN(childN, {
1802
- doc: doc,
1803
- mirror: mirror,
1804
- skipChild: false,
1805
- hackCss: hackCss,
1806
- afterAppend: afterAppend,
1807
- cache: cache
1808
- });
1809
- if (!childNode) {
1810
- console.warn('Failed to rebuild', childN);
1811
- continue;
1812
- }
1813
- if (childN.isShadow && isElement(node) && node.shadowRoot) {
1814
- node.shadowRoot.appendChild(childNode);
1815
- }
1816
- else {
1817
- node.appendChild(childNode);
1818
- }
1819
- if (afterAppend) {
1820
- afterAppend(childNode);
1821
- }
1822
- }
1823
- }
1824
- return node;
1825
- }
1826
- function visit(mirror, onVisit) {
1827
- function walk(node) {
1828
- onVisit(node);
1829
- }
1830
- for (var _i = 0, _a = mirror.getIds(); _i < _a.length; _i++) {
1831
- var id = _a[_i];
1832
- if (mirror.has(id)) {
1833
- walk(mirror.getNode(id));
1834
- }
1835
- }
1836
- }
1837
- function handleScroll(node, mirror) {
1838
- var n = mirror.getMeta(node);
1839
- if ((n === null || n === void 0 ? void 0 : n.type) !== NodeType$2.Element) {
1840
- return;
1841
- }
1842
- var el = node;
1843
- for (var name_2 in n.attributes) {
1844
- if (!(n.attributes.hasOwnProperty(name_2) && name_2.startsWith('rr_'))) {
1845
- continue;
1846
- }
1847
- var value = n.attributes[name_2];
1848
- if (name_2 === 'rr_scrollLeft') {
1849
- el.scrollLeft = value;
1850
- }
1851
- if (name_2 === 'rr_scrollTop') {
1852
- el.scrollTop = value;
1853
- }
1854
- }
1855
- }
1856
- function rebuild(n, options) {
1857
- 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;
1858
- var node = buildNodeWithSN(n, {
1859
- doc: doc,
1860
- mirror: mirror,
1861
- skipChild: false,
1862
- hackCss: hackCss,
1863
- afterAppend: afterAppend,
1864
- cache: cache
1865
- });
1866
- visit(mirror, function (visitedNode) {
1867
- if (onVisit) {
1868
- onVisit(visitedNode);
1869
- }
1870
- handleScroll(visitedNode, mirror);
1871
- });
1872
- return node;
1873
- }
5
+ var rrwebSnapshot = require('@highlight-run/rrweb-snapshot');
1874
6
 
1875
7
  function on(type, fn, target = document) {
1876
8
  const options = { capture: true, passive: true };
@@ -2019,7 +151,7 @@ function isBlocked(node, blockClass, checkAncestors) {
2019
151
  return true;
2020
152
  }
2021
153
  else {
2022
- if (classMatchesRegex(el, blockClass, checkAncestors))
154
+ if (rrwebSnapshot.classMatchesRegex(el, blockClass, checkAncestors))
2023
155
  return true;
2024
156
  }
2025
157
  return false;
@@ -2028,10 +160,10 @@ function isSerialized(n, mirror) {
2028
160
  return mirror.getId(n) !== -1;
2029
161
  }
2030
162
  function isIgnored(n, mirror) {
2031
- return mirror.getId(n) === IGNORED_NODE;
163
+ return mirror.getId(n) === rrwebSnapshot.IGNORED_NODE;
2032
164
  }
2033
165
  function isAncestorRemoved(target, mirror) {
2034
- if (isShadowRoot(target)) {
166
+ if (rrwebSnapshot.isShadowRoot(target)) {
2035
167
  return false;
2036
168
  }
2037
169
  const id = mirror.getId(target);
@@ -2178,30 +310,30 @@ function uniqueTextMutations(mutations) {
2178
310
  }
2179
311
 
2180
312
  var utils = /*#__PURE__*/Object.freeze({
2181
- __proto__: null,
2182
- on: on,
2183
- get _mirror () { return exports.mirror; },
2184
- throttle: throttle,
2185
- hookSetter: hookSetter,
2186
- patch: patch,
2187
- getWindowHeight: getWindowHeight,
2188
- getWindowWidth: getWindowWidth,
2189
- isCanvasNode: isCanvasNode,
2190
- isBlocked: isBlocked,
2191
- isSerialized: isSerialized,
2192
- isIgnored: isIgnored,
2193
- isAncestorRemoved: isAncestorRemoved,
2194
- isTouchEvent: isTouchEvent,
2195
- polyfill: polyfill$1,
2196
- queueToResolveTrees: queueToResolveTrees,
2197
- iterateResolveTree: iterateResolveTree,
2198
- isSerializedIframe: isSerializedIframe,
2199
- isSerializedStylesheet: isSerializedStylesheet,
2200
- getBaseDimension: getBaseDimension,
2201
- hasShadowRoot: hasShadowRoot,
2202
- getNestedRule: getNestedRule$1,
2203
- getPositionsAndIndex: getPositionsAndIndex$1,
2204
- 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
2205
337
  });
2206
338
 
2207
339
  exports.EventType = void 0;
@@ -2380,8 +512,8 @@ class MutationBuffer {
2380
512
  const addList = new DoubleLinkedList();
2381
513
  const getNextId = (n) => {
2382
514
  let ns = n;
2383
- let nextId = IGNORED_NODE;
2384
- while (nextId === IGNORED_NODE) {
515
+ let nextId = rrwebSnapshot.IGNORED_NODE;
516
+ while (nextId === rrwebSnapshot.IGNORED_NODE) {
2385
517
  ns = ns && ns.nextSibling;
2386
518
  nextId = ns && this.mirror.getId(ns);
2387
519
  }
@@ -2402,14 +534,14 @@ class MutationBuffer {
2402
534
  if (!n.parentNode || notInDoc) {
2403
535
  return;
2404
536
  }
2405
- const parentId = isShadowRoot(n.parentNode)
537
+ const parentId = rrwebSnapshot.isShadowRoot(n.parentNode)
2406
538
  ? this.mirror.getId(shadowHost)
2407
539
  : this.mirror.getId(n.parentNode);
2408
540
  const nextId = getNextId(n);
2409
541
  if (parentId === -1 || nextId === -1) {
2410
542
  return addList.addNode(n);
2411
543
  }
2412
- const sn = serializeNodeWithId(n, {
544
+ const sn = rrwebSnapshot.serializeNodeWithId(n, {
2413
545
  doc: this.doc,
2414
546
  mirror: this.mirror,
2415
547
  blockClass: this.blockClass,
@@ -2513,7 +645,7 @@ class MutationBuffer {
2513
645
  .map((text) => {
2514
646
  let value = text.value;
2515
647
  if (this.enableStrictPrivacy && value) {
2516
- value = obfuscateText(value);
648
+ value = rrwebSnapshot.obfuscateText(value);
2517
649
  }
2518
650
  return {
2519
651
  id: this.mirror.getId(text.node),
@@ -2555,7 +687,7 @@ class MutationBuffer {
2555
687
  if (!isBlocked(m.target, this.blockClass, false) &&
2556
688
  value !== m.oldValue) {
2557
689
  this.texts.push({
2558
- value: needMaskingText(m.target, this.maskTextClass, this.maskTextSelector) && value
690
+ value: rrwebSnapshot.needMaskingText(m.target, this.maskTextClass, this.maskTextSelector) && value
2559
691
  ? this.maskTextFn
2560
692
  ? this.maskTextFn(value)
2561
693
  : value.replace(/[\S]/g, '*')
@@ -2569,7 +701,7 @@ class MutationBuffer {
2569
701
  const target = m.target;
2570
702
  let value = m.target.getAttribute(m.attributeName);
2571
703
  if (m.attributeName === 'value') {
2572
- value = maskInputValue({
704
+ value = rrwebSnapshot.maskInputValue({
2573
705
  maskInputOptions: this.maskInputOptions,
2574
706
  tagName: m.target.tagName,
2575
707
  type: m.target.getAttribute('type'),
@@ -2627,7 +759,7 @@ class MutationBuffer {
2627
759
  break;
2628
760
  }
2629
761
  }
2630
- 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);
2631
763
  }
2632
764
  break;
2633
765
  }
@@ -2637,7 +769,7 @@ class MutationBuffer {
2637
769
  m.addedNodes.forEach((n) => this.genAdds(n, m.target));
2638
770
  m.removedNodes.forEach((n) => {
2639
771
  const nodeId = this.mirror.getId(n);
2640
- const parentId = isShadowRoot(m.target)
772
+ const parentId = rrwebSnapshot.isShadowRoot(m.target)
2641
773
  ? this.mirror.getId(m.target.host)
2642
774
  : this.mirror.getId(m.target);
2643
775
  if (isBlocked(m.target, this.blockClass, false) ||
@@ -2659,7 +791,7 @@ class MutationBuffer {
2659
791
  this.removes.push({
2660
792
  parentId,
2661
793
  id: nodeId,
2662
- isShadow: isShadowRoot(m.target) ? true : undefined,
794
+ isShadow: rrwebSnapshot.isShadowRoot(m.target) ? true : undefined,
2663
795
  });
2664
796
  }
2665
797
  this.mapRemoves.push(n);
@@ -2988,7 +1120,7 @@ function initInputObserver({ inputCb, doc, mirror, blockClass, ignoreClass, mask
2988
1120
  }
2989
1121
  else if (maskInputOptions[target.tagName.toLowerCase()] ||
2990
1122
  maskInputOptions[type]) {
2991
- text = maskInputValue({
1123
+ text = rrwebSnapshot.maskInputValue({
2992
1124
  maskInputOptions,
2993
1125
  tagName: target.tagName,
2994
1126
  type,
@@ -4024,7 +2156,7 @@ function wrapEvent(e) {
4024
2156
  }
4025
2157
  let wrappedEmit;
4026
2158
  let takeFullSnapshot;
4027
- const mirror = createMirror$2();
2159
+ const mirror = rrwebSnapshot.createMirror();
4028
2160
  function record(options = {}) {
4029
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;
4030
2162
  if (!emit) {
@@ -4175,7 +2307,7 @@ function record(options = {}) {
4175
2307
  },
4176
2308
  }), isCheckout);
4177
2309
  mutationBuffers.forEach((buf) => buf.lock());
4178
- const node = snapshot(document, {
2310
+ const node = rrwebSnapshot.snapshot(document, {
4179
2311
  mirror,
4180
2312
  blockClass,
4181
2313
  blockSelector,
@@ -4368,70 +2500,6 @@ record.takeFullSnapshot = (isCheckout) => {
4368
2500
  };
4369
2501
  record.mirror = mirror;
4370
2502
 
4371
- var NodeType$1;
4372
- (function (NodeType) {
4373
- NodeType[NodeType["Document"] = 0] = "Document";
4374
- NodeType[NodeType["DocumentType"] = 1] = "DocumentType";
4375
- NodeType[NodeType["Element"] = 2] = "Element";
4376
- NodeType[NodeType["Text"] = 3] = "Text";
4377
- NodeType[NodeType["CDATA"] = 4] = "CDATA";
4378
- NodeType[NodeType["Comment"] = 5] = "Comment";
4379
- })(NodeType$1 || (NodeType$1 = {}));
4380
- var Mirror$1 = (function () {
4381
- function Mirror() {
4382
- this.idNodeMap = new Map();
4383
- this.nodeMetaMap = new WeakMap();
4384
- }
4385
- Mirror.prototype.getId = function (n) {
4386
- var _a;
4387
- if (!n)
4388
- return -1;
4389
- var id = (_a = this.getMeta(n)) === null || _a === void 0 ? void 0 : _a.id;
4390
- return id !== null && id !== void 0 ? id : -1;
4391
- };
4392
- Mirror.prototype.getNode = function (id) {
4393
- return this.idNodeMap.get(id) || null;
4394
- };
4395
- Mirror.prototype.getIds = function () {
4396
- return Array.from(this.idNodeMap.keys());
4397
- };
4398
- Mirror.prototype.getMeta = function (n) {
4399
- return this.nodeMetaMap.get(n) || null;
4400
- };
4401
- Mirror.prototype.removeNodeFromMap = function (n) {
4402
- var _this = this;
4403
- var id = this.getId(n);
4404
- this.idNodeMap["delete"](id);
4405
- if (n.childNodes) {
4406
- n.childNodes.forEach(function (childNode) {
4407
- return _this.removeNodeFromMap(childNode);
4408
- });
4409
- }
4410
- };
4411
- Mirror.prototype.has = function (id) {
4412
- return this.idNodeMap.has(id);
4413
- };
4414
- Mirror.prototype.hasNode = function (node) {
4415
- return this.nodeMetaMap.has(node);
4416
- };
4417
- Mirror.prototype.add = function (n, meta) {
4418
- var id = meta.id;
4419
- this.idNodeMap.set(id, n);
4420
- this.nodeMetaMap.set(n, meta);
4421
- };
4422
- Mirror.prototype.replace = function (id, n) {
4423
- this.idNodeMap.set(id, n);
4424
- };
4425
- Mirror.prototype.reset = function () {
4426
- this.idNodeMap = new Map();
4427
- this.nodeMetaMap = new WeakMap();
4428
- };
4429
- return Mirror;
4430
- }());
4431
- function createMirror$1() {
4432
- return new Mirror$1();
4433
- }
4434
-
4435
2503
  function parseCSSText(cssText) {
4436
2504
  const res = {};
4437
2505
  const listDelimiter = /;(?![^(]*\))/g;
@@ -4522,21 +2590,21 @@ function BaseRRDocumentImpl(RRNodeClass) {
4522
2590
  this.nodeType = NodeType.DOCUMENT_NODE;
4523
2591
  this.nodeName = '#document';
4524
2592
  this.compatMode = 'CSS1Compat';
4525
- this.RRNodeType = NodeType$1.Document;
2593
+ this.RRNodeType = rrwebSnapshot.NodeType.Document;
4526
2594
  this.textContent = null;
4527
2595
  }
4528
2596
  get documentElement() {
4529
- return (this.childNodes.find((node) => node.RRNodeType === NodeType$1.Element &&
2597
+ return (this.childNodes.find((node) => node.RRNodeType === rrwebSnapshot.NodeType.Element &&
4530
2598
  node.tagName === 'HTML') || null);
4531
2599
  }
4532
2600
  get body() {
4533
2601
  var _a;
4534
- 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 &&
4535
2603
  node.tagName === 'BODY')) || null);
4536
2604
  }
4537
2605
  get head() {
4538
2606
  var _a;
4539
- 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 &&
4540
2608
  node.tagName === 'HEAD')) || null);
4541
2609
  }
4542
2610
  get implementation() {
@@ -4547,10 +2615,10 @@ function BaseRRDocumentImpl(RRNodeClass) {
4547
2615
  }
4548
2616
  appendChild(childNode) {
4549
2617
  const nodeType = childNode.RRNodeType;
4550
- if (nodeType === NodeType$1.Element ||
4551
- nodeType === NodeType$1.DocumentType) {
2618
+ if (nodeType === rrwebSnapshot.NodeType.Element ||
2619
+ nodeType === rrwebSnapshot.NodeType.DocumentType) {
4552
2620
  if (this.childNodes.some((s) => s.RRNodeType === nodeType)) {
4553
- 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.`);
4554
2622
  }
4555
2623
  }
4556
2624
  childNode.parentElement = null;
@@ -4560,10 +2628,10 @@ function BaseRRDocumentImpl(RRNodeClass) {
4560
2628
  }
4561
2629
  insertBefore(newChild, refChild) {
4562
2630
  const nodeType = newChild.RRNodeType;
4563
- if (nodeType === NodeType$1.Element ||
4564
- nodeType === NodeType$1.DocumentType) {
2631
+ if (nodeType === rrwebSnapshot.NodeType.Element ||
2632
+ nodeType === rrwebSnapshot.NodeType.DocumentType) {
4565
2633
  if (this.childNodes.some((s) => s.RRNodeType === nodeType)) {
4566
- 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.`);
4567
2635
  }
4568
2636
  }
4569
2637
  if (refChild === null)
@@ -4645,7 +2713,7 @@ function BaseRRDocumentTypeImpl(RRNodeClass) {
4645
2713
  constructor(qualifiedName, publicId, systemId) {
4646
2714
  super();
4647
2715
  this.nodeType = NodeType.DOCUMENT_TYPE_NODE;
4648
- this.RRNodeType = NodeType$1.DocumentType;
2716
+ this.RRNodeType = rrwebSnapshot.NodeType.DocumentType;
4649
2717
  this.textContent = null;
4650
2718
  this.name = qualifiedName;
4651
2719
  this.publicId = publicId;
@@ -4662,7 +2730,7 @@ function BaseRRElementImpl(RRNodeClass) {
4662
2730
  constructor(tagName) {
4663
2731
  super();
4664
2732
  this.nodeType = NodeType.ELEMENT_NODE;
4665
- this.RRNodeType = NodeType$1.Element;
2733
+ this.RRNodeType = rrwebSnapshot.NodeType.Element;
4666
2734
  this.attributes = {};
4667
2735
  this.shadowRoot = null;
4668
2736
  this.tagName = tagName.toUpperCase();
@@ -4789,7 +2857,7 @@ function BaseRRTextImpl(RRNodeClass) {
4789
2857
  super();
4790
2858
  this.nodeType = NodeType.TEXT_NODE;
4791
2859
  this.nodeName = '#text';
4792
- this.RRNodeType = NodeType$1.Text;
2860
+ this.RRNodeType = rrwebSnapshot.NodeType.Text;
4793
2861
  this.data = data;
4794
2862
  }
4795
2863
  get textContent() {
@@ -4809,7 +2877,7 @@ function BaseRRCommentImpl(RRNodeClass) {
4809
2877
  super();
4810
2878
  this.nodeType = NodeType.COMMENT_NODE;
4811
2879
  this.nodeName = '#comment';
4812
- this.RRNodeType = NodeType$1.Comment;
2880
+ this.RRNodeType = rrwebSnapshot.NodeType.Comment;
4813
2881
  this.data = data;
4814
2882
  }
4815
2883
  get textContent() {
@@ -4829,7 +2897,7 @@ function BaseRRCDATASectionImpl(RRNodeClass) {
4829
2897
  super();
4830
2898
  this.nodeName = '#cdata-section';
4831
2899
  this.nodeType = NodeType.CDATA_SECTION_NODE;
4832
- this.RRNodeType = NodeType$1.CDATA;
2900
+ this.RRNodeType = rrwebSnapshot.NodeType.CDATA;
4833
2901
  this.data = data;
4834
2902
  }
4835
2903
  get textContent() {
@@ -4899,12 +2967,12 @@ function diff(oldTree, newTree, replayer, rrnodeMirror) {
4899
2967
  }
4900
2968
  let inputDataToApply = null, scrollDataToApply = null;
4901
2969
  switch (newTree.RRNodeType) {
4902
- case NodeType$1.Document: {
2970
+ case rrwebSnapshot.NodeType.Document: {
4903
2971
  const newRRDocument = newTree;
4904
2972
  scrollDataToApply = newRRDocument.scrollData;
4905
2973
  break;
4906
2974
  }
4907
- case NodeType$1.Element: {
2975
+ case rrwebSnapshot.NodeType.Element: {
4908
2976
  const oldElement = oldTree;
4909
2977
  const newRRElement = newTree;
4910
2978
  diffProps(oldElement, newRRElement, rrnodeMirror);
@@ -4944,9 +3012,9 @@ function diff(oldTree, newTree, replayer, rrnodeMirror) {
4944
3012
  }
4945
3013
  break;
4946
3014
  }
4947
- case NodeType$1.Text:
4948
- case NodeType$1.Comment:
4949
- case NodeType$1.CDATA:
3015
+ case rrwebSnapshot.NodeType.Text:
3016
+ case rrwebSnapshot.NodeType.Comment:
3017
+ case rrwebSnapshot.NodeType.CDATA:
4950
3018
  if (oldTree.textContent !==
4951
3019
  newTree.data)
4952
3020
  oldTree.textContent = newTree.data;
@@ -4994,7 +3062,7 @@ function diffProps(oldTree, newTree, rrnodeMirror) {
4994
3062
  newTree.scrollTop && (oldTree.scrollTop = newTree.scrollTop);
4995
3063
  }
4996
3064
  function diffChildren(oldChildren, newChildren, parentNode, replayer, rrnodeMirror) {
4997
- var _a, _b;
3065
+ var _a;
4998
3066
  let oldStartIndex = 0, oldEndIndex = oldChildren.length - 1, newStartIndex = 0, newEndIndex = newChildren.length - 1;
4999
3067
  let oldStartNode = oldChildren[oldStartIndex], oldEndNode = oldChildren[oldEndIndex], newStartNode = newChildren[newStartIndex], newEndNode = newChildren[newEndIndex];
5000
3068
  let oldIdToIndex = undefined, indexInOld;
@@ -5018,24 +3086,24 @@ function diffChildren(oldChildren, newChildren, parentNode, replayer, rrnodeMirr
5018
3086
  else if (replayer.mirror.getId(oldStartNode) === rrnodeMirror.getId(newEndNode)) {
5019
3087
  try {
5020
3088
  parentNode.insertBefore(oldStartNode, oldEndNode.nextSibling);
5021
- }
5022
- catch (e) {
5023
- console.error(e, parentNode, oldStartNode, oldEndNode);
5024
3089
  diff(oldStartNode, newEndNode, replayer, rrnodeMirror);
5025
3090
  oldStartNode = oldChildren[++oldStartIndex];
5026
3091
  newEndNode = newChildren[--newEndIndex];
5027
3092
  }
3093
+ catch (e) {
3094
+ console.error(e, parentNode, oldStartNode, oldEndNode);
3095
+ }
5028
3096
  }
5029
3097
  else if (replayer.mirror.getId(oldEndNode) === rrnodeMirror.getId(newStartNode)) {
5030
3098
  try {
5031
3099
  parentNode.insertBefore(oldEndNode, oldStartNode);
5032
- }
5033
- catch (e) {
5034
- console.error(e, parentNode, oldEndNode, oldStartNode);
5035
3100
  diff(oldEndNode, newStartNode, replayer, rrnodeMirror);
5036
3101
  oldEndNode = oldChildren[--oldEndIndex];
5037
3102
  newStartNode = newChildren[++newStartIndex];
5038
3103
  }
3104
+ catch (e) {
3105
+ console.error(e, parentNode, oldEndNode, oldStartNode);
3106
+ }
5039
3107
  }
5040
3108
  else {
5041
3109
  if (!oldIdToIndex) {
@@ -5051,17 +3119,17 @@ function diffChildren(oldChildren, newChildren, parentNode, replayer, rrnodeMirr
5051
3119
  const nodeToMove = oldChildren[indexInOld];
5052
3120
  try {
5053
3121
  parentNode.insertBefore(nodeToMove, oldStartNode);
3122
+ diff(nodeToMove, newStartNode, replayer, rrnodeMirror);
3123
+ oldChildren[indexInOld] = undefined;
5054
3124
  }
5055
3125
  catch (e) {
5056
3126
  console.error(e, parentNode, nodeToMove, oldStartNode);
5057
- diff(nodeToMove, newStartNode, replayer, rrnodeMirror);
5058
- oldChildren[indexInOld] = undefined;
5059
3127
  }
5060
3128
  }
5061
3129
  else {
5062
3130
  const newNode = createOrGetNode(newStartNode, replayer.mirror, rrnodeMirror);
5063
- if (((_a = replayer.mirror.getMeta(parentNode)) === null || _a === void 0 ? void 0 : _a.type) === NodeType$1.Document &&
5064
- ((_b = replayer.mirror.getMeta(newNode)) === null || _b === void 0 ? void 0 : _b.type) === NodeType$1.Element &&
3131
+ if (parentNode.nodeName === '#document' &&
3132
+ ((_a = replayer.mirror.getMeta(newNode)) === null || _a === void 0 ? void 0 : _a.type) === rrwebSnapshot.NodeType.Element &&
5065
3133
  parentNode.documentElement) {
5066
3134
  parentNode.removeChild(parentNode.documentElement);
5067
3135
  oldChildren[oldStartIndex] = undefined;
@@ -5069,10 +3137,10 @@ function diffChildren(oldChildren, newChildren, parentNode, replayer, rrnodeMirr
5069
3137
  }
5070
3138
  try {
5071
3139
  parentNode.insertBefore(newNode, oldStartNode || null);
3140
+ diff(newNode, newStartNode, replayer, rrnodeMirror);
5072
3141
  }
5073
3142
  catch (e) {
5074
3143
  console.error(e, parentNode, newNode, oldStartNode || null);
5075
- diff(newNode, newStartNode, replayer, rrnodeMirror);
5076
3144
  }
5077
3145
  }
5078
3146
  newStartNode = newChildren[++newStartIndex];
@@ -5090,10 +3158,10 @@ function diffChildren(oldChildren, newChildren, parentNode, replayer, rrnodeMirr
5090
3158
  const newNode = createOrGetNode(newChildren[newStartIndex], replayer.mirror, rrnodeMirror);
5091
3159
  try {
5092
3160
  parentNode.insertBefore(newNode, referenceNode);
3161
+ diff(newNode, newChildren[newStartIndex], replayer, rrnodeMirror);
5093
3162
  }
5094
3163
  catch (e) {
5095
3164
  console.error(e, parentNode, newNode, referenceNode);
5096
- diff(newNode, newChildren[newStartIndex], replayer, rrnodeMirror);
5097
3165
  }
5098
3166
  }
5099
3167
  }
@@ -5113,13 +3181,13 @@ function createOrGetNode(rrNode, domMirror, rrnodeMirror) {
5113
3181
  if (node !== null)
5114
3182
  return node;
5115
3183
  switch (rrNode.RRNodeType) {
5116
- case NodeType$1.Document:
3184
+ case rrwebSnapshot.NodeType.Document:
5117
3185
  node = new Document();
5118
3186
  break;
5119
- case NodeType$1.DocumentType:
3187
+ case rrwebSnapshot.NodeType.DocumentType:
5120
3188
  node = document.implementation.createDocumentType(rrNode.name, rrNode.publicId, rrNode.systemId);
5121
3189
  break;
5122
- case NodeType$1.Element: {
3190
+ case rrwebSnapshot.NodeType.Element: {
5123
3191
  rrNode.tagName.toLowerCase();
5124
3192
  if (sn && 'isSVG' in sn && (sn === null || sn === void 0 ? void 0 : sn.isSVG)) {
5125
3193
  node = document.createElementNS(NAMESPACES['svg'], rrNode.tagName.toLowerCase());
@@ -5128,13 +3196,13 @@ function createOrGetNode(rrNode, domMirror, rrnodeMirror) {
5128
3196
  node = document.createElement(rrNode.tagName);
5129
3197
  break;
5130
3198
  }
5131
- case NodeType$1.Text:
3199
+ case rrwebSnapshot.NodeType.Text:
5132
3200
  node = document.createTextNode(rrNode.data);
5133
3201
  break;
5134
- case NodeType$1.Comment:
3202
+ case rrwebSnapshot.NodeType.Comment:
5135
3203
  node = document.createComment(rrNode.data);
5136
3204
  break;
5137
- case NodeType$1.CDATA:
3205
+ case rrwebSnapshot.NodeType.CDATA:
5138
3206
  node = document.createCDATASection(rrNode.data);
5139
3207
  break;
5140
3208
  }
@@ -5367,7 +3435,7 @@ function buildFromNode(node, rrdom, domMirror, parentRRNode) {
5367
3435
  }
5368
3436
  return rrNode;
5369
3437
  }
5370
- function buildFromDom(dom, domMirror = createMirror$1(), rrdom = new RRDocument()) {
3438
+ function buildFromDom(dom, domMirror = rrwebSnapshot.createMirror(), rrdom = new RRDocument()) {
5371
3439
  function walk(node, parentRRNode) {
5372
3440
  const rrNode = buildFromNode(node, rrdom, domMirror, parentRRNode);
5373
3441
  if (rrNode === null)
@@ -5445,13 +3513,13 @@ class Mirror {
5445
3513
  }
5446
3514
  function getDefaultSN(node, id) {
5447
3515
  switch (node.RRNodeType) {
5448
- case NodeType$1.Document:
3516
+ case rrwebSnapshot.NodeType.Document:
5449
3517
  return {
5450
3518
  id,
5451
3519
  type: node.RRNodeType,
5452
3520
  childNodes: [],
5453
3521
  };
5454
- case NodeType$1.DocumentType:
3522
+ case rrwebSnapshot.NodeType.DocumentType:
5455
3523
  const doctype = node;
5456
3524
  return {
5457
3525
  id,
@@ -5460,7 +3528,7 @@ function getDefaultSN(node, id) {
5460
3528
  publicId: doctype.publicId,
5461
3529
  systemId: doctype.systemId,
5462
3530
  };
5463
- case NodeType$1.Element:
3531
+ case rrwebSnapshot.NodeType.Element:
5464
3532
  return {
5465
3533
  id,
5466
3534
  type: node.RRNodeType,
@@ -5468,19 +3536,19 @@ function getDefaultSN(node, id) {
5468
3536
  attributes: {},
5469
3537
  childNodes: [],
5470
3538
  };
5471
- case NodeType$1.Text:
3539
+ case rrwebSnapshot.NodeType.Text:
5472
3540
  return {
5473
3541
  id,
5474
3542
  type: node.RRNodeType,
5475
3543
  textContent: node.textContent || '',
5476
3544
  };
5477
- case NodeType$1.Comment:
3545
+ case rrwebSnapshot.NodeType.Comment:
5478
3546
  return {
5479
3547
  id,
5480
3548
  type: node.RRNodeType,
5481
3549
  textContent: node.textContent || '',
5482
3550
  };
5483
- case NodeType$1.CDATA:
3551
+ case rrwebSnapshot.NodeType.CDATA:
5484
3552
  return {
5485
3553
  id,
5486
3554
  type: node.RRNodeType,
@@ -5552,8 +3620,8 @@ function mitt$1(all ) {
5552
3620
  }
5553
3621
 
5554
3622
  var mittProxy = /*#__PURE__*/Object.freeze({
5555
- __proto__: null,
5556
- 'default': mitt$1
3623
+ __proto__: null,
3624
+ 'default': mitt$1
5557
3625
  });
5558
3626
 
5559
3627
  function polyfill(w = window, d = document) {
@@ -6371,10 +4439,10 @@ class Replayer {
6371
4439
  this.emitter = mitt();
6372
4440
  this.activityIntervals = [];
6373
4441
  this.legacy_missingNodeRetryMap = {};
6374
- this.cache = createCache();
4442
+ this.cache = rrwebSnapshot.createCache();
6375
4443
  this.imageMap = new Map();
6376
4444
  this.canvasEventMap = new Map();
6377
- this.mirror = createMirror$2();
4445
+ this.mirror = rrwebSnapshot.createMirror();
6378
4446
  this.firstFullSnapshot = null;
6379
4447
  this.newDocumentQueue = [];
6380
4448
  this.mousePos = null;
@@ -6716,7 +4784,7 @@ class Replayer {
6716
4784
  this.iframe.style.pointerEvents = 'none';
6717
4785
  }
6718
4786
  resetCache() {
6719
- this.cache = createCache();
4787
+ this.cache = rrwebSnapshot.createCache();
6720
4788
  }
6721
4789
  setupDom() {
6722
4790
  this.wrapper = document.createElement('div');
@@ -6918,7 +4986,7 @@ class Replayer {
6918
4986
  }
6919
4987
  this.legacy_missingNodeRetryMap = {};
6920
4988
  const collected = [];
6921
- rebuild(event.data.node, {
4989
+ rrwebSnapshot.rebuild(event.data.node, {
6922
4990
  doc: this.iframe.contentDocument,
6923
4991
  afterAppend: (builtNode) => {
6924
4992
  this.collectIframeAndAttachDocument(collected, builtNode);
@@ -6975,7 +5043,7 @@ class Replayer {
6975
5043
  ? this.virtualDom.mirror
6976
5044
  : this.mirror;
6977
5045
  const collected = [];
6978
- buildNodeWithSN(mutation.node, {
5046
+ rrwebSnapshot.buildNodeWithSN(mutation.node, {
6979
5047
  doc: iframeEl.contentDocument,
6980
5048
  mirror: mirror,
6981
5049
  hackCss: true,
@@ -6983,7 +5051,7 @@ class Replayer {
6983
5051
  afterAppend: (builtNode) => {
6984
5052
  this.collectIframeAndAttachDocument(collected, builtNode);
6985
5053
  const sn = mirror.getMeta(builtNode);
6986
- 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 &&
6987
5055
  (sn === null || sn === void 0 ? void 0 : sn.tagName.toUpperCase()) === 'HTML') {
6988
5056
  const { documentElement, head } = iframeEl.contentDocument;
6989
5057
  this.insertStyleRules(documentElement, head);
@@ -7537,7 +5605,7 @@ class Replayer {
7537
5605
  }
7538
5606
  let parent = mirror.getNode(mutation.parentId);
7539
5607
  if (!parent) {
7540
- if (mutation.node.type === NodeType$2.Document) {
5608
+ if (mutation.node.type === rrwebSnapshot.NodeType.Document) {
7541
5609
  return this.newDocumentQueue.push(mutation);
7542
5610
  }
7543
5611
  return queue.push(mutation);
@@ -7573,7 +5641,7 @@ class Replayer {
7573
5641
  this.attachDocumentToIframe(mutation, parent);
7574
5642
  return;
7575
5643
  }
7576
- const target = buildNodeWithSN(mutation.node, {
5644
+ const target = rrwebSnapshot.buildNodeWithSN(mutation.node, {
7577
5645
  doc: targetDoc,
7578
5646
  mirror: mirror,
7579
5647
  skipChild: true,
@@ -7589,9 +5657,9 @@ class Replayer {
7589
5657
  }
7590
5658
  const parentSn = mirror.getMeta(parent);
7591
5659
  if (parentSn &&
7592
- parentSn.type === NodeType$2.Element &&
5660
+ parentSn.type === rrwebSnapshot.NodeType.Element &&
7593
5661
  parentSn.tagName === 'textarea' &&
7594
- mutation.node.type === NodeType$2.Text) {
5662
+ mutation.node.type === rrwebSnapshot.NodeType.Text) {
7595
5663
  const childNodeArray = Array.isArray(parent.childNodes)
7596
5664
  ? parent.childNodes
7597
5665
  : Array.from(parent.childNodes);
@@ -7734,7 +5802,7 @@ class Replayer {
7734
5802
  behavior: isSync ? 'auto' : 'smooth',
7735
5803
  });
7736
5804
  }
7737
- 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) {
7738
5806
  target.defaultView.scrollTo({
7739
5807
  top: d.y,
7740
5808
  left: d.x,