From b60da0a8eec187d1ed697ac6671143315e342086 Mon Sep 17 00:00:00 2001 From: Vincent Vanwaelscappel Date: Thu, 28 Aug 2025 10:52:45 +0200 Subject: [PATCH] wip #7702 @3 --- app/Console/Commands/UpdatePDFJSLibrary.php | 14 +++++++++++--- app/Fluidbook/Compiler/Compiler.php | 20 ++++++++++++++------ 2 files changed, 25 insertions(+), 9 deletions(-) diff --git a/app/Console/Commands/UpdatePDFJSLibrary.php b/app/Console/Commands/UpdatePDFJSLibrary.php index 74ea810c8..e48ec6dd7 100644 --- a/app/Console/Commands/UpdatePDFJSLibrary.php +++ b/app/Console/Commands/UpdatePDFJSLibrary.php @@ -11,7 +11,9 @@ class UpdatePDFJSLibrary extends ToolboxCommand /** @see https://mozilla.github.io/pdf.js/getting_started/#download */ protected $signature = 'updatepdfjs'; - protected const VERSION = '3.4.120'; + protected const VERSION = '5.4.54'; + //protected const VERSION = '3.11.174'; + protected const JQUERY_VERSION = '3.7.1'; public function handle() { @@ -21,8 +23,8 @@ class UpdatePDFJSLibrary extends ToolboxCommand protected function _update($legacy = false) { - $path = resource_path('pdfjs/' . ($legacy ? 'legacy' : 'dist')); - $minpath = resource_path('pdfjs/' . ($legacy ? 'legacy-min' : 'dist-min')); + $path = Files::mkdir(resource_path('pdfjs/' . ($legacy ? 'legacy' : 'dist'))); + $minpath = Files::mkdir(resource_path('pdfjs/' . ($legacy ? 'legacy-min' : 'dist-min'))); if (file_exists($path)) { `rm -rf $path`; @@ -34,6 +36,12 @@ class UpdatePDFJSLibrary extends ToolboxCommand $tmp = Files::tempnam() . '.zip'; copy('https://github.com/mozilla/pdf.js/releases/download/v' . static::VERSION . '/pdfjs-' . static::VERSION . ($legacy ? '-legacy' : '') . '-dist.zip', $tmp); Zip::extract($tmp, $path); + unlink($path . 'web/debugger.mjs'); + unlink($path . 'web/debugger.css'); + + Files::recursiveReplaceStringInFilename($path, ['.mjs' => '.js']); + Files::recursiveReplaceStringInDir($path, ['.mjs' => '.js']); + unlink($tmp); copy('https://code.jquery.com/jquery-3.7.1.min.js', $path . '/web/jquery.min.js'); touch($path . '/web/custom.js'); diff --git a/app/Fluidbook/Compiler/Compiler.php b/app/Fluidbook/Compiler/Compiler.php index 220e9509e..7386bcdd9 100644 --- a/app/Fluidbook/Compiler/Compiler.php +++ b/app/Fluidbook/Compiler/Compiler.php @@ -1035,19 +1035,19 @@ class Compiler extends Base implements CompilerInterface, IVirtualDirectoryError $script = '' . "\n"; foreach ($this->customJs as $c) { - $script .= "\t" . '' . "\n"; + $script .= $this->_script($c, $jstime); } foreach ($this->jsLibs as $jsLib => $files) { - $script .= "\t" . '' . "\n"; + $script .= $this->_script($assetsPrefix . 'data/' . $jsLib . '.js', $jstime); } if ($this->fluidbookSettings->scorm_enable) { - $script .= "\t" . '' . "\n"; + $script .= $this->_script($assetsPrefix . 'data/scorm.js', $jstime); } if (count($this->specialJsFiles)) { - $script .= "\t" . '' . "\n"; + $script .= $this->_script($assetsPrefix . 'data/special.js', $jstime); } foreach ($this->pluginJs as $p) { - $script .= "\t" . '' . "\n"; + $script .= $this->_script($assetsPrefix . $p, $jstime); } $script .= $iscript; @@ -1199,6 +1199,14 @@ class Compiler extends Base implements CompilerInterface, IVirtualDirectoryError return $this->_indexVars; } + protected function _script($c, $jstime = '') + { + if (is_string($c)) { + $c = ['src' => $c, 'type' => 'text/javascript']; + } + return "\t" . '' . "\n"; + } + protected function _mergeSVG() { $symbols = []; @@ -1560,7 +1568,7 @@ class Compiler extends Base implements CompilerInterface, IVirtualDirectoryError public function addPDFJSPageRenderer() { $this->vdir->copyDirectory(resource_path('pdfjs/dist-min'), 'pdfjs'); - $this->customJs[] = 'pdfjs/build/pdf.js'; + $this->customJs[] = ['src' => 'pdfjs/build/pdf.js', 'type' => 'module']; } public function addPDFJS($force = false) -- 2.39.5