@difizen/mana-common
Version:
213 lines (205 loc) • 8.07 kB
JavaScript
var _nodeProcess, _nodeProcess2;
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
var LANGUAGE_DEFAULT = 'en';
var _isWindows = false;
var _isMacintosh = false;
var _isLinux = false;
var _isLinuxSnap = false;
var _isNative = false;
var _isWeb = false;
var _isIOS = false;
var _locale;
var _language = LANGUAGE_DEFAULT;
var _translationsConfigFile;
var _userAgent;
var _isIE = false;
var _isEdge = false;
var _isOpera = false;
var _isFirefox = false;
var _isWebKit = false;
var _isChrome = true;
var _isSafari = false;
var _isIPad = false;
var _globals = (typeof self === "undefined" ? "undefined" : _typeof(self)) === 'object' ? self : (typeof global === "undefined" ? "undefined" : _typeof(global)) === 'object' ? global : {};
var nodeProcess;
if (typeof process !== 'undefined') {
// Native environment (non-sandboxed)
nodeProcess = process;
} else if (typeof _globals.vscode !== 'undefined') {
// Native environment (sandboxed)
nodeProcess = _globals.vscode.process;
}
var isElectronRenderer = typeof ((_nodeProcess = nodeProcess) === null || _nodeProcess === void 0 || (_nodeProcess = _nodeProcess.versions) === null || _nodeProcess === void 0 ? void 0 : _nodeProcess.electron) === 'string' && nodeProcess.type === 'renderer';
export var isElectronSandboxed = isElectronRenderer && ((_nodeProcess2 = nodeProcess) === null || _nodeProcess2 === void 0 ? void 0 : _nodeProcess2.sandboxed);
export var browserCodeLoadingCacheStrategy = function (_nodeProcess3) {
// Always enabled when sandbox is enabled
if (isElectronSandboxed) {
return 'bypassHeatCheck';
}
// Otherwise, only enabled conditionally
var env = (_nodeProcess3 = nodeProcess) === null || _nodeProcess3 === void 0 ? void 0 : _nodeProcess3.env['ENABLE_VSCODE_BROWSER_CODE_LOADING'];
if (typeof env === 'string') {
if (env === 'none' || env === 'code' || env === 'bypassHeatCheck' || env === 'bypassHeatCheckAndEagerCompile') {
return env;
}
return 'bypassHeatCheck';
}
return undefined;
}();
export var isPreferringBrowserCodeLoad = typeof browserCodeLoadingCacheStrategy === 'string';
// Web environment
if ((typeof navigator === "undefined" ? "undefined" : _typeof(navigator)) === 'object' && !isElectronRenderer) {
_userAgent = navigator.userAgent;
_isWindows = _userAgent.indexOf('Windows') >= 0;
_isMacintosh = _userAgent.indexOf('Macintosh') >= 0;
_isIOS = (_userAgent.indexOf('Macintosh') >= 0 || _userAgent.indexOf('iPad') >= 0 || _userAgent.indexOf('iPhone') >= 0) && !!navigator.maxTouchPoints && navigator.maxTouchPoints > 0;
_isLinux = _userAgent.indexOf('Linux') >= 0;
_isWeb = true;
_locale = navigator.languages ? navigator.languages[0] : navigator.language || navigator.userLanguage;
_language = _locale;
_isIE = _userAgent.indexOf('Trident') >= 0;
_isEdge = _userAgent.indexOf('Edge/') >= 0;
_isOpera = _userAgent.indexOf('Opera') >= 0;
_isFirefox = _userAgent.indexOf('Firefox') >= 0;
_isWebKit = _userAgent.indexOf('AppleWebKit') >= 0;
_isChrome = _userAgent.indexOf('Chrome') >= 0;
_isSafari = _userAgent.indexOf('Chrome') === -1 && _userAgent.indexOf('Safari') >= 0;
_isIPad = _userAgent.indexOf('iPad') >= 0;
}
// Native environment
else if (_typeof(nodeProcess) === 'object') {
_isWindows = nodeProcess.platform === 'win32';
_isMacintosh = nodeProcess.platform === 'darwin';
_isLinux = nodeProcess.platform === 'linux';
_isLinuxSnap = _isLinux && !!nodeProcess.env['SNAP'] && !!nodeProcess.env['SNAP_REVISION'];
_locale = LANGUAGE_DEFAULT;
_language = LANGUAGE_DEFAULT;
var rawNlsConfig = nodeProcess.env['VSCODE_NLS_CONFIG'];
if (rawNlsConfig) {
try {
var nlsConfig = JSON.parse(rawNlsConfig);
var resolved = nlsConfig.availableLanguages['*'];
_locale = nlsConfig.locale;
// VSCode's default language is 'en'
_language = resolved || LANGUAGE_DEFAULT;
_translationsConfigFile = nlsConfig._translationsConfigFile;
} catch (e) {
//
}
}
_isNative = true;
}
// Unknown environment
else {
console.error('Unable to resolve platform.');
}
export var Platform = /*#__PURE__*/function (Platform) {
Platform[Platform["Web"] = 0] = "Web";
Platform[Platform["Mac"] = 1] = "Mac";
Platform[Platform["Linux"] = 2] = "Linux";
Platform[Platform["Windows"] = 3] = "Windows";
return Platform;
}({});
export function PlatformToString(platform) {
switch (platform) {
case Platform.Web:
return 'Web';
case Platform.Mac:
return 'Mac';
case Platform.Linux:
return 'Linux';
case Platform.Windows:
return 'Windows';
}
}
var _platform = Platform.Web;
if (_isMacintosh) {
_platform = Platform.Mac;
} else if (_isWindows) {
_platform = Platform.Windows;
} else if (_isLinux) {
_platform = Platform.Linux;
}
export var isWindows = _isWindows;
export var isMacintosh = _isMacintosh;
export var isOSX = _isMacintosh;
export var isLinux = _isLinux;
export var isLinuxSnap = _isLinuxSnap;
export var isNative = _isNative;
export var isWeb = _isWeb;
export var isIOS = _isIOS;
export var platform = _platform;
export var userAgent = _userAgent;
export var isIE = _isIE;
export var isEdge = _isEdge;
export var isEdgeOrIE = isIE || isEdge;
export var isOpera = _isOpera;
export var isFirefox = _isFirefox;
export var isWebKit = _isWebKit;
export var isChrome = _isChrome;
export var isSafari = _isSafari;
export var isIPad = _isIPad;
/**
* The language used for the user interface. The format of
* the string is all lower case (e.g. zh-tw for Traditional
* Chinese)
*/
export var language = _language;
export var Language;
(function (_Language) {
function value() {
return language;
}
_Language.value = value;
function isDefaultVariant() {
if (language.length === 2) {
return language === 'en';
}
if (language.length >= 3) {
return language[0] === 'e' && language[1] === 'n' && language[2] === '-';
}
return false;
}
_Language.isDefaultVariant = isDefaultVariant;
function isDefault() {
return language === 'en';
}
_Language.isDefault = isDefault;
})(Language || (Language = {}));
/**
* The OS locale or the locale specified by --locale. The format of
* the string is all lower case (e.g. zh-tw for Traditional
* Chinese). The UI is not necessarily shown in the provided locale.
*/
export var locale = _locale;
/**
* The translatios that are available through language packs.
*/
export var translationsConfigFile = _translationsConfigFile;
export var globals = _globals;
export var OperatingSystem = /*#__PURE__*/function (OperatingSystem) {
OperatingSystem[OperatingSystem["Windows"] = 1] = "Windows";
OperatingSystem[OperatingSystem["Macintosh"] = 2] = "Macintosh";
OperatingSystem[OperatingSystem["Linux"] = 3] = "Linux";
return OperatingSystem;
}({});
export var OS = _isMacintosh || _isIOS ? OperatingSystem.Macintosh : _isWindows ? OperatingSystem.Windows : OperatingSystem.Linux;
var _isLittleEndian = true;
var _isLittleEndianComputed = false;
export function isLittleEndian() {
if (!_isLittleEndianComputed) {
_isLittleEndianComputed = true;
var test = new Uint8Array(2);
test[0] = 1;
test[1] = 2;
var view = new Uint16Array(test.buffer);
_isLittleEndian = view[0] === (2 << 8) + 1;
}
return _isLittleEndian;
}
// eslint-disable-next-line @typescript-eslint/no-explicit-any
export var isBasicWasmSupported = isWeb && typeof window.WebAssembly !== 'undefined';