@amplitude/rrweb-player 2.1.6 → 2.1.7

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.
@@ -14006,643 +14006,119 @@ var NodeType$1 = /* @__PURE__ */ ((NodeType2) => {
14006
14006
  NodeType2[NodeType2["Comment"] = 5] = "Comment";
14007
14007
  return NodeType2;
14008
14008
  })(NodeType$1 || {});
14009
- function parseCSSText(cssText) {
14010
- const res = {};
14011
- const listDelimiter = /;(?![^(]*\))/g;
14012
- const propertyDelimiter = /:(.+)/;
14013
- const comment2 = /\/\*.*?\*\//g;
14014
- cssText.replace(comment2, "").split(listDelimiter).forEach(function(item) {
14015
- if (item) {
14016
- const tmp = item.split(propertyDelimiter);
14017
- tmp.length > 1 && (res[camelize(tmp[0].trim())] = tmp[1].trim());
14018
- }
14019
- });
14020
- return res;
14021
- }
14022
- function toCSSText(style) {
14023
- const properties = [];
14024
- for (const name in style) {
14025
- const value = style[name];
14026
- if (typeof value !== "string") continue;
14027
- const normalizedName = hyphenate(name);
14028
- properties.push(`${normalizedName}: ${value};`);
14029
- }
14030
- return properties.join(" ");
14031
- }
14032
- const camelizeRE = /-([a-z])/g;
14033
- const CUSTOM_PROPERTY_REGEX = /^--[a-zA-Z0-9-]+$/;
14034
- const camelize = (str) => {
14035
- if (CUSTOM_PROPERTY_REGEX.test(str)) return str;
14036
- return str.replace(camelizeRE, (_, c2) => c2 ? c2.toUpperCase() : "");
14009
+ const NAMESPACES = {
14010
+ svg: "http://www.w3.org/2000/svg",
14011
+ "xlink:href": "http://www.w3.org/1999/xlink",
14012
+ xmlns: "http://www.w3.org/2000/xmlns/"
14037
14013
  };
14038
- const hyphenateRE = /\B([A-Z])/g;
14039
- const hyphenate = (str) => {
14040
- return str.replace(hyphenateRE, "-$1").toLowerCase();
14014
+ const SVGTagMap = {
14015
+ altglyph: "altGlyph",
14016
+ altglyphdef: "altGlyphDef",
14017
+ altglyphitem: "altGlyphItem",
14018
+ animatecolor: "animateColor",
14019
+ animatemotion: "animateMotion",
14020
+ animatetransform: "animateTransform",
14021
+ clippath: "clipPath",
14022
+ feblend: "feBlend",
14023
+ fecolormatrix: "feColorMatrix",
14024
+ fecomponenttransfer: "feComponentTransfer",
14025
+ fecomposite: "feComposite",
14026
+ feconvolvematrix: "feConvolveMatrix",
14027
+ fediffuselighting: "feDiffuseLighting",
14028
+ fedisplacementmap: "feDisplacementMap",
14029
+ fedistantlight: "feDistantLight",
14030
+ fedropshadow: "feDropShadow",
14031
+ feflood: "feFlood",
14032
+ fefunca: "feFuncA",
14033
+ fefuncb: "feFuncB",
14034
+ fefuncg: "feFuncG",
14035
+ fefuncr: "feFuncR",
14036
+ fegaussianblur: "feGaussianBlur",
14037
+ feimage: "feImage",
14038
+ femerge: "feMerge",
14039
+ femergenode: "feMergeNode",
14040
+ femorphology: "feMorphology",
14041
+ feoffset: "feOffset",
14042
+ fepointlight: "fePointLight",
14043
+ fespecularlighting: "feSpecularLighting",
14044
+ fespotlight: "feSpotLight",
14045
+ fetile: "feTile",
14046
+ feturbulence: "feTurbulence",
14047
+ foreignobject: "foreignObject",
14048
+ glyphref: "glyphRef",
14049
+ lineargradient: "linearGradient",
14050
+ radialgradient: "radialGradient"
14041
14051
  };
14042
- class BaseRRNode {
14043
- // eslint-disable-next-line @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any
14044
- constructor(..._args) {
14045
- __publicField22(this, "parentElement", null);
14046
- __publicField22(this, "parentNode", null);
14047
- __publicField22(this, "ownerDocument");
14048
- __publicField22(this, "firstChild", null);
14049
- __publicField22(this, "lastChild", null);
14050
- __publicField22(this, "previousSibling", null);
14051
- __publicField22(this, "nextSibling", null);
14052
- __publicField22(this, "ELEMENT_NODE", 1);
14053
- __publicField22(this, "TEXT_NODE", 3);
14054
- __publicField22(this, "nodeType");
14055
- __publicField22(this, "nodeName");
14056
- __publicField22(this, "RRNodeType");
14057
- }
14058
- get childNodes() {
14059
- const childNodes2 = [];
14060
- let childIterator = this.firstChild;
14061
- while (childIterator) {
14062
- childNodes2.push(childIterator);
14063
- childIterator = childIterator.nextSibling;
14064
- }
14065
- return childNodes2;
14066
- }
14067
- contains(node2) {
14068
- if (!(node2 instanceof BaseRRNode)) return false;
14069
- else if (node2.ownerDocument !== this.ownerDocument) return false;
14070
- else if (node2 === this) return true;
14071
- while (node2.parentNode) {
14072
- if (node2.parentNode === this) return true;
14073
- node2 = node2.parentNode;
14074
- }
14075
- return false;
14076
- }
14077
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
14078
- appendChild(_newChild) {
14079
- throw new Error(
14080
- `RRDomException: Failed to execute 'appendChild' on 'RRNode': This RRNode type does not support this method.`
14081
- );
14082
- }
14083
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
14084
- insertBefore(_newChild, _refChild) {
14085
- throw new Error(
14086
- `RRDomException: Failed to execute 'insertBefore' on 'RRNode': This RRNode type does not support this method.`
14087
- );
14088
- }
14089
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
14090
- removeChild(_node) {
14091
- throw new Error(
14092
- `RRDomException: Failed to execute 'removeChild' on 'RRNode': This RRNode type does not support this method.`
14093
- );
14094
- }
14095
- toString() {
14096
- return "RRNode";
14097
- }
14052
+ let createdNodeSet = null;
14053
+ function diff(oldTree, newTree, replayer, rrnodeMirror = newTree.mirror || newTree.ownerDocument.mirror) {
14054
+ oldTree = diffBeforeUpdatingChildren(
14055
+ oldTree,
14056
+ newTree,
14057
+ replayer,
14058
+ rrnodeMirror
14059
+ );
14060
+ diffChildren(oldTree, newTree, replayer, rrnodeMirror);
14061
+ diffAfterUpdatingChildren(oldTree, newTree, replayer);
14098
14062
  }
14099
- class BaseRRDocument extends BaseRRNode {
14100
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
14101
- constructor(...args) {
14102
- super(args);
14103
- __publicField22(this, "nodeType", 9);
14104
- __publicField22(this, "nodeName", "#document");
14105
- __publicField22(this, "compatMode", "CSS1Compat");
14106
- __publicField22(this, "RRNodeType", NodeType$1.Document);
14107
- __publicField22(this, "textContent", null);
14108
- this.ownerDocument = this;
14109
- }
14110
- get documentElement() {
14111
- return this.childNodes.find(
14112
- (node2) => node2.RRNodeType === NodeType$1.Element && node2.tagName === "HTML"
14113
- ) || null;
14114
- }
14115
- get body() {
14116
- var _a22;
14117
- return ((_a22 = this.documentElement) == null ? void 0 : _a22.childNodes.find(
14118
- (node2) => node2.RRNodeType === NodeType$1.Element && node2.tagName === "BODY"
14119
- )) || null;
14120
- }
14121
- get head() {
14122
- var _a22;
14123
- return ((_a22 = this.documentElement) == null ? void 0 : _a22.childNodes.find(
14124
- (node2) => node2.RRNodeType === NodeType$1.Element && node2.tagName === "HEAD"
14125
- )) || null;
14126
- }
14127
- get implementation() {
14128
- return this;
14063
+ function diffBeforeUpdatingChildren(oldTree, newTree, replayer, rrnodeMirror) {
14064
+ var _a22;
14065
+ if (replayer.afterAppend && !createdNodeSet) {
14066
+ createdNodeSet = /* @__PURE__ */ new WeakSet();
14067
+ setTimeout(() => {
14068
+ createdNodeSet = null;
14069
+ }, 0);
14129
14070
  }
14130
- get firstElementChild() {
14131
- return this.documentElement;
14071
+ if (!sameNodeType(oldTree, newTree)) {
14072
+ const calibratedOldTree = createOrGetNode(
14073
+ newTree,
14074
+ replayer.mirror,
14075
+ rrnodeMirror
14076
+ );
14077
+ (_a22 = oldTree.parentNode) == null ? void 0 : _a22.replaceChild(calibratedOldTree, oldTree);
14078
+ oldTree = calibratedOldTree;
14132
14079
  }
14133
- appendChild(newChild) {
14134
- const nodeType = newChild.RRNodeType;
14135
- if (nodeType === NodeType$1.Element || nodeType === NodeType$1.DocumentType) {
14136
- if (this.childNodes.some((s2) => s2.RRNodeType === nodeType)) {
14137
- throw new Error(
14138
- `RRDomException: Failed to execute 'appendChild' on 'RRNode': Only one ${nodeType === NodeType$1.Element ? "RRElement" : "RRDoctype"} on RRDocument allowed.`
14139
- );
14080
+ switch (newTree.RRNodeType) {
14081
+ case NodeType$1.Document: {
14082
+ if (!nodeMatching(oldTree, newTree, replayer.mirror, rrnodeMirror)) {
14083
+ const newMeta = rrnodeMirror.getMeta(newTree);
14084
+ if (newMeta) {
14085
+ replayer.mirror.removeNodeFromMap(oldTree);
14086
+ oldTree.close();
14087
+ oldTree.open();
14088
+ replayer.mirror.add(oldTree, newMeta);
14089
+ createdNodeSet == null ? void 0 : createdNodeSet.add(oldTree);
14090
+ }
14140
14091
  }
14092
+ break;
14141
14093
  }
14142
- const child2 = appendChild(this, newChild);
14143
- child2.parentElement = null;
14144
- return child2;
14145
- }
14146
- insertBefore(newChild, refChild) {
14147
- const nodeType = newChild.RRNodeType;
14148
- if (nodeType === NodeType$1.Element || nodeType === NodeType$1.DocumentType) {
14149
- if (this.childNodes.some((s2) => s2.RRNodeType === nodeType)) {
14150
- throw new Error(
14151
- `RRDomException: Failed to execute 'insertBefore' on 'RRNode': Only one ${nodeType === NodeType$1.Element ? "RRElement" : "RRDoctype"} on RRDocument allowed.`
14094
+ case NodeType$1.Element: {
14095
+ const oldElement = oldTree;
14096
+ const newRRElement = newTree;
14097
+ switch (newRRElement.tagName) {
14098
+ case "IFRAME": {
14099
+ const oldContentDocument = oldTree.contentDocument;
14100
+ if (!oldContentDocument) break;
14101
+ diff(
14102
+ oldContentDocument,
14103
+ newTree.contentDocument,
14104
+ replayer,
14105
+ rrnodeMirror
14106
+ );
14107
+ break;
14108
+ }
14109
+ }
14110
+ if (newRRElement.shadowRoot) {
14111
+ if (!oldElement.shadowRoot) oldElement.attachShadow({ mode: "open" });
14112
+ diffChildren(
14113
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
14114
+ oldElement.shadowRoot,
14115
+ newRRElement.shadowRoot,
14116
+ replayer,
14117
+ rrnodeMirror
14152
14118
  );
14153
14119
  }
14154
- }
14155
- const child2 = insertBefore(this, newChild, refChild);
14156
- child2.parentElement = null;
14157
- return child2;
14158
- }
14159
- removeChild(node2) {
14160
- return removeChild(this, node2);
14161
- }
14162
- open() {
14163
- this.firstChild = null;
14164
- this.lastChild = null;
14165
- }
14166
- close() {
14167
- }
14168
- /**
14169
- * Adhoc implementation for setting xhtml namespace in rebuilt.ts (rrweb-snapshot).
14170
- * There are two lines used this function:
14171
- * 1. doc.write('\<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" ""\>')
14172
- * 2. doc.write('\<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" ""\>')
14173
- */
14174
- write(content) {
14175
- let publicId;
14176
- if (content === '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">')
14177
- publicId = "-//W3C//DTD XHTML 1.0 Transitional//EN";
14178
- else if (content === '<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "">')
14179
- publicId = "-//W3C//DTD HTML 4.0 Transitional//EN";
14180
- if (publicId) {
14181
- const doctype = this.createDocumentType("html", publicId, "");
14182
- this.open();
14183
- this.appendChild(doctype);
14184
- }
14185
- }
14186
- createDocument(_namespace, _qualifiedName, _doctype) {
14187
- return new BaseRRDocument();
14188
- }
14189
- createDocumentType(qualifiedName, publicId, systemId) {
14190
- const doctype = new BaseRRDocumentType(qualifiedName, publicId, systemId);
14191
- doctype.ownerDocument = this;
14192
- return doctype;
14193
- }
14194
- createElement(tagName) {
14195
- const element = new BaseRRElement(tagName);
14196
- element.ownerDocument = this;
14197
- return element;
14198
- }
14199
- createElementNS(_namespaceURI, qualifiedName) {
14200
- return this.createElement(qualifiedName);
14201
- }
14202
- createTextNode(data) {
14203
- const text = new BaseRRText(data);
14204
- text.ownerDocument = this;
14205
- return text;
14206
- }
14207
- createComment(data) {
14208
- const comment2 = new BaseRRComment(data);
14209
- comment2.ownerDocument = this;
14210
- return comment2;
14211
- }
14212
- createCDATASection(data) {
14213
- const CDATASection = new BaseRRCDATASection(data);
14214
- CDATASection.ownerDocument = this;
14215
- return CDATASection;
14216
- }
14217
- toString() {
14218
- return "RRDocument";
14219
- }
14220
- }
14221
- class BaseRRDocumentType extends BaseRRNode {
14222
- constructor(qualifiedName, publicId, systemId) {
14223
- super();
14224
- __publicField22(this, "nodeType", 10);
14225
- __publicField22(this, "RRNodeType", NodeType$1.DocumentType);
14226
- __publicField22(this, "name");
14227
- __publicField22(this, "publicId");
14228
- __publicField22(this, "systemId");
14229
- __publicField22(this, "textContent", null);
14230
- this.name = qualifiedName;
14231
- this.publicId = publicId;
14232
- this.systemId = systemId;
14233
- this.nodeName = qualifiedName;
14234
- }
14235
- toString() {
14236
- return "RRDocumentType";
14237
- }
14238
- }
14239
- class BaseRRElement extends BaseRRNode {
14240
- constructor(tagName) {
14241
- super();
14242
- __publicField22(this, "nodeType", 1);
14243
- __publicField22(this, "RRNodeType", NodeType$1.Element);
14244
- __publicField22(this, "tagName");
14245
- __publicField22(this, "attributes", {});
14246
- __publicField22(this, "shadowRoot", null);
14247
- __publicField22(this, "scrollLeft");
14248
- __publicField22(this, "scrollTop");
14249
- this.tagName = tagName.toUpperCase();
14250
- this.nodeName = tagName.toUpperCase();
14251
- }
14252
- get textContent() {
14253
- let result2 = "";
14254
- this.childNodes.forEach((node2) => result2 += node2.textContent);
14255
- return result2;
14256
- }
14257
- set textContent(textContent2) {
14258
- this.firstChild = null;
14259
- this.lastChild = null;
14260
- this.appendChild(this.ownerDocument.createTextNode(textContent2));
14261
- }
14262
- get classList() {
14263
- return new ClassList(
14264
- this.attributes.class,
14265
- (newClassName) => {
14266
- this.attributes.class = newClassName;
14267
- }
14268
- );
14269
- }
14270
- get id() {
14271
- return this.attributes.id || "";
14272
- }
14273
- get className() {
14274
- return this.attributes.class || "";
14275
- }
14276
- get style() {
14277
- const style = this.attributes.style ? parseCSSText(this.attributes.style) : {};
14278
- const hyphenateRE2 = /\B([A-Z])/g;
14279
- style.setProperty = (name, value, priority) => {
14280
- if (hyphenateRE2.test(name)) return;
14281
- const normalizedName = camelize(name);
14282
- if (!value) delete style[normalizedName];
14283
- else style[normalizedName] = value;
14284
- if (priority === "important") style[normalizedName] += " !important";
14285
- this.attributes.style = toCSSText(style);
14286
- };
14287
- style.removeProperty = (name) => {
14288
- if (hyphenateRE2.test(name)) return "";
14289
- const normalizedName = camelize(name);
14290
- const value = style[normalizedName] || "";
14291
- delete style[normalizedName];
14292
- this.attributes.style = toCSSText(style);
14293
- return value;
14294
- };
14295
- return style;
14296
- }
14297
- getAttribute(name) {
14298
- if (this.attributes[name] === void 0) return null;
14299
- return this.attributes[name];
14300
- }
14301
- setAttribute(name, attribute) {
14302
- this.attributes[name] = attribute;
14303
- }
14304
- setAttributeNS(_namespace, qualifiedName, value) {
14305
- this.setAttribute(qualifiedName, value);
14306
- }
14307
- removeAttribute(name) {
14308
- delete this.attributes[name];
14309
- }
14310
- appendChild(newChild) {
14311
- return appendChild(this, newChild);
14312
- }
14313
- insertBefore(newChild, refChild) {
14314
- return insertBefore(this, newChild, refChild);
14315
- }
14316
- removeChild(node2) {
14317
- return removeChild(this, node2);
14318
- }
14319
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
14320
- attachShadow(_init) {
14321
- const shadowRoot2 = this.ownerDocument.createElement("SHADOWROOT");
14322
- this.shadowRoot = shadowRoot2;
14323
- return shadowRoot2;
14324
- }
14325
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
14326
- dispatchEvent(_event) {
14327
- return true;
14328
- }
14329
- toString() {
14330
- let attributeString = "";
14331
- for (const attribute in this.attributes) {
14332
- attributeString += `${attribute}="${this.attributes[attribute]}" `;
14333
- }
14334
- return `${this.tagName} ${attributeString}`;
14335
- }
14336
- }
14337
- class BaseRRMediaElement extends BaseRRElement {
14338
- constructor() {
14339
- super(...arguments);
14340
- __publicField22(this, "currentTime");
14341
- __publicField22(this, "volume");
14342
- __publicField22(this, "paused");
14343
- __publicField22(this, "muted");
14344
- __publicField22(this, "playbackRate");
14345
- __publicField22(this, "loop");
14346
- }
14347
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
14348
- attachShadow(_init) {
14349
- throw new Error(
14350
- `RRDomException: Failed to execute 'attachShadow' on 'RRElement': This RRElement does not support attachShadow`
14351
- );
14352
- }
14353
- play() {
14354
- this.paused = false;
14355
- }
14356
- pause() {
14357
- this.paused = true;
14358
- }
14359
- }
14360
- class BaseRRDialogElement extends BaseRRElement {
14361
- constructor() {
14362
- super(...arguments);
14363
- __publicField22(this, "tagName", "DIALOG");
14364
- __publicField22(this, "nodeName", "DIALOG");
14365
- }
14366
- get isModal() {
14367
- return this.getAttribute("rr_open_mode") === "modal";
14368
- }
14369
- get open() {
14370
- return this.getAttribute("open") !== null;
14371
- }
14372
- close() {
14373
- this.removeAttribute("open");
14374
- this.removeAttribute("rr_open_mode");
14375
- }
14376
- show() {
14377
- this.setAttribute("open", "");
14378
- this.setAttribute("rr_open_mode", "non-modal");
14379
- }
14380
- showModal() {
14381
- this.setAttribute("open", "");
14382
- this.setAttribute("rr_open_mode", "modal");
14383
- }
14384
- }
14385
- class BaseRRText extends BaseRRNode {
14386
- constructor(data) {
14387
- super();
14388
- __publicField22(this, "nodeType", 3);
14389
- __publicField22(this, "nodeName", "#text");
14390
- __publicField22(this, "RRNodeType", NodeType$1.Text);
14391
- __publicField22(this, "data");
14392
- this.data = data;
14393
- }
14394
- get textContent() {
14395
- return this.data;
14396
- }
14397
- set textContent(textContent2) {
14398
- this.data = textContent2;
14399
- }
14400
- toString() {
14401
- return `RRText text=${JSON.stringify(this.data)}`;
14402
- }
14403
- }
14404
- class BaseRRComment extends BaseRRNode {
14405
- constructor(data) {
14406
- super();
14407
- __publicField22(this, "nodeType", 8);
14408
- __publicField22(this, "nodeName", "#comment");
14409
- __publicField22(this, "RRNodeType", NodeType$1.Comment);
14410
- __publicField22(this, "data");
14411
- this.data = data;
14412
- }
14413
- get textContent() {
14414
- return this.data;
14415
- }
14416
- set textContent(textContent2) {
14417
- this.data = textContent2;
14418
- }
14419
- toString() {
14420
- return `RRComment text=${JSON.stringify(this.data)}`;
14421
- }
14422
- }
14423
- class BaseRRCDATASection extends BaseRRNode {
14424
- constructor(data) {
14425
- super();
14426
- __publicField22(this, "nodeName", "#cdata-section");
14427
- __publicField22(this, "nodeType", 4);
14428
- __publicField22(this, "RRNodeType", NodeType$1.CDATA);
14429
- __publicField22(this, "data");
14430
- this.data = data;
14431
- }
14432
- get textContent() {
14433
- return this.data;
14434
- }
14435
- set textContent(textContent2) {
14436
- this.data = textContent2;
14437
- }
14438
- toString() {
14439
- return `RRCDATASection data=${JSON.stringify(this.data)}`;
14440
- }
14441
- }
14442
- class ClassList {
14443
- constructor(classText, onChange) {
14444
- __publicField22(this, "onChange");
14445
- __publicField22(this, "classes", []);
14446
- __publicField22(this, "add", (...classNames) => {
14447
- for (const item of classNames) {
14448
- const className = String(item);
14449
- if (this.classes.indexOf(className) >= 0) continue;
14450
- this.classes.push(className);
14451
- }
14452
- this.onChange && this.onChange(this.classes.join(" "));
14453
- });
14454
- __publicField22(this, "remove", (...classNames) => {
14455
- this.classes = this.classes.filter(
14456
- (item) => classNames.indexOf(item) === -1
14457
- );
14458
- this.onChange && this.onChange(this.classes.join(" "));
14459
- });
14460
- if (classText) {
14461
- const classes = classText.trim().split(/\s+/);
14462
- this.classes.push(...classes);
14463
- }
14464
- this.onChange = onChange;
14465
- }
14466
- }
14467
- function appendChild(parent, newChild) {
14468
- if (newChild.parentNode) newChild.parentNode.removeChild(newChild);
14469
- if (parent.lastChild) {
14470
- parent.lastChild.nextSibling = newChild;
14471
- newChild.previousSibling = parent.lastChild;
14472
- } else {
14473
- parent.firstChild = newChild;
14474
- newChild.previousSibling = null;
14475
- }
14476
- parent.lastChild = newChild;
14477
- newChild.nextSibling = null;
14478
- newChild.parentNode = parent;
14479
- newChild.parentElement = parent;
14480
- newChild.ownerDocument = parent.ownerDocument;
14481
- return newChild;
14482
- }
14483
- function insertBefore(parent, newChild, refChild) {
14484
- if (!refChild) return appendChild(parent, newChild);
14485
- if (refChild.parentNode !== parent)
14486
- throw new Error(
14487
- "Failed to execute 'insertBefore' on 'RRNode': The RRNode before which the new node is to be inserted is not a child of this RRNode."
14488
- );
14489
- if (newChild === refChild) return newChild;
14490
- if (newChild.parentNode) newChild.parentNode.removeChild(newChild);
14491
- newChild.previousSibling = refChild.previousSibling;
14492
- refChild.previousSibling = newChild;
14493
- newChild.nextSibling = refChild;
14494
- if (newChild.previousSibling) newChild.previousSibling.nextSibling = newChild;
14495
- else parent.firstChild = newChild;
14496
- newChild.parentElement = parent;
14497
- newChild.parentNode = parent;
14498
- newChild.ownerDocument = parent.ownerDocument;
14499
- return newChild;
14500
- }
14501
- function removeChild(parent, child2) {
14502
- if (child2.parentNode !== parent)
14503
- throw new Error(
14504
- "Failed to execute 'removeChild' on 'RRNode': The RRNode to be removed is not a child of this RRNode."
14505
- );
14506
- if (child2.previousSibling)
14507
- child2.previousSibling.nextSibling = child2.nextSibling;
14508
- else parent.firstChild = child2.nextSibling;
14509
- if (child2.nextSibling)
14510
- child2.nextSibling.previousSibling = child2.previousSibling;
14511
- else parent.lastChild = child2.previousSibling;
14512
- child2.previousSibling = null;
14513
- child2.nextSibling = null;
14514
- child2.parentElement = null;
14515
- child2.parentNode = null;
14516
- return child2;
14517
- }
14518
- var NodeType$2 = /* @__PURE__ */ ((NodeType2) => {
14519
- NodeType2[NodeType2["PLACEHOLDER"] = 0] = "PLACEHOLDER";
14520
- NodeType2[NodeType2["ELEMENT_NODE"] = 1] = "ELEMENT_NODE";
14521
- NodeType2[NodeType2["ATTRIBUTE_NODE"] = 2] = "ATTRIBUTE_NODE";
14522
- NodeType2[NodeType2["TEXT_NODE"] = 3] = "TEXT_NODE";
14523
- NodeType2[NodeType2["CDATA_SECTION_NODE"] = 4] = "CDATA_SECTION_NODE";
14524
- NodeType2[NodeType2["ENTITY_REFERENCE_NODE"] = 5] = "ENTITY_REFERENCE_NODE";
14525
- NodeType2[NodeType2["ENTITY_NODE"] = 6] = "ENTITY_NODE";
14526
- NodeType2[NodeType2["PROCESSING_INSTRUCTION_NODE"] = 7] = "PROCESSING_INSTRUCTION_NODE";
14527
- NodeType2[NodeType2["COMMENT_NODE"] = 8] = "COMMENT_NODE";
14528
- NodeType2[NodeType2["DOCUMENT_NODE"] = 9] = "DOCUMENT_NODE";
14529
- NodeType2[NodeType2["DOCUMENT_TYPE_NODE"] = 10] = "DOCUMENT_TYPE_NODE";
14530
- NodeType2[NodeType2["DOCUMENT_FRAGMENT_NODE"] = 11] = "DOCUMENT_FRAGMENT_NODE";
14531
- return NodeType2;
14532
- })(NodeType$2 || {});
14533
- const NAMESPACES = {
14534
- svg: "http://www.w3.org/2000/svg",
14535
- "xlink:href": "http://www.w3.org/1999/xlink",
14536
- xmlns: "http://www.w3.org/2000/xmlns/"
14537
- };
14538
- const SVGTagMap = {
14539
- altglyph: "altGlyph",
14540
- altglyphdef: "altGlyphDef",
14541
- altglyphitem: "altGlyphItem",
14542
- animatecolor: "animateColor",
14543
- animatemotion: "animateMotion",
14544
- animatetransform: "animateTransform",
14545
- clippath: "clipPath",
14546
- feblend: "feBlend",
14547
- fecolormatrix: "feColorMatrix",
14548
- fecomponenttransfer: "feComponentTransfer",
14549
- fecomposite: "feComposite",
14550
- feconvolvematrix: "feConvolveMatrix",
14551
- fediffuselighting: "feDiffuseLighting",
14552
- fedisplacementmap: "feDisplacementMap",
14553
- fedistantlight: "feDistantLight",
14554
- fedropshadow: "feDropShadow",
14555
- feflood: "feFlood",
14556
- fefunca: "feFuncA",
14557
- fefuncb: "feFuncB",
14558
- fefuncg: "feFuncG",
14559
- fefuncr: "feFuncR",
14560
- fegaussianblur: "feGaussianBlur",
14561
- feimage: "feImage",
14562
- femerge: "feMerge",
14563
- femergenode: "feMergeNode",
14564
- femorphology: "feMorphology",
14565
- feoffset: "feOffset",
14566
- fepointlight: "fePointLight",
14567
- fespecularlighting: "feSpecularLighting",
14568
- fespotlight: "feSpotLight",
14569
- fetile: "feTile",
14570
- feturbulence: "feTurbulence",
14571
- foreignobject: "foreignObject",
14572
- glyphref: "glyphRef",
14573
- lineargradient: "linearGradient",
14574
- radialgradient: "radialGradient"
14575
- };
14576
- let createdNodeSet = null;
14577
- function diff(oldTree, newTree, replayer, rrnodeMirror = newTree.mirror || newTree.ownerDocument.mirror) {
14578
- oldTree = diffBeforeUpdatingChildren(
14579
- oldTree,
14580
- newTree,
14581
- replayer,
14582
- rrnodeMirror
14583
- );
14584
- diffChildren(oldTree, newTree, replayer, rrnodeMirror);
14585
- diffAfterUpdatingChildren(oldTree, newTree, replayer);
14586
- }
14587
- function diffBeforeUpdatingChildren(oldTree, newTree, replayer, rrnodeMirror) {
14588
- var _a22;
14589
- if (replayer.afterAppend && !createdNodeSet) {
14590
- createdNodeSet = /* @__PURE__ */ new WeakSet();
14591
- setTimeout(() => {
14592
- createdNodeSet = null;
14593
- }, 0);
14594
- }
14595
- if (!sameNodeType(oldTree, newTree)) {
14596
- const calibratedOldTree = createOrGetNode(
14597
- newTree,
14598
- replayer.mirror,
14599
- rrnodeMirror
14600
- );
14601
- (_a22 = oldTree.parentNode) == null ? void 0 : _a22.replaceChild(calibratedOldTree, oldTree);
14602
- oldTree = calibratedOldTree;
14603
- }
14604
- switch (newTree.RRNodeType) {
14605
- case NodeType$1.Document: {
14606
- if (!nodeMatching(oldTree, newTree, replayer.mirror, rrnodeMirror)) {
14607
- const newMeta = rrnodeMirror.getMeta(newTree);
14608
- if (newMeta) {
14609
- replayer.mirror.removeNodeFromMap(oldTree);
14610
- oldTree.close();
14611
- oldTree.open();
14612
- replayer.mirror.add(oldTree, newMeta);
14613
- createdNodeSet == null ? void 0 : createdNodeSet.add(oldTree);
14614
- }
14615
- }
14616
- break;
14617
- }
14618
- case NodeType$1.Element: {
14619
- const oldElement = oldTree;
14620
- const newRRElement = newTree;
14621
- switch (newRRElement.tagName) {
14622
- case "IFRAME": {
14623
- const oldContentDocument = oldTree.contentDocument;
14624
- if (!oldContentDocument) break;
14625
- diff(
14626
- oldContentDocument,
14627
- newTree.contentDocument,
14628
- replayer,
14629
- rrnodeMirror
14630
- );
14631
- break;
14632
- }
14633
- }
14634
- if (newRRElement.shadowRoot) {
14635
- if (!oldElement.shadowRoot) oldElement.attachShadow({ mode: "open" });
14636
- diffChildren(
14637
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
14638
- oldElement.shadowRoot,
14639
- newRRElement.shadowRoot,
14640
- replayer,
14641
- rrnodeMirror
14642
- );
14643
- }
14644
- diffProps(oldElement, newRRElement, rrnodeMirror);
14645
- break;
14120
+ diffProps(oldElement, newRRElement, rrnodeMirror);
14121
+ break;
14646
14122
  }
14647
14123
  }
14648
14124
  return oldTree;
@@ -14804,7 +14280,13 @@ function diffChildren(oldTree, newTree, replayer, rrnodeMirror) {
14804
14280
  nodeMatching(oldStartNode, newEndNode, replayer.mirror, rrnodeMirror)
14805
14281
  ) {
14806
14282
  try {
14807
- oldTree.insertBefore(oldStartNode, oldEndNode.nextSibling);
14283
+ insertPreservingCSSOM(
14284
+ oldTree,
14285
+ oldStartNode,
14286
+ oldEndNode.nextSibling,
14287
+ replayer.mirror,
14288
+ rrnodeMirror
14289
+ );
14808
14290
  } catch (e2) {
14809
14291
  console.warn(e2);
14810
14292
  }
@@ -14815,7 +14297,13 @@ function diffChildren(oldTree, newTree, replayer, rrnodeMirror) {
14815
14297
  nodeMatching(oldEndNode, newStartNode, replayer.mirror, rrnodeMirror)
14816
14298
  ) {
14817
14299
  try {
14818
- oldTree.insertBefore(oldEndNode, oldStartNode);
14300
+ insertPreservingCSSOM(
14301
+ oldTree,
14302
+ oldEndNode,
14303
+ oldStartNode,
14304
+ replayer.mirror,
14305
+ rrnodeMirror
14306
+ );
14819
14307
  } catch (e2) {
14820
14308
  console.warn(e2);
14821
14309
  }
@@ -14834,7 +14322,13 @@ function diffChildren(oldTree, newTree, replayer, rrnodeMirror) {
14834
14322
  const nodeToMove = oldChildren[indexInOld];
14835
14323
  if (indexInOld !== void 0 && nodeToMove && nodeMatching(nodeToMove, newStartNode, replayer.mirror, rrnodeMirror)) {
14836
14324
  try {
14837
- oldTree.insertBefore(nodeToMove, oldStartNode);
14325
+ insertPreservingCSSOM(
14326
+ oldTree,
14327
+ nodeToMove,
14328
+ oldStartNode,
14329
+ replayer.mirror,
14330
+ rrnodeMirror
14331
+ );
14838
14332
  } catch (e2) {
14839
14333
  console.warn(e2);
14840
14334
  }
@@ -14845,119 +14339,709 @@ function diffChildren(oldTree, newTree, replayer, rrnodeMirror) {
14845
14339
  replayer.mirror,
14846
14340
  rrnodeMirror
14847
14341
  );
14848
- if (oldTree.nodeName === "#document" && oldStartNode && /**
14849
- * Special case 1: one document isn't allowed to have two doctype nodes at the same time, so we need to remove the old one first before inserting the new one.
14850
- * How this case happens: A parent document in the old tree already has a doctype node with an id e.g. #1. A new full snapshot rebuilds the replayer with a new doctype node with another id #2. According to the algorithm, the new doctype node will be inserted before the old one, which is not allowed by the Document standard.
14851
- */
14852
- (newNode.nodeType === newNode.DOCUMENT_TYPE_NODE && oldStartNode.nodeType === oldStartNode.DOCUMENT_TYPE_NODE || /**
14853
- * Special case 2: one document isn't allowed to have two HTMLElements at the same time, so we need to remove the old one first before inserting the new one.
14854
- * How this case happens: A mounted iframe element has an automatically created HTML element. We should delete it before inserting a serialized one. Otherwise, an error 'Only one element on document allowed' will be thrown.
14855
- */
14856
- newNode.nodeType === newNode.ELEMENT_NODE && oldStartNode.nodeType === oldStartNode.ELEMENT_NODE)) {
14857
- oldTree.removeChild(oldStartNode);
14858
- replayer.mirror.removeNodeFromMap(oldStartNode);
14859
- oldStartNode = oldChildren[++oldStartIndex];
14860
- }
14861
- try {
14862
- oldTree.insertBefore(newNode, oldStartNode || null);
14863
- } catch (e2) {
14864
- console.warn(e2);
14865
- }
14342
+ if (oldTree.nodeName === "#document" && oldStartNode && /**
14343
+ * Special case 1: one document isn't allowed to have two doctype nodes at the same time, so we need to remove the old one first before inserting the new one.
14344
+ * How this case happens: A parent document in the old tree already has a doctype node with an id e.g. #1. A new full snapshot rebuilds the replayer with a new doctype node with another id #2. According to the algorithm, the new doctype node will be inserted before the old one, which is not allowed by the Document standard.
14345
+ */
14346
+ (newNode.nodeType === newNode.DOCUMENT_TYPE_NODE && oldStartNode.nodeType === oldStartNode.DOCUMENT_TYPE_NODE || /**
14347
+ * Special case 2: one document isn't allowed to have two HTMLElements at the same time, so we need to remove the old one first before inserting the new one.
14348
+ * How this case happens: A mounted iframe element has an automatically created HTML element. We should delete it before inserting a serialized one. Otherwise, an error 'Only one element on document allowed' will be thrown.
14349
+ */
14350
+ newNode.nodeType === newNode.ELEMENT_NODE && oldStartNode.nodeType === oldStartNode.ELEMENT_NODE)) {
14351
+ oldTree.removeChild(oldStartNode);
14352
+ replayer.mirror.removeNodeFromMap(oldStartNode);
14353
+ oldStartNode = oldChildren[++oldStartIndex];
14354
+ }
14355
+ try {
14356
+ insertPreservingCSSOM(
14357
+ oldTree,
14358
+ newNode,
14359
+ oldStartNode || null,
14360
+ replayer.mirror,
14361
+ rrnodeMirror
14362
+ );
14363
+ } catch (e2) {
14364
+ console.warn(e2);
14365
+ }
14366
+ }
14367
+ newStartNode = newChildren[++newStartIndex];
14368
+ }
14369
+ }
14370
+ if (oldStartIndex > oldEndIndex) {
14371
+ const referenceRRNode = newChildren[newEndIndex + 1];
14372
+ let referenceNode = null;
14373
+ if (referenceRRNode)
14374
+ referenceNode = replayer.mirror.getNode(
14375
+ rrnodeMirror.getId(referenceRRNode)
14376
+ );
14377
+ for (; newStartIndex <= newEndIndex; ++newStartIndex) {
14378
+ const newNode = createOrGetNode(
14379
+ newChildren[newStartIndex],
14380
+ replayer.mirror,
14381
+ rrnodeMirror
14382
+ );
14383
+ try {
14384
+ insertPreservingCSSOM(
14385
+ oldTree,
14386
+ newNode,
14387
+ referenceNode,
14388
+ replayer.mirror,
14389
+ rrnodeMirror
14390
+ );
14391
+ } catch (e2) {
14392
+ console.warn(e2);
14393
+ }
14394
+ }
14395
+ } else if (newStartIndex > newEndIndex) {
14396
+ for (; oldStartIndex <= oldEndIndex; oldStartIndex++) {
14397
+ const node2 = oldChildren[oldStartIndex];
14398
+ if (!node2 || node2.parentNode !== oldTree) continue;
14399
+ try {
14400
+ oldTree.removeChild(node2);
14401
+ replayer.mirror.removeNodeFromMap(node2);
14402
+ } catch (e2) {
14403
+ console.warn(e2);
14404
+ }
14405
+ }
14406
+ }
14407
+ let oldChild = oldTree.firstChild;
14408
+ let newChild = newTree.firstChild;
14409
+ while (oldChild !== null && newChild !== null) {
14410
+ diff(oldChild, newChild, replayer, rrnodeMirror);
14411
+ oldChild = oldChild.nextSibling;
14412
+ newChild = newChild.nextSibling;
14413
+ }
14414
+ }
14415
+ const nodesBuiltFromDom = /* @__PURE__ */ new WeakSet();
14416
+ function insertPreservingCSSOM(parent, node2, referenceNode, domMirror, rrnodeMirror) {
14417
+ const saved = node2.isConnected ? collectStyleRules(node2).filter(([styleElement]) => {
14418
+ const rrNode = rrnodeMirror.getNode(domMirror.getId(styleElement));
14419
+ return rrNode !== null && nodesBuiltFromDom.has(rrNode);
14420
+ }) : [];
14421
+ parent.insertBefore(node2, referenceNode);
14422
+ for (const [styleElement, rules2] of saved)
14423
+ restoreStyleRules(styleElement, rules2);
14424
+ }
14425
+ function collectStyleRules(node2) {
14426
+ if (node2.nodeType !== node2.ELEMENT_NODE) return [];
14427
+ const styleElements = [];
14428
+ const collect = (element) => {
14429
+ if (element.localName === "style")
14430
+ styleElements.push(element);
14431
+ if (element.shadowRoot)
14432
+ for (const child2 of Array.from(element.shadowRoot.children))
14433
+ collect(child2);
14434
+ for (const child2 of Array.from(element.children)) collect(child2);
14435
+ };
14436
+ collect(node2);
14437
+ const saved = [];
14438
+ for (const styleElement of styleElements) {
14439
+ try {
14440
+ const sheet = styleElement.sheet;
14441
+ if (sheet)
14442
+ saved.push([
14443
+ styleElement,
14444
+ Array.from(sheet.cssRules, (rule2) => rule2.cssText)
14445
+ ]);
14446
+ } catch (e2) {
14447
+ }
14448
+ }
14449
+ return saved;
14450
+ }
14451
+ function restoreStyleRules(styleElement, rules2) {
14452
+ try {
14453
+ const sheet = styleElement.sheet;
14454
+ if (!sheet) return;
14455
+ const current = sheet.cssRules;
14456
+ if (current.length === rules2.length && rules2.every((rule2, i2) => current[i2].cssText === rule2))
14457
+ return;
14458
+ while (sheet.cssRules.length > 0)
14459
+ sheet.deleteRule(sheet.cssRules.length - 1);
14460
+ for (const rule2 of rules2) {
14461
+ try {
14462
+ sheet.insertRule(rule2, sheet.cssRules.length);
14463
+ } catch (e2) {
14464
+ }
14465
+ }
14466
+ } catch (e2) {
14467
+ }
14468
+ }
14469
+ function createOrGetNode(rrNode, domMirror, rrnodeMirror) {
14470
+ const nodeId = rrnodeMirror.getId(rrNode);
14471
+ const sn = rrnodeMirror.getMeta(rrNode);
14472
+ let node2 = null;
14473
+ if (nodeId > -1) node2 = domMirror.getNode(nodeId);
14474
+ if (node2 !== null && sameNodeType(node2, rrNode)) return node2;
14475
+ switch (rrNode.RRNodeType) {
14476
+ case NodeType$1.Document:
14477
+ node2 = new Document();
14478
+ break;
14479
+ case NodeType$1.DocumentType:
14480
+ node2 = document.implementation.createDocumentType(
14481
+ rrNode.name,
14482
+ rrNode.publicId,
14483
+ rrNode.systemId
14484
+ );
14485
+ break;
14486
+ case NodeType$1.Element: {
14487
+ let tagName = rrNode.tagName.toLowerCase();
14488
+ tagName = SVGTagMap[tagName] || tagName;
14489
+ if (sn && "isSVG" in sn && (sn == null ? void 0 : sn.isSVG)) {
14490
+ node2 = document.createElementNS(NAMESPACES["svg"], tagName);
14491
+ } else node2 = document.createElement(rrNode.tagName);
14492
+ break;
14493
+ }
14494
+ case NodeType$1.Text:
14495
+ node2 = document.createTextNode(rrNode.data);
14496
+ break;
14497
+ case NodeType$1.Comment:
14498
+ node2 = document.createComment(rrNode.data);
14499
+ break;
14500
+ case NodeType$1.CDATA:
14501
+ node2 = document.createCDATASection(rrNode.data);
14502
+ break;
14503
+ }
14504
+ if (sn) domMirror.add(node2, __spreadValues({}, sn));
14505
+ try {
14506
+ createdNodeSet == null ? void 0 : createdNodeSet.add(node2);
14507
+ } catch (e2) {
14508
+ }
14509
+ return node2;
14510
+ }
14511
+ function sameNodeType(node1, node2) {
14512
+ if (node1.nodeType !== node2.nodeType) return false;
14513
+ return node1.nodeType !== node1.ELEMENT_NODE || node1.tagName.toUpperCase() === node2.tagName;
14514
+ }
14515
+ function nodeMatching(node1, node2, domMirror, rrdomMirror) {
14516
+ const node1Id = domMirror.getId(node1);
14517
+ const node2Id = rrdomMirror.getId(node2);
14518
+ if (node1Id === -1 || node1Id !== node2Id) return false;
14519
+ return sameNodeType(node1, node2);
14520
+ }
14521
+ function parseCSSText(cssText) {
14522
+ const res = {};
14523
+ const listDelimiter = /;(?![^(]*\))/g;
14524
+ const propertyDelimiter = /:(.+)/;
14525
+ const comment2 = /\/\*.*?\*\//g;
14526
+ cssText.replace(comment2, "").split(listDelimiter).forEach(function(item) {
14527
+ if (item) {
14528
+ const tmp = item.split(propertyDelimiter);
14529
+ tmp.length > 1 && (res[camelize(tmp[0].trim())] = tmp[1].trim());
14530
+ }
14531
+ });
14532
+ return res;
14533
+ }
14534
+ function toCSSText(style) {
14535
+ const properties = [];
14536
+ for (const name in style) {
14537
+ const value = style[name];
14538
+ if (typeof value !== "string") continue;
14539
+ const normalizedName = hyphenate(name);
14540
+ properties.push(`${normalizedName}: ${value};`);
14541
+ }
14542
+ return properties.join(" ");
14543
+ }
14544
+ const camelizeRE = /-([a-z])/g;
14545
+ const CUSTOM_PROPERTY_REGEX = /^--[a-zA-Z0-9-]+$/;
14546
+ const camelize = (str) => {
14547
+ if (CUSTOM_PROPERTY_REGEX.test(str)) return str;
14548
+ return str.replace(camelizeRE, (_, c2) => c2 ? c2.toUpperCase() : "");
14549
+ };
14550
+ const hyphenateRE = /\B([A-Z])/g;
14551
+ const hyphenate = (str) => {
14552
+ return str.replace(hyphenateRE, "-$1").toLowerCase();
14553
+ };
14554
+ class BaseRRNode {
14555
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any
14556
+ constructor(..._args) {
14557
+ __publicField22(this, "parentElement", null);
14558
+ __publicField22(this, "parentNode", null);
14559
+ __publicField22(this, "ownerDocument");
14560
+ __publicField22(this, "firstChild", null);
14561
+ __publicField22(this, "lastChild", null);
14562
+ __publicField22(this, "previousSibling", null);
14563
+ __publicField22(this, "nextSibling", null);
14564
+ __publicField22(this, "ELEMENT_NODE", 1);
14565
+ __publicField22(this, "TEXT_NODE", 3);
14566
+ __publicField22(this, "nodeType");
14567
+ __publicField22(this, "nodeName");
14568
+ __publicField22(this, "RRNodeType");
14569
+ }
14570
+ get childNodes() {
14571
+ const childNodes2 = [];
14572
+ let childIterator = this.firstChild;
14573
+ while (childIterator) {
14574
+ childNodes2.push(childIterator);
14575
+ childIterator = childIterator.nextSibling;
14576
+ }
14577
+ return childNodes2;
14578
+ }
14579
+ contains(node2) {
14580
+ if (!(node2 instanceof BaseRRNode)) return false;
14581
+ else if (node2.ownerDocument !== this.ownerDocument) return false;
14582
+ else if (node2 === this) return true;
14583
+ while (node2.parentNode) {
14584
+ if (node2.parentNode === this) return true;
14585
+ node2 = node2.parentNode;
14586
+ }
14587
+ return false;
14588
+ }
14589
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
14590
+ appendChild(_newChild) {
14591
+ throw new Error(
14592
+ `RRDomException: Failed to execute 'appendChild' on 'RRNode': This RRNode type does not support this method.`
14593
+ );
14594
+ }
14595
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
14596
+ insertBefore(_newChild, _refChild) {
14597
+ throw new Error(
14598
+ `RRDomException: Failed to execute 'insertBefore' on 'RRNode': This RRNode type does not support this method.`
14599
+ );
14600
+ }
14601
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
14602
+ removeChild(_node) {
14603
+ throw new Error(
14604
+ `RRDomException: Failed to execute 'removeChild' on 'RRNode': This RRNode type does not support this method.`
14605
+ );
14606
+ }
14607
+ toString() {
14608
+ return "RRNode";
14609
+ }
14610
+ }
14611
+ class BaseRRDocument extends BaseRRNode {
14612
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
14613
+ constructor(...args) {
14614
+ super(args);
14615
+ __publicField22(this, "nodeType", 9);
14616
+ __publicField22(this, "nodeName", "#document");
14617
+ __publicField22(this, "compatMode", "CSS1Compat");
14618
+ __publicField22(this, "RRNodeType", NodeType$1.Document);
14619
+ __publicField22(this, "textContent", null);
14620
+ this.ownerDocument = this;
14621
+ }
14622
+ get documentElement() {
14623
+ return this.childNodes.find(
14624
+ (node2) => node2.RRNodeType === NodeType$1.Element && node2.tagName === "HTML"
14625
+ ) || null;
14626
+ }
14627
+ get body() {
14628
+ var _a22;
14629
+ return ((_a22 = this.documentElement) == null ? void 0 : _a22.childNodes.find(
14630
+ (node2) => node2.RRNodeType === NodeType$1.Element && node2.tagName === "BODY"
14631
+ )) || null;
14632
+ }
14633
+ get head() {
14634
+ var _a22;
14635
+ return ((_a22 = this.documentElement) == null ? void 0 : _a22.childNodes.find(
14636
+ (node2) => node2.RRNodeType === NodeType$1.Element && node2.tagName === "HEAD"
14637
+ )) || null;
14638
+ }
14639
+ get implementation() {
14640
+ return this;
14641
+ }
14642
+ get firstElementChild() {
14643
+ return this.documentElement;
14644
+ }
14645
+ appendChild(newChild) {
14646
+ const nodeType = newChild.RRNodeType;
14647
+ if (nodeType === NodeType$1.Element || nodeType === NodeType$1.DocumentType) {
14648
+ if (this.childNodes.some((s2) => s2.RRNodeType === nodeType)) {
14649
+ throw new Error(
14650
+ `RRDomException: Failed to execute 'appendChild' on 'RRNode': Only one ${nodeType === NodeType$1.Element ? "RRElement" : "RRDoctype"} on RRDocument allowed.`
14651
+ );
14866
14652
  }
14867
- newStartNode = newChildren[++newStartIndex];
14868
14653
  }
14654
+ const child2 = appendChild(this, newChild);
14655
+ child2.parentElement = null;
14656
+ return child2;
14869
14657
  }
14870
- if (oldStartIndex > oldEndIndex) {
14871
- const referenceRRNode = newChildren[newEndIndex + 1];
14872
- let referenceNode = null;
14873
- if (referenceRRNode)
14874
- referenceNode = replayer.mirror.getNode(
14875
- rrnodeMirror.getId(referenceRRNode)
14876
- );
14877
- for (; newStartIndex <= newEndIndex; ++newStartIndex) {
14878
- const newNode = createOrGetNode(
14879
- newChildren[newStartIndex],
14880
- replayer.mirror,
14881
- rrnodeMirror
14882
- );
14883
- try {
14884
- oldTree.insertBefore(newNode, referenceNode);
14885
- } catch (e2) {
14886
- console.warn(e2);
14658
+ insertBefore(newChild, refChild) {
14659
+ const nodeType = newChild.RRNodeType;
14660
+ if (nodeType === NodeType$1.Element || nodeType === NodeType$1.DocumentType) {
14661
+ if (this.childNodes.some((s2) => s2.RRNodeType === nodeType)) {
14662
+ throw new Error(
14663
+ `RRDomException: Failed to execute 'insertBefore' on 'RRNode': Only one ${nodeType === NodeType$1.Element ? "RRElement" : "RRDoctype"} on RRDocument allowed.`
14664
+ );
14887
14665
  }
14888
14666
  }
14889
- } else if (newStartIndex > newEndIndex) {
14890
- for (; oldStartIndex <= oldEndIndex; oldStartIndex++) {
14891
- const node2 = oldChildren[oldStartIndex];
14892
- if (!node2 || node2.parentNode !== oldTree) continue;
14893
- try {
14894
- oldTree.removeChild(node2);
14895
- replayer.mirror.removeNodeFromMap(node2);
14896
- } catch (e2) {
14897
- console.warn(e2);
14667
+ const child2 = insertBefore(this, newChild, refChild);
14668
+ child2.parentElement = null;
14669
+ return child2;
14670
+ }
14671
+ removeChild(node2) {
14672
+ return removeChild(this, node2);
14673
+ }
14674
+ open() {
14675
+ this.firstChild = null;
14676
+ this.lastChild = null;
14677
+ }
14678
+ close() {
14679
+ }
14680
+ /**
14681
+ * Adhoc implementation for setting xhtml namespace in rebuilt.ts (rrweb-snapshot).
14682
+ * There are two lines used this function:
14683
+ * 1. doc.write('\<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" ""\>')
14684
+ * 2. doc.write('\<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" ""\>')
14685
+ */
14686
+ write(content) {
14687
+ let publicId;
14688
+ if (content === '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">')
14689
+ publicId = "-//W3C//DTD XHTML 1.0 Transitional//EN";
14690
+ else if (content === '<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "">')
14691
+ publicId = "-//W3C//DTD HTML 4.0 Transitional//EN";
14692
+ if (publicId) {
14693
+ const doctype = this.createDocumentType("html", publicId, "");
14694
+ this.open();
14695
+ this.appendChild(doctype);
14696
+ }
14697
+ }
14698
+ createDocument(_namespace, _qualifiedName, _doctype) {
14699
+ return new BaseRRDocument();
14700
+ }
14701
+ createDocumentType(qualifiedName, publicId, systemId) {
14702
+ const doctype = new BaseRRDocumentType(qualifiedName, publicId, systemId);
14703
+ doctype.ownerDocument = this;
14704
+ return doctype;
14705
+ }
14706
+ createElement(tagName) {
14707
+ const element = new BaseRRElement(tagName);
14708
+ element.ownerDocument = this;
14709
+ return element;
14710
+ }
14711
+ createElementNS(_namespaceURI, qualifiedName) {
14712
+ return this.createElement(qualifiedName);
14713
+ }
14714
+ createTextNode(data) {
14715
+ const text = new BaseRRText(data);
14716
+ text.ownerDocument = this;
14717
+ return text;
14718
+ }
14719
+ createComment(data) {
14720
+ const comment2 = new BaseRRComment(data);
14721
+ comment2.ownerDocument = this;
14722
+ return comment2;
14723
+ }
14724
+ createCDATASection(data) {
14725
+ const CDATASection = new BaseRRCDATASection(data);
14726
+ CDATASection.ownerDocument = this;
14727
+ return CDATASection;
14728
+ }
14729
+ toString() {
14730
+ return "RRDocument";
14731
+ }
14732
+ }
14733
+ class BaseRRDocumentType extends BaseRRNode {
14734
+ constructor(qualifiedName, publicId, systemId) {
14735
+ super();
14736
+ __publicField22(this, "nodeType", 10);
14737
+ __publicField22(this, "RRNodeType", NodeType$1.DocumentType);
14738
+ __publicField22(this, "name");
14739
+ __publicField22(this, "publicId");
14740
+ __publicField22(this, "systemId");
14741
+ __publicField22(this, "textContent", null);
14742
+ this.name = qualifiedName;
14743
+ this.publicId = publicId;
14744
+ this.systemId = systemId;
14745
+ this.nodeName = qualifiedName;
14746
+ }
14747
+ toString() {
14748
+ return "RRDocumentType";
14749
+ }
14750
+ }
14751
+ class BaseRRElement extends BaseRRNode {
14752
+ constructor(tagName) {
14753
+ super();
14754
+ __publicField22(this, "nodeType", 1);
14755
+ __publicField22(this, "RRNodeType", NodeType$1.Element);
14756
+ __publicField22(this, "tagName");
14757
+ __publicField22(this, "attributes", {});
14758
+ __publicField22(this, "shadowRoot", null);
14759
+ __publicField22(this, "scrollLeft");
14760
+ __publicField22(this, "scrollTop");
14761
+ this.tagName = tagName.toUpperCase();
14762
+ this.nodeName = tagName.toUpperCase();
14763
+ }
14764
+ get textContent() {
14765
+ let result2 = "";
14766
+ this.childNodes.forEach((node2) => result2 += node2.textContent);
14767
+ return result2;
14768
+ }
14769
+ set textContent(textContent2) {
14770
+ this.firstChild = null;
14771
+ this.lastChild = null;
14772
+ this.appendChild(this.ownerDocument.createTextNode(textContent2));
14773
+ }
14774
+ get classList() {
14775
+ return new ClassList(
14776
+ this.attributes.class,
14777
+ (newClassName) => {
14778
+ this.attributes.class = newClassName;
14898
14779
  }
14780
+ );
14781
+ }
14782
+ get id() {
14783
+ return this.attributes.id || "";
14784
+ }
14785
+ get className() {
14786
+ return this.attributes.class || "";
14787
+ }
14788
+ get style() {
14789
+ const style = this.attributes.style ? parseCSSText(this.attributes.style) : {};
14790
+ const hyphenateRE2 = /\B([A-Z])/g;
14791
+ style.setProperty = (name, value, priority) => {
14792
+ if (hyphenateRE2.test(name)) return;
14793
+ const normalizedName = camelize(name);
14794
+ if (!value) delete style[normalizedName];
14795
+ else style[normalizedName] = value;
14796
+ if (priority === "important") style[normalizedName] += " !important";
14797
+ this.attributes.style = toCSSText(style);
14798
+ };
14799
+ style.removeProperty = (name) => {
14800
+ if (hyphenateRE2.test(name)) return "";
14801
+ const normalizedName = camelize(name);
14802
+ const value = style[normalizedName] || "";
14803
+ delete style[normalizedName];
14804
+ this.attributes.style = toCSSText(style);
14805
+ return value;
14806
+ };
14807
+ return style;
14808
+ }
14809
+ getAttribute(name) {
14810
+ if (this.attributes[name] === void 0) return null;
14811
+ return this.attributes[name];
14812
+ }
14813
+ setAttribute(name, attribute) {
14814
+ this.attributes[name] = attribute;
14815
+ }
14816
+ setAttributeNS(_namespace, qualifiedName, value) {
14817
+ this.setAttribute(qualifiedName, value);
14818
+ }
14819
+ removeAttribute(name) {
14820
+ delete this.attributes[name];
14821
+ }
14822
+ appendChild(newChild) {
14823
+ return appendChild(this, newChild);
14824
+ }
14825
+ insertBefore(newChild, refChild) {
14826
+ return insertBefore(this, newChild, refChild);
14827
+ }
14828
+ removeChild(node2) {
14829
+ return removeChild(this, node2);
14830
+ }
14831
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
14832
+ attachShadow(_init) {
14833
+ const shadowRoot2 = this.ownerDocument.createElement("SHADOWROOT");
14834
+ this.shadowRoot = shadowRoot2;
14835
+ return shadowRoot2;
14836
+ }
14837
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
14838
+ dispatchEvent(_event) {
14839
+ return true;
14840
+ }
14841
+ toString() {
14842
+ let attributeString = "";
14843
+ for (const attribute in this.attributes) {
14844
+ attributeString += `${attribute}="${this.attributes[attribute]}" `;
14899
14845
  }
14846
+ return `${this.tagName} ${attributeString}`;
14900
14847
  }
14901
- let oldChild = oldTree.firstChild;
14902
- let newChild = newTree.firstChild;
14903
- while (oldChild !== null && newChild !== null) {
14904
- diff(oldChild, newChild, replayer, rrnodeMirror);
14905
- oldChild = oldChild.nextSibling;
14906
- newChild = newChild.nextSibling;
14848
+ }
14849
+ class BaseRRMediaElement extends BaseRRElement {
14850
+ constructor() {
14851
+ super(...arguments);
14852
+ __publicField22(this, "currentTime");
14853
+ __publicField22(this, "volume");
14854
+ __publicField22(this, "paused");
14855
+ __publicField22(this, "muted");
14856
+ __publicField22(this, "playbackRate");
14857
+ __publicField22(this, "loop");
14858
+ }
14859
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
14860
+ attachShadow(_init) {
14861
+ throw new Error(
14862
+ `RRDomException: Failed to execute 'attachShadow' on 'RRElement': This RRElement does not support attachShadow`
14863
+ );
14864
+ }
14865
+ play() {
14866
+ this.paused = false;
14867
+ }
14868
+ pause() {
14869
+ this.paused = true;
14907
14870
  }
14908
14871
  }
14909
- function createOrGetNode(rrNode, domMirror, rrnodeMirror) {
14910
- const nodeId = rrnodeMirror.getId(rrNode);
14911
- const sn = rrnodeMirror.getMeta(rrNode);
14912
- let node2 = null;
14913
- if (nodeId > -1) node2 = domMirror.getNode(nodeId);
14914
- if (node2 !== null && sameNodeType(node2, rrNode)) return node2;
14915
- switch (rrNode.RRNodeType) {
14916
- case NodeType$1.Document:
14917
- node2 = new Document();
14918
- break;
14919
- case NodeType$1.DocumentType:
14920
- node2 = document.implementation.createDocumentType(
14921
- rrNode.name,
14922
- rrNode.publicId,
14923
- rrNode.systemId
14872
+ class BaseRRDialogElement extends BaseRRElement {
14873
+ constructor() {
14874
+ super(...arguments);
14875
+ __publicField22(this, "tagName", "DIALOG");
14876
+ __publicField22(this, "nodeName", "DIALOG");
14877
+ }
14878
+ get isModal() {
14879
+ return this.getAttribute("rr_open_mode") === "modal";
14880
+ }
14881
+ get open() {
14882
+ return this.getAttribute("open") !== null;
14883
+ }
14884
+ close() {
14885
+ this.removeAttribute("open");
14886
+ this.removeAttribute("rr_open_mode");
14887
+ }
14888
+ show() {
14889
+ this.setAttribute("open", "");
14890
+ this.setAttribute("rr_open_mode", "non-modal");
14891
+ }
14892
+ showModal() {
14893
+ this.setAttribute("open", "");
14894
+ this.setAttribute("rr_open_mode", "modal");
14895
+ }
14896
+ }
14897
+ class BaseRRText extends BaseRRNode {
14898
+ constructor(data) {
14899
+ super();
14900
+ __publicField22(this, "nodeType", 3);
14901
+ __publicField22(this, "nodeName", "#text");
14902
+ __publicField22(this, "RRNodeType", NodeType$1.Text);
14903
+ __publicField22(this, "data");
14904
+ this.data = data;
14905
+ }
14906
+ get textContent() {
14907
+ return this.data;
14908
+ }
14909
+ set textContent(textContent2) {
14910
+ this.data = textContent2;
14911
+ }
14912
+ toString() {
14913
+ return `RRText text=${JSON.stringify(this.data)}`;
14914
+ }
14915
+ }
14916
+ class BaseRRComment extends BaseRRNode {
14917
+ constructor(data) {
14918
+ super();
14919
+ __publicField22(this, "nodeType", 8);
14920
+ __publicField22(this, "nodeName", "#comment");
14921
+ __publicField22(this, "RRNodeType", NodeType$1.Comment);
14922
+ __publicField22(this, "data");
14923
+ this.data = data;
14924
+ }
14925
+ get textContent() {
14926
+ return this.data;
14927
+ }
14928
+ set textContent(textContent2) {
14929
+ this.data = textContent2;
14930
+ }
14931
+ toString() {
14932
+ return `RRComment text=${JSON.stringify(this.data)}`;
14933
+ }
14934
+ }
14935
+ class BaseRRCDATASection extends BaseRRNode {
14936
+ constructor(data) {
14937
+ super();
14938
+ __publicField22(this, "nodeName", "#cdata-section");
14939
+ __publicField22(this, "nodeType", 4);
14940
+ __publicField22(this, "RRNodeType", NodeType$1.CDATA);
14941
+ __publicField22(this, "data");
14942
+ this.data = data;
14943
+ }
14944
+ get textContent() {
14945
+ return this.data;
14946
+ }
14947
+ set textContent(textContent2) {
14948
+ this.data = textContent2;
14949
+ }
14950
+ toString() {
14951
+ return `RRCDATASection data=${JSON.stringify(this.data)}`;
14952
+ }
14953
+ }
14954
+ class ClassList {
14955
+ constructor(classText, onChange) {
14956
+ __publicField22(this, "onChange");
14957
+ __publicField22(this, "classes", []);
14958
+ __publicField22(this, "add", (...classNames) => {
14959
+ for (const item of classNames) {
14960
+ const className = String(item);
14961
+ if (this.classes.indexOf(className) >= 0) continue;
14962
+ this.classes.push(className);
14963
+ }
14964
+ this.onChange && this.onChange(this.classes.join(" "));
14965
+ });
14966
+ __publicField22(this, "remove", (...classNames) => {
14967
+ this.classes = this.classes.filter(
14968
+ (item) => classNames.indexOf(item) === -1
14924
14969
  );
14925
- break;
14926
- case NodeType$1.Element: {
14927
- let tagName = rrNode.tagName.toLowerCase();
14928
- tagName = SVGTagMap[tagName] || tagName;
14929
- if (sn && "isSVG" in sn && (sn == null ? void 0 : sn.isSVG)) {
14930
- node2 = document.createElementNS(NAMESPACES["svg"], tagName);
14931
- } else node2 = document.createElement(rrNode.tagName);
14932
- break;
14970
+ this.onChange && this.onChange(this.classes.join(" "));
14971
+ });
14972
+ if (classText) {
14973
+ const classes = classText.trim().split(/\s+/);
14974
+ this.classes.push(...classes);
14933
14975
  }
14934
- case NodeType$1.Text:
14935
- node2 = document.createTextNode(rrNode.data);
14936
- break;
14937
- case NodeType$1.Comment:
14938
- node2 = document.createComment(rrNode.data);
14939
- break;
14940
- case NodeType$1.CDATA:
14941
- node2 = document.createCDATASection(rrNode.data);
14942
- break;
14976
+ this.onChange = onChange;
14943
14977
  }
14944
- if (sn) domMirror.add(node2, __spreadValues({}, sn));
14945
- try {
14946
- createdNodeSet == null ? void 0 : createdNodeSet.add(node2);
14947
- } catch (e2) {
14978
+ }
14979
+ function appendChild(parent, newChild) {
14980
+ if (newChild.parentNode) newChild.parentNode.removeChild(newChild);
14981
+ if (parent.lastChild) {
14982
+ parent.lastChild.nextSibling = newChild;
14983
+ newChild.previousSibling = parent.lastChild;
14984
+ } else {
14985
+ parent.firstChild = newChild;
14986
+ newChild.previousSibling = null;
14948
14987
  }
14949
- return node2;
14988
+ parent.lastChild = newChild;
14989
+ newChild.nextSibling = null;
14990
+ newChild.parentNode = parent;
14991
+ newChild.parentElement = parent;
14992
+ newChild.ownerDocument = parent.ownerDocument;
14993
+ return newChild;
14950
14994
  }
14951
- function sameNodeType(node1, node2) {
14952
- if (node1.nodeType !== node2.nodeType) return false;
14953
- return node1.nodeType !== node1.ELEMENT_NODE || node1.tagName.toUpperCase() === node2.tagName;
14995
+ function insertBefore(parent, newChild, refChild) {
14996
+ if (!refChild) return appendChild(parent, newChild);
14997
+ if (refChild.parentNode !== parent)
14998
+ throw new Error(
14999
+ "Failed to execute 'insertBefore' on 'RRNode': The RRNode before which the new node is to be inserted is not a child of this RRNode."
15000
+ );
15001
+ if (newChild === refChild) return newChild;
15002
+ if (newChild.parentNode) newChild.parentNode.removeChild(newChild);
15003
+ newChild.previousSibling = refChild.previousSibling;
15004
+ refChild.previousSibling = newChild;
15005
+ newChild.nextSibling = refChild;
15006
+ if (newChild.previousSibling) newChild.previousSibling.nextSibling = newChild;
15007
+ else parent.firstChild = newChild;
15008
+ newChild.parentElement = parent;
15009
+ newChild.parentNode = parent;
15010
+ newChild.ownerDocument = parent.ownerDocument;
15011
+ return newChild;
14954
15012
  }
14955
- function nodeMatching(node1, node2, domMirror, rrdomMirror) {
14956
- const node1Id = domMirror.getId(node1);
14957
- const node2Id = rrdomMirror.getId(node2);
14958
- if (node1Id === -1 || node1Id !== node2Id) return false;
14959
- return sameNodeType(node1, node2);
15013
+ function removeChild(parent, child2) {
15014
+ if (child2.parentNode !== parent)
15015
+ throw new Error(
15016
+ "Failed to execute 'removeChild' on 'RRNode': The RRNode to be removed is not a child of this RRNode."
15017
+ );
15018
+ if (child2.previousSibling)
15019
+ child2.previousSibling.nextSibling = child2.nextSibling;
15020
+ else parent.firstChild = child2.nextSibling;
15021
+ if (child2.nextSibling)
15022
+ child2.nextSibling.previousSibling = child2.previousSibling;
15023
+ else parent.lastChild = child2.previousSibling;
15024
+ child2.previousSibling = null;
15025
+ child2.nextSibling = null;
15026
+ child2.parentElement = null;
15027
+ child2.parentNode = null;
15028
+ return child2;
14960
15029
  }
15030
+ var NodeType$2 = /* @__PURE__ */ ((NodeType2) => {
15031
+ NodeType2[NodeType2["PLACEHOLDER"] = 0] = "PLACEHOLDER";
15032
+ NodeType2[NodeType2["ELEMENT_NODE"] = 1] = "ELEMENT_NODE";
15033
+ NodeType2[NodeType2["ATTRIBUTE_NODE"] = 2] = "ATTRIBUTE_NODE";
15034
+ NodeType2[NodeType2["TEXT_NODE"] = 3] = "TEXT_NODE";
15035
+ NodeType2[NodeType2["CDATA_SECTION_NODE"] = 4] = "CDATA_SECTION_NODE";
15036
+ NodeType2[NodeType2["ENTITY_REFERENCE_NODE"] = 5] = "ENTITY_REFERENCE_NODE";
15037
+ NodeType2[NodeType2["ENTITY_NODE"] = 6] = "ENTITY_NODE";
15038
+ NodeType2[NodeType2["PROCESSING_INSTRUCTION_NODE"] = 7] = "PROCESSING_INSTRUCTION_NODE";
15039
+ NodeType2[NodeType2["COMMENT_NODE"] = 8] = "COMMENT_NODE";
15040
+ NodeType2[NodeType2["DOCUMENT_NODE"] = 9] = "DOCUMENT_NODE";
15041
+ NodeType2[NodeType2["DOCUMENT_TYPE_NODE"] = 10] = "DOCUMENT_TYPE_NODE";
15042
+ NodeType2[NodeType2["DOCUMENT_FRAGMENT_NODE"] = 11] = "DOCUMENT_FRAGMENT_NODE";
15043
+ return NodeType2;
15044
+ })(NodeType$2 || {});
14961
15045
  class RRDocument extends BaseRRDocument {
14962
15046
  constructor(mirror2) {
14963
15047
  super();
@@ -15142,6 +15226,7 @@ function buildFromNode(node2, rrdom, domMirror, parentRRNode) {
15142
15226
  }
15143
15227
  rrdom.mirror.add(rrNode, __spreadValues({}, sn));
15144
15228
  }
15229
+ nodesBuiltFromDom.add(rrNode);
15145
15230
  return rrNode;
15146
15231
  }
15147
15232
  function buildFromDom(dom, domMirror = createMirror$1(), rrdom = new RRDocument()) {
@@ -15537,15 +15622,12 @@ function hasShadowRoot(n2) {
15537
15622
  return Boolean(index.shadowRoot(n2));
15538
15623
  }
15539
15624
  function getNestedRule(rules2, position) {
15540
- const rule2 = rules2[position[0]];
15541
- if (position.length === 1) {
15542
- return rule2;
15543
- } else {
15544
- return getNestedRule(
15545
- rule2.cssRules[position[1]].cssRules,
15546
- position.slice(2)
15547
- );
15625
+ var _a22;
15626
+ let rule2 = rules2[position[0]];
15627
+ for (let i2 = 1; i2 < position.length && rule2; i2++) {
15628
+ rule2 = (_a22 = rule2.cssRules) == null ? void 0 : _a22[position[i2]];
15548
15629
  }
15630
+ return rule2;
15549
15631
  }
15550
15632
  function getPositionsAndIndex(nestedIndex) {
15551
15633
  const positions = [...nestedIndex];
@@ -18223,8 +18305,12 @@ class Replayer {
18223
18305
  case IncrementalSource.StyleDeclaration: {
18224
18306
  if (this.usingVirtualDom) {
18225
18307
  if (d.styleId) this.constructedStyleMutations.push(d);
18226
- else if (d.id)
18227
- (_b22 = this.virtualDom.mirror.getNode(d.id)) == null ? void 0 : _b22.rules.push(d);
18308
+ else if (d.id) {
18309
+ const target = this.virtualDom.mirror.getNode(
18310
+ d.id
18311
+ );
18312
+ (_b22 = target == null ? void 0 : target.rules) == null ? void 0 : _b22.push(d);
18313
+ }
18228
18314
  } else this.applyStyleSheetMutation(d);
18229
18315
  break;
18230
18316
  }
@@ -18813,11 +18899,9 @@ class Replayer {
18813
18899
  }
18814
18900
  }
18815
18901
  applyStyleDeclaration(data, styleSheet) {
18902
+ const rule2 = getNestedRule(styleSheet.cssRules, data.index);
18903
+ if (!(rule2 == null ? void 0 : rule2.style)) return;
18816
18904
  if (data.set) {
18817
- const rule2 = getNestedRule(
18818
- styleSheet.rules,
18819
- data.index
18820
- );
18821
18905
  rule2.style.setProperty(
18822
18906
  data.set.property,
18823
18907
  data.set.value,
@@ -18825,10 +18909,6 @@ class Replayer {
18825
18909
  );
18826
18910
  }
18827
18911
  if (data.remove) {
18828
- const rule2 = getNestedRule(
18829
- styleSheet.rules,
18830
- data.index
18831
- );
18832
18912
  rule2.style.removeProperty(data.remove.property);
18833
18913
  }
18834
18914
  }