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