os-detect 1.0.0 → 2.0.0
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/LICENSE +21 -0
- package/README.md +190 -19
- package/dist/index.d.mts +28 -0
- package/dist/index.d.ts +28 -0
- package/dist/index.js +229 -0
- package/dist/index.mjs +184 -0
- package/dist/index.umd.js +223 -0
- package/dist/react.d.mts +15 -0
- package/dist/react.d.ts +15 -0
- package/dist/react.js +198 -0
- package/dist/react.mjs +162 -0
- package/dist/react.umd.js +1653 -0
- package/dist/vue.d.mts +16 -0
- package/dist/vue.d.ts +16 -0
- package/dist/vue.js +200 -0
- package/dist/vue.mjs +164 -0
- package/dist/vue.umd.js +57212 -0
- package/package.json +93 -9
- package/index.js +0 -64
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
// src/index.ts
|
|
2
|
+
var cachedIsIOS;
|
|
3
|
+
var cachedIsMacOS;
|
|
4
|
+
var cachedIsAndroid;
|
|
5
|
+
var cachedIsWindows;
|
|
6
|
+
var cachedIsLinux;
|
|
7
|
+
var cachedIsChromeOS;
|
|
8
|
+
function getUADataPlatform() {
|
|
9
|
+
if (typeof navigator === "undefined") return null;
|
|
10
|
+
const uaData = navigator.userAgentData;
|
|
11
|
+
if (uaData && typeof uaData.platform === "string") {
|
|
12
|
+
return uaData.platform.toLowerCase();
|
|
13
|
+
}
|
|
14
|
+
return null;
|
|
15
|
+
}
|
|
16
|
+
function getNodePlatform() {
|
|
17
|
+
if (typeof navigator !== "undefined") return null;
|
|
18
|
+
if (typeof process === "undefined" || typeof process.platform !== "string") return null;
|
|
19
|
+
return process.platform;
|
|
20
|
+
}
|
|
21
|
+
function detectIsIOS() {
|
|
22
|
+
if (typeof cachedIsIOS === "boolean") return cachedIsIOS;
|
|
23
|
+
if (typeof navigator === "undefined" || typeof window === "undefined") {
|
|
24
|
+
return cachedIsIOS = false;
|
|
25
|
+
}
|
|
26
|
+
const platform = getUADataPlatform();
|
|
27
|
+
if (platform !== null) {
|
|
28
|
+
cachedIsIOS = platform === "ios";
|
|
29
|
+
return cachedIsIOS;
|
|
30
|
+
}
|
|
31
|
+
const isClassicIOSUA = /iPhone|iPod/.test(navigator.userAgent);
|
|
32
|
+
const isIPadUA = /iPad/.test(navigator.userAgent);
|
|
33
|
+
const isIPadOS = /Macintosh/.test(navigator.userAgent) && typeof navigator.maxTouchPoints === "number" && navigator.maxTouchPoints > 1;
|
|
34
|
+
cachedIsIOS = isClassicIOSUA || isIPadUA || isIPadOS;
|
|
35
|
+
return cachedIsIOS;
|
|
36
|
+
}
|
|
37
|
+
function detectIsMacOS() {
|
|
38
|
+
if (typeof cachedIsMacOS === "boolean") return cachedIsMacOS;
|
|
39
|
+
const nodePlatform = getNodePlatform();
|
|
40
|
+
if (nodePlatform !== null) {
|
|
41
|
+
return cachedIsMacOS = nodePlatform === "darwin";
|
|
42
|
+
}
|
|
43
|
+
if (typeof navigator === "undefined") return cachedIsMacOS = false;
|
|
44
|
+
const platform = getUADataPlatform();
|
|
45
|
+
if (platform !== null) {
|
|
46
|
+
cachedIsMacOS = platform === "macos";
|
|
47
|
+
return cachedIsMacOS;
|
|
48
|
+
}
|
|
49
|
+
const isMacUA = /Macintosh|MacIntel|MacPPC|Mac68K/.test(navigator.userAgent);
|
|
50
|
+
cachedIsMacOS = isMacUA && !detectIsIOS();
|
|
51
|
+
return cachedIsMacOS;
|
|
52
|
+
}
|
|
53
|
+
function detectIsAndroid() {
|
|
54
|
+
if (typeof cachedIsAndroid === "boolean") return cachedIsAndroid;
|
|
55
|
+
const nodePlatform = getNodePlatform();
|
|
56
|
+
if (nodePlatform !== null) {
|
|
57
|
+
return cachedIsAndroid = nodePlatform === "android";
|
|
58
|
+
}
|
|
59
|
+
if (typeof navigator === "undefined") return cachedIsAndroid = false;
|
|
60
|
+
const platform = getUADataPlatform();
|
|
61
|
+
if (platform !== null) {
|
|
62
|
+
cachedIsAndroid = platform === "android";
|
|
63
|
+
return cachedIsAndroid;
|
|
64
|
+
}
|
|
65
|
+
cachedIsAndroid = /Android/.test(navigator.userAgent);
|
|
66
|
+
return cachedIsAndroid;
|
|
67
|
+
}
|
|
68
|
+
function detectIsWindows() {
|
|
69
|
+
if (typeof cachedIsWindows === "boolean") return cachedIsWindows;
|
|
70
|
+
const nodePlatform = getNodePlatform();
|
|
71
|
+
if (nodePlatform !== null) {
|
|
72
|
+
return cachedIsWindows = nodePlatform === "win32";
|
|
73
|
+
}
|
|
74
|
+
if (typeof navigator === "undefined") return cachedIsWindows = false;
|
|
75
|
+
const platform = getUADataPlatform();
|
|
76
|
+
if (platform !== null) {
|
|
77
|
+
cachedIsWindows = platform === "windows";
|
|
78
|
+
return cachedIsWindows;
|
|
79
|
+
}
|
|
80
|
+
cachedIsWindows = /Win32|Win64|Windows|WinCE/.test(navigator.userAgent);
|
|
81
|
+
return cachedIsWindows;
|
|
82
|
+
}
|
|
83
|
+
function detectIsChromeOS() {
|
|
84
|
+
if (typeof cachedIsChromeOS === "boolean") return cachedIsChromeOS;
|
|
85
|
+
if (typeof navigator === "undefined") return cachedIsChromeOS = false;
|
|
86
|
+
const platform = getUADataPlatform();
|
|
87
|
+
if (platform !== null) {
|
|
88
|
+
cachedIsChromeOS = platform === "chrome os" || platform === "chromeos";
|
|
89
|
+
return cachedIsChromeOS;
|
|
90
|
+
}
|
|
91
|
+
cachedIsChromeOS = /CrOS/.test(navigator.userAgent);
|
|
92
|
+
return cachedIsChromeOS;
|
|
93
|
+
}
|
|
94
|
+
function detectIsLinux() {
|
|
95
|
+
if (typeof cachedIsLinux === "boolean") return cachedIsLinux;
|
|
96
|
+
const nodePlatform = getNodePlatform();
|
|
97
|
+
if (nodePlatform !== null) {
|
|
98
|
+
return cachedIsLinux = nodePlatform === "linux";
|
|
99
|
+
}
|
|
100
|
+
if (typeof navigator === "undefined") return cachedIsLinux = false;
|
|
101
|
+
const platform = getUADataPlatform();
|
|
102
|
+
if (platform !== null) {
|
|
103
|
+
cachedIsLinux = platform === "linux";
|
|
104
|
+
return cachedIsLinux;
|
|
105
|
+
}
|
|
106
|
+
cachedIsLinux = /Linux/.test(navigator.userAgent) && !detectIsAndroid() && !detectIsChromeOS();
|
|
107
|
+
return cachedIsLinux;
|
|
108
|
+
}
|
|
109
|
+
async function detectIsWindows11() {
|
|
110
|
+
var _a, _b;
|
|
111
|
+
if (!detectIsWindows()) return false;
|
|
112
|
+
if (typeof navigator === "undefined" && typeof process !== "undefined") {
|
|
113
|
+
try {
|
|
114
|
+
const { release } = await import("os");
|
|
115
|
+
const buildNumber = parseInt((_a = release().split(".")[2]) != null ? _a : "0", 10);
|
|
116
|
+
return buildNumber >= 22e3;
|
|
117
|
+
} catch (e) {
|
|
118
|
+
return false;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
try {
|
|
122
|
+
const nav = navigator;
|
|
123
|
+
if (!((_b = nav.userAgentData) == null ? void 0 : _b.getHighEntropyValues)) return false;
|
|
124
|
+
const { platformVersion } = await nav.userAgentData.getHighEntropyValues([
|
|
125
|
+
"platformVersion"
|
|
126
|
+
]);
|
|
127
|
+
if (!platformVersion) return false;
|
|
128
|
+
const majorVersion = parseInt(platformVersion.split(".")[0], 10);
|
|
129
|
+
return majorVersion >= 13;
|
|
130
|
+
} catch (e) {
|
|
131
|
+
return false;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
function getOS() {
|
|
135
|
+
if (detectIsIOS()) return "ios";
|
|
136
|
+
if (detectIsAndroid()) return "android";
|
|
137
|
+
if (detectIsChromeOS()) return "chromeos";
|
|
138
|
+
if (detectIsLinux()) return "linux";
|
|
139
|
+
if (detectIsMacOS()) return "macos";
|
|
140
|
+
if (detectIsWindows()) return "windows";
|
|
141
|
+
return "unknown";
|
|
142
|
+
}
|
|
143
|
+
function isMobileDevice() {
|
|
144
|
+
return detectIsIOS() || detectIsAndroid();
|
|
145
|
+
}
|
|
146
|
+
function isDesktopDevice() {
|
|
147
|
+
return detectIsMacOS() || detectIsWindows() || detectIsLinux() || detectIsChromeOS();
|
|
148
|
+
}
|
|
149
|
+
function detectIsiOS() {
|
|
150
|
+
if (typeof console !== "undefined") {
|
|
151
|
+
console.warn(
|
|
152
|
+
"[os-detect] detectIsiOS() is deprecated. Use detectIsIOS() instead. Will be removed in v3.0."
|
|
153
|
+
);
|
|
154
|
+
}
|
|
155
|
+
return detectIsIOS();
|
|
156
|
+
}
|
|
157
|
+
var osDetect = {
|
|
158
|
+
detectIsIOS,
|
|
159
|
+
detectIsMacOS,
|
|
160
|
+
detectIsAndroid,
|
|
161
|
+
detectIsWindows,
|
|
162
|
+
detectIsLinux,
|
|
163
|
+
detectIsChromeOS,
|
|
164
|
+
detectIsWindows11,
|
|
165
|
+
getOS,
|
|
166
|
+
isMobileDevice,
|
|
167
|
+
isDesktopDevice,
|
|
168
|
+
detectIsiOS
|
|
169
|
+
};
|
|
170
|
+
var index_default = osDetect;
|
|
171
|
+
export {
|
|
172
|
+
index_default as default,
|
|
173
|
+
detectIsAndroid,
|
|
174
|
+
detectIsChromeOS,
|
|
175
|
+
detectIsIOS,
|
|
176
|
+
detectIsLinux,
|
|
177
|
+
detectIsMacOS,
|
|
178
|
+
detectIsWindows,
|
|
179
|
+
detectIsWindows11,
|
|
180
|
+
detectIsiOS,
|
|
181
|
+
getOS,
|
|
182
|
+
isDesktopDevice,
|
|
183
|
+
isMobileDevice
|
|
184
|
+
};
|
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var OsDetect = (() => {
|
|
3
|
+
var __create = Object.create;
|
|
4
|
+
var __defProp = Object.defineProperty;
|
|
5
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
8
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
|
+
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
10
|
+
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
11
|
+
}) : x)(function(x) {
|
|
12
|
+
if (typeof require !== "undefined") return require.apply(this, arguments);
|
|
13
|
+
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
14
|
+
});
|
|
15
|
+
var __export = (target, all) => {
|
|
16
|
+
for (var name in all)
|
|
17
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
18
|
+
};
|
|
19
|
+
var __copyProps = (to, from, except, desc) => {
|
|
20
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
21
|
+
for (let key of __getOwnPropNames(from))
|
|
22
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
23
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
24
|
+
}
|
|
25
|
+
return to;
|
|
26
|
+
};
|
|
27
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
28
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
29
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
30
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
31
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
32
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
33
|
+
mod
|
|
34
|
+
));
|
|
35
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
36
|
+
|
|
37
|
+
// src/index.ts
|
|
38
|
+
var index_exports = {};
|
|
39
|
+
__export(index_exports, {
|
|
40
|
+
default: () => index_default,
|
|
41
|
+
detectIsAndroid: () => detectIsAndroid,
|
|
42
|
+
detectIsChromeOS: () => detectIsChromeOS,
|
|
43
|
+
detectIsIOS: () => detectIsIOS,
|
|
44
|
+
detectIsLinux: () => detectIsLinux,
|
|
45
|
+
detectIsMacOS: () => detectIsMacOS,
|
|
46
|
+
detectIsWindows: () => detectIsWindows,
|
|
47
|
+
detectIsWindows11: () => detectIsWindows11,
|
|
48
|
+
detectIsiOS: () => detectIsiOS,
|
|
49
|
+
getOS: () => getOS,
|
|
50
|
+
isDesktopDevice: () => isDesktopDevice,
|
|
51
|
+
isMobileDevice: () => isMobileDevice
|
|
52
|
+
});
|
|
53
|
+
var cachedIsIOS;
|
|
54
|
+
var cachedIsMacOS;
|
|
55
|
+
var cachedIsAndroid;
|
|
56
|
+
var cachedIsWindows;
|
|
57
|
+
var cachedIsLinux;
|
|
58
|
+
var cachedIsChromeOS;
|
|
59
|
+
function getUADataPlatform() {
|
|
60
|
+
if (typeof navigator === "undefined") return null;
|
|
61
|
+
const uaData = navigator.userAgentData;
|
|
62
|
+
if (uaData && typeof uaData.platform === "string") {
|
|
63
|
+
return uaData.platform.toLowerCase();
|
|
64
|
+
}
|
|
65
|
+
return null;
|
|
66
|
+
}
|
|
67
|
+
function getNodePlatform() {
|
|
68
|
+
if (typeof navigator !== "undefined") return null;
|
|
69
|
+
if (typeof process === "undefined" || typeof process.platform !== "string") return null;
|
|
70
|
+
return process.platform;
|
|
71
|
+
}
|
|
72
|
+
function detectIsIOS() {
|
|
73
|
+
if (typeof cachedIsIOS === "boolean") return cachedIsIOS;
|
|
74
|
+
if (typeof navigator === "undefined" || typeof window === "undefined") {
|
|
75
|
+
return cachedIsIOS = false;
|
|
76
|
+
}
|
|
77
|
+
const platform = getUADataPlatform();
|
|
78
|
+
if (platform !== null) {
|
|
79
|
+
cachedIsIOS = platform === "ios";
|
|
80
|
+
return cachedIsIOS;
|
|
81
|
+
}
|
|
82
|
+
const isClassicIOSUA = /iPhone|iPod/.test(navigator.userAgent);
|
|
83
|
+
const isIPadUA = /iPad/.test(navigator.userAgent);
|
|
84
|
+
const isIPadOS = /Macintosh/.test(navigator.userAgent) && typeof navigator.maxTouchPoints === "number" && navigator.maxTouchPoints > 1;
|
|
85
|
+
cachedIsIOS = isClassicIOSUA || isIPadUA || isIPadOS;
|
|
86
|
+
return cachedIsIOS;
|
|
87
|
+
}
|
|
88
|
+
function detectIsMacOS() {
|
|
89
|
+
if (typeof cachedIsMacOS === "boolean") return cachedIsMacOS;
|
|
90
|
+
const nodePlatform = getNodePlatform();
|
|
91
|
+
if (nodePlatform !== null) {
|
|
92
|
+
return cachedIsMacOS = nodePlatform === "darwin";
|
|
93
|
+
}
|
|
94
|
+
if (typeof navigator === "undefined") return cachedIsMacOS = false;
|
|
95
|
+
const platform = getUADataPlatform();
|
|
96
|
+
if (platform !== null) {
|
|
97
|
+
cachedIsMacOS = platform === "macos";
|
|
98
|
+
return cachedIsMacOS;
|
|
99
|
+
}
|
|
100
|
+
const isMacUA = /Macintosh|MacIntel|MacPPC|Mac68K/.test(navigator.userAgent);
|
|
101
|
+
cachedIsMacOS = isMacUA && !detectIsIOS();
|
|
102
|
+
return cachedIsMacOS;
|
|
103
|
+
}
|
|
104
|
+
function detectIsAndroid() {
|
|
105
|
+
if (typeof cachedIsAndroid === "boolean") return cachedIsAndroid;
|
|
106
|
+
const nodePlatform = getNodePlatform();
|
|
107
|
+
if (nodePlatform !== null) {
|
|
108
|
+
return cachedIsAndroid = nodePlatform === "android";
|
|
109
|
+
}
|
|
110
|
+
if (typeof navigator === "undefined") return cachedIsAndroid = false;
|
|
111
|
+
const platform = getUADataPlatform();
|
|
112
|
+
if (platform !== null) {
|
|
113
|
+
cachedIsAndroid = platform === "android";
|
|
114
|
+
return cachedIsAndroid;
|
|
115
|
+
}
|
|
116
|
+
cachedIsAndroid = /Android/.test(navigator.userAgent);
|
|
117
|
+
return cachedIsAndroid;
|
|
118
|
+
}
|
|
119
|
+
function detectIsWindows() {
|
|
120
|
+
if (typeof cachedIsWindows === "boolean") return cachedIsWindows;
|
|
121
|
+
const nodePlatform = getNodePlatform();
|
|
122
|
+
if (nodePlatform !== null) {
|
|
123
|
+
return cachedIsWindows = nodePlatform === "win32";
|
|
124
|
+
}
|
|
125
|
+
if (typeof navigator === "undefined") return cachedIsWindows = false;
|
|
126
|
+
const platform = getUADataPlatform();
|
|
127
|
+
if (platform !== null) {
|
|
128
|
+
cachedIsWindows = platform === "windows";
|
|
129
|
+
return cachedIsWindows;
|
|
130
|
+
}
|
|
131
|
+
cachedIsWindows = /Win32|Win64|Windows|WinCE/.test(navigator.userAgent);
|
|
132
|
+
return cachedIsWindows;
|
|
133
|
+
}
|
|
134
|
+
function detectIsChromeOS() {
|
|
135
|
+
if (typeof cachedIsChromeOS === "boolean") return cachedIsChromeOS;
|
|
136
|
+
if (typeof navigator === "undefined") return cachedIsChromeOS = false;
|
|
137
|
+
const platform = getUADataPlatform();
|
|
138
|
+
if (platform !== null) {
|
|
139
|
+
cachedIsChromeOS = platform === "chrome os" || platform === "chromeos";
|
|
140
|
+
return cachedIsChromeOS;
|
|
141
|
+
}
|
|
142
|
+
cachedIsChromeOS = /CrOS/.test(navigator.userAgent);
|
|
143
|
+
return cachedIsChromeOS;
|
|
144
|
+
}
|
|
145
|
+
function detectIsLinux() {
|
|
146
|
+
if (typeof cachedIsLinux === "boolean") return cachedIsLinux;
|
|
147
|
+
const nodePlatform = getNodePlatform();
|
|
148
|
+
if (nodePlatform !== null) {
|
|
149
|
+
return cachedIsLinux = nodePlatform === "linux";
|
|
150
|
+
}
|
|
151
|
+
if (typeof navigator === "undefined") return cachedIsLinux = false;
|
|
152
|
+
const platform = getUADataPlatform();
|
|
153
|
+
if (platform !== null) {
|
|
154
|
+
cachedIsLinux = platform === "linux";
|
|
155
|
+
return cachedIsLinux;
|
|
156
|
+
}
|
|
157
|
+
cachedIsLinux = /Linux/.test(navigator.userAgent) && !detectIsAndroid() && !detectIsChromeOS();
|
|
158
|
+
return cachedIsLinux;
|
|
159
|
+
}
|
|
160
|
+
async function detectIsWindows11() {
|
|
161
|
+
var _a, _b;
|
|
162
|
+
if (!detectIsWindows()) return false;
|
|
163
|
+
if (typeof navigator === "undefined" && typeof process !== "undefined") {
|
|
164
|
+
try {
|
|
165
|
+
const { release } = await import("os");
|
|
166
|
+
const buildNumber = parseInt((_a = release().split(".")[2]) != null ? _a : "0", 10);
|
|
167
|
+
return buildNumber >= 22e3;
|
|
168
|
+
} catch (e) {
|
|
169
|
+
return false;
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
try {
|
|
173
|
+
const nav = navigator;
|
|
174
|
+
if (!((_b = nav.userAgentData) == null ? void 0 : _b.getHighEntropyValues)) return false;
|
|
175
|
+
const { platformVersion } = await nav.userAgentData.getHighEntropyValues([
|
|
176
|
+
"platformVersion"
|
|
177
|
+
]);
|
|
178
|
+
if (!platformVersion) return false;
|
|
179
|
+
const majorVersion = parseInt(platformVersion.split(".")[0], 10);
|
|
180
|
+
return majorVersion >= 13;
|
|
181
|
+
} catch (e) {
|
|
182
|
+
return false;
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
function getOS() {
|
|
186
|
+
if (detectIsIOS()) return "ios";
|
|
187
|
+
if (detectIsAndroid()) return "android";
|
|
188
|
+
if (detectIsChromeOS()) return "chromeos";
|
|
189
|
+
if (detectIsLinux()) return "linux";
|
|
190
|
+
if (detectIsMacOS()) return "macos";
|
|
191
|
+
if (detectIsWindows()) return "windows";
|
|
192
|
+
return "unknown";
|
|
193
|
+
}
|
|
194
|
+
function isMobileDevice() {
|
|
195
|
+
return detectIsIOS() || detectIsAndroid();
|
|
196
|
+
}
|
|
197
|
+
function isDesktopDevice() {
|
|
198
|
+
return detectIsMacOS() || detectIsWindows() || detectIsLinux() || detectIsChromeOS();
|
|
199
|
+
}
|
|
200
|
+
function detectIsiOS() {
|
|
201
|
+
if (typeof console !== "undefined") {
|
|
202
|
+
console.warn(
|
|
203
|
+
"[os-detect] detectIsiOS() is deprecated. Use detectIsIOS() instead. Will be removed in v3.0."
|
|
204
|
+
);
|
|
205
|
+
}
|
|
206
|
+
return detectIsIOS();
|
|
207
|
+
}
|
|
208
|
+
var osDetect = {
|
|
209
|
+
detectIsIOS,
|
|
210
|
+
detectIsMacOS,
|
|
211
|
+
detectIsAndroid,
|
|
212
|
+
detectIsWindows,
|
|
213
|
+
detectIsLinux,
|
|
214
|
+
detectIsChromeOS,
|
|
215
|
+
detectIsWindows11,
|
|
216
|
+
getOS,
|
|
217
|
+
isMobileDevice,
|
|
218
|
+
isDesktopDevice,
|
|
219
|
+
detectIsiOS
|
|
220
|
+
};
|
|
221
|
+
var index_default = osDetect;
|
|
222
|
+
return __toCommonJS(index_exports);
|
|
223
|
+
})();
|
package/dist/react.d.mts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { OS } from './index.mjs';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Returns the current OS as a string identifier.
|
|
5
|
+
* Detection is synchronous and cached — safe to call on every render.
|
|
6
|
+
*/
|
|
7
|
+
declare function useOS(): OS;
|
|
8
|
+
/**
|
|
9
|
+
* Asynchronously detects whether the current device runs Windows 11.
|
|
10
|
+
* Returns null while the detection is in progress, then true or false.
|
|
11
|
+
* Requires navigator.userAgentData (Chrome 90+ / Edge 90+).
|
|
12
|
+
*/
|
|
13
|
+
declare function useIsWindows11(): boolean | null;
|
|
14
|
+
|
|
15
|
+
export { useIsWindows11, useOS };
|
package/dist/react.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { OS } from './index.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Returns the current OS as a string identifier.
|
|
5
|
+
* Detection is synchronous and cached — safe to call on every render.
|
|
6
|
+
*/
|
|
7
|
+
declare function useOS(): OS;
|
|
8
|
+
/**
|
|
9
|
+
* Asynchronously detects whether the current device runs Windows 11.
|
|
10
|
+
* Returns null while the detection is in progress, then true or false.
|
|
11
|
+
* Requires navigator.userAgentData (Chrome 90+ / Edge 90+).
|
|
12
|
+
*/
|
|
13
|
+
declare function useIsWindows11(): boolean | null;
|
|
14
|
+
|
|
15
|
+
export { useIsWindows11, useOS };
|
package/dist/react.js
ADDED
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// src/react.ts
|
|
31
|
+
var react_exports = {};
|
|
32
|
+
__export(react_exports, {
|
|
33
|
+
useIsWindows11: () => useIsWindows11,
|
|
34
|
+
useOS: () => useOS
|
|
35
|
+
});
|
|
36
|
+
module.exports = __toCommonJS(react_exports);
|
|
37
|
+
var import_react = require("react");
|
|
38
|
+
|
|
39
|
+
// src/index.ts
|
|
40
|
+
var cachedIsIOS;
|
|
41
|
+
var cachedIsMacOS;
|
|
42
|
+
var cachedIsAndroid;
|
|
43
|
+
var cachedIsWindows;
|
|
44
|
+
var cachedIsLinux;
|
|
45
|
+
var cachedIsChromeOS;
|
|
46
|
+
function getUADataPlatform() {
|
|
47
|
+
if (typeof navigator === "undefined") return null;
|
|
48
|
+
const uaData = navigator.userAgentData;
|
|
49
|
+
if (uaData && typeof uaData.platform === "string") {
|
|
50
|
+
return uaData.platform.toLowerCase();
|
|
51
|
+
}
|
|
52
|
+
return null;
|
|
53
|
+
}
|
|
54
|
+
function getNodePlatform() {
|
|
55
|
+
if (typeof navigator !== "undefined") return null;
|
|
56
|
+
if (typeof process === "undefined" || typeof process.platform !== "string") return null;
|
|
57
|
+
return process.platform;
|
|
58
|
+
}
|
|
59
|
+
function detectIsIOS() {
|
|
60
|
+
if (typeof cachedIsIOS === "boolean") return cachedIsIOS;
|
|
61
|
+
if (typeof navigator === "undefined" || typeof window === "undefined") {
|
|
62
|
+
return cachedIsIOS = false;
|
|
63
|
+
}
|
|
64
|
+
const platform = getUADataPlatform();
|
|
65
|
+
if (platform !== null) {
|
|
66
|
+
cachedIsIOS = platform === "ios";
|
|
67
|
+
return cachedIsIOS;
|
|
68
|
+
}
|
|
69
|
+
const isClassicIOSUA = /iPhone|iPod/.test(navigator.userAgent);
|
|
70
|
+
const isIPadUA = /iPad/.test(navigator.userAgent);
|
|
71
|
+
const isIPadOS = /Macintosh/.test(navigator.userAgent) && typeof navigator.maxTouchPoints === "number" && navigator.maxTouchPoints > 1;
|
|
72
|
+
cachedIsIOS = isClassicIOSUA || isIPadUA || isIPadOS;
|
|
73
|
+
return cachedIsIOS;
|
|
74
|
+
}
|
|
75
|
+
function detectIsMacOS() {
|
|
76
|
+
if (typeof cachedIsMacOS === "boolean") return cachedIsMacOS;
|
|
77
|
+
const nodePlatform = getNodePlatform();
|
|
78
|
+
if (nodePlatform !== null) {
|
|
79
|
+
return cachedIsMacOS = nodePlatform === "darwin";
|
|
80
|
+
}
|
|
81
|
+
if (typeof navigator === "undefined") return cachedIsMacOS = false;
|
|
82
|
+
const platform = getUADataPlatform();
|
|
83
|
+
if (platform !== null) {
|
|
84
|
+
cachedIsMacOS = platform === "macos";
|
|
85
|
+
return cachedIsMacOS;
|
|
86
|
+
}
|
|
87
|
+
const isMacUA = /Macintosh|MacIntel|MacPPC|Mac68K/.test(navigator.userAgent);
|
|
88
|
+
cachedIsMacOS = isMacUA && !detectIsIOS();
|
|
89
|
+
return cachedIsMacOS;
|
|
90
|
+
}
|
|
91
|
+
function detectIsAndroid() {
|
|
92
|
+
if (typeof cachedIsAndroid === "boolean") return cachedIsAndroid;
|
|
93
|
+
const nodePlatform = getNodePlatform();
|
|
94
|
+
if (nodePlatform !== null) {
|
|
95
|
+
return cachedIsAndroid = nodePlatform === "android";
|
|
96
|
+
}
|
|
97
|
+
if (typeof navigator === "undefined") return cachedIsAndroid = false;
|
|
98
|
+
const platform = getUADataPlatform();
|
|
99
|
+
if (platform !== null) {
|
|
100
|
+
cachedIsAndroid = platform === "android";
|
|
101
|
+
return cachedIsAndroid;
|
|
102
|
+
}
|
|
103
|
+
cachedIsAndroid = /Android/.test(navigator.userAgent);
|
|
104
|
+
return cachedIsAndroid;
|
|
105
|
+
}
|
|
106
|
+
function detectIsWindows() {
|
|
107
|
+
if (typeof cachedIsWindows === "boolean") return cachedIsWindows;
|
|
108
|
+
const nodePlatform = getNodePlatform();
|
|
109
|
+
if (nodePlatform !== null) {
|
|
110
|
+
return cachedIsWindows = nodePlatform === "win32";
|
|
111
|
+
}
|
|
112
|
+
if (typeof navigator === "undefined") return cachedIsWindows = false;
|
|
113
|
+
const platform = getUADataPlatform();
|
|
114
|
+
if (platform !== null) {
|
|
115
|
+
cachedIsWindows = platform === "windows";
|
|
116
|
+
return cachedIsWindows;
|
|
117
|
+
}
|
|
118
|
+
cachedIsWindows = /Win32|Win64|Windows|WinCE/.test(navigator.userAgent);
|
|
119
|
+
return cachedIsWindows;
|
|
120
|
+
}
|
|
121
|
+
function detectIsChromeOS() {
|
|
122
|
+
if (typeof cachedIsChromeOS === "boolean") return cachedIsChromeOS;
|
|
123
|
+
if (typeof navigator === "undefined") return cachedIsChromeOS = false;
|
|
124
|
+
const platform = getUADataPlatform();
|
|
125
|
+
if (platform !== null) {
|
|
126
|
+
cachedIsChromeOS = platform === "chrome os" || platform === "chromeos";
|
|
127
|
+
return cachedIsChromeOS;
|
|
128
|
+
}
|
|
129
|
+
cachedIsChromeOS = /CrOS/.test(navigator.userAgent);
|
|
130
|
+
return cachedIsChromeOS;
|
|
131
|
+
}
|
|
132
|
+
function detectIsLinux() {
|
|
133
|
+
if (typeof cachedIsLinux === "boolean") return cachedIsLinux;
|
|
134
|
+
const nodePlatform = getNodePlatform();
|
|
135
|
+
if (nodePlatform !== null) {
|
|
136
|
+
return cachedIsLinux = nodePlatform === "linux";
|
|
137
|
+
}
|
|
138
|
+
if (typeof navigator === "undefined") return cachedIsLinux = false;
|
|
139
|
+
const platform = getUADataPlatform();
|
|
140
|
+
if (platform !== null) {
|
|
141
|
+
cachedIsLinux = platform === "linux";
|
|
142
|
+
return cachedIsLinux;
|
|
143
|
+
}
|
|
144
|
+
cachedIsLinux = /Linux/.test(navigator.userAgent) && !detectIsAndroid() && !detectIsChromeOS();
|
|
145
|
+
return cachedIsLinux;
|
|
146
|
+
}
|
|
147
|
+
async function detectIsWindows11() {
|
|
148
|
+
var _a, _b;
|
|
149
|
+
if (!detectIsWindows()) return false;
|
|
150
|
+
if (typeof navigator === "undefined" && typeof process !== "undefined") {
|
|
151
|
+
try {
|
|
152
|
+
const { release } = await import("os");
|
|
153
|
+
const buildNumber = parseInt((_a = release().split(".")[2]) != null ? _a : "0", 10);
|
|
154
|
+
return buildNumber >= 22e3;
|
|
155
|
+
} catch (e) {
|
|
156
|
+
return false;
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
try {
|
|
160
|
+
const nav = navigator;
|
|
161
|
+
if (!((_b = nav.userAgentData) == null ? void 0 : _b.getHighEntropyValues)) return false;
|
|
162
|
+
const { platformVersion } = await nav.userAgentData.getHighEntropyValues([
|
|
163
|
+
"platformVersion"
|
|
164
|
+
]);
|
|
165
|
+
if (!platformVersion) return false;
|
|
166
|
+
const majorVersion = parseInt(platformVersion.split(".")[0], 10);
|
|
167
|
+
return majorVersion >= 13;
|
|
168
|
+
} catch (e) {
|
|
169
|
+
return false;
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
function getOS() {
|
|
173
|
+
if (detectIsIOS()) return "ios";
|
|
174
|
+
if (detectIsAndroid()) return "android";
|
|
175
|
+
if (detectIsChromeOS()) return "chromeos";
|
|
176
|
+
if (detectIsLinux()) return "linux";
|
|
177
|
+
if (detectIsMacOS()) return "macos";
|
|
178
|
+
if (detectIsWindows()) return "windows";
|
|
179
|
+
return "unknown";
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
// src/react.ts
|
|
183
|
+
function useOS() {
|
|
184
|
+
const [os] = (0, import_react.useState)(() => getOS());
|
|
185
|
+
return os;
|
|
186
|
+
}
|
|
187
|
+
function useIsWindows11() {
|
|
188
|
+
const [isWin11, setIsWin11] = (0, import_react.useState)(null);
|
|
189
|
+
(0, import_react.useEffect)(() => {
|
|
190
|
+
detectIsWindows11().then(setIsWin11);
|
|
191
|
+
}, []);
|
|
192
|
+
return isWin11;
|
|
193
|
+
}
|
|
194
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
195
|
+
0 && (module.exports = {
|
|
196
|
+
useIsWindows11,
|
|
197
|
+
useOS
|
|
198
|
+
});
|