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