utils.js (1116B)
1 function getBlockAxisName(elem) { 2 var wm = getComputedStyle(elem).writingMode; 3 return (!wm || wm == 'horizontal-tb') ? 'height' : 'width'; 4 } 5 6 function getBSize(elem) { 7 return elem.getBoundingClientRect()[getBlockAxisName(elem)] + 'px'; 8 } 9 10 function setBSize(elem, bsize) { 11 elem.style[getBlockAxisName(elem)] = bsize; 12 elem.style.lineHeight = bsize; 13 } 14 15 // Ruby annotations are placed based on block-axis size of inline boxes 16 // instead of line box. Block-axis size of an inline box is the max 17 // height of the font, while that of line box is line height. Hence we 18 // sometimes need to explicitly set the block-axis size of an inline 19 // box to a block to simulate the exact behavior, which is what the 20 // following two functions do. 21 22 function makeBSizeMatchInlineBox(block, inline) { 23 setBSize(block, getBSize(inline)); 24 } 25 26 function makeBSizeOfParentMatch(elems) { 27 // The size change is divided into two phases to avoid 28 // triggering reflow for every element. 29 for (var elem of elems) 30 elem.dataset.bsize = getBSize(elem); 31 for (var elem of elems) 32 setBSize(elem.parentNode, elem.dataset.bsize); 33 }