| 1 |
/* -*- Mode: Javascript; indent-tabs-mode:nil; js-indent-level: 2 -*- */ |
| 2 |
/* vim: set ts=2 et sw=2 tw=80: */ |
| 3 |
|
| 4 |
/************************************************************* |
| 5 |
* |
| 6 |
* MathJax/jax/output/CommonHTML/autoload/menclose.js |
| 7 |
* |
| 8 |
* Implements the CommonHTML output for <menclose> elements. |
| 9 |
* |
| 10 |
* --------------------------------------------------------------------- |
| 11 |
* |
| 12 |
* Copyright (c) 2015-2020 The MathJax Consortium |
| 13 |
* |
| 14 |
* Licensed under the Apache License, Version 2.0 (the "License"); |
| 15 |
* you may not use this file except in compliance with the License. |
| 16 |
* You may obtain a copy of the License at |
| 17 |
* |
| 18 |
* http://www.apache.org/licenses/LICENSE-2.0 |
| 19 |
* |
| 20 |
* Unless required by applicable law or agreed to in writing, software |
| 21 |
* distributed under the License is distributed on an "AS IS" BASIS, |
| 22 |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 23 |
* See the License for the specific language governing permissions and |
| 24 |
* limitations under the License. |
| 25 |
*/ |
| 26 |
|
| 27 |
MathJax.Hub.Register.StartupHook("CommonHTML Jax Ready",function () { |
| 28 |
var VERSION = "2.7.9"; |
| 29 |
var MML = MathJax.ElementJax.mml, |
| 30 |
CHTML = MathJax.OutputJax.CommonHTML; |
| 31 |
|
| 32 |
var SVGNS = "http://www.w3.org/2000/svg"; |
| 33 |
var ARROWX = 4, ARROWDX = 1, ARROWY = 2; |
| 34 |
|
| 35 |
MML.menclose.Augment({ |
| 36 |
toCommonHTML: function (node) { |
| 37 |
var values = this.getValues("notation","thickness","padding"); |
| 38 |
if (values.thickness == null) values.thickness = ".075em"; |
| 39 |
if (values.padding == null) values.padding = ".2em"; |
| 40 |
// |
| 41 |
// Get DOM nodes |
| 42 |
// |
| 43 |
node = this.CHTMLdefaultNode(node,{childNodes:"mjx-box", forceChild:true}); |
| 44 |
var child = node.firstChild, cbox = this.CHTMLbboxFor(0); |
| 45 |
// |
| 46 |
// Get the padding and rule thickness |
| 47 |
// |
| 48 |
var p = this.CHTMLlength2em(values.padding,1/CHTML.em); // padding for enclosure |
| 49 |
var t = this.CHTMLlength2em(values.thickness,1/CHTML.em); // thickness of lines |
| 50 |
t = Math.max(1,Math.round(t*CHTML.em))/CHTML.em; |
| 51 |
var SOLID = CHTML.Px(t)+" solid"; |
| 52 |
var bb = {L:p, R:p, T:p, B:p, H:cbox.h+p, D:cbox.d+p, W:cbox.w+2*p}; |
| 53 |
child.style.padding = CHTML.Em(p); |
| 54 |
// |
| 55 |
// Eliminate duplicate notations. |
| 56 |
// |
| 57 |
var notations = MathJax.Hub.SplitList(values.notation), notation = {}; |
| 58 |
for (var i = 0, m = notations.length; i < m; i++) notation[notations[i]] = true; |
| 59 |
if (notation[MML.NOTATION.UPDIAGONALARROW]) delete notation[MML.NOTATION.UPDIAGONALSTRIKE]; |
| 60 |
// |
| 61 |
// Add the needed notations |
| 62 |
// |
| 63 |
for (var n in notation) { |
| 64 |
if (notation.hasOwnProperty(n)) { |
| 65 |
if (this.CHTMLnotation[n] && this.CHTMLnotation.hasOwnProperty(n)) |
| 66 |
this.CHTMLnotation[n].call(this,child,cbox,bb,p,t,SOLID); |
| 67 |
} |
| 68 |
} |
| 69 |
// |
| 70 |
// Adjust the bounding box |
| 71 |
// |
| 72 |
var BBOX = this.CHTML; |
| 73 |
BBOX.w += bb.L + bb.R; BBOX.r += BBOX.L; if (BBOX.w > BBOX.r) BBOX.r = BBOX.w; |
| 74 |
BBOX.h += bb.T; if (BBOX.h > BBOX.t) BBOX.t = BBOX.h; |
| 75 |
BBOX.d += bb.B; if (BBOX.d > BBOX.b) BBOX.b = BBOX.d; |
| 76 |
|
| 77 |
return node; |
| 78 |
}, |
| 79 |
// |
| 80 |
// The various notations and their implementations |
| 81 |
// |
| 82 |
CHTMLnotation: { |
| 83 |
|
| 84 |
/********************************************************/ |
| 85 |
|
| 86 |
box: function (child,cbox,bb,p,t,SOLID) { |
| 87 |
p -= t; |
| 88 |
child.style.padding = CHTML.Em(p); |
| 89 |
child.style.border = SOLID; |
| 90 |
}, |
| 91 |
|
| 92 |
/********************************************************/ |
| 93 |
|
| 94 |
roundedbox: function (child,cbox,bb,p,t,SOLID) { |
| 95 |
var r = Math.min(cbox.w,cbox.h+cbox.d+2*p)/4; |
| 96 |
CHTML.addElement(child.parentNode,"mjx-box",{ |
| 97 |
style: { |
| 98 |
padding:CHTML.Em(p-t), border:SOLID, "border-radius":CHTML.Em(r), |
| 99 |
height:CHTML.Em(cbox.h+cbox.d), "vertical-align":CHTML.Em(-bb.D), |
| 100 |
width:CHTML.Em(cbox.w), "margin-left":CHTML.Em(-bb.W) |
| 101 |
} |
| 102 |
}); |
| 103 |
}, |
| 104 |
|
| 105 |
/********************************************************/ |
| 106 |
|
| 107 |
circle: function (child,cbox,bb,p,t,SOLID) { |
| 108 |
var H = bb.H, D = bb.D, W = bb.W; |
| 109 |
var svg = this.CHTMLsvg(child,bb,t); |
| 110 |
this.CHTMLsvgElement(svg.firstChild,"ellipse",{ |
| 111 |
rx:CHTML.Px(W/2-t/2), ry:CHTML.Px((H+D)/2-t/2), |
| 112 |
cx:CHTML.Px(W/2), cy:CHTML.Px((H+D)/2) |
| 113 |
}); |
| 114 |
this.CHTMLsvgViewBox(svg); |
| 115 |
}, |
| 116 |
|
| 117 |
/********************************************************/ |
| 118 |
|
| 119 |
left: function (child,cbox,bb,p,t,SOLID) { |
| 120 |
child.style.borderLeft = SOLID; |
| 121 |
child.style.paddingLeft = CHTML.Em(p-t); |
| 122 |
}, |
| 123 |
|
| 124 |
/********************************************************/ |
| 125 |
|
| 126 |
right: function (child,cbox,bb,p,t,SOLID) { |
| 127 |
child.style.borderRight = SOLID; |
| 128 |
child.style.paddingRight = CHTML.Em(p-t); |
| 129 |
}, |
| 130 |
|
| 131 |
/********************************************************/ |
| 132 |
|
| 133 |
top: function (child,cbox,bb,p,t,SOLID) { |
| 134 |
child.style.borderTop = SOLID; |
| 135 |
child.style.paddingTop = CHTML.Em(p-t); |
| 136 |
}, |
| 137 |
|
| 138 |
/********************************************************/ |
| 139 |
|
| 140 |
bottom: function (child,cbox,bb,p,t,SOLID) { |
| 141 |
child.style.borderBottom = SOLID; |
| 142 |
child.style.paddingBottom = CHTML.Em(p-t); |
| 143 |
}, |
| 144 |
|
| 145 |
/********************************************************/ |
| 146 |
|
| 147 |
actuarial: function (child,cbox,bb,p,t,SOLID) { |
| 148 |
child.style.borderTop = child.style.borderRight = SOLID; |
| 149 |
child.style.paddingTop = child.style.paddingRight = CHTML.Em(p-t); |
| 150 |
}, |
| 151 |
|
| 152 |
/********************************************************/ |
| 153 |
|
| 154 |
madruwb: function (child,cbox,bb,p,t,SOLID) { |
| 155 |
child.style.borderBottom = child.style.borderRight = SOLID; |
| 156 |
child.style.paddingBottom = child.style.paddingRight = CHTML.Em(p-t); |
| 157 |
}, |
| 158 |
|
| 159 |
/********************************************************/ |
| 160 |
|
| 161 |
verticalstrike: function (child,cbox,bb,p,t,SOLID) { |
| 162 |
CHTML.addElement(child.parentNode,"mjx-box",{ |
| 163 |
style: { |
| 164 |
"border-left":SOLID, |
| 165 |
height:CHTML.Em(bb.H+bb.D), "vertical-align":CHTML.Em(-bb.D), |
| 166 |
width:CHTML.Em(cbox.w/2+p-t/2), "margin-left":CHTML.Em(-cbox.w/2-p-t/2) |
| 167 |
} |
| 168 |
}); |
| 169 |
}, |
| 170 |
|
| 171 |
/********************************************************/ |
| 172 |
|
| 173 |
horizontalstrike: function (child,cbox,bb,p,t,SOLID) { |
| 174 |
CHTML.addElement(child.parentNode,"mjx-box",{ |
| 175 |
style: { |
| 176 |
"border-top":SOLID, |
| 177 |
height:CHTML.Em((bb.H+bb.D)/2-t/2), "vertical-align":CHTML.Em(-bb.D), |
| 178 |
width:CHTML.Em(bb.W), "margin-left":CHTML.Em(-bb.W) |
| 179 |
} |
| 180 |
}); |
| 181 |
}, |
| 182 |
|
| 183 |
/********************************************************/ |
| 184 |
|
| 185 |
updiagonalstrike: function (child,cbox,bb,p,t,SOLID) { |
| 186 |
var H = bb.H, D = bb.D, W = bb.W; |
| 187 |
var svg = this.CHTMLsvg(child,bb,t); |
| 188 |
this.CHTMLsvgElement(svg.firstChild,"line",{ |
| 189 |
x1:CHTML.Px(t/2), y1:CHTML.Px(H+D-t), x2:CHTML.Px(W-t), y2:CHTML.Px(t/2) |
| 190 |
}); |
| 191 |
this.CHTMLsvgViewBox(svg); |
| 192 |
}, |
| 193 |
|
| 194 |
/********************************************************/ |
| 195 |
|
| 196 |
downdiagonalstrike: function (child,cbox,bb,p,t,SOLID) { |
| 197 |
var H = bb.H, D = bb.D, W = bb.W; |
| 198 |
var svg = this.CHTMLsvg(child,bb,t); |
| 199 |
this.CHTMLsvgElement(svg.firstChild,"line",{ |
| 200 |
x1:CHTML.Px(t/2), y1:CHTML.Px(t/2), x2:CHTML.Px(W-t), y2:CHTML.Px(H+D-t) |
| 201 |
}); |
| 202 |
this.CHTMLsvgViewBox(svg); |
| 203 |
}, |
| 204 |
|
| 205 |
/********************************************************/ |
| 206 |
|
| 207 |
updiagonalarrow: function (child,cbox,bb,p,t,SOLID) { |
| 208 |
var H = bb.H + bb.D - t, W = bb.W - t/2; |
| 209 |
var a = Math.atan2(H,W)*(-180/Math.PI).toFixed(3); |
| 210 |
var R = Math.sqrt(H*H + W*W); |
| 211 |
var svg = this.CHTMLsvg(child,bb,t); |
| 212 |
var g = this.CHTMLsvgElement(svg.firstChild,"g",{ |
| 213 |
fill:"currentColor", |
| 214 |
transform:"translate("+this.CHTMLpx(t/2)+" "+this.CHTMLpx(H+t/2)+") rotate("+a+")" |
| 215 |
}); |
| 216 |
var x = t * ARROWX, dx = t * ARROWDX, y = t * ARROWY; |
| 217 |
this.CHTMLsvgElement(g,"line",{ |
| 218 |
x1:CHTML.Px(t/2), y1:0, x2:CHTML.Px(R-x), y2:0 |
| 219 |
}); |
| 220 |
this.CHTMLsvgElement(g,"path",{ |
| 221 |
d: "M "+this.CHTMLpx(R-x)+",0 " + |
| 222 |
"L "+this.CHTMLpx(R-x-dx)+","+this.CHTMLpx(y) + |
| 223 |
"L "+this.CHTMLpx(R)+",0 " + |
| 224 |
"L "+this.CHTMLpx(R-x-dx)+","+this.CHTMLpx(-y), |
| 225 |
stroke:"none" |
| 226 |
}); |
| 227 |
this.CHTMLsvgViewBox(svg); |
| 228 |
}, |
| 229 |
|
| 230 |
/********************************************************/ |
| 231 |
|
| 232 |
phasorangle: function (child,cbox,bb,p,t,SOLID) { |
| 233 |
var P = p, H = bb.H, D = bb.D; |
| 234 |
p = (H+D)/2; |
| 235 |
var W = bb.W + p - P; bb.W = W; bb.L = p; |
| 236 |
child.style.margin = "0 0 0 "+CHTML.Em(p-P); |
| 237 |
var svg = this.CHTMLsvg(child,bb,t); |
| 238 |
this.CHTMLsvgElement(svg.firstChild,"path",{ |
| 239 |
d: "M "+this.CHTMLpx(p)+",1 " + |
| 240 |
"L 1,"+this.CHTMLpx(H+D-t)+" L "+this.CHTMLpx(W)+","+this.CHTMLpx(H+D-t) |
| 241 |
}); |
| 242 |
this.CHTMLsvgViewBox(svg); |
| 243 |
}, |
| 244 |
|
| 245 |
/********************************************************/ |
| 246 |
|
| 247 |
longdiv: function (child,cbox,bb,p,t,SOLID) { |
| 248 |
bb.W += 1.5*p; bb.L += 1.5*p; |
| 249 |
var H = bb.H, D = bb.D, W = bb.W; |
| 250 |
child.style.margin = "0 0 0 "+CHTML.Em(1.5*p); |
| 251 |
var svg = this.CHTMLsvg(child,bb,t); |
| 252 |
this.CHTMLsvgElement(svg.firstChild,"path",{ |
| 253 |
d: "M "+this.CHTMLpx(W)+",1 L 1,1 "+ |
| 254 |
"a"+this.CHTMLpx(p)+","+this.CHTMLpx((H+D)/2-t/2)+" 0 0,1 1,"+this.CHTMLpx(H+D-1.5*t) |
| 255 |
}); |
| 256 |
this.CHTMLsvgViewBox(svg); |
| 257 |
}, |
| 258 |
|
| 259 |
/********************************************************/ |
| 260 |
|
| 261 |
radical: function (child,cbox,bb,p,t,SOLID) { |
| 262 |
bb.W += 1.5*p; bb.L += 1.5*p; |
| 263 |
var H = bb.H, D = bb.D, W = bb.W; |
| 264 |
child.style.margin = "0 0 0 "+CHTML.Em(1.5*p); |
| 265 |
var svg = this.CHTMLsvg(child,bb,t); |
| 266 |
this.CHTMLsvgElement(svg.firstChild,"path",{ |
| 267 |
d: "M 1,"+this.CHTMLpx(.6*(H+D)) + |
| 268 |
" L "+this.CHTMLpx(p)+","+this.CHTMLpx(H+D) + |
| 269 |
" L "+this.CHTMLpx(2*p)+",1 L "+this.CHTMLpx(W)+",1" |
| 270 |
}); |
| 271 |
this.CHTMLsvgViewBox(svg); |
| 272 |
} |
| 273 |
|
| 274 |
/********************************************************/ |
| 275 |
|
| 276 |
}, |
| 277 |
|
| 278 |
// |
| 279 |
// Pixels with no "px" |
| 280 |
// |
| 281 |
CHTMLpx: function (m) { |
| 282 |
m *= CHTML.em; |
| 283 |
if (Math.abs(m) < .1) return "0"; |
| 284 |
return m.toFixed(1).replace(/\.0$/,""); |
| 285 |
}, |
| 286 |
|
| 287 |
// |
| 288 |
// Create the SVG element and position it over the |
| 289 |
// contents |
| 290 |
// |
| 291 |
CHTMLsvg: function (node,bbox,t) { |
| 292 |
var svg = document.createElementNS(SVGNS,"svg"); |
| 293 |
if (svg.style) { |
| 294 |
svg.style.width = CHTML.Em(bbox.W); |
| 295 |
svg.style.height = CHTML.Em(bbox.H+bbox.D); |
| 296 |
svg.style.verticalAlign = CHTML.Em(-bbox.D); |
| 297 |
svg.style.marginLeft = CHTML.Em(-bbox.W); |
| 298 |
} |
| 299 |
var g = this.CHTMLsvgElement(svg,"g",{"stroke-width":CHTML.Px(t)}); |
| 300 |
if (this.CHTML.scale !== 1) { |
| 301 |
g.setAttribute('transform', 'scale('+this.CHTML.scale+')'); |
| 302 |
} |
| 303 |
node.parentNode.appendChild(svg); |
| 304 |
return svg; |
| 305 |
}, |
| 306 |
// |
| 307 |
CHTMLsvgViewBox: function (svg) { |
| 308 |
var bbox = svg.getBBox(); |
| 309 |
svg.setAttribute('viewBox', [bbox.x, bbox.y, bbox.width, bbox.height].join(' ')); |
| 310 |
}, |
| 311 |
// |
| 312 |
// Add an SVG element to the given svg node |
| 313 |
// |
| 314 |
CHTMLsvgElement: function (svg,type,def) { |
| 315 |
var obj = document.createElementNS(SVGNS,type); obj.isMathJax = true; |
| 316 |
if (def) {for (var id in def) {if (def.hasOwnProperty(id)) {obj.setAttributeNS(null,id,def[id].toString())}}} |
| 317 |
svg.appendChild(obj); |
| 318 |
return obj; |
| 319 |
} |
| 320 |
}); |
| 321 |
|
| 322 |
// |
| 323 |
// Just use default toCommonHTML for EI8 |
| 324 |
// |
| 325 |
if (!document.createElementNS) delete MML.menclose.prototype.toCommonHTML; |
| 326 |
|
| 327 |
MathJax.Hub.Startup.signal.Post("CommonHTML menclose Ready"); |
| 328 |
MathJax.Ajax.loadComplete(CHTML.autoloadDir+"/menclose.js"); |
| 329 |
}); |
| 330 |
|