@highlight-run/rrweb 1.2.0 → 2.0.1

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 (185) hide show
  1. package/dist/plugins/console-record.js +655 -0
  2. package/dist/plugins/console-record.min.js +1 -1
  3. package/dist/plugins/console-record.min.js.map +1 -1
  4. package/dist/plugins/console-replay.js +293 -0
  5. package/dist/plugins/console-replay.min.js +16 -0
  6. package/dist/plugins/console-replay.min.js.map +1 -0
  7. package/dist/plugins/sequential-id-record.js +33 -0
  8. package/dist/plugins/sequential-id-record.min.js +2 -0
  9. package/dist/plugins/sequential-id-record.min.js.map +1 -0
  10. package/dist/plugins/sequential-id-replay.js +37 -0
  11. package/dist/plugins/sequential-id-replay.min.js +2 -0
  12. package/dist/plugins/sequential-id-replay.min.js.map +1 -0
  13. package/dist/record/rrweb-record-pack.js +747 -0
  14. package/dist/record/rrweb-record-pack.min.js +16 -0
  15. package/dist/record/rrweb-record-pack.min.js.map +1 -0
  16. package/dist/record/rrweb-record.js +3318 -0
  17. package/dist/record/rrweb-record.min.js +16 -0
  18. package/dist/record/rrweb-record.min.js.map +1 -0
  19. package/dist/replay/rrweb-replay-unpack.js +4626 -0
  20. package/dist/replay/rrweb-replay-unpack.min.css +2 -0
  21. package/dist/replay/rrweb-replay-unpack.min.css.map +1 -0
  22. package/dist/replay/rrweb-replay-unpack.min.js +30 -0
  23. package/dist/replay/rrweb-replay-unpack.min.js.map +1 -0
  24. package/dist/replay/rrweb-replay.js +4216 -0
  25. package/dist/replay/rrweb-replay.min.css +2 -0
  26. package/dist/replay/rrweb-replay.min.css.map +1 -0
  27. package/dist/replay/rrweb-replay.min.js +30 -0
  28. package/dist/replay/rrweb-replay.min.js.map +1 -0
  29. package/dist/rrweb-all.js +8708 -0
  30. package/dist/rrweb-all.min.css +2 -0
  31. package/dist/rrweb-all.min.css.map +1 -0
  32. package/dist/rrweb-all.min.js +30 -0
  33. package/dist/rrweb-all.min.js.map +1 -0
  34. package/dist/rrweb.js +7294 -0
  35. package/dist/rrweb.min.css +2 -0
  36. package/dist/rrweb.min.css.map +1 -0
  37. package/dist/rrweb.min.js +2 -2
  38. package/dist/rrweb.min.js.map +1 -1
  39. package/es/rrweb/ext/@xstate/fsm/es/index.js +17 -0
  40. package/es/rrweb/ext/base64-arraybuffer/dist/base64-arraybuffer.es5.js +49 -0
  41. package/es/rrweb/ext/fflate/esm/browser.js +777 -0
  42. package/es/rrweb/ext/mitt/dist/mitt.es.js +63 -0
  43. package/es/rrweb/packages/rrweb/ext/tslib/tslib.es6.js +78 -0
  44. package/es/rrweb/packages/rrweb/src/entries/all.js +13 -0
  45. package/es/rrweb/packages/rrweb/src/index.js +12 -0
  46. package/es/rrweb/packages/rrweb/src/packer/base.js +3 -0
  47. package/es/rrweb/packages/rrweb/src/packer/pack.js +10 -0
  48. package/es/rrweb/packages/rrweb/src/packer/unpack.js +29 -0
  49. package/es/rrweb/packages/rrweb/src/plugins/console/record/error-stack-parser.js +179 -0
  50. package/es/rrweb/packages/rrweb/src/plugins/console/record/index.js +134 -0
  51. package/es/rrweb/packages/rrweb/src/plugins/console/record/stringify.js +141 -0
  52. package/es/rrweb/packages/rrweb/src/plugins/console/replay/index.js +111 -0
  53. package/es/rrweb/packages/rrweb/src/plugins/sequential-id/record/index.js +23 -0
  54. package/es/rrweb/packages/rrweb/src/plugins/sequential-id/replay/index.js +28 -0
  55. package/es/rrweb/packages/rrweb/src/record/iframe-manager.js +32 -0
  56. package/es/rrweb/packages/rrweb/src/record/index.js +381 -0
  57. package/es/rrweb/packages/rrweb/src/record/mutation.js +532 -0
  58. package/es/rrweb/packages/rrweb/src/record/observer.js +665 -0
  59. package/es/rrweb/packages/rrweb/src/record/observers/canvas/2d.js +78 -0
  60. package/es/rrweb/packages/rrweb/src/record/observers/canvas/canvas-manager.js +93 -0
  61. package/es/rrweb/packages/rrweb/src/record/observers/canvas/canvas.js +30 -0
  62. package/es/rrweb/packages/rrweb/src/record/observers/canvas/serialize-args.js +116 -0
  63. package/es/rrweb/packages/rrweb/src/record/observers/canvas/webgl.js +78 -0
  64. package/es/rrweb/packages/rrweb/src/record/shadow-dom-manager.js +45 -0
  65. package/es/rrweb/packages/rrweb/src/replay/canvas/2d.js +25 -0
  66. package/es/rrweb/packages/rrweb/src/replay/canvas/index.js +35 -0
  67. package/es/rrweb/packages/rrweb/src/replay/canvas/webgl.js +124 -0
  68. package/es/rrweb/packages/rrweb/src/replay/index.js +1864 -0
  69. package/es/rrweb/packages/rrweb/src/replay/machine.js +321 -0
  70. package/es/rrweb/packages/rrweb/src/replay/smoothscroll.js +221 -0
  71. package/es/rrweb/packages/rrweb/src/replay/styles/inject-style.js +8 -0
  72. package/es/rrweb/packages/rrweb/src/replay/timer.js +96 -0
  73. package/es/rrweb/packages/rrweb/src/replay/virtual-styles.js +121 -0
  74. package/es/rrweb/packages/rrweb/src/types.js +75 -0
  75. package/es/rrweb/packages/rrweb/src/utils.js +509 -0
  76. package/es/rrweb/packages/rrweb-snapshot/es/rrweb-snapshot.js +1697 -0
  77. package/lib/plugins/console-record.js +650 -0
  78. package/lib/plugins/console-replay.js +288 -0
  79. package/lib/plugins/sequential-id-record.js +28 -0
  80. package/lib/plugins/sequential-id-replay.js +32 -0
  81. package/lib/record/rrweb-record-pack.js +742 -0
  82. package/lib/record/rrweb-record.js +3315 -0
  83. package/lib/replay/rrweb-replay-unpack.js +4621 -0
  84. package/lib/replay/rrweb-replay.js +4211 -0
  85. package/lib/rrweb-all.js +8703 -0
  86. package/lib/rrweb.js +7289 -0
  87. package/package.json +41 -43
  88. package/typings/entries/all.d.ts +6 -0
  89. package/{dist → typings}/entries/record-pack.d.ts +0 -0
  90. package/{dist → typings}/entries/replay-unpack.d.ts +0 -0
  91. package/{dist → typings}/index.d.ts +1 -2
  92. package/{dist → typings}/packer/base.d.ts +0 -0
  93. package/{dist → typings}/packer/index.d.ts +0 -0
  94. package/{dist → typings}/packer/pack.d.ts +0 -0
  95. package/{dist → typings}/packer/unpack.d.ts +0 -0
  96. package/{dist → typings}/plugins/console/record/error-stack-parser.d.ts +0 -0
  97. package/{dist → typings}/plugins/console/record/index.d.ts +3 -2
  98. package/{dist → typings}/plugins/console/record/stringify.d.ts +0 -0
  99. package/{dist → typings}/plugins/console/replay/index.d.ts +2 -2
  100. package/{dist → typings}/plugins/sequential-id/record/index.d.ts +0 -0
  101. package/{dist → typings}/plugins/sequential-id/replay/index.d.ts +0 -0
  102. package/{dist → typings}/record/iframe-manager.d.ts +1 -1
  103. package/{dist → typings}/record/index.d.ts +0 -0
  104. package/{dist → typings}/record/mutation.d.ts +5 -8
  105. package/typings/record/observer.d.ts +7 -0
  106. package/{dist → typings}/record/observers/canvas/2d.d.ts +0 -0
  107. package/{dist → typings}/record/observers/canvas/canvas-manager.d.ts +0 -0
  108. package/{dist → typings}/record/observers/canvas/canvas.d.ts +0 -0
  109. package/{dist → typings}/record/observers/canvas/serialize-args.d.ts +1 -1
  110. package/{dist → typings}/record/observers/canvas/webgl.d.ts +0 -0
  111. package/typings/record/observers/canvas/webgl2.d.ts +2 -0
  112. package/typings/record/shadow-dom-manager.d.ts +21 -0
  113. package/{dist → typings}/replay/canvas/2d.d.ts +0 -0
  114. package/{dist → typings}/replay/canvas/index.d.ts +0 -0
  115. package/{dist → typings}/replay/canvas/webgl.d.ts +0 -0
  116. package/{dist → typings}/replay/index.d.ts +1 -0
  117. package/{dist → typings}/replay/machine.d.ts +0 -0
  118. package/{dist → typings}/replay/smoothscroll.d.ts +0 -0
  119. package/{dist → typings}/replay/styles/inject-style.d.ts +0 -0
  120. package/{dist → typings}/replay/timer.d.ts +0 -0
  121. package/{dist → typings}/replay/virtual-styles.d.ts +1 -1
  122. package/{dist → typings}/rrdom/index.d.ts +0 -0
  123. package/{dist → typings}/rrdom/tree-node.d.ts +0 -0
  124. package/{dist → typings}/types.d.ts +7 -8
  125. package/{dist → typings}/utils.d.ts +3 -4
  126. package/CHANGELOG.md +0 -26
  127. package/README.md +0 -124
  128. package/README.zh_CN.md +0 -122
  129. package/dist/entries/all.d.ts +0 -4
  130. package/dist/index.css +0 -82
  131. package/dist/index.css.map +0 -1
  132. package/dist/index.js +0 -3
  133. package/dist/index.js.LICENSE.txt +0 -14
  134. package/dist/index.js.map +0 -1
  135. package/dist/plugins/entries/all.d.ts +0 -4
  136. package/dist/plugins/entries/record-pack.d.ts +0 -2
  137. package/dist/plugins/entries/replay-unpack.d.ts +0 -2
  138. package/dist/plugins/index.d.ts +0 -9
  139. package/dist/plugins/packer/base.d.ts +0 -7
  140. package/dist/plugins/packer/index.d.ts +0 -2
  141. package/dist/plugins/packer/pack.d.ts +0 -2
  142. package/dist/plugins/packer/unpack.d.ts +0 -2
  143. package/dist/plugins/plugins/console/record/error-stack-parser.d.ts +0 -37
  144. package/dist/plugins/plugins/console/record/index.d.ts +0 -41
  145. package/dist/plugins/plugins/console/record/stringify.d.ts +0 -2
  146. package/dist/plugins/plugins/console/replay/index.d.ts +0 -9
  147. package/dist/plugins/plugins/sequential-id/record/index.d.ts +0 -6
  148. package/dist/plugins/plugins/sequential-id/replay/index.d.ts +0 -7
  149. package/dist/plugins/record/iframe-manager.d.ts +0 -13
  150. package/dist/plugins/record/index.d.ts +0 -9
  151. package/dist/plugins/record/mutation.d.ts +0 -45
  152. package/dist/plugins/record/observer.d.ts +0 -11
  153. package/dist/plugins/record/observers/canvas/2d.d.ts +0 -2
  154. package/dist/plugins/record/observers/canvas/canvas-manager.d.ts +0 -32
  155. package/dist/plugins/record/observers/canvas/canvas.d.ts +0 -2
  156. package/dist/plugins/record/observers/canvas/serialize-args.d.ts +0 -6
  157. package/dist/plugins/record/observers/canvas/webgl.d.ts +0 -2
  158. package/dist/plugins/record/shadow-dom-manager.d.ts +0 -34
  159. package/dist/plugins/replay/canvas/2d.d.ts +0 -9
  160. package/dist/plugins/replay/canvas/index.d.ts +0 -9
  161. package/dist/plugins/replay/canvas/webgl.d.ts +0 -11
  162. package/dist/plugins/replay/index.d.ts +0 -82
  163. package/dist/plugins/replay/machine.d.ts +0 -85
  164. package/dist/plugins/replay/smoothscroll.d.ts +0 -1
  165. package/dist/plugins/replay/styles/inject-style.d.ts +0 -2
  166. package/dist/plugins/replay/timer.d.ts +0 -19
  167. package/dist/plugins/replay/virtual-styles.d.ts +0 -43
  168. package/dist/plugins/rrdom/index.d.ts +0 -1
  169. package/dist/plugins/rrdom/tree-node.d.ts +0 -20
  170. package/dist/plugins/snapshot/css.d.ts +0 -92
  171. package/dist/plugins/snapshot/index.d.ts +0 -5
  172. package/dist/plugins/snapshot/rebuild.d.ts +0 -19
  173. package/dist/plugins/snapshot/snapshot.d.ts +0 -49
  174. package/dist/plugins/snapshot/types.d.ts +0 -99
  175. package/dist/plugins/snapshot/utils.d.ts +0 -11
  176. package/dist/plugins/types.d.ts +0 -509
  177. package/dist/plugins/utils.d.ts +0 -71
  178. package/dist/record/observer.d.ts +0 -11
  179. package/dist/record/shadow-dom-manager.d.ts +0 -34
  180. package/dist/snapshot/css.d.ts +0 -92
  181. package/dist/snapshot/index.d.ts +0 -5
  182. package/dist/snapshot/rebuild.d.ts +0 -19
  183. package/dist/snapshot/snapshot.d.ts +0 -49
  184. package/dist/snapshot/types.d.ts +0 -99
  185. package/dist/snapshot/utils.d.ts +0 -11
@@ -0,0 +1,3318 @@
1
+ var rrwebRecord = (function () {
2
+ 'use strict';
3
+
4
+ /*! *****************************************************************************
5
+ Copyright (c) Microsoft Corporation.
6
+
7
+ Permission to use, copy, modify, and/or distribute this software for any
8
+ purpose with or without fee is hereby granted.
9
+
10
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
11
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
12
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
13
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
14
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
15
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
16
+ PERFORMANCE OF THIS SOFTWARE.
17
+ ***************************************************************************** */
18
+
19
+ var __assign = function() {
20
+ __assign = Object.assign || function __assign(t) {
21
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
22
+ s = arguments[i];
23
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
24
+ }
25
+ return t;
26
+ };
27
+ return __assign.apply(this, arguments);
28
+ };
29
+
30
+ function __rest(s, e) {
31
+ var t = {};
32
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
33
+ t[p] = s[p];
34
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
35
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
36
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
37
+ t[p[i]] = s[p[i]];
38
+ }
39
+ return t;
40
+ }
41
+
42
+ function __values(o) {
43
+ var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
44
+ if (m) return m.call(o);
45
+ if (o && typeof o.length === "number") return {
46
+ next: function () {
47
+ if (o && i >= o.length) o = void 0;
48
+ return { value: o && o[i++], done: !o };
49
+ }
50
+ };
51
+ throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
52
+ }
53
+
54
+ function __read(o, n) {
55
+ var m = typeof Symbol === "function" && o[Symbol.iterator];
56
+ if (!m) return o;
57
+ var i = m.call(o), r, ar = [], e;
58
+ try {
59
+ while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
60
+ }
61
+ catch (error) { e = { error: error }; }
62
+ finally {
63
+ try {
64
+ if (r && !r.done && (m = i["return"])) m.call(i);
65
+ }
66
+ finally { if (e) throw e.error; }
67
+ }
68
+ return ar;
69
+ }
70
+
71
+ function __spreadArray(to, from, pack) {
72
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
73
+ if (ar || !(i in from)) {
74
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
75
+ ar[i] = from[i];
76
+ }
77
+ }
78
+ return to.concat(ar || Array.prototype.slice.call(from));
79
+ }
80
+
81
+ var NodeType;
82
+ (function (NodeType) {
83
+ NodeType[NodeType["Document"] = 0] = "Document";
84
+ NodeType[NodeType["DocumentType"] = 1] = "DocumentType";
85
+ NodeType[NodeType["Element"] = 2] = "Element";
86
+ NodeType[NodeType["Text"] = 3] = "Text";
87
+ NodeType[NodeType["CDATA"] = 4] = "CDATA";
88
+ NodeType[NodeType["Comment"] = 5] = "Comment";
89
+ })(NodeType || (NodeType = {}));
90
+
91
+ function isElement(n) {
92
+ return n.nodeType === n.ELEMENT_NODE;
93
+ }
94
+ function isShadowRoot(n) {
95
+ var _a;
96
+ var host = (_a = n) === null || _a === void 0 ? void 0 : _a.host;
97
+ return Boolean(host && host.shadowRoot && host.shadowRoot === n);
98
+ }
99
+ function maskInputValue(_a) {
100
+ var maskInputOptions = _a.maskInputOptions, tagName = _a.tagName, type = _a.type, value = _a.value, maskInputFn = _a.maskInputFn;
101
+ var text = value || '';
102
+ if (maskInputOptions[tagName.toLowerCase()] ||
103
+ maskInputOptions[type]) {
104
+ if (maskInputFn) {
105
+ text = maskInputFn(text);
106
+ }
107
+ else {
108
+ text = '*'.repeat(text.length);
109
+ }
110
+ }
111
+ return text;
112
+ }
113
+ var ORIGINAL_ATTRIBUTE_NAME = '__rrweb_original__';
114
+ function is2DCanvasBlank(canvas) {
115
+ var ctx = canvas.getContext('2d');
116
+ if (!ctx)
117
+ return true;
118
+ var chunkSize = 50;
119
+ for (var x = 0; x < canvas.width; x += chunkSize) {
120
+ for (var y = 0; y < canvas.height; y += chunkSize) {
121
+ var getImageData = ctx.getImageData;
122
+ var originalGetImageData = ORIGINAL_ATTRIBUTE_NAME in getImageData
123
+ ? getImageData[ORIGINAL_ATTRIBUTE_NAME]
124
+ : getImageData;
125
+ var pixelBuffer = new Uint32Array(originalGetImageData.call(ctx, x, y, Math.min(chunkSize, canvas.width - x), Math.min(chunkSize, canvas.height - y)).data.buffer);
126
+ if (pixelBuffer.some(function (pixel) { return pixel !== 0; }))
127
+ return false;
128
+ }
129
+ }
130
+ return true;
131
+ }
132
+ function obfuscateText(text) {
133
+ text = text.replace(/[^ -~]+/g, '');
134
+ text =
135
+ (text === null || text === void 0 ? void 0 : text.split(' ').map(function (word) { return Math.random().toString(20).substr(2, word.length); }).join(' ')) || '';
136
+ return text;
137
+ }
138
+
139
+ var _id = 1;
140
+ var tagNameRegex = new RegExp('[^a-z0-9-_:]');
141
+ var IGNORED_NODE = -2;
142
+ function genId() {
143
+ return _id++;
144
+ }
145
+ function getValidTagName(element) {
146
+ if (element instanceof HTMLFormElement) {
147
+ return 'form';
148
+ }
149
+ var processedTagName = element.tagName.toLowerCase().trim();
150
+ if (tagNameRegex.test(processedTagName)) {
151
+ return 'div';
152
+ }
153
+ return processedTagName;
154
+ }
155
+ function getCssRulesString(s) {
156
+ try {
157
+ var rules = s.rules || s.cssRules;
158
+ return rules ? Array.from(rules).map(getCssRuleString).join('') : null;
159
+ }
160
+ catch (error) {
161
+ return null;
162
+ }
163
+ }
164
+ function getCssRuleString(rule) {
165
+ var cssStringified = rule.cssText;
166
+ if (isCSSImportRule(rule)) {
167
+ try {
168
+ cssStringified = getCssRulesString(rule.styleSheet) || cssStringified;
169
+ }
170
+ catch (_a) {
171
+ }
172
+ }
173
+ return cssStringified;
174
+ }
175
+ function isCSSImportRule(rule) {
176
+ return 'styleSheet' in rule;
177
+ }
178
+ function stringifyStyleSheet(sheet) {
179
+ return sheet.cssRules
180
+ ? Array.from(sheet.cssRules)
181
+ .map(function (rule) { return rule.cssText || ''; })
182
+ .join('')
183
+ : '';
184
+ }
185
+ function extractOrigin(url) {
186
+ var origin = '';
187
+ if (url.indexOf('//') > -1) {
188
+ origin = url.split('/').slice(0, 3).join('/');
189
+ }
190
+ else {
191
+ origin = url.split('/')[0];
192
+ }
193
+ origin = origin.split('?')[0];
194
+ return origin;
195
+ }
196
+ var canvasService;
197
+ var canvasCtx;
198
+ var URL_IN_CSS_REF = /url\((?:(')([^']*)'|(")(.*?)"|([^)]*))\)/gm;
199
+ var RELATIVE_PATH = /^(?!www\.|(?:http|ftp)s?:\/\/|[A-Za-z]:\\|\/\/|#).*/;
200
+ var DATA_URI = /^(data:)([^,]*),(.*)/i;
201
+ function absoluteToStylesheet(cssText, href) {
202
+ return (cssText || '').replace(URL_IN_CSS_REF, function (origin, quote1, path1, quote2, path2, path3) {
203
+ var filePath = path1 || path2 || path3;
204
+ var maybeQuote = quote1 || quote2 || '';
205
+ if (!filePath) {
206
+ return origin;
207
+ }
208
+ if (!RELATIVE_PATH.test(filePath)) {
209
+ return "url(" + maybeQuote + filePath + maybeQuote + ")";
210
+ }
211
+ if (DATA_URI.test(filePath)) {
212
+ return "url(" + maybeQuote + filePath + maybeQuote + ")";
213
+ }
214
+ if (filePath[0] === '/') {
215
+ return "url(" + maybeQuote + (extractOrigin(href) + filePath) + maybeQuote + ")";
216
+ }
217
+ var stack = href.split('/');
218
+ var parts = filePath.split('/');
219
+ stack.pop();
220
+ for (var _i = 0, parts_1 = parts; _i < parts_1.length; _i++) {
221
+ var part = parts_1[_i];
222
+ if (part === '.') {
223
+ continue;
224
+ }
225
+ else if (part === '..') {
226
+ stack.pop();
227
+ }
228
+ else {
229
+ stack.push(part);
230
+ }
231
+ }
232
+ return "url(" + maybeQuote + stack.join('/') + maybeQuote + ")";
233
+ });
234
+ }
235
+ var SRCSET_NOT_SPACES = /^[^ \t\n\r\u000c]+/;
236
+ var SRCSET_COMMAS_OR_SPACES = /^[, \t\n\r\u000c]+/;
237
+ function getAbsoluteSrcsetString(doc, attributeValue) {
238
+ if (attributeValue.trim() === '') {
239
+ return attributeValue;
240
+ }
241
+ var pos = 0;
242
+ function collectCharacters(regEx) {
243
+ var chars;
244
+ var match = regEx.exec(attributeValue.substring(pos));
245
+ if (match) {
246
+ chars = match[0];
247
+ pos += chars.length;
248
+ return chars;
249
+ }
250
+ return '';
251
+ }
252
+ var output = [];
253
+ while (true) {
254
+ collectCharacters(SRCSET_COMMAS_OR_SPACES);
255
+ if (pos >= attributeValue.length) {
256
+ break;
257
+ }
258
+ var url = collectCharacters(SRCSET_NOT_SPACES);
259
+ if (url.slice(-1) === ',') {
260
+ url = absoluteToDoc(doc, url.substring(0, url.length - 1));
261
+ output.push(url);
262
+ }
263
+ else {
264
+ var descriptorsStr = '';
265
+ url = absoluteToDoc(doc, url);
266
+ var inParens = false;
267
+ while (true) {
268
+ var c = attributeValue.charAt(pos);
269
+ if (c === '') {
270
+ output.push((url + descriptorsStr).trim());
271
+ break;
272
+ }
273
+ else if (!inParens) {
274
+ if (c === ',') {
275
+ pos += 1;
276
+ output.push((url + descriptorsStr).trim());
277
+ break;
278
+ }
279
+ else if (c === '(') {
280
+ inParens = true;
281
+ }
282
+ }
283
+ else {
284
+ if (c === ')') {
285
+ inParens = false;
286
+ }
287
+ }
288
+ descriptorsStr += c;
289
+ pos += 1;
290
+ }
291
+ }
292
+ }
293
+ return output.join(', ');
294
+ }
295
+ function absoluteToDoc(doc, attributeValue) {
296
+ if (!attributeValue || attributeValue.trim() === '') {
297
+ return attributeValue;
298
+ }
299
+ var a = doc.createElement('a');
300
+ a.href = attributeValue;
301
+ return a.href;
302
+ }
303
+ function isSVGElement(el) {
304
+ return Boolean(el.tagName === 'svg' || el.ownerSVGElement);
305
+ }
306
+ function getHref() {
307
+ var a = document.createElement('a');
308
+ a.href = '';
309
+ return a.href;
310
+ }
311
+ function transformAttribute(doc, tagName, name, value) {
312
+ if (name === 'src' || (name === 'href' && value)) {
313
+ return absoluteToDoc(doc, value);
314
+ }
315
+ else if (name === 'xlink:href' && value && value[0] !== '#') {
316
+ return absoluteToDoc(doc, value);
317
+ }
318
+ else if (name === 'background' &&
319
+ value &&
320
+ (tagName === 'table' || tagName === 'td' || tagName === 'th')) {
321
+ return absoluteToDoc(doc, value);
322
+ }
323
+ else if (name === 'srcset' && value) {
324
+ return getAbsoluteSrcsetString(doc, value);
325
+ }
326
+ else if (name === 'style' && value) {
327
+ return absoluteToStylesheet(value, getHref());
328
+ }
329
+ else if (tagName === 'object' && name === 'data' && value) {
330
+ return absoluteToDoc(doc, value);
331
+ }
332
+ else {
333
+ return value;
334
+ }
335
+ }
336
+ function _isBlockedElement(element, blockClass, blockSelector) {
337
+ if (typeof blockClass === 'string') {
338
+ if (element.classList.contains(blockClass)) {
339
+ return true;
340
+ }
341
+ }
342
+ else {
343
+ for (var eIndex = 0; eIndex < element.classList.length; eIndex++) {
344
+ var className = element.classList[eIndex];
345
+ if (blockClass.test(className)) {
346
+ return true;
347
+ }
348
+ }
349
+ }
350
+ if (blockSelector) {
351
+ return element.matches(blockSelector);
352
+ }
353
+ return false;
354
+ }
355
+ function needMaskingText(node, maskTextClass, maskTextSelector) {
356
+ if (!node) {
357
+ return false;
358
+ }
359
+ if (node.nodeType === node.ELEMENT_NODE) {
360
+ if (typeof maskTextClass === 'string') {
361
+ if (node.classList.contains(maskTextClass)) {
362
+ return true;
363
+ }
364
+ }
365
+ else {
366
+ for (var eIndex = 0; eIndex < node.classList.length; eIndex++) {
367
+ var className = node.classList[eIndex];
368
+ if (maskTextClass.test(className)) {
369
+ return true;
370
+ }
371
+ }
372
+ }
373
+ if (maskTextSelector) {
374
+ if (node.matches(maskTextSelector)) {
375
+ return true;
376
+ }
377
+ }
378
+ return needMaskingText(node.parentNode, maskTextClass, maskTextSelector);
379
+ }
380
+ if (node.nodeType === node.TEXT_NODE) {
381
+ return needMaskingText(node.parentNode, maskTextClass, maskTextSelector);
382
+ }
383
+ return needMaskingText(node.parentNode, maskTextClass, maskTextSelector);
384
+ }
385
+ function onceIframeLoaded(iframeEl, listener, iframeLoadTimeout) {
386
+ var win = iframeEl.contentWindow;
387
+ if (!win) {
388
+ return;
389
+ }
390
+ var fired = false;
391
+ var readyState;
392
+ try {
393
+ readyState = win.document.readyState;
394
+ }
395
+ catch (error) {
396
+ return;
397
+ }
398
+ if (readyState !== 'complete') {
399
+ var timer_1 = setTimeout(function () {
400
+ if (!fired) {
401
+ listener();
402
+ fired = true;
403
+ }
404
+ }, iframeLoadTimeout);
405
+ iframeEl.addEventListener('load', function () {
406
+ clearTimeout(timer_1);
407
+ fired = true;
408
+ listener();
409
+ });
410
+ return;
411
+ }
412
+ var blankUrl = 'about:blank';
413
+ if (win.location.href !== blankUrl ||
414
+ iframeEl.src === blankUrl ||
415
+ iframeEl.src === '') {
416
+ setTimeout(listener, 0);
417
+ return;
418
+ }
419
+ iframeEl.addEventListener('load', listener);
420
+ }
421
+ function serializeNode(n, options) {
422
+ var _a;
423
+ var doc = options.doc, blockClass = options.blockClass, blockSelector = options.blockSelector, maskTextClass = options.maskTextClass, maskTextSelector = options.maskTextSelector, inlineStylesheet = options.inlineStylesheet, _b = options.maskInputOptions, maskInputOptions = _b === void 0 ? {} : _b, maskTextFn = options.maskTextFn, maskInputFn = options.maskInputFn, _c = options.dataURLOptions, dataURLOptions = _c === void 0 ? {} : _c, inlineImages = options.inlineImages, recordCanvas = options.recordCanvas, keepIframeSrcFn = options.keepIframeSrcFn, enableStrictPrivacy = options.enableStrictPrivacy;
424
+ var rootId;
425
+ if (doc.__sn) {
426
+ var docId = doc.__sn.id;
427
+ rootId = docId === 1 ? undefined : docId;
428
+ }
429
+ switch (n.nodeType) {
430
+ case n.DOCUMENT_NODE:
431
+ if (n.compatMode !== 'CSS1Compat') {
432
+ return {
433
+ type: NodeType.Document,
434
+ childNodes: [],
435
+ compatMode: n.compatMode,
436
+ rootId: rootId
437
+ };
438
+ }
439
+ else {
440
+ return {
441
+ type: NodeType.Document,
442
+ childNodes: [],
443
+ rootId: rootId
444
+ };
445
+ }
446
+ case n.DOCUMENT_TYPE_NODE:
447
+ return {
448
+ type: NodeType.DocumentType,
449
+ name: n.name,
450
+ publicId: n.publicId,
451
+ systemId: n.systemId,
452
+ rootId: rootId
453
+ };
454
+ case n.ELEMENT_NODE:
455
+ var needBlock = _isBlockedElement(n, blockClass, blockSelector);
456
+ var tagName = getValidTagName(n);
457
+ var attributes_1 = {};
458
+ for (var _i = 0, _d = Array.from(n.attributes); _i < _d.length; _i++) {
459
+ var _e = _d[_i], name_1 = _e.name, value = _e.value;
460
+ attributes_1[name_1] = transformAttribute(doc, tagName, name_1, value);
461
+ }
462
+ if (tagName === 'link' && inlineStylesheet) {
463
+ var stylesheet = Array.from(doc.styleSheets).find(function (s) {
464
+ return s.href === n.href;
465
+ });
466
+ var cssText = null;
467
+ if (stylesheet) {
468
+ cssText = getCssRulesString(stylesheet);
469
+ }
470
+ if (cssText) {
471
+ delete attributes_1.rel;
472
+ delete attributes_1.href;
473
+ attributes_1._cssText = absoluteToStylesheet(cssText, stylesheet.href);
474
+ }
475
+ }
476
+ if (tagName === 'style' &&
477
+ n.sheet &&
478
+ !(n.innerText ||
479
+ n.textContent ||
480
+ '').trim().length) {
481
+ var cssText = getCssRulesString(n.sheet);
482
+ if (cssText) {
483
+ attributes_1._cssText = absoluteToStylesheet(cssText, getHref());
484
+ }
485
+ }
486
+ if (tagName === 'input' ||
487
+ tagName === 'textarea' ||
488
+ tagName === 'select') {
489
+ var value = n.value;
490
+ if (attributes_1.type !== 'radio' &&
491
+ attributes_1.type !== 'checkbox' &&
492
+ attributes_1.type !== 'submit' &&
493
+ attributes_1.type !== 'button' &&
494
+ value) {
495
+ attributes_1.value = maskInputValue({
496
+ type: attributes_1.type,
497
+ tagName: tagName,
498
+ value: value,
499
+ maskInputOptions: maskInputOptions,
500
+ maskInputFn: maskInputFn
501
+ });
502
+ }
503
+ else if (n.checked) {
504
+ attributes_1.checked = n.checked;
505
+ }
506
+ }
507
+ if (tagName === 'option') {
508
+ if (n.selected && !maskInputOptions['select']) {
509
+ attributes_1.selected = true;
510
+ }
511
+ else {
512
+ delete attributes_1.selected;
513
+ }
514
+ }
515
+ if (tagName === 'canvas' && recordCanvas) {
516
+ if (n.__context === '2d') {
517
+ if (!is2DCanvasBlank(n)) {
518
+ attributes_1.rr_dataURL = n.toDataURL(dataURLOptions.type, dataURLOptions.quality);
519
+ }
520
+ }
521
+ else if (!('__context' in n)) {
522
+ var canvasDataURL = n.toDataURL(dataURLOptions.type, dataURLOptions.quality);
523
+ var blankCanvas = document.createElement('canvas');
524
+ blankCanvas.width = n.width;
525
+ blankCanvas.height = n.height;
526
+ var blankCanvasDataURL = blankCanvas.toDataURL(dataURLOptions.type, dataURLOptions.quality);
527
+ if (canvasDataURL !== blankCanvasDataURL) {
528
+ attributes_1.rr_dataURL = canvasDataURL;
529
+ }
530
+ }
531
+ }
532
+ if (tagName === 'img' && inlineImages) {
533
+ if (!canvasService) {
534
+ canvasService = doc.createElement('canvas');
535
+ canvasCtx = canvasService.getContext('2d');
536
+ }
537
+ var image_1 = n;
538
+ var oldValue_1 = image_1.crossOrigin;
539
+ image_1.crossOrigin = 'anonymous';
540
+ var recordInlineImage = function () {
541
+ try {
542
+ canvasService.width = image_1.naturalWidth;
543
+ canvasService.height = image_1.naturalHeight;
544
+ canvasCtx.drawImage(image_1, 0, 0);
545
+ attributes_1.rr_dataURL = canvasService.toDataURL(dataURLOptions.type, dataURLOptions.quality);
546
+ }
547
+ catch (err) {
548
+ console.warn("Cannot inline img src=" + image_1.currentSrc + "! Error: " + err);
549
+ }
550
+ oldValue_1
551
+ ? (attributes_1.crossOrigin = oldValue_1)
552
+ : delete attributes_1.crossOrigin;
553
+ };
554
+ if (image_1.complete && image_1.naturalWidth !== 0)
555
+ recordInlineImage();
556
+ else
557
+ image_1.onload = recordInlineImage;
558
+ }
559
+ if (tagName === 'audio' || tagName === 'video') {
560
+ attributes_1.rr_mediaState = n.paused
561
+ ? 'paused'
562
+ : 'played';
563
+ attributes_1.rr_mediaCurrentTime = n.currentTime;
564
+ }
565
+ if (n.scrollLeft) {
566
+ attributes_1.rr_scrollLeft = n.scrollLeft;
567
+ }
568
+ if (n.scrollTop) {
569
+ attributes_1.rr_scrollTop = n.scrollTop;
570
+ }
571
+ if (needBlock || (tagName === 'img' && enableStrictPrivacy)) {
572
+ var _f = n.getBoundingClientRect(), width = _f.width, height = _f.height;
573
+ attributes_1 = {
574
+ "class": attributes_1["class"],
575
+ rr_width: width + "px",
576
+ rr_height: height + "px"
577
+ };
578
+ needBlock = true;
579
+ }
580
+ if (tagName === 'iframe' && !keepIframeSrcFn(attributes_1.src)) {
581
+ if (!n.contentDocument) {
582
+ attributes_1.rr_src = attributes_1.src;
583
+ }
584
+ delete attributes_1.src;
585
+ }
586
+ return {
587
+ type: NodeType.Element,
588
+ tagName: tagName,
589
+ attributes: attributes_1,
590
+ childNodes: [],
591
+ isSVG: isSVGElement(n) || undefined,
592
+ needBlock: needBlock,
593
+ rootId: rootId
594
+ };
595
+ case n.TEXT_NODE:
596
+ var parentTagName = n.parentNode && n.parentNode.tagName;
597
+ var textContent = n.textContent;
598
+ var isStyle = parentTagName === 'STYLE' ? true : undefined;
599
+ var isScript = parentTagName === 'SCRIPT' ? true : undefined;
600
+ var textContentHandled = false;
601
+ if (isStyle && textContent) {
602
+ try {
603
+ if (n.nextSibling || n.previousSibling) {
604
+ }
605
+ else if ((_a = n.parentNode.sheet) === null || _a === void 0 ? void 0 : _a.cssRules) {
606
+ textContent = stringifyStyleSheet(n.parentNode.sheet);
607
+ }
608
+ }
609
+ catch (err) {
610
+ console.warn("Cannot get CSS styles from text's parentNode. Error: " + err, n);
611
+ }
612
+ textContent = absoluteToStylesheet(textContent, getHref());
613
+ textContentHandled = true;
614
+ }
615
+ if (isScript) {
616
+ textContent = 'SCRIPT_PLACEHOLDER';
617
+ textContentHandled = true;
618
+ }
619
+ else if (parentTagName === 'NOSCRIPT') {
620
+ textContent = '';
621
+ textContentHandled = true;
622
+ }
623
+ if (!isStyle &&
624
+ !isScript &&
625
+ needMaskingText(n, maskTextClass, maskTextSelector) &&
626
+ textContent) {
627
+ textContent = maskTextFn
628
+ ? maskTextFn(textContent)
629
+ : textContent.replace(/[\S]/g, '*');
630
+ }
631
+ if (enableStrictPrivacy && !textContentHandled && parentTagName) {
632
+ var IGNORE_TAG_NAMES = new Set([
633
+ 'HEAD',
634
+ 'TITLE',
635
+ 'STYLE',
636
+ 'SCRIPT',
637
+ 'HTML',
638
+ 'BODY',
639
+ 'NOSCRIPT',
640
+ ]);
641
+ if (!IGNORE_TAG_NAMES.has(parentTagName) && textContent) {
642
+ textContent = obfuscateText(textContent);
643
+ }
644
+ }
645
+ return {
646
+ type: NodeType.Text,
647
+ textContent: textContent || '',
648
+ isStyle: isStyle,
649
+ rootId: rootId
650
+ };
651
+ case n.CDATA_SECTION_NODE:
652
+ return {
653
+ type: NodeType.CDATA,
654
+ textContent: '',
655
+ rootId: rootId
656
+ };
657
+ case n.COMMENT_NODE:
658
+ return {
659
+ type: NodeType.Comment,
660
+ textContent: n.textContent || '',
661
+ rootId: rootId
662
+ };
663
+ default:
664
+ return false;
665
+ }
666
+ }
667
+ function lowerIfExists(maybeAttr) {
668
+ if (maybeAttr === undefined) {
669
+ return '';
670
+ }
671
+ else {
672
+ return maybeAttr.toLowerCase();
673
+ }
674
+ }
675
+ function slimDOMExcluded(sn, slimDOMOptions) {
676
+ if (slimDOMOptions.comment && sn.type === NodeType.Comment) {
677
+ return true;
678
+ }
679
+ else if (sn.type === NodeType.Element) {
680
+ if (slimDOMOptions.script &&
681
+ (sn.tagName === 'script' ||
682
+ (sn.tagName === 'link' &&
683
+ sn.attributes.rel === 'preload' &&
684
+ sn.attributes.as === 'script') ||
685
+ (sn.tagName === 'link' &&
686
+ sn.attributes.rel === 'prefetch' &&
687
+ typeof sn.attributes.href === 'string' &&
688
+ sn.attributes.href.endsWith('.js')))) {
689
+ return true;
690
+ }
691
+ else if (slimDOMOptions.headFavicon &&
692
+ ((sn.tagName === 'link' && sn.attributes.rel === 'shortcut icon') ||
693
+ (sn.tagName === 'meta' &&
694
+ (lowerIfExists(sn.attributes.name).match(/^msapplication-tile(image|color)$/) ||
695
+ lowerIfExists(sn.attributes.name) === 'application-name' ||
696
+ lowerIfExists(sn.attributes.rel) === 'icon' ||
697
+ lowerIfExists(sn.attributes.rel) === 'apple-touch-icon' ||
698
+ lowerIfExists(sn.attributes.rel) === 'shortcut icon')))) {
699
+ return true;
700
+ }
701
+ else if (sn.tagName === 'meta') {
702
+ if (slimDOMOptions.headMetaDescKeywords &&
703
+ lowerIfExists(sn.attributes.name).match(/^description|keywords$/)) {
704
+ return true;
705
+ }
706
+ else if (slimDOMOptions.headMetaSocial &&
707
+ (lowerIfExists(sn.attributes.property).match(/^(og|twitter|fb):/) ||
708
+ lowerIfExists(sn.attributes.name).match(/^(og|twitter):/) ||
709
+ lowerIfExists(sn.attributes.name) === 'pinterest')) {
710
+ return true;
711
+ }
712
+ else if (slimDOMOptions.headMetaRobots &&
713
+ (lowerIfExists(sn.attributes.name) === 'robots' ||
714
+ lowerIfExists(sn.attributes.name) === 'googlebot' ||
715
+ lowerIfExists(sn.attributes.name) === 'bingbot')) {
716
+ return true;
717
+ }
718
+ else if (slimDOMOptions.headMetaHttpEquiv &&
719
+ sn.attributes['http-equiv'] !== undefined) {
720
+ return true;
721
+ }
722
+ else if (slimDOMOptions.headMetaAuthorship &&
723
+ (lowerIfExists(sn.attributes.name) === 'author' ||
724
+ lowerIfExists(sn.attributes.name) === 'generator' ||
725
+ lowerIfExists(sn.attributes.name) === 'framework' ||
726
+ lowerIfExists(sn.attributes.name) === 'publisher' ||
727
+ lowerIfExists(sn.attributes.name) === 'progid' ||
728
+ lowerIfExists(sn.attributes.property).match(/^article:/) ||
729
+ lowerIfExists(sn.attributes.property).match(/^product:/))) {
730
+ return true;
731
+ }
732
+ else if (slimDOMOptions.headMetaVerification &&
733
+ (lowerIfExists(sn.attributes.name) === 'google-site-verification' ||
734
+ lowerIfExists(sn.attributes.name) === 'yandex-verification' ||
735
+ lowerIfExists(sn.attributes.name) === 'csrf-token' ||
736
+ lowerIfExists(sn.attributes.name) === 'p:domain_verify' ||
737
+ lowerIfExists(sn.attributes.name) === 'verify-v1' ||
738
+ lowerIfExists(sn.attributes.name) === 'verification' ||
739
+ lowerIfExists(sn.attributes.name) === 'shopify-checkout-api-token')) {
740
+ return true;
741
+ }
742
+ }
743
+ }
744
+ return false;
745
+ }
746
+ function serializeNodeWithId(n, options) {
747
+ var doc = options.doc, map = options.map, 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, _h = options.keepIframeSrcFn, keepIframeSrcFn = _h === void 0 ? function () { return false; } : _h, enableStrictPrivacy = options.enableStrictPrivacy;
748
+ var _j = options.preserveWhiteSpace, preserveWhiteSpace = _j === void 0 ? true : _j;
749
+ var _serializedNode = serializeNode(n, {
750
+ doc: doc,
751
+ blockClass: blockClass,
752
+ blockSelector: blockSelector,
753
+ maskTextClass: maskTextClass,
754
+ maskTextSelector: maskTextSelector,
755
+ inlineStylesheet: inlineStylesheet,
756
+ maskInputOptions: maskInputOptions,
757
+ maskTextFn: maskTextFn,
758
+ maskInputFn: maskInputFn,
759
+ dataURLOptions: dataURLOptions,
760
+ inlineImages: inlineImages,
761
+ recordCanvas: recordCanvas,
762
+ keepIframeSrcFn: keepIframeSrcFn,
763
+ enableStrictPrivacy: enableStrictPrivacy
764
+ });
765
+ if (!_serializedNode) {
766
+ console.warn(n, 'not serialized');
767
+ return null;
768
+ }
769
+ var id;
770
+ if ('__sn' in n) {
771
+ id = n.__sn.id;
772
+ }
773
+ else if (slimDOMExcluded(_serializedNode, slimDOMOptions) ||
774
+ (!preserveWhiteSpace &&
775
+ _serializedNode.type === NodeType.Text &&
776
+ !_serializedNode.isStyle &&
777
+ !_serializedNode.textContent.replace(/^\s+|\s+$/gm, '').length)) {
778
+ id = IGNORED_NODE;
779
+ }
780
+ else {
781
+ id = genId();
782
+ }
783
+ var serializedNode = Object.assign(_serializedNode, { id: id });
784
+ n.__sn = serializedNode;
785
+ if (id === IGNORED_NODE) {
786
+ return null;
787
+ }
788
+ map[id] = n;
789
+ if (onSerialize) {
790
+ onSerialize(n);
791
+ }
792
+ var recordChild = !skipChild;
793
+ if (serializedNode.type === NodeType.Element) {
794
+ recordChild = recordChild && !serializedNode.needBlock;
795
+ if (serializedNode.needBlock && serializedNode.tagName === 'img') {
796
+ var clone = n.cloneNode();
797
+ clone.src = '';
798
+ map[id] = clone;
799
+ }
800
+ delete serializedNode.needBlock;
801
+ if (n.shadowRoot)
802
+ serializedNode.isShadowHost = true;
803
+ }
804
+ if ((serializedNode.type === NodeType.Document ||
805
+ serializedNode.type === NodeType.Element) &&
806
+ recordChild) {
807
+ if (slimDOMOptions.headWhitespace &&
808
+ _serializedNode.type === NodeType.Element &&
809
+ _serializedNode.tagName === 'head') {
810
+ preserveWhiteSpace = false;
811
+ }
812
+ var bypassOptions = {
813
+ doc: doc,
814
+ map: map,
815
+ blockClass: blockClass,
816
+ blockSelector: blockSelector,
817
+ maskTextClass: maskTextClass,
818
+ maskTextSelector: maskTextSelector,
819
+ skipChild: skipChild,
820
+ inlineStylesheet: inlineStylesheet,
821
+ maskInputOptions: maskInputOptions,
822
+ maskTextFn: maskTextFn,
823
+ maskInputFn: maskInputFn,
824
+ slimDOMOptions: slimDOMOptions,
825
+ dataURLOptions: dataURLOptions,
826
+ inlineImages: inlineImages,
827
+ recordCanvas: recordCanvas,
828
+ preserveWhiteSpace: preserveWhiteSpace,
829
+ onSerialize: onSerialize,
830
+ onIframeLoad: onIframeLoad,
831
+ iframeLoadTimeout: iframeLoadTimeout,
832
+ keepIframeSrcFn: keepIframeSrcFn,
833
+ enableStrictPrivacy: enableStrictPrivacy
834
+ };
835
+ for (var _i = 0, _k = Array.from(n.childNodes); _i < _k.length; _i++) {
836
+ var childN = _k[_i];
837
+ var serializedChildNode = serializeNodeWithId(childN, bypassOptions);
838
+ if (serializedChildNode) {
839
+ serializedNode.childNodes.push(serializedChildNode);
840
+ }
841
+ }
842
+ if (isElement(n) && n.shadowRoot) {
843
+ for (var _l = 0, _m = Array.from(n.shadowRoot.childNodes); _l < _m.length; _l++) {
844
+ var childN = _m[_l];
845
+ var serializedChildNode = serializeNodeWithId(childN, bypassOptions);
846
+ if (serializedChildNode) {
847
+ serializedChildNode.isShadow = true;
848
+ serializedNode.childNodes.push(serializedChildNode);
849
+ }
850
+ }
851
+ }
852
+ }
853
+ if (n.parentNode && isShadowRoot(n.parentNode)) {
854
+ serializedNode.isShadow = true;
855
+ }
856
+ if (serializedNode.type === NodeType.Element &&
857
+ serializedNode.tagName === 'iframe') {
858
+ onceIframeLoaded(n, function () {
859
+ var iframeDoc = n.contentDocument;
860
+ if (iframeDoc && onIframeLoad) {
861
+ var serializedIframeNode = serializeNodeWithId(iframeDoc, {
862
+ doc: iframeDoc,
863
+ map: map,
864
+ blockClass: blockClass,
865
+ blockSelector: blockSelector,
866
+ maskTextClass: maskTextClass,
867
+ maskTextSelector: maskTextSelector,
868
+ skipChild: false,
869
+ inlineStylesheet: inlineStylesheet,
870
+ maskInputOptions: maskInputOptions,
871
+ maskTextFn: maskTextFn,
872
+ maskInputFn: maskInputFn,
873
+ slimDOMOptions: slimDOMOptions,
874
+ dataURLOptions: dataURLOptions,
875
+ inlineImages: inlineImages,
876
+ recordCanvas: recordCanvas,
877
+ preserveWhiteSpace: preserveWhiteSpace,
878
+ onSerialize: onSerialize,
879
+ onIframeLoad: onIframeLoad,
880
+ iframeLoadTimeout: iframeLoadTimeout,
881
+ keepIframeSrcFn: keepIframeSrcFn,
882
+ enableStrictPrivacy: enableStrictPrivacy
883
+ });
884
+ if (serializedIframeNode) {
885
+ onIframeLoad(n, serializedIframeNode);
886
+ }
887
+ }
888
+ }, iframeLoadTimeout);
889
+ }
890
+ return serializedNode;
891
+ }
892
+ function snapshot(n, options) {
893
+ var _a = options || {}, _b = _a.blockClass, blockClass = _b === void 0 ? 'highlight-block' : _b, _c = _a.blockSelector, blockSelector = _c === void 0 ? null : _c, _d = _a.maskTextClass, maskTextClass = _d === void 0 ? 'highlight-mask' : _d, _e = _a.maskTextSelector, maskTextSelector = _e === void 0 ? null : _e, _f = _a.inlineStylesheet, inlineStylesheet = _f === void 0 ? true : _f, _g = _a.inlineImages, inlineImages = _g === void 0 ? false : _g, _h = _a.recordCanvas, recordCanvas = _h === void 0 ? false : _h, _j = _a.maskAllInputs, maskAllInputs = _j === void 0 ? false : _j, maskTextFn = _a.maskTextFn, maskInputFn = _a.maskInputFn, _k = _a.slimDOM, slimDOM = _k === void 0 ? false : _k, dataURLOptions = _a.dataURLOptions, preserveWhiteSpace = _a.preserveWhiteSpace, onSerialize = _a.onSerialize, onIframeLoad = _a.onIframeLoad, iframeLoadTimeout = _a.iframeLoadTimeout, _l = _a.keepIframeSrcFn, keepIframeSrcFn = _l === void 0 ? function () { return false; } : _l, _m = _a.enableStrictPrivacy, enableStrictPrivacy = _m === void 0 ? false : _m;
894
+ var idNodeMap = {};
895
+ var maskInputOptions = maskAllInputs === true
896
+ ? {
897
+ color: true,
898
+ date: true,
899
+ 'datetime-local': true,
900
+ email: true,
901
+ month: true,
902
+ number: true,
903
+ range: true,
904
+ search: true,
905
+ tel: true,
906
+ text: true,
907
+ time: true,
908
+ url: true,
909
+ week: true,
910
+ textarea: true,
911
+ select: true,
912
+ password: true
913
+ }
914
+ : maskAllInputs === false
915
+ ? {
916
+ password: true
917
+ }
918
+ : maskAllInputs;
919
+ var slimDOMOptions = slimDOM === true || slimDOM === 'all'
920
+ ?
921
+ {
922
+ script: true,
923
+ comment: true,
924
+ headFavicon: true,
925
+ headWhitespace: true,
926
+ headMetaDescKeywords: slimDOM === 'all',
927
+ headMetaSocial: true,
928
+ headMetaRobots: true,
929
+ headMetaHttpEquiv: true,
930
+ headMetaAuthorship: true,
931
+ headMetaVerification: true
932
+ }
933
+ : slimDOM === false
934
+ ? {}
935
+ : slimDOM;
936
+ return [
937
+ serializeNodeWithId(n, {
938
+ doc: n,
939
+ map: idNodeMap,
940
+ blockClass: blockClass,
941
+ blockSelector: blockSelector,
942
+ maskTextClass: maskTextClass,
943
+ maskTextSelector: maskTextSelector,
944
+ skipChild: false,
945
+ inlineStylesheet: inlineStylesheet,
946
+ maskInputOptions: maskInputOptions,
947
+ maskTextFn: maskTextFn,
948
+ maskInputFn: maskInputFn,
949
+ slimDOMOptions: slimDOMOptions,
950
+ dataURLOptions: dataURLOptions,
951
+ inlineImages: inlineImages,
952
+ recordCanvas: recordCanvas,
953
+ preserveWhiteSpace: preserveWhiteSpace,
954
+ onSerialize: onSerialize,
955
+ onIframeLoad: onIframeLoad,
956
+ iframeLoadTimeout: iframeLoadTimeout,
957
+ keepIframeSrcFn: keepIframeSrcFn,
958
+ enableStrictPrivacy: enableStrictPrivacy
959
+ }),
960
+ idNodeMap,
961
+ ];
962
+ }
963
+
964
+ var EventType;
965
+ (function (EventType) {
966
+ EventType[EventType["DomContentLoaded"] = 0] = "DomContentLoaded";
967
+ EventType[EventType["Load"] = 1] = "Load";
968
+ EventType[EventType["FullSnapshot"] = 2] = "FullSnapshot";
969
+ EventType[EventType["IncrementalSnapshot"] = 3] = "IncrementalSnapshot";
970
+ EventType[EventType["Meta"] = 4] = "Meta";
971
+ EventType[EventType["Custom"] = 5] = "Custom";
972
+ EventType[EventType["Plugin"] = 6] = "Plugin";
973
+ })(EventType || (EventType = {}));
974
+ var IncrementalSource;
975
+ (function (IncrementalSource) {
976
+ IncrementalSource[IncrementalSource["Mutation"] = 0] = "Mutation";
977
+ IncrementalSource[IncrementalSource["MouseMove"] = 1] = "MouseMove";
978
+ IncrementalSource[IncrementalSource["MouseInteraction"] = 2] = "MouseInteraction";
979
+ IncrementalSource[IncrementalSource["Scroll"] = 3] = "Scroll";
980
+ IncrementalSource[IncrementalSource["ViewportResize"] = 4] = "ViewportResize";
981
+ IncrementalSource[IncrementalSource["Input"] = 5] = "Input";
982
+ IncrementalSource[IncrementalSource["TouchMove"] = 6] = "TouchMove";
983
+ IncrementalSource[IncrementalSource["MediaInteraction"] = 7] = "MediaInteraction";
984
+ IncrementalSource[IncrementalSource["StyleSheetRule"] = 8] = "StyleSheetRule";
985
+ IncrementalSource[IncrementalSource["CanvasMutation"] = 9] = "CanvasMutation";
986
+ IncrementalSource[IncrementalSource["Font"] = 10] = "Font";
987
+ IncrementalSource[IncrementalSource["Log"] = 11] = "Log";
988
+ IncrementalSource[IncrementalSource["Drag"] = 12] = "Drag";
989
+ IncrementalSource[IncrementalSource["StyleDeclaration"] = 13] = "StyleDeclaration";
990
+ })(IncrementalSource || (IncrementalSource = {}));
991
+ var MouseInteractions;
992
+ (function (MouseInteractions) {
993
+ MouseInteractions[MouseInteractions["MouseUp"] = 0] = "MouseUp";
994
+ MouseInteractions[MouseInteractions["MouseDown"] = 1] = "MouseDown";
995
+ MouseInteractions[MouseInteractions["Click"] = 2] = "Click";
996
+ MouseInteractions[MouseInteractions["ContextMenu"] = 3] = "ContextMenu";
997
+ MouseInteractions[MouseInteractions["DblClick"] = 4] = "DblClick";
998
+ MouseInteractions[MouseInteractions["Focus"] = 5] = "Focus";
999
+ MouseInteractions[MouseInteractions["Blur"] = 6] = "Blur";
1000
+ MouseInteractions[MouseInteractions["TouchStart"] = 7] = "TouchStart";
1001
+ MouseInteractions[MouseInteractions["TouchMove_Departed"] = 8] = "TouchMove_Departed";
1002
+ MouseInteractions[MouseInteractions["TouchEnd"] = 9] = "TouchEnd";
1003
+ MouseInteractions[MouseInteractions["TouchCancel"] = 10] = "TouchCancel";
1004
+ })(MouseInteractions || (MouseInteractions = {}));
1005
+ var CanvasContext;
1006
+ (function (CanvasContext) {
1007
+ CanvasContext[CanvasContext["2D"] = 0] = "2D";
1008
+ CanvasContext[CanvasContext["WebGL"] = 1] = "WebGL";
1009
+ CanvasContext[CanvasContext["WebGL2"] = 2] = "WebGL2";
1010
+ })(CanvasContext || (CanvasContext = {}));
1011
+ var MediaInteractions;
1012
+ (function (MediaInteractions) {
1013
+ MediaInteractions[MediaInteractions["Play"] = 0] = "Play";
1014
+ MediaInteractions[MediaInteractions["Pause"] = 1] = "Pause";
1015
+ MediaInteractions[MediaInteractions["Seeked"] = 2] = "Seeked";
1016
+ MediaInteractions[MediaInteractions["VolumeChange"] = 3] = "VolumeChange";
1017
+ })(MediaInteractions || (MediaInteractions = {}));
1018
+ var ReplayerEvents;
1019
+ (function (ReplayerEvents) {
1020
+ ReplayerEvents["Start"] = "start";
1021
+ ReplayerEvents["Pause"] = "pause";
1022
+ ReplayerEvents["Resume"] = "resume";
1023
+ ReplayerEvents["Resize"] = "resize";
1024
+ ReplayerEvents["Finish"] = "finish";
1025
+ ReplayerEvents["FullsnapshotRebuilded"] = "fullsnapshot-rebuilded";
1026
+ ReplayerEvents["LoadStylesheetStart"] = "load-stylesheet-start";
1027
+ ReplayerEvents["LoadStylesheetEnd"] = "load-stylesheet-end";
1028
+ ReplayerEvents["SkipStart"] = "skip-start";
1029
+ ReplayerEvents["SkipEnd"] = "skip-end";
1030
+ ReplayerEvents["MouseInteraction"] = "mouse-interaction";
1031
+ ReplayerEvents["EventCast"] = "event-cast";
1032
+ ReplayerEvents["CustomEvent"] = "custom-event";
1033
+ ReplayerEvents["Flush"] = "flush";
1034
+ ReplayerEvents["StateChange"] = "state-change";
1035
+ ReplayerEvents["PlayBack"] = "play-back";
1036
+ })(ReplayerEvents || (ReplayerEvents = {}));
1037
+
1038
+ function on(type, fn, target) {
1039
+ if (target === void 0) { target = document; }
1040
+ var options = { capture: true, passive: true };
1041
+ target.addEventListener(type, fn, options);
1042
+ return function () { return target.removeEventListener(type, fn, options); };
1043
+ }
1044
+ function createMirror() {
1045
+ return {
1046
+ map: {},
1047
+ getId: function (n) {
1048
+ if (!n || !n.__sn) {
1049
+ return -1;
1050
+ }
1051
+ return n.__sn.id;
1052
+ },
1053
+ getNode: function (id) {
1054
+ return this.map[id] || null;
1055
+ },
1056
+ removeNodeFromMap: function (n) {
1057
+ var _this = this;
1058
+ var id = n.__sn && n.__sn.id;
1059
+ delete this.map[id];
1060
+ if (n.childNodes) {
1061
+ n.childNodes.forEach(function (child) {
1062
+ return _this.removeNodeFromMap(child);
1063
+ });
1064
+ }
1065
+ },
1066
+ has: function (id) {
1067
+ return this.map.hasOwnProperty(id);
1068
+ },
1069
+ reset: function () {
1070
+ this.map = {};
1071
+ },
1072
+ };
1073
+ }
1074
+ var DEPARTED_MIRROR_ACCESS_WARNING = 'Please stop import mirror directly. Instead of that,' +
1075
+ '\r\n' +
1076
+ 'now you can use replayer.getMirror() to access the mirror instance of a replayer,' +
1077
+ '\r\n' +
1078
+ 'or you can use record.mirror to access the mirror instance during recording.';
1079
+ var _mirror = {
1080
+ map: {},
1081
+ getId: function () {
1082
+ console.error(DEPARTED_MIRROR_ACCESS_WARNING);
1083
+ return -1;
1084
+ },
1085
+ getNode: function () {
1086
+ console.error(DEPARTED_MIRROR_ACCESS_WARNING);
1087
+ return null;
1088
+ },
1089
+ removeNodeFromMap: function () {
1090
+ console.error(DEPARTED_MIRROR_ACCESS_WARNING);
1091
+ },
1092
+ has: function () {
1093
+ console.error(DEPARTED_MIRROR_ACCESS_WARNING);
1094
+ return false;
1095
+ },
1096
+ reset: function () {
1097
+ console.error(DEPARTED_MIRROR_ACCESS_WARNING);
1098
+ },
1099
+ };
1100
+ if (typeof window !== 'undefined' && window.Proxy && window.Reflect) {
1101
+ _mirror = new Proxy(_mirror, {
1102
+ get: function (target, prop, receiver) {
1103
+ if (prop === 'map') {
1104
+ console.error(DEPARTED_MIRROR_ACCESS_WARNING);
1105
+ }
1106
+ return Reflect.get(target, prop, receiver);
1107
+ },
1108
+ });
1109
+ }
1110
+ function throttle(func, wait, options) {
1111
+ if (options === void 0) { options = {}; }
1112
+ var timeout = null;
1113
+ var previous = 0;
1114
+ return function (arg) {
1115
+ var now = Date.now();
1116
+ if (!previous && options.leading === false) {
1117
+ previous = now;
1118
+ }
1119
+ var remaining = wait - (now - previous);
1120
+ var context = this;
1121
+ var args = arguments;
1122
+ if (remaining <= 0 || remaining > wait) {
1123
+ if (timeout) {
1124
+ clearTimeout(timeout);
1125
+ timeout = null;
1126
+ }
1127
+ previous = now;
1128
+ func.apply(context, args);
1129
+ }
1130
+ else if (!timeout && options.trailing !== false) {
1131
+ timeout = setTimeout(function () {
1132
+ previous = options.leading === false ? 0 : Date.now();
1133
+ timeout = null;
1134
+ func.apply(context, args);
1135
+ }, remaining);
1136
+ }
1137
+ };
1138
+ }
1139
+ function hookSetter(target, key, d, isRevoked, win) {
1140
+ if (win === void 0) { win = window; }
1141
+ var original = win.Object.getOwnPropertyDescriptor(target, key);
1142
+ win.Object.defineProperty(target, key, isRevoked
1143
+ ? d
1144
+ : {
1145
+ set: function (value) {
1146
+ var _this = this;
1147
+ setTimeout(function () {
1148
+ d.set.call(_this, value);
1149
+ }, 0);
1150
+ if (original && original.set) {
1151
+ original.set.call(this, value);
1152
+ }
1153
+ },
1154
+ });
1155
+ return function () { return hookSetter(target, key, original || {}, true); };
1156
+ }
1157
+ function patch(source, name, replacement) {
1158
+ try {
1159
+ if (!(name in source)) {
1160
+ return function () { };
1161
+ }
1162
+ var original_1 = source[name];
1163
+ var wrapped = replacement(original_1);
1164
+ if (typeof wrapped === 'function') {
1165
+ wrapped.prototype = wrapped.prototype || {};
1166
+ Object.defineProperties(wrapped, {
1167
+ __rrweb_original__: {
1168
+ enumerable: false,
1169
+ value: original_1,
1170
+ },
1171
+ });
1172
+ }
1173
+ source[name] = wrapped;
1174
+ return function () {
1175
+ source[name] = original_1;
1176
+ };
1177
+ }
1178
+ catch (_a) {
1179
+ return function () { };
1180
+ }
1181
+ }
1182
+ function getWindowHeight() {
1183
+ return (window.innerHeight ||
1184
+ (document.documentElement && document.documentElement.clientHeight) ||
1185
+ (document.body && document.body.clientHeight));
1186
+ }
1187
+ function getWindowWidth() {
1188
+ return (window.innerWidth ||
1189
+ (document.documentElement && document.documentElement.clientWidth) ||
1190
+ (document.body && document.body.clientWidth));
1191
+ }
1192
+ var isCanvasNode = function (node) {
1193
+ try {
1194
+ if (node instanceof HTMLElement) {
1195
+ return node.tagName === 'CANVAS';
1196
+ }
1197
+ }
1198
+ catch (_a) {
1199
+ return false;
1200
+ }
1201
+ return false;
1202
+ };
1203
+ function isBlocked(node, blockClass) {
1204
+ if (!node) {
1205
+ return false;
1206
+ }
1207
+ if (node.nodeType === node.ELEMENT_NODE) {
1208
+ var needBlock_1 = false;
1209
+ if (typeof blockClass === 'string') {
1210
+ if (node.closest !== undefined) {
1211
+ return node.closest('.' + blockClass) !== null;
1212
+ }
1213
+ else {
1214
+ needBlock_1 = node.classList.contains(blockClass);
1215
+ }
1216
+ }
1217
+ else {
1218
+ node.classList.forEach(function (className) {
1219
+ if (blockClass.test(className)) {
1220
+ needBlock_1 = true;
1221
+ }
1222
+ });
1223
+ }
1224
+ return needBlock_1 || isBlocked(node.parentNode, blockClass);
1225
+ }
1226
+ if (node.nodeType === node.TEXT_NODE) {
1227
+ return isBlocked(node.parentNode, blockClass);
1228
+ }
1229
+ return isBlocked(node.parentNode, blockClass);
1230
+ }
1231
+ function isIgnored(n) {
1232
+ if ('__sn' in n) {
1233
+ return n.__sn.id === IGNORED_NODE;
1234
+ }
1235
+ return false;
1236
+ }
1237
+ function isAncestorRemoved(target, mirror) {
1238
+ if (isShadowRoot(target)) {
1239
+ return false;
1240
+ }
1241
+ var id = mirror.getId(target);
1242
+ if (!mirror.has(id)) {
1243
+ return true;
1244
+ }
1245
+ if (target.parentNode &&
1246
+ target.parentNode.nodeType === target.DOCUMENT_NODE) {
1247
+ return false;
1248
+ }
1249
+ if (!target.parentNode) {
1250
+ return true;
1251
+ }
1252
+ return isAncestorRemoved(target.parentNode, mirror);
1253
+ }
1254
+ function isTouchEvent(event) {
1255
+ return Boolean(event.changedTouches);
1256
+ }
1257
+ function polyfill(win) {
1258
+ if (win === void 0) { win = window; }
1259
+ if ('NodeList' in win && !win.NodeList.prototype.forEach) {
1260
+ win.NodeList.prototype.forEach = Array.prototype
1261
+ .forEach;
1262
+ }
1263
+ if ('DOMTokenList' in win && !win.DOMTokenList.prototype.forEach) {
1264
+ win.DOMTokenList.prototype.forEach = Array.prototype
1265
+ .forEach;
1266
+ }
1267
+ if (!Node.prototype.contains) {
1268
+ Node.prototype.contains = function contains(node) {
1269
+ if (!(0 in arguments)) {
1270
+ throw new TypeError('1 argument is required');
1271
+ }
1272
+ do {
1273
+ if (this === node) {
1274
+ return true;
1275
+ }
1276
+ } while ((node = node && node.parentNode));
1277
+ return false;
1278
+ };
1279
+ }
1280
+ }
1281
+ function isIframeINode(node) {
1282
+ if ('__sn' in node) {
1283
+ return (node.__sn.type === NodeType.Element && node.__sn.tagName === 'iframe');
1284
+ }
1285
+ return false;
1286
+ }
1287
+ function hasShadowRoot(n) {
1288
+ return Boolean(n === null || n === void 0 ? void 0 : n.shadowRoot);
1289
+ }
1290
+
1291
+ function isNodeInLinkedList(n) {
1292
+ return '__ln' in n;
1293
+ }
1294
+ var DoubleLinkedList = (function () {
1295
+ function DoubleLinkedList() {
1296
+ this.length = 0;
1297
+ this.head = null;
1298
+ }
1299
+ DoubleLinkedList.prototype.get = function (position) {
1300
+ if (position >= this.length) {
1301
+ throw new Error('Position outside of list range');
1302
+ }
1303
+ var current = this.head;
1304
+ for (var index = 0; index < position; index++) {
1305
+ current = (current === null || current === void 0 ? void 0 : current.next) || null;
1306
+ }
1307
+ return current;
1308
+ };
1309
+ DoubleLinkedList.prototype.addNode = function (n) {
1310
+ var node = {
1311
+ value: n,
1312
+ previous: null,
1313
+ next: null,
1314
+ };
1315
+ n.__ln = node;
1316
+ if (n.previousSibling && isNodeInLinkedList(n.previousSibling)) {
1317
+ var current = n.previousSibling.__ln.next;
1318
+ node.next = current;
1319
+ node.previous = n.previousSibling.__ln;
1320
+ n.previousSibling.__ln.next = node;
1321
+ if (current) {
1322
+ current.previous = node;
1323
+ }
1324
+ }
1325
+ else if (n.nextSibling &&
1326
+ isNodeInLinkedList(n.nextSibling) &&
1327
+ n.nextSibling.__ln.previous) {
1328
+ var current = n.nextSibling.__ln.previous;
1329
+ node.previous = current;
1330
+ node.next = n.nextSibling.__ln;
1331
+ n.nextSibling.__ln.previous = node;
1332
+ if (current) {
1333
+ current.next = node;
1334
+ }
1335
+ }
1336
+ else {
1337
+ if (this.head) {
1338
+ this.head.previous = node;
1339
+ }
1340
+ node.next = this.head;
1341
+ this.head = node;
1342
+ }
1343
+ this.length++;
1344
+ };
1345
+ DoubleLinkedList.prototype.removeNode = function (n) {
1346
+ var current = n.__ln;
1347
+ if (!this.head) {
1348
+ return;
1349
+ }
1350
+ if (!current.previous) {
1351
+ this.head = current.next;
1352
+ if (this.head) {
1353
+ this.head.previous = null;
1354
+ }
1355
+ }
1356
+ else {
1357
+ current.previous.next = current.next;
1358
+ if (current.next) {
1359
+ current.next.previous = current.previous;
1360
+ }
1361
+ }
1362
+ if (n.__ln) {
1363
+ delete n.__ln;
1364
+ }
1365
+ this.length--;
1366
+ };
1367
+ return DoubleLinkedList;
1368
+ }());
1369
+ var moveKey = function (id, parentId) { return "".concat(id, "@").concat(parentId); };
1370
+ function isINode(n) {
1371
+ return '__sn' in n;
1372
+ }
1373
+ var MutationBuffer = (function () {
1374
+ function MutationBuffer() {
1375
+ var _this = this;
1376
+ this.frozen = false;
1377
+ this.locked = false;
1378
+ this.texts = [];
1379
+ this.attributes = [];
1380
+ this.removes = [];
1381
+ this.mapRemoves = [];
1382
+ this.movedMap = {};
1383
+ this.addedSet = new Set();
1384
+ this.movedSet = new Set();
1385
+ this.droppedSet = new Set();
1386
+ this.processMutations = function (mutations) {
1387
+ mutations.forEach(_this.processMutation);
1388
+ _this.emit();
1389
+ };
1390
+ this.emit = function () {
1391
+ var e_1, _a, e_2, _b;
1392
+ if (_this.frozen || _this.locked) {
1393
+ return;
1394
+ }
1395
+ var adds = [];
1396
+ var addList = new DoubleLinkedList();
1397
+ var getNextId = function (n) {
1398
+ var ns = n;
1399
+ var nextId = IGNORED_NODE;
1400
+ while (nextId === IGNORED_NODE) {
1401
+ ns = ns && ns.nextSibling;
1402
+ nextId = ns && _this.mirror.getId(ns);
1403
+ }
1404
+ return nextId;
1405
+ };
1406
+ var pushAdd = function (n) {
1407
+ var _a, _b, _c, _d, _e;
1408
+ var shadowHost = n.getRootNode
1409
+ ? (_a = n.getRootNode()) === null || _a === void 0 ? void 0 : _a.host
1410
+ : null;
1411
+ var rootShadowHost = shadowHost;
1412
+ while ((_c = (_b = rootShadowHost === null || rootShadowHost === void 0 ? void 0 : rootShadowHost.getRootNode) === null || _b === void 0 ? void 0 : _b.call(rootShadowHost)) === null || _c === void 0 ? void 0 : _c.host)
1413
+ rootShadowHost =
1414
+ ((_e = (_d = rootShadowHost === null || rootShadowHost === void 0 ? void 0 : rootShadowHost.getRootNode) === null || _d === void 0 ? void 0 : _d.call(rootShadowHost)) === null || _e === void 0 ? void 0 : _e.host) ||
1415
+ null;
1416
+ var notInDoc = !_this.doc.contains(n) &&
1417
+ (rootShadowHost === null || !_this.doc.contains(rootShadowHost));
1418
+ if (!n.parentNode || notInDoc) {
1419
+ return;
1420
+ }
1421
+ var parentId = isShadowRoot(n.parentNode)
1422
+ ? _this.mirror.getId(shadowHost)
1423
+ : _this.mirror.getId(n.parentNode);
1424
+ var nextId = getNextId(n);
1425
+ if (parentId === -1 || nextId === -1) {
1426
+ return addList.addNode(n);
1427
+ }
1428
+ var sn = serializeNodeWithId(n, {
1429
+ doc: _this.doc,
1430
+ map: _this.mirror.map,
1431
+ blockClass: _this.blockClass,
1432
+ blockSelector: _this.blockSelector,
1433
+ maskTextClass: _this.maskTextClass,
1434
+ maskTextSelector: _this.maskTextSelector,
1435
+ skipChild: true,
1436
+ inlineStylesheet: _this.inlineStylesheet,
1437
+ maskInputOptions: _this.maskInputOptions,
1438
+ maskTextFn: _this.maskTextFn,
1439
+ maskInputFn: _this.maskInputFn,
1440
+ slimDOMOptions: _this.slimDOMOptions,
1441
+ recordCanvas: _this.recordCanvas,
1442
+ inlineImages: _this.inlineImages,
1443
+ enableStrictPrivacy: _this.enableStrictPrivacy,
1444
+ onSerialize: function (currentN) {
1445
+ if (isIframeINode(currentN)) {
1446
+ _this.iframeManager.addIframe(currentN);
1447
+ }
1448
+ if (hasShadowRoot(n)) {
1449
+ _this.shadowDomManager.addShadowRoot(n.shadowRoot, document);
1450
+ }
1451
+ },
1452
+ onIframeLoad: function (iframe, childSn) {
1453
+ _this.iframeManager.attachIframe(iframe, childSn);
1454
+ _this.shadowDomManager.observeAttachShadow(iframe);
1455
+ },
1456
+ });
1457
+ if (sn) {
1458
+ adds.push({
1459
+ parentId: parentId,
1460
+ nextId: nextId,
1461
+ node: sn,
1462
+ });
1463
+ }
1464
+ };
1465
+ while (_this.mapRemoves.length) {
1466
+ _this.mirror.removeNodeFromMap(_this.mapRemoves.shift());
1467
+ }
1468
+ try {
1469
+ for (var _c = __values(_this.movedSet), _d = _c.next(); !_d.done; _d = _c.next()) {
1470
+ var n = _d.value;
1471
+ if (isParentRemoved(_this.removes, n, _this.mirror) &&
1472
+ !_this.movedSet.has(n.parentNode)) {
1473
+ continue;
1474
+ }
1475
+ pushAdd(n);
1476
+ }
1477
+ }
1478
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
1479
+ finally {
1480
+ try {
1481
+ if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
1482
+ }
1483
+ finally { if (e_1) throw e_1.error; }
1484
+ }
1485
+ try {
1486
+ for (var _e = __values(_this.addedSet), _f = _e.next(); !_f.done; _f = _e.next()) {
1487
+ var n = _f.value;
1488
+ if (!isAncestorInSet(_this.droppedSet, n) &&
1489
+ !isParentRemoved(_this.removes, n, _this.mirror)) {
1490
+ pushAdd(n);
1491
+ }
1492
+ else if (isAncestorInSet(_this.movedSet, n)) {
1493
+ pushAdd(n);
1494
+ }
1495
+ else {
1496
+ _this.droppedSet.add(n);
1497
+ }
1498
+ }
1499
+ }
1500
+ catch (e_2_1) { e_2 = { error: e_2_1 }; }
1501
+ finally {
1502
+ try {
1503
+ if (_f && !_f.done && (_b = _e.return)) _b.call(_e);
1504
+ }
1505
+ finally { if (e_2) throw e_2.error; }
1506
+ }
1507
+ var candidate = null;
1508
+ while (addList.length) {
1509
+ var node = null;
1510
+ if (candidate) {
1511
+ var parentId = _this.mirror.getId(candidate.value.parentNode);
1512
+ var nextId = getNextId(candidate.value);
1513
+ if (parentId !== -1 && nextId !== -1) {
1514
+ node = candidate;
1515
+ }
1516
+ }
1517
+ if (!node) {
1518
+ for (var index = addList.length - 1; index >= 0; index--) {
1519
+ var _node = addList.get(index);
1520
+ if (_node) {
1521
+ var parentId = _this.mirror.getId(_node.value.parentNode);
1522
+ var nextId = getNextId(_node.value);
1523
+ if (parentId !== -1 && nextId !== -1) {
1524
+ node = _node;
1525
+ break;
1526
+ }
1527
+ }
1528
+ }
1529
+ }
1530
+ if (!node) {
1531
+ while (addList.head) {
1532
+ addList.removeNode(addList.head.value);
1533
+ }
1534
+ break;
1535
+ }
1536
+ candidate = node.previous;
1537
+ addList.removeNode(node.value);
1538
+ pushAdd(node.value);
1539
+ }
1540
+ var payload = {
1541
+ texts: _this.texts
1542
+ .map(function (text) {
1543
+ var value = text.value;
1544
+ if (_this.enableStrictPrivacy && value) {
1545
+ value = obfuscateText(value);
1546
+ }
1547
+ return {
1548
+ id: _this.mirror.getId(text.node),
1549
+ value: value,
1550
+ };
1551
+ })
1552
+ .filter(function (text) { return _this.mirror.has(text.id); }),
1553
+ attributes: _this.attributes
1554
+ .map(function (attribute) { return ({
1555
+ id: _this.mirror.getId(attribute.node),
1556
+ attributes: attribute.attributes,
1557
+ }); })
1558
+ .filter(function (attribute) { return _this.mirror.has(attribute.id); }),
1559
+ removes: _this.removes,
1560
+ adds: adds,
1561
+ };
1562
+ if (!payload.texts.length &&
1563
+ !payload.attributes.length &&
1564
+ !payload.removes.length &&
1565
+ !payload.adds.length) {
1566
+ return;
1567
+ }
1568
+ _this.texts = [];
1569
+ _this.attributes = [];
1570
+ _this.removes = [];
1571
+ _this.addedSet = new Set();
1572
+ _this.movedSet = new Set();
1573
+ _this.droppedSet = new Set();
1574
+ _this.movedMap = {};
1575
+ _this.mutationCb(payload);
1576
+ };
1577
+ this.processMutation = function (m) {
1578
+ var e_3, _a, e_4, _b;
1579
+ if (isIgnored(m.target)) {
1580
+ return;
1581
+ }
1582
+ switch (m.type) {
1583
+ case 'characterData': {
1584
+ var value = m.target.textContent;
1585
+ if (!isBlocked(m.target, _this.blockClass) && value !== m.oldValue) {
1586
+ _this.texts.push({
1587
+ value: needMaskingText(m.target, _this.maskTextClass, _this.maskTextSelector) && value
1588
+ ? _this.maskTextFn
1589
+ ? _this.maskTextFn(value)
1590
+ : value.replace(/[\S]/g, '*')
1591
+ : value,
1592
+ node: m.target,
1593
+ });
1594
+ }
1595
+ break;
1596
+ }
1597
+ case 'attributes': {
1598
+ var target = m.target;
1599
+ var value = m.target.getAttribute(m.attributeName);
1600
+ if (m.attributeName === 'value') {
1601
+ value = maskInputValue({
1602
+ maskInputOptions: _this.maskInputOptions,
1603
+ tagName: m.target.tagName,
1604
+ type: m.target.getAttribute('type'),
1605
+ value: value,
1606
+ maskInputFn: _this.maskInputFn,
1607
+ });
1608
+ }
1609
+ if (isBlocked(m.target, _this.blockClass) || value === m.oldValue) {
1610
+ return;
1611
+ }
1612
+ var item = _this.attributes.find(function (a) { return a.node === m.target; });
1613
+ if (!item) {
1614
+ item = {
1615
+ node: m.target,
1616
+ attributes: {},
1617
+ };
1618
+ _this.attributes.push(item);
1619
+ }
1620
+ if (m.attributeName === 'style') {
1621
+ var old = _this.doc.createElement('span');
1622
+ if (m.oldValue) {
1623
+ old.setAttribute('style', m.oldValue);
1624
+ }
1625
+ if (item.attributes.style === undefined ||
1626
+ item.attributes.style === null) {
1627
+ item.attributes.style = {};
1628
+ }
1629
+ var styleObj = item.attributes.style;
1630
+ try {
1631
+ for (var _c = __values(Array.from(target.style)), _d = _c.next(); !_d.done; _d = _c.next()) {
1632
+ var pname = _d.value;
1633
+ var newValue = target.style.getPropertyValue(pname);
1634
+ var newPriority = target.style.getPropertyPriority(pname);
1635
+ if (newValue !== old.style.getPropertyValue(pname) ||
1636
+ newPriority !== old.style.getPropertyPriority(pname)) {
1637
+ if (newPriority === '') {
1638
+ styleObj[pname] = newValue;
1639
+ }
1640
+ else {
1641
+ styleObj[pname] = [newValue, newPriority];
1642
+ }
1643
+ }
1644
+ }
1645
+ }
1646
+ catch (e_3_1) { e_3 = { error: e_3_1 }; }
1647
+ finally {
1648
+ try {
1649
+ if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
1650
+ }
1651
+ finally { if (e_3) throw e_3.error; }
1652
+ }
1653
+ try {
1654
+ for (var _e = __values(Array.from(old.style)), _f = _e.next(); !_f.done; _f = _e.next()) {
1655
+ var pname = _f.value;
1656
+ if (target.style.getPropertyValue(pname) === '') {
1657
+ styleObj[pname] = false;
1658
+ }
1659
+ }
1660
+ }
1661
+ catch (e_4_1) { e_4 = { error: e_4_1 }; }
1662
+ finally {
1663
+ try {
1664
+ if (_f && !_f.done && (_b = _e.return)) _b.call(_e);
1665
+ }
1666
+ finally { if (e_4) throw e_4.error; }
1667
+ }
1668
+ }
1669
+ else {
1670
+ var tagName = m.target.tagName;
1671
+ if (tagName === 'INPUT') {
1672
+ var node = m.target;
1673
+ if (node.type === 'password') {
1674
+ item.attributes['value'] = '*'.repeat(node.value.length);
1675
+ break;
1676
+ }
1677
+ }
1678
+ item.attributes[m.attributeName] = transformAttribute(_this.doc, m.target.tagName, m.attributeName, value);
1679
+ }
1680
+ break;
1681
+ }
1682
+ case 'childList': {
1683
+ m.addedNodes.forEach(function (n) { return _this.genAdds(n, m.target); });
1684
+ m.removedNodes.forEach(function (n) {
1685
+ var nodeId = _this.mirror.getId(n);
1686
+ var parentId = isShadowRoot(m.target)
1687
+ ? _this.mirror.getId(m.target.host)
1688
+ : _this.mirror.getId(m.target);
1689
+ if (isBlocked(m.target, _this.blockClass) || isIgnored(n)) {
1690
+ return;
1691
+ }
1692
+ if (_this.addedSet.has(n)) {
1693
+ deepDelete(_this.addedSet, n);
1694
+ _this.droppedSet.add(n);
1695
+ }
1696
+ else if (_this.addedSet.has(m.target) && nodeId === -1) ;
1697
+ else if (isAncestorRemoved(m.target, _this.mirror)) ;
1698
+ else if (_this.movedSet.has(n) &&
1699
+ _this.movedMap[moveKey(nodeId, parentId)]) {
1700
+ deepDelete(_this.movedSet, n);
1701
+ }
1702
+ else {
1703
+ _this.removes.push({
1704
+ parentId: parentId,
1705
+ id: nodeId,
1706
+ isShadow: isShadowRoot(m.target) ? true : undefined,
1707
+ });
1708
+ }
1709
+ _this.mapRemoves.push(n);
1710
+ });
1711
+ break;
1712
+ }
1713
+ }
1714
+ };
1715
+ this.genAdds = function (n, target) {
1716
+ if (target && isBlocked(target, _this.blockClass)) {
1717
+ return;
1718
+ }
1719
+ if (isINode(n)) {
1720
+ if (isIgnored(n)) {
1721
+ return;
1722
+ }
1723
+ _this.movedSet.add(n);
1724
+ var targetId = null;
1725
+ if (target && isINode(target)) {
1726
+ targetId = target.__sn.id;
1727
+ }
1728
+ if (targetId) {
1729
+ _this.movedMap[moveKey(n.__sn.id, targetId)] = true;
1730
+ }
1731
+ }
1732
+ else {
1733
+ _this.addedSet.add(n);
1734
+ _this.droppedSet.delete(n);
1735
+ }
1736
+ if (!isBlocked(n, _this.blockClass))
1737
+ n.childNodes.forEach(function (childN) { return _this.genAdds(childN); });
1738
+ };
1739
+ }
1740
+ MutationBuffer.prototype.init = function (options) {
1741
+ var _this = this;
1742
+ [
1743
+ 'mutationCb',
1744
+ 'blockClass',
1745
+ 'blockSelector',
1746
+ 'maskTextClass',
1747
+ 'maskTextSelector',
1748
+ 'inlineStylesheet',
1749
+ 'maskInputOptions',
1750
+ 'maskTextFn',
1751
+ 'maskInputFn',
1752
+ 'recordCanvas',
1753
+ 'inlineImages',
1754
+ 'slimDOMOptions',
1755
+ 'doc',
1756
+ 'mirror',
1757
+ 'iframeManager',
1758
+ 'shadowDomManager',
1759
+ 'canvasManager',
1760
+ 'enableStrictPrivacy',
1761
+ ].forEach(function (key) {
1762
+ _this[key] = options[key];
1763
+ });
1764
+ };
1765
+ MutationBuffer.prototype.freeze = function () {
1766
+ this.frozen = true;
1767
+ this.canvasManager.freeze();
1768
+ };
1769
+ MutationBuffer.prototype.unfreeze = function () {
1770
+ this.frozen = false;
1771
+ this.canvasManager.unfreeze();
1772
+ this.emit();
1773
+ };
1774
+ MutationBuffer.prototype.isFrozen = function () {
1775
+ return this.frozen;
1776
+ };
1777
+ MutationBuffer.prototype.lock = function () {
1778
+ this.locked = true;
1779
+ this.canvasManager.lock();
1780
+ };
1781
+ MutationBuffer.prototype.unlock = function () {
1782
+ this.locked = false;
1783
+ this.canvasManager.unlock();
1784
+ this.emit();
1785
+ };
1786
+ MutationBuffer.prototype.reset = function () {
1787
+ this.shadowDomManager.reset();
1788
+ this.canvasManager.reset();
1789
+ };
1790
+ return MutationBuffer;
1791
+ }());
1792
+ function deepDelete(addsSet, n) {
1793
+ addsSet.delete(n);
1794
+ n.childNodes.forEach(function (childN) { return deepDelete(addsSet, childN); });
1795
+ }
1796
+ function isParentRemoved(removes, n, mirror) {
1797
+ var parentNode = n.parentNode;
1798
+ if (!parentNode) {
1799
+ return false;
1800
+ }
1801
+ var parentId = mirror.getId(parentNode);
1802
+ if (removes.some(function (r) { return r.id === parentId; })) {
1803
+ return true;
1804
+ }
1805
+ return isParentRemoved(removes, parentNode, mirror);
1806
+ }
1807
+ function isAncestorInSet(set, n) {
1808
+ var parentNode = n.parentNode;
1809
+ if (!parentNode) {
1810
+ return false;
1811
+ }
1812
+ if (set.has(parentNode)) {
1813
+ return true;
1814
+ }
1815
+ return isAncestorInSet(set, parentNode);
1816
+ }
1817
+
1818
+ var mutationBuffers = [];
1819
+ var isCSSGroupingRuleSupported = typeof CSSGroupingRule !== 'undefined';
1820
+ var isCSSMediaRuleSupported = typeof CSSMediaRule !== 'undefined';
1821
+ var isCSSSupportsRuleSupported = typeof CSSSupportsRule !== 'undefined';
1822
+ var isCSSConditionRuleSupported = typeof CSSConditionRule !== 'undefined';
1823
+ function getEventTarget(event) {
1824
+ try {
1825
+ if ('composedPath' in event) {
1826
+ var path = event.composedPath();
1827
+ if (path.length) {
1828
+ return path[0];
1829
+ }
1830
+ }
1831
+ else if ('path' in event && event.path.length) {
1832
+ return event.path[0];
1833
+ }
1834
+ return event.target;
1835
+ }
1836
+ catch (_a) {
1837
+ return event.target;
1838
+ }
1839
+ }
1840
+ function initMutationObserver(options, rootEl) {
1841
+ var _a, _b;
1842
+ var mutationBuffer = new MutationBuffer();
1843
+ mutationBuffers.push(mutationBuffer);
1844
+ mutationBuffer.init(options);
1845
+ var mutationObserverCtor = window.MutationObserver ||
1846
+ window.__rrMutationObserver;
1847
+ var angularZoneSymbol = (_b = (_a = window === null || window === void 0 ? void 0 : window.Zone) === null || _a === void 0 ? void 0 : _a.__symbol__) === null || _b === void 0 ? void 0 : _b.call(_a, 'MutationObserver');
1848
+ if (angularZoneSymbol &&
1849
+ window[angularZoneSymbol]) {
1850
+ mutationObserverCtor = window[angularZoneSymbol];
1851
+ }
1852
+ var observer = new mutationObserverCtor(mutationBuffer.processMutations.bind(mutationBuffer));
1853
+ observer.observe(rootEl, {
1854
+ attributes: true,
1855
+ attributeOldValue: true,
1856
+ characterData: true,
1857
+ characterDataOldValue: true,
1858
+ childList: true,
1859
+ subtree: true,
1860
+ });
1861
+ return observer;
1862
+ }
1863
+ function initMoveObserver(_a) {
1864
+ var mousemoveCb = _a.mousemoveCb, sampling = _a.sampling, doc = _a.doc, mirror = _a.mirror;
1865
+ if (sampling.mousemove === false) {
1866
+ return function () { };
1867
+ }
1868
+ var threshold = typeof sampling.mousemove === 'number' ? sampling.mousemove : 50;
1869
+ var callbackThreshold = typeof sampling.mousemoveCallback === 'number'
1870
+ ? sampling.mousemoveCallback
1871
+ : 500;
1872
+ var positions = [];
1873
+ var timeBaseline;
1874
+ var wrappedCb = throttle(function (source) {
1875
+ var totalOffset = Date.now() - timeBaseline;
1876
+ mousemoveCb(positions.map(function (p) {
1877
+ p.timeOffset -= totalOffset;
1878
+ return p;
1879
+ }), source);
1880
+ positions = [];
1881
+ timeBaseline = null;
1882
+ }, callbackThreshold);
1883
+ var updatePosition = throttle(function (evt) {
1884
+ var target = getEventTarget(evt);
1885
+ var _a = isTouchEvent(evt)
1886
+ ? evt.changedTouches[0]
1887
+ : evt, clientX = _a.clientX, clientY = _a.clientY;
1888
+ if (!timeBaseline) {
1889
+ timeBaseline = Date.now();
1890
+ }
1891
+ positions.push({
1892
+ x: clientX,
1893
+ y: clientY,
1894
+ id: mirror.getId(target),
1895
+ timeOffset: Date.now() - timeBaseline,
1896
+ });
1897
+ wrappedCb(typeof DragEvent !== 'undefined' && evt instanceof DragEvent
1898
+ ? IncrementalSource.Drag
1899
+ : evt instanceof MouseEvent
1900
+ ? IncrementalSource.MouseMove
1901
+ : IncrementalSource.TouchMove);
1902
+ }, threshold, {
1903
+ trailing: false,
1904
+ });
1905
+ var handlers = [
1906
+ on('mousemove', updatePosition, doc),
1907
+ on('touchmove', updatePosition, doc),
1908
+ on('drag', updatePosition, doc),
1909
+ ];
1910
+ return function () {
1911
+ handlers.forEach(function (h) { return h(); });
1912
+ };
1913
+ }
1914
+ function initMouseInteractionObserver(_a) {
1915
+ var mouseInteractionCb = _a.mouseInteractionCb, doc = _a.doc, mirror = _a.mirror, blockClass = _a.blockClass, sampling = _a.sampling;
1916
+ if (sampling.mouseInteraction === false) {
1917
+ return function () { };
1918
+ }
1919
+ var disableMap = sampling.mouseInteraction === true ||
1920
+ sampling.mouseInteraction === undefined
1921
+ ? {}
1922
+ : sampling.mouseInteraction;
1923
+ var handlers = [];
1924
+ var getHandler = function (eventKey) {
1925
+ return function (event) {
1926
+ var target = getEventTarget(event);
1927
+ if (isBlocked(target, blockClass) ||
1928
+ isCanvasNode(target)) {
1929
+ return;
1930
+ }
1931
+ var e = isTouchEvent(event) ? event.changedTouches[0] : event;
1932
+ if (!e) {
1933
+ return;
1934
+ }
1935
+ var id = mirror.getId(target);
1936
+ var clientX = e.clientX, clientY = e.clientY;
1937
+ mouseInteractionCb({
1938
+ type: MouseInteractions[eventKey],
1939
+ id: id,
1940
+ x: clientX,
1941
+ y: clientY,
1942
+ });
1943
+ };
1944
+ };
1945
+ Object.keys(MouseInteractions)
1946
+ .filter(function (key) {
1947
+ return Number.isNaN(Number(key)) &&
1948
+ !key.endsWith('_Departed') &&
1949
+ disableMap[key] !== false;
1950
+ })
1951
+ .forEach(function (eventKey) {
1952
+ var eventName = eventKey.toLowerCase();
1953
+ var handler = getHandler(eventKey);
1954
+ handlers.push(on(eventName, handler, doc));
1955
+ });
1956
+ return function () {
1957
+ handlers.forEach(function (h) { return h(); });
1958
+ };
1959
+ }
1960
+ function initScrollObserver(_a) {
1961
+ var scrollCb = _a.scrollCb, doc = _a.doc, mirror = _a.mirror, blockClass = _a.blockClass, sampling = _a.sampling;
1962
+ var updatePosition = throttle(function (evt) {
1963
+ var target = getEventTarget(evt);
1964
+ if (!target || isBlocked(target, blockClass)) {
1965
+ return;
1966
+ }
1967
+ var id = mirror.getId(target);
1968
+ if (target === doc) {
1969
+ var scrollEl = (doc.scrollingElement || doc.documentElement);
1970
+ scrollCb({
1971
+ id: id,
1972
+ x: scrollEl.scrollLeft,
1973
+ y: scrollEl.scrollTop,
1974
+ });
1975
+ }
1976
+ else {
1977
+ scrollCb({
1978
+ id: id,
1979
+ x: target.scrollLeft,
1980
+ y: target.scrollTop,
1981
+ });
1982
+ }
1983
+ }, sampling.scroll || 100);
1984
+ return on('scroll', updatePosition, doc);
1985
+ }
1986
+ function initViewportResizeObserver(_a) {
1987
+ var viewportResizeCb = _a.viewportResizeCb;
1988
+ var lastH = -1;
1989
+ var lastW = -1;
1990
+ var updateDimension = throttle(function () {
1991
+ var height = getWindowHeight();
1992
+ var width = getWindowWidth();
1993
+ if (lastH !== height || lastW !== width) {
1994
+ viewportResizeCb({
1995
+ width: Number(width),
1996
+ height: Number(height),
1997
+ });
1998
+ lastH = height;
1999
+ lastW = width;
2000
+ }
2001
+ }, 200);
2002
+ return on('resize', updateDimension, window);
2003
+ }
2004
+ function wrapEventWithUserTriggeredFlag(v, enable) {
2005
+ var value = __assign({}, v);
2006
+ if (!enable)
2007
+ delete value.userTriggered;
2008
+ return value;
2009
+ }
2010
+ var INPUT_TAGS = ['INPUT', 'TEXTAREA', 'SELECT'];
2011
+ var lastInputValueMap = new WeakMap();
2012
+ function initInputObserver(_a) {
2013
+ var inputCb = _a.inputCb, doc = _a.doc, mirror = _a.mirror, blockClass = _a.blockClass, ignoreClass = _a.ignoreClass, maskInputOptions = _a.maskInputOptions, maskInputFn = _a.maskInputFn, sampling = _a.sampling, userTriggeredOnInput = _a.userTriggeredOnInput;
2014
+ function eventHandler(event) {
2015
+ var target = getEventTarget(event);
2016
+ var userTriggered = event.isTrusted;
2017
+ if (target && target.tagName === 'OPTION')
2018
+ target = target.parentElement;
2019
+ if (!target ||
2020
+ !target.tagName ||
2021
+ INPUT_TAGS.indexOf(target.tagName) < 0 ||
2022
+ isBlocked(target, blockClass)) {
2023
+ return;
2024
+ }
2025
+ var type = target.type;
2026
+ if (target.classList.contains(ignoreClass)) {
2027
+ return;
2028
+ }
2029
+ var text = target.value;
2030
+ var isChecked = false;
2031
+ if (type === 'radio' || type === 'checkbox') {
2032
+ isChecked = target.checked;
2033
+ }
2034
+ else if (maskInputOptions[target.tagName.toLowerCase()] ||
2035
+ maskInputOptions[type]) {
2036
+ text = maskInputValue({
2037
+ maskInputOptions: maskInputOptions,
2038
+ tagName: target.tagName,
2039
+ type: type,
2040
+ value: text,
2041
+ maskInputFn: maskInputFn,
2042
+ });
2043
+ }
2044
+ cbWithDedup(target, wrapEventWithUserTriggeredFlag({ text: text, isChecked: isChecked, userTriggered: userTriggered }, userTriggeredOnInput));
2045
+ var name = target.name;
2046
+ if (type === 'radio' && name && isChecked) {
2047
+ doc
2048
+ .querySelectorAll("input[type=\"radio\"][name=\"".concat(name, "\"]"))
2049
+ .forEach(function (el) {
2050
+ if (el !== target) {
2051
+ cbWithDedup(el, wrapEventWithUserTriggeredFlag({
2052
+ text: el.value,
2053
+ isChecked: !isChecked,
2054
+ userTriggered: false,
2055
+ }, userTriggeredOnInput));
2056
+ }
2057
+ });
2058
+ }
2059
+ }
2060
+ function cbWithDedup(target, v) {
2061
+ var lastInputValue = lastInputValueMap.get(target);
2062
+ if (!lastInputValue ||
2063
+ lastInputValue.text !== v.text ||
2064
+ lastInputValue.isChecked !== v.isChecked) {
2065
+ lastInputValueMap.set(target, v);
2066
+ var id = mirror.getId(target);
2067
+ inputCb(__assign(__assign({}, v), { id: id }));
2068
+ }
2069
+ }
2070
+ var events = sampling.input === 'last' ? ['change'] : ['input', 'change'];
2071
+ var handlers = events.map(function (eventName) { return on(eventName, eventHandler, doc); });
2072
+ var propertyDescriptor = Object.getOwnPropertyDescriptor(HTMLInputElement.prototype, 'value');
2073
+ var hookProperties = [
2074
+ [HTMLInputElement.prototype, 'value'],
2075
+ [HTMLInputElement.prototype, 'checked'],
2076
+ [HTMLSelectElement.prototype, 'value'],
2077
+ [HTMLTextAreaElement.prototype, 'value'],
2078
+ [HTMLSelectElement.prototype, 'selectedIndex'],
2079
+ [HTMLOptionElement.prototype, 'selected'],
2080
+ ];
2081
+ if (propertyDescriptor && propertyDescriptor.set) {
2082
+ handlers.push.apply(handlers, __spreadArray([], __read(hookProperties.map(function (p) {
2083
+ return hookSetter(p[0], p[1], {
2084
+ set: function () {
2085
+ eventHandler({ target: this });
2086
+ },
2087
+ });
2088
+ })), false));
2089
+ }
2090
+ return function () {
2091
+ handlers.forEach(function (h) { return h(); });
2092
+ };
2093
+ }
2094
+ function getNestedCSSRulePositions(rule) {
2095
+ var positions = [];
2096
+ function recurse(childRule, pos) {
2097
+ if ((isCSSGroupingRuleSupported &&
2098
+ childRule.parentRule instanceof CSSGroupingRule) ||
2099
+ (isCSSMediaRuleSupported &&
2100
+ childRule.parentRule instanceof CSSMediaRule) ||
2101
+ (isCSSSupportsRuleSupported &&
2102
+ childRule.parentRule instanceof CSSSupportsRule) ||
2103
+ (isCSSConditionRuleSupported &&
2104
+ childRule.parentRule instanceof CSSConditionRule)) {
2105
+ var rules = Array.from(childRule.parentRule.cssRules);
2106
+ var index = rules.indexOf(childRule);
2107
+ pos.unshift(index);
2108
+ }
2109
+ else {
2110
+ var rules = Array.from(childRule.parentStyleSheet.cssRules);
2111
+ var index = rules.indexOf(childRule);
2112
+ pos.unshift(index);
2113
+ }
2114
+ return pos;
2115
+ }
2116
+ return recurse(rule, positions);
2117
+ }
2118
+ function initStyleSheetObserver(_a, _b) {
2119
+ var styleSheetRuleCb = _a.styleSheetRuleCb, mirror = _a.mirror;
2120
+ var win = _b.win;
2121
+ var insertRule = win.CSSStyleSheet.prototype.insertRule;
2122
+ win.CSSStyleSheet.prototype.insertRule = function (rule, index) {
2123
+ var id = mirror.getId(this.ownerNode);
2124
+ if (id !== -1) {
2125
+ styleSheetRuleCb({
2126
+ id: id,
2127
+ adds: [{ rule: rule, index: index }],
2128
+ });
2129
+ }
2130
+ return insertRule.apply(this, arguments);
2131
+ };
2132
+ var deleteRule = win.CSSStyleSheet.prototype.deleteRule;
2133
+ win.CSSStyleSheet.prototype.deleteRule = function (index) {
2134
+ var id = mirror.getId(this.ownerNode);
2135
+ if (id !== -1) {
2136
+ styleSheetRuleCb({
2137
+ id: id,
2138
+ removes: [{ index: index }],
2139
+ });
2140
+ }
2141
+ return deleteRule.apply(this, arguments);
2142
+ };
2143
+ var supportedNestedCSSRuleTypes = {};
2144
+ if (isCSSGroupingRuleSupported) {
2145
+ supportedNestedCSSRuleTypes.CSSGroupingRule = win.CSSGroupingRule;
2146
+ }
2147
+ else {
2148
+ if (isCSSMediaRuleSupported) {
2149
+ supportedNestedCSSRuleTypes.CSSMediaRule = win.CSSMediaRule;
2150
+ }
2151
+ if (isCSSConditionRuleSupported) {
2152
+ supportedNestedCSSRuleTypes.CSSConditionRule = win.CSSConditionRule;
2153
+ }
2154
+ if (isCSSSupportsRuleSupported) {
2155
+ supportedNestedCSSRuleTypes.CSSSupportsRule = win.CSSSupportsRule;
2156
+ }
2157
+ }
2158
+ var unmodifiedFunctions = {};
2159
+ Object.entries(supportedNestedCSSRuleTypes).forEach(function (_a) {
2160
+ var _b = __read(_a, 2), typeKey = _b[0], type = _b[1];
2161
+ unmodifiedFunctions[typeKey] = {
2162
+ insertRule: type.prototype.insertRule,
2163
+ deleteRule: type.prototype.deleteRule,
2164
+ };
2165
+ type.prototype.insertRule = function (rule, index) {
2166
+ var id = mirror.getId(this.parentStyleSheet.ownerNode);
2167
+ if (id !== -1) {
2168
+ styleSheetRuleCb({
2169
+ id: id,
2170
+ adds: [
2171
+ {
2172
+ rule: rule,
2173
+ index: __spreadArray(__spreadArray([], __read(getNestedCSSRulePositions(this)), false), [
2174
+ index || 0,
2175
+ ], false),
2176
+ },
2177
+ ],
2178
+ });
2179
+ }
2180
+ return unmodifiedFunctions[typeKey].insertRule.apply(this, arguments);
2181
+ };
2182
+ type.prototype.deleteRule = function (index) {
2183
+ var id = mirror.getId(this.parentStyleSheet.ownerNode);
2184
+ if (id !== -1) {
2185
+ styleSheetRuleCb({
2186
+ id: id,
2187
+ removes: [{ index: __spreadArray(__spreadArray([], __read(getNestedCSSRulePositions(this)), false), [index], false) }],
2188
+ });
2189
+ }
2190
+ return unmodifiedFunctions[typeKey].deleteRule.apply(this, arguments);
2191
+ };
2192
+ });
2193
+ return function () {
2194
+ win.CSSStyleSheet.prototype.insertRule = insertRule;
2195
+ win.CSSStyleSheet.prototype.deleteRule = deleteRule;
2196
+ Object.entries(supportedNestedCSSRuleTypes).forEach(function (_a) {
2197
+ var _b = __read(_a, 2), typeKey = _b[0], type = _b[1];
2198
+ type.prototype.insertRule = unmodifiedFunctions[typeKey].insertRule;
2199
+ type.prototype.deleteRule = unmodifiedFunctions[typeKey].deleteRule;
2200
+ });
2201
+ };
2202
+ }
2203
+ function initStyleDeclarationObserver(_a, _b) {
2204
+ var styleDeclarationCb = _a.styleDeclarationCb, mirror = _a.mirror;
2205
+ var win = _b.win;
2206
+ var setProperty = win.CSSStyleDeclaration.prototype.setProperty;
2207
+ win.CSSStyleDeclaration.prototype.setProperty = function (property, value, priority) {
2208
+ var _a, _b;
2209
+ var id = mirror.getId((_b = (_a = this.parentRule) === null || _a === void 0 ? void 0 : _a.parentStyleSheet) === null || _b === void 0 ? void 0 : _b.ownerNode);
2210
+ if (id !== -1) {
2211
+ styleDeclarationCb({
2212
+ id: id,
2213
+ set: {
2214
+ property: property,
2215
+ value: value,
2216
+ priority: priority,
2217
+ },
2218
+ index: getNestedCSSRulePositions(this.parentRule),
2219
+ });
2220
+ }
2221
+ return setProperty.apply(this, arguments);
2222
+ };
2223
+ var removeProperty = win.CSSStyleDeclaration.prototype.removeProperty;
2224
+ win.CSSStyleDeclaration.prototype.removeProperty = function (property) {
2225
+ var _a, _b;
2226
+ var id = mirror.getId((_b = (_a = this.parentRule) === null || _a === void 0 ? void 0 : _a.parentStyleSheet) === null || _b === void 0 ? void 0 : _b.ownerNode);
2227
+ if (id !== -1) {
2228
+ styleDeclarationCb({
2229
+ id: id,
2230
+ remove: {
2231
+ property: property,
2232
+ },
2233
+ index: getNestedCSSRulePositions(this.parentRule),
2234
+ });
2235
+ }
2236
+ return removeProperty.apply(this, arguments);
2237
+ };
2238
+ return function () {
2239
+ win.CSSStyleDeclaration.prototype.setProperty = setProperty;
2240
+ win.CSSStyleDeclaration.prototype.removeProperty = removeProperty;
2241
+ };
2242
+ }
2243
+ function initMediaInteractionObserver(_a) {
2244
+ var mediaInteractionCb = _a.mediaInteractionCb, blockClass = _a.blockClass, mirror = _a.mirror, sampling = _a.sampling;
2245
+ var handler = function (type) {
2246
+ return throttle(function (event) {
2247
+ var target = getEventTarget(event);
2248
+ if (!target || isBlocked(target, blockClass)) {
2249
+ return;
2250
+ }
2251
+ var _a = target, currentTime = _a.currentTime, volume = _a.volume, muted = _a.muted;
2252
+ mediaInteractionCb({
2253
+ type: type,
2254
+ id: mirror.getId(target),
2255
+ currentTime: currentTime,
2256
+ volume: volume,
2257
+ muted: muted,
2258
+ });
2259
+ }, sampling.media || 500);
2260
+ };
2261
+ var handlers = [
2262
+ on('play', handler(0)),
2263
+ on('pause', handler(1)),
2264
+ on('seeked', handler(2)),
2265
+ on('volumechange', handler(3)),
2266
+ ];
2267
+ return function () {
2268
+ handlers.forEach(function (h) { return h(); });
2269
+ };
2270
+ }
2271
+ function initFontObserver(_a) {
2272
+ var fontCb = _a.fontCb, doc = _a.doc;
2273
+ var win = doc.defaultView;
2274
+ if (!win) {
2275
+ return function () { };
2276
+ }
2277
+ var handlers = [];
2278
+ var fontMap = new WeakMap();
2279
+ var originalFontFace = win.FontFace;
2280
+ win.FontFace = function FontFace(family, source, descriptors) {
2281
+ var fontFace = new originalFontFace(family, source, descriptors);
2282
+ fontMap.set(fontFace, {
2283
+ family: family,
2284
+ buffer: typeof source !== 'string',
2285
+ descriptors: descriptors,
2286
+ fontSource: typeof source === 'string'
2287
+ ? source
2288
+ :
2289
+ JSON.stringify(Array.from(new Uint8Array(source))),
2290
+ });
2291
+ return fontFace;
2292
+ };
2293
+ var restoreHandler = patch(doc.fonts, 'add', function (original) {
2294
+ return function (fontFace) {
2295
+ setTimeout(function () {
2296
+ var p = fontMap.get(fontFace);
2297
+ if (p) {
2298
+ fontCb(p);
2299
+ fontMap.delete(fontFace);
2300
+ }
2301
+ }, 0);
2302
+ return original.apply(this, [fontFace]);
2303
+ };
2304
+ });
2305
+ handlers.push(function () {
2306
+ win.FontFace = originalFontFace;
2307
+ });
2308
+ handlers.push(restoreHandler);
2309
+ return function () {
2310
+ handlers.forEach(function (h) { return h(); });
2311
+ };
2312
+ }
2313
+ function mergeHooks(o, hooks) {
2314
+ var mutationCb = o.mutationCb, mousemoveCb = o.mousemoveCb, mouseInteractionCb = o.mouseInteractionCb, scrollCb = o.scrollCb, viewportResizeCb = o.viewportResizeCb, inputCb = o.inputCb, mediaInteractionCb = o.mediaInteractionCb, styleSheetRuleCb = o.styleSheetRuleCb, styleDeclarationCb = o.styleDeclarationCb, canvasMutationCb = o.canvasMutationCb, fontCb = o.fontCb;
2315
+ o.mutationCb = function () {
2316
+ var p = [];
2317
+ for (var _i = 0; _i < arguments.length; _i++) {
2318
+ p[_i] = arguments[_i];
2319
+ }
2320
+ if (hooks.mutation) {
2321
+ hooks.mutation.apply(hooks, __spreadArray([], __read(p), false));
2322
+ }
2323
+ mutationCb.apply(void 0, __spreadArray([], __read(p), false));
2324
+ };
2325
+ o.mousemoveCb = function () {
2326
+ var p = [];
2327
+ for (var _i = 0; _i < arguments.length; _i++) {
2328
+ p[_i] = arguments[_i];
2329
+ }
2330
+ if (hooks.mousemove) {
2331
+ hooks.mousemove.apply(hooks, __spreadArray([], __read(p), false));
2332
+ }
2333
+ mousemoveCb.apply(void 0, __spreadArray([], __read(p), false));
2334
+ };
2335
+ o.mouseInteractionCb = function () {
2336
+ var p = [];
2337
+ for (var _i = 0; _i < arguments.length; _i++) {
2338
+ p[_i] = arguments[_i];
2339
+ }
2340
+ if (hooks.mouseInteraction) {
2341
+ hooks.mouseInteraction.apply(hooks, __spreadArray([], __read(p), false));
2342
+ }
2343
+ mouseInteractionCb.apply(void 0, __spreadArray([], __read(p), false));
2344
+ };
2345
+ o.scrollCb = function () {
2346
+ var p = [];
2347
+ for (var _i = 0; _i < arguments.length; _i++) {
2348
+ p[_i] = arguments[_i];
2349
+ }
2350
+ if (hooks.scroll) {
2351
+ hooks.scroll.apply(hooks, __spreadArray([], __read(p), false));
2352
+ }
2353
+ scrollCb.apply(void 0, __spreadArray([], __read(p), false));
2354
+ };
2355
+ o.viewportResizeCb = function () {
2356
+ var p = [];
2357
+ for (var _i = 0; _i < arguments.length; _i++) {
2358
+ p[_i] = arguments[_i];
2359
+ }
2360
+ if (hooks.viewportResize) {
2361
+ hooks.viewportResize.apply(hooks, __spreadArray([], __read(p), false));
2362
+ }
2363
+ viewportResizeCb.apply(void 0, __spreadArray([], __read(p), false));
2364
+ };
2365
+ o.inputCb = function () {
2366
+ var p = [];
2367
+ for (var _i = 0; _i < arguments.length; _i++) {
2368
+ p[_i] = arguments[_i];
2369
+ }
2370
+ if (hooks.input) {
2371
+ hooks.input.apply(hooks, __spreadArray([], __read(p), false));
2372
+ }
2373
+ inputCb.apply(void 0, __spreadArray([], __read(p), false));
2374
+ };
2375
+ o.mediaInteractionCb = function () {
2376
+ var p = [];
2377
+ for (var _i = 0; _i < arguments.length; _i++) {
2378
+ p[_i] = arguments[_i];
2379
+ }
2380
+ if (hooks.mediaInteaction) {
2381
+ hooks.mediaInteaction.apply(hooks, __spreadArray([], __read(p), false));
2382
+ }
2383
+ mediaInteractionCb.apply(void 0, __spreadArray([], __read(p), false));
2384
+ };
2385
+ o.styleSheetRuleCb = function () {
2386
+ var p = [];
2387
+ for (var _i = 0; _i < arguments.length; _i++) {
2388
+ p[_i] = arguments[_i];
2389
+ }
2390
+ if (hooks.styleSheetRule) {
2391
+ hooks.styleSheetRule.apply(hooks, __spreadArray([], __read(p), false));
2392
+ }
2393
+ styleSheetRuleCb.apply(void 0, __spreadArray([], __read(p), false));
2394
+ };
2395
+ o.styleDeclarationCb = function () {
2396
+ var p = [];
2397
+ for (var _i = 0; _i < arguments.length; _i++) {
2398
+ p[_i] = arguments[_i];
2399
+ }
2400
+ if (hooks.styleDeclaration) {
2401
+ hooks.styleDeclaration.apply(hooks, __spreadArray([], __read(p), false));
2402
+ }
2403
+ styleDeclarationCb.apply(void 0, __spreadArray([], __read(p), false));
2404
+ };
2405
+ o.canvasMutationCb = function () {
2406
+ var p = [];
2407
+ for (var _i = 0; _i < arguments.length; _i++) {
2408
+ p[_i] = arguments[_i];
2409
+ }
2410
+ if (hooks.canvasMutation) {
2411
+ hooks.canvasMutation.apply(hooks, __spreadArray([], __read(p), false));
2412
+ }
2413
+ canvasMutationCb.apply(void 0, __spreadArray([], __read(p), false));
2414
+ };
2415
+ o.fontCb = function () {
2416
+ var p = [];
2417
+ for (var _i = 0; _i < arguments.length; _i++) {
2418
+ p[_i] = arguments[_i];
2419
+ }
2420
+ if (hooks.font) {
2421
+ hooks.font.apply(hooks, __spreadArray([], __read(p), false));
2422
+ }
2423
+ fontCb.apply(void 0, __spreadArray([], __read(p), false));
2424
+ };
2425
+ }
2426
+ function initObservers(o, hooks) {
2427
+ var e_1, _a;
2428
+ if (hooks === void 0) { hooks = {}; }
2429
+ var currentWindow = o.doc.defaultView;
2430
+ if (!currentWindow) {
2431
+ return function () { };
2432
+ }
2433
+ mergeHooks(o, hooks);
2434
+ var mutationObserver = initMutationObserver(o, o.doc);
2435
+ var mousemoveHandler = initMoveObserver(o);
2436
+ var mouseInteractionHandler = initMouseInteractionObserver(o);
2437
+ var scrollHandler = initScrollObserver(o);
2438
+ var viewportResizeHandler = initViewportResizeObserver(o);
2439
+ var inputHandler = initInputObserver(o);
2440
+ var mediaInteractionHandler = initMediaInteractionObserver(o);
2441
+ var styleSheetObserver = initStyleSheetObserver(o, { win: currentWindow });
2442
+ var styleDeclarationObserver = initStyleDeclarationObserver(o, {
2443
+ win: currentWindow,
2444
+ });
2445
+ var fontObserver = o.collectFonts ? initFontObserver(o) : function () { };
2446
+ var pluginHandlers = [];
2447
+ try {
2448
+ for (var _b = __values(o.plugins), _c = _b.next(); !_c.done; _c = _b.next()) {
2449
+ var plugin = _c.value;
2450
+ pluginHandlers.push(plugin.observer(plugin.callback, currentWindow, plugin.options));
2451
+ }
2452
+ }
2453
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
2454
+ finally {
2455
+ try {
2456
+ if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
2457
+ }
2458
+ finally { if (e_1) throw e_1.error; }
2459
+ }
2460
+ return function () {
2461
+ mutationBuffers.forEach(function (b) { return b.reset(); });
2462
+ mutationObserver.disconnect();
2463
+ mousemoveHandler();
2464
+ mouseInteractionHandler();
2465
+ scrollHandler();
2466
+ viewportResizeHandler();
2467
+ inputHandler();
2468
+ mediaInteractionHandler();
2469
+ styleSheetObserver();
2470
+ styleDeclarationObserver();
2471
+ fontObserver();
2472
+ pluginHandlers.forEach(function (h) { return h(); });
2473
+ };
2474
+ }
2475
+
2476
+ var IframeManager = (function () {
2477
+ function IframeManager(options) {
2478
+ this.iframes = new WeakMap();
2479
+ this.mutationCb = options.mutationCb;
2480
+ }
2481
+ IframeManager.prototype.addIframe = function (iframeEl) {
2482
+ this.iframes.set(iframeEl, true);
2483
+ };
2484
+ IframeManager.prototype.addLoadListener = function (cb) {
2485
+ this.loadListener = cb;
2486
+ };
2487
+ IframeManager.prototype.attachIframe = function (iframeEl, childSn) {
2488
+ var _a;
2489
+ this.mutationCb({
2490
+ adds: [
2491
+ {
2492
+ parentId: iframeEl.__sn.id,
2493
+ nextId: null,
2494
+ node: childSn,
2495
+ },
2496
+ ],
2497
+ removes: [],
2498
+ texts: [],
2499
+ attributes: [],
2500
+ isAttachIframe: true,
2501
+ });
2502
+ (_a = this.loadListener) === null || _a === void 0 ? void 0 : _a.call(this, iframeEl);
2503
+ };
2504
+ return IframeManager;
2505
+ }());
2506
+
2507
+ var ShadowDomManager = (function () {
2508
+ function ShadowDomManager(options) {
2509
+ this.restorePatches = [];
2510
+ this.mutationCb = options.mutationCb;
2511
+ this.scrollCb = options.scrollCb;
2512
+ this.bypassOptions = options.bypassOptions;
2513
+ this.mirror = options.mirror;
2514
+ var manager = this;
2515
+ this.restorePatches.push(patch(HTMLElement.prototype, 'attachShadow', function (original) {
2516
+ return function () {
2517
+ var shadowRoot = original.apply(this, arguments);
2518
+ if (this.shadowRoot)
2519
+ manager.addShadowRoot(this.shadowRoot, this.ownerDocument);
2520
+ return shadowRoot;
2521
+ };
2522
+ }));
2523
+ }
2524
+ ShadowDomManager.prototype.addShadowRoot = function (shadowRoot, doc) {
2525
+ initMutationObserver(__assign(__assign({}, this.bypassOptions), { doc: doc, mutationCb: this.mutationCb, mirror: this.mirror, shadowDomManager: this }), shadowRoot);
2526
+ initScrollObserver(__assign(__assign({}, this.bypassOptions), { scrollCb: this.scrollCb, doc: shadowRoot, mirror: this.mirror }));
2527
+ };
2528
+ ShadowDomManager.prototype.observeAttachShadow = function (iframeElement) {
2529
+ if (iframeElement.contentWindow) {
2530
+ var manager_1 = this;
2531
+ this.restorePatches.push(patch(iframeElement.contentWindow.HTMLElement.prototype, 'attachShadow', function (original) {
2532
+ return function () {
2533
+ var shadowRoot = original.apply(this, arguments);
2534
+ if (this.shadowRoot)
2535
+ manager_1.addShadowRoot(this.shadowRoot, iframeElement.contentDocument);
2536
+ return shadowRoot;
2537
+ };
2538
+ }));
2539
+ }
2540
+ };
2541
+ ShadowDomManager.prototype.reset = function () {
2542
+ this.restorePatches.forEach(function (restorePatch) { return restorePatch(); });
2543
+ };
2544
+ return ShadowDomManager;
2545
+ }());
2546
+
2547
+ function initCanvas2DMutationObserver(cb, win, blockClass, mirror) {
2548
+ var e_1, _a;
2549
+ var handlers = [];
2550
+ var props2D = Object.getOwnPropertyNames(win.CanvasRenderingContext2D.prototype);
2551
+ var _loop_1 = function (prop) {
2552
+ try {
2553
+ if (typeof win.CanvasRenderingContext2D.prototype[prop] !== 'function') {
2554
+ return "continue";
2555
+ }
2556
+ var restoreHandler = patch(win.CanvasRenderingContext2D.prototype, prop, function (original) {
2557
+ return function () {
2558
+ var _this = this;
2559
+ var args = [];
2560
+ for (var _i = 0; _i < arguments.length; _i++) {
2561
+ args[_i] = arguments[_i];
2562
+ }
2563
+ if (!isBlocked(this.canvas, blockClass)) {
2564
+ setTimeout(function () {
2565
+ var recordArgs = __spreadArray([], __read(args), false);
2566
+ if (prop === 'drawImage') {
2567
+ if (recordArgs[0] &&
2568
+ recordArgs[0] instanceof HTMLCanvasElement) {
2569
+ var canvas = recordArgs[0];
2570
+ var ctx = canvas.getContext('2d');
2571
+ var imgd = ctx === null || ctx === void 0 ? void 0 : ctx.getImageData(0, 0, canvas.width, canvas.height);
2572
+ var pix = imgd === null || imgd === void 0 ? void 0 : imgd.data;
2573
+ recordArgs[0] = JSON.stringify(pix);
2574
+ }
2575
+ }
2576
+ cb(_this.canvas, {
2577
+ type: CanvasContext['2D'],
2578
+ property: prop,
2579
+ args: recordArgs,
2580
+ });
2581
+ }, 0);
2582
+ }
2583
+ return original.apply(this, args);
2584
+ };
2585
+ });
2586
+ handlers.push(restoreHandler);
2587
+ }
2588
+ catch (_b) {
2589
+ var hookHandler = hookSetter(win.CanvasRenderingContext2D.prototype, prop, {
2590
+ set: function (v) {
2591
+ cb(this.canvas, {
2592
+ type: CanvasContext['2D'],
2593
+ property: prop,
2594
+ args: [v],
2595
+ setter: true,
2596
+ });
2597
+ },
2598
+ });
2599
+ handlers.push(hookHandler);
2600
+ }
2601
+ };
2602
+ try {
2603
+ for (var props2D_1 = __values(props2D), props2D_1_1 = props2D_1.next(); !props2D_1_1.done; props2D_1_1 = props2D_1.next()) {
2604
+ var prop = props2D_1_1.value;
2605
+ _loop_1(prop);
2606
+ }
2607
+ }
2608
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
2609
+ finally {
2610
+ try {
2611
+ if (props2D_1_1 && !props2D_1_1.done && (_a = props2D_1.return)) _a.call(props2D_1);
2612
+ }
2613
+ finally { if (e_1) throw e_1.error; }
2614
+ }
2615
+ return function () {
2616
+ handlers.forEach(function (h) { return h(); });
2617
+ };
2618
+ }
2619
+
2620
+ function initCanvasContextObserver(win, blockClass) {
2621
+ var handlers = [];
2622
+ try {
2623
+ var restoreHandler = patch(win.HTMLCanvasElement.prototype, 'getContext', function (original) {
2624
+ return function (contextType) {
2625
+ var args = [];
2626
+ for (var _i = 1; _i < arguments.length; _i++) {
2627
+ args[_i - 1] = arguments[_i];
2628
+ }
2629
+ if (!isBlocked(this, blockClass)) {
2630
+ if (!('__context' in this))
2631
+ this.__context = contextType;
2632
+ }
2633
+ return original.apply(this, __spreadArray([contextType], __read(args), false));
2634
+ };
2635
+ });
2636
+ handlers.push(restoreHandler);
2637
+ }
2638
+ catch (_a) {
2639
+ console.error('failed to patch HTMLCanvasElement.prototype.getContext');
2640
+ }
2641
+ return function () {
2642
+ handlers.forEach(function (h) { return h(); });
2643
+ };
2644
+ }
2645
+
2646
+ /*
2647
+ * base64-arraybuffer 1.0.1 <https://github.com/niklasvh/base64-arraybuffer>
2648
+ * Copyright (c) 2021 Niklas von Hertzen <https://hertzen.com>
2649
+ * Released under MIT License
2650
+ */
2651
+ var chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
2652
+ // Use a lookup table to find the index.
2653
+ var lookup = typeof Uint8Array === 'undefined' ? [] : new Uint8Array(256);
2654
+ for (var i = 0; i < chars.length; i++) {
2655
+ lookup[chars.charCodeAt(i)] = i;
2656
+ }
2657
+ var encode = function (arraybuffer) {
2658
+ var bytes = new Uint8Array(arraybuffer), i, len = bytes.length, base64 = '';
2659
+ for (i = 0; i < len; i += 3) {
2660
+ base64 += chars[bytes[i] >> 2];
2661
+ base64 += chars[((bytes[i] & 3) << 4) | (bytes[i + 1] >> 4)];
2662
+ base64 += chars[((bytes[i + 1] & 15) << 2) | (bytes[i + 2] >> 6)];
2663
+ base64 += chars[bytes[i + 2] & 63];
2664
+ }
2665
+ if (len % 3 === 2) {
2666
+ base64 = base64.substring(0, base64.length - 1) + '=';
2667
+ }
2668
+ else if (len % 3 === 1) {
2669
+ base64 = base64.substring(0, base64.length - 2) + '==';
2670
+ }
2671
+ return base64;
2672
+ };
2673
+
2674
+ var webGLVarMap = new Map();
2675
+ function variableListFor(ctx, ctor) {
2676
+ var contextMap = webGLVarMap.get(ctx);
2677
+ if (!contextMap) {
2678
+ contextMap = new Map();
2679
+ webGLVarMap.set(ctx, contextMap);
2680
+ }
2681
+ if (!contextMap.has(ctor)) {
2682
+ contextMap.set(ctor, []);
2683
+ }
2684
+ return contextMap.get(ctor);
2685
+ }
2686
+ var saveWebGLVar = function (value, win, ctx) {
2687
+ if (!value ||
2688
+ !(isInstanceOfWebGLObject(value, win) || typeof value === 'object'))
2689
+ return;
2690
+ var name = value.constructor.name;
2691
+ var list = variableListFor(ctx, name);
2692
+ var index = list.indexOf(value);
2693
+ if (index === -1) {
2694
+ index = list.length;
2695
+ list.push(value);
2696
+ }
2697
+ return index;
2698
+ };
2699
+ function serializeArg(value, win, ctx) {
2700
+ if (value instanceof Array) {
2701
+ return value.map(function (arg) { return serializeArg(arg, win, ctx); });
2702
+ }
2703
+ else if (value === null) {
2704
+ return value;
2705
+ }
2706
+ else if (value instanceof Float32Array ||
2707
+ value instanceof Float64Array ||
2708
+ value instanceof Int32Array ||
2709
+ value instanceof Uint32Array ||
2710
+ value instanceof Uint8Array ||
2711
+ value instanceof Uint16Array ||
2712
+ value instanceof Int16Array ||
2713
+ value instanceof Int8Array ||
2714
+ value instanceof Uint8ClampedArray) {
2715
+ var name_1 = value.constructor.name;
2716
+ return {
2717
+ rr_type: name_1,
2718
+ args: [Object.values(value)],
2719
+ };
2720
+ }
2721
+ else if (value instanceof ArrayBuffer) {
2722
+ var name_2 = value.constructor.name;
2723
+ var base64 = encode(value);
2724
+ return {
2725
+ rr_type: name_2,
2726
+ base64: base64,
2727
+ };
2728
+ }
2729
+ else if (value instanceof DataView) {
2730
+ var name_3 = value.constructor.name;
2731
+ return {
2732
+ rr_type: name_3,
2733
+ args: [
2734
+ serializeArg(value.buffer, win, ctx),
2735
+ value.byteOffset,
2736
+ value.byteLength,
2737
+ ],
2738
+ };
2739
+ }
2740
+ else if (value instanceof HTMLImageElement) {
2741
+ var name_4 = value.constructor.name;
2742
+ var src = value.src;
2743
+ return {
2744
+ rr_type: name_4,
2745
+ src: src,
2746
+ };
2747
+ }
2748
+ else if (value instanceof ImageData) {
2749
+ var name_5 = value.constructor.name;
2750
+ return {
2751
+ rr_type: name_5,
2752
+ args: [serializeArg(value.data, win, ctx), value.width, value.height],
2753
+ };
2754
+ }
2755
+ else if (isInstanceOfWebGLObject(value, win) || typeof value === 'object') {
2756
+ var name_6 = value.constructor.name;
2757
+ var index = saveWebGLVar(value, win, ctx);
2758
+ return {
2759
+ rr_type: name_6,
2760
+ index: index,
2761
+ };
2762
+ }
2763
+ return value;
2764
+ }
2765
+ var serializeArgs = function (args, win, ctx) {
2766
+ return __spreadArray([], __read(args), false).map(function (arg) { return serializeArg(arg, win, ctx); });
2767
+ };
2768
+ var isInstanceOfWebGLObject = function (value, win) {
2769
+ var webGLConstructorNames = [
2770
+ 'WebGLActiveInfo',
2771
+ 'WebGLBuffer',
2772
+ 'WebGLFramebuffer',
2773
+ 'WebGLProgram',
2774
+ 'WebGLRenderbuffer',
2775
+ 'WebGLShader',
2776
+ 'WebGLShaderPrecisionFormat',
2777
+ 'WebGLTexture',
2778
+ 'WebGLUniformLocation',
2779
+ 'WebGLVertexArrayObject',
2780
+ 'WebGLVertexArrayObjectOES',
2781
+ ];
2782
+ var supportedWebGLConstructorNames = webGLConstructorNames.filter(function (name) { return typeof win[name] === 'function'; });
2783
+ return Boolean(supportedWebGLConstructorNames.find(function (name) { return value instanceof win[name]; }));
2784
+ };
2785
+
2786
+ function patchGLPrototype(prototype, type, cb, blockClass, mirror, win) {
2787
+ var e_1, _a;
2788
+ var handlers = [];
2789
+ var props = Object.getOwnPropertyNames(prototype);
2790
+ var _loop_1 = function (prop) {
2791
+ try {
2792
+ if (typeof prototype[prop] !== 'function') {
2793
+ return "continue";
2794
+ }
2795
+ var restoreHandler = patch(prototype, prop, function (original) {
2796
+ return function () {
2797
+ var args = [];
2798
+ for (var _i = 0; _i < arguments.length; _i++) {
2799
+ args[_i] = arguments[_i];
2800
+ }
2801
+ var result = original.apply(this, args);
2802
+ saveWebGLVar(result, win, prototype);
2803
+ if (!isBlocked(this.canvas, blockClass)) {
2804
+ var id = mirror.getId(this.canvas);
2805
+ var recordArgs = serializeArgs(__spreadArray([], __read(args), false), win, prototype);
2806
+ var mutation = {
2807
+ type: type,
2808
+ property: prop,
2809
+ args: recordArgs,
2810
+ };
2811
+ cb(this.canvas, mutation);
2812
+ }
2813
+ return result;
2814
+ };
2815
+ });
2816
+ handlers.push(restoreHandler);
2817
+ }
2818
+ catch (_b) {
2819
+ var hookHandler = hookSetter(prototype, prop, {
2820
+ set: function (v) {
2821
+ cb(this.canvas, {
2822
+ type: type,
2823
+ property: prop,
2824
+ args: [v],
2825
+ setter: true,
2826
+ });
2827
+ },
2828
+ });
2829
+ handlers.push(hookHandler);
2830
+ }
2831
+ };
2832
+ try {
2833
+ for (var props_1 = __values(props), props_1_1 = props_1.next(); !props_1_1.done; props_1_1 = props_1.next()) {
2834
+ var prop = props_1_1.value;
2835
+ _loop_1(prop);
2836
+ }
2837
+ }
2838
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
2839
+ finally {
2840
+ try {
2841
+ if (props_1_1 && !props_1_1.done && (_a = props_1.return)) _a.call(props_1);
2842
+ }
2843
+ finally { if (e_1) throw e_1.error; }
2844
+ }
2845
+ return handlers;
2846
+ }
2847
+ function initCanvasWebGLMutationObserver(cb, win, blockClass, mirror) {
2848
+ var handlers = [];
2849
+ handlers.push.apply(handlers, __spreadArray([], __read(patchGLPrototype(win.WebGLRenderingContext.prototype, CanvasContext.WebGL, cb, blockClass, mirror, win)), false));
2850
+ if (typeof win.WebGL2RenderingContext !== 'undefined') {
2851
+ handlers.push.apply(handlers, __spreadArray([], __read(patchGLPrototype(win.WebGL2RenderingContext.prototype, CanvasContext.WebGL2, cb, blockClass, mirror, win)), false));
2852
+ }
2853
+ return function () {
2854
+ handlers.forEach(function (h) { return h(); });
2855
+ };
2856
+ }
2857
+
2858
+ var CanvasManager = (function () {
2859
+ function CanvasManager(options) {
2860
+ this.pendingCanvasMutations = new Map();
2861
+ this.rafStamps = { latestId: 0, invokeId: null };
2862
+ this.frozen = false;
2863
+ this.locked = false;
2864
+ this.processMutation = function (target, mutation) {
2865
+ var newFrame = this.rafStamps.invokeId &&
2866
+ this.rafStamps.latestId !== this.rafStamps.invokeId;
2867
+ if (newFrame || !this.rafStamps.invokeId)
2868
+ this.rafStamps.invokeId = this.rafStamps.latestId;
2869
+ if (!this.pendingCanvasMutations.has(target)) {
2870
+ this.pendingCanvasMutations.set(target, []);
2871
+ }
2872
+ this.pendingCanvasMutations.get(target).push(mutation);
2873
+ };
2874
+ this.mutationCb = options.mutationCb;
2875
+ this.mirror = options.mirror;
2876
+ if (options.recordCanvas === true)
2877
+ this.initCanvasMutationObserver(options.win, options.blockClass);
2878
+ }
2879
+ CanvasManager.prototype.reset = function () {
2880
+ this.pendingCanvasMutations.clear();
2881
+ this.resetObservers && this.resetObservers();
2882
+ };
2883
+ CanvasManager.prototype.freeze = function () {
2884
+ this.frozen = true;
2885
+ };
2886
+ CanvasManager.prototype.unfreeze = function () {
2887
+ this.frozen = false;
2888
+ };
2889
+ CanvasManager.prototype.lock = function () {
2890
+ this.locked = true;
2891
+ };
2892
+ CanvasManager.prototype.unlock = function () {
2893
+ this.locked = false;
2894
+ };
2895
+ CanvasManager.prototype.initCanvasMutationObserver = function (win, blockClass) {
2896
+ this.startRAFTimestamping();
2897
+ this.startPendingCanvasMutationFlusher();
2898
+ var canvasContextReset = initCanvasContextObserver(win, blockClass);
2899
+ var canvas2DReset = initCanvas2DMutationObserver(this.processMutation.bind(this), win, blockClass, this.mirror);
2900
+ var canvasWebGL1and2Reset = initCanvasWebGLMutationObserver(this.processMutation.bind(this), win, blockClass, this.mirror);
2901
+ this.resetObservers = function () {
2902
+ canvasContextReset();
2903
+ canvas2DReset();
2904
+ canvasWebGL1and2Reset();
2905
+ };
2906
+ };
2907
+ CanvasManager.prototype.startPendingCanvasMutationFlusher = function () {
2908
+ var _this = this;
2909
+ requestAnimationFrame(function () { return _this.flushPendingCanvasMutations(); });
2910
+ };
2911
+ CanvasManager.prototype.startRAFTimestamping = function () {
2912
+ var _this = this;
2913
+ var setLatestRAFTimestamp = function (timestamp) {
2914
+ _this.rafStamps.latestId = timestamp;
2915
+ requestAnimationFrame(setLatestRAFTimestamp);
2916
+ };
2917
+ requestAnimationFrame(setLatestRAFTimestamp);
2918
+ };
2919
+ CanvasManager.prototype.flushPendingCanvasMutations = function () {
2920
+ var _this = this;
2921
+ this.pendingCanvasMutations.forEach(function (values, canvas) {
2922
+ var id = _this.mirror.getId(canvas);
2923
+ _this.flushPendingCanvasMutationFor(canvas, id);
2924
+ });
2925
+ requestAnimationFrame(function () { return _this.flushPendingCanvasMutations(); });
2926
+ };
2927
+ CanvasManager.prototype.flushPendingCanvasMutationFor = function (canvas, id) {
2928
+ if (this.frozen || this.locked) {
2929
+ return;
2930
+ }
2931
+ var valuesWithType = this.pendingCanvasMutations.get(canvas);
2932
+ if (!valuesWithType || id === -1)
2933
+ return;
2934
+ var values = valuesWithType.map(function (value) {
2935
+ value.type; var rest = __rest(value, ["type"]);
2936
+ return rest;
2937
+ });
2938
+ var type = valuesWithType[0].type;
2939
+ this.mutationCb({ id: id, type: type, commands: values });
2940
+ this.pendingCanvasMutations.delete(canvas);
2941
+ };
2942
+ return CanvasManager;
2943
+ }());
2944
+
2945
+ function wrapEvent(e) {
2946
+ return __assign(__assign({}, e), { timestamp: Date.now() });
2947
+ }
2948
+ var wrappedEmit;
2949
+ var takeFullSnapshot;
2950
+ var mirror = createMirror();
2951
+ function record(options) {
2952
+ if (options === void 0) { options = {}; }
2953
+ var emit = options.emit, checkoutEveryNms = options.checkoutEveryNms, checkoutEveryNth = options.checkoutEveryNth, _a = options.blockClass, blockClass = _a === void 0 ? 'highlight-block' : _a, _b = options.blockSelector, blockSelector = _b === void 0 ? null : _b, _c = options.ignoreClass, ignoreClass = _c === void 0 ? 'highlight-ignore' : _c, _d = options.maskTextClass, maskTextClass = _d === void 0 ? 'highlight-mask' : _d, _e = options.maskTextSelector, maskTextSelector = _e === void 0 ? null : _e, _f = options.inlineStylesheet, inlineStylesheet = _f === void 0 ? true : _f, maskAllInputs = options.maskAllInputs, _maskInputOptions = options.maskInputOptions, _slimDOMOptions = options.slimDOMOptions, maskInputFn = options.maskInputFn, maskTextFn = options.maskTextFn, hooks = options.hooks, packFn = options.packFn, _g = options.sampling, sampling = _g === void 0 ? {} : _g, mousemoveWait = options.mousemoveWait, _h = options.recordCanvas, recordCanvas = _h === void 0 ? false : _h, _j = options.userTriggeredOnInput, userTriggeredOnInput = _j === void 0 ? false : _j, _k = options.collectFonts, collectFonts = _k === void 0 ? false : _k, _l = options.inlineImages, inlineImages = _l === void 0 ? false : _l, plugins = options.plugins, _m = options.keepIframeSrcFn, keepIframeSrcFn = _m === void 0 ? function () { return false; } : _m, _o = options.enableStrictPrivacy, enableStrictPrivacy = _o === void 0 ? false : _o;
2954
+ if (!emit) {
2955
+ throw new Error('emit function is required');
2956
+ }
2957
+ if (mousemoveWait !== undefined && sampling.mousemove === undefined) {
2958
+ sampling.mousemove = mousemoveWait;
2959
+ }
2960
+ var maskInputOptions = maskAllInputs === true
2961
+ ? {
2962
+ color: true,
2963
+ date: true,
2964
+ 'datetime-local': true,
2965
+ email: true,
2966
+ month: true,
2967
+ number: true,
2968
+ range: true,
2969
+ search: true,
2970
+ tel: true,
2971
+ text: true,
2972
+ time: true,
2973
+ url: true,
2974
+ week: true,
2975
+ textarea: true,
2976
+ select: true,
2977
+ password: true,
2978
+ }
2979
+ : _maskInputOptions !== undefined
2980
+ ? _maskInputOptions
2981
+ : { password: true };
2982
+ var slimDOMOptions = _slimDOMOptions === true || _slimDOMOptions === 'all'
2983
+ ? {
2984
+ script: true,
2985
+ comment: true,
2986
+ headFavicon: true,
2987
+ headWhitespace: true,
2988
+ headMetaSocial: true,
2989
+ headMetaRobots: true,
2990
+ headMetaHttpEquiv: true,
2991
+ headMetaVerification: true,
2992
+ headMetaAuthorship: _slimDOMOptions === 'all',
2993
+ headMetaDescKeywords: _slimDOMOptions === 'all',
2994
+ }
2995
+ : _slimDOMOptions
2996
+ ? _slimDOMOptions
2997
+ : {};
2998
+ polyfill();
2999
+ var lastFullSnapshotEvent;
3000
+ var incrementalSnapshotCount = 0;
3001
+ var eventProcessor = function (e) {
3002
+ var e_1, _a;
3003
+ try {
3004
+ for (var _b = __values(plugins || []), _c = _b.next(); !_c.done; _c = _b.next()) {
3005
+ var plugin = _c.value;
3006
+ if (plugin.eventProcessor) {
3007
+ e = plugin.eventProcessor(e);
3008
+ }
3009
+ }
3010
+ }
3011
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
3012
+ finally {
3013
+ try {
3014
+ if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
3015
+ }
3016
+ finally { if (e_1) throw e_1.error; }
3017
+ }
3018
+ if (packFn) {
3019
+ e = packFn(e);
3020
+ }
3021
+ return e;
3022
+ };
3023
+ wrappedEmit = function (e, isCheckout) {
3024
+ var _a;
3025
+ if (((_a = mutationBuffers[0]) === null || _a === void 0 ? void 0 : _a.isFrozen()) &&
3026
+ e.type !== EventType.FullSnapshot &&
3027
+ !(e.type === EventType.IncrementalSnapshot &&
3028
+ e.data.source === IncrementalSource.Mutation)) {
3029
+ mutationBuffers.forEach(function (buf) { return buf.unfreeze(); });
3030
+ }
3031
+ emit(eventProcessor(e), isCheckout);
3032
+ if (e.type === EventType.FullSnapshot) {
3033
+ lastFullSnapshotEvent = e;
3034
+ incrementalSnapshotCount = 0;
3035
+ }
3036
+ else if (e.type === EventType.IncrementalSnapshot) {
3037
+ if (e.data.source === IncrementalSource.Mutation &&
3038
+ e.data.isAttachIframe) {
3039
+ return;
3040
+ }
3041
+ incrementalSnapshotCount++;
3042
+ var exceedCount = checkoutEveryNth && incrementalSnapshotCount >= checkoutEveryNth;
3043
+ var exceedTime = checkoutEveryNms &&
3044
+ e.timestamp - lastFullSnapshotEvent.timestamp > checkoutEveryNms;
3045
+ if (exceedCount || exceedTime) {
3046
+ takeFullSnapshot(true);
3047
+ }
3048
+ }
3049
+ };
3050
+ var wrappedMutationEmit = function (m) {
3051
+ wrappedEmit(wrapEvent({
3052
+ type: EventType.IncrementalSnapshot,
3053
+ data: __assign({ source: IncrementalSource.Mutation }, m),
3054
+ }));
3055
+ };
3056
+ var wrappedScrollEmit = function (p) {
3057
+ return wrappedEmit(wrapEvent({
3058
+ type: EventType.IncrementalSnapshot,
3059
+ data: __assign({ source: IncrementalSource.Scroll }, p),
3060
+ }));
3061
+ };
3062
+ var wrappedCanvasMutationEmit = function (p) {
3063
+ return wrappedEmit(wrapEvent({
3064
+ type: EventType.IncrementalSnapshot,
3065
+ data: __assign({ source: IncrementalSource.CanvasMutation }, p),
3066
+ }));
3067
+ };
3068
+ var iframeManager = new IframeManager({
3069
+ mutationCb: wrappedMutationEmit,
3070
+ });
3071
+ var canvasManager = new CanvasManager({
3072
+ recordCanvas: recordCanvas,
3073
+ mutationCb: wrappedCanvasMutationEmit,
3074
+ win: window,
3075
+ blockClass: blockClass,
3076
+ mirror: mirror,
3077
+ });
3078
+ var shadowDomManager = new ShadowDomManager({
3079
+ mutationCb: wrappedMutationEmit,
3080
+ scrollCb: wrappedScrollEmit,
3081
+ bypassOptions: {
3082
+ blockClass: blockClass,
3083
+ blockSelector: blockSelector,
3084
+ maskTextClass: maskTextClass,
3085
+ maskTextSelector: maskTextSelector,
3086
+ inlineStylesheet: inlineStylesheet,
3087
+ maskInputOptions: maskInputOptions,
3088
+ maskTextFn: maskTextFn,
3089
+ maskInputFn: maskInputFn,
3090
+ recordCanvas: recordCanvas,
3091
+ inlineImages: inlineImages,
3092
+ sampling: sampling,
3093
+ slimDOMOptions: slimDOMOptions,
3094
+ iframeManager: iframeManager,
3095
+ canvasManager: canvasManager,
3096
+ enableStrictPrivacy: enableStrictPrivacy
3097
+ },
3098
+ mirror: mirror,
3099
+ });
3100
+ takeFullSnapshot = function (isCheckout) {
3101
+ var _a, _b, _c, _d;
3102
+ if (isCheckout === void 0) { isCheckout = false; }
3103
+ wrappedEmit(wrapEvent({
3104
+ type: EventType.Meta,
3105
+ data: {
3106
+ href: window.location.href,
3107
+ width: getWindowWidth(),
3108
+ height: getWindowHeight(),
3109
+ },
3110
+ }), isCheckout);
3111
+ mutationBuffers.forEach(function (buf) { return buf.lock(); });
3112
+ var _e = __read(snapshot(document, {
3113
+ blockClass: blockClass,
3114
+ blockSelector: blockSelector,
3115
+ maskTextClass: maskTextClass,
3116
+ maskTextSelector: maskTextSelector,
3117
+ inlineStylesheet: inlineStylesheet,
3118
+ maskAllInputs: maskInputOptions,
3119
+ maskTextFn: maskTextFn,
3120
+ slimDOM: slimDOMOptions,
3121
+ recordCanvas: recordCanvas,
3122
+ inlineImages: inlineImages,
3123
+ enableStrictPrivacy: enableStrictPrivacy,
3124
+ onSerialize: function (n) {
3125
+ if (isIframeINode(n)) {
3126
+ iframeManager.addIframe(n);
3127
+ }
3128
+ if (hasShadowRoot(n)) {
3129
+ shadowDomManager.addShadowRoot(n.shadowRoot, document);
3130
+ }
3131
+ },
3132
+ onIframeLoad: function (iframe, childSn) {
3133
+ iframeManager.attachIframe(iframe, childSn);
3134
+ shadowDomManager.observeAttachShadow(iframe);
3135
+ },
3136
+ keepIframeSrcFn: keepIframeSrcFn,
3137
+ }), 2), node = _e[0], idNodeMap = _e[1];
3138
+ if (!node) {
3139
+ return console.warn('Failed to snapshot the document');
3140
+ }
3141
+ mirror.map = idNodeMap;
3142
+ wrappedEmit(wrapEvent({
3143
+ type: EventType.FullSnapshot,
3144
+ data: {
3145
+ node: node,
3146
+ initialOffset: {
3147
+ left: window.pageXOffset !== undefined
3148
+ ? window.pageXOffset
3149
+ : (document === null || document === void 0 ? void 0 : document.documentElement.scrollLeft) ||
3150
+ ((_b = (_a = document === null || document === void 0 ? void 0 : document.body) === null || _a === void 0 ? void 0 : _a.parentElement) === null || _b === void 0 ? void 0 : _b.scrollLeft) ||
3151
+ (document === null || document === void 0 ? void 0 : document.body.scrollLeft) ||
3152
+ 0,
3153
+ top: window.pageYOffset !== undefined
3154
+ ? window.pageYOffset
3155
+ : (document === null || document === void 0 ? void 0 : document.documentElement.scrollTop) ||
3156
+ ((_d = (_c = document === null || document === void 0 ? void 0 : document.body) === null || _c === void 0 ? void 0 : _c.parentElement) === null || _d === void 0 ? void 0 : _d.scrollTop) ||
3157
+ (document === null || document === void 0 ? void 0 : document.body.scrollTop) ||
3158
+ 0,
3159
+ },
3160
+ },
3161
+ }));
3162
+ mutationBuffers.forEach(function (buf) { return buf.unlock(); });
3163
+ };
3164
+ try {
3165
+ var handlers_1 = [];
3166
+ handlers_1.push(on('DOMContentLoaded', function () {
3167
+ wrappedEmit(wrapEvent({
3168
+ type: EventType.DomContentLoaded,
3169
+ data: {},
3170
+ }));
3171
+ }));
3172
+ var observe_1 = function (doc) {
3173
+ var _a;
3174
+ return initObservers({
3175
+ mutationCb: wrappedMutationEmit,
3176
+ mousemoveCb: function (positions, source) {
3177
+ return wrappedEmit(wrapEvent({
3178
+ type: EventType.IncrementalSnapshot,
3179
+ data: {
3180
+ source: source,
3181
+ positions: positions,
3182
+ },
3183
+ }));
3184
+ },
3185
+ mouseInteractionCb: function (d) {
3186
+ return wrappedEmit(wrapEvent({
3187
+ type: EventType.IncrementalSnapshot,
3188
+ data: __assign({ source: IncrementalSource.MouseInteraction }, d),
3189
+ }));
3190
+ },
3191
+ scrollCb: wrappedScrollEmit,
3192
+ viewportResizeCb: function (d) {
3193
+ return wrappedEmit(wrapEvent({
3194
+ type: EventType.IncrementalSnapshot,
3195
+ data: __assign({ source: IncrementalSource.ViewportResize }, d),
3196
+ }));
3197
+ },
3198
+ inputCb: function (v) {
3199
+ return wrappedEmit(wrapEvent({
3200
+ type: EventType.IncrementalSnapshot,
3201
+ data: __assign({ source: IncrementalSource.Input }, v),
3202
+ }));
3203
+ },
3204
+ mediaInteractionCb: function (p) {
3205
+ return wrappedEmit(wrapEvent({
3206
+ type: EventType.IncrementalSnapshot,
3207
+ data: __assign({ source: IncrementalSource.MediaInteraction }, p),
3208
+ }));
3209
+ },
3210
+ styleSheetRuleCb: function (r) {
3211
+ return wrappedEmit(wrapEvent({
3212
+ type: EventType.IncrementalSnapshot,
3213
+ data: __assign({ source: IncrementalSource.StyleSheetRule }, r),
3214
+ }));
3215
+ },
3216
+ styleDeclarationCb: function (r) {
3217
+ return wrappedEmit(wrapEvent({
3218
+ type: EventType.IncrementalSnapshot,
3219
+ data: __assign({ source: IncrementalSource.StyleDeclaration }, r),
3220
+ }));
3221
+ },
3222
+ canvasMutationCb: wrappedCanvasMutationEmit,
3223
+ fontCb: function (p) {
3224
+ return wrappedEmit(wrapEvent({
3225
+ type: EventType.IncrementalSnapshot,
3226
+ data: __assign({ source: IncrementalSource.Font }, p),
3227
+ }));
3228
+ },
3229
+ blockClass: blockClass,
3230
+ ignoreClass: ignoreClass,
3231
+ maskTextClass: maskTextClass,
3232
+ maskTextSelector: maskTextSelector,
3233
+ maskInputOptions: maskInputOptions,
3234
+ inlineStylesheet: inlineStylesheet,
3235
+ sampling: sampling,
3236
+ recordCanvas: recordCanvas,
3237
+ inlineImages: inlineImages,
3238
+ userTriggeredOnInput: userTriggeredOnInput,
3239
+ collectFonts: collectFonts,
3240
+ doc: doc,
3241
+ maskInputFn: maskInputFn,
3242
+ maskTextFn: maskTextFn,
3243
+ blockSelector: blockSelector,
3244
+ slimDOMOptions: slimDOMOptions,
3245
+ mirror: mirror,
3246
+ iframeManager: iframeManager,
3247
+ shadowDomManager: shadowDomManager,
3248
+ canvasManager: canvasManager,
3249
+ enableStrictPrivacy: enableStrictPrivacy,
3250
+ plugins: ((_a = plugins === null || plugins === void 0 ? void 0 : plugins.filter(function (p) { return p.observer; })) === null || _a === void 0 ? void 0 : _a.map(function (p) { return ({
3251
+ observer: p.observer,
3252
+ options: p.options,
3253
+ callback: function (payload) {
3254
+ return wrappedEmit(wrapEvent({
3255
+ type: EventType.Plugin,
3256
+ data: {
3257
+ plugin: p.name,
3258
+ payload: payload,
3259
+ },
3260
+ }));
3261
+ },
3262
+ }); })) || [],
3263
+ }, hooks);
3264
+ };
3265
+ iframeManager.addLoadListener(function (iframeEl) {
3266
+ handlers_1.push(observe_1(iframeEl.contentDocument));
3267
+ });
3268
+ var init_1 = function () {
3269
+ takeFullSnapshot();
3270
+ handlers_1.push(observe_1(document));
3271
+ };
3272
+ if (document.readyState === 'interactive' ||
3273
+ document.readyState === 'complete') {
3274
+ init_1();
3275
+ }
3276
+ else {
3277
+ handlers_1.push(on('load', function () {
3278
+ wrappedEmit(wrapEvent({
3279
+ type: EventType.Load,
3280
+ data: {},
3281
+ }));
3282
+ init_1();
3283
+ }, window));
3284
+ }
3285
+ return function () {
3286
+ handlers_1.forEach(function (h) { return h(); });
3287
+ };
3288
+ }
3289
+ catch (error) {
3290
+ console.warn(error);
3291
+ }
3292
+ }
3293
+ record.addCustomEvent = function (tag, payload) {
3294
+ if (!wrappedEmit) {
3295
+ return;
3296
+ }
3297
+ wrappedEmit(wrapEvent({
3298
+ type: EventType.Custom,
3299
+ data: {
3300
+ tag: tag,
3301
+ payload: payload,
3302
+ },
3303
+ }));
3304
+ };
3305
+ record.freezePage = function () {
3306
+ mutationBuffers.forEach(function (buf) { return buf.freeze(); });
3307
+ };
3308
+ record.takeFullSnapshot = function (isCheckout) {
3309
+ if (!takeFullSnapshot) {
3310
+ throw new Error('please take full snapshot after start recording');
3311
+ }
3312
+ takeFullSnapshot(isCheckout);
3313
+ };
3314
+ record.mirror = mirror;
3315
+
3316
+ return record;
3317
+
3318
+ }());