@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.cjs CHANGED
@@ -485,6 +485,7 @@ function stringifyStylesheet$1(s2) {
485
485
  ).join("");
486
486
  return fixBrowserCompatibilityIssuesInCSS$1(stringifiedRules);
487
487
  } catch (error) {
488
+ console.log("stringifyStylesheet error:", error);
488
489
  return null;
489
490
  }
490
491
  }
@@ -820,23 +821,40 @@ const _AsyncStylesheetManager$1 = class _AsyncStylesheetManager {
820
821
  if (_AsyncStylesheetManager.instance) return _AsyncStylesheetManager.instance;
821
822
  _AsyncStylesheetManager.instance = this;
822
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
+ }
823
828
  onLoad(href) {
824
829
  if (!(href in this.clones) || this.clones[href] === void 0) return;
825
830
  console.log("AsyncStylesheetManager, onLoad: href:", href);
826
831
  const styleSheets2 = Array.from(document.styleSheets);
827
832
  let clonedStyleSheet = null;
828
- document.head.removeChild(this.clones[href].clone);
829
833
  for (let i2 = styleSheets2.length - 1; i2 >= 0; i2--) {
830
834
  if (styleSheets2[i2].href === href) {
831
835
  clonedStyleSheet = styleSheets2[i2];
832
836
  break;
833
837
  }
834
838
  }
835
- 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
+ }
836
846
  const newCssText = stringifyStylesheet$1(clonedStyleSheet);
837
- 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
+ }
838
855
  console.log(
839
- "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
840
858
  );
841
859
  this.clones[href].cssText = newCssText;
842
860
  this.clones[href].loaded = true;
@@ -847,12 +865,11 @@ const _AsyncStylesheetManager$1 = class _AsyncStylesheetManager {
847
865
  }
848
866
  onLoadError(href) {
849
867
  if (!(href in this.clones) || this.clones[href] === void 0) return;
850
- document.head.removeChild(this.clones[href].clone);
868
+ this.removeCloneNode(href);
851
869
  }
852
870
  removeAllCloneElements() {
853
- for (const clone of Object.values(this.clones)) {
854
- if (!clone) continue;
855
- document.head.removeChild(clone.clone);
871
+ for (const href of Object.keys(this.clones)) {
872
+ this.removeCloneNode(href);
856
873
  }
857
874
  }
858
875
  onCleanTimeout() {
@@ -870,10 +887,6 @@ const _AsyncStylesheetManager$1 = class _AsyncStylesheetManager {
870
887
  this.blowCache();
871
888
  this.currentHref = document.location.href;
872
889
  const href = forElement.href;
873
- console.log(
874
- "AsyncStylesheetManager, registerClone: wants a clone for href:",
875
- href
876
- );
877
890
  if (!href) return;
878
891
  if (href in this.clones && this.clones[href] !== void 0) return;
879
892
  if (forElement.getAttribute("crossorigin") === "anonymous") return;
@@ -903,7 +916,8 @@ const _AsyncStylesheetManager$1 = class _AsyncStylesheetManager {
903
916
  getClonedCssTextIfAvailable(href) {
904
917
  if (href in this.clones && this.clones[href] !== void 0 && this.clones[href].loaded === true) {
905
918
  console.log(
906
- "AsyncStylesheetManager, getClonedCssTextIfAvailable: returning cloned cssText!"
919
+ "AsyncStylesheetManager, getClonedCssTextIfAvailable: returning cloned cssText, for href:",
920
+ href
907
921
  );
908
922
  return this.clones[href].cssText;
909
923
  }
@@ -1305,10 +1319,13 @@ function serializeElementNode(n2, options) {
1305
1319
  }
1306
1320
  if (tagName === "link" && inlineStylesheet) {
1307
1321
  const styleSheets2 = Array.from(doc.styleSheets);
1308
- const styleSheetIndex = styleSheets2.findIndex((s2) => {
1309
- return s2.href === n2.href;
1310
- });
1311
- 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
+ }
1312
1329
  let cssText = null;
1313
1330
  if (stylesheet) {
1314
1331
  cssText = stringifyStylesheet$1(stylesheet);
@@ -5524,6 +5541,7 @@ function stringifyStylesheet(s2) {
5524
5541
  ).join("");
5525
5542
  return fixBrowserCompatibilityIssuesInCSS(stringifiedRules);
5526
5543
  } catch (error) {
5544
+ console.log("stringifyStylesheet error:", error);
5527
5545
  return null;
5528
5546
  }
5529
5547
  }
@@ -5620,23 +5638,40 @@ const _AsyncStylesheetManager2 = class _AsyncStylesheetManager22 {
5620
5638
  if (_AsyncStylesheetManager22.instance) return _AsyncStylesheetManager22.instance;
5621
5639
  _AsyncStylesheetManager22.instance = this;
5622
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
+ }
5623
5645
  onLoad(href) {
5624
5646
  if (!(href in this.clones) || this.clones[href] === void 0) return;
5625
5647
  console.log("AsyncStylesheetManager, onLoad: href:", href);
5626
5648
  const styleSheets2 = Array.from(document.styleSheets);
5627
5649
  let clonedStyleSheet = null;
5628
- document.head.removeChild(this.clones[href].clone);
5629
5650
  for (let i2 = styleSheets2.length - 1; i2 >= 0; i2--) {
5630
5651
  if (styleSheets2[i2].href === href) {
5631
5652
  clonedStyleSheet = styleSheets2[i2];
5632
5653
  break;
5633
5654
  }
5634
5655
  }
5635
- 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
+ }
5636
5663
  const newCssText = stringifyStylesheet(clonedStyleSheet);
5637
- 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
+ }
5638
5672
  console.log(
5639
- "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
5640
5675
  );
5641
5676
  this.clones[href].cssText = newCssText;
5642
5677
  this.clones[href].loaded = true;
@@ -5647,12 +5682,11 @@ const _AsyncStylesheetManager2 = class _AsyncStylesheetManager22 {
5647
5682
  }
5648
5683
  onLoadError(href) {
5649
5684
  if (!(href in this.clones) || this.clones[href] === void 0) return;
5650
- document.head.removeChild(this.clones[href].clone);
5685
+ this.removeCloneNode(href);
5651
5686
  }
5652
5687
  removeAllCloneElements() {
5653
- for (const clone of Object.values(this.clones)) {
5654
- if (!clone) continue;
5655
- document.head.removeChild(clone.clone);
5688
+ for (const href of Object.keys(this.clones)) {
5689
+ this.removeCloneNode(href);
5656
5690
  }
5657
5691
  }
5658
5692
  onCleanTimeout() {
@@ -5670,10 +5704,6 @@ const _AsyncStylesheetManager2 = class _AsyncStylesheetManager22 {
5670
5704
  this.blowCache();
5671
5705
  this.currentHref = document.location.href;
5672
5706
  const href = forElement.href;
5673
- console.log(
5674
- "AsyncStylesheetManager, registerClone: wants a clone for href:",
5675
- href
5676
- );
5677
5707
  if (!href) return;
5678
5708
  if (href in this.clones && this.clones[href] !== void 0) return;
5679
5709
  if (forElement.getAttribute("crossorigin") === "anonymous") return;
@@ -5703,7 +5733,8 @@ const _AsyncStylesheetManager2 = class _AsyncStylesheetManager22 {
5703
5733
  getClonedCssTextIfAvailable(href) {
5704
5734
  if (href in this.clones && this.clones[href] !== void 0 && this.clones[href].loaded === true) {
5705
5735
  console.log(
5706
- "AsyncStylesheetManager, getClonedCssTextIfAvailable: returning cloned cssText!"
5736
+ "AsyncStylesheetManager, getClonedCssTextIfAvailable: returning cloned cssText, for href:",
5737
+ href
5707
5738
  );
5708
5739
  return this.clones[href].cssText;
5709
5740
  }