package eu.friedcutlet.yokan.ui.screens.reader /** Opens the platform share UI for in-memory image data. */ expect fun shareImage(bytes: ByteArray, fileName: String, mimeType: String): Boolean /** * Saves in-memory image data to the platform's user-visible picture library, inside a * [folder] (album on iOS) below Yokan's own location when one is given. */ expect suspend fun saveImageToGallery(bytes: ByteArray, fileName: String, mimeType: String, folder: String?): Boolean /** Places the image on the system clipboard. */ expect suspend fun copyImageToClipboard(bytes: ByteArray, fileName: String, mimeType: String): Boolean /** * Two decoded pages side by side at a common height, encoded as JPEG; null for animated, * undecodable or oversized inputs. */ internal expect suspend fun mergeSpreadImages(left: ByteArray, right: ByteArray): ByteArray? internal fun String.safeSharedFileName(): String = replace(Regex("[^A-Za-z0-9._-]+"), "_").trim('_').ifBlank { "yokan-cover.jpg" } /** A title as a single path segment: path separators and reserved characters are replaced. */ internal fun readerImageFolderName(title: String): String = title.replace(Regex("[\\\\/:*?\"<>|\\x00-\\x1F]+"), "_").trim().trim('.').take(100).trim().ifBlank { "Untitled" } /** Side-by-side pixel layout shared by every platform's spread merge. */ internal data class SpreadLayout(val width: Int, val height: Int, val leftWidth: Int, val rightWidth: Int) /** Scales both pages to the taller page's height; null when the result would exceed the decode budget. */ internal fun spreadLayout(leftWidth: Int, leftHeight: Int, rightWidth: Int, rightHeight: Int): SpreadLayout? { if (leftWidth <= 0 || leftHeight <= 0 || rightWidth <= 0 || rightHeight <= 0) return null val height = maxOf(leftHeight, rightHeight) val scaledLeft = (leftWidth.toLong() * height / leftHeight).toInt().coerceAtLeast(1) val scaledRight = (rightWidth.toLong() * height / rightHeight).toInt().coerceAtLeast(1) val width = scaledLeft.toLong() + scaledRight if (width * height > eu.friedcutlet.yokan.services.download.MaxSplitImagePixels) return null return SpreadLayout(width.toInt(), height, scaledLeft, scaledRight) }