@amplitude/rrweb-player 2.0.0-alpha.38 → 2.0.0-alpha.40

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.
@@ -5450,7 +5450,30 @@ function slimDOMExcluded(sn, slimDOMOptions) {
5450
5450
  }
5451
5451
  return false;
5452
5452
  }
5453
+ function serializeAdoptedStyleSheets(sheets, onAdoptedStyleSheet, emittedStyleIds) {
5454
+ return Array.from(sheets).map((sheet) => {
5455
+ const styleId = onAdoptedStyleSheet(sheet);
5456
+ let rules2 = [];
5457
+ if (!emittedStyleIds.has(styleId)) {
5458
+ emittedStyleIds.add(styleId);
5459
+ try {
5460
+ rules2 = Array.from(sheet.cssRules, (rule2, index2) => ({
5461
+ rule: stringifyRule(rule2, sheet.href),
5462
+ index: index2
5463
+ }));
5464
+ } catch (e2) {
5465
+ if (e2 instanceof DOMException && e2.name === "SecurityError") ;
5466
+ else {
5467
+ throw e2;
5468
+ }
5469
+ }
5470
+ }
5471
+ return { styleId, rules: rules2 };
5472
+ });
5473
+ }
5453
5474
  function serializeNodeWithId(n2, options) {
5475
+ var _a4;
5476
+ var _a22, _b22;
5454
5477
  const {
5455
5478
  doc,
5456
5479
  mirror: mirror2,
@@ -5469,6 +5492,7 @@ function serializeNodeWithId(n2, options) {
5469
5492
  inlineImages = false,
5470
5493
  recordCanvas = false,
5471
5494
  onSerialize,
5495
+ onAdoptedStyleSheet,
5472
5496
  onIframeLoad,
5473
5497
  iframeLoadTimeout = 5e3,
5474
5498
  onStylesheetLoad,
@@ -5478,6 +5502,7 @@ function serializeNodeWithId(n2, options) {
5478
5502
  cssCaptured = false,
5479
5503
  applyBackgroundColorToBlockedElements = false
5480
5504
  } = options;
5505
+ const emittedStyleIds = (_a4 = options._emittedStyleIds) != null ? _a4 : /* @__PURE__ */ new Set();
5481
5506
  let { needsMask } = options;
5482
5507
  let { preserveWhiteSpace = true } = options;
5483
5508
  if (!needsMask) {
@@ -5533,8 +5558,26 @@ function serializeNodeWithId(n2, options) {
5533
5558
  recordChild = recordChild && !serializedNode.needBlock;
5534
5559
  delete serializedNode.needBlock;
5535
5560
  const shadowRootEl = index$1.shadowRoot(n2);
5536
- if (shadowRootEl && isNativeShadowDom(shadowRootEl))
5561
+ if (shadowRootEl && isNativeShadowDom(shadowRootEl)) {
5537
5562
  serializedNode.isShadowHost = true;
5563
+ if (onAdoptedStyleSheet && ((_a22 = shadowRootEl.adoptedStyleSheets) == null ? void 0 : _a22.length)) {
5564
+ serializedNode.adoptedStyleSheets = serializeAdoptedStyleSheets(
5565
+ shadowRootEl.adoptedStyleSheets,
5566
+ onAdoptedStyleSheet,
5567
+ emittedStyleIds
5568
+ );
5569
+ }
5570
+ }
5571
+ }
5572
+ if (serializedNode.type === NodeType$3.Document && onAdoptedStyleSheet) {
5573
+ const doc2 = n2;
5574
+ if ((_b22 = doc2.adoptedStyleSheets) == null ? void 0 : _b22.length) {
5575
+ serializedNode.adoptedStyleSheets = serializeAdoptedStyleSheets(
5576
+ doc2.adoptedStyleSheets,
5577
+ onAdoptedStyleSheet,
5578
+ emittedStyleIds
5579
+ );
5580
+ }
5538
5581
  }
5539
5582
  if ((serializedNode.type === NodeType$3.Document || serializedNode.type === NodeType$3.Element) && recordChild) {
5540
5583
  if (slimDOMOptions.headWhitespace && serializedNode.type === NodeType$3.Element && serializedNode.tagName === "head") {
@@ -5560,6 +5603,8 @@ function serializeNodeWithId(n2, options) {
5560
5603
  recordCanvas,
5561
5604
  preserveWhiteSpace,
5562
5605
  onSerialize,
5606
+ onAdoptedStyleSheet,
5607
+ _emittedStyleIds: emittedStyleIds,
5563
5608
  onIframeLoad,
5564
5609
  iframeLoadTimeout,
5565
5610
  onStylesheetLoad,
@@ -5621,6 +5666,7 @@ function serializeNodeWithId(n2, options) {
5621
5666
  recordCanvas,
5622
5667
  preserveWhiteSpace,
5623
5668
  onSerialize,
5669
+ onAdoptedStyleSheet,
5624
5670
  onIframeLoad,
5625
5671
  iframeLoadTimeout,
5626
5672
  onStylesheetLoad,
@@ -5700,6 +5746,7 @@ function snapshot(n2, options) {
5700
5746
  dataURLOptions,
5701
5747
  preserveWhiteSpace,
5702
5748
  onSerialize,
5749
+ onAdoptedStyleSheet,
5703
5750
  onIframeLoad,
5704
5751
  iframeLoadTimeout,
5705
5752
  onStylesheetLoad,
@@ -5762,6 +5809,7 @@ function snapshot(n2, options) {
5762
5809
  recordCanvas,
5763
5810
  preserveWhiteSpace,
5764
5811
  onSerialize,
5812
+ onAdoptedStyleSheet,
5765
5813
  onIframeLoad,
5766
5814
  iframeLoadTimeout,
5767
5815
  onStylesheetLoad,
@@ -9826,7 +9874,8 @@ function buildNodeWithSN(n2, options) {
9826
9874
  skipChild = false,
9827
9875
  hackCss = true,
9828
9876
  afterAppend,
9829
- cache
9877
+ cache,
9878
+ scrollNodes
9830
9879
  } = options;
9831
9880
  if (mirror2.has(n2.id)) {
9832
9881
  const nodeInMirror = mirror2.getNode(n2.id);
@@ -9857,6 +9906,9 @@ function buildNodeWithSN(n2, options) {
9857
9906
  node2 = doc;
9858
9907
  }
9859
9908
  mirror2.add(node2, n2);
9909
+ if (scrollNodes && n2.type === NodeType$3.Element && n2.attributes && ("rr_scrollLeft" in n2.attributes || "rr_scrollTop" in n2.attributes)) {
9910
+ scrollNodes.push(node2);
9911
+ }
9860
9912
  if ((n2.type === NodeType$3.Document || n2.type === NodeType$3.Element) && !skipChild) {
9861
9913
  for (const childN of n2.childNodes) {
9862
9914
  const childNode = buildNodeWithSN(childN, {
@@ -9865,7 +9917,8 @@ function buildNodeWithSN(n2, options) {
9865
9917
  skipChild: false,
9866
9918
  hackCss,
9867
9919
  afterAppend,
9868
- cache
9920
+ cache,
9921
+ scrollNodes
9869
9922
  });
9870
9923
  if (!childNode) {
9871
9924
  console.warn("Failed to rebuild", childN);
@@ -9934,20 +9987,22 @@ function rebuild(n2, options) {
9934
9987
  cache,
9935
9988
  mirror: mirror2 = new Mirror()
9936
9989
  } = options;
9990
+ const scrollNodes = [];
9937
9991
  const node2 = buildNodeWithSN(n2, {
9938
9992
  doc,
9939
9993
  mirror: mirror2,
9940
9994
  skipChild: false,
9941
9995
  hackCss,
9942
9996
  afterAppend,
9943
- cache
9944
- });
9945
- visit(mirror2, (visitedNode) => {
9946
- if (onVisit) {
9947
- onVisit(visitedNode);
9948
- }
9949
- handleScroll(visitedNode, mirror2);
9997
+ cache,
9998
+ scrollNodes
9950
9999
  });
10000
+ if (onVisit) {
10001
+ visit(mirror2, onVisit);
10002
+ }
10003
+ for (const scrollNode of scrollNodes) {
10004
+ handleScroll(scrollNode, mirror2);
10005
+ }
9951
10006
  return node2;
9952
10007
  }
9953
10008
  var __defProp222 = Object.defineProperty;
@@ -15818,6 +15873,7 @@ class Timer {
15818
15873
  __publicField2(this, "timeOffset", 0);
15819
15874
  __publicField2(this, "speed");
15820
15875
  __publicField2(this, "actions");
15876
+ __publicField2(this, "actionIndex", 0);
15821
15877
  __publicField2(this, "raf", null);
15822
15878
  __publicField2(this, "lastTimestamp");
15823
15879
  this.actions = actions;
@@ -15828,7 +15884,7 @@ class Timer {
15828
15884
  */
15829
15885
  addAction(action) {
15830
15886
  const rafWasActive = this.raf === true;
15831
- if (!this.actions.length || this.actions[this.actions.length - 1].delay <= action.delay) {
15887
+ if (this.actionIndex >= this.actions.length || this.actions[this.actions.length - 1].delay <= action.delay) {
15832
15888
  this.actions.push(action);
15833
15889
  } else {
15834
15890
  const index2 = this.findActionIndex(action);
@@ -15847,16 +15903,16 @@ class Timer {
15847
15903
  const time = performance.now();
15848
15904
  this.timeOffset += (time - this.lastTimestamp) * this.speed;
15849
15905
  this.lastTimestamp = time;
15850
- while (this.actions.length) {
15851
- const action = this.actions[0];
15906
+ while (this.actionIndex < this.actions.length) {
15907
+ const action = this.actions[this.actionIndex];
15852
15908
  if (this.timeOffset >= action.delay) {
15853
- this.actions.shift();
15909
+ this.actionIndex++;
15854
15910
  action.doAction();
15855
15911
  } else {
15856
15912
  break;
15857
15913
  }
15858
15914
  }
15859
- if (this.actions.length > 0) {
15915
+ if (this.actionIndex < this.actions.length) {
15860
15916
  this.raf = requestAnimationFrame(this.rafCheck.bind(this));
15861
15917
  } else {
15862
15918
  this.raf = true;
@@ -15870,6 +15926,7 @@ class Timer {
15870
15926
  this.raf = null;
15871
15927
  }
15872
15928
  this.actions.length = 0;
15929
+ this.actionIndex = 0;
15873
15930
  }
15874
15931
  setSpeed(speed) {
15875
15932
  this.speed = speed;
@@ -15878,7 +15935,7 @@ class Timer {
15878
15935
  return this.raf !== null;
15879
15936
  }
15880
15937
  findActionIndex(action) {
15881
- let start = 0;
15938
+ let start = this.actionIndex;
15882
15939
  let end = this.actions.length - 1;
15883
15940
  while (start <= end) {
15884
15941
  const mid = Math.floor((start + end) / 2);
@@ -16047,34 +16104,44 @@ function v(t2) {
16047
16104
  } };
16048
16105
  return c2;
16049
16106
  }
16050
- function isDuplicateEvent(existing, incoming) {
16051
- if (existing === incoming) {
16052
- return true;
16053
- }
16054
- if (existing.timestamp === incoming.timestamp && existing.type === incoming.type) {
16055
- return JSON.stringify(existing) === JSON.stringify(incoming);
16107
+ function buildCheckpointIndex(events) {
16108
+ const checkpoints = [];
16109
+ for (let i2 = 0; i2 < events.length; i2++) {
16110
+ if (events[i2].type === EventType$1.Meta) {
16111
+ checkpoints.push({
16112
+ metaEventIndex: i2,
16113
+ timestamp: events[i2].timestamp
16114
+ });
16115
+ }
16056
16116
  }
16057
- return false;
16117
+ return checkpoints;
16058
16118
  }
16059
- function discardPriorSnapshots(events, baselineTime) {
16119
+ function findNearestCheckpoint(checkpoints, baselineTime) {
16120
+ if (checkpoints.length === 0) {
16121
+ return null;
16122
+ }
16060
16123
  let lo = 0;
16061
- let hi = events.length - 1;
16062
- let lastBeforeOrAt = -1;
16124
+ let hi = checkpoints.length - 1;
16125
+ let result2 = null;
16063
16126
  while (lo <= hi) {
16064
- const mid = lo + hi >>> 1;
16065
- if (events[mid].timestamp <= baselineTime) {
16066
- lastBeforeOrAt = mid;
16127
+ const mid = Math.floor((lo + hi) / 2);
16128
+ if (checkpoints[mid].timestamp <= baselineTime) {
16129
+ result2 = checkpoints[mid];
16067
16130
  lo = mid + 1;
16068
16131
  } else {
16069
16132
  hi = mid - 1;
16070
16133
  }
16071
16134
  }
16072
- for (let idx = lastBeforeOrAt; idx >= 0; idx--) {
16073
- if (events[idx].type === EventType$1.Meta) {
16074
- return events.slice(idx);
16075
- }
16135
+ return result2;
16136
+ }
16137
+ function isDuplicateEvent(existing, incoming) {
16138
+ if (existing === incoming) {
16139
+ return true;
16076
16140
  }
16077
- return events;
16141
+ if (existing.timestamp === incoming.timestamp && existing.type === incoming.type) {
16142
+ return JSON.stringify(existing) === JSON.stringify(incoming);
16143
+ }
16144
+ return false;
16078
16145
  }
16079
16146
  function createPlayerService(context, { getCastFn, applyEventsSynchronously, emitter }) {
16080
16147
  const playerMachine = s(
@@ -16160,9 +16227,19 @@ function createPlayerService(context, { getCastFn, applyEventsSynchronously, emi
16160
16227
  play(ctx) {
16161
16228
  var _a4;
16162
16229
  var _a22;
16163
- const { timer, events, baselineTime, lastPlayedEvent } = ctx;
16230
+ const {
16231
+ timer,
16232
+ events,
16233
+ baselineTime,
16234
+ lastPlayedEvent,
16235
+ checkpointIndex
16236
+ } = ctx;
16164
16237
  timer.clear();
16165
- const neededEvents = discardPriorSnapshots(events, baselineTime);
16238
+ const checkpoint = findNearestCheckpoint(
16239
+ checkpointIndex,
16240
+ baselineTime
16241
+ );
16242
+ const startIndex = checkpoint ? checkpoint.metaEventIndex : 0;
16166
16243
  let lastPlayedTimestamp = lastPlayedEvent == null ? void 0 : lastPlayedEvent.timestamp;
16167
16244
  if ((lastPlayedEvent == null ? void 0 : lastPlayedEvent.type) === EventType$1.IncrementalSnapshot && lastPlayedEvent.data.source === IncrementalSource.MouseMove) {
16168
16245
  lastPlayedTimestamp = lastPlayedEvent.timestamp + ((_a22 = lastPlayedEvent.data.positions[0]) == null ? void 0 : _a22.timeOffset);
@@ -16170,46 +16247,25 @@ function createPlayerService(context, { getCastFn, applyEventsSynchronously, emi
16170
16247
  if (baselineTime < (lastPlayedTimestamp || 0)) {
16171
16248
  emitter.emit(ReplayerEvents.PlayBack);
16172
16249
  }
16173
- let syncEnd = neededEvents.length;
16174
- {
16175
- let lo = 0;
16176
- let hi = neededEvents.length;
16177
- while (lo < hi) {
16178
- const mid = lo + hi >>> 1;
16179
- if (neededEvents[mid].timestamp < baselineTime) lo = mid + 1;
16180
- else hi = mid;
16181
- }
16182
- syncEnd = lo;
16183
- }
16184
- let syncStart = 0;
16185
- if (lastPlayedTimestamp && lastPlayedTimestamp < baselineTime) {
16186
- let lo = 0;
16187
- let hi = syncEnd;
16188
- while (lo < hi) {
16189
- const mid = lo + hi >>> 1;
16190
- if (neededEvents[mid].timestamp <= lastPlayedTimestamp)
16191
- lo = mid + 1;
16192
- else hi = mid;
16250
+ const syncEvents = new Array();
16251
+ for (let i2 = startIndex; i2 < events.length; i2++) {
16252
+ const event2 = events[i2];
16253
+ if (lastPlayedTimestamp && lastPlayedTimestamp < baselineTime && (event2.timestamp <= lastPlayedTimestamp || event2 === lastPlayedEvent)) {
16254
+ continue;
16193
16255
  }
16194
- syncStart = lo;
16195
- if (syncStart < syncEnd && neededEvents[syncStart] === lastPlayedEvent) {
16196
- syncStart++;
16256
+ if (event2.timestamp < baselineTime) {
16257
+ syncEvents.push(event2);
16258
+ } else {
16259
+ addDelay(event2, baselineTime);
16260
+ const castFn = getCastFn(event2, false);
16261
+ timer.addAction({
16262
+ doAction: () => {
16263
+ castFn();
16264
+ },
16265
+ delay: (_a4 = event2.delay) != null ? _a4 : 0
16266
+ });
16197
16267
  }
16198
16268
  }
16199
- for (let i2 = syncEnd; i2 < neededEvents.length; i2++) {
16200
- addDelay(neededEvents[i2], baselineTime);
16201
- }
16202
- const syncEvents = neededEvents.slice(syncStart, syncEnd);
16203
- for (let i2 = syncEnd; i2 < neededEvents.length; i2++) {
16204
- const event2 = neededEvents[i2];
16205
- const castFn = getCastFn(event2, false);
16206
- timer.addAction({
16207
- doAction: () => {
16208
- castFn();
16209
- },
16210
- delay: (_a4 = event2.delay) != null ? _a4 : 0
16211
- });
16212
- }
16213
16269
  applyEventsSynchronously(syncEvents);
16214
16270
  emitter.emit(ReplayerEvents.Flush);
16215
16271
  timer.start();
@@ -16233,19 +16289,21 @@ function createPlayerService(context, { getCastFn, applyEventsSynchronously, emi
16233
16289
  }),
16234
16290
  addEvent: o((ctx, machineEvent) => {
16235
16291
  var _a4;
16236
- const { baselineTime, timer, events } = ctx;
16292
+ const { baselineTime, timer, events, checkpointIndex } = ctx;
16237
16293
  if (machineEvent.type === "ADD_EVENT") {
16238
16294
  const { event: event2 } = machineEvent.payload;
16239
16295
  addDelay(event2, baselineTime);
16240
16296
  let end = events.length - 1;
16297
+ let insertionIndex;
16241
16298
  if (!events[end] || events[end].timestamp <= event2.timestamp) {
16242
16299
  if (events[end] && isDuplicateEvent(events[end], event2)) {
16243
16300
  return __spreadProps(__spreadValues({}, ctx), { events });
16244
16301
  }
16245
16302
  events.push(event2);
16303
+ insertionIndex = events.length - 1;
16246
16304
  } else {
16247
- let insertionIndex = -1;
16248
16305
  let start = 0;
16306
+ insertionIndex = 0;
16249
16307
  while (start <= end) {
16250
16308
  const mid = Math.floor((start + end) / 2);
16251
16309
  if (events[mid].timestamp <= event2.timestamp) {
@@ -16254,9 +16312,7 @@ function createPlayerService(context, { getCastFn, applyEventsSynchronously, emi
16254
16312
  end = mid - 1;
16255
16313
  }
16256
16314
  }
16257
- if (insertionIndex === -1) {
16258
- insertionIndex = start;
16259
- }
16315
+ insertionIndex = start;
16260
16316
  for (let i2 = insertionIndex - 1; i2 >= 0 && events[i2].timestamp === event2.timestamp; i2--) {
16261
16317
  if (isDuplicateEvent(events[i2], event2)) {
16262
16318
  return __spreadProps(__spreadValues({}, ctx), { events });
@@ -16269,6 +16325,39 @@ function createPlayerService(context, { getCastFn, applyEventsSynchronously, emi
16269
16325
  }
16270
16326
  events.splice(insertionIndex, 0, event2);
16271
16327
  }
16328
+ if (event2.type === EventType$1.Meta) {
16329
+ const newCheckpoint = {
16330
+ metaEventIndex: insertionIndex,
16331
+ timestamp: event2.timestamp
16332
+ };
16333
+ const lastCheckpoint = checkpointIndex[checkpointIndex.length - 1];
16334
+ if (!lastCheckpoint || lastCheckpoint.timestamp <= event2.timestamp) {
16335
+ checkpointIndex.push(newCheckpoint);
16336
+ } else {
16337
+ for (const checkpoint of checkpointIndex) {
16338
+ if (checkpoint.metaEventIndex >= insertionIndex) {
16339
+ checkpoint.metaEventIndex++;
16340
+ }
16341
+ }
16342
+ let searchLo = 0;
16343
+ let searchHi = checkpointIndex.length - 1;
16344
+ while (searchLo <= searchHi) {
16345
+ const mid = Math.floor((searchLo + searchHi) / 2);
16346
+ if (checkpointIndex[mid].timestamp <= event2.timestamp) {
16347
+ searchLo = mid + 1;
16348
+ } else {
16349
+ searchHi = mid - 1;
16350
+ }
16351
+ }
16352
+ checkpointIndex.splice(searchLo, 0, newCheckpoint);
16353
+ }
16354
+ } else if (insertionIndex < events.length - 1) {
16355
+ for (const checkpoint of checkpointIndex) {
16356
+ if (checkpoint.metaEventIndex >= insertionIndex) {
16357
+ checkpoint.metaEventIndex++;
16358
+ }
16359
+ }
16360
+ }
16272
16361
  const isSync = event2.timestamp < baselineTime;
16273
16362
  const castFn = getCastFn(event2, isSync);
16274
16363
  if (isSync) {
@@ -16282,7 +16371,7 @@ function createPlayerService(context, { getCastFn, applyEventsSynchronously, emi
16282
16371
  });
16283
16372
  }
16284
16373
  }
16285
- return __spreadProps(__spreadValues({}, ctx), { events });
16374
+ return __spreadProps(__spreadValues({}, ctx), { events, checkpointIndex });
16286
16375
  })
16287
16376
  }
16288
16377
  }
@@ -16811,6 +16900,7 @@ class Replayer {
16811
16900
  __publicField2(this, "lastSelectionData", null);
16812
16901
  __publicField2(this, "constructedStyleMutations", []);
16813
16902
  __publicField2(this, "adoptedStyleSheets", []);
16903
+ __publicField2(this, "snapshotAdoptedStyleSheetQueue", []);
16814
16904
  __publicField2(this, "handleResize", (dimension) => {
16815
16905
  this.iframe.style.display = "inherit";
16816
16906
  for (const el of [this.mouseTail, this.iframe]) {
@@ -16823,6 +16913,13 @@ class Replayer {
16823
16913
  });
16824
16914
  __publicField2(this, "applyEventsSynchronously", (events2) => {
16825
16915
  var _a22;
16916
+ let lastFullSnapshotIndex = -1;
16917
+ for (let i2 = events2.length - 1; i2 >= 0; i2--) {
16918
+ if (events2[i2].type === EventType$1.FullSnapshot) {
16919
+ lastFullSnapshotIndex = i2;
16920
+ break;
16921
+ }
16922
+ }
16826
16923
  let startIdx = 0;
16827
16924
  if (this.config.useSeekCache && events2.length > 0) {
16828
16925
  const fullSnapshotEvt = events2.find(
@@ -16868,10 +16965,14 @@ class Replayer {
16868
16965
  case EventType$1.Load:
16869
16966
  case EventType$1.Custom:
16870
16967
  continue;
16968
+ case EventType$1.IncrementalSnapshot:
16969
+ if (i2 < lastFullSnapshotIndex) {
16970
+ continue;
16971
+ }
16972
+ break;
16871
16973
  case EventType$1.FullSnapshot:
16872
16974
  case EventType$1.Meta:
16873
16975
  case EventType$1.Plugin:
16874
- case EventType$1.IncrementalSnapshot:
16875
16976
  break;
16876
16977
  }
16877
16978
  const castFn = this.getCastFn(event2, true);
@@ -17079,6 +17180,14 @@ class Replayer {
17079
17180
  this.applyAdoptedStyleSheet(data);
17080
17181
  });
17081
17182
  this.adoptedStyleSheets = [];
17183
+ this.snapshotAdoptedStyleSheetQueue.forEach(
17184
+ ({ id, adoptedStyleSheets }) => {
17185
+ const node2 = this.mirror.getNode(id);
17186
+ if (node2)
17187
+ this.applySnapshotAdoptedStyleSheets(node2, adoptedStyleSheets);
17188
+ }
17189
+ );
17190
+ this.snapshotAdoptedStyleSheetQueue = [];
17082
17191
  }
17083
17192
  if (this.mousePos) {
17084
17193
  this.moveAndHover(
@@ -17134,18 +17243,21 @@ class Replayer {
17134
17243
  const timer = new Timer([], {
17135
17244
  speed: this.config.speed
17136
17245
  });
17246
+ const sortedEvents = events.map((e2) => {
17247
+ if (config && config.unpackFn) {
17248
+ return config.unpackFn(e2);
17249
+ }
17250
+ return e2;
17251
+ }).sort((a1, a2) => a1.timestamp - a2.timestamp);
17252
+ const checkpointIndex = buildCheckpointIndex(sortedEvents);
17137
17253
  this.service = createPlayerService(
17138
17254
  {
17139
- events: events.map((e2) => {
17140
- if (config && config.unpackFn) {
17141
- return config.unpackFn(e2);
17142
- }
17143
- return e2;
17144
- }).sort((a1, a2) => a1.timestamp - a2.timestamp),
17255
+ events: sortedEvents,
17145
17256
  timer,
17146
17257
  timeOffset: 0,
17147
17258
  baselineTime: 0,
17148
- lastPlayedEvent: null
17259
+ lastPlayedEvent: null,
17260
+ checkpointIndex
17149
17261
  },
17150
17262
  {
17151
17263
  getCastFn: this.getCastFn,
@@ -17450,6 +17562,7 @@ class Replayer {
17450
17562
  const collectedIframes = [];
17451
17563
  const collectedDialogs = /* @__PURE__ */ new Set();
17452
17564
  const afterAppend = (builtNode, id) => {
17565
+ var _a22;
17453
17566
  if (builtNode.nodeName === "DIALOG")
17454
17567
  collectedDialogs.add(builtNode);
17455
17568
  this.collectIframeAndAttachDocument(collectedIframes, builtNode);
@@ -17461,6 +17574,10 @@ class Replayer {
17461
17574
  this.mirror
17462
17575
  );
17463
17576
  }
17577
+ const sn = this.mirror.getMeta(builtNode);
17578
+ if (sn && "adoptedStyleSheets" in sn && ((_a22 = sn.adoptedStyleSheets) == null ? void 0 : _a22.length)) {
17579
+ this.applySnapshotAdoptedStyleSheets(builtNode, sn.adoptedStyleSheets);
17580
+ }
17464
17581
  for (const plugin of this.config.plugins || []) {
17465
17582
  if (plugin.onBuild)
17466
17583
  plugin.onBuild(builtNode, {
@@ -17578,6 +17695,7 @@ class Replayer {
17578
17695
  const collectedIframes = [];
17579
17696
  const collectedDialogs = /* @__PURE__ */ new Set();
17580
17697
  const afterAppend = (builtNode, id) => {
17698
+ var _a22;
17581
17699
  if (builtNode.nodeName === "DIALOG")
17582
17700
  collectedDialogs.add(builtNode);
17583
17701
  this.collectIframeAndAttachDocument(collectedIframes, builtNode);
@@ -17590,6 +17708,25 @@ class Replayer {
17590
17708
  head
17591
17709
  );
17592
17710
  }
17711
+ {
17712
+ const nodeSn = mirror2.getMeta(
17713
+ builtNode
17714
+ );
17715
+ if (nodeSn && "adoptedStyleSheets" in nodeSn && ((_a22 = nodeSn.adoptedStyleSheets) == null ? void 0 : _a22.length)) {
17716
+ if (this.usingVirtualDom) {
17717
+ const id2 = mirror2.getId(builtNode);
17718
+ this.snapshotAdoptedStyleSheetQueue.push({
17719
+ id: id2,
17720
+ adoptedStyleSheets: nodeSn.adoptedStyleSheets
17721
+ });
17722
+ } else {
17723
+ this.applySnapshotAdoptedStyleSheets(
17724
+ builtNode,
17725
+ nodeSn.adoptedStyleSheets
17726
+ );
17727
+ }
17728
+ }
17729
+ }
17593
17730
  if (this.usingVirtualDom) return;
17594
17731
  for (const plugin of this.config.plugins || []) {
17595
17732
  if (plugin.onBuild)
@@ -18473,6 +18610,44 @@ class Replayer {
18473
18610
  rule2.style.removeProperty(data.remove.property);
18474
18611
  }
18475
18612
  }
18613
+ applySnapshotAdoptedStyleSheets(node2, adoptedStyleSheets) {
18614
+ var _a22;
18615
+ let hostWindow = null;
18616
+ if (hasShadowRoot(node2))
18617
+ hostWindow = ((_a22 = node2.ownerDocument) == null ? void 0 : _a22.defaultView) || null;
18618
+ else if (node2.nodeName === "#document")
18619
+ hostWindow = node2.defaultView;
18620
+ if (!hostWindow) return;
18621
+ const sheets = [];
18622
+ for (const { styleId, rules: rules2 } of adoptedStyleSheets) {
18623
+ const existing = this.styleMirror.getStyle(styleId);
18624
+ if (existing) {
18625
+ if (rules2.length) {
18626
+ this.applyStyleSheetRule(
18627
+ { source: IncrementalSource.StyleSheetRule, adds: rules2 },
18628
+ existing
18629
+ );
18630
+ }
18631
+ sheets.push(existing);
18632
+ continue;
18633
+ }
18634
+ try {
18635
+ const sheet = new hostWindow.CSSStyleSheet();
18636
+ this.styleMirror.add(sheet, styleId);
18637
+ if (rules2.length) {
18638
+ this.applyStyleSheetRule(
18639
+ { source: IncrementalSource.StyleSheetRule, adds: rules2 },
18640
+ sheet
18641
+ );
18642
+ }
18643
+ sheets.push(sheet);
18644
+ } catch (e2) {
18645
+ }
18646
+ }
18647
+ if (hasShadowRoot(node2)) node2.shadowRoot.adoptedStyleSheets = sheets;
18648
+ else if (node2.nodeName === "#document")
18649
+ node2.adoptedStyleSheets = sheets;
18650
+ }
18476
18651
  applyAdoptedStyleSheet(data) {
18477
18652
  var _a22;
18478
18653
  const targetHost = this.mirror.getNode(data.id);