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