@glimt/record 0.0.2 → 0.0.4

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/record.cjs CHANGED
@@ -144,32 +144,6 @@ function querySelectorAll$1(n2, selectors) {
144
144
  function mutationObserverCtor$1() {
145
145
  return getUntaintedPrototype$1("MutationObserver").constructor;
146
146
  }
147
- function patch$1(source, name, replacement) {
148
- try {
149
- if (!(name in source)) {
150
- return () => {
151
- };
152
- }
153
- const original = source[name];
154
- const wrapped = replacement(original);
155
- if (typeof wrapped === "function") {
156
- wrapped.prototype = wrapped.prototype || {};
157
- Object.defineProperties(wrapped, {
158
- __rrweb_original__: {
159
- enumerable: false,
160
- value: original
161
- }
162
- });
163
- }
164
- source[name] = wrapped;
165
- return () => {
166
- source[name] = original;
167
- };
168
- } catch {
169
- return () => {
170
- };
171
- }
172
- }
173
147
  const index$1 = {
174
148
  childNodes: childNodes$1,
175
149
  parentNode: parentNode$1,
@@ -182,8 +156,7 @@ const index$1 = {
182
156
  shadowRoot: shadowRoot$1,
183
157
  querySelector: querySelector$1,
184
158
  querySelectorAll: querySelectorAll$1,
185
- mutationObserver: mutationObserverCtor$1,
186
- patch: patch$1
159
+ mutationObserver: mutationObserverCtor$1
187
160
  };
188
161
  function isElement(n2) {
189
162
  return n2.nodeType === n2.ELEMENT_NODE;
@@ -452,97 +425,26 @@ function absolutifyURLs(cssText, href) {
452
425
  }
453
426
  );
454
427
  }
455
- function normalizeCssString(cssText, _testNoPxNorm = false) {
456
- if (_testNoPxNorm) {
457
- return cssText.replace(/(\/\*[^*]*\*\/)|[\s;]/g, "");
458
- } else {
459
- return cssText.replace(/(\/\*[^*]*\*\/)|[\s;]/g, "").replace(/0px/g, "0");
460
- }
428
+ function normalizeCssString(cssText) {
429
+ return cssText.replace(/(\/\*[^*]*\*\/)|[\s;]/g, "");
461
430
  }
462
- function splitCssText(cssText, style, _testNoPxNorm = false) {
431
+ function splitCssText(cssText, style) {
463
432
  const childNodes2 = Array.from(style.childNodes);
464
433
  const splits = [];
465
- let iterCount = 0;
466
434
  if (childNodes2.length > 1 && cssText && typeof cssText === "string") {
467
- let cssTextNorm = normalizeCssString(cssText, _testNoPxNorm);
468
- const normFactor = cssTextNorm.length / cssText.length;
435
+ const cssTextNorm = normalizeCssString(cssText);
469
436
  for (let i2 = 1; i2 < childNodes2.length; i2++) {
470
437
  if (childNodes2[i2].textContent && typeof childNodes2[i2].textContent === "string") {
471
- const textContentNorm = normalizeCssString(
472
- childNodes2[i2].textContent,
473
- _testNoPxNorm
474
- );
475
- const jLimit = 100;
476
- let j = 3;
477
- for (; j < textContentNorm.length; j++) {
478
- if (
479
- // keep consuming css identifiers (to get a decent chunk more quickly)
480
- textContentNorm[j].match(/[a-zA-Z0-9]/) || // substring needs to be unique to this section
481
- textContentNorm.indexOf(textContentNorm.substring(0, j), 1) !== -1
482
- ) {
483
- continue;
484
- }
485
- break;
486
- }
487
- for (; j < textContentNorm.length; j++) {
488
- let startSubstring = textContentNorm.substring(0, j);
489
- let cssNormSplits = cssTextNorm.split(startSubstring);
490
- let splitNorm = -1;
491
- if (cssNormSplits.length === 2) {
492
- splitNorm = cssNormSplits[0].length;
493
- } else if (cssNormSplits.length > 2 && cssNormSplits[0] === "" && childNodes2[i2 - 1].textContent !== "") {
494
- splitNorm = cssTextNorm.indexOf(startSubstring, 1);
495
- } else if (cssNormSplits.length === 1) {
496
- startSubstring = startSubstring.substring(
497
- 0,
498
- startSubstring.length - 1
499
- );
500
- cssNormSplits = cssTextNorm.split(startSubstring);
501
- if (cssNormSplits.length <= 1) {
502
- splits.push(cssText);
503
- return splits;
504
- }
505
- j = jLimit + 1;
506
- } else if (j === textContentNorm.length - 1) {
507
- splitNorm = cssTextNorm.indexOf(startSubstring);
508
- }
509
- if (cssNormSplits.length >= 2 && j > jLimit) {
510
- const prevTextContent = childNodes2[i2 - 1].textContent;
511
- if (prevTextContent && typeof prevTextContent === "string") {
512
- const prevMinLength = normalizeCssString(prevTextContent).length;
513
- splitNorm = cssTextNorm.indexOf(startSubstring, prevMinLength);
514
- }
515
- if (splitNorm === -1) {
516
- splitNorm = cssNormSplits[0].length;
517
- }
518
- }
519
- if (splitNorm !== -1) {
520
- let k = Math.floor(splitNorm / normFactor);
521
- for (; k > 0 && k < cssText.length; ) {
522
- iterCount += 1;
523
- if (iterCount > 50 * childNodes2.length) {
524
- splits.push(cssText);
525
- return splits;
526
- }
527
- const normPart = normalizeCssString(
528
- cssText.substring(0, k),
529
- _testNoPxNorm
530
- );
531
- if (normPart.length === splitNorm) {
438
+ const textContentNorm = normalizeCssString(childNodes2[i2].textContent);
439
+ for (let j = 3; j < textContentNorm.length; j++) {
440
+ const bit = textContentNorm.substring(0, j);
441
+ if (cssTextNorm.split(bit).length === 2) {
442
+ const splitNorm = cssTextNorm.indexOf(bit);
443
+ for (let k = splitNorm; k < cssText.length; k++) {
444
+ if (normalizeCssString(cssText.substring(0, k)).length === splitNorm) {
532
445
  splits.push(cssText.substring(0, k));
533
446
  cssText = cssText.substring(k);
534
- cssTextNorm = cssTextNorm.substring(splitNorm);
535
447
  break;
536
- } else if (normPart.length < splitNorm) {
537
- k += Math.max(
538
- 1,
539
- Math.floor((splitNorm - normPart.length) / normFactor)
540
- );
541
- } else {
542
- k -= Math.max(
543
- 1,
544
- Math.floor((normPart.length - splitNorm) * normFactor)
545
- );
546
448
  }
547
449
  }
548
450
  break;
@@ -1024,19 +926,8 @@ function serializeElementNode(n2, options) {
1024
926
  const image = n2;
1025
927
  const imageSrc = image.currentSrc || image.getAttribute("src") || "<unknown-src>";
1026
928
  const priorCrossOrigin = image.crossOrigin;
1027
- const cleanupCrossOriginAttribute = () => {
1028
- if (image.crossOrigin === "anonymous") {
1029
- if (priorCrossOrigin) {
1030
- image.setAttribute("crossorigin", priorCrossOrigin);
1031
- attributes.crossOrigin = priorCrossOrigin;
1032
- } else {
1033
- image.removeAttribute("crossorigin");
1034
- }
1035
- }
1036
- };
1037
929
  const recordInlineImage = () => {
1038
930
  image.removeEventListener("load", recordInlineImage);
1039
- image.removeEventListener("error", onImageLoadError);
1040
931
  try {
1041
932
  canvasService.width = image.naturalWidth;
1042
933
  canvasService.height = image.naturalHeight;
@@ -1050,10 +941,7 @@ function serializeElementNode(n2, options) {
1050
941
  image.crossOrigin = "anonymous";
1051
942
  if (image.complete && image.naturalWidth !== 0)
1052
943
  recordInlineImage();
1053
- else {
1054
- image.addEventListener("load", recordInlineImage);
1055
- image.addEventListener("error", onImageLoadError);
1056
- }
944
+ else image.addEventListener("load", recordInlineImage);
1057
945
  return;
1058
946
  } else {
1059
947
  console.warn(
@@ -1061,18 +949,12 @@ function serializeElementNode(n2, options) {
1061
949
  );
1062
950
  }
1063
951
  }
1064
- cleanupCrossOriginAttribute();
1065
- };
1066
- const onImageLoadError = () => {
1067
- image.removeEventListener("load", recordInlineImage);
1068
- image.removeEventListener("error", onImageLoadError);
1069
- cleanupCrossOriginAttribute();
952
+ if (image.crossOrigin === "anonymous") {
953
+ priorCrossOrigin ? attributes.crossOrigin = priorCrossOrigin : image.removeAttribute("crossorigin");
954
+ }
1070
955
  };
1071
956
  if (image.complete && image.naturalWidth !== 0) recordInlineImage();
1072
- else {
1073
- image.addEventListener("load", recordInlineImage);
1074
- image.addEventListener("error", onImageLoadError);
1075
- }
957
+ else image.addEventListener("load", recordInlineImage);
1076
958
  }
1077
959
  if (tagName === "audio" || tagName === "video") {
1078
960
  const mediaAttributes = attributes;
@@ -1134,7 +1016,7 @@ function slimDOMExcluded(sn, slimDOMOptions) {
1134
1016
  } else if (sn.type === NodeType$3.Element) {
1135
1017
  if (slimDOMOptions.script && // script tag
1136
1018
  (sn.tagName === "script" || // (module)preload link
1137
- sn.tagName === "link" && (sn.attributes.rel === "preload" && sn.attributes.as === "script" || sn.attributes.rel === "modulepreload") || // prefetch link
1019
+ sn.tagName === "link" && (sn.attributes.rel === "preload" || sn.attributes.rel === "modulepreload") && sn.attributes.as === "script" || // prefetch link
1138
1020
  sn.tagName === "link" && sn.attributes.rel === "prefetch" && typeof sn.attributes.href === "string" && extractFileExtension(sn.attributes.href) === "js")) {
1139
1021
  return true;
1140
1022
  } else if (slimDOMOptions.headFavicon && (sn.tagName === "link" && sn.attributes.rel === "shortcut icon" || sn.tagName === "meta" && (lowerIfExists(sn.attributes.name).match(
@@ -1278,10 +1160,7 @@ function serializeNodeWithId(n2, options) {
1278
1160
  bypassOptions.cssCaptured = true;
1279
1161
  }
1280
1162
  for (const childN of Array.from(index$1.childNodes(n2))) {
1281
- const serializedChildNode = serializeNodeWithId(
1282
- childN,
1283
- bypassOptions
1284
- );
1163
+ const serializedChildNode = serializeNodeWithId(childN, bypassOptions);
1285
1164
  if (serializedChildNode) {
1286
1165
  serializedNode.childNodes.push(serializedChildNode);
1287
1166
  }
@@ -1290,10 +1169,7 @@ function serializeNodeWithId(n2, options) {
1290
1169
  let shadowRootEl = null;
1291
1170
  if (isElement(n2) && (shadowRootEl = index$1.shadowRoot(n2))) {
1292
1171
  for (const childN of Array.from(index$1.childNodes(shadowRootEl))) {
1293
- const serializedChildNode = serializeNodeWithId(
1294
- childN,
1295
- bypassOptions
1296
- );
1172
+ const serializedChildNode = serializeNodeWithId(childN, bypassOptions);
1297
1173
  if (serializedChildNode) {
1298
1174
  isNativeShadowDom(shadowRootEl) && (serializedChildNode.isShadow = true);
1299
1175
  serializedNode.childNodes.push(serializedChildNode);
@@ -8761,32 +8637,6 @@ function querySelectorAll(n2, selectors) {
8761
8637
  function mutationObserverCtor() {
8762
8638
  return getUntaintedPrototype("MutationObserver").constructor;
8763
8639
  }
8764
- function patch(source, name, replacement) {
8765
- try {
8766
- if (!(name in source)) {
8767
- return () => {
8768
- };
8769
- }
8770
- const original = source[name];
8771
- const wrapped = replacement(original);
8772
- if (typeof wrapped === "function") {
8773
- wrapped.prototype = wrapped.prototype || {};
8774
- Object.defineProperties(wrapped, {
8775
- __rrweb_original__: {
8776
- enumerable: false,
8777
- value: original
8778
- }
8779
- });
8780
- }
8781
- source[name] = wrapped;
8782
- return () => {
8783
- source[name] = original;
8784
- };
8785
- } catch {
8786
- return () => {
8787
- };
8788
- }
8789
- }
8790
8640
  const index = {
8791
8641
  childNodes,
8792
8642
  parentNode,
@@ -8799,8 +8649,7 @@ const index = {
8799
8649
  shadowRoot,
8800
8650
  querySelector,
8801
8651
  querySelectorAll,
8802
- mutationObserver: mutationObserverCtor,
8803
- patch
8652
+ mutationObserver: mutationObserverCtor
8804
8653
  };
8805
8654
  function on(type, fn, target = document) {
8806
8655
  const options = { capture: true, passive: true };
@@ -8883,6 +8732,32 @@ function hookSetter(target, key, d, isRevoked, win = window) {
8883
8732
  );
8884
8733
  return () => hookSetter(target, key, original || {}, true);
8885
8734
  }
8735
+ function patch(source, name, replacement) {
8736
+ try {
8737
+ if (!(name in source)) {
8738
+ return () => {
8739
+ };
8740
+ }
8741
+ const original = source[name];
8742
+ const wrapped = replacement(original);
8743
+ if (typeof wrapped === "function") {
8744
+ wrapped.prototype = wrapped.prototype || {};
8745
+ Object.defineProperties(wrapped, {
8746
+ __rrweb_original__: {
8747
+ enumerable: false,
8748
+ value: original
8749
+ }
8750
+ });
8751
+ }
8752
+ source[name] = wrapped;
8753
+ return () => {
8754
+ source[name] = original;
8755
+ };
8756
+ } catch {
8757
+ return () => {
8758
+ };
8759
+ }
8760
+ }
8886
8761
  let nowTimestamp = Date.now;
8887
8762
  if (!/* @__PURE__ */ /[1-9][0-9]{12}/.test(Date.now().toString())) {
8888
8763
  nowTimestamp = () => (/* @__PURE__ */ new Date()).getTime();
@@ -9444,18 +9319,10 @@ class MutationBuffer {
9444
9319
  this.attributes.push(item);
9445
9320
  this.attributeMap.set(textarea, item);
9446
9321
  }
9447
- const value = Array.from(
9322
+ item.attributes.value = Array.from(
9448
9323
  index.childNodes(textarea),
9449
9324
  (cn) => index.textContent(cn) || ""
9450
9325
  ).join("");
9451
- item.attributes.value = maskInputValue({
9452
- element: textarea,
9453
- maskInputOptions: this.maskInputOptions,
9454
- tagName: textarea.tagName,
9455
- type: getInputType(textarea),
9456
- value,
9457
- maskInputFn: this.maskInputFn
9458
- });
9459
9326
  });
9460
9327
  __publicField(this, "processMutation", (m) => {
9461
9328
  if (isIgnored(m.target, this.mirror, this.slimDOMOptions)) {