@highlight-run/rrweb 1.2.1 → 2.0.4

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