@highlight-run/rrweb 2.0.0-lambda.3 → 2.0.0-lambda.5

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;
@@ -576,7 +624,10 @@ function markCssSplits(cssText, style) {
576
624
  }
577
625
  function obfuscateText(text) {
578
626
  text = text.replace(/[^ -~]+/g, "");
579
- text = (text == null ? void 0 : text.split(" ").map((word) => Math.random().toString(20).substring(2, word.length)).join(" ")) || "";
627
+ text = (text == null ? void 0 : text.split(" ").map((word) => {
628
+ if (!word) return "";
629
+ return Math.random().toString(20).substring(2, word.length + 2);
630
+ }).join(" ")) || "";
580
631
  return text;
581
632
  }
582
633
  function isElementSrcBlocked(tagName) {
@@ -2238,7 +2289,7 @@ let Node$4$1 = class Node2 {
2238
2289
  let index2 = this.parent.index(this);
2239
2290
  return this.parent.nodes[index2 + 1];
2240
2291
  }
2241
- positionBy(opts) {
2292
+ positionBy(opts = {}) {
2242
2293
  let pos = this.source.start;
2243
2294
  if (opts.index) {
2244
2295
  pos = this.positionInside(opts.index);
@@ -2267,27 +2318,38 @@ let Node$4$1 = class Node2 {
2267
2318
  column += 1;
2268
2319
  }
2269
2320
  }
2270
- return { column, line };
2321
+ return { column, line, offset: end };
2271
2322
  }
2272
2323
  prev() {
2273
2324
  if (!this.parent) return void 0;
2274
2325
  let index2 = this.parent.index(this);
2275
2326
  return this.parent.nodes[index2 - 1];
2276
2327
  }
2277
- rangeBy(opts) {
2328
+ rangeBy(opts = {}) {
2329
+ let inputString = "document" in this.source.input ? this.source.input.document : this.source.input.css;
2278
2330
  let start = {
2279
2331
  column: this.source.start.column,
2280
- line: this.source.start.line
2332
+ line: this.source.start.line,
2333
+ offset: sourceOffset$1(inputString, this.source.start)
2281
2334
  };
2282
2335
  let end = this.source.end ? {
2283
2336
  column: this.source.end.column + 1,
2284
- line: this.source.end.line
2337
+ line: this.source.end.line,
2338
+ offset: typeof this.source.end.offset === "number" ? (
2339
+ // `source.end.offset` is exclusive, so we don't need to add 1
2340
+ this.source.end.offset
2341
+ ) : (
2342
+ // Since line/column in this.source.end is inclusive,
2343
+ // the `sourceOffset(... , this.source.end)` returns an inclusive offset.
2344
+ // So, we add 1 to convert it to exclusive.
2345
+ sourceOffset$1(inputString, this.source.end) + 1
2346
+ )
2285
2347
  } : {
2286
2348
  column: start.column + 1,
2287
- line: start.line
2349
+ line: start.line,
2350
+ offset: start.offset + 1
2288
2351
  };
2289
2352
  if (opts.word) {
2290
- let inputString = "document" in this.source.input ? this.source.input.document : this.source.input.css;
2291
2353
  let stringRepresentation = inputString.slice(
2292
2354
  sourceOffset$1(inputString, this.source.start),
2293
2355
  sourceOffset$1(inputString, this.source.end)
@@ -2295,15 +2357,14 @@ let Node$4$1 = class Node2 {
2295
2357
  let index2 = stringRepresentation.indexOf(opts.word);
2296
2358
  if (index2 !== -1) {
2297
2359
  start = this.positionInside(index2);
2298
- end = this.positionInside(
2299
- index2 + opts.word.length
2300
- );
2360
+ end = this.positionInside(index2 + opts.word.length);
2301
2361
  }
2302
2362
  } else {
2303
2363
  if (opts.start) {
2304
2364
  start = {
2305
2365
  column: opts.start.column,
2306
- line: opts.start.line
2366
+ line: opts.start.line,
2367
+ offset: sourceOffset$1(inputString, opts.start)
2307
2368
  };
2308
2369
  } else if (opts.index) {
2309
2370
  start = this.positionInside(opts.index);
@@ -2311,7 +2372,8 @@ let Node$4$1 = class Node2 {
2311
2372
  if (opts.end) {
2312
2373
  end = {
2313
2374
  column: opts.end.column,
2314
- line: opts.end.line
2375
+ line: opts.end.line,
2376
+ offset: sourceOffset$1(inputString, opts.end)
2315
2377
  };
2316
2378
  } else if (typeof opts.endIndex === "number") {
2317
2379
  end = this.positionInside(opts.endIndex);
@@ -2320,7 +2382,11 @@ let Node$4$1 = class Node2 {
2320
2382
  }
2321
2383
  }
2322
2384
  if (end.line < start.line || end.line === start.line && end.column <= start.column) {
2323
- end = { column: start.column + 1, line: start.line };
2385
+ end = {
2386
+ column: start.column + 1,
2387
+ line: start.line,
2388
+ offset: start.offset + 1
2389
+ };
2324
2390
  }
2325
2391
  return { end, start };
2326
2392
  }
@@ -2384,6 +2450,7 @@ let Node$4$1 = class Node2 {
2384
2450
  } else if (typeof value === "object" && value.toJSON) {
2385
2451
  fixed[name] = value.toJSON(null, inputs);
2386
2452
  } else if (name === "source") {
2453
+ if (value == null) continue;
2387
2454
  let inputId = inputs.get(value.input);
2388
2455
  if (inputId == null) {
2389
2456
  inputId = inputsNextIndex;
@@ -2418,7 +2485,7 @@ let Node$4$1 = class Node2 {
2418
2485
  });
2419
2486
  return result2;
2420
2487
  }
2421
- warn(result2, text, opts) {
2488
+ warn(result2, text, opts = {}) {
2422
2489
  let data = { node: this };
2423
2490
  for (let i2 in opts) data[i2] = opts[i2];
2424
2491
  return result2.warn(text, data);
@@ -2995,9 +3062,21 @@ let { fileURLToPath: fileURLToPath$1, pathToFileURL: pathToFileURL$1$1 } = requi
2995
3062
  let CssSyntaxError$1$1 = cssSyntaxError$1;
2996
3063
  let PreviousMap$1$1 = previousMap$1;
2997
3064
  let terminalHighlight$2 = require$$2$1;
2998
- let fromOffsetCache$1 = Symbol("fromOffsetCache");
3065
+ let lineToIndexCache$1 = Symbol("lineToIndexCache");
2999
3066
  let sourceMapAvailable$1$1 = Boolean(SourceMapConsumer$1$1 && SourceMapGenerator$1$1);
3000
3067
  let pathAvailable$1$1 = Boolean(resolve$1$1 && isAbsolute$1);
3068
+ function getLineToIndex$1(input2) {
3069
+ if (input2[lineToIndexCache$1]) return input2[lineToIndexCache$1];
3070
+ let lines = input2.css.split("\n");
3071
+ let lineToIndex = new Array(lines.length);
3072
+ let prevIndex = 0;
3073
+ for (let i2 = 0, l2 = lines.length; i2 < l2; i2++) {
3074
+ lineToIndex[i2] = prevIndex;
3075
+ prevIndex += lines[i2].length + 1;
3076
+ }
3077
+ input2[lineToIndexCache$1] = lineToIndex;
3078
+ return lineToIndex;
3079
+ }
3001
3080
  let Input$4$1 = class Input {
3002
3081
  get from() {
3003
3082
  return this.file || this.id;
@@ -3036,30 +3115,37 @@ let Input$4$1 = class Input {
3036
3115
  if (this.map) this.map.file = this.from;
3037
3116
  }
3038
3117
  error(message, line, column, opts = {}) {
3039
- let endColumn, endLine, result2;
3118
+ let endColumn, endLine, endOffset, offset, result2;
3040
3119
  if (line && typeof line === "object") {
3041
3120
  let start = line;
3042
3121
  let end = column;
3043
3122
  if (typeof start.offset === "number") {
3044
- let pos = this.fromOffset(start.offset);
3123
+ offset = start.offset;
3124
+ let pos = this.fromOffset(offset);
3045
3125
  line = pos.line;
3046
3126
  column = pos.col;
3047
3127
  } else {
3048
3128
  line = start.line;
3049
3129
  column = start.column;
3130
+ offset = this.fromLineAndColumn(line, column);
3050
3131
  }
3051
3132
  if (typeof end.offset === "number") {
3052
- let pos = this.fromOffset(end.offset);
3133
+ endOffset = end.offset;
3134
+ let pos = this.fromOffset(endOffset);
3053
3135
  endLine = pos.line;
3054
3136
  endColumn = pos.col;
3055
3137
  } else {
3056
3138
  endLine = end.line;
3057
3139
  endColumn = end.column;
3140
+ endOffset = this.fromLineAndColumn(end.line, end.column);
3058
3141
  }
3059
3142
  } else if (!column) {
3060
- let pos = this.fromOffset(line);
3143
+ offset = line;
3144
+ let pos = this.fromOffset(offset);
3061
3145
  line = pos.line;
3062
3146
  column = pos.col;
3147
+ } else {
3148
+ offset = this.fromLineAndColumn(line, column);
3063
3149
  }
3064
3150
  let origin = this.origin(line, column, endLine, endColumn);
3065
3151
  if (origin) {
@@ -3081,7 +3167,7 @@ let Input$4$1 = class Input {
3081
3167
  opts.plugin
3082
3168
  );
3083
3169
  }
3084
- result2.input = { column, endColumn, endLine, line, source: this.css };
3170
+ result2.input = { column, endColumn, endLine, endOffset, line, offset, source: this.css };
3085
3171
  if (this.file) {
3086
3172
  if (pathToFileURL$1$1) {
3087
3173
  result2.input.url = pathToFileURL$1$1(this.file).toString();
@@ -3090,21 +3176,14 @@ let Input$4$1 = class Input {
3090
3176
  }
3091
3177
  return result2;
3092
3178
  }
3179
+ fromLineAndColumn(line, column) {
3180
+ let lineToIndex = getLineToIndex$1(this);
3181
+ let index2 = lineToIndex[line - 1];
3182
+ return index2 + column - 1;
3183
+ }
3093
3184
  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];
3185
+ let lineToIndex = getLineToIndex$1(this);
3186
+ let lastLine = lineToIndex[lineToIndex.length - 1];
3108
3187
  let min = 0;
3109
3188
  if (offset >= lastLine) {
3110
3189
  min = lineToIndex.length - 1;
@@ -4466,7 +4545,7 @@ let Result$3$1 = class Result {
4466
4545
  this.messages = [];
4467
4546
  this.root = root2;
4468
4547
  this.opts = opts;
4469
- this.css = void 0;
4548
+ this.css = "";
4470
4549
  this.map = void 0;
4471
4550
  }
4472
4551
  toString() {
@@ -5078,7 +5157,7 @@ let NoWorkResult2$1 = noWorkResult$1;
5078
5157
  let Root$1$1 = root$1;
5079
5158
  let Processor$1$1 = class Processor {
5080
5159
  constructor(plugins = []) {
5081
- this.version = "8.5.3";
5160
+ this.version = "8.5.6";
5082
5161
  this.plugins = this.normalize(plugins);
5083
5162
  }
5084
5163
  normalize(plugins) {
@@ -5446,13 +5525,12 @@ function buildNode(n2, options) {
5446
5525
  const value = specialAttributes[name];
5447
5526
  if (tagName === "canvas" && name === "rr_dataURL") {
5448
5527
  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
5528
  image.src = value.toString();
5529
+ const ctx = node2.getContext("2d");
5530
+ if (ctx) {
5531
+ wrapCanvasContextDrawImage$2(ctx);
5532
+ ctx.drawImage(image, 0, 0);
5533
+ }
5456
5534
  if (node2.RRNodeType)
5457
5535
  node2.rr_dataURL = value.toString();
5458
5536
  } else if (tagName === "img" && name === "rr_dataURL") {
@@ -6321,7 +6399,7 @@ let Node$4 = class Node3 {
6321
6399
  let index2 = this.parent.index(this);
6322
6400
  return this.parent.nodes[index2 + 1];
6323
6401
  }
6324
- positionBy(opts) {
6402
+ positionBy(opts = {}) {
6325
6403
  let pos = this.source.start;
6326
6404
  if (opts.index) {
6327
6405
  pos = this.positionInside(opts.index);
@@ -6350,27 +6428,38 @@ let Node$4 = class Node3 {
6350
6428
  column += 1;
6351
6429
  }
6352
6430
  }
6353
- return { column, line };
6431
+ return { column, line, offset: end };
6354
6432
  }
6355
6433
  prev() {
6356
6434
  if (!this.parent) return void 0;
6357
6435
  let index2 = this.parent.index(this);
6358
6436
  return this.parent.nodes[index2 - 1];
6359
6437
  }
6360
- rangeBy(opts) {
6438
+ rangeBy(opts = {}) {
6439
+ let inputString = "document" in this.source.input ? this.source.input.document : this.source.input.css;
6361
6440
  let start = {
6362
6441
  column: this.source.start.column,
6363
- line: this.source.start.line
6442
+ line: this.source.start.line,
6443
+ offset: sourceOffset(inputString, this.source.start)
6364
6444
  };
6365
6445
  let end = this.source.end ? {
6366
6446
  column: this.source.end.column + 1,
6367
- line: this.source.end.line
6447
+ line: this.source.end.line,
6448
+ offset: typeof this.source.end.offset === "number" ? (
6449
+ // `source.end.offset` is exclusive, so we don't need to add 1
6450
+ this.source.end.offset
6451
+ ) : (
6452
+ // Since line/column in this.source.end is inclusive,
6453
+ // the `sourceOffset(... , this.source.end)` returns an inclusive offset.
6454
+ // So, we add 1 to convert it to exclusive.
6455
+ sourceOffset(inputString, this.source.end) + 1
6456
+ )
6368
6457
  } : {
6369
6458
  column: start.column + 1,
6370
- line: start.line
6459
+ line: start.line,
6460
+ offset: start.offset + 1
6371
6461
  };
6372
6462
  if (opts.word) {
6373
- let inputString = "document" in this.source.input ? this.source.input.document : this.source.input.css;
6374
6463
  let stringRepresentation = inputString.slice(
6375
6464
  sourceOffset(inputString, this.source.start),
6376
6465
  sourceOffset(inputString, this.source.end)
@@ -6378,15 +6467,14 @@ let Node$4 = class Node3 {
6378
6467
  let index2 = stringRepresentation.indexOf(opts.word);
6379
6468
  if (index2 !== -1) {
6380
6469
  start = this.positionInside(index2);
6381
- end = this.positionInside(
6382
- index2 + opts.word.length
6383
- );
6470
+ end = this.positionInside(index2 + opts.word.length);
6384
6471
  }
6385
6472
  } else {
6386
6473
  if (opts.start) {
6387
6474
  start = {
6388
6475
  column: opts.start.column,
6389
- line: opts.start.line
6476
+ line: opts.start.line,
6477
+ offset: sourceOffset(inputString, opts.start)
6390
6478
  };
6391
6479
  } else if (opts.index) {
6392
6480
  start = this.positionInside(opts.index);
@@ -6394,7 +6482,8 @@ let Node$4 = class Node3 {
6394
6482
  if (opts.end) {
6395
6483
  end = {
6396
6484
  column: opts.end.column,
6397
- line: opts.end.line
6485
+ line: opts.end.line,
6486
+ offset: sourceOffset(inputString, opts.end)
6398
6487
  };
6399
6488
  } else if (typeof opts.endIndex === "number") {
6400
6489
  end = this.positionInside(opts.endIndex);
@@ -6403,7 +6492,11 @@ let Node$4 = class Node3 {
6403
6492
  }
6404
6493
  }
6405
6494
  if (end.line < start.line || end.line === start.line && end.column <= start.column) {
6406
- end = { column: start.column + 1, line: start.line };
6495
+ end = {
6496
+ column: start.column + 1,
6497
+ line: start.line,
6498
+ offset: start.offset + 1
6499
+ };
6407
6500
  }
6408
6501
  return { end, start };
6409
6502
  }
@@ -6467,6 +6560,7 @@ let Node$4 = class Node3 {
6467
6560
  } else if (typeof value === "object" && value.toJSON) {
6468
6561
  fixed[name] = value.toJSON(null, inputs);
6469
6562
  } else if (name === "source") {
6563
+ if (value == null) continue;
6470
6564
  let inputId = inputs.get(value.input);
6471
6565
  if (inputId == null) {
6472
6566
  inputId = inputsNextIndex;
@@ -6501,7 +6595,7 @@ let Node$4 = class Node3 {
6501
6595
  });
6502
6596
  return result2;
6503
6597
  }
6504
- warn(result2, text, opts) {
6598
+ warn(result2, text, opts = {}) {
6505
6599
  let data = { node: this };
6506
6600
  for (let i2 in opts) data[i2] = opts[i2];
6507
6601
  return result2.warn(text, data);
@@ -7078,9 +7172,21 @@ let { fileURLToPath, pathToFileURL: pathToFileURL$1 } = require$$2;
7078
7172
  let CssSyntaxError$1 = cssSyntaxError;
7079
7173
  let PreviousMap$1 = previousMap;
7080
7174
  let terminalHighlight = require$$2;
7081
- let fromOffsetCache = Symbol("fromOffsetCache");
7175
+ let lineToIndexCache = Symbol("lineToIndexCache");
7082
7176
  let sourceMapAvailable$1 = Boolean(SourceMapConsumer$1 && SourceMapGenerator$1);
7083
7177
  let pathAvailable$1 = Boolean(resolve$1 && isAbsolute);
7178
+ function getLineToIndex(input2) {
7179
+ if (input2[lineToIndexCache]) return input2[lineToIndexCache];
7180
+ let lines = input2.css.split("\n");
7181
+ let lineToIndex = new Array(lines.length);
7182
+ let prevIndex = 0;
7183
+ for (let i2 = 0, l2 = lines.length; i2 < l2; i2++) {
7184
+ lineToIndex[i2] = prevIndex;
7185
+ prevIndex += lines[i2].length + 1;
7186
+ }
7187
+ input2[lineToIndexCache] = lineToIndex;
7188
+ return lineToIndex;
7189
+ }
7084
7190
  let Input$4 = class Input2 {
7085
7191
  get from() {
7086
7192
  return this.file || this.id;
@@ -7119,30 +7225,37 @@ let Input$4 = class Input2 {
7119
7225
  if (this.map) this.map.file = this.from;
7120
7226
  }
7121
7227
  error(message, line, column, opts = {}) {
7122
- let endColumn, endLine, result2;
7228
+ let endColumn, endLine, endOffset, offset, result2;
7123
7229
  if (line && typeof line === "object") {
7124
7230
  let start = line;
7125
7231
  let end = column;
7126
7232
  if (typeof start.offset === "number") {
7127
- let pos = this.fromOffset(start.offset);
7233
+ offset = start.offset;
7234
+ let pos = this.fromOffset(offset);
7128
7235
  line = pos.line;
7129
7236
  column = pos.col;
7130
7237
  } else {
7131
7238
  line = start.line;
7132
7239
  column = start.column;
7240
+ offset = this.fromLineAndColumn(line, column);
7133
7241
  }
7134
7242
  if (typeof end.offset === "number") {
7135
- let pos = this.fromOffset(end.offset);
7243
+ endOffset = end.offset;
7244
+ let pos = this.fromOffset(endOffset);
7136
7245
  endLine = pos.line;
7137
7246
  endColumn = pos.col;
7138
7247
  } else {
7139
7248
  endLine = end.line;
7140
7249
  endColumn = end.column;
7250
+ endOffset = this.fromLineAndColumn(end.line, end.column);
7141
7251
  }
7142
7252
  } else if (!column) {
7143
- let pos = this.fromOffset(line);
7253
+ offset = line;
7254
+ let pos = this.fromOffset(offset);
7144
7255
  line = pos.line;
7145
7256
  column = pos.col;
7257
+ } else {
7258
+ offset = this.fromLineAndColumn(line, column);
7146
7259
  }
7147
7260
  let origin = this.origin(line, column, endLine, endColumn);
7148
7261
  if (origin) {
@@ -7164,7 +7277,7 @@ let Input$4 = class Input2 {
7164
7277
  opts.plugin
7165
7278
  );
7166
7279
  }
7167
- result2.input = { column, endColumn, endLine, line, source: this.css };
7280
+ result2.input = { column, endColumn, endLine, endOffset, line, offset, source: this.css };
7168
7281
  if (this.file) {
7169
7282
  if (pathToFileURL$1) {
7170
7283
  result2.input.url = pathToFileURL$1(this.file).toString();
@@ -7173,21 +7286,14 @@ let Input$4 = class Input2 {
7173
7286
  }
7174
7287
  return result2;
7175
7288
  }
7289
+ fromLineAndColumn(line, column) {
7290
+ let lineToIndex = getLineToIndex(this);
7291
+ let index2 = lineToIndex[line - 1];
7292
+ return index2 + column - 1;
7293
+ }
7176
7294
  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];
7295
+ let lineToIndex = getLineToIndex(this);
7296
+ let lastLine = lineToIndex[lineToIndex.length - 1];
7191
7297
  let min = 0;
7192
7298
  if (offset >= lastLine) {
7193
7299
  min = lineToIndex.length - 1;
@@ -8549,7 +8655,7 @@ let Result$3 = class Result2 {
8549
8655
  this.messages = [];
8550
8656
  this.root = root2;
8551
8657
  this.opts = opts;
8552
- this.css = void 0;
8658
+ this.css = "";
8553
8659
  this.map = void 0;
8554
8660
  }
8555
8661
  toString() {
@@ -9161,7 +9267,7 @@ let NoWorkResult22 = noWorkResult;
9161
9267
  let Root$1 = root;
9162
9268
  let Processor$1 = class Processor2 {
9163
9269
  constructor(plugins = []) {
9164
- this.version = "8.5.3";
9270
+ this.version = "8.5.6";
9165
9271
  this.plugins = this.normalize(plugins);
9166
9272
  }
9167
9273
  normalize(plugins) {
@@ -9845,6 +9951,53 @@ var NodeType$2 = /* @__PURE__ */ ((NodeType2) => {
9845
9951
  NodeType2[NodeType2["DOCUMENT_FRAGMENT_NODE"] = 11] = "DOCUMENT_FRAGMENT_NODE";
9846
9952
  return NodeType2;
9847
9953
  })(NodeType$2 || {});
9954
+ const pendingImageLoads$1 = /* @__PURE__ */ new Map();
9955
+ const wrappedContexts$1 = /* @__PURE__ */ new WeakSet();
9956
+ function isHTMLImageElement$1(img) {
9957
+ return img !== null && typeof img === "object" && "complete" in img && "naturalWidth" in img && "naturalHeight" in img && "src" in img && "onload" in img;
9958
+ }
9959
+ function wrapCanvasContextDrawImage$1(ctx) {
9960
+ if (wrappedContexts$1.has(ctx)) {
9961
+ return;
9962
+ }
9963
+ wrappedContexts$1.add(ctx);
9964
+ const originalDrawImage = ctx.drawImage.bind(ctx);
9965
+ ctx.drawImage = function(image, ...args) {
9966
+ const pending = pendingImageLoads$1.get(ctx);
9967
+ if (pending) {
9968
+ pending.cancelled = true;
9969
+ }
9970
+ const drawImageWithArgs = () => {
9971
+ if (args.length === 2 && isHTMLImageElement$1(image)) {
9972
+ args.push(image.naturalWidth || image.width, image.naturalHeight || image.height);
9973
+ }
9974
+ originalDrawImage(image, ...args);
9975
+ };
9976
+ if (isHTMLImageElement$1(image) && !image.complete) {
9977
+ const loadState = { cancelled: false };
9978
+ pendingImageLoads$1.set(ctx, loadState);
9979
+ const onLoad = () => {
9980
+ if (!loadState.cancelled) {
9981
+ pendingImageLoads$1.delete(ctx);
9982
+ drawImageWithArgs();
9983
+ }
9984
+ };
9985
+ const onError = () => {
9986
+ if (!loadState.cancelled) {
9987
+ pendingImageLoads$1.delete(ctx);
9988
+ try {
9989
+ drawImageWithArgs();
9990
+ } catch (e2) {
9991
+ }
9992
+ }
9993
+ };
9994
+ image.onload = onLoad;
9995
+ image.onerror = onError;
9996
+ } else {
9997
+ drawImageWithArgs();
9998
+ }
9999
+ };
10000
+ }
9848
10001
  const NAMESPACES = {
9849
10002
  svg: "http://www.w3.org/2000/svg",
9850
10003
  "xlink:href": "http://www.w3.org/1999/xlink",
@@ -9998,13 +10151,12 @@ function diffAfterUpdatingChildren(oldTree, newTree, replayer) {
9998
10151
  const rrCanvasElement = newTree;
9999
10152
  if (rrCanvasElement.rr_dataURL !== null) {
10000
10153
  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
10154
  image.src = rrCanvasElement.rr_dataURL;
10155
+ const ctx = oldElement.getContext("2d");
10156
+ if (ctx) {
10157
+ wrapCanvasContextDrawImage$1(ctx);
10158
+ ctx.drawImage(image, 0, 0);
10159
+ }
10008
10160
  }
10009
10161
  rrCanvasElement.canvasMutations.forEach(
10010
10162
  (canvasMutation2) => replayer.applyCanvas(
@@ -10069,12 +10221,11 @@ function diffProps(oldTree, newTree, rrnodeMirror) {
10069
10221
  else if (newTree.tagName === "CANVAS" && name === "rr_dataURL") {
10070
10222
  const image = document.createElement("img");
10071
10223
  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
- };
10224
+ const ctx = oldTree.getContext("2d");
10225
+ if (ctx) {
10226
+ wrapCanvasContextDrawImage$1(ctx);
10227
+ ctx.drawImage(image, 0, 0);
10228
+ }
10078
10229
  } else if (newTree.tagName === "IFRAME" && name === "srcdoc") continue;
10079
10230
  else {
10080
10231
  try {
@@ -10585,6 +10736,53 @@ function getDefaultSN(node2, id) {
10585
10736
  };
10586
10737
  }
10587
10738
  }
10739
+ const pendingImageLoads = /* @__PURE__ */ new Map();
10740
+ const wrappedContexts = /* @__PURE__ */ new WeakSet();
10741
+ function isHTMLImageElement(img) {
10742
+ return img !== null && typeof img === "object" && "complete" in img && "naturalWidth" in img && "naturalHeight" in img && "src" in img && "onload" in img;
10743
+ }
10744
+ function wrapCanvasContextDrawImage(ctx) {
10745
+ if (wrappedContexts.has(ctx)) {
10746
+ return;
10747
+ }
10748
+ wrappedContexts.add(ctx);
10749
+ const originalDrawImage = ctx.drawImage.bind(ctx);
10750
+ ctx.drawImage = function(image, ...args) {
10751
+ const pending = pendingImageLoads.get(ctx);
10752
+ if (pending) {
10753
+ pending.cancelled = true;
10754
+ }
10755
+ const drawImageWithArgs = () => {
10756
+ if (args.length === 2 && isHTMLImageElement(image)) {
10757
+ args.push(image.naturalWidth || image.width, image.naturalHeight || image.height);
10758
+ }
10759
+ originalDrawImage(image, ...args);
10760
+ };
10761
+ if (isHTMLImageElement(image) && !image.complete) {
10762
+ const loadState = { cancelled: false };
10763
+ pendingImageLoads.set(ctx, loadState);
10764
+ const onLoad = () => {
10765
+ if (!loadState.cancelled) {
10766
+ pendingImageLoads.delete(ctx);
10767
+ drawImageWithArgs();
10768
+ }
10769
+ };
10770
+ const onError = () => {
10771
+ if (!loadState.cancelled) {
10772
+ pendingImageLoads.delete(ctx);
10773
+ try {
10774
+ drawImageWithArgs();
10775
+ } catch (e2) {
10776
+ }
10777
+ }
10778
+ };
10779
+ image.onload = onLoad;
10780
+ image.onerror = onError;
10781
+ } else {
10782
+ drawImageWithArgs();
10783
+ }
10784
+ };
10785
+ }
10588
10786
  const testableAccessors = {
10589
10787
  Node: ["childNodes", "parentNode", "parentElement", "textContent"],
10590
10788
  ShadowRoot: ["host", "styleSheets"],
@@ -10752,7 +10950,8 @@ const index = {
10752
10950
  querySelector,
10753
10951
  querySelectorAll,
10754
10952
  mutationObserver: mutationObserverCtor,
10755
- patch
10953
+ patch,
10954
+ wrapCanvasContextDrawImage
10756
10955
  };
10757
10956
  function on(type, fn, target = document) {
10758
10957
  const options = { capture: true };
@@ -15634,6 +15833,7 @@ async function canvasMutation$1({
15634
15833
  errorHandler2(mutations[0], new Error("Canvas context is null"));
15635
15834
  return;
15636
15835
  }
15836
+ wrapCanvasContextDrawImage(ctx);
15637
15837
  const mutationArgsPromises = mutations.map(
15638
15838
  async (mutation) => {
15639
15839
  return Promise.all(mutation.args.map(deserializeArg(imageMap, ctx)));
@@ -16656,6 +16856,7 @@ class Replayer {
16656
16856
  this.usingVirtualDom = false;
16657
16857
  }
16658
16858
  this.mirror.reset();
16859
+ this.newDocumentQueue = [];
16659
16860
  rebuild(event.data.node, {
16660
16861
  doc: this.iframe.contentDocument,
16661
16862
  afterAppend,