@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.
@@ -38,6 +38,184 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
38
38
  var __defProp22 = Object.defineProperty;
39
39
  var __defNormalProp22 = (obj, key, value) => key in obj ? __defProp22(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
40
40
  var __publicField2 = (obj, key, value) => __defNormalProp22(obj, typeof key !== "symbol" ? key + "" : key, value);
41
+ const testableAccessors = {
42
+ Node: ["childNodes", "parentNode", "parentElement", "textContent"],
43
+ ShadowRoot: ["host", "styleSheets"],
44
+ Element: ["shadowRoot", "querySelector", "querySelectorAll"],
45
+ MutationObserver: []
46
+ };
47
+ const testableMethods = {
48
+ Node: ["contains", "getRootNode"],
49
+ ShadowRoot: ["getSelection"],
50
+ Element: [],
51
+ MutationObserver: ["constructor"]
52
+ };
53
+ const untaintedBasePrototype = {};
54
+ function angularZoneUnpatchedAlternative(key) {
55
+ var _a, _b;
56
+ const angularUnpatchedVersionSymbol = (_b = (_a = globalThis == null ? void 0 : globalThis.Zone) == null ? void 0 : _a.__symbol__) == null ? void 0 : _b.call(_a, key);
57
+ if (angularUnpatchedVersionSymbol && globalThis[angularUnpatchedVersionSymbol]) {
58
+ return globalThis[angularUnpatchedVersionSymbol];
59
+ } else {
60
+ return void 0;
61
+ }
62
+ }
63
+ function getUntaintedPrototype(key) {
64
+ if (untaintedBasePrototype[key])
65
+ return untaintedBasePrototype[key];
66
+ const candidate = angularZoneUnpatchedAlternative(key) || globalThis[key];
67
+ const defaultPrototype = candidate.prototype;
68
+ const accessorNames = key in testableAccessors ? testableAccessors[key] : void 0;
69
+ const isUntaintedAccessors = Boolean(
70
+ accessorNames && // @ts-expect-error 2345
71
+ accessorNames.every(
72
+ (accessor) => {
73
+ var _a, _b;
74
+ return Boolean(
75
+ (_b = (_a = Object.getOwnPropertyDescriptor(defaultPrototype, accessor)) == null ? void 0 : _a.get) == null ? void 0 : _b.toString().includes("[native code]")
76
+ );
77
+ }
78
+ )
79
+ );
80
+ const methodNames = key in testableMethods ? testableMethods[key] : void 0;
81
+ const isUntaintedMethods = Boolean(
82
+ methodNames && methodNames.every(
83
+ // @ts-expect-error 2345
84
+ (method) => {
85
+ var _a;
86
+ return typeof defaultPrototype[method] === "function" && ((_a = defaultPrototype[method]) == null ? void 0 : _a.toString().includes("[native code]"));
87
+ }
88
+ )
89
+ );
90
+ if (isUntaintedAccessors && isUntaintedMethods) {
91
+ untaintedBasePrototype[key] = candidate.prototype;
92
+ return candidate.prototype;
93
+ }
94
+ try {
95
+ const iframeEl = document.createElement("iframe");
96
+ document.body.appendChild(iframeEl);
97
+ const win = iframeEl.contentWindow;
98
+ if (!win) return candidate.prototype;
99
+ const untaintedObject = win[key].prototype;
100
+ document.body.removeChild(iframeEl);
101
+ if (!untaintedObject) return defaultPrototype;
102
+ return untaintedBasePrototype[key] = untaintedObject;
103
+ } catch (e) {
104
+ return defaultPrototype;
105
+ }
106
+ }
107
+ const untaintedAccessorCache = {};
108
+ function getUntaintedAccessor(key, instance, accessor) {
109
+ var _a;
110
+ const cacheKey = `${key}.${String(accessor)}`;
111
+ if (untaintedAccessorCache[cacheKey])
112
+ return untaintedAccessorCache[cacheKey].call(
113
+ instance
114
+ );
115
+ const untaintedPrototype = getUntaintedPrototype(key);
116
+ const untaintedAccessor = (_a = Object.getOwnPropertyDescriptor(
117
+ untaintedPrototype,
118
+ accessor
119
+ )) == null ? void 0 : _a.get;
120
+ if (!untaintedAccessor) return instance[accessor];
121
+ untaintedAccessorCache[cacheKey] = untaintedAccessor;
122
+ return untaintedAccessor.call(instance);
123
+ }
124
+ const untaintedMethodCache = {};
125
+ function getUntaintedMethod(key, instance, method) {
126
+ const cacheKey = `${key}.${String(method)}`;
127
+ if (untaintedMethodCache[cacheKey])
128
+ return untaintedMethodCache[cacheKey].bind(
129
+ instance
130
+ );
131
+ const untaintedPrototype = getUntaintedPrototype(key);
132
+ const untaintedMethod = untaintedPrototype[method];
133
+ if (typeof untaintedMethod !== "function") return instance[method];
134
+ untaintedMethodCache[cacheKey] = untaintedMethod;
135
+ return untaintedMethod.bind(instance);
136
+ }
137
+ function childNodes(n) {
138
+ return getUntaintedAccessor("Node", n, "childNodes");
139
+ }
140
+ function parentNode(n) {
141
+ return getUntaintedAccessor("Node", n, "parentNode");
142
+ }
143
+ function parentElement(n) {
144
+ return getUntaintedAccessor("Node", n, "parentElement");
145
+ }
146
+ function textContent(n) {
147
+ return getUntaintedAccessor("Node", n, "textContent");
148
+ }
149
+ function contains(n, other) {
150
+ return getUntaintedMethod("Node", n, "contains")(other);
151
+ }
152
+ function getRootNode(n) {
153
+ return getUntaintedMethod("Node", n, "getRootNode")();
154
+ }
155
+ function host(n) {
156
+ if (!n || !("host" in n)) return null;
157
+ return getUntaintedAccessor("ShadowRoot", n, "host");
158
+ }
159
+ function styleSheets(n) {
160
+ return n.styleSheets;
161
+ }
162
+ function shadowRoot(n) {
163
+ if (!n || !("shadowRoot" in n)) return null;
164
+ return getUntaintedAccessor("Element", n, "shadowRoot");
165
+ }
166
+ function querySelector(n, selectors) {
167
+ return getUntaintedAccessor("Element", n, "querySelector")(selectors);
168
+ }
169
+ function querySelectorAll(n, selectors) {
170
+ return getUntaintedAccessor("Element", n, "querySelectorAll")(selectors);
171
+ }
172
+ function mutationObserverCtor() {
173
+ return getUntaintedPrototype("MutationObserver").constructor;
174
+ }
175
+ function patch(source, name, replacement) {
176
+ try {
177
+ if (!(name in source)) {
178
+ return () => {
179
+ };
180
+ }
181
+ const original = source[name];
182
+ const wrapped = replacement(original);
183
+ if (typeof wrapped === "function") {
184
+ wrapped.prototype = wrapped.prototype || {};
185
+ Object.defineProperties(wrapped, {
186
+ __rrweb_original__: {
187
+ enumerable: false,
188
+ value: original
189
+ }
190
+ });
191
+ }
192
+ source[name] = wrapped;
193
+ return () => {
194
+ source[name] = original;
195
+ };
196
+ } catch (e) {
197
+ return () => {
198
+ };
199
+ }
200
+ }
201
+ const index = {
202
+ childNodes,
203
+ parentNode,
204
+ parentElement,
205
+ textContent,
206
+ contains,
207
+ getRootNode,
208
+ host,
209
+ styleSheets,
210
+ shadowRoot,
211
+ querySelector,
212
+ querySelectorAll,
213
+ mutationObserver: mutationObserverCtor,
214
+ patch
215
+ };
216
+ function isElement(n) {
217
+ return n.nodeType === n.ELEMENT_NODE;
218
+ }
41
219
  let Mirror$1 = class Mirror {
42
220
  constructor() {
43
221
  __publicField2(this, "idNodeMap", /* @__PURE__ */ new Map());
@@ -68,6 +246,17 @@ let Mirror$1 = class Mirror {
68
246
  (childNode) => this.removeNodeFromMap(childNode)
69
247
  );
70
248
  }
249
+ if (isElement(n)) {
250
+ const shadowRootEl = index.shadowRoot(n);
251
+ if (shadowRootEl) {
252
+ this.removeNodeFromMap(shadowRootEl);
253
+ }
254
+ if (n.nodeName === "IFRAME" && n.contentDocument) {
255
+ this.removeNodeFromMap(
256
+ n.contentDocument
257
+ );
258
+ }
259
+ }
71
260
  }
72
261
  has(id) {
73
262
  return this.idNodeMap.has(id);
@@ -206,8 +395,8 @@ function requireCssSyntaxError() {
206
395
  let start = Math.max(this.line - 3, 0);
207
396
  let end = Math.min(this.line + 2, lines.length);
208
397
  let maxWidth = String(end).length;
209
- return lines.slice(start, end).map((line, index) => {
210
- let number = start + 1 + index;
398
+ return lines.slice(start, end).map((line, index2) => {
399
+ let number = start + 1 + index2;
211
400
  let gutter = " " + (" " + number).slice(-maxWidth) + " | ";
212
401
  if (number === this.line) {
213
402
  if (line.length > 160) {
@@ -737,8 +926,8 @@ function requireNode() {
737
926
  }
738
927
  next() {
739
928
  if (!this.parent) return void 0;
740
- let index = this.parent.index(this);
741
- return this.parent.nodes[index + 1];
929
+ let index2 = this.parent.index(this);
930
+ return this.parent.nodes[index2 + 1];
742
931
  }
743
932
  positionBy(opts = {}) {
744
933
  let pos = this.source.start;
@@ -750,17 +939,17 @@ function requireNode() {
750
939
  sourceOffset(inputString, this.source.start),
751
940
  sourceOffset(inputString, this.source.end)
752
941
  );
753
- let index = stringRepresentation.indexOf(opts.word);
754
- if (index !== -1) pos = this.positionInside(index);
942
+ let index2 = stringRepresentation.indexOf(opts.word);
943
+ if (index2 !== -1) pos = this.positionInside(index2);
755
944
  }
756
945
  return pos;
757
946
  }
758
- positionInside(index) {
947
+ positionInside(index2) {
759
948
  let column = this.source.start.column;
760
949
  let line = this.source.start.line;
761
950
  let inputString = "document" in this.source.input ? this.source.input.document : this.source.input.css;
762
951
  let offset = sourceOffset(inputString, this.source.start);
763
- let end = offset + index;
952
+ let end = offset + index2;
764
953
  for (let i = offset; i < end; i++) {
765
954
  if (inputString[i] === "\n") {
766
955
  column = 1;
@@ -773,8 +962,8 @@ function requireNode() {
773
962
  }
774
963
  prev() {
775
964
  if (!this.parent) return void 0;
776
- let index = this.parent.index(this);
777
- return this.parent.nodes[index - 1];
965
+ let index2 = this.parent.index(this);
966
+ return this.parent.nodes[index2 - 1];
778
967
  }
779
968
  rangeBy(opts = {}) {
780
969
  let inputString = "document" in this.source.input ? this.source.input.document : this.source.input.css;
@@ -805,10 +994,10 @@ function requireNode() {
805
994
  sourceOffset(inputString, this.source.start),
806
995
  sourceOffset(inputString, this.source.end)
807
996
  );
808
- let index = stringRepresentation.indexOf(opts.word);
809
- if (index !== -1) {
810
- start = this.positionInside(index);
811
- end = this.positionInside(index + opts.word.length);
997
+ let index2 = stringRepresentation.indexOf(opts.word);
998
+ if (index2 !== -1) {
999
+ start = this.positionInside(index2);
1000
+ end = this.positionInside(index2 + opts.word.length);
812
1001
  }
813
1002
  } else {
814
1003
  if (opts.start) {
@@ -1035,10 +1224,10 @@ function requireContainer() {
1035
1224
  each(callback) {
1036
1225
  if (!this.proxyOf.nodes) return void 0;
1037
1226
  let iterator = this.getIterator();
1038
- let index, result2;
1227
+ let index2, result2;
1039
1228
  while (this.indexes[iterator] < this.proxyOf.nodes.length) {
1040
- index = this.indexes[iterator];
1041
- result2 = callback(this.proxyOf.nodes[index], index);
1229
+ index2 = this.indexes[iterator];
1230
+ result2 = callback(this.proxyOf.nodes[index2], index2);
1042
1231
  if (result2 === false) break;
1043
1232
  this.indexes[iterator] += 1;
1044
1233
  }
@@ -1068,7 +1257,7 @@ function requireContainer() {
1068
1257
  return node2[prop](
1069
1258
  ...args.map((i) => {
1070
1259
  if (typeof i === "function") {
1071
- return (child, index) => i(child.toProxy(), index);
1260
+ return (child, index2) => i(child.toProxy(), index2);
1072
1261
  } else {
1073
1262
  return i;
1074
1263
  }
@@ -1111,11 +1300,11 @@ function requireContainer() {
1111
1300
  let nodes = this.normalize(add, this.proxyOf.nodes[existIndex]).reverse();
1112
1301
  existIndex = this.index(exist);
1113
1302
  for (let node2 of nodes) this.proxyOf.nodes.splice(existIndex + 1, 0, node2);
1114
- let index;
1303
+ let index2;
1115
1304
  for (let id in this.indexes) {
1116
- index = this.indexes[id];
1117
- if (existIndex < index) {
1118
- this.indexes[id] = index + nodes.length;
1305
+ index2 = this.indexes[id];
1306
+ if (existIndex < index2) {
1307
+ this.indexes[id] = index2 + nodes.length;
1119
1308
  }
1120
1309
  }
1121
1310
  this.markDirty();
@@ -1131,11 +1320,11 @@ function requireContainer() {
1131
1320
  ).reverse();
1132
1321
  existIndex = this.index(exist);
1133
1322
  for (let node2 of nodes) this.proxyOf.nodes.splice(existIndex, 0, node2);
1134
- let index;
1323
+ let index2;
1135
1324
  for (let id in this.indexes) {
1136
- index = this.indexes[id];
1137
- if (existIndex <= index) {
1138
- this.indexes[id] = index + nodes.length;
1325
+ index2 = this.indexes[id];
1326
+ if (existIndex <= index2) {
1327
+ this.indexes[id] = index2 + nodes.length;
1139
1328
  }
1140
1329
  }
1141
1330
  this.markDirty();
@@ -1217,11 +1406,11 @@ function requireContainer() {
1217
1406
  child = this.index(child);
1218
1407
  this.proxyOf.nodes[child].parent = void 0;
1219
1408
  this.proxyOf.nodes.splice(child, 1);
1220
- let index;
1409
+ let index2;
1221
1410
  for (let id in this.indexes) {
1222
- index = this.indexes[id];
1223
- if (index >= child) {
1224
- this.indexes[id] = index - 1;
1411
+ index2 = this.indexes[id];
1412
+ if (index2 >= child) {
1413
+ this.indexes[id] = index2 - 1;
1225
1414
  }
1226
1415
  }
1227
1416
  this.markDirty();
@@ -1695,8 +1884,8 @@ function requireInput() {
1695
1884
  }
1696
1885
  fromLineAndColumn(line, column) {
1697
1886
  let lineToIndex = getLineToIndex(this);
1698
- let index = lineToIndex[line - 1];
1699
- return index + column - 1;
1887
+ let index2 = lineToIndex[line - 1];
1888
+ return index2 + column - 1;
1700
1889
  }
1701
1890
  fromOffset(offset) {
1702
1891
  let lineToIndex = getLineToIndex(this);
@@ -1820,9 +2009,9 @@ function requireRoot() {
1820
2009
  return nodes;
1821
2010
  }
1822
2011
  removeChild(child, ignore) {
1823
- let index = this.index(child);
1824
- if (!ignore && index === 0 && this.nodes.length > 1) {
1825
- this.nodes[1].raws.before = this.nodes[index].raws.before;
2012
+ let index2 = this.index(child);
2013
+ if (!ignore && index2 === 0 && this.nodes.length > 1) {
2014
+ this.nodes[1].raws.before = this.nodes[index2].raws.before;
1826
2015
  }
1827
2016
  return super.removeChild(child);
1828
2017
  }
@@ -4096,13 +4285,13 @@ class BaseRRNode {
4096
4285
  __publicField(this, "RRNodeType");
4097
4286
  }
4098
4287
  get childNodes() {
4099
- const childNodes = [];
4288
+ const childNodes2 = [];
4100
4289
  let childIterator = this.firstChild;
4101
4290
  while (childIterator) {
4102
- childNodes.push(childIterator);
4291
+ childNodes2.push(childIterator);
4103
4292
  childIterator = childIterator.nextSibling;
4104
4293
  }
4105
- return childNodes;
4294
+ return childNodes2;
4106
4295
  }
4107
4296
  contains(node2) {
4108
4297
  if (!(node2 instanceof BaseRRNode)) return false;
@@ -4294,10 +4483,10 @@ class BaseRRElement extends BaseRRNode {
4294
4483
  this.childNodes.forEach((node2) => result2 += node2.textContent);
4295
4484
  return result2;
4296
4485
  }
4297
- set textContent(textContent) {
4486
+ set textContent(textContent2) {
4298
4487
  this.firstChild = null;
4299
4488
  this.lastChild = null;
4300
- this.appendChild(this.ownerDocument.createTextNode(textContent));
4489
+ this.appendChild(this.ownerDocument.createTextNode(textContent2));
4301
4490
  }
4302
4491
  get classList() {
4303
4492
  return new ClassList(
@@ -4358,9 +4547,9 @@ class BaseRRElement extends BaseRRNode {
4358
4547
  }
4359
4548
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
4360
4549
  attachShadow(_init) {
4361
- const shadowRoot = this.ownerDocument.createElement("SHADOWROOT");
4362
- this.shadowRoot = shadowRoot;
4363
- return shadowRoot;
4550
+ const shadowRoot2 = this.ownerDocument.createElement("SHADOWROOT");
4551
+ this.shadowRoot = shadowRoot2;
4552
+ return shadowRoot2;
4364
4553
  }
4365
4554
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
4366
4555
  dispatchEvent(_event) {
@@ -4434,8 +4623,8 @@ class BaseRRText extends BaseRRNode {
4434
4623
  get textContent() {
4435
4624
  return this.data;
4436
4625
  }
4437
- set textContent(textContent) {
4438
- this.data = textContent;
4626
+ set textContent(textContent2) {
4627
+ this.data = textContent2;
4439
4628
  }
4440
4629
  toString() {
4441
4630
  return `RRText text=${JSON.stringify(this.data)}`;
@@ -4453,8 +4642,8 @@ class BaseRRComment extends BaseRRNode {
4453
4642
  get textContent() {
4454
4643
  return this.data;
4455
4644
  }
4456
- set textContent(textContent) {
4457
- this.data = textContent;
4645
+ set textContent(textContent2) {
4646
+ this.data = textContent2;
4458
4647
  }
4459
4648
  toString() {
4460
4649
  return `RRComment text=${JSON.stringify(this.data)}`;
@@ -4472,8 +4661,8 @@ class BaseRRCDATASection extends BaseRRNode {
4472
4661
  get textContent() {
4473
4662
  return this.data;
4474
4663
  }
4475
- set textContent(textContent) {
4476
- this.data = textContent;
4664
+ set textContent(textContent2) {
4665
+ this.data = textContent2;
4477
4666
  }
4478
4667
  toString() {
4479
4668
  return `RRCDATASection data=${JSON.stringify(this.data)}`;