@appsurify-testmap/rrweb-record 3.1.1-alpha.3 → 3.2.0-alpha.1

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.
@@ -13471,6 +13471,30 @@ class MutationBuffer {
13471
13471
  this.shadowDomManager.reset();
13472
13472
  this.canvasManager.reset();
13473
13473
  }
13474
+ /**
13475
+ * Clear all accumulated mutation data without emitting.
13476
+ * Used after freeze+debounce checkout — FullSnapshot already captured the state.
13477
+ */
13478
+ resetBuffers() {
13479
+ this.addedSet = /* @__PURE__ */ new Set();
13480
+ this.movedSet = /* @__PURE__ */ new Set();
13481
+ this.droppedSet = /* @__PURE__ */ new Set();
13482
+ this.removesSubTreeCache = /* @__PURE__ */ new Set();
13483
+ this.mapRemoves = [];
13484
+ this.movedMap = {};
13485
+ this.attributes = [];
13486
+ this.texts = [];
13487
+ this.attributeMap = /* @__PURE__ */ new WeakMap();
13488
+ this.removes = [];
13489
+ }
13490
+ /**
13491
+ * Clear frozen flag without triggering emit.
13492
+ * Used after freeze+debounce checkout — buffers already cleared by resetBuffers().
13493
+ */
13494
+ unsetFrozen() {
13495
+ this.frozen = false;
13496
+ this.canvasManager.unfreeze();
13497
+ }
13474
13498
  }
13475
13499
  function deepDelete(addsSet, n2) {
13476
13500
  addsSet.delete(n2);
@@ -15861,10 +15885,13 @@ class VisibilityManager {
15861
15885
  }
15862
15886
  flushBuffer() {
15863
15887
  var _a2;
15888
+ if (this.frozen || this.locked) return;
15864
15889
  if (this.buffer.size === 0) return;
15865
- (_a2 = this.notifyActivity) == null ? void 0 : _a2.call(this, this.buffer.size);
15866
- this.mutationCb({ mutations: Array.from(this.buffer.values()) });
15890
+ const mutations = Array.from(this.buffer.values());
15891
+ const count = mutations.length;
15867
15892
  this.buffer.clear();
15893
+ this.mutationCb({ mutations });
15894
+ (_a2 = this.notifyActivity) == null ? void 0 : _a2.call(this, count);
15868
15895
  }
15869
15896
  observe(el) {
15870
15897
  if (this.disabled) return;
@@ -15878,6 +15905,10 @@ class VisibilityManager {
15878
15905
  }
15879
15906
  freeze() {
15880
15907
  this.frozen = true;
15908
+ if (this.debounceTimer) {
15909
+ clearTimeout(this.debounceTimer);
15910
+ this.debounceTimer = null;
15911
+ }
15881
15912
  }
15882
15913
  unfreeze() {
15883
15914
  this.frozen = false;
@@ -15885,9 +15916,33 @@ class VisibilityManager {
15885
15916
  }
15886
15917
  lock() {
15887
15918
  this.locked = true;
15919
+ if (this.debounceTimer) {
15920
+ clearTimeout(this.debounceTimer);
15921
+ this.debounceTimer = null;
15922
+ }
15888
15923
  }
15889
15924
  unlock() {
15890
15925
  this.locked = false;
15926
+ this.buffer.clear();
15927
+ if (this.debounceTimer) {
15928
+ clearTimeout(this.debounceTimer);
15929
+ this.debounceTimer = null;
15930
+ }
15931
+ if (!this.disabled && this.elements.size > 0) {
15932
+ this.previousState = computeVisibility(this.elements, /* @__PURE__ */ new Map(), {
15933
+ root: this.root,
15934
+ threshold: this.threshold,
15935
+ sensitivity: this.sensitivity,
15936
+ rootMargin: this.rootMargin
15937
+ });
15938
+ }
15939
+ }
15940
+ /**
15941
+ * Clear frozen flag without triggering flush.
15942
+ * Used after freeze+debounce checkout — buffer already cleared by unlock().
15943
+ */
15944
+ unsetFrozen() {
15945
+ this.frozen = false;
15891
15946
  }
15892
15947
  reset() {
15893
15948
  this.elements.clear();
@@ -16040,6 +16095,7 @@ function record(options = {}) {
16040
16095
  checkoutEveryNms,
16041
16096
  checkoutEveryNth,
16042
16097
  checkoutEveryNvm,
16098
+ checkoutDebounce,
16043
16099
  blockClass = "rr-block",
16044
16100
  blockSelector = null,
16045
16101
  ignoreClass = "rr-ignore",
@@ -16134,6 +16190,10 @@ function record(options = {}) {
16134
16190
  let lastFullSnapshotEvent;
16135
16191
  let incrementalSnapshotCount = 0;
16136
16192
  let visibilityMutationCount = 0;
16193
+ let checkoutId = 0;
16194
+ let checkoutPending = false;
16195
+ let checkoutDebounceTimer = null;
16196
+ let checkoutFreezeTimestamp = null;
16137
16197
  const eventProcessor = (e2) => {
16138
16198
  for (const plugin3 of plugins || []) {
16139
16199
  if (plugin3.eventProcessor) {
@@ -16146,11 +16206,25 @@ function record(options = {}) {
16146
16206
  }
16147
16207
  return e2;
16148
16208
  };
16209
+ const executeCheckout = () => {
16210
+ checkoutDebounceTimer = null;
16211
+ checkoutPending = false;
16212
+ checkoutFreezeTimestamp = null;
16213
+ takeFullSnapshot$1(true);
16214
+ mutationBuffers.forEach((buf) => {
16215
+ buf.resetBuffers();
16216
+ buf.unsetFrozen();
16217
+ });
16218
+ if (visibilityManager) {
16219
+ visibilityManager.unsetFrozen();
16220
+ }
16221
+ };
16149
16222
  wrappedEmit = (r2, isCheckout) => {
16150
16223
  var _a2;
16151
16224
  const e2 = r2;
16152
16225
  e2.timestamp = nowTimestamp();
16153
- if (((_a2 = mutationBuffers[0]) == null ? void 0 : _a2.isFrozen()) && e2.type !== EventType.FullSnapshot && !(e2.type === EventType.IncrementalSnapshot && e2.data.source === IncrementalSource.Mutation)) {
16226
+ e2.checkoutId = checkoutId;
16227
+ if (((_a2 = mutationBuffers[0]) == null ? void 0 : _a2.isFrozen()) && !checkoutPending && e2.type !== EventType.FullSnapshot && !(e2.type === EventType.IncrementalSnapshot && e2.data.source === IncrementalSource.Mutation)) {
16154
16228
  mutationBuffers.forEach((buf) => buf.unfreeze());
16155
16229
  visibilityManager == null ? void 0 : visibilityManager.unfreeze();
16156
16230
  }
@@ -16177,7 +16251,29 @@ function record(options = {}) {
16177
16251
  const exceedCount = checkoutEveryNth && incrementalSnapshotCount >= checkoutEveryNth;
16178
16252
  const exceedTime = checkoutEveryNms && e2.timestamp - lastFullSnapshotEvent.timestamp > checkoutEveryNms;
16179
16253
  if (exceedCount || exceedTime) {
16180
- takeFullSnapshot$1(true);
16254
+ if (checkoutDebounce) {
16255
+ if (!checkoutPending) {
16256
+ checkoutPending = true;
16257
+ checkoutFreezeTimestamp = nowTimestamp();
16258
+ mutationBuffers.forEach((buf) => buf.freeze());
16259
+ visibilityManager == null ? void 0 : visibilityManager.freeze();
16260
+ }
16261
+ if (checkoutDebounceTimer) {
16262
+ clearTimeout(checkoutDebounceTimer);
16263
+ }
16264
+ const frozenDuration = nowTimestamp() - checkoutFreezeTimestamp;
16265
+ const maxFreeze = checkoutDebounce * 3;
16266
+ if (frozenDuration >= maxFreeze) {
16267
+ executeCheckout();
16268
+ } else {
16269
+ checkoutDebounceTimer = setTimeout(
16270
+ () => executeCheckout(),
16271
+ checkoutDebounce
16272
+ );
16273
+ }
16274
+ } else {
16275
+ takeFullSnapshot$1(true);
16276
+ }
16181
16277
  }
16182
16278
  }
16183
16279
  }
@@ -16292,8 +16388,30 @@ function record(options = {}) {
16292
16388
  notifyActivity: checkoutEveryNvm != null ? (count) => {
16293
16389
  visibilityMutationCount += count;
16294
16390
  if (visibilityMutationCount >= checkoutEveryNvm) {
16295
- takeFullSnapshot$1(true);
16296
16391
  visibilityMutationCount = 0;
16392
+ if (checkoutDebounce) {
16393
+ if (!checkoutPending) {
16394
+ checkoutPending = true;
16395
+ checkoutFreezeTimestamp = nowTimestamp();
16396
+ mutationBuffers.forEach((buf) => buf.freeze());
16397
+ visibilityManager == null ? void 0 : visibilityManager.freeze();
16398
+ }
16399
+ if (checkoutDebounceTimer) {
16400
+ clearTimeout(checkoutDebounceTimer);
16401
+ }
16402
+ const frozenDuration = nowTimestamp() - checkoutFreezeTimestamp;
16403
+ const maxFreeze = checkoutDebounce * 3;
16404
+ if (frozenDuration >= maxFreeze) {
16405
+ executeCheckout();
16406
+ } else {
16407
+ checkoutDebounceTimer = setTimeout(
16408
+ () => executeCheckout(),
16409
+ checkoutDebounce
16410
+ );
16411
+ }
16412
+ } else {
16413
+ takeFullSnapshot$1(true);
16414
+ }
16297
16415
  }
16298
16416
  } : void 0
16299
16417
  });
@@ -16302,6 +16420,7 @@ function record(options = {}) {
16302
16420
  if (!recordDOM) {
16303
16421
  return;
16304
16422
  }
16423
+ checkoutId++;
16305
16424
  wrappedEmit(
16306
16425
  {
16307
16426
  type: EventType.Meta,
@@ -16580,6 +16699,10 @@ function record(options = {}) {
16580
16699
  );
16581
16700
  }
16582
16701
  return () => {
16702
+ if (checkoutDebounceTimer) {
16703
+ clearTimeout(checkoutDebounceTimer);
16704
+ checkoutDebounceTimer = null;
16705
+ }
16583
16706
  flushCustomEventQueue$1();
16584
16707
  handlers.forEach((h) => h());
16585
16708
  processedNodeManager.destroy();