| 1 | |
| 2 | |
| 3 | |
| 4 | |
| 5 | |
| 6 | |
| 7 | |
| 8 | |
| 9 | |
| 10 | |
| 11 | import * as Log from './logging.js'; |
| 12 | import Base64 from '../base64.js'; |
| 13 | |
| 14 | |
| 15 | export let isTouchDevice = ('ontouchstart' in document.documentElement) || |
| 16 | |
| 17 | (document.ontouchstart !== undefined) || |
| 18 | |
| 19 | (navigator.maxTouchPoints > 0) || |
| 20 | (navigator.msMaxTouchPoints > 0); |
| 21 | window.addEventListener('touchstart', function onFirstTouch() { |
| 22 | isTouchDevice = true; |
| 23 | window.removeEventListener('touchstart', onFirstTouch, false); |
| 24 | }, false); |
| 25 | |
| 26 | |
| 27 | |
| 28 | |
| 29 | export let dragThreshold = 10 * (window.devicePixelRatio || 1); |
| 30 | |
| 31 | let _supportsCursorURIs = false; |
| 32 | |
| 33 | try { |
| 34 | const target = document.createElement('canvas'); |
| 35 | target.style.cursor = 'url("data:image/x-icon;base64,AAACAAEACAgAAAIAAgA4AQAAFgAAACgAAAAIAAAAEAAAAAEAIAAAAAAAEAAAAAAAAAAAAAAAAAAAAAAAAAD/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////AAAAAAAAAAAAAAAAAAAAAA==") 2 2, default'; |
| 36 | |
| 37 | if (target.style.cursor.indexOf("url") === 0) { |
| 38 | Log.Info("Data URI scheme cursor supported"); |
| 39 | _supportsCursorURIs = true; |
| 40 | } else { |
| 41 | Log.Warn("Data URI scheme cursor not supported"); |
| 42 | } |
| 43 | } catch (exc) { |
| 44 | Log.Error("Data URI scheme cursor test exception: " + exc); |
| 45 | } |
| 46 | |
| 47 | export const supportsCursorURIs = _supportsCursorURIs; |
| 48 | |
| 49 | let _hasScrollbarGutter = true; |
| 50 | try { |
| 51 | |
| 52 | const container = document.createElement('div'); |
| 53 | container.style.visibility = 'hidden'; |
| 54 | container.style.overflow = 'scroll'; |
| 55 | document.body.appendChild(container); |
| 56 | |
| 57 | |
| 58 | const child = document.createElement('div'); |
| 59 | container.appendChild(child); |
| 60 | |
| 61 | |
| 62 | |
| 63 | const scrollbarWidth = (container.offsetWidth - child.offsetWidth); |
| 64 | |
| 65 | |
| 66 | container.parentNode.removeChild(container); |
| 67 | |
| 68 | _hasScrollbarGutter = scrollbarWidth != 0; |
| 69 | } catch (exc) { |
| 70 | Log.Error("Scrollbar test exception: " + exc); |
| 71 | } |
| 72 | export const hasScrollbarGutter = _hasScrollbarGutter; |
| 73 | |
| 74 | export let supportsWebCodecsH264Decode = false; |
| 75 | |
| 76 | async function _checkWebCodecsH264DecodeSupport() { |
| 77 | if (!('VideoDecoder' in window)) { |
| 78 | return false; |
| 79 | } |
| 80 | |
| 81 | |
| 82 | const config = { |
| 83 | codec: 'avc1.42401f', |
| 84 | codedWidth: 1920, |
| 85 | codedHeight: 1080, |
| 86 | optimizeForLatency: true, |
| 87 | }; |
| 88 | |
| 89 | let support = await VideoDecoder.isConfigSupported(config); |
| 90 | if (!support.supported) { |
| 91 | return false; |
| 92 | } |
| 93 | |
| 94 | |
| 95 | |
| 96 | |
| 97 | |
| 98 | const data = new Uint8Array(Base64.decode( |
| 99 | 'AAAAAWdCwBTZnpuAgICgAAADACAAAAZB4oVNAAAAAWjJYyyAAAABBgX//4Hc' + |
| 100 | 'Rem95tlIt5Ys2CDZI+7veDI2NCAtIGNvcmUgMTY0IHIzMTA4IDMxZTE5Zjkg' + |
| 101 | 'LSBILjI2NC9NUEVHLTQgQVZDIGNvZGVjIC0gQ29weWxlZnQgMjAwMy0yMDIz' + |
| 102 | 'IC0gaHR0cDovL3d3dy52aWRlb2xhbi5vcmcveDI2NC5odG1sIC0gb3B0aW9u' + |
| 103 | 'czogY2FiYWM9MCByZWY9NSBkZWJsb2NrPTE6MDowIGFuYWx5c2U9MHgxOjB4' + |
| 104 | 'MTExIG1lPWhleCBzdWJtZT04IHBzeT0xIHBzeV9yZD0xLjAwOjAuMDAgbWl4' + |
| 105 | 'ZWRfcmVmPTEgbWVfcmFuZ2U9MTYgY2hyb21hX21lPTEgdHJlbGxpcz0yIDh4' + |
| 106 | 'OGRjdD0wIGNxbT0wIGRlYWR6b25lPTIxLDExIGZhc3RfcHNraXA9MSBjaHJv' + |
| 107 | 'bWFfcXBfb2Zmc2V0PS0yIHRocmVhZHM9MSBsb29rYWhlYWRfdGhyZWFkcz0x' + |
| 108 | 'IHNsaWNlZF90aHJlYWRzPTAgbnI9MCBkZWNpbWF0ZT0xIGludGVybGFjZWQ9' + |
| 109 | 'MCBibHVyYXlfY29tcGF0PTAgY29uc3RyYWluZWRfaW50cmE9MCBiZnJhbWVz' + |
| 110 | 'PTAgd2VpZ2h0cD0wIGtleWludD1pbmZpbml0ZSBrZXlpbnRfbWluPTI1IHNj' + |
| 111 | 'ZW5lY3V0PTQwIGludHJhX3JlZnJlc2g9MCByY19sb29rYWhlYWQ9NTAgcmM9' + |
| 112 | 'YWJyIG1idHJlZT0xIGJpdHJhdGU9NDAwIHJhdGV0b2w9MS4wIHFjb21wPTAu' + |
| 113 | 'NjAgcXBtaW49MCBxcG1heD02OSBxcHN0ZXA9NCBpcF9yYXRpbz0xLjQwIGFx' + |
| 114 | 'PTE6MS4wMACAAAABZYiEBrxmKAAPVccAAS044AA5DRJMnkycJk4TPw==')); |
| 115 | |
| 116 | let gotframe = false; |
| 117 | let error = null; |
| 118 | |
| 119 | let decoder = new VideoDecoder({ |
| 120 | output: (frame) => { |
| 121 | gotframe = true; |
| 122 | frame.close(); |
| 123 | }, |
| 124 | error: (e) => { error = e; }, |
| 125 | }); |
| 126 | let chunk = new EncodedVideoChunk({ |
| 127 | timestamp: 0, |
| 128 | type: 'key', |
| 129 | data: data, |
| 130 | }); |
| 131 | |
| 132 | try { |
| 133 | decoder.configure(config); |
| 134 | decoder.decode(chunk); |
| 135 | await decoder.flush(); |
| 136 | } catch (e) { |
| 137 | |
| 138 | |
| 139 | error = e; |
| 140 | } finally { |
| 141 | if (decoder.state !== 'closed') { |
| 142 | decoder.close(); |
| 143 | } |
| 144 | } |
| 145 | |
| 146 | |
| 147 | |
| 148 | |
| 149 | if (!gotframe) { |
| 150 | return false; |
| 151 | } |
| 152 | |
| 153 | if (error !== null) { |
| 154 | return false; |
| 155 | } |
| 156 | |
| 157 | return true; |
| 158 | } |
| 159 | supportsWebCodecsH264Decode = await _checkWebCodecsH264DecodeSupport(); |
| 160 | |
| 161 | |
| 162 | |
| 163 | |
| 164 | |
| 165 | |
| 166 | |
| 167 | |
| 168 | |
| 169 | |
| 170 | export function isMac() { |
| 171 | return !!(/mac/i).exec(navigator.platform); |
| 172 | } |
| 173 | |
| 174 | export function isWindows() { |
| 175 | return !!(/win/i).exec(navigator.platform); |
| 176 | } |
| 177 | |
| 178 | export function isIOS() { |
| 179 | return (!!(/ipad/i).exec(navigator.platform) || |
| 180 | !!(/iphone/i).exec(navigator.platform) || |
| 181 | !!(/ipod/i).exec(navigator.platform)); |
| 182 | } |
| 183 | |
| 184 | export function isAndroid() { |
| 185 | |
| 186 | return !!navigator.userAgent.match('Android '); |
| 187 | } |
| 188 | |
| 189 | export function isChromeOS() { |
| 190 | |
| 191 | return !!navigator.userAgent.match(' CrOS '); |
| 192 | } |
| 193 | |
| 194 | |
| 195 | |
| 196 | export function isSafari() { |
| 197 | return !!navigator.userAgent.match('Safari/...') && |
| 198 | !navigator.userAgent.match('Chrome/...') && |
| 199 | !navigator.userAgent.match('Chromium/...') && |
| 200 | !navigator.userAgent.match('Epiphany/...'); |
| 201 | } |
| 202 | |
| 203 | export function isFirefox() { |
| 204 | return !!navigator.userAgent.match('Firefox/...') && |
| 205 | !navigator.userAgent.match('Seamonkey/...'); |
| 206 | } |
| 207 | |
| 208 | export function isChrome() { |
| 209 | return !!navigator.userAgent.match('Chrome/...') && |
| 210 | !navigator.userAgent.match('Chromium/...') && |
| 211 | !navigator.userAgent.match('Edg/...') && |
| 212 | !navigator.userAgent.match('OPR/...'); |
| 213 | } |
| 214 | |
| 215 | export function isChromium() { |
| 216 | return !!navigator.userAgent.match('Chromium/...'); |
| 217 | } |
| 218 | |
| 219 | export function isOpera() { |
| 220 | return !!navigator.userAgent.match('OPR/...'); |
| 221 | } |
| 222 | |
| 223 | export function isEdge() { |
| 224 | return !!navigator.userAgent.match('Edg/...'); |
| 225 | } |
| 226 | |
| 227 | |
| 228 | |
| 229 | export function isGecko() { |
| 230 | return !!navigator.userAgent.match('Gecko/...'); |
| 231 | } |
| 232 | |
| 233 | export function isWebKit() { |
| 234 | return !!navigator.userAgent.match('AppleWebKit/...') && |
| 235 | !navigator.userAgent.match('Chrome/...'); |
| 236 | } |
| 237 | |
| 238 | export function isBlink() { |
| 239 | return !!navigator.userAgent.match('Chrome/...'); |
| 240 | } |