@aller/blink-labrador
Advanced tools
Comparing version 8.27.0 to 8.27.1-alpha.0
@@ -1,5 +0,4 @@ | ||
import type { Metric } from 'web-vitals'; | ||
import { type Metric } from 'web-vitals'; | ||
type LogMetric = { | ||
value: number; | ||
attribution?: string; | ||
} | null; | ||
@@ -23,3 +22,2 @@ type WebVitalsReport = { | ||
fcp(): void; | ||
fid(): void; | ||
get performanceAPISupported(): boolean; | ||
@@ -26,0 +24,0 @@ getAllMetrics(): WebVitalsReport | undefined; |
@@ -7,3 +7,2 @@ "use strict"; | ||
var web_vitals_1 = require("web-vitals"); | ||
var attribution_1 = require("web-vitals/attribution"); | ||
var round_1 = __importDefault(require("../utils/round")); | ||
@@ -29,3 +28,3 @@ var ChromeWebVitals = /** @class */ (function () { | ||
var _this = this; | ||
return (0, attribution_1.onCLS)(function (metric) { return _this.mapMetric(metric); }, { | ||
return (0, web_vitals_1.onCLS)(function (metric) { return _this.mapMetric(metric); }, { | ||
reportAllChanges: true, | ||
@@ -42,3 +41,3 @@ }); | ||
var _this = this; | ||
return (0, attribution_1.onLCP)(function (metric) { return _this.mapMetric(metric); }, { | ||
return (0, web_vitals_1.onLCP)(function (metric) { return _this.mapMetric(metric); }, { | ||
reportAllChanges: true, | ||
@@ -59,8 +58,2 @@ }); | ||
}; | ||
ChromeWebVitals.prototype.fid = function () { | ||
var _this = this; | ||
return (0, web_vitals_1.onFID)(function (report) { | ||
_this.webVitalsReport[report.name] = formatCWVreport(report); | ||
}, { reportAllChanges: true }); | ||
}; | ||
Object.defineProperty(ChromeWebVitals.prototype, "performanceAPISupported", { | ||
@@ -81,3 +74,2 @@ get: function () { | ||
this.fcp(); | ||
this.fid(); | ||
return this.webVitalsReport; | ||
@@ -88,47 +80,12 @@ }; | ||
function formatCWVreport(metric) { | ||
// Picking attribution if available from CLS and LCP | ||
switch (metric.name) { | ||
case 'CLS': { | ||
return potentiallyAttributedAndRoundedMetric(metric, 4); | ||
return { value: (0, round_1.default)(metric.value, 4) }; | ||
} | ||
case 'LCP': { | ||
return potentiallyAttributedAndRoundedMetric(metric, 0); | ||
} | ||
default: { | ||
var value = (0, round_1.default)(metric.value, 0); | ||
return { value: value }; | ||
return { value: (0, round_1.default)(metric.value, 0) }; | ||
} | ||
} | ||
} | ||
// rough version of picking only the metadata we want for now | ||
// largestShiftTarget in CLS and largest paint target in LCP | ||
function attributionElement(metric) { | ||
if ('attribution' in metric && | ||
metric.attribution && | ||
typeof metric.attribution === 'object') { | ||
var attribution = metric.attribution; | ||
if ('largestShiftTarget' in attribution && | ||
attribution.largestShiftTarget && | ||
typeof attribution.largestShiftTarget === 'string' && | ||
attribution.largestShiftTarget.length > 0) { | ||
return attribution.largestShiftTarget; | ||
} | ||
else if ('element' in attribution && | ||
typeof (attribution === null || attribution === void 0 ? void 0 : attribution.element) === 'string' && | ||
attribution.element.length > 0) { | ||
return attribution.element; | ||
} | ||
} | ||
return null; | ||
} | ||
function potentiallyAttributedAndRoundedMetric(metric, rounding) { | ||
var value = metric.value; | ||
var rounded = (0, round_1.default)(value || 0, rounding); | ||
var attribution = attributionElement(metric); | ||
if (attribution) { | ||
return { value: rounded, attribution: attribution }; | ||
} | ||
return { value: rounded }; | ||
} | ||
exports.default = ChromeWebVitals; | ||
//# sourceMappingURL=chrome-web-vitals.js.map |
{ | ||
"name": "@aller/blink-labrador", | ||
"version": "8.27.0", | ||
"version": "8.27.1-alpha.0", | ||
"description": "Library for using blink on Labrador", | ||
@@ -76,6 +76,6 @@ "main": "lib/main.js", | ||
"dependencies": { | ||
"@aller/blink": "^8.27.0", | ||
"@aller/blink": "^8.27.1-alpha.0", | ||
"@soldotno/aller-in-view": "^3.0.2", | ||
"react": "^16.11.0", | ||
"web-vitals": "^3.5.2" | ||
"web-vitals": "^4.2.3" | ||
}, | ||
@@ -96,3 +96,3 @@ "devDependencies": { | ||
}, | ||
"gitHead": "0953fbcdcbe9c0b96e3cb817604ff9db8fa9cd41" | ||
"gitHead": "f53276374fc3f115df397c0f374bf00c9ba9ed22" | ||
} |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
465406
6272
2
+ Addedweb-vitals@4.2.4(transitive)
- Removedweb-vitals@3.5.2(transitive)
Updated@aller/blink@^8.27.1-alpha.0
Updatedweb-vitals@^4.2.3