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