fullscreen-engine 1.0.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 +109 -49
- package/bin/fullscreen-engine.js +162 -0
- 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 +2282 -0
- package/dist/config.cjs.map +1 -0
- package/dist/config.esm.js +2276 -0
- package/dist/config.esm.js.map +1 -0
- package/dist/fullscreen.esm.js +1013 -18
- 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 +1017 -18
- package/dist/fullscreen.iife.js.map +1 -1
- package/dist/fullscreen.umd.cjs +1017 -18
- 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 +15 -3
- package/src/adapters/electron.js +1 -0
- package/src/adapters/ssr.js +1 -0
- package/src/config-loader.js +114 -0
- package/src/config.js +187 -0
- package/src/core.js +201 -5
- package/src/fallback.js +22 -8
- package/src/guards.js +277 -0
- package/src/index.js +2 -1
- package/src/vendor.js +1 -0
- package/types/config.d.ts +40 -0
- package/types/electron.d.ts +4 -0
- package/types/index.d.ts +94 -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
|
*
|
|
@@ -672,7 +965,7 @@ var FullscreenEngine = (function (exports) {
|
|
|
672
965
|
);
|
|
673
966
|
}
|
|
674
967
|
|
|
675
|
-
function normalizeAutoRelock(val) {
|
|
968
|
+
function normalizeAutoRelock$1(val) {
|
|
676
969
|
if (val === undefined || val === null || val === false) {
|
|
677
970
|
return { enabled: false, delay: 50, maxRetries: 3 };
|
|
678
971
|
}
|
|
@@ -691,9 +984,9 @@ var FullscreenEngine = (function (exports) {
|
|
|
691
984
|
throw new TypeError('[fullscreen-engine] invalid autoRelock option: expected boolean or object');
|
|
692
985
|
}
|
|
693
986
|
|
|
694
|
-
function createFullscreen(userOptions = {}) {
|
|
987
|
+
function createFullscreen$1(userOptions = {}) {
|
|
695
988
|
const triggers = normalizeTriggers(userOptions.trigger);
|
|
696
|
-
const relockConfig = normalizeAutoRelock(userOptions.autoRelock);
|
|
989
|
+
const relockConfig = normalizeAutoRelock$1(userOptions.autoRelock);
|
|
697
990
|
|
|
698
991
|
const fallbackOption = userOptions.fallback ?? 'none';
|
|
699
992
|
if (fallbackOption !== 'css' && fallbackOption !== 'none') {
|
|
@@ -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,
|
|
@@ -1170,12 +1654,527 @@ var FullscreenEngine = (function (exports) {
|
|
|
1170
1654
|
};
|
|
1171
1655
|
}
|
|
1172
1656
|
|
|
1657
|
+
/**
|
|
1658
|
+
* Electron renderer-side adapter.
|
|
1659
|
+
*
|
|
1660
|
+
* Provide this on the renderer via contextBridge (window.fsNative).
|
|
1661
|
+
*/
|
|
1662
|
+
|
|
1663
|
+
|
|
1664
|
+
function normalizeAutoRelock(val) {
|
|
1665
|
+
if (val === undefined || val === null || val === false) {
|
|
1666
|
+
return { enabled: false, delay: 50, maxRetries: 3 };
|
|
1667
|
+
}
|
|
1668
|
+
if (val === true) {
|
|
1669
|
+
return { enabled: true, delay: 50, maxRetries: 3 };
|
|
1670
|
+
}
|
|
1671
|
+
if (typeof val === 'object') {
|
|
1672
|
+
const delayNum = Number(val.delay);
|
|
1673
|
+
const retriesNum = Number(val.maxRetries);
|
|
1674
|
+
return {
|
|
1675
|
+
enabled: val.enabled ?? true,
|
|
1676
|
+
delay: Number.isFinite(delayNum) ? Math.max(0, delayNum) : 50,
|
|
1677
|
+
maxRetries: Number.isFinite(retriesNum) ? Math.max(1, Math.trunc(retriesNum)) : 3
|
|
1678
|
+
};
|
|
1679
|
+
}
|
|
1680
|
+
throw new TypeError('[fullscreen-engine/electron] invalid autoRelock option: expected boolean or object');
|
|
1681
|
+
}
|
|
1682
|
+
|
|
1683
|
+
function createElectronFullscreen(bridge, opts = {}) {
|
|
1684
|
+
if (!bridge || typeof bridge.set !== 'function') {
|
|
1685
|
+
throw new Error('[fullscreen-engine/electron] bridge with .set() required');
|
|
1686
|
+
}
|
|
1687
|
+
|
|
1688
|
+
const relockConfig = normalizeAutoRelock(opts.autoRelock);
|
|
1689
|
+
const onError = typeof opts.onError === 'function' ? opts.onError : null;
|
|
1690
|
+
const emitter = new Emitter();
|
|
1691
|
+
let active = false;
|
|
1692
|
+
let destroyed = false;
|
|
1693
|
+
let unsubscribe = null;
|
|
1694
|
+
let exitLocked = !!opts.preventExit;
|
|
1695
|
+
let manualUnlocking = false;
|
|
1696
|
+
let relockTimer = null;
|
|
1697
|
+
let relockRetries = 0;
|
|
1698
|
+
|
|
1699
|
+
function emitError(err) {
|
|
1700
|
+
emitter.emit('error', err);
|
|
1701
|
+
if (onError) onError(err);
|
|
1702
|
+
}
|
|
1703
|
+
|
|
1704
|
+
function clearRelockTimer() {
|
|
1705
|
+
if (relockTimer !== null) {
|
|
1706
|
+
clearTimeout(relockTimer);
|
|
1707
|
+
relockTimer = null;
|
|
1708
|
+
}
|
|
1709
|
+
}
|
|
1710
|
+
|
|
1711
|
+
function getState() {
|
|
1712
|
+
return {
|
|
1713
|
+
active,
|
|
1714
|
+
source: active ? 'electron' : 'none',
|
|
1715
|
+
element: null,
|
|
1716
|
+
supported: true
|
|
1717
|
+
};
|
|
1718
|
+
}
|
|
1719
|
+
|
|
1720
|
+
function scheduleRelock() {
|
|
1721
|
+
if (destroyed || !relockConfig.enabled || manualUnlocking) return;
|
|
1722
|
+
if (relockRetries >= relockConfig.maxRetries) {
|
|
1723
|
+
emitError(new Error('[fullscreen-engine/electron] autoRelock failed after maxRetries'));
|
|
1724
|
+
return;
|
|
1725
|
+
}
|
|
1726
|
+
clearRelockTimer();
|
|
1727
|
+
relockTimer = setTimeout(() => {
|
|
1728
|
+
relockTimer = null;
|
|
1729
|
+
if (destroyed || !relockConfig.enabled || manualUnlocking || active) return;
|
|
1730
|
+
relockRetries += 1;
|
|
1731
|
+
request()
|
|
1732
|
+
.catch((err) => {
|
|
1733
|
+
emitError(err);
|
|
1734
|
+
if (!destroyed && relockConfig.enabled && !manualUnlocking && !active) {
|
|
1735
|
+
scheduleRelock();
|
|
1736
|
+
}
|
|
1737
|
+
});
|
|
1738
|
+
}, relockConfig.delay);
|
|
1739
|
+
}
|
|
1740
|
+
|
|
1741
|
+
function updateActive(next) {
|
|
1742
|
+
const boolNext = !!next;
|
|
1743
|
+
if (boolNext) {
|
|
1744
|
+
relockRetries = 0;
|
|
1745
|
+
clearRelockTimer();
|
|
1746
|
+
}
|
|
1747
|
+
if (boolNext === active) return;
|
|
1748
|
+
const wasActive = active;
|
|
1749
|
+
active = boolNext;
|
|
1750
|
+
const state = getState();
|
|
1751
|
+
emitter.emit('change', state);
|
|
1752
|
+
if (active) emitter.emit('enter', state);
|
|
1753
|
+
else {
|
|
1754
|
+
emitter.emit('exit', state);
|
|
1755
|
+
if (wasActive && relockConfig.enabled && !manualUnlocking) {
|
|
1756
|
+
scheduleRelock();
|
|
1757
|
+
}
|
|
1758
|
+
}
|
|
1759
|
+
}
|
|
1760
|
+
|
|
1761
|
+
if (typeof bridge.onChange === 'function') {
|
|
1762
|
+
unsubscribe = bridge.onChange((on) => {
|
|
1763
|
+
if (!destroyed) updateActive(on);
|
|
1764
|
+
});
|
|
1765
|
+
}
|
|
1766
|
+
|
|
1767
|
+
if (typeof bridge.get === 'function') {
|
|
1768
|
+
Promise.resolve(bridge.get())
|
|
1769
|
+
.then((on) => {
|
|
1770
|
+
if (!destroyed) updateActive(on);
|
|
1771
|
+
})
|
|
1772
|
+
.catch(() => {});
|
|
1773
|
+
}
|
|
1774
|
+
|
|
1775
|
+
async function request() {
|
|
1776
|
+
if (destroyed) throw new Error('[fullscreen-engine/electron] destroyed');
|
|
1777
|
+
manualUnlocking = false;
|
|
1778
|
+
const res = await bridge.set(true);
|
|
1779
|
+
if (res === false) {
|
|
1780
|
+
throw new Error('[fullscreen-engine/electron] bridge.set(true) returned false');
|
|
1781
|
+
}
|
|
1782
|
+
updateActive(true);
|
|
1783
|
+
}
|
|
1784
|
+
|
|
1785
|
+
async function exit() {
|
|
1786
|
+
if (destroyed) throw new Error('[fullscreen-engine/electron] destroyed');
|
|
1787
|
+
if (exitLocked) {
|
|
1788
|
+
emitter.emit('exitAttempt', { reason: 'api', state: getState() });
|
|
1789
|
+
const err = new Error('[fullscreen-engine/electron] Exit blocked: preventExit is active');
|
|
1790
|
+
emitError(err);
|
|
1791
|
+
throw err;
|
|
1792
|
+
}
|
|
1793
|
+
const res = await bridge.set(false);
|
|
1794
|
+
if (res === true) {
|
|
1795
|
+
throw new Error('[fullscreen-engine/electron] bridge.set(false) failed to exit');
|
|
1796
|
+
}
|
|
1797
|
+
updateActive(false);
|
|
1798
|
+
}
|
|
1799
|
+
|
|
1800
|
+
function unlock() {
|
|
1801
|
+
exitLocked = false;
|
|
1802
|
+
manualUnlocking = true;
|
|
1803
|
+
clearRelockTimer();
|
|
1804
|
+
relockRetries = 0;
|
|
1805
|
+
}
|
|
1806
|
+
|
|
1807
|
+
async function relock() {
|
|
1808
|
+
manualUnlocking = false;
|
|
1809
|
+
return request();
|
|
1810
|
+
}
|
|
1811
|
+
|
|
1812
|
+
return {
|
|
1813
|
+
request,
|
|
1814
|
+
exit,
|
|
1815
|
+
async toggle() {
|
|
1816
|
+
return active ? exit() : request();
|
|
1817
|
+
},
|
|
1818
|
+
unlock,
|
|
1819
|
+
relock,
|
|
1820
|
+
isActive() { return active; },
|
|
1821
|
+
isSupported() { return true; },
|
|
1822
|
+
getState,
|
|
1823
|
+
on(event, cb) { return emitter.on(event, cb); },
|
|
1824
|
+
once(event, cb) { return emitter.once(event, cb); },
|
|
1825
|
+
off(event, cb) { return emitter.off(event, cb); },
|
|
1826
|
+
destroy() {
|
|
1827
|
+
if (destroyed) return;
|
|
1828
|
+
destroyed = true;
|
|
1829
|
+
clearRelockTimer();
|
|
1830
|
+
if (typeof unsubscribe === 'function') unsubscribe();
|
|
1831
|
+
unsubscribe = null;
|
|
1832
|
+
active = false;
|
|
1833
|
+
emitter.clear();
|
|
1834
|
+
}
|
|
1835
|
+
};
|
|
1836
|
+
}
|
|
1837
|
+
|
|
1838
|
+
/**
|
|
1839
|
+
* True backend fullscreen control from Node.js.
|
|
1840
|
+
*
|
|
1841
|
+
* Uses Chrome DevTools Protocol (CDP) via Puppeteer to control the
|
|
1842
|
+
* browser window's fullscreen state. This works from a Node.js process.
|
|
1843
|
+
*/
|
|
1844
|
+
|
|
1845
|
+
function createPuppeteerFullscreen(page, opts = {}) {
|
|
1846
|
+
if (!page || typeof page.createCDPSession !== 'function') {
|
|
1847
|
+
throw new Error('[fullscreen-engine/puppeteer] page with .createCDPSession() required');
|
|
1848
|
+
}
|
|
1849
|
+
|
|
1850
|
+
let client = null;
|
|
1851
|
+
let windowId = null;
|
|
1852
|
+
let initPromise = null;
|
|
1853
|
+
let active = false;
|
|
1854
|
+
let destroyed = false;
|
|
1855
|
+
let exitLocked = !!opts.preventExit;
|
|
1856
|
+
|
|
1857
|
+
async function ensure() {
|
|
1858
|
+
if (destroyed) throw new Error('[fullscreen-engine/puppeteer] destroyed');
|
|
1859
|
+
if (client && windowId !== null) return;
|
|
1860
|
+
if (!initPromise) {
|
|
1861
|
+
initPromise = (async () => {
|
|
1862
|
+
let session = null;
|
|
1863
|
+
try {
|
|
1864
|
+
session = await page.createCDPSession();
|
|
1865
|
+
const res = await session.send('Browser.getWindowForTarget');
|
|
1866
|
+
if (destroyed) {
|
|
1867
|
+
try { await session.detach(); } catch {}
|
|
1868
|
+
throw new Error('[fullscreen-engine/puppeteer] destroyed');
|
|
1869
|
+
}
|
|
1870
|
+
client = session;
|
|
1871
|
+
windowId = res.windowId;
|
|
1872
|
+
} catch (err) {
|
|
1873
|
+
if (session) {
|
|
1874
|
+
try { await session.detach(); } catch {}
|
|
1875
|
+
}
|
|
1876
|
+
client = null;
|
|
1877
|
+
windowId = null;
|
|
1878
|
+
throw err;
|
|
1879
|
+
} finally {
|
|
1880
|
+
initPromise = null;
|
|
1881
|
+
}
|
|
1882
|
+
})();
|
|
1883
|
+
}
|
|
1884
|
+
return initPromise;
|
|
1885
|
+
}
|
|
1886
|
+
|
|
1887
|
+
async function setState(state) {
|
|
1888
|
+
if (destroyed) throw new Error('[fullscreen-engine/puppeteer] destroyed');
|
|
1889
|
+
await ensure();
|
|
1890
|
+
await client.send('Browser.setWindowBounds', {
|
|
1891
|
+
windowId,
|
|
1892
|
+
bounds: { windowState: state } // 'fullscreen' | 'normal' | 'minimized' | 'maximized'
|
|
1893
|
+
});
|
|
1894
|
+
active = state === 'fullscreen';
|
|
1895
|
+
return active;
|
|
1896
|
+
}
|
|
1897
|
+
|
|
1898
|
+
return {
|
|
1899
|
+
async request() {
|
|
1900
|
+
if (destroyed) throw new Error('[fullscreen-engine/puppeteer] destroyed');
|
|
1901
|
+
if (active) return true;
|
|
1902
|
+
return setState('fullscreen');
|
|
1903
|
+
},
|
|
1904
|
+
async exit() {
|
|
1905
|
+
if (destroyed) throw new Error('[fullscreen-engine/puppeteer] destroyed');
|
|
1906
|
+
if (exitLocked) {
|
|
1907
|
+
throw new Error('[fullscreen-engine/puppeteer] Exit blocked: preventExit is active');
|
|
1908
|
+
}
|
|
1909
|
+
if (!active) {
|
|
1910
|
+
const current = await this.getWindowState();
|
|
1911
|
+
if (current !== 'fullscreen') return false;
|
|
1912
|
+
}
|
|
1913
|
+
return setState(opts.restoreState || 'normal');
|
|
1914
|
+
},
|
|
1915
|
+
async toggle() {
|
|
1916
|
+
if (destroyed) throw new Error('[fullscreen-engine/puppeteer] destroyed');
|
|
1917
|
+
const current = await this.getWindowState();
|
|
1918
|
+
return current === 'fullscreen' ? this.exit() : this.request();
|
|
1919
|
+
},
|
|
1920
|
+
unlock() {
|
|
1921
|
+
exitLocked = false;
|
|
1922
|
+
},
|
|
1923
|
+
async relock() {
|
|
1924
|
+
if (destroyed) throw new Error('[fullscreen-engine/puppeteer] destroyed');
|
|
1925
|
+
const current = await this.getWindowState();
|
|
1926
|
+
if (current === 'fullscreen') return true;
|
|
1927
|
+
return setState('fullscreen');
|
|
1928
|
+
},
|
|
1929
|
+
isActive() {
|
|
1930
|
+
return active;
|
|
1931
|
+
},
|
|
1932
|
+
isSupported() {
|
|
1933
|
+
return true;
|
|
1934
|
+
},
|
|
1935
|
+
async getWindowState() {
|
|
1936
|
+
if (destroyed) throw new Error('[fullscreen-engine/puppeteer] destroyed');
|
|
1937
|
+
await ensure();
|
|
1938
|
+
const res = await client.send('Browser.getWindowBounds', { windowId });
|
|
1939
|
+
const state = res.bounds.windowState;
|
|
1940
|
+
active = state === 'fullscreen';
|
|
1941
|
+
return state;
|
|
1942
|
+
},
|
|
1943
|
+
async destroy() {
|
|
1944
|
+
if (destroyed) return;
|
|
1945
|
+
destroyed = true;
|
|
1946
|
+
if (initPromise) {
|
|
1947
|
+
try { await initPromise; } catch {}
|
|
1948
|
+
}
|
|
1949
|
+
try { if (client) await client.detach(); } catch {}
|
|
1950
|
+
client = null;
|
|
1951
|
+
windowId = null;
|
|
1952
|
+
initPromise = null;
|
|
1953
|
+
active = false;
|
|
1954
|
+
}
|
|
1955
|
+
};
|
|
1956
|
+
}
|
|
1957
|
+
|
|
1958
|
+
/**
|
|
1959
|
+
* SSR / Node.js safe stub.
|
|
1960
|
+
*
|
|
1961
|
+
* Importing the main entry already works in Node (all guards are in place).
|
|
1962
|
+
* But if you explicitly need a no-op controller (e.g. for template
|
|
1963
|
+
* environments that can't tree-shake), use this:
|
|
1964
|
+
*
|
|
1965
|
+
* import { createFullscreen } from 'fullscreen-engine/adapters/ssr';
|
|
1966
|
+
*/
|
|
1967
|
+
|
|
1968
|
+
function createFullscreen() {
|
|
1969
|
+
return {
|
|
1970
|
+
async request() { throw new Error('[fullscreen-engine/ssr] fullscreen unavailable in SSR'); },
|
|
1971
|
+
async exit() {},
|
|
1972
|
+
async toggle() { return this.request(); },
|
|
1973
|
+
unlock() {},
|
|
1974
|
+
isActive() { return false; },
|
|
1975
|
+
isSupported() { return false; },
|
|
1976
|
+
isFallback() { return false; },
|
|
1977
|
+
getState() { return { active: false, source: 'none', element: null, supported: false }; },
|
|
1978
|
+
on() { return () => {}; },
|
|
1979
|
+
once() { return () => {}; },
|
|
1980
|
+
off() {},
|
|
1981
|
+
destroy() {}
|
|
1982
|
+
};
|
|
1983
|
+
}
|
|
1984
|
+
|
|
1985
|
+
/**
|
|
1986
|
+
* Global configuration engine for fullscreen-engine.
|
|
1987
|
+
*
|
|
1988
|
+
* Pure isomorphic module (no Node.js built-in imports) safe for Browser,
|
|
1989
|
+
* Electron renderer, Puppeteer/Node, and SSR environments.
|
|
1990
|
+
*/
|
|
1991
|
+
|
|
1992
|
+
|
|
1993
|
+
function isPlainObject(val) {
|
|
1994
|
+
return typeof val === 'object' && val !== null && !Array.isArray(val);
|
|
1995
|
+
}
|
|
1996
|
+
|
|
1997
|
+
function mergeAutoRelock(baseVal, nextVal) {
|
|
1998
|
+
if (nextVal === undefined) return baseVal;
|
|
1999
|
+
if (isPlainObject(baseVal) && isPlainObject(nextVal)) {
|
|
2000
|
+
return { ...baseVal, ...nextVal };
|
|
2001
|
+
}
|
|
2002
|
+
return nextVal;
|
|
2003
|
+
}
|
|
2004
|
+
|
|
2005
|
+
function mergeSection(base, ext) {
|
|
2006
|
+
if (!ext) return { ...base };
|
|
2007
|
+
const merged = { ...base, ...ext };
|
|
2008
|
+
if ('autoRelock' in base || 'autoRelock' in ext) {
|
|
2009
|
+
merged.autoRelock = mergeAutoRelock(base.autoRelock, ext.autoRelock);
|
|
2010
|
+
}
|
|
2011
|
+
return merged;
|
|
2012
|
+
}
|
|
2013
|
+
|
|
2014
|
+
function validateConfigShape(cfg, label = 'config') {
|
|
2015
|
+
if (!isPlainObject(cfg)) {
|
|
2016
|
+
throw new TypeError(`[fullscreen-engine/config] ${label} must be a plain object`);
|
|
2017
|
+
}
|
|
2018
|
+
if (cfg.mode !== undefined && (typeof cfg.mode !== 'string' || !(cfg.mode in PRESETS))) {
|
|
2019
|
+
throw new TypeError(`[fullscreen-engine/config] unknown mode/preset: ${String(cfg.mode)}`);
|
|
2020
|
+
}
|
|
2021
|
+
if (cfg.core !== undefined && !isPlainObject(cfg.core)) {
|
|
2022
|
+
throw new TypeError(`[fullscreen-engine/config] ${label}.core must be a plain object`);
|
|
2023
|
+
}
|
|
2024
|
+
if (cfg.adapters !== undefined) {
|
|
2025
|
+
if (!isPlainObject(cfg.adapters)) {
|
|
2026
|
+
throw new TypeError(`[fullscreen-engine/config] ${label}.adapters must be a plain object`);
|
|
2027
|
+
}
|
|
2028
|
+
for (const key of ['electron', 'puppeteer', 'ssr']) {
|
|
2029
|
+
if (cfg.adapters[key] !== undefined && !isPlainObject(cfg.adapters[key])) {
|
|
2030
|
+
throw new TypeError(
|
|
2031
|
+
`[fullscreen-engine/config] adapter "${key}" options must be a plain object`
|
|
2032
|
+
);
|
|
2033
|
+
}
|
|
2034
|
+
}
|
|
2035
|
+
}
|
|
2036
|
+
}
|
|
2037
|
+
|
|
2038
|
+
const PRESETS = Object.freeze({
|
|
2039
|
+
default: Object.freeze({
|
|
2040
|
+
core: Object.freeze({}),
|
|
2041
|
+
adapters: Object.freeze({
|
|
2042
|
+
electron: Object.freeze({}),
|
|
2043
|
+
puppeteer: Object.freeze({}),
|
|
2044
|
+
ssr: Object.freeze({ enabled: true })
|
|
2045
|
+
})
|
|
2046
|
+
}),
|
|
2047
|
+
kiosk: Object.freeze({
|
|
2048
|
+
core: Object.freeze({
|
|
2049
|
+
fallback: 'css',
|
|
2050
|
+
lockBody: true,
|
|
2051
|
+
autoRelock: true,
|
|
2052
|
+
preventExit: true,
|
|
2053
|
+
suppressOnManualExit: true
|
|
2054
|
+
}),
|
|
2055
|
+
adapters: Object.freeze({
|
|
2056
|
+
electron: Object.freeze({ autoRelock: true, preventExit: true }),
|
|
2057
|
+
puppeteer: Object.freeze({ preventExit: true }),
|
|
2058
|
+
ssr: Object.freeze({ enabled: true })
|
|
2059
|
+
})
|
|
2060
|
+
}),
|
|
2061
|
+
presentation: Object.freeze({
|
|
2062
|
+
core: Object.freeze({
|
|
2063
|
+
fallback: 'css',
|
|
2064
|
+
lockBody: true,
|
|
2065
|
+
trigger: 'manual',
|
|
2066
|
+
autoExit: false,
|
|
2067
|
+
suppressOnManualExit: true,
|
|
2068
|
+
autoRelock: false,
|
|
2069
|
+
preventExit: false
|
|
2070
|
+
}),
|
|
2071
|
+
adapters: Object.freeze({
|
|
2072
|
+
electron: Object.freeze({ autoRelock: false, preventExit: false }),
|
|
2073
|
+
puppeteer: Object.freeze({ restoreState: 'normal', preventExit: false }),
|
|
2074
|
+
ssr: Object.freeze({ enabled: true })
|
|
2075
|
+
})
|
|
2076
|
+
}),
|
|
2077
|
+
strict: Object.freeze({
|
|
2078
|
+
core: Object.freeze({
|
|
2079
|
+
fallback: 'css',
|
|
2080
|
+
lockBody: true,
|
|
2081
|
+
freezePage: true,
|
|
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,
|
|
2089
|
+
preventExit: true,
|
|
2090
|
+
suppressOnManualExit: true
|
|
2091
|
+
}),
|
|
2092
|
+
adapters: Object.freeze({
|
|
2093
|
+
electron: Object.freeze({
|
|
2094
|
+
autoRelock: Object.freeze({ enabled: true, delay: 50, maxRetries: 5 }),
|
|
2095
|
+
preventExit: true
|
|
2096
|
+
}),
|
|
2097
|
+
puppeteer: Object.freeze({ preventExit: true }),
|
|
2098
|
+
ssr: Object.freeze({ enabled: false })
|
|
2099
|
+
})
|
|
2100
|
+
})
|
|
2101
|
+
});
|
|
2102
|
+
|
|
2103
|
+
function defineConfig(config = {}) {
|
|
2104
|
+
validateConfigShape(config, 'config');
|
|
2105
|
+
return config;
|
|
2106
|
+
}
|
|
2107
|
+
|
|
2108
|
+
function resolveConfig(config = {}, overrides = {}) {
|
|
2109
|
+
validateConfigShape(config, 'config');
|
|
2110
|
+
validateConfigShape(overrides, 'overrides');
|
|
2111
|
+
|
|
2112
|
+
const mode = overrides.mode ?? config.mode ?? 'default';
|
|
2113
|
+
const preset = PRESETS[mode];
|
|
2114
|
+
|
|
2115
|
+
const cfgAdapters = config.adapters || {};
|
|
2116
|
+
const ovAdapters = overrides.adapters || {};
|
|
2117
|
+
|
|
2118
|
+
return {
|
|
2119
|
+
mode,
|
|
2120
|
+
core: mergeSection(mergeSection(preset.core, config.core), overrides.core),
|
|
2121
|
+
adapters: {
|
|
2122
|
+
electron: mergeSection(
|
|
2123
|
+
mergeSection(preset.adapters.electron, cfgAdapters.electron),
|
|
2124
|
+
ovAdapters.electron
|
|
2125
|
+
),
|
|
2126
|
+
puppeteer: mergeSection(
|
|
2127
|
+
mergeSection(preset.adapters.puppeteer, cfgAdapters.puppeteer),
|
|
2128
|
+
ovAdapters.puppeteer
|
|
2129
|
+
),
|
|
2130
|
+
ssr: mergeSection(
|
|
2131
|
+
mergeSection(preset.adapters.ssr, cfgAdapters.ssr),
|
|
2132
|
+
ovAdapters.ssr
|
|
2133
|
+
)
|
|
2134
|
+
}
|
|
2135
|
+
};
|
|
2136
|
+
}
|
|
2137
|
+
|
|
2138
|
+
function initFullscreen(config = {}, context = {}) {
|
|
2139
|
+
if (!isPlainObject(context)) {
|
|
2140
|
+
throw new TypeError('[fullscreen-engine/config] context must be a plain object');
|
|
2141
|
+
}
|
|
2142
|
+
|
|
2143
|
+
const resolved = resolveConfig(config, context.overrides || {});
|
|
2144
|
+
if (context.target !== undefined) {
|
|
2145
|
+
resolved.core.target = context.target;
|
|
2146
|
+
}
|
|
2147
|
+
|
|
2148
|
+
if (context.bridge !== undefined || context.adapter === 'electron') {
|
|
2149
|
+
const bridge =
|
|
2150
|
+
context.bridge ?? (typeof window !== 'undefined' ? window.fsNative : null);
|
|
2151
|
+
return createElectronFullscreen(bridge, resolved.adapters.electron);
|
|
2152
|
+
}
|
|
2153
|
+
|
|
2154
|
+
if (context.page !== undefined || context.adapter === 'puppeteer') {
|
|
2155
|
+
return createPuppeteerFullscreen(context.page, resolved.adapters.puppeteer);
|
|
2156
|
+
}
|
|
2157
|
+
|
|
2158
|
+
if (context.adapter === 'ssr' || (isNode() && !isBrowser() && !isElectron())) {
|
|
2159
|
+
if (resolved.adapters.ssr.enabled === false) {
|
|
2160
|
+
throw new Error('[fullscreen-engine/config] SSR adapter is disabled by config');
|
|
2161
|
+
}
|
|
2162
|
+
return createFullscreen();
|
|
2163
|
+
}
|
|
2164
|
+
|
|
2165
|
+
return createFullscreen$1(resolved.core);
|
|
2166
|
+
}
|
|
2167
|
+
|
|
1173
2168
|
exports.Emitter = Emitter;
|
|
1174
|
-
exports.
|
|
2169
|
+
exports.PRESETS = PRESETS;
|
|
2170
|
+
exports.createFullscreen = createFullscreen$1;
|
|
2171
|
+
exports.defineConfig = defineConfig;
|
|
1175
2172
|
exports.detectEnvironment = detectEnvironment;
|
|
2173
|
+
exports.initFullscreen = initFullscreen;
|
|
1176
2174
|
exports.isBrowser = isBrowser;
|
|
1177
2175
|
exports.isElectron = isElectron;
|
|
1178
2176
|
exports.isNode = isNode;
|
|
2177
|
+
exports.resolveConfig = resolveConfig;
|
|
1179
2178
|
|
|
1180
2179
|
return exports;
|
|
1181
2180
|
|