Repository: JetBrains/compose-multiplatform
File: components/resources/library/src/webMain/kotlin/org/jetbrains/compose/resources/Resource.web.kt (Kotlin)

Code before:
 * ```
 *  configureWebResources {
 *     resourcePathMapping { path -> "/myApp1/resources/$path" }
 *  }
 *  configureWebResources {
 *     resourcePathMapping { path -> "https://mycdn.com/myApp1/res/$path" }
 *  }
 * ```
 */
@Suppress("unused")
fun configureWebResources(configure: WebResourcesConfiguration.() -> Unit) {
    WebResourcesConfiguration.configure()
}

internal fun getResourceUrl(windowOrigin: String, windowPathname: String, resourcePath: String): String {
    val path = WebResourcesConfiguration.getResourcePath(resourcePath)
    return when {
        path.startsWith("/") -> windowOrigin + path
        path.startsWith("http://") || path.startsWith("https://") -> path
        else -> windowOrigin + windowPathname + path
    }
}

@ExperimentalResourceApi
@Composable
fun preloadAndCacheFont(
    resource: FontResource,
    weight: FontWeight = FontWeight.Normal,
    style: FontStyle = FontStyle.Normal
): State<Font?> {
    val resState = remember(resource, weight, style) { mutableStateOf<Font?>(null) }.apply {
        value = Font(resource, weight, style).takeIf { !it.isDefaultEmptyFont }
    }
    return resState
}

@ExperimentalResourceApi
@Composable
fun preloadAndCacheImageResource(
    resource: DrawableResource,
): State<ImageBitmap?> {
    val resState = remember(resource) { mutableStateOf<ImageBitmap?>(null) }.apply {
        value = imageResource(resource).takeIf { !it.isEmptyImageBitmapPlaceholder }
    }
    return resState
}

@ExperimentalResourceApi
@Composable
fun preloadAndCacheVectorResource(
    resource: DrawableResource,

Review comment (suggestion):
As we agreed:
 - add documentation
 - rename to `preloadFont`
 - check environment changes

Code after:
 * ```
 *  configureWebResources {
 *     resourcePathMapping { path -> "/myApp1/resources/$path" }
 *  }
 *  configureWebResources {
 *     resourcePathMapping { path -> "https://mycdn.com/myApp1/res/$path" }
 *  }
 * ```
 */
@Suppress("unused")
fun configureWebResources(configure: WebResourcesConfiguration.() -> Unit) {
    WebResourcesConfiguration.configure()
}

internal fun getResourceUrl(windowOrigin: String, windowPathname: String, resourcePath: String): String {
    val path = WebResourcesConfiguration.getResourcePath(resourcePath)
    return when {
        path.startsWith("/") -> windowOrigin + path
        path.startsWith("http://") || path.startsWith("https://") -> path
        else -> windowOrigin + windowPathname + path
    }
}

/**
 * Preloads a font resource and provides a [State] containing the loaded [Font] or `null` if not yet loaded.
 *
 * Internally, it reads font bytes, converts them to a [Font] object, and caches the result, speeding up future
 * accesses to the same font resource when using @Composable Font function.
 *
 * **Usage Example:**
 * ```
 * @Composable
 * fun MyApp() {
 *     val fontState by preloadFont(Res.font.HeavyFont)
 *
 *     if (fontState != null) {
 *          MyText()
 *     } else {
 *          Box(modifier = Modifier.fillMaxSize()) {
 *              CircularProgressIndicator(modifier = Modifier.align(Alignment.Center))
 *          }
 *     }
 * }
 *
 * @Composable
 * fun MyText() {
 *      // the font is taken from the cache
 *      Text(text = "Hello, World!", fontFamily = FontFamily(Font(Res.font.HeavyFont)))
 * }
 * ```
 *