1
0
mirror of https://github.com/hakimel/reveal.js.git synced 2025-08-10 16:47:28 +02:00

bake font into themes, fix broken test, switch tests to mjs

This commit is contained in:
Hakim El Hattab
2024-10-18 14:11:45 +02:00
parent 22a23e43ee
commit d712c148ec
30 changed files with 37 additions and 436 deletions

View File

@@ -11,7 +11,7 @@
// ---------------------------------------------
// Include theme-specific fonts
@import url("/theme/fonts/league-gothic/league-gothic.css");
@import url("./fonts/league-gothic/league-gothic.css");
@import url("https://fonts.googleapis.com/css?family=Lato:400,700,400italic,700italic");
// Override theme settings (see ../template/settings.scss)

View File

@@ -14,7 +14,7 @@
// ---------------------------------------------
// Include theme-specific fonts
@import url("/theme/fonts/source-sans-pro/source-sans-pro.css");
@import url("./fonts/source-sans-pro/source-sans-pro.css");
// Override theme settings (see ../template/settings.scss)
$backgroundColor: #000000;

View File

@@ -11,7 +11,7 @@
// ---------------------------------------------
// Include theme-specific fonts
@import url("/theme/fonts/source-sans-pro/source-sans-pro.css");
@import url("./fonts/source-sans-pro/source-sans-pro.css");
// Override theme settings (see ../template/settings.scss)
$backgroundColor: #191919;

View File

@@ -16,7 +16,7 @@
// Include theme-specific fonts
@import url("/theme/fonts/league-gothic/league-gothic.css");
@import url("./fonts/league-gothic/league-gothic.css");
@import url("https://fonts.googleapis.com/css?family=Lato:400,700,400italic,700italic");
// Override theme settings (see ../template/settings.scss)

View File

@@ -10,7 +10,7 @@
// ---------------------------------------------
// Include theme-specific fonts
@import url("/theme/fonts/league-gothic/league-gothic.css");
@import url("./fonts/league-gothic/league-gothic.css");
@import url("https://fonts.googleapis.com/css?family=Lato:400,700,400italic,700italic");
/**

View File

@@ -10,7 +10,7 @@
// ---------------------------------------------
// Include theme-specific fonts
@import url("/theme/fonts/league-gothic/league-gothic.css");
@import url("./fonts/league-gothic/league-gothic.css");
@import url("https://fonts.googleapis.com/css?family=Lato:400,700,400italic,700italic");
/**

View File

@@ -14,7 +14,7 @@
// ---------------------------------------------
// Include theme-specific fonts
@import url("/theme/fonts/source-sans-pro/source-sans-pro.css");
@import url("./fonts/source-sans-pro/source-sans-pro.css");
// Override theme settings (see ../template/settings.scss)
$backgroundColor: #fff;

View File

@@ -11,7 +11,7 @@
// ---------------------------------------------
// Include theme-specific fonts
@import url("/theme/fonts/source-sans-pro/source-sans-pro.css");
@import url("./fonts/source-sans-pro/source-sans-pro.css");
// Override theme settings (see ../template/settings.scss)
$backgroundColor: #fff;

View File

@@ -1,331 +0,0 @@
const fs = require('fs');
const pkg = require('./package.json')
const glob = require('glob')
const yargs = require('yargs')
const through = require('through2');
const qunit = require('node-qunit-puppeteer')
const {rollup} = require('rollup')
const terser = require('@rollup/plugin-terser')
const babel = require('@rollup/plugin-babel').default
const commonjs = require('@rollup/plugin-commonjs')
const resolve = require('@rollup/plugin-node-resolve').default
const sass = require('sass')
const gulp = require('gulp')
const zip = require('gulp-zip')
const header = require('gulp-header-comment')
const eslint = require('gulp-eslint')
const minify = require('gulp-clean-css')
const connect = require('gulp-connect')
const autoprefixer = require('gulp-autoprefixer')
const root = yargs.argv.root || '.'
const port = yargs.argv.port || 8000
const host = yargs.argv.host || 'localhost'
const cssLicense = `
reveal.js ${pkg.version}
${pkg.homepage}
MIT licensed
Copyright (C) 2011-2024 Hakim El Hattab, https://hakim.se
`;
const jsLicense = `/*!
* reveal.js ${pkg.version}
* ${pkg.homepage}
* MIT licensed
*
* Copyright (C) 2011-2024 Hakim El Hattab, https://hakim.se
*/\n`;
// Prevents warnings from opening too many test pages
process.setMaxListeners(20);
const babelConfig = {
babelHelpers: 'bundled',
ignore: ['node_modules'],
compact: false,
extensions: ['.js', '.html'],
plugins: [
'transform-html-import-to-string'
],
presets: [[
'@babel/preset-env',
{
corejs: 3,
useBuiltIns: 'usage',
modules: false
}
]]
};
// Our ES module bundle only targets newer browsers with
// module support. Browsers are targeted explicitly instead
// of using the "esmodule: true" target since that leads to
// polyfilling older browsers and a larger bundle.
const babelConfigESM = JSON.parse( JSON.stringify( babelConfig ) );
babelConfigESM.presets[0][1].targets = { browsers: [
'last 2 Chrome versions',
'last 2 Safari versions',
'last 2 iOS versions',
'last 2 Firefox versions',
'last 2 Edge versions',
] };
let cache = {};
// Creates a bundle with broad browser support, exposed
// as UMD
gulp.task('js-es5', () => {
return rollup({
cache: cache.umd,
input: 'js/index.js',
plugins: [
resolve(),
commonjs(),
babel( babelConfig ),
terser()
]
}).then( bundle => {
cache.umd = bundle.cache;
return bundle.write({
name: 'Reveal',
file: './dist/reveal.js',
format: 'umd',
banner: jsLicense,
sourcemap: true
});
});
})
// Creates an ES module bundle
gulp.task('js-es6', () => {
return rollup({
cache: cache.esm,
input: 'js/index.js',
plugins: [
resolve(),
commonjs(),
babel( babelConfigESM ),
terser()
]
}).then( bundle => {
cache.esm = bundle.cache;
return bundle.write({
file: './dist/reveal.esm.js',
format: 'es',
banner: jsLicense,
sourcemap: true
});
});
})
gulp.task('js', gulp.parallel('js-es5', 'js-es6'));
// Creates a UMD and ES module bundle for each of our
// built-in plugins
gulp.task('plugins', () => {
return Promise.all([
{ name: 'RevealHighlight', input: './plugin/highlight/plugin.js', output: './plugin/highlight/highlight' },
{ name: 'RevealMarkdown', input: './plugin/markdown/plugin.js', output: './plugin/markdown/markdown' },
{ name: 'RevealSearch', input: './plugin/search/plugin.js', output: './plugin/search/search' },
{ name: 'RevealNotes', input: './plugin/notes/plugin.js', output: './plugin/notes/notes' },
{ name: 'RevealZoom', input: './plugin/zoom/plugin.js', output: './plugin/zoom/zoom' },
{ name: 'RevealMath', input: './plugin/math/plugin.js', output: './plugin/math/math' },
].map( plugin => {
return rollup({
cache: cache[plugin.input],
input: plugin.input,
plugins: [
resolve(),
commonjs(),
babel({
...babelConfig,
ignore: [/node_modules\/(?!(highlight\.js|marked)\/).*/],
}),
terser()
]
}).then( bundle => {
cache[plugin.input] = bundle.cache;
bundle.write({
file: plugin.output + '.esm.js',
name: plugin.name,
format: 'es'
})
bundle.write({
file: plugin.output + '.js',
name: plugin.name,
format: 'umd'
})
});
} ));
})
// a custom pipeable step to transform Sass to CSS
function compileSass() {
return through.obj( ( vinylFile, encoding, callback ) => {
const transformedFile = vinylFile.clone();
sass.render({
silenceDeprecations: ['legacy-js-api'],
data: transformedFile.contents.toString(),
file: transformedFile.path,
}, ( err, result ) => {
if( err ) {
callback(err);
}
else {
transformedFile.extname = '.css';
transformedFile.contents = result.css;
callback( null, transformedFile );
}
});
});
}
gulp.task('css-themes', () => gulp.src(['./css/theme/source/*.{sass,scss}'])
.pipe(compileSass())
.pipe(gulp.dest('./dist/theme')))
gulp.task('css-core', () => gulp.src(['css/reveal.scss'])
.pipe(compileSass())
.pipe(autoprefixer())
.pipe(minify({compatibility: 'ie9'}))
.pipe(header(cssLicense))
.pipe(gulp.dest('./dist')))
gulp.task('css', gulp.parallel('css-themes', 'css-core'))
gulp.task('qunit', () => {
let serverConfig = {
root,
port: 8009,
host: 'localhost',
name: 'test-server'
}
let server = connect.server( serverConfig )
let testFiles = glob.sync('test/*.html' )
let totalTests = 0;
let failingTests = 0;
let tests = Promise.all( testFiles.map( filename => {
return new Promise( ( resolve, reject ) => {
qunit.runQunitPuppeteer({
targetUrl: `http://${serverConfig.host}:${serverConfig.port}/${filename}`,
timeout: 20000,
redirectConsole: false,
puppeteerArgs: ['--allow-file-access-from-files', '--no-sandbox']
})
.then(result => {
if( result.stats.failed > 0 ) {
console.log(`${'!'} ${filename} [${result.stats.passed}/${result.stats.total}] in ${result.stats.runtime}ms`.red);
// qunit.printResultSummary(result, console);
qunit.printFailedTests(result, console);
}
else {
console.log(`${'✔'} ${filename} [${result.stats.passed}/${result.stats.total}] in ${result.stats.runtime}ms`.green);
}
totalTests += result.stats.total;
failingTests += result.stats.failed;
resolve();
})
.catch(error => {
console.error(error);
reject();
});
} )
} ) );
return new Promise( ( resolve, reject ) => {
tests.then( () => {
if( failingTests > 0 ) {
reject( new Error(`${failingTests}/${totalTests} tests failed`.red) );
}
else {
console.log(`${'✔'} Passed ${totalTests} tests`.green.bold);
resolve();
}
} )
.catch( () => {
reject();
} )
.finally( () => {
server.close();
} );
} );
} )
gulp.task('eslint', () => gulp.src(['./js/**', 'gulpfile.js'])
.pipe(eslint())
.pipe(eslint.format()))
gulp.task('test', gulp.series( 'eslint', 'qunit' ))
gulp.task('default', gulp.series(gulp.parallel('js', 'css', 'plugins'), 'test'))
gulp.task('build', gulp.parallel('js', 'css', 'plugins'))
gulp.task('package', gulp.series(async () => {
let dirs = [
'./index.html',
'./dist/**',
'./plugin/**',
'./*/*.md'
];
if (fs.existsSync('./lib')) dirs.push('./lib/**');
if (fs.existsSync('./images')) dirs.push('./images/**');
if (fs.existsSync('./slides')) dirs.push('./slides/**');
return gulp.src( dirs, { base: './', encoding: false } )
.pipe(zip('reveal-js-presentation.zip')).pipe(gulp.dest('./'))
}))
gulp.task('reload', () => gulp.src(['index.html'])
.pipe(connect.reload()));
gulp.task('serve', () => {
connect.server({
root: root,
port: port,
host: host,
livereload: true
})
const slidesRoot = root.endsWith('/') ? root : root + '/'
gulp.watch([
slidesRoot + '**/*.html',
slidesRoot + '**/*.md',
`!${slidesRoot}**/node_modules/**`, // ignore node_modules
], gulp.series('reload'))
gulp.watch(['js/**'], gulp.series('js', 'reload', 'eslint'))
gulp.watch(['plugin/**/plugin.js', 'plugin/**/*.html'], gulp.series('plugins', 'reload'))
gulp.watch([
'css/theme/source/**/*.{sass,scss}',
'css/theme/template/*.{sass,scss}',
], gulp.series('css-themes', 'reload'))
gulp.watch([
'css/*.scss',
'css/print/*.{sass,scss,css}'
], gulp.series('css-core', 'reload'))
gulp.watch(['test/*.html'], gulp.series('test'))
})

View File

@@ -12,43 +12,52 @@
"exports": {
".": {
"import": "./dist/reveal.mjs",
"require": "./dist/reveal.js"
"require": "./dist/reveal.js",
"default": "./dist/reveal.js"
},
"./reveal.css": "./dist/reveal.css",
"./reset.css": "./dist/reset.css",
"./theme/*": "./dist/theme/*",
"./plugin/highlight": {
"import": "./dist/plugin/highlight.mjs",
"require": "./dist/plugin/highlight.js"
"require": "./dist/plugin/highlight.js",
"default": "./dist/plugin/highlight.js"
},
"./plugin/markdown": {
"import": "./dist/plugin/markdown.mjs",
"require": "./dist/plugin/markdown.js"
"require": "./dist/plugin/markdown.js",
"default": "./dist/plugin/markdown.js"
},
"./plugin/math": {
"import": "./dist/plugin/math.mjs",
"require": "./dist/plugin/math.js"
"require": "./dist/plugin/math.js",
"default": "./dist/plugin/math.js"
},
"./plugin/notes": {
"import": "./dist/plugin/notes.mjs",
"require": "./dist/plugin/notes.js"
"require": "./dist/plugin/notes.js",
"default": "./dist/plugin/notes.js"
},
"./plugin/search": {
"import": "./dist/plugin/search.mjs",
"require": "./dist/plugin/search.js"
"require": "./dist/plugin/search.js",
"default": "./dist/plugin/search.js"
},
"./plugin/zoom": {
"import": "./dist/plugin/zoom.mjs",
"require": "./dist/plugin/zoom.js"
"require": "./dist/plugin/zoom.js",
"default": "./dist/plugin/zoom.js"
}
},
"scripts": {
"dev": "vite --port 8000",
"dev": "npm run start",
"start": "vite --port 8000",
"build:core": "tsc && vite build && vite build -c vite.config.styles.ts",
"build": "tsc && vite build && vite build -c vite.config.styles.ts && vite build -c plugin/highlight/vite.config.ts && vite build -c plugin/markdown/vite.config.ts && vite build -c plugin/math/vite.config.ts && vite build -c plugin/notes/vite.config.ts && vite build -c plugin/search/vite.config.ts && vite build -c plugin/zoom/vite.config.ts",
"test": "node test.cjs",
"start": "vite --port 8000"
"test": "node test.js"
},
"author": {
"name": "Hakim El Hattab",

View File

@@ -1,2 +0,0 @@
SIL Open Font License (OFL)
http://scripts.sil.org/cms/scripts/page.php?site_id=nrsi&id=OFL

View File

@@ -1,7 +0,0 @@
@font-face {
font-family: 'League Gothic';
src: url('./league-gothic.woff') format('woff');
font-weight: normal;
font-style: normal;
}

View File

@@ -1,45 +0,0 @@
SIL Open Font License
Copyright 2010, 2012 Adobe Systems Incorporated (http://www.adobe.com/), with Reserved Font Name Source. All Rights Reserved. Source is a trademark of Adobe Systems Incorporated in the United States and/or other countries.
This Font Software is licensed under the SIL Open Font License, Version 1.1.
This license is copied below, and is also available with a FAQ at: http://scripts.sil.org/OFL
—————————————————————————————-
SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
—————————————————————————————-
PREAMBLE
The goals of the Open Font License (OFL) are to stimulate worldwide development of collaborative font projects, to support the font creation efforts of academic and linguistic communities, and to provide a free and open framework in which fonts may be shared and improved in partnership with others.
The OFL allows the licensed fonts to be used, studied, modified and redistributed freely as long as they are not sold by themselves. The fonts, including any derivative works, can be bundled, embedded, redistributed and/or sold with any software provided that any reserved names are not used by derivative works. The fonts and derivatives, however, cannot be released under any other type of license. The requirement for fonts to remain under this license does not apply to any document created using the fonts or their derivatives.
DEFINITIONS
“Font Software” refers to the set of files released by the Copyright Holder(s) under this license and clearly marked as such. This may include source files, build scripts and documentation.
“Reserved Font Name” refers to any names specified as such after the copyright statement(s).
“Original Version” refers to the collection of Font Software components as distributed by the Copyright Holder(s).
“Modified Version” refers to any derivative made by adding to, deleting, or substituting—in part or in whole—any of the components of the Original Version, by changing formats or by porting the Font Software to a new environment.
“Author” refers to any designer, engineer, programmer, technical writer or other person who contributed to the Font Software.
PERMISSION & CONDITIONS
Permission is hereby granted, free of charge, to any person obtaining a copy of the Font Software, to use, study, copy, merge, embed, modify, redistribute, and sell modified and unmodified copies of the Font Software, subject to the following conditions:
1) Neither the Font Software nor any of its individual components, in Original or Modified Versions, may be sold by itself.
2) Original or Modified Versions of the Font Software may be bundled, redistributed and/or sold with any software, provided that each copy contains the above copyright notice and this license. These can be included either as stand-alone text files, human-readable headers or in the appropriate machine-readable metadata fields within text or binary files as long as those fields can be easily viewed by the user.
3) No Modified Version of the Font Software may use the Reserved Font Name(s) unless explicit written permission is granted by the corresponding Copyright Holder. This restriction only applies to the primary font name as presented to the users.
4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font Software shall not be used to promote, endorse or advertise any Modified Version, except to acknowledge the contribution(s) of the Copyright Holder(s) and the Author(s) or with their explicit written permission.
5) The Font Software, modified or unmodified, in part or in whole, must be distributed entirely under this license, and must not be distributed under any other license. The requirement for fonts to remain under this license does not apply to any document created using the Font Software.
TERMINATION
This license becomes null and void if any of the above conditions are not met.
DISCLAIMER
THE FONT SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM OTHER DEALINGS IN THE FONT SOFTWARE.

View File

@@ -1,27 +0,0 @@
@font-face {
font-family: 'Source Sans Pro';
src: url('./source-sans-pro-regular.woff') format('woff');
font-weight: normal;
font-style: normal;
}
@font-face {
font-family: 'Source Sans Pro';
src: url('./source-sans-pro-italic.woff') format('woff');
font-weight: normal;
font-style: italic;
}
@font-face {
font-family: 'Source Sans Pro';
src: url('./source-sans-pro-semibold.woff') format('woff');
font-weight: 600;
font-style: normal;
}
@font-face {
font-family: 'Source Sans Pro';
src: url('./source-sans-pro-semibolditalic.woff') format('woff');
font-weight: 600;
font-style: italic;
}

View File

@@ -1,7 +1,11 @@
const path = require("path");
const glob = require("glob");
const { runQunitPuppeteer, printFailedTests, printOutput } = require("node-qunit-puppeteer");
const { createServer } = require('vite');
import { fileURLToPath } from 'url';
import { dirname } from 'path';
import { glob } from "glob";
import { runQunitPuppeteer, printFailedTests } from "node-qunit-puppeteer";
import { createServer } from 'vite';
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
const testFiles = glob.sync('test/*.html');
@@ -48,7 +52,7 @@ const runTests = async (server) => {
}
}));
console.log(`\n${combinedResults.failed}/${combinedResults.total} tests failed, ${combinedResults.runtime}ms runtime`);
console.log(`\n${combinedResults.passed}/${combinedResults.total} tests passed, ${combinedResults.failed} failed, ${combinedResults.runtime}ms runtime`);
// Exit with status code 1 if any tests failed, otherwise exit with 0
process.exit(combinedResults.failed > 0 ? 1 : 0);

View File

@@ -37,7 +37,7 @@
</div>
<script src="../dist/reveal.js"></script>
<script src="../plugin/zoom/zoom.js"></script>
<script src="../dist/plugin/zoom.js"></script>
<script>
QUnit.config.testTimeout = 30000;