Move primitives and runtime out of src/common/
Relocate src/common/primitives and src/common/runtime to src/primitives and src/runtime. Add src/tsconfig.json as the primitives+runtime solution. Update tsconfigs, esbuild, webpack aliases, publish path, and docs. Co-authored-by: Daniel Imms <Tyriar@users.noreply.github.com>
This commit is contained in:
co-authored by
Daniel Imms
parent
c569e5ab19
commit
f22ef02831
@@ -0,0 +1,54 @@
|
||||
/**
|
||||
* Copyright (c) 2016 The xterm.js authors. All rights reserved.
|
||||
* @license MIT
|
||||
*/
|
||||
|
||||
interface INavigator {
|
||||
userAgent: string;
|
||||
language: string;
|
||||
platform: string;
|
||||
}
|
||||
|
||||
// We're declaring a navigator global here as we expect it in all runtimes (node and browser), but
|
||||
// we want this module to live in common.
|
||||
declare const navigator: INavigator;
|
||||
declare const process: unknown;
|
||||
|
||||
// navigator.userAgent is also checked here because bundling with the process module can cause
|
||||
// issues otherwise. Note that navigator exists in Node.js 21+ but the userAgent is
|
||||
// "Node.js/<version>".
|
||||
export const isNode = (typeof process !== 'undefined' && 'title' in (process as any) && (typeof navigator === 'undefined' || navigator.userAgent.startsWith('Node.js/'))) ? true : false;
|
||||
const userAgent = (isNode) ? 'node' : navigator.userAgent;
|
||||
const platform = (isNode) ? 'node' : navigator.platform;
|
||||
|
||||
export const isFirefox = userAgent.includes('Firefox');
|
||||
export const isChrome = userAgent.includes('Chrome');
|
||||
export const isLegacyEdge = userAgent.includes('Edge');
|
||||
export const isSafari = /^((?!chrome|android).)*safari/i.test(userAgent);
|
||||
|
||||
interface IZoomWindow {
|
||||
devicePixelRatio?: number;
|
||||
}
|
||||
|
||||
export function getZoomFactor(_targetWindow: IZoomWindow): number {
|
||||
return 1;
|
||||
}
|
||||
export function getSafariVersion(): number {
|
||||
if (!isSafari) {
|
||||
return 0;
|
||||
}
|
||||
const majorVersion = userAgent.match(/Version\/(\d+)/);
|
||||
if (majorVersion === null || majorVersion.length < 2) {
|
||||
return 0;
|
||||
}
|
||||
return parseInt(majorVersion[1]);
|
||||
}
|
||||
|
||||
// Find the users platform. We use this to interpret the meta key
|
||||
// and ISO third level shifts.
|
||||
// http://stackoverflow.com/q/19877924/577598
|
||||
export const isMac = ['Macintosh', 'MacIntel', 'MacPPC', 'Mac68K'].includes(platform);
|
||||
export const isWindows = ['Windows', 'Win16', 'Win32', 'WinCE'].includes(platform);
|
||||
export const isLinux = platform.indexOf('Linux') >= 0;
|
||||
// Note that when this is true, isLinux will also be true.
|
||||
export const isChromeOS = /\bCrOS\b/.test(userAgent);
|
||||
Reference in New Issue
Block a user