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