@posthog/rrweb-player 0.0.24 → 0.0.26

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.
@@ -4758,6 +4758,12 @@ function buildNodeWithSN(n2, options) {
4758
4758
  } else {
4759
4759
  node2.appendChild(childNode);
4760
4760
  }
4761
+ } else if (n2.type === NodeType$1$1.Document && childN.type === NodeType$1$1.DocumentType) {
4762
+ if (node2.firstChild && node2.firstChild.nodeType === 1) {
4763
+ node2.insertBefore(childNode, node2.firstChild);
4764
+ } else {
4765
+ node2.appendChild(childNode);
4766
+ }
4761
4767
  } else {
4762
4768
  node2.appendChild(childNode);
4763
4769
  }
@@ -11737,6 +11743,11 @@ class Replayer {
11737
11743
  __publicField2(this, "lastSelectionData", null);
11738
11744
  __publicField2(this, "constructedStyleMutations", []);
11739
11745
  __publicField2(this, "adoptedStyleSheets", []);
11746
+ __publicField2(this, "emitterHandlers", []);
11747
+ __publicField2(this, "serviceSubscription");
11748
+ __publicField2(this, "speedServiceSubscription");
11749
+ __publicField2(this, "timeouts", /* @__PURE__ */ new Set());
11750
+ __publicField2(this, "styleSheetLoadListeners", /* @__PURE__ */ new Map());
11740
11751
  __publicField2(this, "handleResize", (dimension) => {
11741
11752
  this.iframe.style.display = "inherit";
11742
11753
  for (const el of [this.mouseTail, this.iframe]) {
@@ -11896,12 +11907,12 @@ class Replayer {
11896
11907
  this.handleResize = this.handleResize.bind(this);
11897
11908
  this.getCastFn = this.getCastFn.bind(this);
11898
11909
  this.applyEventsSynchronously = this.applyEventsSynchronously.bind(this);
11899
- this.emitter.on(ReplayerEvents.Resize, this.handleResize);
11910
+ this.addEmitterHandler(ReplayerEvents.Resize, this.handleResize);
11900
11911
  this.setupDom();
11901
11912
  for (const plugin of this.config.plugins || []) {
11902
11913
  if (plugin.getMirror) plugin.getMirror({ nodeMirror: this.mirror });
11903
11914
  }
11904
- this.emitter.on(ReplayerEvents.Flush, () => {
11915
+ const flushHandler = () => {
11905
11916
  if (this.usingVirtualDom) {
11906
11917
  const replayerHandler = {
11907
11918
  mirror: this.mirror,
@@ -11997,13 +12008,15 @@ class Replayer {
11997
12008
  this.applySelection(this.lastSelectionData);
11998
12009
  this.lastSelectionData = null;
11999
12010
  }
12000
- });
12001
- this.emitter.on(ReplayerEvents.PlayBack, () => {
12011
+ };
12012
+ this.addEmitterHandler(ReplayerEvents.Flush, flushHandler);
12013
+ const playBackHandler = () => {
12002
12014
  this.firstFullSnapshot = null;
12003
12015
  this.mirror.reset();
12004
12016
  this.styleMirror.reset();
12005
12017
  this.mediaManager.reset();
12006
- });
12018
+ };
12019
+ this.addEmitterHandler(ReplayerEvents.PlayBack, playBackHandler);
12007
12020
  const timer = new Timer([], {
12008
12021
  speed: this.config.speed
12009
12022
  });
@@ -12027,7 +12040,7 @@ class Replayer {
12027
12040
  }
12028
12041
  );
12029
12042
  this.service.start();
12030
- this.service.subscribe((state) => {
12043
+ this.serviceSubscription = this.service.subscribe((state) => {
12031
12044
  this.emitter.emit(ReplayerEvents.StateChange, {
12032
12045
  player: state
12033
12046
  });
@@ -12037,7 +12050,7 @@ class Replayer {
12037
12050
  timer
12038
12051
  });
12039
12052
  this.speedService.start();
12040
- this.speedService.subscribe((state) => {
12053
+ this.speedServiceSubscription = this.speedService.subscribe((state) => {
12041
12054
  this.emitter.emit(ReplayerEvents.StateChange, {
12042
12055
  speed: state
12043
12056
  });
@@ -12057,7 +12070,7 @@ class Replayer {
12057
12070
  );
12058
12071
  if (firstMeta) {
12059
12072
  const { width, height } = firstMeta.data;
12060
- setTimeout(() => {
12073
+ this.addTimeout(() => {
12061
12074
  this.emitter.emit(ReplayerEvents.Resize, {
12062
12075
  width,
12063
12076
  height
@@ -12065,7 +12078,7 @@ class Replayer {
12065
12078
  }, 0);
12066
12079
  }
12067
12080
  if (firstFullsnapshot) {
12068
- setTimeout(() => {
12081
+ this.addTimeout(() => {
12069
12082
  var _a2;
12070
12083
  if (this.firstFullSnapshot) {
12071
12084
  return;
@@ -12094,6 +12107,24 @@ class Replayer {
12094
12107
  this.emitter.off(event, handler);
12095
12108
  return this;
12096
12109
  }
12110
+ /**
12111
+ * Track emitter handlers for cleanup
12112
+ */
12113
+ addEmitterHandler(event, handler) {
12114
+ this.emitter.on(event, handler);
12115
+ this.emitterHandlers.push({ event, handler });
12116
+ }
12117
+ /**
12118
+ * Track timeouts for cleanup
12119
+ */
12120
+ addTimeout(callback, delay) {
12121
+ const timeout = setTimeout(() => {
12122
+ this.timeouts.delete(timeout);
12123
+ callback();
12124
+ }, delay);
12125
+ this.timeouts.add(timeout);
12126
+ return timeout;
12127
+ }
12097
12128
  setConfig(config) {
12098
12129
  Object.keys(config).forEach((key) => {
12099
12130
  config[key];
@@ -12196,10 +12227,31 @@ class Replayer {
12196
12227
  * Memory occupation can be released by removing all references to this replayer.
12197
12228
  */
12198
12229
  destroy() {
12230
+ var _a2, _b2;
12231
+ if (!this.wrapper || !this.wrapper.parentNode) {
12232
+ return;
12233
+ }
12199
12234
  this.pause();
12235
+ this.emitterHandlers.forEach(({ event, handler }) => {
12236
+ this.emitter.off(event, handler);
12237
+ });
12238
+ this.emitterHandlers = [];
12239
+ (_a2 = this.serviceSubscription) == null ? void 0 : _a2.unsubscribe();
12240
+ (_b2 = this.speedServiceSubscription) == null ? void 0 : _b2.unsubscribe();
12241
+ this.serviceSubscription = void 0;
12242
+ this.speedServiceSubscription = void 0;
12243
+ this.timeouts.forEach((timeout) => clearTimeout(timeout));
12244
+ this.timeouts.clear();
12245
+ this.styleSheetLoadListeners.forEach((handler, element2) => {
12246
+ element2.removeEventListener("load", handler);
12247
+ });
12248
+ this.styleSheetLoadListeners.clear();
12249
+ this.imageMap.clear();
12250
+ this.canvasEventMap.clear();
12200
12251
  this.mirror.reset();
12201
12252
  this.styleMirror.reset();
12202
12253
  this.mediaManager.reset();
12254
+ this.resetCache();
12203
12255
  this.config.root.removeChild(this.wrapper);
12204
12256
  this.emitter.emit(ReplayerEvents.Destroy);
12205
12257
  }