Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ This repository contains a collection of custom plugins for [Reveal.js](https://

## Plugins

| Plugin | Description |
| ------ | ----------- |
| Plugin | Description |
| -------------------------------- | ------------------------------------------------------------------------- |
| [☕️ Caffeine](plugins/caffeine) | Custom plugin to avoid screen going to sleep during active presentations. |

---

Expand Down
21 changes: 21 additions & 0 deletions plugins/caffeine/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2025 ForWarD Software (https://forwardsoftware.solutions/)

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
40 changes: 40 additions & 0 deletions plugins/caffeine/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# ☕️ Caffeine

> Custom plugin for [Reveal.js](https://revealjs.com/) to avoid screen going to sleep during active presentations

## How To

Simply include `RevealCaffeine` plugin and it will automatically activate on presentation start if [`Screen Wake Lock API`](https://developer.mozilla.org/en-US/docs/Web/API/Screen_Wake_Lock_API) is supported by the browser.

```js
Reveal.initialize({
// ...
plugins: [
// ...,
RevealCaffeine,
],
});
```

> [!IMPORTANT]
> The Wake Lock will be released when the presentation is paused or the tab is hidden.

## Configuration

You can configure the plugin with the following options:

```js
// ...
plugins: [ /* ... */ ],
caffeine: {

}
```

## License

MIT

---

Made with ✨ & ❤️ by [ForWarD Software](https://github.com/forwardsoftware) and [contributors](https://github.com/forwardsoftware/revealjs-plugins/graphs/contributors)
77 changes: 77 additions & 0 deletions plugins/caffeine/gulpfile.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import babel from "@rollup/plugin-babel";
import commonjs from "@rollup/plugin-commonjs";
import resolve from "@rollup/plugin-node-resolve";
import strip from "@rollup/plugin-strip";
import terser from "@rollup/plugin-terser";
import gulp from "gulp";
import { rimraf } from "rimraf";
import { rollup } from "rollup";

const babelConfig = {
babelHelpers: "bundled",
ignore: ["node_modules"],
compact: false,
extensions: [".js"],
presets: [
[
"@babel/preset-env",
{
corejs: 3,
useBuiltIns: "usage",
modules: false,
targets: {
browsers: [
"last 2 Chrome versions",
"last 2 Safari versions",
"last 2 iOS versions",
"last 2 Firefox versions",
"last 2 Edge versions",
],
},
},
],
],
ignore: [/node_modules\/(?!(highlight\.js|marked)\/).*/],
};

const debugRollupPlugins = [resolve(), commonjs(), babel(babelConfig), terser()];

const prodRollupPlugins = [resolve(), commonjs(), strip(), babel(babelConfig), terser()];

async function compile(variant) {
const rollupPlugins = variant === "debug" ? debugRollupPlugins : prodRollupPlugins;
const rollupOutputName = variant !== "prod" ? `plugin.${variant}.js` : `plugin.js`;
const rollupOutputFormat = variant === "esm" ? "es" : "umd";

const builder = await rollup({
input: `./src/plugin.js`,
plugins: rollupPlugins,
});

await builder.write({
file: `./dist/${rollupOutputName}`,
name: "RevealCaffeine",
format: rollupOutputFormat,
});
}

// Creates a UMD and ES module bundle for each plugin
export async function plugins() {
await Promise.all(["debug", "esm", "prod"].map(compile));
}

// npm run clean / npx gulp clean: clean 'dist' folder
export const clean = () => rimraf("./dist/");

// npm run build / npx gulp build: build plugins
export const build = gulp.series(clean, plugins);

// watch files for changes and trigger rebuild tasks
async function watchFiles() {
gulp.watch("src/**/*.js", plugins);
}

// npm run watch / npx gulp watch: continuously update index.html from deps
export const watch = gulp.series(build, watchFiles);

export default build;
47 changes: 47 additions & 0 deletions plugins/caffeine/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
{
"name": "@forward-software/reveal.js-caffeine",
"version": "1.0.0",
"description": "Custom plugin for Reveal.js to avoid screen going to sleep during active presentations",
"author": "ForWarD Software (https://forwardsoftware.solutions/)",
"license": "MIT",
"keywords": [
"revealjs",
"reveal-js",
"reveal-plugin",
"reveal-js-plugin",
"caffeine",
"wakelock"
],
"homepage": "https://github.com/forwardsoftware/revealjs-plugins/tree/main/plugins/caffeine#readme",
"bugs": "https://github.com/forwardsoftware/revealjs-plugins/issues",
"repository": {
"type": "git",
"url": "git+https://github.com/forwardsoftware/revealjs-plugins.git",
"directory": "plugins/caffeine"
},
"main": "dist/plugin.js",
"module": "dist/plugin.esm.js",
"files": [
"dist"
],
"publishConfig": {
"access": "public"
},
"scripts": {
"clean": "gulp clean",
"watch": "gulp watch",
"build": "gulp build"
},
"devDependencies": {
"@babel/core": "catalog:",
"@babel/preset-env": "catalog:",
"@rollup/plugin-babel": "catalog:",
"@rollup/plugin-commonjs": "catalog:",
"@rollup/plugin-node-resolve": "catalog:",
"@rollup/plugin-strip": "catalog:",
"@rollup/plugin-terser": "catalog:",
"gulp": "catalog:",
"rimraf": "catalog:",
"rollup": "catalog:"
}
}
85 changes: 85 additions & 0 deletions plugins/caffeine/src/plugin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
const DEFAULT_CONFIGURATION = {};

const Plugin = () => {
let wakeLockSentinel = null;

async function acquireWakeLock(evt) {
console.debug("☕️ Screen Wake Lock acquiring on", evt.type, "event");

try {
// release existing lock (if any)
if (wakeLockSentinel !== null) {
releaseWakeLock(evt);
}

// acquire screen wake lock
wakeLockSentinel = await navigator.wakeLock.request("screen");
console.info("☕️ Screen Wake Lock acquired");
} catch (err) {
console.error("☕️ Screen Wake Lock API acquire error:", err.name, err.message);
}
}

async function releaseWakeLock(evt) {
console.debug("☕️ Screen Wake Lock releasing on", evt.type, "event");
if (wakeLockSentinel === null) {
console.warn("☕️ Screen Wake Lock not yet acquired");
return;
}

try {
await wakeLockSentinel.release();
wakeLockSentinel = null;

console.info("☕️ Screen Wake Lock released");
} catch (err) {
console.error("☕️ Screen Wake Lock API release error:", err.name, err.message);
}
}

async function handleVisibilityChanged(evt) {
console.info("☕️ Tab visibility changed to", document.visibilityState);

// release/acquire wakelock on tab visibility change
switch (document.visibilityState) {
case "hidden":
return releaseWakeLock(evt);

case "visible":
return acquireWakeLock(evt);
}
}

return {
id: "caffeine",

init: function (deck) {
const deckConfig = deck.getConfig();
const config = Object.assign({}, DEFAULT_CONFIGURATION, deckConfig.caffeine);

console.info("☕️ Caffeine plugin by ForWarD Software loaded", config);

if (!navigator.wakeLock) {
console.warn("☕️ Screen Wake Lock API NOT supported!");
return;
}

console.info("☕️ Screen Wake Lock API supported... attaching event listeners");

deck.on("paused", releaseWakeLock);
deck.on("resumed", acquireWakeLock);

deck.on("ready", acquireWakeLock);

document.addEventListener("visibilitychange", handleVisibilityChanged);
},

destroy: function () {
document.removeEventListener("visibilitychange", handleVisibilityChanged);

releaseWakeLock({ type: "destroy" });
},
};
};

export default Plugin;
Loading