@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.
@@ -488,20 +488,57 @@ function normalizeCssString(cssText) {
488
488
  function splitCssText(cssText, style) {
489
489
  const childNodes2 = Array.from(style.childNodes);
490
490
  const splits = [];
491
+ let iterLimit = 0;
491
492
  if (childNodes2.length > 1 && cssText && typeof cssText === "string") {
492
- const cssTextNorm = normalizeCssString(cssText);
493
+ let cssTextNorm = normalizeCssString(cssText);
494
+ const normFactor = cssTextNorm.length / cssText.length;
493
495
  for (let i2 = 1; i2 < childNodes2.length; i2++) {
494
496
  if (childNodes2[i2].textContent && typeof childNodes2[i2].textContent === "string") {
495
497
  const textContentNorm = normalizeCssString(childNodes2[i2].textContent);
496
- for (let j = 3; j < textContentNorm.length; j++) {
498
+ let j = 3;
499
+ for (; j < textContentNorm.length; j++) {
500
+ if (
501
+ // keep consuming css identifiers (to get a decent chunk more quickly)
502
+ textContentNorm[j].match(/[a-zA-Z0-9]/) || // substring needs to be unique to this section
503
+ textContentNorm.indexOf(textContentNorm.substring(0, j), 1) !== -1
504
+ ) {
505
+ continue;
506
+ }
507
+ break;
508
+ }
509
+ for (; j < textContentNorm.length; j++) {
497
510
  const bit = textContentNorm.substring(0, j);
498
- if (cssTextNorm.split(bit).length === 2) {
499
- const splitNorm = cssTextNorm.indexOf(bit);
500
- for (let k = splitNorm; k < cssText.length; k++) {
501
- if (normalizeCssString(cssText.substring(0, k)).length === splitNorm) {
511
+ const bits = cssTextNorm.split(bit);
512
+ let splitNorm = -1;
513
+ if (bits.length === 2) {
514
+ splitNorm = cssTextNorm.indexOf(bit);
515
+ } else if (bits.length > 2 && bits[0] === "" && childNodes2[i2 - 1].textContent !== "") {
516
+ splitNorm = cssTextNorm.indexOf(bit, 1);
517
+ }
518
+ if (splitNorm !== -1) {
519
+ let k = Math.floor(splitNorm / normFactor);
520
+ for (; k > 0 && k < cssText.length; ) {
521
+ iterLimit += 1;
522
+ if (iterLimit > 50 * childNodes2.length) {
523
+ splits.push(cssText);
524
+ return splits;
525
+ }
526
+ const normPart = normalizeCssString(cssText.substring(0, k));
527
+ if (normPart.length === splitNorm) {
502
528
  splits.push(cssText.substring(0, k));
503
529
  cssText = cssText.substring(k);
530
+ cssTextNorm = cssTextNorm.substring(splitNorm);
504
531
  break;
532
+ } else if (normPart.length < splitNorm) {
533
+ k += Math.max(
534
+ 1,
535
+ Math.floor((splitNorm - normPart.length) / normFactor)
536
+ );
537
+ } else {
538
+ k -= Math.max(
539
+ 1,
540
+ Math.floor((normPart.length - splitNorm) * normFactor)
541
+ );
505
542
  }
506
543
  }
507
544
  break;