@posthog/rrdom 0.0.36 → 0.0.38

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.
package/dist/rrdom.cjs CHANGED
@@ -6,6 +6,184 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
6
6
  var __defProp2 = Object.defineProperty;
7
7
  var __defNormalProp2 = (obj, key, value) => key in obj ? __defProp2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
8
8
  var __publicField2 = (obj, key, value) => __defNormalProp2(obj, typeof key !== "symbol" ? key + "" : key, value);
9
+ const testableAccessors = {
10
+ Node: ["childNodes", "parentNode", "parentElement", "textContent"],
11
+ ShadowRoot: ["host", "styleSheets"],
12
+ Element: ["shadowRoot", "querySelector", "querySelectorAll"],
13
+ MutationObserver: []
14
+ };
15
+ const testableMethods = {
16
+ Node: ["contains", "getRootNode"],
17
+ ShadowRoot: ["getSelection"],
18
+ Element: [],
19
+ MutationObserver: ["constructor"]
20
+ };
21
+ const untaintedBasePrototype = {};
22
+ function angularZoneUnpatchedAlternative(key) {
23
+ var _a, _b;
24
+ const angularUnpatchedVersionSymbol = (_b = (_a = globalThis == null ? void 0 : globalThis.Zone) == null ? void 0 : _a.__symbol__) == null ? void 0 : _b.call(_a, key);
25
+ if (angularUnpatchedVersionSymbol && globalThis[angularUnpatchedVersionSymbol]) {
26
+ return globalThis[angularUnpatchedVersionSymbol];
27
+ } else {
28
+ return void 0;
29
+ }
30
+ }
31
+ function getUntaintedPrototype(key) {
32
+ if (untaintedBasePrototype[key])
33
+ return untaintedBasePrototype[key];
34
+ const candidate = angularZoneUnpatchedAlternative(key) || globalThis[key];
35
+ const defaultPrototype = candidate.prototype;
36
+ const accessorNames = key in testableAccessors ? testableAccessors[key] : void 0;
37
+ const isUntaintedAccessors = Boolean(
38
+ accessorNames && // @ts-expect-error 2345
39
+ accessorNames.every(
40
+ (accessor) => {
41
+ var _a, _b;
42
+ return Boolean(
43
+ (_b = (_a = Object.getOwnPropertyDescriptor(defaultPrototype, accessor)) == null ? void 0 : _a.get) == null ? void 0 : _b.toString().includes("[native code]")
44
+ );
45
+ }
46
+ )
47
+ );
48
+ const methodNames = key in testableMethods ? testableMethods[key] : void 0;
49
+ const isUntaintedMethods = Boolean(
50
+ methodNames && methodNames.every(
51
+ // @ts-expect-error 2345
52
+ (method) => {
53
+ var _a;
54
+ return typeof defaultPrototype[method] === "function" && ((_a = defaultPrototype[method]) == null ? void 0 : _a.toString().includes("[native code]"));
55
+ }
56
+ )
57
+ );
58
+ if (isUntaintedAccessors && isUntaintedMethods) {
59
+ untaintedBasePrototype[key] = candidate.prototype;
60
+ return candidate.prototype;
61
+ }
62
+ try {
63
+ const iframeEl = document.createElement("iframe");
64
+ document.body.appendChild(iframeEl);
65
+ const win = iframeEl.contentWindow;
66
+ if (!win) return candidate.prototype;
67
+ const untaintedObject = win[key].prototype;
68
+ document.body.removeChild(iframeEl);
69
+ if (!untaintedObject) return defaultPrototype;
70
+ return untaintedBasePrototype[key] = untaintedObject;
71
+ } catch {
72
+ return defaultPrototype;
73
+ }
74
+ }
75
+ const untaintedAccessorCache = {};
76
+ function getUntaintedAccessor(key, instance, accessor) {
77
+ var _a;
78
+ const cacheKey = `${key}.${String(accessor)}`;
79
+ if (untaintedAccessorCache[cacheKey])
80
+ return untaintedAccessorCache[cacheKey].call(
81
+ instance
82
+ );
83
+ const untaintedPrototype = getUntaintedPrototype(key);
84
+ const untaintedAccessor = (_a = Object.getOwnPropertyDescriptor(
85
+ untaintedPrototype,
86
+ accessor
87
+ )) == null ? void 0 : _a.get;
88
+ if (!untaintedAccessor) return instance[accessor];
89
+ untaintedAccessorCache[cacheKey] = untaintedAccessor;
90
+ return untaintedAccessor.call(instance);
91
+ }
92
+ const untaintedMethodCache = {};
93
+ function getUntaintedMethod(key, instance, method) {
94
+ const cacheKey = `${key}.${String(method)}`;
95
+ if (untaintedMethodCache[cacheKey])
96
+ return untaintedMethodCache[cacheKey].bind(
97
+ instance
98
+ );
99
+ const untaintedPrototype = getUntaintedPrototype(key);
100
+ const untaintedMethod = untaintedPrototype[method];
101
+ if (typeof untaintedMethod !== "function") return instance[method];
102
+ untaintedMethodCache[cacheKey] = untaintedMethod;
103
+ return untaintedMethod.bind(instance);
104
+ }
105
+ function childNodes(n) {
106
+ return getUntaintedAccessor("Node", n, "childNodes");
107
+ }
108
+ function parentNode(n) {
109
+ return getUntaintedAccessor("Node", n, "parentNode");
110
+ }
111
+ function parentElement(n) {
112
+ return getUntaintedAccessor("Node", n, "parentElement");
113
+ }
114
+ function textContent(n) {
115
+ return getUntaintedAccessor("Node", n, "textContent");
116
+ }
117
+ function contains(n, other) {
118
+ return getUntaintedMethod("Node", n, "contains")(other);
119
+ }
120
+ function getRootNode(n) {
121
+ return getUntaintedMethod("Node", n, "getRootNode")();
122
+ }
123
+ function host(n) {
124
+ if (!n || !("host" in n)) return null;
125
+ return getUntaintedAccessor("ShadowRoot", n, "host");
126
+ }
127
+ function styleSheets(n) {
128
+ return n.styleSheets;
129
+ }
130
+ function shadowRoot(n) {
131
+ if (!n || !("shadowRoot" in n)) return null;
132
+ return getUntaintedAccessor("Element", n, "shadowRoot");
133
+ }
134
+ function querySelector(n, selectors) {
135
+ return getUntaintedAccessor("Element", n, "querySelector")(selectors);
136
+ }
137
+ function querySelectorAll(n, selectors) {
138
+ return getUntaintedAccessor("Element", n, "querySelectorAll")(selectors);
139
+ }
140
+ function mutationObserverCtor() {
141
+ return getUntaintedPrototype("MutationObserver").constructor;
142
+ }
143
+ function patch(source, name, replacement) {
144
+ try {
145
+ if (!(name in source)) {
146
+ return () => {
147
+ };
148
+ }
149
+ const original = source[name];
150
+ const wrapped = replacement(original);
151
+ if (typeof wrapped === "function") {
152
+ wrapped.prototype = wrapped.prototype || {};
153
+ Object.defineProperties(wrapped, {
154
+ __rrweb_original__: {
155
+ enumerable: false,
156
+ value: original
157
+ }
158
+ });
159
+ }
160
+ source[name] = wrapped;
161
+ return () => {
162
+ source[name] = original;
163
+ };
164
+ } catch {
165
+ return () => {
166
+ };
167
+ }
168
+ }
169
+ const index = {
170
+ childNodes,
171
+ parentNode,
172
+ parentElement,
173
+ textContent,
174
+ contains,
175
+ getRootNode,
176
+ host,
177
+ styleSheets,
178
+ shadowRoot,
179
+ querySelector,
180
+ querySelectorAll,
181
+ mutationObserver: mutationObserverCtor,
182
+ patch
183
+ };
184
+ function isElement(n) {
185
+ return n.nodeType === n.ELEMENT_NODE;
186
+ }
9
187
  let Mirror$1 = class Mirror {
10
188
  constructor() {
11
189
  __publicField2(this, "idNodeMap", /* @__PURE__ */ new Map());
@@ -36,6 +214,17 @@ let Mirror$1 = class Mirror {
36
214
  (childNode) => this.removeNodeFromMap(childNode)
37
215
  );
38
216
  }
217
+ if (isElement(n)) {
218
+ const shadowRootEl = index.shadowRoot(n);
219
+ if (shadowRootEl) {
220
+ this.removeNodeFromMap(shadowRootEl);
221
+ }
222
+ if (n.nodeName === "IFRAME" && n.contentDocument) {
223
+ this.removeNodeFromMap(
224
+ n.contentDocument
225
+ );
226
+ }
227
+ }
39
228
  }
40
229
  has(id) {
41
230
  return this.idNodeMap.has(id);
@@ -174,8 +363,8 @@ function requireCssSyntaxError() {
174
363
  let start = Math.max(this.line - 3, 0);
175
364
  let end = Math.min(this.line + 2, lines.length);
176
365
  let maxWidth = String(end).length;
177
- return lines.slice(start, end).map((line, index) => {
178
- let number = start + 1 + index;
366
+ return lines.slice(start, end).map((line, index2) => {
367
+ let number = start + 1 + index2;
179
368
  let gutter = " " + (" " + number).slice(-maxWidth) + " | ";
180
369
  if (number === this.line) {
181
370
  if (line.length > 160) {
@@ -705,8 +894,8 @@ function requireNode() {
705
894
  }
706
895
  next() {
707
896
  if (!this.parent) return void 0;
708
- let index = this.parent.index(this);
709
- return this.parent.nodes[index + 1];
897
+ let index2 = this.parent.index(this);
898
+ return this.parent.nodes[index2 + 1];
710
899
  }
711
900
  positionBy(opts = {}) {
712
901
  let pos = this.source.start;
@@ -718,17 +907,17 @@ function requireNode() {
718
907
  sourceOffset(inputString, this.source.start),
719
908
  sourceOffset(inputString, this.source.end)
720
909
  );
721
- let index = stringRepresentation.indexOf(opts.word);
722
- if (index !== -1) pos = this.positionInside(index);
910
+ let index2 = stringRepresentation.indexOf(opts.word);
911
+ if (index2 !== -1) pos = this.positionInside(index2);
723
912
  }
724
913
  return pos;
725
914
  }
726
- positionInside(index) {
915
+ positionInside(index2) {
727
916
  let column = this.source.start.column;
728
917
  let line = this.source.start.line;
729
918
  let inputString = "document" in this.source.input ? this.source.input.document : this.source.input.css;
730
919
  let offset = sourceOffset(inputString, this.source.start);
731
- let end = offset + index;
920
+ let end = offset + index2;
732
921
  for (let i = offset; i < end; i++) {
733
922
  if (inputString[i] === "\n") {
734
923
  column = 1;
@@ -741,8 +930,8 @@ function requireNode() {
741
930
  }
742
931
  prev() {
743
932
  if (!this.parent) return void 0;
744
- let index = this.parent.index(this);
745
- return this.parent.nodes[index - 1];
933
+ let index2 = this.parent.index(this);
934
+ return this.parent.nodes[index2 - 1];
746
935
  }
747
936
  rangeBy(opts = {}) {
748
937
  let inputString = "document" in this.source.input ? this.source.input.document : this.source.input.css;
@@ -773,10 +962,10 @@ function requireNode() {
773
962
  sourceOffset(inputString, this.source.start),
774
963
  sourceOffset(inputString, this.source.end)
775
964
  );
776
- let index = stringRepresentation.indexOf(opts.word);
777
- if (index !== -1) {
778
- start = this.positionInside(index);
779
- end = this.positionInside(index + opts.word.length);
965
+ let index2 = stringRepresentation.indexOf(opts.word);
966
+ if (index2 !== -1) {
967
+ start = this.positionInside(index2);
968
+ end = this.positionInside(index2 + opts.word.length);
780
969
  }
781
970
  } else {
782
971
  if (opts.start) {
@@ -1003,10 +1192,10 @@ function requireContainer() {
1003
1192
  each(callback) {
1004
1193
  if (!this.proxyOf.nodes) return void 0;
1005
1194
  let iterator = this.getIterator();
1006
- let index, result2;
1195
+ let index2, result2;
1007
1196
  while (this.indexes[iterator] < this.proxyOf.nodes.length) {
1008
- index = this.indexes[iterator];
1009
- result2 = callback(this.proxyOf.nodes[index], index);
1197
+ index2 = this.indexes[iterator];
1198
+ result2 = callback(this.proxyOf.nodes[index2], index2);
1010
1199
  if (result2 === false) break;
1011
1200
  this.indexes[iterator] += 1;
1012
1201
  }
@@ -1036,7 +1225,7 @@ function requireContainer() {
1036
1225
  return node2[prop](
1037
1226
  ...args.map((i) => {
1038
1227
  if (typeof i === "function") {
1039
- return (child, index) => i(child.toProxy(), index);
1228
+ return (child, index2) => i(child.toProxy(), index2);
1040
1229
  } else {
1041
1230
  return i;
1042
1231
  }
@@ -1079,11 +1268,11 @@ function requireContainer() {
1079
1268
  let nodes = this.normalize(add, this.proxyOf.nodes[existIndex]).reverse();
1080
1269
  existIndex = this.index(exist);
1081
1270
  for (let node2 of nodes) this.proxyOf.nodes.splice(existIndex + 1, 0, node2);
1082
- let index;
1271
+ let index2;
1083
1272
  for (let id in this.indexes) {
1084
- index = this.indexes[id];
1085
- if (existIndex < index) {
1086
- this.indexes[id] = index + nodes.length;
1273
+ index2 = this.indexes[id];
1274
+ if (existIndex < index2) {
1275
+ this.indexes[id] = index2 + nodes.length;
1087
1276
  }
1088
1277
  }
1089
1278
  this.markDirty();
@@ -1099,11 +1288,11 @@ function requireContainer() {
1099
1288
  ).reverse();
1100
1289
  existIndex = this.index(exist);
1101
1290
  for (let node2 of nodes) this.proxyOf.nodes.splice(existIndex, 0, node2);
1102
- let index;
1291
+ let index2;
1103
1292
  for (let id in this.indexes) {
1104
- index = this.indexes[id];
1105
- if (existIndex <= index) {
1106
- this.indexes[id] = index + nodes.length;
1293
+ index2 = this.indexes[id];
1294
+ if (existIndex <= index2) {
1295
+ this.indexes[id] = index2 + nodes.length;
1107
1296
  }
1108
1297
  }
1109
1298
  this.markDirty();
@@ -1185,11 +1374,11 @@ function requireContainer() {
1185
1374
  child = this.index(child);
1186
1375
  this.proxyOf.nodes[child].parent = void 0;
1187
1376
  this.proxyOf.nodes.splice(child, 1);
1188
- let index;
1377
+ let index2;
1189
1378
  for (let id in this.indexes) {
1190
- index = this.indexes[id];
1191
- if (index >= child) {
1192
- this.indexes[id] = index - 1;
1379
+ index2 = this.indexes[id];
1380
+ if (index2 >= child) {
1381
+ this.indexes[id] = index2 - 1;
1193
1382
  }
1194
1383
  }
1195
1384
  this.markDirty();
@@ -1663,8 +1852,8 @@ function requireInput() {
1663
1852
  }
1664
1853
  fromLineAndColumn(line, column) {
1665
1854
  let lineToIndex = getLineToIndex(this);
1666
- let index = lineToIndex[line - 1];
1667
- return index + column - 1;
1855
+ let index2 = lineToIndex[line - 1];
1856
+ return index2 + column - 1;
1668
1857
  }
1669
1858
  fromOffset(offset) {
1670
1859
  let lineToIndex = getLineToIndex(this);
@@ -1788,9 +1977,9 @@ function requireRoot() {
1788
1977
  return nodes;
1789
1978
  }
1790
1979
  removeChild(child, ignore) {
1791
- let index = this.index(child);
1792
- if (!ignore && index === 0 && this.nodes.length > 1) {
1793
- this.nodes[1].raws.before = this.nodes[index].raws.before;
1980
+ let index2 = this.index(child);
1981
+ if (!ignore && index2 === 0 && this.nodes.length > 1) {
1982
+ this.nodes[1].raws.before = this.nodes[index2].raws.before;
1794
1983
  }
1795
1984
  return super.removeChild(child);
1796
1985
  }
@@ -4066,13 +4255,13 @@ class BaseRRNode {
4066
4255
  __publicField(this, "RRNodeType");
4067
4256
  }
4068
4257
  get childNodes() {
4069
- const childNodes = [];
4258
+ const childNodes2 = [];
4070
4259
  let childIterator = this.firstChild;
4071
4260
  while (childIterator) {
4072
- childNodes.push(childIterator);
4261
+ childNodes2.push(childIterator);
4073
4262
  childIterator = childIterator.nextSibling;
4074
4263
  }
4075
- return childNodes;
4264
+ return childNodes2;
4076
4265
  }
4077
4266
  contains(node2) {
4078
4267
  if (!(node2 instanceof BaseRRNode)) return false;
@@ -4264,10 +4453,10 @@ class BaseRRElement extends BaseRRNode {
4264
4453
  this.childNodes.forEach((node2) => result2 += node2.textContent);
4265
4454
  return result2;
4266
4455
  }
4267
- set textContent(textContent) {
4456
+ set textContent(textContent2) {
4268
4457
  this.firstChild = null;
4269
4458
  this.lastChild = null;
4270
- this.appendChild(this.ownerDocument.createTextNode(textContent));
4459
+ this.appendChild(this.ownerDocument.createTextNode(textContent2));
4271
4460
  }
4272
4461
  get classList() {
4273
4462
  return new ClassList(
@@ -4328,9 +4517,9 @@ class BaseRRElement extends BaseRRNode {
4328
4517
  }
4329
4518
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
4330
4519
  attachShadow(_init) {
4331
- const shadowRoot = this.ownerDocument.createElement("SHADOWROOT");
4332
- this.shadowRoot = shadowRoot;
4333
- return shadowRoot;
4520
+ const shadowRoot2 = this.ownerDocument.createElement("SHADOWROOT");
4521
+ this.shadowRoot = shadowRoot2;
4522
+ return shadowRoot2;
4334
4523
  }
4335
4524
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
4336
4525
  dispatchEvent(_event) {
@@ -4404,8 +4593,8 @@ class BaseRRText extends BaseRRNode {
4404
4593
  get textContent() {
4405
4594
  return this.data;
4406
4595
  }
4407
- set textContent(textContent) {
4408
- this.data = textContent;
4596
+ set textContent(textContent2) {
4597
+ this.data = textContent2;
4409
4598
  }
4410
4599
  toString() {
4411
4600
  return `RRText text=${JSON.stringify(this.data)}`;
@@ -4423,8 +4612,8 @@ class BaseRRComment extends BaseRRNode {
4423
4612
  get textContent() {
4424
4613
  return this.data;
4425
4614
  }
4426
- set textContent(textContent) {
4427
- this.data = textContent;
4615
+ set textContent(textContent2) {
4616
+ this.data = textContent2;
4428
4617
  }
4429
4618
  toString() {
4430
4619
  return `RRComment text=${JSON.stringify(this.data)}`;
@@ -4442,8 +4631,8 @@ class BaseRRCDATASection extends BaseRRNode {
4442
4631
  get textContent() {
4443
4632
  return this.data;
4444
4633
  }
4445
- set textContent(textContent) {
4446
- this.data = textContent;
4634
+ set textContent(textContent2) {
4635
+ this.data = textContent2;
4447
4636
  }
4448
4637
  toString() {
4449
4638
  return `RRCDATASection data=${JSON.stringify(this.data)}`;