@mapbox/mapbox-gl-supported
Advanced tools
Comparing version 1.5.0 to 2.0.0
55
index.js
'use strict'; | ||
if (typeof module !== 'undefined' && module.exports) { | ||
module.exports = isSupported; | ||
} else if (window) { | ||
window.mapboxgl = window.mapboxgl || {}; | ||
window.mapboxgl.supported = isSupported; | ||
window.mapboxgl.notSupportedReason = notSupportedReason; | ||
} | ||
exports.supported = isSupported; | ||
exports.notSupportedReason = notSupportedReason; | ||
@@ -34,2 +29,3 @@ /** | ||
if (!isWebGLSupportedCached(options && options.failIfMajorPerformanceCaveat)) return 'insufficient WebGL support'; | ||
if (!isNotIE()) return 'insufficient ECMAScript 6 support'; | ||
} | ||
@@ -122,9 +118,9 @@ | ||
function isCanvasGetImageDataSupported() { | ||
const canvas = document.createElement('canvas'); | ||
var canvas = document.createElement('canvas'); | ||
canvas.width = canvas.height = 1; | ||
const context = canvas.getContext('2d'); | ||
var context = canvas.getContext('2d'); | ||
if (!context) { | ||
return false; | ||
} | ||
const imageData = context.getImageData(0, 0, 1, 1); | ||
var imageData = context.getImageData(0, 0, 1, 1); | ||
return imageData && imageData.width === canvas.width; | ||
@@ -156,24 +152,10 @@ } | ||
if (canvas.probablySupportsContext) { | ||
return ( | ||
canvas.probablySupportsContext('webgl', attributes) || | ||
canvas.probablySupportsContext('experimental-webgl', attributes) | ||
); | ||
} else if (canvas.supportsContext) { | ||
return ( | ||
canvas.supportsContext('webgl', attributes) || | ||
canvas.supportsContext('experimental-webgl', attributes) | ||
); | ||
} else { | ||
return ( | ||
canvas.getContext('webgl', attributes) || | ||
canvas.getContext('experimental-webgl', attributes) | ||
); | ||
} | ||
return ( | ||
canvas.getContext('webgl', attributes) || | ||
canvas.getContext('experimental-webgl', attributes) | ||
); | ||
} | ||
function isWebGLSupported(failIfMajorPerformanceCaveat) { | ||
const gl = getWebGLContext(failIfMajorPerformanceCaveat); | ||
var gl = getWebGLContext(failIfMajorPerformanceCaveat); | ||
if (!gl) { | ||
@@ -185,3 +167,12 @@ return false; | ||
// to prevent fingerprinting. Unfortunately, this also means that Mapbox GL won't work. | ||
const shader = gl.createShader(gl.VERTEX_SHADER); | ||
var shader; | ||
try { | ||
shader = gl.createShader(gl.VERTEX_SHADER); | ||
} catch (e) { | ||
// some older browsers throw an exception that `createShader` is not defined | ||
// so handle this separately from the case where browsers block `createShader` | ||
// for security reasons | ||
return false; | ||
} | ||
if (!shader || gl.isContextLost()) { | ||
@@ -194,1 +185,5 @@ return false; | ||
} | ||
function isNotIE() { | ||
return !document.documentMode; | ||
} |
{ | ||
"name": "@mapbox/mapbox-gl-supported", | ||
"version": "1.5.0", | ||
"version": "2.0.0", | ||
"description": "A library to determine if a browser supports Mapbox GL JS", | ||
@@ -8,3 +8,4 @@ "main": "index.js", | ||
"test": "eslint index.js", | ||
"build": "mkdir -p dist && uglifyjs index.js -c -m -o dist/mapbox-gl-supported.js" | ||
"build": "browserify -s mapboxgl index.js | uglifyjs -c -m -o mapbox-gl-supported.js", | ||
"prepublishOnly": "npm run build" | ||
}, | ||
@@ -20,11 +21,11 @@ "repository": { | ||
"homepage": "https://github.com/mapbox/mapbox-gl-supported#readme", | ||
"files": [ | ||
"mapbox-gl-supported.js" | ||
], | ||
"devDependencies": { | ||
"browserify": "^16.2.3", | ||
"eslint": "^2.8.0", | ||
"browserify": "^17.0.0", | ||
"eslint": "^7.15.0", | ||
"eslint-config-mourner": "^2.0.1", | ||
"uglify-js": "^2.4.24" | ||
}, | ||
"peerDependencies": { | ||
"mapbox-gl": ">=0.32.1 <2.0.0" | ||
"uglify-js": "^3.12.1" | ||
} | ||
} |
@@ -29,3 +29,7 @@ # Mapbox GL JS Supported | ||
```js | ||
var isSupported = require('@mapbox/mapbox-gl-supported')(); | ||
var mapboxglSupported = require('@mapbox/mapbox-gl-supported'); | ||
if (mapboxglSupported.supported()) { | ||
... | ||
} | ||
``` |
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
0
35
11647
5
157
1
2