use App\Elearning\QuizCompiler\Animations;
use App\Elearning\QuizCompiler\L10N;
use App\Fields\FluidbookFont;
+use App\Fields\HorizontalAlign;
+use App\Fields\ThemeBackgroundSize;
+use App\Fields\VerticalAlign;
use App\Jobs\Base;
use App\Models\Quiz;
use App\Models\QuizTheme;
use Cubist\Util\Data;
use Cubist\Util\Files\Files;
use Cubist\Util\Files\VirtualDirectory;
+use Cubist\Util\Graphics\Color;
+use Psy\Output\Theme;
use RyanChandler\Blade\Blade;
+use function PHPUnit\Framework\matches;
class QuizCompiler extends Base
{
$this->sassVariables['neutral-color'] = $this->theme->neutralColor;
$this->sassVariables['ok-color'] = $this->theme->okColor;
$this->sassVariables['nok-color'] = $this->theme->nokColor;
- // Breakpoints
- $this->sassVariables['breakpoints'] = "(sm: (min: '576px',max: '575.98px') , md: (min: '768px',max: '767.98px'), lg: (min: '1024px',max: '1023.98px' ), xl: (min: '1200px', max: '1199.98px'))";
// Fonts size:Line Height
$this->sassVariables['fonts-size'] = "(14: 20px, 16: 22px, 20: 28px, 24: 35px)";
+ $this->sassVariables['background-color'] = Color::colorToCSS($this->theme->backgroundColor);
+ $this->sassVariables['background-custom'] = $this->theme->backgroundCustom ? 'true' : 'false';
+ if ($this->theme->backgroundCustom) {
+ $this->_addBackgroundVariables('background-desktop', 'background');
+ if ($this->theme->backgroundCustomMobile) {
+ $this->_addBackgroundVariables('background-mobile', 'background', 'Mobile');
+ } else {
+ $this->_addBackgroundVariables('background-mobile', 'background');
+ }
+ }
+
$this->writeSass();
}
+ protected function _addBackgroundVariables($sassPrefix, $themePrefix, $themeSuffix = '')
+ {
+ $this->sassVariables[$sassPrefix . '-image'] = '../' . $this->data['theme']->{$themePrefix . 'Image' . $themeSuffix};
+
+ switch ($this->data['theme']->{$themePrefix . 'Image' . $themeSuffix}) {
+
+ case ThemeBackgroundSize::REPEAT:
+ $size = 'auto auto';
+ $repeat = 'repeat';
+ break;
+ case ThemeBackgroundSize::RATIO:
+ $size = 'cover';
+ $repeat = 'no-repeat';
+ break;
+ case ThemeBackgroundSize::NONE:
+ $size = 'auto auto';
+ $repeat = 'no-repeat';
+ break;
+ default:
+ case ThemeBackgroundSize::STRETCH:
+ $size = '100% 100%';
+ $repeat = 'no-repeat';
+ break;
+
+ }
+
+ $positionx = match ($this->data['theme']->{$themePrefix . 'HorizontalAlign' . $themeSuffix}) {
+ HorizontalAlign::LEFT => '0%',
+ HorizontalAlign::CENTER => '50%',
+ HorizontalAlign::RIGHT => '100%',
+ default => '50%',
+ };
+
+
+ $positiony = match ($this->data['theme']->{$themePrefix . 'VerticalAlign' . $themeSuffix}) {
+ VerticalAlign::TOP => '0%',
+ VerticalAlign::MIDDLE => '50%',
+ VerticalAlign::BOTTOM => '100%',
+ default => '50%',
+ };
+
+
+ $this->sassVariables[$sassPrefix . '-repeat'] = $repeat;
+ $this->sassVariables[$sassPrefix . '-size'] = $size;
+ $this->sassVariables[$sassPrefix . '-position-x'] = $positionx;
+ $this->sassVariables[$sassPrefix . '-position-y'] = $positiony;
+ }
+
+
protected function _font($f)
{
$font = FluidbookFont::getAvailableFonts()[$f];
{
$sass = '';
foreach ($this->sassVariables as $key => $value) {
- $sass .= '$' . $key . ': ' . $value . "\n";
+ $sass .= '$' . $key . ': ' . $this->_escapeSassValue($value) . "\n";
}
file_put_contents($this->compilePath . '/style/002-item-variables.sass', $sass);
}
+ protected function _escapeSassValue($value)
+ {
+ if (stristr($value, '.')) {
+ return '"' . $value . '"';
+ }
+ return $value;
+ }
+
/**
* @param $vdir VirtualDirectory
$cli->setModule('cross-env process.env.local=1 mix' . $arg);
$cli->execute();
- if (!file_exists($this->compilePath . '/dist/js/quiz.js')) {
- $cli->dd();
+ $requiredFiles = ['js/quiz.js', 'css/style.css'];
+
+ foreach ($requiredFiles as $requiredFile) {
+ if (!file_exists($this->compilePath . '/dist/' . $requiredFile)) {
+ $cli->dd();
+ }
}
}
}
$this->addField('outroImage', FluidbookThemeImage::class, __('Desktop'), ['hint' => __('Taille recommandée : :size', ['size' => '1200 x 680px']), 'when' => ['outroCustom' => 1]]);
$this->addField('outroImageMobile', FluidbookThemeImage::class, __('Mobile'), ['hint' => __('Taille recommandée : :size', ['size' => '390 x 844px']), 'when' => ['outroCustom' => 1]]);
$this->addField('', FormSeparator::class, '');
- $this->addField('outroSuccessAnimation', FluidbookThemeImage::class, __('Animation de réussite'), ['hint' => __('390 x390px')]);
- $this->addField('outroFailAnimation', FluidbookThemeImage::class, __('Animation d\'échec'), ['hint' => __('390 x390px')]);
+ $this->addField('outroSuccessAnimation', FluidbookThemeImage::class, __('Animation de réussite'), ['hint' => __('390 x 390px')]);
+ $this->addField('outroFailAnimation', FluidbookThemeImage::class, __('Animation d\'échec'), ['hint' => __('390 x 390px')]);
}
public function getTextsColor()