fullscreen-engine 1.1.0 → 1.2.0

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.
@@ -1,4 +1,4 @@
1
- /*! fullscreen-engine v1.1.0 | MIT */
1
+ /*! fullscreen-engine v1.2.0 | MIT */
2
2
  (function (global, factory) {
3
3
  typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
4
4
  typeof define === 'function' && define.amd ? define(['exports'], factory) :
@@ -228,6 +228,7 @@
228
228
  exit,
229
229
  elementProp,
230
230
  enabledProp,
231
+ prefix: vendorPrefix,
231
232
  changeEvent,
232
233
  errorEvent,
233
234
  supported: !!(request && exit && elementProp && policyAllowed)
@@ -259,11 +260,22 @@
259
260
  return Number.isFinite(num) ? Math.trunc(num) : 2147483647;
260
261
  }
261
262
 
262
- function getStyleId(baseClass, lockClass, zIndex) {
263
- return `__fullscreen_engine_style_${baseClass}_${lockClass}_${zIndex}__`;
263
+ function getStyleId(baseClass, lockClass, zIndex, freezePage = false) {
264
+ return `__fullscreen_engine_style_${baseClass}_${lockClass}_${zIndex}${freezePage ? '_freeze' : ''}__`;
264
265
  }
265
266
 
266
- function buildCSS(baseClass, lockClass, zIndex) {
267
+ function buildCSS(baseClass, lockClass, zIndex, freezePage = false) {
268
+ const freezeTargetCSS = freezePage
269
+ ? `
270
+ overscroll-behavior: none !important;
271
+ touch-action: manipulation !important;
272
+ user-select: none !important;
273
+ -webkit-user-select: none !important;`
274
+ : '';
275
+ const freezeLockCSS = freezePage
276
+ ? `
277
+ overscroll-behavior: none !important;`
278
+ : '';
267
279
  return `
268
280
  .${baseClass} {
269
281
  position: fixed !important;
@@ -273,25 +285,27 @@
273
285
  bottom: 0 !important;
274
286
  width: 100vw !important;
275
287
  height: 100vh !important;
288
+ height: 100dvh !important;
276
289
  margin: 0 !important;
277
290
  padding: 0 !important;
278
291
  border: 0 !important;
279
292
  z-index: ${zIndex} !important;
280
293
  background: #000 !important;
281
- overflow: auto !important;
294
+ overflow: auto !important;${freezeTargetCSS}
282
295
  }
283
296
  html.${lockClass}, body.${lockClass} {
284
297
  overflow: hidden !important;
298
+ scrollbar-width: none !important;${freezeLockCSS}
285
299
  }
286
300
  `;
287
301
  }
288
302
 
289
- function ensureStyle(styleId, baseClass, lockClass, zIndex) {
303
+ function ensureStyle(styleId, baseClass, lockClass, zIndex, freezePage = false) {
290
304
  if (typeof document === 'undefined') return;
291
305
  if (document.getElementById(styleId)) return;
292
306
  const style = document.createElement('style');
293
307
  style.id = styleId;
294
- style.textContent = buildCSS(baseClass, lockClass, zIndex);
308
+ style.textContent = buildCSS(baseClass, lockClass, zIndex, freezePage);
295
309
  (document.head || document.documentElement).appendChild(style);
296
310
  }
297
311
 
@@ -305,7 +319,8 @@
305
319
  const baseClass = sanitizeClassName(opts.fallbackClass, 'fs-engine-active');
306
320
  const lockClass = opts.lockBody === false ? '__no_lock__' : 'fs-engine-scroll-lock';
307
321
  const zIndex = sanitizeZIndex(opts.zIndex);
308
- const styleId = getStyleId(baseClass, lockClass, zIndex);
322
+ const freezePage = !!opts.freezePage;
323
+ const styleId = getStyleId(baseClass, lockClass, zIndex, freezePage);
309
324
  let active = false;
310
325
  let activeTarget = null;
311
326
  let styleRegistered = false;
@@ -317,7 +332,7 @@
317
332
  styleRefCounts.set(styleId, (styleRefCounts.get(styleId) ?? 0) + 1);
318
333
  styleRegistered = true;
319
334
  }
320
- ensureStyle(styleId, baseClass, lockClass, zIndex);
335
+ ensureStyle(styleId, baseClass, lockClass, zIndex, freezePage);
321
336
  activeTarget = target;
322
337
  target.classList.add(baseClass);
323
338
  if (opts.lockBody !== false && !lockApplied) {
@@ -653,6 +668,284 @@
653
668
  };
654
669
  }
655
670
 
671
+ /**
672
+ * Cross-browser kiosk & exit-key guards (browser-safe, zero Node built-ins).
673
+ *
674
+ * Supports:
675
+ * - keyboardLock: navigator.keyboard?.lock(keys) on native fullscreen
676
+ * - blockShortcuts: keydown guard for F11, Escape (when exitLocked), or custom keys
677
+ * - confirmOnLeave: beforeunload prompt while exitLocked && active
678
+ * - blockContextMenu: contextmenu prevention while active
679
+ */
680
+
681
+ function normalizeKeyboardLock(val) {
682
+ if (val === undefined || val === null || val === false) {
683
+ return { enabled: false, keys: ['Escape', 'F11'] };
684
+ }
685
+ if (val === true) {
686
+ return { enabled: true, keys: ['Escape', 'F11'] };
687
+ }
688
+ if (Array.isArray(val)) {
689
+ const keys = val.map((k) => String(k)).filter(Boolean);
690
+ return { enabled: keys.length > 0, keys };
691
+ }
692
+ throw new TypeError(
693
+ '[fullscreen-engine] invalid keyboardLock option: expected boolean or string[]'
694
+ );
695
+ }
696
+
697
+ const DEFAULT_SHORTCUTS = [
698
+ 'F11',
699
+ 'Escape',
700
+ 'F5',
701
+ 'F12',
702
+ 'Ctrl+R',
703
+ 'Meta+R',
704
+ 'Ctrl+Shift+I',
705
+ 'Meta+Alt+I'
706
+ ];
707
+
708
+ function parseShortcut(raw) {
709
+ const parts = String(raw)
710
+ .split('+')
711
+ .map((p) => p.trim())
712
+ .filter(Boolean);
713
+ if (parts.length === 0) return null;
714
+ const key = parts[parts.length - 1].toLowerCase();
715
+ const mods = parts.slice(0, -1).map((m) => m.toLowerCase());
716
+ const hasModifiers = mods.length > 0;
717
+ return {
718
+ key,
719
+ hasModifiers,
720
+ ctrl: mods.includes('ctrl') || mods.includes('control'),
721
+ meta: mods.includes('meta') || mods.includes('cmd') || mods.includes('command'),
722
+ alt: mods.includes('alt') || mods.includes('option'),
723
+ shift: mods.includes('shift')
724
+ };
725
+ }
726
+
727
+ function matchesShortcut(e, rule) {
728
+ if (!rule || !e || !e.key) return false;
729
+ if (String(e.key).toLowerCase() !== rule.key) return false;
730
+ if (!rule.hasModifiers) return true;
731
+ return (
732
+ !!e.ctrlKey === rule.ctrl &&
733
+ !!e.metaKey === rule.meta &&
734
+ !!e.altKey === rule.alt &&
735
+ !!e.shiftKey === rule.shift
736
+ );
737
+ }
738
+
739
+ function normalizeBlockShortcuts(val) {
740
+ if (val === undefined || val === null || val === false) {
741
+ return { enabled: false, keys: ['F11'], rules: [parseShortcut('F11')] };
742
+ }
743
+ if (val === true) {
744
+ return {
745
+ enabled: true,
746
+ keys: DEFAULT_SHORTCUTS.slice(),
747
+ rules: DEFAULT_SHORTCUTS.map(parseShortcut).filter(Boolean)
748
+ };
749
+ }
750
+ if (Array.isArray(val)) {
751
+ const keys = val.map((k) => String(k).trim()).filter(Boolean);
752
+ const rules = keys.map(parseShortcut).filter(Boolean);
753
+ return { enabled: rules.length > 0, keys, rules };
754
+ }
755
+ throw new TypeError(
756
+ '[fullscreen-engine] invalid blockShortcuts option: expected boolean or string[]'
757
+ );
758
+ }
759
+
760
+ function createGuards({
761
+ keyboardLock,
762
+ blockShortcuts,
763
+ confirmOnLeave,
764
+ blockContextMenu,
765
+ watchFocus = false,
766
+ isExitLocked,
767
+ onExitAttempt,
768
+ onEscapeExit,
769
+ onFocusLost
770
+ }) {
771
+ let keyboardLocked = false;
772
+ let keydownBound = false;
773
+ let beforeUnloadBound = false;
774
+ let contextMenuBound = false;
775
+ let focusBound = false;
776
+
777
+ function releaseKeyboardLock() {
778
+ if (!keyboardLocked) return;
779
+ keyboardLocked = false;
780
+ if (
781
+ typeof navigator !== 'undefined' &&
782
+ navigator.keyboard &&
783
+ typeof navigator.keyboard.unlock === 'function'
784
+ ) {
785
+ try {
786
+ navigator.keyboard.unlock();
787
+ } catch {
788
+ // ignore unsupported unlock errors
789
+ }
790
+ }
791
+ }
792
+
793
+ function onKeyDown(e) {
794
+ if (!e || !e.key) return;
795
+ const rules = blockShortcuts.rules || blockShortcuts.keys.map(parseShortcut).filter(Boolean);
796
+ const matched = rules.some((rule) => matchesShortcut(e, rule));
797
+ if (!matched) return;
798
+ if (e.key === 'Escape' && !isExitLocked()) {
799
+ if (typeof onEscapeExit === 'function') onEscapeExit();
800
+ return;
801
+ }
802
+ if (typeof e.preventDefault === 'function') e.preventDefault();
803
+ if (typeof e.stopPropagation === 'function') e.stopPropagation();
804
+ if (typeof onExitAttempt === 'function') {
805
+ onExitAttempt(e.key === 'Escape' ? 'escape' : 'shortcut');
806
+ }
807
+ }
808
+
809
+ function onVisibilityChange() {
810
+ if (typeof document !== 'undefined' && document.hidden && typeof onFocusLost === 'function') {
811
+ onFocusLost('visibilitychange');
812
+ }
813
+ }
814
+
815
+ function onWindowBlur() {
816
+ if (typeof onFocusLost === 'function') {
817
+ onFocusLost('blur');
818
+ }
819
+ }
820
+
821
+ function onBeforeUnload(e) {
822
+ if (!isExitLocked()) return;
823
+ if (typeof e.preventDefault === 'function') e.preventDefault();
824
+ e.returnValue = '';
825
+ }
826
+
827
+ function onContextMenu(e) {
828
+ if (typeof e.preventDefault === 'function') e.preventDefault();
829
+ }
830
+
831
+ function bindKeydown() {
832
+ if (typeof document === 'undefined' || keydownBound) return;
833
+ document.addEventListener('keydown', onKeyDown, true);
834
+ keydownBound = true;
835
+ }
836
+
837
+ function unbindKeydown() {
838
+ if (typeof document === 'undefined' || !keydownBound) return;
839
+ document.removeEventListener('keydown', onKeyDown, true);
840
+ keydownBound = false;
841
+ }
842
+
843
+ function bindBeforeUnload() {
844
+ if (typeof window === 'undefined' || beforeUnloadBound) return;
845
+ window.addEventListener('beforeunload', onBeforeUnload);
846
+ beforeUnloadBound = true;
847
+ }
848
+
849
+ function unbindBeforeUnload() {
850
+ if (typeof window === 'undefined' || !beforeUnloadBound) return;
851
+ window.removeEventListener('beforeunload', onBeforeUnload);
852
+ beforeUnloadBound = false;
853
+ }
854
+
855
+ function bindContextMenu() {
856
+ if (typeof document === 'undefined' || contextMenuBound) return;
857
+ document.addEventListener('contextmenu', onContextMenu, true);
858
+ contextMenuBound = true;
859
+ }
860
+
861
+ function unbindContextMenu() {
862
+ if (typeof document === 'undefined' || !contextMenuBound) return;
863
+ document.removeEventListener('contextmenu', onContextMenu, true);
864
+ contextMenuBound = false;
865
+ }
866
+
867
+ function bindFocus() {
868
+ if (focusBound) return;
869
+ if (typeof document !== 'undefined') {
870
+ document.addEventListener('visibilitychange', onVisibilityChange);
871
+ }
872
+ if (typeof window !== 'undefined') {
873
+ window.addEventListener('blur', onWindowBlur);
874
+ }
875
+ focusBound = true;
876
+ }
877
+
878
+ function unbindFocus() {
879
+ if (!focusBound) return;
880
+ if (typeof document !== 'undefined') {
881
+ document.removeEventListener('visibilitychange', onVisibilityChange);
882
+ }
883
+ if (typeof window !== 'undefined') {
884
+ window.removeEventListener('blur', onWindowBlur);
885
+ }
886
+ focusBound = false;
887
+ }
888
+
889
+ function sync(active, source) {
890
+ if (!active) {
891
+ releaseKeyboardLock();
892
+ unbindKeydown();
893
+ unbindBeforeUnload();
894
+ unbindContextMenu();
895
+ unbindFocus();
896
+ return;
897
+ }
898
+
899
+ if (
900
+ keyboardLock.enabled &&
901
+ source === 'native' &&
902
+ !keyboardLocked &&
903
+ typeof navigator !== 'undefined' &&
904
+ navigator.keyboard &&
905
+ typeof navigator.keyboard.lock === 'function'
906
+ ) {
907
+ keyboardLocked = true;
908
+ try {
909
+ Promise.resolve(navigator.keyboard.lock(keyboardLock.keys)).catch(() => {
910
+ keyboardLocked = false;
911
+ });
912
+ } catch {
913
+ keyboardLocked = false;
914
+ }
915
+ } else if (source !== 'native') {
916
+ releaseKeyboardLock();
917
+ }
918
+
919
+ if (blockShortcuts.enabled) bindKeydown();
920
+ else unbindKeydown();
921
+
922
+ if (confirmOnLeave && isExitLocked()) bindBeforeUnload();
923
+ else unbindBeforeUnload();
924
+
925
+ if (blockContextMenu) bindContextMenu();
926
+ else unbindContextMenu();
927
+
928
+ if (watchFocus) bindFocus();
929
+ else unbindFocus();
930
+ }
931
+
932
+ function unlock() {
933
+ releaseKeyboardLock();
934
+ unbindBeforeUnload();
935
+ unbindFocus();
936
+ }
937
+
938
+ function destroy() {
939
+ sync(false, 'none');
940
+ }
941
+
942
+ return {
943
+ sync,
944
+ unlock,
945
+ destroy
946
+ };
947
+ }
948
+
656
949
  /**
657
950
  * Core engine: createFullscreen()
658
951
  *
@@ -707,6 +1000,57 @@
707
1000
  throw new TypeError('[fullscreen-engine] target must be a valid DOM Element');
708
1001
  }
709
1002
 
1003
+ const navigationUIOption = userOptions.navigationUI ?? 'hide';
1004
+ if (navigationUIOption !== 'hide' && navigationUIOption !== 'show' && navigationUIOption !== 'auto') {
1005
+ throw new TypeError(
1006
+ `[fullscreen-engine] invalid navigationUI "${String(navigationUIOption)}": expected 'hide', 'show', or 'auto'`
1007
+ );
1008
+ }
1009
+
1010
+ let exitButtons = [];
1011
+ if (userOptions.exitButton !== undefined && userOptions.exitButton !== null) {
1012
+ if (Array.isArray(userOptions.exitButton)) {
1013
+ for (const btn of userOptions.exitButton) {
1014
+ if (!isValidElement(btn)) {
1015
+ throw new TypeError('[fullscreen-engine] exitButton must be a valid DOM Element or Element[]');
1016
+ }
1017
+ }
1018
+ exitButtons = userOptions.exitButton.slice();
1019
+ } else if (isValidElement(userOptions.exitButton)) {
1020
+ exitButtons = [userOptions.exitButton];
1021
+ } else {
1022
+ throw new TypeError('[fullscreen-engine] exitButton must be a valid DOM Element or Element[]');
1023
+ }
1024
+ }
1025
+
1026
+ const freezePageOption = userOptions.freezePage ?? false;
1027
+ if (typeof freezePageOption !== 'boolean') {
1028
+ throw new TypeError('[fullscreen-engine] invalid freezePage option: expected boolean');
1029
+ }
1030
+
1031
+ const gestureUpgradeOption = userOptions.gestureUpgrade ?? false;
1032
+ if (typeof gestureUpgradeOption !== 'boolean') {
1033
+ throw new TypeError('[fullscreen-engine] invalid gestureUpgrade option: expected boolean');
1034
+ }
1035
+
1036
+ const keyboardLockConfig = normalizeKeyboardLock(userOptions.keyboardLock);
1037
+ const blockShortcutsConfig = normalizeBlockShortcuts(userOptions.blockShortcuts);
1038
+
1039
+ const confirmOnLeaveOption = userOptions.confirmOnLeave ?? false;
1040
+ if (typeof confirmOnLeaveOption !== 'boolean') {
1041
+ throw new TypeError('[fullscreen-engine] invalid confirmOnLeave option: expected boolean');
1042
+ }
1043
+
1044
+ const blockContextMenuOption = userOptions.blockContextMenu ?? false;
1045
+ if (typeof blockContextMenuOption !== 'boolean') {
1046
+ throw new TypeError('[fullscreen-engine] invalid blockContextMenu option: expected boolean');
1047
+ }
1048
+
1049
+ const watchFocusOption = userOptions.watchFocus ?? false;
1050
+ if (typeof watchFocusOption !== 'boolean') {
1051
+ throw new TypeError('[fullscreen-engine] invalid watchFocus option: expected boolean');
1052
+ }
1053
+
710
1054
  const options = {
711
1055
  target: userOptions.target ?? null,
712
1056
  fallback: fallbackOption, // 'css' | 'none'
@@ -715,6 +1059,15 @@
715
1059
  zIndex: userOptions.zIndex ?? 2147483647,
716
1060
  onError: userOptions.onError ?? null,
717
1061
  autoDetectElectron: userOptions.autoDetectElectron ?? true,
1062
+ navigationUI: navigationUIOption,
1063
+ exitButton: userOptions.exitButton ?? null,
1064
+ freezePage: freezePageOption,
1065
+ gestureUpgrade: gestureUpgradeOption,
1066
+ keyboardLock: keyboardLockConfig,
1067
+ blockShortcuts: blockShortcutsConfig,
1068
+ confirmOnLeave: confirmOnLeaveOption,
1069
+ blockContextMenu: blockContextMenuOption,
1070
+ watchFocus: watchFocusOption,
718
1071
  trigger: triggers.list,
719
1072
  hoverTarget: userOptions.hoverTarget ?? null,
720
1073
  hoverDelay: userOptions.hoverDelay ?? 0,
@@ -770,7 +1123,8 @@
770
1123
  ? createFallback({
771
1124
  fallbackClass: options.fallbackClass,
772
1125
  lockBody: effectiveLockBody,
773
- zIndex: options.zIndex
1126
+ zIndex: options.zIndex,
1127
+ freezePage: options.freezePage
774
1128
  })
775
1129
  : null;
776
1130
 
@@ -780,6 +1134,7 @@
780
1134
  let lastSource = 'none';
781
1135
  let electronUnsub = null;
782
1136
  let escapeBound = false;
1137
+ let gestureUpgradeBound = false;
783
1138
  let exitLocked = !!options.preventExit;
784
1139
  let manualUnlocking = false;
785
1140
  let relockTimer = null;
@@ -824,6 +1179,7 @@
824
1179
  if (exitLocked) {
825
1180
  if (typeof e.preventDefault === 'function') e.preventDefault();
826
1181
  if (typeof e.stopPropagation === 'function') e.stopPropagation();
1182
+ emitter.emit('exitAttempt', { reason: 'escape', state: getState() });
827
1183
  emitError(new Error('[fullscreen-engine] Exit blocked: preventExit is active'));
828
1184
  return;
829
1185
  }
@@ -886,7 +1242,12 @@
886
1242
  if (state.active && state.source !== 'fallback' && fallback && fallback.active) {
887
1243
  fallback.exit();
888
1244
  }
889
- syncEscapeListener(state.active && state.source === 'fallback');
1245
+ const guardsHandlesEscape =
1246
+ blockShortcutsConfig.enabled &&
1247
+ (blockShortcutsConfig.rules || []).some((r) => r.key === 'escape');
1248
+ syncEscapeListener(state.active && state.source === 'fallback' && !guardsHandlesEscape);
1249
+ syncGestureUpgrade(state.active && state.source === 'fallback');
1250
+ guards.sync(state.active, state.source);
890
1251
  if (state.active) {
891
1252
  relockRetries = 0;
892
1253
  clearRelockTimer();
@@ -903,6 +1264,14 @@
903
1264
  else {
904
1265
  emitter.emit('exit', state);
905
1266
  if (wasActive && relockConfig.enabled && !manualUnlocking) {
1267
+ if (options.gestureUpgrade && hasFallback && fallback && !hasElectron) {
1268
+ const target = resolveTarget();
1269
+ if (target) {
1270
+ fallback.enter(target);
1271
+ notifyChange(false);
1272
+ return;
1273
+ }
1274
+ }
906
1275
  scheduleRelock();
907
1276
  }
908
1277
  }
@@ -913,7 +1282,11 @@
913
1282
  if (typeof electronBridge.onChange === 'function') {
914
1283
  electronUnsub = electronBridge.onChange((on) => {
915
1284
  if (destroyed) return;
916
- electronActive = !!on;
1285
+ const next = !!on;
1286
+ if (electronActive && !next && exitLocked) {
1287
+ emitter.emit('exitAttempt', { reason: 'external', state: getState() });
1288
+ }
1289
+ electronActive = next;
917
1290
  notifyChange(false);
918
1291
  });
919
1292
  }
@@ -958,6 +1331,70 @@
958
1331
 
959
1332
  bindNativeListeners();
960
1333
 
1334
+ // ---------- native request + gestureUpgrade helpers ----------
1335
+ function invokeNativeRequest(target) {
1336
+ return maybePromise(() => {
1337
+ if (env.request === 'requestFullscreen') {
1338
+ try {
1339
+ return target[env.request]({ navigationUI: options.navigationUI });
1340
+ } catch (optErr) {
1341
+ if (optErr instanceof TypeError) {
1342
+ return target[env.request]();
1343
+ }
1344
+ throw optErr;
1345
+ }
1346
+ }
1347
+ return target[env.request]();
1348
+ });
1349
+ }
1350
+
1351
+ function clearGestureUpgrade() {
1352
+ if (typeof document === 'undefined' || !gestureUpgradeBound) return;
1353
+ document.removeEventListener('pointerdown', onGestureUpgrade, true);
1354
+ gestureUpgradeBound = false;
1355
+ }
1356
+
1357
+ function onGestureUpgrade() {
1358
+ gestureUpgradeBound = false;
1359
+ if (destroyed || manualUnlocking || !options.gestureUpgrade || !hasNative || !isBrowser()) return;
1360
+ const st = getState();
1361
+ if (!st.active || st.source !== 'fallback') return;
1362
+ const target = resolveTarget();
1363
+ if (!target) return;
1364
+ invokeNativeRequest(target)
1365
+ .then(() => {
1366
+ if (destroyed) return;
1367
+ if (fallback && fallback.active) {
1368
+ fallback.exit();
1369
+ }
1370
+ notifyChange(false);
1371
+ })
1372
+ .catch((err) => {
1373
+ emitError(err);
1374
+ if (!destroyed && !manualUnlocking && getState().source === 'fallback') {
1375
+ syncGestureUpgrade(true);
1376
+ }
1377
+ });
1378
+ }
1379
+
1380
+ function syncGestureUpgrade(shouldArm) {
1381
+ if (
1382
+ !options.gestureUpgrade ||
1383
+ !hasNative ||
1384
+ hasElectron ||
1385
+ !isBrowser() ||
1386
+ manualUnlocking ||
1387
+ !shouldArm
1388
+ ) {
1389
+ clearGestureUpgrade();
1390
+ return;
1391
+ }
1392
+ if (!gestureUpgradeBound) {
1393
+ document.addEventListener('pointerdown', onGestureUpgrade, { capture: true, once: true });
1394
+ gestureUpgradeBound = true;
1395
+ }
1396
+ }
1397
+
961
1398
  // ---------- auto-trigger activation (gesture-safe) ----------
962
1399
  async function requestAuto() {
963
1400
  if (destroyed) return;
@@ -988,12 +1425,13 @@
988
1425
  }
989
1426
  }
990
1427
 
991
- async function exitInternal(fromAutoTrigger = false) {
1428
+ async function exitInternal(fromAutoTrigger = false, reason = 'api') {
992
1429
  if (destroyed) {
993
1430
  if (!fromAutoTrigger) throw new Error('[fullscreen-engine] instance destroyed');
994
1431
  return;
995
1432
  }
996
1433
  if (exitLocked && !fromAutoTrigger) {
1434
+ emitter.emit('exitAttempt', { reason, state: getState() });
997
1435
  const err = new Error('[fullscreen-engine] Exit blocked: preventExit is active');
998
1436
  emitError(err);
999
1437
  throw err;
@@ -1049,6 +1487,26 @@
1049
1487
  onExit: () => exitInternal(true)
1050
1488
  });
1051
1489
 
1490
+ const guards = createGuards({
1491
+ keyboardLock: keyboardLockConfig,
1492
+ blockShortcuts: blockShortcutsConfig,
1493
+ confirmOnLeave: confirmOnLeaveOption,
1494
+ blockContextMenu: blockContextMenuOption,
1495
+ watchFocus: watchFocusOption,
1496
+ isExitLocked: () => exitLocked,
1497
+ onExitAttempt: (reason) => {
1498
+ emitter.emit('exitAttempt', { reason, state: getState() });
1499
+ },
1500
+ onEscapeExit: () => {
1501
+ if (!destroyed && fallback && fallback.active && !exitLocked) {
1502
+ exit().catch((err) => emitError(err));
1503
+ }
1504
+ },
1505
+ onFocusLost: (reason) => {
1506
+ emitter.emit('focusLost', { reason, state: getState() });
1507
+ }
1508
+ });
1509
+
1052
1510
  // ---------- public API ----------
1053
1511
  async function request() {
1054
1512
  if (destroyed) throw new Error('[fullscreen-engine] instance destroyed');
@@ -1074,7 +1532,7 @@
1074
1532
  const target = resolveTarget();
1075
1533
  if (!target) throw new Error('[fullscreen-engine] no target element');
1076
1534
  try {
1077
- await maybePromise(() => target[env.request]());
1535
+ await invokeNativeRequest(target);
1078
1536
  // Avoid duplicate emissions if native changeEvent already fired
1079
1537
  notifyChange(false);
1080
1538
  return;
@@ -1111,9 +1569,16 @@
1111
1569
  exitLocked = false;
1112
1570
  manualUnlocking = true;
1113
1571
  clearRelockTimer();
1572
+ clearGestureUpgrade();
1573
+ guards.unlock();
1114
1574
  relockRetries = 0;
1115
1575
  }
1116
1576
 
1577
+ async function relock() {
1578
+ manualUnlocking = false;
1579
+ return request();
1580
+ }
1581
+
1117
1582
  function isActive() {
1118
1583
  return getState().active;
1119
1584
  }
@@ -1136,12 +1601,30 @@
1136
1601
  return emitter.off(event, cb);
1137
1602
  }
1138
1603
 
1604
+ function onExitButtonClick() {
1605
+ if (destroyed) return;
1606
+ exitInternal(false, 'button').catch(() => {});
1607
+ }
1608
+
1609
+ for (const btn of exitButtons) {
1610
+ if (typeof btn.addEventListener === 'function') {
1611
+ btn.addEventListener('click', onExitButtonClick);
1612
+ }
1613
+ }
1614
+
1139
1615
  function destroy() {
1140
1616
  if (destroyed) return;
1141
1617
  destroyed = true;
1142
1618
  clearRelockTimer();
1619
+ clearGestureUpgrade();
1620
+ guards.destroy();
1143
1621
  syncEscapeListener(false);
1144
1622
  unbindNativeListeners();
1623
+ for (const btn of exitButtons) {
1624
+ if (typeof btn.removeEventListener === 'function') {
1625
+ btn.removeEventListener('click', onExitButtonClick);
1626
+ }
1627
+ }
1145
1628
  if (typeof electronUnsub === 'function') {
1146
1629
  electronUnsub();
1147
1630
  electronUnsub = null;
@@ -1159,6 +1642,7 @@
1159
1642
  exit,
1160
1643
  toggle,
1161
1644
  unlock,
1645
+ relock,
1162
1646
  isActive,
1163
1647
  isSupported,
1164
1648
  isFallback,
@@ -1304,6 +1788,7 @@
1304
1788
  async function exit() {
1305
1789
  if (destroyed) throw new Error('[fullscreen-engine/electron] destroyed');
1306
1790
  if (exitLocked) {
1791
+ emitter.emit('exitAttempt', { reason: 'api', state: getState() });
1307
1792
  const err = new Error('[fullscreen-engine/electron] Exit blocked: preventExit is active');
1308
1793
  emitError(err);
1309
1794
  throw err;
@@ -1488,6 +1973,7 @@
1488
1973
  async request() { throw new Error('[fullscreen-engine/ssr] fullscreen unavailable in SSR'); },
1489
1974
  async exit() {},
1490
1975
  async toggle() { return this.request(); },
1976
+ unlock() {},
1491
1977
  isActive() { return false; },
1492
1978
  isSupported() { return false; },
1493
1979
  isFallback() { return false; },
@@ -1595,7 +2081,14 @@
1595
2081
  core: Object.freeze({
1596
2082
  fallback: 'css',
1597
2083
  lockBody: true,
2084
+ freezePage: true,
1598
2085
  autoRelock: Object.freeze({ enabled: true, delay: 50, maxRetries: 5 }),
2086
+ gestureUpgrade: true,
2087
+ keyboardLock: true,
2088
+ blockShortcuts: true,
2089
+ confirmOnLeave: true,
2090
+ blockContextMenu: true,
2091
+ watchFocus: true,
1599
2092
  preventExit: true,
1600
2093
  suppressOnManualExit: true
1601
2094
  }),