@glimt/record 0.0.48 → 0.0.49

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/record.js CHANGED
@@ -425,6 +425,9 @@ const index = {
425
425
  mutationObserver: mutationObserverCtor,
426
426
  patch
427
427
  };
428
+ const shouldTryAnonymousFetchingOnCorsError$1 = () => {
429
+ return !("_rrweb_skip_re_fetching_to_suppress_cors_errors" in window && window._rrweb_skip_re_fetching_to_suppress_cors_errors === true);
430
+ };
428
431
  function isElement(n2) {
429
432
  return n2.nodeType === n2.ELEMENT_NODE;
430
433
  }
@@ -441,7 +444,7 @@ function isShadowRoot(n2) {
441
444
  function isNativeShadowDom(shadowRoot2) {
442
445
  return Object.prototype.toString.call(shadowRoot2) === "[object ShadowRoot]";
443
446
  }
444
- function fixBrowserCompatibilityIssuesInCSS(cssText) {
447
+ function fixBrowserCompatibilityIssuesInCSS$1(cssText) {
445
448
  if (cssText.includes(" background-clip: text;") && !cssText.includes(" -webkit-background-clip: text;")) {
446
449
  cssText = cssText.replace(
447
450
  /\sbackground-clip:\s*text;/g,
@@ -450,7 +453,7 @@ function fixBrowserCompatibilityIssuesInCSS(cssText) {
450
453
  }
451
454
  return cssText;
452
455
  }
453
- function escapeImportStatement(rule2) {
456
+ function escapeImportStatement$1(rule2) {
454
457
  const { cssText } = rule2;
455
458
  if (cssText.split('"').length < 3) return cssText;
456
459
  const statement = ["@import", `url(${JSON.stringify(rule2.href)})`];
@@ -467,7 +470,7 @@ function escapeImportStatement(rule2) {
467
470
  }
468
471
  return statement.join(" ") + ";";
469
472
  }
470
- function stringifyStylesheet(s2) {
473
+ function stringifyStylesheet$1(s2) {
471
474
  try {
472
475
  const rules2 = s2.rules || s2.cssRules;
473
476
  if (!rules2) {
@@ -479,47 +482,47 @@ function stringifyStylesheet(s2) {
479
482
  }
480
483
  const stringifiedRules = Array.from(
481
484
  rules2,
482
- (rule2) => stringifyRule(rule2, sheetHref)
485
+ (rule2) => stringifyRule$1(rule2, sheetHref)
483
486
  ).join("");
484
- return fixBrowserCompatibilityIssuesInCSS(stringifiedRules);
487
+ return fixBrowserCompatibilityIssuesInCSS$1(stringifiedRules);
485
488
  } catch (error) {
486
489
  return null;
487
490
  }
488
491
  }
489
- function stringifyRule(rule2, sheetHref) {
490
- if (isCSSImportRule(rule2)) {
492
+ function stringifyRule$1(rule2, sheetHref) {
493
+ if (isCSSImportRule$1(rule2)) {
491
494
  let importStringified;
492
495
  try {
493
496
  importStringified = // for same-origin stylesheets,
494
497
  // we can access the imported stylesheet rules directly
495
- stringifyStylesheet(rule2.styleSheet) || // work around browser issues with the raw string `@import url(...)` statement
496
- escapeImportStatement(rule2);
498
+ stringifyStylesheet$1(rule2.styleSheet) || // work around browser issues with the raw string `@import url(...)` statement
499
+ escapeImportStatement$1(rule2);
497
500
  } catch (error) {
498
501
  importStringified = rule2.cssText;
499
502
  }
500
503
  if (rule2.styleSheet.href) {
501
- return absolutifyURLs(importStringified, rule2.styleSheet.href);
504
+ return absolutifyURLs$1(importStringified, rule2.styleSheet.href);
502
505
  }
503
506
  return importStringified;
504
507
  } else {
505
508
  let ruleStringified = rule2.cssText;
506
- if (isCSSStyleRule(rule2) && rule2.selectorText.includes(":")) {
507
- ruleStringified = fixSafariColons(ruleStringified);
509
+ if (isCSSStyleRule$1(rule2) && rule2.selectorText.includes(":")) {
510
+ ruleStringified = fixSafariColons$1(ruleStringified);
508
511
  }
509
512
  if (sheetHref) {
510
- return absolutifyURLs(ruleStringified, sheetHref);
513
+ return absolutifyURLs$1(ruleStringified, sheetHref);
511
514
  }
512
515
  return ruleStringified;
513
516
  }
514
517
  }
515
- function fixSafariColons(cssStringified) {
518
+ function fixSafariColons$1(cssStringified) {
516
519
  const regex = /(\[(?:[\w-]+)[^\\])(:(?:[\w-]+)\])/gm;
517
520
  return cssStringified.replace(regex, "$1\\$2");
518
521
  }
519
- function isCSSImportRule(rule2) {
522
+ function isCSSImportRule$1(rule2) {
520
523
  return "styleSheet" in rule2;
521
524
  }
522
- function isCSSStyleRule(rule2) {
525
+ function isCSSStyleRule$1(rule2) {
523
526
  return "selectorText" in rule2;
524
527
  }
525
528
  class Mirror {
@@ -656,7 +659,7 @@ function extractFileExtension(path, baseURL) {
656
659
  const match = url.pathname.match(regex);
657
660
  return (match == null ? void 0 : match[1]) ?? null;
658
661
  }
659
- function extractOrigin(url) {
662
+ function extractOrigin$1(url) {
660
663
  let origin = "";
661
664
  if (url.indexOf("//") > -1) {
662
665
  origin = url.split("/").slice(0, 3).join("/");
@@ -666,27 +669,27 @@ function extractOrigin(url) {
666
669
  origin = origin.split("?")[0];
667
670
  return origin;
668
671
  }
669
- const URL_IN_CSS_REF = /url\((?:(')([^']*)'|(")(.*?)"|([^)]*))\)/gm;
670
- const URL_PROTOCOL_MATCH = /^(?:[a-z+]+:)?\/\//i;
671
- const URL_WWW_MATCH = /^www\..*/i;
672
- const DATA_URI = /^(data:)([^,]*),(.*)/i;
673
- function absolutifyURLs(cssText, href) {
672
+ const URL_IN_CSS_REF$1 = /url\((?:(')([^']*)'|(")(.*?)"|([^)]*))\)/gm;
673
+ const URL_PROTOCOL_MATCH$1 = /^(?:[a-z+]+:)?\/\//i;
674
+ const URL_WWW_MATCH$1 = /^www\..*/i;
675
+ const DATA_URI$1 = /^(data:)([^,]*),(.*)/i;
676
+ function absolutifyURLs$1(cssText, href) {
674
677
  return (cssText || "").replace(
675
- URL_IN_CSS_REF,
678
+ URL_IN_CSS_REF$1,
676
679
  (origin, quote1, path1, quote2, path2, path3) => {
677
680
  const filePath = path1 || path2 || path3;
678
681
  const maybeQuote = quote1 || quote2 || "";
679
682
  if (!filePath) {
680
683
  return origin;
681
684
  }
682
- if (URL_PROTOCOL_MATCH.test(filePath) || URL_WWW_MATCH.test(filePath)) {
685
+ if (URL_PROTOCOL_MATCH$1.test(filePath) || URL_WWW_MATCH$1.test(filePath)) {
683
686
  return `url(${maybeQuote}${filePath}${maybeQuote})`;
684
687
  }
685
- if (DATA_URI.test(filePath)) {
688
+ if (DATA_URI$1.test(filePath)) {
686
689
  return `url(${maybeQuote}${filePath}${maybeQuote})`;
687
690
  }
688
691
  if (filePath[0] === "/") {
689
- return `url(${maybeQuote}${extractOrigin(href) + filePath}${maybeQuote})`;
692
+ return `url(${maybeQuote}${extractOrigin$1(href) + filePath}${maybeQuote})`;
690
693
  }
691
694
  const stack = href.split("/");
692
695
  const parts = filePath.split("/");
@@ -809,6 +812,190 @@ function splitCssText(cssText, style, _testNoPxNorm = false) {
809
812
  function markCssSplits(cssText, style) {
810
813
  return splitCssText(cssText, style).join("/* rr_split */");
811
814
  }
815
+ const CLEANUP_DEBOUNCE_TIME$1 = 1e3 * 30;
816
+ const DATA_ATTRIBUTE_CLONED_NAME$1 = "data-rrweb-link-cloned";
817
+ const DISALLOWED_EXTENSIONS$1 = [
818
+ // Fonts
819
+ "woff",
820
+ "woff2",
821
+ "ttf",
822
+ "otf",
823
+ // Embedded OpenType font
824
+ "eot",
825
+ // Images
826
+ "png",
827
+ "jpg",
828
+ "jpeg",
829
+ "gif",
830
+ "svg",
831
+ "webp",
832
+ "ico",
833
+ // Scripts
834
+ "js",
835
+ "mjs",
836
+ "ts",
837
+ "jsx",
838
+ "tsx",
839
+ // Data files
840
+ "json",
841
+ "map",
842
+ // Media
843
+ "mp4",
844
+ "webm",
845
+ "ogg",
846
+ "mp3",
847
+ "wav",
848
+ // Archives
849
+ "zip",
850
+ "rar",
851
+ "7z",
852
+ "tar",
853
+ "gz",
854
+ // Documents
855
+ "pdf",
856
+ "doc",
857
+ "docx",
858
+ "xls",
859
+ "xlsx"
860
+ ];
861
+ const _AsyncStylesheetManager$1 = class _AsyncStylesheetManager {
862
+ constructor() {
863
+ __publicField$1(this, "currentHref", null);
864
+ __publicField$1(this, "clones", {});
865
+ __publicField$1(this, "cleanTimeout", null);
866
+ if (_AsyncStylesheetManager.instance) return _AsyncStylesheetManager.instance;
867
+ _AsyncStylesheetManager.instance = this;
868
+ }
869
+ removeCloneNode(href) {
870
+ var _a2;
871
+ if (!(href in this.clones) || this.clones[href] === void 0) return;
872
+ const clone = document.querySelector(
873
+ `link[${DATA_ATTRIBUTE_CLONED_NAME$1}="${this.clones[href].cloneNodeAttrId}"]`
874
+ );
875
+ if (!clone) return;
876
+ (_a2 = clone.parentNode) == null ? void 0 : _a2.removeChild(clone);
877
+ }
878
+ onLoad(href) {
879
+ if (!(href in this.clones) || this.clones[href] === void 0) return;
880
+ const styleSheets2 = Array.from(document.styleSheets);
881
+ let clonedStyleSheet = null;
882
+ for (let i2 = styleSheets2.length - 1; i2 >= 0; i2--) {
883
+ if (styleSheets2[i2].href === href) {
884
+ clonedStyleSheet = styleSheets2[i2];
885
+ break;
886
+ }
887
+ }
888
+ if (!clonedStyleSheet) return this.removeCloneNode(href);
889
+ const newCssText = stringifyStylesheet$1(clonedStyleSheet);
890
+ this.removeCloneNode(href);
891
+ if (!newCssText) return;
892
+ this.clones[href].cssText = newCssText;
893
+ this.clones[href].loaded = true;
894
+ const original = document.querySelector(
895
+ `link[${DATA_ATTRIBUTE_CLONED_NAME$1}="source-${this.clones[href].cloneNodeAttrId}"]`
896
+ );
897
+ if (original) {
898
+ original.setAttribute("data-rrweb-mutation", Date.now().toString());
899
+ original.removeAttribute(DATA_ATTRIBUTE_CLONED_NAME$1);
900
+ } else {
901
+ this.clones[href].original.setAttribute(
902
+ "data-rrweb-mutation",
903
+ Date.now().toString()
904
+ );
905
+ this.clones[href].original.removeAttribute(DATA_ATTRIBUTE_CLONED_NAME$1);
906
+ }
907
+ window.dispatchEvent(
908
+ new CustomEvent("__rrweb_custom_event__", {
909
+ detail: {
910
+ type: 5,
911
+ timestamp: Date.now(),
912
+ data: {
913
+ tag: "async-css-resolution",
914
+ requestCssId: this.clones[href].requestCssId,
915
+ cssText: this.clones[href].cssText
916
+ }
917
+ }
918
+ })
919
+ );
920
+ }
921
+ onLoadError(href) {
922
+ if (!(href in this.clones) || this.clones[href] === void 0) return;
923
+ this.removeCloneNode(href);
924
+ }
925
+ removeAllCloneElements() {
926
+ for (const href of Object.keys(this.clones)) {
927
+ this.removeCloneNode(href);
928
+ }
929
+ }
930
+ onCleanTimeout() {
931
+ asyncStylesheetManager$1.cleanTimeout = null;
932
+ asyncStylesheetManager$1.removeAllCloneElements();
933
+ }
934
+ blowCache() {
935
+ this.removeAllCloneElements();
936
+ this.clones = {};
937
+ }
938
+ requestClone({
939
+ forElement,
940
+ requestCssId
941
+ }) {
942
+ if (!shouldTryAnonymousFetchingOnCorsError$1()) return;
943
+ if (this.currentHref != null && document.location.href !== this.currentHref)
944
+ this.blowCache();
945
+ this.currentHref = document.location.href;
946
+ const href = forElement.href;
947
+ if (!href) return;
948
+ if (href in this.clones && this.clones[href] !== void 0) return;
949
+ if (forElement.getAttribute("crossorigin") === "anonymous") return;
950
+ if (forElement.rel !== "stylesheet") {
951
+ const last = href.split("/").pop();
952
+ if (last && last.includes(".")) {
953
+ const [filename] = last.split("?");
954
+ const ext = filename.split(".").pop();
955
+ if (ext) {
956
+ if (DISALLOWED_EXTENSIONS$1.includes(ext.trim().toLowerCase())) return;
957
+ }
958
+ }
959
+ }
960
+ const clone = forElement.cloneNode();
961
+ const cloneNodeAttrId = Math.random().toString(36).slice(2);
962
+ clone.setAttribute("crossorigin", "anonymous");
963
+ clone.setAttribute(DATA_ATTRIBUTE_CLONED_NAME$1, cloneNodeAttrId);
964
+ forElement.setAttribute(
965
+ DATA_ATTRIBUTE_CLONED_NAME$1,
966
+ `source-${cloneNodeAttrId}`
967
+ );
968
+ document.head.appendChild(clone);
969
+ this.clones[href] = {
970
+ original: forElement,
971
+ clone,
972
+ loaded: false,
973
+ cssText: null,
974
+ cloneNodeAttrId,
975
+ requestCssId
976
+ };
977
+ clone.onload = () => {
978
+ this.onLoad(href);
979
+ };
980
+ clone.onerror = () => {
981
+ this.onLoadError(href);
982
+ };
983
+ if (this.cleanTimeout) clearTimeout(this.cleanTimeout);
984
+ this.cleanTimeout = setTimeout(
985
+ asyncStylesheetManager$1.onCleanTimeout,
986
+ CLEANUP_DEBOUNCE_TIME$1
987
+ );
988
+ }
989
+ getClonedCssTextIfAvailable(href) {
990
+ if (href in this.clones && this.clones[href] !== void 0 && this.clones[href].loaded === true) {
991
+ return this.clones[href].cssText;
992
+ }
993
+ return null;
994
+ }
995
+ };
996
+ __publicField$1(_AsyncStylesheetManager$1, "instance");
997
+ let AsyncStylesheetManager$1 = _AsyncStylesheetManager$1;
998
+ const asyncStylesheetManager$1 = new AsyncStylesheetManager$1();
812
999
  let _id = 1;
813
1000
  const tagNameRegex = new RegExp("[^a-z0-9-_:]");
814
1001
  const IGNORED_NODE = -2;
@@ -920,7 +1107,7 @@ function transformAttribute(doc, tagName, name, value) {
920
1107
  } else if (name === "srcset") {
921
1108
  return getAbsoluteSrcsetString(doc, value);
922
1109
  } else if (name === "style") {
923
- return absolutifyURLs(value, getHref(doc));
1110
+ return absolutifyURLs$1(value, getHref(doc));
924
1111
  } else if (tagName === "object" && name === "data") {
925
1112
  return absoluteToDoc(doc, value);
926
1113
  }
@@ -1157,7 +1344,7 @@ function serializeTextNode(n2, options) {
1157
1344
  } else if (!cssCaptured) {
1158
1345
  textContent2 = index.textContent(n2);
1159
1346
  if (isStyle && textContent2) {
1160
- textContent2 = absolutifyURLs(textContent2, getHref(options.doc));
1347
+ textContent2 = absolutifyURLs$1(textContent2, getHref(options.doc));
1161
1348
  }
1162
1349
  }
1163
1350
  if (!isStyle && !isScript && textContent2 && needsMask) {
@@ -1200,21 +1387,38 @@ function serializeElementNode(n2, options) {
1200
1387
  }
1201
1388
  }
1202
1389
  if (tagName === "link" && inlineStylesheet) {
1203
- const stylesheet = Array.from(doc.styleSheets).find((s2) => {
1204
- return s2.href === n2.href;
1205
- });
1390
+ const styleSheets2 = Array.from(doc.styleSheets);
1391
+ let stylesheet = null;
1392
+ for (let i2 = 0; i2 < styleSheets2.length; i2++) {
1393
+ if (styleSheets2[i2].href === n2.href) {
1394
+ stylesheet = styleSheets2[i2];
1395
+ break;
1396
+ }
1397
+ }
1206
1398
  let cssText = null;
1207
1399
  if (stylesheet) {
1208
- cssText = stringifyStylesheet(stylesheet);
1400
+ cssText = stringifyStylesheet$1(stylesheet);
1401
+ }
1402
+ if (!cssText) {
1403
+ cssText = asyncStylesheetManager$1.getClonedCssTextIfAvailable(
1404
+ n2.href
1405
+ );
1209
1406
  }
1210
1407
  if (cssText) {
1211
1408
  delete attributes.rel;
1212
1409
  delete attributes.href;
1213
1410
  attributes._cssText = cssText;
1411
+ } else {
1412
+ const requestCssId = `css-request-${Math.random().toString(36).slice(2)}`;
1413
+ asyncStylesheetManager$1.requestClone({
1414
+ forElement: n2,
1415
+ requestCssId
1416
+ });
1417
+ attributes._requestCssId = requestCssId;
1214
1418
  }
1215
1419
  }
1216
1420
  if (tagName === "style" && n2.sheet) {
1217
- let cssText = stringifyStylesheet(
1421
+ let cssText = stringifyStylesheet$1(
1218
1422
  n2.sheet
1219
1423
  );
1220
1424
  if (cssText) {
@@ -1306,18 +1510,20 @@ function serializeElementNode(n2, options) {
1306
1510
  );
1307
1511
  } catch (err) {
1308
1512
  if (image.crossOrigin !== "anonymous") {
1309
- image = new Image();
1310
- image.src = imageSrc;
1311
- image.crossOrigin = "anonymous";
1312
- image.height = imageHeight;
1313
- image.width = imageWidth;
1314
- if (image.complete && image.naturalWidth !== 0) {
1315
- recordInlineImage();
1316
- } else {
1317
- image.addEventListener("load", recordInlineImage, { once: true });
1318
- image.addEventListener("error", onImageLoadError, { once: true });
1513
+ if (shouldTryAnonymousFetchingOnCorsError$1()) {
1514
+ image = new Image();
1515
+ image.src = imageSrc;
1516
+ image.crossOrigin = "anonymous";
1517
+ image.height = imageHeight;
1518
+ image.width = imageWidth;
1519
+ if (image.complete && image.naturalWidth !== 0) {
1520
+ recordInlineImage();
1521
+ } else {
1522
+ image.addEventListener("load", recordInlineImage, { once: true });
1523
+ image.addEventListener("error", onImageLoadError, { once: true });
1524
+ }
1525
+ return;
1319
1526
  }
1320
- return;
1321
1527
  } else {
1322
1528
  console.warn(
1323
1529
  `Cannot inline img src=${imageSrc}! Error: ${err}`
@@ -2346,7 +2552,7 @@ let Node$4$1 = class Node2 {
2346
2552
  let index2 = this.parent.index(this);
2347
2553
  return this.parent.nodes[index2 + 1];
2348
2554
  }
2349
- positionBy(opts) {
2555
+ positionBy(opts = {}) {
2350
2556
  let pos = this.source.start;
2351
2557
  if (opts.index) {
2352
2558
  pos = this.positionInside(opts.index);
@@ -2375,27 +2581,38 @@ let Node$4$1 = class Node2 {
2375
2581
  column += 1;
2376
2582
  }
2377
2583
  }
2378
- return { column, line };
2584
+ return { column, line, offset: end };
2379
2585
  }
2380
2586
  prev() {
2381
2587
  if (!this.parent) return void 0;
2382
2588
  let index2 = this.parent.index(this);
2383
2589
  return this.parent.nodes[index2 - 1];
2384
2590
  }
2385
- rangeBy(opts) {
2591
+ rangeBy(opts = {}) {
2592
+ let inputString = "document" in this.source.input ? this.source.input.document : this.source.input.css;
2386
2593
  let start = {
2387
2594
  column: this.source.start.column,
2388
- line: this.source.start.line
2595
+ line: this.source.start.line,
2596
+ offset: sourceOffset$1(inputString, this.source.start)
2389
2597
  };
2390
2598
  let end = this.source.end ? {
2391
2599
  column: this.source.end.column + 1,
2392
- line: this.source.end.line
2600
+ line: this.source.end.line,
2601
+ offset: typeof this.source.end.offset === "number" ? (
2602
+ // `source.end.offset` is exclusive, so we don't need to add 1
2603
+ this.source.end.offset
2604
+ ) : (
2605
+ // Since line/column in this.source.end is inclusive,
2606
+ // the `sourceOffset(... , this.source.end)` returns an inclusive offset.
2607
+ // So, we add 1 to convert it to exclusive.
2608
+ sourceOffset$1(inputString, this.source.end) + 1
2609
+ )
2393
2610
  } : {
2394
2611
  column: start.column + 1,
2395
- line: start.line
2612
+ line: start.line,
2613
+ offset: start.offset + 1
2396
2614
  };
2397
2615
  if (opts.word) {
2398
- let inputString = "document" in this.source.input ? this.source.input.document : this.source.input.css;
2399
2616
  let stringRepresentation = inputString.slice(
2400
2617
  sourceOffset$1(inputString, this.source.start),
2401
2618
  sourceOffset$1(inputString, this.source.end)
@@ -2403,15 +2620,14 @@ let Node$4$1 = class Node2 {
2403
2620
  let index2 = stringRepresentation.indexOf(opts.word);
2404
2621
  if (index2 !== -1) {
2405
2622
  start = this.positionInside(index2);
2406
- end = this.positionInside(
2407
- index2 + opts.word.length
2408
- );
2623
+ end = this.positionInside(index2 + opts.word.length);
2409
2624
  }
2410
2625
  } else {
2411
2626
  if (opts.start) {
2412
2627
  start = {
2413
2628
  column: opts.start.column,
2414
- line: opts.start.line
2629
+ line: opts.start.line,
2630
+ offset: sourceOffset$1(inputString, opts.start)
2415
2631
  };
2416
2632
  } else if (opts.index) {
2417
2633
  start = this.positionInside(opts.index);
@@ -2419,7 +2635,8 @@ let Node$4$1 = class Node2 {
2419
2635
  if (opts.end) {
2420
2636
  end = {
2421
2637
  column: opts.end.column,
2422
- line: opts.end.line
2638
+ line: opts.end.line,
2639
+ offset: sourceOffset$1(inputString, opts.end)
2423
2640
  };
2424
2641
  } else if (typeof opts.endIndex === "number") {
2425
2642
  end = this.positionInside(opts.endIndex);
@@ -2428,7 +2645,11 @@ let Node$4$1 = class Node2 {
2428
2645
  }
2429
2646
  }
2430
2647
  if (end.line < start.line || end.line === start.line && end.column <= start.column) {
2431
- end = { column: start.column + 1, line: start.line };
2648
+ end = {
2649
+ column: start.column + 1,
2650
+ line: start.line,
2651
+ offset: start.offset + 1
2652
+ };
2432
2653
  }
2433
2654
  return { end, start };
2434
2655
  }
@@ -2492,6 +2713,7 @@ let Node$4$1 = class Node2 {
2492
2713
  } else if (typeof value === "object" && value.toJSON) {
2493
2714
  fixed[name] = value.toJSON(null, inputs);
2494
2715
  } else if (name === "source") {
2716
+ if (value == null) continue;
2495
2717
  let inputId = inputs.get(value.input);
2496
2718
  if (inputId == null) {
2497
2719
  inputId = inputsNextIndex;
@@ -2526,7 +2748,7 @@ let Node$4$1 = class Node2 {
2526
2748
  });
2527
2749
  return result2;
2528
2750
  }
2529
- warn(result2, text, opts) {
2751
+ warn(result2, text, opts = {}) {
2530
2752
  let data = { node: this };
2531
2753
  for (let i2 in opts) data[i2] = opts[i2];
2532
2754
  return result2.warn(text, data);
@@ -3103,9 +3325,21 @@ let { fileURLToPath: fileURLToPath$1, pathToFileURL: pathToFileURL$1$1 } = requi
3103
3325
  let CssSyntaxError$1$1 = cssSyntaxError$1;
3104
3326
  let PreviousMap$1$1 = previousMap$1;
3105
3327
  let terminalHighlight$2 = require$$2$1;
3106
- let fromOffsetCache$1 = Symbol("fromOffsetCache");
3328
+ let lineToIndexCache$1 = Symbol("lineToIndexCache");
3107
3329
  let sourceMapAvailable$1$1 = Boolean(SourceMapConsumer$1$1 && SourceMapGenerator$1$1);
3108
3330
  let pathAvailable$1$1 = Boolean(resolve$1$1 && isAbsolute$1);
3331
+ function getLineToIndex$1(input2) {
3332
+ if (input2[lineToIndexCache$1]) return input2[lineToIndexCache$1];
3333
+ let lines = input2.css.split("\n");
3334
+ let lineToIndex = new Array(lines.length);
3335
+ let prevIndex = 0;
3336
+ for (let i2 = 0, l2 = lines.length; i2 < l2; i2++) {
3337
+ lineToIndex[i2] = prevIndex;
3338
+ prevIndex += lines[i2].length + 1;
3339
+ }
3340
+ input2[lineToIndexCache$1] = lineToIndex;
3341
+ return lineToIndex;
3342
+ }
3109
3343
  let Input$4$1 = class Input {
3110
3344
  get from() {
3111
3345
  return this.file || this.id;
@@ -3144,30 +3378,37 @@ let Input$4$1 = class Input {
3144
3378
  if (this.map) this.map.file = this.from;
3145
3379
  }
3146
3380
  error(message, line, column, opts = {}) {
3147
- let endColumn, endLine, result2;
3381
+ let endColumn, endLine, endOffset, offset, result2;
3148
3382
  if (line && typeof line === "object") {
3149
3383
  let start = line;
3150
3384
  let end = column;
3151
3385
  if (typeof start.offset === "number") {
3152
- let pos = this.fromOffset(start.offset);
3386
+ offset = start.offset;
3387
+ let pos = this.fromOffset(offset);
3153
3388
  line = pos.line;
3154
3389
  column = pos.col;
3155
3390
  } else {
3156
3391
  line = start.line;
3157
3392
  column = start.column;
3393
+ offset = this.fromLineAndColumn(line, column);
3158
3394
  }
3159
3395
  if (typeof end.offset === "number") {
3160
- let pos = this.fromOffset(end.offset);
3396
+ endOffset = end.offset;
3397
+ let pos = this.fromOffset(endOffset);
3161
3398
  endLine = pos.line;
3162
3399
  endColumn = pos.col;
3163
3400
  } else {
3164
3401
  endLine = end.line;
3165
3402
  endColumn = end.column;
3403
+ endOffset = this.fromLineAndColumn(end.line, end.column);
3166
3404
  }
3167
3405
  } else if (!column) {
3168
- let pos = this.fromOffset(line);
3406
+ offset = line;
3407
+ let pos = this.fromOffset(offset);
3169
3408
  line = pos.line;
3170
3409
  column = pos.col;
3410
+ } else {
3411
+ offset = this.fromLineAndColumn(line, column);
3171
3412
  }
3172
3413
  let origin = this.origin(line, column, endLine, endColumn);
3173
3414
  if (origin) {
@@ -3189,7 +3430,7 @@ let Input$4$1 = class Input {
3189
3430
  opts.plugin
3190
3431
  );
3191
3432
  }
3192
- result2.input = { column, endColumn, endLine, line, source: this.css };
3433
+ result2.input = { column, endColumn, endLine, endOffset, line, offset, source: this.css };
3193
3434
  if (this.file) {
3194
3435
  if (pathToFileURL$1$1) {
3195
3436
  result2.input.url = pathToFileURL$1$1(this.file).toString();
@@ -3198,21 +3439,14 @@ let Input$4$1 = class Input {
3198
3439
  }
3199
3440
  return result2;
3200
3441
  }
3442
+ fromLineAndColumn(line, column) {
3443
+ let lineToIndex = getLineToIndex$1(this);
3444
+ let index2 = lineToIndex[line - 1];
3445
+ return index2 + column - 1;
3446
+ }
3201
3447
  fromOffset(offset) {
3202
- let lastLine, lineToIndex;
3203
- if (!this[fromOffsetCache$1]) {
3204
- let lines = this.css.split("\n");
3205
- lineToIndex = new Array(lines.length);
3206
- let prevIndex = 0;
3207
- for (let i2 = 0, l2 = lines.length; i2 < l2; i2++) {
3208
- lineToIndex[i2] = prevIndex;
3209
- prevIndex += lines[i2].length + 1;
3210
- }
3211
- this[fromOffsetCache$1] = lineToIndex;
3212
- } else {
3213
- lineToIndex = this[fromOffsetCache$1];
3214
- }
3215
- lastLine = lineToIndex[lineToIndex.length - 1];
3448
+ let lineToIndex = getLineToIndex$1(this);
3449
+ let lastLine = lineToIndex[lineToIndex.length - 1];
3216
3450
  let min = 0;
3217
3451
  if (offset >= lastLine) {
3218
3452
  min = lineToIndex.length - 1;
@@ -4574,7 +4808,7 @@ let Result$3$1 = class Result {
4574
4808
  this.messages = [];
4575
4809
  this.root = root2;
4576
4810
  this.opts = opts;
4577
- this.css = void 0;
4811
+ this.css = "";
4578
4812
  this.map = void 0;
4579
4813
  }
4580
4814
  toString() {
@@ -5186,7 +5420,7 @@ let NoWorkResult2$1 = noWorkResult$1;
5186
5420
  let Root$1$1 = root$1;
5187
5421
  let Processor$1$1 = class Processor {
5188
5422
  constructor(plugins = []) {
5189
- this.version = "8.5.3";
5423
+ this.version = "8.5.4";
5190
5424
  this.plugins = this.normalize(plugins);
5191
5425
  }
5192
5426
  normalize(plugins) {
@@ -5340,6 +5574,325 @@ postcss$1$1.Node;
5340
5574
  var __defProp2 = Object.defineProperty;
5341
5575
  var __defNormalProp2 = (obj, key, value) => key in obj ? __defProp2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
5342
5576
  var __publicField2 = (obj, key, value) => __defNormalProp2(obj, typeof key !== "symbol" ? key + "" : key, value);
5577
+ var __defProp22 = Object.defineProperty;
5578
+ var __defNormalProp22 = (obj, key, value) => key in obj ? __defProp22(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
5579
+ var __publicField22 = (obj, key, value) => __defNormalProp22(obj, typeof key !== "symbol" ? key + "" : key, value);
5580
+ const shouldTryAnonymousFetchingOnCorsError = () => {
5581
+ return !("_rrweb_skip_re_fetching_to_suppress_cors_errors" in window && window._rrweb_skip_re_fetching_to_suppress_cors_errors === true);
5582
+ };
5583
+ function fixBrowserCompatibilityIssuesInCSS(cssText) {
5584
+ if (cssText.includes(" background-clip: text;") && !cssText.includes(" -webkit-background-clip: text;")) {
5585
+ cssText = cssText.replace(
5586
+ /\sbackground-clip:\s*text;/g,
5587
+ " -webkit-background-clip: text; background-clip: text;"
5588
+ );
5589
+ }
5590
+ return cssText;
5591
+ }
5592
+ function escapeImportStatement(rule2) {
5593
+ const { cssText } = rule2;
5594
+ if (cssText.split('"').length < 3) return cssText;
5595
+ const statement = ["@import", `url(${JSON.stringify(rule2.href)})`];
5596
+ if (rule2.layerName === "") {
5597
+ statement.push(`layer`);
5598
+ } else if (rule2.layerName) {
5599
+ statement.push(`layer(${rule2.layerName})`);
5600
+ }
5601
+ if (rule2.supportsText) {
5602
+ statement.push(`supports(${rule2.supportsText})`);
5603
+ }
5604
+ if (rule2.media.length) {
5605
+ statement.push(rule2.media.mediaText);
5606
+ }
5607
+ return statement.join(" ") + ";";
5608
+ }
5609
+ function stringifyStylesheet(s2) {
5610
+ try {
5611
+ const rules2 = s2.rules || s2.cssRules;
5612
+ if (!rules2) {
5613
+ return null;
5614
+ }
5615
+ let sheetHref = s2.href;
5616
+ if (!sheetHref && s2.ownerNode && s2.ownerNode.ownerDocument) {
5617
+ sheetHref = s2.ownerNode.ownerDocument.location.href;
5618
+ }
5619
+ const stringifiedRules = Array.from(
5620
+ rules2,
5621
+ (rule2) => stringifyRule(rule2, sheetHref)
5622
+ ).join("");
5623
+ return fixBrowserCompatibilityIssuesInCSS(stringifiedRules);
5624
+ } catch (error) {
5625
+ return null;
5626
+ }
5627
+ }
5628
+ function stringifyRule(rule2, sheetHref) {
5629
+ if (isCSSImportRule(rule2)) {
5630
+ let importStringified;
5631
+ try {
5632
+ importStringified = // for same-origin stylesheets,
5633
+ // we can access the imported stylesheet rules directly
5634
+ stringifyStylesheet(rule2.styleSheet) || // work around browser issues with the raw string `@import url(...)` statement
5635
+ escapeImportStatement(rule2);
5636
+ } catch (error) {
5637
+ importStringified = rule2.cssText;
5638
+ }
5639
+ if (rule2.styleSheet.href) {
5640
+ return absolutifyURLs(importStringified, rule2.styleSheet.href);
5641
+ }
5642
+ return importStringified;
5643
+ } else {
5644
+ let ruleStringified = rule2.cssText;
5645
+ if (isCSSStyleRule(rule2) && rule2.selectorText.includes(":")) {
5646
+ ruleStringified = fixSafariColons(ruleStringified);
5647
+ }
5648
+ if (sheetHref) {
5649
+ return absolutifyURLs(ruleStringified, sheetHref);
5650
+ }
5651
+ return ruleStringified;
5652
+ }
5653
+ }
5654
+ function fixSafariColons(cssStringified) {
5655
+ const regex = /(\[(?:[\w-]+)[^\\])(:(?:[\w-]+)\])/gm;
5656
+ return cssStringified.replace(regex, "$1\\$2");
5657
+ }
5658
+ function isCSSImportRule(rule2) {
5659
+ return "styleSheet" in rule2;
5660
+ }
5661
+ function isCSSStyleRule(rule2) {
5662
+ return "selectorText" in rule2;
5663
+ }
5664
+ function extractOrigin(url) {
5665
+ let origin = "";
5666
+ if (url.indexOf("//") > -1) {
5667
+ origin = url.split("/").slice(0, 3).join("/");
5668
+ } else {
5669
+ origin = url.split("/")[0];
5670
+ }
5671
+ origin = origin.split("?")[0];
5672
+ return origin;
5673
+ }
5674
+ const URL_IN_CSS_REF = /url\((?:(')([^']*)'|(")(.*?)"|([^)]*))\)/gm;
5675
+ const URL_PROTOCOL_MATCH = /^(?:[a-z+]+:)?\/\//i;
5676
+ const URL_WWW_MATCH = /^www\..*/i;
5677
+ const DATA_URI = /^(data:)([^,]*),(.*)/i;
5678
+ function absolutifyURLs(cssText, href) {
5679
+ return (cssText || "").replace(
5680
+ URL_IN_CSS_REF,
5681
+ (origin, quote1, path1, quote2, path2, path3) => {
5682
+ const filePath = path1 || path2 || path3;
5683
+ const maybeQuote = quote1 || quote2 || "";
5684
+ if (!filePath) {
5685
+ return origin;
5686
+ }
5687
+ if (URL_PROTOCOL_MATCH.test(filePath) || URL_WWW_MATCH.test(filePath)) {
5688
+ return `url(${maybeQuote}${filePath}${maybeQuote})`;
5689
+ }
5690
+ if (DATA_URI.test(filePath)) {
5691
+ return `url(${maybeQuote}${filePath}${maybeQuote})`;
5692
+ }
5693
+ if (filePath[0] === "/") {
5694
+ return `url(${maybeQuote}${extractOrigin(href) + filePath}${maybeQuote})`;
5695
+ }
5696
+ const stack = href.split("/");
5697
+ const parts = filePath.split("/");
5698
+ stack.pop();
5699
+ for (const part of parts) {
5700
+ if (part === ".") {
5701
+ continue;
5702
+ } else if (part === "..") {
5703
+ stack.pop();
5704
+ } else {
5705
+ stack.push(part);
5706
+ }
5707
+ }
5708
+ return `url(${maybeQuote}${stack.join("/")}${maybeQuote})`;
5709
+ }
5710
+ );
5711
+ }
5712
+ const CLEANUP_DEBOUNCE_TIME = 1e3 * 30;
5713
+ const DATA_ATTRIBUTE_CLONED_NAME = "data-rrweb-link-cloned";
5714
+ const DISALLOWED_EXTENSIONS = [
5715
+ // Fonts
5716
+ "woff",
5717
+ "woff2",
5718
+ "ttf",
5719
+ "otf",
5720
+ // Embedded OpenType font
5721
+ "eot",
5722
+ // Images
5723
+ "png",
5724
+ "jpg",
5725
+ "jpeg",
5726
+ "gif",
5727
+ "svg",
5728
+ "webp",
5729
+ "ico",
5730
+ // Scripts
5731
+ "js",
5732
+ "mjs",
5733
+ "ts",
5734
+ "jsx",
5735
+ "tsx",
5736
+ // Data files
5737
+ "json",
5738
+ "map",
5739
+ // Media
5740
+ "mp4",
5741
+ "webm",
5742
+ "ogg",
5743
+ "mp3",
5744
+ "wav",
5745
+ // Archives
5746
+ "zip",
5747
+ "rar",
5748
+ "7z",
5749
+ "tar",
5750
+ "gz",
5751
+ // Documents
5752
+ "pdf",
5753
+ "doc",
5754
+ "docx",
5755
+ "xls",
5756
+ "xlsx"
5757
+ ];
5758
+ const _AsyncStylesheetManager2 = class _AsyncStylesheetManager22 {
5759
+ constructor() {
5760
+ __publicField22(this, "currentHref", null);
5761
+ __publicField22(this, "clones", {});
5762
+ __publicField22(this, "cleanTimeout", null);
5763
+ if (_AsyncStylesheetManager22.instance) return _AsyncStylesheetManager22.instance;
5764
+ _AsyncStylesheetManager22.instance = this;
5765
+ }
5766
+ removeCloneNode(href) {
5767
+ var _a2;
5768
+ if (!(href in this.clones) || this.clones[href] === void 0) return;
5769
+ const clone = document.querySelector(
5770
+ `link[${DATA_ATTRIBUTE_CLONED_NAME}="${this.clones[href].cloneNodeAttrId}"]`
5771
+ );
5772
+ if (!clone) return;
5773
+ (_a2 = clone.parentNode) == null ? void 0 : _a2.removeChild(clone);
5774
+ }
5775
+ onLoad(href) {
5776
+ if (!(href in this.clones) || this.clones[href] === void 0) return;
5777
+ const styleSheets2 = Array.from(document.styleSheets);
5778
+ let clonedStyleSheet = null;
5779
+ for (let i2 = styleSheets2.length - 1; i2 >= 0; i2--) {
5780
+ if (styleSheets2[i2].href === href) {
5781
+ clonedStyleSheet = styleSheets2[i2];
5782
+ break;
5783
+ }
5784
+ }
5785
+ if (!clonedStyleSheet) return this.removeCloneNode(href);
5786
+ const newCssText = stringifyStylesheet(clonedStyleSheet);
5787
+ this.removeCloneNode(href);
5788
+ if (!newCssText) return;
5789
+ this.clones[href].cssText = newCssText;
5790
+ this.clones[href].loaded = true;
5791
+ const original = document.querySelector(
5792
+ `link[${DATA_ATTRIBUTE_CLONED_NAME}="source-${this.clones[href].cloneNodeAttrId}"]`
5793
+ );
5794
+ if (original) {
5795
+ original.setAttribute("data-rrweb-mutation", Date.now().toString());
5796
+ original.removeAttribute(DATA_ATTRIBUTE_CLONED_NAME);
5797
+ } else {
5798
+ this.clones[href].original.setAttribute(
5799
+ "data-rrweb-mutation",
5800
+ Date.now().toString()
5801
+ );
5802
+ this.clones[href].original.removeAttribute(DATA_ATTRIBUTE_CLONED_NAME);
5803
+ }
5804
+ window.dispatchEvent(
5805
+ new CustomEvent("__rrweb_custom_event__", {
5806
+ detail: {
5807
+ type: 5,
5808
+ timestamp: Date.now(),
5809
+ data: {
5810
+ tag: "async-css-resolution",
5811
+ requestCssId: this.clones[href].requestCssId,
5812
+ cssText: this.clones[href].cssText
5813
+ }
5814
+ }
5815
+ })
5816
+ );
5817
+ }
5818
+ onLoadError(href) {
5819
+ if (!(href in this.clones) || this.clones[href] === void 0) return;
5820
+ this.removeCloneNode(href);
5821
+ }
5822
+ removeAllCloneElements() {
5823
+ for (const href of Object.keys(this.clones)) {
5824
+ this.removeCloneNode(href);
5825
+ }
5826
+ }
5827
+ onCleanTimeout() {
5828
+ asyncStylesheetManager.cleanTimeout = null;
5829
+ asyncStylesheetManager.removeAllCloneElements();
5830
+ }
5831
+ blowCache() {
5832
+ this.removeAllCloneElements();
5833
+ this.clones = {};
5834
+ }
5835
+ requestClone({
5836
+ forElement,
5837
+ requestCssId
5838
+ }) {
5839
+ if (!shouldTryAnonymousFetchingOnCorsError()) return;
5840
+ if (this.currentHref != null && document.location.href !== this.currentHref)
5841
+ this.blowCache();
5842
+ this.currentHref = document.location.href;
5843
+ const href = forElement.href;
5844
+ if (!href) return;
5845
+ if (href in this.clones && this.clones[href] !== void 0) return;
5846
+ if (forElement.getAttribute("crossorigin") === "anonymous") return;
5847
+ if (forElement.rel !== "stylesheet") {
5848
+ const last = href.split("/").pop();
5849
+ if (last && last.includes(".")) {
5850
+ const [filename] = last.split("?");
5851
+ const ext = filename.split(".").pop();
5852
+ if (ext) {
5853
+ if (DISALLOWED_EXTENSIONS.includes(ext.trim().toLowerCase())) return;
5854
+ }
5855
+ }
5856
+ }
5857
+ const clone = forElement.cloneNode();
5858
+ const cloneNodeAttrId = Math.random().toString(36).slice(2);
5859
+ clone.setAttribute("crossorigin", "anonymous");
5860
+ clone.setAttribute(DATA_ATTRIBUTE_CLONED_NAME, cloneNodeAttrId);
5861
+ forElement.setAttribute(
5862
+ DATA_ATTRIBUTE_CLONED_NAME,
5863
+ `source-${cloneNodeAttrId}`
5864
+ );
5865
+ document.head.appendChild(clone);
5866
+ this.clones[href] = {
5867
+ original: forElement,
5868
+ clone,
5869
+ loaded: false,
5870
+ cssText: null,
5871
+ cloneNodeAttrId,
5872
+ requestCssId
5873
+ };
5874
+ clone.onload = () => {
5875
+ this.onLoad(href);
5876
+ };
5877
+ clone.onerror = () => {
5878
+ this.onLoadError(href);
5879
+ };
5880
+ if (this.cleanTimeout) clearTimeout(this.cleanTimeout);
5881
+ this.cleanTimeout = setTimeout(
5882
+ asyncStylesheetManager.onCleanTimeout,
5883
+ CLEANUP_DEBOUNCE_TIME
5884
+ );
5885
+ }
5886
+ getClonedCssTextIfAvailable(href) {
5887
+ if (href in this.clones && this.clones[href] !== void 0 && this.clones[href].loaded === true) {
5888
+ return this.clones[href].cssText;
5889
+ }
5890
+ return null;
5891
+ }
5892
+ };
5893
+ __publicField22(_AsyncStylesheetManager2, "instance");
5894
+ let AsyncStylesheetManager = _AsyncStylesheetManager2;
5895
+ const asyncStylesheetManager = new AsyncStylesheetManager();
5343
5896
  function getDefaultExportFromCjs(x2) {
5344
5897
  return x2 && x2.__esModule && Object.prototype.hasOwnProperty.call(x2, "default") ? x2["default"] : x2;
5345
5898
  }
@@ -5947,7 +6500,7 @@ let Node$4 = class Node3 {
5947
6500
  let index2 = this.parent.index(this);
5948
6501
  return this.parent.nodes[index2 + 1];
5949
6502
  }
5950
- positionBy(opts) {
6503
+ positionBy(opts = {}) {
5951
6504
  let pos = this.source.start;
5952
6505
  if (opts.index) {
5953
6506
  pos = this.positionInside(opts.index);
@@ -5976,27 +6529,38 @@ let Node$4 = class Node3 {
5976
6529
  column += 1;
5977
6530
  }
5978
6531
  }
5979
- return { column, line };
6532
+ return { column, line, offset: end };
5980
6533
  }
5981
6534
  prev() {
5982
6535
  if (!this.parent) return void 0;
5983
6536
  let index2 = this.parent.index(this);
5984
6537
  return this.parent.nodes[index2 - 1];
5985
6538
  }
5986
- rangeBy(opts) {
6539
+ rangeBy(opts = {}) {
6540
+ let inputString = "document" in this.source.input ? this.source.input.document : this.source.input.css;
5987
6541
  let start = {
5988
6542
  column: this.source.start.column,
5989
- line: this.source.start.line
6543
+ line: this.source.start.line,
6544
+ offset: sourceOffset(inputString, this.source.start)
5990
6545
  };
5991
6546
  let end = this.source.end ? {
5992
6547
  column: this.source.end.column + 1,
5993
- line: this.source.end.line
6548
+ line: this.source.end.line,
6549
+ offset: typeof this.source.end.offset === "number" ? (
6550
+ // `source.end.offset` is exclusive, so we don't need to add 1
6551
+ this.source.end.offset
6552
+ ) : (
6553
+ // Since line/column in this.source.end is inclusive,
6554
+ // the `sourceOffset(... , this.source.end)` returns an inclusive offset.
6555
+ // So, we add 1 to convert it to exclusive.
6556
+ sourceOffset(inputString, this.source.end) + 1
6557
+ )
5994
6558
  } : {
5995
6559
  column: start.column + 1,
5996
- line: start.line
6560
+ line: start.line,
6561
+ offset: start.offset + 1
5997
6562
  };
5998
6563
  if (opts.word) {
5999
- let inputString = "document" in this.source.input ? this.source.input.document : this.source.input.css;
6000
6564
  let stringRepresentation = inputString.slice(
6001
6565
  sourceOffset(inputString, this.source.start),
6002
6566
  sourceOffset(inputString, this.source.end)
@@ -6004,15 +6568,14 @@ let Node$4 = class Node3 {
6004
6568
  let index2 = stringRepresentation.indexOf(opts.word);
6005
6569
  if (index2 !== -1) {
6006
6570
  start = this.positionInside(index2);
6007
- end = this.positionInside(
6008
- index2 + opts.word.length
6009
- );
6571
+ end = this.positionInside(index2 + opts.word.length);
6010
6572
  }
6011
6573
  } else {
6012
6574
  if (opts.start) {
6013
6575
  start = {
6014
6576
  column: opts.start.column,
6015
- line: opts.start.line
6577
+ line: opts.start.line,
6578
+ offset: sourceOffset(inputString, opts.start)
6016
6579
  };
6017
6580
  } else if (opts.index) {
6018
6581
  start = this.positionInside(opts.index);
@@ -6020,7 +6583,8 @@ let Node$4 = class Node3 {
6020
6583
  if (opts.end) {
6021
6584
  end = {
6022
6585
  column: opts.end.column,
6023
- line: opts.end.line
6586
+ line: opts.end.line,
6587
+ offset: sourceOffset(inputString, opts.end)
6024
6588
  };
6025
6589
  } else if (typeof opts.endIndex === "number") {
6026
6590
  end = this.positionInside(opts.endIndex);
@@ -6029,7 +6593,11 @@ let Node$4 = class Node3 {
6029
6593
  }
6030
6594
  }
6031
6595
  if (end.line < start.line || end.line === start.line && end.column <= start.column) {
6032
- end = { column: start.column + 1, line: start.line };
6596
+ end = {
6597
+ column: start.column + 1,
6598
+ line: start.line,
6599
+ offset: start.offset + 1
6600
+ };
6033
6601
  }
6034
6602
  return { end, start };
6035
6603
  }
@@ -6093,6 +6661,7 @@ let Node$4 = class Node3 {
6093
6661
  } else if (typeof value === "object" && value.toJSON) {
6094
6662
  fixed[name] = value.toJSON(null, inputs);
6095
6663
  } else if (name === "source") {
6664
+ if (value == null) continue;
6096
6665
  let inputId = inputs.get(value.input);
6097
6666
  if (inputId == null) {
6098
6667
  inputId = inputsNextIndex;
@@ -6127,7 +6696,7 @@ let Node$4 = class Node3 {
6127
6696
  });
6128
6697
  return result2;
6129
6698
  }
6130
- warn(result2, text, opts) {
6699
+ warn(result2, text, opts = {}) {
6131
6700
  let data = { node: this };
6132
6701
  for (let i2 in opts) data[i2] = opts[i2];
6133
6702
  return result2.warn(text, data);
@@ -6704,9 +7273,21 @@ let { fileURLToPath, pathToFileURL: pathToFileURL$1 } = require$$2;
6704
7273
  let CssSyntaxError$1 = cssSyntaxError;
6705
7274
  let PreviousMap$1 = previousMap;
6706
7275
  let terminalHighlight = require$$2;
6707
- let fromOffsetCache = Symbol("fromOffsetCache");
7276
+ let lineToIndexCache = Symbol("lineToIndexCache");
6708
7277
  let sourceMapAvailable$1 = Boolean(SourceMapConsumer$1 && SourceMapGenerator$1);
6709
7278
  let pathAvailable$1 = Boolean(resolve$1 && isAbsolute);
7279
+ function getLineToIndex(input2) {
7280
+ if (input2[lineToIndexCache]) return input2[lineToIndexCache];
7281
+ let lines = input2.css.split("\n");
7282
+ let lineToIndex = new Array(lines.length);
7283
+ let prevIndex = 0;
7284
+ for (let i2 = 0, l2 = lines.length; i2 < l2; i2++) {
7285
+ lineToIndex[i2] = prevIndex;
7286
+ prevIndex += lines[i2].length + 1;
7287
+ }
7288
+ input2[lineToIndexCache] = lineToIndex;
7289
+ return lineToIndex;
7290
+ }
6710
7291
  let Input$4 = class Input2 {
6711
7292
  get from() {
6712
7293
  return this.file || this.id;
@@ -6745,30 +7326,37 @@ let Input$4 = class Input2 {
6745
7326
  if (this.map) this.map.file = this.from;
6746
7327
  }
6747
7328
  error(message, line, column, opts = {}) {
6748
- let endColumn, endLine, result2;
7329
+ let endColumn, endLine, endOffset, offset, result2;
6749
7330
  if (line && typeof line === "object") {
6750
7331
  let start = line;
6751
7332
  let end = column;
6752
7333
  if (typeof start.offset === "number") {
6753
- let pos = this.fromOffset(start.offset);
7334
+ offset = start.offset;
7335
+ let pos = this.fromOffset(offset);
6754
7336
  line = pos.line;
6755
7337
  column = pos.col;
6756
7338
  } else {
6757
7339
  line = start.line;
6758
7340
  column = start.column;
7341
+ offset = this.fromLineAndColumn(line, column);
6759
7342
  }
6760
7343
  if (typeof end.offset === "number") {
6761
- let pos = this.fromOffset(end.offset);
7344
+ endOffset = end.offset;
7345
+ let pos = this.fromOffset(endOffset);
6762
7346
  endLine = pos.line;
6763
7347
  endColumn = pos.col;
6764
7348
  } else {
6765
7349
  endLine = end.line;
6766
7350
  endColumn = end.column;
7351
+ endOffset = this.fromLineAndColumn(end.line, end.column);
6767
7352
  }
6768
7353
  } else if (!column) {
6769
- let pos = this.fromOffset(line);
7354
+ offset = line;
7355
+ let pos = this.fromOffset(offset);
6770
7356
  line = pos.line;
6771
7357
  column = pos.col;
7358
+ } else {
7359
+ offset = this.fromLineAndColumn(line, column);
6772
7360
  }
6773
7361
  let origin = this.origin(line, column, endLine, endColumn);
6774
7362
  if (origin) {
@@ -6790,7 +7378,7 @@ let Input$4 = class Input2 {
6790
7378
  opts.plugin
6791
7379
  );
6792
7380
  }
6793
- result2.input = { column, endColumn, endLine, line, source: this.css };
7381
+ result2.input = { column, endColumn, endLine, endOffset, line, offset, source: this.css };
6794
7382
  if (this.file) {
6795
7383
  if (pathToFileURL$1) {
6796
7384
  result2.input.url = pathToFileURL$1(this.file).toString();
@@ -6799,21 +7387,14 @@ let Input$4 = class Input2 {
6799
7387
  }
6800
7388
  return result2;
6801
7389
  }
7390
+ fromLineAndColumn(line, column) {
7391
+ let lineToIndex = getLineToIndex(this);
7392
+ let index2 = lineToIndex[line - 1];
7393
+ return index2 + column - 1;
7394
+ }
6802
7395
  fromOffset(offset) {
6803
- let lastLine, lineToIndex;
6804
- if (!this[fromOffsetCache]) {
6805
- let lines = this.css.split("\n");
6806
- lineToIndex = new Array(lines.length);
6807
- let prevIndex = 0;
6808
- for (let i2 = 0, l2 = lines.length; i2 < l2; i2++) {
6809
- lineToIndex[i2] = prevIndex;
6810
- prevIndex += lines[i2].length + 1;
6811
- }
6812
- this[fromOffsetCache] = lineToIndex;
6813
- } else {
6814
- lineToIndex = this[fromOffsetCache];
6815
- }
6816
- lastLine = lineToIndex[lineToIndex.length - 1];
7396
+ let lineToIndex = getLineToIndex(this);
7397
+ let lastLine = lineToIndex[lineToIndex.length - 1];
6817
7398
  let min = 0;
6818
7399
  if (offset >= lastLine) {
6819
7400
  min = lineToIndex.length - 1;
@@ -8175,7 +8756,7 @@ let Result$3 = class Result2 {
8175
8756
  this.messages = [];
8176
8757
  this.root = root2;
8177
8758
  this.opts = opts;
8178
- this.css = void 0;
8759
+ this.css = "";
8179
8760
  this.map = void 0;
8180
8761
  }
8181
8762
  toString() {
@@ -8787,7 +9368,7 @@ let NoWorkResult22 = noWorkResult;
8787
9368
  let Root$1 = root;
8788
9369
  let Processor$1 = class Processor2 {
8789
9370
  constructor(plugins = []) {
8790
- this.version = "8.5.3";
9371
+ this.version = "8.5.4";
8791
9372
  this.plugins = this.normalize(plugins);
8792
9373
  }
8793
9374
  normalize(plugins) {
@@ -12066,7 +12647,7 @@ class StylesheetManager {
12066
12647
  styles.push({
12067
12648
  styleId,
12068
12649
  rules: Array.from(sheet.rules || CSSRule, (r2, index2) => ({
12069
- rule: stringifyRule(r2, sheet.href),
12650
+ rule: stringifyRule$1(r2, sheet.href),
12070
12651
  index: index2
12071
12652
  }))
12072
12653
  });
@@ -12526,12 +13107,26 @@ function record(options = {}) {
12526
13107
  console.warn(error);
12527
13108
  }
12528
13109
  });
13110
+ let initedAt = null;
12529
13111
  const init = () => {
13112
+ initedAt = Date.now();
12530
13113
  takeFullSnapshot$1();
12531
13114
  handlers.push(observe(document));
12532
13115
  recording = true;
12533
13116
  };
13117
+ const customOnLoad = () => {
13118
+ window.removeEventListener("load", customOnLoad);
13119
+ if (!recording || initedAt == null) return;
13120
+ if (Date.now() - initedAt <= 10) {
13121
+ return;
13122
+ }
13123
+ takeFullSnapshot$1();
13124
+ };
13125
+ window.addEventListener("load", customOnLoad);
12534
13126
  if (document.readyState === "interactive" || document.readyState === "complete") {
13127
+ if (document.readyState === "complete") {
13128
+ window.removeEventListener("load", customOnLoad);
13129
+ }
12535
13130
  init();
12536
13131
  } else {
12537
13132
  handlers.push(
@@ -12540,7 +13135,9 @@ function record(options = {}) {
12540
13135
  type: EventType.DomContentLoaded,
12541
13136
  data: {}
12542
13137
  });
12543
- if (recordAfter === "DOMContentLoaded") init();
13138
+ if (recordAfter === "DOMContentLoaded") {
13139
+ init();
13140
+ }
12544
13141
  })
12545
13142
  );
12546
13143
  handlers.push(
@@ -12551,7 +13148,9 @@ function record(options = {}) {
12551
13148
  type: EventType.Load,
12552
13149
  data: {}
12553
13150
  });
12554
- if (recordAfter === "load") init();
13151
+ if (recordAfter === "load") {
13152
+ init();
13153
+ }
12555
13154
  },
12556
13155
  window
12557
13156
  )