Last active
January 25, 2023 04:12
-
-
Save jonathantneal/3ff00130407328f3e14179c593e62481 to your computer and use it in GitHub Desktop.
Constructable Stylesheet Polyfill — 330 bytes / 235 bytes gzipped — https://wicg.github.io/construct-stylesheets/
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
try { | |
new CSSStyleSheet() | |
} catch { | |
CSSStyleSheet = (( | |
stylePtt = CSSStyleSheet.prototype, | |
styleDoc = new Document(), | |
styleDom = styleDoc.appendChild(document.createElement('style')), | |
sheet | |
) => Object.assign(stylePtt.constructor = function CSSStyleSheet() { | |
if (!new.target) { | |
throw new TypeError("Constructor requires 'new' operator") | |
} | |
sheet = styleDom.sheet | |
styleDoc.removeChild(styleDom) | |
styleDoc.appendChild(styleDom) | |
return sheet | |
}.bind(), { prototype: stylePtt }) | |
)() | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
try{new CSSStyleSheet}catch{CSSStyleSheet=((e=CSSStyleSheet.prototype,t=new Document,r=t.appendChild(document.createElement("style")),n)=>Object.assign(e.constructor=function(){if(!new.target)throw new TypeError("Constructor requires 'new' operator");return n=r.sheet,t.removeChild(r),t.appendChild(r),n}.bind(),{prototype:e}))()} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment