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