@openpresentation/opf-editor 0.25.1 → 0.25.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/presenter.js +18 -13
  2. package/package.json +1 -1
package/dist/presenter.js CHANGED
@@ -69,7 +69,7 @@ export function createPresenter(container, options = {}) {
69
69
  // Drawn slides by deck index, for the deck object they were drawn from: a new snapshot (an edit) or a new start() draws again.
70
70
  let drawn = new Map(), drawnFor;
71
71
 
72
- let active = false, destroyed = false, current = -1, opener = null, enteredFullscreen = false, leaving = false;
72
+ let active = false, destroyed = false, current = -1, opener = null, enteredFullscreen = false, leaving = false, returnTo = null;
73
73
  let counterTimer, preloadTimer, renderToken = 0, swipe = null, clickGuardUntil = 0;
74
74
 
75
75
  // ---- the DOM ----------------------------------------------------------------------------------------------------------------------------
@@ -197,7 +197,10 @@ export function createPresenter(container, options = {}) {
197
197
  try { attempt = Promise.resolve(request.call(root, { navigationUI: "hide" })); } catch (error) { attempt = Promise.reject(error); }
198
198
  return attempt.then(
199
199
  () => {
200
- if (!active || doc.fullscreenElement !== root) return "overlay";
200
+ if (doc.fullscreenElement !== root) return "overlay";
201
+ // stop() ran while the request was pending (a quick Esc or close), so it saw no full screen to leave: give the screen back now, or the
202
+ // page stays full screen behind a hidden presenter.
203
+ if (!active) { leaveFullscreen(); return "overlay"; }
201
204
  enteredFullscreen = true;
202
205
  root.dataset.mode = "fullscreen";
203
206
  return "fullscreen";
@@ -205,6 +208,17 @@ export function createPresenter(container, options = {}) {
205
208
  () => "overlay",
206
209
  );
207
210
  }
211
+ // Ask the browser to leave full screen; onFullscreenChange then sees `leaving` and does not read the exit as the user's. Focus goes back to the
212
+ // element that opened the presentation once the exit is done, because the page behind a full screen element takes no focus until then.
213
+ function leaveFullscreen() {
214
+ leaving = true;
215
+ Promise.resolve(doc.exitFullscreen?.()).then(restoreFocus, () => { leaving = false; });
216
+ }
217
+ // Only when nobody took focus since: the host may move it in `onExit`.
218
+ function restoreFocus() {
219
+ const now = doc.activeElement;
220
+ if (returnTo?.isConnected && typeof returnTo.focus === "function" && (!now || now === doc.body || now === root)) returnTo.focus({ preventScroll: true });
221
+ }
208
222
  // The browser takes full screen away with Esc (that key never reaches the page) or the host exits it: the presentation ends with it.
209
223
  function onFullscreenChange() {
210
224
  if (doc.fullscreenElement === root) return;
@@ -314,19 +328,10 @@ export function createPresenter(container, options = {}) {
314
328
  root.hidden = true;
315
329
  slide.replaceChildren();
316
330
  swipe = null;
317
- const back = opener;
331
+ returnTo = opener;
318
332
  opener = null;
319
- const restoreFocus = () => {
320
- // Only when nobody took focus since: the host may move it in `onExit`.
321
- const now = doc.activeElement;
322
- if (back?.isConnected && typeof back.focus === "function" && (!now || now === doc.body || now === root)) back.focus({ preventScroll: true });
323
- };
324
333
  restoreFocus();
325
- if (fullscreen) {
326
- leaving = true;
327
- // The page behind a full screen element takes no focus until the exit is done.
328
- Promise.resolve(doc.exitFullscreen?.()).then(restoreFocus, () => { leaving = false; });
329
- }
334
+ if (fullscreen) leaveFullscreen();
330
335
  // The deck index the presentation ended on (-1 when no slide was shown: there was nothing to present).
331
336
  options.onExit?.(index);
332
337
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openpresentation/opf-editor",
3
- "version": "0.25.1",
3
+ "version": "0.25.2",
4
4
  "description": "Embeddable local OPF editor primitives built on the deterministic renderer.",
5
5
  "license": "MIT",
6
6
  "type": "module",