@glimt/record 0.0.40 → 0.0.42

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
@@ -483,6 +483,7 @@ function stringifyStylesheet$1(s2) {
483
483
  ).join("");
484
484
  return fixBrowserCompatibilityIssuesInCSS$1(stringifiedRules);
485
485
  } catch (error) {
486
+ console.log("stringifyStylesheet error:", error);
486
487
  return null;
487
488
  }
488
489
  }
@@ -818,23 +819,40 @@ const _AsyncStylesheetManager$1 = class _AsyncStylesheetManager {
818
819
  if (_AsyncStylesheetManager.instance) return _AsyncStylesheetManager.instance;
819
820
  _AsyncStylesheetManager.instance = this;
820
821
  }
822
+ removeCloneNode(href) {
823
+ if (!(href in this.clones) || this.clones[href] === void 0) return;
824
+ document.head.removeChild(this.clones[href].clone);
825
+ }
821
826
  onLoad(href) {
822
827
  if (!(href in this.clones) || this.clones[href] === void 0) return;
823
828
  console.log("AsyncStylesheetManager, onLoad: href:", href);
824
829
  const styleSheets2 = Array.from(document.styleSheets);
825
830
  let clonedStyleSheet = null;
826
- document.head.removeChild(this.clones[href].clone);
827
831
  for (let i2 = styleSheets2.length - 1; i2 >= 0; i2--) {
828
832
  if (styleSheets2[i2].href === href) {
829
833
  clonedStyleSheet = styleSheets2[i2];
830
834
  break;
831
835
  }
832
836
  }
833
- if (!clonedStyleSheet) return;
837
+ if (!clonedStyleSheet) {
838
+ console.log(
839
+ "AsyncStylesheetManager, onLoad: couldn't find stylesheet for href:",
840
+ href
841
+ );
842
+ return this.removeCloneNode(href);
843
+ }
834
844
  const newCssText = stringifyStylesheet$1(clonedStyleSheet);
835
- if (!newCssText) return;
845
+ this.removeCloneNode(href);
846
+ if (!newCssText) {
847
+ console.log(
848
+ "AsyncStylesheetManager, onLoad: couldn't stringify stylesheet for href:",
849
+ href
850
+ );
851
+ return;
852
+ }
836
853
  console.log(
837
- "AsyncStylesheetManager, onLoad: success! did get new css text! forcing mutation..."
854
+ "AsyncStylesheetManager, onLoad: success! did get new css text! forcing mutation... for href:",
855
+ href
838
856
  );
839
857
  this.clones[href].cssText = newCssText;
840
858
  this.clones[href].loaded = true;
@@ -845,12 +863,11 @@ const _AsyncStylesheetManager$1 = class _AsyncStylesheetManager {
845
863
  }
846
864
  onLoadError(href) {
847
865
  if (!(href in this.clones) || this.clones[href] === void 0) return;
848
- document.head.removeChild(this.clones[href].clone);
866
+ this.removeCloneNode(href);
849
867
  }
850
868
  removeAllCloneElements() {
851
- for (const clone of Object.values(this.clones)) {
852
- if (!clone) continue;
853
- document.head.removeChild(clone.clone);
869
+ for (const href of Object.keys(this.clones)) {
870
+ this.removeCloneNode(href);
854
871
  }
855
872
  }
856
873
  onCleanTimeout() {
@@ -868,10 +885,6 @@ const _AsyncStylesheetManager$1 = class _AsyncStylesheetManager {
868
885
  this.blowCache();
869
886
  this.currentHref = document.location.href;
870
887
  const href = forElement.href;
871
- console.log(
872
- "AsyncStylesheetManager, registerClone: wants a clone for href:",
873
- href
874
- );
875
888
  if (!href) return;
876
889
  if (href in this.clones && this.clones[href] !== void 0) return;
877
890
  if (forElement.getAttribute("crossorigin") === "anonymous") return;
@@ -901,7 +914,8 @@ const _AsyncStylesheetManager$1 = class _AsyncStylesheetManager {
901
914
  getClonedCssTextIfAvailable(href) {
902
915
  if (href in this.clones && this.clones[href] !== void 0 && this.clones[href].loaded === true) {
903
916
  console.log(
904
- "AsyncStylesheetManager, getClonedCssTextIfAvailable: returning cloned cssText!"
917
+ "AsyncStylesheetManager, getClonedCssTextIfAvailable: returning cloned cssText, for href:",
918
+ href
905
919
  );
906
920
  return this.clones[href].cssText;
907
921
  }
@@ -1303,10 +1317,13 @@ function serializeElementNode(n2, options) {
1303
1317
  }
1304
1318
  if (tagName === "link" && inlineStylesheet) {
1305
1319
  const styleSheets2 = Array.from(doc.styleSheets);
1306
- const styleSheetIndex = styleSheets2.findIndex((s2) => {
1307
- return s2.href === n2.href;
1308
- });
1309
- const stylesheet = styleSheets2[styleSheetIndex];
1320
+ let stylesheet = null;
1321
+ for (let i2 = 0; i2 < styleSheets2.length; i2++) {
1322
+ if (styleSheets2[i2].href === n2.href) {
1323
+ stylesheet = styleSheets2[i2];
1324
+ break;
1325
+ }
1326
+ }
1310
1327
  let cssText = null;
1311
1328
  if (stylesheet) {
1312
1329
  cssText = stringifyStylesheet$1(stylesheet);
@@ -5522,6 +5539,7 @@ function stringifyStylesheet(s2) {
5522
5539
  ).join("");
5523
5540
  return fixBrowserCompatibilityIssuesInCSS(stringifiedRules);
5524
5541
  } catch (error) {
5542
+ console.log("stringifyStylesheet error:", error);
5525
5543
  return null;
5526
5544
  }
5527
5545
  }
@@ -5618,23 +5636,40 @@ const _AsyncStylesheetManager2 = class _AsyncStylesheetManager22 {
5618
5636
  if (_AsyncStylesheetManager22.instance) return _AsyncStylesheetManager22.instance;
5619
5637
  _AsyncStylesheetManager22.instance = this;
5620
5638
  }
5639
+ removeCloneNode(href) {
5640
+ if (!(href in this.clones) || this.clones[href] === void 0) return;
5641
+ document.head.removeChild(this.clones[href].clone);
5642
+ }
5621
5643
  onLoad(href) {
5622
5644
  if (!(href in this.clones) || this.clones[href] === void 0) return;
5623
5645
  console.log("AsyncStylesheetManager, onLoad: href:", href);
5624
5646
  const styleSheets2 = Array.from(document.styleSheets);
5625
5647
  let clonedStyleSheet = null;
5626
- document.head.removeChild(this.clones[href].clone);
5627
5648
  for (let i2 = styleSheets2.length - 1; i2 >= 0; i2--) {
5628
5649
  if (styleSheets2[i2].href === href) {
5629
5650
  clonedStyleSheet = styleSheets2[i2];
5630
5651
  break;
5631
5652
  }
5632
5653
  }
5633
- if (!clonedStyleSheet) return;
5654
+ if (!clonedStyleSheet) {
5655
+ console.log(
5656
+ "AsyncStylesheetManager, onLoad: couldn't find stylesheet for href:",
5657
+ href
5658
+ );
5659
+ return this.removeCloneNode(href);
5660
+ }
5634
5661
  const newCssText = stringifyStylesheet(clonedStyleSheet);
5635
- if (!newCssText) return;
5662
+ this.removeCloneNode(href);
5663
+ if (!newCssText) {
5664
+ console.log(
5665
+ "AsyncStylesheetManager, onLoad: couldn't stringify stylesheet for href:",
5666
+ href
5667
+ );
5668
+ return;
5669
+ }
5636
5670
  console.log(
5637
- "AsyncStylesheetManager, onLoad: success! did get new css text! forcing mutation..."
5671
+ "AsyncStylesheetManager, onLoad: success! did get new css text! forcing mutation... for href:",
5672
+ href
5638
5673
  );
5639
5674
  this.clones[href].cssText = newCssText;
5640
5675
  this.clones[href].loaded = true;
@@ -5645,12 +5680,11 @@ const _AsyncStylesheetManager2 = class _AsyncStylesheetManager22 {
5645
5680
  }
5646
5681
  onLoadError(href) {
5647
5682
  if (!(href in this.clones) || this.clones[href] === void 0) return;
5648
- document.head.removeChild(this.clones[href].clone);
5683
+ this.removeCloneNode(href);
5649
5684
  }
5650
5685
  removeAllCloneElements() {
5651
- for (const clone of Object.values(this.clones)) {
5652
- if (!clone) continue;
5653
- document.head.removeChild(clone.clone);
5686
+ for (const href of Object.keys(this.clones)) {
5687
+ this.removeCloneNode(href);
5654
5688
  }
5655
5689
  }
5656
5690
  onCleanTimeout() {
@@ -5668,10 +5702,6 @@ const _AsyncStylesheetManager2 = class _AsyncStylesheetManager22 {
5668
5702
  this.blowCache();
5669
5703
  this.currentHref = document.location.href;
5670
5704
  const href = forElement.href;
5671
- console.log(
5672
- "AsyncStylesheetManager, registerClone: wants a clone for href:",
5673
- href
5674
- );
5675
5705
  if (!href) return;
5676
5706
  if (href in this.clones && this.clones[href] !== void 0) return;
5677
5707
  if (forElement.getAttribute("crossorigin") === "anonymous") return;
@@ -5701,7 +5731,8 @@ const _AsyncStylesheetManager2 = class _AsyncStylesheetManager22 {
5701
5731
  getClonedCssTextIfAvailable(href) {
5702
5732
  if (href in this.clones && this.clones[href] !== void 0 && this.clones[href].loaded === true) {
5703
5733
  console.log(
5704
- "AsyncStylesheetManager, getClonedCssTextIfAvailable: returning cloned cssText!"
5734
+ "AsyncStylesheetManager, getClonedCssTextIfAvailable: returning cloned cssText, for href:",
5735
+ href
5705
5736
  );
5706
5737
  return this.clones[href].cssText;
5707
5738
  }