@glimt/record 0.0.9 → 0.0.11

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
@@ -42,9 +42,9 @@ function getUntaintedPrototype$1(key) {
42
42
  accessorNames && // @ts-expect-error 2345
43
43
  accessorNames.every(
44
44
  (accessor) => {
45
- var _a2, _b2;
45
+ var _a2, _b;
46
46
  return Boolean(
47
- (_b2 = (_a2 = Object.getOwnPropertyDescriptor(defaultPrototype, accessor)) == null ? void 0 : _a2.get) == null ? void 0 : _b2.toString().includes("[native code]")
47
+ (_b = (_a2 = Object.getOwnPropertyDescriptor(defaultPrototype, accessor)) == null ? void 0 : _a2.get) == null ? void 0 : _b.toString().includes("[native code]")
48
48
  );
49
49
  }
50
50
  )
@@ -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;
@@ -1021,35 +923,11 @@ function serializeElementNode(n2, options) {
1021
923
  canvasService = doc.createElement("canvas");
1022
924
  canvasCtx = canvasService.getContext("2d");
1023
925
  }
1024
- let image = n2.cloneNode(true);
926
+ const image = n2;
1025
927
  const imageSrc = image.currentSrc || image.getAttribute("src") || "<unknown-src>";
1026
928
  const priorCrossOrigin = image.crossOrigin;
1027
- console.log(
1028
- "initializing inlineImages with image:",
1029
- image,
1030
- "imageSrc:",
1031
- imageSrc,
1032
- "priorCrossOrigin:",
1033
- priorCrossOrigin
1034
- );
1035
- const cleanupCrossOriginAttribute = () => {
1036
- console.log("cleaning up attributes");
1037
- console.log("priorCrossOrigin", priorCrossOrigin);
1038
- console.log("currentCrossOrigin", image.crossOrigin);
1039
- if (image.crossOrigin === "anonymous") {
1040
- if (priorCrossOrigin) {
1041
- image.setAttribute("crossorigin", priorCrossOrigin);
1042
- attributes.crossOrigin = priorCrossOrigin;
1043
- } else {
1044
- image.removeAttribute("crossorigin");
1045
- }
1046
- }
1047
- image = null;
1048
- };
1049
929
  const recordInlineImage = () => {
1050
- console.log("recordInlineImage()");
1051
930
  image.removeEventListener("load", recordInlineImage);
1052
- image.removeEventListener("error", onImageLoadError);
1053
931
  try {
1054
932
  canvasService.width = image.naturalWidth;
1055
933
  canvasService.height = image.naturalHeight;
@@ -1059,15 +937,11 @@ function serializeElementNode(n2, options) {
1059
937
  dataURLOptions.quality
1060
938
  );
1061
939
  } catch (err) {
1062
- console.log("catched err", err);
1063
940
  if (image.crossOrigin !== "anonymous") {
1064
941
  image.crossOrigin = "anonymous";
1065
942
  if (image.complete && image.naturalWidth !== 0)
1066
943
  recordInlineImage();
1067
- else {
1068
- image.addEventListener("load", recordInlineImage);
1069
- image.addEventListener("error", onImageLoadError);
1070
- }
944
+ else image.addEventListener("load", recordInlineImage);
1071
945
  return;
1072
946
  } else {
1073
947
  console.warn(
@@ -1075,19 +949,12 @@ function serializeElementNode(n2, options) {
1075
949
  );
1076
950
  }
1077
951
  }
1078
- cleanupCrossOriginAttribute();
1079
- };
1080
- const onImageLoadError = () => {
1081
- console.log("onImageLoadError()");
1082
- image.removeEventListener("load", recordInlineImage);
1083
- image.removeEventListener("error", onImageLoadError);
1084
- cleanupCrossOriginAttribute();
952
+ if (image.crossOrigin === "anonymous") {
953
+ priorCrossOrigin ? attributes.crossOrigin = priorCrossOrigin : image.removeAttribute("crossorigin");
954
+ }
1085
955
  };
1086
956
  if (image.complete && image.naturalWidth !== 0) recordInlineImage();
1087
- else {
1088
- image.addEventListener("load", recordInlineImage);
1089
- image.addEventListener("error", onImageLoadError);
1090
- }
957
+ else image.addEventListener("load", recordInlineImage);
1091
958
  }
1092
959
  if (tagName === "audio" || tagName === "video") {
1093
960
  const mediaAttributes = attributes;
@@ -1149,7 +1016,7 @@ function slimDOMExcluded(sn, slimDOMOptions) {
1149
1016
  } else if (sn.type === NodeType$3.Element) {
1150
1017
  if (slimDOMOptions.script && // script tag
1151
1018
  (sn.tagName === "script" || // (module)preload link
1152
- 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
1153
1020
  sn.tagName === "link" && sn.attributes.rel === "prefetch" && typeof sn.attributes.href === "string" && extractFileExtension(sn.attributes.href) === "js")) {
1154
1021
  return true;
1155
1022
  } else if (slimDOMOptions.headFavicon && (sn.tagName === "link" && sn.attributes.rel === "shortcut icon" || sn.tagName === "meta" && (lowerIfExists(sn.attributes.name).match(
@@ -1293,10 +1160,7 @@ function serializeNodeWithId(n2, options) {
1293
1160
  bypassOptions.cssCaptured = true;
1294
1161
  }
1295
1162
  for (const childN of Array.from(index$1.childNodes(n2))) {
1296
- const serializedChildNode = serializeNodeWithId(
1297
- childN,
1298
- bypassOptions
1299
- );
1163
+ const serializedChildNode = serializeNodeWithId(childN, bypassOptions);
1300
1164
  if (serializedChildNode) {
1301
1165
  serializedNode.childNodes.push(serializedChildNode);
1302
1166
  }
@@ -1305,10 +1169,7 @@ function serializeNodeWithId(n2, options) {
1305
1169
  let shadowRootEl = null;
1306
1170
  if (isElement(n2) && (shadowRootEl = index$1.shadowRoot(n2))) {
1307
1171
  for (const childN of Array.from(index$1.childNodes(shadowRootEl))) {
1308
- const serializedChildNode = serializeNodeWithId(
1309
- childN,
1310
- bypassOptions
1311
- );
1172
+ const serializedChildNode = serializeNodeWithId(childN, bypassOptions);
1312
1173
  if (serializedChildNode) {
1313
1174
  isNativeShadowDom(shadowRootEl) && (serializedChildNode.isShadow = true);
1314
1175
  serializedNode.childNodes.push(serializedChildNode);
@@ -8654,9 +8515,9 @@ function getUntaintedPrototype(key) {
8654
8515
  accessorNames && // @ts-expect-error 2345
8655
8516
  accessorNames.every(
8656
8517
  (accessor) => {
8657
- var _a2, _b2;
8518
+ var _a2, _b;
8658
8519
  return Boolean(
8659
- (_b2 = (_a2 = Object.getOwnPropertyDescriptor(defaultPrototype, accessor)) == null ? void 0 : _a2.get) == null ? void 0 : _b2.toString().includes("[native code]")
8520
+ (_b = (_a2 = Object.getOwnPropertyDescriptor(defaultPrototype, accessor)) == null ? void 0 : _a2.get) == null ? void 0 : _b.toString().includes("[native code]")
8660
8521
  );
8661
8522
  }
8662
8523
  )
@@ -8756,32 +8617,6 @@ function querySelectorAll(n2, selectors) {
8756
8617
  function mutationObserverCtor() {
8757
8618
  return getUntaintedPrototype("MutationObserver").constructor;
8758
8619
  }
8759
- function patch(source, name, replacement) {
8760
- try {
8761
- if (!(name in source)) {
8762
- return () => {
8763
- };
8764
- }
8765
- const original = source[name];
8766
- const wrapped = replacement(original);
8767
- if (typeof wrapped === "function") {
8768
- wrapped.prototype = wrapped.prototype || {};
8769
- Object.defineProperties(wrapped, {
8770
- __rrweb_original__: {
8771
- enumerable: false,
8772
- value: original
8773
- }
8774
- });
8775
- }
8776
- source[name] = wrapped;
8777
- return () => {
8778
- source[name] = original;
8779
- };
8780
- } catch {
8781
- return () => {
8782
- };
8783
- }
8784
- }
8785
8620
  const index = {
8786
8621
  childNodes,
8787
8622
  parentNode,
@@ -8794,8 +8629,7 @@ const index = {
8794
8629
  shadowRoot,
8795
8630
  querySelector,
8796
8631
  querySelectorAll,
8797
- mutationObserver: mutationObserverCtor,
8798
- patch
8632
+ mutationObserver: mutationObserverCtor
8799
8633
  };
8800
8634
  function on(type, fn, target = document) {
8801
8635
  const options = { capture: true, passive: true };
@@ -8878,15 +8712,41 @@ function hookSetter(target, key, d, isRevoked, win = window) {
8878
8712
  );
8879
8713
  return () => hookSetter(target, key, original || {}, true);
8880
8714
  }
8715
+ function patch(source, name, replacement) {
8716
+ try {
8717
+ if (!(name in source)) {
8718
+ return () => {
8719
+ };
8720
+ }
8721
+ const original = source[name];
8722
+ const wrapped = replacement(original);
8723
+ if (typeof wrapped === "function") {
8724
+ wrapped.prototype = wrapped.prototype || {};
8725
+ Object.defineProperties(wrapped, {
8726
+ __rrweb_original__: {
8727
+ enumerable: false,
8728
+ value: original
8729
+ }
8730
+ });
8731
+ }
8732
+ source[name] = wrapped;
8733
+ return () => {
8734
+ source[name] = original;
8735
+ };
8736
+ } catch {
8737
+ return () => {
8738
+ };
8739
+ }
8740
+ }
8881
8741
  let nowTimestamp = Date.now;
8882
8742
  if (!/* @__PURE__ */ /[1-9][0-9]{12}/.test(Date.now().toString())) {
8883
8743
  nowTimestamp = () => (/* @__PURE__ */ new Date()).getTime();
8884
8744
  }
8885
8745
  function getWindowScroll(win) {
8886
- var _a2, _b2, _c, _d;
8746
+ var _a2, _b, _c, _d;
8887
8747
  const doc = win.document;
8888
8748
  return {
8889
- left: doc.scrollingElement ? doc.scrollingElement.scrollLeft : win.pageXOffset !== void 0 ? win.pageXOffset : doc.documentElement.scrollLeft || (doc == null ? void 0 : doc.body) && ((_a2 = index.parentElement(doc.body)) == null ? void 0 : _a2.scrollLeft) || ((_b2 = doc == null ? void 0 : doc.body) == null ? void 0 : _b2.scrollLeft) || 0,
8749
+ left: doc.scrollingElement ? doc.scrollingElement.scrollLeft : win.pageXOffset !== void 0 ? win.pageXOffset : doc.documentElement.scrollLeft || (doc == null ? void 0 : doc.body) && ((_a2 = index.parentElement(doc.body)) == null ? void 0 : _a2.scrollLeft) || ((_b = doc == null ? void 0 : doc.body) == null ? void 0 : _b.scrollLeft) || 0,
8890
8750
  top: doc.scrollingElement ? doc.scrollingElement.scrollTop : win.pageYOffset !== void 0 ? win.pageYOffset : (doc == null ? void 0 : doc.documentElement.scrollTop) || (doc == null ? void 0 : doc.body) && ((_c = index.parentElement(doc.body)) == null ? void 0 : _c.scrollTop) || ((_d = doc == null ? void 0 : doc.body) == null ? void 0 : _d.scrollTop) || 0
8891
8751
  };
8892
8752
  }
@@ -9439,18 +9299,10 @@ class MutationBuffer {
9439
9299
  this.attributes.push(item);
9440
9300
  this.attributeMap.set(textarea, item);
9441
9301
  }
9442
- const value = Array.from(
9302
+ item.attributes.value = Array.from(
9443
9303
  index.childNodes(textarea),
9444
9304
  (cn) => index.textContent(cn) || ""
9445
9305
  ).join("");
9446
- item.attributes.value = maskInputValue({
9447
- element: textarea,
9448
- maskInputOptions: this.maskInputOptions,
9449
- tagName: textarea.tagName,
9450
- type: getInputType(textarea),
9451
- value,
9452
- maskInputFn: this.maskInputFn
9453
- });
9454
9306
  });
9455
9307
  __publicField(this, "processMutation", (m) => {
9456
9308
  if (isIgnored(m.target, this.mirror, this.slimDOMOptions)) {
@@ -10329,11 +10181,11 @@ function initAdoptedStyleSheetObserver({
10329
10181
  mirror: mirror2,
10330
10182
  stylesheetManager
10331
10183
  }, host2) {
10332
- var _a2, _b2, _c;
10184
+ var _a2, _b, _c;
10333
10185
  let hostId = null;
10334
10186
  if (host2.nodeName === "#document") hostId = mirror2.getId(host2);
10335
10187
  else hostId = mirror2.getId(index.host(host2));
10336
- const patchTarget = host2.nodeName === "#document" ? (_a2 = host2.defaultView) == null ? void 0 : _a2.Document : (_c = (_b2 = host2.ownerDocument) == null ? void 0 : _b2.defaultView) == null ? void 0 : _c.ShadowRoot;
10188
+ const patchTarget = host2.nodeName === "#document" ? (_a2 = host2.defaultView) == null ? void 0 : _a2.Document : (_c = (_b = host2.ownerDocument) == null ? void 0 : _b.defaultView) == null ? void 0 : _c.ShadowRoot;
10337
10189
  const originalPropertyDescriptor = (patchTarget == null ? void 0 : patchTarget.prototype) ? Object.getOwnPropertyDescriptor(
10338
10190
  patchTarget == null ? void 0 : patchTarget.prototype,
10339
10191
  "adoptedStyleSheets"
@@ -10846,7 +10698,7 @@ class IframeManager {
10846
10698
  this.loadListener = cb;
10847
10699
  }
10848
10700
  attachIframe(iframeEl, childSn) {
10849
- var _a2, _b2;
10701
+ var _a2, _b;
10850
10702
  this.mutationCb({
10851
10703
  adds: [
10852
10704
  {
@@ -10865,7 +10717,7 @@ class IframeManager {
10865
10717
  "message",
10866
10718
  this.handleMessage.bind(this)
10867
10719
  );
10868
- (_b2 = this.loadListener) == null ? void 0 : _b2.call(this, iframeEl);
10720
+ (_b = this.loadListener) == null ? void 0 : _b.call(this, iframeEl);
10869
10721
  if (iframeEl.contentDocument && iframeEl.contentDocument.adoptedStyleSheets && iframeEl.contentDocument.adoptedStyleSheets.length > 0)
10870
10722
  this.stylesheetManager.adoptStyleSheets(
10871
10723
  iframeEl.contentDocument.adoptedStyleSheets,