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