@amplitude/rrweb-player 2.0.0-alpha.35 → 2.0.0-alpha.37

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.
@@ -3396,7 +3396,7 @@ function if_block(node2, fn, elseif = false) {
3396
3396
  }
3397
3397
  }, flags2);
3398
3398
  }
3399
- function index$1(_, i) {
3399
+ function index$2(_, i) {
3400
3400
  return i;
3401
3401
  }
3402
3402
  function pause_effects(state2, to_destroy, controlled_anchor) {
@@ -4326,9 +4326,251 @@ var NodeType$3 = /* @__PURE__ */ ((NodeType2) => {
4326
4326
  NodeType2[NodeType2["Comment"] = 5] = "Comment";
4327
4327
  return NodeType2;
4328
4328
  })(NodeType$3 || {});
4329
+ const testableAccessors$1 = {
4330
+ Node: ["childNodes", "parentNode", "parentElement", "textContent"],
4331
+ ShadowRoot: ["host", "styleSheets"],
4332
+ Element: ["shadowRoot", "querySelector", "querySelectorAll"],
4333
+ MutationObserver: []
4334
+ };
4335
+ const testableMethods$1 = {
4336
+ Node: ["contains", "getRootNode"],
4337
+ ShadowRoot: ["getSelection"],
4338
+ Element: [],
4339
+ MutationObserver: ["constructor"]
4340
+ };
4341
+ const untaintedBasePrototype$1 = {};
4342
+ function angularZoneUnpatchedAlternative$1(key) {
4343
+ var _a22, _b2;
4344
+ const angularUnpatchedVersionSymbol = (_b2 = (_a22 = globalThis == null ? void 0 : globalThis.Zone) == null ? void 0 : _a22.__symbol__) == null ? void 0 : _b2.call(_a22, key);
4345
+ if (angularUnpatchedVersionSymbol && globalThis[angularUnpatchedVersionSymbol]) {
4346
+ return globalThis[angularUnpatchedVersionSymbol];
4347
+ } else {
4348
+ return void 0;
4349
+ }
4350
+ }
4351
+ function getUntaintedPrototype$1(key) {
4352
+ if (untaintedBasePrototype$1[key])
4353
+ return untaintedBasePrototype$1[key];
4354
+ const candidate = angularZoneUnpatchedAlternative$1(key) || globalThis[key];
4355
+ const defaultPrototype = candidate.prototype;
4356
+ const accessorNames = key in testableAccessors$1 ? testableAccessors$1[key] : void 0;
4357
+ const isUntaintedAccessors = Boolean(
4358
+ accessorNames && // @ts-expect-error 2345
4359
+ accessorNames.every(
4360
+ (accessor) => {
4361
+ var _a22, _b2;
4362
+ return Boolean(
4363
+ (_b2 = (_a22 = Object.getOwnPropertyDescriptor(defaultPrototype, accessor)) == null ? void 0 : _a22.get) == null ? void 0 : _b2.toString().includes("[native code]")
4364
+ );
4365
+ }
4366
+ )
4367
+ );
4368
+ const methodNames = key in testableMethods$1 ? testableMethods$1[key] : void 0;
4369
+ const isUntaintedMethods = Boolean(
4370
+ methodNames && methodNames.every(
4371
+ // @ts-expect-error 2345
4372
+ (method) => {
4373
+ var _a22;
4374
+ return typeof defaultPrototype[method] === "function" && ((_a22 = defaultPrototype[method]) == null ? void 0 : _a22.toString().includes("[native code]"));
4375
+ }
4376
+ )
4377
+ );
4378
+ if (isUntaintedAccessors && isUntaintedMethods) {
4379
+ untaintedBasePrototype$1[key] = candidate.prototype;
4380
+ return candidate.prototype;
4381
+ }
4382
+ try {
4383
+ const iframeEl = document.createElement("iframe");
4384
+ document.body.appendChild(iframeEl);
4385
+ const win = iframeEl.contentWindow;
4386
+ if (!win) return candidate.prototype;
4387
+ const untaintedObject = win[key].prototype;
4388
+ document.body.removeChild(iframeEl);
4389
+ if (!untaintedObject) return defaultPrototype;
4390
+ return untaintedBasePrototype$1[key] = untaintedObject;
4391
+ } catch {
4392
+ return defaultPrototype;
4393
+ }
4394
+ }
4395
+ const untaintedAccessorCache$1 = {};
4396
+ function getUntaintedAccessor$1(key, instance, accessor) {
4397
+ var _a22;
4398
+ const cacheKey = `${key}.${String(accessor)}`;
4399
+ if (untaintedAccessorCache$1[cacheKey])
4400
+ return untaintedAccessorCache$1[cacheKey].call(
4401
+ instance
4402
+ );
4403
+ const untaintedPrototype = getUntaintedPrototype$1(key);
4404
+ const untaintedAccessor = (_a22 = Object.getOwnPropertyDescriptor(
4405
+ untaintedPrototype,
4406
+ accessor
4407
+ )) == null ? void 0 : _a22.get;
4408
+ if (!untaintedAccessor) return instance[accessor];
4409
+ untaintedAccessorCache$1[cacheKey] = untaintedAccessor;
4410
+ return untaintedAccessor.call(instance);
4411
+ }
4412
+ const untaintedMethodCache$1 = {};
4413
+ function getUntaintedMethod$1(key, instance, method) {
4414
+ const cacheKey = `${key}.${String(method)}`;
4415
+ if (untaintedMethodCache$1[cacheKey])
4416
+ return untaintedMethodCache$1[cacheKey].bind(
4417
+ instance
4418
+ );
4419
+ const untaintedPrototype = getUntaintedPrototype$1(key);
4420
+ const untaintedMethod = untaintedPrototype[method];
4421
+ if (typeof untaintedMethod !== "function") return instance[method];
4422
+ untaintedMethodCache$1[cacheKey] = untaintedMethod;
4423
+ return untaintedMethod.bind(instance);
4424
+ }
4425
+ function childNodes$1(n2) {
4426
+ return getUntaintedAccessor$1("Node", n2, "childNodes");
4427
+ }
4428
+ function parentNode$1(n2) {
4429
+ return getUntaintedAccessor$1("Node", n2, "parentNode");
4430
+ }
4431
+ function parentElement$1(n2) {
4432
+ return getUntaintedAccessor$1("Node", n2, "parentElement");
4433
+ }
4434
+ function textContent$1(n2) {
4435
+ return getUntaintedAccessor$1("Node", n2, "textContent");
4436
+ }
4437
+ function contains$1(n2, other) {
4438
+ return getUntaintedMethod$1("Node", n2, "contains")(other);
4439
+ }
4440
+ function getRootNode$1(n2) {
4441
+ return getUntaintedMethod$1("Node", n2, "getRootNode")();
4442
+ }
4443
+ function host$1(n2) {
4444
+ if (!n2 || !("host" in n2)) return null;
4445
+ return getUntaintedAccessor$1("ShadowRoot", n2, "host");
4446
+ }
4447
+ function styleSheets$1(n2) {
4448
+ return n2.styleSheets;
4449
+ }
4450
+ function shadowRoot$1(n2) {
4451
+ if (!n2 || !("shadowRoot" in n2)) return null;
4452
+ return getUntaintedAccessor$1("Element", n2, "shadowRoot");
4453
+ }
4454
+ function querySelector$1(n2, selectors) {
4455
+ return getUntaintedAccessor$1("Element", n2, "querySelector")(selectors);
4456
+ }
4457
+ function querySelectorAll$1(n2, selectors) {
4458
+ return getUntaintedAccessor$1("Element", n2, "querySelectorAll")(selectors);
4459
+ }
4460
+ function mutationObserverCtor$1() {
4461
+ return getUntaintedPrototype$1("MutationObserver").constructor;
4462
+ }
4463
+ const index$1 = {
4464
+ childNodes: childNodes$1,
4465
+ parentNode: parentNode$1,
4466
+ parentElement: parentElement$1,
4467
+ textContent: textContent$1,
4468
+ contains: contains$1,
4469
+ getRootNode: getRootNode$1,
4470
+ host: host$1,
4471
+ styleSheets: styleSheets$1,
4472
+ shadowRoot: shadowRoot$1,
4473
+ querySelector: querySelector$1,
4474
+ querySelectorAll: querySelectorAll$1,
4475
+ mutationObserver: mutationObserverCtor$1
4476
+ };
4329
4477
  function isElement(n2) {
4330
4478
  return n2.nodeType === n2.ELEMENT_NODE;
4331
4479
  }
4480
+ function isShadowRoot(n2) {
4481
+ const hostEl = (
4482
+ // anchor and textarea elements also have a `host` property
4483
+ // but only shadow roots have a `mode` property
4484
+ n2 && "host" in n2 && "mode" in n2 && index$1.host(n2) || null
4485
+ );
4486
+ return Boolean(
4487
+ hostEl && "shadowRoot" in hostEl && index$1.shadowRoot(hostEl) === n2
4488
+ );
4489
+ }
4490
+ function isNativeShadowDom(shadowRoot2) {
4491
+ return Object.prototype.toString.call(shadowRoot2) === "[object ShadowRoot]";
4492
+ }
4493
+ function fixBrowserCompatibilityIssuesInCSS(cssText) {
4494
+ if (cssText.includes(" background-clip: text;") && !cssText.includes(" -webkit-background-clip: text;")) {
4495
+ cssText = cssText.replace(
4496
+ /\sbackground-clip:\s*text;/g,
4497
+ " -webkit-background-clip: text; background-clip: text;"
4498
+ );
4499
+ }
4500
+ return cssText;
4501
+ }
4502
+ function escapeImportStatement(rule2) {
4503
+ const { cssText } = rule2;
4504
+ if (cssText.split('"').length < 3) return cssText;
4505
+ const statement = ["@import", `url(${JSON.stringify(rule2.href)})`];
4506
+ if (rule2.layerName === "") {
4507
+ statement.push(`layer`);
4508
+ } else if (rule2.layerName) {
4509
+ statement.push(`layer(${rule2.layerName})`);
4510
+ }
4511
+ if (rule2.supportsText) {
4512
+ statement.push(`supports(${rule2.supportsText})`);
4513
+ }
4514
+ if (rule2.media.length) {
4515
+ statement.push(rule2.media.mediaText);
4516
+ }
4517
+ return statement.join(" ") + ";";
4518
+ }
4519
+ function stringifyStylesheet(s2) {
4520
+ try {
4521
+ const rules2 = s2.rules || s2.cssRules;
4522
+ if (!rules2) {
4523
+ return null;
4524
+ }
4525
+ let sheetHref = s2.href;
4526
+ if (!sheetHref && s2.ownerNode && s2.ownerNode.ownerDocument) {
4527
+ sheetHref = s2.ownerNode.ownerDocument.location.href;
4528
+ }
4529
+ const stringifiedRules = Array.from(
4530
+ rules2,
4531
+ (rule2) => stringifyRule(rule2, sheetHref)
4532
+ ).join("");
4533
+ return fixBrowserCompatibilityIssuesInCSS(stringifiedRules);
4534
+ } catch (error) {
4535
+ return null;
4536
+ }
4537
+ }
4538
+ function stringifyRule(rule2, sheetHref) {
4539
+ if (isCSSImportRule(rule2)) {
4540
+ let importStringified;
4541
+ try {
4542
+ importStringified = // for same-origin stylesheets,
4543
+ // we can access the imported stylesheet rules directly
4544
+ stringifyStylesheet(rule2.styleSheet) || // work around browser issues with the raw string `@import url(...)` statement
4545
+ escapeImportStatement(rule2);
4546
+ } catch (error) {
4547
+ importStringified = rule2.cssText;
4548
+ }
4549
+ if (rule2.styleSheet.href) {
4550
+ return absolutifyURLs(importStringified, rule2.styleSheet.href);
4551
+ }
4552
+ return importStringified;
4553
+ } else {
4554
+ let ruleStringified = rule2.cssText;
4555
+ if (isCSSStyleRule(rule2) && rule2.selectorText.includes(":")) {
4556
+ ruleStringified = fixSafariColons(ruleStringified);
4557
+ }
4558
+ if (sheetHref) {
4559
+ return absolutifyURLs(ruleStringified, sheetHref);
4560
+ }
4561
+ return ruleStringified;
4562
+ }
4563
+ }
4564
+ function fixSafariColons(cssStringified) {
4565
+ const regex = /(\[(?:[\w-]+)[^\\])(:(?:[\w-]+)\])/gm;
4566
+ return cssStringified.replace(regex, "$1\\$2");
4567
+ }
4568
+ function isCSSImportRule(rule2) {
4569
+ return "styleSheet" in rule2;
4570
+ }
4571
+ function isCSSStyleRule(rule2) {
4572
+ return "selectorText" in rule2;
4573
+ }
4332
4574
  class Mirror {
4333
4575
  constructor() {
4334
4576
  __publicField$1(this, "idNodeMap", /* @__PURE__ */ new Map());
@@ -4387,9 +4629,52 @@ class Mirror {
4387
4629
  function createMirror$2() {
4388
4630
  return new Mirror();
4389
4631
  }
4632
+ function maskInputValue({
4633
+ element,
4634
+ maskInputOptions,
4635
+ tagName,
4636
+ type,
4637
+ value,
4638
+ maskInputFn
4639
+ }) {
4640
+ let text = value || "";
4641
+ const actualType = type && toLowerCase(type);
4642
+ if (maskInputOptions[tagName.toLowerCase()] || actualType && maskInputOptions[actualType]) {
4643
+ if (maskInputFn) {
4644
+ text = maskInputFn(text, element);
4645
+ } else {
4646
+ text = "*".repeat(text.length);
4647
+ }
4648
+ }
4649
+ return text;
4650
+ }
4390
4651
  function toLowerCase(str) {
4391
4652
  return str.toLowerCase();
4392
4653
  }
4654
+ const ORIGINAL_ATTRIBUTE_NAME = "__rrweb_original__";
4655
+ function is2DCanvasBlank(canvas) {
4656
+ const ctx = canvas.getContext("2d");
4657
+ if (!ctx) return true;
4658
+ const chunkSize = 50;
4659
+ for (let x = 0; x < canvas.width; x += chunkSize) {
4660
+ for (let y = 0; y < canvas.height; y += chunkSize) {
4661
+ const getImageData = ctx.getImageData;
4662
+ const originalGetImageData = ORIGINAL_ATTRIBUTE_NAME in getImageData ? getImageData[ORIGINAL_ATTRIBUTE_NAME] : getImageData;
4663
+ const pixelBuffer = new Uint32Array(
4664
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-unsafe-member-access
4665
+ originalGetImageData.call(
4666
+ ctx,
4667
+ x,
4668
+ y,
4669
+ Math.min(chunkSize, canvas.width - x),
4670
+ Math.min(chunkSize, canvas.height - y)
4671
+ ).data.buffer
4672
+ );
4673
+ if (pixelBuffer.some((pixel) => pixel !== 0)) return false;
4674
+ }
4675
+ }
4676
+ return true;
4677
+ }
4393
4678
  function isNodeMetaEqual(a2, b) {
4394
4679
  if (!a2 || !b || a2.type !== b.type) return false;
4395
4680
  if (a2.type === NodeType$3.Document)
@@ -4402,6 +4687,1097 @@ function isNodeMetaEqual(a2, b) {
4402
4687
  return a2.tagName === b.tagName && JSON.stringify(a2.attributes) === JSON.stringify(b.attributes) && a2.isSVG === b.isSVG && a2.needBlock === b.needBlock;
4403
4688
  return false;
4404
4689
  }
4690
+ function getInputType(element) {
4691
+ const type = element.type;
4692
+ return element.hasAttribute("data-rr-is-password") ? "password" : type ? (
4693
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
4694
+ toLowerCase(type)
4695
+ ) : null;
4696
+ }
4697
+ function extractFileExtension(path, baseURL) {
4698
+ let url;
4699
+ try {
4700
+ url = new URL(path, baseURL ?? window.location.href);
4701
+ } catch (err) {
4702
+ return null;
4703
+ }
4704
+ const regex = /\.([0-9a-z]+)(?:$)/i;
4705
+ const match = url.pathname.match(regex);
4706
+ return (match == null ? void 0 : match[1]) ?? null;
4707
+ }
4708
+ function extractOrigin(url) {
4709
+ let origin = "";
4710
+ if (url.indexOf("//") > -1) {
4711
+ origin = url.split("/").slice(0, 3).join("/");
4712
+ } else {
4713
+ origin = url.split("/")[0];
4714
+ }
4715
+ origin = origin.split("?")[0];
4716
+ return origin;
4717
+ }
4718
+ const URL_IN_CSS_REF = /url\((?:(')([^']*)'|(")(.*?)"|([^)]*))\)/gm;
4719
+ const URL_PROTOCOL_MATCH = /^(?:[a-z+]+:)?\/\//i;
4720
+ const URL_WWW_MATCH = /^www\..*/i;
4721
+ const DATA_URI = /^(data:)([^,]*),(.*)/i;
4722
+ function absolutifyURLs(cssText, href) {
4723
+ return (cssText || "").replace(
4724
+ URL_IN_CSS_REF,
4725
+ (origin, quote1, path1, quote2, path2, path3) => {
4726
+ const filePath = path1 || path2 || path3;
4727
+ const maybeQuote = quote1 || quote2 || "";
4728
+ if (!filePath) {
4729
+ return origin;
4730
+ }
4731
+ if (URL_PROTOCOL_MATCH.test(filePath) || URL_WWW_MATCH.test(filePath)) {
4732
+ return `url(${maybeQuote}${filePath}${maybeQuote})`;
4733
+ }
4734
+ if (DATA_URI.test(filePath)) {
4735
+ return `url(${maybeQuote}${filePath}${maybeQuote})`;
4736
+ }
4737
+ if (filePath[0] === "/") {
4738
+ return `url(${maybeQuote}${extractOrigin(href) + filePath}${maybeQuote})`;
4739
+ }
4740
+ const stack = href.split("/");
4741
+ const parts = filePath.split("/");
4742
+ stack.pop();
4743
+ for (const part of parts) {
4744
+ if (part === ".") {
4745
+ continue;
4746
+ } else if (part === "..") {
4747
+ stack.pop();
4748
+ } else {
4749
+ stack.push(part);
4750
+ }
4751
+ }
4752
+ return `url(${maybeQuote}${stack.join("/")}${maybeQuote})`;
4753
+ }
4754
+ );
4755
+ }
4756
+ function normalizeCssString(cssText, _testNoPxNorm = false) {
4757
+ if (_testNoPxNorm) {
4758
+ return cssText.replace(/(\/\*[^*]*\*\/)|[\s;]/g, "");
4759
+ } else {
4760
+ return cssText.replace(/(\/\*[^*]*\*\/)|[\s;]/g, "").replace(/0px/g, "0");
4761
+ }
4762
+ }
4763
+ function splitCssText(cssText, style, _testNoPxNorm = false) {
4764
+ const childNodes2 = Array.from(style.childNodes);
4765
+ const splits = [];
4766
+ let iterCount = 0;
4767
+ if (childNodes2.length > 1 && cssText && typeof cssText === "string") {
4768
+ let cssTextNorm = normalizeCssString(cssText, _testNoPxNorm);
4769
+ const normFactor = cssTextNorm.length / cssText.length;
4770
+ for (let i2 = 1; i2 < childNodes2.length; i2++) {
4771
+ if (childNodes2[i2].textContent && typeof childNodes2[i2].textContent === "string") {
4772
+ const textContentNorm = normalizeCssString(
4773
+ childNodes2[i2].textContent,
4774
+ _testNoPxNorm
4775
+ );
4776
+ const jLimit = 100;
4777
+ let j = 3;
4778
+ for (; j < textContentNorm.length; j++) {
4779
+ if (
4780
+ // keep consuming css identifiers (to get a decent chunk more quickly)
4781
+ textContentNorm[j].match(/[a-zA-Z0-9]/) || // substring needs to be unique to this section
4782
+ textContentNorm.indexOf(textContentNorm.substring(0, j), 1) !== -1
4783
+ ) {
4784
+ continue;
4785
+ }
4786
+ break;
4787
+ }
4788
+ for (; j < textContentNorm.length; j++) {
4789
+ let startSubstring = textContentNorm.substring(0, j);
4790
+ let cssNormSplits = cssTextNorm.split(startSubstring);
4791
+ let splitNorm = -1;
4792
+ if (cssNormSplits.length === 2) {
4793
+ splitNorm = cssNormSplits[0].length;
4794
+ } else if (cssNormSplits.length > 2 && cssNormSplits[0] === "" && childNodes2[i2 - 1].textContent !== "") {
4795
+ splitNorm = cssTextNorm.indexOf(startSubstring, 1);
4796
+ } else if (cssNormSplits.length === 1) {
4797
+ startSubstring = startSubstring.substring(
4798
+ 0,
4799
+ startSubstring.length - 1
4800
+ );
4801
+ cssNormSplits = cssTextNorm.split(startSubstring);
4802
+ if (cssNormSplits.length <= 1) {
4803
+ splits.push(cssText);
4804
+ return splits;
4805
+ }
4806
+ j = jLimit + 1;
4807
+ } else if (j === textContentNorm.length - 1) {
4808
+ splitNorm = cssTextNorm.indexOf(startSubstring);
4809
+ }
4810
+ if (cssNormSplits.length >= 2 && j > jLimit) {
4811
+ const prevTextContent = childNodes2[i2 - 1].textContent;
4812
+ if (prevTextContent && typeof prevTextContent === "string") {
4813
+ const prevMinLength = normalizeCssString(prevTextContent).length;
4814
+ splitNorm = cssTextNorm.indexOf(startSubstring, prevMinLength);
4815
+ }
4816
+ if (splitNorm === -1) {
4817
+ splitNorm = cssNormSplits[0].length;
4818
+ }
4819
+ }
4820
+ if (splitNorm !== -1) {
4821
+ let k = Math.floor(splitNorm / normFactor);
4822
+ for (; k > 0 && k < cssText.length; ) {
4823
+ iterCount += 1;
4824
+ if (iterCount > 50 * childNodes2.length) {
4825
+ splits.push(cssText);
4826
+ return splits;
4827
+ }
4828
+ const normPart = normalizeCssString(
4829
+ cssText.substring(0, k),
4830
+ _testNoPxNorm
4831
+ );
4832
+ if (normPart.length === splitNorm) {
4833
+ splits.push(cssText.substring(0, k));
4834
+ cssText = cssText.substring(k);
4835
+ cssTextNorm = cssTextNorm.substring(splitNorm);
4836
+ break;
4837
+ } else if (normPart.length < splitNorm) {
4838
+ k += Math.max(
4839
+ 1,
4840
+ Math.floor((splitNorm - normPart.length) / normFactor)
4841
+ );
4842
+ } else {
4843
+ k -= Math.max(
4844
+ 1,
4845
+ Math.floor((normPart.length - splitNorm) * normFactor)
4846
+ );
4847
+ }
4848
+ }
4849
+ break;
4850
+ }
4851
+ }
4852
+ }
4853
+ }
4854
+ }
4855
+ splits.push(cssText);
4856
+ return splits;
4857
+ }
4858
+ function markCssSplits(cssText, style) {
4859
+ return splitCssText(cssText, style).join("/* rr_split */");
4860
+ }
4861
+ const _DEFAULT_BLOCKED_ELEMENT_BACKGROUND_COLOR = "lightgrey";
4862
+ let _id = 1;
4863
+ const tagNameRegex = new RegExp("[^a-z0-9-_:]");
4864
+ const IGNORED_NODE = -2;
4865
+ function genId() {
4866
+ return _id++;
4867
+ }
4868
+ function getValidTagName$1(element) {
4869
+ if (element instanceof HTMLFormElement) {
4870
+ return "form";
4871
+ }
4872
+ const processedTagName = toLowerCase(element.tagName);
4873
+ if (tagNameRegex.test(processedTagName)) {
4874
+ return "div";
4875
+ }
4876
+ return processedTagName;
4877
+ }
4878
+ let canvasService;
4879
+ let canvasCtx;
4880
+ const SRCSET_NOT_SPACES = /^[^ \t\n\r\u000c]+/;
4881
+ const SRCSET_COMMAS_OR_SPACES = /^[, \t\n\r\u000c]+/;
4882
+ function getAbsoluteSrcsetString(doc, attributeValue) {
4883
+ if (attributeValue.trim() === "") {
4884
+ return attributeValue;
4885
+ }
4886
+ let pos = 0;
4887
+ function collectCharacters(regEx) {
4888
+ let chars2;
4889
+ const match = regEx.exec(attributeValue.substring(pos));
4890
+ if (match) {
4891
+ chars2 = match[0];
4892
+ pos += chars2.length;
4893
+ return chars2;
4894
+ }
4895
+ return "";
4896
+ }
4897
+ const output = [];
4898
+ while (true) {
4899
+ collectCharacters(SRCSET_COMMAS_OR_SPACES);
4900
+ if (pos >= attributeValue.length) {
4901
+ break;
4902
+ }
4903
+ let url = collectCharacters(SRCSET_NOT_SPACES);
4904
+ if (url.slice(-1) === ",") {
4905
+ url = absoluteToDoc(doc, url.substring(0, url.length - 1));
4906
+ output.push(url);
4907
+ } else {
4908
+ let descriptorsStr = "";
4909
+ url = absoluteToDoc(doc, url);
4910
+ let inParens = false;
4911
+ while (true) {
4912
+ const c2 = attributeValue.charAt(pos);
4913
+ if (c2 === "") {
4914
+ output.push((url + descriptorsStr).trim());
4915
+ break;
4916
+ } else if (!inParens) {
4917
+ if (c2 === ",") {
4918
+ pos += 1;
4919
+ output.push((url + descriptorsStr).trim());
4920
+ break;
4921
+ } else if (c2 === "(") {
4922
+ inParens = true;
4923
+ }
4924
+ } else {
4925
+ if (c2 === ")") {
4926
+ inParens = false;
4927
+ }
4928
+ }
4929
+ descriptorsStr += c2;
4930
+ pos += 1;
4931
+ }
4932
+ }
4933
+ }
4934
+ return output.join(", ");
4935
+ }
4936
+ const cachedDocument = /* @__PURE__ */ new WeakMap();
4937
+ function absoluteToDoc(doc, attributeValue) {
4938
+ if (!attributeValue || attributeValue.trim() === "") {
4939
+ return attributeValue;
4940
+ }
4941
+ return getHref(doc, attributeValue);
4942
+ }
4943
+ function isSVGElement(el) {
4944
+ return Boolean(el.tagName === "svg" || el.ownerSVGElement);
4945
+ }
4946
+ function getHref(doc, customHref) {
4947
+ let a2 = cachedDocument.get(doc);
4948
+ if (!a2) {
4949
+ a2 = doc.createElement("a");
4950
+ cachedDocument.set(doc, a2);
4951
+ }
4952
+ if (!customHref) {
4953
+ customHref = "";
4954
+ } else if (customHref.startsWith("blob:") || customHref.startsWith("data:")) {
4955
+ return customHref;
4956
+ }
4957
+ a2.setAttribute("href", customHref);
4958
+ return a2.href;
4959
+ }
4960
+ function transformAttribute(doc, tagName, name, value) {
4961
+ if (!value) {
4962
+ return value;
4963
+ }
4964
+ if (name === "src" || name === "href" && !(tagName === "use" && value[0] === "#")) {
4965
+ return absoluteToDoc(doc, value);
4966
+ } else if (name === "xlink:href" && value[0] !== "#") {
4967
+ return absoluteToDoc(doc, value);
4968
+ } else if (name === "background" && (tagName === "table" || tagName === "td" || tagName === "th")) {
4969
+ return absoluteToDoc(doc, value);
4970
+ } else if (name === "srcset") {
4971
+ return getAbsoluteSrcsetString(doc, value);
4972
+ } else if (name === "style") {
4973
+ return absolutifyURLs(value, getHref(doc));
4974
+ } else if (tagName === "object" && name === "data") {
4975
+ return absoluteToDoc(doc, value);
4976
+ }
4977
+ return value;
4978
+ }
4979
+ function ignoreAttribute(tagName, name, _value) {
4980
+ return (tagName === "video" || tagName === "audio") && name === "autoplay";
4981
+ }
4982
+ function _isBlockedElement(element, blockClass, blockSelector) {
4983
+ try {
4984
+ if (typeof blockClass === "string") {
4985
+ if (element.classList.contains(blockClass)) {
4986
+ return true;
4987
+ }
4988
+ } else {
4989
+ for (let eIndex = element.classList.length; eIndex--; ) {
4990
+ const className = element.classList[eIndex];
4991
+ if (blockClass.test(className)) {
4992
+ return true;
4993
+ }
4994
+ }
4995
+ }
4996
+ if (blockSelector) {
4997
+ return element.matches(blockSelector);
4998
+ }
4999
+ } catch (e2) {
5000
+ }
5001
+ return false;
5002
+ }
5003
+ function classMatchesRegex(node2, regex, checkAncestors) {
5004
+ if (!node2) return false;
5005
+ if (node2.nodeType !== node2.ELEMENT_NODE) {
5006
+ if (!checkAncestors) return false;
5007
+ return classMatchesRegex(index$1.parentNode(node2), regex, checkAncestors);
5008
+ }
5009
+ for (let eIndex = node2.classList.length; eIndex--; ) {
5010
+ const className = node2.classList[eIndex];
5011
+ if (regex.test(className)) {
5012
+ return true;
5013
+ }
5014
+ }
5015
+ if (!checkAncestors) return false;
5016
+ return classMatchesRegex(index$1.parentNode(node2), regex, checkAncestors);
5017
+ }
5018
+ function needMaskingText(node2, maskTextClass, maskTextSelector, checkAncestors) {
5019
+ let el;
5020
+ if (isElement(node2)) {
5021
+ el = node2;
5022
+ if (!index$1.childNodes(el).length) {
5023
+ return false;
5024
+ }
5025
+ } else if (index$1.parentElement(node2) === null) {
5026
+ return false;
5027
+ } else {
5028
+ el = index$1.parentElement(node2);
5029
+ }
5030
+ try {
5031
+ if (typeof maskTextClass === "string") {
5032
+ if (checkAncestors) {
5033
+ if (el.closest(`.${maskTextClass}`)) return true;
5034
+ } else {
5035
+ if (el.classList.contains(maskTextClass)) return true;
5036
+ }
5037
+ } else {
5038
+ if (classMatchesRegex(el, maskTextClass, checkAncestors)) return true;
5039
+ }
5040
+ if (maskTextSelector) {
5041
+ if (checkAncestors) {
5042
+ if (el.closest(maskTextSelector)) return true;
5043
+ } else {
5044
+ if (el.matches(maskTextSelector)) return true;
5045
+ }
5046
+ }
5047
+ } catch (e2) {
5048
+ }
5049
+ return false;
5050
+ }
5051
+ function onceIframeLoaded(iframeEl, listener, iframeLoadTimeout) {
5052
+ const win = iframeEl.contentWindow;
5053
+ if (!win) {
5054
+ return;
5055
+ }
5056
+ let fired = false;
5057
+ let readyState;
5058
+ try {
5059
+ readyState = win.document.readyState;
5060
+ } catch (error) {
5061
+ return;
5062
+ }
5063
+ if (readyState !== "complete") {
5064
+ const timer = setTimeout(() => {
5065
+ if (!fired) {
5066
+ listener();
5067
+ fired = true;
5068
+ }
5069
+ }, iframeLoadTimeout);
5070
+ iframeEl.addEventListener("load", () => {
5071
+ clearTimeout(timer);
5072
+ fired = true;
5073
+ listener();
5074
+ });
5075
+ return;
5076
+ }
5077
+ const blankUrl = "about:blank";
5078
+ if (win.location.href !== blankUrl || iframeEl.src === blankUrl || iframeEl.src === "") {
5079
+ setTimeout(listener, 0);
5080
+ return iframeEl.addEventListener("load", listener);
5081
+ }
5082
+ iframeEl.addEventListener("load", listener);
5083
+ }
5084
+ function onceStylesheetLoaded(link2, listener, styleSheetLoadTimeout) {
5085
+ let fired = false;
5086
+ let styleSheetLoaded;
5087
+ try {
5088
+ styleSheetLoaded = link2.sheet;
5089
+ } catch (error) {
5090
+ return;
5091
+ }
5092
+ if (styleSheetLoaded) return;
5093
+ const timer = setTimeout(() => {
5094
+ if (!fired) {
5095
+ listener();
5096
+ fired = true;
5097
+ }
5098
+ }, styleSheetLoadTimeout);
5099
+ link2.addEventListener("load", () => {
5100
+ clearTimeout(timer);
5101
+ fired = true;
5102
+ listener();
5103
+ });
5104
+ }
5105
+ function serializeNode(n2, options) {
5106
+ const {
5107
+ doc,
5108
+ mirror: mirror2,
5109
+ blockClass,
5110
+ blockSelector,
5111
+ needsMask,
5112
+ inlineStylesheet,
5113
+ maskInputOptions = {},
5114
+ maskTextFn,
5115
+ maskInputFn,
5116
+ maskAttributeFn,
5117
+ dataURLOptions = {},
5118
+ inlineImages,
5119
+ recordCanvas,
5120
+ keepIframeSrcFn,
5121
+ newlyAddedElement = false,
5122
+ cssCaptured = false,
5123
+ applyBackgroundColorToBlockedElements = false
5124
+ } = options;
5125
+ const rootId = getRootId(doc, mirror2);
5126
+ switch (n2.nodeType) {
5127
+ case n2.DOCUMENT_NODE:
5128
+ if (n2.compatMode !== "CSS1Compat") {
5129
+ return {
5130
+ type: NodeType$3.Document,
5131
+ childNodes: [],
5132
+ compatMode: n2.compatMode
5133
+ // probably "BackCompat"
5134
+ };
5135
+ } else {
5136
+ return {
5137
+ type: NodeType$3.Document,
5138
+ childNodes: []
5139
+ };
5140
+ }
5141
+ case n2.DOCUMENT_TYPE_NODE:
5142
+ return {
5143
+ type: NodeType$3.DocumentType,
5144
+ name: n2.name,
5145
+ publicId: n2.publicId,
5146
+ systemId: n2.systemId,
5147
+ rootId
5148
+ };
5149
+ case n2.ELEMENT_NODE:
5150
+ return serializeElementNode(n2, {
5151
+ doc,
5152
+ blockClass,
5153
+ blockSelector,
5154
+ inlineStylesheet,
5155
+ maskInputOptions,
5156
+ maskInputFn,
5157
+ maskAttributeFn,
5158
+ dataURLOptions,
5159
+ inlineImages,
5160
+ recordCanvas,
5161
+ keepIframeSrcFn,
5162
+ newlyAddedElement,
5163
+ rootId,
5164
+ applyBackgroundColorToBlockedElements
5165
+ });
5166
+ case n2.TEXT_NODE:
5167
+ return serializeTextNode(n2, {
5168
+ doc,
5169
+ needsMask,
5170
+ maskTextFn,
5171
+ rootId,
5172
+ cssCaptured
5173
+ });
5174
+ case n2.CDATA_SECTION_NODE:
5175
+ return {
5176
+ type: NodeType$3.CDATA,
5177
+ textContent: "",
5178
+ rootId
5179
+ };
5180
+ case n2.COMMENT_NODE:
5181
+ return {
5182
+ type: NodeType$3.Comment,
5183
+ textContent: index$1.textContent(n2) || "",
5184
+ rootId
5185
+ };
5186
+ default:
5187
+ return false;
5188
+ }
5189
+ }
5190
+ function getRootId(doc, mirror2) {
5191
+ if (!mirror2.hasNode(doc)) return void 0;
5192
+ const docId = mirror2.getId(doc);
5193
+ return docId === 1 ? void 0 : docId;
5194
+ }
5195
+ function serializeTextNode(n2, options) {
5196
+ const { needsMask, maskTextFn, rootId, cssCaptured } = options;
5197
+ const parent = index$1.parentNode(n2);
5198
+ const parentTagName = parent && parent.tagName;
5199
+ let textContent2 = "";
5200
+ const isStyle = parentTagName === "STYLE" ? true : void 0;
5201
+ const isScript = parentTagName === "SCRIPT" ? true : void 0;
5202
+ if (isScript) {
5203
+ textContent2 = "SCRIPT_PLACEHOLDER";
5204
+ } else if (!cssCaptured) {
5205
+ textContent2 = index$1.textContent(n2);
5206
+ if (isStyle && textContent2) {
5207
+ textContent2 = absolutifyURLs(textContent2, getHref(options.doc));
5208
+ }
5209
+ }
5210
+ if (!isStyle && !isScript && textContent2 && needsMask) {
5211
+ textContent2 = maskTextFn ? maskTextFn(textContent2, index$1.parentElement(n2)) : textContent2.replace(/[\S]/g, "*");
5212
+ }
5213
+ return {
5214
+ type: NodeType$3.Text,
5215
+ textContent: textContent2 || "",
5216
+ rootId
5217
+ };
5218
+ }
5219
+ function serializeElementNode(n2, options) {
5220
+ const {
5221
+ doc,
5222
+ blockClass,
5223
+ blockSelector,
5224
+ inlineStylesheet,
5225
+ maskInputOptions = {},
5226
+ maskInputFn,
5227
+ maskAttributeFn,
5228
+ dataURLOptions = {},
5229
+ inlineImages,
5230
+ recordCanvas,
5231
+ keepIframeSrcFn,
5232
+ newlyAddedElement = false,
5233
+ rootId,
5234
+ applyBackgroundColorToBlockedElements = false
5235
+ } = options;
5236
+ const needBlock = _isBlockedElement(n2, blockClass, blockSelector);
5237
+ const tagName = getValidTagName$1(n2);
5238
+ let attributes = {};
5239
+ const len = n2.attributes.length;
5240
+ for (let i2 = 0; i2 < len; i2++) {
5241
+ const attr = n2.attributes[i2];
5242
+ if (!ignoreAttribute(tagName, attr.name, attr.value)) {
5243
+ const transformedValue = transformAttribute(
5244
+ doc,
5245
+ tagName,
5246
+ toLowerCase(attr.name),
5247
+ attr.value
5248
+ );
5249
+ if (maskAttributeFn && transformedValue !== null) {
5250
+ const maskedValue = maskAttributeFn(attr.name, transformedValue, n2);
5251
+ if (maskedValue !== null) {
5252
+ attributes[attr.name] = maskedValue;
5253
+ }
5254
+ } else {
5255
+ attributes[attr.name] = transformedValue;
5256
+ }
5257
+ }
5258
+ }
5259
+ if (tagName === "link" && inlineStylesheet) {
5260
+ const stylesheet = Array.from(doc.styleSheets).find((s2) => {
5261
+ return s2.href === n2.href;
5262
+ });
5263
+ let cssText = null;
5264
+ if (stylesheet) {
5265
+ cssText = stringifyStylesheet(stylesheet);
5266
+ }
5267
+ if (cssText) {
5268
+ delete attributes.rel;
5269
+ delete attributes.href;
5270
+ attributes._cssText = cssText;
5271
+ }
5272
+ }
5273
+ if (tagName === "style" && n2.sheet) {
5274
+ let cssText = stringifyStylesheet(
5275
+ n2.sheet
5276
+ );
5277
+ if (cssText) {
5278
+ if (n2.childNodes.length > 1) {
5279
+ cssText = markCssSplits(cssText, n2);
5280
+ }
5281
+ attributes._cssText = cssText;
5282
+ }
5283
+ }
5284
+ if (tagName === "input" || tagName === "textarea" || tagName === "select") {
5285
+ const value = n2.value;
5286
+ const checked = n2.checked;
5287
+ if (attributes.type !== "radio" && attributes.type !== "checkbox" && attributes.type !== "submit" && attributes.type !== "button" && value) {
5288
+ attributes.value = maskInputValue({
5289
+ element: n2,
5290
+ type: getInputType(n2),
5291
+ tagName,
5292
+ value,
5293
+ maskInputOptions,
5294
+ maskInputFn
5295
+ });
5296
+ } else if (checked) {
5297
+ attributes.checked = checked;
5298
+ }
5299
+ }
5300
+ if (tagName === "option") {
5301
+ if (n2.selected && !maskInputOptions["select"]) {
5302
+ attributes.selected = true;
5303
+ } else {
5304
+ delete attributes.selected;
5305
+ }
5306
+ }
5307
+ if (tagName === "dialog" && n2.open) {
5308
+ attributes.rr_open_mode = n2.matches("dialog:modal") ? "modal" : "non-modal";
5309
+ }
5310
+ if (tagName === "canvas" && recordCanvas) {
5311
+ if (n2.__context === "2d") {
5312
+ if (!is2DCanvasBlank(n2)) {
5313
+ attributes.rr_dataURL = n2.toDataURL(
5314
+ dataURLOptions.type,
5315
+ dataURLOptions.quality
5316
+ );
5317
+ }
5318
+ } else if (!("__context" in n2)) {
5319
+ const canvasDataURL = n2.toDataURL(
5320
+ dataURLOptions.type,
5321
+ dataURLOptions.quality
5322
+ );
5323
+ const blankCanvas = doc.createElement("canvas");
5324
+ blankCanvas.width = n2.width;
5325
+ blankCanvas.height = n2.height;
5326
+ const blankCanvasDataURL = blankCanvas.toDataURL(
5327
+ dataURLOptions.type,
5328
+ dataURLOptions.quality
5329
+ );
5330
+ if (canvasDataURL !== blankCanvasDataURL) {
5331
+ attributes.rr_dataURL = canvasDataURL;
5332
+ }
5333
+ }
5334
+ }
5335
+ if (tagName === "img" && inlineImages) {
5336
+ if (!canvasService) {
5337
+ canvasService = doc.createElement("canvas");
5338
+ canvasCtx = canvasService.getContext("2d");
5339
+ }
5340
+ const image = n2;
5341
+ const imageSrc = image.currentSrc || image.getAttribute("src") || "<unknown-src>";
5342
+ const priorCrossOrigin = image.crossOrigin;
5343
+ const recordInlineImage = () => {
5344
+ image.removeEventListener("load", recordInlineImage);
5345
+ try {
5346
+ canvasService.width = image.naturalWidth;
5347
+ canvasService.height = image.naturalHeight;
5348
+ canvasCtx.drawImage(image, 0, 0);
5349
+ attributes.rr_dataURL = canvasService.toDataURL(
5350
+ dataURLOptions.type,
5351
+ dataURLOptions.quality
5352
+ );
5353
+ } catch (err) {
5354
+ if (image.crossOrigin !== "anonymous") {
5355
+ image.crossOrigin = "anonymous";
5356
+ if (image.complete && image.naturalWidth !== 0)
5357
+ recordInlineImage();
5358
+ else image.addEventListener("load", recordInlineImage);
5359
+ return;
5360
+ } else {
5361
+ console.warn(
5362
+ `Cannot inline img src=${imageSrc}! Error: ${err}`
5363
+ );
5364
+ }
5365
+ }
5366
+ if (image.crossOrigin === "anonymous") {
5367
+ priorCrossOrigin ? attributes.crossOrigin = priorCrossOrigin : image.removeAttribute("crossorigin");
5368
+ }
5369
+ };
5370
+ if (image.complete && image.naturalWidth !== 0) recordInlineImage();
5371
+ else image.addEventListener("load", recordInlineImage);
5372
+ }
5373
+ if (tagName === "audio" || tagName === "video") {
5374
+ const mediaAttributes = attributes;
5375
+ mediaAttributes.rr_mediaState = n2.paused ? "paused" : "played";
5376
+ mediaAttributes.rr_mediaCurrentTime = n2.currentTime;
5377
+ mediaAttributes.rr_mediaPlaybackRate = n2.playbackRate;
5378
+ mediaAttributes.rr_mediaMuted = n2.muted;
5379
+ mediaAttributes.rr_mediaLoop = n2.loop;
5380
+ mediaAttributes.rr_mediaVolume = n2.volume;
5381
+ }
5382
+ if (!newlyAddedElement) {
5383
+ if (n2.scrollLeft) {
5384
+ attributes.rr_scrollLeft = n2.scrollLeft;
5385
+ }
5386
+ if (n2.scrollTop) {
5387
+ attributes.rr_scrollTop = n2.scrollTop;
5388
+ }
5389
+ }
5390
+ if (needBlock) {
5391
+ const { width, height } = n2.getBoundingClientRect();
5392
+ attributes = {
5393
+ class: attributes.class,
5394
+ rr_width: `${width}px`,
5395
+ rr_height: `${height}px`,
5396
+ ...applyBackgroundColorToBlockedElements ? { rr_background_color: _DEFAULT_BLOCKED_ELEMENT_BACKGROUND_COLOR } : {}
5397
+ };
5398
+ }
5399
+ if (tagName === "iframe" && !keepIframeSrcFn(attributes.src)) {
5400
+ if (!n2.contentDocument) {
5401
+ attributes.rr_src = attributes.src;
5402
+ }
5403
+ delete attributes.src;
5404
+ }
5405
+ let isCustomElement;
5406
+ try {
5407
+ if (customElements.get(tagName)) isCustomElement = true;
5408
+ } catch (e2) {
5409
+ }
5410
+ return {
5411
+ type: NodeType$3.Element,
5412
+ tagName,
5413
+ attributes,
5414
+ childNodes: [],
5415
+ isSVG: isSVGElement(n2) || void 0,
5416
+ needBlock,
5417
+ rootId,
5418
+ isCustom: isCustomElement
5419
+ };
5420
+ }
5421
+ function lowerIfExists(maybeAttr) {
5422
+ if (maybeAttr === void 0 || maybeAttr === null) {
5423
+ return "";
5424
+ } else {
5425
+ return maybeAttr.toLowerCase();
5426
+ }
5427
+ }
5428
+ function slimDOMExcluded(sn, slimDOMOptions) {
5429
+ if (slimDOMOptions.comment && sn.type === NodeType$3.Comment) {
5430
+ return true;
5431
+ } else if (sn.type === NodeType$3.Element) {
5432
+ if (slimDOMOptions.script && // script tag
5433
+ (sn.tagName === "script" || // (module)preload link
5434
+ sn.tagName === "link" && (sn.attributes.rel === "preload" || sn.attributes.rel === "modulepreload") && sn.attributes.as === "script" || // prefetch link
5435
+ sn.tagName === "link" && sn.attributes.rel === "prefetch" && typeof sn.attributes.href === "string" && extractFileExtension(sn.attributes.href) === "js")) {
5436
+ return true;
5437
+ } else if (slimDOMOptions.headFavicon && (sn.tagName === "link" && sn.attributes.rel === "shortcut icon" || sn.tagName === "meta" && (lowerIfExists(sn.attributes.name).match(
5438
+ /^msapplication-tile(image|color)$/
5439
+ ) || lowerIfExists(sn.attributes.name) === "application-name" || lowerIfExists(sn.attributes.rel) === "icon" || lowerIfExists(sn.attributes.rel) === "apple-touch-icon" || lowerIfExists(sn.attributes.rel) === "shortcut icon"))) {
5440
+ return true;
5441
+ } else if (sn.tagName === "meta") {
5442
+ if (slimDOMOptions.headMetaDescKeywords && lowerIfExists(sn.attributes.name).match(/^description|keywords$/)) {
5443
+ return true;
5444
+ } else if (slimDOMOptions.headMetaSocial && (lowerIfExists(sn.attributes.property).match(/^(og|twitter|fb):/) || // og = opengraph (facebook)
5445
+ lowerIfExists(sn.attributes.name).match(/^(og|twitter):/) || lowerIfExists(sn.attributes.name) === "pinterest")) {
5446
+ return true;
5447
+ } else if (slimDOMOptions.headMetaRobots && (lowerIfExists(sn.attributes.name) === "robots" || lowerIfExists(sn.attributes.name) === "googlebot" || lowerIfExists(sn.attributes.name) === "bingbot")) {
5448
+ return true;
5449
+ } else if (slimDOMOptions.headMetaHttpEquiv && sn.attributes["http-equiv"] !== void 0) {
5450
+ return true;
5451
+ } else if (slimDOMOptions.headMetaAuthorship && (lowerIfExists(sn.attributes.name) === "author" || lowerIfExists(sn.attributes.name) === "generator" || lowerIfExists(sn.attributes.name) === "framework" || lowerIfExists(sn.attributes.name) === "publisher" || lowerIfExists(sn.attributes.name) === "progid" || lowerIfExists(sn.attributes.property).match(/^article:/) || lowerIfExists(sn.attributes.property).match(/^product:/))) {
5452
+ return true;
5453
+ } else if (slimDOMOptions.headMetaVerification && (lowerIfExists(sn.attributes.name) === "google-site-verification" || lowerIfExists(sn.attributes.name) === "yandex-verification" || lowerIfExists(sn.attributes.name) === "csrf-token" || lowerIfExists(sn.attributes.name) === "p:domain_verify" || lowerIfExists(sn.attributes.name) === "verify-v1" || lowerIfExists(sn.attributes.name) === "verification" || lowerIfExists(sn.attributes.name) === "shopify-checkout-api-token")) {
5454
+ return true;
5455
+ }
5456
+ }
5457
+ }
5458
+ return false;
5459
+ }
5460
+ function serializeNodeWithId(n2, options) {
5461
+ const {
5462
+ doc,
5463
+ mirror: mirror2,
5464
+ blockClass,
5465
+ blockSelector,
5466
+ maskTextClass,
5467
+ maskTextSelector,
5468
+ skipChild = false,
5469
+ inlineStylesheet = true,
5470
+ maskInputOptions = {},
5471
+ maskTextFn,
5472
+ maskInputFn,
5473
+ maskAttributeFn,
5474
+ slimDOMOptions,
5475
+ dataURLOptions = {},
5476
+ inlineImages = false,
5477
+ recordCanvas = false,
5478
+ onSerialize,
5479
+ onIframeLoad,
5480
+ iframeLoadTimeout = 5e3,
5481
+ onStylesheetLoad,
5482
+ stylesheetLoadTimeout = 5e3,
5483
+ keepIframeSrcFn = () => false,
5484
+ newlyAddedElement = false,
5485
+ cssCaptured = false,
5486
+ applyBackgroundColorToBlockedElements = false
5487
+ } = options;
5488
+ let { needsMask } = options;
5489
+ let { preserveWhiteSpace = true } = options;
5490
+ if (!needsMask) {
5491
+ const checkAncestors = needsMask === void 0;
5492
+ needsMask = needMaskingText(
5493
+ n2,
5494
+ maskTextClass,
5495
+ maskTextSelector,
5496
+ checkAncestors
5497
+ );
5498
+ }
5499
+ const _serializedNode = serializeNode(n2, {
5500
+ doc,
5501
+ mirror: mirror2,
5502
+ blockClass,
5503
+ blockSelector,
5504
+ needsMask,
5505
+ inlineStylesheet,
5506
+ maskInputOptions,
5507
+ maskTextFn,
5508
+ maskInputFn,
5509
+ maskAttributeFn,
5510
+ dataURLOptions,
5511
+ inlineImages,
5512
+ recordCanvas,
5513
+ keepIframeSrcFn,
5514
+ newlyAddedElement,
5515
+ cssCaptured,
5516
+ applyBackgroundColorToBlockedElements
5517
+ });
5518
+ if (!_serializedNode) {
5519
+ console.warn(n2, "not serialized");
5520
+ return null;
5521
+ }
5522
+ let id;
5523
+ if (mirror2.hasNode(n2)) {
5524
+ id = mirror2.getId(n2);
5525
+ } else if (slimDOMExcluded(_serializedNode, slimDOMOptions) || !preserveWhiteSpace && _serializedNode.type === NodeType$3.Text && !_serializedNode.textContent.replace(/^\s+|\s+$/gm, "").length) {
5526
+ id = IGNORED_NODE;
5527
+ } else {
5528
+ id = genId();
5529
+ }
5530
+ const serializedNode = Object.assign(_serializedNode, { id });
5531
+ mirror2.add(n2, serializedNode);
5532
+ if (id === IGNORED_NODE) {
5533
+ return null;
5534
+ }
5535
+ if (onSerialize) {
5536
+ onSerialize(n2);
5537
+ }
5538
+ let recordChild = !skipChild;
5539
+ if (serializedNode.type === NodeType$3.Element) {
5540
+ recordChild = recordChild && !serializedNode.needBlock;
5541
+ delete serializedNode.needBlock;
5542
+ const shadowRootEl = index$1.shadowRoot(n2);
5543
+ if (shadowRootEl && isNativeShadowDom(shadowRootEl))
5544
+ serializedNode.isShadowHost = true;
5545
+ }
5546
+ if ((serializedNode.type === NodeType$3.Document || serializedNode.type === NodeType$3.Element) && recordChild) {
5547
+ if (slimDOMOptions.headWhitespace && serializedNode.type === NodeType$3.Element && serializedNode.tagName === "head") {
5548
+ preserveWhiteSpace = false;
5549
+ }
5550
+ const bypassOptions = {
5551
+ doc,
5552
+ mirror: mirror2,
5553
+ blockClass,
5554
+ blockSelector,
5555
+ needsMask,
5556
+ maskTextClass,
5557
+ maskTextSelector,
5558
+ skipChild,
5559
+ inlineStylesheet,
5560
+ maskInputOptions,
5561
+ maskTextFn,
5562
+ maskInputFn,
5563
+ maskAttributeFn,
5564
+ slimDOMOptions,
5565
+ dataURLOptions,
5566
+ inlineImages,
5567
+ recordCanvas,
5568
+ preserveWhiteSpace,
5569
+ onSerialize,
5570
+ onIframeLoad,
5571
+ iframeLoadTimeout,
5572
+ onStylesheetLoad,
5573
+ stylesheetLoadTimeout,
5574
+ keepIframeSrcFn,
5575
+ cssCaptured: false,
5576
+ applyBackgroundColorToBlockedElements
5577
+ };
5578
+ if (serializedNode.type === NodeType$3.Element && serializedNode.tagName === "textarea" && serializedNode.attributes.value !== void 0) ;
5579
+ else {
5580
+ if (serializedNode.type === NodeType$3.Element && serializedNode.attributes._cssText !== void 0 && typeof serializedNode.attributes._cssText === "string") {
5581
+ bypassOptions.cssCaptured = true;
5582
+ }
5583
+ for (const childN of Array.from(index$1.childNodes(n2))) {
5584
+ const serializedChildNode = serializeNodeWithId(childN, bypassOptions);
5585
+ if (serializedChildNode) {
5586
+ serializedNode.childNodes.push(serializedChildNode);
5587
+ }
5588
+ }
5589
+ }
5590
+ let shadowRootEl = null;
5591
+ if (isElement(n2) && (shadowRootEl = index$1.shadowRoot(n2))) {
5592
+ for (const childN of Array.from(index$1.childNodes(shadowRootEl))) {
5593
+ const serializedChildNode = serializeNodeWithId(childN, bypassOptions);
5594
+ if (serializedChildNode) {
5595
+ isNativeShadowDom(shadowRootEl) && (serializedChildNode.isShadow = true);
5596
+ serializedNode.childNodes.push(serializedChildNode);
5597
+ }
5598
+ }
5599
+ }
5600
+ }
5601
+ const parent = index$1.parentNode(n2);
5602
+ if (parent && isShadowRoot(parent) && isNativeShadowDom(parent)) {
5603
+ serializedNode.isShadow = true;
5604
+ }
5605
+ if (serializedNode.type === NodeType$3.Element && serializedNode.tagName === "iframe") {
5606
+ onceIframeLoaded(
5607
+ n2,
5608
+ () => {
5609
+ const iframeDoc = n2.contentDocument;
5610
+ if (iframeDoc && onIframeLoad) {
5611
+ const serializedIframeNode = serializeNodeWithId(iframeDoc, {
5612
+ doc: iframeDoc,
5613
+ mirror: mirror2,
5614
+ blockClass,
5615
+ blockSelector,
5616
+ needsMask,
5617
+ maskTextClass,
5618
+ maskTextSelector,
5619
+ skipChild: false,
5620
+ inlineStylesheet,
5621
+ maskInputOptions,
5622
+ maskTextFn,
5623
+ maskInputFn,
5624
+ maskAttributeFn,
5625
+ slimDOMOptions,
5626
+ dataURLOptions,
5627
+ inlineImages,
5628
+ recordCanvas,
5629
+ preserveWhiteSpace,
5630
+ onSerialize,
5631
+ onIframeLoad,
5632
+ iframeLoadTimeout,
5633
+ onStylesheetLoad,
5634
+ stylesheetLoadTimeout,
5635
+ keepIframeSrcFn
5636
+ });
5637
+ if (serializedIframeNode) {
5638
+ onIframeLoad(
5639
+ n2,
5640
+ serializedIframeNode
5641
+ );
5642
+ }
5643
+ }
5644
+ },
5645
+ iframeLoadTimeout
5646
+ );
5647
+ }
5648
+ if (serializedNode.type === NodeType$3.Element && serializedNode.tagName === "link" && typeof serializedNode.attributes.rel === "string" && (serializedNode.attributes.rel === "stylesheet" || serializedNode.attributes.rel === "preload" && typeof serializedNode.attributes.href === "string" && extractFileExtension(serializedNode.attributes.href) === "css")) {
5649
+ onceStylesheetLoaded(
5650
+ n2,
5651
+ () => {
5652
+ if (onStylesheetLoad) {
5653
+ const serializedLinkNode = serializeNodeWithId(n2, {
5654
+ doc,
5655
+ mirror: mirror2,
5656
+ blockClass,
5657
+ blockSelector,
5658
+ needsMask,
5659
+ maskTextClass,
5660
+ maskTextSelector,
5661
+ skipChild: false,
5662
+ inlineStylesheet,
5663
+ maskInputOptions,
5664
+ maskTextFn,
5665
+ maskInputFn,
5666
+ maskAttributeFn,
5667
+ slimDOMOptions,
5668
+ dataURLOptions,
5669
+ inlineImages,
5670
+ recordCanvas,
5671
+ preserveWhiteSpace,
5672
+ onSerialize,
5673
+ onIframeLoad,
5674
+ iframeLoadTimeout,
5675
+ onStylesheetLoad,
5676
+ stylesheetLoadTimeout,
5677
+ keepIframeSrcFn
5678
+ });
5679
+ if (serializedLinkNode) {
5680
+ onStylesheetLoad(
5681
+ n2,
5682
+ serializedLinkNode
5683
+ );
5684
+ }
5685
+ }
5686
+ },
5687
+ stylesheetLoadTimeout
5688
+ );
5689
+ }
5690
+ return serializedNode;
5691
+ }
5692
+ function snapshot(n2, options) {
5693
+ const {
5694
+ mirror: mirror2 = new Mirror(),
5695
+ blockClass = "rr-block",
5696
+ blockSelector = null,
5697
+ maskTextClass = "rr-mask",
5698
+ maskTextSelector = null,
5699
+ inlineStylesheet = true,
5700
+ inlineImages = false,
5701
+ recordCanvas = false,
5702
+ maskAllInputs = false,
5703
+ maskTextFn,
5704
+ maskInputFn,
5705
+ maskAttributeFn,
5706
+ slimDOM = false,
5707
+ dataURLOptions,
5708
+ preserveWhiteSpace,
5709
+ onSerialize,
5710
+ onIframeLoad,
5711
+ iframeLoadTimeout,
5712
+ onStylesheetLoad,
5713
+ stylesheetLoadTimeout,
5714
+ keepIframeSrcFn = () => false,
5715
+ applyBackgroundColorToBlockedElements = false
5716
+ } = options || {};
5717
+ const maskInputOptions = maskAllInputs === true ? {
5718
+ color: true,
5719
+ date: true,
5720
+ "datetime-local": true,
5721
+ email: true,
5722
+ month: true,
5723
+ number: true,
5724
+ range: true,
5725
+ search: true,
5726
+ tel: true,
5727
+ text: true,
5728
+ time: true,
5729
+ url: true,
5730
+ week: true,
5731
+ textarea: true,
5732
+ select: true,
5733
+ password: true
5734
+ } : maskAllInputs === false ? {
5735
+ password: true
5736
+ } : maskAllInputs;
5737
+ const slimDOMOptions = slimDOM === true || slimDOM === "all" ? (
5738
+ // if true: set of sensible options that should not throw away any information
5739
+ {
5740
+ script: true,
5741
+ comment: true,
5742
+ headFavicon: true,
5743
+ headWhitespace: true,
5744
+ headMetaDescKeywords: slimDOM === "all",
5745
+ // destructive
5746
+ headMetaSocial: true,
5747
+ headMetaRobots: true,
5748
+ headMetaHttpEquiv: true,
5749
+ headMetaAuthorship: true,
5750
+ headMetaVerification: true
5751
+ }
5752
+ ) : slimDOM === false ? {} : slimDOM;
5753
+ return serializeNodeWithId(n2, {
5754
+ doc: n2,
5755
+ mirror: mirror2,
5756
+ blockClass,
5757
+ blockSelector,
5758
+ maskTextClass,
5759
+ maskTextSelector,
5760
+ skipChild: false,
5761
+ inlineStylesheet,
5762
+ maskInputOptions,
5763
+ maskTextFn,
5764
+ maskInputFn,
5765
+ maskAttributeFn,
5766
+ slimDOMOptions,
5767
+ dataURLOptions,
5768
+ inlineImages,
5769
+ recordCanvas,
5770
+ preserveWhiteSpace,
5771
+ onSerialize,
5772
+ onIframeLoad,
5773
+ iframeLoadTimeout,
5774
+ onStylesheetLoad,
5775
+ stylesheetLoadTimeout,
5776
+ keepIframeSrcFn,
5777
+ newlyAddedElement: false,
5778
+ applyBackgroundColorToBlockedElements
5779
+ });
5780
+ }
4405
5781
  const MEDIA_SELECTOR = /(max|min)-device-(width|height)/;
4406
5782
  const MEDIA_SELECTOR_GLOBAL = new RegExp(MEDIA_SELECTOR.source, "g");
4407
5783
  const mediaSelectorPlugin = {
@@ -14076,6 +15452,8 @@ var ReplayerEvents = /* @__PURE__ */ ((ReplayerEvents2) => {
14076
15452
  ReplayerEvents2["StateChange"] = "state-change";
14077
15453
  ReplayerEvents2["PlayBack"] = "play-back";
14078
15454
  ReplayerEvents2["Destroy"] = "destroy";
15455
+ ReplayerEvents2["SeekStart"] = "seek-start";
15456
+ ReplayerEvents2["SeekEnd"] = "seek-end";
14079
15457
  return ReplayerEvents2;
14080
15458
  })(ReplayerEvents || {});
14081
15459
  var NodeType = /* @__PURE__ */ ((NodeType2) => {
@@ -14125,6 +15503,86 @@ try {
14125
15503
  console.debug("Unable to override Array.from", err);
14126
15504
  }
14127
15505
  createMirror$2();
15506
+ class SeekCache {
15507
+ constructor(maxEntries = 10) {
15508
+ __publicField2(this, "entries", []);
15509
+ __publicField2(this, "maxEntries");
15510
+ this.maxEntries = maxEntries;
15511
+ }
15512
+ /**
15513
+ * Store a new checkpoint. Entries are kept sorted by timestamp.
15514
+ * When the cache is full the oldest entry is evicted.
15515
+ */
15516
+ add(timestamp, snapshotNode, initialOffset) {
15517
+ const event2 = {
15518
+ type: EventType$1.FullSnapshot,
15519
+ data: { node: snapshotNode, initialOffset },
15520
+ timestamp
15521
+ };
15522
+ const entry = { timestamp, event: event2 };
15523
+ if (!this.entries.length || this.entries[this.entries.length - 1].timestamp < timestamp) {
15524
+ this.entries.push(entry);
15525
+ } else {
15526
+ let lo = 0;
15527
+ let hi = this.entries.length - 1;
15528
+ while (lo <= hi) {
15529
+ const mid = lo + hi >>> 1;
15530
+ if (this.entries[mid].timestamp <= timestamp) lo = mid + 1;
15531
+ else hi = mid - 1;
15532
+ }
15533
+ if (lo > 0 && this.entries[lo - 1].timestamp === timestamp) {
15534
+ this.entries[lo - 1] = entry;
15535
+ } else {
15536
+ this.entries.splice(lo, 0, entry);
15537
+ }
15538
+ }
15539
+ if (this.entries.length > this.maxEntries) {
15540
+ this.entries.shift();
15541
+ }
15542
+ }
15543
+ /**
15544
+ * Find the best cached checkpoint for seeking to `targetTime`.
15545
+ *
15546
+ * The checkpoint must be:
15547
+ * - at or before `targetTime` (we cannot seek forward past the snapshot)
15548
+ * - strictly after `baselineMetaTimestamp` (ensures the snapshot belongs to
15549
+ * the same recording session / checkout as the current seek)
15550
+ *
15551
+ * Returns `null` on cache miss.
15552
+ */
15553
+ findBestFor(targetTime, baselineMetaTimestamp) {
15554
+ let lo = 0;
15555
+ let hi = this.entries.length - 1;
15556
+ let best = -1;
15557
+ while (lo <= hi) {
15558
+ const mid = lo + hi >>> 1;
15559
+ if (this.entries[mid].timestamp <= targetTime) {
15560
+ best = mid;
15561
+ lo = mid + 1;
15562
+ } else {
15563
+ hi = mid - 1;
15564
+ }
15565
+ }
15566
+ if (best === -1) return null;
15567
+ for (let i2 = best; i2 >= 0; i2--) {
15568
+ if (this.entries[i2].timestamp > baselineMetaTimestamp) {
15569
+ return this.entries[i2];
15570
+ }
15571
+ }
15572
+ return null;
15573
+ }
15574
+ /** Remove all cached entries (e.g. when a new set of events is loaded). */
15575
+ clear() {
15576
+ this.entries = [];
15577
+ }
15578
+ get size() {
15579
+ return this.entries.length;
15580
+ }
15581
+ /** Expose entries for testing. */
15582
+ getEntries() {
15583
+ return this.entries;
15584
+ }
15585
+ }
14128
15586
  function mitt$1(n2) {
14129
15587
  return { all: n2 = n2 || /* @__PURE__ */ new Map(), on: function(t2, e2) {
14130
15588
  var i2 = n2.get(t2);
@@ -14597,13 +16055,31 @@ function v(t2) {
14597
16055
  } };
14598
16056
  return c2;
14599
16057
  }
16058
+ function isDuplicateEvent(existing, incoming) {
16059
+ if (existing === incoming) {
16060
+ return true;
16061
+ }
16062
+ if (existing.timestamp === incoming.timestamp && existing.type === incoming.type) {
16063
+ return JSON.stringify(existing) === JSON.stringify(incoming);
16064
+ }
16065
+ return false;
16066
+ }
14600
16067
  function discardPriorSnapshots(events, baselineTime) {
14601
- for (let idx = events.length - 1; idx >= 0; idx--) {
14602
- const event2 = events[idx];
14603
- if (event2.type === EventType$1.Meta) {
14604
- if (event2.timestamp <= baselineTime) {
14605
- return events.slice(idx);
14606
- }
16068
+ let lo = 0;
16069
+ let hi = events.length - 1;
16070
+ let lastBeforeOrAt = -1;
16071
+ while (lo <= hi) {
16072
+ const mid = lo + hi >>> 1;
16073
+ if (events[mid].timestamp <= baselineTime) {
16074
+ lastBeforeOrAt = mid;
16075
+ lo = mid + 1;
16076
+ } else {
16077
+ hi = mid - 1;
16078
+ }
16079
+ }
16080
+ for (let idx = lastBeforeOrAt; idx >= 0; idx--) {
16081
+ if (events[idx].type === EventType$1.Meta) {
16082
+ return events.slice(idx);
14607
16083
  }
14608
16084
  }
14609
16085
  return events;
@@ -14694,9 +16170,6 @@ function createPlayerService(context, { getCastFn, applyEventsSynchronously, emi
14694
16170
  var _a22;
14695
16171
  const { timer, events, baselineTime, lastPlayedEvent } = ctx;
14696
16172
  timer.clear();
14697
- for (const event2 of events) {
14698
- addDelay(event2, baselineTime);
14699
- }
14700
16173
  const neededEvents = discardPriorSnapshots(events, baselineTime);
14701
16174
  let lastPlayedTimestamp = lastPlayedEvent == null ? void 0 : lastPlayedEvent.timestamp;
14702
16175
  if ((lastPlayedEvent == null ? void 0 : lastPlayedEvent.type) === EventType$1.IncrementalSnapshot && lastPlayedEvent.data.source === IncrementalSource.MouseMove) {
@@ -14705,23 +16178,46 @@ function createPlayerService(context, { getCastFn, applyEventsSynchronously, emi
14705
16178
  if (baselineTime < (lastPlayedTimestamp || 0)) {
14706
16179
  emitter.emit(ReplayerEvents.PlayBack);
14707
16180
  }
14708
- const syncEvents = new Array();
14709
- for (const event2 of neededEvents) {
14710
- if (lastPlayedTimestamp && lastPlayedTimestamp < baselineTime && (event2.timestamp <= lastPlayedTimestamp || event2 === lastPlayedEvent)) {
14711
- continue;
16181
+ let syncEnd = neededEvents.length;
16182
+ {
16183
+ let lo = 0;
16184
+ let hi = neededEvents.length;
16185
+ while (lo < hi) {
16186
+ const mid = lo + hi >>> 1;
16187
+ if (neededEvents[mid].timestamp < baselineTime) lo = mid + 1;
16188
+ else hi = mid;
14712
16189
  }
14713
- if (event2.timestamp < baselineTime) {
14714
- syncEvents.push(event2);
14715
- } else {
14716
- const castFn = getCastFn(event2, false);
14717
- timer.addAction({
14718
- doAction: () => {
14719
- castFn();
14720
- },
14721
- delay: event2.delay
14722
- });
16190
+ syncEnd = lo;
16191
+ }
16192
+ let syncStart = 0;
16193
+ if (lastPlayedTimestamp && lastPlayedTimestamp < baselineTime) {
16194
+ let lo = 0;
16195
+ let hi = syncEnd;
16196
+ while (lo < hi) {
16197
+ const mid = lo + hi >>> 1;
16198
+ if (neededEvents[mid].timestamp <= lastPlayedTimestamp)
16199
+ lo = mid + 1;
16200
+ else hi = mid;
16201
+ }
16202
+ syncStart = lo;
16203
+ if (syncStart < syncEnd && neededEvents[syncStart] === lastPlayedEvent) {
16204
+ syncStart++;
14723
16205
  }
14724
16206
  }
16207
+ for (let i2 = syncEnd; i2 < neededEvents.length; i2++) {
16208
+ addDelay(neededEvents[i2], baselineTime);
16209
+ }
16210
+ const syncEvents = neededEvents.slice(syncStart, syncEnd);
16211
+ for (let i2 = syncEnd; i2 < neededEvents.length; i2++) {
16212
+ const event2 = neededEvents[i2];
16213
+ const castFn = getCastFn(event2, false);
16214
+ timer.addAction({
16215
+ doAction: () => {
16216
+ castFn();
16217
+ },
16218
+ delay: event2.delay ?? 0
16219
+ });
16220
+ }
14725
16221
  applyEventsSynchronously(syncEvents);
14726
16222
  emitter.emit(ReplayerEvents.Flush);
14727
16223
  timer.start();
@@ -14751,6 +16247,9 @@ function createPlayerService(context, { getCastFn, applyEventsSynchronously, emi
14751
16247
  addDelay(event2, baselineTime);
14752
16248
  let end = events.length - 1;
14753
16249
  if (!events[end] || events[end].timestamp <= event2.timestamp) {
16250
+ if (events[end] && isDuplicateEvent(events[end], event2)) {
16251
+ return { ...ctx, events };
16252
+ }
14754
16253
  events.push(event2);
14755
16254
  } else {
14756
16255
  let insertionIndex = -1;
@@ -14766,6 +16265,16 @@ function createPlayerService(context, { getCastFn, applyEventsSynchronously, emi
14766
16265
  if (insertionIndex === -1) {
14767
16266
  insertionIndex = start;
14768
16267
  }
16268
+ for (let i2 = insertionIndex - 1; i2 >= 0 && events[i2].timestamp === event2.timestamp; i2--) {
16269
+ if (isDuplicateEvent(events[i2], event2)) {
16270
+ return { ...ctx, events };
16271
+ }
16272
+ }
16273
+ for (let i2 = insertionIndex; i2 < events.length && events[i2].timestamp === event2.timestamp; i2++) {
16274
+ if (isDuplicateEvent(events[i2], event2)) {
16275
+ return { ...ctx, events };
16276
+ }
16277
+ }
14769
16278
  events.splice(insertionIndex, 0, event2);
14770
16279
  }
14771
16280
  const isSync = event2.timestamp < baselineTime;
@@ -14777,7 +16286,7 @@ function createPlayerService(context, { getCastFn, applyEventsSynchronously, emi
14777
16286
  doAction: () => {
14778
16287
  castFn();
14779
16288
  },
14780
- delay: event2.delay
16289
+ delay: event2.delay ?? 0
14781
16290
  });
14782
16291
  }
14783
16292
  }
@@ -15298,9 +16807,12 @@ class Replayer {
15298
16807
  __publicField2(this, "styleMirror", new StyleSheetMirror());
15299
16808
  __publicField2(this, "mediaManager");
15300
16809
  __publicField2(this, "firstFullSnapshot", null);
16810
+ __publicField2(this, "seekCache");
15301
16811
  __publicField2(this, "newDocumentQueue", []);
15302
16812
  __publicField2(this, "mousePos", null);
15303
16813
  __publicField2(this, "touchActive", null);
16814
+ __publicField2(this, "seekInProgress", false);
16815
+ __publicField2(this, "pendingCaptureTimer", null);
15304
16816
  __publicField2(this, "lastMouseDownEvent", null);
15305
16817
  __publicField2(this, "lastHoveredRootNode");
15306
16818
  __publicField2(this, "lastSelectionData", null);
@@ -15317,7 +16829,47 @@ class Replayer {
15317
16829
  }
15318
16830
  });
15319
16831
  __publicField2(this, "applyEventsSynchronously", (events2) => {
15320
- for (const event2 of events2) {
16832
+ var _a22;
16833
+ let startIdx = 0;
16834
+ if (this.config.useSeekCache && events2.length > 0) {
16835
+ const fullSnapshotEvt = events2.find(
16836
+ (e2) => e2.type === EventType$1.FullSnapshot
16837
+ );
16838
+ if (fullSnapshotEvt) {
16839
+ const targetTime = events2[events2.length - 1].timestamp;
16840
+ const checkpoint = this.seekCache.findBestFor(
16841
+ targetTime,
16842
+ fullSnapshotEvt.timestamp
16843
+ );
16844
+ if (checkpoint) {
16845
+ const metaEvt = events2.find((e2) => e2.type === EventType$1.Meta);
16846
+ if (metaEvt) {
16847
+ this.getCastFn(metaEvt, true)();
16848
+ }
16849
+ this.mediaManager.reset();
16850
+ this.styleMirror.reset();
16851
+ this.rebuildFullSnapshot(
16852
+ checkpoint.event,
16853
+ /* isSync */
16854
+ true
16855
+ );
16856
+ this.firstFullSnapshot = true;
16857
+ (_a22 = this.iframe.contentWindow) == null ? void 0 : _a22.scrollTo(
16858
+ checkpoint.event.data.initialOffset
16859
+ );
16860
+ let lo = 0;
16861
+ let hi = events2.length;
16862
+ while (lo < hi) {
16863
+ const mid = lo + hi >>> 1;
16864
+ if (events2[mid].timestamp <= checkpoint.timestamp) lo = mid + 1;
16865
+ else hi = mid;
16866
+ }
16867
+ startIdx = lo;
16868
+ }
16869
+ }
16870
+ }
16871
+ for (let i2 = startIdx; i2 < events2.length; i2++) {
16872
+ const event2 = events2[i2];
15321
16873
  switch (event2.type) {
15322
16874
  case EventType$1.DomContentLoaded:
15323
16875
  case EventType$1.Load:
@@ -15393,7 +16945,7 @@ class Replayer {
15393
16945
  // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
15394
16946
  this.nextUserInteractionEvent.delay - event2.delay
15395
16947
  );
15396
- this.play(this.getCurrentTime() + skipTime);
16948
+ this.playInternal(this.getCurrentTime() + skipTime);
15397
16949
  this.nextUserInteractionEvent = null;
15398
16950
  }
15399
16951
  }
@@ -15449,9 +17001,13 @@ class Replayer {
15449
17001
  mouseTail: defaultMouseTailConfig,
15450
17002
  useVirtualDom: true,
15451
17003
  // Virtual-dom optimization is enabled by default.
17004
+ useSeekCache: false,
17005
+ // Opt-in until production-validated; flip to true once confidence is high.
17006
+ seekCacheMaxEntries: 10,
15452
17007
  logger: console
15453
17008
  };
15454
17009
  this.config = Object.assign({}, defaultConfig, config);
17010
+ this.seekCache = new SeekCache(this.config.seekCacheMaxEntries);
15455
17011
  this.handleResize = this.handleResize.bind(this);
15456
17012
  this.getCastFn = this.getCastFn.bind(this);
15457
17013
  this.applyEventsSynchronously = this.applyEventsSynchronously.bind(this);
@@ -15563,6 +17119,25 @@ class Replayer {
15563
17119
  this.styleMirror.reset();
15564
17120
  this.mediaManager.reset();
15565
17121
  });
17122
+ this.emitter.on(ReplayerEvents.Flush, () => {
17123
+ if (this.seekInProgress) {
17124
+ this.seekInProgress = false;
17125
+ const seekEndTimeOffset = this.getTimeOffset();
17126
+ this.emitter.emit(ReplayerEvents.SeekEnd, {
17127
+ timeOffset: seekEndTimeOffset
17128
+ });
17129
+ }
17130
+ if (this.config.useSeekCache) {
17131
+ const captureTimestamp = this.service.state.context.baselineTime;
17132
+ if (this.pendingCaptureTimer !== null) {
17133
+ clearTimeout(this.pendingCaptureTimer);
17134
+ }
17135
+ this.pendingCaptureTimer = setTimeout(() => {
17136
+ this.pendingCaptureTimer = null;
17137
+ this.captureSeekCacheEntry(captureTimestamp);
17138
+ }, 0);
17139
+ }
17140
+ });
15566
17141
  const timer = new Timer([], {
15567
17142
  speed: this.config.speed
15568
17143
  });
@@ -15721,6 +17296,16 @@ class Replayer {
15721
17296
  * @param timeOffset - number
15722
17297
  */
15723
17298
  play(timeOffset = 0) {
17299
+ this.seekInProgress = true;
17300
+ this.emitter.emit(ReplayerEvents.SeekStart, { timeOffset });
17301
+ this.playInternal(timeOffset);
17302
+ }
17303
+ /**
17304
+ * Internal seek/resume that does NOT emit SeekStart/SeekEnd. Use this for
17305
+ * programmatic jumps that are not initiated by the user (e.g. skipInactive,
17306
+ * stylesheet-load resume) to avoid spurious loading-indicator flicker.
17307
+ */
17308
+ playInternal(timeOffset = 0) {
15724
17309
  var _a22, _b2;
15725
17310
  if (this.service.state.matches("paused")) {
15726
17311
  this.service.send({ type: "PLAY", payload: { timeOffset } });
@@ -15789,6 +17374,13 @@ class Replayer {
15789
17374
  resetCache() {
15790
17375
  this.cache = createCache();
15791
17376
  }
17377
+ /**
17378
+ * Empties the seek-checkpoint cache. Call this if you load a new set of
17379
+ * events into an existing Replayer instance to avoid stale snapshots.
17380
+ */
17381
+ resetSeekCache() {
17382
+ this.seekCache.clear();
17383
+ }
15792
17384
  setupDom() {
15793
17385
  this.wrapper = document.createElement("div");
15794
17386
  this.wrapper.classList.add("replayer-wrapper");
@@ -15819,6 +17411,37 @@ class Replayer {
15819
17411
  polyfill$1(this.iframe.contentWindow);
15820
17412
  }
15821
17413
  }
17414
+ /**
17415
+ * Serialize the current iframe DOM into the seek-checkpoint cache so that
17416
+ * future seeks near this timestamp can restore from the cache instead of
17417
+ * replaying all incremental events from the original FullSnapshot.
17418
+ *
17419
+ * This is called asynchronously (via requestIdleCallback / setTimeout) after
17420
+ * each Flush so it does not block the seek operation itself.
17421
+ */
17422
+ captureSeekCacheEntry(timestamp) {
17423
+ if (!this.iframe.contentDocument) return;
17424
+ if (timestamp <= 0) return;
17425
+ const scratchMirror = createMirror$2();
17426
+ this.mirror.getIds().forEach((id) => {
17427
+ const node2 = this.mirror.getNode(id);
17428
+ if (!node2) return;
17429
+ const meta = this.mirror.getMeta(node2);
17430
+ if (meta) scratchMirror.add(node2, meta);
17431
+ });
17432
+ const snapshotNode = snapshot(this.iframe.contentDocument, {
17433
+ mirror: scratchMirror,
17434
+ blockClass: this.config.blockClass,
17435
+ inlineStylesheet: true
17436
+ });
17437
+ if (!snapshotNode) return;
17438
+ const scrollEl = this.iframe.contentDocument.scrollingElement || this.iframe.contentDocument.documentElement;
17439
+ const initialOffset = {
17440
+ top: (scrollEl == null ? void 0 : scrollEl.scrollTop) ?? 0,
17441
+ left: (scrollEl == null ? void 0 : scrollEl.scrollLeft) ?? 0
17442
+ };
17443
+ this.seekCache.add(timestamp, snapshotNode, initialOffset);
17444
+ }
15822
17445
  rebuildFullSnapshot(event2, isSync = false) {
15823
17446
  if (!this.iframe.contentDocument) {
15824
17447
  return this.warn("Looks like your replayer has been destroyed.");
@@ -15965,6 +17588,7 @@ class Replayer {
15965
17588
  this.collectIframeAndAttachDocument(collectedIframes, builtNode);
15966
17589
  const sn = mirror2.getMeta(builtNode);
15967
17590
  if ((sn == null ? void 0 : sn.type) === NodeType.Element && (sn == null ? void 0 : sn.tagName.toUpperCase()) === "HTML") {
17591
+ if (!iframeEl.contentDocument) return;
15968
17592
  const { documentElement, head } = iframeEl.contentDocument;
15969
17593
  this.insertStyleRules(
15970
17594
  documentElement,
@@ -15980,15 +17604,17 @@ class Replayer {
15980
17604
  });
15981
17605
  }
15982
17606
  };
17607
+ const iframeDoc = iframeEl.contentDocument;
17608
+ if (!iframeDoc) return;
15983
17609
  buildNodeWithSN(mutation.node, {
15984
- doc: iframeEl.contentDocument,
17610
+ doc: iframeDoc,
15985
17611
  mirror: mirror2,
15986
17612
  hackCss: true,
15987
17613
  skipChild: false,
15988
17614
  afterAppend,
15989
17615
  cache: this.cache
15990
17616
  });
15991
- afterAppend(iframeEl.contentDocument, mutation.node.id);
17617
+ afterAppend(iframeDoc, mutation.node.id);
15992
17618
  for (const { mutationInQueue, builtNode } of collectedIframes) {
15993
17619
  this.attachDocumentToIframe(mutationInQueue, builtNode);
15994
17620
  this.newDocumentQueue = this.newDocumentQueue.filter(
@@ -16036,7 +17662,7 @@ class Replayer {
16036
17662
  unloadSheets.delete(css);
16037
17663
  if (unloadSheets.size === 0 && timer !== -1) {
16038
17664
  if (beforeLoadState.matches("playing")) {
16039
- this.play(this.getCurrentTime());
17665
+ this.playInternal(this.getCurrentTime());
16040
17666
  }
16041
17667
  this.emitter.emit(ReplayerEvents.LoadStylesheetEnd);
16042
17668
  if (timer) {
@@ -16052,7 +17678,7 @@ class Replayer {
16052
17678
  this.emitter.emit(ReplayerEvents.LoadStylesheetStart);
16053
17679
  timer = setTimeout(() => {
16054
17680
  if (beforeLoadState.matches("playing")) {
16055
- this.play(this.getCurrentTime());
17681
+ this.playInternal(this.getCurrentTime());
16056
17682
  }
16057
17683
  timer = -1;
16058
17684
  unsubscribe();
@@ -16083,7 +17709,7 @@ class Replayer {
16083
17709
  const canvas = document.createElement("canvas");
16084
17710
  const ctx = canvas.getContext("2d");
16085
17711
  const imgd = ctx == null ? void 0 : ctx.createImageData(canvas.width, canvas.height);
16086
- ctx == null ? void 0 : ctx.putImageData(imgd, 0, 0);
17712
+ if (imgd) ctx == null ? void 0 : ctx.putImageData(imgd, 0, 0);
16087
17713
  }
16088
17714
  }
16089
17715
  async deserializeAndPreloadCanvasEvents(data, event2) {
@@ -16358,6 +17984,7 @@ class Replayer {
16358
17984
  applyMutation(d, isSync) {
16359
17985
  if (this.config.useVirtualDom && !this.usingVirtualDom && isSync) {
16360
17986
  this.usingVirtualDom = true;
17987
+ if (!this.iframe.contentDocument) return;
16361
17988
  buildFromDom(this.iframe.contentDocument, this.mirror, this.virtualDom);
16362
17989
  if (Object.keys(this.legacy_missingNodeRetryMap).length) {
16363
17990
  for (const key in this.legacy_missingNodeRetryMap) {
@@ -17848,7 +19475,7 @@ function Controller($$anchor, $$props) {
17848
19475
  let classes;
17849
19476
  var div_3 = child(div_2);
17850
19477
  var node_1 = sibling(div_3, 2);
17851
- each(node_1, 1, () => get(inactivePeriods), index$1, ($$anchor3, period) => {
19478
+ each(node_1, 1, () => get(inactivePeriods), index$2, ($$anchor3, period) => {
17852
19479
  var div_4 = root_2();
17853
19480
  template_effect(() => {
17854
19481
  set_attribute(div_4, "title", (get(period), untrack(() => get(period).name)));
@@ -17858,7 +19485,7 @@ function Controller($$anchor, $$props) {
17858
19485
  append($$anchor3, div_4);
17859
19486
  });
17860
19487
  var node_2 = sibling(node_1, 2);
17861
- each(node_2, 1, () => get(customEvents), index$1, ($$anchor3, event2) => {
19488
+ each(node_2, 1, () => get(customEvents), index$2, ($$anchor3, event2) => {
17862
19489
  var div_5 = root_3();
17863
19490
  template_effect(() => {
17864
19491
  set_attribute(div_5, "title", (get(event2), untrack(() => get(event2).name)));
@@ -17894,7 +19521,7 @@ function Controller($$anchor, $$props) {
17894
19521
  }
17895
19522
  reset(button);
17896
19523
  var node_4 = sibling(button, 2);
17897
- each(node_4, 1, speedOption, index$1, ($$anchor3, s2) => {
19524
+ each(node_4, 1, speedOption, index$2, ($$anchor3, s2) => {
17898
19525
  var button_1 = root_6();
17899
19526
  let classes_1;
17900
19527
  var text_2 = child(button_1);