|
|
@ -9,6 +9,7 @@ import org.w3c.dom.css.CSSStyleDeclaration |
|
|
|
import org.w3c.dom.css.CSSStyleRule |
|
|
|
import org.w3c.dom.css.CSSStyleRule |
|
|
|
import org.w3c.dom.css.StyleSheet |
|
|
|
import org.w3c.dom.css.StyleSheet |
|
|
|
import org.jetbrains.compose.web.css.* |
|
|
|
import org.jetbrains.compose.web.css.* |
|
|
|
|
|
|
|
import org.w3c.dom.css.CSSStyleSheet |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Use this function to mount the <style> tag into the DOM tree. |
|
|
|
* Use this function to mount the <style> tag into the DOM tree. |
|
|
@ -43,47 +44,49 @@ inline fun Style( |
|
|
|
}, |
|
|
|
}, |
|
|
|
) { |
|
|
|
) { |
|
|
|
DomSideEffect(cssRules) { style -> |
|
|
|
DomSideEffect(cssRules) { style -> |
|
|
|
style.sheet?.let { sheet -> |
|
|
|
(style.sheet as? CSSStyleSheet)?.let { cssStylesheet -> |
|
|
|
setCSSRules(sheet, cssRules) |
|
|
|
setCSSRules(cssStylesheet, cssRules) |
|
|
|
onDispose { |
|
|
|
onDispose { |
|
|
|
clearCSSRules(sheet) |
|
|
|
clearCSSRules(cssStylesheet) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
fun clearCSSRules(sheet: StyleSheet) { |
|
|
|
fun clearCSSRules(sheet: CSSStyleSheet) { |
|
|
|
repeat(sheet.cssRules.length) { |
|
|
|
repeat(sheet.cssRules.length) { |
|
|
|
sheet.deleteRule(0) |
|
|
|
sheet.deleteRule(0) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
fun setCSSRules(sheet: StyleSheet, cssRules: CSSRuleDeclarationList) { |
|
|
|
fun setCSSRules(sheet: CSSStyleSheet, cssRules: CSSRuleDeclarationList) { |
|
|
|
cssRules.forEach { cssRule -> |
|
|
|
cssRules.forEach { cssRule -> |
|
|
|
sheet.addRule(cssRule) |
|
|
|
sheet.addRule(cssRule) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private fun StyleSheet.addRule(cssRule: String): CSSRule { |
|
|
|
private fun CSSStyleSheet.addRule(cssRule: String): CSSRule? { |
|
|
|
val cssRuleIndex = this.insertRule(cssRule, this.cssRules.length) |
|
|
|
val cssRuleIndex = this.insertRule(cssRule, this.cssRules.length) |
|
|
|
return this.cssRules[cssRuleIndex] |
|
|
|
return this.cssRules.item(cssRuleIndex) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private fun CSSGroupingRule.addRule(cssRule: String): CSSRule { |
|
|
|
private fun CSSStyleSheet.addRule(cssRuleDeclaration: CSSRuleDeclaration) { |
|
|
|
val cssRuleIndex = this.insertRule(cssRule, this.cssRules.length) |
|
|
|
addRule("${cssRuleDeclaration.header} {}")?.let { cssRule -> |
|
|
|
return this.cssRules[cssRuleIndex] |
|
|
|
fillRule(cssRuleDeclaration, cssRule) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private fun StyleSheet.addRule(cssRuleDeclaration: CSSRuleDeclaration) { |
|
|
|
private fun CSSGroupingRule.addRule(cssRule: String): CSSRule? { |
|
|
|
val cssRule = addRule("${cssRuleDeclaration.header} {}") |
|
|
|
val cssRuleIndex = this.insertRule(cssRule, this.cssRules.length) |
|
|
|
fillRule(cssRuleDeclaration, cssRule) |
|
|
|
return this.cssRules.item(cssRuleIndex) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private fun CSSGroupingRule.addRule(cssRuleDeclaration: CSSRuleDeclaration) { |
|
|
|
private fun CSSGroupingRule.addRule(cssRuleDeclaration: CSSRuleDeclaration) { |
|
|
|
val cssRule = addRule("${cssRuleDeclaration.header} {}") |
|
|
|
addRule("${cssRuleDeclaration.header} {}")?.let { cssRule -> |
|
|
|
fillRule(cssRuleDeclaration, cssRule) |
|
|
|
fillRule(cssRuleDeclaration, cssRule) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private fun fillRule( |
|
|
|
private fun fillRule( |
|
|
|
cssRuleDeclaration: CSSRuleDeclaration, |
|
|
|
cssRuleDeclaration: CSSRuleDeclaration, |
|
|
|