112 lines
3.2 KiB
JavaScript
112 lines
3.2 KiB
JavaScript
"use strict";
|
|
var __defProp = Object.defineProperty;
|
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
var __export = (target, all) => {
|
|
for (var name in all)
|
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
};
|
|
var __copyProps = (to, from, except, desc) => {
|
|
if (from && typeof from === "object" || typeof from === "function") {
|
|
for (let key of __getOwnPropNames(from))
|
|
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
}
|
|
return to;
|
|
};
|
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
|
|
// src/user-agent.ts
|
|
var user_agent_exports = {};
|
|
__export(user_agent_exports, {
|
|
detectBrowser: () => detectBrowser,
|
|
detectDeviceType: () => detectDeviceType,
|
|
detectOS: () => detectOS,
|
|
detectTouch: () => detectTouch
|
|
});
|
|
module.exports = __toCommonJS(user_agent_exports);
|
|
|
|
// src/dom.ts
|
|
function canUseDOM() {
|
|
return !!(typeof window !== "undefined" && window.document && window.document.createElement);
|
|
}
|
|
var isBrowser = /* @__PURE__ */ canUseDOM();
|
|
|
|
// src/user-agent.ts
|
|
function getUserAgentBrowser(navigator) {
|
|
const { userAgent: ua, vendor } = navigator;
|
|
const android = /(android)/i.test(ua);
|
|
switch (true) {
|
|
case /CriOS/.test(ua):
|
|
return "Chrome for iOS";
|
|
case /Edg\//.test(ua):
|
|
return "Edge";
|
|
case (android && /Silk\//.test(ua)):
|
|
return "Silk";
|
|
case (/Chrome/.test(ua) && /Google Inc/.test(vendor)):
|
|
return "Chrome";
|
|
case /Firefox\/\d+\.\d+$/.test(ua):
|
|
return "Firefox";
|
|
case android:
|
|
return "AOSP";
|
|
case /MSIE|Trident/.test(ua):
|
|
return "IE";
|
|
case (/Safari/.test(navigator.userAgent) && /Apple Computer/.test(ua)):
|
|
return "Safari";
|
|
case /AppleWebKit/.test(ua):
|
|
return "WebKit";
|
|
default:
|
|
return null;
|
|
}
|
|
}
|
|
function getUserAgentOS(navigator) {
|
|
const { userAgent: ua, platform } = navigator;
|
|
switch (true) {
|
|
case /Android/.test(ua):
|
|
return "Android";
|
|
case /iPhone|iPad|iPod/.test(platform):
|
|
return "iOS";
|
|
case /Win/.test(platform):
|
|
return "Windows";
|
|
case /Mac/.test(platform):
|
|
return "Mac";
|
|
case /CrOS/.test(ua):
|
|
return "Chrome OS";
|
|
case /Firefox/.test(ua):
|
|
return "Firefox OS";
|
|
default:
|
|
return null;
|
|
}
|
|
}
|
|
function detectDeviceType(navigator) {
|
|
const { userAgent: ua } = navigator;
|
|
if (/(tablet)|(iPad)|(Nexus 9)/i.test(ua))
|
|
return "tablet";
|
|
if (/(mobi)/i.test(ua))
|
|
return "phone";
|
|
return "desktop";
|
|
}
|
|
function detectOS(os) {
|
|
if (!isBrowser)
|
|
return false;
|
|
return getUserAgentOS(window.navigator) === os;
|
|
}
|
|
function detectBrowser(browser) {
|
|
if (!isBrowser)
|
|
return false;
|
|
return getUserAgentBrowser(window.navigator) === browser;
|
|
}
|
|
function detectTouch() {
|
|
if (!isBrowser)
|
|
return false;
|
|
return window.ontouchstart === null && window.ontouchmove === null && window.ontouchend === null;
|
|
}
|
|
// Annotate the CommonJS export names for ESM import in node:
|
|
0 && (module.exports = {
|
|
detectBrowser,
|
|
detectDeviceType,
|
|
detectOS,
|
|
detectTouch
|
|
});
|