@difizen/mana-common
Version:
223 lines (214 loc) • 9.34 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.Platform = exports.OperatingSystem = exports.OS = exports.Language = void 0;
exports.PlatformToString = PlatformToString;
exports.isLinuxSnap = exports.isLinux = exports.isIPad = exports.isIOS = exports.isIE = exports.isFirefox = exports.isElectronSandboxed = exports.isEdgeOrIE = exports.isEdge = exports.isChrome = exports.isBasicWasmSupported = exports.globals = exports.browserCodeLoadingCacheStrategy = void 0;
exports.isLittleEndian = isLittleEndian;
exports.userAgent = exports.translationsConfigFile = exports.platform = exports.locale = exports.language = exports.isWindows = exports.isWebKit = exports.isWeb = exports.isSafari = exports.isPreferringBrowserCodeLoad = exports.isOpera = exports.isOSX = exports.isNative = exports.isMacintosh = void 0;
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';
var isElectronSandboxed = exports.isElectronSandboxed = isElectronRenderer && ((_nodeProcess2 = nodeProcess) === null || _nodeProcess2 === void 0 ? void 0 : _nodeProcess2.sandboxed);
var browserCodeLoadingCacheStrategy = exports.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;
}();
var isPreferringBrowserCodeLoad = exports.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.');
}
var Platform = exports.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;
}({});
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;
}
var isWindows = exports.isWindows = _isWindows;
var isMacintosh = exports.isMacintosh = _isMacintosh;
var isOSX = exports.isOSX = _isMacintosh;
var isLinux = exports.isLinux = _isLinux;
var isLinuxSnap = exports.isLinuxSnap = _isLinuxSnap;
var isNative = exports.isNative = _isNative;
var isWeb = exports.isWeb = _isWeb;
var isIOS = exports.isIOS = _isIOS;
var platform = exports.platform = _platform;
var userAgent = exports.userAgent = _userAgent;
var isIE = exports.isIE = _isIE;
var isEdge = exports.isEdge = _isEdge;
var isEdgeOrIE = exports.isEdgeOrIE = isIE || isEdge;
var isOpera = exports.isOpera = _isOpera;
var isFirefox = exports.isFirefox = _isFirefox;
var isWebKit = exports.isWebKit = _isWebKit;
var isChrome = exports.isChrome = _isChrome;
var isSafari = exports.isSafari = _isSafari;
var isIPad = exports.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)
*/
var language = exports.language = _language;
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 || (exports.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.
*/
var locale = exports.locale = _locale;
/**
* The translatios that are available through language packs.
*/
var translationsConfigFile = exports.translationsConfigFile = _translationsConfigFile;
var globals = exports.globals = _globals;
var OperatingSystem = exports.OperatingSystem = /*#__PURE__*/function (OperatingSystem) {
OperatingSystem[OperatingSystem["Windows"] = 1] = "Windows";
OperatingSystem[OperatingSystem["Macintosh"] = 2] = "Macintosh";
OperatingSystem[OperatingSystem["Linux"] = 3] = "Linux";
return OperatingSystem;
}({});
var OS = exports.OS = _isMacintosh || _isIOS ? OperatingSystem.Macintosh : _isWindows ? OperatingSystem.Windows : OperatingSystem.Linux;
var _isLittleEndian = true;
var _isLittleEndianComputed = false;
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
var isBasicWasmSupported = exports.isBasicWasmSupported = isWeb && typeof window.WebAssembly !== 'undefined';