@highlight-run/rrweb 2.0.1 → 2.0.6

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 (118) hide show
  1. package/dist/plugins/console-record.js +12 -655
  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 +4 -293
  5. package/dist/plugins/console-replay.min.js +4 -15
  6. package/dist/plugins/console-replay.min.js.map +1 -1
  7. package/dist/plugins/sequential-id-record.js +1 -33
  8. package/dist/plugins/sequential-id-record.min.js +1 -1
  9. package/dist/plugins/sequential-id-record.min.js.map +1 -1
  10. package/dist/plugins/sequential-id-replay.js +1 -37
  11. package/dist/plugins/sequential-id-replay.min.js +1 -1
  12. package/dist/plugins/sequential-id-replay.min.js.map +1 -1
  13. package/dist/record/rrweb-record-pack.js +3 -747
  14. package/dist/record/rrweb-record-pack.min.js +3 -15
  15. package/dist/record/rrweb-record-pack.min.js.map +1 -1
  16. package/dist/record/rrweb-record.js +4 -3318
  17. package/dist/record/rrweb-record.min.js +4 -15
  18. package/dist/record/rrweb-record.min.js.map +1 -1
  19. package/dist/replay/rrweb-replay-unpack.css +1 -0
  20. package/dist/replay/rrweb-replay-unpack.js +5 -4614
  21. package/dist/replay/rrweb-replay-unpack.min.js +5 -17
  22. package/dist/replay/rrweb-replay-unpack.min.js.map +1 -1
  23. package/dist/replay/rrweb-replay.css +1 -0
  24. package/dist/replay/rrweb-replay.js +5 -4204
  25. package/dist/replay/rrweb-replay.min.js +5 -17
  26. package/dist/replay/rrweb-replay.min.js.map +1 -1
  27. package/dist/rrweb-all.css +1 -0
  28. package/dist/rrweb-all.js +16 -8696
  29. package/dist/rrweb-all.min.js +16 -17
  30. package/dist/rrweb-all.min.js.map +1 -1
  31. package/dist/rrweb.css +1 -0
  32. package/dist/rrweb.js +6 -7282
  33. package/dist/rrweb.min.js +6 -17
  34. package/dist/rrweb.min.js.map +1 -1
  35. package/es/rrweb/_virtual/_rollup-plugin-web-worker-loader__helper__auto__createBase64WorkerFactory.js +12 -0
  36. package/es/rrweb/_virtual/_rollup-plugin-web-worker-loader__helper__auto__isNodeJS.js +7 -0
  37. package/es/rrweb/_virtual/_rollup-plugin-web-worker-loader__helper__browser__createBase64WorkerFactory.js +31 -0
  38. package/es/rrweb/_virtual/_rollup-plugin-web-worker-loader__helper__node__WorkerClass.js +11 -0
  39. package/es/rrweb/_virtual/_rollup-plugin-web-worker-loader__helper__node__createBase64WorkerFactory.js +18 -0
  40. package/es/rrweb/_virtual/image-bitmap-data-url-worker.js +6 -0
  41. package/es/rrweb/all.css +1 -0
  42. package/es/rrweb/ext/mitt/dist/mitt.es.js +1 -1
  43. package/es/rrweb/ext/tslib/tslib.es6.js +38 -0
  44. package/es/rrweb/packages/rrdom/es/virtual-dom.js +1099 -0
  45. package/es/rrweb/packages/rrweb/src/index.js +6 -4
  46. package/es/rrweb/packages/rrweb/src/packer/base.js +1 -1
  47. package/es/rrweb/packages/rrweb/src/packer/pack.js +4 -5
  48. package/es/rrweb/packages/rrweb/src/packer/unpack.js +24 -24
  49. package/es/rrweb/packages/rrweb/src/plugins/console/record/error-stack-parser.js +175 -176
  50. package/es/rrweb/packages/rrweb/src/plugins/console/record/index.js +109 -128
  51. package/es/rrweb/packages/rrweb/src/plugins/console/record/stringify.js +125 -138
  52. package/es/rrweb/packages/rrweb/src/plugins/console/replay/index.js +88 -105
  53. package/es/rrweb/packages/rrweb/src/plugins/sequential-id/record/index.js +19 -20
  54. package/es/rrweb/packages/rrweb/src/plugins/sequential-id/replay/index.js +25 -25
  55. package/es/rrweb/packages/rrweb/src/record/iframe-manager.js +29 -30
  56. package/es/rrweb/packages/rrweb/src/record/index.js +348 -373
  57. package/es/rrweb/packages/rrweb/src/record/mutation.js +487 -528
  58. package/es/rrweb/packages/rrweb/src/record/observer.js +584 -659
  59. package/es/rrweb/packages/rrweb/src/record/observers/canvas/2d.js +44 -73
  60. package/es/rrweb/packages/rrweb/src/record/observers/canvas/canvas-manager.js +166 -87
  61. package/es/rrweb/packages/rrweb/src/record/observers/canvas/canvas.js +21 -26
  62. package/es/rrweb/packages/rrweb/src/record/observers/canvas/serialize-args.js +119 -112
  63. package/es/rrweb/packages/rrweb/src/record/observers/canvas/webgl.js +53 -72
  64. package/es/rrweb/packages/rrweb/src/record/shadow-dom-manager.js +38 -40
  65. package/es/rrweb/packages/rrweb/src/record/stylesheet-manager.js +31 -0
  66. package/es/rrweb/packages/rrweb/src/replay/canvas/2d.js +27 -23
  67. package/es/rrweb/packages/rrweb/src/replay/canvas/deserialize-args.js +67 -0
  68. package/es/rrweb/packages/rrweb/src/replay/canvas/index.js +37 -29
  69. package/es/rrweb/packages/rrweb/src/replay/canvas/webgl.js +58 -120
  70. package/es/rrweb/packages/rrweb/src/replay/index.js +1545 -1854
  71. package/es/rrweb/packages/rrweb/src/replay/machine.js +275 -315
  72. package/es/rrweb/packages/rrweb/src/replay/smoothscroll.js +216 -218
  73. package/es/rrweb/packages/rrweb/src/replay/styles/inject-style.js +7 -7
  74. package/es/rrweb/packages/rrweb/src/replay/timer.js +87 -91
  75. package/es/rrweb/packages/rrweb/src/types.js +72 -72
  76. package/es/rrweb/packages/rrweb/src/utils.js +312 -506
  77. package/es/rrweb/packages/rrweb-snapshot/es/rrweb-snapshot.js +190 -72
  78. package/lib/plugins/console-record.js +469 -627
  79. package/lib/plugins/console-replay.js +198 -268
  80. package/lib/plugins/sequential-id-record.js +19 -20
  81. package/lib/plugins/sequential-id-replay.js +25 -25
  82. package/lib/record/rrweb-record-pack.js +184 -139
  83. package/lib/record/rrweb-record.js +2467 -2425
  84. package/lib/replay/rrweb-replay-unpack.css +1 -0
  85. package/lib/replay/rrweb-replay-unpack.js +3798 -3344
  86. package/lib/replay/rrweb-replay.css +1 -0
  87. package/lib/replay/rrweb-replay.js +3743 -3289
  88. package/lib/rrweb-all.css +1 -0
  89. package/lib/rrweb-all.js +6721 -6249
  90. package/lib/rrweb.css +1 -0
  91. package/lib/rrweb.js +6151 -5632
  92. package/package.json +14 -13
  93. package/typings/packer/base.d.ts +1 -1
  94. package/typings/plugins/console/record/index.d.ts +1 -1
  95. package/typings/plugins/console/record/stringify.d.ts +1 -1
  96. package/typings/plugins/sequential-id/record/index.d.ts +1 -1
  97. package/typings/plugins/sequential-id/replay/index.d.ts +1 -1
  98. package/typings/record/iframe-manager.d.ts +3 -3
  99. package/typings/record/index.d.ts +1 -1
  100. package/typings/record/mutation.d.ts +2 -1
  101. package/typings/record/observers/canvas/2d.d.ts +2 -1
  102. package/typings/record/observers/canvas/canvas-manager.d.ts +5 -2
  103. package/typings/record/observers/canvas/canvas.d.ts +1 -1
  104. package/typings/record/observers/canvas/serialize-args.d.ts +5 -5
  105. package/typings/record/observers/canvas/webgl.d.ts +2 -1
  106. package/typings/record/shadow-dom-manager.d.ts +2 -1
  107. package/typings/record/stylesheet-manager.d.ts +12 -0
  108. package/typings/record/workers/image-bitmap-data-url-worker.d.ts +5 -0
  109. package/typings/replay/canvas/2d.d.ts +3 -3
  110. package/typings/replay/canvas/deserialize-args.d.ts +7 -0
  111. package/typings/replay/canvas/index.d.ts +4 -3
  112. package/typings/replay/canvas/webgl.d.ts +3 -5
  113. package/typings/replay/index.d.ts +7 -10
  114. package/typings/types.d.ts +45 -17
  115. package/typings/utils.d.ts +17 -44
  116. package/es/rrweb/packages/rrweb/ext/tslib/tslib.es6.js +0 -78
  117. package/es/rrweb/packages/rrweb/src/replay/virtual-styles.js +0 -121
  118. package/typings/replay/virtual-styles.d.ts +0 -43
@@ -0,0 +1,1099 @@
1
+ var NodeType$1;
2
+ (function (NodeType) {
3
+ NodeType[NodeType["Document"] = 0] = "Document";
4
+ NodeType[NodeType["DocumentType"] = 1] = "DocumentType";
5
+ NodeType[NodeType["Element"] = 2] = "Element";
6
+ NodeType[NodeType["Text"] = 3] = "Text";
7
+ NodeType[NodeType["CDATA"] = 4] = "CDATA";
8
+ NodeType[NodeType["Comment"] = 5] = "Comment";
9
+ })(NodeType$1 || (NodeType$1 = {}));
10
+ var Mirror$1 = (function () {
11
+ function Mirror() {
12
+ this.idNodeMap = new Map();
13
+ this.nodeMetaMap = new WeakMap();
14
+ }
15
+ Mirror.prototype.getId = function (n) {
16
+ var _a;
17
+ if (!n)
18
+ return -1;
19
+ var id = (_a = this.getMeta(n)) === null || _a === void 0 ? void 0 : _a.id;
20
+ return id !== null && id !== void 0 ? id : -1;
21
+ };
22
+ Mirror.prototype.getNode = function (id) {
23
+ return this.idNodeMap.get(id) || null;
24
+ };
25
+ Mirror.prototype.getIds = function () {
26
+ return Array.from(this.idNodeMap.keys());
27
+ };
28
+ Mirror.prototype.getMeta = function (n) {
29
+ return this.nodeMetaMap.get(n) || null;
30
+ };
31
+ Mirror.prototype.removeNodeFromMap = function (n) {
32
+ var _this = this;
33
+ var id = this.getId(n);
34
+ this.idNodeMap["delete"](id);
35
+ if (n.childNodes) {
36
+ n.childNodes.forEach(function (childNode) {
37
+ return _this.removeNodeFromMap(childNode);
38
+ });
39
+ }
40
+ };
41
+ Mirror.prototype.has = function (id) {
42
+ return this.idNodeMap.has(id);
43
+ };
44
+ Mirror.prototype.hasNode = function (node) {
45
+ return this.nodeMetaMap.has(node);
46
+ };
47
+ Mirror.prototype.add = function (n, meta) {
48
+ var id = meta.id;
49
+ this.idNodeMap.set(id, n);
50
+ this.nodeMetaMap.set(n, meta);
51
+ };
52
+ Mirror.prototype.replace = function (id, n) {
53
+ this.idNodeMap.set(id, n);
54
+ };
55
+ Mirror.prototype.reset = function () {
56
+ this.idNodeMap = new Map();
57
+ this.nodeMetaMap = new WeakMap();
58
+ };
59
+ return Mirror;
60
+ }());
61
+ function createMirror$1() {
62
+ return new Mirror$1();
63
+ }
64
+
65
+ function parseCSSText(cssText) {
66
+ const res = {};
67
+ const listDelimiter = /;(?![^(]*\))/g;
68
+ const propertyDelimiter = /:(.+)/;
69
+ const comment = /\/\*.*?\*\//g;
70
+ cssText
71
+ .replace(comment, '')
72
+ .split(listDelimiter)
73
+ .forEach(function (item) {
74
+ if (item) {
75
+ const tmp = item.split(propertyDelimiter);
76
+ tmp.length > 1 && (res[camelize(tmp[0].trim())] = tmp[1].trim());
77
+ }
78
+ });
79
+ return res;
80
+ }
81
+ function toCSSText(style) {
82
+ const properties = [];
83
+ for (const name in style) {
84
+ const value = style[name];
85
+ if (typeof value !== 'string')
86
+ continue;
87
+ const normalizedName = hyphenate(name);
88
+ properties.push(`${normalizedName}: ${value};`);
89
+ }
90
+ return properties.join(' ');
91
+ }
92
+ const camelizeRE = /-([a-z])/g;
93
+ const CUSTOM_PROPERTY_REGEX = /^--[a-zA-Z0-9-]+$/;
94
+ const camelize = (str) => {
95
+ if (CUSTOM_PROPERTY_REGEX.test(str))
96
+ return str;
97
+ return str.replace(camelizeRE, (_, c) => (c ? c.toUpperCase() : ''));
98
+ };
99
+ const hyphenateRE = /\B([A-Z])/g;
100
+ const hyphenate = (str) => {
101
+ return str.replace(hyphenateRE, '-$1').toLowerCase();
102
+ };
103
+
104
+ class BaseRRNode {
105
+ constructor(...args) {
106
+ this.childNodes = [];
107
+ this.parentElement = null;
108
+ this.parentNode = null;
109
+ this.ELEMENT_NODE = NodeType.ELEMENT_NODE;
110
+ this.TEXT_NODE = NodeType.TEXT_NODE;
111
+ }
112
+ get firstChild() {
113
+ return this.childNodes[0] || null;
114
+ }
115
+ get lastChild() {
116
+ return this.childNodes[this.childNodes.length - 1] || null;
117
+ }
118
+ get nextSibling() {
119
+ const parentNode = this.parentNode;
120
+ if (!parentNode)
121
+ return null;
122
+ const siblings = parentNode.childNodes;
123
+ const index = siblings.indexOf(this);
124
+ return siblings[index + 1] || null;
125
+ }
126
+ contains(node) {
127
+ if (node === this)
128
+ return true;
129
+ for (const child of this.childNodes) {
130
+ if (child.contains(node))
131
+ return true;
132
+ }
133
+ return false;
134
+ }
135
+ appendChild(_newChild) {
136
+ throw new Error(`RRDomException: Failed to execute 'appendChild' on 'RRNode': This RRNode type does not support this method.`);
137
+ }
138
+ insertBefore(_newChild, _refChild) {
139
+ throw new Error(`RRDomException: Failed to execute 'insertBefore' on 'RRNode': This RRNode type does not support this method.`);
140
+ }
141
+ removeChild(node) {
142
+ throw new Error(`RRDomException: Failed to execute 'removeChild' on 'RRNode': This RRNode type does not support this method.`);
143
+ }
144
+ toString() {
145
+ return 'RRNode';
146
+ }
147
+ }
148
+ function BaseRRDocumentImpl(RRNodeClass) {
149
+ return class BaseRRDocument extends RRNodeClass {
150
+ constructor() {
151
+ super(...arguments);
152
+ this.nodeType = NodeType.DOCUMENT_NODE;
153
+ this.nodeName = '#document';
154
+ this.compatMode = 'CSS1Compat';
155
+ this.RRNodeType = NodeType$1.Document;
156
+ this.textContent = null;
157
+ }
158
+ get documentElement() {
159
+ return (this.childNodes.find((node) => node.RRNodeType === NodeType$1.Element &&
160
+ node.tagName === 'HTML') || null);
161
+ }
162
+ get body() {
163
+ var _a;
164
+ return (((_a = this.documentElement) === null || _a === void 0 ? void 0 : _a.childNodes.find((node) => node.RRNodeType === NodeType$1.Element &&
165
+ node.tagName === 'BODY')) || null);
166
+ }
167
+ get head() {
168
+ var _a;
169
+ return (((_a = this.documentElement) === null || _a === void 0 ? void 0 : _a.childNodes.find((node) => node.RRNodeType === NodeType$1.Element &&
170
+ node.tagName === 'HEAD')) || null);
171
+ }
172
+ get implementation() {
173
+ return this;
174
+ }
175
+ get firstElementChild() {
176
+ return this.documentElement;
177
+ }
178
+ appendChild(childNode) {
179
+ const nodeType = childNode.RRNodeType;
180
+ if (nodeType === NodeType$1.Element ||
181
+ nodeType === NodeType$1.DocumentType) {
182
+ if (this.childNodes.some((s) => s.RRNodeType === nodeType)) {
183
+ throw new Error(`RRDomException: Failed to execute 'appendChild' on 'RRNode': Only one ${nodeType === NodeType$1.Element ? 'RRElement' : 'RRDoctype'} on RRDocument allowed.`);
184
+ }
185
+ }
186
+ childNode.parentElement = null;
187
+ childNode.parentNode = this;
188
+ this.childNodes.push(childNode);
189
+ return childNode;
190
+ }
191
+ insertBefore(newChild, refChild) {
192
+ const nodeType = newChild.RRNodeType;
193
+ if (nodeType === NodeType$1.Element ||
194
+ nodeType === NodeType$1.DocumentType) {
195
+ if (this.childNodes.some((s) => s.RRNodeType === nodeType)) {
196
+ throw new Error(`RRDomException: Failed to execute 'insertBefore' on 'RRNode': Only one ${nodeType === NodeType$1.Element ? 'RRElement' : 'RRDoctype'} on RRDocument allowed.`);
197
+ }
198
+ }
199
+ if (refChild === null)
200
+ return this.appendChild(newChild);
201
+ const childIndex = this.childNodes.indexOf(refChild);
202
+ if (childIndex == -1)
203
+ throw new Error("Failed to execute 'insertBefore' on 'RRNode': The RRNode before which the new node is to be inserted is not a child of this RRNode.");
204
+ this.childNodes.splice(childIndex, 0, newChild);
205
+ newChild.parentElement = null;
206
+ newChild.parentNode = this;
207
+ return newChild;
208
+ }
209
+ removeChild(node) {
210
+ const indexOfChild = this.childNodes.indexOf(node);
211
+ if (indexOfChild === -1)
212
+ throw new Error("Failed to execute 'removeChild' on 'RRDocument': The RRNode to be removed is not a child of this RRNode.");
213
+ this.childNodes.splice(indexOfChild, 1);
214
+ node.parentElement = null;
215
+ node.parentNode = null;
216
+ return node;
217
+ }
218
+ open() {
219
+ this.childNodes = [];
220
+ }
221
+ close() {
222
+ }
223
+ write(content) {
224
+ let publicId;
225
+ if (content ===
226
+ '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">')
227
+ publicId = '-//W3C//DTD XHTML 1.0 Transitional//EN';
228
+ else if (content ===
229
+ '<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "">')
230
+ publicId = '-//W3C//DTD HTML 4.0 Transitional//EN';
231
+ if (publicId) {
232
+ const doctype = this.createDocumentType('html', publicId, '');
233
+ this.open();
234
+ this.appendChild(doctype);
235
+ }
236
+ }
237
+ createDocument(_namespace, _qualifiedName, _doctype) {
238
+ return new BaseRRDocument();
239
+ }
240
+ createDocumentType(qualifiedName, publicId, systemId) {
241
+ const doctype = new (BaseRRDocumentTypeImpl(BaseRRNode))(qualifiedName, publicId, systemId);
242
+ doctype.ownerDocument = this;
243
+ return doctype;
244
+ }
245
+ createElement(tagName) {
246
+ const element = new (BaseRRElementImpl(BaseRRNode))(tagName);
247
+ element.ownerDocument = this;
248
+ return element;
249
+ }
250
+ createElementNS(_namespaceURI, qualifiedName) {
251
+ return this.createElement(qualifiedName);
252
+ }
253
+ createTextNode(data) {
254
+ const text = new (BaseRRTextImpl(BaseRRNode))(data);
255
+ text.ownerDocument = this;
256
+ return text;
257
+ }
258
+ createComment(data) {
259
+ const comment = new (BaseRRCommentImpl(BaseRRNode))(data);
260
+ comment.ownerDocument = this;
261
+ return comment;
262
+ }
263
+ createCDATASection(data) {
264
+ const CDATASection = new (BaseRRCDATASectionImpl(BaseRRNode))(data);
265
+ CDATASection.ownerDocument = this;
266
+ return CDATASection;
267
+ }
268
+ toString() {
269
+ return 'RRDocument';
270
+ }
271
+ };
272
+ }
273
+ function BaseRRDocumentTypeImpl(RRNodeClass) {
274
+ return class BaseRRDocumentType extends RRNodeClass {
275
+ constructor(qualifiedName, publicId, systemId) {
276
+ super();
277
+ this.nodeType = NodeType.DOCUMENT_TYPE_NODE;
278
+ this.RRNodeType = NodeType$1.DocumentType;
279
+ this.textContent = null;
280
+ this.name = qualifiedName;
281
+ this.publicId = publicId;
282
+ this.systemId = systemId;
283
+ this.nodeName = qualifiedName;
284
+ }
285
+ toString() {
286
+ return 'RRDocumentType';
287
+ }
288
+ };
289
+ }
290
+ function BaseRRElementImpl(RRNodeClass) {
291
+ return class BaseRRElement extends RRNodeClass {
292
+ constructor(tagName) {
293
+ super();
294
+ this.nodeType = NodeType.ELEMENT_NODE;
295
+ this.RRNodeType = NodeType$1.Element;
296
+ this.attributes = {};
297
+ this.shadowRoot = null;
298
+ this.tagName = tagName.toUpperCase();
299
+ this.nodeName = tagName.toUpperCase();
300
+ }
301
+ get textContent() {
302
+ let result = '';
303
+ this.childNodes.forEach((node) => (result += node.textContent));
304
+ return result;
305
+ }
306
+ set textContent(textContent) {
307
+ this.childNodes = [this.ownerDocument.createTextNode(textContent)];
308
+ }
309
+ get classList() {
310
+ return new ClassList(this.attributes.class, (newClassName) => {
311
+ this.attributes.class = newClassName;
312
+ });
313
+ }
314
+ get id() {
315
+ return this.attributes.id || '';
316
+ }
317
+ get className() {
318
+ return this.attributes.class || '';
319
+ }
320
+ get style() {
321
+ const style = (this.attributes.style
322
+ ? parseCSSText(this.attributes.style)
323
+ : {});
324
+ const hyphenateRE = /\B([A-Z])/g;
325
+ style.setProperty = (name, value, priority) => {
326
+ if (hyphenateRE.test(name))
327
+ return;
328
+ const normalizedName = camelize(name);
329
+ if (!value)
330
+ delete style[normalizedName];
331
+ else
332
+ style[normalizedName] = value;
333
+ if (priority === 'important')
334
+ style[normalizedName] += ' !important';
335
+ this.attributes.style = toCSSText(style);
336
+ };
337
+ style.removeProperty = (name) => {
338
+ if (hyphenateRE.test(name))
339
+ return '';
340
+ const normalizedName = camelize(name);
341
+ const value = style[normalizedName] || '';
342
+ delete style[normalizedName];
343
+ this.attributes.style = toCSSText(style);
344
+ return value;
345
+ };
346
+ return style;
347
+ }
348
+ getAttribute(name) {
349
+ return this.attributes[name] || null;
350
+ }
351
+ setAttribute(name, attribute) {
352
+ this.attributes[name] = attribute;
353
+ }
354
+ setAttributeNS(_namespace, qualifiedName, value) {
355
+ this.setAttribute(qualifiedName, value);
356
+ }
357
+ removeAttribute(name) {
358
+ delete this.attributes[name];
359
+ }
360
+ appendChild(newChild) {
361
+ this.childNodes.push(newChild);
362
+ newChild.parentNode = this;
363
+ newChild.parentElement = this;
364
+ return newChild;
365
+ }
366
+ insertBefore(newChild, refChild) {
367
+ if (refChild === null)
368
+ return this.appendChild(newChild);
369
+ const childIndex = this.childNodes.indexOf(refChild);
370
+ if (childIndex == -1)
371
+ throw new Error("Failed to execute 'insertBefore' on 'RRNode': The RRNode before which the new node is to be inserted is not a child of this RRNode.");
372
+ this.childNodes.splice(childIndex, 0, newChild);
373
+ newChild.parentElement = this;
374
+ newChild.parentNode = this;
375
+ return newChild;
376
+ }
377
+ removeChild(node) {
378
+ const indexOfChild = this.childNodes.indexOf(node);
379
+ if (indexOfChild === -1)
380
+ throw new Error("Failed to execute 'removeChild' on 'RRElement': The RRNode to be removed is not a child of this RRNode.");
381
+ this.childNodes.splice(indexOfChild, 1);
382
+ node.parentElement = null;
383
+ node.parentNode = null;
384
+ return node;
385
+ }
386
+ attachShadow(_init) {
387
+ const shadowRoot = this.ownerDocument.createElement('SHADOWROOT');
388
+ this.shadowRoot = shadowRoot;
389
+ return shadowRoot;
390
+ }
391
+ dispatchEvent(_event) {
392
+ return true;
393
+ }
394
+ toString() {
395
+ let attributeString = '';
396
+ for (const attribute in this.attributes) {
397
+ attributeString += `${attribute}="${this.attributes[attribute]}" `;
398
+ }
399
+ return `${this.tagName} ${attributeString}`;
400
+ }
401
+ };
402
+ }
403
+ function BaseRRMediaElementImpl(RRElementClass) {
404
+ return class BaseRRMediaElement extends RRElementClass {
405
+ attachShadow(_init) {
406
+ throw new Error(`RRDomException: Failed to execute 'attachShadow' on 'RRElement': This RRElement does not support attachShadow`);
407
+ }
408
+ play() {
409
+ this.paused = false;
410
+ }
411
+ pause() {
412
+ this.paused = true;
413
+ }
414
+ };
415
+ }
416
+ function BaseRRTextImpl(RRNodeClass) {
417
+ return class BaseRRText extends RRNodeClass {
418
+ constructor(data) {
419
+ super();
420
+ this.nodeType = NodeType.TEXT_NODE;
421
+ this.nodeName = '#text';
422
+ this.RRNodeType = NodeType$1.Text;
423
+ this.data = data;
424
+ }
425
+ get textContent() {
426
+ return this.data;
427
+ }
428
+ set textContent(textContent) {
429
+ this.data = textContent;
430
+ }
431
+ toString() {
432
+ return `RRText text=${JSON.stringify(this.data)}`;
433
+ }
434
+ };
435
+ }
436
+ function BaseRRCommentImpl(RRNodeClass) {
437
+ return class BaseRRComment extends RRNodeClass {
438
+ constructor(data) {
439
+ super();
440
+ this.nodeType = NodeType.COMMENT_NODE;
441
+ this.nodeName = '#comment';
442
+ this.RRNodeType = NodeType$1.Comment;
443
+ this.data = data;
444
+ }
445
+ get textContent() {
446
+ return this.data;
447
+ }
448
+ set textContent(textContent) {
449
+ this.data = textContent;
450
+ }
451
+ toString() {
452
+ return `RRComment text=${JSON.stringify(this.data)}`;
453
+ }
454
+ };
455
+ }
456
+ function BaseRRCDATASectionImpl(RRNodeClass) {
457
+ return class BaseRRCDATASection extends RRNodeClass {
458
+ constructor(data) {
459
+ super();
460
+ this.nodeName = '#cdata-section';
461
+ this.nodeType = NodeType.CDATA_SECTION_NODE;
462
+ this.RRNodeType = NodeType$1.CDATA;
463
+ this.data = data;
464
+ }
465
+ get textContent() {
466
+ return this.data;
467
+ }
468
+ set textContent(textContent) {
469
+ this.data = textContent;
470
+ }
471
+ toString() {
472
+ return `RRCDATASection data=${JSON.stringify(this.data)}`;
473
+ }
474
+ };
475
+ }
476
+ class ClassList {
477
+ constructor(classText, onChange) {
478
+ this.classes = [];
479
+ this.add = (...classNames) => {
480
+ for (const item of classNames) {
481
+ const className = String(item);
482
+ if (this.classes.indexOf(className) >= 0)
483
+ continue;
484
+ this.classes.push(className);
485
+ }
486
+ this.onChange && this.onChange(this.classes.join(' '));
487
+ };
488
+ this.remove = (...classNames) => {
489
+ this.classes = this.classes.filter((item) => classNames.indexOf(item) === -1);
490
+ this.onChange && this.onChange(this.classes.join(' '));
491
+ };
492
+ if (classText) {
493
+ const classes = classText.trim().split(/\s+/);
494
+ this.classes.push(...classes);
495
+ }
496
+ this.onChange = onChange;
497
+ }
498
+ }
499
+ var NodeType;
500
+ (function (NodeType) {
501
+ NodeType[NodeType["PLACEHOLDER"] = 0] = "PLACEHOLDER";
502
+ NodeType[NodeType["ELEMENT_NODE"] = 1] = "ELEMENT_NODE";
503
+ NodeType[NodeType["ATTRIBUTE_NODE"] = 2] = "ATTRIBUTE_NODE";
504
+ NodeType[NodeType["TEXT_NODE"] = 3] = "TEXT_NODE";
505
+ NodeType[NodeType["CDATA_SECTION_NODE"] = 4] = "CDATA_SECTION_NODE";
506
+ NodeType[NodeType["ENTITY_REFERENCE_NODE"] = 5] = "ENTITY_REFERENCE_NODE";
507
+ NodeType[NodeType["ENTITY_NODE"] = 6] = "ENTITY_NODE";
508
+ NodeType[NodeType["PROCESSING_INSTRUCTION_NODE"] = 7] = "PROCESSING_INSTRUCTION_NODE";
509
+ NodeType[NodeType["COMMENT_NODE"] = 8] = "COMMENT_NODE";
510
+ NodeType[NodeType["DOCUMENT_NODE"] = 9] = "DOCUMENT_NODE";
511
+ NodeType[NodeType["DOCUMENT_TYPE_NODE"] = 10] = "DOCUMENT_TYPE_NODE";
512
+ NodeType[NodeType["DOCUMENT_FRAGMENT_NODE"] = 11] = "DOCUMENT_FRAGMENT_NODE";
513
+ })(NodeType || (NodeType = {}));
514
+
515
+ const NAMESPACES = {
516
+ svg: 'http://www.w3.org/2000/svg',
517
+ 'xlink:href': 'http://www.w3.org/1999/xlink',
518
+ xmlns: 'http://www.w3.org/2000/xmlns/',
519
+ };
520
+ function diff(oldTree, newTree, replayer, rrnodeMirror) {
521
+ const oldChildren = oldTree.childNodes;
522
+ const newChildren = newTree.childNodes;
523
+ rrnodeMirror =
524
+ rrnodeMirror ||
525
+ newTree.mirror ||
526
+ newTree.ownerDocument.mirror;
527
+ if (oldChildren.length > 0 || newChildren.length > 0) {
528
+ diffChildren(Array.from(oldChildren), newChildren, oldTree, replayer, rrnodeMirror);
529
+ }
530
+ let inputDataToApply = null, scrollDataToApply = null;
531
+ switch (newTree.RRNodeType) {
532
+ case NodeType$1.Document: {
533
+ const newRRDocument = newTree;
534
+ scrollDataToApply = newRRDocument.scrollData;
535
+ break;
536
+ }
537
+ case NodeType$1.Element: {
538
+ const oldElement = (oldTree);
539
+ const newRRElement = newTree;
540
+ diffProps(oldElement, newRRElement, rrnodeMirror);
541
+ scrollDataToApply = newRRElement.scrollData;
542
+ inputDataToApply = newRRElement.inputData;
543
+ switch (newRRElement.tagName) {
544
+ case 'AUDIO':
545
+ case 'VIDEO': {
546
+ const oldMediaElement = (oldTree);
547
+ const newMediaRRElement = newRRElement;
548
+ if (newMediaRRElement.paused !== undefined)
549
+ newMediaRRElement.paused
550
+ ? oldMediaElement.pause()
551
+ : oldMediaElement.play();
552
+ if (newMediaRRElement.muted !== undefined)
553
+ oldMediaElement.muted = newMediaRRElement.muted;
554
+ if (newMediaRRElement.volume !== undefined)
555
+ oldMediaElement.volume = newMediaRRElement.volume;
556
+ if (newMediaRRElement.currentTime !== undefined)
557
+ oldMediaElement.currentTime = newMediaRRElement.currentTime;
558
+ break;
559
+ }
560
+ case 'CANVAS':
561
+ newTree.canvasMutations.forEach((canvasMutation) => replayer.applyCanvas(canvasMutation.event, canvasMutation.mutation, (oldTree)));
562
+ break;
563
+ case 'STYLE':
564
+ applyVirtualStyleRulesToNode(oldElement, newTree.rules);
565
+ break;
566
+ }
567
+ if (newRRElement.shadowRoot) {
568
+ if (!oldElement.shadowRoot)
569
+ oldElement.attachShadow({ mode: 'open' });
570
+ const oldChildren = oldElement.shadowRoot.childNodes;
571
+ const newChildren = newRRElement.shadowRoot.childNodes;
572
+ if (oldChildren.length > 0 || newChildren.length > 0)
573
+ diffChildren(Array.from(oldChildren), newChildren, oldElement.shadowRoot, replayer, rrnodeMirror);
574
+ }
575
+ break;
576
+ }
577
+ case NodeType$1.Text:
578
+ case NodeType$1.Comment:
579
+ case NodeType$1.CDATA:
580
+ if (oldTree.textContent !==
581
+ newTree.data)
582
+ oldTree.textContent = newTree.data;
583
+ break;
584
+ }
585
+ scrollDataToApply && replayer.applyScroll(scrollDataToApply, true);
586
+ inputDataToApply && replayer.applyInput(inputDataToApply);
587
+ if (newTree.nodeName === 'IFRAME') {
588
+ const oldContentDocument = (oldTree)
589
+ .contentDocument;
590
+ const newIFrameElement = newTree;
591
+ if (oldContentDocument) {
592
+ const sn = rrnodeMirror.getMeta(newIFrameElement.contentDocument);
593
+ if (sn) {
594
+ replayer.mirror.add(oldContentDocument, Object.assign({}, sn));
595
+ }
596
+ diff(oldContentDocument, newIFrameElement.contentDocument, replayer, rrnodeMirror);
597
+ }
598
+ }
599
+ }
600
+ function diffProps(oldTree, newTree, rrnodeMirror) {
601
+ const oldAttributes = oldTree.attributes;
602
+ const newAttributes = newTree.attributes;
603
+ for (const name in newAttributes) {
604
+ const newValue = newAttributes[name];
605
+ const sn = rrnodeMirror.getMeta(newTree);
606
+ if (sn && 'isSVG' in sn && sn.isSVG && NAMESPACES[name])
607
+ oldTree.setAttributeNS(NAMESPACES[name], name, newValue);
608
+ else if (newTree.tagName === 'CANVAS' && name === 'rr_dataURL') {
609
+ const image = document.createElement('img');
610
+ image.src = newValue;
611
+ image.onload = () => {
612
+ const ctx = oldTree.getContext('2d');
613
+ if (ctx) {
614
+ ctx.drawImage(image, 0, 0, image.width, image.height);
615
+ }
616
+ };
617
+ }
618
+ else
619
+ oldTree.setAttribute(name, newValue);
620
+ }
621
+ for (const { name } of Array.from(oldAttributes))
622
+ if (!(name in newAttributes))
623
+ oldTree.removeAttribute(name);
624
+ newTree.scrollLeft && (oldTree.scrollLeft = newTree.scrollLeft);
625
+ newTree.scrollTop && (oldTree.scrollTop = newTree.scrollTop);
626
+ }
627
+ function diffChildren(oldChildren, newChildren, parentNode, replayer, rrnodeMirror) {
628
+ var _a, _b;
629
+ let oldStartIndex = 0, oldEndIndex = oldChildren.length - 1, newStartIndex = 0, newEndIndex = newChildren.length - 1;
630
+ let oldStartNode = oldChildren[oldStartIndex], oldEndNode = oldChildren[oldEndIndex], newStartNode = newChildren[newStartIndex], newEndNode = newChildren[newEndIndex];
631
+ let oldIdToIndex = undefined, indexInOld;
632
+ while (oldStartIndex <= oldEndIndex && newStartIndex <= newEndIndex) {
633
+ if (oldStartNode === undefined) {
634
+ oldStartNode = oldChildren[++oldStartIndex];
635
+ }
636
+ else if (oldEndNode === undefined) {
637
+ oldEndNode = oldChildren[--oldEndIndex];
638
+ }
639
+ else if (replayer.mirror.getId(oldStartNode) === rrnodeMirror.getId(newStartNode)) {
640
+ diff(oldStartNode, newStartNode, replayer, rrnodeMirror);
641
+ oldStartNode = oldChildren[++oldStartIndex];
642
+ newStartNode = newChildren[++newStartIndex];
643
+ }
644
+ else if (replayer.mirror.getId(oldEndNode) === rrnodeMirror.getId(newEndNode)) {
645
+ diff(oldEndNode, newEndNode, replayer, rrnodeMirror);
646
+ oldEndNode = oldChildren[--oldEndIndex];
647
+ newEndNode = newChildren[--newEndIndex];
648
+ }
649
+ else if (replayer.mirror.getId(oldStartNode) === rrnodeMirror.getId(newEndNode)) {
650
+ parentNode.insertBefore(oldStartNode, oldEndNode.nextSibling);
651
+ diff(oldStartNode, newEndNode, replayer, rrnodeMirror);
652
+ oldStartNode = oldChildren[++oldStartIndex];
653
+ newEndNode = newChildren[--newEndIndex];
654
+ }
655
+ else if (replayer.mirror.getId(oldEndNode) === rrnodeMirror.getId(newStartNode)) {
656
+ parentNode.insertBefore(oldEndNode, oldStartNode);
657
+ diff(oldEndNode, newStartNode, replayer, rrnodeMirror);
658
+ oldEndNode = oldChildren[--oldEndIndex];
659
+ newStartNode = newChildren[++newStartIndex];
660
+ }
661
+ else {
662
+ if (!oldIdToIndex) {
663
+ oldIdToIndex = {};
664
+ for (let i = oldStartIndex; i <= oldEndIndex; i++) {
665
+ const oldChild = oldChildren[i];
666
+ if (oldChild && replayer.mirror.hasNode(oldChild))
667
+ oldIdToIndex[replayer.mirror.getId(oldChild)] = i;
668
+ }
669
+ }
670
+ indexInOld = oldIdToIndex[rrnodeMirror.getId(newStartNode)];
671
+ if (indexInOld) {
672
+ const nodeToMove = oldChildren[indexInOld];
673
+ parentNode.insertBefore(nodeToMove, oldStartNode);
674
+ diff(nodeToMove, newStartNode, replayer, rrnodeMirror);
675
+ oldChildren[indexInOld] = undefined;
676
+ }
677
+ else {
678
+ const newNode = createOrGetNode(newStartNode, replayer.mirror, rrnodeMirror);
679
+ if (((_a = replayer.mirror.getMeta(parentNode)) === null || _a === void 0 ? void 0 : _a.type) === NodeType$1.Document &&
680
+ ((_b = replayer.mirror.getMeta(newNode)) === null || _b === void 0 ? void 0 : _b.type) === NodeType$1.Element &&
681
+ (parentNode).documentElement) {
682
+ parentNode.removeChild((parentNode).documentElement);
683
+ oldChildren[oldStartIndex] = undefined;
684
+ oldStartNode = undefined;
685
+ }
686
+ parentNode.insertBefore(newNode, oldStartNode || null);
687
+ diff(newNode, newStartNode, replayer, rrnodeMirror);
688
+ }
689
+ newStartNode = newChildren[++newStartIndex];
690
+ }
691
+ }
692
+ if (oldStartIndex > oldEndIndex) {
693
+ const referenceRRNode = newChildren[newEndIndex + 1];
694
+ let referenceNode = null;
695
+ if (referenceRRNode)
696
+ parentNode.childNodes.forEach((child) => {
697
+ if (replayer.mirror.getId(child) === rrnodeMirror.getId(referenceRRNode))
698
+ referenceNode = child;
699
+ });
700
+ for (; newStartIndex <= newEndIndex; ++newStartIndex) {
701
+ const newNode = createOrGetNode(newChildren[newStartIndex], replayer.mirror, rrnodeMirror);
702
+ parentNode.insertBefore(newNode, referenceNode);
703
+ diff(newNode, newChildren[newStartIndex], replayer, rrnodeMirror);
704
+ }
705
+ }
706
+ else if (newStartIndex > newEndIndex) {
707
+ for (; oldStartIndex <= oldEndIndex; oldStartIndex++) {
708
+ const node = oldChildren[oldStartIndex];
709
+ if (node) {
710
+ parentNode.removeChild(node);
711
+ replayer.mirror.removeNodeFromMap(node);
712
+ }
713
+ }
714
+ }
715
+ }
716
+ function createOrGetNode(rrNode, domMirror, rrnodeMirror) {
717
+ let node = domMirror.getNode(rrnodeMirror.getId(rrNode));
718
+ const sn = rrnodeMirror.getMeta(rrNode);
719
+ if (node !== null)
720
+ return node;
721
+ switch (rrNode.RRNodeType) {
722
+ case NodeType$1.Document:
723
+ node = new Document();
724
+ break;
725
+ case NodeType$1.DocumentType:
726
+ node = document.implementation.createDocumentType(rrNode.name, rrNode.publicId, rrNode.systemId);
727
+ break;
728
+ case NodeType$1.Element: {
729
+ rrNode.tagName.toLowerCase();
730
+ if (sn && 'isSVG' in sn && (sn === null || sn === void 0 ? void 0 : sn.isSVG)) {
731
+ node = document.createElementNS(NAMESPACES['svg'], rrNode.tagName.toLowerCase());
732
+ }
733
+ else
734
+ node = document.createElement(rrNode.tagName);
735
+ break;
736
+ }
737
+ case NodeType$1.Text:
738
+ node = document.createTextNode(rrNode.data);
739
+ break;
740
+ case NodeType$1.Comment:
741
+ node = document.createComment(rrNode.data);
742
+ break;
743
+ case NodeType$1.CDATA:
744
+ node = document.createCDATASection(rrNode.data);
745
+ break;
746
+ }
747
+ if (sn)
748
+ domMirror.add(node, Object.assign({}, sn));
749
+ return node;
750
+ }
751
+ function getNestedRule(rules, position) {
752
+ const rule = rules[position[0]];
753
+ if (position.length === 1) {
754
+ return rule;
755
+ }
756
+ else {
757
+ return getNestedRule((rule).cssRules[position[1]]
758
+ .cssRules, position.slice(2));
759
+ }
760
+ }
761
+ var StyleRuleType;
762
+ (function (StyleRuleType) {
763
+ StyleRuleType[StyleRuleType["Insert"] = 0] = "Insert";
764
+ StyleRuleType[StyleRuleType["Remove"] = 1] = "Remove";
765
+ StyleRuleType[StyleRuleType["Snapshot"] = 2] = "Snapshot";
766
+ StyleRuleType[StyleRuleType["SetProperty"] = 3] = "SetProperty";
767
+ StyleRuleType[StyleRuleType["RemoveProperty"] = 4] = "RemoveProperty";
768
+ })(StyleRuleType || (StyleRuleType = {}));
769
+ function getPositionsAndIndex(nestedIndex) {
770
+ const positions = [...nestedIndex];
771
+ const index = positions.pop();
772
+ return { positions, index };
773
+ }
774
+ function applyVirtualStyleRulesToNode(styleNode, virtualStyleRules) {
775
+ const sheet = styleNode.sheet;
776
+ virtualStyleRules.forEach((rule) => {
777
+ if (rule.type === StyleRuleType.Insert) {
778
+ try {
779
+ if (Array.isArray(rule.index)) {
780
+ const { positions, index } = getPositionsAndIndex(rule.index);
781
+ const nestedRule = getNestedRule(sheet.cssRules, positions);
782
+ nestedRule.insertRule(rule.cssText, index);
783
+ }
784
+ else {
785
+ sheet.insertRule(rule.cssText, rule.index);
786
+ }
787
+ }
788
+ catch (e) {
789
+ }
790
+ }
791
+ else if (rule.type === StyleRuleType.Remove) {
792
+ try {
793
+ if (Array.isArray(rule.index)) {
794
+ const { positions, index } = getPositionsAndIndex(rule.index);
795
+ const nestedRule = getNestedRule(sheet.cssRules, positions);
796
+ nestedRule.deleteRule(index || 0);
797
+ }
798
+ else {
799
+ sheet.deleteRule(rule.index);
800
+ }
801
+ }
802
+ catch (e) {
803
+ }
804
+ }
805
+ else if (rule.type === StyleRuleType.SetProperty) {
806
+ const nativeRule = getNestedRule(sheet.cssRules, rule.index);
807
+ nativeRule.style.setProperty(rule.property, rule.value, rule.priority);
808
+ }
809
+ else if (rule.type === StyleRuleType.RemoveProperty) {
810
+ const nativeRule = getNestedRule(sheet.cssRules, rule.index);
811
+ nativeRule.style.removeProperty(rule.property);
812
+ }
813
+ });
814
+ }
815
+
816
+ class RRDocument extends BaseRRDocumentImpl(BaseRRNode) {
817
+ constructor(mirror) {
818
+ super();
819
+ this._unserializedId = -1;
820
+ this.mirror = createMirror();
821
+ this.scrollData = null;
822
+ if (mirror) {
823
+ this.mirror = mirror;
824
+ }
825
+ }
826
+ get unserializedId() {
827
+ return this._unserializedId--;
828
+ }
829
+ createDocument(_namespace, _qualifiedName, _doctype) {
830
+ return new RRDocument();
831
+ }
832
+ createDocumentType(qualifiedName, publicId, systemId) {
833
+ const documentTypeNode = new RRDocumentType(qualifiedName, publicId, systemId);
834
+ documentTypeNode.ownerDocument = this;
835
+ return documentTypeNode;
836
+ }
837
+ createElement(tagName) {
838
+ const upperTagName = tagName.toUpperCase();
839
+ let element;
840
+ switch (upperTagName) {
841
+ case 'AUDIO':
842
+ case 'VIDEO':
843
+ element = new RRMediaElement(upperTagName);
844
+ break;
845
+ case 'IFRAME':
846
+ element = new RRIFrameElement(upperTagName, this.mirror);
847
+ break;
848
+ case 'CANVAS':
849
+ element = new RRCanvasElement(upperTagName);
850
+ break;
851
+ case 'STYLE':
852
+ element = new RRStyleElement(upperTagName);
853
+ break;
854
+ default:
855
+ element = new RRElement(upperTagName);
856
+ break;
857
+ }
858
+ element.ownerDocument = this;
859
+ return element;
860
+ }
861
+ createComment(data) {
862
+ const commentNode = new RRComment(data);
863
+ commentNode.ownerDocument = this;
864
+ return commentNode;
865
+ }
866
+ createCDATASection(data) {
867
+ const sectionNode = new RRCDATASection(data);
868
+ sectionNode.ownerDocument = this;
869
+ return sectionNode;
870
+ }
871
+ createTextNode(data) {
872
+ const textNode = new RRText(data);
873
+ textNode.ownerDocument = this;
874
+ return textNode;
875
+ }
876
+ destroyTree() {
877
+ this.childNodes = [];
878
+ this.mirror.reset();
879
+ }
880
+ open() {
881
+ super.open();
882
+ this._unserializedId = -1;
883
+ }
884
+ }
885
+ const RRDocumentType = BaseRRDocumentTypeImpl(BaseRRNode);
886
+ class RRElement extends BaseRRElementImpl(BaseRRNode) {
887
+ constructor() {
888
+ super(...arguments);
889
+ this.inputData = null;
890
+ this.scrollData = null;
891
+ }
892
+ }
893
+ class RRMediaElement extends BaseRRMediaElementImpl(RRElement) {
894
+ }
895
+ class RRCanvasElement extends RRElement {
896
+ constructor() {
897
+ super(...arguments);
898
+ this.canvasMutations = [];
899
+ }
900
+ getContext() {
901
+ return null;
902
+ }
903
+ }
904
+ class RRStyleElement extends RRElement {
905
+ constructor() {
906
+ super(...arguments);
907
+ this.rules = [];
908
+ }
909
+ }
910
+ class RRIFrameElement extends RRElement {
911
+ constructor(upperTagName, mirror) {
912
+ super(upperTagName);
913
+ this.contentDocument = new RRDocument();
914
+ this.contentDocument.mirror = mirror;
915
+ }
916
+ }
917
+ const RRText = BaseRRTextImpl(BaseRRNode);
918
+ const RRComment = BaseRRCommentImpl(BaseRRNode);
919
+ const RRCDATASection = BaseRRCDATASectionImpl(BaseRRNode);
920
+ function getValidTagName(element) {
921
+ if (element instanceof HTMLFormElement) {
922
+ return 'FORM';
923
+ }
924
+ return element.tagName.toUpperCase();
925
+ }
926
+ function buildFromNode(node, rrdom, domMirror, parentRRNode) {
927
+ let rrNode;
928
+ switch (node.nodeType) {
929
+ case NodeType.DOCUMENT_NODE:
930
+ if (parentRRNode && parentRRNode.nodeName === 'IFRAME')
931
+ rrNode = parentRRNode.contentDocument;
932
+ else {
933
+ rrNode = rrdom;
934
+ rrNode.compatMode = node.compatMode;
935
+ }
936
+ break;
937
+ case NodeType.DOCUMENT_TYPE_NODE:
938
+ const documentType = (node);
939
+ rrNode = rrdom.createDocumentType(documentType.name, documentType.publicId, documentType.systemId);
940
+ break;
941
+ case NodeType.ELEMENT_NODE:
942
+ const elementNode = (node);
943
+ const tagName = getValidTagName(elementNode);
944
+ rrNode = rrdom.createElement(tagName);
945
+ const rrElement = rrNode;
946
+ for (const { name, value } of Array.from(elementNode.attributes)) {
947
+ rrElement.attributes[name] = value;
948
+ }
949
+ elementNode.scrollLeft && (rrElement.scrollLeft = elementNode.scrollLeft);
950
+ elementNode.scrollTop && (rrElement.scrollTop = elementNode.scrollTop);
951
+ break;
952
+ case NodeType.TEXT_NODE:
953
+ rrNode = rrdom.createTextNode((node).textContent || '');
954
+ break;
955
+ case NodeType.CDATA_SECTION_NODE:
956
+ rrNode = rrdom.createCDATASection((node).data);
957
+ break;
958
+ case NodeType.COMMENT_NODE:
959
+ rrNode = rrdom.createComment((node).textContent || '');
960
+ break;
961
+ case NodeType.DOCUMENT_FRAGMENT_NODE:
962
+ rrNode = parentRRNode.attachShadow({ mode: 'open' });
963
+ break;
964
+ default:
965
+ return null;
966
+ }
967
+ let sn = domMirror.getMeta(node);
968
+ if (rrdom instanceof RRDocument) {
969
+ if (!sn) {
970
+ sn = getDefaultSN(rrNode, rrdom.unserializedId);
971
+ domMirror.add(node, sn);
972
+ }
973
+ rrdom.mirror.add(rrNode, Object.assign({}, sn));
974
+ }
975
+ return rrNode;
976
+ }
977
+ function buildFromDom(dom, domMirror = createMirror$1(), rrdom = new RRDocument()) {
978
+ function walk(node, parentRRNode) {
979
+ const rrNode = buildFromNode(node, rrdom, domMirror, parentRRNode);
980
+ if (rrNode === null)
981
+ return;
982
+ if ((parentRRNode === null || parentRRNode === void 0 ? void 0 : parentRRNode.nodeName) !== 'IFRAME' &&
983
+ node.nodeType !== NodeType.DOCUMENT_FRAGMENT_NODE) {
984
+ parentRRNode === null || parentRRNode === void 0 ? void 0 : parentRRNode.appendChild(rrNode);
985
+ rrNode.parentNode = parentRRNode;
986
+ rrNode.parentElement = parentRRNode;
987
+ }
988
+ if (node.nodeName === 'IFRAME') {
989
+ walk(node.contentDocument, rrNode);
990
+ }
991
+ else if (node.nodeType === NodeType.DOCUMENT_NODE ||
992
+ node.nodeType === NodeType.ELEMENT_NODE ||
993
+ node.nodeType === NodeType.DOCUMENT_FRAGMENT_NODE) {
994
+ if (node.nodeType === NodeType.ELEMENT_NODE &&
995
+ (node).shadowRoot)
996
+ walk((node).shadowRoot, rrNode);
997
+ node.childNodes.forEach((childNode) => walk(childNode, rrNode));
998
+ }
999
+ }
1000
+ walk(dom, null);
1001
+ return rrdom;
1002
+ }
1003
+ function createMirror() {
1004
+ return new Mirror();
1005
+ }
1006
+ class Mirror {
1007
+ constructor() {
1008
+ this.idNodeMap = new Map();
1009
+ this.nodeMetaMap = new WeakMap();
1010
+ }
1011
+ getId(n) {
1012
+ var _a;
1013
+ if (!n)
1014
+ return -1;
1015
+ const id = (_a = this.getMeta(n)) === null || _a === void 0 ? void 0 : _a.id;
1016
+ return id !== null && id !== void 0 ? id : -1;
1017
+ }
1018
+ getNode(id) {
1019
+ return this.idNodeMap.get(id) || null;
1020
+ }
1021
+ getIds() {
1022
+ return Array.from(this.idNodeMap.keys());
1023
+ }
1024
+ getMeta(n) {
1025
+ return this.nodeMetaMap.get(n) || null;
1026
+ }
1027
+ removeNodeFromMap(n) {
1028
+ const id = this.getId(n);
1029
+ this.idNodeMap.delete(id);
1030
+ if (n.childNodes) {
1031
+ n.childNodes.forEach((childNode) => this.removeNodeFromMap(childNode));
1032
+ }
1033
+ }
1034
+ has(id) {
1035
+ return this.idNodeMap.has(id);
1036
+ }
1037
+ hasNode(node) {
1038
+ return this.nodeMetaMap.has(node);
1039
+ }
1040
+ add(n, meta) {
1041
+ const id = meta.id;
1042
+ this.idNodeMap.set(id, n);
1043
+ this.nodeMetaMap.set(n, meta);
1044
+ }
1045
+ replace(id, n) {
1046
+ this.idNodeMap.set(id, n);
1047
+ }
1048
+ reset() {
1049
+ this.idNodeMap = new Map();
1050
+ this.nodeMetaMap = new WeakMap();
1051
+ }
1052
+ }
1053
+ function getDefaultSN(node, id) {
1054
+ switch (node.RRNodeType) {
1055
+ case NodeType$1.Document:
1056
+ return {
1057
+ id,
1058
+ type: node.RRNodeType,
1059
+ childNodes: [],
1060
+ };
1061
+ case NodeType$1.DocumentType:
1062
+ const doctype = node;
1063
+ return {
1064
+ id,
1065
+ type: node.RRNodeType,
1066
+ name: doctype.name,
1067
+ publicId: doctype.publicId,
1068
+ systemId: doctype.systemId,
1069
+ };
1070
+ case NodeType$1.Element:
1071
+ return {
1072
+ id,
1073
+ type: node.RRNodeType,
1074
+ tagName: node.tagName.toLowerCase(),
1075
+ attributes: {},
1076
+ childNodes: [],
1077
+ };
1078
+ case NodeType$1.Text:
1079
+ return {
1080
+ id,
1081
+ type: node.RRNodeType,
1082
+ textContent: node.textContent || '',
1083
+ };
1084
+ case NodeType$1.Comment:
1085
+ return {
1086
+ id,
1087
+ type: node.RRNodeType,
1088
+ textContent: node.textContent || '',
1089
+ };
1090
+ case NodeType$1.CDATA:
1091
+ return {
1092
+ id,
1093
+ type: node.RRNodeType,
1094
+ textContent: '',
1095
+ };
1096
+ }
1097
+ }
1098
+
1099
+ export { Mirror, RRCDATASection, RRCanvasElement, RRComment, RRDocument, RRDocumentType, RRElement, RRIFrameElement, RRMediaElement, BaseRRNode as RRNode, RRStyleElement, RRText, StyleRuleType, buildFromDom, buildFromNode, createMirror, createOrGetNode, diff, getDefaultSN };