Skip to content

Commit

Permalink
🪚 Allow to put Style into @DOM block
Browse files Browse the repository at this point in the history
  • Loading branch information
MihaelIsaev committed Dec 4, 2022
1 parent 1f4ffdd commit ee1e78f
Showing 1 changed file with 29 additions and 20 deletions.
49 changes: 29 additions & 20 deletions Sources/CSS/Stylesheet.swift
Original file line number Diff line number Diff line change
Expand Up @@ -51,26 +51,35 @@ open class Stylesheet: BaseElement, Stylesheetable {
}

public func processRules() {
_rules.enumerated().forEach { i, rule in
let cssText = rule.render()
#if !WEBPREVIEW
guard let index = sheet.insertRule.function?.callAsFunction(optionalThis: sheet.object, cssText)?.number else { return }
rule.domElement = sheet.rules.item.function?.callAsFunction(optionalThis: sheet.rules.object, Int(index))
#endif
}
_keyframes.enumerated().forEach { i, kf in
let cssText = kf.render()
#if !WEBPREVIEW
guard let index = sheet.insertRule.function?.callAsFunction(optionalThis: sheet.object, cssText)?.number else { return }
kf.domElement = sheet.rules.item.function?.callAsFunction(optionalThis: sheet.rules.object, Int(index))
#endif
}
_medias.enumerated().forEach { i, m in
let cssText = m.render()
#if !WEBPREVIEW
guard let index = sheet.insertRule.function?.callAsFunction(optionalThis: sheet.object, cssText)?.number else { return }
m.domElement = sheet.rules.item.function?.callAsFunction(optionalThis: sheet.rules.object, Int(index))
#endif
if sheet.object != nil {
_rules.enumerated().forEach { i, rule in
let cssText = rule.render()
#if !WEBPREVIEW
guard let index = sheet.insertRule.function?.callAsFunction(optionalThis: sheet.object, cssText)?.number else { return }
rule.domElement = sheet.rules.item.function?.callAsFunction(optionalThis: sheet.rules.object, Int(index))
#endif
}
_keyframes.enumerated().forEach { i, kf in
let cssText = kf.render()
#if !WEBPREVIEW
guard let index = sheet.insertRule.function?.callAsFunction(optionalThis: sheet.object, cssText)?.number else { return }
kf.domElement = sheet.rules.item.function?.callAsFunction(optionalThis: sheet.rules.object, Int(index))
#endif
}
_medias.enumerated().forEach { i, m in
let cssText = m.render()
#if !WEBPREVIEW
guard let index = sheet.insertRule.function?.callAsFunction(optionalThis: sheet.object, cssText)?.number else { return }
m.domElement = sheet.rules.item.function?.callAsFunction(optionalThis: sheet.rules.object, Int(index))
#endif
}
} else {
var style = "\r\n"
style.append(_rules.map { $0.render() }.joined(separator: "\n"))
style.append(_keyframes.map { $0.render() }.joined(separator: "\n"))
style.append(_medias.map { $0.render() }.joined(separator: "\n"))
style.append("\r\n")
domElement.innerHTML = style.jsValue()
}
}

Expand Down

0 comments on commit ee1e78f

Please sign in to comment.