Skip to content

Commit 30af29b

Browse files
committed
Refactor codepoint parsers to use updated CSS selectors and CDN links, cover by tests
1 parent e848dc7 commit 30af29b

18 files changed

Lines changed: 1838 additions & 33 deletions

File tree

tools/idea-plugin/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ dependencies {
6969
implementation(libs.leviathan.compose)
7070
implementation(libs.tiamat)
7171

72+
testImplementation(projects.sdk.test.resourceLoader)
7273
testImplementation(testFixtures(projects.sdk.intellij.testFixtures))
7374
testImplementation(libs.bundles.kmp.test)
7475
testImplementation(libs.junit5.jupiter)
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,8 @@
11
package io.github.composegears.valkyrie.ui.screen.webimport.standard.bootstrap.data
22

3-
import io.github.composegears.valkyrie.ui.screen.webimport.standard.common.data.CodepointParser
4-
import kotlinx.serialization.json.Json
3+
import io.github.composegears.valkyrie.ui.screen.webimport.standard.common.data.RegexCssCodepointParser
54

6-
class BootstrapCodepointParser(
7-
private val json: Json,
8-
) : CodepointParser {
9-
10-
override fun parse(text: String): Map<String, Int> {
11-
return json.decodeFromString<Map<String, Int>>(text)
12-
}
13-
}
5+
class BootstrapCodepointParser :
6+
RegexCssCodepointParser(
7+
Regex("""\.bi-([a-z0-9-]+)::before\s*\{\s*content\s*:\s*"\\([A-Fa-f0-9]+)"\s*;?\s*}"""),
8+
)

tools/idea-plugin/src/main/kotlin/io/github/composegears/valkyrie/ui/screen/webimport/standard/bootstrap/data/BootstrapRepository.kt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ class BootstrapRepository(
1616
private val codepointParser: CodepointParser,
1717
) {
1818
companion object {
19-
private const val UNPKG_BASE = "https://unpkg.com/bootstrap-icons@latest"
20-
private const val FONT_URL = "$UNPKG_BASE/font/fonts/bootstrap-icons.woff2"
21-
private const val JSON_URL = "$UNPKG_BASE/font/bootstrap-icons.json"
22-
private const val ICONS_BASE_URL = "$UNPKG_BASE/icons"
19+
private const val CDN_BASE = "https://cdn.jsdelivr.net/npm/bootstrap-icons@latest"
20+
private const val FONT_URL = "$CDN_BASE/font/fonts/bootstrap-icons.woff2"
21+
private const val CSS_URL = "$CDN_BASE/font/bootstrap-icons.min.css"
22+
private const val ICONS_BASE_URL = "$CDN_BASE/icons"
2323
}
2424

2525
private val fontBytes = suspendLazy {
@@ -34,8 +34,8 @@ class BootstrapRepository(
3434

3535
private val codepoints = suspendLazy {
3636
withContext(Dispatchers.IO) {
37-
val jsonText = httpClient.get(JSON_URL).bodyAsText()
38-
codepointParser.parse(jsonText)
37+
val cssText = httpClient.get(CSS_URL).bodyAsText()
38+
codepointParser.parse(cssText)
3939
}
4040
}
4141

tools/idea-plugin/src/main/kotlin/io/github/composegears/valkyrie/ui/screen/webimport/standard/bootstrap/di/BootstrapModule.kt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,7 @@ object BootstrapModule : Leviathan() {
1111
private val network = NetworkModule
1212
private val coreModule = coreModule()
1313

14-
private val bootstrapCodepointParser by factoryOf {
15-
BootstrapCodepointParser(json = inject(network.json))
16-
}
14+
private val bootstrapCodepointParser by factoryOf { BootstrapCodepointParser() }
1715

1816
private val bootstrapRepository by instanceOf {
1917
BootstrapRepository(

tools/idea-plugin/src/main/kotlin/io/github/composegears/valkyrie/ui/screen/webimport/standard/boxicons/data/BoxCodepointParser.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@ import io.github.composegears.valkyrie.ui.screen.webimport.standard.common.data.
44

55
class BoxCodepointParser :
66
RegexCssCodepointParser(
7-
Regex("""\.((?:bx|bxs|bxl)-[a-z0-9-]+)::?before\s*\{\s*content\s*:\s*["']\\([A-Fa-f0-9]+)["']\s*;?\s*}"""),
7+
Regex("""\.((?:bx|bxs|bxl)-[a-z0-9-]+):before\s*\{\s*content\s*:\s*["']\\([A-Fa-f0-9]+)["']\s*;?\s*}"""),
88
)

tools/idea-plugin/src/main/kotlin/io/github/composegears/valkyrie/ui/screen/webimport/standard/boxicons/data/BoxIconsRepository.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ class BoxIconsRepository(
1616
private val codepointParser: CodepointParser,
1717
) {
1818
companion object {
19-
private const val UNPKG_BASE = "https://unpkg.com/boxicons@latest"
20-
private const val CSS_URL = "$UNPKG_BASE/css/boxicons.min.css"
21-
private const val FONT_WOFF2_URL = "$UNPKG_BASE/fonts/boxicons.woff2"
19+
private const val CDN_BASE = "https://cdn.jsdelivr.net/npm/boxicons@latest"
20+
private const val CSS_URL = "$CDN_BASE/css/boxicons.min.css"
21+
private const val FONT_URL = "$CDN_BASE/fonts/boxicons.woff2"
2222
}
2323

2424
private val codepoints = suspendLazy {
@@ -30,7 +30,7 @@ class BoxIconsRepository(
3030

3131
private val fontBytes = suspendLazy {
3232
withContext(Dispatchers.IO) {
33-
val woff2Bytes = httpClient.get(FONT_WOFF2_URL).bodyAsChannel().toByteArray()
33+
val woff2Bytes = httpClient.get(FONT_URL).bodyAsChannel().toByteArray()
3434

3535
withContext(Dispatchers.Default) {
3636
Woff2Decoder.decodeBytes(woff2Bytes) ?: error("Failed to decode BoxIcons WOFF2 font")
@@ -49,6 +49,6 @@ class BoxIconsRepository(
4949
else -> "regular"
5050
}
5151

52-
httpClient.get("$UNPKG_BASE/svg/$stylePath/$iconName.svg").bodyAsText()
52+
httpClient.get("$CDN_BASE/svg/$stylePath/$iconName.svg").bodyAsText()
5353
}
5454
}

tools/idea-plugin/src/main/kotlin/io/github/composegears/valkyrie/ui/screen/webimport/standard/lucide/data/LucideCodepointParser.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@ import io.github.composegears.valkyrie.ui.screen.webimport.standard.common.data.
44

55
class LucideCodepointParser :
66
RegexCssCodepointParser(
7-
Regex("""\.icon-([a-z0-9-]+)::?before\s*\{\s*content:\s*["']\\([a-fA-F0-9]+)["'];\s*}"""),
7+
Regex("""\.icon-([a-z0-9-]+)::before\s*\{\s*content:\s*"\\([a-fA-F0-9]+)";\s*}"""),
88
)

tools/idea-plugin/src/main/kotlin/io/github/composegears/valkyrie/ui/screen/webimport/standard/lucide/data/LucideRepository.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ class LucideRepository(
2121
private val codepointParser: CodepointParser,
2222
) {
2323
companion object {
24-
private const val UNPKG_BASE = "https://unpkg.com/lucide-static@latest"
25-
private const val FONT_URL = "$UNPKG_BASE/font/lucide.woff2"
26-
private const val CSS_URL = "https://cdn.jsdelivr.net/npm/lucide-static@latest/font/lucide.css"
24+
private const val CDN_BASE = "https://cdn.jsdelivr.net/npm/lucide-static@latest"
25+
private const val FONT_URL = "$CDN_BASE/font/lucide.woff2"
26+
private const val CSS_URL = "$CDN_BASE/font/lucide.css"
2727
}
2828

2929
private val fontBytes = suspendLazy {
@@ -48,7 +48,7 @@ class LucideRepository(
4848
suspend fun loadCodepoints(): Map<String, Int> = codepoints()
4949

5050
suspend fun loadIconList(): List<Pair<String, LucideIconMetadata>> = withContext(Dispatchers.IO) {
51-
val response = httpClient.get("$UNPKG_BASE/tags.json")
51+
val response = httpClient.get("$CDN_BASE/tags.json")
5252
val tagsJson = json.parseToJsonElement(response.bodyAsText()) as JsonObject
5353

5454
tagsJson.entries.map { (iconName, tagsArray) ->
@@ -61,6 +61,6 @@ class LucideRepository(
6161
}
6262

6363
suspend fun downloadSvg(iconName: String): String = withContext(Dispatchers.IO) {
64-
httpClient.get("$UNPKG_BASE/icons/$iconName.svg").bodyAsText()
64+
httpClient.get("$CDN_BASE/icons/$iconName.svg").bodyAsText()
6565
}
6666
}

tools/idea-plugin/src/main/kotlin/io/github/composegears/valkyrie/ui/screen/webimport/standard/remix/data/RemixCodepointParser.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@ import io.github.composegears.valkyrie.ui.screen.webimport.standard.common.data.
44

55
class RemixCodepointParser :
66
RegexCssCodepointParser(
7-
Regex("""\.ri-([a-z0-9-]+)::?before\s*\{\s*content:\s*["']\\([a-fA-F0-9]+)["'];?\s*}"""),
7+
Regex("""\.ri-([a-z0-9-]+):before\s*\{\s*content:\s*"\\([a-fA-F0-9]+)";?\s*}"""),
88
)

tools/idea-plugin/src/main/kotlin/io/github/composegears/valkyrie/ui/screen/webimport/standard/remix/data/RemixRepository.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class RemixRepository(
2424
private const val CDN_BASE = "https://cdn.jsdelivr.net/npm/remixicon@latest"
2525
private const val PACKAGE_JSON_URL = "$CDN_BASE/package.json"
2626
private const val FONT_URL = "$CDN_BASE/fonts/remixicon.woff2"
27-
private const val CSS_URL = "$CDN_BASE/fonts/remixicon.css"
27+
private const val CSS_URL = "$CDN_BASE/fonts/remixicon.min.css"
2828
private const val FLAT_INDEX_URL_TEMPLATE = "https://data.jsdelivr.com/v1/package/npm/remixicon@%s/flat"
2929
}
3030

0 commit comments

Comments
 (0)