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