@highlight-run/rrweb 2.0.10 → 2.0.14

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 (37) hide show
  1. package/dist/plugins/console-record.min.js.map +1 -1
  2. package/dist/plugins/console-replay.min.js.map +1 -1
  3. package/dist/record/rrweb-record-pack.min.js.map +1 -1
  4. package/dist/record/rrweb-record.js +3 -3
  5. package/dist/record/rrweb-record.min.js +3 -3
  6. package/dist/record/rrweb-record.min.js.map +1 -1
  7. package/dist/replay/rrweb-replay-unpack.js +4 -4
  8. package/dist/replay/rrweb-replay-unpack.min.js +4 -4
  9. package/dist/replay/rrweb-replay-unpack.min.js.map +1 -1
  10. package/dist/replay/rrweb-replay.js +4 -4
  11. package/dist/replay/rrweb-replay.min.js +4 -4
  12. package/dist/replay/rrweb-replay.min.js.map +1 -1
  13. package/dist/rrweb-all.js +8 -8
  14. package/dist/rrweb-all.min.js +8 -8
  15. package/dist/rrweb-all.min.js.map +1 -1
  16. package/dist/rrweb.js +5 -5
  17. package/dist/rrweb.min.js +5 -5
  18. package/dist/rrweb.min.js.map +1 -1
  19. package/es/rrweb/packages/rrdom/es/{virtual-dom.js → rrdom.js} +87 -112
  20. package/es/rrweb/packages/rrweb/src/index.js +1 -1
  21. package/es/rrweb/packages/rrweb/src/record/index.js +2 -0
  22. package/es/rrweb/packages/rrweb/src/record/mutation.js +12 -1
  23. package/es/rrweb/packages/rrweb/src/replay/index.js +3 -3
  24. package/es/rrweb/packages/rrweb-snapshot/es/rrweb-snapshot.js +1860 -1861
  25. package/lib/plugins/console-record.js +8 -8
  26. package/lib/plugins/console-replay.js +8 -8
  27. package/lib/record/rrweb-record-pack.js +8 -8
  28. package/lib/record/rrweb-record.js +1055 -1043
  29. package/lib/replay/rrweb-replay-unpack.js +971 -996
  30. package/lib/replay/rrweb-replay.js +971 -996
  31. package/lib/rrweb-all.js +1963 -1976
  32. package/lib/rrweb.js +1963 -1976
  33. package/package.json +4 -4
  34. package/typings/record/mutation.d.ts +1 -0
  35. package/typings/replay/index.d.ts +1 -1
  36. package/typings/types.d.ts +3 -2
  37. package/typings/utils.d.ts +1 -1
@@ -1,1871 +1,1870 @@
1
- var NodeType;
2
- (function (NodeType) {
3
- NodeType[NodeType["Document"] = 0] = "Document";
4
- NodeType[NodeType["DocumentType"] = 1] = "DocumentType";
5
- NodeType[NodeType["Element"] = 2] = "Element";
6
- NodeType[NodeType["Text"] = 3] = "Text";
7
- NodeType[NodeType["CDATA"] = 4] = "CDATA";
8
- NodeType[NodeType["Comment"] = 5] = "Comment";
1
+ var NodeType;
2
+ (function (NodeType) {
3
+ NodeType[NodeType["Document"] = 0] = "Document";
4
+ NodeType[NodeType["DocumentType"] = 1] = "DocumentType";
5
+ NodeType[NodeType["Element"] = 2] = "Element";
6
+ NodeType[NodeType["Text"] = 3] = "Text";
7
+ NodeType[NodeType["CDATA"] = 4] = "CDATA";
8
+ NodeType[NodeType["Comment"] = 5] = "Comment";
9
9
  })(NodeType || (NodeType = {}));
10
10
 
11
- function isElement(n) {
12
- return n.nodeType === n.ELEMENT_NODE;
13
- }
14
- function isShadowRoot(n) {
15
- var _a;
16
- var host = (_a = n) === null || _a === void 0 ? void 0 : _a.host;
17
- return Boolean((host === null || host === void 0 ? void 0 : host.shadowRoot) === n);
18
- }
19
- var Mirror = (function () {
20
- function Mirror() {
21
- this.idNodeMap = new Map();
22
- this.nodeMetaMap = new WeakMap();
23
- }
24
- Mirror.prototype.getId = function (n) {
25
- var _a;
26
- if (!n)
27
- return -1;
28
- var id = (_a = this.getMeta(n)) === null || _a === void 0 ? void 0 : _a.id;
29
- return id !== null && id !== void 0 ? id : -1;
30
- };
31
- Mirror.prototype.getNode = function (id) {
32
- return this.idNodeMap.get(id) || null;
33
- };
34
- Mirror.prototype.getIds = function () {
35
- return Array.from(this.idNodeMap.keys());
36
- };
37
- Mirror.prototype.getMeta = function (n) {
38
- return this.nodeMetaMap.get(n) || null;
39
- };
40
- Mirror.prototype.removeNodeFromMap = function (n) {
41
- var _this = this;
42
- var id = this.getId(n);
43
- this.idNodeMap["delete"](id);
44
- if (n.childNodes) {
45
- n.childNodes.forEach(function (childNode) {
46
- return _this.removeNodeFromMap(childNode);
47
- });
48
- }
49
- };
50
- Mirror.prototype.has = function (id) {
51
- return this.idNodeMap.has(id);
52
- };
53
- Mirror.prototype.hasNode = function (node) {
54
- return this.nodeMetaMap.has(node);
55
- };
56
- Mirror.prototype.add = function (n, meta) {
57
- var id = meta.id;
58
- this.idNodeMap.set(id, n);
59
- this.nodeMetaMap.set(n, meta);
60
- };
61
- Mirror.prototype.replace = function (id, n) {
62
- this.idNodeMap.set(id, n);
63
- };
64
- Mirror.prototype.reset = function () {
65
- this.idNodeMap = new Map();
66
- this.nodeMetaMap = new WeakMap();
67
- };
68
- return Mirror;
69
- }());
70
- function createMirror() {
71
- return new Mirror();
72
- }
73
- function maskInputValue(_a) {
74
- var maskInputOptions = _a.maskInputOptions, tagName = _a.tagName, type = _a.type, value = _a.value, maskInputFn = _a.maskInputFn;
75
- var text = value || '';
76
- if (maskInputOptions[tagName.toLowerCase()] ||
77
- maskInputOptions[type]) {
78
- if (maskInputFn) {
79
- text = maskInputFn(text);
80
- }
81
- else {
82
- text = '*'.repeat(text.length);
83
- }
84
- }
85
- return text;
86
- }
87
- var ORIGINAL_ATTRIBUTE_NAME = '__rrweb_original__';
88
- function is2DCanvasBlank(canvas) {
89
- var ctx = canvas.getContext('2d');
90
- if (!ctx)
91
- return true;
92
- var chunkSize = 50;
93
- for (var x = 0; x < canvas.width; x += chunkSize) {
94
- for (var y = 0; y < canvas.height; y += chunkSize) {
95
- var getImageData = ctx.getImageData;
96
- var originalGetImageData = ORIGINAL_ATTRIBUTE_NAME in getImageData
97
- ? getImageData[ORIGINAL_ATTRIBUTE_NAME]
98
- : getImageData;
99
- var pixelBuffer = new Uint32Array(originalGetImageData.call(ctx, x, y, Math.min(chunkSize, canvas.width - x), Math.min(chunkSize, canvas.height - y)).data.buffer);
100
- if (pixelBuffer.some(function (pixel) { return pixel !== 0; }))
101
- return false;
102
- }
103
- }
104
- return true;
105
- }
106
- function obfuscateText(text) {
107
- text = text.replace(/[^ -~]+/g, '');
108
- text =
109
- (text === null || text === void 0 ? void 0 : text.split(' ').map(function (word) { return Math.random().toString(20).substr(2, word.length); }).join(' ')) || '';
110
- return text;
11
+ function isElement(n) {
12
+ return n.nodeType === n.ELEMENT_NODE;
13
+ }
14
+ function isShadowRoot(n) {
15
+ var host = n === null || n === void 0 ? void 0 : n.host;
16
+ return Boolean((host === null || host === void 0 ? void 0 : host.shadowRoot) === n);
17
+ }
18
+ var Mirror = (function () {
19
+ function Mirror() {
20
+ this.idNodeMap = new Map();
21
+ this.nodeMetaMap = new WeakMap();
22
+ }
23
+ Mirror.prototype.getId = function (n) {
24
+ var _a;
25
+ if (!n)
26
+ return -1;
27
+ var id = (_a = this.getMeta(n)) === null || _a === void 0 ? void 0 : _a.id;
28
+ return id !== null && id !== void 0 ? id : -1;
29
+ };
30
+ Mirror.prototype.getNode = function (id) {
31
+ return this.idNodeMap.get(id) || null;
32
+ };
33
+ Mirror.prototype.getIds = function () {
34
+ return Array.from(this.idNodeMap.keys());
35
+ };
36
+ Mirror.prototype.getMeta = function (n) {
37
+ return this.nodeMetaMap.get(n) || null;
38
+ };
39
+ Mirror.prototype.removeNodeFromMap = function (n) {
40
+ var _this = this;
41
+ var id = this.getId(n);
42
+ this.idNodeMap["delete"](id);
43
+ if (n.childNodes) {
44
+ n.childNodes.forEach(function (childNode) {
45
+ return _this.removeNodeFromMap(childNode);
46
+ });
47
+ }
48
+ };
49
+ Mirror.prototype.has = function (id) {
50
+ return this.idNodeMap.has(id);
51
+ };
52
+ Mirror.prototype.hasNode = function (node) {
53
+ return this.nodeMetaMap.has(node);
54
+ };
55
+ Mirror.prototype.add = function (n, meta) {
56
+ var id = meta.id;
57
+ this.idNodeMap.set(id, n);
58
+ this.nodeMetaMap.set(n, meta);
59
+ };
60
+ Mirror.prototype.replace = function (id, n) {
61
+ this.idNodeMap.set(id, n);
62
+ };
63
+ Mirror.prototype.reset = function () {
64
+ this.idNodeMap = new Map();
65
+ this.nodeMetaMap = new WeakMap();
66
+ };
67
+ return Mirror;
68
+ }());
69
+ function createMirror() {
70
+ return new Mirror();
71
+ }
72
+ function maskInputValue(_a) {
73
+ var maskInputOptions = _a.maskInputOptions, tagName = _a.tagName, type = _a.type, value = _a.value, maskInputFn = _a.maskInputFn;
74
+ var text = value || '';
75
+ if (maskInputOptions[tagName.toLowerCase()] ||
76
+ maskInputOptions[type]) {
77
+ if (maskInputFn) {
78
+ text = maskInputFn(text);
79
+ }
80
+ else {
81
+ text = '*'.repeat(text.length);
82
+ }
83
+ }
84
+ return text;
85
+ }
86
+ var ORIGINAL_ATTRIBUTE_NAME = '__rrweb_original__';
87
+ function is2DCanvasBlank(canvas) {
88
+ var ctx = canvas.getContext('2d');
89
+ if (!ctx)
90
+ return true;
91
+ var chunkSize = 50;
92
+ for (var x = 0; x < canvas.width; x += chunkSize) {
93
+ for (var y = 0; y < canvas.height; y += chunkSize) {
94
+ var getImageData = ctx.getImageData;
95
+ var originalGetImageData = ORIGINAL_ATTRIBUTE_NAME in getImageData
96
+ ? getImageData[ORIGINAL_ATTRIBUTE_NAME]
97
+ : getImageData;
98
+ var pixelBuffer = new Uint32Array(originalGetImageData.call(ctx, x, y, Math.min(chunkSize, canvas.width - x), Math.min(chunkSize, canvas.height - y)).data.buffer);
99
+ if (pixelBuffer.some(function (pixel) { return pixel !== 0; }))
100
+ return false;
101
+ }
102
+ }
103
+ return true;
104
+ }
105
+ function obfuscateText(text) {
106
+ text = text.replace(/[^ -~]+/g, '');
107
+ text =
108
+ (text === null || text === void 0 ? void 0 : text.split(' ').map(function (word) { return Math.random().toString(20).substr(2, word.length); }).join(' ')) || '';
109
+ return text;
111
110
  }
112
111
 
113
- var _id = 1;
114
- var tagNameRegex = new RegExp('[^a-z0-9-_:]');
115
- var IGNORED_NODE = -2;
116
- function genId() {
117
- return _id++;
118
- }
119
- function getValidTagName(element) {
120
- if (element instanceof HTMLFormElement) {
121
- return 'form';
122
- }
123
- var processedTagName = element.tagName.toLowerCase().trim();
124
- if (tagNameRegex.test(processedTagName)) {
125
- return 'div';
126
- }
127
- return processedTagName;
128
- }
129
- function getCssRulesString(s) {
130
- try {
131
- var rules = s.rules || s.cssRules;
132
- return rules ? Array.from(rules).map(getCssRuleString).join('') : null;
133
- }
134
- catch (error) {
135
- return null;
136
- }
137
- }
138
- function getCssRuleString(rule) {
139
- var cssStringified = rule.cssText;
140
- if (isCSSImportRule(rule)) {
141
- try {
142
- cssStringified = getCssRulesString(rule.styleSheet) || cssStringified;
143
- }
144
- catch (_a) {
145
- }
146
- }
147
- return cssStringified;
148
- }
149
- function isCSSImportRule(rule) {
150
- return 'styleSheet' in rule;
151
- }
152
- function stringifyStyleSheet(sheet) {
153
- return sheet.cssRules
154
- ? Array.from(sheet.cssRules)
155
- .map(function (rule) { return rule.cssText || ''; })
156
- .join('')
157
- : '';
158
- }
159
- function extractOrigin(url) {
160
- var origin = '';
161
- if (url.indexOf('//') > -1) {
162
- origin = url.split('/').slice(0, 3).join('/');
163
- }
164
- else {
165
- origin = url.split('/')[0];
166
- }
167
- origin = origin.split('?')[0];
168
- return origin;
169
- }
170
- var canvasService;
171
- var canvasCtx;
172
- var URL_IN_CSS_REF = /url\((?:(')([^']*)'|(")(.*?)"|([^)]*))\)/gm;
173
- var RELATIVE_PATH = /^(?!www\.|(?:http|ftp)s?:\/\/|[A-Za-z]:\\|\/\/|#).*/;
174
- var DATA_URI = /^(data:)([^,]*),(.*)/i;
175
- function absoluteToStylesheet(cssText, href) {
176
- return (cssText || '').replace(URL_IN_CSS_REF, function (origin, quote1, path1, quote2, path2, path3) {
177
- var filePath = path1 || path2 || path3;
178
- var maybeQuote = quote1 || quote2 || '';
179
- if (!filePath) {
180
- return origin;
181
- }
182
- if (!RELATIVE_PATH.test(filePath)) {
183
- return "url(" + maybeQuote + filePath + maybeQuote + ")";
184
- }
185
- if (DATA_URI.test(filePath)) {
186
- return "url(" + maybeQuote + filePath + maybeQuote + ")";
187
- }
188
- if (filePath[0] === '/') {
189
- return "url(" + maybeQuote + (extractOrigin(href) + filePath) + maybeQuote + ")";
190
- }
191
- var stack = href.split('/');
192
- var parts = filePath.split('/');
193
- stack.pop();
194
- for (var _i = 0, parts_1 = parts; _i < parts_1.length; _i++) {
195
- var part = parts_1[_i];
196
- if (part === '.') {
197
- continue;
198
- }
199
- else if (part === '..') {
200
- stack.pop();
201
- }
202
- else {
203
- stack.push(part);
204
- }
205
- }
206
- return "url(" + maybeQuote + stack.join('/') + maybeQuote + ")";
207
- });
208
- }
209
- var SRCSET_NOT_SPACES = /^[^ \t\n\r\u000c]+/;
210
- var SRCSET_COMMAS_OR_SPACES = /^[, \t\n\r\u000c]+/;
211
- function getAbsoluteSrcsetString(doc, attributeValue) {
212
- if (attributeValue.trim() === '') {
213
- return attributeValue;
214
- }
215
- var pos = 0;
216
- function collectCharacters(regEx) {
217
- var chars;
218
- var match = regEx.exec(attributeValue.substring(pos));
219
- if (match) {
220
- chars = match[0];
221
- pos += chars.length;
222
- return chars;
223
- }
224
- return '';
225
- }
226
- var output = [];
227
- while (true) {
228
- collectCharacters(SRCSET_COMMAS_OR_SPACES);
229
- if (pos >= attributeValue.length) {
230
- break;
231
- }
232
- var url = collectCharacters(SRCSET_NOT_SPACES);
233
- if (url.slice(-1) === ',') {
234
- url = absoluteToDoc(doc, url.substring(0, url.length - 1));
235
- output.push(url);
236
- }
237
- else {
238
- var descriptorsStr = '';
239
- url = absoluteToDoc(doc, url);
240
- var inParens = false;
241
- while (true) {
242
- var c = attributeValue.charAt(pos);
243
- if (c === '') {
244
- output.push((url + descriptorsStr).trim());
245
- break;
246
- }
247
- else if (!inParens) {
248
- if (c === ',') {
249
- pos += 1;
250
- output.push((url + descriptorsStr).trim());
251
- break;
252
- }
253
- else if (c === '(') {
254
- inParens = true;
255
- }
256
- }
257
- else {
258
- if (c === ')') {
259
- inParens = false;
260
- }
261
- }
262
- descriptorsStr += c;
263
- pos += 1;
264
- }
265
- }
266
- }
267
- return output.join(', ');
268
- }
269
- function absoluteToDoc(doc, attributeValue) {
270
- if (!attributeValue || attributeValue.trim() === '') {
271
- return attributeValue;
272
- }
273
- var a = doc.createElement('a');
274
- a.href = attributeValue;
275
- return a.href;
276
- }
277
- function isSVGElement(el) {
278
- return Boolean(el.tagName === 'svg' || el.ownerSVGElement);
279
- }
280
- function getHref() {
281
- var a = document.createElement('a');
282
- a.href = '';
283
- return a.href;
284
- }
285
- function transformAttribute(doc, tagName, name, value) {
286
- if (name === 'src' || (name === 'href' && value)) {
287
- return absoluteToDoc(doc, value);
288
- }
289
- else if (name === 'xlink:href' && value && value[0] !== '#') {
290
- return absoluteToDoc(doc, value);
291
- }
292
- else if (name === 'background' &&
293
- value &&
294
- (tagName === 'table' || tagName === 'td' || tagName === 'th')) {
295
- return absoluteToDoc(doc, value);
296
- }
297
- else if (name === 'srcset' && value) {
298
- return getAbsoluteSrcsetString(doc, value);
299
- }
300
- else if (name === 'style' && value) {
301
- return absoluteToStylesheet(value, getHref());
302
- }
303
- else if (tagName === 'object' && name === 'data' && value) {
304
- return absoluteToDoc(doc, value);
305
- }
306
- else {
307
- return value;
308
- }
309
- }
310
- function _isBlockedElement(element, blockClass, blockSelector) {
311
- if (typeof blockClass === 'string') {
312
- if (element.classList.contains(blockClass)) {
313
- return true;
314
- }
315
- }
316
- else {
317
- for (var eIndex = element.classList.length; eIndex--;) {
318
- var className = element.classList[eIndex];
319
- if (blockClass.test(className)) {
320
- return true;
321
- }
322
- }
323
- }
324
- if (blockSelector) {
325
- return element.matches(blockSelector);
326
- }
327
- return false;
328
- }
329
- function classMatchesRegex(node, regex, checkAncestors) {
330
- if (!node)
331
- return false;
332
- if (node.nodeType !== node.ELEMENT_NODE) {
333
- if (!checkAncestors)
334
- return false;
335
- return classMatchesRegex(node.parentNode, regex, checkAncestors);
336
- }
337
- for (var eIndex = node.classList.length; eIndex--;) {
338
- var className = node.classList[eIndex];
339
- if (regex.test(className)) {
340
- return true;
341
- }
342
- }
343
- if (!checkAncestors)
344
- return false;
345
- return classMatchesRegex(node.parentNode, regex, checkAncestors);
346
- }
347
- function needMaskingText(node, maskTextClass, maskTextSelector) {
348
- var el = node.nodeType === node.ELEMENT_NODE
349
- ? node
350
- : node.parentElement;
351
- if (el === null)
352
- return false;
353
- if (typeof maskTextClass === 'string') {
354
- if (el.classList.contains(maskTextClass))
355
- return true;
356
- if (el.closest("." + maskTextClass))
357
- return true;
358
- }
359
- else {
360
- if (classMatchesRegex(el, maskTextClass, true))
361
- return true;
362
- }
363
- if (maskTextSelector) {
364
- if (el.matches(maskTextSelector))
365
- return true;
366
- if (el.closest(maskTextSelector))
367
- return true;
368
- }
369
- return false;
370
- }
371
- function onceIframeLoaded(iframeEl, listener, iframeLoadTimeout) {
372
- var win = iframeEl.contentWindow;
373
- if (!win) {
374
- return;
375
- }
376
- var fired = false;
377
- var readyState;
378
- try {
379
- readyState = win.document.readyState;
380
- }
381
- catch (error) {
382
- return;
383
- }
384
- if (readyState !== 'complete') {
385
- var timer_1 = setTimeout(function () {
386
- if (!fired) {
387
- listener();
388
- fired = true;
389
- }
390
- }, iframeLoadTimeout);
391
- iframeEl.addEventListener('load', function () {
392
- clearTimeout(timer_1);
393
- fired = true;
394
- listener();
395
- });
396
- return;
397
- }
398
- var blankUrl = 'about:blank';
399
- if (win.location.href !== blankUrl ||
400
- iframeEl.src === blankUrl ||
401
- iframeEl.src === '') {
402
- setTimeout(listener, 0);
403
- return;
404
- }
405
- iframeEl.addEventListener('load', listener);
406
- }
407
- function isStylesheetLoaded(link) {
408
- if (!link.getAttribute('href'))
409
- return true;
410
- return link.sheet !== null;
411
- }
412
- function onceStylesheetLoaded(link, listener, iframeLoadTimeout) {
413
- var fired = false;
414
- var styleSheetLoaded;
415
- try {
416
- styleSheetLoaded = link.sheet;
417
- }
418
- catch (error) {
419
- return;
420
- }
421
- if (styleSheetLoaded)
422
- return;
423
- var timer = setTimeout(function () {
424
- if (!fired) {
425
- listener();
426
- fired = true;
427
- }
428
- }, iframeLoadTimeout);
429
- link.addEventListener('load', function () {
430
- clearTimeout(timer);
431
- fired = true;
432
- listener();
433
- });
434
- }
435
- function serializeNode(n, options) {
436
- 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;
437
- var rootId = getRootId(doc, mirror);
438
- switch (n.nodeType) {
439
- case n.DOCUMENT_NODE:
440
- if (n.compatMode !== 'CSS1Compat') {
441
- return {
442
- type: NodeType.Document,
443
- childNodes: [],
444
- compatMode: n.compatMode,
445
- rootId: rootId
446
- };
447
- }
448
- else {
449
- return {
450
- type: NodeType.Document,
451
- childNodes: [],
452
- rootId: rootId
453
- };
454
- }
455
- case n.DOCUMENT_TYPE_NODE:
456
- return {
457
- type: NodeType.DocumentType,
458
- name: n.name,
459
- publicId: n.publicId,
460
- systemId: n.systemId,
461
- rootId: rootId
462
- };
463
- case n.ELEMENT_NODE:
464
- return serializeElementNode(n, {
465
- doc: doc,
466
- blockClass: blockClass,
467
- blockSelector: blockSelector,
468
- inlineStylesheet: inlineStylesheet,
469
- maskInputOptions: maskInputOptions,
470
- maskInputFn: maskInputFn,
471
- dataURLOptions: dataURLOptions,
472
- inlineImages: inlineImages,
473
- recordCanvas: recordCanvas,
474
- keepIframeSrcFn: keepIframeSrcFn,
475
- newlyAddedElement: newlyAddedElement,
476
- enableStrictPrivacy: enableStrictPrivacy,
477
- rootId: rootId
478
- });
479
- case n.TEXT_NODE:
480
- return serializeTextNode(n, {
481
- maskTextClass: maskTextClass,
482
- maskTextSelector: maskTextSelector,
483
- maskTextFn: maskTextFn,
484
- enableStrictPrivacy: enableStrictPrivacy,
485
- rootId: rootId
486
- });
487
- case n.CDATA_SECTION_NODE:
488
- return {
489
- type: NodeType.CDATA,
490
- textContent: '',
491
- rootId: rootId
492
- };
493
- case n.COMMENT_NODE:
494
- return {
495
- type: NodeType.Comment,
496
- textContent: n.textContent || '',
497
- rootId: rootId
498
- };
499
- default:
500
- return false;
501
- }
502
- }
503
- function getRootId(doc, mirror) {
504
- if (!mirror.hasNode(doc))
505
- return undefined;
506
- var docId = mirror.getId(doc);
507
- return docId === 1 ? undefined : docId;
508
- }
509
- function serializeTextNode(n, options) {
510
- var _a;
511
- var maskTextClass = options.maskTextClass, maskTextSelector = options.maskTextSelector, maskTextFn = options.maskTextFn, enableStrictPrivacy = options.enableStrictPrivacy, rootId = options.rootId;
512
- var parentTagName = n.parentNode && n.parentNode.tagName;
513
- var textContent = n.textContent;
514
- var isStyle = parentTagName === 'STYLE' ? true : undefined;
515
- var isScript = parentTagName === 'SCRIPT' ? true : undefined;
516
- var textContentHandled = false;
517
- if (isStyle && textContent) {
518
- try {
519
- if (n.nextSibling || n.previousSibling) {
520
- }
521
- else if ((_a = n.parentNode.sheet) === null || _a === void 0 ? void 0 : _a.cssRules) {
522
- textContent = stringifyStyleSheet(n.parentNode.sheet);
523
- }
524
- }
525
- catch (err) {
526
- console.warn("Cannot get CSS styles from text's parentNode. Error: " + err, n);
527
- }
528
- textContent = absoluteToStylesheet(textContent, getHref());
529
- textContentHandled = true;
530
- }
531
- if (isScript) {
532
- textContent = 'SCRIPT_PLACEHOLDER';
533
- textContentHandled = true;
534
- }
535
- else if (parentTagName === 'NOSCRIPT') {
536
- textContent = '';
537
- textContentHandled = true;
538
- }
539
- if (!isStyle &&
540
- !isScript &&
541
- textContent &&
542
- needMaskingText(n, maskTextClass, maskTextSelector)) {
543
- textContent = maskTextFn
544
- ? maskTextFn(textContent)
545
- : textContent.replace(/[\S]/g, '*');
546
- }
547
- if (enableStrictPrivacy && !textContentHandled && parentTagName) {
548
- var IGNORE_TAG_NAMES = new Set([
549
- 'HEAD',
550
- 'TITLE',
551
- 'STYLE',
552
- 'SCRIPT',
553
- 'HTML',
554
- 'BODY',
555
- 'NOSCRIPT',
556
- ]);
557
- if (!IGNORE_TAG_NAMES.has(parentTagName) && textContent) {
558
- textContent = obfuscateText(textContent);
559
- }
560
- }
561
- return {
562
- type: NodeType.Text,
563
- textContent: textContent || '',
564
- isStyle: isStyle,
565
- rootId: rootId
566
- };
567
- }
568
- function serializeElementNode(n, options) {
569
- 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;
570
- var needBlock = _isBlockedElement(n, blockClass, blockSelector);
571
- var tagName = getValidTagName(n);
572
- var attributes = {};
573
- var len = n.attributes.length;
574
- for (var i = 0; i < len; i++) {
575
- var attr = n.attributes[i];
576
- attributes[attr.name] = transformAttribute(doc, tagName, attr.name, attr.value);
577
- }
578
- if (tagName === 'link' && inlineStylesheet) {
579
- var stylesheet = Array.from(doc.styleSheets).find(function (s) {
580
- return s.href === n.href;
581
- });
582
- var cssText = null;
583
- if (stylesheet) {
584
- cssText = getCssRulesString(stylesheet);
585
- }
586
- if (cssText) {
587
- delete attributes.rel;
588
- delete attributes.href;
589
- attributes._cssText = absoluteToStylesheet(cssText, stylesheet.href);
590
- }
591
- }
592
- if (tagName === 'style' &&
593
- n.sheet &&
594
- !(n.innerText || n.textContent || '').trim().length) {
595
- var cssText = getCssRulesString(n.sheet);
596
- if (cssText) {
597
- attributes._cssText = absoluteToStylesheet(cssText, getHref());
598
- }
599
- }
600
- if (tagName === 'input' || tagName === 'textarea' || tagName === 'select') {
601
- var value = n.value;
602
- if (attributes.type !== 'radio' &&
603
- attributes.type !== 'checkbox' &&
604
- attributes.type !== 'submit' &&
605
- attributes.type !== 'button' &&
606
- value) {
607
- attributes.value = maskInputValue({
608
- type: attributes.type,
609
- tagName: tagName,
610
- value: value,
611
- maskInputOptions: maskInputOptions,
612
- maskInputFn: maskInputFn
613
- });
614
- }
615
- else if (n.checked) {
616
- attributes.checked = n.checked;
617
- }
618
- }
619
- if (tagName === 'option') {
620
- if (n.selected && !maskInputOptions['select']) {
621
- attributes.selected = true;
622
- }
623
- else {
624
- delete attributes.selected;
625
- }
626
- }
627
- if (tagName === 'canvas' && recordCanvas) {
628
- if (n.__context === '2d') {
629
- if (!is2DCanvasBlank(n)) {
630
- attributes.rr_dataURL = n.toDataURL(dataURLOptions.type, dataURLOptions.quality);
631
- }
632
- }
633
- else if (!('__context' in n)) {
634
- var canvasDataURL = n.toDataURL(dataURLOptions.type, dataURLOptions.quality);
635
- var blankCanvas = document.createElement('canvas');
636
- blankCanvas.width = n.width;
637
- blankCanvas.height = n.height;
638
- var blankCanvasDataURL = blankCanvas.toDataURL(dataURLOptions.type, dataURLOptions.quality);
639
- if (canvasDataURL !== blankCanvasDataURL) {
640
- attributes.rr_dataURL = canvasDataURL;
641
- }
642
- }
643
- }
644
- if (tagName === 'img' && inlineImages) {
645
- if (!canvasService) {
646
- canvasService = doc.createElement('canvas');
647
- canvasCtx = canvasService.getContext('2d');
648
- }
649
- var image_1 = n;
650
- var oldValue_1 = image_1.crossOrigin;
651
- image_1.crossOrigin = 'anonymous';
652
- var recordInlineImage = function () {
653
- try {
654
- canvasService.width = image_1.naturalWidth;
655
- canvasService.height = image_1.naturalHeight;
656
- canvasCtx.drawImage(image_1, 0, 0);
657
- attributes.rr_dataURL = canvasService.toDataURL(dataURLOptions.type, dataURLOptions.quality);
658
- }
659
- catch (err) {
660
- console.warn("Cannot inline img src=" + image_1.currentSrc + "! Error: " + err);
661
- }
662
- oldValue_1
663
- ? (attributes.crossOrigin = oldValue_1)
664
- : image_1.removeAttribute('crossorigin');
665
- };
666
- if (image_1.complete && image_1.naturalWidth !== 0)
667
- recordInlineImage();
668
- else
669
- image_1.onload = recordInlineImage;
670
- }
671
- if (tagName === 'audio' || tagName === 'video') {
672
- attributes.rr_mediaState = n.paused
673
- ? 'paused'
674
- : 'played';
675
- attributes.rr_mediaCurrentTime = n.currentTime;
676
- }
677
- if (!newlyAddedElement) {
678
- if (n.scrollLeft) {
679
- attributes.rr_scrollLeft = n.scrollLeft;
680
- }
681
- if (n.scrollTop) {
682
- attributes.rr_scrollTop = n.scrollTop;
683
- }
684
- }
685
- if (needBlock || (tagName === 'img' && enableStrictPrivacy)) {
686
- var _d = n.getBoundingClientRect(), width = _d.width, height = _d.height;
687
- attributes = {
688
- "class": attributes["class"],
689
- rr_width: width + "px",
690
- rr_height: height + "px"
691
- };
692
- needBlock = true;
693
- }
694
- if (tagName === 'iframe' && !keepIframeSrcFn(attributes.src)) {
695
- if (!n.contentDocument) {
696
- attributes.rr_src = attributes.src;
697
- }
698
- delete attributes.src;
699
- }
700
- return {
701
- type: NodeType.Element,
702
- tagName: tagName,
703
- attributes: attributes,
704
- childNodes: [],
705
- isSVG: isSVGElement(n) || undefined,
706
- needBlock: needBlock,
707
- rootId: rootId
708
- };
709
- }
710
- function lowerIfExists(maybeAttr) {
711
- if (maybeAttr === undefined) {
712
- return '';
713
- }
714
- else {
715
- return maybeAttr.toLowerCase();
716
- }
717
- }
718
- function slimDOMExcluded(sn, slimDOMOptions) {
719
- if (slimDOMOptions.comment && sn.type === NodeType.Comment) {
720
- return true;
721
- }
722
- else if (sn.type === NodeType.Element) {
723
- if (slimDOMOptions.script &&
724
- (sn.tagName === 'script' ||
725
- (sn.tagName === 'link' &&
726
- sn.attributes.rel === 'preload' &&
727
- sn.attributes.as === 'script') ||
728
- (sn.tagName === 'link' &&
729
- sn.attributes.rel === 'prefetch' &&
730
- typeof sn.attributes.href === 'string' &&
731
- sn.attributes.href.endsWith('.js')))) {
732
- return true;
733
- }
734
- else if (slimDOMOptions.headFavicon &&
735
- ((sn.tagName === 'link' && sn.attributes.rel === 'shortcut icon') ||
736
- (sn.tagName === 'meta' &&
737
- (lowerIfExists(sn.attributes.name).match(/^msapplication-tile(image|color)$/) ||
738
- lowerIfExists(sn.attributes.name) === 'application-name' ||
739
- lowerIfExists(sn.attributes.rel) === 'icon' ||
740
- lowerIfExists(sn.attributes.rel) === 'apple-touch-icon' ||
741
- lowerIfExists(sn.attributes.rel) === 'shortcut icon')))) {
742
- return true;
743
- }
744
- else if (sn.tagName === 'meta') {
745
- if (slimDOMOptions.headMetaDescKeywords &&
746
- lowerIfExists(sn.attributes.name).match(/^description|keywords$/)) {
747
- return true;
748
- }
749
- else if (slimDOMOptions.headMetaSocial &&
750
- (lowerIfExists(sn.attributes.property).match(/^(og|twitter|fb):/) ||
751
- lowerIfExists(sn.attributes.name).match(/^(og|twitter):/) ||
752
- lowerIfExists(sn.attributes.name) === 'pinterest')) {
753
- return true;
754
- }
755
- else if (slimDOMOptions.headMetaRobots &&
756
- (lowerIfExists(sn.attributes.name) === 'robots' ||
757
- lowerIfExists(sn.attributes.name) === 'googlebot' ||
758
- lowerIfExists(sn.attributes.name) === 'bingbot')) {
759
- return true;
760
- }
761
- else if (slimDOMOptions.headMetaHttpEquiv &&
762
- sn.attributes['http-equiv'] !== undefined) {
763
- return true;
764
- }
765
- else if (slimDOMOptions.headMetaAuthorship &&
766
- (lowerIfExists(sn.attributes.name) === 'author' ||
767
- lowerIfExists(sn.attributes.name) === 'generator' ||
768
- lowerIfExists(sn.attributes.name) === 'framework' ||
769
- lowerIfExists(sn.attributes.name) === 'publisher' ||
770
- lowerIfExists(sn.attributes.name) === 'progid' ||
771
- lowerIfExists(sn.attributes.property).match(/^article:/) ||
772
- lowerIfExists(sn.attributes.property).match(/^product:/))) {
773
- return true;
774
- }
775
- else if (slimDOMOptions.headMetaVerification &&
776
- (lowerIfExists(sn.attributes.name) === 'google-site-verification' ||
777
- lowerIfExists(sn.attributes.name) === 'yandex-verification' ||
778
- lowerIfExists(sn.attributes.name) === 'csrf-token' ||
779
- lowerIfExists(sn.attributes.name) === 'p:domain_verify' ||
780
- lowerIfExists(sn.attributes.name) === 'verify-v1' ||
781
- lowerIfExists(sn.attributes.name) === 'verification' ||
782
- lowerIfExists(sn.attributes.name) === 'shopify-checkout-api-token')) {
783
- return true;
784
- }
785
- }
786
- }
787
- return false;
788
- }
789
- function serializeNodeWithId(n, options) {
790
- 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;
791
- var _l = options.preserveWhiteSpace, preserveWhiteSpace = _l === void 0 ? true : _l;
792
- var _serializedNode = serializeNode(n, {
793
- doc: doc,
794
- mirror: mirror,
795
- blockClass: blockClass,
796
- blockSelector: blockSelector,
797
- maskTextClass: maskTextClass,
798
- maskTextSelector: maskTextSelector,
799
- inlineStylesheet: inlineStylesheet,
800
- maskInputOptions: maskInputOptions,
801
- maskTextFn: maskTextFn,
802
- maskInputFn: maskInputFn,
803
- dataURLOptions: dataURLOptions,
804
- inlineImages: inlineImages,
805
- recordCanvas: recordCanvas,
806
- keepIframeSrcFn: keepIframeSrcFn,
807
- newlyAddedElement: newlyAddedElement,
808
- enableStrictPrivacy: enableStrictPrivacy
809
- });
810
- if (!_serializedNode) {
811
- console.warn(n, 'not serialized');
812
- return null;
813
- }
814
- var id;
815
- if (mirror.hasNode(n)) {
816
- id = mirror.getId(n);
817
- }
818
- else if (slimDOMExcluded(_serializedNode, slimDOMOptions) ||
819
- (!preserveWhiteSpace &&
820
- _serializedNode.type === NodeType.Text &&
821
- !_serializedNode.isStyle &&
822
- !_serializedNode.textContent.replace(/^\s+|\s+$/gm, '').length)) {
823
- id = IGNORED_NODE;
824
- }
825
- else {
826
- id = genId();
827
- }
828
- if (id === IGNORED_NODE) {
829
- return null;
830
- }
831
- var serializedNode = Object.assign(_serializedNode, { id: id });
832
- mirror.add(n, serializedNode);
833
- if (onSerialize) {
834
- onSerialize(n);
835
- }
836
- var recordChild = !skipChild;
837
- if (serializedNode.type === NodeType.Element) {
838
- recordChild = recordChild && !serializedNode.needBlock;
839
- if (serializedNode.needBlock && serializedNode.tagName === 'img') {
840
- var clone = n.cloneNode();
841
- clone.src = '';
842
- mirror.add(clone, serializedNode);
843
- }
844
- delete serializedNode.needBlock;
845
- if (n.shadowRoot)
846
- serializedNode.isShadowHost = true;
847
- }
848
- if ((serializedNode.type === NodeType.Document ||
849
- serializedNode.type === NodeType.Element) &&
850
- recordChild) {
851
- if (slimDOMOptions.headWhitespace &&
852
- serializedNode.type === NodeType.Element &&
853
- serializedNode.tagName === 'head') {
854
- preserveWhiteSpace = false;
855
- }
856
- var bypassOptions = {
857
- doc: doc,
858
- mirror: mirror,
859
- blockClass: blockClass,
860
- blockSelector: blockSelector,
861
- maskTextClass: maskTextClass,
862
- maskTextSelector: maskTextSelector,
863
- skipChild: skipChild,
864
- inlineStylesheet: inlineStylesheet,
865
- maskInputOptions: maskInputOptions,
866
- maskTextFn: maskTextFn,
867
- maskInputFn: maskInputFn,
868
- slimDOMOptions: slimDOMOptions,
869
- dataURLOptions: dataURLOptions,
870
- inlineImages: inlineImages,
871
- recordCanvas: recordCanvas,
872
- preserveWhiteSpace: preserveWhiteSpace,
873
- onSerialize: onSerialize,
874
- onIframeLoad: onIframeLoad,
875
- iframeLoadTimeout: iframeLoadTimeout,
876
- onStylesheetLoad: onStylesheetLoad,
877
- stylesheetLoadTimeout: stylesheetLoadTimeout,
878
- keepIframeSrcFn: keepIframeSrcFn,
879
- enableStrictPrivacy: enableStrictPrivacy
880
- };
881
- for (var _i = 0, _m = Array.from(n.childNodes); _i < _m.length; _i++) {
882
- var childN = _m[_i];
883
- var serializedChildNode = serializeNodeWithId(childN, bypassOptions);
884
- if (serializedChildNode) {
885
- serializedNode.childNodes.push(serializedChildNode);
886
- }
887
- }
888
- if (isElement(n) && n.shadowRoot) {
889
- for (var _o = 0, _p = Array.from(n.shadowRoot.childNodes); _o < _p.length; _o++) {
890
- var childN = _p[_o];
891
- var serializedChildNode = serializeNodeWithId(childN, bypassOptions);
892
- if (serializedChildNode) {
893
- serializedChildNode.isShadow = true;
894
- serializedNode.childNodes.push(serializedChildNode);
895
- }
896
- }
897
- }
898
- }
899
- if (n.parentNode && isShadowRoot(n.parentNode)) {
900
- serializedNode.isShadow = true;
901
- }
902
- if (serializedNode.type === NodeType.Element &&
903
- serializedNode.tagName === 'iframe') {
904
- onceIframeLoaded(n, function () {
905
- var iframeDoc = n.contentDocument;
906
- if (iframeDoc && onIframeLoad) {
907
- var serializedIframeNode = serializeNodeWithId(iframeDoc, {
908
- doc: iframeDoc,
909
- mirror: mirror,
910
- blockClass: blockClass,
911
- blockSelector: blockSelector,
912
- maskTextClass: maskTextClass,
913
- maskTextSelector: maskTextSelector,
914
- skipChild: false,
915
- inlineStylesheet: inlineStylesheet,
916
- maskInputOptions: maskInputOptions,
917
- maskTextFn: maskTextFn,
918
- maskInputFn: maskInputFn,
919
- slimDOMOptions: slimDOMOptions,
920
- dataURLOptions: dataURLOptions,
921
- inlineImages: inlineImages,
922
- recordCanvas: recordCanvas,
923
- preserveWhiteSpace: preserveWhiteSpace,
924
- onSerialize: onSerialize,
925
- onIframeLoad: onIframeLoad,
926
- iframeLoadTimeout: iframeLoadTimeout,
927
- onStylesheetLoad: onStylesheetLoad,
928
- stylesheetLoadTimeout: stylesheetLoadTimeout,
929
- keepIframeSrcFn: keepIframeSrcFn,
930
- enableStrictPrivacy: enableStrictPrivacy
931
- });
932
- if (serializedIframeNode) {
933
- onIframeLoad(n, serializedIframeNode);
934
- }
935
- }
936
- }, iframeLoadTimeout);
937
- }
938
- if (serializedNode.type === NodeType.Element &&
939
- serializedNode.tagName === 'link' &&
940
- serializedNode.attributes.rel === 'stylesheet') {
941
- onceStylesheetLoaded(n, function () {
942
- if (onStylesheetLoad) {
943
- var serializedLinkNode = serializeNodeWithId(n, {
944
- doc: doc,
945
- mirror: mirror,
946
- blockClass: blockClass,
947
- blockSelector: blockSelector,
948
- maskTextClass: maskTextClass,
949
- maskTextSelector: maskTextSelector,
950
- skipChild: false,
951
- inlineStylesheet: inlineStylesheet,
952
- maskInputOptions: maskInputOptions,
953
- maskTextFn: maskTextFn,
954
- maskInputFn: maskInputFn,
955
- slimDOMOptions: slimDOMOptions,
956
- dataURLOptions: dataURLOptions,
957
- inlineImages: inlineImages,
958
- recordCanvas: recordCanvas,
959
- preserveWhiteSpace: preserveWhiteSpace,
960
- onSerialize: onSerialize,
961
- onIframeLoad: onIframeLoad,
962
- iframeLoadTimeout: iframeLoadTimeout,
963
- onStylesheetLoad: onStylesheetLoad,
964
- stylesheetLoadTimeout: stylesheetLoadTimeout,
965
- keepIframeSrcFn: keepIframeSrcFn,
966
- enableStrictPrivacy: enableStrictPrivacy
967
- });
968
- if (serializedLinkNode) {
969
- onStylesheetLoad(n, serializedLinkNode);
970
- }
971
- }
972
- }, stylesheetLoadTimeout);
973
- if (isStylesheetLoaded(n) === false)
974
- return null;
975
- }
976
- return serializedNode;
977
- }
978
- function snapshot(n, options) {
979
- var _a = options || {}, _b = _a.mirror, mirror = _b === void 0 ? new Mirror() : _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;
980
- var maskInputOptions = maskAllInputs === true
981
- ? {
982
- color: true,
983
- date: true,
984
- 'datetime-local': true,
985
- email: true,
986
- month: true,
987
- number: true,
988
- range: true,
989
- search: true,
990
- tel: true,
991
- text: true,
992
- time: true,
993
- url: true,
994
- week: true,
995
- textarea: true,
996
- select: true,
997
- password: true
998
- }
999
- : maskAllInputs === false
1000
- ? {
1001
- password: true
1002
- }
1003
- : maskAllInputs;
1004
- var slimDOMOptions = slimDOM === true || slimDOM === 'all'
1005
- ?
1006
- {
1007
- script: true,
1008
- comment: true,
1009
- headFavicon: true,
1010
- headWhitespace: true,
1011
- headMetaDescKeywords: slimDOM === 'all',
1012
- headMetaSocial: true,
1013
- headMetaRobots: true,
1014
- headMetaHttpEquiv: true,
1015
- headMetaAuthorship: true,
1016
- headMetaVerification: true
1017
- }
1018
- : slimDOM === false
1019
- ? {}
1020
- : slimDOM;
1021
- return serializeNodeWithId(n, {
1022
- doc: n,
1023
- mirror: mirror,
1024
- blockClass: blockClass,
1025
- blockSelector: blockSelector,
1026
- maskTextClass: maskTextClass,
1027
- maskTextSelector: maskTextSelector,
1028
- skipChild: false,
1029
- inlineStylesheet: inlineStylesheet,
1030
- maskInputOptions: maskInputOptions,
1031
- maskTextFn: maskTextFn,
1032
- maskInputFn: maskInputFn,
1033
- slimDOMOptions: slimDOMOptions,
1034
- dataURLOptions: dataURLOptions,
1035
- inlineImages: inlineImages,
1036
- recordCanvas: recordCanvas,
1037
- preserveWhiteSpace: preserveWhiteSpace,
1038
- onSerialize: onSerialize,
1039
- onIframeLoad: onIframeLoad,
1040
- iframeLoadTimeout: iframeLoadTimeout,
1041
- onStylesheetLoad: onStylesheetLoad,
1042
- stylesheetLoadTimeout: stylesheetLoadTimeout,
1043
- keepIframeSrcFn: keepIframeSrcFn,
1044
- newlyAddedElement: false,
1045
- enableStrictPrivacy: enableStrictPrivacy
1046
- });
1047
- }
112
+ var _id = 1;
113
+ var tagNameRegex = new RegExp('[^a-z0-9-_:]');
114
+ var IGNORED_NODE = -2;
115
+ function genId() {
116
+ return _id++;
117
+ }
118
+ function getValidTagName(element) {
119
+ if (element instanceof HTMLFormElement) {
120
+ return 'form';
121
+ }
122
+ var processedTagName = element.tagName.toLowerCase().trim();
123
+ if (tagNameRegex.test(processedTagName)) {
124
+ return 'div';
125
+ }
126
+ return processedTagName;
127
+ }
128
+ function getCssRulesString(s) {
129
+ try {
130
+ var rules = s.rules || s.cssRules;
131
+ return rules ? Array.from(rules).map(getCssRuleString).join('') : null;
132
+ }
133
+ catch (error) {
134
+ return null;
135
+ }
136
+ }
137
+ function getCssRuleString(rule) {
138
+ var cssStringified = rule.cssText;
139
+ if (isCSSImportRule(rule)) {
140
+ try {
141
+ cssStringified = getCssRulesString(rule.styleSheet) || cssStringified;
142
+ }
143
+ catch (_a) {
144
+ }
145
+ }
146
+ return cssStringified;
147
+ }
148
+ function isCSSImportRule(rule) {
149
+ return 'styleSheet' in rule;
150
+ }
151
+ function stringifyStyleSheet(sheet) {
152
+ return sheet.cssRules
153
+ ? Array.from(sheet.cssRules)
154
+ .map(function (rule) { return rule.cssText || ''; })
155
+ .join('')
156
+ : '';
157
+ }
158
+ function extractOrigin(url) {
159
+ var origin = '';
160
+ if (url.indexOf('//') > -1) {
161
+ origin = url.split('/').slice(0, 3).join('/');
162
+ }
163
+ else {
164
+ origin = url.split('/')[0];
165
+ }
166
+ origin = origin.split('?')[0];
167
+ return origin;
168
+ }
169
+ var canvasService;
170
+ var canvasCtx;
171
+ var URL_IN_CSS_REF = /url\((?:(')([^']*)'|(")(.*?)"|([^)]*))\)/gm;
172
+ var RELATIVE_PATH = /^(?!www\.|(?:http|ftp)s?:\/\/|[A-Za-z]:\\|\/\/|#).*/;
173
+ var DATA_URI = /^(data:)([^,]*),(.*)/i;
174
+ function absoluteToStylesheet(cssText, href) {
175
+ return (cssText || '').replace(URL_IN_CSS_REF, function (origin, quote1, path1, quote2, path2, path3) {
176
+ var filePath = path1 || path2 || path3;
177
+ var maybeQuote = quote1 || quote2 || '';
178
+ if (!filePath) {
179
+ return origin;
180
+ }
181
+ if (!RELATIVE_PATH.test(filePath)) {
182
+ return "url(".concat(maybeQuote).concat(filePath).concat(maybeQuote, ")");
183
+ }
184
+ if (DATA_URI.test(filePath)) {
185
+ return "url(".concat(maybeQuote).concat(filePath).concat(maybeQuote, ")");
186
+ }
187
+ if (filePath[0] === '/') {
188
+ return "url(".concat(maybeQuote).concat(extractOrigin(href) + filePath).concat(maybeQuote, ")");
189
+ }
190
+ var stack = href.split('/');
191
+ var parts = filePath.split('/');
192
+ stack.pop();
193
+ for (var _i = 0, parts_1 = parts; _i < parts_1.length; _i++) {
194
+ var part = parts_1[_i];
195
+ if (part === '.') {
196
+ continue;
197
+ }
198
+ else if (part === '..') {
199
+ stack.pop();
200
+ }
201
+ else {
202
+ stack.push(part);
203
+ }
204
+ }
205
+ return "url(".concat(maybeQuote).concat(stack.join('/')).concat(maybeQuote, ")");
206
+ });
207
+ }
208
+ var SRCSET_NOT_SPACES = /^[^ \t\n\r\u000c]+/;
209
+ var SRCSET_COMMAS_OR_SPACES = /^[, \t\n\r\u000c]+/;
210
+ function getAbsoluteSrcsetString(doc, attributeValue) {
211
+ if (attributeValue.trim() === '') {
212
+ return attributeValue;
213
+ }
214
+ var pos = 0;
215
+ function collectCharacters(regEx) {
216
+ var chars;
217
+ var match = regEx.exec(attributeValue.substring(pos));
218
+ if (match) {
219
+ chars = match[0];
220
+ pos += chars.length;
221
+ return chars;
222
+ }
223
+ return '';
224
+ }
225
+ var output = [];
226
+ while (true) {
227
+ collectCharacters(SRCSET_COMMAS_OR_SPACES);
228
+ if (pos >= attributeValue.length) {
229
+ break;
230
+ }
231
+ var url = collectCharacters(SRCSET_NOT_SPACES);
232
+ if (url.slice(-1) === ',') {
233
+ url = absoluteToDoc(doc, url.substring(0, url.length - 1));
234
+ output.push(url);
235
+ }
236
+ else {
237
+ var descriptorsStr = '';
238
+ url = absoluteToDoc(doc, url);
239
+ var inParens = false;
240
+ while (true) {
241
+ var c = attributeValue.charAt(pos);
242
+ if (c === '') {
243
+ output.push((url + descriptorsStr).trim());
244
+ break;
245
+ }
246
+ else if (!inParens) {
247
+ if (c === ',') {
248
+ pos += 1;
249
+ output.push((url + descriptorsStr).trim());
250
+ break;
251
+ }
252
+ else if (c === '(') {
253
+ inParens = true;
254
+ }
255
+ }
256
+ else {
257
+ if (c === ')') {
258
+ inParens = false;
259
+ }
260
+ }
261
+ descriptorsStr += c;
262
+ pos += 1;
263
+ }
264
+ }
265
+ }
266
+ return output.join(', ');
267
+ }
268
+ function absoluteToDoc(doc, attributeValue) {
269
+ if (!attributeValue || attributeValue.trim() === '') {
270
+ return attributeValue;
271
+ }
272
+ var a = doc.createElement('a');
273
+ a.href = attributeValue;
274
+ return a.href;
275
+ }
276
+ function isSVGElement(el) {
277
+ return Boolean(el.tagName === 'svg' || el.ownerSVGElement);
278
+ }
279
+ function getHref() {
280
+ var a = document.createElement('a');
281
+ a.href = '';
282
+ return a.href;
283
+ }
284
+ function transformAttribute(doc, tagName, name, value) {
285
+ if (name === 'src' || (name === 'href' && value)) {
286
+ return absoluteToDoc(doc, value);
287
+ }
288
+ else if (name === 'xlink:href' && value && value[0] !== '#') {
289
+ return absoluteToDoc(doc, value);
290
+ }
291
+ else if (name === 'background' &&
292
+ value &&
293
+ (tagName === 'table' || tagName === 'td' || tagName === 'th')) {
294
+ return absoluteToDoc(doc, value);
295
+ }
296
+ else if (name === 'srcset' && value) {
297
+ return getAbsoluteSrcsetString(doc, value);
298
+ }
299
+ else if (name === 'style' && value) {
300
+ return absoluteToStylesheet(value, getHref());
301
+ }
302
+ else if (tagName === 'object' && name === 'data' && value) {
303
+ return absoluteToDoc(doc, value);
304
+ }
305
+ else {
306
+ return value;
307
+ }
308
+ }
309
+ function _isBlockedElement(element, blockClass, blockSelector) {
310
+ if (typeof blockClass === 'string') {
311
+ if (element.classList.contains(blockClass)) {
312
+ return true;
313
+ }
314
+ }
315
+ else {
316
+ for (var eIndex = element.classList.length; eIndex--;) {
317
+ var className = element.classList[eIndex];
318
+ if (blockClass.test(className)) {
319
+ return true;
320
+ }
321
+ }
322
+ }
323
+ if (blockSelector) {
324
+ return element.matches(blockSelector);
325
+ }
326
+ return false;
327
+ }
328
+ function classMatchesRegex(node, regex, checkAncestors) {
329
+ if (!node)
330
+ return false;
331
+ if (node.nodeType !== node.ELEMENT_NODE) {
332
+ if (!checkAncestors)
333
+ return false;
334
+ return classMatchesRegex(node.parentNode, regex, checkAncestors);
335
+ }
336
+ for (var eIndex = node.classList.length; eIndex--;) {
337
+ var className = node.classList[eIndex];
338
+ if (regex.test(className)) {
339
+ return true;
340
+ }
341
+ }
342
+ if (!checkAncestors)
343
+ return false;
344
+ return classMatchesRegex(node.parentNode, regex, checkAncestors);
345
+ }
346
+ function needMaskingText(node, maskTextClass, maskTextSelector) {
347
+ var el = node.nodeType === node.ELEMENT_NODE
348
+ ? node
349
+ : node.parentElement;
350
+ if (el === null)
351
+ return false;
352
+ if (typeof maskTextClass === 'string') {
353
+ if (el.classList.contains(maskTextClass))
354
+ return true;
355
+ if (el.closest(".".concat(maskTextClass)))
356
+ return true;
357
+ }
358
+ else {
359
+ if (classMatchesRegex(el, maskTextClass, true))
360
+ return true;
361
+ }
362
+ if (maskTextSelector) {
363
+ if (el.matches(maskTextSelector))
364
+ return true;
365
+ if (el.closest(maskTextSelector))
366
+ return true;
367
+ }
368
+ return false;
369
+ }
370
+ function onceIframeLoaded(iframeEl, listener, iframeLoadTimeout) {
371
+ var win = iframeEl.contentWindow;
372
+ if (!win) {
373
+ return;
374
+ }
375
+ var fired = false;
376
+ var readyState;
377
+ try {
378
+ readyState = win.document.readyState;
379
+ }
380
+ catch (error) {
381
+ return;
382
+ }
383
+ if (readyState !== 'complete') {
384
+ var timer_1 = setTimeout(function () {
385
+ if (!fired) {
386
+ listener();
387
+ fired = true;
388
+ }
389
+ }, iframeLoadTimeout);
390
+ iframeEl.addEventListener('load', function () {
391
+ clearTimeout(timer_1);
392
+ fired = true;
393
+ listener();
394
+ });
395
+ return;
396
+ }
397
+ var blankUrl = 'about:blank';
398
+ if (win.location.href !== blankUrl ||
399
+ iframeEl.src === blankUrl ||
400
+ iframeEl.src === '') {
401
+ setTimeout(listener, 0);
402
+ return iframeEl.addEventListener('load', listener);
403
+ }
404
+ iframeEl.addEventListener('load', listener);
405
+ }
406
+ function isStylesheetLoaded(link) {
407
+ if (!link.getAttribute('href'))
408
+ return true;
409
+ return link.sheet !== null;
410
+ }
411
+ function onceStylesheetLoaded(link, listener, styleSheetLoadTimeout) {
412
+ var fired = false;
413
+ var styleSheetLoaded;
414
+ try {
415
+ styleSheetLoaded = link.sheet;
416
+ }
417
+ catch (error) {
418
+ return;
419
+ }
420
+ if (styleSheetLoaded)
421
+ return;
422
+ var timer = setTimeout(function () {
423
+ if (!fired) {
424
+ listener();
425
+ fired = true;
426
+ }
427
+ }, styleSheetLoadTimeout);
428
+ link.addEventListener('load', function () {
429
+ clearTimeout(timer);
430
+ fired = true;
431
+ listener();
432
+ });
433
+ }
434
+ function serializeNode(n, options) {
435
+ 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;
436
+ var rootId = getRootId(doc, mirror);
437
+ switch (n.nodeType) {
438
+ case n.DOCUMENT_NODE:
439
+ if (n.compatMode !== 'CSS1Compat') {
440
+ return {
441
+ type: NodeType.Document,
442
+ childNodes: [],
443
+ compatMode: n.compatMode,
444
+ rootId: rootId
445
+ };
446
+ }
447
+ else {
448
+ return {
449
+ type: NodeType.Document,
450
+ childNodes: [],
451
+ rootId: rootId
452
+ };
453
+ }
454
+ case n.DOCUMENT_TYPE_NODE:
455
+ return {
456
+ type: NodeType.DocumentType,
457
+ name: n.name,
458
+ publicId: n.publicId,
459
+ systemId: n.systemId,
460
+ rootId: rootId
461
+ };
462
+ case n.ELEMENT_NODE:
463
+ return serializeElementNode(n, {
464
+ doc: doc,
465
+ blockClass: blockClass,
466
+ blockSelector: blockSelector,
467
+ inlineStylesheet: inlineStylesheet,
468
+ maskInputOptions: maskInputOptions,
469
+ maskInputFn: maskInputFn,
470
+ dataURLOptions: dataURLOptions,
471
+ inlineImages: inlineImages,
472
+ recordCanvas: recordCanvas,
473
+ keepIframeSrcFn: keepIframeSrcFn,
474
+ newlyAddedElement: newlyAddedElement,
475
+ enableStrictPrivacy: enableStrictPrivacy,
476
+ rootId: rootId
477
+ });
478
+ case n.TEXT_NODE:
479
+ return serializeTextNode(n, {
480
+ maskTextClass: maskTextClass,
481
+ maskTextSelector: maskTextSelector,
482
+ maskTextFn: maskTextFn,
483
+ enableStrictPrivacy: enableStrictPrivacy,
484
+ rootId: rootId
485
+ });
486
+ case n.CDATA_SECTION_NODE:
487
+ return {
488
+ type: NodeType.CDATA,
489
+ textContent: '',
490
+ rootId: rootId
491
+ };
492
+ case n.COMMENT_NODE:
493
+ return {
494
+ type: NodeType.Comment,
495
+ textContent: n.textContent || '',
496
+ rootId: rootId
497
+ };
498
+ default:
499
+ return false;
500
+ }
501
+ }
502
+ function getRootId(doc, mirror) {
503
+ if (!mirror.hasNode(doc))
504
+ return undefined;
505
+ var docId = mirror.getId(doc);
506
+ return docId === 1 ? undefined : docId;
507
+ }
508
+ function serializeTextNode(n, options) {
509
+ var _a;
510
+ var maskTextClass = options.maskTextClass, maskTextSelector = options.maskTextSelector, maskTextFn = options.maskTextFn, enableStrictPrivacy = options.enableStrictPrivacy, rootId = options.rootId;
511
+ var parentTagName = n.parentNode && n.parentNode.tagName;
512
+ var textContent = n.textContent;
513
+ var isStyle = parentTagName === 'STYLE' ? true : undefined;
514
+ var isScript = parentTagName === 'SCRIPT' ? true : undefined;
515
+ var textContentHandled = false;
516
+ if (isStyle && textContent) {
517
+ try {
518
+ if (n.nextSibling || n.previousSibling) {
519
+ }
520
+ else if ((_a = n.parentNode.sheet) === null || _a === void 0 ? void 0 : _a.cssRules) {
521
+ textContent = stringifyStyleSheet(n.parentNode.sheet);
522
+ }
523
+ }
524
+ catch (err) {
525
+ console.warn("Cannot get CSS styles from text's parentNode. Error: ".concat(err), n);
526
+ }
527
+ textContent = absoluteToStylesheet(textContent, getHref());
528
+ textContentHandled = true;
529
+ }
530
+ if (isScript) {
531
+ textContent = 'SCRIPT_PLACEHOLDER';
532
+ textContentHandled = true;
533
+ }
534
+ else if (parentTagName === 'NOSCRIPT') {
535
+ textContent = '';
536
+ textContentHandled = true;
537
+ }
538
+ if (!isStyle &&
539
+ !isScript &&
540
+ textContent &&
541
+ needMaskingText(n, maskTextClass, maskTextSelector)) {
542
+ textContent = maskTextFn
543
+ ? maskTextFn(textContent)
544
+ : textContent.replace(/[\S]/g, '*');
545
+ }
546
+ if (enableStrictPrivacy && !textContentHandled && parentTagName) {
547
+ var IGNORE_TAG_NAMES = new Set([
548
+ 'HEAD',
549
+ 'TITLE',
550
+ 'STYLE',
551
+ 'SCRIPT',
552
+ 'HTML',
553
+ 'BODY',
554
+ 'NOSCRIPT',
555
+ ]);
556
+ if (!IGNORE_TAG_NAMES.has(parentTagName) && textContent) {
557
+ textContent = obfuscateText(textContent);
558
+ }
559
+ }
560
+ return {
561
+ type: NodeType.Text,
562
+ textContent: textContent || '',
563
+ isStyle: isStyle,
564
+ rootId: rootId
565
+ };
566
+ }
567
+ function serializeElementNode(n, options) {
568
+ 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;
569
+ var needBlock = _isBlockedElement(n, blockClass, blockSelector);
570
+ var tagName = getValidTagName(n);
571
+ var attributes = {};
572
+ var len = n.attributes.length;
573
+ for (var i = 0; i < len; i++) {
574
+ var attr = n.attributes[i];
575
+ attributes[attr.name] = transformAttribute(doc, tagName, attr.name, attr.value);
576
+ }
577
+ if (tagName === 'link' && inlineStylesheet) {
578
+ var stylesheet = Array.from(doc.styleSheets).find(function (s) {
579
+ return s.href === n.href;
580
+ });
581
+ var cssText = null;
582
+ if (stylesheet) {
583
+ cssText = getCssRulesString(stylesheet);
584
+ }
585
+ if (cssText) {
586
+ delete attributes.rel;
587
+ delete attributes.href;
588
+ attributes._cssText = absoluteToStylesheet(cssText, stylesheet.href);
589
+ }
590
+ }
591
+ if (tagName === 'style' &&
592
+ n.sheet &&
593
+ !(n.innerText || n.textContent || '').trim().length) {
594
+ var cssText = getCssRulesString(n.sheet);
595
+ if (cssText) {
596
+ attributes._cssText = absoluteToStylesheet(cssText, getHref());
597
+ }
598
+ }
599
+ if (tagName === 'input' || tagName === 'textarea' || tagName === 'select') {
600
+ var value = n.value;
601
+ if (attributes.type !== 'radio' &&
602
+ attributes.type !== 'checkbox' &&
603
+ attributes.type !== 'submit' &&
604
+ attributes.type !== 'button' &&
605
+ value) {
606
+ attributes.value = maskInputValue({
607
+ type: attributes.type,
608
+ tagName: tagName,
609
+ value: value,
610
+ maskInputOptions: maskInputOptions,
611
+ maskInputFn: maskInputFn
612
+ });
613
+ }
614
+ else if (n.checked) {
615
+ attributes.checked = n.checked;
616
+ }
617
+ }
618
+ if (tagName === 'option') {
619
+ if (n.selected && !maskInputOptions['select']) {
620
+ attributes.selected = true;
621
+ }
622
+ else {
623
+ delete attributes.selected;
624
+ }
625
+ }
626
+ if (tagName === 'canvas' && recordCanvas) {
627
+ if (n.__context === '2d') {
628
+ if (!is2DCanvasBlank(n)) {
629
+ attributes.rr_dataURL = n.toDataURL(dataURLOptions.type, dataURLOptions.quality);
630
+ }
631
+ }
632
+ else if (!('__context' in n)) {
633
+ var canvasDataURL = n.toDataURL(dataURLOptions.type, dataURLOptions.quality);
634
+ var blankCanvas = document.createElement('canvas');
635
+ blankCanvas.width = n.width;
636
+ blankCanvas.height = n.height;
637
+ var blankCanvasDataURL = blankCanvas.toDataURL(dataURLOptions.type, dataURLOptions.quality);
638
+ if (canvasDataURL !== blankCanvasDataURL) {
639
+ attributes.rr_dataURL = canvasDataURL;
640
+ }
641
+ }
642
+ }
643
+ if (tagName === 'img' && inlineImages) {
644
+ if (!canvasService) {
645
+ canvasService = doc.createElement('canvas');
646
+ canvasCtx = canvasService.getContext('2d');
647
+ }
648
+ var image_1 = n;
649
+ var oldValue_1 = image_1.crossOrigin;
650
+ image_1.crossOrigin = 'anonymous';
651
+ var recordInlineImage = function () {
652
+ try {
653
+ canvasService.width = image_1.naturalWidth;
654
+ canvasService.height = image_1.naturalHeight;
655
+ canvasCtx.drawImage(image_1, 0, 0);
656
+ attributes.rr_dataURL = canvasService.toDataURL(dataURLOptions.type, dataURLOptions.quality);
657
+ }
658
+ catch (err) {
659
+ console.warn("Cannot inline img src=".concat(image_1.currentSrc, "! Error: ").concat(err));
660
+ }
661
+ oldValue_1
662
+ ? (attributes.crossOrigin = oldValue_1)
663
+ : image_1.removeAttribute('crossorigin');
664
+ };
665
+ if (image_1.complete && image_1.naturalWidth !== 0)
666
+ recordInlineImage();
667
+ else
668
+ image_1.onload = recordInlineImage;
669
+ }
670
+ if (tagName === 'audio' || tagName === 'video') {
671
+ attributes.rr_mediaState = n.paused
672
+ ? 'paused'
673
+ : 'played';
674
+ attributes.rr_mediaCurrentTime = n.currentTime;
675
+ }
676
+ if (!newlyAddedElement) {
677
+ if (n.scrollLeft) {
678
+ attributes.rr_scrollLeft = n.scrollLeft;
679
+ }
680
+ if (n.scrollTop) {
681
+ attributes.rr_scrollTop = n.scrollTop;
682
+ }
683
+ }
684
+ if (needBlock || (tagName === 'img' && enableStrictPrivacy)) {
685
+ var _d = n.getBoundingClientRect(), width = _d.width, height = _d.height;
686
+ attributes = {
687
+ "class": attributes["class"],
688
+ rr_width: "".concat(width, "px"),
689
+ rr_height: "".concat(height, "px")
690
+ };
691
+ needBlock = true;
692
+ }
693
+ if (tagName === 'iframe' && !keepIframeSrcFn(attributes.src)) {
694
+ if (!n.contentDocument) {
695
+ attributes.rr_src = attributes.src;
696
+ }
697
+ delete attributes.src;
698
+ }
699
+ return {
700
+ type: NodeType.Element,
701
+ tagName: tagName,
702
+ attributes: attributes,
703
+ childNodes: [],
704
+ isSVG: isSVGElement(n) || undefined,
705
+ needBlock: needBlock,
706
+ rootId: rootId
707
+ };
708
+ }
709
+ function lowerIfExists(maybeAttr) {
710
+ if (maybeAttr === undefined) {
711
+ return '';
712
+ }
713
+ else {
714
+ return maybeAttr.toLowerCase();
715
+ }
716
+ }
717
+ function slimDOMExcluded(sn, slimDOMOptions) {
718
+ if (slimDOMOptions.comment && sn.type === NodeType.Comment) {
719
+ return true;
720
+ }
721
+ else if (sn.type === NodeType.Element) {
722
+ if (slimDOMOptions.script &&
723
+ (sn.tagName === 'script' ||
724
+ (sn.tagName === 'link' &&
725
+ sn.attributes.rel === 'preload' &&
726
+ sn.attributes.as === 'script') ||
727
+ (sn.tagName === 'link' &&
728
+ sn.attributes.rel === 'prefetch' &&
729
+ typeof sn.attributes.href === 'string' &&
730
+ sn.attributes.href.endsWith('.js')))) {
731
+ return true;
732
+ }
733
+ else if (slimDOMOptions.headFavicon &&
734
+ ((sn.tagName === 'link' && sn.attributes.rel === 'shortcut icon') ||
735
+ (sn.tagName === 'meta' &&
736
+ (lowerIfExists(sn.attributes.name).match(/^msapplication-tile(image|color)$/) ||
737
+ lowerIfExists(sn.attributes.name) === 'application-name' ||
738
+ lowerIfExists(sn.attributes.rel) === 'icon' ||
739
+ lowerIfExists(sn.attributes.rel) === 'apple-touch-icon' ||
740
+ lowerIfExists(sn.attributes.rel) === 'shortcut icon')))) {
741
+ return true;
742
+ }
743
+ else if (sn.tagName === 'meta') {
744
+ if (slimDOMOptions.headMetaDescKeywords &&
745
+ lowerIfExists(sn.attributes.name).match(/^description|keywords$/)) {
746
+ return true;
747
+ }
748
+ else if (slimDOMOptions.headMetaSocial &&
749
+ (lowerIfExists(sn.attributes.property).match(/^(og|twitter|fb):/) ||
750
+ lowerIfExists(sn.attributes.name).match(/^(og|twitter):/) ||
751
+ lowerIfExists(sn.attributes.name) === 'pinterest')) {
752
+ return true;
753
+ }
754
+ else if (slimDOMOptions.headMetaRobots &&
755
+ (lowerIfExists(sn.attributes.name) === 'robots' ||
756
+ lowerIfExists(sn.attributes.name) === 'googlebot' ||
757
+ lowerIfExists(sn.attributes.name) === 'bingbot')) {
758
+ return true;
759
+ }
760
+ else if (slimDOMOptions.headMetaHttpEquiv &&
761
+ sn.attributes['http-equiv'] !== undefined) {
762
+ return true;
763
+ }
764
+ else if (slimDOMOptions.headMetaAuthorship &&
765
+ (lowerIfExists(sn.attributes.name) === 'author' ||
766
+ lowerIfExists(sn.attributes.name) === 'generator' ||
767
+ lowerIfExists(sn.attributes.name) === 'framework' ||
768
+ lowerIfExists(sn.attributes.name) === 'publisher' ||
769
+ lowerIfExists(sn.attributes.name) === 'progid' ||
770
+ lowerIfExists(sn.attributes.property).match(/^article:/) ||
771
+ lowerIfExists(sn.attributes.property).match(/^product:/))) {
772
+ return true;
773
+ }
774
+ else if (slimDOMOptions.headMetaVerification &&
775
+ (lowerIfExists(sn.attributes.name) === 'google-site-verification' ||
776
+ lowerIfExists(sn.attributes.name) === 'yandex-verification' ||
777
+ lowerIfExists(sn.attributes.name) === 'csrf-token' ||
778
+ lowerIfExists(sn.attributes.name) === 'p:domain_verify' ||
779
+ lowerIfExists(sn.attributes.name) === 'verify-v1' ||
780
+ lowerIfExists(sn.attributes.name) === 'verification' ||
781
+ lowerIfExists(sn.attributes.name) === 'shopify-checkout-api-token')) {
782
+ return true;
783
+ }
784
+ }
785
+ }
786
+ return false;
787
+ }
788
+ function serializeNodeWithId(n, options) {
789
+ 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;
790
+ var _l = options.preserveWhiteSpace, preserveWhiteSpace = _l === void 0 ? true : _l;
791
+ var _serializedNode = serializeNode(n, {
792
+ doc: doc,
793
+ mirror: mirror,
794
+ blockClass: blockClass,
795
+ blockSelector: blockSelector,
796
+ maskTextClass: maskTextClass,
797
+ maskTextSelector: maskTextSelector,
798
+ inlineStylesheet: inlineStylesheet,
799
+ maskInputOptions: maskInputOptions,
800
+ maskTextFn: maskTextFn,
801
+ maskInputFn: maskInputFn,
802
+ dataURLOptions: dataURLOptions,
803
+ inlineImages: inlineImages,
804
+ recordCanvas: recordCanvas,
805
+ keepIframeSrcFn: keepIframeSrcFn,
806
+ newlyAddedElement: newlyAddedElement,
807
+ enableStrictPrivacy: enableStrictPrivacy
808
+ });
809
+ if (!_serializedNode) {
810
+ console.warn(n, 'not serialized');
811
+ return null;
812
+ }
813
+ var id;
814
+ if (mirror.hasNode(n)) {
815
+ id = mirror.getId(n);
816
+ }
817
+ else if (slimDOMExcluded(_serializedNode, slimDOMOptions) ||
818
+ (!preserveWhiteSpace &&
819
+ _serializedNode.type === NodeType.Text &&
820
+ !_serializedNode.isStyle &&
821
+ !_serializedNode.textContent.replace(/^\s+|\s+$/gm, '').length)) {
822
+ id = IGNORED_NODE;
823
+ }
824
+ else {
825
+ id = genId();
826
+ }
827
+ if (id === IGNORED_NODE) {
828
+ return null;
829
+ }
830
+ var serializedNode = Object.assign(_serializedNode, { id: id });
831
+ mirror.add(n, serializedNode);
832
+ if (onSerialize) {
833
+ onSerialize(n);
834
+ }
835
+ var recordChild = !skipChild;
836
+ if (serializedNode.type === NodeType.Element) {
837
+ recordChild = recordChild && !serializedNode.needBlock;
838
+ if (serializedNode.needBlock && serializedNode.tagName === 'img') {
839
+ var clone = n.cloneNode();
840
+ clone.src = '';
841
+ mirror.add(clone, serializedNode);
842
+ }
843
+ delete serializedNode.needBlock;
844
+ if (n.shadowRoot)
845
+ serializedNode.isShadowHost = true;
846
+ }
847
+ if ((serializedNode.type === NodeType.Document ||
848
+ serializedNode.type === NodeType.Element) &&
849
+ recordChild) {
850
+ if (slimDOMOptions.headWhitespace &&
851
+ serializedNode.type === NodeType.Element &&
852
+ serializedNode.tagName === 'head') {
853
+ preserveWhiteSpace = false;
854
+ }
855
+ var bypassOptions = {
856
+ doc: doc,
857
+ mirror: mirror,
858
+ blockClass: blockClass,
859
+ blockSelector: blockSelector,
860
+ maskTextClass: maskTextClass,
861
+ maskTextSelector: maskTextSelector,
862
+ skipChild: skipChild,
863
+ inlineStylesheet: inlineStylesheet,
864
+ maskInputOptions: maskInputOptions,
865
+ maskTextFn: maskTextFn,
866
+ maskInputFn: maskInputFn,
867
+ slimDOMOptions: slimDOMOptions,
868
+ dataURLOptions: dataURLOptions,
869
+ inlineImages: inlineImages,
870
+ recordCanvas: recordCanvas,
871
+ preserveWhiteSpace: preserveWhiteSpace,
872
+ onSerialize: onSerialize,
873
+ onIframeLoad: onIframeLoad,
874
+ iframeLoadTimeout: iframeLoadTimeout,
875
+ onStylesheetLoad: onStylesheetLoad,
876
+ stylesheetLoadTimeout: stylesheetLoadTimeout,
877
+ keepIframeSrcFn: keepIframeSrcFn,
878
+ enableStrictPrivacy: enableStrictPrivacy
879
+ };
880
+ for (var _i = 0, _m = Array.from(n.childNodes); _i < _m.length; _i++) {
881
+ var childN = _m[_i];
882
+ var serializedChildNode = serializeNodeWithId(childN, bypassOptions);
883
+ if (serializedChildNode) {
884
+ serializedNode.childNodes.push(serializedChildNode);
885
+ }
886
+ }
887
+ if (isElement(n) && n.shadowRoot) {
888
+ for (var _o = 0, _p = Array.from(n.shadowRoot.childNodes); _o < _p.length; _o++) {
889
+ var childN = _p[_o];
890
+ var serializedChildNode = serializeNodeWithId(childN, bypassOptions);
891
+ if (serializedChildNode) {
892
+ serializedChildNode.isShadow = true;
893
+ serializedNode.childNodes.push(serializedChildNode);
894
+ }
895
+ }
896
+ }
897
+ }
898
+ if (n.parentNode && isShadowRoot(n.parentNode)) {
899
+ serializedNode.isShadow = true;
900
+ }
901
+ if (serializedNode.type === NodeType.Element &&
902
+ serializedNode.tagName === 'iframe') {
903
+ onceIframeLoaded(n, function () {
904
+ var iframeDoc = n.contentDocument;
905
+ if (iframeDoc && onIframeLoad) {
906
+ var serializedIframeNode = serializeNodeWithId(iframeDoc, {
907
+ doc: iframeDoc,
908
+ mirror: mirror,
909
+ blockClass: blockClass,
910
+ blockSelector: blockSelector,
911
+ maskTextClass: maskTextClass,
912
+ maskTextSelector: maskTextSelector,
913
+ skipChild: false,
914
+ inlineStylesheet: inlineStylesheet,
915
+ maskInputOptions: maskInputOptions,
916
+ maskTextFn: maskTextFn,
917
+ maskInputFn: maskInputFn,
918
+ slimDOMOptions: slimDOMOptions,
919
+ dataURLOptions: dataURLOptions,
920
+ inlineImages: inlineImages,
921
+ recordCanvas: recordCanvas,
922
+ preserveWhiteSpace: preserveWhiteSpace,
923
+ onSerialize: onSerialize,
924
+ onIframeLoad: onIframeLoad,
925
+ iframeLoadTimeout: iframeLoadTimeout,
926
+ onStylesheetLoad: onStylesheetLoad,
927
+ stylesheetLoadTimeout: stylesheetLoadTimeout,
928
+ keepIframeSrcFn: keepIframeSrcFn,
929
+ enableStrictPrivacy: enableStrictPrivacy
930
+ });
931
+ if (serializedIframeNode) {
932
+ onIframeLoad(n, serializedIframeNode);
933
+ }
934
+ }
935
+ }, iframeLoadTimeout);
936
+ }
937
+ if (serializedNode.type === NodeType.Element &&
938
+ serializedNode.tagName === 'link' &&
939
+ serializedNode.attributes.rel === 'stylesheet') {
940
+ onceStylesheetLoaded(n, function () {
941
+ if (onStylesheetLoad) {
942
+ var serializedLinkNode = serializeNodeWithId(n, {
943
+ doc: doc,
944
+ mirror: mirror,
945
+ blockClass: blockClass,
946
+ blockSelector: blockSelector,
947
+ maskTextClass: maskTextClass,
948
+ maskTextSelector: maskTextSelector,
949
+ skipChild: false,
950
+ inlineStylesheet: inlineStylesheet,
951
+ maskInputOptions: maskInputOptions,
952
+ maskTextFn: maskTextFn,
953
+ maskInputFn: maskInputFn,
954
+ slimDOMOptions: slimDOMOptions,
955
+ dataURLOptions: dataURLOptions,
956
+ inlineImages: inlineImages,
957
+ recordCanvas: recordCanvas,
958
+ preserveWhiteSpace: preserveWhiteSpace,
959
+ onSerialize: onSerialize,
960
+ onIframeLoad: onIframeLoad,
961
+ iframeLoadTimeout: iframeLoadTimeout,
962
+ onStylesheetLoad: onStylesheetLoad,
963
+ stylesheetLoadTimeout: stylesheetLoadTimeout,
964
+ keepIframeSrcFn: keepIframeSrcFn,
965
+ enableStrictPrivacy: enableStrictPrivacy
966
+ });
967
+ if (serializedLinkNode) {
968
+ onStylesheetLoad(n, serializedLinkNode);
969
+ }
970
+ }
971
+ }, stylesheetLoadTimeout);
972
+ if (isStylesheetLoaded(n) === false)
973
+ return null;
974
+ }
975
+ return serializedNode;
976
+ }
977
+ function snapshot(n, options) {
978
+ var _a = options || {}, _b = _a.mirror, mirror = _b === void 0 ? new Mirror() : _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;
979
+ var maskInputOptions = maskAllInputs === true
980
+ ? {
981
+ color: true,
982
+ date: true,
983
+ 'datetime-local': true,
984
+ email: true,
985
+ month: true,
986
+ number: true,
987
+ range: true,
988
+ search: true,
989
+ tel: true,
990
+ text: true,
991
+ time: true,
992
+ url: true,
993
+ week: true,
994
+ textarea: true,
995
+ select: true,
996
+ password: true
997
+ }
998
+ : maskAllInputs === false
999
+ ? {
1000
+ password: true
1001
+ }
1002
+ : maskAllInputs;
1003
+ var slimDOMOptions = slimDOM === true || slimDOM === 'all'
1004
+ ?
1005
+ {
1006
+ script: true,
1007
+ comment: true,
1008
+ headFavicon: true,
1009
+ headWhitespace: true,
1010
+ headMetaDescKeywords: slimDOM === 'all',
1011
+ headMetaSocial: true,
1012
+ headMetaRobots: true,
1013
+ headMetaHttpEquiv: true,
1014
+ headMetaAuthorship: true,
1015
+ headMetaVerification: true
1016
+ }
1017
+ : slimDOM === false
1018
+ ? {}
1019
+ : slimDOM;
1020
+ return serializeNodeWithId(n, {
1021
+ doc: n,
1022
+ mirror: mirror,
1023
+ blockClass: blockClass,
1024
+ blockSelector: blockSelector,
1025
+ maskTextClass: maskTextClass,
1026
+ maskTextSelector: maskTextSelector,
1027
+ skipChild: false,
1028
+ inlineStylesheet: inlineStylesheet,
1029
+ maskInputOptions: maskInputOptions,
1030
+ maskTextFn: maskTextFn,
1031
+ maskInputFn: maskInputFn,
1032
+ slimDOMOptions: slimDOMOptions,
1033
+ dataURLOptions: dataURLOptions,
1034
+ inlineImages: inlineImages,
1035
+ recordCanvas: recordCanvas,
1036
+ preserveWhiteSpace: preserveWhiteSpace,
1037
+ onSerialize: onSerialize,
1038
+ onIframeLoad: onIframeLoad,
1039
+ iframeLoadTimeout: iframeLoadTimeout,
1040
+ onStylesheetLoad: onStylesheetLoad,
1041
+ stylesheetLoadTimeout: stylesheetLoadTimeout,
1042
+ keepIframeSrcFn: keepIframeSrcFn,
1043
+ newlyAddedElement: false,
1044
+ enableStrictPrivacy: enableStrictPrivacy
1045
+ });
1046
+ }
1048
1047
 
1049
- var commentre = /\/\*[^*]*\*+([^/*][^*]*\*+)*\//g;
1050
- function parse(css, options) {
1051
- if (options === void 0) { options = {}; }
1052
- var lineno = 1;
1053
- var column = 1;
1054
- function updatePosition(str) {
1055
- var lines = str.match(/\n/g);
1056
- if (lines) {
1057
- lineno += lines.length;
1058
- }
1059
- var i = str.lastIndexOf('\n');
1060
- column = i === -1 ? column + str.length : str.length - i;
1061
- }
1062
- function position() {
1063
- var start = { line: lineno, column: column };
1064
- return function (node) {
1065
- node.position = new Position(start);
1066
- whitespace();
1067
- return node;
1068
- };
1069
- }
1070
- var Position = (function () {
1071
- function Position(start) {
1072
- this.start = start;
1073
- this.end = { line: lineno, column: column };
1074
- this.source = options.source;
1075
- }
1076
- return Position;
1077
- }());
1078
- Position.prototype.content = css;
1079
- var errorsList = [];
1080
- function error(msg) {
1081
- var err = new Error(options.source + ':' + lineno + ':' + column + ': ' + msg);
1082
- err.reason = msg;
1083
- err.filename = options.source;
1084
- err.line = lineno;
1085
- err.column = column;
1086
- err.source = css;
1087
- if (options.silent) {
1088
- errorsList.push(err);
1089
- }
1090
- else {
1091
- throw err;
1092
- }
1093
- }
1094
- function stylesheet() {
1095
- var rulesList = rules();
1096
- return {
1097
- type: 'stylesheet',
1098
- stylesheet: {
1099
- source: options.source,
1100
- rules: rulesList,
1101
- parsingErrors: errorsList
1102
- }
1103
- };
1104
- }
1105
- function open() {
1106
- return match(/^{\s*/);
1107
- }
1108
- function close() {
1109
- return match(/^}/);
1110
- }
1111
- function rules() {
1112
- var node;
1113
- var rules = [];
1114
- whitespace();
1115
- comments(rules);
1116
- while (css.length && css.charAt(0) !== '}' && (node = atrule() || rule())) {
1117
- if (node !== false) {
1118
- rules.push(node);
1119
- comments(rules);
1120
- }
1121
- }
1122
- return rules;
1123
- }
1124
- function match(re) {
1125
- var m = re.exec(css);
1126
- if (!m) {
1127
- return;
1128
- }
1129
- var str = m[0];
1130
- updatePosition(str);
1131
- css = css.slice(str.length);
1132
- return m;
1133
- }
1134
- function whitespace() {
1135
- match(/^\s*/);
1136
- }
1137
- function comments(rules) {
1138
- if (rules === void 0) { rules = []; }
1139
- var c;
1140
- while ((c = comment())) {
1141
- if (c !== false) {
1142
- rules.push(c);
1143
- }
1144
- c = comment();
1145
- }
1146
- return rules;
1147
- }
1148
- function comment() {
1149
- var pos = position();
1150
- if ('/' !== css.charAt(0) || '*' !== css.charAt(1)) {
1151
- return;
1152
- }
1153
- var i = 2;
1154
- while ('' !== css.charAt(i) &&
1155
- ('*' !== css.charAt(i) || '/' !== css.charAt(i + 1))) {
1156
- ++i;
1157
- }
1158
- i += 2;
1159
- if ('' === css.charAt(i - 1)) {
1160
- return error('End of comment missing');
1161
- }
1162
- var str = css.slice(2, i - 2);
1163
- column += 2;
1164
- updatePosition(str);
1165
- css = css.slice(i);
1166
- column += 2;
1167
- return pos({
1168
- type: 'comment',
1169
- comment: str
1170
- });
1171
- }
1172
- function selector() {
1173
- var m = match(/^([^{]+)/);
1174
- if (!m) {
1175
- return;
1176
- }
1177
- return trim(m[0])
1178
- .replace(/\/\*([^*]|[\r\n]|(\*+([^*/]|[\r\n])))*\*\/+/g, '')
1179
- .replace(/"(?:\\"|[^"])*"|'(?:\\'|[^'])*'/g, function (m) {
1180
- return m.replace(/,/g, '\u200C');
1181
- })
1182
- .split(/\s*(?![^(]*\)),\s*/)
1183
- .map(function (s) {
1184
- return s.replace(/\u200C/g, ',');
1185
- });
1186
- }
1187
- function declaration() {
1188
- var pos = position();
1189
- var propMatch = match(/^(\*?[-#\/\*\\\w]+(\[[0-9a-z_-]+\])?)\s*/);
1190
- if (!propMatch) {
1191
- return;
1192
- }
1193
- var prop = trim(propMatch[0]);
1194
- if (!match(/^:\s*/)) {
1195
- return error("property missing ':'");
1196
- }
1197
- var val = match(/^((?:'(?:\\'|.)*?'|"(?:\\"|.)*?"|\([^\)]*?\)|[^};])+)/);
1198
- var ret = pos({
1199
- type: 'declaration',
1200
- property: prop.replace(commentre, ''),
1201
- value: val ? trim(val[0]).replace(commentre, '') : ''
1202
- });
1203
- match(/^[;\s]*/);
1204
- return ret;
1205
- }
1206
- function declarations() {
1207
- var decls = [];
1208
- if (!open()) {
1209
- return error("missing '{'");
1210
- }
1211
- comments(decls);
1212
- var decl;
1213
- while ((decl = declaration())) {
1214
- if (decl !== false) {
1215
- decls.push(decl);
1216
- comments(decls);
1217
- }
1218
- decl = declaration();
1219
- }
1220
- if (!close()) {
1221
- return error("missing '}'");
1222
- }
1223
- return decls;
1224
- }
1225
- function keyframe() {
1226
- var m;
1227
- var vals = [];
1228
- var pos = position();
1229
- while ((m = match(/^((\d+\.\d+|\.\d+|\d+)%?|[a-z]+)\s*/))) {
1230
- vals.push(m[1]);
1231
- match(/^,\s*/);
1232
- }
1233
- if (!vals.length) {
1234
- return;
1235
- }
1236
- return pos({
1237
- type: 'keyframe',
1238
- values: vals,
1239
- declarations: declarations()
1240
- });
1241
- }
1242
- function atkeyframes() {
1243
- var pos = position();
1244
- var m = match(/^@([-\w]+)?keyframes\s*/);
1245
- if (!m) {
1246
- return;
1247
- }
1248
- var vendor = m[1];
1249
- m = match(/^([-\w]+)\s*/);
1250
- if (!m) {
1251
- return error('@keyframes missing name');
1252
- }
1253
- var name = m[1];
1254
- if (!open()) {
1255
- return error("@keyframes missing '{'");
1256
- }
1257
- var frame;
1258
- var frames = comments();
1259
- while ((frame = keyframe())) {
1260
- frames.push(frame);
1261
- frames = frames.concat(comments());
1262
- }
1263
- if (!close()) {
1264
- return error("@keyframes missing '}'");
1265
- }
1266
- return pos({
1267
- type: 'keyframes',
1268
- name: name,
1269
- vendor: vendor,
1270
- keyframes: frames
1271
- });
1272
- }
1273
- function atsupports() {
1274
- var pos = position();
1275
- var m = match(/^@supports *([^{]+)/);
1276
- if (!m) {
1277
- return;
1278
- }
1279
- var supports = trim(m[1]);
1280
- if (!open()) {
1281
- return error("@supports missing '{'");
1282
- }
1283
- var style = comments().concat(rules());
1284
- if (!close()) {
1285
- return error("@supports missing '}'");
1286
- }
1287
- return pos({
1288
- type: 'supports',
1289
- supports: supports,
1290
- rules: style
1291
- });
1292
- }
1293
- function athost() {
1294
- var pos = position();
1295
- var m = match(/^@host\s*/);
1296
- if (!m) {
1297
- return;
1298
- }
1299
- if (!open()) {
1300
- return error("@host missing '{'");
1301
- }
1302
- var style = comments().concat(rules());
1303
- if (!close()) {
1304
- return error("@host missing '}'");
1305
- }
1306
- return pos({
1307
- type: 'host',
1308
- rules: style
1309
- });
1310
- }
1311
- function atmedia() {
1312
- var pos = position();
1313
- var m = match(/^@media *([^{]+)/);
1314
- if (!m) {
1315
- return;
1316
- }
1317
- var media = trim(m[1]);
1318
- if (!open()) {
1319
- return error("@media missing '{'");
1320
- }
1321
- var style = comments().concat(rules());
1322
- if (!close()) {
1323
- return error("@media missing '}'");
1324
- }
1325
- return pos({
1326
- type: 'media',
1327
- media: media,
1328
- rules: style
1329
- });
1330
- }
1331
- function atcustommedia() {
1332
- var pos = position();
1333
- var m = match(/^@custom-media\s+(--[^\s]+)\s*([^{;]+);/);
1334
- if (!m) {
1335
- return;
1336
- }
1337
- return pos({
1338
- type: 'custom-media',
1339
- name: trim(m[1]),
1340
- media: trim(m[2])
1341
- });
1342
- }
1343
- function atpage() {
1344
- var pos = position();
1345
- var m = match(/^@page */);
1346
- if (!m) {
1347
- return;
1348
- }
1349
- var sel = selector() || [];
1350
- if (!open()) {
1351
- return error("@page missing '{'");
1352
- }
1353
- var decls = comments();
1354
- var decl;
1355
- while ((decl = declaration())) {
1356
- decls.push(decl);
1357
- decls = decls.concat(comments());
1358
- }
1359
- if (!close()) {
1360
- return error("@page missing '}'");
1361
- }
1362
- return pos({
1363
- type: 'page',
1364
- selectors: sel,
1365
- declarations: decls
1366
- });
1367
- }
1368
- function atdocument() {
1369
- var pos = position();
1370
- var m = match(/^@([-\w]+)?document *([^{]+)/);
1371
- if (!m) {
1372
- return;
1373
- }
1374
- var vendor = trim(m[1]);
1375
- var doc = trim(m[2]);
1376
- if (!open()) {
1377
- return error("@document missing '{'");
1378
- }
1379
- var style = comments().concat(rules());
1380
- if (!close()) {
1381
- return error("@document missing '}'");
1382
- }
1383
- return pos({
1384
- type: 'document',
1385
- document: doc,
1386
- vendor: vendor,
1387
- rules: style
1388
- });
1389
- }
1390
- function atfontface() {
1391
- var pos = position();
1392
- var m = match(/^@font-face\s*/);
1393
- if (!m) {
1394
- return;
1395
- }
1396
- if (!open()) {
1397
- return error("@font-face missing '{'");
1398
- }
1399
- var decls = comments();
1400
- var decl;
1401
- while ((decl = declaration())) {
1402
- decls.push(decl);
1403
- decls = decls.concat(comments());
1404
- }
1405
- if (!close()) {
1406
- return error("@font-face missing '}'");
1407
- }
1408
- return pos({
1409
- type: 'font-face',
1410
- declarations: decls
1411
- });
1412
- }
1413
- var atimport = _compileAtrule('import');
1414
- var atcharset = _compileAtrule('charset');
1415
- var atnamespace = _compileAtrule('namespace');
1416
- function _compileAtrule(name) {
1417
- var re = new RegExp('^@' + name + '\\s*([^;]+);');
1418
- return function () {
1419
- var pos = position();
1420
- var m = match(re);
1421
- if (!m) {
1422
- return;
1423
- }
1424
- var ret = { type: name };
1425
- ret[name] = m[1].trim();
1426
- return pos(ret);
1427
- };
1428
- }
1429
- function atrule() {
1430
- if (css[0] !== '@') {
1431
- return;
1432
- }
1433
- return (atkeyframes() ||
1434
- atmedia() ||
1435
- atcustommedia() ||
1436
- atsupports() ||
1437
- atimport() ||
1438
- atcharset() ||
1439
- atnamespace() ||
1440
- atdocument() ||
1441
- atpage() ||
1442
- athost() ||
1443
- atfontface());
1444
- }
1445
- function rule() {
1446
- var pos = position();
1447
- var sel = selector();
1448
- if (!sel) {
1449
- return error('selector missing');
1450
- }
1451
- comments();
1452
- return pos({
1453
- type: 'rule',
1454
- selectors: sel,
1455
- declarations: declarations()
1456
- });
1457
- }
1458
- return addParent(stylesheet());
1459
- }
1460
- function trim(str) {
1461
- return str ? str.replace(/^\s+|\s+$/g, '') : '';
1462
- }
1463
- function addParent(obj, parent) {
1464
- var isNode = obj && typeof obj.type === 'string';
1465
- var childParent = isNode ? obj : parent;
1466
- for (var _i = 0, _a = Object.keys(obj); _i < _a.length; _i++) {
1467
- var k = _a[_i];
1468
- var value = obj[k];
1469
- if (Array.isArray(value)) {
1470
- value.forEach(function (v) {
1471
- addParent(v, childParent);
1472
- });
1473
- }
1474
- else if (value && typeof value === 'object') {
1475
- addParent(value, childParent);
1476
- }
1477
- }
1478
- if (isNode) {
1479
- Object.defineProperty(obj, 'parent', {
1480
- configurable: true,
1481
- writable: true,
1482
- enumerable: false,
1483
- value: parent || null
1484
- });
1485
- }
1486
- return obj;
1048
+ var commentre = /\/\*[^*]*\*+([^/*][^*]*\*+)*\//g;
1049
+ function parse(css, options) {
1050
+ if (options === void 0) { options = {}; }
1051
+ var lineno = 1;
1052
+ var column = 1;
1053
+ function updatePosition(str) {
1054
+ var lines = str.match(/\n/g);
1055
+ if (lines) {
1056
+ lineno += lines.length;
1057
+ }
1058
+ var i = str.lastIndexOf('\n');
1059
+ column = i === -1 ? column + str.length : str.length - i;
1060
+ }
1061
+ function position() {
1062
+ var start = { line: lineno, column: column };
1063
+ return function (node) {
1064
+ node.position = new Position(start);
1065
+ whitespace();
1066
+ return node;
1067
+ };
1068
+ }
1069
+ var Position = (function () {
1070
+ function Position(start) {
1071
+ this.start = start;
1072
+ this.end = { line: lineno, column: column };
1073
+ this.source = options.source;
1074
+ }
1075
+ return Position;
1076
+ }());
1077
+ Position.prototype.content = css;
1078
+ var errorsList = [];
1079
+ function error(msg) {
1080
+ var err = new Error(options.source + ':' + lineno + ':' + column + ': ' + msg);
1081
+ err.reason = msg;
1082
+ err.filename = options.source;
1083
+ err.line = lineno;
1084
+ err.column = column;
1085
+ err.source = css;
1086
+ if (options.silent) {
1087
+ errorsList.push(err);
1088
+ }
1089
+ else {
1090
+ throw err;
1091
+ }
1092
+ }
1093
+ function stylesheet() {
1094
+ var rulesList = rules();
1095
+ return {
1096
+ type: 'stylesheet',
1097
+ stylesheet: {
1098
+ source: options.source,
1099
+ rules: rulesList,
1100
+ parsingErrors: errorsList
1101
+ }
1102
+ };
1103
+ }
1104
+ function open() {
1105
+ return match(/^{\s*/);
1106
+ }
1107
+ function close() {
1108
+ return match(/^}/);
1109
+ }
1110
+ function rules() {
1111
+ var node;
1112
+ var rules = [];
1113
+ whitespace();
1114
+ comments(rules);
1115
+ while (css.length && css.charAt(0) !== '}' && (node = atrule() || rule())) {
1116
+ if (node !== false) {
1117
+ rules.push(node);
1118
+ comments(rules);
1119
+ }
1120
+ }
1121
+ return rules;
1122
+ }
1123
+ function match(re) {
1124
+ var m = re.exec(css);
1125
+ if (!m) {
1126
+ return;
1127
+ }
1128
+ var str = m[0];
1129
+ updatePosition(str);
1130
+ css = css.slice(str.length);
1131
+ return m;
1132
+ }
1133
+ function whitespace() {
1134
+ match(/^\s*/);
1135
+ }
1136
+ function comments(rules) {
1137
+ if (rules === void 0) { rules = []; }
1138
+ var c;
1139
+ while ((c = comment())) {
1140
+ if (c !== false) {
1141
+ rules.push(c);
1142
+ }
1143
+ c = comment();
1144
+ }
1145
+ return rules;
1146
+ }
1147
+ function comment() {
1148
+ var pos = position();
1149
+ if ('/' !== css.charAt(0) || '*' !== css.charAt(1)) {
1150
+ return;
1151
+ }
1152
+ var i = 2;
1153
+ while ('' !== css.charAt(i) &&
1154
+ ('*' !== css.charAt(i) || '/' !== css.charAt(i + 1))) {
1155
+ ++i;
1156
+ }
1157
+ i += 2;
1158
+ if ('' === css.charAt(i - 1)) {
1159
+ return error('End of comment missing');
1160
+ }
1161
+ var str = css.slice(2, i - 2);
1162
+ column += 2;
1163
+ updatePosition(str);
1164
+ css = css.slice(i);
1165
+ column += 2;
1166
+ return pos({
1167
+ type: 'comment',
1168
+ comment: str
1169
+ });
1170
+ }
1171
+ function selector() {
1172
+ var m = match(/^([^{]+)/);
1173
+ if (!m) {
1174
+ return;
1175
+ }
1176
+ return trim(m[0])
1177
+ .replace(/\/\*([^*]|[\r\n]|(\*+([^*/]|[\r\n])))*\*\/+/g, '')
1178
+ .replace(/"(?:\\"|[^"])*"|'(?:\\'|[^'])*'/g, function (m) {
1179
+ return m.replace(/,/g, '\u200C');
1180
+ })
1181
+ .split(/\s*(?![^(]*\)),\s*/)
1182
+ .map(function (s) {
1183
+ return s.replace(/\u200C/g, ',');
1184
+ });
1185
+ }
1186
+ function declaration() {
1187
+ var pos = position();
1188
+ var propMatch = match(/^(\*?[-#\/\*\\\w]+(\[[0-9a-z_-]+\])?)\s*/);
1189
+ if (!propMatch) {
1190
+ return;
1191
+ }
1192
+ var prop = trim(propMatch[0]);
1193
+ if (!match(/^:\s*/)) {
1194
+ return error("property missing ':'");
1195
+ }
1196
+ var val = match(/^((?:'(?:\\'|.)*?'|"(?:\\"|.)*?"|\([^\)]*?\)|[^};])+)/);
1197
+ var ret = pos({
1198
+ type: 'declaration',
1199
+ property: prop.replace(commentre, ''),
1200
+ value: val ? trim(val[0]).replace(commentre, '') : ''
1201
+ });
1202
+ match(/^[;\s]*/);
1203
+ return ret;
1204
+ }
1205
+ function declarations() {
1206
+ var decls = [];
1207
+ if (!open()) {
1208
+ return error("missing '{'");
1209
+ }
1210
+ comments(decls);
1211
+ var decl;
1212
+ while ((decl = declaration())) {
1213
+ if (decl !== false) {
1214
+ decls.push(decl);
1215
+ comments(decls);
1216
+ }
1217
+ decl = declaration();
1218
+ }
1219
+ if (!close()) {
1220
+ return error("missing '}'");
1221
+ }
1222
+ return decls;
1223
+ }
1224
+ function keyframe() {
1225
+ var m;
1226
+ var vals = [];
1227
+ var pos = position();
1228
+ while ((m = match(/^((\d+\.\d+|\.\d+|\d+)%?|[a-z]+)\s*/))) {
1229
+ vals.push(m[1]);
1230
+ match(/^,\s*/);
1231
+ }
1232
+ if (!vals.length) {
1233
+ return;
1234
+ }
1235
+ return pos({
1236
+ type: 'keyframe',
1237
+ values: vals,
1238
+ declarations: declarations()
1239
+ });
1240
+ }
1241
+ function atkeyframes() {
1242
+ var pos = position();
1243
+ var m = match(/^@([-\w]+)?keyframes\s*/);
1244
+ if (!m) {
1245
+ return;
1246
+ }
1247
+ var vendor = m[1];
1248
+ m = match(/^([-\w]+)\s*/);
1249
+ if (!m) {
1250
+ return error('@keyframes missing name');
1251
+ }
1252
+ var name = m[1];
1253
+ if (!open()) {
1254
+ return error("@keyframes missing '{'");
1255
+ }
1256
+ var frame;
1257
+ var frames = comments();
1258
+ while ((frame = keyframe())) {
1259
+ frames.push(frame);
1260
+ frames = frames.concat(comments());
1261
+ }
1262
+ if (!close()) {
1263
+ return error("@keyframes missing '}'");
1264
+ }
1265
+ return pos({
1266
+ type: 'keyframes',
1267
+ name: name,
1268
+ vendor: vendor,
1269
+ keyframes: frames
1270
+ });
1271
+ }
1272
+ function atsupports() {
1273
+ var pos = position();
1274
+ var m = match(/^@supports *([^{]+)/);
1275
+ if (!m) {
1276
+ return;
1277
+ }
1278
+ var supports = trim(m[1]);
1279
+ if (!open()) {
1280
+ return error("@supports missing '{'");
1281
+ }
1282
+ var style = comments().concat(rules());
1283
+ if (!close()) {
1284
+ return error("@supports missing '}'");
1285
+ }
1286
+ return pos({
1287
+ type: 'supports',
1288
+ supports: supports,
1289
+ rules: style
1290
+ });
1291
+ }
1292
+ function athost() {
1293
+ var pos = position();
1294
+ var m = match(/^@host\s*/);
1295
+ if (!m) {
1296
+ return;
1297
+ }
1298
+ if (!open()) {
1299
+ return error("@host missing '{'");
1300
+ }
1301
+ var style = comments().concat(rules());
1302
+ if (!close()) {
1303
+ return error("@host missing '}'");
1304
+ }
1305
+ return pos({
1306
+ type: 'host',
1307
+ rules: style
1308
+ });
1309
+ }
1310
+ function atmedia() {
1311
+ var pos = position();
1312
+ var m = match(/^@media *([^{]+)/);
1313
+ if (!m) {
1314
+ return;
1315
+ }
1316
+ var media = trim(m[1]);
1317
+ if (!open()) {
1318
+ return error("@media missing '{'");
1319
+ }
1320
+ var style = comments().concat(rules());
1321
+ if (!close()) {
1322
+ return error("@media missing '}'");
1323
+ }
1324
+ return pos({
1325
+ type: 'media',
1326
+ media: media,
1327
+ rules: style
1328
+ });
1329
+ }
1330
+ function atcustommedia() {
1331
+ var pos = position();
1332
+ var m = match(/^@custom-media\s+(--[^\s]+)\s*([^{;]+);/);
1333
+ if (!m) {
1334
+ return;
1335
+ }
1336
+ return pos({
1337
+ type: 'custom-media',
1338
+ name: trim(m[1]),
1339
+ media: trim(m[2])
1340
+ });
1341
+ }
1342
+ function atpage() {
1343
+ var pos = position();
1344
+ var m = match(/^@page */);
1345
+ if (!m) {
1346
+ return;
1347
+ }
1348
+ var sel = selector() || [];
1349
+ if (!open()) {
1350
+ return error("@page missing '{'");
1351
+ }
1352
+ var decls = comments();
1353
+ var decl;
1354
+ while ((decl = declaration())) {
1355
+ decls.push(decl);
1356
+ decls = decls.concat(comments());
1357
+ }
1358
+ if (!close()) {
1359
+ return error("@page missing '}'");
1360
+ }
1361
+ return pos({
1362
+ type: 'page',
1363
+ selectors: sel,
1364
+ declarations: decls
1365
+ });
1366
+ }
1367
+ function atdocument() {
1368
+ var pos = position();
1369
+ var m = match(/^@([-\w]+)?document *([^{]+)/);
1370
+ if (!m) {
1371
+ return;
1372
+ }
1373
+ var vendor = trim(m[1]);
1374
+ var doc = trim(m[2]);
1375
+ if (!open()) {
1376
+ return error("@document missing '{'");
1377
+ }
1378
+ var style = comments().concat(rules());
1379
+ if (!close()) {
1380
+ return error("@document missing '}'");
1381
+ }
1382
+ return pos({
1383
+ type: 'document',
1384
+ document: doc,
1385
+ vendor: vendor,
1386
+ rules: style
1387
+ });
1388
+ }
1389
+ function atfontface() {
1390
+ var pos = position();
1391
+ var m = match(/^@font-face\s*/);
1392
+ if (!m) {
1393
+ return;
1394
+ }
1395
+ if (!open()) {
1396
+ return error("@font-face missing '{'");
1397
+ }
1398
+ var decls = comments();
1399
+ var decl;
1400
+ while ((decl = declaration())) {
1401
+ decls.push(decl);
1402
+ decls = decls.concat(comments());
1403
+ }
1404
+ if (!close()) {
1405
+ return error("@font-face missing '}'");
1406
+ }
1407
+ return pos({
1408
+ type: 'font-face',
1409
+ declarations: decls
1410
+ });
1411
+ }
1412
+ var atimport = _compileAtrule('import');
1413
+ var atcharset = _compileAtrule('charset');
1414
+ var atnamespace = _compileAtrule('namespace');
1415
+ function _compileAtrule(name) {
1416
+ var re = new RegExp('^@' + name + '\\s*([^;]+);');
1417
+ return function () {
1418
+ var pos = position();
1419
+ var m = match(re);
1420
+ if (!m) {
1421
+ return;
1422
+ }
1423
+ var ret = { type: name };
1424
+ ret[name] = m[1].trim();
1425
+ return pos(ret);
1426
+ };
1427
+ }
1428
+ function atrule() {
1429
+ if (css[0] !== '@') {
1430
+ return;
1431
+ }
1432
+ return (atkeyframes() ||
1433
+ atmedia() ||
1434
+ atcustommedia() ||
1435
+ atsupports() ||
1436
+ atimport() ||
1437
+ atcharset() ||
1438
+ atnamespace() ||
1439
+ atdocument() ||
1440
+ atpage() ||
1441
+ athost() ||
1442
+ atfontface());
1443
+ }
1444
+ function rule() {
1445
+ var pos = position();
1446
+ var sel = selector();
1447
+ if (!sel) {
1448
+ return error('selector missing');
1449
+ }
1450
+ comments();
1451
+ return pos({
1452
+ type: 'rule',
1453
+ selectors: sel,
1454
+ declarations: declarations()
1455
+ });
1456
+ }
1457
+ return addParent(stylesheet());
1458
+ }
1459
+ function trim(str) {
1460
+ return str ? str.replace(/^\s+|\s+$/g, '') : '';
1461
+ }
1462
+ function addParent(obj, parent) {
1463
+ var isNode = obj && typeof obj.type === 'string';
1464
+ var childParent = isNode ? obj : parent;
1465
+ for (var _i = 0, _a = Object.keys(obj); _i < _a.length; _i++) {
1466
+ var k = _a[_i];
1467
+ var value = obj[k];
1468
+ if (Array.isArray(value)) {
1469
+ value.forEach(function (v) {
1470
+ addParent(v, childParent);
1471
+ });
1472
+ }
1473
+ else if (value && typeof value === 'object') {
1474
+ addParent(value, childParent);
1475
+ }
1476
+ }
1477
+ if (isNode) {
1478
+ Object.defineProperty(obj, 'parent', {
1479
+ configurable: true,
1480
+ writable: true,
1481
+ enumerable: false,
1482
+ value: parent || null
1483
+ });
1484
+ }
1485
+ return obj;
1487
1486
  }
1488
1487
 
1489
- var tagMap = {
1490
- script: 'noscript',
1491
- altglyph: 'altGlyph',
1492
- altglyphdef: 'altGlyphDef',
1493
- altglyphitem: 'altGlyphItem',
1494
- animatecolor: 'animateColor',
1495
- animatemotion: 'animateMotion',
1496
- animatetransform: 'animateTransform',
1497
- clippath: 'clipPath',
1498
- feblend: 'feBlend',
1499
- fecolormatrix: 'feColorMatrix',
1500
- fecomponenttransfer: 'feComponentTransfer',
1501
- fecomposite: 'feComposite',
1502
- feconvolvematrix: 'feConvolveMatrix',
1503
- fediffuselighting: 'feDiffuseLighting',
1504
- fedisplacementmap: 'feDisplacementMap',
1505
- fedistantlight: 'feDistantLight',
1506
- fedropshadow: 'feDropShadow',
1507
- feflood: 'feFlood',
1508
- fefunca: 'feFuncA',
1509
- fefuncb: 'feFuncB',
1510
- fefuncg: 'feFuncG',
1511
- fefuncr: 'feFuncR',
1512
- fegaussianblur: 'feGaussianBlur',
1513
- feimage: 'feImage',
1514
- femerge: 'feMerge',
1515
- femergenode: 'feMergeNode',
1516
- femorphology: 'feMorphology',
1517
- feoffset: 'feOffset',
1518
- fepointlight: 'fePointLight',
1519
- fespecularlighting: 'feSpecularLighting',
1520
- fespotlight: 'feSpotLight',
1521
- fetile: 'feTile',
1522
- feturbulence: 'feTurbulence',
1523
- foreignobject: 'foreignObject',
1524
- glyphref: 'glyphRef',
1525
- lineargradient: 'linearGradient',
1526
- radialgradient: 'radialGradient'
1527
- };
1528
- function getTagName(n) {
1529
- var tagName = tagMap[n.tagName] ? tagMap[n.tagName] : n.tagName;
1530
- if (tagName === 'link' && n.attributes._cssText) {
1531
- tagName = 'style';
1532
- }
1533
- return tagName;
1534
- }
1535
- function escapeRegExp(str) {
1536
- return str.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
1537
- }
1538
- var HOVER_SELECTOR = /([^\\]):hover/;
1539
- var HOVER_SELECTOR_GLOBAL = new RegExp(HOVER_SELECTOR.source, 'g');
1540
- function addHoverClass(cssText, cache) {
1541
- var _a;
1542
- if (!((_a = window === null || window === void 0 ? void 0 : window.HIG_CONFIGURATION) === null || _a === void 0 ? void 0 : _a.enableOnHoverClass)) {
1543
- return cssText;
1544
- }
1545
- var cachedStyle = cache === null || cache === void 0 ? void 0 : cache.stylesWithHoverClass.get(cssText);
1546
- if (cachedStyle)
1547
- return cachedStyle;
1548
- var ast = parse(cssText, {
1549
- silent: true
1550
- });
1551
- if (!ast.stylesheet) {
1552
- return cssText;
1553
- }
1554
- var selectors = [];
1555
- ast.stylesheet.rules.forEach(function (rule) {
1556
- if ('selectors' in rule) {
1557
- (rule.selectors || []).forEach(function (selector) {
1558
- if (HOVER_SELECTOR.test(selector)) {
1559
- selectors.push(selector);
1560
- }
1561
- });
1562
- }
1563
- });
1564
- if (selectors.length === 0) {
1565
- return cssText;
1566
- }
1567
- var selectorMatcher = new RegExp(selectors
1568
- .filter(function (selector, index) { return selectors.indexOf(selector) === index; })
1569
- .sort(function (a, b) { return b.length - a.length; })
1570
- .map(function (selector) {
1571
- return escapeRegExp(selector);
1572
- })
1573
- .join('|'), 'g');
1574
- var result = cssText.replace(selectorMatcher, function (selector) {
1575
- var newSelector = selector.replace(HOVER_SELECTOR_GLOBAL, '$1.\\:hover');
1576
- return selector + ", " + newSelector;
1577
- });
1578
- cache === null || cache === void 0 ? void 0 : cache.stylesWithHoverClass.set(cssText, result);
1579
- return result;
1580
- }
1581
- function createCache() {
1582
- var stylesWithHoverClass = new Map();
1583
- return {
1584
- stylesWithHoverClass: stylesWithHoverClass
1585
- };
1586
- }
1587
- function buildNode(n, options) {
1588
- var doc = options.doc, hackCss = options.hackCss, cache = options.cache;
1589
- switch (n.type) {
1590
- case NodeType.Document:
1591
- return doc.implementation.createDocument(null, '', null);
1592
- case NodeType.DocumentType:
1593
- return doc.implementation.createDocumentType(n.name || 'html', n.publicId, n.systemId);
1594
- case NodeType.Element:
1595
- var tagName = getTagName(n);
1596
- var node_1;
1597
- if (n.isSVG) {
1598
- node_1 = doc.createElementNS('http://www.w3.org/2000/svg', tagName);
1599
- }
1600
- else {
1601
- node_1 = doc.createElement(tagName);
1602
- }
1603
- var _loop_1 = function (name_1) {
1604
- if (!n.attributes.hasOwnProperty(name_1)) {
1605
- return "continue";
1606
- }
1607
- var value = n.attributes[name_1];
1608
- if (tagName === 'option' && name_1 === 'selected' && value === false) {
1609
- return "continue";
1610
- }
1611
- value =
1612
- typeof value === 'boolean' || typeof value === 'number' ? '' : value;
1613
- if (!name_1.startsWith('rr_')) {
1614
- var isTextarea = tagName === 'textarea' && name_1 === 'value';
1615
- var isRemoteOrDynamicCss = tagName === 'style' && name_1 === '_cssText';
1616
- if (isRemoteOrDynamicCss && hackCss) {
1617
- value = addHoverClass(value, cache);
1618
- if (typeof value === 'string') {
1619
- var regex = /url\(\"https:\/\/\S*(.eot|.woff2|.ttf|.woff)\S*\"\)/gm;
1620
- var m = void 0;
1621
- var fontUrls_1 = [];
1622
- var PROXY_URL_1 = 'https://replay-cors-proxy.highlightrun.workers.dev';
1623
- while ((m = regex.exec(value)) !== null) {
1624
- if (m.index === regex.lastIndex) {
1625
- regex.lastIndex++;
1626
- }
1627
- m.forEach(function (match, groupIndex) {
1628
- if (groupIndex === 0) {
1629
- var url = match.slice(5, match.length - 2);
1630
- fontUrls_1.push({
1631
- originalUrl: url,
1632
- proxyUrl: url.replace(url, PROXY_URL_1 + "?url=" + url)
1633
- });
1634
- }
1635
- });
1636
- }
1637
- fontUrls_1.forEach(function (urlPair) {
1638
- value = value.replace(urlPair.originalUrl, urlPair.proxyUrl);
1639
- });
1640
- }
1641
- }
1642
- if (isTextarea || isRemoteOrDynamicCss) {
1643
- var child = doc.createTextNode(value);
1644
- for (var _i = 0, _a = Array.from(node_1.childNodes); _i < _a.length; _i++) {
1645
- var c = _a[_i];
1646
- if (c.nodeType === node_1.TEXT_NODE) {
1647
- node_1.removeChild(c);
1648
- }
1649
- }
1650
- node_1.appendChild(child);
1651
- return "continue";
1652
- }
1653
- try {
1654
- if (n.isSVG && name_1 === 'xlink:href') {
1655
- node_1.setAttributeNS('http://www.w3.org/1999/xlink', name_1, value);
1656
- }
1657
- else if (name_1 === 'onload' ||
1658
- name_1 === 'onclick' ||
1659
- name_1.substring(0, 7) === 'onmouse') {
1660
- node_1.setAttribute('_' + name_1, value);
1661
- }
1662
- else if (tagName === 'meta' &&
1663
- n.attributes['http-equiv'] === 'Content-Security-Policy' &&
1664
- name_1 === 'content') {
1665
- node_1.setAttribute('csp-content', value);
1666
- return "continue";
1667
- }
1668
- else if (tagName === 'link' &&
1669
- n.attributes.rel === 'preload' &&
1670
- n.attributes.as === 'script') {
1671
- }
1672
- else if (tagName === 'link' &&
1673
- n.attributes.rel === 'prefetch' &&
1674
- typeof n.attributes.href === 'string' &&
1675
- n.attributes.href.endsWith('.js')) {
1676
- }
1677
- else if (tagName === 'img' &&
1678
- n.attributes.srcset &&
1679
- n.attributes.rr_dataURL) {
1680
- node_1.setAttribute('rrweb-original-srcset', n.attributes.srcset);
1681
- }
1682
- else {
1683
- node_1.setAttribute(name_1, value);
1684
- }
1685
- }
1686
- catch (error) {
1687
- }
1688
- }
1689
- else {
1690
- if (tagName === 'canvas' && name_1 === 'rr_dataURL') {
1691
- var image_1 = document.createElement('img');
1692
- image_1.src = value;
1693
- image_1.onload = function () {
1694
- var ctx = node_1.getContext('2d');
1695
- if (ctx) {
1696
- ctx.drawImage(image_1, 0, 0, image_1.width, image_1.height);
1697
- }
1698
- };
1699
- }
1700
- else if (tagName === 'img' && name_1 === 'rr_dataURL') {
1701
- var image = node_1;
1702
- if (!image.currentSrc.startsWith('data:')) {
1703
- image.setAttribute('rrweb-original-src', n.attributes.src);
1704
- image.src = value;
1705
- image.setAttribute('rrweb-inline-src', value);
1706
- }
1707
- }
1708
- if (name_1 === 'rr_width') {
1709
- node_1.style.width = value;
1710
- }
1711
- else if (name_1 === 'rr_height') {
1712
- node_1.style.height = value;
1713
- }
1714
- else if (name_1 === 'rr_mediaCurrentTime') {
1715
- node_1.currentTime = n.attributes
1716
- .rr_mediaCurrentTime;
1717
- }
1718
- else if (name_1 === 'rr_mediaState') {
1719
- switch (value) {
1720
- case 'played':
1721
- node_1
1722
- .play()["catch"](function (e) { return console.warn('media playback error', e); });
1723
- break;
1724
- case 'paused':
1725
- node_1.pause();
1726
- break;
1727
- }
1728
- }
1729
- }
1730
- };
1731
- for (var name_1 in n.attributes) {
1732
- _loop_1(name_1);
1733
- }
1734
- if (tagName === 'img') {
1735
- var image = node_1;
1736
- if (!image.currentSrc.startsWith('data:')) {
1737
- var inlineSrc = image.getAttribute('rrweb-inline-src');
1738
- if (inlineSrc === null || inlineSrc === void 0 ? void 0 : inlineSrc.startsWith('data:')) {
1739
- image.src = inlineSrc;
1740
- }
1741
- }
1742
- }
1743
- if (n.isShadowHost) {
1744
- if (!node_1.shadowRoot) {
1745
- node_1.attachShadow({ mode: 'open' });
1746
- }
1747
- else {
1748
- while (node_1.shadowRoot.firstChild) {
1749
- node_1.shadowRoot.removeChild(node_1.shadowRoot.firstChild);
1750
- }
1751
- }
1752
- }
1753
- return node_1;
1754
- case NodeType.Text:
1755
- return doc.createTextNode(n.isStyle && hackCss
1756
- ? addHoverClass(n.textContent, cache)
1757
- : n.textContent);
1758
- case NodeType.CDATA:
1759
- return doc.createCDATASection(n.textContent);
1760
- case NodeType.Comment:
1761
- return doc.createComment(n.textContent);
1762
- default:
1763
- return null;
1764
- }
1765
- }
1766
- function buildNodeWithSN(n, options) {
1767
- 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;
1768
- var node = buildNode(n, { doc: doc, hackCss: hackCss, cache: cache });
1769
- if (!node) {
1770
- return null;
1771
- }
1772
- if (n.rootId) {
1773
- console.assert(mirror.getNode(n.rootId) === doc, 'Target document should have the same root id.');
1774
- }
1775
- if (n.type === NodeType.Document) {
1776
- doc.close();
1777
- doc.open();
1778
- if (n.compatMode === 'BackCompat' &&
1779
- n.childNodes &&
1780
- n.childNodes[0].type !== NodeType.DocumentType) {
1781
- if (n.childNodes[0].type === NodeType.Element &&
1782
- 'xmlns' in n.childNodes[0].attributes &&
1783
- n.childNodes[0].attributes.xmlns === 'http://www.w3.org/1999/xhtml') {
1784
- doc.write('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">');
1785
- }
1786
- else {
1787
- doc.write('<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "">');
1788
- }
1789
- }
1790
- node = doc;
1791
- }
1792
- mirror.add(node, n);
1793
- if ((n.type === NodeType.Document || n.type === NodeType.Element) &&
1794
- !skipChild) {
1795
- for (var _i = 0, _c = n.childNodes; _i < _c.length; _i++) {
1796
- var childN = _c[_i];
1797
- var childNode = buildNodeWithSN(childN, {
1798
- doc: doc,
1799
- mirror: mirror,
1800
- skipChild: false,
1801
- hackCss: hackCss,
1802
- afterAppend: afterAppend,
1803
- cache: cache
1804
- });
1805
- if (!childNode) {
1806
- console.warn('Failed to rebuild', childN);
1807
- continue;
1808
- }
1809
- if (childN.isShadow && isElement(node) && node.shadowRoot) {
1810
- node.shadowRoot.appendChild(childNode);
1811
- }
1812
- else {
1813
- node.appendChild(childNode);
1814
- }
1815
- if (afterAppend) {
1816
- afterAppend(childNode);
1817
- }
1818
- }
1819
- }
1820
- return node;
1821
- }
1822
- function visit(mirror, onVisit) {
1823
- function walk(node) {
1824
- onVisit(node);
1825
- }
1826
- for (var _i = 0, _a = mirror.getIds(); _i < _a.length; _i++) {
1827
- var id = _a[_i];
1828
- if (mirror.has(id)) {
1829
- walk(mirror.getNode(id));
1830
- }
1831
- }
1832
- }
1833
- function handleScroll(node, mirror) {
1834
- var n = mirror.getMeta(node);
1835
- if ((n === null || n === void 0 ? void 0 : n.type) !== NodeType.Element) {
1836
- return;
1837
- }
1838
- var el = node;
1839
- for (var name_2 in n.attributes) {
1840
- if (!(n.attributes.hasOwnProperty(name_2) && name_2.startsWith('rr_'))) {
1841
- continue;
1842
- }
1843
- var value = n.attributes[name_2];
1844
- if (name_2 === 'rr_scrollLeft') {
1845
- el.scrollLeft = value;
1846
- }
1847
- if (name_2 === 'rr_scrollTop') {
1848
- el.scrollTop = value;
1849
- }
1850
- }
1851
- }
1852
- function rebuild(n, options) {
1853
- 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() : _b;
1854
- var node = buildNodeWithSN(n, {
1855
- doc: doc,
1856
- mirror: mirror,
1857
- skipChild: false,
1858
- hackCss: hackCss,
1859
- afterAppend: afterAppend,
1860
- cache: cache
1861
- });
1862
- visit(mirror, function (visitedNode) {
1863
- if (onVisit) {
1864
- onVisit(visitedNode);
1865
- }
1866
- handleScroll(visitedNode, mirror);
1867
- });
1868
- return node;
1488
+ var tagMap = {
1489
+ script: 'noscript',
1490
+ altglyph: 'altGlyph',
1491
+ altglyphdef: 'altGlyphDef',
1492
+ altglyphitem: 'altGlyphItem',
1493
+ animatecolor: 'animateColor',
1494
+ animatemotion: 'animateMotion',
1495
+ animatetransform: 'animateTransform',
1496
+ clippath: 'clipPath',
1497
+ feblend: 'feBlend',
1498
+ fecolormatrix: 'feColorMatrix',
1499
+ fecomponenttransfer: 'feComponentTransfer',
1500
+ fecomposite: 'feComposite',
1501
+ feconvolvematrix: 'feConvolveMatrix',
1502
+ fediffuselighting: 'feDiffuseLighting',
1503
+ fedisplacementmap: 'feDisplacementMap',
1504
+ fedistantlight: 'feDistantLight',
1505
+ fedropshadow: 'feDropShadow',
1506
+ feflood: 'feFlood',
1507
+ fefunca: 'feFuncA',
1508
+ fefuncb: 'feFuncB',
1509
+ fefuncg: 'feFuncG',
1510
+ fefuncr: 'feFuncR',
1511
+ fegaussianblur: 'feGaussianBlur',
1512
+ feimage: 'feImage',
1513
+ femerge: 'feMerge',
1514
+ femergenode: 'feMergeNode',
1515
+ femorphology: 'feMorphology',
1516
+ feoffset: 'feOffset',
1517
+ fepointlight: 'fePointLight',
1518
+ fespecularlighting: 'feSpecularLighting',
1519
+ fespotlight: 'feSpotLight',
1520
+ fetile: 'feTile',
1521
+ feturbulence: 'feTurbulence',
1522
+ foreignobject: 'foreignObject',
1523
+ glyphref: 'glyphRef',
1524
+ lineargradient: 'linearGradient',
1525
+ radialgradient: 'radialGradient'
1526
+ };
1527
+ function getTagName(n) {
1528
+ var tagName = tagMap[n.tagName] ? tagMap[n.tagName] : n.tagName;
1529
+ if (tagName === 'link' && n.attributes._cssText) {
1530
+ tagName = 'style';
1531
+ }
1532
+ return tagName;
1533
+ }
1534
+ function escapeRegExp(str) {
1535
+ return str.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
1536
+ }
1537
+ var HOVER_SELECTOR = /([^\\]):hover/;
1538
+ var HOVER_SELECTOR_GLOBAL = new RegExp(HOVER_SELECTOR.source, 'g');
1539
+ function addHoverClass(cssText, cache) {
1540
+ var _a;
1541
+ if (!((_a = window === null || window === void 0 ? void 0 : window.HIG_CONFIGURATION) === null || _a === void 0 ? void 0 : _a.enableOnHoverClass)) {
1542
+ return cssText;
1543
+ }
1544
+ var cachedStyle = cache === null || cache === void 0 ? void 0 : cache.stylesWithHoverClass.get(cssText);
1545
+ if (cachedStyle)
1546
+ return cachedStyle;
1547
+ var ast = parse(cssText, {
1548
+ silent: true
1549
+ });
1550
+ if (!ast.stylesheet) {
1551
+ return cssText;
1552
+ }
1553
+ var selectors = [];
1554
+ ast.stylesheet.rules.forEach(function (rule) {
1555
+ if ('selectors' in rule) {
1556
+ (rule.selectors || []).forEach(function (selector) {
1557
+ if (HOVER_SELECTOR.test(selector)) {
1558
+ selectors.push(selector);
1559
+ }
1560
+ });
1561
+ }
1562
+ });
1563
+ if (selectors.length === 0) {
1564
+ return cssText;
1565
+ }
1566
+ var selectorMatcher = new RegExp(selectors
1567
+ .filter(function (selector, index) { return selectors.indexOf(selector) === index; })
1568
+ .sort(function (a, b) { return b.length - a.length; })
1569
+ .map(function (selector) {
1570
+ return escapeRegExp(selector);
1571
+ })
1572
+ .join('|'), 'g');
1573
+ var result = cssText.replace(selectorMatcher, function (selector) {
1574
+ var newSelector = selector.replace(HOVER_SELECTOR_GLOBAL, '$1.\\:hover');
1575
+ return "".concat(selector, ", ").concat(newSelector);
1576
+ });
1577
+ cache === null || cache === void 0 ? void 0 : cache.stylesWithHoverClass.set(cssText, result);
1578
+ return result;
1579
+ }
1580
+ function createCache() {
1581
+ var stylesWithHoverClass = new Map();
1582
+ return {
1583
+ stylesWithHoverClass: stylesWithHoverClass
1584
+ };
1585
+ }
1586
+ function buildNode(n, options) {
1587
+ var doc = options.doc, hackCss = options.hackCss, cache = options.cache;
1588
+ switch (n.type) {
1589
+ case NodeType.Document:
1590
+ return doc.implementation.createDocument(null, '', null);
1591
+ case NodeType.DocumentType:
1592
+ return doc.implementation.createDocumentType(n.name || 'html', n.publicId, n.systemId);
1593
+ case NodeType.Element:
1594
+ var tagName = getTagName(n);
1595
+ var node_1;
1596
+ if (n.isSVG) {
1597
+ node_1 = doc.createElementNS('http://www.w3.org/2000/svg', tagName);
1598
+ }
1599
+ else {
1600
+ node_1 = doc.createElement(tagName);
1601
+ }
1602
+ var _loop_1 = function (name_1) {
1603
+ if (!n.attributes.hasOwnProperty(name_1)) {
1604
+ return "continue";
1605
+ }
1606
+ var value = n.attributes[name_1];
1607
+ if (tagName === 'option' && name_1 === 'selected' && value === false) {
1608
+ return "continue";
1609
+ }
1610
+ value =
1611
+ typeof value === 'boolean' || typeof value === 'number' ? '' : value;
1612
+ if (!name_1.startsWith('rr_')) {
1613
+ var isTextarea = tagName === 'textarea' && name_1 === 'value';
1614
+ var isRemoteOrDynamicCss = tagName === 'style' && name_1 === '_cssText';
1615
+ if (isRemoteOrDynamicCss && hackCss) {
1616
+ value = addHoverClass(value, cache);
1617
+ if (typeof value === 'string') {
1618
+ var regex = /url\(\"https:\/\/\S*(.eot|.woff2|.ttf|.woff)\S*\"\)/gm;
1619
+ var m = void 0;
1620
+ var fontUrls_1 = [];
1621
+ var PROXY_URL_1 = 'https://replay-cors-proxy.highlightrun.workers.dev';
1622
+ while ((m = regex.exec(value)) !== null) {
1623
+ if (m.index === regex.lastIndex) {
1624
+ regex.lastIndex++;
1625
+ }
1626
+ m.forEach(function (match, groupIndex) {
1627
+ if (groupIndex === 0) {
1628
+ var url = match.slice(5, match.length - 2);
1629
+ fontUrls_1.push({
1630
+ originalUrl: url,
1631
+ proxyUrl: url.replace(url, "".concat(PROXY_URL_1, "?url=").concat(url))
1632
+ });
1633
+ }
1634
+ });
1635
+ }
1636
+ fontUrls_1.forEach(function (urlPair) {
1637
+ value = value.replace(urlPair.originalUrl, urlPair.proxyUrl);
1638
+ });
1639
+ }
1640
+ }
1641
+ if (isTextarea || isRemoteOrDynamicCss) {
1642
+ var child = doc.createTextNode(value);
1643
+ for (var _i = 0, _a = Array.from(node_1.childNodes); _i < _a.length; _i++) {
1644
+ var c = _a[_i];
1645
+ if (c.nodeType === node_1.TEXT_NODE) {
1646
+ node_1.removeChild(c);
1647
+ }
1648
+ }
1649
+ node_1.appendChild(child);
1650
+ return "continue";
1651
+ }
1652
+ try {
1653
+ if (n.isSVG && name_1 === 'xlink:href') {
1654
+ node_1.setAttributeNS('http://www.w3.org/1999/xlink', name_1, value);
1655
+ }
1656
+ else if (name_1 === 'onload' ||
1657
+ name_1 === 'onclick' ||
1658
+ name_1.substring(0, 7) === 'onmouse') {
1659
+ node_1.setAttribute('_' + name_1, value);
1660
+ }
1661
+ else if (tagName === 'meta' &&
1662
+ n.attributes['http-equiv'] === 'Content-Security-Policy' &&
1663
+ name_1 === 'content') {
1664
+ node_1.setAttribute('csp-content', value);
1665
+ return "continue";
1666
+ }
1667
+ else if (tagName === 'link' &&
1668
+ n.attributes.rel === 'preload' &&
1669
+ n.attributes.as === 'script') {
1670
+ }
1671
+ else if (tagName === 'link' &&
1672
+ n.attributes.rel === 'prefetch' &&
1673
+ typeof n.attributes.href === 'string' &&
1674
+ n.attributes.href.endsWith('.js')) {
1675
+ }
1676
+ else if (tagName === 'img' &&
1677
+ n.attributes.srcset &&
1678
+ n.attributes.rr_dataURL) {
1679
+ node_1.setAttribute('rrweb-original-srcset', n.attributes.srcset);
1680
+ }
1681
+ else {
1682
+ node_1.setAttribute(name_1, value);
1683
+ }
1684
+ }
1685
+ catch (error) {
1686
+ }
1687
+ }
1688
+ else {
1689
+ if (tagName === 'canvas' && name_1 === 'rr_dataURL') {
1690
+ var image_1 = document.createElement('img');
1691
+ image_1.src = value;
1692
+ image_1.onload = function () {
1693
+ var ctx = node_1.getContext('2d');
1694
+ if (ctx) {
1695
+ ctx.drawImage(image_1, 0, 0, image_1.width, image_1.height);
1696
+ }
1697
+ };
1698
+ }
1699
+ else if (tagName === 'img' && name_1 === 'rr_dataURL') {
1700
+ var image = node_1;
1701
+ if (!image.currentSrc.startsWith('data:')) {
1702
+ image.setAttribute('rrweb-original-src', n.attributes.src);
1703
+ image.src = value;
1704
+ image.setAttribute('rrweb-inline-src', value);
1705
+ }
1706
+ }
1707
+ if (name_1 === 'rr_width') {
1708
+ node_1.style.width = value;
1709
+ }
1710
+ else if (name_1 === 'rr_height') {
1711
+ node_1.style.height = value;
1712
+ }
1713
+ else if (name_1 === 'rr_mediaCurrentTime') {
1714
+ node_1.currentTime = n.attributes
1715
+ .rr_mediaCurrentTime;
1716
+ }
1717
+ else if (name_1 === 'rr_mediaState') {
1718
+ switch (value) {
1719
+ case 'played':
1720
+ node_1
1721
+ .play()["catch"](function (e) { return console.warn('media playback error', e); });
1722
+ break;
1723
+ case 'paused':
1724
+ node_1.pause();
1725
+ break;
1726
+ }
1727
+ }
1728
+ }
1729
+ };
1730
+ for (var name_1 in n.attributes) {
1731
+ _loop_1(name_1);
1732
+ }
1733
+ if (tagName === 'img') {
1734
+ var image = node_1;
1735
+ if (!image.currentSrc.startsWith('data:')) {
1736
+ var inlineSrc = image.getAttribute('rrweb-inline-src');
1737
+ if (inlineSrc === null || inlineSrc === void 0 ? void 0 : inlineSrc.startsWith('data:')) {
1738
+ image.src = inlineSrc;
1739
+ }
1740
+ }
1741
+ }
1742
+ if (n.isShadowHost) {
1743
+ if (!node_1.shadowRoot) {
1744
+ node_1.attachShadow({ mode: 'open' });
1745
+ }
1746
+ else {
1747
+ while (node_1.shadowRoot.firstChild) {
1748
+ node_1.shadowRoot.removeChild(node_1.shadowRoot.firstChild);
1749
+ }
1750
+ }
1751
+ }
1752
+ return node_1;
1753
+ case NodeType.Text:
1754
+ return doc.createTextNode(n.isStyle && hackCss
1755
+ ? addHoverClass(n.textContent, cache)
1756
+ : n.textContent);
1757
+ case NodeType.CDATA:
1758
+ return doc.createCDATASection(n.textContent);
1759
+ case NodeType.Comment:
1760
+ return doc.createComment(n.textContent);
1761
+ default:
1762
+ return null;
1763
+ }
1764
+ }
1765
+ function buildNodeWithSN(n, options) {
1766
+ 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;
1767
+ var node = buildNode(n, { doc: doc, hackCss: hackCss, cache: cache });
1768
+ if (!node) {
1769
+ return null;
1770
+ }
1771
+ if (n.rootId) {
1772
+ console.assert(mirror.getNode(n.rootId) === doc, 'Target document should have the same root id.');
1773
+ }
1774
+ if (n.type === NodeType.Document) {
1775
+ doc.close();
1776
+ doc.open();
1777
+ if (n.compatMode === 'BackCompat' &&
1778
+ n.childNodes &&
1779
+ n.childNodes[0].type !== NodeType.DocumentType) {
1780
+ if (n.childNodes[0].type === NodeType.Element &&
1781
+ 'xmlns' in n.childNodes[0].attributes &&
1782
+ n.childNodes[0].attributes.xmlns === 'http://www.w3.org/1999/xhtml') {
1783
+ doc.write('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">');
1784
+ }
1785
+ else {
1786
+ doc.write('<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "">');
1787
+ }
1788
+ }
1789
+ node = doc;
1790
+ }
1791
+ mirror.add(node, n);
1792
+ if ((n.type === NodeType.Document || n.type === NodeType.Element) &&
1793
+ !skipChild) {
1794
+ for (var _i = 0, _c = n.childNodes; _i < _c.length; _i++) {
1795
+ var childN = _c[_i];
1796
+ var childNode = buildNodeWithSN(childN, {
1797
+ doc: doc,
1798
+ mirror: mirror,
1799
+ skipChild: false,
1800
+ hackCss: hackCss,
1801
+ afterAppend: afterAppend,
1802
+ cache: cache
1803
+ });
1804
+ if (!childNode) {
1805
+ console.warn('Failed to rebuild', childN);
1806
+ continue;
1807
+ }
1808
+ if (childN.isShadow && isElement(node) && node.shadowRoot) {
1809
+ node.shadowRoot.appendChild(childNode);
1810
+ }
1811
+ else {
1812
+ node.appendChild(childNode);
1813
+ }
1814
+ if (afterAppend) {
1815
+ afterAppend(childNode);
1816
+ }
1817
+ }
1818
+ }
1819
+ return node;
1820
+ }
1821
+ function visit(mirror, onVisit) {
1822
+ function walk(node) {
1823
+ onVisit(node);
1824
+ }
1825
+ for (var _i = 0, _a = mirror.getIds(); _i < _a.length; _i++) {
1826
+ var id = _a[_i];
1827
+ if (mirror.has(id)) {
1828
+ walk(mirror.getNode(id));
1829
+ }
1830
+ }
1831
+ }
1832
+ function handleScroll(node, mirror) {
1833
+ var n = mirror.getMeta(node);
1834
+ if ((n === null || n === void 0 ? void 0 : n.type) !== NodeType.Element) {
1835
+ return;
1836
+ }
1837
+ var el = node;
1838
+ for (var name_2 in n.attributes) {
1839
+ if (!(n.attributes.hasOwnProperty(name_2) && name_2.startsWith('rr_'))) {
1840
+ continue;
1841
+ }
1842
+ var value = n.attributes[name_2];
1843
+ if (name_2 === 'rr_scrollLeft') {
1844
+ el.scrollLeft = value;
1845
+ }
1846
+ if (name_2 === 'rr_scrollTop') {
1847
+ el.scrollTop = value;
1848
+ }
1849
+ }
1850
+ }
1851
+ function rebuild(n, options) {
1852
+ 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() : _b;
1853
+ var node = buildNodeWithSN(n, {
1854
+ doc: doc,
1855
+ mirror: mirror,
1856
+ skipChild: false,
1857
+ hackCss: hackCss,
1858
+ afterAppend: afterAppend,
1859
+ cache: cache
1860
+ });
1861
+ visit(mirror, function (visitedNode) {
1862
+ if (onVisit) {
1863
+ onVisit(visitedNode);
1864
+ }
1865
+ handleScroll(visitedNode, mirror);
1866
+ });
1867
+ return node;
1869
1868
  }
1870
1869
 
1871
1870
  export { IGNORED_NODE, Mirror, NodeType, addHoverClass, buildNodeWithSN, classMatchesRegex, createCache, createMirror, is2DCanvasBlank, isElement, isShadowRoot, maskInputValue, needMaskingText, obfuscateText, rebuild, serializeNodeWithId, snapshot, transformAttribute };