@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.
@@ -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;
@@ -621,7 +669,10 @@ function markCssSplits(cssText, style) {
621
669
  }
622
670
  function obfuscateText(text) {
623
671
  text = text.replace(/[^ -~]+/g, "");
624
- text = (text == null ? void 0 : text.split(" ").map((word) => Math.random().toString(20).substring(2, word.length)).join(" ")) || "";
672
+ text = (text == null ? void 0 : text.split(" ").map((word) => {
673
+ if (!word) return "";
674
+ return Math.random().toString(20).substring(2, word.length + 2);
675
+ }).join(" ")) || "";
625
676
  return text;
626
677
  }
627
678
  function isElementSrcBlocked(tagName) {
@@ -2283,7 +2334,7 @@ let Node$4$1 = class Node2 {
2283
2334
  let index2 = this.parent.index(this);
2284
2335
  return this.parent.nodes[index2 + 1];
2285
2336
  }
2286
- positionBy(opts) {
2337
+ positionBy(opts = {}) {
2287
2338
  let pos = this.source.start;
2288
2339
  if (opts.index) {
2289
2340
  pos = this.positionInside(opts.index);
@@ -2312,27 +2363,38 @@ let Node$4$1 = class Node2 {
2312
2363
  column += 1;
2313
2364
  }
2314
2365
  }
2315
- return { column, line };
2366
+ return { column, line, offset: end };
2316
2367
  }
2317
2368
  prev() {
2318
2369
  if (!this.parent) return void 0;
2319
2370
  let index2 = this.parent.index(this);
2320
2371
  return this.parent.nodes[index2 - 1];
2321
2372
  }
2322
- rangeBy(opts) {
2373
+ rangeBy(opts = {}) {
2374
+ let inputString = "document" in this.source.input ? this.source.input.document : this.source.input.css;
2323
2375
  let start = {
2324
2376
  column: this.source.start.column,
2325
- line: this.source.start.line
2377
+ line: this.source.start.line,
2378
+ offset: sourceOffset$1(inputString, this.source.start)
2326
2379
  };
2327
2380
  let end = this.source.end ? {
2328
2381
  column: this.source.end.column + 1,
2329
- line: this.source.end.line
2382
+ line: this.source.end.line,
2383
+ offset: typeof this.source.end.offset === "number" ? (
2384
+ // `source.end.offset` is exclusive, so we don't need to add 1
2385
+ this.source.end.offset
2386
+ ) : (
2387
+ // Since line/column in this.source.end is inclusive,
2388
+ // the `sourceOffset(... , this.source.end)` returns an inclusive offset.
2389
+ // So, we add 1 to convert it to exclusive.
2390
+ sourceOffset$1(inputString, this.source.end) + 1
2391
+ )
2330
2392
  } : {
2331
2393
  column: start.column + 1,
2332
- line: start.line
2394
+ line: start.line,
2395
+ offset: start.offset + 1
2333
2396
  };
2334
2397
  if (opts.word) {
2335
- let inputString = "document" in this.source.input ? this.source.input.document : this.source.input.css;
2336
2398
  let stringRepresentation = inputString.slice(
2337
2399
  sourceOffset$1(inputString, this.source.start),
2338
2400
  sourceOffset$1(inputString, this.source.end)
@@ -2340,15 +2402,14 @@ let Node$4$1 = class Node2 {
2340
2402
  let index2 = stringRepresentation.indexOf(opts.word);
2341
2403
  if (index2 !== -1) {
2342
2404
  start = this.positionInside(index2);
2343
- end = this.positionInside(
2344
- index2 + opts.word.length
2345
- );
2405
+ end = this.positionInside(index2 + opts.word.length);
2346
2406
  }
2347
2407
  } else {
2348
2408
  if (opts.start) {
2349
2409
  start = {
2350
2410
  column: opts.start.column,
2351
- line: opts.start.line
2411
+ line: opts.start.line,
2412
+ offset: sourceOffset$1(inputString, opts.start)
2352
2413
  };
2353
2414
  } else if (opts.index) {
2354
2415
  start = this.positionInside(opts.index);
@@ -2356,7 +2417,8 @@ let Node$4$1 = class Node2 {
2356
2417
  if (opts.end) {
2357
2418
  end = {
2358
2419
  column: opts.end.column,
2359
- line: opts.end.line
2420
+ line: opts.end.line,
2421
+ offset: sourceOffset$1(inputString, opts.end)
2360
2422
  };
2361
2423
  } else if (typeof opts.endIndex === "number") {
2362
2424
  end = this.positionInside(opts.endIndex);
@@ -2365,7 +2427,11 @@ let Node$4$1 = class Node2 {
2365
2427
  }
2366
2428
  }
2367
2429
  if (end.line < start.line || end.line === start.line && end.column <= start.column) {
2368
- end = { column: start.column + 1, line: start.line };
2430
+ end = {
2431
+ column: start.column + 1,
2432
+ line: start.line,
2433
+ offset: start.offset + 1
2434
+ };
2369
2435
  }
2370
2436
  return { end, start };
2371
2437
  }
@@ -2429,6 +2495,7 @@ let Node$4$1 = class Node2 {
2429
2495
  } else if (typeof value === "object" && value.toJSON) {
2430
2496
  fixed[name] = value.toJSON(null, inputs);
2431
2497
  } else if (name === "source") {
2498
+ if (value == null) continue;
2432
2499
  let inputId = inputs.get(value.input);
2433
2500
  if (inputId == null) {
2434
2501
  inputId = inputsNextIndex;
@@ -2463,7 +2530,7 @@ let Node$4$1 = class Node2 {
2463
2530
  });
2464
2531
  return result2;
2465
2532
  }
2466
- warn(result2, text, opts) {
2533
+ warn(result2, text, opts = {}) {
2467
2534
  let data = { node: this };
2468
2535
  for (let i2 in opts) data[i2] = opts[i2];
2469
2536
  return result2.warn(text, data);
@@ -3044,9 +3111,21 @@ let { fileURLToPath: fileURLToPath$1, pathToFileURL: pathToFileURL$1$1 } = requi
3044
3111
  let CssSyntaxError$1$1 = cssSyntaxError$1;
3045
3112
  let PreviousMap$1$1 = previousMap$1;
3046
3113
  let terminalHighlight$2 = require$$2$1;
3047
- let fromOffsetCache$1 = Symbol("fromOffsetCache");
3114
+ let lineToIndexCache$1 = Symbol("lineToIndexCache");
3048
3115
  let sourceMapAvailable$1$1 = Boolean(SourceMapConsumer$1$1 && SourceMapGenerator$1$1);
3049
3116
  let pathAvailable$1$1 = Boolean(resolve$1$1 && isAbsolute$1);
3117
+ function getLineToIndex$1(input2) {
3118
+ if (input2[lineToIndexCache$1]) return input2[lineToIndexCache$1];
3119
+ let lines = input2.css.split("\n");
3120
+ let lineToIndex = new Array(lines.length);
3121
+ let prevIndex = 0;
3122
+ for (let i2 = 0, l2 = lines.length; i2 < l2; i2++) {
3123
+ lineToIndex[i2] = prevIndex;
3124
+ prevIndex += lines[i2].length + 1;
3125
+ }
3126
+ input2[lineToIndexCache$1] = lineToIndex;
3127
+ return lineToIndex;
3128
+ }
3050
3129
  let Input$4$1 = class Input {
3051
3130
  get from() {
3052
3131
  return this.file || this.id;
@@ -3085,30 +3164,37 @@ let Input$4$1 = class Input {
3085
3164
  if (this.map) this.map.file = this.from;
3086
3165
  }
3087
3166
  error(message, line, column, opts = {}) {
3088
- let endColumn, endLine, result2;
3167
+ let endColumn, endLine, endOffset, offset, result2;
3089
3168
  if (line && typeof line === "object") {
3090
3169
  let start = line;
3091
3170
  let end = column;
3092
3171
  if (typeof start.offset === "number") {
3093
- let pos = this.fromOffset(start.offset);
3172
+ offset = start.offset;
3173
+ let pos = this.fromOffset(offset);
3094
3174
  line = pos.line;
3095
3175
  column = pos.col;
3096
3176
  } else {
3097
3177
  line = start.line;
3098
3178
  column = start.column;
3179
+ offset = this.fromLineAndColumn(line, column);
3099
3180
  }
3100
3181
  if (typeof end.offset === "number") {
3101
- let pos = this.fromOffset(end.offset);
3182
+ endOffset = end.offset;
3183
+ let pos = this.fromOffset(endOffset);
3102
3184
  endLine = pos.line;
3103
3185
  endColumn = pos.col;
3104
3186
  } else {
3105
3187
  endLine = end.line;
3106
3188
  endColumn = end.column;
3189
+ endOffset = this.fromLineAndColumn(end.line, end.column);
3107
3190
  }
3108
3191
  } else if (!column) {
3109
- let pos = this.fromOffset(line);
3192
+ offset = line;
3193
+ let pos = this.fromOffset(offset);
3110
3194
  line = pos.line;
3111
3195
  column = pos.col;
3196
+ } else {
3197
+ offset = this.fromLineAndColumn(line, column);
3112
3198
  }
3113
3199
  let origin = this.origin(line, column, endLine, endColumn);
3114
3200
  if (origin) {
@@ -3130,7 +3216,7 @@ let Input$4$1 = class Input {
3130
3216
  opts.plugin
3131
3217
  );
3132
3218
  }
3133
- result2.input = { column, endColumn, endLine, line, source: this.css };
3219
+ result2.input = { column, endColumn, endLine, endOffset, line, offset, source: this.css };
3134
3220
  if (this.file) {
3135
3221
  if (pathToFileURL$1$1) {
3136
3222
  result2.input.url = pathToFileURL$1$1(this.file).toString();
@@ -3139,21 +3225,14 @@ let Input$4$1 = class Input {
3139
3225
  }
3140
3226
  return result2;
3141
3227
  }
3228
+ fromLineAndColumn(line, column) {
3229
+ let lineToIndex = getLineToIndex$1(this);
3230
+ let index2 = lineToIndex[line - 1];
3231
+ return index2 + column - 1;
3232
+ }
3142
3233
  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];
3234
+ let lineToIndex = getLineToIndex$1(this);
3235
+ let lastLine = lineToIndex[lineToIndex.length - 1];
3157
3236
  let min = 0;
3158
3237
  if (offset >= lastLine) {
3159
3238
  min = lineToIndex.length - 1;
@@ -4515,7 +4594,7 @@ let Result$3$1 = class Result {
4515
4594
  this.messages = [];
4516
4595
  this.root = root2;
4517
4596
  this.opts = opts;
4518
- this.css = void 0;
4597
+ this.css = "";
4519
4598
  this.map = void 0;
4520
4599
  }
4521
4600
  toString() {
@@ -5127,7 +5206,7 @@ let NoWorkResult2$1 = noWorkResult$1;
5127
5206
  let Root$1$1 = root$1;
5128
5207
  let Processor$1$1 = class Processor {
5129
5208
  constructor(plugins = []) {
5130
- this.version = "8.5.3";
5209
+ this.version = "8.5.6";
5131
5210
  this.plugins = this.normalize(plugins);
5132
5211
  }
5133
5212
  normalize(plugins) {
@@ -5495,13 +5574,12 @@ function buildNode(n2, options) {
5495
5574
  const value = specialAttributes[name];
5496
5575
  if (tagName === "canvas" && name === "rr_dataURL") {
5497
5576
  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
5577
  image.src = value.toString();
5578
+ const ctx = node2.getContext("2d");
5579
+ if (ctx) {
5580
+ wrapCanvasContextDrawImage$2(ctx);
5581
+ ctx.drawImage(image, 0, 0);
5582
+ }
5505
5583
  if (node2.RRNodeType)
5506
5584
  node2.rr_dataURL = value.toString();
5507
5585
  } else if (tagName === "img" && name === "rr_dataURL") {
@@ -6370,7 +6448,7 @@ let Node$4 = class Node3 {
6370
6448
  let index2 = this.parent.index(this);
6371
6449
  return this.parent.nodes[index2 + 1];
6372
6450
  }
6373
- positionBy(opts) {
6451
+ positionBy(opts = {}) {
6374
6452
  let pos = this.source.start;
6375
6453
  if (opts.index) {
6376
6454
  pos = this.positionInside(opts.index);
@@ -6399,27 +6477,38 @@ let Node$4 = class Node3 {
6399
6477
  column += 1;
6400
6478
  }
6401
6479
  }
6402
- return { column, line };
6480
+ return { column, line, offset: end };
6403
6481
  }
6404
6482
  prev() {
6405
6483
  if (!this.parent) return void 0;
6406
6484
  let index2 = this.parent.index(this);
6407
6485
  return this.parent.nodes[index2 - 1];
6408
6486
  }
6409
- rangeBy(opts) {
6487
+ rangeBy(opts = {}) {
6488
+ let inputString = "document" in this.source.input ? this.source.input.document : this.source.input.css;
6410
6489
  let start = {
6411
6490
  column: this.source.start.column,
6412
- line: this.source.start.line
6491
+ line: this.source.start.line,
6492
+ offset: sourceOffset(inputString, this.source.start)
6413
6493
  };
6414
6494
  let end = this.source.end ? {
6415
6495
  column: this.source.end.column + 1,
6416
- line: this.source.end.line
6496
+ line: this.source.end.line,
6497
+ offset: typeof this.source.end.offset === "number" ? (
6498
+ // `source.end.offset` is exclusive, so we don't need to add 1
6499
+ this.source.end.offset
6500
+ ) : (
6501
+ // Since line/column in this.source.end is inclusive,
6502
+ // the `sourceOffset(... , this.source.end)` returns an inclusive offset.
6503
+ // So, we add 1 to convert it to exclusive.
6504
+ sourceOffset(inputString, this.source.end) + 1
6505
+ )
6417
6506
  } : {
6418
6507
  column: start.column + 1,
6419
- line: start.line
6508
+ line: start.line,
6509
+ offset: start.offset + 1
6420
6510
  };
6421
6511
  if (opts.word) {
6422
- let inputString = "document" in this.source.input ? this.source.input.document : this.source.input.css;
6423
6512
  let stringRepresentation = inputString.slice(
6424
6513
  sourceOffset(inputString, this.source.start),
6425
6514
  sourceOffset(inputString, this.source.end)
@@ -6427,15 +6516,14 @@ let Node$4 = class Node3 {
6427
6516
  let index2 = stringRepresentation.indexOf(opts.word);
6428
6517
  if (index2 !== -1) {
6429
6518
  start = this.positionInside(index2);
6430
- end = this.positionInside(
6431
- index2 + opts.word.length
6432
- );
6519
+ end = this.positionInside(index2 + opts.word.length);
6433
6520
  }
6434
6521
  } else {
6435
6522
  if (opts.start) {
6436
6523
  start = {
6437
6524
  column: opts.start.column,
6438
- line: opts.start.line
6525
+ line: opts.start.line,
6526
+ offset: sourceOffset(inputString, opts.start)
6439
6527
  };
6440
6528
  } else if (opts.index) {
6441
6529
  start = this.positionInside(opts.index);
@@ -6443,7 +6531,8 @@ let Node$4 = class Node3 {
6443
6531
  if (opts.end) {
6444
6532
  end = {
6445
6533
  column: opts.end.column,
6446
- line: opts.end.line
6534
+ line: opts.end.line,
6535
+ offset: sourceOffset(inputString, opts.end)
6447
6536
  };
6448
6537
  } else if (typeof opts.endIndex === "number") {
6449
6538
  end = this.positionInside(opts.endIndex);
@@ -6452,7 +6541,11 @@ let Node$4 = class Node3 {
6452
6541
  }
6453
6542
  }
6454
6543
  if (end.line < start.line || end.line === start.line && end.column <= start.column) {
6455
- end = { column: start.column + 1, line: start.line };
6544
+ end = {
6545
+ column: start.column + 1,
6546
+ line: start.line,
6547
+ offset: start.offset + 1
6548
+ };
6456
6549
  }
6457
6550
  return { end, start };
6458
6551
  }
@@ -6516,6 +6609,7 @@ let Node$4 = class Node3 {
6516
6609
  } else if (typeof value === "object" && value.toJSON) {
6517
6610
  fixed[name] = value.toJSON(null, inputs);
6518
6611
  } else if (name === "source") {
6612
+ if (value == null) continue;
6519
6613
  let inputId = inputs.get(value.input);
6520
6614
  if (inputId == null) {
6521
6615
  inputId = inputsNextIndex;
@@ -6550,7 +6644,7 @@ let Node$4 = class Node3 {
6550
6644
  });
6551
6645
  return result2;
6552
6646
  }
6553
- warn(result2, text, opts) {
6647
+ warn(result2, text, opts = {}) {
6554
6648
  let data = { node: this };
6555
6649
  for (let i2 in opts) data[i2] = opts[i2];
6556
6650
  return result2.warn(text, data);
@@ -7131,9 +7225,21 @@ let { fileURLToPath, pathToFileURL: pathToFileURL$1 } = require$$2;
7131
7225
  let CssSyntaxError$1 = cssSyntaxError;
7132
7226
  let PreviousMap$1 = previousMap;
7133
7227
  let terminalHighlight = require$$2;
7134
- let fromOffsetCache = Symbol("fromOffsetCache");
7228
+ let lineToIndexCache = Symbol("lineToIndexCache");
7135
7229
  let sourceMapAvailable$1 = Boolean(SourceMapConsumer$1 && SourceMapGenerator$1);
7136
7230
  let pathAvailable$1 = Boolean(resolve$1 && isAbsolute);
7231
+ function getLineToIndex(input2) {
7232
+ if (input2[lineToIndexCache]) return input2[lineToIndexCache];
7233
+ let lines = input2.css.split("\n");
7234
+ let lineToIndex = new Array(lines.length);
7235
+ let prevIndex = 0;
7236
+ for (let i2 = 0, l2 = lines.length; i2 < l2; i2++) {
7237
+ lineToIndex[i2] = prevIndex;
7238
+ prevIndex += lines[i2].length + 1;
7239
+ }
7240
+ input2[lineToIndexCache] = lineToIndex;
7241
+ return lineToIndex;
7242
+ }
7137
7243
  let Input$4 = class Input2 {
7138
7244
  get from() {
7139
7245
  return this.file || this.id;
@@ -7172,30 +7278,37 @@ let Input$4 = class Input2 {
7172
7278
  if (this.map) this.map.file = this.from;
7173
7279
  }
7174
7280
  error(message, line, column, opts = {}) {
7175
- let endColumn, endLine, result2;
7281
+ let endColumn, endLine, endOffset, offset, result2;
7176
7282
  if (line && typeof line === "object") {
7177
7283
  let start = line;
7178
7284
  let end = column;
7179
7285
  if (typeof start.offset === "number") {
7180
- let pos = this.fromOffset(start.offset);
7286
+ offset = start.offset;
7287
+ let pos = this.fromOffset(offset);
7181
7288
  line = pos.line;
7182
7289
  column = pos.col;
7183
7290
  } else {
7184
7291
  line = start.line;
7185
7292
  column = start.column;
7293
+ offset = this.fromLineAndColumn(line, column);
7186
7294
  }
7187
7295
  if (typeof end.offset === "number") {
7188
- let pos = this.fromOffset(end.offset);
7296
+ endOffset = end.offset;
7297
+ let pos = this.fromOffset(endOffset);
7189
7298
  endLine = pos.line;
7190
7299
  endColumn = pos.col;
7191
7300
  } else {
7192
7301
  endLine = end.line;
7193
7302
  endColumn = end.column;
7303
+ endOffset = this.fromLineAndColumn(end.line, end.column);
7194
7304
  }
7195
7305
  } else if (!column) {
7196
- let pos = this.fromOffset(line);
7306
+ offset = line;
7307
+ let pos = this.fromOffset(offset);
7197
7308
  line = pos.line;
7198
7309
  column = pos.col;
7310
+ } else {
7311
+ offset = this.fromLineAndColumn(line, column);
7199
7312
  }
7200
7313
  let origin = this.origin(line, column, endLine, endColumn);
7201
7314
  if (origin) {
@@ -7217,7 +7330,7 @@ let Input$4 = class Input2 {
7217
7330
  opts.plugin
7218
7331
  );
7219
7332
  }
7220
- result2.input = { column, endColumn, endLine, line, source: this.css };
7333
+ result2.input = { column, endColumn, endLine, endOffset, line, offset, source: this.css };
7221
7334
  if (this.file) {
7222
7335
  if (pathToFileURL$1) {
7223
7336
  result2.input.url = pathToFileURL$1(this.file).toString();
@@ -7226,21 +7339,14 @@ let Input$4 = class Input2 {
7226
7339
  }
7227
7340
  return result2;
7228
7341
  }
7342
+ fromLineAndColumn(line, column) {
7343
+ let lineToIndex = getLineToIndex(this);
7344
+ let index2 = lineToIndex[line - 1];
7345
+ return index2 + column - 1;
7346
+ }
7229
7347
  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];
7348
+ let lineToIndex = getLineToIndex(this);
7349
+ let lastLine = lineToIndex[lineToIndex.length - 1];
7244
7350
  let min = 0;
7245
7351
  if (offset >= lastLine) {
7246
7352
  min = lineToIndex.length - 1;
@@ -8602,7 +8708,7 @@ let Result$3 = class Result2 {
8602
8708
  this.messages = [];
8603
8709
  this.root = root2;
8604
8710
  this.opts = opts;
8605
- this.css = void 0;
8711
+ this.css = "";
8606
8712
  this.map = void 0;
8607
8713
  }
8608
8714
  toString() {
@@ -9214,7 +9320,7 @@ let NoWorkResult22 = noWorkResult;
9214
9320
  let Root$1 = root;
9215
9321
  let Processor$1 = class Processor2 {
9216
9322
  constructor(plugins = []) {
9217
- this.version = "8.5.3";
9323
+ this.version = "8.5.6";
9218
9324
  this.plugins = this.normalize(plugins);
9219
9325
  }
9220
9326
  normalize(plugins) {
@@ -9898,6 +10004,53 @@ var NodeType$2 = /* @__PURE__ */ ((NodeType2) => {
9898
10004
  NodeType2[NodeType2["DOCUMENT_FRAGMENT_NODE"] = 11] = "DOCUMENT_FRAGMENT_NODE";
9899
10005
  return NodeType2;
9900
10006
  })(NodeType$2 || {});
10007
+ const pendingImageLoads$1 = /* @__PURE__ */ new Map();
10008
+ const wrappedContexts$1 = /* @__PURE__ */ new WeakSet();
10009
+ function isHTMLImageElement$1(img) {
10010
+ return img !== null && typeof img === "object" && "complete" in img && "naturalWidth" in img && "naturalHeight" in img && "src" in img && "onload" in img;
10011
+ }
10012
+ function wrapCanvasContextDrawImage$1(ctx) {
10013
+ if (wrappedContexts$1.has(ctx)) {
10014
+ return;
10015
+ }
10016
+ wrappedContexts$1.add(ctx);
10017
+ const originalDrawImage = ctx.drawImage.bind(ctx);
10018
+ ctx.drawImage = function(image, ...args) {
10019
+ const pending = pendingImageLoads$1.get(ctx);
10020
+ if (pending) {
10021
+ pending.cancelled = true;
10022
+ }
10023
+ const drawImageWithArgs = () => {
10024
+ if (args.length === 2 && isHTMLImageElement$1(image)) {
10025
+ args.push(image.naturalWidth || image.width, image.naturalHeight || image.height);
10026
+ }
10027
+ originalDrawImage(image, ...args);
10028
+ };
10029
+ if (isHTMLImageElement$1(image) && !image.complete) {
10030
+ const loadState = { cancelled: false };
10031
+ pendingImageLoads$1.set(ctx, loadState);
10032
+ const onLoad = () => {
10033
+ if (!loadState.cancelled) {
10034
+ pendingImageLoads$1.delete(ctx);
10035
+ drawImageWithArgs();
10036
+ }
10037
+ };
10038
+ const onError = () => {
10039
+ if (!loadState.cancelled) {
10040
+ pendingImageLoads$1.delete(ctx);
10041
+ try {
10042
+ drawImageWithArgs();
10043
+ } catch (e2) {
10044
+ }
10045
+ }
10046
+ };
10047
+ image.onload = onLoad;
10048
+ image.onerror = onError;
10049
+ } else {
10050
+ drawImageWithArgs();
10051
+ }
10052
+ };
10053
+ }
9901
10054
  const NAMESPACES = {
9902
10055
  svg: "http://www.w3.org/2000/svg",
9903
10056
  "xlink:href": "http://www.w3.org/1999/xlink",
@@ -10051,13 +10204,12 @@ function diffAfterUpdatingChildren(oldTree, newTree, replayer) {
10051
10204
  const rrCanvasElement = newTree;
10052
10205
  if (rrCanvasElement.rr_dataURL !== null) {
10053
10206
  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
10207
  image.src = rrCanvasElement.rr_dataURL;
10208
+ const ctx = oldElement.getContext("2d");
10209
+ if (ctx) {
10210
+ wrapCanvasContextDrawImage$1(ctx);
10211
+ ctx.drawImage(image, 0, 0);
10212
+ }
10061
10213
  }
10062
10214
  rrCanvasElement.canvasMutations.forEach(
10063
10215
  (canvasMutation2) => replayer.applyCanvas(
@@ -10122,12 +10274,11 @@ function diffProps(oldTree, newTree, rrnodeMirror) {
10122
10274
  else if (newTree.tagName === "CANVAS" && name === "rr_dataURL") {
10123
10275
  const image = document.createElement("img");
10124
10276
  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
- };
10277
+ const ctx = oldTree.getContext("2d");
10278
+ if (ctx) {
10279
+ wrapCanvasContextDrawImage$1(ctx);
10280
+ ctx.drawImage(image, 0, 0);
10281
+ }
10131
10282
  } else if (newTree.tagName === "IFRAME" && name === "srcdoc") continue;
10132
10283
  else {
10133
10284
  try {
@@ -10638,6 +10789,53 @@ function getDefaultSN(node2, id) {
10638
10789
  };
10639
10790
  }
10640
10791
  }
10792
+ const pendingImageLoads = /* @__PURE__ */ new Map();
10793
+ const wrappedContexts = /* @__PURE__ */ new WeakSet();
10794
+ function isHTMLImageElement(img) {
10795
+ return img !== null && typeof img === "object" && "complete" in img && "naturalWidth" in img && "naturalHeight" in img && "src" in img && "onload" in img;
10796
+ }
10797
+ function wrapCanvasContextDrawImage(ctx) {
10798
+ if (wrappedContexts.has(ctx)) {
10799
+ return;
10800
+ }
10801
+ wrappedContexts.add(ctx);
10802
+ const originalDrawImage = ctx.drawImage.bind(ctx);
10803
+ ctx.drawImage = function(image, ...args) {
10804
+ const pending = pendingImageLoads.get(ctx);
10805
+ if (pending) {
10806
+ pending.cancelled = true;
10807
+ }
10808
+ const drawImageWithArgs = () => {
10809
+ if (args.length === 2 && isHTMLImageElement(image)) {
10810
+ args.push(image.naturalWidth || image.width, image.naturalHeight || image.height);
10811
+ }
10812
+ originalDrawImage(image, ...args);
10813
+ };
10814
+ if (isHTMLImageElement(image) && !image.complete) {
10815
+ const loadState = { cancelled: false };
10816
+ pendingImageLoads.set(ctx, loadState);
10817
+ const onLoad = () => {
10818
+ if (!loadState.cancelled) {
10819
+ pendingImageLoads.delete(ctx);
10820
+ drawImageWithArgs();
10821
+ }
10822
+ };
10823
+ const onError = () => {
10824
+ if (!loadState.cancelled) {
10825
+ pendingImageLoads.delete(ctx);
10826
+ try {
10827
+ drawImageWithArgs();
10828
+ } catch (e2) {
10829
+ }
10830
+ }
10831
+ };
10832
+ image.onload = onLoad;
10833
+ image.onerror = onError;
10834
+ } else {
10835
+ drawImageWithArgs();
10836
+ }
10837
+ };
10838
+ }
10641
10839
  const testableAccessors = {
10642
10840
  Node: ["childNodes", "parentNode", "parentElement", "textContent"],
10643
10841
  ShadowRoot: ["host", "styleSheets"],
@@ -10805,7 +11003,8 @@ const index = {
10805
11003
  querySelector,
10806
11004
  querySelectorAll,
10807
11005
  mutationObserver: mutationObserverCtor,
10808
- patch
11006
+ patch,
11007
+ wrapCanvasContextDrawImage
10809
11008
  };
10810
11009
  function on(type, fn, target = document) {
10811
11010
  const options = { capture: true };
@@ -15646,6 +15845,7 @@ async function canvasMutation$1({
15646
15845
  errorHandler2(mutations[0], new Error("Canvas context is null"));
15647
15846
  return;
15648
15847
  }
15848
+ wrapCanvasContextDrawImage(ctx);
15649
15849
  const mutationArgsPromises = mutations.map(
15650
15850
  async (mutation) => {
15651
15851
  return Promise.all(mutation.args.map(deserializeArg(imageMap, ctx)));
@@ -16661,6 +16861,7 @@ class Replayer {
16661
16861
  this.usingVirtualDom = false;
16662
16862
  }
16663
16863
  this.mirror.reset();
16864
+ this.newDocumentQueue = [];
16664
16865
  rebuild(event.data.node, {
16665
16866
  doc: this.iframe.contentDocument,
16666
16867
  afterAppend,