@highlight-run/rrweb 2.0.0-lambda.2 → 2.0.0-lambda.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/rrweb.js CHANGED
@@ -14,6 +14,53 @@ var NodeType$3 = /* @__PURE__ */ ((NodeType2) => {
14
14
  NodeType2[NodeType2["Comment"] = 5] = "Comment";
15
15
  return NodeType2;
16
16
  })(NodeType$3 || {});
17
+ const pendingImageLoads$2 = /* @__PURE__ */ new Map();
18
+ const wrappedContexts$2 = /* @__PURE__ */ new WeakSet();
19
+ function isHTMLImageElement$2(img) {
20
+ return img !== null && typeof img === "object" && "complete" in img && "naturalWidth" in img && "naturalHeight" in img && "src" in img && "onload" in img;
21
+ }
22
+ function wrapCanvasContextDrawImage$2(ctx) {
23
+ if (wrappedContexts$2.has(ctx)) {
24
+ return;
25
+ }
26
+ wrappedContexts$2.add(ctx);
27
+ const originalDrawImage = ctx.drawImage.bind(ctx);
28
+ ctx.drawImage = function(image, ...args) {
29
+ const pending = pendingImageLoads$2.get(ctx);
30
+ if (pending) {
31
+ pending.cancelled = true;
32
+ }
33
+ const drawImageWithArgs = () => {
34
+ if (args.length === 2 && isHTMLImageElement$2(image)) {
35
+ args.push(image.naturalWidth || image.width, image.naturalHeight || image.height);
36
+ }
37
+ originalDrawImage(image, ...args);
38
+ };
39
+ if (isHTMLImageElement$2(image) && !image.complete) {
40
+ const loadState = { cancelled: false };
41
+ pendingImageLoads$2.set(ctx, loadState);
42
+ const onLoad = () => {
43
+ if (!loadState.cancelled) {
44
+ pendingImageLoads$2.delete(ctx);
45
+ drawImageWithArgs();
46
+ }
47
+ };
48
+ const onError = () => {
49
+ if (!loadState.cancelled) {
50
+ pendingImageLoads$2.delete(ctx);
51
+ try {
52
+ drawImageWithArgs();
53
+ } catch (e2) {
54
+ }
55
+ }
56
+ };
57
+ image.onload = onLoad;
58
+ image.onerror = onError;
59
+ } else {
60
+ drawImageWithArgs();
61
+ }
62
+ };
63
+ }
17
64
  const testableAccessors$1 = {
18
65
  Node: ["childNodes", "parentNode", "parentElement", "textContent"],
19
66
  ShadowRoot: ["host", "styleSheets"],
@@ -181,7 +228,8 @@ const index$1 = {
181
228
  querySelector: querySelector$1,
182
229
  querySelectorAll: querySelectorAll$1,
183
230
  mutationObserver: mutationObserverCtor$1,
184
- patch: patch$1
231
+ patch: patch$1,
232
+ wrapCanvasContextDrawImage: wrapCanvasContextDrawImage$2
185
233
  };
186
234
  function isElement(n2) {
187
235
  return n2.nodeType === n2.ELEMENT_NODE;
@@ -2236,7 +2284,7 @@ let Node$4$1 = class Node2 {
2236
2284
  let index2 = this.parent.index(this);
2237
2285
  return this.parent.nodes[index2 + 1];
2238
2286
  }
2239
- positionBy(opts) {
2287
+ positionBy(opts = {}) {
2240
2288
  let pos = this.source.start;
2241
2289
  if (opts.index) {
2242
2290
  pos = this.positionInside(opts.index);
@@ -2265,27 +2313,38 @@ let Node$4$1 = class Node2 {
2265
2313
  column += 1;
2266
2314
  }
2267
2315
  }
2268
- return { column, line };
2316
+ return { column, line, offset: end };
2269
2317
  }
2270
2318
  prev() {
2271
2319
  if (!this.parent) return void 0;
2272
2320
  let index2 = this.parent.index(this);
2273
2321
  return this.parent.nodes[index2 - 1];
2274
2322
  }
2275
- rangeBy(opts) {
2323
+ rangeBy(opts = {}) {
2324
+ let inputString = "document" in this.source.input ? this.source.input.document : this.source.input.css;
2276
2325
  let start = {
2277
2326
  column: this.source.start.column,
2278
- line: this.source.start.line
2327
+ line: this.source.start.line,
2328
+ offset: sourceOffset$1(inputString, this.source.start)
2279
2329
  };
2280
2330
  let end = this.source.end ? {
2281
2331
  column: this.source.end.column + 1,
2282
- line: this.source.end.line
2332
+ line: this.source.end.line,
2333
+ offset: typeof this.source.end.offset === "number" ? (
2334
+ // `source.end.offset` is exclusive, so we don't need to add 1
2335
+ this.source.end.offset
2336
+ ) : (
2337
+ // Since line/column in this.source.end is inclusive,
2338
+ // the `sourceOffset(... , this.source.end)` returns an inclusive offset.
2339
+ // So, we add 1 to convert it to exclusive.
2340
+ sourceOffset$1(inputString, this.source.end) + 1
2341
+ )
2283
2342
  } : {
2284
2343
  column: start.column + 1,
2285
- line: start.line
2344
+ line: start.line,
2345
+ offset: start.offset + 1
2286
2346
  };
2287
2347
  if (opts.word) {
2288
- let inputString = "document" in this.source.input ? this.source.input.document : this.source.input.css;
2289
2348
  let stringRepresentation = inputString.slice(
2290
2349
  sourceOffset$1(inputString, this.source.start),
2291
2350
  sourceOffset$1(inputString, this.source.end)
@@ -2293,15 +2352,14 @@ let Node$4$1 = class Node2 {
2293
2352
  let index2 = stringRepresentation.indexOf(opts.word);
2294
2353
  if (index2 !== -1) {
2295
2354
  start = this.positionInside(index2);
2296
- end = this.positionInside(
2297
- index2 + opts.word.length
2298
- );
2355
+ end = this.positionInside(index2 + opts.word.length);
2299
2356
  }
2300
2357
  } else {
2301
2358
  if (opts.start) {
2302
2359
  start = {
2303
2360
  column: opts.start.column,
2304
- line: opts.start.line
2361
+ line: opts.start.line,
2362
+ offset: sourceOffset$1(inputString, opts.start)
2305
2363
  };
2306
2364
  } else if (opts.index) {
2307
2365
  start = this.positionInside(opts.index);
@@ -2309,7 +2367,8 @@ let Node$4$1 = class Node2 {
2309
2367
  if (opts.end) {
2310
2368
  end = {
2311
2369
  column: opts.end.column,
2312
- line: opts.end.line
2370
+ line: opts.end.line,
2371
+ offset: sourceOffset$1(inputString, opts.end)
2313
2372
  };
2314
2373
  } else if (typeof opts.endIndex === "number") {
2315
2374
  end = this.positionInside(opts.endIndex);
@@ -2318,7 +2377,11 @@ let Node$4$1 = class Node2 {
2318
2377
  }
2319
2378
  }
2320
2379
  if (end.line < start.line || end.line === start.line && end.column <= start.column) {
2321
- end = { column: start.column + 1, line: start.line };
2380
+ end = {
2381
+ column: start.column + 1,
2382
+ line: start.line,
2383
+ offset: start.offset + 1
2384
+ };
2322
2385
  }
2323
2386
  return { end, start };
2324
2387
  }
@@ -2382,6 +2445,7 @@ let Node$4$1 = class Node2 {
2382
2445
  } else if (typeof value === "object" && value.toJSON) {
2383
2446
  fixed[name] = value.toJSON(null, inputs);
2384
2447
  } else if (name === "source") {
2448
+ if (value == null) continue;
2385
2449
  let inputId = inputs.get(value.input);
2386
2450
  if (inputId == null) {
2387
2451
  inputId = inputsNextIndex;
@@ -2416,7 +2480,7 @@ let Node$4$1 = class Node2 {
2416
2480
  });
2417
2481
  return result2;
2418
2482
  }
2419
- warn(result2, text, opts) {
2483
+ warn(result2, text, opts = {}) {
2420
2484
  let data = { node: this };
2421
2485
  for (let i2 in opts) data[i2] = opts[i2];
2422
2486
  return result2.warn(text, data);
@@ -2993,9 +3057,21 @@ let { fileURLToPath: fileURLToPath$1, pathToFileURL: pathToFileURL$1$1 } = requi
2993
3057
  let CssSyntaxError$1$1 = cssSyntaxError$1;
2994
3058
  let PreviousMap$1$1 = previousMap$1;
2995
3059
  let terminalHighlight$2 = require$$2$1;
2996
- let fromOffsetCache$1 = Symbol("fromOffsetCache");
3060
+ let lineToIndexCache$1 = Symbol("lineToIndexCache");
2997
3061
  let sourceMapAvailable$1$1 = Boolean(SourceMapConsumer$1$1 && SourceMapGenerator$1$1);
2998
3062
  let pathAvailable$1$1 = Boolean(resolve$1$1 && isAbsolute$1);
3063
+ function getLineToIndex$1(input2) {
3064
+ if (input2[lineToIndexCache$1]) return input2[lineToIndexCache$1];
3065
+ let lines = input2.css.split("\n");
3066
+ let lineToIndex = new Array(lines.length);
3067
+ let prevIndex = 0;
3068
+ for (let i2 = 0, l2 = lines.length; i2 < l2; i2++) {
3069
+ lineToIndex[i2] = prevIndex;
3070
+ prevIndex += lines[i2].length + 1;
3071
+ }
3072
+ input2[lineToIndexCache$1] = lineToIndex;
3073
+ return lineToIndex;
3074
+ }
2999
3075
  let Input$4$1 = class Input {
3000
3076
  get from() {
3001
3077
  return this.file || this.id;
@@ -3034,30 +3110,37 @@ let Input$4$1 = class Input {
3034
3110
  if (this.map) this.map.file = this.from;
3035
3111
  }
3036
3112
  error(message, line, column, opts = {}) {
3037
- let endColumn, endLine, result2;
3113
+ let endColumn, endLine, endOffset, offset, result2;
3038
3114
  if (line && typeof line === "object") {
3039
3115
  let start = line;
3040
3116
  let end = column;
3041
3117
  if (typeof start.offset === "number") {
3042
- let pos = this.fromOffset(start.offset);
3118
+ offset = start.offset;
3119
+ let pos = this.fromOffset(offset);
3043
3120
  line = pos.line;
3044
3121
  column = pos.col;
3045
3122
  } else {
3046
3123
  line = start.line;
3047
3124
  column = start.column;
3125
+ offset = this.fromLineAndColumn(line, column);
3048
3126
  }
3049
3127
  if (typeof end.offset === "number") {
3050
- let pos = this.fromOffset(end.offset);
3128
+ endOffset = end.offset;
3129
+ let pos = this.fromOffset(endOffset);
3051
3130
  endLine = pos.line;
3052
3131
  endColumn = pos.col;
3053
3132
  } else {
3054
3133
  endLine = end.line;
3055
3134
  endColumn = end.column;
3135
+ endOffset = this.fromLineAndColumn(end.line, end.column);
3056
3136
  }
3057
3137
  } else if (!column) {
3058
- let pos = this.fromOffset(line);
3138
+ offset = line;
3139
+ let pos = this.fromOffset(offset);
3059
3140
  line = pos.line;
3060
3141
  column = pos.col;
3142
+ } else {
3143
+ offset = this.fromLineAndColumn(line, column);
3061
3144
  }
3062
3145
  let origin = this.origin(line, column, endLine, endColumn);
3063
3146
  if (origin) {
@@ -3079,7 +3162,7 @@ let Input$4$1 = class Input {
3079
3162
  opts.plugin
3080
3163
  );
3081
3164
  }
3082
- result2.input = { column, endColumn, endLine, line, source: this.css };
3165
+ result2.input = { column, endColumn, endLine, endOffset, line, offset, source: this.css };
3083
3166
  if (this.file) {
3084
3167
  if (pathToFileURL$1$1) {
3085
3168
  result2.input.url = pathToFileURL$1$1(this.file).toString();
@@ -3088,21 +3171,14 @@ let Input$4$1 = class Input {
3088
3171
  }
3089
3172
  return result2;
3090
3173
  }
3174
+ fromLineAndColumn(line, column) {
3175
+ let lineToIndex = getLineToIndex$1(this);
3176
+ let index2 = lineToIndex[line - 1];
3177
+ return index2 + column - 1;
3178
+ }
3091
3179
  fromOffset(offset) {
3092
- let lastLine, lineToIndex;
3093
- if (!this[fromOffsetCache$1]) {
3094
- let lines = this.css.split("\n");
3095
- lineToIndex = new Array(lines.length);
3096
- let prevIndex = 0;
3097
- for (let i2 = 0, l2 = lines.length; i2 < l2; i2++) {
3098
- lineToIndex[i2] = prevIndex;
3099
- prevIndex += lines[i2].length + 1;
3100
- }
3101
- this[fromOffsetCache$1] = lineToIndex;
3102
- } else {
3103
- lineToIndex = this[fromOffsetCache$1];
3104
- }
3105
- lastLine = lineToIndex[lineToIndex.length - 1];
3180
+ let lineToIndex = getLineToIndex$1(this);
3181
+ let lastLine = lineToIndex[lineToIndex.length - 1];
3106
3182
  let min = 0;
3107
3183
  if (offset >= lastLine) {
3108
3184
  min = lineToIndex.length - 1;
@@ -4464,7 +4540,7 @@ let Result$3$1 = class Result {
4464
4540
  this.messages = [];
4465
4541
  this.root = root2;
4466
4542
  this.opts = opts;
4467
- this.css = void 0;
4543
+ this.css = "";
4468
4544
  this.map = void 0;
4469
4545
  }
4470
4546
  toString() {
@@ -5076,7 +5152,7 @@ let NoWorkResult2$1 = noWorkResult$1;
5076
5152
  let Root$1$1 = root$1;
5077
5153
  let Processor$1$1 = class Processor {
5078
5154
  constructor(plugins = []) {
5079
- this.version = "8.5.3";
5155
+ this.version = "8.5.6";
5080
5156
  this.plugins = this.normalize(plugins);
5081
5157
  }
5082
5158
  normalize(plugins) {
@@ -5444,13 +5520,12 @@ function buildNode(n2, options) {
5444
5520
  const value = specialAttributes[name];
5445
5521
  if (tagName === "canvas" && name === "rr_dataURL") {
5446
5522
  const image = doc.createElement("img");
5447
- image.onload = () => {
5448
- const ctx = node2.getContext("2d");
5449
- if (ctx) {
5450
- ctx.drawImage(image, 0, 0, image.width, image.height);
5451
- }
5452
- };
5453
5523
  image.src = value.toString();
5524
+ const ctx = node2.getContext("2d");
5525
+ if (ctx) {
5526
+ wrapCanvasContextDrawImage$2(ctx);
5527
+ ctx.drawImage(image, 0, 0);
5528
+ }
5454
5529
  if (node2.RRNodeType)
5455
5530
  node2.rr_dataURL = value.toString();
5456
5531
  } else if (tagName === "img" && name === "rr_dataURL") {
@@ -6319,7 +6394,7 @@ let Node$4 = class Node3 {
6319
6394
  let index2 = this.parent.index(this);
6320
6395
  return this.parent.nodes[index2 + 1];
6321
6396
  }
6322
- positionBy(opts) {
6397
+ positionBy(opts = {}) {
6323
6398
  let pos = this.source.start;
6324
6399
  if (opts.index) {
6325
6400
  pos = this.positionInside(opts.index);
@@ -6348,27 +6423,38 @@ let Node$4 = class Node3 {
6348
6423
  column += 1;
6349
6424
  }
6350
6425
  }
6351
- return { column, line };
6426
+ return { column, line, offset: end };
6352
6427
  }
6353
6428
  prev() {
6354
6429
  if (!this.parent) return void 0;
6355
6430
  let index2 = this.parent.index(this);
6356
6431
  return this.parent.nodes[index2 - 1];
6357
6432
  }
6358
- rangeBy(opts) {
6433
+ rangeBy(opts = {}) {
6434
+ let inputString = "document" in this.source.input ? this.source.input.document : this.source.input.css;
6359
6435
  let start = {
6360
6436
  column: this.source.start.column,
6361
- line: this.source.start.line
6437
+ line: this.source.start.line,
6438
+ offset: sourceOffset(inputString, this.source.start)
6362
6439
  };
6363
6440
  let end = this.source.end ? {
6364
6441
  column: this.source.end.column + 1,
6365
- line: this.source.end.line
6442
+ line: this.source.end.line,
6443
+ offset: typeof this.source.end.offset === "number" ? (
6444
+ // `source.end.offset` is exclusive, so we don't need to add 1
6445
+ this.source.end.offset
6446
+ ) : (
6447
+ // Since line/column in this.source.end is inclusive,
6448
+ // the `sourceOffset(... , this.source.end)` returns an inclusive offset.
6449
+ // So, we add 1 to convert it to exclusive.
6450
+ sourceOffset(inputString, this.source.end) + 1
6451
+ )
6366
6452
  } : {
6367
6453
  column: start.column + 1,
6368
- line: start.line
6454
+ line: start.line,
6455
+ offset: start.offset + 1
6369
6456
  };
6370
6457
  if (opts.word) {
6371
- let inputString = "document" in this.source.input ? this.source.input.document : this.source.input.css;
6372
6458
  let stringRepresentation = inputString.slice(
6373
6459
  sourceOffset(inputString, this.source.start),
6374
6460
  sourceOffset(inputString, this.source.end)
@@ -6376,15 +6462,14 @@ let Node$4 = class Node3 {
6376
6462
  let index2 = stringRepresentation.indexOf(opts.word);
6377
6463
  if (index2 !== -1) {
6378
6464
  start = this.positionInside(index2);
6379
- end = this.positionInside(
6380
- index2 + opts.word.length
6381
- );
6465
+ end = this.positionInside(index2 + opts.word.length);
6382
6466
  }
6383
6467
  } else {
6384
6468
  if (opts.start) {
6385
6469
  start = {
6386
6470
  column: opts.start.column,
6387
- line: opts.start.line
6471
+ line: opts.start.line,
6472
+ offset: sourceOffset(inputString, opts.start)
6388
6473
  };
6389
6474
  } else if (opts.index) {
6390
6475
  start = this.positionInside(opts.index);
@@ -6392,7 +6477,8 @@ let Node$4 = class Node3 {
6392
6477
  if (opts.end) {
6393
6478
  end = {
6394
6479
  column: opts.end.column,
6395
- line: opts.end.line
6480
+ line: opts.end.line,
6481
+ offset: sourceOffset(inputString, opts.end)
6396
6482
  };
6397
6483
  } else if (typeof opts.endIndex === "number") {
6398
6484
  end = this.positionInside(opts.endIndex);
@@ -6401,7 +6487,11 @@ let Node$4 = class Node3 {
6401
6487
  }
6402
6488
  }
6403
6489
  if (end.line < start.line || end.line === start.line && end.column <= start.column) {
6404
- end = { column: start.column + 1, line: start.line };
6490
+ end = {
6491
+ column: start.column + 1,
6492
+ line: start.line,
6493
+ offset: start.offset + 1
6494
+ };
6405
6495
  }
6406
6496
  return { end, start };
6407
6497
  }
@@ -6465,6 +6555,7 @@ let Node$4 = class Node3 {
6465
6555
  } else if (typeof value === "object" && value.toJSON) {
6466
6556
  fixed[name] = value.toJSON(null, inputs);
6467
6557
  } else if (name === "source") {
6558
+ if (value == null) continue;
6468
6559
  let inputId = inputs.get(value.input);
6469
6560
  if (inputId == null) {
6470
6561
  inputId = inputsNextIndex;
@@ -6499,7 +6590,7 @@ let Node$4 = class Node3 {
6499
6590
  });
6500
6591
  return result2;
6501
6592
  }
6502
- warn(result2, text, opts) {
6593
+ warn(result2, text, opts = {}) {
6503
6594
  let data = { node: this };
6504
6595
  for (let i2 in opts) data[i2] = opts[i2];
6505
6596
  return result2.warn(text, data);
@@ -7076,9 +7167,21 @@ let { fileURLToPath, pathToFileURL: pathToFileURL$1 } = require$$2;
7076
7167
  let CssSyntaxError$1 = cssSyntaxError;
7077
7168
  let PreviousMap$1 = previousMap;
7078
7169
  let terminalHighlight = require$$2;
7079
- let fromOffsetCache = Symbol("fromOffsetCache");
7170
+ let lineToIndexCache = Symbol("lineToIndexCache");
7080
7171
  let sourceMapAvailable$1 = Boolean(SourceMapConsumer$1 && SourceMapGenerator$1);
7081
7172
  let pathAvailable$1 = Boolean(resolve$1 && isAbsolute);
7173
+ function getLineToIndex(input2) {
7174
+ if (input2[lineToIndexCache]) return input2[lineToIndexCache];
7175
+ let lines = input2.css.split("\n");
7176
+ let lineToIndex = new Array(lines.length);
7177
+ let prevIndex = 0;
7178
+ for (let i2 = 0, l2 = lines.length; i2 < l2; i2++) {
7179
+ lineToIndex[i2] = prevIndex;
7180
+ prevIndex += lines[i2].length + 1;
7181
+ }
7182
+ input2[lineToIndexCache] = lineToIndex;
7183
+ return lineToIndex;
7184
+ }
7082
7185
  let Input$4 = class Input2 {
7083
7186
  get from() {
7084
7187
  return this.file || this.id;
@@ -7117,30 +7220,37 @@ let Input$4 = class Input2 {
7117
7220
  if (this.map) this.map.file = this.from;
7118
7221
  }
7119
7222
  error(message, line, column, opts = {}) {
7120
- let endColumn, endLine, result2;
7223
+ let endColumn, endLine, endOffset, offset, result2;
7121
7224
  if (line && typeof line === "object") {
7122
7225
  let start = line;
7123
7226
  let end = column;
7124
7227
  if (typeof start.offset === "number") {
7125
- let pos = this.fromOffset(start.offset);
7228
+ offset = start.offset;
7229
+ let pos = this.fromOffset(offset);
7126
7230
  line = pos.line;
7127
7231
  column = pos.col;
7128
7232
  } else {
7129
7233
  line = start.line;
7130
7234
  column = start.column;
7235
+ offset = this.fromLineAndColumn(line, column);
7131
7236
  }
7132
7237
  if (typeof end.offset === "number") {
7133
- let pos = this.fromOffset(end.offset);
7238
+ endOffset = end.offset;
7239
+ let pos = this.fromOffset(endOffset);
7134
7240
  endLine = pos.line;
7135
7241
  endColumn = pos.col;
7136
7242
  } else {
7137
7243
  endLine = end.line;
7138
7244
  endColumn = end.column;
7245
+ endOffset = this.fromLineAndColumn(end.line, end.column);
7139
7246
  }
7140
7247
  } else if (!column) {
7141
- let pos = this.fromOffset(line);
7248
+ offset = line;
7249
+ let pos = this.fromOffset(offset);
7142
7250
  line = pos.line;
7143
7251
  column = pos.col;
7252
+ } else {
7253
+ offset = this.fromLineAndColumn(line, column);
7144
7254
  }
7145
7255
  let origin = this.origin(line, column, endLine, endColumn);
7146
7256
  if (origin) {
@@ -7162,7 +7272,7 @@ let Input$4 = class Input2 {
7162
7272
  opts.plugin
7163
7273
  );
7164
7274
  }
7165
- result2.input = { column, endColumn, endLine, line, source: this.css };
7275
+ result2.input = { column, endColumn, endLine, endOffset, line, offset, source: this.css };
7166
7276
  if (this.file) {
7167
7277
  if (pathToFileURL$1) {
7168
7278
  result2.input.url = pathToFileURL$1(this.file).toString();
@@ -7171,21 +7281,14 @@ let Input$4 = class Input2 {
7171
7281
  }
7172
7282
  return result2;
7173
7283
  }
7284
+ fromLineAndColumn(line, column) {
7285
+ let lineToIndex = getLineToIndex(this);
7286
+ let index2 = lineToIndex[line - 1];
7287
+ return index2 + column - 1;
7288
+ }
7174
7289
  fromOffset(offset) {
7175
- let lastLine, lineToIndex;
7176
- if (!this[fromOffsetCache]) {
7177
- let lines = this.css.split("\n");
7178
- lineToIndex = new Array(lines.length);
7179
- let prevIndex = 0;
7180
- for (let i2 = 0, l2 = lines.length; i2 < l2; i2++) {
7181
- lineToIndex[i2] = prevIndex;
7182
- prevIndex += lines[i2].length + 1;
7183
- }
7184
- this[fromOffsetCache] = lineToIndex;
7185
- } else {
7186
- lineToIndex = this[fromOffsetCache];
7187
- }
7188
- lastLine = lineToIndex[lineToIndex.length - 1];
7290
+ let lineToIndex = getLineToIndex(this);
7291
+ let lastLine = lineToIndex[lineToIndex.length - 1];
7189
7292
  let min = 0;
7190
7293
  if (offset >= lastLine) {
7191
7294
  min = lineToIndex.length - 1;
@@ -8547,7 +8650,7 @@ let Result$3 = class Result2 {
8547
8650
  this.messages = [];
8548
8651
  this.root = root2;
8549
8652
  this.opts = opts;
8550
- this.css = void 0;
8653
+ this.css = "";
8551
8654
  this.map = void 0;
8552
8655
  }
8553
8656
  toString() {
@@ -9159,7 +9262,7 @@ let NoWorkResult22 = noWorkResult;
9159
9262
  let Root$1 = root;
9160
9263
  let Processor$1 = class Processor2 {
9161
9264
  constructor(plugins = []) {
9162
- this.version = "8.5.3";
9265
+ this.version = "8.5.6";
9163
9266
  this.plugins = this.normalize(plugins);
9164
9267
  }
9165
9268
  normalize(plugins) {
@@ -9843,6 +9946,53 @@ var NodeType$2 = /* @__PURE__ */ ((NodeType2) => {
9843
9946
  NodeType2[NodeType2["DOCUMENT_FRAGMENT_NODE"] = 11] = "DOCUMENT_FRAGMENT_NODE";
9844
9947
  return NodeType2;
9845
9948
  })(NodeType$2 || {});
9949
+ const pendingImageLoads$1 = /* @__PURE__ */ new Map();
9950
+ const wrappedContexts$1 = /* @__PURE__ */ new WeakSet();
9951
+ function isHTMLImageElement$1(img) {
9952
+ return img !== null && typeof img === "object" && "complete" in img && "naturalWidth" in img && "naturalHeight" in img && "src" in img && "onload" in img;
9953
+ }
9954
+ function wrapCanvasContextDrawImage$1(ctx) {
9955
+ if (wrappedContexts$1.has(ctx)) {
9956
+ return;
9957
+ }
9958
+ wrappedContexts$1.add(ctx);
9959
+ const originalDrawImage = ctx.drawImage.bind(ctx);
9960
+ ctx.drawImage = function(image, ...args) {
9961
+ const pending = pendingImageLoads$1.get(ctx);
9962
+ if (pending) {
9963
+ pending.cancelled = true;
9964
+ }
9965
+ const drawImageWithArgs = () => {
9966
+ if (args.length === 2 && isHTMLImageElement$1(image)) {
9967
+ args.push(image.naturalWidth || image.width, image.naturalHeight || image.height);
9968
+ }
9969
+ originalDrawImage(image, ...args);
9970
+ };
9971
+ if (isHTMLImageElement$1(image) && !image.complete) {
9972
+ const loadState = { cancelled: false };
9973
+ pendingImageLoads$1.set(ctx, loadState);
9974
+ const onLoad = () => {
9975
+ if (!loadState.cancelled) {
9976
+ pendingImageLoads$1.delete(ctx);
9977
+ drawImageWithArgs();
9978
+ }
9979
+ };
9980
+ const onError = () => {
9981
+ if (!loadState.cancelled) {
9982
+ pendingImageLoads$1.delete(ctx);
9983
+ try {
9984
+ drawImageWithArgs();
9985
+ } catch (e2) {
9986
+ }
9987
+ }
9988
+ };
9989
+ image.onload = onLoad;
9990
+ image.onerror = onError;
9991
+ } else {
9992
+ drawImageWithArgs();
9993
+ }
9994
+ };
9995
+ }
9846
9996
  const NAMESPACES = {
9847
9997
  svg: "http://www.w3.org/2000/svg",
9848
9998
  "xlink:href": "http://www.w3.org/1999/xlink",
@@ -9996,13 +10146,12 @@ function diffAfterUpdatingChildren(oldTree, newTree, replayer) {
9996
10146
  const rrCanvasElement = newTree;
9997
10147
  if (rrCanvasElement.rr_dataURL !== null) {
9998
10148
  const image = document.createElement("img");
9999
- image.onload = () => {
10000
- const ctx = oldElement.getContext("2d");
10001
- if (ctx) {
10002
- ctx.drawImage(image, 0, 0, image.width, image.height);
10003
- }
10004
- };
10005
10149
  image.src = rrCanvasElement.rr_dataURL;
10150
+ const ctx = oldElement.getContext("2d");
10151
+ if (ctx) {
10152
+ wrapCanvasContextDrawImage$1(ctx);
10153
+ ctx.drawImage(image, 0, 0);
10154
+ }
10006
10155
  }
10007
10156
  rrCanvasElement.canvasMutations.forEach(
10008
10157
  (canvasMutation2) => replayer.applyCanvas(
@@ -10067,12 +10216,11 @@ function diffProps(oldTree, newTree, rrnodeMirror) {
10067
10216
  else if (newTree.tagName === "CANVAS" && name === "rr_dataURL") {
10068
10217
  const image = document.createElement("img");
10069
10218
  image.src = newValue;
10070
- image.onload = () => {
10071
- const ctx = oldTree.getContext("2d");
10072
- if (ctx) {
10073
- ctx.drawImage(image, 0, 0, image.width, image.height);
10074
- }
10075
- };
10219
+ const ctx = oldTree.getContext("2d");
10220
+ if (ctx) {
10221
+ wrapCanvasContextDrawImage$1(ctx);
10222
+ ctx.drawImage(image, 0, 0);
10223
+ }
10076
10224
  } else if (newTree.tagName === "IFRAME" && name === "srcdoc") continue;
10077
10225
  else {
10078
10226
  try {
@@ -10583,6 +10731,53 @@ function getDefaultSN(node2, id) {
10583
10731
  };
10584
10732
  }
10585
10733
  }
10734
+ const pendingImageLoads = /* @__PURE__ */ new Map();
10735
+ const wrappedContexts = /* @__PURE__ */ new WeakSet();
10736
+ function isHTMLImageElement(img) {
10737
+ return img !== null && typeof img === "object" && "complete" in img && "naturalWidth" in img && "naturalHeight" in img && "src" in img && "onload" in img;
10738
+ }
10739
+ function wrapCanvasContextDrawImage(ctx) {
10740
+ if (wrappedContexts.has(ctx)) {
10741
+ return;
10742
+ }
10743
+ wrappedContexts.add(ctx);
10744
+ const originalDrawImage = ctx.drawImage.bind(ctx);
10745
+ ctx.drawImage = function(image, ...args) {
10746
+ const pending = pendingImageLoads.get(ctx);
10747
+ if (pending) {
10748
+ pending.cancelled = true;
10749
+ }
10750
+ const drawImageWithArgs = () => {
10751
+ if (args.length === 2 && isHTMLImageElement(image)) {
10752
+ args.push(image.naturalWidth || image.width, image.naturalHeight || image.height);
10753
+ }
10754
+ originalDrawImage(image, ...args);
10755
+ };
10756
+ if (isHTMLImageElement(image) && !image.complete) {
10757
+ const loadState = { cancelled: false };
10758
+ pendingImageLoads.set(ctx, loadState);
10759
+ const onLoad = () => {
10760
+ if (!loadState.cancelled) {
10761
+ pendingImageLoads.delete(ctx);
10762
+ drawImageWithArgs();
10763
+ }
10764
+ };
10765
+ const onError = () => {
10766
+ if (!loadState.cancelled) {
10767
+ pendingImageLoads.delete(ctx);
10768
+ try {
10769
+ drawImageWithArgs();
10770
+ } catch (e2) {
10771
+ }
10772
+ }
10773
+ };
10774
+ image.onload = onLoad;
10775
+ image.onerror = onError;
10776
+ } else {
10777
+ drawImageWithArgs();
10778
+ }
10779
+ };
10780
+ }
10586
10781
  const testableAccessors = {
10587
10782
  Node: ["childNodes", "parentNode", "parentElement", "textContent"],
10588
10783
  ShadowRoot: ["host", "styleSheets"],
@@ -10750,7 +10945,8 @@ const index = {
10750
10945
  querySelector,
10751
10946
  querySelectorAll,
10752
10947
  mutationObserver: mutationObserverCtor,
10753
- patch
10948
+ patch,
10949
+ wrapCanvasContextDrawImage
10754
10950
  };
10755
10951
  function on(type, fn, target = document) {
10756
10952
  const options = { capture: true };
@@ -15007,8 +15203,12 @@ class Timer {
15007
15203
  this.actions = this.actions.concat(actions);
15008
15204
  }
15009
15205
  replaceActions(actions) {
15206
+ const rafWasActive = this.raf === true;
15010
15207
  this.actions.length = 0;
15011
- this.actions.splice(0, 0, ...actions);
15208
+ this.actions = [...actions];
15209
+ if (rafWasActive) {
15210
+ this.raf = requestAnimationFrame(this.rafCheck.bind(this));
15211
+ }
15012
15212
  }
15013
15213
  /* End Highlight Code */
15014
15214
  start() {
@@ -15377,28 +15577,26 @@ function createPlayerService(context, { getCastFn, applyEventsSynchronously, emi
15377
15577
  }),
15378
15578
  /* Highlight Code Start */
15379
15579
  replaceEvents: o((ctx, machineEvent) => {
15580
+ if (machineEvent.type !== "REPLACE_EVENTS") return ctx;
15380
15581
  const { events: curEvents, timer, baselineTime } = ctx;
15381
- if (machineEvent.type === "REPLACE_EVENTS") {
15382
- const { events: newEvents } = machineEvent.payload;
15383
- curEvents.length = 0;
15384
- const actions = [];
15385
- for (const event of newEvents) {
15386
- addDelay(event, baselineTime);
15387
- curEvents.push(event);
15388
- if (event.timestamp >= timer.timeOffset + baselineTime) {
15389
- const castFn = getCastFn(event, false);
15390
- actions.push({
15391
- doAction: () => {
15392
- castFn();
15393
- },
15394
- delay: event.delay
15395
- });
15396
- }
15397
- }
15398
- if (timer.isActive()) {
15399
- timer.replaceActions(actions);
15582
+ const { events: newEvents } = machineEvent.payload;
15583
+ if (newEvents.length === 0) return ctx;
15584
+ curEvents.length = 0;
15585
+ const actions = [];
15586
+ const timeThreshold = timer.timeOffset + baselineTime;
15587
+ for (const event of newEvents) {
15588
+ addDelay(event, baselineTime);
15589
+ curEvents.push(event);
15590
+ if (event.timestamp >= timeThreshold) {
15591
+ actions.push({
15592
+ doAction: getCastFn(event, false),
15593
+ delay: event.delay
15594
+ });
15400
15595
  }
15401
15596
  }
15597
+ if (timer.isActive()) {
15598
+ timer.replaceActions(actions);
15599
+ }
15402
15600
  return { ...ctx, events: curEvents };
15403
15601
  }),
15404
15602
  /* Highlight Code End */
@@ -15630,6 +15828,7 @@ async function canvasMutation$1({
15630
15828
  errorHandler2(mutations[0], new Error("Canvas context is null"));
15631
15829
  return;
15632
15830
  }
15831
+ wrapCanvasContextDrawImage(ctx);
15633
15832
  const mutationArgsPromises = mutations.map(
15634
15833
  async (mutation) => {
15635
15834
  return Promise.all(mutation.args.map(deserializeArg(imageMap, ctx)));