@amplitude/rrweb-player 2.1.5 → 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.
@@ -5554,8 +5554,10 @@ function serializeNodeWithId(n2, options) {
5554
5554
  onSerialize(n2);
5555
5555
  }
5556
5556
  let recordChild = !skipChild;
5557
+ let isBlockedElement = false;
5557
5558
  if (serializedNode.type === NodeType$3.Element) {
5558
- recordChild = recordChild && !serializedNode.needBlock;
5559
+ isBlockedElement = Boolean(serializedNode.needBlock);
5560
+ recordChild = recordChild && !isBlockedElement;
5559
5561
  delete serializedNode.needBlock;
5560
5562
  const shadowRootEl = index$1.shadowRoot(n2);
5561
5563
  if (shadowRootEl && isNativeShadowDom(shadowRootEl)) {
@@ -5640,7 +5642,7 @@ function serializeNodeWithId(n2, options) {
5640
5642
  if (parent && isShadowRoot(parent) && isNativeShadowDom(parent)) {
5641
5643
  serializedNode.isShadow = true;
5642
5644
  }
5643
- if (serializedNode.type === NodeType$3.Element && serializedNode.tagName === "iframe") {
5645
+ if (serializedNode.type === NodeType$3.Element && serializedNode.tagName === "iframe" && !isBlockedElement) {
5644
5646
  onceIframeLoaded(
5645
5647
  n2,
5646
5648
  () => {
@@ -14004,643 +14006,119 @@ var NodeType$1 = /* @__PURE__ */ ((NodeType2) => {
14004
14006
  NodeType2[NodeType2["Comment"] = 5] = "Comment";
14005
14007
  return NodeType2;
14006
14008
  })(NodeType$1 || {});
14007
- function parseCSSText(cssText) {
14008
- const res = {};
14009
- const listDelimiter = /;(?![^(]*\))/g;
14010
- const propertyDelimiter = /:(.+)/;
14011
- const comment2 = /\/\*.*?\*\//g;
14012
- cssText.replace(comment2, "").split(listDelimiter).forEach(function(item) {
14013
- if (item) {
14014
- const tmp = item.split(propertyDelimiter);
14015
- tmp.length > 1 && (res[camelize(tmp[0].trim())] = tmp[1].trim());
14016
- }
14017
- });
14018
- return res;
14019
- }
14020
- function toCSSText(style) {
14021
- const properties = [];
14022
- for (const name in style) {
14023
- const value = style[name];
14024
- if (typeof value !== "string") continue;
14025
- const normalizedName = hyphenate(name);
14026
- properties.push(`${normalizedName}: ${value};`);
14027
- }
14028
- return properties.join(" ");
14029
- }
14030
- const camelizeRE = /-([a-z])/g;
14031
- const CUSTOM_PROPERTY_REGEX = /^--[a-zA-Z0-9-]+$/;
14032
- const camelize = (str) => {
14033
- if (CUSTOM_PROPERTY_REGEX.test(str)) return str;
14034
- 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/"
14035
14013
  };
14036
- const hyphenateRE = /\B([A-Z])/g;
14037
- const hyphenate = (str) => {
14038
- 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"
14039
14051
  };
14040
- class BaseRRNode {
14041
- // eslint-disable-next-line @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any
14042
- constructor(..._args) {
14043
- __publicField22(this, "parentElement", null);
14044
- __publicField22(this, "parentNode", null);
14045
- __publicField22(this, "ownerDocument");
14046
- __publicField22(this, "firstChild", null);
14047
- __publicField22(this, "lastChild", null);
14048
- __publicField22(this, "previousSibling", null);
14049
- __publicField22(this, "nextSibling", null);
14050
- __publicField22(this, "ELEMENT_NODE", 1);
14051
- __publicField22(this, "TEXT_NODE", 3);
14052
- __publicField22(this, "nodeType");
14053
- __publicField22(this, "nodeName");
14054
- __publicField22(this, "RRNodeType");
14055
- }
14056
- get childNodes() {
14057
- const childNodes2 = [];
14058
- let childIterator = this.firstChild;
14059
- while (childIterator) {
14060
- childNodes2.push(childIterator);
14061
- childIterator = childIterator.nextSibling;
14062
- }
14063
- return childNodes2;
14064
- }
14065
- contains(node2) {
14066
- if (!(node2 instanceof BaseRRNode)) return false;
14067
- else if (node2.ownerDocument !== this.ownerDocument) return false;
14068
- else if (node2 === this) return true;
14069
- while (node2.parentNode) {
14070
- if (node2.parentNode === this) return true;
14071
- node2 = node2.parentNode;
14072
- }
14073
- return false;
14074
- }
14075
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
14076
- appendChild(_newChild) {
14077
- throw new Error(
14078
- `RRDomException: Failed to execute 'appendChild' on 'RRNode': This RRNode type does not support this method.`
14079
- );
14080
- }
14081
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
14082
- insertBefore(_newChild, _refChild) {
14083
- throw new Error(
14084
- `RRDomException: Failed to execute 'insertBefore' on 'RRNode': This RRNode type does not support this method.`
14085
- );
14086
- }
14087
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
14088
- removeChild(_node) {
14089
- throw new Error(
14090
- `RRDomException: Failed to execute 'removeChild' on 'RRNode': This RRNode type does not support this method.`
14091
- );
14092
- }
14093
- toString() {
14094
- return "RRNode";
14095
- }
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);
14096
14062
  }
14097
- class BaseRRDocument extends BaseRRNode {
14098
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
14099
- constructor(...args) {
14100
- super(args);
14101
- __publicField22(this, "nodeType", 9);
14102
- __publicField22(this, "nodeName", "#document");
14103
- __publicField22(this, "compatMode", "CSS1Compat");
14104
- __publicField22(this, "RRNodeType", NodeType$1.Document);
14105
- __publicField22(this, "textContent", null);
14106
- this.ownerDocument = this;
14107
- }
14108
- get documentElement() {
14109
- return this.childNodes.find(
14110
- (node2) => node2.RRNodeType === NodeType$1.Element && node2.tagName === "HTML"
14111
- ) || null;
14112
- }
14113
- get body() {
14114
- var _a22;
14115
- return ((_a22 = this.documentElement) == null ? void 0 : _a22.childNodes.find(
14116
- (node2) => node2.RRNodeType === NodeType$1.Element && node2.tagName === "BODY"
14117
- )) || null;
14118
- }
14119
- get head() {
14120
- var _a22;
14121
- return ((_a22 = this.documentElement) == null ? void 0 : _a22.childNodes.find(
14122
- (node2) => node2.RRNodeType === NodeType$1.Element && node2.tagName === "HEAD"
14123
- )) || null;
14124
- }
14125
- get implementation() {
14126
- 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);
14127
14070
  }
14128
- get firstElementChild() {
14129
- 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;
14130
14079
  }
14131
- appendChild(newChild) {
14132
- const nodeType = newChild.RRNodeType;
14133
- if (nodeType === NodeType$1.Element || nodeType === NodeType$1.DocumentType) {
14134
- if (this.childNodes.some((s2) => s2.RRNodeType === nodeType)) {
14135
- throw new Error(
14136
- `RRDomException: Failed to execute 'appendChild' on 'RRNode': Only one ${nodeType === NodeType$1.Element ? "RRElement" : "RRDoctype"} on RRDocument allowed.`
14137
- );
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
+ }
14138
14091
  }
14092
+ break;
14139
14093
  }
14140
- const child2 = appendChild(this, newChild);
14141
- child2.parentElement = null;
14142
- return child2;
14143
- }
14144
- insertBefore(newChild, refChild) {
14145
- const nodeType = newChild.RRNodeType;
14146
- if (nodeType === NodeType$1.Element || nodeType === NodeType$1.DocumentType) {
14147
- if (this.childNodes.some((s2) => s2.RRNodeType === nodeType)) {
14148
- throw new Error(
14149
- `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
14150
14118
  );
14151
14119
  }
14152
- }
14153
- const child2 = insertBefore(this, newChild, refChild);
14154
- child2.parentElement = null;
14155
- return child2;
14156
- }
14157
- removeChild(node2) {
14158
- return removeChild(this, node2);
14159
- }
14160
- open() {
14161
- this.firstChild = null;
14162
- this.lastChild = null;
14163
- }
14164
- close() {
14165
- }
14166
- /**
14167
- * Adhoc implementation for setting xhtml namespace in rebuilt.ts (rrweb-snapshot).
14168
- * There are two lines used this function:
14169
- * 1. doc.write('\<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" ""\>')
14170
- * 2. doc.write('\<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" ""\>')
14171
- */
14172
- write(content) {
14173
- let publicId;
14174
- if (content === '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">')
14175
- publicId = "-//W3C//DTD XHTML 1.0 Transitional//EN";
14176
- else if (content === '<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "">')
14177
- publicId = "-//W3C//DTD HTML 4.0 Transitional//EN";
14178
- if (publicId) {
14179
- const doctype = this.createDocumentType("html", publicId, "");
14180
- this.open();
14181
- this.appendChild(doctype);
14182
- }
14183
- }
14184
- createDocument(_namespace, _qualifiedName, _doctype) {
14185
- return new BaseRRDocument();
14186
- }
14187
- createDocumentType(qualifiedName, publicId, systemId) {
14188
- const doctype = new BaseRRDocumentType(qualifiedName, publicId, systemId);
14189
- doctype.ownerDocument = this;
14190
- return doctype;
14191
- }
14192
- createElement(tagName) {
14193
- const element = new BaseRRElement(tagName);
14194
- element.ownerDocument = this;
14195
- return element;
14196
- }
14197
- createElementNS(_namespaceURI, qualifiedName) {
14198
- return this.createElement(qualifiedName);
14199
- }
14200
- createTextNode(data) {
14201
- const text = new BaseRRText(data);
14202
- text.ownerDocument = this;
14203
- return text;
14204
- }
14205
- createComment(data) {
14206
- const comment2 = new BaseRRComment(data);
14207
- comment2.ownerDocument = this;
14208
- return comment2;
14209
- }
14210
- createCDATASection(data) {
14211
- const CDATASection = new BaseRRCDATASection(data);
14212
- CDATASection.ownerDocument = this;
14213
- return CDATASection;
14214
- }
14215
- toString() {
14216
- return "RRDocument";
14217
- }
14218
- }
14219
- class BaseRRDocumentType extends BaseRRNode {
14220
- constructor(qualifiedName, publicId, systemId) {
14221
- super();
14222
- __publicField22(this, "nodeType", 10);
14223
- __publicField22(this, "RRNodeType", NodeType$1.DocumentType);
14224
- __publicField22(this, "name");
14225
- __publicField22(this, "publicId");
14226
- __publicField22(this, "systemId");
14227
- __publicField22(this, "textContent", null);
14228
- this.name = qualifiedName;
14229
- this.publicId = publicId;
14230
- this.systemId = systemId;
14231
- this.nodeName = qualifiedName;
14232
- }
14233
- toString() {
14234
- return "RRDocumentType";
14235
- }
14236
- }
14237
- class BaseRRElement extends BaseRRNode {
14238
- constructor(tagName) {
14239
- super();
14240
- __publicField22(this, "nodeType", 1);
14241
- __publicField22(this, "RRNodeType", NodeType$1.Element);
14242
- __publicField22(this, "tagName");
14243
- __publicField22(this, "attributes", {});
14244
- __publicField22(this, "shadowRoot", null);
14245
- __publicField22(this, "scrollLeft");
14246
- __publicField22(this, "scrollTop");
14247
- this.tagName = tagName.toUpperCase();
14248
- this.nodeName = tagName.toUpperCase();
14249
- }
14250
- get textContent() {
14251
- let result2 = "";
14252
- this.childNodes.forEach((node2) => result2 += node2.textContent);
14253
- return result2;
14254
- }
14255
- set textContent(textContent2) {
14256
- this.firstChild = null;
14257
- this.lastChild = null;
14258
- this.appendChild(this.ownerDocument.createTextNode(textContent2));
14259
- }
14260
- get classList() {
14261
- return new ClassList(
14262
- this.attributes.class,
14263
- (newClassName) => {
14264
- this.attributes.class = newClassName;
14265
- }
14266
- );
14267
- }
14268
- get id() {
14269
- return this.attributes.id || "";
14270
- }
14271
- get className() {
14272
- return this.attributes.class || "";
14273
- }
14274
- get style() {
14275
- const style = this.attributes.style ? parseCSSText(this.attributes.style) : {};
14276
- const hyphenateRE2 = /\B([A-Z])/g;
14277
- style.setProperty = (name, value, priority) => {
14278
- if (hyphenateRE2.test(name)) return;
14279
- const normalizedName = camelize(name);
14280
- if (!value) delete style[normalizedName];
14281
- else style[normalizedName] = value;
14282
- if (priority === "important") style[normalizedName] += " !important";
14283
- this.attributes.style = toCSSText(style);
14284
- };
14285
- style.removeProperty = (name) => {
14286
- if (hyphenateRE2.test(name)) return "";
14287
- const normalizedName = camelize(name);
14288
- const value = style[normalizedName] || "";
14289
- delete style[normalizedName];
14290
- this.attributes.style = toCSSText(style);
14291
- return value;
14292
- };
14293
- return style;
14294
- }
14295
- getAttribute(name) {
14296
- if (this.attributes[name] === void 0) return null;
14297
- return this.attributes[name];
14298
- }
14299
- setAttribute(name, attribute) {
14300
- this.attributes[name] = attribute;
14301
- }
14302
- setAttributeNS(_namespace, qualifiedName, value) {
14303
- this.setAttribute(qualifiedName, value);
14304
- }
14305
- removeAttribute(name) {
14306
- delete this.attributes[name];
14307
- }
14308
- appendChild(newChild) {
14309
- return appendChild(this, newChild);
14310
- }
14311
- insertBefore(newChild, refChild) {
14312
- return insertBefore(this, newChild, refChild);
14313
- }
14314
- removeChild(node2) {
14315
- return removeChild(this, node2);
14316
- }
14317
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
14318
- attachShadow(_init) {
14319
- const shadowRoot2 = this.ownerDocument.createElement("SHADOWROOT");
14320
- this.shadowRoot = shadowRoot2;
14321
- return shadowRoot2;
14322
- }
14323
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
14324
- dispatchEvent(_event) {
14325
- return true;
14326
- }
14327
- toString() {
14328
- let attributeString = "";
14329
- for (const attribute in this.attributes) {
14330
- attributeString += `${attribute}="${this.attributes[attribute]}" `;
14331
- }
14332
- return `${this.tagName} ${attributeString}`;
14333
- }
14334
- }
14335
- class BaseRRMediaElement extends BaseRRElement {
14336
- constructor() {
14337
- super(...arguments);
14338
- __publicField22(this, "currentTime");
14339
- __publicField22(this, "volume");
14340
- __publicField22(this, "paused");
14341
- __publicField22(this, "muted");
14342
- __publicField22(this, "playbackRate");
14343
- __publicField22(this, "loop");
14344
- }
14345
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
14346
- attachShadow(_init) {
14347
- throw new Error(
14348
- `RRDomException: Failed to execute 'attachShadow' on 'RRElement': This RRElement does not support attachShadow`
14349
- );
14350
- }
14351
- play() {
14352
- this.paused = false;
14353
- }
14354
- pause() {
14355
- this.paused = true;
14356
- }
14357
- }
14358
- class BaseRRDialogElement extends BaseRRElement {
14359
- constructor() {
14360
- super(...arguments);
14361
- __publicField22(this, "tagName", "DIALOG");
14362
- __publicField22(this, "nodeName", "DIALOG");
14363
- }
14364
- get isModal() {
14365
- return this.getAttribute("rr_open_mode") === "modal";
14366
- }
14367
- get open() {
14368
- return this.getAttribute("open") !== null;
14369
- }
14370
- close() {
14371
- this.removeAttribute("open");
14372
- this.removeAttribute("rr_open_mode");
14373
- }
14374
- show() {
14375
- this.setAttribute("open", "");
14376
- this.setAttribute("rr_open_mode", "non-modal");
14377
- }
14378
- showModal() {
14379
- this.setAttribute("open", "");
14380
- this.setAttribute("rr_open_mode", "modal");
14381
- }
14382
- }
14383
- class BaseRRText extends BaseRRNode {
14384
- constructor(data) {
14385
- super();
14386
- __publicField22(this, "nodeType", 3);
14387
- __publicField22(this, "nodeName", "#text");
14388
- __publicField22(this, "RRNodeType", NodeType$1.Text);
14389
- __publicField22(this, "data");
14390
- this.data = data;
14391
- }
14392
- get textContent() {
14393
- return this.data;
14394
- }
14395
- set textContent(textContent2) {
14396
- this.data = textContent2;
14397
- }
14398
- toString() {
14399
- return `RRText text=${JSON.stringify(this.data)}`;
14400
- }
14401
- }
14402
- class BaseRRComment extends BaseRRNode {
14403
- constructor(data) {
14404
- super();
14405
- __publicField22(this, "nodeType", 8);
14406
- __publicField22(this, "nodeName", "#comment");
14407
- __publicField22(this, "RRNodeType", NodeType$1.Comment);
14408
- __publicField22(this, "data");
14409
- this.data = data;
14410
- }
14411
- get textContent() {
14412
- return this.data;
14413
- }
14414
- set textContent(textContent2) {
14415
- this.data = textContent2;
14416
- }
14417
- toString() {
14418
- return `RRComment text=${JSON.stringify(this.data)}`;
14419
- }
14420
- }
14421
- class BaseRRCDATASection extends BaseRRNode {
14422
- constructor(data) {
14423
- super();
14424
- __publicField22(this, "nodeName", "#cdata-section");
14425
- __publicField22(this, "nodeType", 4);
14426
- __publicField22(this, "RRNodeType", NodeType$1.CDATA);
14427
- __publicField22(this, "data");
14428
- this.data = data;
14429
- }
14430
- get textContent() {
14431
- return this.data;
14432
- }
14433
- set textContent(textContent2) {
14434
- this.data = textContent2;
14435
- }
14436
- toString() {
14437
- return `RRCDATASection data=${JSON.stringify(this.data)}`;
14438
- }
14439
- }
14440
- class ClassList {
14441
- constructor(classText, onChange) {
14442
- __publicField22(this, "onChange");
14443
- __publicField22(this, "classes", []);
14444
- __publicField22(this, "add", (...classNames) => {
14445
- for (const item of classNames) {
14446
- const className = String(item);
14447
- if (this.classes.indexOf(className) >= 0) continue;
14448
- this.classes.push(className);
14449
- }
14450
- this.onChange && this.onChange(this.classes.join(" "));
14451
- });
14452
- __publicField22(this, "remove", (...classNames) => {
14453
- this.classes = this.classes.filter(
14454
- (item) => classNames.indexOf(item) === -1
14455
- );
14456
- this.onChange && this.onChange(this.classes.join(" "));
14457
- });
14458
- if (classText) {
14459
- const classes = classText.trim().split(/\s+/);
14460
- this.classes.push(...classes);
14461
- }
14462
- this.onChange = onChange;
14463
- }
14464
- }
14465
- function appendChild(parent, newChild) {
14466
- if (newChild.parentNode) newChild.parentNode.removeChild(newChild);
14467
- if (parent.lastChild) {
14468
- parent.lastChild.nextSibling = newChild;
14469
- newChild.previousSibling = parent.lastChild;
14470
- } else {
14471
- parent.firstChild = newChild;
14472
- newChild.previousSibling = null;
14473
- }
14474
- parent.lastChild = newChild;
14475
- newChild.nextSibling = null;
14476
- newChild.parentNode = parent;
14477
- newChild.parentElement = parent;
14478
- newChild.ownerDocument = parent.ownerDocument;
14479
- return newChild;
14480
- }
14481
- function insertBefore(parent, newChild, refChild) {
14482
- if (!refChild) return appendChild(parent, newChild);
14483
- if (refChild.parentNode !== parent)
14484
- throw new Error(
14485
- "Failed to execute 'insertBefore' on 'RRNode': The RRNode before which the new node is to be inserted is not a child of this RRNode."
14486
- );
14487
- if (newChild === refChild) return newChild;
14488
- if (newChild.parentNode) newChild.parentNode.removeChild(newChild);
14489
- newChild.previousSibling = refChild.previousSibling;
14490
- refChild.previousSibling = newChild;
14491
- newChild.nextSibling = refChild;
14492
- if (newChild.previousSibling) newChild.previousSibling.nextSibling = newChild;
14493
- else parent.firstChild = newChild;
14494
- newChild.parentElement = parent;
14495
- newChild.parentNode = parent;
14496
- newChild.ownerDocument = parent.ownerDocument;
14497
- return newChild;
14498
- }
14499
- function removeChild(parent, child2) {
14500
- if (child2.parentNode !== parent)
14501
- throw new Error(
14502
- "Failed to execute 'removeChild' on 'RRNode': The RRNode to be removed is not a child of this RRNode."
14503
- );
14504
- if (child2.previousSibling)
14505
- child2.previousSibling.nextSibling = child2.nextSibling;
14506
- else parent.firstChild = child2.nextSibling;
14507
- if (child2.nextSibling)
14508
- child2.nextSibling.previousSibling = child2.previousSibling;
14509
- else parent.lastChild = child2.previousSibling;
14510
- child2.previousSibling = null;
14511
- child2.nextSibling = null;
14512
- child2.parentElement = null;
14513
- child2.parentNode = null;
14514
- return child2;
14515
- }
14516
- var NodeType$2 = /* @__PURE__ */ ((NodeType2) => {
14517
- NodeType2[NodeType2["PLACEHOLDER"] = 0] = "PLACEHOLDER";
14518
- NodeType2[NodeType2["ELEMENT_NODE"] = 1] = "ELEMENT_NODE";
14519
- NodeType2[NodeType2["ATTRIBUTE_NODE"] = 2] = "ATTRIBUTE_NODE";
14520
- NodeType2[NodeType2["TEXT_NODE"] = 3] = "TEXT_NODE";
14521
- NodeType2[NodeType2["CDATA_SECTION_NODE"] = 4] = "CDATA_SECTION_NODE";
14522
- NodeType2[NodeType2["ENTITY_REFERENCE_NODE"] = 5] = "ENTITY_REFERENCE_NODE";
14523
- NodeType2[NodeType2["ENTITY_NODE"] = 6] = "ENTITY_NODE";
14524
- NodeType2[NodeType2["PROCESSING_INSTRUCTION_NODE"] = 7] = "PROCESSING_INSTRUCTION_NODE";
14525
- NodeType2[NodeType2["COMMENT_NODE"] = 8] = "COMMENT_NODE";
14526
- NodeType2[NodeType2["DOCUMENT_NODE"] = 9] = "DOCUMENT_NODE";
14527
- NodeType2[NodeType2["DOCUMENT_TYPE_NODE"] = 10] = "DOCUMENT_TYPE_NODE";
14528
- NodeType2[NodeType2["DOCUMENT_FRAGMENT_NODE"] = 11] = "DOCUMENT_FRAGMENT_NODE";
14529
- return NodeType2;
14530
- })(NodeType$2 || {});
14531
- const NAMESPACES = {
14532
- svg: "http://www.w3.org/2000/svg",
14533
- "xlink:href": "http://www.w3.org/1999/xlink",
14534
- xmlns: "http://www.w3.org/2000/xmlns/"
14535
- };
14536
- const SVGTagMap = {
14537
- altglyph: "altGlyph",
14538
- altglyphdef: "altGlyphDef",
14539
- altglyphitem: "altGlyphItem",
14540
- animatecolor: "animateColor",
14541
- animatemotion: "animateMotion",
14542
- animatetransform: "animateTransform",
14543
- clippath: "clipPath",
14544
- feblend: "feBlend",
14545
- fecolormatrix: "feColorMatrix",
14546
- fecomponenttransfer: "feComponentTransfer",
14547
- fecomposite: "feComposite",
14548
- feconvolvematrix: "feConvolveMatrix",
14549
- fediffuselighting: "feDiffuseLighting",
14550
- fedisplacementmap: "feDisplacementMap",
14551
- fedistantlight: "feDistantLight",
14552
- fedropshadow: "feDropShadow",
14553
- feflood: "feFlood",
14554
- fefunca: "feFuncA",
14555
- fefuncb: "feFuncB",
14556
- fefuncg: "feFuncG",
14557
- fefuncr: "feFuncR",
14558
- fegaussianblur: "feGaussianBlur",
14559
- feimage: "feImage",
14560
- femerge: "feMerge",
14561
- femergenode: "feMergeNode",
14562
- femorphology: "feMorphology",
14563
- feoffset: "feOffset",
14564
- fepointlight: "fePointLight",
14565
- fespecularlighting: "feSpecularLighting",
14566
- fespotlight: "feSpotLight",
14567
- fetile: "feTile",
14568
- feturbulence: "feTurbulence",
14569
- foreignobject: "foreignObject",
14570
- glyphref: "glyphRef",
14571
- lineargradient: "linearGradient",
14572
- radialgradient: "radialGradient"
14573
- };
14574
- let createdNodeSet = null;
14575
- function diff(oldTree, newTree, replayer, rrnodeMirror = newTree.mirror || newTree.ownerDocument.mirror) {
14576
- oldTree = diffBeforeUpdatingChildren(
14577
- oldTree,
14578
- newTree,
14579
- replayer,
14580
- rrnodeMirror
14581
- );
14582
- diffChildren(oldTree, newTree, replayer, rrnodeMirror);
14583
- diffAfterUpdatingChildren(oldTree, newTree, replayer);
14584
- }
14585
- function diffBeforeUpdatingChildren(oldTree, newTree, replayer, rrnodeMirror) {
14586
- var _a22;
14587
- if (replayer.afterAppend && !createdNodeSet) {
14588
- createdNodeSet = /* @__PURE__ */ new WeakSet();
14589
- setTimeout(() => {
14590
- createdNodeSet = null;
14591
- }, 0);
14592
- }
14593
- if (!sameNodeType(oldTree, newTree)) {
14594
- const calibratedOldTree = createOrGetNode(
14595
- newTree,
14596
- replayer.mirror,
14597
- rrnodeMirror
14598
- );
14599
- (_a22 = oldTree.parentNode) == null ? void 0 : _a22.replaceChild(calibratedOldTree, oldTree);
14600
- oldTree = calibratedOldTree;
14601
- }
14602
- switch (newTree.RRNodeType) {
14603
- case NodeType$1.Document: {
14604
- if (!nodeMatching(oldTree, newTree, replayer.mirror, rrnodeMirror)) {
14605
- const newMeta = rrnodeMirror.getMeta(newTree);
14606
- if (newMeta) {
14607
- replayer.mirror.removeNodeFromMap(oldTree);
14608
- oldTree.close();
14609
- oldTree.open();
14610
- replayer.mirror.add(oldTree, newMeta);
14611
- createdNodeSet == null ? void 0 : createdNodeSet.add(oldTree);
14612
- }
14613
- }
14614
- break;
14615
- }
14616
- case NodeType$1.Element: {
14617
- const oldElement = oldTree;
14618
- const newRRElement = newTree;
14619
- switch (newRRElement.tagName) {
14620
- case "IFRAME": {
14621
- const oldContentDocument = oldTree.contentDocument;
14622
- if (!oldContentDocument) break;
14623
- diff(
14624
- oldContentDocument,
14625
- newTree.contentDocument,
14626
- replayer,
14627
- rrnodeMirror
14628
- );
14629
- break;
14630
- }
14631
- }
14632
- if (newRRElement.shadowRoot) {
14633
- if (!oldElement.shadowRoot) oldElement.attachShadow({ mode: "open" });
14634
- diffChildren(
14635
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
14636
- oldElement.shadowRoot,
14637
- newRRElement.shadowRoot,
14638
- replayer,
14639
- rrnodeMirror
14640
- );
14641
- }
14642
- diffProps(oldElement, newRRElement, rrnodeMirror);
14643
- break;
14120
+ diffProps(oldElement, newRRElement, rrnodeMirror);
14121
+ break;
14644
14122
  }
14645
14123
  }
14646
14124
  return oldTree;
@@ -14802,7 +14280,13 @@ function diffChildren(oldTree, newTree, replayer, rrnodeMirror) {
14802
14280
  nodeMatching(oldStartNode, newEndNode, replayer.mirror, rrnodeMirror)
14803
14281
  ) {
14804
14282
  try {
14805
- oldTree.insertBefore(oldStartNode, oldEndNode.nextSibling);
14283
+ insertPreservingCSSOM(
14284
+ oldTree,
14285
+ oldStartNode,
14286
+ oldEndNode.nextSibling,
14287
+ replayer.mirror,
14288
+ rrnodeMirror
14289
+ );
14806
14290
  } catch (e2) {
14807
14291
  console.warn(e2);
14808
14292
  }
@@ -14813,7 +14297,13 @@ function diffChildren(oldTree, newTree, replayer, rrnodeMirror) {
14813
14297
  nodeMatching(oldEndNode, newStartNode, replayer.mirror, rrnodeMirror)
14814
14298
  ) {
14815
14299
  try {
14816
- oldTree.insertBefore(oldEndNode, oldStartNode);
14300
+ insertPreservingCSSOM(
14301
+ oldTree,
14302
+ oldEndNode,
14303
+ oldStartNode,
14304
+ replayer.mirror,
14305
+ rrnodeMirror
14306
+ );
14817
14307
  } catch (e2) {
14818
14308
  console.warn(e2);
14819
14309
  }
@@ -14832,7 +14322,13 @@ function diffChildren(oldTree, newTree, replayer, rrnodeMirror) {
14832
14322
  const nodeToMove = oldChildren[indexInOld];
14833
14323
  if (indexInOld !== void 0 && nodeToMove && nodeMatching(nodeToMove, newStartNode, replayer.mirror, rrnodeMirror)) {
14834
14324
  try {
14835
- oldTree.insertBefore(nodeToMove, oldStartNode);
14325
+ insertPreservingCSSOM(
14326
+ oldTree,
14327
+ nodeToMove,
14328
+ oldStartNode,
14329
+ replayer.mirror,
14330
+ rrnodeMirror
14331
+ );
14836
14332
  } catch (e2) {
14837
14333
  console.warn(e2);
14838
14334
  }
@@ -14843,119 +14339,709 @@ function diffChildren(oldTree, newTree, replayer, rrnodeMirror) {
14843
14339
  replayer.mirror,
14844
14340
  rrnodeMirror
14845
14341
  );
14846
- if (oldTree.nodeName === "#document" && oldStartNode && /**
14847
- * 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.
14848
- * 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.
14849
- */
14850
- (newNode.nodeType === newNode.DOCUMENT_TYPE_NODE && oldStartNode.nodeType === oldStartNode.DOCUMENT_TYPE_NODE || /**
14851
- * 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.
14852
- * 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.
14853
- */
14854
- newNode.nodeType === newNode.ELEMENT_NODE && oldStartNode.nodeType === oldStartNode.ELEMENT_NODE)) {
14855
- oldTree.removeChild(oldStartNode);
14856
- replayer.mirror.removeNodeFromMap(oldStartNode);
14857
- oldStartNode = oldChildren[++oldStartIndex];
14858
- }
14859
- try {
14860
- oldTree.insertBefore(newNode, oldStartNode || null);
14861
- } catch (e2) {
14862
- console.warn(e2);
14863
- }
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
+ );
14864
14652
  }
14865
- newStartNode = newChildren[++newStartIndex];
14866
14653
  }
14654
+ const child2 = appendChild(this, newChild);
14655
+ child2.parentElement = null;
14656
+ return child2;
14867
14657
  }
14868
- if (oldStartIndex > oldEndIndex) {
14869
- const referenceRRNode = newChildren[newEndIndex + 1];
14870
- let referenceNode = null;
14871
- if (referenceRRNode)
14872
- referenceNode = replayer.mirror.getNode(
14873
- rrnodeMirror.getId(referenceRRNode)
14874
- );
14875
- for (; newStartIndex <= newEndIndex; ++newStartIndex) {
14876
- const newNode = createOrGetNode(
14877
- newChildren[newStartIndex],
14878
- replayer.mirror,
14879
- rrnodeMirror
14880
- );
14881
- try {
14882
- oldTree.insertBefore(newNode, referenceNode);
14883
- } catch (e2) {
14884
- 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
+ );
14885
14665
  }
14886
14666
  }
14887
- } else if (newStartIndex > newEndIndex) {
14888
- for (; oldStartIndex <= oldEndIndex; oldStartIndex++) {
14889
- const node2 = oldChildren[oldStartIndex];
14890
- if (!node2 || node2.parentNode !== oldTree) continue;
14891
- try {
14892
- oldTree.removeChild(node2);
14893
- replayer.mirror.removeNodeFromMap(node2);
14894
- } catch (e2) {
14895
- 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;
14896
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]}" `;
14897
14845
  }
14846
+ return `${this.tagName} ${attributeString}`;
14898
14847
  }
14899
- let oldChild = oldTree.firstChild;
14900
- let newChild = newTree.firstChild;
14901
- while (oldChild !== null && newChild !== null) {
14902
- diff(oldChild, newChild, replayer, rrnodeMirror);
14903
- oldChild = oldChild.nextSibling;
14904
- 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;
14905
14870
  }
14906
14871
  }
14907
- function createOrGetNode(rrNode, domMirror, rrnodeMirror) {
14908
- const nodeId = rrnodeMirror.getId(rrNode);
14909
- const sn = rrnodeMirror.getMeta(rrNode);
14910
- let node2 = null;
14911
- if (nodeId > -1) node2 = domMirror.getNode(nodeId);
14912
- if (node2 !== null && sameNodeType(node2, rrNode)) return node2;
14913
- switch (rrNode.RRNodeType) {
14914
- case NodeType$1.Document:
14915
- node2 = new Document();
14916
- break;
14917
- case NodeType$1.DocumentType:
14918
- node2 = document.implementation.createDocumentType(
14919
- rrNode.name,
14920
- rrNode.publicId,
14921
- 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
14922
14969
  );
14923
- break;
14924
- case NodeType$1.Element: {
14925
- let tagName = rrNode.tagName.toLowerCase();
14926
- tagName = SVGTagMap[tagName] || tagName;
14927
- if (sn && "isSVG" in sn && (sn == null ? void 0 : sn.isSVG)) {
14928
- node2 = document.createElementNS(NAMESPACES["svg"], tagName);
14929
- } else node2 = document.createElement(rrNode.tagName);
14930
- 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);
14931
14975
  }
14932
- case NodeType$1.Text:
14933
- node2 = document.createTextNode(rrNode.data);
14934
- break;
14935
- case NodeType$1.Comment:
14936
- node2 = document.createComment(rrNode.data);
14937
- break;
14938
- case NodeType$1.CDATA:
14939
- node2 = document.createCDATASection(rrNode.data);
14940
- break;
14976
+ this.onChange = onChange;
14941
14977
  }
14942
- if (sn) domMirror.add(node2, __spreadValues({}, sn));
14943
- try {
14944
- createdNodeSet == null ? void 0 : createdNodeSet.add(node2);
14945
- } 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;
14946
14987
  }
14947
- 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;
14948
14994
  }
14949
- function sameNodeType(node1, node2) {
14950
- if (node1.nodeType !== node2.nodeType) return false;
14951
- 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;
14952
15012
  }
14953
- function nodeMatching(node1, node2, domMirror, rrdomMirror) {
14954
- const node1Id = domMirror.getId(node1);
14955
- const node2Id = rrdomMirror.getId(node2);
14956
- if (node1Id === -1 || node1Id !== node2Id) return false;
14957
- 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;
14958
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 || {});
14959
15045
  class RRDocument extends BaseRRDocument {
14960
15046
  constructor(mirror2) {
14961
15047
  super();
@@ -15140,6 +15226,7 @@ function buildFromNode(node2, rrdom, domMirror, parentRRNode) {
15140
15226
  }
15141
15227
  rrdom.mirror.add(rrNode, __spreadValues({}, sn));
15142
15228
  }
15229
+ nodesBuiltFromDom.add(rrNode);
15143
15230
  return rrNode;
15144
15231
  }
15145
15232
  function buildFromDom(dom, domMirror = createMirror$1(), rrdom = new RRDocument()) {
@@ -15535,15 +15622,12 @@ function hasShadowRoot(n2) {
15535
15622
  return Boolean(index.shadowRoot(n2));
15536
15623
  }
15537
15624
  function getNestedRule(rules2, position) {
15538
- const rule2 = rules2[position[0]];
15539
- if (position.length === 1) {
15540
- return rule2;
15541
- } else {
15542
- return getNestedRule(
15543
- rule2.cssRules[position[1]].cssRules,
15544
- position.slice(2)
15545
- );
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]];
15546
15629
  }
15630
+ return rule2;
15547
15631
  }
15548
15632
  function getPositionsAndIndex(nestedIndex) {
15549
15633
  const positions = [...nestedIndex];
@@ -18221,8 +18305,12 @@ class Replayer {
18221
18305
  case IncrementalSource.StyleDeclaration: {
18222
18306
  if (this.usingVirtualDom) {
18223
18307
  if (d.styleId) this.constructedStyleMutations.push(d);
18224
- else if (d.id)
18225
- (_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
+ }
18226
18314
  } else this.applyStyleSheetMutation(d);
18227
18315
  break;
18228
18316
  }
@@ -18544,6 +18632,22 @@ class Replayer {
18544
18632
  }
18545
18633
  }
18546
18634
  if (queue.length === pendingCount) {
18635
+ const queuedIds = new Set(queue.map((m) => m.node.id));
18636
+ let salvaged = 0;
18637
+ for (let i2 = 0; i2 < queue.length; i2++) {
18638
+ const m = queue[i2];
18639
+ if (!mirror2.getNode(m.node.id) && mirror2.getNode(m.parentId) && m.nextId !== null && m.nextId !== void 0 && m.nextId !== -1 && !mirror2.getNode(m.nextId) && !queuedIds.has(m.nextId)) {
18640
+ queue[i2] = __spreadProps(__spreadValues({}, m), { nextId: null });
18641
+ salvaged++;
18642
+ }
18643
+ }
18644
+ if (salvaged) {
18645
+ this.warn(
18646
+ "Inserting nodes without their next sibling since it was never recorded",
18647
+ salvaged
18648
+ );
18649
+ continue;
18650
+ }
18547
18651
  this.warn(
18548
18652
  "Dropping the resolve queue since none of the remaining nodes can be resolved",
18549
18653
  resolveTrees.map((tree) => ({
@@ -18795,11 +18899,9 @@ class Replayer {
18795
18899
  }
18796
18900
  }
18797
18901
  applyStyleDeclaration(data, styleSheet) {
18902
+ const rule2 = getNestedRule(styleSheet.cssRules, data.index);
18903
+ if (!(rule2 == null ? void 0 : rule2.style)) return;
18798
18904
  if (data.set) {
18799
- const rule2 = getNestedRule(
18800
- styleSheet.rules,
18801
- data.index
18802
- );
18803
18905
  rule2.style.setProperty(
18804
18906
  data.set.property,
18805
18907
  data.set.value,
@@ -18807,10 +18909,6 @@ class Replayer {
18807
18909
  );
18808
18910
  }
18809
18911
  if (data.remove) {
18810
- const rule2 = getNestedRule(
18811
- styleSheet.rules,
18812
- data.index
18813
- );
18814
18912
  rule2.style.removeProperty(data.remove.property);
18815
18913
  }
18816
18914
  }