51 lines
1.6 KiB
JavaScript
51 lines
1.6 KiB
JavaScript
"use strict";
|
|
|
|
Object.defineProperty(exports, "__esModule", {
|
|
value: true
|
|
});
|
|
exports.maxTouchPoints = exports.lowerUserAgent = exports.lowerPlatform = void 0;
|
|
/**
|
|
* Reads `navigator.userAgent` / `navigator.platform` (legacy but universally
|
|
* supported) into a normalized shape. In development, prefers the modern
|
|
* `navigator.userAgentData` API on Chromium to avoid DevTools warnings about
|
|
* the deprecated reads; that branch is dead-code-eliminated in production
|
|
* builds to keep the bundle small.
|
|
*
|
|
* Returns empty/zero values when `navigator` is undefined (SSR), so every
|
|
* derived flag safely evaluates to `false`.
|
|
*/
|
|
function readRawData() {
|
|
if (typeof navigator === 'undefined') {
|
|
return {
|
|
userAgent: '',
|
|
platform: '',
|
|
maxTouchPoints: 0
|
|
};
|
|
}
|
|
if (process.env.NODE_ENV !== 'production') {
|
|
const uaData = navigator.userAgentData;
|
|
if (uaData && Array.isArray(uaData.brands)) {
|
|
return {
|
|
userAgent: uaData.brands.map(({
|
|
brand,
|
|
version
|
|
}) => `${brand}/${version}`).join(' '),
|
|
platform: uaData.platform ?? navigator.platform ?? '',
|
|
maxTouchPoints: navigator.maxTouchPoints ?? 0
|
|
};
|
|
}
|
|
}
|
|
return {
|
|
userAgent: navigator.userAgent,
|
|
platform: navigator.platform ?? '',
|
|
maxTouchPoints: navigator.maxTouchPoints ?? 0
|
|
};
|
|
}
|
|
const {
|
|
userAgent,
|
|
platform,
|
|
maxTouchPoints
|
|
} = readRawData();
|
|
exports.maxTouchPoints = maxTouchPoints;
|
|
const lowerUserAgent = exports.lowerUserAgent = userAgent.toLowerCase();
|
|
const lowerPlatform = exports.lowerPlatform = platform.toLowerCase(); |