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.
Files changed (40) hide show
  1. package/README.md +109 -49
  2. package/bin/fullscreen-engine.js +162 -0
  3. package/dist/adapters/electron.cjs +2 -1
  4. package/dist/adapters/electron.cjs.map +1 -1
  5. package/dist/adapters/electron.esm.js +2 -1
  6. package/dist/adapters/electron.esm.js.map +1 -1
  7. package/dist/adapters/puppeteer.cjs +1 -1
  8. package/dist/adapters/puppeteer.esm.js +1 -1
  9. package/dist/adapters/ssr.cjs +2 -1
  10. package/dist/adapters/ssr.cjs.map +1 -1
  11. package/dist/adapters/ssr.esm.js +2 -1
  12. package/dist/adapters/ssr.esm.js.map +1 -1
  13. package/dist/config.cjs +2282 -0
  14. package/dist/config.cjs.map +1 -0
  15. package/dist/config.esm.js +2276 -0
  16. package/dist/config.esm.js.map +1 -0
  17. package/dist/fullscreen.esm.js +1013 -18
  18. package/dist/fullscreen.esm.js.map +1 -1
  19. package/dist/fullscreen.esm.min.js +2 -2
  20. package/dist/fullscreen.esm.min.js.map +1 -1
  21. package/dist/fullscreen.iife.js +1017 -18
  22. package/dist/fullscreen.iife.js.map +1 -1
  23. package/dist/fullscreen.umd.cjs +1017 -18
  24. package/dist/fullscreen.umd.cjs.map +1 -1
  25. package/dist/fullscreen.umd.min.cjs +2 -2
  26. package/dist/fullscreen.umd.min.cjs.map +1 -1
  27. package/package.json +15 -3
  28. package/src/adapters/electron.js +1 -0
  29. package/src/adapters/ssr.js +1 -0
  30. package/src/config-loader.js +114 -0
  31. package/src/config.js +187 -0
  32. package/src/core.js +201 -5
  33. package/src/fallback.js +22 -8
  34. package/src/guards.js +277 -0
  35. package/src/index.js +2 -1
  36. package/src/vendor.js +1 -0
  37. package/types/config.d.ts +40 -0
  38. package/types/electron.d.ts +4 -0
  39. package/types/index.d.ts +94 -1
  40. package/types/ssr.d.ts +1 -0
@@ -1,4 +1,4 @@
1
- /*! fullscreen-engine v1.0.0 | MIT */
1
+ /*! fullscreen-engine v1.2.0 | MIT */
2
2
  (function (global, factory) {
3
3
  typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
4
4
  typeof define === 'function' && define.amd ? define(['exports'], factory) :
@@ -228,6 +228,7 @@
228
228
  exit,
229
229
  elementProp,
230
230
  enabledProp,
231
+ prefix: vendorPrefix,
231
232
  changeEvent,
232
233
  errorEvent,
233
234
  supported: !!(request && exit && elementProp && policyAllowed)
@@ -259,11 +260,22 @@
259
260
  return Number.isFinite(num) ? Math.trunc(num) : 2147483647;
260
261
  }
261
262
 
262
- function getStyleId(baseClass, lockClass, zIndex) {
263
- return `__fullscreen_engine_style_${baseClass}_${lockClass}_${zIndex}__`;
263
+ function getStyleId(baseClass, lockClass, zIndex, freezePage = false) {
264
+ return `__fullscreen_engine_style_${baseClass}_${lockClass}_${zIndex}${freezePage ? '_freeze' : ''}__`;
264
265
  }
265
266
 
266
- function buildCSS(baseClass, lockClass, zIndex) {
267
+ function buildCSS(baseClass, lockClass, zIndex, freezePage = false) {
268
+ const freezeTargetCSS = freezePage
269
+ ? `
270
+ overscroll-behavior: none !important;
271
+ touch-action: manipulation !important;
272
+ user-select: none !important;
273
+ -webkit-user-select: none !important;`
274
+ : '';
275
+ const freezeLockCSS = freezePage
276
+ ? `
277
+ overscroll-behavior: none !important;`
278
+ : '';
267
279
  return `
268
280
  .${baseClass} {
269
281
  position: fixed !important;
@@ -273,25 +285,27 @@
273
285
  bottom: 0 !important;
274
286
  width: 100vw !important;
275
287
  height: 100vh !important;
288
+ height: 100dvh !important;
276
289
  margin: 0 !important;
277
290
  padding: 0 !important;
278
291
  border: 0 !important;
279
292
  z-index: ${zIndex} !important;
280
293
  background: #000 !important;
281
- overflow: auto !important;
294
+ overflow: auto !important;${freezeTargetCSS}
282
295
  }
283
296
  html.${lockClass}, body.${lockClass} {
284
297
  overflow: hidden !important;
298
+ scrollbar-width: none !important;${freezeLockCSS}
285
299
  }
286
300
  `;
287
301
  }
288
302
 
289
- function ensureStyle(styleId, baseClass, lockClass, zIndex) {
303
+ function ensureStyle(styleId, baseClass, lockClass, zIndex, freezePage = false) {
290
304
  if (typeof document === 'undefined') return;
291
305
  if (document.getElementById(styleId)) return;
292
306
  const style = document.createElement('style');
293
307
  style.id = styleId;
294
- style.textContent = buildCSS(baseClass, lockClass, zIndex);
308
+ style.textContent = buildCSS(baseClass, lockClass, zIndex, freezePage);
295
309
  (document.head || document.documentElement).appendChild(style);
296
310
  }
297
311
 
@@ -305,7 +319,8 @@
305
319
  const baseClass = sanitizeClassName(opts.fallbackClass, 'fs-engine-active');
306
320
  const lockClass = opts.lockBody === false ? '__no_lock__' : 'fs-engine-scroll-lock';
307
321
  const zIndex = sanitizeZIndex(opts.zIndex);
308
- const styleId = getStyleId(baseClass, lockClass, zIndex);
322
+ const freezePage = !!opts.freezePage;
323
+ const styleId = getStyleId(baseClass, lockClass, zIndex, freezePage);
309
324
  let active = false;
310
325
  let activeTarget = null;
311
326
  let styleRegistered = false;
@@ -317,7 +332,7 @@
317
332
  styleRefCounts.set(styleId, (styleRefCounts.get(styleId) ?? 0) + 1);
318
333
  styleRegistered = true;
319
334
  }
320
- ensureStyle(styleId, baseClass, lockClass, zIndex);
335
+ ensureStyle(styleId, baseClass, lockClass, zIndex, freezePage);
321
336
  activeTarget = target;
322
337
  target.classList.add(baseClass);
323
338
  if (opts.lockBody !== false && !lockApplied) {
@@ -653,6 +668,284 @@
653
668
  };
654
669
  }
655
670
 
671
+ /**
672
+ * Cross-browser kiosk & exit-key guards (browser-safe, zero Node built-ins).
673
+ *
674
+ * Supports:
675
+ * - keyboardLock: navigator.keyboard?.lock(keys) on native fullscreen
676
+ * - blockShortcuts: keydown guard for F11, Escape (when exitLocked), or custom keys
677
+ * - confirmOnLeave: beforeunload prompt while exitLocked && active
678
+ * - blockContextMenu: contextmenu prevention while active
679
+ */
680
+
681
+ function normalizeKeyboardLock(val) {
682
+ if (val === undefined || val === null || val === false) {
683
+ return { enabled: false, keys: ['Escape', 'F11'] };
684
+ }
685
+ if (val === true) {
686
+ return { enabled: true, keys: ['Escape', 'F11'] };
687
+ }
688
+ if (Array.isArray(val)) {
689
+ const keys = val.map((k) => String(k)).filter(Boolean);
690
+ return { enabled: keys.length > 0, keys };
691
+ }
692
+ throw new TypeError(
693
+ '[fullscreen-engine] invalid keyboardLock option: expected boolean or string[]'
694
+ );
695
+ }
696
+
697
+ const DEFAULT_SHORTCUTS = [
698
+ 'F11',
699
+ 'Escape',
700
+ 'F5',
701
+ 'F12',
702
+ 'Ctrl+R',
703
+ 'Meta+R',
704
+ 'Ctrl+Shift+I',
705
+ 'Meta+Alt+I'
706
+ ];
707
+
708
+ function parseShortcut(raw) {
709
+ const parts = String(raw)
710
+ .split('+')
711
+ .map((p) => p.trim())
712
+ .filter(Boolean);
713
+ if (parts.length === 0) return null;
714
+ const key = parts[parts.length - 1].toLowerCase();
715
+ const mods = parts.slice(0, -1).map((m) => m.toLowerCase());
716
+ const hasModifiers = mods.length > 0;
717
+ return {
718
+ key,
719
+ hasModifiers,
720
+ ctrl: mods.includes('ctrl') || mods.includes('control'),
721
+ meta: mods.includes('meta') || mods.includes('cmd') || mods.includes('command'),
722
+ alt: mods.includes('alt') || mods.includes('option'),
723
+ shift: mods.includes('shift')
724
+ };
725
+ }
726
+
727
+ function matchesShortcut(e, rule) {
728
+ if (!rule || !e || !e.key) return false;
729
+ if (String(e.key).toLowerCase() !== rule.key) return false;
730
+ if (!rule.hasModifiers) return true;
731
+ return (
732
+ !!e.ctrlKey === rule.ctrl &&
733
+ !!e.metaKey === rule.meta &&
734
+ !!e.altKey === rule.alt &&
735
+ !!e.shiftKey === rule.shift
736
+ );
737
+ }
738
+
739
+ function normalizeBlockShortcuts(val) {
740
+ if (val === undefined || val === null || val === false) {
741
+ return { enabled: false, keys: ['F11'], rules: [parseShortcut('F11')] };
742
+ }
743
+ if (val === true) {
744
+ return {
745
+ enabled: true,
746
+ keys: DEFAULT_SHORTCUTS.slice(),
747
+ rules: DEFAULT_SHORTCUTS.map(parseShortcut).filter(Boolean)
748
+ };
749
+ }
750
+ if (Array.isArray(val)) {
751
+ const keys = val.map((k) => String(k).trim()).filter(Boolean);
752
+ const rules = keys.map(parseShortcut).filter(Boolean);
753
+ return { enabled: rules.length > 0, keys, rules };
754
+ }
755
+ throw new TypeError(
756
+ '[fullscreen-engine] invalid blockShortcuts option: expected boolean or string[]'
757
+ );
758
+ }
759
+
760
+ function createGuards({
761
+ keyboardLock,
762
+ blockShortcuts,
763
+ confirmOnLeave,
764
+ blockContextMenu,
765
+ watchFocus = false,
766
+ isExitLocked,
767
+ onExitAttempt,
768
+ onEscapeExit,
769
+ onFocusLost
770
+ }) {
771
+ let keyboardLocked = false;
772
+ let keydownBound = false;
773
+ let beforeUnloadBound = false;
774
+ let contextMenuBound = false;
775
+ let focusBound = false;
776
+
777
+ function releaseKeyboardLock() {
778
+ if (!keyboardLocked) return;
779
+ keyboardLocked = false;
780
+ if (
781
+ typeof navigator !== 'undefined' &&
782
+ navigator.keyboard &&
783
+ typeof navigator.keyboard.unlock === 'function'
784
+ ) {
785
+ try {
786
+ navigator.keyboard.unlock();
787
+ } catch {
788
+ // ignore unsupported unlock errors
789
+ }
790
+ }
791
+ }
792
+
793
+ function onKeyDown(e) {
794
+ if (!e || !e.key) return;
795
+ const rules = blockShortcuts.rules || blockShortcuts.keys.map(parseShortcut).filter(Boolean);
796
+ const matched = rules.some((rule) => matchesShortcut(e, rule));
797
+ if (!matched) return;
798
+ if (e.key === 'Escape' && !isExitLocked()) {
799
+ if (typeof onEscapeExit === 'function') onEscapeExit();
800
+ return;
801
+ }
802
+ if (typeof e.preventDefault === 'function') e.preventDefault();
803
+ if (typeof e.stopPropagation === 'function') e.stopPropagation();
804
+ if (typeof onExitAttempt === 'function') {
805
+ onExitAttempt(e.key === 'Escape' ? 'escape' : 'shortcut');
806
+ }
807
+ }
808
+
809
+ function onVisibilityChange() {
810
+ if (typeof document !== 'undefined' && document.hidden && typeof onFocusLost === 'function') {
811
+ onFocusLost('visibilitychange');
812
+ }
813
+ }
814
+
815
+ function onWindowBlur() {
816
+ if (typeof onFocusLost === 'function') {
817
+ onFocusLost('blur');
818
+ }
819
+ }
820
+
821
+ function onBeforeUnload(e) {
822
+ if (!isExitLocked()) return;
823
+ if (typeof e.preventDefault === 'function') e.preventDefault();
824
+ e.returnValue = '';
825
+ }
826
+
827
+ function onContextMenu(e) {
828
+ if (typeof e.preventDefault === 'function') e.preventDefault();
829
+ }
830
+
831
+ function bindKeydown() {
832
+ if (typeof document === 'undefined' || keydownBound) return;
833
+ document.addEventListener('keydown', onKeyDown, true);
834
+ keydownBound = true;
835
+ }
836
+
837
+ function unbindKeydown() {
838
+ if (typeof document === 'undefined' || !keydownBound) return;
839
+ document.removeEventListener('keydown', onKeyDown, true);
840
+ keydownBound = false;
841
+ }
842
+
843
+ function bindBeforeUnload() {
844
+ if (typeof window === 'undefined' || beforeUnloadBound) return;
845
+ window.addEventListener('beforeunload', onBeforeUnload);
846
+ beforeUnloadBound = true;
847
+ }
848
+
849
+ function unbindBeforeUnload() {
850
+ if (typeof window === 'undefined' || !beforeUnloadBound) return;
851
+ window.removeEventListener('beforeunload', onBeforeUnload);
852
+ beforeUnloadBound = false;
853
+ }
854
+
855
+ function bindContextMenu() {
856
+ if (typeof document === 'undefined' || contextMenuBound) return;
857
+ document.addEventListener('contextmenu', onContextMenu, true);
858
+ contextMenuBound = true;
859
+ }
860
+
861
+ function unbindContextMenu() {
862
+ if (typeof document === 'undefined' || !contextMenuBound) return;
863
+ document.removeEventListener('contextmenu', onContextMenu, true);
864
+ contextMenuBound = false;
865
+ }
866
+
867
+ function bindFocus() {
868
+ if (focusBound) return;
869
+ if (typeof document !== 'undefined') {
870
+ document.addEventListener('visibilitychange', onVisibilityChange);
871
+ }
872
+ if (typeof window !== 'undefined') {
873
+ window.addEventListener('blur', onWindowBlur);
874
+ }
875
+ focusBound = true;
876
+ }
877
+
878
+ function unbindFocus() {
879
+ if (!focusBound) return;
880
+ if (typeof document !== 'undefined') {
881
+ document.removeEventListener('visibilitychange', onVisibilityChange);
882
+ }
883
+ if (typeof window !== 'undefined') {
884
+ window.removeEventListener('blur', onWindowBlur);
885
+ }
886
+ focusBound = false;
887
+ }
888
+
889
+ function sync(active, source) {
890
+ if (!active) {
891
+ releaseKeyboardLock();
892
+ unbindKeydown();
893
+ unbindBeforeUnload();
894
+ unbindContextMenu();
895
+ unbindFocus();
896
+ return;
897
+ }
898
+
899
+ if (
900
+ keyboardLock.enabled &&
901
+ source === 'native' &&
902
+ !keyboardLocked &&
903
+ typeof navigator !== 'undefined' &&
904
+ navigator.keyboard &&
905
+ typeof navigator.keyboard.lock === 'function'
906
+ ) {
907
+ keyboardLocked = true;
908
+ try {
909
+ Promise.resolve(navigator.keyboard.lock(keyboardLock.keys)).catch(() => {
910
+ keyboardLocked = false;
911
+ });
912
+ } catch {
913
+ keyboardLocked = false;
914
+ }
915
+ } else if (source !== 'native') {
916
+ releaseKeyboardLock();
917
+ }
918
+
919
+ if (blockShortcuts.enabled) bindKeydown();
920
+ else unbindKeydown();
921
+
922
+ if (confirmOnLeave && isExitLocked()) bindBeforeUnload();
923
+ else unbindBeforeUnload();
924
+
925
+ if (blockContextMenu) bindContextMenu();
926
+ else unbindContextMenu();
927
+
928
+ if (watchFocus) bindFocus();
929
+ else unbindFocus();
930
+ }
931
+
932
+ function unlock() {
933
+ releaseKeyboardLock();
934
+ unbindBeforeUnload();
935
+ unbindFocus();
936
+ }
937
+
938
+ function destroy() {
939
+ sync(false, 'none');
940
+ }
941
+
942
+ return {
943
+ sync,
944
+ unlock,
945
+ destroy
946
+ };
947
+ }
948
+
656
949
  /**
657
950
  * Core engine: createFullscreen()
658
951
  *
@@ -675,7 +968,7 @@
675
968
  );
676
969
  }
677
970
 
678
- function normalizeAutoRelock(val) {
971
+ function normalizeAutoRelock$1(val) {
679
972
  if (val === undefined || val === null || val === false) {
680
973
  return { enabled: false, delay: 50, maxRetries: 3 };
681
974
  }
@@ -694,9 +987,9 @@
694
987
  throw new TypeError('[fullscreen-engine] invalid autoRelock option: expected boolean or object');
695
988
  }
696
989
 
697
- function createFullscreen(userOptions = {}) {
990
+ function createFullscreen$1(userOptions = {}) {
698
991
  const triggers = normalizeTriggers(userOptions.trigger);
699
- const relockConfig = normalizeAutoRelock(userOptions.autoRelock);
992
+ const relockConfig = normalizeAutoRelock$1(userOptions.autoRelock);
700
993
 
701
994
  const fallbackOption = userOptions.fallback ?? 'none';
702
995
  if (fallbackOption !== 'css' && fallbackOption !== 'none') {
@@ -707,6 +1000,57 @@
707
1000
  throw new TypeError('[fullscreen-engine] target must be a valid DOM Element');
708
1001
  }
709
1002
 
1003
+ const navigationUIOption = userOptions.navigationUI ?? 'hide';
1004
+ if (navigationUIOption !== 'hide' && navigationUIOption !== 'show' && navigationUIOption !== 'auto') {
1005
+ throw new TypeError(
1006
+ `[fullscreen-engine] invalid navigationUI "${String(navigationUIOption)}": expected 'hide', 'show', or 'auto'`
1007
+ );
1008
+ }
1009
+
1010
+ let exitButtons = [];
1011
+ if (userOptions.exitButton !== undefined && userOptions.exitButton !== null) {
1012
+ if (Array.isArray(userOptions.exitButton)) {
1013
+ for (const btn of userOptions.exitButton) {
1014
+ if (!isValidElement(btn)) {
1015
+ throw new TypeError('[fullscreen-engine] exitButton must be a valid DOM Element or Element[]');
1016
+ }
1017
+ }
1018
+ exitButtons = userOptions.exitButton.slice();
1019
+ } else if (isValidElement(userOptions.exitButton)) {
1020
+ exitButtons = [userOptions.exitButton];
1021
+ } else {
1022
+ throw new TypeError('[fullscreen-engine] exitButton must be a valid DOM Element or Element[]');
1023
+ }
1024
+ }
1025
+
1026
+ const freezePageOption = userOptions.freezePage ?? false;
1027
+ if (typeof freezePageOption !== 'boolean') {
1028
+ throw new TypeError('[fullscreen-engine] invalid freezePage option: expected boolean');
1029
+ }
1030
+
1031
+ const gestureUpgradeOption = userOptions.gestureUpgrade ?? false;
1032
+ if (typeof gestureUpgradeOption !== 'boolean') {
1033
+ throw new TypeError('[fullscreen-engine] invalid gestureUpgrade option: expected boolean');
1034
+ }
1035
+
1036
+ const keyboardLockConfig = normalizeKeyboardLock(userOptions.keyboardLock);
1037
+ const blockShortcutsConfig = normalizeBlockShortcuts(userOptions.blockShortcuts);
1038
+
1039
+ const confirmOnLeaveOption = userOptions.confirmOnLeave ?? false;
1040
+ if (typeof confirmOnLeaveOption !== 'boolean') {
1041
+ throw new TypeError('[fullscreen-engine] invalid confirmOnLeave option: expected boolean');
1042
+ }
1043
+
1044
+ const blockContextMenuOption = userOptions.blockContextMenu ?? false;
1045
+ if (typeof blockContextMenuOption !== 'boolean') {
1046
+ throw new TypeError('[fullscreen-engine] invalid blockContextMenu option: expected boolean');
1047
+ }
1048
+
1049
+ const watchFocusOption = userOptions.watchFocus ?? false;
1050
+ if (typeof watchFocusOption !== 'boolean') {
1051
+ throw new TypeError('[fullscreen-engine] invalid watchFocus option: expected boolean');
1052
+ }
1053
+
710
1054
  const options = {
711
1055
  target: userOptions.target ?? null,
712
1056
  fallback: fallbackOption, // 'css' | 'none'
@@ -715,6 +1059,15 @@
715
1059
  zIndex: userOptions.zIndex ?? 2147483647,
716
1060
  onError: userOptions.onError ?? null,
717
1061
  autoDetectElectron: userOptions.autoDetectElectron ?? true,
1062
+ navigationUI: navigationUIOption,
1063
+ exitButton: userOptions.exitButton ?? null,
1064
+ freezePage: freezePageOption,
1065
+ gestureUpgrade: gestureUpgradeOption,
1066
+ keyboardLock: keyboardLockConfig,
1067
+ blockShortcuts: blockShortcutsConfig,
1068
+ confirmOnLeave: confirmOnLeaveOption,
1069
+ blockContextMenu: blockContextMenuOption,
1070
+ watchFocus: watchFocusOption,
718
1071
  trigger: triggers.list,
719
1072
  hoverTarget: userOptions.hoverTarget ?? null,
720
1073
  hoverDelay: userOptions.hoverDelay ?? 0,
@@ -770,7 +1123,8 @@
770
1123
  ? createFallback({
771
1124
  fallbackClass: options.fallbackClass,
772
1125
  lockBody: effectiveLockBody,
773
- zIndex: options.zIndex
1126
+ zIndex: options.zIndex,
1127
+ freezePage: options.freezePage
774
1128
  })
775
1129
  : null;
776
1130
 
@@ -780,6 +1134,7 @@
780
1134
  let lastSource = 'none';
781
1135
  let electronUnsub = null;
782
1136
  let escapeBound = false;
1137
+ let gestureUpgradeBound = false;
783
1138
  let exitLocked = !!options.preventExit;
784
1139
  let manualUnlocking = false;
785
1140
  let relockTimer = null;
@@ -824,6 +1179,7 @@
824
1179
  if (exitLocked) {
825
1180
  if (typeof e.preventDefault === 'function') e.preventDefault();
826
1181
  if (typeof e.stopPropagation === 'function') e.stopPropagation();
1182
+ emitter.emit('exitAttempt', { reason: 'escape', state: getState() });
827
1183
  emitError(new Error('[fullscreen-engine] Exit blocked: preventExit is active'));
828
1184
  return;
829
1185
  }
@@ -886,7 +1242,12 @@
886
1242
  if (state.active && state.source !== 'fallback' && fallback && fallback.active) {
887
1243
  fallback.exit();
888
1244
  }
889
- syncEscapeListener(state.active && state.source === 'fallback');
1245
+ const guardsHandlesEscape =
1246
+ blockShortcutsConfig.enabled &&
1247
+ (blockShortcutsConfig.rules || []).some((r) => r.key === 'escape');
1248
+ syncEscapeListener(state.active && state.source === 'fallback' && !guardsHandlesEscape);
1249
+ syncGestureUpgrade(state.active && state.source === 'fallback');
1250
+ guards.sync(state.active, state.source);
890
1251
  if (state.active) {
891
1252
  relockRetries = 0;
892
1253
  clearRelockTimer();
@@ -903,6 +1264,14 @@
903
1264
  else {
904
1265
  emitter.emit('exit', state);
905
1266
  if (wasActive && relockConfig.enabled && !manualUnlocking) {
1267
+ if (options.gestureUpgrade && hasFallback && fallback && !hasElectron) {
1268
+ const target = resolveTarget();
1269
+ if (target) {
1270
+ fallback.enter(target);
1271
+ notifyChange(false);
1272
+ return;
1273
+ }
1274
+ }
906
1275
  scheduleRelock();
907
1276
  }
908
1277
  }
@@ -913,7 +1282,11 @@
913
1282
  if (typeof electronBridge.onChange === 'function') {
914
1283
  electronUnsub = electronBridge.onChange((on) => {
915
1284
  if (destroyed) return;
916
- electronActive = !!on;
1285
+ const next = !!on;
1286
+ if (electronActive && !next && exitLocked) {
1287
+ emitter.emit('exitAttempt', { reason: 'external', state: getState() });
1288
+ }
1289
+ electronActive = next;
917
1290
  notifyChange(false);
918
1291
  });
919
1292
  }
@@ -958,6 +1331,70 @@
958
1331
 
959
1332
  bindNativeListeners();
960
1333
 
1334
+ // ---------- native request + gestureUpgrade helpers ----------
1335
+ function invokeNativeRequest(target) {
1336
+ return maybePromise(() => {
1337
+ if (env.request === 'requestFullscreen') {
1338
+ try {
1339
+ return target[env.request]({ navigationUI: options.navigationUI });
1340
+ } catch (optErr) {
1341
+ if (optErr instanceof TypeError) {
1342
+ return target[env.request]();
1343
+ }
1344
+ throw optErr;
1345
+ }
1346
+ }
1347
+ return target[env.request]();
1348
+ });
1349
+ }
1350
+
1351
+ function clearGestureUpgrade() {
1352
+ if (typeof document === 'undefined' || !gestureUpgradeBound) return;
1353
+ document.removeEventListener('pointerdown', onGestureUpgrade, true);
1354
+ gestureUpgradeBound = false;
1355
+ }
1356
+
1357
+ function onGestureUpgrade() {
1358
+ gestureUpgradeBound = false;
1359
+ if (destroyed || manualUnlocking || !options.gestureUpgrade || !hasNative || !isBrowser()) return;
1360
+ const st = getState();
1361
+ if (!st.active || st.source !== 'fallback') return;
1362
+ const target = resolveTarget();
1363
+ if (!target) return;
1364
+ invokeNativeRequest(target)
1365
+ .then(() => {
1366
+ if (destroyed) return;
1367
+ if (fallback && fallback.active) {
1368
+ fallback.exit();
1369
+ }
1370
+ notifyChange(false);
1371
+ })
1372
+ .catch((err) => {
1373
+ emitError(err);
1374
+ if (!destroyed && !manualUnlocking && getState().source === 'fallback') {
1375
+ syncGestureUpgrade(true);
1376
+ }
1377
+ });
1378
+ }
1379
+
1380
+ function syncGestureUpgrade(shouldArm) {
1381
+ if (
1382
+ !options.gestureUpgrade ||
1383
+ !hasNative ||
1384
+ hasElectron ||
1385
+ !isBrowser() ||
1386
+ manualUnlocking ||
1387
+ !shouldArm
1388
+ ) {
1389
+ clearGestureUpgrade();
1390
+ return;
1391
+ }
1392
+ if (!gestureUpgradeBound) {
1393
+ document.addEventListener('pointerdown', onGestureUpgrade, { capture: true, once: true });
1394
+ gestureUpgradeBound = true;
1395
+ }
1396
+ }
1397
+
961
1398
  // ---------- auto-trigger activation (gesture-safe) ----------
962
1399
  async function requestAuto() {
963
1400
  if (destroyed) return;
@@ -988,12 +1425,13 @@
988
1425
  }
989
1426
  }
990
1427
 
991
- async function exitInternal(fromAutoTrigger = false) {
1428
+ async function exitInternal(fromAutoTrigger = false, reason = 'api') {
992
1429
  if (destroyed) {
993
1430
  if (!fromAutoTrigger) throw new Error('[fullscreen-engine] instance destroyed');
994
1431
  return;
995
1432
  }
996
1433
  if (exitLocked && !fromAutoTrigger) {
1434
+ emitter.emit('exitAttempt', { reason, state: getState() });
997
1435
  const err = new Error('[fullscreen-engine] Exit blocked: preventExit is active');
998
1436
  emitError(err);
999
1437
  throw err;
@@ -1049,6 +1487,26 @@
1049
1487
  onExit: () => exitInternal(true)
1050
1488
  });
1051
1489
 
1490
+ const guards = createGuards({
1491
+ keyboardLock: keyboardLockConfig,
1492
+ blockShortcuts: blockShortcutsConfig,
1493
+ confirmOnLeave: confirmOnLeaveOption,
1494
+ blockContextMenu: blockContextMenuOption,
1495
+ watchFocus: watchFocusOption,
1496
+ isExitLocked: () => exitLocked,
1497
+ onExitAttempt: (reason) => {
1498
+ emitter.emit('exitAttempt', { reason, state: getState() });
1499
+ },
1500
+ onEscapeExit: () => {
1501
+ if (!destroyed && fallback && fallback.active && !exitLocked) {
1502
+ exit().catch((err) => emitError(err));
1503
+ }
1504
+ },
1505
+ onFocusLost: (reason) => {
1506
+ emitter.emit('focusLost', { reason, state: getState() });
1507
+ }
1508
+ });
1509
+
1052
1510
  // ---------- public API ----------
1053
1511
  async function request() {
1054
1512
  if (destroyed) throw new Error('[fullscreen-engine] instance destroyed');
@@ -1074,7 +1532,7 @@
1074
1532
  const target = resolveTarget();
1075
1533
  if (!target) throw new Error('[fullscreen-engine] no target element');
1076
1534
  try {
1077
- await maybePromise(() => target[env.request]());
1535
+ await invokeNativeRequest(target);
1078
1536
  // Avoid duplicate emissions if native changeEvent already fired
1079
1537
  notifyChange(false);
1080
1538
  return;
@@ -1111,9 +1569,16 @@
1111
1569
  exitLocked = false;
1112
1570
  manualUnlocking = true;
1113
1571
  clearRelockTimer();
1572
+ clearGestureUpgrade();
1573
+ guards.unlock();
1114
1574
  relockRetries = 0;
1115
1575
  }
1116
1576
 
1577
+ async function relock() {
1578
+ manualUnlocking = false;
1579
+ return request();
1580
+ }
1581
+
1117
1582
  function isActive() {
1118
1583
  return getState().active;
1119
1584
  }
@@ -1136,12 +1601,30 @@
1136
1601
  return emitter.off(event, cb);
1137
1602
  }
1138
1603
 
1604
+ function onExitButtonClick() {
1605
+ if (destroyed) return;
1606
+ exitInternal(false, 'button').catch(() => {});
1607
+ }
1608
+
1609
+ for (const btn of exitButtons) {
1610
+ if (typeof btn.addEventListener === 'function') {
1611
+ btn.addEventListener('click', onExitButtonClick);
1612
+ }
1613
+ }
1614
+
1139
1615
  function destroy() {
1140
1616
  if (destroyed) return;
1141
1617
  destroyed = true;
1142
1618
  clearRelockTimer();
1619
+ clearGestureUpgrade();
1620
+ guards.destroy();
1143
1621
  syncEscapeListener(false);
1144
1622
  unbindNativeListeners();
1623
+ for (const btn of exitButtons) {
1624
+ if (typeof btn.removeEventListener === 'function') {
1625
+ btn.removeEventListener('click', onExitButtonClick);
1626
+ }
1627
+ }
1145
1628
  if (typeof electronUnsub === 'function') {
1146
1629
  electronUnsub();
1147
1630
  electronUnsub = null;
@@ -1159,6 +1642,7 @@
1159
1642
  exit,
1160
1643
  toggle,
1161
1644
  unlock,
1645
+ relock,
1162
1646
  isActive,
1163
1647
  isSupported,
1164
1648
  isFallback,
@@ -1173,12 +1657,527 @@
1173
1657
  };
1174
1658
  }
1175
1659
 
1660
+ /**
1661
+ * Electron renderer-side adapter.
1662
+ *
1663
+ * Provide this on the renderer via contextBridge (window.fsNative).
1664
+ */
1665
+
1666
+
1667
+ function normalizeAutoRelock(val) {
1668
+ if (val === undefined || val === null || val === false) {
1669
+ return { enabled: false, delay: 50, maxRetries: 3 };
1670
+ }
1671
+ if (val === true) {
1672
+ return { enabled: true, delay: 50, maxRetries: 3 };
1673
+ }
1674
+ if (typeof val === 'object') {
1675
+ const delayNum = Number(val.delay);
1676
+ const retriesNum = Number(val.maxRetries);
1677
+ return {
1678
+ enabled: val.enabled ?? true,
1679
+ delay: Number.isFinite(delayNum) ? Math.max(0, delayNum) : 50,
1680
+ maxRetries: Number.isFinite(retriesNum) ? Math.max(1, Math.trunc(retriesNum)) : 3
1681
+ };
1682
+ }
1683
+ throw new TypeError('[fullscreen-engine/electron] invalid autoRelock option: expected boolean or object');
1684
+ }
1685
+
1686
+ function createElectronFullscreen(bridge, opts = {}) {
1687
+ if (!bridge || typeof bridge.set !== 'function') {
1688
+ throw new Error('[fullscreen-engine/electron] bridge with .set() required');
1689
+ }
1690
+
1691
+ const relockConfig = normalizeAutoRelock(opts.autoRelock);
1692
+ const onError = typeof opts.onError === 'function' ? opts.onError : null;
1693
+ const emitter = new Emitter();
1694
+ let active = false;
1695
+ let destroyed = false;
1696
+ let unsubscribe = null;
1697
+ let exitLocked = !!opts.preventExit;
1698
+ let manualUnlocking = false;
1699
+ let relockTimer = null;
1700
+ let relockRetries = 0;
1701
+
1702
+ function emitError(err) {
1703
+ emitter.emit('error', err);
1704
+ if (onError) onError(err);
1705
+ }
1706
+
1707
+ function clearRelockTimer() {
1708
+ if (relockTimer !== null) {
1709
+ clearTimeout(relockTimer);
1710
+ relockTimer = null;
1711
+ }
1712
+ }
1713
+
1714
+ function getState() {
1715
+ return {
1716
+ active,
1717
+ source: active ? 'electron' : 'none',
1718
+ element: null,
1719
+ supported: true
1720
+ };
1721
+ }
1722
+
1723
+ function scheduleRelock() {
1724
+ if (destroyed || !relockConfig.enabled || manualUnlocking) return;
1725
+ if (relockRetries >= relockConfig.maxRetries) {
1726
+ emitError(new Error('[fullscreen-engine/electron] autoRelock failed after maxRetries'));
1727
+ return;
1728
+ }
1729
+ clearRelockTimer();
1730
+ relockTimer = setTimeout(() => {
1731
+ relockTimer = null;
1732
+ if (destroyed || !relockConfig.enabled || manualUnlocking || active) return;
1733
+ relockRetries += 1;
1734
+ request()
1735
+ .catch((err) => {
1736
+ emitError(err);
1737
+ if (!destroyed && relockConfig.enabled && !manualUnlocking && !active) {
1738
+ scheduleRelock();
1739
+ }
1740
+ });
1741
+ }, relockConfig.delay);
1742
+ }
1743
+
1744
+ function updateActive(next) {
1745
+ const boolNext = !!next;
1746
+ if (boolNext) {
1747
+ relockRetries = 0;
1748
+ clearRelockTimer();
1749
+ }
1750
+ if (boolNext === active) return;
1751
+ const wasActive = active;
1752
+ active = boolNext;
1753
+ const state = getState();
1754
+ emitter.emit('change', state);
1755
+ if (active) emitter.emit('enter', state);
1756
+ else {
1757
+ emitter.emit('exit', state);
1758
+ if (wasActive && relockConfig.enabled && !manualUnlocking) {
1759
+ scheduleRelock();
1760
+ }
1761
+ }
1762
+ }
1763
+
1764
+ if (typeof bridge.onChange === 'function') {
1765
+ unsubscribe = bridge.onChange((on) => {
1766
+ if (!destroyed) updateActive(on);
1767
+ });
1768
+ }
1769
+
1770
+ if (typeof bridge.get === 'function') {
1771
+ Promise.resolve(bridge.get())
1772
+ .then((on) => {
1773
+ if (!destroyed) updateActive(on);
1774
+ })
1775
+ .catch(() => {});
1776
+ }
1777
+
1778
+ async function request() {
1779
+ if (destroyed) throw new Error('[fullscreen-engine/electron] destroyed');
1780
+ manualUnlocking = false;
1781
+ const res = await bridge.set(true);
1782
+ if (res === false) {
1783
+ throw new Error('[fullscreen-engine/electron] bridge.set(true) returned false');
1784
+ }
1785
+ updateActive(true);
1786
+ }
1787
+
1788
+ async function exit() {
1789
+ if (destroyed) throw new Error('[fullscreen-engine/electron] destroyed');
1790
+ if (exitLocked) {
1791
+ emitter.emit('exitAttempt', { reason: 'api', state: getState() });
1792
+ const err = new Error('[fullscreen-engine/electron] Exit blocked: preventExit is active');
1793
+ emitError(err);
1794
+ throw err;
1795
+ }
1796
+ const res = await bridge.set(false);
1797
+ if (res === true) {
1798
+ throw new Error('[fullscreen-engine/electron] bridge.set(false) failed to exit');
1799
+ }
1800
+ updateActive(false);
1801
+ }
1802
+
1803
+ function unlock() {
1804
+ exitLocked = false;
1805
+ manualUnlocking = true;
1806
+ clearRelockTimer();
1807
+ relockRetries = 0;
1808
+ }
1809
+
1810
+ async function relock() {
1811
+ manualUnlocking = false;
1812
+ return request();
1813
+ }
1814
+
1815
+ return {
1816
+ request,
1817
+ exit,
1818
+ async toggle() {
1819
+ return active ? exit() : request();
1820
+ },
1821
+ unlock,
1822
+ relock,
1823
+ isActive() { return active; },
1824
+ isSupported() { return true; },
1825
+ getState,
1826
+ on(event, cb) { return emitter.on(event, cb); },
1827
+ once(event, cb) { return emitter.once(event, cb); },
1828
+ off(event, cb) { return emitter.off(event, cb); },
1829
+ destroy() {
1830
+ if (destroyed) return;
1831
+ destroyed = true;
1832
+ clearRelockTimer();
1833
+ if (typeof unsubscribe === 'function') unsubscribe();
1834
+ unsubscribe = null;
1835
+ active = false;
1836
+ emitter.clear();
1837
+ }
1838
+ };
1839
+ }
1840
+
1841
+ /**
1842
+ * True backend fullscreen control from Node.js.
1843
+ *
1844
+ * Uses Chrome DevTools Protocol (CDP) via Puppeteer to control the
1845
+ * browser window's fullscreen state. This works from a Node.js process.
1846
+ */
1847
+
1848
+ function createPuppeteerFullscreen(page, opts = {}) {
1849
+ if (!page || typeof page.createCDPSession !== 'function') {
1850
+ throw new Error('[fullscreen-engine/puppeteer] page with .createCDPSession() required');
1851
+ }
1852
+
1853
+ let client = null;
1854
+ let windowId = null;
1855
+ let initPromise = null;
1856
+ let active = false;
1857
+ let destroyed = false;
1858
+ let exitLocked = !!opts.preventExit;
1859
+
1860
+ async function ensure() {
1861
+ if (destroyed) throw new Error('[fullscreen-engine/puppeteer] destroyed');
1862
+ if (client && windowId !== null) return;
1863
+ if (!initPromise) {
1864
+ initPromise = (async () => {
1865
+ let session = null;
1866
+ try {
1867
+ session = await page.createCDPSession();
1868
+ const res = await session.send('Browser.getWindowForTarget');
1869
+ if (destroyed) {
1870
+ try { await session.detach(); } catch {}
1871
+ throw new Error('[fullscreen-engine/puppeteer] destroyed');
1872
+ }
1873
+ client = session;
1874
+ windowId = res.windowId;
1875
+ } catch (err) {
1876
+ if (session) {
1877
+ try { await session.detach(); } catch {}
1878
+ }
1879
+ client = null;
1880
+ windowId = null;
1881
+ throw err;
1882
+ } finally {
1883
+ initPromise = null;
1884
+ }
1885
+ })();
1886
+ }
1887
+ return initPromise;
1888
+ }
1889
+
1890
+ async function setState(state) {
1891
+ if (destroyed) throw new Error('[fullscreen-engine/puppeteer] destroyed');
1892
+ await ensure();
1893
+ await client.send('Browser.setWindowBounds', {
1894
+ windowId,
1895
+ bounds: { windowState: state } // 'fullscreen' | 'normal' | 'minimized' | 'maximized'
1896
+ });
1897
+ active = state === 'fullscreen';
1898
+ return active;
1899
+ }
1900
+
1901
+ return {
1902
+ async request() {
1903
+ if (destroyed) throw new Error('[fullscreen-engine/puppeteer] destroyed');
1904
+ if (active) return true;
1905
+ return setState('fullscreen');
1906
+ },
1907
+ async exit() {
1908
+ if (destroyed) throw new Error('[fullscreen-engine/puppeteer] destroyed');
1909
+ if (exitLocked) {
1910
+ throw new Error('[fullscreen-engine/puppeteer] Exit blocked: preventExit is active');
1911
+ }
1912
+ if (!active) {
1913
+ const current = await this.getWindowState();
1914
+ if (current !== 'fullscreen') return false;
1915
+ }
1916
+ return setState(opts.restoreState || 'normal');
1917
+ },
1918
+ async toggle() {
1919
+ if (destroyed) throw new Error('[fullscreen-engine/puppeteer] destroyed');
1920
+ const current = await this.getWindowState();
1921
+ return current === 'fullscreen' ? this.exit() : this.request();
1922
+ },
1923
+ unlock() {
1924
+ exitLocked = false;
1925
+ },
1926
+ async relock() {
1927
+ if (destroyed) throw new Error('[fullscreen-engine/puppeteer] destroyed');
1928
+ const current = await this.getWindowState();
1929
+ if (current === 'fullscreen') return true;
1930
+ return setState('fullscreen');
1931
+ },
1932
+ isActive() {
1933
+ return active;
1934
+ },
1935
+ isSupported() {
1936
+ return true;
1937
+ },
1938
+ async getWindowState() {
1939
+ if (destroyed) throw new Error('[fullscreen-engine/puppeteer] destroyed');
1940
+ await ensure();
1941
+ const res = await client.send('Browser.getWindowBounds', { windowId });
1942
+ const state = res.bounds.windowState;
1943
+ active = state === 'fullscreen';
1944
+ return state;
1945
+ },
1946
+ async destroy() {
1947
+ if (destroyed) return;
1948
+ destroyed = true;
1949
+ if (initPromise) {
1950
+ try { await initPromise; } catch {}
1951
+ }
1952
+ try { if (client) await client.detach(); } catch {}
1953
+ client = null;
1954
+ windowId = null;
1955
+ initPromise = null;
1956
+ active = false;
1957
+ }
1958
+ };
1959
+ }
1960
+
1961
+ /**
1962
+ * SSR / Node.js safe stub.
1963
+ *
1964
+ * Importing the main entry already works in Node (all guards are in place).
1965
+ * But if you explicitly need a no-op controller (e.g. for template
1966
+ * environments that can't tree-shake), use this:
1967
+ *
1968
+ * import { createFullscreen } from 'fullscreen-engine/adapters/ssr';
1969
+ */
1970
+
1971
+ function createFullscreen() {
1972
+ return {
1973
+ async request() { throw new Error('[fullscreen-engine/ssr] fullscreen unavailable in SSR'); },
1974
+ async exit() {},
1975
+ async toggle() { return this.request(); },
1976
+ unlock() {},
1977
+ isActive() { return false; },
1978
+ isSupported() { return false; },
1979
+ isFallback() { return false; },
1980
+ getState() { return { active: false, source: 'none', element: null, supported: false }; },
1981
+ on() { return () => {}; },
1982
+ once() { return () => {}; },
1983
+ off() {},
1984
+ destroy() {}
1985
+ };
1986
+ }
1987
+
1988
+ /**
1989
+ * Global configuration engine for fullscreen-engine.
1990
+ *
1991
+ * Pure isomorphic module (no Node.js built-in imports) safe for Browser,
1992
+ * Electron renderer, Puppeteer/Node, and SSR environments.
1993
+ */
1994
+
1995
+
1996
+ function isPlainObject(val) {
1997
+ return typeof val === 'object' && val !== null && !Array.isArray(val);
1998
+ }
1999
+
2000
+ function mergeAutoRelock(baseVal, nextVal) {
2001
+ if (nextVal === undefined) return baseVal;
2002
+ if (isPlainObject(baseVal) && isPlainObject(nextVal)) {
2003
+ return { ...baseVal, ...nextVal };
2004
+ }
2005
+ return nextVal;
2006
+ }
2007
+
2008
+ function mergeSection(base, ext) {
2009
+ if (!ext) return { ...base };
2010
+ const merged = { ...base, ...ext };
2011
+ if ('autoRelock' in base || 'autoRelock' in ext) {
2012
+ merged.autoRelock = mergeAutoRelock(base.autoRelock, ext.autoRelock);
2013
+ }
2014
+ return merged;
2015
+ }
2016
+
2017
+ function validateConfigShape(cfg, label = 'config') {
2018
+ if (!isPlainObject(cfg)) {
2019
+ throw new TypeError(`[fullscreen-engine/config] ${label} must be a plain object`);
2020
+ }
2021
+ if (cfg.mode !== undefined && (typeof cfg.mode !== 'string' || !(cfg.mode in PRESETS))) {
2022
+ throw new TypeError(`[fullscreen-engine/config] unknown mode/preset: ${String(cfg.mode)}`);
2023
+ }
2024
+ if (cfg.core !== undefined && !isPlainObject(cfg.core)) {
2025
+ throw new TypeError(`[fullscreen-engine/config] ${label}.core must be a plain object`);
2026
+ }
2027
+ if (cfg.adapters !== undefined) {
2028
+ if (!isPlainObject(cfg.adapters)) {
2029
+ throw new TypeError(`[fullscreen-engine/config] ${label}.adapters must be a plain object`);
2030
+ }
2031
+ for (const key of ['electron', 'puppeteer', 'ssr']) {
2032
+ if (cfg.adapters[key] !== undefined && !isPlainObject(cfg.adapters[key])) {
2033
+ throw new TypeError(
2034
+ `[fullscreen-engine/config] adapter "${key}" options must be a plain object`
2035
+ );
2036
+ }
2037
+ }
2038
+ }
2039
+ }
2040
+
2041
+ const PRESETS = Object.freeze({
2042
+ default: Object.freeze({
2043
+ core: Object.freeze({}),
2044
+ adapters: Object.freeze({
2045
+ electron: Object.freeze({}),
2046
+ puppeteer: Object.freeze({}),
2047
+ ssr: Object.freeze({ enabled: true })
2048
+ })
2049
+ }),
2050
+ kiosk: Object.freeze({
2051
+ core: Object.freeze({
2052
+ fallback: 'css',
2053
+ lockBody: true,
2054
+ autoRelock: true,
2055
+ preventExit: true,
2056
+ suppressOnManualExit: true
2057
+ }),
2058
+ adapters: Object.freeze({
2059
+ electron: Object.freeze({ autoRelock: true, preventExit: true }),
2060
+ puppeteer: Object.freeze({ preventExit: true }),
2061
+ ssr: Object.freeze({ enabled: true })
2062
+ })
2063
+ }),
2064
+ presentation: Object.freeze({
2065
+ core: Object.freeze({
2066
+ fallback: 'css',
2067
+ lockBody: true,
2068
+ trigger: 'manual',
2069
+ autoExit: false,
2070
+ suppressOnManualExit: true,
2071
+ autoRelock: false,
2072
+ preventExit: false
2073
+ }),
2074
+ adapters: Object.freeze({
2075
+ electron: Object.freeze({ autoRelock: false, preventExit: false }),
2076
+ puppeteer: Object.freeze({ restoreState: 'normal', preventExit: false }),
2077
+ ssr: Object.freeze({ enabled: true })
2078
+ })
2079
+ }),
2080
+ strict: Object.freeze({
2081
+ core: Object.freeze({
2082
+ fallback: 'css',
2083
+ lockBody: true,
2084
+ freezePage: true,
2085
+ autoRelock: Object.freeze({ enabled: true, delay: 50, maxRetries: 5 }),
2086
+ gestureUpgrade: true,
2087
+ keyboardLock: true,
2088
+ blockShortcuts: true,
2089
+ confirmOnLeave: true,
2090
+ blockContextMenu: true,
2091
+ watchFocus: true,
2092
+ preventExit: true,
2093
+ suppressOnManualExit: true
2094
+ }),
2095
+ adapters: Object.freeze({
2096
+ electron: Object.freeze({
2097
+ autoRelock: Object.freeze({ enabled: true, delay: 50, maxRetries: 5 }),
2098
+ preventExit: true
2099
+ }),
2100
+ puppeteer: Object.freeze({ preventExit: true }),
2101
+ ssr: Object.freeze({ enabled: false })
2102
+ })
2103
+ })
2104
+ });
2105
+
2106
+ function defineConfig(config = {}) {
2107
+ validateConfigShape(config, 'config');
2108
+ return config;
2109
+ }
2110
+
2111
+ function resolveConfig(config = {}, overrides = {}) {
2112
+ validateConfigShape(config, 'config');
2113
+ validateConfigShape(overrides, 'overrides');
2114
+
2115
+ const mode = overrides.mode ?? config.mode ?? 'default';
2116
+ const preset = PRESETS[mode];
2117
+
2118
+ const cfgAdapters = config.adapters || {};
2119
+ const ovAdapters = overrides.adapters || {};
2120
+
2121
+ return {
2122
+ mode,
2123
+ core: mergeSection(mergeSection(preset.core, config.core), overrides.core),
2124
+ adapters: {
2125
+ electron: mergeSection(
2126
+ mergeSection(preset.adapters.electron, cfgAdapters.electron),
2127
+ ovAdapters.electron
2128
+ ),
2129
+ puppeteer: mergeSection(
2130
+ mergeSection(preset.adapters.puppeteer, cfgAdapters.puppeteer),
2131
+ ovAdapters.puppeteer
2132
+ ),
2133
+ ssr: mergeSection(
2134
+ mergeSection(preset.adapters.ssr, cfgAdapters.ssr),
2135
+ ovAdapters.ssr
2136
+ )
2137
+ }
2138
+ };
2139
+ }
2140
+
2141
+ function initFullscreen(config = {}, context = {}) {
2142
+ if (!isPlainObject(context)) {
2143
+ throw new TypeError('[fullscreen-engine/config] context must be a plain object');
2144
+ }
2145
+
2146
+ const resolved = resolveConfig(config, context.overrides || {});
2147
+ if (context.target !== undefined) {
2148
+ resolved.core.target = context.target;
2149
+ }
2150
+
2151
+ if (context.bridge !== undefined || context.adapter === 'electron') {
2152
+ const bridge =
2153
+ context.bridge ?? (typeof window !== 'undefined' ? window.fsNative : null);
2154
+ return createElectronFullscreen(bridge, resolved.adapters.electron);
2155
+ }
2156
+
2157
+ if (context.page !== undefined || context.adapter === 'puppeteer') {
2158
+ return createPuppeteerFullscreen(context.page, resolved.adapters.puppeteer);
2159
+ }
2160
+
2161
+ if (context.adapter === 'ssr' || (isNode() && !isBrowser() && !isElectron())) {
2162
+ if (resolved.adapters.ssr.enabled === false) {
2163
+ throw new Error('[fullscreen-engine/config] SSR adapter is disabled by config');
2164
+ }
2165
+ return createFullscreen();
2166
+ }
2167
+
2168
+ return createFullscreen$1(resolved.core);
2169
+ }
2170
+
1176
2171
  exports.Emitter = Emitter;
1177
- exports.createFullscreen = createFullscreen;
2172
+ exports.PRESETS = PRESETS;
2173
+ exports.createFullscreen = createFullscreen$1;
2174
+ exports.defineConfig = defineConfig;
1178
2175
  exports.detectEnvironment = detectEnvironment;
2176
+ exports.initFullscreen = initFullscreen;
1179
2177
  exports.isBrowser = isBrowser;
1180
2178
  exports.isElectron = isElectron;
1181
2179
  exports.isNode = isNode;
2180
+ exports.resolveConfig = resolveConfig;
1182
2181
 
1183
2182
  }));
1184
2183
  //# sourceMappingURL=fullscreen.umd.cjs.map