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