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