kodeshare/src/main/kotlin/moe/kageru/kodeshare/pages/Css.kt

135 lines
4.2 KiB
Kotlin
Raw Normal View History

2019-09-22 18:26:28 +02:00
package moe.kageru.kodeshare.pages
import kotlinx.css.*
2019-09-29 11:50:14 +02:00
import kotlinx.css.properties.*
2019-09-29 15:56:22 +02:00
import kotlin.math.ceil
2019-09-22 18:26:28 +02:00
object Css {
2019-09-29 11:50:14 +02:00
const val FLOATY_CLASS = "floatything"
2020-05-03 20:11:01 +02:00
private val accent1 = Color("#e6db74") // monokai yellow
private val accent2 = Color("#a6e22e") // monokai green
2020-05-03 20:18:13 +02:00
private val selection = accent1
2019-09-22 18:26:28 +02:00
private val fontcolor = Color.lightGrey
2019-09-29 08:17:31 +02:00
private val bgcolor = Color("#23241f")
2019-09-29 15:56:22 +02:00
private const val borderpixels = 3
private const val bodyPadding = 20
private const val inputPadding = 8
2020-04-12 11:01:42 +02:00
2019-09-29 15:56:22 +02:00
// Text areas apparently grow beyond their parent element if padding and/or borders are added.
// They always grow to the right, so we simply add more padding to shift everything back (see usage of this).
private const val bodyShift = bodyPadding + 2 * borderpixels + 2 * inputPadding
2020-05-03 20:11:01 +02:00
private const val fonts = """Hack, "Jetbrains Mono", "Fira Code", "Noto Mono", monospace"""
2019-09-29 15:56:22 +02:00
private fun StyledElement.defaultBorder() = border(borderpixels.px, BorderStyle.solid, accent1)
2019-09-22 18:26:28 +02:00
val default = CSSBuilder().apply {
2019-09-29 15:56:22 +02:00
rule("html, body, form") {
height = (100 - ceil(bodyPadding.toDouble() / 8)).pct
}
not(textarea.tagName) {
transition(duration = 400.ms)
}
2019-09-22 18:26:28 +02:00
body {
2020-04-12 11:01:42 +02:00
fontFamily = fonts
2019-09-22 18:26:28 +02:00
fontSize = 13.pt
margin = "auto"
2019-09-29 08:17:31 +02:00
backgroundColor = bgcolor
2019-09-22 18:26:28 +02:00
color = fontcolor
2019-09-29 15:56:22 +02:00
padding(
top = bodyPadding.px,
left = bodyPadding.px,
right = (bodyShift).px,
bottom = bodyPadding.px
)
2019-09-22 18:26:28 +02:00
}
2019-09-29 11:50:14 +02:00
form {
2019-09-29 15:56:22 +02:00
width = 100.pct
marginTop = 0.px
2020-04-12 11:01:42 +02:00
textAlign = TextAlign.center
2019-09-29 11:50:14 +02:00
}
2019-09-22 18:26:28 +02:00
textarea {
2020-04-12 11:01:42 +02:00
fontFamily = fonts
2019-09-29 08:17:31 +02:00
backgroundColor = bgcolor
2019-09-22 18:26:28 +02:00
color = Color.white
fontSize = 13.pt
borderRadius = 8.px
2019-09-29 15:56:22 +02:00
defaultBorder()
padding = "${inputPadding}px"
width = 100.pct
height = 90.pct
2019-09-22 18:26:28 +02:00
}
2019-09-29 08:17:31 +02:00
// this doesn’t inherit the style from anything else for some reason
2019-09-29 09:51:15 +02:00
rule(".hljs, pre, code") {
2019-09-29 10:15:42 +02:00
width = 95.pct
2019-09-29 08:17:31 +02:00
height = 100.pct
textAlign = TextAlign.left
2020-04-12 11:01:42 +02:00
fontFamily = fonts
2019-09-29 08:17:31 +02:00
fontSize = 13.pt
2019-09-29 10:15:42 +02:00
display = Display.inline
position = Position.relative
2019-09-29 08:17:31 +02:00
}
2019-09-22 18:26:28 +02:00
rule("input[type=\"submit\"]") {
backgroundColor = accent1
2019-09-29 15:56:22 +02:00
defaultBorder()
2019-09-22 18:26:28 +02:00
borderRadius = 5.px
color = Color.black
fontWeight = FontWeight.w600
2019-09-29 15:56:22 +02:00
padding = "0.2em"
2019-09-22 18:26:28 +02:00
cursor = Cursor.pointer
transition(duration = 500.ms)
2019-09-29 15:56:22 +02:00
marginRight = (-bodyShift).px
width = 80.pct
2019-09-22 18:26:28 +02:00
}
2019-09-29 11:50:14 +02:00
rule("div.$FLOATY_CLASS") {
2019-09-29 10:15:42 +02:00
position = Position.absolute
padding = "5px"
2019-09-29 15:56:22 +02:00
defaultBorder()
borderRadius = 5.px
2019-09-29 10:15:42 +02:00
color = accent1
2019-09-29 15:56:22 +02:00
// I have no idea where this one pixel is coming from
top = (bodyPadding + 1).px
right = bodyPadding.px
2019-09-29 10:15:42 +02:00
zIndex = 1
}
2019-09-29 11:50:14 +02:00
rule("div.$FLOATY_CLASS:hover") {
color = accent2
borderColor = accent2
}
rule("div.wrapper") {
margin = "auto"
lineHeight = LineHeight("140%")
width = 70.pct
textAlign = TextAlign.left
}
rule(".framed") {
border(1.px, BorderStyle.solid, fontcolor)
padding = "0.3em"
margin = "0.5em"
marginBottom = 1.em
}
2019-09-22 18:26:28 +02:00
rule("input[type=\"submit\"]:hover") {
backgroundColor = Color.transparent
2019-09-29 08:17:31 +02:00
borderColor = accent2
color = accent2
2019-09-22 18:26:28 +02:00
}
rule("textarea:focus") {
outline = Outline.none
2019-09-22 18:26:28 +02:00
}
rule("::selection") {
2020-05-03 20:11:01 +02:00
backgroundColor = selection
color = bgcolor
2019-09-22 18:26:28 +02:00
}
2019-09-29 10:15:42 +02:00
a {
color = accent1
textDecoration = TextDecoration.none
}
rule("a:visited") {
color = accent1
}
rule("a:focus") {
color = accent2
}
2019-09-22 18:26:28 +02:00
}.toString()
2019-09-29 17:18:38 +02:00
}