@absolutejs/beacon 0.6.36 → 0.6.37
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/index.js +61 -8
- package/dist/index.js.map +3 -3
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -3800,14 +3800,66 @@ var createBeacon = (options) => {
|
|
|
3800
3800
|
localStorage.setItem(STALE_RELEASE_STORAGE_KEY, JSON.stringify(trimmed));
|
|
3801
3801
|
} catch {}
|
|
3802
3802
|
}
|
|
3803
|
-
if (signals !== null && signals.fontFailures !== false && typeof document !== "undefined" && "fonts" in document) {
|
|
3803
|
+
if (signals !== null && signals.fontFailures !== false && typeof document !== "undefined" && "fonts" in document && (typeof navigator === "undefined" || navigator.webdriver !== true)) {
|
|
3804
3804
|
const reportedFonts = new Set;
|
|
3805
|
+
const checkingFonts = new Set;
|
|
3806
|
+
const normalizedFamily = (family) => family.trim().replace(/^(['"])(.*)\1$/u, "$2").toLowerCase();
|
|
3807
|
+
const isRendered = (element) => {
|
|
3808
|
+
for (let current = element;current !== null; current = current.parentElement) {
|
|
3809
|
+
const style = window.getComputedStyle(current);
|
|
3810
|
+
if (style.display === "none" || style.visibility === "hidden" || style.visibility === "collapse" || Number.parseFloat(style.opacity || "1") <= 0.01) {
|
|
3811
|
+
return false;
|
|
3812
|
+
}
|
|
3813
|
+
}
|
|
3814
|
+
const rect = element.getBoundingClientRect();
|
|
3815
|
+
return rect.width > 0 && rect.height > 0;
|
|
3816
|
+
};
|
|
3817
|
+
const affectedElement = (family) => {
|
|
3818
|
+
const expected = normalizedFamily(family);
|
|
3819
|
+
for (const element of document.querySelectorAll("body *")) {
|
|
3820
|
+
if (!isRendered(element))
|
|
3821
|
+
continue;
|
|
3822
|
+
const style = window.getComputedStyle(element);
|
|
3823
|
+
const families = style.fontFamily.split(",").map(normalizedFamily);
|
|
3824
|
+
if (families.includes(expected))
|
|
3825
|
+
return element;
|
|
3826
|
+
}
|
|
3827
|
+
return null;
|
|
3828
|
+
};
|
|
3829
|
+
const reportFontFailure = (face, element, key) => {
|
|
3830
|
+
reportedFonts.add(key);
|
|
3831
|
+
emitSignal(`Font failure — ${face.family} failed to load — ${shortUrl(location.href)}`, {
|
|
3832
|
+
fontFamily: face.family,
|
|
3833
|
+
fontStretch: face.stretch,
|
|
3834
|
+
fontStyle: face.style,
|
|
3835
|
+
fontWeight: face.weight,
|
|
3836
|
+
signal: BEACON_SIGNAL.FONT_FAILURE,
|
|
3837
|
+
target: describeElement(element)
|
|
3838
|
+
});
|
|
3839
|
+
};
|
|
3840
|
+
const verifyFontFailure = async (face) => {
|
|
3841
|
+
const key = [face.family, face.style, face.weight, face.stretch].join("|");
|
|
3842
|
+
if (reportedFonts.has(key) || checkingFonts.has(key))
|
|
3843
|
+
return;
|
|
3844
|
+
const element = affectedElement(face.family);
|
|
3845
|
+
if (element === null)
|
|
3846
|
+
return;
|
|
3847
|
+
checkingFonts.add(key);
|
|
3848
|
+
const sample = element.textContent?.trim().slice(0, 64) || "BESbswy";
|
|
3849
|
+
const font = `${face.style} ${face.weight} ${face.stretch} 16px ${JSON.stringify(face.family)}`;
|
|
3850
|
+
try {
|
|
3851
|
+
await document.fonts.load(font, sample);
|
|
3852
|
+
if (document.fonts.check(font, sample))
|
|
3853
|
+
return;
|
|
3854
|
+
} catch {} finally {
|
|
3855
|
+
checkingFonts.delete(key);
|
|
3856
|
+
}
|
|
3857
|
+
reportFontFailure(face, element, key);
|
|
3858
|
+
};
|
|
3805
3859
|
const sweepFonts = () => {
|
|
3806
3860
|
document.fonts.forEach((face) => {
|
|
3807
|
-
if (face.status
|
|
3808
|
-
|
|
3809
|
-
reportedFonts.add(face.family);
|
|
3810
|
-
emitSignal(`Font failure — ${face.family} failed to load — ${shortUrl(location.href)}`, { fontFamily: face.family, signal: BEACON_SIGNAL.FONT_FAILURE });
|
|
3861
|
+
if (face.status === "error")
|
|
3862
|
+
verifyFontFailure(face);
|
|
3811
3863
|
});
|
|
3812
3864
|
};
|
|
3813
3865
|
const fontsReady = document.fonts.ready;
|
|
@@ -3817,8 +3869,9 @@ var createBeacon = (options) => {
|
|
|
3817
3869
|
});
|
|
3818
3870
|
}
|
|
3819
3871
|
if (typeof document.fonts.addEventListener === "function") {
|
|
3820
|
-
|
|
3821
|
-
|
|
3872
|
+
const handleLoadingError = () => sweepFonts();
|
|
3873
|
+
document.fonts.addEventListener("loadingerror", handleLoadingError);
|
|
3874
|
+
cleanups.push(() => document.fonts.removeEventListener("loadingerror", handleLoadingError));
|
|
3822
3875
|
}
|
|
3823
3876
|
}
|
|
3824
3877
|
if (signals !== null && signals.requestStorms !== false) {
|
|
@@ -4081,5 +4134,5 @@ export {
|
|
|
4081
4134
|
BEACON_ATTRIBUTE
|
|
4082
4135
|
};
|
|
4083
4136
|
|
|
4084
|
-
//# debugId=
|
|
4137
|
+
//# debugId=E29B0984FFB5596E64756E2164756E21
|
|
4085
4138
|
//# sourceMappingURL=index.js.map
|