hfill
Version:
A speculative polyfill to use the h element in HTML
3 lines (2 loc) • 1.28 kB
JavaScript
!function(e){"use strict";function t(e,t){function n(e){for(var t=1,n=e;n=n.parentElement;)if(a.test(n.nodeName))++t;else if(n.nodeName.toLowerCase()===o)return;e.setAttribute("role","heading"),e.setAttribute("aria-level",t)}var o=t?t.toLowerCase():"x-h";[].forEach.call(e.getElementsByTagName(o),n),new MutationObserver(function(e){return e.forEach(function(e){[].forEach.call(e.addedNodes,function(e){o===e.nodeName.toLowerCase()?n(e):e.getElementsByTagName&&[].forEach.call(e.getElementsByTagName(o),n)})})}).observe(e,{childList:!0,subtree:!0})}function n(e,t,n,a){var i=t?t.toLowerCase():"x-h";if(!e.querySelector("style#hfill-style")){var l=document.createElement("style");l.setAttribute("id","hfill-style"),l.textContent=[].concat(a||["2em","1.5em","1.17em","1em",".83em",".67em"]).reduce(function(e,t,n,a){for(var l=Math.pow(r,n),s=[],c=-1;++c<l;){for(var f=[],u=c,h=-1;++h<n;){var m=u%r;f.push(o[m]),u=(u-m)/r}s.push(f)}return e+s.map(function(e){return e.length?e.join(" ").concat(" "+i):i}).join(",")+"{font-size:"+a[n]+"}"},i+"{"+(n||"display:block;font-weight:bold")+"}"),e.appendChild(l)}}var o=["article","aside","nav","section"],a=RegExp("^("+o.join("|")+")$","i"),r=o.length;e.observe=t,e.style=n}(this.hfill=this.hfill||{});
//# sourceMappingURL=hfill.es5.js.map