@glimt/record 0.0.2 → 0.0.3

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.
@@ -188,32 +188,6 @@ function querySelectorAll$1(n2, selectors) {
188
188
  function mutationObserverCtor$1() {
189
189
  return getUntaintedPrototype$1("MutationObserver").constructor;
190
190
  }
191
- function patch$1(source, name, replacement) {
192
- try {
193
- if (!(name in source)) {
194
- return () => {
195
- };
196
- }
197
- const original = source[name];
198
- const wrapped = replacement(original);
199
- if (typeof wrapped === "function") {
200
- wrapped.prototype = wrapped.prototype || {};
201
- Object.defineProperties(wrapped, {
202
- __rrweb_original__: {
203
- enumerable: false,
204
- value: original
205
- }
206
- });
207
- }
208
- source[name] = wrapped;
209
- return () => {
210
- source[name] = original;
211
- };
212
- } catch (e) {
213
- return () => {
214
- };
215
- }
216
- }
217
191
  const index$1 = {
218
192
  childNodes: childNodes$1,
219
193
  parentNode: parentNode$1,
@@ -226,8 +200,7 @@ const index$1 = {
226
200
  shadowRoot: shadowRoot$1,
227
201
  querySelector: querySelector$1,
228
202
  querySelectorAll: querySelectorAll$1,
229
- mutationObserver: mutationObserverCtor$1,
230
- patch: patch$1
203
+ mutationObserver: mutationObserverCtor$1
231
204
  };
232
205
  function isElement(n2) {
233
206
  return n2.nodeType === n2.ELEMENT_NODE;
@@ -497,97 +470,26 @@ function absolutifyURLs(cssText, href) {
497
470
  }
498
471
  );
499
472
  }
500
- function normalizeCssString(cssText, _testNoPxNorm = false) {
501
- if (_testNoPxNorm) {
502
- return cssText.replace(/(\/\*[^*]*\*\/)|[\s;]/g, "");
503
- } else {
504
- return cssText.replace(/(\/\*[^*]*\*\/)|[\s;]/g, "").replace(/0px/g, "0");
505
- }
473
+ function normalizeCssString(cssText) {
474
+ return cssText.replace(/(\/\*[^*]*\*\/)|[\s;]/g, "");
506
475
  }
507
- function splitCssText(cssText, style, _testNoPxNorm = false) {
476
+ function splitCssText(cssText, style) {
508
477
  const childNodes2 = Array.from(style.childNodes);
509
478
  const splits = [];
510
- let iterCount = 0;
511
479
  if (childNodes2.length > 1 && cssText && typeof cssText === "string") {
512
- let cssTextNorm = normalizeCssString(cssText, _testNoPxNorm);
513
- const normFactor = cssTextNorm.length / cssText.length;
480
+ const cssTextNorm = normalizeCssString(cssText);
514
481
  for (let i2 = 1; i2 < childNodes2.length; i2++) {
515
482
  if (childNodes2[i2].textContent && typeof childNodes2[i2].textContent === "string") {
516
- const textContentNorm = normalizeCssString(
517
- childNodes2[i2].textContent,
518
- _testNoPxNorm
519
- );
520
- const jLimit = 100;
521
- let j = 3;
522
- for (; j < textContentNorm.length; j++) {
523
- if (
524
- // keep consuming css identifiers (to get a decent chunk more quickly)
525
- textContentNorm[j].match(/[a-zA-Z0-9]/) || // substring needs to be unique to this section
526
- textContentNorm.indexOf(textContentNorm.substring(0, j), 1) !== -1
527
- ) {
528
- continue;
529
- }
530
- break;
531
- }
532
- for (; j < textContentNorm.length; j++) {
533
- let startSubstring = textContentNorm.substring(0, j);
534
- let cssNormSplits = cssTextNorm.split(startSubstring);
535
- let splitNorm = -1;
536
- if (cssNormSplits.length === 2) {
537
- splitNorm = cssNormSplits[0].length;
538
- } else if (cssNormSplits.length > 2 && cssNormSplits[0] === "" && childNodes2[i2 - 1].textContent !== "") {
539
- splitNorm = cssTextNorm.indexOf(startSubstring, 1);
540
- } else if (cssNormSplits.length === 1) {
541
- startSubstring = startSubstring.substring(
542
- 0,
543
- startSubstring.length - 1
544
- );
545
- cssNormSplits = cssTextNorm.split(startSubstring);
546
- if (cssNormSplits.length <= 1) {
547
- splits.push(cssText);
548
- return splits;
549
- }
550
- j = jLimit + 1;
551
- } else if (j === textContentNorm.length - 1) {
552
- splitNorm = cssTextNorm.indexOf(startSubstring);
553
- }
554
- if (cssNormSplits.length >= 2 && j > jLimit) {
555
- const prevTextContent = childNodes2[i2 - 1].textContent;
556
- if (prevTextContent && typeof prevTextContent === "string") {
557
- const prevMinLength = normalizeCssString(prevTextContent).length;
558
- splitNorm = cssTextNorm.indexOf(startSubstring, prevMinLength);
559
- }
560
- if (splitNorm === -1) {
561
- splitNorm = cssNormSplits[0].length;
562
- }
563
- }
564
- if (splitNorm !== -1) {
565
- let k = Math.floor(splitNorm / normFactor);
566
- for (; k > 0 && k < cssText.length; ) {
567
- iterCount += 1;
568
- if (iterCount > 50 * childNodes2.length) {
569
- splits.push(cssText);
570
- return splits;
571
- }
572
- const normPart = normalizeCssString(
573
- cssText.substring(0, k),
574
- _testNoPxNorm
575
- );
576
- if (normPart.length === splitNorm) {
483
+ const textContentNorm = normalizeCssString(childNodes2[i2].textContent);
484
+ for (let j = 3; j < textContentNorm.length; j++) {
485
+ const bit = textContentNorm.substring(0, j);
486
+ if (cssTextNorm.split(bit).length === 2) {
487
+ const splitNorm = cssTextNorm.indexOf(bit);
488
+ for (let k = splitNorm; k < cssText.length; k++) {
489
+ if (normalizeCssString(cssText.substring(0, k)).length === splitNorm) {
577
490
  splits.push(cssText.substring(0, k));
578
491
  cssText = cssText.substring(k);
579
- cssTextNorm = cssTextNorm.substring(splitNorm);
580
492
  break;
581
- } else if (normPart.length < splitNorm) {
582
- k += Math.max(
583
- 1,
584
- Math.floor((splitNorm - normPart.length) / normFactor)
585
- );
586
- } else {
587
- k -= Math.max(
588
- 1,
589
- Math.floor((normPart.length - splitNorm) * normFactor)
590
- );
591
493
  }
592
494
  }
593
495
  break;
@@ -1069,19 +971,8 @@ function serializeElementNode(n2, options) {
1069
971
  const image = n2;
1070
972
  const imageSrc = image.currentSrc || image.getAttribute("src") || "<unknown-src>";
1071
973
  const priorCrossOrigin = image.crossOrigin;
1072
- const cleanupCrossOriginAttribute = () => {
1073
- if (image.crossOrigin === "anonymous") {
1074
- if (priorCrossOrigin) {
1075
- image.setAttribute("crossorigin", priorCrossOrigin);
1076
- attributes.crossOrigin = priorCrossOrigin;
1077
- } else {
1078
- image.removeAttribute("crossorigin");
1079
- }
1080
- }
1081
- };
1082
974
  const recordInlineImage = () => {
1083
975
  image.removeEventListener("load", recordInlineImage);
1084
- image.removeEventListener("error", onImageLoadError);
1085
976
  try {
1086
977
  canvasService.width = image.naturalWidth;
1087
978
  canvasService.height = image.naturalHeight;
@@ -1095,10 +986,7 @@ function serializeElementNode(n2, options) {
1095
986
  image.crossOrigin = "anonymous";
1096
987
  if (image.complete && image.naturalWidth !== 0)
1097
988
  recordInlineImage();
1098
- else {
1099
- image.addEventListener("load", recordInlineImage);
1100
- image.addEventListener("error", onImageLoadError);
1101
- }
989
+ else image.addEventListener("load", recordInlineImage);
1102
990
  return;
1103
991
  } else {
1104
992
  console.warn(
@@ -1106,18 +994,12 @@ function serializeElementNode(n2, options) {
1106
994
  );
1107
995
  }
1108
996
  }
1109
- cleanupCrossOriginAttribute();
1110
- };
1111
- const onImageLoadError = () => {
1112
- image.removeEventListener("load", recordInlineImage);
1113
- image.removeEventListener("error", onImageLoadError);
1114
- cleanupCrossOriginAttribute();
997
+ if (image.crossOrigin === "anonymous") {
998
+ priorCrossOrigin ? attributes.crossOrigin = priorCrossOrigin : image.removeAttribute("crossorigin");
999
+ }
1115
1000
  };
1116
1001
  if (image.complete && image.naturalWidth !== 0) recordInlineImage();
1117
- else {
1118
- image.addEventListener("load", recordInlineImage);
1119
- image.addEventListener("error", onImageLoadError);
1120
- }
1002
+ else image.addEventListener("load", recordInlineImage);
1121
1003
  }
1122
1004
  if (tagName === "audio" || tagName === "video") {
1123
1005
  const mediaAttributes = attributes;
@@ -1179,7 +1061,7 @@ function slimDOMExcluded(sn, slimDOMOptions) {
1179
1061
  } else if (sn.type === NodeType$3.Element) {
1180
1062
  if (slimDOMOptions.script && // script tag
1181
1063
  (sn.tagName === "script" || // (module)preload link
1182
- sn.tagName === "link" && (sn.attributes.rel === "preload" && sn.attributes.as === "script" || sn.attributes.rel === "modulepreload") || // prefetch link
1064
+ sn.tagName === "link" && (sn.attributes.rel === "preload" || sn.attributes.rel === "modulepreload") && sn.attributes.as === "script" || // prefetch link
1183
1065
  sn.tagName === "link" && sn.attributes.rel === "prefetch" && typeof sn.attributes.href === "string" && extractFileExtension(sn.attributes.href) === "js")) {
1184
1066
  return true;
1185
1067
  } else if (slimDOMOptions.headFavicon && (sn.tagName === "link" && sn.attributes.rel === "shortcut icon" || sn.tagName === "meta" && (lowerIfExists(sn.attributes.name).match(
@@ -1323,10 +1205,7 @@ function serializeNodeWithId(n2, options) {
1323
1205
  bypassOptions.cssCaptured = true;
1324
1206
  }
1325
1207
  for (const childN of Array.from(index$1.childNodes(n2))) {
1326
- const serializedChildNode = serializeNodeWithId(
1327
- childN,
1328
- bypassOptions
1329
- );
1208
+ const serializedChildNode = serializeNodeWithId(childN, bypassOptions);
1330
1209
  if (serializedChildNode) {
1331
1210
  serializedNode.childNodes.push(serializedChildNode);
1332
1211
  }
@@ -1335,10 +1214,7 @@ function serializeNodeWithId(n2, options) {
1335
1214
  let shadowRootEl = null;
1336
1215
  if (isElement(n2) && (shadowRootEl = index$1.shadowRoot(n2))) {
1337
1216
  for (const childN of Array.from(index$1.childNodes(shadowRootEl))) {
1338
- const serializedChildNode = serializeNodeWithId(
1339
- childN,
1340
- bypassOptions
1341
- );
1217
+ const serializedChildNode = serializeNodeWithId(childN, bypassOptions);
1342
1218
  if (serializedChildNode) {
1343
1219
  isNativeShadowDom(shadowRootEl) && (serializedChildNode.isShadow = true);
1344
1220
  serializedNode.childNodes.push(serializedChildNode);
@@ -8814,32 +8690,6 @@ function querySelectorAll(n2, selectors) {
8814
8690
  function mutationObserverCtor() {
8815
8691
  return getUntaintedPrototype("MutationObserver").constructor;
8816
8692
  }
8817
- function patch(source, name, replacement) {
8818
- try {
8819
- if (!(name in source)) {
8820
- return () => {
8821
- };
8822
- }
8823
- const original = source[name];
8824
- const wrapped = replacement(original);
8825
- if (typeof wrapped === "function") {
8826
- wrapped.prototype = wrapped.prototype || {};
8827
- Object.defineProperties(wrapped, {
8828
- __rrweb_original__: {
8829
- enumerable: false,
8830
- value: original
8831
- }
8832
- });
8833
- }
8834
- source[name] = wrapped;
8835
- return () => {
8836
- source[name] = original;
8837
- };
8838
- } catch (e) {
8839
- return () => {
8840
- };
8841
- }
8842
- }
8843
8693
  const index = {
8844
8694
  childNodes,
8845
8695
  parentNode,
@@ -8852,8 +8702,7 @@ const index = {
8852
8702
  shadowRoot,
8853
8703
  querySelector,
8854
8704
  querySelectorAll,
8855
- mutationObserver: mutationObserverCtor,
8856
- patch
8705
+ mutationObserver: mutationObserverCtor
8857
8706
  };
8858
8707
  function on(type, fn, target = document) {
8859
8708
  const options = { capture: true, passive: true };
@@ -8936,6 +8785,32 @@ function hookSetter(target, key, d, isRevoked, win = window) {
8936
8785
  );
8937
8786
  return () => hookSetter(target, key, original || {}, true);
8938
8787
  }
8788
+ function patch(source, name, replacement) {
8789
+ try {
8790
+ if (!(name in source)) {
8791
+ return () => {
8792
+ };
8793
+ }
8794
+ const original = source[name];
8795
+ const wrapped = replacement(original);
8796
+ if (typeof wrapped === "function") {
8797
+ wrapped.prototype = wrapped.prototype || {};
8798
+ Object.defineProperties(wrapped, {
8799
+ __rrweb_original__: {
8800
+ enumerable: false,
8801
+ value: original
8802
+ }
8803
+ });
8804
+ }
8805
+ source[name] = wrapped;
8806
+ return () => {
8807
+ source[name] = original;
8808
+ };
8809
+ } catch (e) {
8810
+ return () => {
8811
+ };
8812
+ }
8813
+ }
8939
8814
  let nowTimestamp = Date.now;
8940
8815
  if (!/* @__PURE__ */ /[1-9][0-9]{12}/.test(Date.now().toString())) {
8941
8816
  nowTimestamp = () => (/* @__PURE__ */ new Date()).getTime();
@@ -9498,18 +9373,10 @@ class MutationBuffer {
9498
9373
  this.attributes.push(item);
9499
9374
  this.attributeMap.set(textarea, item);
9500
9375
  }
9501
- const value = Array.from(
9376
+ item.attributes.value = Array.from(
9502
9377
  index.childNodes(textarea),
9503
9378
  (cn) => index.textContent(cn) || ""
9504
9379
  ).join("");
9505
- item.attributes.value = maskInputValue({
9506
- element: textarea,
9507
- maskInputOptions: this.maskInputOptions,
9508
- tagName: textarea.tagName,
9509
- type: getInputType(textarea),
9510
- value,
9511
- maskInputFn: this.maskInputFn
9512
- });
9513
9380
  });
9514
9381
  __publicField(this, "processMutation", (m) => {
9515
9382
  if (isIgnored(m.target, this.mirror, this.slimDOMOptions)) {