From bceca49cdcdd1d72494c68af688cac1484355a35 Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Tue, 4 Feb 2020 11:00:47 +0000 Subject: [PATCH 1/5] Update vendored modernizr --- package.json | 2 +- src/vector/modernizr.js | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index 004d6d7c..edfa893c 100644 --- a/package.json +++ b/package.json @@ -67,7 +67,6 @@ "highlight.js": "^9.13.1", "matrix-js-sdk": "github:matrix-org/matrix-js-sdk#develop", "matrix-react-sdk": "github:matrix-org/matrix-react-sdk#develop", - "modernizr": "^3.6.0", "olm": "https://packages.matrix.org/npm/olm/olm-3.1.4.tgz", "postcss-easings": "^2.0.0", "prop-types": "^15.7.2", @@ -131,6 +130,7 @@ "mini-css-extract-plugin": "^0.8.0", "minimist": "^1.2.0", "mkdirp": "^0.5.1", + "modernizr": "^3.6.0", "optimize-css-assets-webpack-plugin": "^5.0.3", "postcss-extend": "^1.0.5", "postcss-import": "^12.0.1", diff --git a/src/vector/modernizr.js b/src/vector/modernizr.js index 07bd2fd3..5b51d69e 100644 --- a/src/vector/modernizr.js +++ b/src/vector/modernizr.js @@ -1,3 +1,3 @@ -/*! modernizr 3.3.1 (Custom Build) | MIT * - * http://modernizr.com/download/?-displaytable-es5-flexbox-indexeddb-localstorage-objectfit-webworkers-setclasses-cssclassprefix:modernizr_ !*/ -!function(window,document,undefined){function is(e,t){return typeof e===t}function testRunner(){var e,t,r,n,o,i,s;for(var d in tests)if(tests.hasOwnProperty(d)){if(e=[],t=tests[d],t.name&&(e.push(t.name.toLowerCase()),t.options&&t.options.aliases&&t.options.aliases.length))for(r=0;rd;d++)if(l=e[d],c=mStyle.style[l],contains(l,"-")&&(l=cssToDOM(l)),mStyle.style[l]!==undefined){if(n||is(r,"undefined"))return o(),"pfx"==t?l:!0;try{mStyle.style[l]=r}catch(u){}if(mStyle.style[l]!=c)return o(),"pfx"==t?l:!0}return o(),!1}function fnBind(e,t){return function(){return e.apply(t,arguments)}}function testDOMProps(e,t,r){var n;for(var o in e)if(e[o]in t)return r===!1?e[o]:(n=t[e[o]],is(n,"function")?fnBind(n,r||t):n);return!1}function testPropsAll(e,t,r,n,o){var i=e.charAt(0).toUpperCase()+e.slice(1),s=(e+" "+cssomPrefixes.join(i+" ")+i).split(" ");return is(t,"string")||is(t,"undefined")?testProps(s,t,n,o):(s=(e+" "+domPrefixes.join(i+" ")+i).split(" "),testDOMProps(s,t,r))}function testAllProps(e,t,r){return testPropsAll(e,undefined,undefined,t,r)}var tests=[],ModernizrProto={_version:"3.3.1",_config:{classPrefix:"modernizr_",enableClasses:!0,enableJSClass:!0,usePrefixes:!0},_q:[],on:function(e,t){var r=this;setTimeout(function(){t(r[e])},0)},addTest:function(e,t,r){tests.push({name:e,fn:t,options:r})},addAsyncTest:function(e){tests.push({name:null,fn:e})}},Modernizr=function(){};Modernizr.prototype=ModernizrProto,Modernizr=new Modernizr;var classes=[],docElement=document.documentElement,isSVG="svg"===docElement.nodeName.toLowerCase(),testStyles=ModernizrProto.testStyles=injectElementWithStyles;testStyles("#modernizr{display: table; direction: ltr}#modernizr div{display: table-cell; padding: 10px}",function(e){var t,r=e.childNodes;t=r[0].offsetLefto;o++){var i=prefixes[o],s=i.toUpperCase()+"_"+t;if(s in n)return"@-"+i.toLowerCase()+"-"+e}return!1};ModernizrProto.atRule=atRule;var prefixed=ModernizrProto.prefixed=function(e,t,r){return 0===e.indexOf("@")?atRule(e):(-1!=e.indexOf("-")&&(e=cssToDOM(e)),t?testPropsAll(e,t,r):testPropsAll(e,"pfx"))};Modernizr.addTest("objectfit",!!prefixed("objectFit"),{aliases:["object-fit"]}),Modernizr.addTest("localstorage",function(){var e="modernizr";try{return localStorage.setItem(e,e),localStorage.removeItem(e),!0}catch(t){return!1}}),Modernizr.addTest("webworkers","Worker"in window);var indexeddb;try{indexeddb=prefixed("indexedDB",window)}catch(e){}Modernizr.addTest("indexeddb",!!indexeddb),indexeddb&&Modernizr.addTest("indexeddb.deletedatabase","deleteDatabase"in indexeddb),testRunner(),setClasses(classes),delete ModernizrProto.addTest,delete ModernizrProto.addAsyncTest;for(var i=0;i0&&(t+=" "+r+e.join(" "+r)),isSVG?docElement.className.baseVal=t:docElement.className=t)}function createElement(){return"function"!=typeof document.createElement?document.createElement(arguments[0]):isSVG?document.createElementNS.call(document,"http://www.w3.org/2000/svg",arguments[0]):document.createElement.apply(document,arguments)}function getBody(){var e=document.body;return e||(e=createElement(isSVG?"svg":"body"),e.fake=!0),e}function injectElementWithStyles(e,t,r,n){var o,i,s,d,a="modernizr",l=createElement("div"),c=getBody();if(parseInt(r,10))for(;r--;)s=createElement("div"),s.id=n?n[r]:a+(r+1),l.appendChild(s);return o=createElement("style"),o.type="text/css",o.id="s"+a,(c.fake?c:l).appendChild(o),c.appendChild(l),o.styleSheet?o.styleSheet.cssText=e:o.appendChild(document.createTextNode(e)),l.id=a,c.fake&&(c.style.background="",c.style.overflow="hidden",d=docElement.style.overflow,docElement.style.overflow="hidden",docElement.appendChild(c)),i=t(l,e),c.fake?(c.parentNode.removeChild(c),docElement.style.overflow=d,docElement.offsetHeight):l.parentNode.removeChild(l),!!i}function contains(e,t){return!!~(""+e).indexOf(t)}function domToCSS(e){return e.replace(/([A-Z])/g,function(e,t){return"-"+t.toLowerCase()}).replace(/^ms-/,"-ms-")}function computedStyle(e,t,r){var n;if("getComputedStyle"in window){n=getComputedStyle.call(window,e,t);var o=window.console;if(null!==n)r&&(n=n.getPropertyValue(r));else if(o){var i=o.error?"error":"log";o[i].call(o,"getComputedStyle returning null, its possible modernizr test results are inaccurate")}}else n=!t&&e.currentStyle&&e.currentStyle[r];return n}function nativeTestProps(e,t){var r=e.length;if("CSS"in window&&"supports"in window.CSS){for(;r--;)if(window.CSS.supports(domToCSS(e[r]),t))return!0;return!1}if("CSSSupportsRule"in window){for(var n=[];r--;)n.push("("+domToCSS(e[r])+":"+t+")");return n=n.join(" or "),injectElementWithStyles("@supports ("+n+") { #modernizr { position: absolute; } }",function(e){return"absolute"===computedStyle(e,null,"position")})}return undefined}function cssToDOM(e){return e.replace(/([a-z])-([a-z])/g,function(e,t,r){return t+r.toUpperCase()}).replace(/^-/,"")}function testProps(e,t,r,n){function o(){s&&(delete mStyle.style,delete mStyle.modElem)}if(n=!is(n,"undefined")&&n,!is(r,"undefined")){var i=nativeTestProps(e,r);if(!is(i,"undefined"))return i}for(var s,d,a,l,c,u=["modernizr","tspan","samp"];!mStyle.style&&u.length;)s=!0,mStyle.modElem=createElement(u.shift()),mStyle.style=mStyle.modElem.style;for(a=e.length,d=0;d Date: Tue, 4 Feb 2020 11:08:52 +0000 Subject: [PATCH 2/5] Add custom browser checks outside of Modernizr --- src/vector/app.js | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/vector/app.js b/src/vector/app.js index c77049f5..6267ed0b 100644 --- a/src/vector/app.js +++ b/src/vector/app.js @@ -54,6 +54,19 @@ import CallHandler from 'matrix-react-sdk/src/CallHandler'; let lastLocationHashSet = null; function checkBrowserFeatures(featureList) { + // custom checks atop Modernizr because it doesn't have ES2018/ES2019 checks in it for some features we depend on: + // ran prior to Modernizr so the missing features are logged even if Modernizr is broken + // ES2018: http://www.ecma-international.org/ecma-262/9.0/#sec-promise.prototype.finally + if (typeof Promise.prototype.finally !== "function") { + console.error("Browser missing feature: Promise.prototype.finally"); + featureComplete = false; + } + // ES2019: http://www.ecma-international.org/ecma-262/10.0/#sec-object.fromentries + if (typeof Object.fromEntries !== "function") { + console.error("Browser missing feature: Object.fromEntries"); + featureComplete = false; + } + if (!window.Modernizr) { console.error("Cannot check features - Modernizr global is missing."); return false; @@ -69,11 +82,11 @@ function checkBrowserFeatures(featureList) { } if (window.Modernizr[featureList[i]] === false) { console.error("Browser missing feature: '%s'", featureList[i]); - // toggle flag rather than return early so we log all missing features - // rather than just the first. + // toggle flag rather than return early so we log all missing features rather than just the first. featureComplete = false; } } + return featureComplete; } From 087bcf0ae608bdf47db6fd2c28e1a549afdc0028 Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Tue, 4 Feb 2020 11:11:06 +0000 Subject: [PATCH 3/5] fix declaration order --- src/vector/app.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/vector/app.js b/src/vector/app.js index 6267ed0b..b2d9e02c 100644 --- a/src/vector/app.js +++ b/src/vector/app.js @@ -54,6 +54,8 @@ import CallHandler from 'matrix-react-sdk/src/CallHandler'; let lastLocationHashSet = null; function checkBrowserFeatures(featureList) { + let featureComplete = true; + // custom checks atop Modernizr because it doesn't have ES2018/ES2019 checks in it for some features we depend on: // ran prior to Modernizr so the missing features are logged even if Modernizr is broken // ES2018: http://www.ecma-international.org/ecma-262/9.0/#sec-promise.prototype.finally @@ -71,7 +73,6 @@ function checkBrowserFeatures(featureList) { console.error("Cannot check features - Modernizr global is missing."); return false; } - let featureComplete = true; for (let i = 0; i < featureList.length; i++) { if (window.Modernizr[featureList[i]] === undefined) { console.error( From 032efafe2e3c4ca2c82fa633dadaabf221fe2d35 Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Tue, 4 Feb 2020 13:35:05 +0000 Subject: [PATCH 4/5] Rejig things around to catch Promises not being a thing at all --- src/vector/app.js | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/src/vector/app.js b/src/vector/app.js index b2d9e02c..2fe4ddff 100644 --- a/src/vector/app.js +++ b/src/vector/app.js @@ -54,25 +54,12 @@ import CallHandler from 'matrix-react-sdk/src/CallHandler'; let lastLocationHashSet = null; function checkBrowserFeatures(featureList) { - let featureComplete = true; - - // custom checks atop Modernizr because it doesn't have ES2018/ES2019 checks in it for some features we depend on: - // ran prior to Modernizr so the missing features are logged even if Modernizr is broken - // ES2018: http://www.ecma-international.org/ecma-262/9.0/#sec-promise.prototype.finally - if (typeof Promise.prototype.finally !== "function") { - console.error("Browser missing feature: Promise.prototype.finally"); - featureComplete = false; - } - // ES2019: http://www.ecma-international.org/ecma-262/10.0/#sec-object.fromentries - if (typeof Object.fromEntries !== "function") { - console.error("Browser missing feature: Object.fromEntries"); - featureComplete = false; - } - if (!window.Modernizr) { console.error("Cannot check features - Modernizr global is missing."); return false; } + + let featureComplete = true; for (let i = 0; i < featureList.length; i++) { if (window.Modernizr[featureList[i]] === undefined) { console.error( @@ -88,6 +75,18 @@ function checkBrowserFeatures(featureList) { } } + // custom checks atop Modernizr because it doesn't have ES2018/ES2019 checks in it for some features we depend on: + // ES2018: http://www.ecma-international.org/ecma-262/9.0/#sec-promise.prototype.finally + if (!Promise || !Promise.prototype || typeof Promise.prototype.finally !== "function") { + console.error("Browser missing feature: Promise.prototype.finally"); + featureComplete = false; + } + // ES2019: http://www.ecma-international.org/ecma-262/10.0/#sec-object.fromentries + if (!Object || typeof Object.fromEntries !== "function") { + console.error("Browser missing feature: Object.fromEntries"); + featureComplete = false; + } + return featureComplete; } From 7d49078f2274feb101981f5a0b9688b46d59f558 Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Wed, 5 Feb 2020 14:05:46 +0000 Subject: [PATCH 5/5] Change them to Modernizr tests and add more rules --- .modernizr.json | 12 +++++++++++- src/vector/app.js | 31 +++++++++++++------------------ src/vector/modernizr.js | 4 ++-- 3 files changed, 26 insertions(+), 21 deletions(-) diff --git a/.modernizr.json b/.modernizr.json index 06be8b4f..6e1d47c0 100644 --- a/.modernizr.json +++ b/.modernizr.json @@ -11,6 +11,16 @@ "test/css/objectfit", "test/storage/localstorage", "test/workers/webworkers", - "test/indexeddb" + "test/indexeddb", + "test/es6/array", + "test/es6/collections", + "test/es6/promises", + "test/serviceworker", + "test/svg", + "test/svg/asimg", + "test/svg/filters", + "test/css/animations", + "test/css/filters", + "test/network/fetch" ] } diff --git a/src/vector/app.js b/src/vector/app.js index 2fe4ddff..458d061b 100644 --- a/src/vector/app.js +++ b/src/vector/app.js @@ -53,12 +53,23 @@ import CallHandler from 'matrix-react-sdk/src/CallHandler'; let lastLocationHashSet = null; -function checkBrowserFeatures(featureList) { +function checkBrowserFeatures() { if (!window.Modernizr) { console.error("Cannot check features - Modernizr global is missing."); return false; } + // custom checks atop Modernizr because it doesn't have ES2018/ES2019 checks in it for some features we depend on, + // Modernizr requires rules to be lowercase with no punctuation: + // ES2018: http://www.ecma-international.org/ecma-262/9.0/#sec-promise.prototype.finally + window.Modernizr.addTest("promiseprototypefinally", () => + window.Promise && window.Promise.prototype && typeof window.Promise.prototype.finally === "function"); + // ES2019: http://www.ecma-international.org/ecma-262/10.0/#sec-object.fromentries + window.Modernizr.addTest("objectfromentries", () => + window.Object && typeof window.Object.fromEntries === "function"); + + const featureList = Object.keys(window.Modernizr); + let featureComplete = true; for (let i = 0; i < featureList.length; i++) { if (window.Modernizr[featureList[i]] === undefined) { @@ -74,19 +85,6 @@ function checkBrowserFeatures(featureList) { featureComplete = false; } } - - // custom checks atop Modernizr because it doesn't have ES2018/ES2019 checks in it for some features we depend on: - // ES2018: http://www.ecma-international.org/ecma-262/9.0/#sec-promise.prototype.finally - if (!Promise || !Promise.prototype || typeof Promise.prototype.finally !== "function") { - console.error("Browser missing feature: Promise.prototype.finally"); - featureComplete = false; - } - // ES2019: http://www.ecma-international.org/ecma-262/10.0/#sec-object.fromentries - if (!Object || typeof Object.fromEntries !== "function") { - console.error("Browser missing feature: Object.fromEntries"); - featureComplete = false; - } - return featureComplete; } @@ -273,10 +271,7 @@ export async function loadApp() { return; } - const validBrowser = checkBrowserFeatures([ - "displaytable", "flexbox", "es5object", "es5function", "localstorage", - "objectfit", "indexeddb", "webworkers", - ]); + const validBrowser = checkBrowserFeatures(); const acceptInvalidBrowser = window.localStorage && window.localStorage.getItem('mx_accepts_unsupported_browser'); diff --git a/src/vector/modernizr.js b/src/vector/modernizr.js index 5b51d69e..22e330d1 100644 --- a/src/vector/modernizr.js +++ b/src/vector/modernizr.js @@ -1,3 +1,3 @@ /*! modernizr 3.8.0 (Custom Build) | MIT * - * https://modernizr.com/download/?-displaytable-es5-flexbox-indexeddb-localstorage-objectfit-webworkers-setclasses-cssclassprefix:modernizr_ !*/ -!function(window,document,undefined){function is(e,t){return typeof e===t}function testRunner(){var e,t,r,n,o,i,s;for(var d in tests)if(tests.hasOwnProperty(d)){if(e=[],t=tests[d],t.name&&(e.push(t.name.toLowerCase()),t.options&&t.options.aliases&&t.options.aliases.length))for(r=0;r0&&(t+=" "+r+e.join(" "+r)),isSVG?docElement.className.baseVal=t:docElement.className=t)}function createElement(){return"function"!=typeof document.createElement?document.createElement(arguments[0]):isSVG?document.createElementNS.call(document,"http://www.w3.org/2000/svg",arguments[0]):document.createElement.apply(document,arguments)}function getBody(){var e=document.body;return e||(e=createElement(isSVG?"svg":"body"),e.fake=!0),e}function injectElementWithStyles(e,t,r,n){var o,i,s,d,a="modernizr",l=createElement("div"),c=getBody();if(parseInt(r,10))for(;r--;)s=createElement("div"),s.id=n?n[r]:a+(r+1),l.appendChild(s);return o=createElement("style"),o.type="text/css",o.id="s"+a,(c.fake?c:l).appendChild(o),c.appendChild(l),o.styleSheet?o.styleSheet.cssText=e:o.appendChild(document.createTextNode(e)),l.id=a,c.fake&&(c.style.background="",c.style.overflow="hidden",d=docElement.style.overflow,docElement.style.overflow="hidden",docElement.appendChild(c)),i=t(l,e),c.fake?(c.parentNode.removeChild(c),docElement.style.overflow=d,docElement.offsetHeight):l.parentNode.removeChild(l),!!i}function contains(e,t){return!!~(""+e).indexOf(t)}function domToCSS(e){return e.replace(/([A-Z])/g,function(e,t){return"-"+t.toLowerCase()}).replace(/^ms-/,"-ms-")}function computedStyle(e,t,r){var n;if("getComputedStyle"in window){n=getComputedStyle.call(window,e,t);var o=window.console;if(null!==n)r&&(n=n.getPropertyValue(r));else if(o){var i=o.error?"error":"log";o[i].call(o,"getComputedStyle returning null, its possible modernizr test results are inaccurate")}}else n=!t&&e.currentStyle&&e.currentStyle[r];return n}function nativeTestProps(e,t){var r=e.length;if("CSS"in window&&"supports"in window.CSS){for(;r--;)if(window.CSS.supports(domToCSS(e[r]),t))return!0;return!1}if("CSSSupportsRule"in window){for(var n=[];r--;)n.push("("+domToCSS(e[r])+":"+t+")");return n=n.join(" or "),injectElementWithStyles("@supports ("+n+") { #modernizr { position: absolute; } }",function(e){return"absolute"===computedStyle(e,null,"position")})}return undefined}function cssToDOM(e){return e.replace(/([a-z])-([a-z])/g,function(e,t,r){return t+r.toUpperCase()}).replace(/^-/,"")}function testProps(e,t,r,n){function o(){s&&(delete mStyle.style,delete mStyle.modElem)}if(n=!is(n,"undefined")&&n,!is(r,"undefined")){var i=nativeTestProps(e,r);if(!is(i,"undefined"))return i}for(var s,d,a,l,c,u=["modernizr","tspan","samp"];!mStyle.style&&u.length;)s=!0,mStyle.modElem=createElement(u.shift()),mStyle.style=mStyle.modElem.style;for(a=e.length,d=0;d0&&(r+=" "+t+e.join(" "+t)),isSVG?docElement.className.baseVal=r:docElement.className=r)}function createElement(){return"function"!=typeof document.createElement?document.createElement(arguments[0]):isSVG?document.createElementNS.call(document,"http://www.w3.org/2000/svg",arguments[0]):document.createElement.apply(document,arguments)}function getBody(){var e=document.body;return e||(e=createElement(isSVG?"svg":"body"),e.fake=!0),e}function injectElementWithStyles(e,r,t,n){var o,i,s,d,a="modernizr",l=createElement("div"),c=getBody();if(parseInt(t,10))for(;t--;)s=createElement("div"),s.id=n?n[t]:a+(t+1),l.appendChild(s);return o=createElement("style"),o.type="text/css",o.id="s"+a,(c.fake?c:l).appendChild(o),c.appendChild(l),o.styleSheet?o.styleSheet.cssText=e:o.appendChild(document.createTextNode(e)),l.id=a,c.fake&&(c.style.background="",c.style.overflow="hidden",d=docElement.style.overflow,docElement.style.overflow="hidden",docElement.appendChild(c)),i=r(l,e),c.fake?(c.parentNode.removeChild(c),docElement.style.overflow=d,docElement.offsetHeight):l.parentNode.removeChild(l),!!i}function contains(e,r){return!!~(""+e).indexOf(r)}function domToCSS(e){return e.replace(/([A-Z])/g,function(e,r){return"-"+r.toLowerCase()}).replace(/^ms-/,"-ms-")}function computedStyle(e,r,t){var n;if("getComputedStyle"in window){n=getComputedStyle.call(window,e,r);var o=window.console;if(null!==n)t&&(n=n.getPropertyValue(t));else if(o){var i=o.error?"error":"log";o[i].call(o,"getComputedStyle returning null, its possible modernizr test results are inaccurate")}}else n=!r&&e.currentStyle&&e.currentStyle[t];return n}function nativeTestProps(e,r){var t=e.length;if("CSS"in window&&"supports"in window.CSS){for(;t--;)if(window.CSS.supports(domToCSS(e[t]),r))return!0;return!1}if("CSSSupportsRule"in window){for(var n=[];t--;)n.push("("+domToCSS(e[t])+":"+r+")");return n=n.join(" or "),injectElementWithStyles("@supports ("+n+") { #modernizr { position: absolute; } }",function(e){return"absolute"===computedStyle(e,null,"position")})}return undefined}function cssToDOM(e){return e.replace(/([a-z])-([a-z])/g,function(e,r,t){return r+t.toUpperCase()}).replace(/^-/,"")}function testProps(e,r,t,n){function o(){s&&(delete mStyle.style,delete mStyle.modElem)}if(n=!is(n,"undefined")&&n,!is(t,"undefined")){var i=nativeTestProps(e,t);if(!is(i,"undefined"))return i}for(var s,d,a,l,c,u=["modernizr","tspan","samp"];!mStyle.style&&u.length;)s=!0,mStyle.modElem=createElement(u.shift()),mStyle.style=mStyle.modElem.style;for(a=e.length,d=0;d9)}),Modernizr.addTest("fetch","fetch"in window),testRunner(),setClasses(classes),delete ModernizrProto.addTest,delete ModernizrProto.addAsyncTest;for(var i=0;i