@glimt/record 0.0.41 → 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.cjs CHANGED
@@ -821,23 +821,40 @@ const _AsyncStylesheetManager$1 = class _AsyncStylesheetManager {
821
821
  if (_AsyncStylesheetManager.instance) return _AsyncStylesheetManager.instance;
822
822
  _AsyncStylesheetManager.instance = this;
823
823
  }
824
+ removeCloneNode(href) {
825
+ if (!(href in this.clones) || this.clones[href] === void 0) return;
826
+ document.head.removeChild(this.clones[href].clone);
827
+ }
824
828
  onLoad(href) {
825
829
  if (!(href in this.clones) || this.clones[href] === void 0) return;
826
830
  console.log("AsyncStylesheetManager, onLoad: href:", href);
827
831
  const styleSheets2 = Array.from(document.styleSheets);
828
832
  let clonedStyleSheet = null;
829
- document.head.removeChild(this.clones[href].clone);
830
833
  for (let i2 = styleSheets2.length - 1; i2 >= 0; i2--) {
831
834
  if (styleSheets2[i2].href === href) {
832
835
  clonedStyleSheet = styleSheets2[i2];
833
836
  break;
834
837
  }
835
838
  }
836
- if (!clonedStyleSheet) return;
839
+ if (!clonedStyleSheet) {
840
+ console.log(
841
+ "AsyncStylesheetManager, onLoad: couldn't find stylesheet for href:",
842
+ href
843
+ );
844
+ return this.removeCloneNode(href);
845
+ }
837
846
  const newCssText = stringifyStylesheet$1(clonedStyleSheet);
838
- if (!newCssText) return;
847
+ this.removeCloneNode(href);
848
+ if (!newCssText) {
849
+ console.log(
850
+ "AsyncStylesheetManager, onLoad: couldn't stringify stylesheet for href:",
851
+ href
852
+ );
853
+ return;
854
+ }
839
855
  console.log(
840
- "AsyncStylesheetManager, onLoad: success! did get new css text! forcing mutation..."
856
+ "AsyncStylesheetManager, onLoad: success! did get new css text! forcing mutation... for href:",
857
+ href
841
858
  );
842
859
  this.clones[href].cssText = newCssText;
843
860
  this.clones[href].loaded = true;
@@ -848,12 +865,11 @@ const _AsyncStylesheetManager$1 = class _AsyncStylesheetManager {
848
865
  }
849
866
  onLoadError(href) {
850
867
  if (!(href in this.clones) || this.clones[href] === void 0) return;
851
- document.head.removeChild(this.clones[href].clone);
868
+ this.removeCloneNode(href);
852
869
  }
853
870
  removeAllCloneElements() {
854
- for (const clone of Object.values(this.clones)) {
855
- if (!clone) continue;
856
- document.head.removeChild(clone.clone);
871
+ for (const href of Object.keys(this.clones)) {
872
+ this.removeCloneNode(href);
857
873
  }
858
874
  }
859
875
  onCleanTimeout() {
@@ -871,10 +887,6 @@ const _AsyncStylesheetManager$1 = class _AsyncStylesheetManager {
871
887
  this.blowCache();
872
888
  this.currentHref = document.location.href;
873
889
  const href = forElement.href;
874
- console.log(
875
- "AsyncStylesheetManager, registerClone: wants a clone for href:",
876
- href
877
- );
878
890
  if (!href) return;
879
891
  if (href in this.clones && this.clones[href] !== void 0) return;
880
892
  if (forElement.getAttribute("crossorigin") === "anonymous") return;
@@ -904,7 +916,8 @@ const _AsyncStylesheetManager$1 = class _AsyncStylesheetManager {
904
916
  getClonedCssTextIfAvailable(href) {
905
917
  if (href in this.clones && this.clones[href] !== void 0 && this.clones[href].loaded === true) {
906
918
  console.log(
907
- "AsyncStylesheetManager, getClonedCssTextIfAvailable: returning cloned cssText!"
919
+ "AsyncStylesheetManager, getClonedCssTextIfAvailable: returning cloned cssText, for href:",
920
+ href
908
921
  );
909
922
  return this.clones[href].cssText;
910
923
  }
@@ -1306,10 +1319,13 @@ function serializeElementNode(n2, options) {
1306
1319
  }
1307
1320
  if (tagName === "link" && inlineStylesheet) {
1308
1321
  const styleSheets2 = Array.from(doc.styleSheets);
1309
- const styleSheetIndex = styleSheets2.findIndex((s2) => {
1310
- return s2.href === n2.href;
1311
- });
1312
- const stylesheet = styleSheets2[styleSheetIndex];
1322
+ let stylesheet = null;
1323
+ for (let i2 = 0; i2 < styleSheets2.length; i2++) {
1324
+ if (styleSheets2[i2].href === n2.href) {
1325
+ stylesheet = styleSheets2[i2];
1326
+ break;
1327
+ }
1328
+ }
1313
1329
  let cssText = null;
1314
1330
  if (stylesheet) {
1315
1331
  cssText = stringifyStylesheet$1(stylesheet);
@@ -1324,10 +1340,6 @@ function serializeElementNode(n2, options) {
1324
1340
  delete attributes.href;
1325
1341
  attributes._cssText = cssText;
1326
1342
  } else {
1327
- console.log(
1328
- "missing cssText on first passthrough for href:",
1329
- n2.href
1330
- );
1331
1343
  asyncStylesheetManager.registerClone({
1332
1344
  forElement: n2
1333
1345
  });
@@ -5626,23 +5638,40 @@ const _AsyncStylesheetManager2 = class _AsyncStylesheetManager22 {
5626
5638
  if (_AsyncStylesheetManager22.instance) return _AsyncStylesheetManager22.instance;
5627
5639
  _AsyncStylesheetManager22.instance = this;
5628
5640
  }
5641
+ removeCloneNode(href) {
5642
+ if (!(href in this.clones) || this.clones[href] === void 0) return;
5643
+ document.head.removeChild(this.clones[href].clone);
5644
+ }
5629
5645
  onLoad(href) {
5630
5646
  if (!(href in this.clones) || this.clones[href] === void 0) return;
5631
5647
  console.log("AsyncStylesheetManager, onLoad: href:", href);
5632
5648
  const styleSheets2 = Array.from(document.styleSheets);
5633
5649
  let clonedStyleSheet = null;
5634
- document.head.removeChild(this.clones[href].clone);
5635
5650
  for (let i2 = styleSheets2.length - 1; i2 >= 0; i2--) {
5636
5651
  if (styleSheets2[i2].href === href) {
5637
5652
  clonedStyleSheet = styleSheets2[i2];
5638
5653
  break;
5639
5654
  }
5640
5655
  }
5641
- if (!clonedStyleSheet) return;
5656
+ if (!clonedStyleSheet) {
5657
+ console.log(
5658
+ "AsyncStylesheetManager, onLoad: couldn't find stylesheet for href:",
5659
+ href
5660
+ );
5661
+ return this.removeCloneNode(href);
5662
+ }
5642
5663
  const newCssText = stringifyStylesheet(clonedStyleSheet);
5643
- if (!newCssText) return;
5664
+ this.removeCloneNode(href);
5665
+ if (!newCssText) {
5666
+ console.log(
5667
+ "AsyncStylesheetManager, onLoad: couldn't stringify stylesheet for href:",
5668
+ href
5669
+ );
5670
+ return;
5671
+ }
5644
5672
  console.log(
5645
- "AsyncStylesheetManager, onLoad: success! did get new css text! forcing mutation..."
5673
+ "AsyncStylesheetManager, onLoad: success! did get new css text! forcing mutation... for href:",
5674
+ href
5646
5675
  );
5647
5676
  this.clones[href].cssText = newCssText;
5648
5677
  this.clones[href].loaded = true;
@@ -5653,12 +5682,11 @@ const _AsyncStylesheetManager2 = class _AsyncStylesheetManager22 {
5653
5682
  }
5654
5683
  onLoadError(href) {
5655
5684
  if (!(href in this.clones) || this.clones[href] === void 0) return;
5656
- document.head.removeChild(this.clones[href].clone);
5685
+ this.removeCloneNode(href);
5657
5686
  }
5658
5687
  removeAllCloneElements() {
5659
- for (const clone of Object.values(this.clones)) {
5660
- if (!clone) continue;
5661
- document.head.removeChild(clone.clone);
5688
+ for (const href of Object.keys(this.clones)) {
5689
+ this.removeCloneNode(href);
5662
5690
  }
5663
5691
  }
5664
5692
  onCleanTimeout() {
@@ -5676,10 +5704,6 @@ const _AsyncStylesheetManager2 = class _AsyncStylesheetManager22 {
5676
5704
  this.blowCache();
5677
5705
  this.currentHref = document.location.href;
5678
5706
  const href = forElement.href;
5679
- console.log(
5680
- "AsyncStylesheetManager, registerClone: wants a clone for href:",
5681
- href
5682
- );
5683
5707
  if (!href) return;
5684
5708
  if (href in this.clones && this.clones[href] !== void 0) return;
5685
5709
  if (forElement.getAttribute("crossorigin") === "anonymous") return;
@@ -5709,7 +5733,8 @@ const _AsyncStylesheetManager2 = class _AsyncStylesheetManager22 {
5709
5733
  getClonedCssTextIfAvailable(href) {
5710
5734
  if (href in this.clones && this.clones[href] !== void 0 && this.clones[href].loaded === true) {
5711
5735
  console.log(
5712
- "AsyncStylesheetManager, getClonedCssTextIfAvailable: returning cloned cssText!"
5736
+ "AsyncStylesheetManager, getClonedCssTextIfAvailable: returning cloned cssText, for href:",
5737
+ href
5713
5738
  );
5714
5739
  return this.clones[href].cssText;
5715
5740
  }