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