@posthog/rrweb-snapshot 0.0.30 → 0.0.32

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 (39) hide show
  1. package/dist/record.cjs +980 -0
  2. package/dist/record.cjs.map +1 -0
  3. package/dist/record.d.cts +265 -0
  4. package/dist/record.d.ts +265 -0
  5. package/dist/record.js +981 -0
  6. package/dist/record.js.map +1 -0
  7. package/dist/record.umd.cjs +1556 -0
  8. package/dist/record.umd.cjs.map +7 -0
  9. package/dist/record.umd.min.cjs +32 -0
  10. package/dist/record.umd.min.cjs.map +7 -0
  11. package/dist/replay.cjs +4356 -0
  12. package/dist/replay.cjs.map +1 -0
  13. package/dist/replay.d.cts +219 -0
  14. package/dist/replay.d.ts +219 -0
  15. package/dist/replay.js +4357 -0
  16. package/dist/replay.js.map +1 -0
  17. package/dist/replay.umd.cjs +4962 -0
  18. package/dist/replay.umd.cjs.map +7 -0
  19. package/dist/replay.umd.min.cjs +60 -0
  20. package/dist/replay.umd.min.cjs.map +7 -0
  21. package/dist/rrweb-snapshot.cjs +38 -5816
  22. package/dist/rrweb-snapshot.cjs.map +1 -1
  23. package/dist/rrweb-snapshot.js +24 -5802
  24. package/dist/rrweb-snapshot.js.map +1 -1
  25. package/dist/rrweb-snapshot.umd.cjs +5581 -5468
  26. package/dist/rrweb-snapshot.umd.cjs.map +4 -4
  27. package/dist/rrweb-snapshot.umd.min.cjs +15 -15
  28. package/dist/rrweb-snapshot.umd.min.cjs.map +4 -4
  29. package/dist/types-FDk_ocpu.js +535 -0
  30. package/dist/types-FDk_ocpu.js.map +1 -0
  31. package/dist/types-pLXhbZlp.cjs +534 -0
  32. package/dist/types-pLXhbZlp.cjs.map +1 -0
  33. package/dist/types-pLXhbZlp.umd.cjs +567 -0
  34. package/dist/types-pLXhbZlp.umd.cjs.map +7 -0
  35. package/dist/types-pLXhbZlp.umd.min.cjs +32 -0
  36. package/dist/types-pLXhbZlp.umd.min.cjs.map +7 -0
  37. package/package.json +26 -6
  38. /package/dist/{index.d.cts → rrweb-snapshot.d.cts} +0 -0
  39. /package/dist/{index.d.ts → rrweb-snapshot.d.ts} +0 -0
@@ -0,0 +1,980 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const types = require("./types-pLXhbZlp.cjs");
4
+ let _id = 1;
5
+ const tagNameRegex = new RegExp("[^a-z0-9-_:]");
6
+ const IGNORED_NODE = -2;
7
+ function genId() {
8
+ return _id++;
9
+ }
10
+ function getValidTagName(element) {
11
+ if (element instanceof HTMLFormElement) {
12
+ return "form";
13
+ }
14
+ const processedTagName = types.toLowerCase(element.tagName);
15
+ if (tagNameRegex.test(processedTagName)) {
16
+ return "div";
17
+ }
18
+ return processedTagName;
19
+ }
20
+ let canvasService;
21
+ let canvasCtx;
22
+ const SRCSET_NOT_SPACES = /^[^ \t\n\r\u000c]+/;
23
+ const SRCSET_COMMAS_OR_SPACES = /^[, \t\n\r\u000c]+/;
24
+ function getAbsoluteSrcsetString(doc, attributeValue) {
25
+ if (attributeValue.trim() === "") {
26
+ return attributeValue;
27
+ }
28
+ let pos = 0;
29
+ function collectCharacters(regEx) {
30
+ let chars;
31
+ const match = regEx.exec(attributeValue.substring(pos));
32
+ if (match) {
33
+ chars = match[0];
34
+ pos += chars.length;
35
+ return chars;
36
+ }
37
+ return "";
38
+ }
39
+ const output = [];
40
+ while (true) {
41
+ collectCharacters(SRCSET_COMMAS_OR_SPACES);
42
+ if (pos >= attributeValue.length) {
43
+ break;
44
+ }
45
+ let url = collectCharacters(SRCSET_NOT_SPACES);
46
+ if (url.slice(-1) === ",") {
47
+ url = absoluteToDoc(doc, url.substring(0, url.length - 1));
48
+ output.push(url);
49
+ } else {
50
+ let descriptorsStr = "";
51
+ url = absoluteToDoc(doc, url);
52
+ let inParens = false;
53
+ while (true) {
54
+ const c = attributeValue.charAt(pos);
55
+ if (c === "") {
56
+ output.push((url + descriptorsStr).trim());
57
+ break;
58
+ } else if (!inParens) {
59
+ if (c === ",") {
60
+ pos += 1;
61
+ output.push((url + descriptorsStr).trim());
62
+ break;
63
+ } else if (c === "(") {
64
+ inParens = true;
65
+ }
66
+ } else {
67
+ if (c === ")") {
68
+ inParens = false;
69
+ }
70
+ }
71
+ descriptorsStr += c;
72
+ pos += 1;
73
+ }
74
+ }
75
+ }
76
+ return output.join(", ");
77
+ }
78
+ const cachedDocument = /* @__PURE__ */ new WeakMap();
79
+ function absoluteToDoc(doc, attributeValue) {
80
+ if (!attributeValue || attributeValue.trim() === "") {
81
+ return attributeValue;
82
+ }
83
+ return getHref(doc, attributeValue);
84
+ }
85
+ function isSVGElement(el) {
86
+ return Boolean(el.tagName === "svg" || el.ownerSVGElement);
87
+ }
88
+ function getHref(doc, customHref) {
89
+ let a = cachedDocument.get(doc);
90
+ if (!a) {
91
+ a = doc.createElement("a");
92
+ cachedDocument.set(doc, a);
93
+ }
94
+ if (!customHref) {
95
+ customHref = "";
96
+ } else if (customHref.startsWith("blob:") || customHref.startsWith("data:")) {
97
+ return customHref;
98
+ }
99
+ a.setAttribute("href", customHref);
100
+ return a.href;
101
+ }
102
+ function transformAttribute(doc, tagName, name, value, element, dataURLOptions) {
103
+ if (!value) {
104
+ return value;
105
+ }
106
+ if (name === "src" || name === "href" && !(tagName === "use" && value[0] === "#")) {
107
+ const transformedValue = absoluteToDoc(doc, value);
108
+ if (tagName === "img" && transformedValue.startsWith("data:") && element) {
109
+ const img = element;
110
+ let processedDataURL = transformedValue;
111
+ if ((dataURLOptions == null ? void 0 : dataURLOptions.type) || (dataURLOptions == null ? void 0 : dataURLOptions.quality) !== void 0) {
112
+ processedDataURL = types.recompressBase64Image(
113
+ img,
114
+ transformedValue,
115
+ dataURLOptions.type,
116
+ dataURLOptions.quality
117
+ );
118
+ }
119
+ if (dataURLOptions == null ? void 0 : dataURLOptions.maxBase64ImageLength) {
120
+ processedDataURL = types.checkDataURLSize(
121
+ processedDataURL,
122
+ dataURLOptions.maxBase64ImageLength
123
+ );
124
+ }
125
+ return processedDataURL;
126
+ }
127
+ return transformedValue;
128
+ } else if (name === "xlink:href" && value[0] !== "#") {
129
+ return absoluteToDoc(doc, value);
130
+ } else if (name === "background" && (tagName === "table" || tagName === "td" || tagName === "th")) {
131
+ return absoluteToDoc(doc, value);
132
+ } else if (name === "srcset") {
133
+ return getAbsoluteSrcsetString(doc, value);
134
+ } else if (name === "style") {
135
+ return types.absolutifyURLs(value, getHref(doc));
136
+ } else if (tagName === "object" && name === "data") {
137
+ return absoluteToDoc(doc, value);
138
+ }
139
+ return value;
140
+ }
141
+ function ignoreAttribute(tagName, name, _value) {
142
+ return (tagName === "video" || tagName === "audio") && name === "autoplay";
143
+ }
144
+ function _isBlockedElement(element, blockClass, blockSelector) {
145
+ try {
146
+ if (typeof blockClass === "string") {
147
+ if (element.classList.contains(blockClass)) {
148
+ return true;
149
+ }
150
+ } else {
151
+ for (let eIndex = element.classList.length; eIndex--; ) {
152
+ const className = element.classList[eIndex];
153
+ if (blockClass.test(className)) {
154
+ return true;
155
+ }
156
+ }
157
+ }
158
+ if (blockSelector) {
159
+ return element.matches(blockSelector);
160
+ }
161
+ } catch (e) {
162
+ }
163
+ return false;
164
+ }
165
+ function classMatchesRegex(node, regex, checkAncestors) {
166
+ if (!node) return false;
167
+ if (node.nodeType !== node.ELEMENT_NODE) {
168
+ if (!checkAncestors) return false;
169
+ return classMatchesRegex(types.index.parentNode(node), regex, checkAncestors);
170
+ }
171
+ for (let eIndex = node.classList.length; eIndex--; ) {
172
+ const className = node.classList[eIndex];
173
+ if (regex.test(className)) {
174
+ return true;
175
+ }
176
+ }
177
+ if (!checkAncestors) return false;
178
+ return classMatchesRegex(types.index.parentNode(node), regex, checkAncestors);
179
+ }
180
+ function needMaskingText(node, maskTextClass, maskTextSelector, checkAncestors) {
181
+ let el;
182
+ if (types.isElement(node)) {
183
+ el = node;
184
+ if (!types.index.childNodes(el).length) {
185
+ return false;
186
+ }
187
+ } else if (types.index.parentElement(node) === null) {
188
+ return false;
189
+ } else {
190
+ el = types.index.parentElement(node);
191
+ }
192
+ try {
193
+ if (typeof maskTextClass === "string") {
194
+ if (checkAncestors) {
195
+ if (el.closest(`.${maskTextClass}`)) return true;
196
+ } else {
197
+ if (el.classList.contains(maskTextClass)) return true;
198
+ }
199
+ } else {
200
+ if (classMatchesRegex(el, maskTextClass, checkAncestors)) return true;
201
+ }
202
+ if (maskTextSelector) {
203
+ if (checkAncestors) {
204
+ if (el.closest(maskTextSelector)) return true;
205
+ } else {
206
+ if (el.matches(maskTextSelector)) return true;
207
+ }
208
+ }
209
+ } catch (e) {
210
+ }
211
+ return false;
212
+ }
213
+ function onceIframeLoaded(iframeEl, listener, iframeLoadTimeout) {
214
+ const win = iframeEl.contentWindow;
215
+ if (!win) {
216
+ return;
217
+ }
218
+ let fired = false;
219
+ let readyState;
220
+ try {
221
+ readyState = win.document.readyState;
222
+ } catch (error) {
223
+ return;
224
+ }
225
+ if (readyState !== "complete") {
226
+ const timer = setTimeout(() => {
227
+ if (!fired) {
228
+ listener();
229
+ fired = true;
230
+ }
231
+ }, iframeLoadTimeout);
232
+ iframeEl.addEventListener("load", () => {
233
+ clearTimeout(timer);
234
+ fired = true;
235
+ listener();
236
+ });
237
+ return;
238
+ }
239
+ const blankUrl = "about:blank";
240
+ if (win.location.href !== blankUrl || iframeEl.src === blankUrl || iframeEl.src === "") {
241
+ setTimeout(listener, 0);
242
+ return iframeEl.addEventListener("load", listener);
243
+ }
244
+ iframeEl.addEventListener("load", listener);
245
+ }
246
+ function onceStylesheetLoaded(link, listener, styleSheetLoadTimeout) {
247
+ let fired = false;
248
+ let styleSheetLoaded;
249
+ try {
250
+ styleSheetLoaded = link.sheet;
251
+ } catch (error) {
252
+ return;
253
+ }
254
+ if (styleSheetLoaded) return;
255
+ const timer = setTimeout(() => {
256
+ if (!fired) {
257
+ listener();
258
+ fired = true;
259
+ }
260
+ }, styleSheetLoadTimeout);
261
+ link.addEventListener("load", () => {
262
+ clearTimeout(timer);
263
+ fired = true;
264
+ listener();
265
+ });
266
+ }
267
+ function serializeNode(n, options) {
268
+ const {
269
+ doc,
270
+ mirror,
271
+ blockClass,
272
+ blockSelector,
273
+ needsMask,
274
+ inlineStylesheet,
275
+ maskInputOptions = {},
276
+ maskTextFn,
277
+ maskInputFn,
278
+ dataURLOptions = {},
279
+ inlineImages,
280
+ recordCanvas,
281
+ keepIframeSrcFn,
282
+ newlyAddedElement = false
283
+ } = options;
284
+ const rootId = getRootId(doc, mirror);
285
+ switch (n.nodeType) {
286
+ case n.DOCUMENT_NODE:
287
+ if (n.compatMode !== "CSS1Compat") {
288
+ return {
289
+ type: types.NodeType$1.Document,
290
+ childNodes: [],
291
+ compatMode: n.compatMode
292
+ // probably "BackCompat"
293
+ };
294
+ } else {
295
+ return {
296
+ type: types.NodeType$1.Document,
297
+ childNodes: []
298
+ };
299
+ }
300
+ case n.DOCUMENT_TYPE_NODE:
301
+ return {
302
+ type: types.NodeType$1.DocumentType,
303
+ name: n.name,
304
+ publicId: n.publicId,
305
+ systemId: n.systemId,
306
+ rootId
307
+ };
308
+ case n.ELEMENT_NODE:
309
+ return serializeElementNode(n, {
310
+ doc,
311
+ blockClass,
312
+ blockSelector,
313
+ inlineStylesheet,
314
+ maskInputOptions,
315
+ maskInputFn,
316
+ dataURLOptions,
317
+ inlineImages,
318
+ recordCanvas,
319
+ keepIframeSrcFn,
320
+ newlyAddedElement,
321
+ rootId
322
+ });
323
+ case n.TEXT_NODE:
324
+ return serializeTextNode(n, {
325
+ doc,
326
+ needsMask,
327
+ maskTextFn,
328
+ rootId
329
+ });
330
+ case n.CDATA_SECTION_NODE:
331
+ return {
332
+ type: types.NodeType$1.CDATA,
333
+ textContent: "",
334
+ rootId
335
+ };
336
+ case n.COMMENT_NODE:
337
+ return {
338
+ type: types.NodeType$1.Comment,
339
+ textContent: types.index.textContent(n) || "",
340
+ rootId
341
+ };
342
+ default:
343
+ return false;
344
+ }
345
+ }
346
+ function getRootId(doc, mirror) {
347
+ if (!mirror.hasNode(doc)) return void 0;
348
+ const docId = mirror.getId(doc);
349
+ return docId === 1 ? void 0 : docId;
350
+ }
351
+ function serializeTextNode(n, options) {
352
+ var _a;
353
+ const { needsMask, maskTextFn, rootId } = options;
354
+ const parent = types.index.parentNode(n);
355
+ const parentTagName = parent && parent.tagName;
356
+ let text = types.index.textContent(n);
357
+ const isStyle = parentTagName === "STYLE" ? true : void 0;
358
+ const isScript = parentTagName === "SCRIPT" ? true : void 0;
359
+ if (isStyle && text) {
360
+ try {
361
+ if (n.nextSibling || n.previousSibling) {
362
+ } else if ((_a = parent.sheet) == null ? void 0 : _a.cssRules) {
363
+ text = types.stringifyStylesheet(parent.sheet);
364
+ }
365
+ } catch (err) {
366
+ console.warn(
367
+ `Cannot get CSS styles from text's parentNode. Error: ${err}`,
368
+ n
369
+ );
370
+ }
371
+ text = types.absolutifyURLs(text, getHref(options.doc));
372
+ }
373
+ if (isScript) {
374
+ text = "SCRIPT_PLACEHOLDER";
375
+ }
376
+ if (!isStyle && !isScript && text && needsMask) {
377
+ text = maskTextFn ? maskTextFn(text, types.index.parentElement(n)) : text.replace(/[\S]/g, "*");
378
+ }
379
+ return {
380
+ type: types.NodeType$1.Text,
381
+ textContent: text || "",
382
+ isStyle,
383
+ rootId
384
+ };
385
+ }
386
+ function findStylesheet(doc, href) {
387
+ return Array.from(doc.styleSheets).find((s) => s.href === href);
388
+ }
389
+ function hrefFrom(n) {
390
+ return n.href;
391
+ }
392
+ function serializeElementNode(n, options) {
393
+ const {
394
+ doc,
395
+ blockClass,
396
+ blockSelector,
397
+ inlineStylesheet,
398
+ maskInputOptions = {},
399
+ maskInputFn,
400
+ dataURLOptions = {},
401
+ inlineImages,
402
+ recordCanvas,
403
+ keepIframeSrcFn,
404
+ newlyAddedElement = false,
405
+ rootId
406
+ } = options;
407
+ const needBlock = _isBlockedElement(n, blockClass, blockSelector);
408
+ const tagName = getValidTagName(n);
409
+ let attributes = {};
410
+ const len = n.attributes.length;
411
+ for (let i = 0; i < len; i++) {
412
+ const attr = n.attributes[i];
413
+ if (!ignoreAttribute(tagName, attr.name, attr.value)) {
414
+ attributes[attr.name] = transformAttribute(
415
+ doc,
416
+ tagName,
417
+ types.toLowerCase(attr.name),
418
+ attr.value,
419
+ n,
420
+ dataURLOptions
421
+ );
422
+ }
423
+ }
424
+ if (tagName === "link" && inlineStylesheet) {
425
+ const href = hrefFrom(n);
426
+ if (href) {
427
+ let stylesheet = findStylesheet(doc, href);
428
+ if (!stylesheet && href.includes(".css")) {
429
+ const rootDomain = window.location.origin;
430
+ const stylesheetPath = href.replace(window.location.href, "");
431
+ const potentialStylesheetHref = rootDomain + "/" + stylesheetPath;
432
+ stylesheet = findStylesheet(doc, potentialStylesheetHref);
433
+ }
434
+ let cssText = null;
435
+ if (stylesheet) {
436
+ cssText = types.stringifyStylesheet(stylesheet);
437
+ }
438
+ if (cssText) {
439
+ delete attributes.rel;
440
+ delete attributes.href;
441
+ attributes._cssText = cssText;
442
+ }
443
+ }
444
+ }
445
+ if (tagName === "style" && n.sheet && // TODO: Currently we only try to get dynamic stylesheet when it is an empty style element
446
+ !(n.innerText || types.index.textContent(n) || "").trim().length) {
447
+ const cssText = types.stringifyStylesheet(
448
+ n.sheet
449
+ );
450
+ if (cssText) {
451
+ attributes._cssText = cssText;
452
+ }
453
+ }
454
+ if (tagName === "input" || tagName === "textarea" || tagName === "select") {
455
+ const value = n.value;
456
+ const checked = n.checked;
457
+ if (attributes.type !== "radio" && attributes.type !== "checkbox" && attributes.type !== "submit" && attributes.type !== "button" && value) {
458
+ attributes.value = types.maskInputValue({
459
+ element: n,
460
+ type: types.getInputType(n),
461
+ tagName,
462
+ value,
463
+ maskInputOptions,
464
+ maskInputFn
465
+ });
466
+ } else if (checked) {
467
+ attributes.checked = checked;
468
+ }
469
+ }
470
+ if (tagName === "option") {
471
+ if (n.selected && !maskInputOptions["select"]) {
472
+ attributes.selected = true;
473
+ } else {
474
+ delete attributes.selected;
475
+ }
476
+ }
477
+ if (tagName === "dialog" && n.open) {
478
+ try {
479
+ attributes.rr_open_mode = n.matches("dialog:modal") ? "modal" : "non-modal";
480
+ } catch {
481
+ attributes.rr_open_mode = "modal";
482
+ attributes.ph_rr_could_not_detect_modal = true;
483
+ }
484
+ }
485
+ if (tagName === "canvas" && recordCanvas) {
486
+ if (n.__context === "2d") {
487
+ if (!types.is2DCanvasBlank(n)) {
488
+ attributes.rr_dataURL = n.toDataURL(
489
+ dataURLOptions.type,
490
+ dataURLOptions.quality
491
+ );
492
+ }
493
+ } else if (!("__context" in n)) {
494
+ const canvasDataURL = n.toDataURL(
495
+ dataURLOptions.type,
496
+ dataURLOptions.quality
497
+ );
498
+ const blankCanvas = doc.createElement("canvas");
499
+ blankCanvas.width = n.width;
500
+ blankCanvas.height = n.height;
501
+ const blankCanvasDataURL = blankCanvas.toDataURL(
502
+ dataURLOptions.type,
503
+ dataURLOptions.quality
504
+ );
505
+ if (canvasDataURL !== blankCanvasDataURL) {
506
+ attributes.rr_dataURL = canvasDataURL;
507
+ }
508
+ }
509
+ }
510
+ if (tagName === "img" && inlineImages) {
511
+ if (!canvasService) {
512
+ canvasService = doc.createElement("canvas");
513
+ canvasCtx = canvasService.getContext("2d");
514
+ }
515
+ const image = n;
516
+ const imageSrc = image.currentSrc || image.getAttribute("src") || "<unknown-src>";
517
+ const priorCrossOrigin = image.crossOrigin;
518
+ const recordInlineImage = () => {
519
+ image.removeEventListener("load", recordInlineImage);
520
+ try {
521
+ canvasService.width = image.naturalWidth;
522
+ canvasService.height = image.naturalHeight;
523
+ canvasCtx.drawImage(image, 0, 0);
524
+ attributes.rr_dataURL = canvasService.toDataURL(
525
+ dataURLOptions.type,
526
+ dataURLOptions.quality
527
+ );
528
+ } catch (err) {
529
+ if (image.crossOrigin !== "anonymous") {
530
+ image.crossOrigin = "anonymous";
531
+ if (image.complete && image.naturalWidth !== 0)
532
+ recordInlineImage();
533
+ else image.addEventListener("load", recordInlineImage);
534
+ return;
535
+ } else {
536
+ console.warn(
537
+ `Cannot inline img src=${imageSrc}! Error: ${err}`
538
+ );
539
+ }
540
+ }
541
+ if (image.crossOrigin === "anonymous") {
542
+ priorCrossOrigin ? attributes.crossOrigin = priorCrossOrigin : image.removeAttribute("crossorigin");
543
+ }
544
+ };
545
+ if (image.complete && image.naturalWidth !== 0) recordInlineImage();
546
+ else image.addEventListener("load", recordInlineImage);
547
+ }
548
+ if (tagName === "audio" || tagName === "video") {
549
+ const mediaAttributes = attributes;
550
+ mediaAttributes.rr_mediaState = n.paused ? "paused" : "played";
551
+ mediaAttributes.rr_mediaCurrentTime = n.currentTime;
552
+ mediaAttributes.rr_mediaPlaybackRate = n.playbackRate;
553
+ mediaAttributes.rr_mediaMuted = n.muted;
554
+ mediaAttributes.rr_mediaLoop = n.loop;
555
+ mediaAttributes.rr_mediaVolume = n.volume;
556
+ }
557
+ if (!newlyAddedElement) {
558
+ if (n.scrollLeft) {
559
+ attributes.rr_scrollLeft = n.scrollLeft;
560
+ }
561
+ if (n.scrollTop) {
562
+ attributes.rr_scrollTop = n.scrollTop;
563
+ }
564
+ }
565
+ if (needBlock) {
566
+ const { width, height } = n.getBoundingClientRect();
567
+ attributes = {
568
+ class: attributes.class,
569
+ rr_width: `${width}px`,
570
+ rr_height: `${height}px`
571
+ };
572
+ }
573
+ if (tagName === "iframe" && !keepIframeSrcFn(attributes.src)) {
574
+ if (!n.contentDocument) {
575
+ attributes.rr_src = attributes.src;
576
+ }
577
+ delete attributes.src;
578
+ }
579
+ let isCustomElement;
580
+ try {
581
+ if (customElements.get(tagName)) isCustomElement = true;
582
+ } catch (e) {
583
+ }
584
+ return {
585
+ type: types.NodeType$1.Element,
586
+ tagName,
587
+ attributes,
588
+ childNodes: [],
589
+ isSVG: isSVGElement(n) || void 0,
590
+ needBlock,
591
+ rootId,
592
+ isCustom: isCustomElement
593
+ };
594
+ }
595
+ function lowerIfExists(maybeAttr) {
596
+ if (maybeAttr === void 0 || maybeAttr === null) {
597
+ return "";
598
+ } else {
599
+ return maybeAttr.toLowerCase();
600
+ }
601
+ }
602
+ function slimDOMExcluded(sn, slimDOMOptions) {
603
+ if (slimDOMOptions.comment && sn.type === types.NodeType$1.Comment) {
604
+ return true;
605
+ } else if (sn.type === types.NodeType$1.Element) {
606
+ if (slimDOMOptions.script && // script tag
607
+ (sn.tagName === "script" || // (module)preload link
608
+ sn.tagName === "link" && (sn.attributes.rel === "preload" && sn.attributes.as === "script" || sn.attributes.rel === "modulepreload") || // prefetch link
609
+ sn.tagName === "link" && sn.attributes.rel === "prefetch" && typeof sn.attributes.href === "string" && types.extractFileExtension(sn.attributes.href) === "js")) {
610
+ return true;
611
+ } else if (slimDOMOptions.headFavicon && (sn.tagName === "link" && sn.attributes.rel === "shortcut icon" || sn.tagName === "meta" && (lowerIfExists(sn.attributes.name).match(
612
+ /^msapplication-tile(image|color)$/
613
+ ) || lowerIfExists(sn.attributes.name) === "application-name" || lowerIfExists(sn.attributes.rel) === "icon" || lowerIfExists(sn.attributes.rel) === "apple-touch-icon" || lowerIfExists(sn.attributes.rel) === "shortcut icon"))) {
614
+ return true;
615
+ } else if (sn.tagName === "meta") {
616
+ if (slimDOMOptions.headMetaDescKeywords && lowerIfExists(sn.attributes.name).match(/^description|keywords$/)) {
617
+ return true;
618
+ } else if (slimDOMOptions.headMetaSocial && (lowerIfExists(sn.attributes.property).match(/^(og|twitter|fb):/) || // og = opengraph (facebook)
619
+ lowerIfExists(sn.attributes.name).match(/^(og|twitter):/) || lowerIfExists(sn.attributes.name) === "pinterest")) {
620
+ return true;
621
+ } else if (slimDOMOptions.headMetaRobots && (lowerIfExists(sn.attributes.name) === "robots" || lowerIfExists(sn.attributes.name) === "googlebot" || lowerIfExists(sn.attributes.name) === "bingbot")) {
622
+ return true;
623
+ } else if (slimDOMOptions.headMetaHttpEquiv && sn.attributes["http-equiv"] !== void 0) {
624
+ return true;
625
+ } else if (slimDOMOptions.headMetaAuthorship && (lowerIfExists(sn.attributes.name) === "author" || lowerIfExists(sn.attributes.name) === "generator" || lowerIfExists(sn.attributes.name) === "framework" || lowerIfExists(sn.attributes.name) === "publisher" || lowerIfExists(sn.attributes.name) === "progid" || lowerIfExists(sn.attributes.property).match(/^article:/) || lowerIfExists(sn.attributes.property).match(/^product:/))) {
626
+ return true;
627
+ } else if (slimDOMOptions.headMetaVerification && (lowerIfExists(sn.attributes.name) === "google-site-verification" || lowerIfExists(sn.attributes.name) === "yandex-verification" || lowerIfExists(sn.attributes.name) === "csrf-token" || lowerIfExists(sn.attributes.name) === "p:domain_verify" || lowerIfExists(sn.attributes.name) === "verify-v1" || lowerIfExists(sn.attributes.name) === "verification" || lowerIfExists(sn.attributes.name) === "shopify-checkout-api-token")) {
628
+ return true;
629
+ }
630
+ }
631
+ }
632
+ return false;
633
+ }
634
+ function serializeNodeWithId(n, options) {
635
+ const {
636
+ doc,
637
+ mirror,
638
+ blockClass,
639
+ blockSelector,
640
+ maskTextClass,
641
+ maskTextSelector,
642
+ skipChild = false,
643
+ inlineStylesheet = true,
644
+ maskInputOptions = {},
645
+ maskTextFn,
646
+ maskInputFn,
647
+ slimDOMOptions,
648
+ dataURLOptions = {},
649
+ inlineImages = false,
650
+ recordCanvas = false,
651
+ onSerialize,
652
+ onIframeLoad,
653
+ iframeLoadTimeout = 5e3,
654
+ onStylesheetLoad,
655
+ stylesheetLoadTimeout = 5e3,
656
+ keepIframeSrcFn = () => false,
657
+ newlyAddedElement = false
658
+ } = options;
659
+ let { needsMask } = options;
660
+ let { preserveWhiteSpace = true } = options;
661
+ if (!needsMask) {
662
+ const checkAncestors = needsMask === void 0;
663
+ needsMask = needMaskingText(
664
+ n,
665
+ maskTextClass,
666
+ maskTextSelector,
667
+ checkAncestors
668
+ );
669
+ }
670
+ const _serializedNode = serializeNode(n, {
671
+ doc,
672
+ mirror,
673
+ blockClass,
674
+ blockSelector,
675
+ needsMask,
676
+ inlineStylesheet,
677
+ maskInputOptions,
678
+ maskTextFn,
679
+ maskInputFn,
680
+ dataURLOptions,
681
+ inlineImages,
682
+ recordCanvas,
683
+ keepIframeSrcFn,
684
+ newlyAddedElement
685
+ });
686
+ if (!_serializedNode) {
687
+ console.warn(n, "not serialized");
688
+ return null;
689
+ }
690
+ let id;
691
+ if (mirror.hasNode(n)) {
692
+ id = mirror.getId(n);
693
+ } else if (slimDOMExcluded(_serializedNode, slimDOMOptions) || !preserveWhiteSpace && _serializedNode.type === types.NodeType$1.Text && !_serializedNode.isStyle && !_serializedNode.textContent.replace(/^\s+|\s+$/gm, "").length) {
694
+ id = IGNORED_NODE;
695
+ } else {
696
+ id = genId();
697
+ }
698
+ const serializedNode = Object.assign(_serializedNode, { id });
699
+ mirror.add(n, serializedNode);
700
+ if (id === IGNORED_NODE) {
701
+ return null;
702
+ }
703
+ if (onSerialize) {
704
+ onSerialize(n);
705
+ }
706
+ let recordChild = !skipChild;
707
+ if (serializedNode.type === types.NodeType$1.Element) {
708
+ recordChild = recordChild && !serializedNode.needBlock;
709
+ delete serializedNode.needBlock;
710
+ const shadowRootEl = types.index.shadowRoot(n);
711
+ if (shadowRootEl && types.isNativeShadowDom(shadowRootEl))
712
+ serializedNode.isShadowHost = true;
713
+ }
714
+ if ((serializedNode.type === types.NodeType$1.Document || serializedNode.type === types.NodeType$1.Element) && recordChild) {
715
+ if (slimDOMOptions.headWhitespace && serializedNode.type === types.NodeType$1.Element && serializedNode.tagName === "head") {
716
+ preserveWhiteSpace = false;
717
+ }
718
+ const bypassOptions = {
719
+ doc,
720
+ mirror,
721
+ blockClass,
722
+ blockSelector,
723
+ needsMask,
724
+ maskTextClass,
725
+ maskTextSelector,
726
+ skipChild,
727
+ inlineStylesheet,
728
+ maskInputOptions,
729
+ maskTextFn,
730
+ maskInputFn,
731
+ slimDOMOptions,
732
+ dataURLOptions,
733
+ inlineImages,
734
+ recordCanvas,
735
+ preserveWhiteSpace,
736
+ onSerialize,
737
+ onIframeLoad,
738
+ iframeLoadTimeout,
739
+ onStylesheetLoad,
740
+ stylesheetLoadTimeout,
741
+ keepIframeSrcFn
742
+ };
743
+ if (serializedNode.type === types.NodeType$1.Element && serializedNode.tagName === "textarea" && serializedNode.attributes.value !== void 0) ;
744
+ else {
745
+ for (const childN of Array.from(types.index.childNodes(n))) {
746
+ const serializedChildNode = serializeNodeWithId(childN, bypassOptions);
747
+ if (serializedChildNode) {
748
+ serializedNode.childNodes.push(serializedChildNode);
749
+ }
750
+ }
751
+ }
752
+ let shadowRootEl = null;
753
+ if (types.isElement(n) && (shadowRootEl = types.index.shadowRoot(n))) {
754
+ for (const childN of Array.from(types.index.childNodes(shadowRootEl))) {
755
+ const serializedChildNode = serializeNodeWithId(childN, bypassOptions);
756
+ if (serializedChildNode) {
757
+ types.isNativeShadowDom(shadowRootEl) && (serializedChildNode.isShadow = true);
758
+ serializedNode.childNodes.push(serializedChildNode);
759
+ }
760
+ }
761
+ }
762
+ }
763
+ const parent = types.index.parentNode(n);
764
+ if (parent && types.isShadowRoot(parent) && types.isNativeShadowDom(parent)) {
765
+ serializedNode.isShadow = true;
766
+ }
767
+ if (serializedNode.type === types.NodeType$1.Element && serializedNode.tagName === "iframe") {
768
+ onceIframeLoaded(
769
+ n,
770
+ () => {
771
+ const iframeDoc = n.contentDocument;
772
+ if (iframeDoc && onIframeLoad) {
773
+ const serializedIframeNode = serializeNodeWithId(iframeDoc, {
774
+ doc: iframeDoc,
775
+ mirror,
776
+ blockClass,
777
+ blockSelector,
778
+ needsMask,
779
+ maskTextClass,
780
+ maskTextSelector,
781
+ skipChild: false,
782
+ inlineStylesheet,
783
+ maskInputOptions,
784
+ maskTextFn,
785
+ maskInputFn,
786
+ slimDOMOptions,
787
+ dataURLOptions,
788
+ inlineImages,
789
+ recordCanvas,
790
+ preserveWhiteSpace,
791
+ onSerialize,
792
+ onIframeLoad,
793
+ iframeLoadTimeout,
794
+ onStylesheetLoad,
795
+ stylesheetLoadTimeout,
796
+ keepIframeSrcFn
797
+ });
798
+ if (serializedIframeNode) {
799
+ onIframeLoad(
800
+ n,
801
+ serializedIframeNode
802
+ );
803
+ }
804
+ }
805
+ },
806
+ iframeLoadTimeout
807
+ );
808
+ }
809
+ if (serializedNode.type === types.NodeType$1.Element && serializedNode.tagName === "link" && typeof serializedNode.attributes.rel === "string" && (serializedNode.attributes.rel === "stylesheet" || serializedNode.attributes.rel === "preload" && typeof serializedNode.attributes.href === "string" && types.extractFileExtension(serializedNode.attributes.href) === "css")) {
810
+ onceStylesheetLoaded(
811
+ n,
812
+ () => {
813
+ if (onStylesheetLoad) {
814
+ const serializedLinkNode = serializeNodeWithId(n, {
815
+ doc,
816
+ mirror,
817
+ blockClass,
818
+ blockSelector,
819
+ needsMask,
820
+ maskTextClass,
821
+ maskTextSelector,
822
+ skipChild: false,
823
+ inlineStylesheet,
824
+ maskInputOptions,
825
+ maskTextFn,
826
+ maskInputFn,
827
+ slimDOMOptions,
828
+ dataURLOptions,
829
+ inlineImages,
830
+ recordCanvas,
831
+ preserveWhiteSpace,
832
+ onSerialize,
833
+ onIframeLoad,
834
+ iframeLoadTimeout,
835
+ onStylesheetLoad,
836
+ stylesheetLoadTimeout,
837
+ keepIframeSrcFn
838
+ });
839
+ if (serializedLinkNode) {
840
+ onStylesheetLoad(
841
+ n,
842
+ serializedLinkNode
843
+ );
844
+ }
845
+ }
846
+ },
847
+ stylesheetLoadTimeout
848
+ );
849
+ }
850
+ return serializedNode;
851
+ }
852
+ function snapshot(n, options) {
853
+ const {
854
+ mirror = new types.Mirror(),
855
+ blockClass = "rr-block",
856
+ blockSelector = null,
857
+ maskTextClass = "rr-mask",
858
+ maskTextSelector = null,
859
+ inlineStylesheet = true,
860
+ inlineImages = false,
861
+ recordCanvas = false,
862
+ maskAllInputs = false,
863
+ maskTextFn,
864
+ maskInputFn,
865
+ slimDOM = false,
866
+ dataURLOptions,
867
+ preserveWhiteSpace,
868
+ onSerialize,
869
+ onIframeLoad,
870
+ iframeLoadTimeout,
871
+ onStylesheetLoad,
872
+ stylesheetLoadTimeout,
873
+ keepIframeSrcFn = () => false
874
+ } = options || {};
875
+ const maskInputOptions = maskAllInputs === true ? {
876
+ color: true,
877
+ date: true,
878
+ "datetime-local": true,
879
+ email: true,
880
+ month: true,
881
+ number: true,
882
+ range: true,
883
+ search: true,
884
+ tel: true,
885
+ text: true,
886
+ time: true,
887
+ url: true,
888
+ week: true,
889
+ textarea: true,
890
+ select: true,
891
+ password: true
892
+ } : maskAllInputs === false ? {
893
+ password: true
894
+ } : maskAllInputs;
895
+ const slimDOMOptions = slimDOM === true || slimDOM === "all" ? (
896
+ // if true: set of sensible options that should not throw away any information
897
+ {
898
+ script: true,
899
+ comment: true,
900
+ headFavicon: true,
901
+ headWhitespace: true,
902
+ headMetaDescKeywords: slimDOM === "all",
903
+ // destructive
904
+ headMetaSocial: true,
905
+ headMetaRobots: true,
906
+ headMetaHttpEquiv: true,
907
+ headMetaAuthorship: true,
908
+ headMetaVerification: true
909
+ }
910
+ ) : slimDOM === false ? {} : slimDOM;
911
+ return serializeNodeWithId(n, {
912
+ doc: n,
913
+ mirror,
914
+ blockClass,
915
+ blockSelector,
916
+ maskTextClass,
917
+ maskTextSelector,
918
+ skipChild: false,
919
+ inlineStylesheet,
920
+ maskInputOptions,
921
+ maskTextFn,
922
+ maskInputFn,
923
+ slimDOMOptions,
924
+ dataURLOptions,
925
+ inlineImages,
926
+ recordCanvas,
927
+ preserveWhiteSpace,
928
+ onSerialize,
929
+ onIframeLoad,
930
+ iframeLoadTimeout,
931
+ onStylesheetLoad,
932
+ stylesheetLoadTimeout,
933
+ keepIframeSrcFn,
934
+ newlyAddedElement: false
935
+ });
936
+ }
937
+ function visitSnapshot(node, onVisit) {
938
+ function walk(current) {
939
+ onVisit(current);
940
+ if (current.type === types.NodeType$1.Document || current.type === types.NodeType$1.Element) {
941
+ current.childNodes.forEach(walk);
942
+ }
943
+ }
944
+ walk(node);
945
+ }
946
+ function cleanupSnapshot() {
947
+ _id = 1;
948
+ }
949
+ exports.Mirror = types.Mirror;
950
+ exports.NodeType = types.NodeType;
951
+ exports.absolutifyURLs = types.absolutifyURLs;
952
+ exports.checkDataURLSize = types.checkDataURLSize;
953
+ exports.createMirror = types.createMirror;
954
+ exports.escapeImportStatement = types.escapeImportStatement;
955
+ exports.extractFileExtension = types.extractFileExtension;
956
+ exports.fixSafariColons = types.fixSafariColons;
957
+ exports.getInputType = types.getInputType;
958
+ exports.is2DCanvasBlank = types.is2DCanvasBlank;
959
+ exports.isCSSImportRule = types.isCSSImportRule;
960
+ exports.isCSSStyleRule = types.isCSSStyleRule;
961
+ exports.isElement = types.isElement;
962
+ exports.isNativeShadowDom = types.isNativeShadowDom;
963
+ exports.isNodeMetaEqual = types.isNodeMetaEqual;
964
+ exports.isShadowRoot = types.isShadowRoot;
965
+ exports.maskInputValue = types.maskInputValue;
966
+ exports.recompressBase64Image = types.recompressBase64Image;
967
+ exports.stringifyRule = types.stringifyRule;
968
+ exports.stringifyStylesheet = types.stringifyStylesheet;
969
+ exports.toLowerCase = types.toLowerCase;
970
+ exports.IGNORED_NODE = IGNORED_NODE;
971
+ exports.classMatchesRegex = classMatchesRegex;
972
+ exports.cleanupSnapshot = cleanupSnapshot;
973
+ exports.genId = genId;
974
+ exports.ignoreAttribute = ignoreAttribute;
975
+ exports.needMaskingText = needMaskingText;
976
+ exports.serializeNodeWithId = serializeNodeWithId;
977
+ exports.snapshot = snapshot;
978
+ exports.transformAttribute = transformAttribute;
979
+ exports.visitSnapshot = visitSnapshot;
980
+ //# sourceMappingURL=record.cjs.map