fix: ship viewer.css and pdf.mjs with the plugin

This stops us having to redownload them for every PDF but still requires a redownload of the worker, which should be version locked with pdf.mjs, which is why this is not yet in the master branch
This commit is contained in:
Johannes Frohnmeyer 2024-05-16 18:55:48 +02:00
parent 96ddd61720
commit fb140e1697
Signed by: Johannes
GPG Key ID: E76429612C2929F4
2 changed files with 33 additions and 3 deletions

View File

@ -3,6 +3,7 @@ plugins {
id("org.jetbrains.intellij") version "1.17.3"
kotlin("jvm") version "1.9.22"
kotlin("plugin.serialization") version "1.9.22"
id("de.undercouch.download") version "5.3.0"
}
group = "io.gitlab.jfronny"
@ -32,6 +33,26 @@ dependencies {
}
tasks {
val extraResources = layout.buildDirectory.dir("downloads/resources")
val downloadPdfViewerCss by registering(de.undercouch.gradle.tasks.download.Download::class) {
src("https://mozilla.github.io/pdf.js/web/viewer.css")
dest(extraResources.map { it.file("viewer.css") })
overwrite(false)
}
val downloadPdfViewerJs by registering(de.undercouch.gradle.tasks.download.Download::class) {
src("https://mozilla.github.io/pdf.js/build/pdf.mjs")
dest(extraResources.map { it.file("pdf.mjs") })
overwrite(false)
}
processResources {
dependsOn(downloadPdfViewerCss, downloadPdfViewerJs)
}
sourceSets.main {
resources.srcDirs(extraResources)
}
// Set the JVM compatibility versions
withType<JavaCompile> {
sourceCompatibility = "17"

View File

@ -1,15 +1,22 @@
package io.gitlab.jfronny.sdom.util
import com.intellij.ui.jcef.JBCefScrollbarsHelper
import io.gitlab.jfronny.sdom.SDom
import org.intellij.lang.annotations.Language
import java.util.Base64
import java.io.InputStreamReader
import java.util.*
private val viewerCss = SDom.javaClass.getResourceAsStream("/viewer.css")!!.use { InputStreamReader(it).use { it.readText() } }
private val pdfJs = SDom.javaClass.getResourceAsStream("/pdf.mjs")!!.use { InputStreamReader(it).use { it.readText() } }
@Language("HTML")
fun pdfBootstrap(pdf: ByteArray) = """
<!DOCTYPE html>
<html>
<head>
<script src="https://mozilla.github.io/pdf.js/build/pdf.mjs" type="module"></script>
<script type="module">
$pdfJs
</script>
</head>
<body>
<script type="module">
@ -73,7 +80,9 @@ fun pdfBootstrap(pdf: ByteArray) = """
});
</script>
<div id="our-body" style="width: 100%"></div>
<link rel='stylesheet' type='text/css' href='https://mozilla.github.io/pdf.js/web/viewer.css'>
<style>
$viewerCss
</style>
<style>
${JBCefScrollbarsHelper.getOverlayScrollbarsSourceCSS()}
${JBCefScrollbarsHelper.buildScrollbarsStyle()}