1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325
|
// This is a helper for MathML feature detection.
// It is indented to be used to prevent false negative test results.
var MathMLFeatureDetection = {
"has_annotation": function() {
// FIXME: Improve feature detection.
return this.has_mspace();
},
"has_annotation-xml": function() {
// FIXME: Improve feature detection.
return this.has_mspace();
},
"has_maction": function() {
// FIXME: Improve feature detection.
return this.has_mspace();
},
"has_math": function() {
// FIXME: Improve feature detection.
return this.has_mspace();
},
"has_menclose": function() {
// Just check whether <mrow> is supported because discussion on this is
// still open ( https://github.com/mathml-refresh/mathml/issues/105 )
// and it would have to behave at least like an mrow, even if it becomes
// an unknown element at the end.
return this.has_mrow();
},
"has_merror": function() {
// FIXME: Improve feature detection.
return this.has_mspace();
},
"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", "<math>\
<mfrac>\
<mspace height='50px' depth='50px'></mspace>\
<mspace height='50px' depth='50px'></mspace>\
</mfrac>\
<mfrac>\
<mspace height='60px' depth='60px'></mspace>\
<mspace height='60px' depth='60px'></mspace>\
</mfrac>\
</math>");
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_mi": function() {
// FIXME: Improve feature detection.
return this.has_mspace();
},
"has_mmultiscripts": function() {
// FIXME: Improve feature detection.
return this.has_mspace();
},
"has_mn": function() {
// FIXME: Improve feature detection.
return this.has_mspace();
},
"has_mo": function() {
// FIXME: Improve feature detection.
return this.has_mspace();
},
"has_mover": function() {
// FIXME: Improve feature detection.
return this.has_munderover();
},
"has_mpadded": function() {
// FIXME: Improve feature detection.
return this.has_mspace();
},
"has_mphantom": function() {
// FIXME: Improve feature detection.
return this.has_mspace();
},
"has_mprescripts": function() {
// FIXME: Improve feature detection.
return this.has_mspace();
},
"has_mroot": function() {
// FIXME: Improve feature detection.
return this.has_msqrt();
},
"has_mrow": function() {
// FIXME: Improve feature detection.
return this.has_mspace();
},
"has_ms": function() {
// FIXME: Improve feature detection.
return this.has_mspace();
},
"has_mspace": function() {
// https://w3c.github.io/mathml-core/#space-mspace
if (!this.hasOwnProperty("_has_mspace")) {
document.body.insertAdjacentHTML("beforeend", "<math>\
<mspace></mspace>\
<mspace width='20px'></mspace>\
</math>");
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_msqrt": function() {
if (!this.hasOwnProperty("_has_msqrt")) {
document.body.insertAdjacentHTML("beforeend", "<math>\
<mrow style='font-size: 20px !important'>\
<mtext>A</mtext>\
</mrow>\
<msqrt style='font-size: 20px !important'>\
<mtext>A</mtext>\
</msqrt>\
</math>");
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_mstyle": function() {
// FIXME: Improve feature detection.
return this.has_mspace();
},
"has_msub": function() {
// FIXME: Improve feature detection.
return this.has_mspace();
},
"has_msubsup": function() {
// FIXME: Improve feature detection.
return this.has_mspace();
},
"has_msup": function() {
// FIXME: Improve feature detection.
return this.has_mspace();
},
"has_mtable": function() {
// FIXME: Improve feature detection.
return this.has_mspace();
},
"has_mtd": function() {
// FIXME: Improve feature detection.
return this.has_mspace();
},
"has_mtext": function() {
// FIXME: Improve feature detection.
return this.has_mspace();
},
"has_mtr": function() {
// FIXME: Improve feature detection.
return this.has_mspace();
},
"has_munder": function() {
// FIXME: Improve feature detection.
return this.has_munderover();
},
"has_munderover": function() {
if (!this.hasOwnProperty("_has_munderover")) {
document.body.insertAdjacentHTML("beforeend", "<math>\
<munderover>\
<mspace width='20px'></mspace>\
<mspace width='20px'></mspace>\
<mspace width='20px'></mspace>\
</munderover>\
<munderover>\
<mspace width='40px'></mspace>\
<mspace width='40px'></mspace>\
<mspace width='40px'></mspace>\
</munderover>\
</math>");
var math = document.body.lastElementChild;
var munderover = math.getElementsByTagName("munderover");
// width_delta will be 20px per MathML, 3 * 20 = 60px if mundeover does not stack its children and 0px if mspace is not supported.
var width_delta =
munderover[1].getBoundingClientRect().width -
munderover[0].getBoundingClientRect().width;
this._has_munderover = width_delta > 10 && width_delta < 30;
document.body.removeChild(math);
}
return this._has_munderover;
},
"has_none": function() {
// FIXME: Improve feature detection.
return this.has_mspace();
},
"has_semantics": function() {
// FIXME: Improve feature detection.
return this.has_mspace();
},
"has_dir": function() {
if (!this.hasOwnProperty("_has_dir")) {
document.body.insertAdjacentHTML("beforeend", "<math style='direction: ltr !important;'>\
<mtext dir='rtl'></mtext>\
</math>");
var math = document.body.lastElementChild;
this._has_dir =
window.getComputedStyle(math.firstElementChild).
getPropertyValue('direction') === 'rtl';
document.body.removeChild(math);
}
return this._has_dir;
},
"has_mathsize": function() {
if (!this.hasOwnProperty("_has_mathsize")) {
document.body.insertAdjacentHTML("beforeend", "<math style='font-size: 64px !important;'>\
<mtext mathsize='32px'></mtext>\
</math>");
var math = document.body.lastElementChild;
this._has_mathsize =
window.getComputedStyle(math.firstElementChild).
getPropertyValue('font-size') === '32px';
document.body.removeChild(math);
}
return this._has_mathsize;
},
"has_movablelimits": function() {
if (!this.hasOwnProperty("_has_movablelimits")) {
document.body.insertAdjacentHTML("beforeend", "<math>\
<munder>\
<mo style='font-size: 30px !important' movablelimits='false'>A</mo>\
<mspace width='100px'></mspace>\
</munder>\
<munder>\
<mo style='font-size: 30px !important' movablelimits='true'>A</mo>\
<mspace width='100px'></mspace>\
</munder>\
</math>");
var math = document.body.lastElementChild;
var munder = math.getElementsByTagName("munder");
// If movablelimits is supported, the <mspace> will be placed next
// to <mo> rather than below it, so width_delta is about the width
// of the <mo>.
var width_delta =
munder[1].getBoundingClientRect().width -
munder[0].getBoundingClientRect().width;
this._has_movablelimits = this.has_munder() && width_delta > 20;
document.body.removeChild(math);
}
return this._has_movablelimits;
},
"has_operator_spacing": function() {
// https://w3c.github.io/mathml-core/#dfn-lspace
// https://w3c.github.io/mathml-core/#layout-of-mrow
if (!this.hasOwnProperty("_has_operator_spacing")) {
document.body.insertAdjacentHTML("beforeend", "<math>\
<mrow>\
<mn>1</mn><mo lspace='0px' rspace='0px'>+</mo><mn>2</mn>\
</mrow>\
<mrow>\
<mn>1</mn><mo lspace='20px' rspace='20px'>+</mo><mn>2</mn>\
</mrow>\
</math>");
var math = document.body.lastElementChild;
var mrow = math.getElementsByTagName("mrow");
// lspace/rspace will add 40px per MathML and none if not supported.
this._has_operator_spacing =
mrow[1].getBoundingClientRect().width -
mrow[0].getBoundingClientRect().width > 30;
document.body.removeChild(math);
}
return this._has_operator_spacing;
},
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", "\
<div style='width: 10px !important; height: 10px !important;\
position: absolute !important;\
left: 0 !important; top: 0 !important;\
background: red !important; z-index: 1000 !important;'></div>");
}
}
};
|