mirror of
https://github.com/MercuryWorkshop/dreamlandjs.git
synced 2025-05-15 15:10:02 -04:00
fix: non-scoped css rules, scoped media rules, falsy attributes
This commit is contained in:
parent
bd94e92985
commit
f9cc927c60
3 changed files with 19 additions and 7 deletions
2
dreamland.d.ts
vendored
2
dreamland.d.ts
vendored
|
@ -77,7 +77,7 @@ interface DLElement<T> extends HTMLElement {
|
|||
}
|
||||
|
||||
type ComponentElement<T extends (...args: any) => any> = ReturnType<T>
|
||||
type ComponentType<T extends (...args: any) => any> = ReturnType<T>["$"]
|
||||
type ComponentType<T extends (...args: any) => any> = ReturnType<T>['$']
|
||||
|
||||
type OuterComponentTypes = {
|
||||
root: Element
|
||||
|
|
|
@ -575,6 +575,7 @@ function JSXAddChild(child, cb) {
|
|||
|
||||
// Where properties are assigned to elements, and where the *non-reactive* syntax sugar goes
|
||||
function JSXAddAttributes(elm, name, prop) {
|
||||
if (!prop && elm.hasAttribute(name)) elm.removeAttribute(name)
|
||||
if (!prop) return
|
||||
|
||||
if (name.startsWith('on:')) {
|
||||
|
|
15
src/css.js
15
src/css.js
|
@ -96,7 +96,7 @@ export function genCss(uid, str, scoped) {
|
|||
|
||||
let extstr = ''
|
||||
for (const rule of styleElement.sheet.cssRules) {
|
||||
if (!rule.selectorText) {
|
||||
if (!rule.selectorText && !rule.media) {
|
||||
extstr += rule.cssText
|
||||
} else if (rule.selectorText?.startsWith(':')) {
|
||||
rule.selectorText = `.${uid}${rule.selectorText}`
|
||||
|
@ -109,7 +109,18 @@ export function genCss(uid, str, scoped) {
|
|||
styleElement.textContent = `.${uid} {${selfstr}} @scope (.${uid}) to (:not(.${uid}).${cssBoundary} *) { ${newstr} } ${extstr}`
|
||||
} else {
|
||||
for (const rule of styleElement.sheet.cssRules) {
|
||||
rule.selectorText = `.${uid} ${rule.selectorText}`
|
||||
if (rule.selectorText)
|
||||
rule.selectorText = rule.selectorText
|
||||
.split(',')
|
||||
.map((x) => {
|
||||
x = x.trim()
|
||||
if (x[0] === ':') {
|
||||
return `.${uid}${x}`
|
||||
} else {
|
||||
return `.${uid} ${x}`
|
||||
}
|
||||
})
|
||||
.join(', ')
|
||||
newstr += rule.cssText
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue