mirror of
https://github.com/google/blockly.git
synced 2026-01-06 16:40:07 +01:00
* fix(build): Restore erroneously-deleted filter function This was deleted in PR #7406 as it was mainly being used to filter core/ vs. test/mocha/ deps into separate deps files - but it turns out also to be used for filtering error messages too. Oops. * refactor(tests): Migrate advanced compilation test to ES Modules * refactor(build): Migrate main.js to TypeScript This turns out to be pretty straight forward, even if it would cause crashing if one actually tried to import this module instead of just feeding it to Closure Compiler. * chore(build): Remove goog.declareModuleId calls Replace goog.declareModuleId calls with a comment recording the former module ID for posterity (or at least until we decide how to reformat the renamings file. * chore(tests): Delete closure/goog/* For the moment we still need something to serve as base.js for the benefit of closure-make-deps, so we keep a vestigial base.js around, containing only the @provideGoog declaration. * refactor(build): Remove vestigial base.js By changing slightly the command line arguments to closure-make-deps and closure-calculate-chunks the need to have any base.js is eliminated. * chore: Typo fix for PR #7415
87 lines
2.3 KiB
TypeScript
87 lines
2.3 KiB
TypeScript
/**
|
|
* @license
|
|
* Copyright 2019 Google LLC
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
*/
|
|
|
|
// Former goog.module ID: Blockly.utils.userAgent
|
|
|
|
/** The raw useragent string. */
|
|
let rawUserAgent: string;
|
|
|
|
let isJavaFx: boolean;
|
|
|
|
let isWebKit: boolean;
|
|
|
|
let isGecko: boolean;
|
|
|
|
let isAndroid: boolean;
|
|
|
|
let isIPad: boolean;
|
|
|
|
let isIPhone: boolean;
|
|
|
|
let isMac: boolean;
|
|
|
|
let isTablet: boolean;
|
|
|
|
let isMobile: boolean;
|
|
|
|
(function (raw) {
|
|
rawUserAgent = raw;
|
|
const rawUpper = rawUserAgent.toUpperCase();
|
|
/**
|
|
* Case-insensitive test of whether name is in the useragent string.
|
|
*
|
|
* @param name Name to test.
|
|
* @returns True if name is present.
|
|
*/
|
|
function has(name: string): boolean {
|
|
return rawUpper.indexOf(name.toUpperCase()) !== -1;
|
|
}
|
|
|
|
// Browsers. Logic from:
|
|
// https://github.com/google/closure-library/blob/master/closure/goog/labs/useragent/browser.js
|
|
// Useragent for JavaFX:
|
|
// Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.44
|
|
// (KHTML, like Gecko) JavaFX/8.0 Safari/537.44
|
|
isJavaFx = has('JavaFX');
|
|
|
|
// Engines. Logic from:
|
|
// https://github.com/google/closure-library/blob/master/closure/goog/labs/useragent/engine.js
|
|
isWebKit = has('WebKit');
|
|
isGecko = has('Gecko') && !isWebKit;
|
|
|
|
// Platforms. Logic from:
|
|
// https://github.com/google/closure-library/blob/master/closure/goog/labs/useragent/platform.js
|
|
// and
|
|
// https://github.com/google/closure-library/blob/master/closure/goog/labs/useragent/extra.js
|
|
isAndroid = has('Android');
|
|
const maxTouchPoints =
|
|
globalThis['navigator'] && globalThis['navigator']['maxTouchPoints'];
|
|
isIPad = has('iPad') || (has('Macintosh') && maxTouchPoints > 0);
|
|
isIPhone = has('iPhone') && !isIPad;
|
|
isMac = has('Macintosh');
|
|
|
|
// Devices. Logic from:
|
|
// https://github.com/google/closure-library/blob/master/closure/goog/labs/useragent/device.js
|
|
isTablet = isIPad || (isAndroid && !has('Mobile')) || has('Silk');
|
|
isMobile = !isTablet && (isIPhone || isAndroid);
|
|
})((globalThis['navigator'] && globalThis['navigator']['userAgent']) || '');
|
|
|
|
export const raw: string = rawUserAgent;
|
|
|
|
export const JavaFx: boolean = isJavaFx;
|
|
|
|
export const GECKO: boolean = isGecko;
|
|
|
|
export const ANDROID: boolean = isAndroid;
|
|
|
|
export const IPAD: boolean = isIPad;
|
|
|
|
export const IPHONE: boolean = isIPhone;
|
|
|
|
export const MAC: boolean = isMac;
|
|
|
|
export const MOBILE: boolean = isMobile;
|