From d57b8ca307b093a3137bcd57c52da55486f7997a Mon Sep 17 00:00:00 2001 From: Veeck Date: Thu, 20 Jul 2023 23:04:25 +0200 Subject: [PATCH] Add latest feature detects and fixes from v4 branch (#2726) * Fix: Update lowbandwidth condition to match new spec (#2688) * Adds PushManager feature detection #2703 (#2708) * Added detection of type worker option and aspect ratio (#2702) --- feature-detects/css/aspectratio.js | 36 ++++++++++++++++++ feature-detects/network/connection.js | 12 ++++-- feature-detects/window/pushmanager.js | 19 ++++++++++ feature-detects/workers/workertypeoption.js | 42 +++++++++++++++++++++ lib/config-all.json | 3 ++ test/browser/integration/caniuse.js | 3 ++ 6 files changed, 111 insertions(+), 4 deletions(-) create mode 100644 feature-detects/css/aspectratio.js create mode 100644 feature-detects/window/pushmanager.js create mode 100644 feature-detects/workers/workertypeoption.js diff --git a/feature-detects/css/aspectratio.js b/feature-detects/css/aspectratio.js new file mode 100644 index 00000000..5a8a6f10 --- /dev/null +++ b/feature-detects/css/aspectratio.js @@ -0,0 +1,36 @@ +/*! +{ + "name": "aspectratio css property", + "property": "aspectratio", + "tags": ["css aspectratio", "aspect-ratio"], + "builderAliases": ["aspectratio"], + "caniuse":"mdn-css_properties_aspect-ratio", + "authors": ["Debadutta Panda"], + "notes": [{ + "name": "MDN Docs", + "href": "https://developer.mozilla.org/en-US/docs/Web/CSS/aspect-ratio" + }] +} +!*/ +/* DOC +Detect working status of all aspectratio css property +https://developer.mozilla.org/en-US/docs/Web/CSS/aspect-ratio +*/ +define(['Modernizr', 'createElement'], function (Modernizr, createElement) { + Modernizr.addTest("aspectratio", function () { + if (typeof CSS !== "object" && typeof CSS.supports === "function") { + return CSS.supports('aspect-ratio', '1 / 1') + } else { + var element = createElement('p'), + elStyle = element.style + if ('aspectRatio' in elStyle) { + elStyle.cssText = 'aspect-ratio:1 / 1' + element.remove() + return (elStyle['aspectRatio'] === '1 / 1'); + } else { + element.remove(); + return false; + } + } + }); +}); \ No newline at end of file diff --git a/feature-detects/network/connection.js b/feature-detects/network/connection.js index 0f814340..9cbc2222 100644 --- a/feature-detects/network/connection.js +++ b/feature-detects/network/connection.js @@ -9,7 +9,7 @@ /* DOC Tests for determining low-bandwidth via `navigator.connection` -There are two iterations of the `navigator.connection` interface. +There are three iterations of the `navigator.connection` interface. The first is present in Android 2.2+ and only in the Browser (not WebView) @@ -22,15 +22,19 @@ The second is speced at https://dvcs.w3.org/hg/dap/raw-file/tip/network-api/Over Unknown devices are assumed as fast +The third is placed at https://wicg.github.io/netinfo/ + +- Support for the old type now only exists in Android 4 and below (https://caniuse.com/netinfo) + For more rigorous network testing, consider boomerang.js: https://github.com/bluesmoon/boomerang/ */ define(['Modernizr'], function(Modernizr) { Modernizr.addTest('lowbandwidth', function() { - // polyfill - var connection = navigator.connection || {type: 0}; + // Polyfill the network info API to inculde both the old type and new effectiveType + var connection = navigator.connection || {type: 0, effectiveType: 0}; return connection.type === 3 || // connection.CELL_2G connection.type === 4 || // connection.CELL_3G - /^[23]g$/.test(connection.type); // string value in new spec + /^[23]g$/.test(connection.effectiveType); // string value in new spec }); }); diff --git a/feature-detects/window/pushmanager.js b/feature-detects/window/pushmanager.js new file mode 100644 index 00000000..bbdb8965 --- /dev/null +++ b/feature-detects/window/pushmanager.js @@ -0,0 +1,19 @@ +/*! +{ + "name": "PushManager", + "property": "pushmanager", + "caniuse": "mdn-api_pushmanager", + "authors": ["Dawid Kulpa (@dawidkulpa)"], + "notes": [{ + "name": "MDN Docs", + "href": "https://developer.mozilla.org/en-US/docs/Web/API/PushManager" + }] +} +!*/ + +/* DOC +Detects support for PushManager. +*/ +define(['Modernizr'], function(Modernizr) { + Modernizr.addTest('pushmanager', 'PushManager' in window); +}); diff --git a/feature-detects/workers/workertypeoption.js b/feature-detects/workers/workertypeoption.js new file mode 100644 index 00000000..0f61c757 --- /dev/null +++ b/feature-detects/workers/workertypeoption.js @@ -0,0 +1,42 @@ +/*! +{ + "name": "worker type option test", + "property": "workertypeoption", + "caniuse":"mdn-api_worker_worker_ecmascript_modules", + "tags": ["web worker type options", "web worker"], + "builderAliases": ["worker_type_options"], + "authors": ["Debadutta Panda"], + "notes": [{ + "name": "MDN Docs", + "href": "https://developer.mozilla.org/en-US/docs/Web/API/Worker/Worker" + }] +} +!*/ +/* DOC +Detect working status of all Workeroptions +https://developer.mozilla.org/en-US/docs/Web/API/Worker/Worker +*/ +define(['Modernizr'], function (Modernizr) { + Modernizr.addTest("workertypeoption", function () { + if ('Worker' in window) { + var isTypeOptionSupported = false, + textTypeOption = { + get type() { + isTypeOptionSupported = true; + return "module" + } + }, + scriptText = `var message='hello'`, + blob = new Blob([scriptText], { type: 'text/javascript' }), + url = URL.createObjectURL(blob) + try { + new Worker(url, textTypeOption).terminate(); + return isTypeOptionSupported; + } catch (err) { + return false; + } + } else { + return false; + } + }); +}); \ No newline at end of file diff --git a/lib/config-all.json b/lib/config-all.json index c512b9b7..01a5cf1d 100644 --- a/lib/config-all.json +++ b/lib/config-all.json @@ -51,6 +51,7 @@ "css/all", "css/animations", "css/appearance", + "css/aspectratio", "css/backdropfilter", "css/backgroundblendmode", "css/backgroundcliptext", @@ -320,7 +321,9 @@ "window/atob-btoa", "window/framed", "window/matchmedia", + "window/pushmanager", "window/resizeobserver", + "workers/workertypeoption", "workers/blobworkers", "workers/dataworkers", "workers/sharedworkers", diff --git a/test/browser/integration/caniuse.js b/test/browser/integration/caniuse.js index 838b0376..ec294850 100644 --- a/test/browser/integration/caniuse.js +++ b/test/browser/integration/caniuse.js @@ -64,6 +64,7 @@ window.caniusecb = function(caniuse) { cssvmaxunit: 'viewport-units', cssvminunit: 'viewport-units', cssvwunit: 'viewport-units', + cssaspectratio:'mdn-css_properties_aspect-ratio', customproperties: 'css-variables', datalistelem: 'datalist', dataset: 'dataset', @@ -126,6 +127,7 @@ window.caniusecb = function(caniuse) { progressbar: 'progress', promises: 'promises', proximity: 'proximity', + pushmanager: 'mdn-api_pushmanager', queryselector: 'queryselector', regions: 'css-regions', requestanimationframe: 'requestanimationframe', @@ -165,6 +167,7 @@ window.caniusecb = function(caniuse) { websockets: 'websockets', websqldatabase: 'sql-storage', webworkers: 'webworkers', + workertypeoption:'mdn-api_worker_worker_ecmascript_modules', willchange: 'will-change', xhr2: 'xhr2' };