feat(quartz): theme parser tags for kind-30312 (T3 #1)

Adds the Tier-3 minimum-viable theming primitives so a themed
nostrnests room renders without crashing the client:

  ColorTag       — `["c", "<hex6>", "background"|"text"|"primary"]`.
                   Strict 6-char hex parser; `#abc` shorthand and
                   named colors are REJECTED so a typo'd room
                   event can't crash the renderer. Output hex is
                   normalised uppercase, no `#` prefix.
  BackgroundTag  — `["bg", "<url>", "tile"|"cover"]`. Mode defaults
                   to COVER when missing; unknown modes (a future
                   "blur") fall back to COVER until the renderer
                   learns them. Empty URL is rejected.

  MeetingSpaceEvent.colors() / .background() — tag accessors. The
  font tag (`["f", family, optionalUrl]`) is intentionally NOT in
  this commit; loading a custom FontFamily would need a per-pack
  loader, and font-less rooms still render fine on the client.

Tests:
  ColorTagTest — happy path, no-`#` prefix, rejects shorthand /
                 named / unknown target / missing target;
                 assemble normalisation; round-trip.
  BackgroundTagTest — happy path, default-COVER, future-mode
                       fallback, rejects empty URL, round-trip.

The Compose `RoomTheme` projection + `AudioRoomThemedScope`
renderer come next.
This commit is contained in:
Claude
2026-04-26 23:00:30 +00:00
parent cc33bdbb92
commit 885b77f1f3
5 changed files with 295 additions and 0 deletions
@@ -0,0 +1,64 @@
/*
* Copyright (c) 2025 Vitor Pamplona
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
* Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
* AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
package com.vitorpamplona.quartz.nip53LiveActivities.meetingSpaces.tags
import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertNull
class BackgroundTagTest {
@Test
fun parseValidWithMode() {
val parsed = BackgroundTag.parse(arrayOf("bg", "https://i/x.jpg", "tile"))
assertEquals("https://i/x.jpg", parsed?.url)
assertEquals(BackgroundTag.Mode.TILE, parsed?.mode)
}
@Test
fun defaultsToCoverWhenModeMissing() {
val parsed = BackgroundTag.parse(arrayOf("bg", "https://i/x.jpg"))
assertEquals(BackgroundTag.Mode.COVER, parsed?.mode)
}
@Test
fun unknownModeFallsBackToCover() {
// Spec evolution — a future "blur" mode must not crash the
// parser. Falls back to COVER until the renderer learns the
// new mode.
val parsed = BackgroundTag.parse(arrayOf("bg", "https://i/x.jpg", "blur"))
assertEquals(BackgroundTag.Mode.COVER, parsed?.mode)
}
@Test
fun rejectsEmptyUrl() {
assertNull(BackgroundTag.parse(arrayOf("bg", "")))
}
@Test
fun assembleRoundTrips() {
val tag = BackgroundTag.assemble("https://i/p.png", BackgroundTag.Mode.TILE)
val parsed = BackgroundTag.parse(tag)
assertEquals(
BackgroundTag(url = "https://i/p.png", mode = BackgroundTag.Mode.TILE),
parsed,
)
}
}
@@ -0,0 +1,76 @@
/*
* Copyright (c) 2025 Vitor Pamplona
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
* Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
* AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
package com.vitorpamplona.quartz.nip53LiveActivities.meetingSpaces.tags
import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertNull
class ColorTagTest {
@Test
fun parsesValidHexAndTarget() {
val parsed = ColorTag.parse(arrayOf("c", "#FF8800", "background"))
assertEquals("FF8800", parsed?.hex)
assertEquals(ColorTag.Target.BACKGROUND, parsed?.target)
}
@Test
fun parsesWithoutHashPrefix() {
val parsed = ColorTag.parse(arrayOf("c", "abcdef", "primary"))
assertEquals("ABCDEF", parsed?.hex)
assertEquals(ColorTag.Target.PRIMARY, parsed?.target)
}
@Test
fun rejectsShortHex() {
// `#abc` shorthand is rejected — keeps the parser strict so
// a typo'd room event can't crash the renderer.
assertNull(ColorTag.parse(arrayOf("c", "#abc", "text")))
}
@Test
fun rejectsNamedColors() {
assertNull(ColorTag.parse(arrayOf("c", "red", "text")))
}
@Test
fun rejectsUnknownTarget() {
assertNull(ColorTag.parse(arrayOf("c", "#abcdef", "accent")))
}
@Test
fun rejectsMissingTarget() {
assertNull(ColorTag.parse(arrayOf("c", "#abcdef")))
}
@Test
fun assembleProducesUppercaseNoHash() {
val tag = ColorTag.assemble("#abcdef", ColorTag.Target.TEXT)
assertEquals(arrayOf("c", "ABCDEF", "text").toList(), tag.toList())
}
@Test
fun roundTripPreservesEverything() {
val tag = ColorTag.assemble("FF00FF", ColorTag.Target.PRIMARY)
val parsed = ColorTag.parse(tag)
assertEquals(ColorTag(hex = "FF00FF", target = ColorTag.Target.PRIMARY), parsed)
}
}