From e8585b8a35978bb1dcff001649d233204488b7d9 Mon Sep 17 00:00:00 2001 From: Vincent Vanwaelscappel Date: Tue, 29 Aug 2023 12:30:40 +0200 Subject: [PATCH] wait #5929 @0.75 --- src/Links/LottieLink.php | 41 +++++++++++++++++++++++++++++----------- 1 file changed, 30 insertions(+), 11 deletions(-) diff --git a/src/Links/LottieLink.php b/src/Links/LottieLink.php index 9e0903d..485c863 100644 --- a/src/Links/LottieLink.php +++ b/src/Links/LottieLink.php @@ -4,6 +4,7 @@ namespace Fluidbook\Tools\Links; use Cubist\Util\CSS; use Cubist\Util\Files\Files; +use Cubist\Util\Graphics\Color; use Cubist\Util\Json; use SplFileInfo; @@ -24,22 +25,35 @@ class LottieLink extends HTMLMultimediaLink if ($ext === 'zip') { $d = $this->unzipFile($this->to, false); $this->_config = $this->getConfigZIP($d['dir']); - $this->copyExternalDir($d['dir'], $d['fdir']); - if (file_exists($d['dir'] . '/index.html')) { - $html = file_get_contents($d['dir'] . '/index.html'); - $html = str_replace('var pRatio = window.devicePixelRatio || 1,', 'var pRatio = 0.5,', $html); - $this->_config['lowDef'] = 'index_ld.html'; - $this->compiler->getVirtualDirectory()->file_put_contents($d['fdir'] . '/' . $this->_config['lowDef'], $html); - } + + $htmlfile = $d['dir'] . '/index.html'; } elseif ($ext === 'html') { $fdir = 'data/links'; $dir = $fdir; - - $d = array('fdir' => $fdir, 'dir' => $dir); - $this->compiler->getVirtualDirectory()->copy($this->compiler->working_path($this->to), $d['dir'] . '/' . $this->to); + $d = array('fdir' => $fdir, 'dir' => $this->compiler->working_path()); $this->_config = $this->getConfigHTML($d['dir'], $this->to); $this->copyExternalFile($d['dir'] . '/' . $this->to); + $htmlfile = $this->compiler->working_path($this->to); + + } + + + $html = file_get_contents($htmlfile); + $bgc = new Color($this->background); + $html = preg_replace('/background-color:.*$/m', 'background-color:' . $bgc->toCSS() . ';', $html); + $html = preg_replace('/loop:\s*(true|false),\s*$/m', 'loop: ' . ($this->video_loop ? 'true' : 'false') . ',', $html); + $html = preg_replace('/autoplay:\s*(true|false),\s*$/m', 'autoplay: ' . ($this->video_auto_start ? 'true' : 'false') . ',', $html); + $html = preg_replace('/renderer:\s*\'(svg|canvas|html)\',\s*$/m', 'renderer: \'' . $this->renderer . '\',', $html); + $replacedHTML = $this->_htmlReplacedName($htmlfile); + file_put_contents($replacedHTML, $html); + + if ($ext === 'zip') { + $this->copyExternalDir($d['dir'], $d['fdir']); + } else { + $this->compiler->getVirtualDirectory()->copy($replacedHTML, $d['fdir'] . '/' . $this->_htmlReplacedName($this->to)); } + + if ($this->_config['width'] == 0) { $this->_config['width'] = $this->width; } @@ -50,7 +64,7 @@ class LottieLink extends HTMLMultimediaLink $res = ''; $s = $this->in_popup ? 1 : $this->getCssScale(); if ($this->_config['html']) { - $this->_url = $d['fdir'] . '/' . $this->_config['html']; + $this->_url = $d['fdir'] . '/' . $this->_htmlReplacedName($this->_config['html']); if ($this->extra) { $this->_url .= '?' . $this->extra; } @@ -64,4 +78,9 @@ class LottieLink extends HTMLMultimediaLink } return $this->_content; } + + protected function _htmlReplacedName($html) + { + return str_replace('.html', '.r.html', $html); + } } -- 2.39.5