@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.
@@ -251,6 +251,91 @@ function isShadowRoot(n2) {
251
251
  function isNativeShadowDom(shadowRoot2) {
252
252
  return Object.prototype.toString.call(shadowRoot2) === "[object ShadowRoot]";
253
253
  }
254
+ function fixBrowserCompatibilityIssuesInCSS(cssText) {
255
+ if (cssText.includes(" background-clip: text;") && !cssText.includes(" -webkit-background-clip: text;")) {
256
+ cssText = cssText.replace(
257
+ /\sbackground-clip:\s*text;/g,
258
+ " -webkit-background-clip: text; background-clip: text;"
259
+ );
260
+ }
261
+ return cssText;
262
+ }
263
+ function escapeImportStatement(rule2) {
264
+ const { cssText } = rule2;
265
+ if (cssText.split('"').length < 3) return cssText;
266
+ const statement = ["@import", `url(${JSON.stringify(rule2.href)})`];
267
+ if (rule2.layerName === "") {
268
+ statement.push(`layer`);
269
+ } else if (rule2.layerName) {
270
+ statement.push(`layer(${rule2.layerName})`);
271
+ }
272
+ if (rule2.supportsText) {
273
+ statement.push(`supports(${rule2.supportsText})`);
274
+ }
275
+ if (rule2.media.length) {
276
+ statement.push(rule2.media.mediaText);
277
+ }
278
+ return statement.join(" ") + ";";
279
+ }
280
+ function stringifyStylesheet(s2) {
281
+ try {
282
+ const rules2 = s2.rules || s2.cssRules;
283
+ if (!rules2) {
284
+ return null;
285
+ }
286
+ let sheetHref = s2.href;
287
+ if (!sheetHref && s2.ownerNode) {
288
+ sheetHref = s2.ownerNode.baseURI;
289
+ }
290
+ const stringifiedRules = Array.from(
291
+ rules2,
292
+ (rule2) => stringifyRule(rule2, sheetHref)
293
+ ).join("");
294
+ return fixBrowserCompatibilityIssuesInCSS(stringifiedRules);
295
+ } catch (error) {
296
+ return null;
297
+ }
298
+ }
299
+ function stringifyRule(rule2, sheetHref) {
300
+ var _a2;
301
+ if (isCSSImportRule(rule2)) {
302
+ let importStringified;
303
+ try {
304
+ importStringified = // for same-origin stylesheets,
305
+ // we can access the imported stylesheet rules directly
306
+ stringifyStylesheet(rule2.styleSheet) || // work around browser issues with the raw string `@import url(...)` statement
307
+ escapeImportStatement(rule2);
308
+ } catch (error) {
309
+ importStringified = rule2.cssText;
310
+ }
311
+ try {
312
+ if (importStringified && ((_a2 = rule2.styleSheet) == null ? void 0 : _a2.href)) {
313
+ return absolutifyURLs(importStringified, rule2.styleSheet.href);
314
+ }
315
+ } catch (e2) {
316
+ }
317
+ return importStringified;
318
+ } else {
319
+ let ruleStringified = rule2.cssText;
320
+ if (isCSSStyleRule(rule2) && rule2.selectorText.includes(":")) {
321
+ ruleStringified = fixSafariColons(ruleStringified);
322
+ }
323
+ if (sheetHref) {
324
+ return absolutifyURLs(ruleStringified, sheetHref);
325
+ }
326
+ return ruleStringified;
327
+ }
328
+ }
329
+ function fixSafariColons(cssStringified) {
330
+ const regex = /(\[(?:[\w-]+)[^\\])(:(?:[\w-]+)\])/gm;
331
+ return cssStringified.replace(regex, "$1\\$2");
332
+ }
333
+ function isCSSImportRule(rule2) {
334
+ return "styleSheet" in rule2;
335
+ }
336
+ function isCSSStyleRule(rule2) {
337
+ return "selectorText" in rule2;
338
+ }
254
339
  class Mirror {
255
340
  constructor() {
256
341
  __publicField$1(this, "idNodeMap", /* @__PURE__ */ new Map());
@@ -386,91 +471,6 @@ function extractFileExtension(path, baseURL) {
386
471
  const match = url.pathname.match(regex);
387
472
  return (_a2 = match == null ? void 0 : match[1]) != null ? _a2 : null;
388
473
  }
389
- function fixBrowserCompatibilityIssuesInCSS(cssText) {
390
- if (cssText.includes(" background-clip: text;") && !cssText.includes(" -webkit-background-clip: text;")) {
391
- cssText = cssText.replace(
392
- /\sbackground-clip:\s*text;/g,
393
- " -webkit-background-clip: text; background-clip: text;"
394
- );
395
- }
396
- return cssText;
397
- }
398
- function escapeImportStatement(rule2) {
399
- const { cssText } = rule2;
400
- if (cssText.split('"').length < 3) return cssText;
401
- const statement = ["@import", `url(${JSON.stringify(rule2.href)})`];
402
- if (rule2.layerName === "") {
403
- statement.push(`layer`);
404
- } else if (rule2.layerName) {
405
- statement.push(`layer(${rule2.layerName})`);
406
- }
407
- if (rule2.supportsText) {
408
- statement.push(`supports(${rule2.supportsText})`);
409
- }
410
- if (rule2.media.length) {
411
- statement.push(rule2.media.mediaText);
412
- }
413
- return statement.join(" ") + ";";
414
- }
415
- function stringifyStylesheet(s2) {
416
- try {
417
- const rules2 = s2.rules || s2.cssRules;
418
- if (!rules2) {
419
- return null;
420
- }
421
- let sheetHref = s2.href;
422
- if (!sheetHref && s2.ownerNode) {
423
- sheetHref = s2.ownerNode.baseURI;
424
- }
425
- const stringifiedRules = Array.from(
426
- rules2,
427
- (rule2) => stringifyRule(rule2, sheetHref)
428
- ).join("");
429
- return fixBrowserCompatibilityIssuesInCSS(stringifiedRules);
430
- } catch (error) {
431
- return null;
432
- }
433
- }
434
- function stringifyRule(rule2, sheetHref) {
435
- var _a2;
436
- if (isCSSImportRule(rule2)) {
437
- let importStringified;
438
- try {
439
- importStringified = // for same-origin stylesheets,
440
- // we can access the imported stylesheet rules directly
441
- stringifyStylesheet(rule2.styleSheet) || // work around browser issues with the raw string `@import url(...)` statement
442
- escapeImportStatement(rule2);
443
- } catch (error) {
444
- importStringified = rule2.cssText;
445
- }
446
- try {
447
- if (importStringified && ((_a2 = rule2.styleSheet) == null ? void 0 : _a2.href)) {
448
- return absolutifyURLs(importStringified, rule2.styleSheet.href);
449
- }
450
- } catch (e2) {
451
- }
452
- return importStringified;
453
- } else {
454
- let ruleStringified = rule2.cssText;
455
- if (isCSSStyleRule(rule2) && rule2.selectorText.includes(":")) {
456
- ruleStringified = fixSafariColons(ruleStringified);
457
- }
458
- if (sheetHref) {
459
- return absolutifyURLs(ruleStringified, sheetHref);
460
- }
461
- return ruleStringified;
462
- }
463
- }
464
- function fixSafariColons(cssStringified) {
465
- const regex = /(\[(?:[\w-]+)[^\\])(:(?:[\w-]+)\])/gm;
466
- return cssStringified.replace(regex, "$1\\$2");
467
- }
468
- function isCSSImportRule(rule2) {
469
- return "styleSheet" in rule2;
470
- }
471
- function isCSSStyleRule(rule2) {
472
- return "selectorText" in rule2;
473
- }
474
474
  function extractOrigin(url) {
475
475
  let origin = "";
476
476
  if (url.indexOf("//") > -1) {
@@ -5376,22 +5376,6 @@ postcss$1.Input;
5376
5376
  postcss$1.Rule;
5377
5377
  postcss$1.Root;
5378
5378
  postcss$1.Node;
5379
- function adaptCssForReplay(cssText, cache) {
5380
- const cachedStyle = cache == null ? void 0 : cache.stylesWithHoverClass.get(cssText);
5381
- if (cachedStyle) return cachedStyle;
5382
- let result2 = cssText;
5383
- try {
5384
- const ast = postcss$1([
5385
- mediaSelectorPlugin,
5386
- pseudoClassPlugin
5387
- ]).process(cssText, { parser: safeParser });
5388
- result2 = ast.css;
5389
- } catch (error) {
5390
- console.warn("Failed to adapt css for replay", error);
5391
- }
5392
- cache == null ? void 0 : cache.stylesWithHoverClass.set(cssText, result2);
5393
- return result2;
5394
- }
5395
5379
  const tagMap = {
5396
5380
  script: "noscript",
5397
5381
  // camel case svg element tag names
@@ -5439,6 +5423,22 @@ function getTagName(n2) {
5439
5423
  }
5440
5424
  return tagName;
5441
5425
  }
5426
+ function adaptCssForReplay(cssText, cache) {
5427
+ const cachedStyle = cache == null ? void 0 : cache.stylesWithHoverClass.get(cssText);
5428
+ if (cachedStyle) return cachedStyle;
5429
+ let result2 = cssText;
5430
+ try {
5431
+ const ast = postcss$1([
5432
+ mediaSelectorPlugin,
5433
+ pseudoClassPlugin
5434
+ ]).process(cssText, { parser: safeParser });
5435
+ result2 = ast.css;
5436
+ } catch (error) {
5437
+ console.warn("Failed to adapt css for replay", error);
5438
+ }
5439
+ cache == null ? void 0 : cache.stylesWithHoverClass.set(cssText, result2);
5440
+ return result2;
5441
+ }
5442
5442
  function createCache() {
5443
5443
  const stylesWithHoverClass = /* @__PURE__ */ new Map();
5444
5444
  return {
@@ -12192,6 +12192,11 @@ class MutationBuffer {
12192
12192
  this.shadowDomManager.reset();
12193
12193
  this.canvasManager.reset();
12194
12194
  }
12195
+ destroy() {
12196
+ while (this.mapRemoves.length) {
12197
+ this.mirror.removeNodeFromMap(this.mapRemoves.shift());
12198
+ }
12199
+ }
12195
12200
  }
12196
12201
  function deepDelete(addsSet, n2) {
12197
12202
  addsSet.delete(n2);
@@ -13236,6 +13241,7 @@ function initObservers(o2, hooks = {}) {
13236
13241
  );
13237
13242
  }
13238
13243
  return callbackWrapper(() => {
13244
+ mutationBuffers.forEach((b) => b.destroy());
13239
13245
  mutationBuffers.forEach((b) => b.reset());
13240
13246
  mutationObserver == null ? void 0 : mutationObserver.disconnect();
13241
13247
  mousemoveHandler();
@@ -13573,6 +13579,8 @@ class IframeManager {
13573
13579
  contentWindow.removeEventListener("message", handler);
13574
13580
  });
13575
13581
  this.nestedIframeListeners.clear();
13582
+ this.crossOriginIframeMirror.reset();
13583
+ this.crossOriginIframeStyleMirror.reset();
13576
13584
  }
13577
13585
  }
13578
13586
  class ShadowDomManager {
@@ -14049,6 +14057,8 @@ class CanvasManager {
14049
14057
  __publicField(this, "resetObservers");
14050
14058
  __publicField(this, "frozen", false);
14051
14059
  __publicField(this, "locked", false);
14060
+ __publicField(this, "rafIdTimestamp", null);
14061
+ __publicField(this, "rafIdFlush", null);
14052
14062
  __publicField(this, "processMutation", (target, mutation) => {
14053
14063
  const newFrame = this.rafStamps.invokeId && this.rafStamps.latestId !== this.rafStamps.invokeId;
14054
14064
  if (newFrame || !this.rafStamps.invokeId)
@@ -14083,6 +14093,14 @@ class CanvasManager {
14083
14093
  reset() {
14084
14094
  this.pendingCanvasMutations.clear();
14085
14095
  this.resetObservers && this.resetObservers();
14096
+ if (this.rafIdTimestamp !== null) {
14097
+ cancelAnimationFrame(this.rafIdTimestamp);
14098
+ this.rafIdTimestamp = null;
14099
+ }
14100
+ if (this.rafIdFlush !== null) {
14101
+ cancelAnimationFrame(this.rafIdFlush);
14102
+ this.rafIdFlush = null;
14103
+ }
14086
14104
  }
14087
14105
  freeze() {
14088
14106
  this.frozen = true;
@@ -14233,14 +14251,16 @@ class CanvasManager {
14233
14251
  };
14234
14252
  }
14235
14253
  startPendingCanvasMutationFlusher() {
14236
- requestAnimationFrame(() => this.flushPendingCanvasMutations());
14254
+ this.rafIdFlush = requestAnimationFrame(
14255
+ () => this.flushPendingCanvasMutations()
14256
+ );
14237
14257
  }
14238
14258
  startRAFTimestamping() {
14239
14259
  const setLatestRAFTimestamp = (timestamp) => {
14240
14260
  this.rafStamps.latestId = timestamp;
14241
- requestAnimationFrame(setLatestRAFTimestamp);
14261
+ this.rafIdTimestamp = requestAnimationFrame(setLatestRAFTimestamp);
14242
14262
  };
14243
- requestAnimationFrame(setLatestRAFTimestamp);
14263
+ this.rafIdTimestamp = requestAnimationFrame(setLatestRAFTimestamp);
14244
14264
  }
14245
14265
  flushPendingCanvasMutations() {
14246
14266
  this.pendingCanvasMutations.forEach(
@@ -14249,7 +14269,9 @@ class CanvasManager {
14249
14269
  this.flushPendingCanvasMutationFor(canvas, id);
14250
14270
  }
14251
14271
  );
14252
- requestAnimationFrame(() => this.flushPendingCanvasMutations());
14272
+ this.rafIdFlush = requestAnimationFrame(
14273
+ () => this.flushPendingCanvasMutations()
14274
+ );
14253
14275
  }
14254
14276
  flushPendingCanvasMutationFor(canvas, id) {
14255
14277
  if (this.frozen || this.locked) {
@@ -14815,6 +14837,7 @@ function record(options = {}) {
14815
14837
  processedNodeManager.destroy();
14816
14838
  iframeManager.removeLoadListener();
14817
14839
  iframeManager.destroy();
14840
+ mirror.reset();
14818
14841
  recording = false;
14819
14842
  unregisterErrorHandler();
14820
14843
  };