@posthog/rrweb 0.0.28 → 0.0.29

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/rrweb.js CHANGED
@@ -205,6 +205,91 @@ function isShadowRoot(n2) {
205
205
  function isNativeShadowDom(shadowRoot2) {
206
206
  return Object.prototype.toString.call(shadowRoot2) === "[object ShadowRoot]";
207
207
  }
208
+ function fixBrowserCompatibilityIssuesInCSS(cssText) {
209
+ if (cssText.includes(" background-clip: text;") && !cssText.includes(" -webkit-background-clip: text;")) {
210
+ cssText = cssText.replace(
211
+ /\sbackground-clip:\s*text;/g,
212
+ " -webkit-background-clip: text; background-clip: text;"
213
+ );
214
+ }
215
+ return cssText;
216
+ }
217
+ function escapeImportStatement(rule2) {
218
+ const { cssText } = rule2;
219
+ if (cssText.split('"').length < 3) return cssText;
220
+ const statement = ["@import", `url(${JSON.stringify(rule2.href)})`];
221
+ if (rule2.layerName === "") {
222
+ statement.push(`layer`);
223
+ } else if (rule2.layerName) {
224
+ statement.push(`layer(${rule2.layerName})`);
225
+ }
226
+ if (rule2.supportsText) {
227
+ statement.push(`supports(${rule2.supportsText})`);
228
+ }
229
+ if (rule2.media.length) {
230
+ statement.push(rule2.media.mediaText);
231
+ }
232
+ return statement.join(" ") + ";";
233
+ }
234
+ function stringifyStylesheet(s2) {
235
+ try {
236
+ const rules2 = s2.rules || s2.cssRules;
237
+ if (!rules2) {
238
+ return null;
239
+ }
240
+ let sheetHref = s2.href;
241
+ if (!sheetHref && s2.ownerNode) {
242
+ sheetHref = s2.ownerNode.baseURI;
243
+ }
244
+ const stringifiedRules = Array.from(
245
+ rules2,
246
+ (rule2) => stringifyRule(rule2, sheetHref)
247
+ ).join("");
248
+ return fixBrowserCompatibilityIssuesInCSS(stringifiedRules);
249
+ } catch (error) {
250
+ return null;
251
+ }
252
+ }
253
+ function stringifyRule(rule2, sheetHref) {
254
+ var _a2;
255
+ if (isCSSImportRule(rule2)) {
256
+ let importStringified;
257
+ try {
258
+ importStringified = // for same-origin stylesheets,
259
+ // we can access the imported stylesheet rules directly
260
+ stringifyStylesheet(rule2.styleSheet) || // work around browser issues with the raw string `@import url(...)` statement
261
+ escapeImportStatement(rule2);
262
+ } catch (error) {
263
+ importStringified = rule2.cssText;
264
+ }
265
+ try {
266
+ if (importStringified && ((_a2 = rule2.styleSheet) == null ? void 0 : _a2.href)) {
267
+ return absolutifyURLs(importStringified, rule2.styleSheet.href);
268
+ }
269
+ } catch {
270
+ }
271
+ return importStringified;
272
+ } else {
273
+ let ruleStringified = rule2.cssText;
274
+ if (isCSSStyleRule(rule2) && rule2.selectorText.includes(":")) {
275
+ ruleStringified = fixSafariColons(ruleStringified);
276
+ }
277
+ if (sheetHref) {
278
+ return absolutifyURLs(ruleStringified, sheetHref);
279
+ }
280
+ return ruleStringified;
281
+ }
282
+ }
283
+ function fixSafariColons(cssStringified) {
284
+ const regex = /(\[(?:[\w-]+)[^\\])(:(?:[\w-]+)\])/gm;
285
+ return cssStringified.replace(regex, "$1\\$2");
286
+ }
287
+ function isCSSImportRule(rule2) {
288
+ return "styleSheet" in rule2;
289
+ }
290
+ function isCSSStyleRule(rule2) {
291
+ return "selectorText" in rule2;
292
+ }
208
293
  class Mirror {
209
294
  constructor() {
210
295
  __publicField$1(this, "idNodeMap", /* @__PURE__ */ new Map());
@@ -339,91 +424,6 @@ function extractFileExtension(path, baseURL) {
339
424
  const match = url.pathname.match(regex);
340
425
  return (match == null ? void 0 : match[1]) ?? null;
341
426
  }
342
- function fixBrowserCompatibilityIssuesInCSS(cssText) {
343
- if (cssText.includes(" background-clip: text;") && !cssText.includes(" -webkit-background-clip: text;")) {
344
- cssText = cssText.replace(
345
- /\sbackground-clip:\s*text;/g,
346
- " -webkit-background-clip: text; background-clip: text;"
347
- );
348
- }
349
- return cssText;
350
- }
351
- function escapeImportStatement(rule2) {
352
- const { cssText } = rule2;
353
- if (cssText.split('"').length < 3) return cssText;
354
- const statement = ["@import", `url(${JSON.stringify(rule2.href)})`];
355
- if (rule2.layerName === "") {
356
- statement.push(`layer`);
357
- } else if (rule2.layerName) {
358
- statement.push(`layer(${rule2.layerName})`);
359
- }
360
- if (rule2.supportsText) {
361
- statement.push(`supports(${rule2.supportsText})`);
362
- }
363
- if (rule2.media.length) {
364
- statement.push(rule2.media.mediaText);
365
- }
366
- return statement.join(" ") + ";";
367
- }
368
- function stringifyStylesheet(s2) {
369
- try {
370
- const rules2 = s2.rules || s2.cssRules;
371
- if (!rules2) {
372
- return null;
373
- }
374
- let sheetHref = s2.href;
375
- if (!sheetHref && s2.ownerNode) {
376
- sheetHref = s2.ownerNode.baseURI;
377
- }
378
- const stringifiedRules = Array.from(
379
- rules2,
380
- (rule2) => stringifyRule(rule2, sheetHref)
381
- ).join("");
382
- return fixBrowserCompatibilityIssuesInCSS(stringifiedRules);
383
- } catch (error) {
384
- return null;
385
- }
386
- }
387
- function stringifyRule(rule2, sheetHref) {
388
- var _a2;
389
- if (isCSSImportRule(rule2)) {
390
- let importStringified;
391
- try {
392
- importStringified = // for same-origin stylesheets,
393
- // we can access the imported stylesheet rules directly
394
- stringifyStylesheet(rule2.styleSheet) || // work around browser issues with the raw string `@import url(...)` statement
395
- escapeImportStatement(rule2);
396
- } catch (error) {
397
- importStringified = rule2.cssText;
398
- }
399
- try {
400
- if (importStringified && ((_a2 = rule2.styleSheet) == null ? void 0 : _a2.href)) {
401
- return absolutifyURLs(importStringified, rule2.styleSheet.href);
402
- }
403
- } catch {
404
- }
405
- return importStringified;
406
- } else {
407
- let ruleStringified = rule2.cssText;
408
- if (isCSSStyleRule(rule2) && rule2.selectorText.includes(":")) {
409
- ruleStringified = fixSafariColons(ruleStringified);
410
- }
411
- if (sheetHref) {
412
- return absolutifyURLs(ruleStringified, sheetHref);
413
- }
414
- return ruleStringified;
415
- }
416
- }
417
- function fixSafariColons(cssStringified) {
418
- const regex = /(\[(?:[\w-]+)[^\\])(:(?:[\w-]+)\])/gm;
419
- return cssStringified.replace(regex, "$1\\$2");
420
- }
421
- function isCSSImportRule(rule2) {
422
- return "styleSheet" in rule2;
423
- }
424
- function isCSSStyleRule(rule2) {
425
- return "selectorText" in rule2;
426
- }
427
427
  function extractOrigin(url) {
428
428
  let origin = "";
429
429
  if (url.indexOf("//") > -1) {
@@ -5330,22 +5330,6 @@ postcss$1.Input;
5330
5330
  postcss$1.Rule;
5331
5331
  postcss$1.Root;
5332
5332
  postcss$1.Node;
5333
- function adaptCssForReplay(cssText, cache) {
5334
- const cachedStyle = cache == null ? void 0 : cache.stylesWithHoverClass.get(cssText);
5335
- if (cachedStyle) return cachedStyle;
5336
- let result2 = cssText;
5337
- try {
5338
- const ast = postcss$1([
5339
- mediaSelectorPlugin,
5340
- pseudoClassPlugin
5341
- ]).process(cssText, { parser: safeParser });
5342
- result2 = ast.css;
5343
- } catch (error) {
5344
- console.warn("Failed to adapt css for replay", error);
5345
- }
5346
- cache == null ? void 0 : cache.stylesWithHoverClass.set(cssText, result2);
5347
- return result2;
5348
- }
5349
5333
  const tagMap = {
5350
5334
  script: "noscript",
5351
5335
  // camel case svg element tag names
@@ -5393,6 +5377,22 @@ function getTagName(n2) {
5393
5377
  }
5394
5378
  return tagName;
5395
5379
  }
5380
+ function adaptCssForReplay(cssText, cache) {
5381
+ const cachedStyle = cache == null ? void 0 : cache.stylesWithHoverClass.get(cssText);
5382
+ if (cachedStyle) return cachedStyle;
5383
+ let result2 = cssText;
5384
+ try {
5385
+ const ast = postcss$1([
5386
+ mediaSelectorPlugin,
5387
+ pseudoClassPlugin
5388
+ ]).process(cssText, { parser: safeParser });
5389
+ result2 = ast.css;
5390
+ } catch (error) {
5391
+ console.warn("Failed to adapt css for replay", error);
5392
+ }
5393
+ cache == null ? void 0 : cache.stylesWithHoverClass.set(cssText, result2);
5394
+ return result2;
5395
+ }
5396
5396
  function createCache() {
5397
5397
  const stylesWithHoverClass = /* @__PURE__ */ new Map();
5398
5398
  return {
@@ -12166,6 +12166,11 @@ class MutationBuffer {
12166
12166
  this.shadowDomManager.reset();
12167
12167
  this.canvasManager.reset();
12168
12168
  }
12169
+ destroy() {
12170
+ while (this.mapRemoves.length) {
12171
+ this.mirror.removeNodeFromMap(this.mapRemoves.shift());
12172
+ }
12173
+ }
12169
12174
  }
12170
12175
  function deepDelete(addsSet, n2) {
12171
12176
  addsSet.delete(n2);
@@ -13212,6 +13217,7 @@ function initObservers(o2, hooks = {}) {
13212
13217
  );
13213
13218
  }
13214
13219
  return callbackWrapper(() => {
13220
+ mutationBuffers.forEach((b) => b.destroy());
13215
13221
  mutationBuffers.forEach((b) => b.reset());
13216
13222
  mutationObserver == null ? void 0 : mutationObserver.disconnect();
13217
13223
  mousemoveHandler();
@@ -13550,6 +13556,8 @@ class IframeManager {
13550
13556
  contentWindow.removeEventListener("message", handler);
13551
13557
  });
13552
13558
  this.nestedIframeListeners.clear();
13559
+ this.crossOriginIframeMirror.reset();
13560
+ this.crossOriginIframeStyleMirror.reset();
13553
13561
  }
13554
13562
  }
13555
13563
  class ShadowDomManager {
@@ -14028,6 +14036,8 @@ class CanvasManager {
14028
14036
  __publicField(this, "resetObservers");
14029
14037
  __publicField(this, "frozen", false);
14030
14038
  __publicField(this, "locked", false);
14039
+ __publicField(this, "rafIdTimestamp", null);
14040
+ __publicField(this, "rafIdFlush", null);
14031
14041
  __publicField(this, "processMutation", (target, mutation) => {
14032
14042
  const newFrame = this.rafStamps.invokeId && this.rafStamps.latestId !== this.rafStamps.invokeId;
14033
14043
  if (newFrame || !this.rafStamps.invokeId)
@@ -14062,6 +14072,14 @@ class CanvasManager {
14062
14072
  reset() {
14063
14073
  this.pendingCanvasMutations.clear();
14064
14074
  this.resetObservers && this.resetObservers();
14075
+ if (this.rafIdTimestamp !== null) {
14076
+ cancelAnimationFrame(this.rafIdTimestamp);
14077
+ this.rafIdTimestamp = null;
14078
+ }
14079
+ if (this.rafIdFlush !== null) {
14080
+ cancelAnimationFrame(this.rafIdFlush);
14081
+ this.rafIdFlush = null;
14082
+ }
14065
14083
  }
14066
14084
  freeze() {
14067
14085
  this.frozen = true;
@@ -14212,14 +14230,16 @@ class CanvasManager {
14212
14230
  };
14213
14231
  }
14214
14232
  startPendingCanvasMutationFlusher() {
14215
- requestAnimationFrame(() => this.flushPendingCanvasMutations());
14233
+ this.rafIdFlush = requestAnimationFrame(
14234
+ () => this.flushPendingCanvasMutations()
14235
+ );
14216
14236
  }
14217
14237
  startRAFTimestamping() {
14218
14238
  const setLatestRAFTimestamp = (timestamp) => {
14219
14239
  this.rafStamps.latestId = timestamp;
14220
- requestAnimationFrame(setLatestRAFTimestamp);
14240
+ this.rafIdTimestamp = requestAnimationFrame(setLatestRAFTimestamp);
14221
14241
  };
14222
- requestAnimationFrame(setLatestRAFTimestamp);
14242
+ this.rafIdTimestamp = requestAnimationFrame(setLatestRAFTimestamp);
14223
14243
  }
14224
14244
  flushPendingCanvasMutations() {
14225
14245
  this.pendingCanvasMutations.forEach(
@@ -14228,7 +14248,9 @@ class CanvasManager {
14228
14248
  this.flushPendingCanvasMutationFor(canvas, id);
14229
14249
  }
14230
14250
  );
14231
- requestAnimationFrame(() => this.flushPendingCanvasMutations());
14251
+ this.rafIdFlush = requestAnimationFrame(
14252
+ () => this.flushPendingCanvasMutations()
14253
+ );
14232
14254
  }
14233
14255
  flushPendingCanvasMutationFor(canvas, id) {
14234
14256
  if (this.frozen || this.locked) {
@@ -14807,6 +14829,7 @@ function record(options = {}) {
14807
14829
  processedNodeManager.destroy();
14808
14830
  iframeManager.removeLoadListener();
14809
14831
  iframeManager.destroy();
14832
+ mirror.reset();
14810
14833
  recording = false;
14811
14834
  unregisterErrorHandler();
14812
14835
  };