@highlight-run/rrweb 2.0.0-lambda.3 → 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.
@@ -60,6 +60,53 @@ var NodeType$3 = /* @__PURE__ */ ((NodeType2) => {
60
60
  NodeType2[NodeType2["Comment"] = 5] = "Comment";
61
61
  return NodeType2;
62
62
  })(NodeType$3 || {});
63
+ const pendingImageLoads$2 = /* @__PURE__ */ new Map();
64
+ const wrappedContexts$2 = /* @__PURE__ */ new WeakSet();
65
+ function isHTMLImageElement$2(img) {
66
+ return img !== null && typeof img === "object" && "complete" in img && "naturalWidth" in img && "naturalHeight" in img && "src" in img && "onload" in img;
67
+ }
68
+ function wrapCanvasContextDrawImage$2(ctx) {
69
+ if (wrappedContexts$2.has(ctx)) {
70
+ return;
71
+ }
72
+ wrappedContexts$2.add(ctx);
73
+ const originalDrawImage = ctx.drawImage.bind(ctx);
74
+ ctx.drawImage = function(image, ...args) {
75
+ const pending = pendingImageLoads$2.get(ctx);
76
+ if (pending) {
77
+ pending.cancelled = true;
78
+ }
79
+ const drawImageWithArgs = () => {
80
+ if (args.length === 2 && isHTMLImageElement$2(image)) {
81
+ args.push(image.naturalWidth || image.width, image.naturalHeight || image.height);
82
+ }
83
+ originalDrawImage(image, ...args);
84
+ };
85
+ if (isHTMLImageElement$2(image) && !image.complete) {
86
+ const loadState = { cancelled: false };
87
+ pendingImageLoads$2.set(ctx, loadState);
88
+ const onLoad = () => {
89
+ if (!loadState.cancelled) {
90
+ pendingImageLoads$2.delete(ctx);
91
+ drawImageWithArgs();
92
+ }
93
+ };
94
+ const onError = () => {
95
+ if (!loadState.cancelled) {
96
+ pendingImageLoads$2.delete(ctx);
97
+ try {
98
+ drawImageWithArgs();
99
+ } catch (e2) {
100
+ }
101
+ }
102
+ };
103
+ image.onload = onLoad;
104
+ image.onerror = onError;
105
+ } else {
106
+ drawImageWithArgs();
107
+ }
108
+ };
109
+ }
63
110
  const testableAccessors$1 = {
64
111
  Node: ["childNodes", "parentNode", "parentElement", "textContent"],
65
112
  ShadowRoot: ["host", "styleSheets"],
@@ -227,7 +274,8 @@ const index$1 = {
227
274
  querySelector: querySelector$1,
228
275
  querySelectorAll: querySelectorAll$1,
229
276
  mutationObserver: mutationObserverCtor$1,
230
- patch: patch$1
277
+ patch: patch$1,
278
+ wrapCanvasContextDrawImage: wrapCanvasContextDrawImage$2
231
279
  };
232
280
  function isElement(n2) {
233
281
  return n2.nodeType === n2.ELEMENT_NODE;
@@ -2283,7 +2331,7 @@ let Node$4$1 = class Node2 {
2283
2331
  let index2 = this.parent.index(this);
2284
2332
  return this.parent.nodes[index2 + 1];
2285
2333
  }
2286
- positionBy(opts) {
2334
+ positionBy(opts = {}) {
2287
2335
  let pos = this.source.start;
2288
2336
  if (opts.index) {
2289
2337
  pos = this.positionInside(opts.index);
@@ -2312,27 +2360,38 @@ let Node$4$1 = class Node2 {
2312
2360
  column += 1;
2313
2361
  }
2314
2362
  }
2315
- return { column, line };
2363
+ return { column, line, offset: end };
2316
2364
  }
2317
2365
  prev() {
2318
2366
  if (!this.parent) return void 0;
2319
2367
  let index2 = this.parent.index(this);
2320
2368
  return this.parent.nodes[index2 - 1];
2321
2369
  }
2322
- rangeBy(opts) {
2370
+ rangeBy(opts = {}) {
2371
+ let inputString = "document" in this.source.input ? this.source.input.document : this.source.input.css;
2323
2372
  let start = {
2324
2373
  column: this.source.start.column,
2325
- line: this.source.start.line
2374
+ line: this.source.start.line,
2375
+ offset: sourceOffset$1(inputString, this.source.start)
2326
2376
  };
2327
2377
  let end = this.source.end ? {
2328
2378
  column: this.source.end.column + 1,
2329
- line: this.source.end.line
2379
+ line: this.source.end.line,
2380
+ offset: typeof this.source.end.offset === "number" ? (
2381
+ // `source.end.offset` is exclusive, so we don't need to add 1
2382
+ this.source.end.offset
2383
+ ) : (
2384
+ // Since line/column in this.source.end is inclusive,
2385
+ // the `sourceOffset(... , this.source.end)` returns an inclusive offset.
2386
+ // So, we add 1 to convert it to exclusive.
2387
+ sourceOffset$1(inputString, this.source.end) + 1
2388
+ )
2330
2389
  } : {
2331
2390
  column: start.column + 1,
2332
- line: start.line
2391
+ line: start.line,
2392
+ offset: start.offset + 1
2333
2393
  };
2334
2394
  if (opts.word) {
2335
- let inputString = "document" in this.source.input ? this.source.input.document : this.source.input.css;
2336
2395
  let stringRepresentation = inputString.slice(
2337
2396
  sourceOffset$1(inputString, this.source.start),
2338
2397
  sourceOffset$1(inputString, this.source.end)
@@ -2340,15 +2399,14 @@ let Node$4$1 = class Node2 {
2340
2399
  let index2 = stringRepresentation.indexOf(opts.word);
2341
2400
  if (index2 !== -1) {
2342
2401
  start = this.positionInside(index2);
2343
- end = this.positionInside(
2344
- index2 + opts.word.length
2345
- );
2402
+ end = this.positionInside(index2 + opts.word.length);
2346
2403
  }
2347
2404
  } else {
2348
2405
  if (opts.start) {
2349
2406
  start = {
2350
2407
  column: opts.start.column,
2351
- line: opts.start.line
2408
+ line: opts.start.line,
2409
+ offset: sourceOffset$1(inputString, opts.start)
2352
2410
  };
2353
2411
  } else if (opts.index) {
2354
2412
  start = this.positionInside(opts.index);
@@ -2356,7 +2414,8 @@ let Node$4$1 = class Node2 {
2356
2414
  if (opts.end) {
2357
2415
  end = {
2358
2416
  column: opts.end.column,
2359
- line: opts.end.line
2417
+ line: opts.end.line,
2418
+ offset: sourceOffset$1(inputString, opts.end)
2360
2419
  };
2361
2420
  } else if (typeof opts.endIndex === "number") {
2362
2421
  end = this.positionInside(opts.endIndex);
@@ -2365,7 +2424,11 @@ let Node$4$1 = class Node2 {
2365
2424
  }
2366
2425
  }
2367
2426
  if (end.line < start.line || end.line === start.line && end.column <= start.column) {
2368
- end = { column: start.column + 1, line: start.line };
2427
+ end = {
2428
+ column: start.column + 1,
2429
+ line: start.line,
2430
+ offset: start.offset + 1
2431
+ };
2369
2432
  }
2370
2433
  return { end, start };
2371
2434
  }
@@ -2429,6 +2492,7 @@ let Node$4$1 = class Node2 {
2429
2492
  } else if (typeof value === "object" && value.toJSON) {
2430
2493
  fixed[name] = value.toJSON(null, inputs);
2431
2494
  } else if (name === "source") {
2495
+ if (value == null) continue;
2432
2496
  let inputId = inputs.get(value.input);
2433
2497
  if (inputId == null) {
2434
2498
  inputId = inputsNextIndex;
@@ -2463,7 +2527,7 @@ let Node$4$1 = class Node2 {
2463
2527
  });
2464
2528
  return result2;
2465
2529
  }
2466
- warn(result2, text, opts) {
2530
+ warn(result2, text, opts = {}) {
2467
2531
  let data = { node: this };
2468
2532
  for (let i2 in opts) data[i2] = opts[i2];
2469
2533
  return result2.warn(text, data);
@@ -3044,9 +3108,21 @@ let { fileURLToPath: fileURLToPath$1, pathToFileURL: pathToFileURL$1$1 } = requi
3044
3108
  let CssSyntaxError$1$1 = cssSyntaxError$1;
3045
3109
  let PreviousMap$1$1 = previousMap$1;
3046
3110
  let terminalHighlight$2 = require$$2$1;
3047
- let fromOffsetCache$1 = Symbol("fromOffsetCache");
3111
+ let lineToIndexCache$1 = Symbol("lineToIndexCache");
3048
3112
  let sourceMapAvailable$1$1 = Boolean(SourceMapConsumer$1$1 && SourceMapGenerator$1$1);
3049
3113
  let pathAvailable$1$1 = Boolean(resolve$1$1 && isAbsolute$1);
3114
+ function getLineToIndex$1(input2) {
3115
+ if (input2[lineToIndexCache$1]) return input2[lineToIndexCache$1];
3116
+ let lines = input2.css.split("\n");
3117
+ let lineToIndex = new Array(lines.length);
3118
+ let prevIndex = 0;
3119
+ for (let i2 = 0, l2 = lines.length; i2 < l2; i2++) {
3120
+ lineToIndex[i2] = prevIndex;
3121
+ prevIndex += lines[i2].length + 1;
3122
+ }
3123
+ input2[lineToIndexCache$1] = lineToIndex;
3124
+ return lineToIndex;
3125
+ }
3050
3126
  let Input$4$1 = class Input {
3051
3127
  get from() {
3052
3128
  return this.file || this.id;
@@ -3085,30 +3161,37 @@ let Input$4$1 = class Input {
3085
3161
  if (this.map) this.map.file = this.from;
3086
3162
  }
3087
3163
  error(message, line, column, opts = {}) {
3088
- let endColumn, endLine, result2;
3164
+ let endColumn, endLine, endOffset, offset, result2;
3089
3165
  if (line && typeof line === "object") {
3090
3166
  let start = line;
3091
3167
  let end = column;
3092
3168
  if (typeof start.offset === "number") {
3093
- let pos = this.fromOffset(start.offset);
3169
+ offset = start.offset;
3170
+ let pos = this.fromOffset(offset);
3094
3171
  line = pos.line;
3095
3172
  column = pos.col;
3096
3173
  } else {
3097
3174
  line = start.line;
3098
3175
  column = start.column;
3176
+ offset = this.fromLineAndColumn(line, column);
3099
3177
  }
3100
3178
  if (typeof end.offset === "number") {
3101
- let pos = this.fromOffset(end.offset);
3179
+ endOffset = end.offset;
3180
+ let pos = this.fromOffset(endOffset);
3102
3181
  endLine = pos.line;
3103
3182
  endColumn = pos.col;
3104
3183
  } else {
3105
3184
  endLine = end.line;
3106
3185
  endColumn = end.column;
3186
+ endOffset = this.fromLineAndColumn(end.line, end.column);
3107
3187
  }
3108
3188
  } else if (!column) {
3109
- let pos = this.fromOffset(line);
3189
+ offset = line;
3190
+ let pos = this.fromOffset(offset);
3110
3191
  line = pos.line;
3111
3192
  column = pos.col;
3193
+ } else {
3194
+ offset = this.fromLineAndColumn(line, column);
3112
3195
  }
3113
3196
  let origin = this.origin(line, column, endLine, endColumn);
3114
3197
  if (origin) {
@@ -3130,7 +3213,7 @@ let Input$4$1 = class Input {
3130
3213
  opts.plugin
3131
3214
  );
3132
3215
  }
3133
- result2.input = { column, endColumn, endLine, line, source: this.css };
3216
+ result2.input = { column, endColumn, endLine, endOffset, line, offset, source: this.css };
3134
3217
  if (this.file) {
3135
3218
  if (pathToFileURL$1$1) {
3136
3219
  result2.input.url = pathToFileURL$1$1(this.file).toString();
@@ -3139,21 +3222,14 @@ let Input$4$1 = class Input {
3139
3222
  }
3140
3223
  return result2;
3141
3224
  }
3225
+ fromLineAndColumn(line, column) {
3226
+ let lineToIndex = getLineToIndex$1(this);
3227
+ let index2 = lineToIndex[line - 1];
3228
+ return index2 + column - 1;
3229
+ }
3142
3230
  fromOffset(offset) {
3143
- let lastLine, lineToIndex;
3144
- if (!this[fromOffsetCache$1]) {
3145
- let lines = this.css.split("\n");
3146
- lineToIndex = new Array(lines.length);
3147
- let prevIndex = 0;
3148
- for (let i2 = 0, l2 = lines.length; i2 < l2; i2++) {
3149
- lineToIndex[i2] = prevIndex;
3150
- prevIndex += lines[i2].length + 1;
3151
- }
3152
- this[fromOffsetCache$1] = lineToIndex;
3153
- } else {
3154
- lineToIndex = this[fromOffsetCache$1];
3155
- }
3156
- lastLine = lineToIndex[lineToIndex.length - 1];
3231
+ let lineToIndex = getLineToIndex$1(this);
3232
+ let lastLine = lineToIndex[lineToIndex.length - 1];
3157
3233
  let min = 0;
3158
3234
  if (offset >= lastLine) {
3159
3235
  min = lineToIndex.length - 1;
@@ -4515,7 +4591,7 @@ let Result$3$1 = class Result {
4515
4591
  this.messages = [];
4516
4592
  this.root = root2;
4517
4593
  this.opts = opts;
4518
- this.css = void 0;
4594
+ this.css = "";
4519
4595
  this.map = void 0;
4520
4596
  }
4521
4597
  toString() {
@@ -5127,7 +5203,7 @@ let NoWorkResult2$1 = noWorkResult$1;
5127
5203
  let Root$1$1 = root$1;
5128
5204
  let Processor$1$1 = class Processor {
5129
5205
  constructor(plugins = []) {
5130
- this.version = "8.5.3";
5206
+ this.version = "8.5.6";
5131
5207
  this.plugins = this.normalize(plugins);
5132
5208
  }
5133
5209
  normalize(plugins) {
@@ -5495,13 +5571,12 @@ function buildNode(n2, options) {
5495
5571
  const value = specialAttributes[name];
5496
5572
  if (tagName === "canvas" && name === "rr_dataURL") {
5497
5573
  const image = doc.createElement("img");
5498
- image.onload = () => {
5499
- const ctx = node2.getContext("2d");
5500
- if (ctx) {
5501
- ctx.drawImage(image, 0, 0, image.width, image.height);
5502
- }
5503
- };
5504
5574
  image.src = value.toString();
5575
+ const ctx = node2.getContext("2d");
5576
+ if (ctx) {
5577
+ wrapCanvasContextDrawImage$2(ctx);
5578
+ ctx.drawImage(image, 0, 0);
5579
+ }
5505
5580
  if (node2.RRNodeType)
5506
5581
  node2.rr_dataURL = value.toString();
5507
5582
  } else if (tagName === "img" && name === "rr_dataURL") {
@@ -6370,7 +6445,7 @@ let Node$4 = class Node3 {
6370
6445
  let index2 = this.parent.index(this);
6371
6446
  return this.parent.nodes[index2 + 1];
6372
6447
  }
6373
- positionBy(opts) {
6448
+ positionBy(opts = {}) {
6374
6449
  let pos = this.source.start;
6375
6450
  if (opts.index) {
6376
6451
  pos = this.positionInside(opts.index);
@@ -6399,27 +6474,38 @@ let Node$4 = class Node3 {
6399
6474
  column += 1;
6400
6475
  }
6401
6476
  }
6402
- return { column, line };
6477
+ return { column, line, offset: end };
6403
6478
  }
6404
6479
  prev() {
6405
6480
  if (!this.parent) return void 0;
6406
6481
  let index2 = this.parent.index(this);
6407
6482
  return this.parent.nodes[index2 - 1];
6408
6483
  }
6409
- rangeBy(opts) {
6484
+ rangeBy(opts = {}) {
6485
+ let inputString = "document" in this.source.input ? this.source.input.document : this.source.input.css;
6410
6486
  let start = {
6411
6487
  column: this.source.start.column,
6412
- line: this.source.start.line
6488
+ line: this.source.start.line,
6489
+ offset: sourceOffset(inputString, this.source.start)
6413
6490
  };
6414
6491
  let end = this.source.end ? {
6415
6492
  column: this.source.end.column + 1,
6416
- line: this.source.end.line
6493
+ line: this.source.end.line,
6494
+ offset: typeof this.source.end.offset === "number" ? (
6495
+ // `source.end.offset` is exclusive, so we don't need to add 1
6496
+ this.source.end.offset
6497
+ ) : (
6498
+ // Since line/column in this.source.end is inclusive,
6499
+ // the `sourceOffset(... , this.source.end)` returns an inclusive offset.
6500
+ // So, we add 1 to convert it to exclusive.
6501
+ sourceOffset(inputString, this.source.end) + 1
6502
+ )
6417
6503
  } : {
6418
6504
  column: start.column + 1,
6419
- line: start.line
6505
+ line: start.line,
6506
+ offset: start.offset + 1
6420
6507
  };
6421
6508
  if (opts.word) {
6422
- let inputString = "document" in this.source.input ? this.source.input.document : this.source.input.css;
6423
6509
  let stringRepresentation = inputString.slice(
6424
6510
  sourceOffset(inputString, this.source.start),
6425
6511
  sourceOffset(inputString, this.source.end)
@@ -6427,15 +6513,14 @@ let Node$4 = class Node3 {
6427
6513
  let index2 = stringRepresentation.indexOf(opts.word);
6428
6514
  if (index2 !== -1) {
6429
6515
  start = this.positionInside(index2);
6430
- end = this.positionInside(
6431
- index2 + opts.word.length
6432
- );
6516
+ end = this.positionInside(index2 + opts.word.length);
6433
6517
  }
6434
6518
  } else {
6435
6519
  if (opts.start) {
6436
6520
  start = {
6437
6521
  column: opts.start.column,
6438
- line: opts.start.line
6522
+ line: opts.start.line,
6523
+ offset: sourceOffset(inputString, opts.start)
6439
6524
  };
6440
6525
  } else if (opts.index) {
6441
6526
  start = this.positionInside(opts.index);
@@ -6443,7 +6528,8 @@ let Node$4 = class Node3 {
6443
6528
  if (opts.end) {
6444
6529
  end = {
6445
6530
  column: opts.end.column,
6446
- line: opts.end.line
6531
+ line: opts.end.line,
6532
+ offset: sourceOffset(inputString, opts.end)
6447
6533
  };
6448
6534
  } else if (typeof opts.endIndex === "number") {
6449
6535
  end = this.positionInside(opts.endIndex);
@@ -6452,7 +6538,11 @@ let Node$4 = class Node3 {
6452
6538
  }
6453
6539
  }
6454
6540
  if (end.line < start.line || end.line === start.line && end.column <= start.column) {
6455
- end = { column: start.column + 1, line: start.line };
6541
+ end = {
6542
+ column: start.column + 1,
6543
+ line: start.line,
6544
+ offset: start.offset + 1
6545
+ };
6456
6546
  }
6457
6547
  return { end, start };
6458
6548
  }
@@ -6516,6 +6606,7 @@ let Node$4 = class Node3 {
6516
6606
  } else if (typeof value === "object" && value.toJSON) {
6517
6607
  fixed[name] = value.toJSON(null, inputs);
6518
6608
  } else if (name === "source") {
6609
+ if (value == null) continue;
6519
6610
  let inputId = inputs.get(value.input);
6520
6611
  if (inputId == null) {
6521
6612
  inputId = inputsNextIndex;
@@ -6550,7 +6641,7 @@ let Node$4 = class Node3 {
6550
6641
  });
6551
6642
  return result2;
6552
6643
  }
6553
- warn(result2, text, opts) {
6644
+ warn(result2, text, opts = {}) {
6554
6645
  let data = { node: this };
6555
6646
  for (let i2 in opts) data[i2] = opts[i2];
6556
6647
  return result2.warn(text, data);
@@ -7131,9 +7222,21 @@ let { fileURLToPath, pathToFileURL: pathToFileURL$1 } = require$$2;
7131
7222
  let CssSyntaxError$1 = cssSyntaxError;
7132
7223
  let PreviousMap$1 = previousMap;
7133
7224
  let terminalHighlight = require$$2;
7134
- let fromOffsetCache = Symbol("fromOffsetCache");
7225
+ let lineToIndexCache = Symbol("lineToIndexCache");
7135
7226
  let sourceMapAvailable$1 = Boolean(SourceMapConsumer$1 && SourceMapGenerator$1);
7136
7227
  let pathAvailable$1 = Boolean(resolve$1 && isAbsolute);
7228
+ function getLineToIndex(input2) {
7229
+ if (input2[lineToIndexCache]) return input2[lineToIndexCache];
7230
+ let lines = input2.css.split("\n");
7231
+ let lineToIndex = new Array(lines.length);
7232
+ let prevIndex = 0;
7233
+ for (let i2 = 0, l2 = lines.length; i2 < l2; i2++) {
7234
+ lineToIndex[i2] = prevIndex;
7235
+ prevIndex += lines[i2].length + 1;
7236
+ }
7237
+ input2[lineToIndexCache] = lineToIndex;
7238
+ return lineToIndex;
7239
+ }
7137
7240
  let Input$4 = class Input2 {
7138
7241
  get from() {
7139
7242
  return this.file || this.id;
@@ -7172,30 +7275,37 @@ let Input$4 = class Input2 {
7172
7275
  if (this.map) this.map.file = this.from;
7173
7276
  }
7174
7277
  error(message, line, column, opts = {}) {
7175
- let endColumn, endLine, result2;
7278
+ let endColumn, endLine, endOffset, offset, result2;
7176
7279
  if (line && typeof line === "object") {
7177
7280
  let start = line;
7178
7281
  let end = column;
7179
7282
  if (typeof start.offset === "number") {
7180
- let pos = this.fromOffset(start.offset);
7283
+ offset = start.offset;
7284
+ let pos = this.fromOffset(offset);
7181
7285
  line = pos.line;
7182
7286
  column = pos.col;
7183
7287
  } else {
7184
7288
  line = start.line;
7185
7289
  column = start.column;
7290
+ offset = this.fromLineAndColumn(line, column);
7186
7291
  }
7187
7292
  if (typeof end.offset === "number") {
7188
- let pos = this.fromOffset(end.offset);
7293
+ endOffset = end.offset;
7294
+ let pos = this.fromOffset(endOffset);
7189
7295
  endLine = pos.line;
7190
7296
  endColumn = pos.col;
7191
7297
  } else {
7192
7298
  endLine = end.line;
7193
7299
  endColumn = end.column;
7300
+ endOffset = this.fromLineAndColumn(end.line, end.column);
7194
7301
  }
7195
7302
  } else if (!column) {
7196
- let pos = this.fromOffset(line);
7303
+ offset = line;
7304
+ let pos = this.fromOffset(offset);
7197
7305
  line = pos.line;
7198
7306
  column = pos.col;
7307
+ } else {
7308
+ offset = this.fromLineAndColumn(line, column);
7199
7309
  }
7200
7310
  let origin = this.origin(line, column, endLine, endColumn);
7201
7311
  if (origin) {
@@ -7217,7 +7327,7 @@ let Input$4 = class Input2 {
7217
7327
  opts.plugin
7218
7328
  );
7219
7329
  }
7220
- result2.input = { column, endColumn, endLine, line, source: this.css };
7330
+ result2.input = { column, endColumn, endLine, endOffset, line, offset, source: this.css };
7221
7331
  if (this.file) {
7222
7332
  if (pathToFileURL$1) {
7223
7333
  result2.input.url = pathToFileURL$1(this.file).toString();
@@ -7226,21 +7336,14 @@ let Input$4 = class Input2 {
7226
7336
  }
7227
7337
  return result2;
7228
7338
  }
7339
+ fromLineAndColumn(line, column) {
7340
+ let lineToIndex = getLineToIndex(this);
7341
+ let index2 = lineToIndex[line - 1];
7342
+ return index2 + column - 1;
7343
+ }
7229
7344
  fromOffset(offset) {
7230
- let lastLine, lineToIndex;
7231
- if (!this[fromOffsetCache]) {
7232
- let lines = this.css.split("\n");
7233
- lineToIndex = new Array(lines.length);
7234
- let prevIndex = 0;
7235
- for (let i2 = 0, l2 = lines.length; i2 < l2; i2++) {
7236
- lineToIndex[i2] = prevIndex;
7237
- prevIndex += lines[i2].length + 1;
7238
- }
7239
- this[fromOffsetCache] = lineToIndex;
7240
- } else {
7241
- lineToIndex = this[fromOffsetCache];
7242
- }
7243
- lastLine = lineToIndex[lineToIndex.length - 1];
7345
+ let lineToIndex = getLineToIndex(this);
7346
+ let lastLine = lineToIndex[lineToIndex.length - 1];
7244
7347
  let min = 0;
7245
7348
  if (offset >= lastLine) {
7246
7349
  min = lineToIndex.length - 1;
@@ -8602,7 +8705,7 @@ let Result$3 = class Result2 {
8602
8705
  this.messages = [];
8603
8706
  this.root = root2;
8604
8707
  this.opts = opts;
8605
- this.css = void 0;
8708
+ this.css = "";
8606
8709
  this.map = void 0;
8607
8710
  }
8608
8711
  toString() {
@@ -9214,7 +9317,7 @@ let NoWorkResult22 = noWorkResult;
9214
9317
  let Root$1 = root;
9215
9318
  let Processor$1 = class Processor2 {
9216
9319
  constructor(plugins = []) {
9217
- this.version = "8.5.3";
9320
+ this.version = "8.5.6";
9218
9321
  this.plugins = this.normalize(plugins);
9219
9322
  }
9220
9323
  normalize(plugins) {
@@ -9898,6 +10001,53 @@ var NodeType$2 = /* @__PURE__ */ ((NodeType2) => {
9898
10001
  NodeType2[NodeType2["DOCUMENT_FRAGMENT_NODE"] = 11] = "DOCUMENT_FRAGMENT_NODE";
9899
10002
  return NodeType2;
9900
10003
  })(NodeType$2 || {});
10004
+ const pendingImageLoads$1 = /* @__PURE__ */ new Map();
10005
+ const wrappedContexts$1 = /* @__PURE__ */ new WeakSet();
10006
+ function isHTMLImageElement$1(img) {
10007
+ return img !== null && typeof img === "object" && "complete" in img && "naturalWidth" in img && "naturalHeight" in img && "src" in img && "onload" in img;
10008
+ }
10009
+ function wrapCanvasContextDrawImage$1(ctx) {
10010
+ if (wrappedContexts$1.has(ctx)) {
10011
+ return;
10012
+ }
10013
+ wrappedContexts$1.add(ctx);
10014
+ const originalDrawImage = ctx.drawImage.bind(ctx);
10015
+ ctx.drawImage = function(image, ...args) {
10016
+ const pending = pendingImageLoads$1.get(ctx);
10017
+ if (pending) {
10018
+ pending.cancelled = true;
10019
+ }
10020
+ const drawImageWithArgs = () => {
10021
+ if (args.length === 2 && isHTMLImageElement$1(image)) {
10022
+ args.push(image.naturalWidth || image.width, image.naturalHeight || image.height);
10023
+ }
10024
+ originalDrawImage(image, ...args);
10025
+ };
10026
+ if (isHTMLImageElement$1(image) && !image.complete) {
10027
+ const loadState = { cancelled: false };
10028
+ pendingImageLoads$1.set(ctx, loadState);
10029
+ const onLoad = () => {
10030
+ if (!loadState.cancelled) {
10031
+ pendingImageLoads$1.delete(ctx);
10032
+ drawImageWithArgs();
10033
+ }
10034
+ };
10035
+ const onError = () => {
10036
+ if (!loadState.cancelled) {
10037
+ pendingImageLoads$1.delete(ctx);
10038
+ try {
10039
+ drawImageWithArgs();
10040
+ } catch (e2) {
10041
+ }
10042
+ }
10043
+ };
10044
+ image.onload = onLoad;
10045
+ image.onerror = onError;
10046
+ } else {
10047
+ drawImageWithArgs();
10048
+ }
10049
+ };
10050
+ }
9901
10051
  const NAMESPACES = {
9902
10052
  svg: "http://www.w3.org/2000/svg",
9903
10053
  "xlink:href": "http://www.w3.org/1999/xlink",
@@ -10051,13 +10201,12 @@ function diffAfterUpdatingChildren(oldTree, newTree, replayer) {
10051
10201
  const rrCanvasElement = newTree;
10052
10202
  if (rrCanvasElement.rr_dataURL !== null) {
10053
10203
  const image = document.createElement("img");
10054
- image.onload = () => {
10055
- const ctx = oldElement.getContext("2d");
10056
- if (ctx) {
10057
- ctx.drawImage(image, 0, 0, image.width, image.height);
10058
- }
10059
- };
10060
10204
  image.src = rrCanvasElement.rr_dataURL;
10205
+ const ctx = oldElement.getContext("2d");
10206
+ if (ctx) {
10207
+ wrapCanvasContextDrawImage$1(ctx);
10208
+ ctx.drawImage(image, 0, 0);
10209
+ }
10061
10210
  }
10062
10211
  rrCanvasElement.canvasMutations.forEach(
10063
10212
  (canvasMutation2) => replayer.applyCanvas(
@@ -10122,12 +10271,11 @@ function diffProps(oldTree, newTree, rrnodeMirror) {
10122
10271
  else if (newTree.tagName === "CANVAS" && name === "rr_dataURL") {
10123
10272
  const image = document.createElement("img");
10124
10273
  image.src = newValue;
10125
- image.onload = () => {
10126
- const ctx = oldTree.getContext("2d");
10127
- if (ctx) {
10128
- ctx.drawImage(image, 0, 0, image.width, image.height);
10129
- }
10130
- };
10274
+ const ctx = oldTree.getContext("2d");
10275
+ if (ctx) {
10276
+ wrapCanvasContextDrawImage$1(ctx);
10277
+ ctx.drawImage(image, 0, 0);
10278
+ }
10131
10279
  } else if (newTree.tagName === "IFRAME" && name === "srcdoc") continue;
10132
10280
  else {
10133
10281
  try {
@@ -10638,6 +10786,53 @@ function getDefaultSN(node2, id) {
10638
10786
  };
10639
10787
  }
10640
10788
  }
10789
+ const pendingImageLoads = /* @__PURE__ */ new Map();
10790
+ const wrappedContexts = /* @__PURE__ */ new WeakSet();
10791
+ function isHTMLImageElement(img) {
10792
+ return img !== null && typeof img === "object" && "complete" in img && "naturalWidth" in img && "naturalHeight" in img && "src" in img && "onload" in img;
10793
+ }
10794
+ function wrapCanvasContextDrawImage(ctx) {
10795
+ if (wrappedContexts.has(ctx)) {
10796
+ return;
10797
+ }
10798
+ wrappedContexts.add(ctx);
10799
+ const originalDrawImage = ctx.drawImage.bind(ctx);
10800
+ ctx.drawImage = function(image, ...args) {
10801
+ const pending = pendingImageLoads.get(ctx);
10802
+ if (pending) {
10803
+ pending.cancelled = true;
10804
+ }
10805
+ const drawImageWithArgs = () => {
10806
+ if (args.length === 2 && isHTMLImageElement(image)) {
10807
+ args.push(image.naturalWidth || image.width, image.naturalHeight || image.height);
10808
+ }
10809
+ originalDrawImage(image, ...args);
10810
+ };
10811
+ if (isHTMLImageElement(image) && !image.complete) {
10812
+ const loadState = { cancelled: false };
10813
+ pendingImageLoads.set(ctx, loadState);
10814
+ const onLoad = () => {
10815
+ if (!loadState.cancelled) {
10816
+ pendingImageLoads.delete(ctx);
10817
+ drawImageWithArgs();
10818
+ }
10819
+ };
10820
+ const onError = () => {
10821
+ if (!loadState.cancelled) {
10822
+ pendingImageLoads.delete(ctx);
10823
+ try {
10824
+ drawImageWithArgs();
10825
+ } catch (e2) {
10826
+ }
10827
+ }
10828
+ };
10829
+ image.onload = onLoad;
10830
+ image.onerror = onError;
10831
+ } else {
10832
+ drawImageWithArgs();
10833
+ }
10834
+ };
10835
+ }
10641
10836
  const testableAccessors = {
10642
10837
  Node: ["childNodes", "parentNode", "parentElement", "textContent"],
10643
10838
  ShadowRoot: ["host", "styleSheets"],
@@ -10805,7 +11000,8 @@ const index = {
10805
11000
  querySelector,
10806
11001
  querySelectorAll,
10807
11002
  mutationObserver: mutationObserverCtor,
10808
- patch
11003
+ patch,
11004
+ wrapCanvasContextDrawImage
10809
11005
  };
10810
11006
  function on(type, fn, target = document) {
10811
11007
  const options = { capture: true };
@@ -15646,6 +15842,7 @@ async function canvasMutation$1({
15646
15842
  errorHandler2(mutations[0], new Error("Canvas context is null"));
15647
15843
  return;
15648
15844
  }
15845
+ wrapCanvasContextDrawImage(ctx);
15649
15846
  const mutationArgsPromises = mutations.map(
15650
15847
  async (mutation) => {
15651
15848
  return Promise.all(mutation.args.map(deserializeArg(imageMap, ctx)));