// This is a helper for MathML feature detection. // It is indented to be used to prevent false negative test results. var MathMLFeatureDetection = { has_mspace: function() { // https://mathml-refresh.github.io/mathml-core/#space-mspace if (!this.hasOwnProperty("_has_mspace")) { document.body.insertAdjacentHTML("beforeend", "\ \ \ "); var math = document.body.lastElementChild; // The width attribute will add 20px per MathML and none if not supported. this._has_mspace = math.lastChild.getBoundingClientRect().width - math.firstChild.getBoundingClientRect().width > 10; document.body.removeChild(math); } return this._has_mspace; }, has_operator_spacing: function() { // https://mathml-refresh.github.io/mathml-core/#dfn-lspace // https://mathml-refresh.github.io/mathml-core/#layout-of-mrow if (!this.hasOwnProperty("_has_operator_spacing")) { document.body.insertAdjacentHTML("beforeend", "\ \ 1+2\ \ \ 1+2\ \ "); var math = document.body.lastElementChild; var mrow = math.getElementsByTagName("mrow"); // lspace/rspace will add 16px per MathML and none if not supported. this._has_operator_spacing = mrow[1].getBoundingClientRect().width - mrow[0].getBoundingClientRect().width > 10; document.body.removeChild(math); } return this._has_operator_spacing; }, has_mfrac: function() { if (!this.hasOwnProperty("_has_mfrac")) { // Use tall enough fraction to avoid side effect of min num/denum shifts. document.body.insertAdjacentHTML("beforeend", "\ \ \ \ \ \ \ \ \ "); var math = document.body.lastElementChild; var mfrac = math.getElementsByTagName("mfrac"); // height/depth will add 40px per MathML, 20px if mfrac does not stack its children and none if mspace is not supported. this._has_mfrac = mfrac[1].getBoundingClientRect().height - mfrac[0].getBoundingClientRect().height > 30; document.body.removeChild(math); } return this._has_mfrac; }, has_msqrt: function() { if (!this.hasOwnProperty("_has_msqrt")) { document.body.insertAdjacentHTML("beforeend", "\ \ A\ \ \ A\ \ "); var math = document.body.lastElementChild; // The radical symbol will make msqrt wider than mrow, if the former is supported. this._has_msqrt = math.lastElementChild.getBoundingClientRect().width - math.firstElementChild.getBoundingClientRect().width > 5; document.body.removeChild(math); } return this._has_msqrt; }, has_menclose: function() { if (!this.hasOwnProperty("_has_menclose")) { document.body.insertAdjacentHTML("beforeend", "\ \ \ \ \ A\ \ \ \ \ \ \ \ \ A\ \ \ \ \ "); var math = document.body.lastElementChild; // The boxes will make menclose wider than mrow, if the former is supported. this._has_menclose = math.lastElementChild.getBoundingClientRect().width - math.firstElementChild.getBoundingClientRect().width > 5; document.body.removeChild(math); } return this._has_menclose; }, has_dir: function() { if (!this.hasOwnProperty("_has_dir")) { document.body.insertAdjacentHTML("beforeend", "\ \ "); var math = document.body.lastElementChild; this._has_dir = window.getComputedStyle(math.firstElementChild). getPropertyValue('direction') === 'rtl'; document.body.removeChild(math); } return this._has_dir; }, ensure_for_match_reftest: function(has_function) { if (!document.querySelector("link[rel='match']")) throw "This function must only be used for match reftest"; // Add a little red square at the top left corner if the feature is not supported in order to make match reftest fail. if (!this[has_function]()) { document.body.insertAdjacentHTML("beforeend", "\
"); } } };