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