mirror of
https://github.com/MercuryWorkshop/dreamlandjs.git
synced 2025-05-15 23:20:01 -04:00
fix: scope polyfill not detecting support reliably
This commit is contained in:
parent
74a174a211
commit
2d5093a86b
1 changed files with 6 additions and 6 deletions
10
src/css.js
10
src/css.js
|
@ -4,8 +4,8 @@ export const cssmap = {}
|
||||||
|
|
||||||
/* POLYFILL.SCOPE.START */
|
/* POLYFILL.SCOPE.START */
|
||||||
let scopeSupported
|
let scopeSupported
|
||||||
|
function checkScopeSupported() {
|
||||||
window.addEventListener('load', () => {
|
if (scopeSupported) return true;
|
||||||
const style = document.createElement('style')
|
const style = document.createElement('style')
|
||||||
style.textContent = '@scope (.test) { :scope { color: red } }'
|
style.textContent = '@scope (.test) { :scope { color: red } }'
|
||||||
document.head.appendChild(style)
|
document.head.appendChild(style)
|
||||||
|
@ -19,8 +19,8 @@ window.addEventListener('load', () => {
|
||||||
document.body.removeChild(testElement)
|
document.body.removeChild(testElement)
|
||||||
|
|
||||||
scopeSupported = computedColor == 'rgb(255, 0, 0)'
|
scopeSupported = computedColor == 'rgb(255, 0, 0)'
|
||||||
})
|
return scopeSupported;
|
||||||
|
}
|
||||||
const depth = 50
|
const depth = 50
|
||||||
// polyfills @scope for firefox and older browsers, using a :not selector recursively increasing in depth
|
// polyfills @scope for firefox and older browsers, using a :not selector recursively increasing in depth
|
||||||
// depth 50 means that after 50 layers of nesting, switching between an unrelated component and the target component, it will eventually stop applying styles (or let them leak into children)
|
// depth 50 means that after 50 layers of nesting, switching between an unrelated component and the target component, it will eventually stop applying styles (or let them leak into children)
|
||||||
|
@ -85,7 +85,7 @@ export function genCss(uid, str, scoped) {
|
||||||
let newstr, selfstr
|
let newstr, selfstr
|
||||||
if (scoped) {
|
if (scoped) {
|
||||||
/* POLYFILL.SCOPE.START */
|
/* POLYFILL.SCOPE.START */
|
||||||
if (!scopeSupported) {
|
if (!checkScopeSupported()) {
|
||||||
;[newstr, selfstr, str] = parseCombinedCss(str)
|
;[newstr, selfstr, str] = parseCombinedCss(str)
|
||||||
|
|
||||||
styleElement.textContent = str
|
styleElement.textContent = str
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue