@posthog/rrweb-snapshot 0.0.40 → 0.0.42

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.
@@ -0,0 +1,1569 @@
1
+ (function (g, f) {if ("object" == typeof exports && "object" == typeof module) {module.exports = f();} else if ("function" == typeof define && define.amd) {define("rrwebSnapshotRecord", [], f);} else if ("object" == typeof exports) {exports["rrwebSnapshotRecord"] = f();} else {g["rrwebSnapshotRecord"] = f();}}(typeof self !== 'undefined' ? self : typeof globalThis !== 'undefined' ? globalThis : this, () => {var exports = {};var module = { exports };
2
+ "use strict";
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __commonJS = (cb, mod) => function __require() {
5
+ return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
6
+ };
7
+
8
+ // dist/types-B7TTv7Jc.cjs
9
+ var require_types_B7TTv7Jc = __commonJS({
10
+ "dist/types-B7TTv7Jc.cjs"(exports2) {
11
+ "use strict";
12
+ var __defProp = Object.defineProperty;
13
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
14
+ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
15
+ var NodeType$1 = /* @__PURE__ */ ((NodeType2) => {
16
+ NodeType2[NodeType2["Document"] = 0] = "Document";
17
+ NodeType2[NodeType2["DocumentType"] = 1] = "DocumentType";
18
+ NodeType2[NodeType2["Element"] = 2] = "Element";
19
+ NodeType2[NodeType2["Text"] = 3] = "Text";
20
+ NodeType2[NodeType2["CDATA"] = 4] = "CDATA";
21
+ NodeType2[NodeType2["Comment"] = 5] = "Comment";
22
+ return NodeType2;
23
+ })(NodeType$1 || {});
24
+ var testableAccessors = {
25
+ Node: ["childNodes", "parentNode", "parentElement", "textContent"],
26
+ ShadowRoot: ["host", "styleSheets"],
27
+ Element: ["shadowRoot", "querySelector", "querySelectorAll"],
28
+ MutationObserver: []
29
+ };
30
+ var testableMethods = {
31
+ Node: ["contains", "getRootNode"],
32
+ ShadowRoot: ["getSelection"],
33
+ Element: [],
34
+ MutationObserver: ["constructor"]
35
+ };
36
+ var untaintedBasePrototype = {};
37
+ function angularZoneUnpatchedAlternative(key) {
38
+ var _a, _b;
39
+ const angularUnpatchedVersionSymbol = (_b = (_a = globalThis == null ? void 0 : globalThis.Zone) == null ? void 0 : _a.__symbol__) == null ? void 0 : _b.call(_a, key);
40
+ if (angularUnpatchedVersionSymbol && globalThis[angularUnpatchedVersionSymbol]) {
41
+ return globalThis[angularUnpatchedVersionSymbol];
42
+ } else {
43
+ return void 0;
44
+ }
45
+ }
46
+ function getUntaintedPrototype(key) {
47
+ if (untaintedBasePrototype[key])
48
+ return untaintedBasePrototype[key];
49
+ const candidate = angularZoneUnpatchedAlternative(key) || globalThis[key];
50
+ const defaultPrototype = candidate.prototype;
51
+ const accessorNames = key in testableAccessors ? testableAccessors[key] : void 0;
52
+ const isUntaintedAccessors = Boolean(
53
+ accessorNames && // @ts-expect-error 2345
54
+ accessorNames.every(
55
+ (accessor) => {
56
+ var _a, _b;
57
+ return Boolean(
58
+ (_b = (_a = Object.getOwnPropertyDescriptor(defaultPrototype, accessor)) == null ? void 0 : _a.get) == null ? void 0 : _b.toString().includes("[native code]")
59
+ );
60
+ }
61
+ )
62
+ );
63
+ const methodNames = key in testableMethods ? testableMethods[key] : void 0;
64
+ const isUntaintedMethods = Boolean(
65
+ methodNames && methodNames.every(
66
+ // @ts-expect-error 2345
67
+ (method) => {
68
+ var _a;
69
+ return typeof defaultPrototype[method] === "function" && ((_a = defaultPrototype[method]) == null ? void 0 : _a.toString().includes("[native code]"));
70
+ }
71
+ )
72
+ );
73
+ if (isUntaintedAccessors && isUntaintedMethods) {
74
+ untaintedBasePrototype[key] = candidate.prototype;
75
+ return candidate.prototype;
76
+ }
77
+ try {
78
+ const iframeEl = document.createElement("iframe");
79
+ document.body.appendChild(iframeEl);
80
+ const win = iframeEl.contentWindow;
81
+ if (!win) return candidate.prototype;
82
+ const untaintedObject = win[key].prototype;
83
+ document.body.removeChild(iframeEl);
84
+ if (!untaintedObject) return defaultPrototype;
85
+ return untaintedBasePrototype[key] = untaintedObject;
86
+ } catch (e) {
87
+ return defaultPrototype;
88
+ }
89
+ }
90
+ var untaintedAccessorCache = {};
91
+ function getUntaintedAccessor(key, instance, accessor) {
92
+ var _a;
93
+ const cacheKey = `${key}.${String(accessor)}`;
94
+ if (untaintedAccessorCache[cacheKey])
95
+ return untaintedAccessorCache[cacheKey].call(
96
+ instance
97
+ );
98
+ const untaintedPrototype = getUntaintedPrototype(key);
99
+ const untaintedAccessor = (_a = Object.getOwnPropertyDescriptor(
100
+ untaintedPrototype,
101
+ accessor
102
+ )) == null ? void 0 : _a.get;
103
+ if (!untaintedAccessor) return instance[accessor];
104
+ untaintedAccessorCache[cacheKey] = untaintedAccessor;
105
+ return untaintedAccessor.call(instance);
106
+ }
107
+ var untaintedMethodCache = {};
108
+ function getUntaintedMethod(key, instance, method) {
109
+ const cacheKey = `${key}.${String(method)}`;
110
+ if (untaintedMethodCache[cacheKey])
111
+ return untaintedMethodCache[cacheKey].bind(
112
+ instance
113
+ );
114
+ const untaintedPrototype = getUntaintedPrototype(key);
115
+ const untaintedMethod = untaintedPrototype[method];
116
+ if (typeof untaintedMethod !== "function") return instance[method];
117
+ untaintedMethodCache[cacheKey] = untaintedMethod;
118
+ return untaintedMethod.bind(instance);
119
+ }
120
+ function childNodes(n) {
121
+ return getUntaintedAccessor("Node", n, "childNodes");
122
+ }
123
+ function parentNode(n) {
124
+ return getUntaintedAccessor("Node", n, "parentNode");
125
+ }
126
+ function parentElement(n) {
127
+ return getUntaintedAccessor("Node", n, "parentElement");
128
+ }
129
+ function textContent(n) {
130
+ return getUntaintedAccessor("Node", n, "textContent");
131
+ }
132
+ function contains(n, other) {
133
+ return getUntaintedMethod("Node", n, "contains")(other);
134
+ }
135
+ function getRootNode(n) {
136
+ return getUntaintedMethod("Node", n, "getRootNode")();
137
+ }
138
+ function host(n) {
139
+ if (!n || !("host" in n)) return null;
140
+ return getUntaintedAccessor("ShadowRoot", n, "host");
141
+ }
142
+ function styleSheets(n) {
143
+ return n.styleSheets;
144
+ }
145
+ function shadowRoot(n) {
146
+ if (!n || !("shadowRoot" in n)) return null;
147
+ return getUntaintedAccessor("Element", n, "shadowRoot");
148
+ }
149
+ function querySelector(n, selectors) {
150
+ return getUntaintedAccessor("Element", n, "querySelector")(selectors);
151
+ }
152
+ function querySelectorAll(n, selectors) {
153
+ return getUntaintedAccessor("Element", n, "querySelectorAll")(selectors);
154
+ }
155
+ function mutationObserverCtor() {
156
+ return getUntaintedPrototype("MutationObserver").constructor;
157
+ }
158
+ function patch(source, name, replacement) {
159
+ try {
160
+ if (!(name in source)) {
161
+ return () => {
162
+ };
163
+ }
164
+ const original = source[name];
165
+ const wrapped = replacement(original);
166
+ if (typeof wrapped === "function") {
167
+ wrapped.prototype = wrapped.prototype || {};
168
+ Object.defineProperties(wrapped, {
169
+ __rrweb_original__: {
170
+ enumerable: false,
171
+ value: original
172
+ }
173
+ });
174
+ }
175
+ source[name] = wrapped;
176
+ return () => {
177
+ source[name] = original;
178
+ };
179
+ } catch (e) {
180
+ return () => {
181
+ };
182
+ }
183
+ }
184
+ var index = {
185
+ childNodes,
186
+ parentNode,
187
+ parentElement,
188
+ textContent,
189
+ contains,
190
+ getRootNode,
191
+ host,
192
+ styleSheets,
193
+ shadowRoot,
194
+ querySelector,
195
+ querySelectorAll,
196
+ mutationObserver: mutationObserverCtor,
197
+ patch
198
+ };
199
+ function isElement(n) {
200
+ return n.nodeType === n.ELEMENT_NODE;
201
+ }
202
+ function isShadowRoot(n) {
203
+ const hostEl = (
204
+ // anchor and textarea elements also have a `host` property
205
+ // but only shadow roots have a `mode` property
206
+ n && "host" in n && "mode" in n && index.host(n) || null
207
+ );
208
+ return Boolean(
209
+ hostEl && "shadowRoot" in hostEl && index.shadowRoot(hostEl) === n
210
+ );
211
+ }
212
+ function isNativeShadowDom(shadowRoot2) {
213
+ return Object.prototype.toString.call(shadowRoot2) === "[object ShadowRoot]";
214
+ }
215
+ function fixBrowserCompatibilityIssuesInCSS(cssText) {
216
+ if (cssText.includes(" background-clip: text;") && !cssText.includes(" -webkit-background-clip: text;")) {
217
+ cssText = cssText.replace(
218
+ /\sbackground-clip:\s*text;/g,
219
+ " -webkit-background-clip: text; background-clip: text;"
220
+ );
221
+ }
222
+ return cssText;
223
+ }
224
+ function escapeImportStatement(rule) {
225
+ const { cssText } = rule;
226
+ if (cssText.split('"').length < 3) return cssText;
227
+ const statement = ["@import", `url(${JSON.stringify(rule.href)})`];
228
+ if (rule.layerName === "") {
229
+ statement.push(`layer`);
230
+ } else if (rule.layerName) {
231
+ statement.push(`layer(${rule.layerName})`);
232
+ }
233
+ if (rule.supportsText) {
234
+ statement.push(`supports(${rule.supportsText})`);
235
+ }
236
+ if (rule.media.length) {
237
+ statement.push(rule.media.mediaText);
238
+ }
239
+ return statement.join(" ") + ";";
240
+ }
241
+ function stringifyStylesheet(s) {
242
+ try {
243
+ const rules = s.rules || s.cssRules;
244
+ if (!rules) {
245
+ return null;
246
+ }
247
+ let sheetHref = s.href;
248
+ if (!sheetHref && s.ownerNode) {
249
+ sheetHref = s.ownerNode.baseURI;
250
+ }
251
+ const stringifiedRules = Array.from(
252
+ rules,
253
+ (rule) => stringifyRule(rule, sheetHref)
254
+ ).join("");
255
+ return fixBrowserCompatibilityIssuesInCSS(stringifiedRules);
256
+ } catch (error) {
257
+ return null;
258
+ }
259
+ }
260
+ function stringifyRule(rule, sheetHref) {
261
+ var _a;
262
+ if (isCSSImportRule(rule)) {
263
+ let importStringified;
264
+ try {
265
+ importStringified = // for same-origin stylesheets,
266
+ // we can access the imported stylesheet rules directly
267
+ stringifyStylesheet(rule.styleSheet) || // work around browser issues with the raw string `@import url(...)` statement
268
+ escapeImportStatement(rule);
269
+ } catch (error) {
270
+ importStringified = rule.cssText;
271
+ }
272
+ try {
273
+ if (importStringified && ((_a = rule.styleSheet) == null ? void 0 : _a.href)) {
274
+ return absolutifyURLs(importStringified, rule.styleSheet.href);
275
+ }
276
+ } catch (e) {
277
+ }
278
+ return importStringified;
279
+ } else {
280
+ let ruleStringified = rule.cssText;
281
+ if (isCSSStyleRule(rule) && rule.selectorText.includes(":")) {
282
+ ruleStringified = fixSafariColons(ruleStringified);
283
+ }
284
+ if (sheetHref) {
285
+ return absolutifyURLs(ruleStringified, sheetHref);
286
+ }
287
+ return ruleStringified;
288
+ }
289
+ }
290
+ function fixSafariColons(cssStringified) {
291
+ const regex = /(\[(?:[\w-]+)[^\\])(:(?:[\w-]+)\])/gm;
292
+ return cssStringified.replace(regex, "$1\\$2");
293
+ }
294
+ function isCSSImportRule(rule) {
295
+ return "styleSheet" in rule;
296
+ }
297
+ function isCSSStyleRule(rule) {
298
+ return "selectorText" in rule;
299
+ }
300
+ var Mirror = class {
301
+ constructor() {
302
+ __publicField(this, "idNodeMap", /* @__PURE__ */ new Map());
303
+ __publicField(this, "nodeMetaMap", /* @__PURE__ */ new WeakMap());
304
+ }
305
+ getId(n) {
306
+ var _a;
307
+ if (!n) return -1;
308
+ const id = (_a = this.getMeta(n)) == null ? void 0 : _a.id;
309
+ return id != null ? id : -1;
310
+ }
311
+ getNode(id) {
312
+ return this.idNodeMap.get(id) || null;
313
+ }
314
+ getIds() {
315
+ return Array.from(this.idNodeMap.keys());
316
+ }
317
+ getMeta(n) {
318
+ return this.nodeMetaMap.get(n) || null;
319
+ }
320
+ // removes the node from idNodeMap
321
+ // doesn't remove the node from nodeMetaMap
322
+ removeNodeFromMap(n) {
323
+ const id = this.getId(n);
324
+ this.idNodeMap.delete(id);
325
+ if (n.childNodes) {
326
+ n.childNodes.forEach(
327
+ (childNode) => this.removeNodeFromMap(childNode)
328
+ );
329
+ }
330
+ if (isElement(n)) {
331
+ const shadowRootEl = index.shadowRoot(n);
332
+ if (shadowRootEl) {
333
+ this.removeNodeFromMap(shadowRootEl);
334
+ }
335
+ if (n.nodeName === "IFRAME" && n.contentDocument) {
336
+ this.removeNodeFromMap(
337
+ n.contentDocument
338
+ );
339
+ }
340
+ }
341
+ }
342
+ has(id) {
343
+ return this.idNodeMap.has(id);
344
+ }
345
+ hasNode(node) {
346
+ return this.nodeMetaMap.has(node);
347
+ }
348
+ add(n, meta) {
349
+ const id = meta.id;
350
+ this.idNodeMap.set(id, n);
351
+ this.nodeMetaMap.set(n, meta);
352
+ }
353
+ replace(id, n) {
354
+ const oldNode = this.getNode(id);
355
+ if (oldNode) {
356
+ const meta = this.nodeMetaMap.get(oldNode);
357
+ if (meta) this.nodeMetaMap.set(n, meta);
358
+ }
359
+ this.idNodeMap.set(id, n);
360
+ }
361
+ reset() {
362
+ this.idNodeMap = /* @__PURE__ */ new Map();
363
+ this.nodeMetaMap = /* @__PURE__ */ new WeakMap();
364
+ }
365
+ };
366
+ function createMirror() {
367
+ return new Mirror();
368
+ }
369
+ function maskInputValue({
370
+ element,
371
+ maskInputOptions,
372
+ tagName,
373
+ type,
374
+ value,
375
+ maskInputFn
376
+ }) {
377
+ let text = value || "";
378
+ const actualType = type && toLowerCase(type);
379
+ if (maskInputOptions[tagName.toLowerCase()] || actualType && maskInputOptions[actualType]) {
380
+ if (maskInputFn) {
381
+ text = maskInputFn(text, element);
382
+ } else {
383
+ text = "*".repeat(text.length);
384
+ }
385
+ }
386
+ return text;
387
+ }
388
+ function toLowerCase(str) {
389
+ return str.toLowerCase();
390
+ }
391
+ var ORIGINAL_ATTRIBUTE_NAME = "__rrweb_original__";
392
+ function is2DCanvasBlank(canvas) {
393
+ const ctx = canvas.getContext("2d");
394
+ if (!ctx) return true;
395
+ const chunkSize = 50;
396
+ for (let x = 0; x < canvas.width; x += chunkSize) {
397
+ for (let y = 0; y < canvas.height; y += chunkSize) {
398
+ const getImageData = ctx.getImageData;
399
+ const originalGetImageData = ORIGINAL_ATTRIBUTE_NAME in getImageData ? getImageData[ORIGINAL_ATTRIBUTE_NAME] : getImageData;
400
+ const pixelBuffer = new Uint32Array(
401
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-unsafe-member-access
402
+ originalGetImageData.call(
403
+ ctx,
404
+ x,
405
+ y,
406
+ Math.min(chunkSize, canvas.width - x),
407
+ Math.min(chunkSize, canvas.height - y)
408
+ ).data.buffer
409
+ );
410
+ if (pixelBuffer.some((pixel) => pixel !== 0)) return false;
411
+ }
412
+ }
413
+ return true;
414
+ }
415
+ function isNodeMetaEqual(a, b) {
416
+ if (!a || !b || a.type !== b.type) return false;
417
+ if (a.type === NodeType$1.Document)
418
+ return a.compatMode === b.compatMode;
419
+ else if (a.type === NodeType$1.DocumentType)
420
+ return a.name === b.name && a.publicId === b.publicId && a.systemId === b.systemId;
421
+ else if (a.type === NodeType$1.Comment || a.type === NodeType$1.Text || a.type === NodeType$1.CDATA)
422
+ return a.textContent === b.textContent;
423
+ else if (a.type === NodeType$1.Element)
424
+ return a.tagName === b.tagName && JSON.stringify(a.attributes) === JSON.stringify(b.attributes) && a.isSVG === b.isSVG && a.needBlock === b.needBlock;
425
+ return false;
426
+ }
427
+ function getInputType(element) {
428
+ const type = element.type;
429
+ return element.hasAttribute("data-rr-is-password") ? "password" : type ? (
430
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
431
+ toLowerCase(type)
432
+ ) : null;
433
+ }
434
+ function extractFileExtension(path, baseURL) {
435
+ var _a;
436
+ let url;
437
+ try {
438
+ url = new URL(path, baseURL != null ? baseURL : window.location.href);
439
+ } catch (err) {
440
+ return null;
441
+ }
442
+ const regex = /\.([0-9a-z]+)(?:$)/i;
443
+ const match = url.pathname.match(regex);
444
+ return (_a = match == null ? void 0 : match[1]) != null ? _a : null;
445
+ }
446
+ function extractOrigin(url) {
447
+ let origin = "";
448
+ if (url.indexOf("//") > -1) {
449
+ origin = url.split("/").slice(0, 3).join("/");
450
+ } else {
451
+ origin = url.split("/")[0];
452
+ }
453
+ origin = origin.split("?")[0];
454
+ return origin;
455
+ }
456
+ var URL_IN_CSS_REF = /url\((?:(')([^']*)'|(")(.*?)"|([^)]*))\)/gm;
457
+ var URL_PROTOCOL_MATCH = /^(?:[a-z+]+:)?\/\//i;
458
+ var URL_WWW_MATCH = /^www\..*/i;
459
+ var DATA_URI = /^(data:)([^,]*),(.*)/i;
460
+ function absolutifyURLs(cssText, href) {
461
+ return (cssText || "").replace(
462
+ URL_IN_CSS_REF,
463
+ (origin, quote1, path1, quote2, path2, path3) => {
464
+ const filePath = path1 || path2 || path3;
465
+ const maybeQuote = quote1 || quote2 || "";
466
+ if (!filePath) {
467
+ return origin;
468
+ }
469
+ if (URL_PROTOCOL_MATCH.test(filePath) || URL_WWW_MATCH.test(filePath)) {
470
+ return `url(${maybeQuote}${filePath}${maybeQuote})`;
471
+ }
472
+ if (DATA_URI.test(filePath)) {
473
+ return `url(${maybeQuote}${filePath}${maybeQuote})`;
474
+ }
475
+ if (filePath[0] === "/") {
476
+ return `url(${maybeQuote}${extractOrigin(href) + filePath}${maybeQuote})`;
477
+ }
478
+ const stack = href.split("/");
479
+ const parts = filePath.split("/");
480
+ stack.pop();
481
+ for (const part of parts) {
482
+ if (part === ".") {
483
+ continue;
484
+ } else if (part === "..") {
485
+ stack.pop();
486
+ } else {
487
+ stack.push(part);
488
+ }
489
+ }
490
+ return `url(${maybeQuote}${stack.join("/")}${maybeQuote})`;
491
+ }
492
+ );
493
+ }
494
+ var STRIPED_PLACEHOLDER_SVG = "data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMTAwJSIgaGVpZ2h0PSIxMDAlIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPgogIDxkZWZzPgogICAgPHBhdHRlcm4gaWQ9InN0cmlwZXMiIHBhdHRlcm5Vbml0cz0idXNlclNwYWNlT25Vc2UiIHdpZHRoPSIxNiIgaGVpZ2h0PSIxNiI+CiAgICAgIDxyZWN0IHdpZHRoPSIxNiIgaGVpZ2h0PSIxNiIgZmlsbD0iYmxhY2siLz4KICAgICAgPHBhdGggZD0iTTggMEgxNkwwIDE2VjhMOCAwWiIgZmlsbD0iIzJEMkQyRCIvPgogICAgICA8cGF0aCBkPSJNMTYgOFYxNkg4TDE2IDhaIiBmaWxsPSIjMkQyRDJEIi8+CiAgICA8L3BhdHRlcm4+CiAgPC9kZWZzPgogIDxyZWN0IHdpZHRoPSIxMDAlIiBoZWlnaHQ9IjEwMCUiIGZpbGw9InVybCgjc3RyaXBlcykiLz4KPC9zdmc+Cg==";
495
+ var MAX_IMAGE_DIMENSION_FOR_RECOMPRESSION = 4096;
496
+ function recompressBase64Image(img, dataURL, type, quality) {
497
+ if (!img.complete || img.naturalWidth === 0) {
498
+ return dataURL;
499
+ }
500
+ if (img.naturalWidth > MAX_IMAGE_DIMENSION_FOR_RECOMPRESSION || img.naturalHeight > MAX_IMAGE_DIMENSION_FOR_RECOMPRESSION) {
501
+ return dataURL;
502
+ }
503
+ try {
504
+ const canvas = document.createElement("canvas");
505
+ canvas.width = img.naturalWidth;
506
+ canvas.height = img.naturalHeight;
507
+ const ctx = canvas.getContext("2d");
508
+ if (!ctx) {
509
+ return dataURL;
510
+ }
511
+ ctx.drawImage(img, 0, 0);
512
+ const recompressed = canvas.toDataURL(type || "image/webp", quality != null ? quality : 0.4);
513
+ return recompressed;
514
+ } catch (err) {
515
+ return dataURL;
516
+ }
517
+ }
518
+ function checkDataURLSize(dataURL, maxLength) {
519
+ if (!maxLength || dataURL.length <= maxLength) {
520
+ return dataURL;
521
+ }
522
+ return STRIPED_PLACEHOLDER_SVG;
523
+ }
524
+ var NodeType = /* @__PURE__ */ ((NodeType2) => {
525
+ NodeType2[NodeType2["Document"] = 0] = "Document";
526
+ NodeType2[NodeType2["DocumentType"] = 1] = "DocumentType";
527
+ NodeType2[NodeType2["Element"] = 2] = "Element";
528
+ NodeType2[NodeType2["Text"] = 3] = "Text";
529
+ NodeType2[NodeType2["CDATA"] = 4] = "CDATA";
530
+ NodeType2[NodeType2["Comment"] = 5] = "Comment";
531
+ return NodeType2;
532
+ })(NodeType || {});
533
+ exports2.Mirror = Mirror;
534
+ exports2.NodeType = NodeType;
535
+ exports2.NodeType$1 = NodeType$1;
536
+ exports2.absolutifyURLs = absolutifyURLs;
537
+ exports2.checkDataURLSize = checkDataURLSize;
538
+ exports2.createMirror = createMirror;
539
+ exports2.escapeImportStatement = escapeImportStatement;
540
+ exports2.extractFileExtension = extractFileExtension;
541
+ exports2.fixSafariColons = fixSafariColons;
542
+ exports2.getInputType = getInputType;
543
+ exports2.index = index;
544
+ exports2.is2DCanvasBlank = is2DCanvasBlank;
545
+ exports2.isCSSImportRule = isCSSImportRule;
546
+ exports2.isCSSStyleRule = isCSSStyleRule;
547
+ exports2.isElement = isElement;
548
+ exports2.isNativeShadowDom = isNativeShadowDom;
549
+ exports2.isNodeMetaEqual = isNodeMetaEqual;
550
+ exports2.isShadowRoot = isShadowRoot;
551
+ exports2.maskInputValue = maskInputValue;
552
+ exports2.recompressBase64Image = recompressBase64Image;
553
+ exports2.stringifyRule = stringifyRule;
554
+ exports2.stringifyStylesheet = stringifyStylesheet;
555
+ exports2.toLowerCase = toLowerCase;
556
+ }
557
+ });
558
+
559
+ // dist/record-oACzRSl-.cjs
560
+ var types = require_types_B7TTv7Jc();
561
+ var _id = 1;
562
+ var tagNameRegex = new RegExp("[^a-z0-9-_:]");
563
+ var IGNORED_NODE = -2;
564
+ function genId() {
565
+ return _id++;
566
+ }
567
+ function getValidTagName(element) {
568
+ if (element instanceof HTMLFormElement) {
569
+ return "form";
570
+ }
571
+ const processedTagName = types.toLowerCase(element.tagName);
572
+ if (tagNameRegex.test(processedTagName)) {
573
+ return "div";
574
+ }
575
+ return processedTagName;
576
+ }
577
+ var canvasService;
578
+ var canvasCtx;
579
+ var SRCSET_NOT_SPACES = /^[^ \t\n\r\u000c]+/;
580
+ var SRCSET_COMMAS_OR_SPACES = /^[, \t\n\r\u000c]+/;
581
+ function getAbsoluteSrcsetString(doc, attributeValue) {
582
+ if (attributeValue.trim() === "") {
583
+ return attributeValue;
584
+ }
585
+ let pos = 0;
586
+ function collectCharacters(regEx) {
587
+ let chars;
588
+ const match = regEx.exec(attributeValue.substring(pos));
589
+ if (match) {
590
+ chars = match[0];
591
+ pos += chars.length;
592
+ return chars;
593
+ }
594
+ return "";
595
+ }
596
+ const output = [];
597
+ while (true) {
598
+ collectCharacters(SRCSET_COMMAS_OR_SPACES);
599
+ if (pos >= attributeValue.length) {
600
+ break;
601
+ }
602
+ let url = collectCharacters(SRCSET_NOT_SPACES);
603
+ if (url.slice(-1) === ",") {
604
+ url = absoluteToDoc(doc, url.substring(0, url.length - 1));
605
+ output.push(url);
606
+ } else {
607
+ let descriptorsStr = "";
608
+ url = absoluteToDoc(doc, url);
609
+ let inParens = false;
610
+ while (true) {
611
+ const c = attributeValue.charAt(pos);
612
+ if (c === "") {
613
+ output.push((url + descriptorsStr).trim());
614
+ break;
615
+ } else if (!inParens) {
616
+ if (c === ",") {
617
+ pos += 1;
618
+ output.push((url + descriptorsStr).trim());
619
+ break;
620
+ } else if (c === "(") {
621
+ inParens = true;
622
+ }
623
+ } else {
624
+ if (c === ")") {
625
+ inParens = false;
626
+ }
627
+ }
628
+ descriptorsStr += c;
629
+ pos += 1;
630
+ }
631
+ }
632
+ }
633
+ return output.join(", ");
634
+ }
635
+ var cachedDocument = /* @__PURE__ */ new WeakMap();
636
+ function absoluteToDoc(doc, attributeValue) {
637
+ if (!attributeValue || attributeValue.trim() === "") {
638
+ return attributeValue;
639
+ }
640
+ return getHref(doc, attributeValue);
641
+ }
642
+ function isSVGElement(el) {
643
+ return Boolean(el.tagName === "svg" || el.ownerSVGElement);
644
+ }
645
+ function getHref(doc, customHref) {
646
+ let a = cachedDocument.get(doc);
647
+ if (!a) {
648
+ a = doc.createElement("a");
649
+ cachedDocument.set(doc, a);
650
+ }
651
+ if (!customHref) {
652
+ customHref = "";
653
+ } else if (customHref.startsWith("blob:") || customHref.startsWith("data:")) {
654
+ return customHref;
655
+ }
656
+ a.setAttribute("href", customHref);
657
+ return a.href;
658
+ }
659
+ function transformAttribute(doc, tagName, name, value, element, dataURLOptions) {
660
+ if (!value) {
661
+ return value;
662
+ }
663
+ if (name === "src" || name === "href" && !(tagName === "use" && value[0] === "#")) {
664
+ const transformedValue = absoluteToDoc(doc, value);
665
+ if (tagName === "img" && transformedValue.startsWith("data:") && element) {
666
+ const img = element;
667
+ let processedDataURL = transformedValue;
668
+ if ((dataURLOptions == null ? void 0 : dataURLOptions.type) || (dataURLOptions == null ? void 0 : dataURLOptions.quality) !== void 0) {
669
+ processedDataURL = types.recompressBase64Image(
670
+ img,
671
+ transformedValue,
672
+ dataURLOptions.type,
673
+ dataURLOptions.quality
674
+ );
675
+ }
676
+ if (dataURLOptions == null ? void 0 : dataURLOptions.maxBase64ImageLength) {
677
+ processedDataURL = types.checkDataURLSize(
678
+ processedDataURL,
679
+ dataURLOptions.maxBase64ImageLength
680
+ );
681
+ }
682
+ return processedDataURL;
683
+ }
684
+ return transformedValue;
685
+ } else if (name === "xlink:href" && value[0] !== "#") {
686
+ return absoluteToDoc(doc, value);
687
+ } else if (name === "background" && (tagName === "table" || tagName === "td" || tagName === "th")) {
688
+ return absoluteToDoc(doc, value);
689
+ } else if (name === "srcset") {
690
+ return getAbsoluteSrcsetString(doc, value);
691
+ } else if (name === "style") {
692
+ return types.absolutifyURLs(value, getHref(doc));
693
+ } else if (tagName === "object" && name === "data") {
694
+ return absoluteToDoc(doc, value);
695
+ }
696
+ return value;
697
+ }
698
+ function ignoreAttribute(tagName, name, _value) {
699
+ return (tagName === "video" || tagName === "audio") && name === "autoplay";
700
+ }
701
+ function _isBlockedElement(element, blockClass, blockSelector) {
702
+ try {
703
+ if (typeof blockClass === "string") {
704
+ if (element.classList.contains(blockClass)) {
705
+ return true;
706
+ }
707
+ } else {
708
+ for (let eIndex = element.classList.length; eIndex--; ) {
709
+ const className = element.classList[eIndex];
710
+ if (blockClass.test(className)) {
711
+ return true;
712
+ }
713
+ }
714
+ }
715
+ if (blockSelector) {
716
+ return element.matches(blockSelector);
717
+ }
718
+ } catch (e) {
719
+ }
720
+ return false;
721
+ }
722
+ function classMatchesRegex(node, regex, checkAncestors) {
723
+ if (!node) return false;
724
+ if (node.nodeType !== node.ELEMENT_NODE) {
725
+ if (!checkAncestors) return false;
726
+ return classMatchesRegex(types.index.parentNode(node), regex, checkAncestors);
727
+ }
728
+ for (let eIndex = node.classList.length; eIndex--; ) {
729
+ const className = node.classList[eIndex];
730
+ if (regex.test(className)) {
731
+ return true;
732
+ }
733
+ }
734
+ if (!checkAncestors) return false;
735
+ return classMatchesRegex(types.index.parentNode(node), regex, checkAncestors);
736
+ }
737
+ function needMaskingText(node, maskTextClass, maskTextSelector, checkAncestors) {
738
+ let el;
739
+ if (types.isElement(node)) {
740
+ el = node;
741
+ if (!types.index.childNodes(el).length) {
742
+ return false;
743
+ }
744
+ } else if (types.index.parentElement(node) === null) {
745
+ return false;
746
+ } else {
747
+ el = types.index.parentElement(node);
748
+ }
749
+ try {
750
+ if (typeof maskTextClass === "string") {
751
+ if (checkAncestors) {
752
+ if (el.closest(`.${maskTextClass}`)) return true;
753
+ } else {
754
+ if (el.classList.contains(maskTextClass)) return true;
755
+ }
756
+ } else {
757
+ if (classMatchesRegex(el, maskTextClass, checkAncestors)) return true;
758
+ }
759
+ if (maskTextSelector) {
760
+ if (checkAncestors) {
761
+ if (el.closest(maskTextSelector)) return true;
762
+ } else {
763
+ if (el.matches(maskTextSelector)) return true;
764
+ }
765
+ }
766
+ } catch (e) {
767
+ }
768
+ return false;
769
+ }
770
+ function onceIframeLoaded(iframeEl, listener, iframeLoadTimeout) {
771
+ const win = iframeEl.contentWindow;
772
+ if (!win) {
773
+ return;
774
+ }
775
+ let fired = false;
776
+ let readyState;
777
+ try {
778
+ readyState = win.document.readyState;
779
+ } catch (error) {
780
+ return;
781
+ }
782
+ if (readyState !== "complete") {
783
+ const timer = setTimeout(() => {
784
+ if (!fired) {
785
+ listener();
786
+ fired = true;
787
+ }
788
+ }, iframeLoadTimeout);
789
+ iframeEl.addEventListener("load", () => {
790
+ clearTimeout(timer);
791
+ fired = true;
792
+ listener();
793
+ });
794
+ return;
795
+ }
796
+ const blankUrl = "about:blank";
797
+ if (win.location.href !== blankUrl || iframeEl.src === blankUrl || iframeEl.src === "") {
798
+ setTimeout(listener, 0);
799
+ return iframeEl.addEventListener("load", listener);
800
+ }
801
+ iframeEl.addEventListener("load", listener);
802
+ }
803
+ function onceStylesheetLoaded(link, listener, styleSheetLoadTimeout) {
804
+ let fired = false;
805
+ let styleSheetLoaded;
806
+ try {
807
+ styleSheetLoaded = link.sheet;
808
+ } catch (error) {
809
+ return;
810
+ }
811
+ if (styleSheetLoaded) return;
812
+ const timer = setTimeout(() => {
813
+ if (!fired) {
814
+ listener();
815
+ fired = true;
816
+ }
817
+ }, styleSheetLoadTimeout);
818
+ link.addEventListener("load", () => {
819
+ clearTimeout(timer);
820
+ fired = true;
821
+ listener();
822
+ });
823
+ }
824
+ function serializeNode(n, options) {
825
+ const {
826
+ doc,
827
+ mirror,
828
+ blockClass,
829
+ blockSelector,
830
+ needsMask,
831
+ inlineStylesheet,
832
+ maskInputOptions = {},
833
+ maskTextFn,
834
+ maskInputFn,
835
+ dataURLOptions = {},
836
+ inlineImages,
837
+ recordCanvas,
838
+ keepIframeSrcFn,
839
+ newlyAddedElement = false
840
+ } = options;
841
+ const rootId = getRootId(doc, mirror);
842
+ switch (n.nodeType) {
843
+ case n.DOCUMENT_NODE:
844
+ if (n.compatMode !== "CSS1Compat") {
845
+ return {
846
+ type: types.NodeType$1.Document,
847
+ childNodes: [],
848
+ compatMode: n.compatMode
849
+ // probably "BackCompat"
850
+ };
851
+ } else {
852
+ return {
853
+ type: types.NodeType$1.Document,
854
+ childNodes: []
855
+ };
856
+ }
857
+ case n.DOCUMENT_TYPE_NODE:
858
+ return {
859
+ type: types.NodeType$1.DocumentType,
860
+ name: n.name,
861
+ publicId: n.publicId,
862
+ systemId: n.systemId,
863
+ rootId
864
+ };
865
+ case n.ELEMENT_NODE:
866
+ return serializeElementNode(n, {
867
+ doc,
868
+ blockClass,
869
+ blockSelector,
870
+ inlineStylesheet,
871
+ maskInputOptions,
872
+ maskInputFn,
873
+ dataURLOptions,
874
+ inlineImages,
875
+ recordCanvas,
876
+ keepIframeSrcFn,
877
+ newlyAddedElement,
878
+ rootId
879
+ });
880
+ case n.TEXT_NODE:
881
+ return serializeTextNode(n, {
882
+ doc,
883
+ needsMask,
884
+ maskTextFn,
885
+ rootId
886
+ });
887
+ case n.CDATA_SECTION_NODE:
888
+ return {
889
+ type: types.NodeType$1.CDATA,
890
+ textContent: "",
891
+ rootId
892
+ };
893
+ case n.COMMENT_NODE:
894
+ return {
895
+ type: types.NodeType$1.Comment,
896
+ textContent: types.index.textContent(n) || "",
897
+ rootId
898
+ };
899
+ default:
900
+ return false;
901
+ }
902
+ }
903
+ function getRootId(doc, mirror) {
904
+ if (!mirror.hasNode(doc)) return void 0;
905
+ const docId = mirror.getId(doc);
906
+ return docId === 1 ? void 0 : docId;
907
+ }
908
+ function serializeTextNode(n, options) {
909
+ var _a;
910
+ const { needsMask, maskTextFn, rootId } = options;
911
+ const parent = types.index.parentNode(n);
912
+ const parentTagName = parent && parent.tagName;
913
+ let text = types.index.textContent(n);
914
+ const isStyle = parentTagName === "STYLE" ? true : void 0;
915
+ const isScript = parentTagName === "SCRIPT" ? true : void 0;
916
+ if (isStyle && text) {
917
+ try {
918
+ if (n.nextSibling || n.previousSibling) {
919
+ } else if ((_a = parent.sheet) == null ? void 0 : _a.cssRules) {
920
+ text = types.stringifyStylesheet(parent.sheet);
921
+ }
922
+ } catch (err) {
923
+ console.warn(
924
+ `Cannot get CSS styles from text's parentNode. Error: ${err}`,
925
+ n
926
+ );
927
+ }
928
+ text = types.absolutifyURLs(text, getHref(options.doc));
929
+ }
930
+ if (isScript) {
931
+ text = "SCRIPT_PLACEHOLDER";
932
+ }
933
+ if (!isStyle && !isScript && text && needsMask) {
934
+ text = maskTextFn ? maskTextFn(text, types.index.parentElement(n)) : text.replace(/[\S]/g, "*");
935
+ }
936
+ return {
937
+ type: types.NodeType$1.Text,
938
+ textContent: text || "",
939
+ isStyle,
940
+ rootId
941
+ };
942
+ }
943
+ function findStylesheet(doc, href) {
944
+ return Array.from(doc.styleSheets).find((s) => s.href === href);
945
+ }
946
+ function hrefFrom(n) {
947
+ return n.href;
948
+ }
949
+ function serializeElementNode(n, options) {
950
+ var _a, _b;
951
+ const {
952
+ doc,
953
+ blockClass,
954
+ blockSelector,
955
+ inlineStylesheet,
956
+ maskInputOptions = {},
957
+ maskInputFn,
958
+ dataURLOptions = {},
959
+ inlineImages,
960
+ recordCanvas,
961
+ keepIframeSrcFn,
962
+ newlyAddedElement = false,
963
+ rootId
964
+ } = options;
965
+ const needBlock = _isBlockedElement(n, blockClass, blockSelector);
966
+ const tagName = getValidTagName(n);
967
+ let attributes = {};
968
+ const len = n.attributes.length;
969
+ for (let i = 0; i < len; i++) {
970
+ const attr = n.attributes[i];
971
+ if (!ignoreAttribute(tagName, attr.name, attr.value)) {
972
+ attributes[attr.name] = transformAttribute(
973
+ doc,
974
+ tagName,
975
+ types.toLowerCase(attr.name),
976
+ attr.value,
977
+ n,
978
+ dataURLOptions
979
+ );
980
+ }
981
+ }
982
+ if (tagName === "link" && inlineStylesheet) {
983
+ const href = hrefFrom(n);
984
+ if (href) {
985
+ let stylesheet = findStylesheet(doc, href);
986
+ if (!stylesheet && href.includes(".css")) {
987
+ const rootDomain = window.location.origin;
988
+ const stylesheetPath = href.replace(window.location.href, "");
989
+ const potentialStylesheetHref = rootDomain + "/" + stylesheetPath;
990
+ stylesheet = findStylesheet(doc, potentialStylesheetHref);
991
+ }
992
+ let cssText = null;
993
+ if (stylesheet) {
994
+ cssText = types.stringifyStylesheet(stylesheet);
995
+ }
996
+ if (cssText) {
997
+ delete attributes.rel;
998
+ delete attributes.href;
999
+ attributes._cssText = cssText;
1000
+ }
1001
+ }
1002
+ }
1003
+ if (tagName === "style" && n.sheet && // TODO: Currently we only try to get dynamic stylesheet when it is an empty style element
1004
+ !(n.innerText || types.index.textContent(n) || "").trim().length) {
1005
+ const cssText = types.stringifyStylesheet(
1006
+ n.sheet
1007
+ );
1008
+ if (cssText) {
1009
+ attributes._cssText = cssText;
1010
+ }
1011
+ }
1012
+ if (tagName === "input" || tagName === "textarea" || tagName === "select") {
1013
+ const value = n.value;
1014
+ const checked = n.checked;
1015
+ if (attributes.type !== "radio" && attributes.type !== "checkbox" && attributes.type !== "submit" && attributes.type !== "button" && value) {
1016
+ attributes.value = types.maskInputValue({
1017
+ element: n,
1018
+ type: types.getInputType(n),
1019
+ tagName,
1020
+ value,
1021
+ maskInputOptions,
1022
+ maskInputFn
1023
+ });
1024
+ } else if (checked) {
1025
+ attributes.checked = checked;
1026
+ }
1027
+ }
1028
+ if (tagName === "option") {
1029
+ if (n.selected && !maskInputOptions["select"]) {
1030
+ attributes.selected = true;
1031
+ } else {
1032
+ delete attributes.selected;
1033
+ }
1034
+ }
1035
+ if (tagName === "dialog" && n.open) {
1036
+ try {
1037
+ attributes.rr_open_mode = n.matches("dialog:modal") ? "modal" : "non-modal";
1038
+ } catch (e) {
1039
+ attributes.rr_open_mode = "modal";
1040
+ attributes.ph_rr_could_not_detect_modal = true;
1041
+ }
1042
+ }
1043
+ if (tagName === "canvas" && recordCanvas) {
1044
+ if (n.__context === "2d") {
1045
+ if (!types.is2DCanvasBlank(n)) {
1046
+ attributes.rr_dataURL = n.toDataURL(
1047
+ dataURLOptions.type,
1048
+ dataURLOptions.quality
1049
+ );
1050
+ }
1051
+ } else if (!("__context" in n)) {
1052
+ const canvasDataURL = n.toDataURL(
1053
+ dataURLOptions.type,
1054
+ dataURLOptions.quality
1055
+ );
1056
+ const blankCanvas = doc.createElement("canvas");
1057
+ blankCanvas.width = n.width;
1058
+ blankCanvas.height = n.height;
1059
+ const blankCanvasDataURL = blankCanvas.toDataURL(
1060
+ dataURLOptions.type,
1061
+ dataURLOptions.quality
1062
+ );
1063
+ if (canvasDataURL !== blankCanvasDataURL) {
1064
+ attributes.rr_dataURL = canvasDataURL;
1065
+ }
1066
+ }
1067
+ }
1068
+ if (tagName === "img" && inlineImages) {
1069
+ if (!canvasService) {
1070
+ canvasService = doc.createElement("canvas");
1071
+ canvasCtx = canvasService.getContext("2d");
1072
+ }
1073
+ const image = n;
1074
+ const imageSrc = image.currentSrc || image.getAttribute("src") || "<unknown-src>";
1075
+ const priorCrossOrigin = image.crossOrigin;
1076
+ const recordInlineImage = () => {
1077
+ image.removeEventListener("load", recordInlineImage);
1078
+ try {
1079
+ canvasService.width = image.naturalWidth;
1080
+ canvasService.height = image.naturalHeight;
1081
+ canvasCtx.drawImage(image, 0, 0);
1082
+ attributes.rr_dataURL = canvasService.toDataURL(
1083
+ dataURLOptions.type,
1084
+ dataURLOptions.quality
1085
+ );
1086
+ } catch (err) {
1087
+ if (image.crossOrigin !== "anonymous") {
1088
+ image.crossOrigin = "anonymous";
1089
+ if (image.complete && image.naturalWidth !== 0)
1090
+ recordInlineImage();
1091
+ else image.addEventListener("load", recordInlineImage);
1092
+ return;
1093
+ } else {
1094
+ console.warn(
1095
+ `Cannot inline img src=${imageSrc}! Error: ${err}`
1096
+ );
1097
+ }
1098
+ }
1099
+ if (image.crossOrigin === "anonymous") {
1100
+ priorCrossOrigin ? attributes.crossOrigin = priorCrossOrigin : image.removeAttribute("crossorigin");
1101
+ }
1102
+ };
1103
+ if (image.complete && image.naturalWidth !== 0) recordInlineImage();
1104
+ else image.addEventListener("load", recordInlineImage);
1105
+ }
1106
+ if (tagName === "audio" || tagName === "video") {
1107
+ const mediaAttributes = attributes;
1108
+ mediaAttributes.rr_mediaState = n.paused ? "paused" : "played";
1109
+ mediaAttributes.rr_mediaCurrentTime = n.currentTime;
1110
+ mediaAttributes.rr_mediaPlaybackRate = n.playbackRate;
1111
+ mediaAttributes.rr_mediaMuted = n.muted;
1112
+ mediaAttributes.rr_mediaLoop = n.loop;
1113
+ mediaAttributes.rr_mediaVolume = n.volume;
1114
+ }
1115
+ if (!newlyAddedElement) {
1116
+ if (n.scrollLeft) {
1117
+ attributes.rr_scrollLeft = n.scrollLeft;
1118
+ }
1119
+ if (n.scrollTop) {
1120
+ attributes.rr_scrollTop = n.scrollTop;
1121
+ }
1122
+ }
1123
+ if (needBlock) {
1124
+ const { width, height, left, top } = n.getBoundingClientRect();
1125
+ attributes = {
1126
+ class: attributes.class,
1127
+ rr_width: `${width}px`,
1128
+ rr_height: `${height}px`,
1129
+ rr_left: `${Math.floor(left + (((_a = doc.defaultView) == null ? void 0 : _a.scrollX) || 0))}px`,
1130
+ rr_top: `${Math.floor(top + (((_b = doc.defaultView) == null ? void 0 : _b.scrollY) || 0))}px`
1131
+ };
1132
+ }
1133
+ if (tagName === "iframe" && !keepIframeSrcFn(attributes.src)) {
1134
+ if (!n.contentDocument) {
1135
+ attributes.rr_src = attributes.src;
1136
+ }
1137
+ delete attributes.src;
1138
+ }
1139
+ let isCustomElement;
1140
+ try {
1141
+ if (customElements.get(tagName)) isCustomElement = true;
1142
+ } catch (e) {
1143
+ }
1144
+ return {
1145
+ type: types.NodeType$1.Element,
1146
+ tagName,
1147
+ attributes,
1148
+ childNodes: [],
1149
+ isSVG: isSVGElement(n) || void 0,
1150
+ needBlock,
1151
+ rootId,
1152
+ isCustom: isCustomElement
1153
+ };
1154
+ }
1155
+ function lowerIfExists(maybeAttr) {
1156
+ if (maybeAttr === void 0 || maybeAttr === null) {
1157
+ return "";
1158
+ } else {
1159
+ return maybeAttr.toLowerCase();
1160
+ }
1161
+ }
1162
+ function slimDOMExcluded(sn, slimDOMOptions) {
1163
+ if (slimDOMOptions.comment && sn.type === types.NodeType$1.Comment) {
1164
+ return true;
1165
+ } else if (sn.type === types.NodeType$1.Element) {
1166
+ if (slimDOMOptions.script && // script tag
1167
+ (sn.tagName === "script" || // (module)preload link
1168
+ sn.tagName === "link" && (sn.attributes.rel === "preload" && sn.attributes.as === "script" || sn.attributes.rel === "modulepreload") || // prefetch link
1169
+ sn.tagName === "link" && sn.attributes.rel === "prefetch" && typeof sn.attributes.href === "string" && types.extractFileExtension(sn.attributes.href) === "js")) {
1170
+ return true;
1171
+ } else if (slimDOMOptions.headFavicon && (sn.tagName === "link" && sn.attributes.rel === "shortcut icon" || sn.tagName === "meta" && (lowerIfExists(sn.attributes.name).match(
1172
+ /^msapplication-tile(image|color)$/
1173
+ ) || lowerIfExists(sn.attributes.name) === "application-name" || lowerIfExists(sn.attributes.rel) === "icon" || lowerIfExists(sn.attributes.rel) === "apple-touch-icon" || lowerIfExists(sn.attributes.rel) === "shortcut icon"))) {
1174
+ return true;
1175
+ } else if (sn.tagName === "meta") {
1176
+ if (slimDOMOptions.headMetaDescKeywords && lowerIfExists(sn.attributes.name).match(/^description|keywords$/)) {
1177
+ return true;
1178
+ } else if (slimDOMOptions.headMetaSocial && (lowerIfExists(sn.attributes.property).match(/^(og|twitter|fb):/) || // og = opengraph (facebook)
1179
+ lowerIfExists(sn.attributes.name).match(/^(og|twitter):/) || lowerIfExists(sn.attributes.name) === "pinterest")) {
1180
+ return true;
1181
+ } else if (slimDOMOptions.headMetaRobots && (lowerIfExists(sn.attributes.name) === "robots" || lowerIfExists(sn.attributes.name) === "googlebot" || lowerIfExists(sn.attributes.name) === "bingbot")) {
1182
+ return true;
1183
+ } else if (slimDOMOptions.headMetaHttpEquiv && sn.attributes["http-equiv"] !== void 0) {
1184
+ return true;
1185
+ } 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:/))) {
1186
+ return true;
1187
+ } 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")) {
1188
+ return true;
1189
+ }
1190
+ }
1191
+ }
1192
+ return false;
1193
+ }
1194
+ var DEFAULT_MAX_DEPTH = 50;
1195
+ var _maxDepthWarned = false;
1196
+ var _maxDepthReached = false;
1197
+ function wasMaxDepthReached() {
1198
+ return _maxDepthReached;
1199
+ }
1200
+ function resetMaxDepthState() {
1201
+ _maxDepthReached = false;
1202
+ _maxDepthWarned = false;
1203
+ }
1204
+ function serializeNodeWithId(n, options) {
1205
+ const {
1206
+ doc,
1207
+ mirror,
1208
+ blockClass,
1209
+ blockSelector,
1210
+ maskTextClass,
1211
+ maskTextSelector,
1212
+ skipChild = false,
1213
+ inlineStylesheet = true,
1214
+ maskInputOptions = {},
1215
+ maskTextFn,
1216
+ maskInputFn,
1217
+ slimDOMOptions,
1218
+ dataURLOptions = {},
1219
+ inlineImages = false,
1220
+ recordCanvas = false,
1221
+ onSerialize,
1222
+ onIframeLoad,
1223
+ iframeLoadTimeout = 5e3,
1224
+ onStylesheetLoad,
1225
+ stylesheetLoadTimeout = 5e3,
1226
+ keepIframeSrcFn = () => false,
1227
+ newlyAddedElement = false,
1228
+ depth = 0,
1229
+ maxDepth = DEFAULT_MAX_DEPTH
1230
+ } = options;
1231
+ let { needsMask } = options;
1232
+ let { preserveWhiteSpace = true } = options;
1233
+ if (depth >= maxDepth) {
1234
+ _maxDepthReached = true;
1235
+ if (!_maxDepthWarned) {
1236
+ _maxDepthWarned = true;
1237
+ console.warn(
1238
+ `[rrweb-snapshot] DOM tree depth exceeded max depth of ${maxDepth}. Children beyond this depth will not be recorded. This may indicate deeply nested DOM structures.`
1239
+ );
1240
+ }
1241
+ return null;
1242
+ }
1243
+ if (!needsMask) {
1244
+ const checkAncestors = needsMask === void 0;
1245
+ needsMask = needMaskingText(
1246
+ n,
1247
+ maskTextClass,
1248
+ maskTextSelector,
1249
+ checkAncestors
1250
+ );
1251
+ }
1252
+ const _serializedNode = serializeNode(n, {
1253
+ doc,
1254
+ mirror,
1255
+ blockClass,
1256
+ blockSelector,
1257
+ needsMask,
1258
+ inlineStylesheet,
1259
+ maskInputOptions,
1260
+ maskTextFn,
1261
+ maskInputFn,
1262
+ dataURLOptions,
1263
+ inlineImages,
1264
+ recordCanvas,
1265
+ keepIframeSrcFn,
1266
+ newlyAddedElement
1267
+ });
1268
+ if (!_serializedNode) {
1269
+ console.warn(n, "not serialized");
1270
+ return null;
1271
+ }
1272
+ let id;
1273
+ if (mirror.hasNode(n)) {
1274
+ id = mirror.getId(n);
1275
+ } else if (slimDOMExcluded(_serializedNode, slimDOMOptions) || !preserveWhiteSpace && _serializedNode.type === types.NodeType$1.Text && !_serializedNode.isStyle && !_serializedNode.textContent.replace(/^\s+|\s+$/gm, "").length) {
1276
+ id = IGNORED_NODE;
1277
+ } else {
1278
+ id = genId();
1279
+ }
1280
+ const serializedNode = Object.assign(_serializedNode, { id });
1281
+ mirror.add(n, serializedNode);
1282
+ if (id === IGNORED_NODE) {
1283
+ return null;
1284
+ }
1285
+ if (onSerialize) {
1286
+ onSerialize(n);
1287
+ }
1288
+ let recordChild = !skipChild;
1289
+ if (serializedNode.type === types.NodeType$1.Element) {
1290
+ recordChild = recordChild && !serializedNode.needBlock;
1291
+ delete serializedNode.needBlock;
1292
+ const shadowRootEl = types.index.shadowRoot(n);
1293
+ if (shadowRootEl && types.isNativeShadowDom(shadowRootEl))
1294
+ serializedNode.isShadowHost = true;
1295
+ }
1296
+ if ((serializedNode.type === types.NodeType$1.Document || serializedNode.type === types.NodeType$1.Element) && recordChild) {
1297
+ if (slimDOMOptions.headWhitespace && serializedNode.type === types.NodeType$1.Element && serializedNode.tagName === "head") {
1298
+ preserveWhiteSpace = false;
1299
+ }
1300
+ const bypassOptions = {
1301
+ doc,
1302
+ mirror,
1303
+ blockClass,
1304
+ blockSelector,
1305
+ needsMask,
1306
+ maskTextClass,
1307
+ maskTextSelector,
1308
+ skipChild,
1309
+ inlineStylesheet,
1310
+ maskInputOptions,
1311
+ maskTextFn,
1312
+ maskInputFn,
1313
+ slimDOMOptions,
1314
+ dataURLOptions,
1315
+ inlineImages,
1316
+ recordCanvas,
1317
+ preserveWhiteSpace,
1318
+ onSerialize,
1319
+ onIframeLoad,
1320
+ iframeLoadTimeout,
1321
+ onStylesheetLoad,
1322
+ stylesheetLoadTimeout,
1323
+ keepIframeSrcFn,
1324
+ depth: depth + 1,
1325
+ maxDepth
1326
+ };
1327
+ if (serializedNode.type === types.NodeType$1.Element && serializedNode.tagName === "textarea" && serializedNode.attributes.value !== void 0) ;
1328
+ else {
1329
+ for (const childN of Array.from(types.index.childNodes(n))) {
1330
+ const serializedChildNode = serializeNodeWithId(childN, bypassOptions);
1331
+ if (serializedChildNode) {
1332
+ serializedNode.childNodes.push(serializedChildNode);
1333
+ }
1334
+ }
1335
+ }
1336
+ let shadowRootEl = null;
1337
+ if (types.isElement(n) && (shadowRootEl = types.index.shadowRoot(n))) {
1338
+ for (const childN of Array.from(types.index.childNodes(shadowRootEl))) {
1339
+ const serializedChildNode = serializeNodeWithId(childN, bypassOptions);
1340
+ if (serializedChildNode) {
1341
+ types.isNativeShadowDom(shadowRootEl) && (serializedChildNode.isShadow = true);
1342
+ serializedNode.childNodes.push(serializedChildNode);
1343
+ }
1344
+ }
1345
+ }
1346
+ }
1347
+ const parent = types.index.parentNode(n);
1348
+ if (parent && types.isShadowRoot(parent) && types.isNativeShadowDom(parent)) {
1349
+ serializedNode.isShadow = true;
1350
+ }
1351
+ if (serializedNode.type === types.NodeType$1.Element && serializedNode.tagName === "iframe") {
1352
+ onceIframeLoaded(
1353
+ n,
1354
+ () => {
1355
+ const iframeDoc = n.contentDocument;
1356
+ if (iframeDoc && onIframeLoad) {
1357
+ const serializedIframeNode = serializeNodeWithId(iframeDoc, {
1358
+ doc: iframeDoc,
1359
+ mirror,
1360
+ blockClass,
1361
+ blockSelector,
1362
+ needsMask,
1363
+ maskTextClass,
1364
+ maskTextSelector,
1365
+ skipChild: false,
1366
+ inlineStylesheet,
1367
+ maskInputOptions,
1368
+ maskTextFn,
1369
+ maskInputFn,
1370
+ slimDOMOptions,
1371
+ dataURLOptions,
1372
+ inlineImages,
1373
+ recordCanvas,
1374
+ preserveWhiteSpace,
1375
+ onSerialize,
1376
+ onIframeLoad,
1377
+ iframeLoadTimeout,
1378
+ onStylesheetLoad,
1379
+ stylesheetLoadTimeout,
1380
+ keepIframeSrcFn,
1381
+ depth: depth + 1,
1382
+ maxDepth
1383
+ });
1384
+ if (serializedIframeNode) {
1385
+ onIframeLoad(
1386
+ n,
1387
+ serializedIframeNode
1388
+ );
1389
+ }
1390
+ }
1391
+ },
1392
+ iframeLoadTimeout
1393
+ );
1394
+ }
1395
+ 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")) {
1396
+ onceStylesheetLoaded(
1397
+ n,
1398
+ () => {
1399
+ if (onStylesheetLoad) {
1400
+ const serializedLinkNode = serializeNodeWithId(n, {
1401
+ doc,
1402
+ mirror,
1403
+ blockClass,
1404
+ blockSelector,
1405
+ needsMask,
1406
+ maskTextClass,
1407
+ maskTextSelector,
1408
+ skipChild: false,
1409
+ inlineStylesheet,
1410
+ maskInputOptions,
1411
+ maskTextFn,
1412
+ maskInputFn,
1413
+ slimDOMOptions,
1414
+ dataURLOptions,
1415
+ inlineImages,
1416
+ recordCanvas,
1417
+ preserveWhiteSpace,
1418
+ onSerialize,
1419
+ onIframeLoad,
1420
+ iframeLoadTimeout,
1421
+ onStylesheetLoad,
1422
+ stylesheetLoadTimeout,
1423
+ keepIframeSrcFn,
1424
+ depth,
1425
+ maxDepth
1426
+ });
1427
+ if (serializedLinkNode) {
1428
+ onStylesheetLoad(
1429
+ n,
1430
+ serializedLinkNode
1431
+ );
1432
+ }
1433
+ }
1434
+ },
1435
+ stylesheetLoadTimeout
1436
+ );
1437
+ }
1438
+ return serializedNode;
1439
+ }
1440
+ function snapshot(n, options) {
1441
+ const {
1442
+ mirror = new types.Mirror(),
1443
+ blockClass = "rr-block",
1444
+ blockSelector = null,
1445
+ maskTextClass = "rr-mask",
1446
+ maskTextSelector = null,
1447
+ inlineStylesheet = true,
1448
+ inlineImages = false,
1449
+ recordCanvas = false,
1450
+ maskAllInputs = false,
1451
+ maskTextFn,
1452
+ maskInputFn,
1453
+ slimDOM = false,
1454
+ dataURLOptions,
1455
+ preserveWhiteSpace,
1456
+ onSerialize,
1457
+ onIframeLoad,
1458
+ iframeLoadTimeout,
1459
+ onStylesheetLoad,
1460
+ stylesheetLoadTimeout,
1461
+ keepIframeSrcFn = () => false,
1462
+ maxDepth
1463
+ } = options || {};
1464
+ const maskInputOptions = maskAllInputs === true ? {
1465
+ color: true,
1466
+ date: true,
1467
+ "datetime-local": true,
1468
+ email: true,
1469
+ month: true,
1470
+ number: true,
1471
+ range: true,
1472
+ search: true,
1473
+ tel: true,
1474
+ text: true,
1475
+ time: true,
1476
+ url: true,
1477
+ week: true,
1478
+ textarea: true,
1479
+ select: true,
1480
+ password: true
1481
+ } : maskAllInputs === false ? {
1482
+ password: true
1483
+ } : maskAllInputs;
1484
+ const slimDOMOptions = slimDOM === true || slimDOM === "all" ? (
1485
+ // if true: set of sensible options that should not throw away any information
1486
+ {
1487
+ script: true,
1488
+ comment: true,
1489
+ headFavicon: true,
1490
+ headWhitespace: true,
1491
+ headMetaDescKeywords: slimDOM === "all",
1492
+ // destructive
1493
+ headMetaSocial: true,
1494
+ headMetaRobots: true,
1495
+ headMetaHttpEquiv: true,
1496
+ headMetaAuthorship: true,
1497
+ headMetaVerification: true
1498
+ }
1499
+ ) : slimDOM === false ? {} : slimDOM;
1500
+ return serializeNodeWithId(n, {
1501
+ doc: n,
1502
+ mirror,
1503
+ blockClass,
1504
+ blockSelector,
1505
+ maskTextClass,
1506
+ maskTextSelector,
1507
+ skipChild: false,
1508
+ inlineStylesheet,
1509
+ maskInputOptions,
1510
+ maskTextFn,
1511
+ maskInputFn,
1512
+ slimDOMOptions,
1513
+ dataURLOptions,
1514
+ inlineImages,
1515
+ recordCanvas,
1516
+ preserveWhiteSpace,
1517
+ onSerialize,
1518
+ onIframeLoad,
1519
+ iframeLoadTimeout,
1520
+ onStylesheetLoad,
1521
+ stylesheetLoadTimeout,
1522
+ keepIframeSrcFn,
1523
+ newlyAddedElement: false,
1524
+ maxDepth
1525
+ });
1526
+ }
1527
+ function visitSnapshot(node, onVisit) {
1528
+ function walk(current) {
1529
+ onVisit(current);
1530
+ if (current.type === types.NodeType$1.Document || current.type === types.NodeType$1.Element) {
1531
+ current.childNodes.forEach(walk);
1532
+ }
1533
+ }
1534
+ walk(node);
1535
+ }
1536
+ function cleanupSnapshot() {
1537
+ _id = 1;
1538
+ }
1539
+ exports.DEFAULT_MAX_DEPTH = DEFAULT_MAX_DEPTH;
1540
+ exports.IGNORED_NODE = IGNORED_NODE;
1541
+ exports.classMatchesRegex = classMatchesRegex;
1542
+ exports.cleanupSnapshot = cleanupSnapshot;
1543
+ exports.genId = genId;
1544
+ exports.ignoreAttribute = ignoreAttribute;
1545
+ exports.needMaskingText = needMaskingText;
1546
+ exports.resetMaxDepthState = resetMaxDepthState;
1547
+ exports.serializeNodeWithId = serializeNodeWithId;
1548
+ exports.snapshot = snapshot;
1549
+ exports.transformAttribute = transformAttribute;
1550
+ exports.visitSnapshot = visitSnapshot;
1551
+ exports.wasMaxDepthReached = wasMaxDepthReached;
1552
+ ;if (typeof module.exports == "object" && typeof exports == "object") {
1553
+ var __cp = (to, from, except, desc) => {
1554
+ if ((from && typeof from === "object") || typeof from === "function") {
1555
+ for (let key of Object.getOwnPropertyNames(from)) {
1556
+ if (!Object.prototype.hasOwnProperty.call(to, key) && key !== except)
1557
+ Object.defineProperty(to, key, {
1558
+ get: () => from[key],
1559
+ enumerable: !(desc = Object.getOwnPropertyDescriptor(from, key)) || desc.enumerable,
1560
+ });
1561
+ }
1562
+ }
1563
+ return to;
1564
+ };
1565
+ module.exports = __cp(module.exports, exports);
1566
+ }
1567
+ return module.exports;
1568
+ }))
1569
+ //# sourceMappingURL=record-oACzRSl-.umd.cjs.map