@screeb/rrweb 1.0.7 → 1.0.8

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
@@ -443,20 +443,57 @@ function normalizeCssString(cssText) {
443
443
  function splitCssText(cssText, style) {
444
444
  const childNodes2 = Array.from(style.childNodes);
445
445
  const splits = [];
446
+ let iterLimit = 0;
446
447
  if (childNodes2.length > 1 && cssText && typeof cssText === "string") {
447
- const cssTextNorm = normalizeCssString(cssText);
448
+ let cssTextNorm = normalizeCssString(cssText);
449
+ const normFactor = cssTextNorm.length / cssText.length;
448
450
  for (let i2 = 1; i2 < childNodes2.length; i2++) {
449
451
  if (childNodes2[i2].textContent && typeof childNodes2[i2].textContent === "string") {
450
452
  const textContentNorm = normalizeCssString(childNodes2[i2].textContent);
451
- for (let j = 3; j < textContentNorm.length; j++) {
453
+ let j = 3;
454
+ for (; j < textContentNorm.length; j++) {
455
+ if (
456
+ // keep consuming css identifiers (to get a decent chunk more quickly)
457
+ textContentNorm[j].match(/[a-zA-Z0-9]/) || // substring needs to be unique to this section
458
+ textContentNorm.indexOf(textContentNorm.substring(0, j), 1) !== -1
459
+ ) {
460
+ continue;
461
+ }
462
+ break;
463
+ }
464
+ for (; j < textContentNorm.length; j++) {
452
465
  const bit = textContentNorm.substring(0, j);
453
- if (cssTextNorm.split(bit).length === 2) {
454
- const splitNorm = cssTextNorm.indexOf(bit);
455
- for (let k = splitNorm; k < cssText.length; k++) {
456
- if (normalizeCssString(cssText.substring(0, k)).length === splitNorm) {
466
+ const bits = cssTextNorm.split(bit);
467
+ let splitNorm = -1;
468
+ if (bits.length === 2) {
469
+ splitNorm = cssTextNorm.indexOf(bit);
470
+ } else if (bits.length > 2 && bits[0] === "" && childNodes2[i2 - 1].textContent !== "") {
471
+ splitNorm = cssTextNorm.indexOf(bit, 1);
472
+ }
473
+ if (splitNorm !== -1) {
474
+ let k = Math.floor(splitNorm / normFactor);
475
+ for (; k > 0 && k < cssText.length; ) {
476
+ iterLimit += 1;
477
+ if (iterLimit > 50 * childNodes2.length) {
478
+ splits.push(cssText);
479
+ return splits;
480
+ }
481
+ const normPart = normalizeCssString(cssText.substring(0, k));
482
+ if (normPart.length === splitNorm) {
457
483
  splits.push(cssText.substring(0, k));
458
484
  cssText = cssText.substring(k);
485
+ cssTextNorm = cssTextNorm.substring(splitNorm);
459
486
  break;
487
+ } else if (normPart.length < splitNorm) {
488
+ k += Math.max(
489
+ 1,
490
+ Math.floor((splitNorm - normPart.length) / normFactor)
491
+ );
492
+ } else {
493
+ k -= Math.max(
494
+ 1,
495
+ Math.floor((normPart.length - splitNorm) * normFactor)
496
+ );
460
497
  }
461
498
  }
462
499
  break;