fullscreen-engine 1.1.0 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +16 -2
- package/dist/adapters/electron.cjs +2 -1
- package/dist/adapters/electron.cjs.map +1 -1
- package/dist/adapters/electron.esm.js +2 -1
- package/dist/adapters/electron.esm.js.map +1 -1
- package/dist/adapters/puppeteer.cjs +1 -1
- package/dist/adapters/puppeteer.esm.js +1 -1
- package/dist/adapters/ssr.cjs +2 -1
- package/dist/adapters/ssr.cjs.map +1 -1
- package/dist/adapters/ssr.esm.js +2 -1
- package/dist/adapters/ssr.esm.js.map +1 -1
- package/dist/config.cjs +507 -14
- package/dist/config.cjs.map +1 -1
- package/dist/config.esm.js +507 -14
- package/dist/config.esm.js.map +1 -1
- package/dist/fullscreen.esm.js +507 -14
- package/dist/fullscreen.esm.js.map +1 -1
- package/dist/fullscreen.esm.min.js +2 -2
- package/dist/fullscreen.esm.min.js.map +1 -1
- package/dist/fullscreen.iife.js +507 -14
- package/dist/fullscreen.iife.js.map +1 -1
- package/dist/fullscreen.umd.cjs +507 -14
- package/dist/fullscreen.umd.cjs.map +1 -1
- package/dist/fullscreen.umd.min.cjs +2 -2
- package/dist/fullscreen.umd.min.cjs.map +1 -1
- package/package.json +2 -2
- package/src/adapters/electron.js +1 -0
- package/src/adapters/ssr.js +1 -0
- package/src/config.js +7 -0
- package/src/core.js +201 -5
- package/src/fallback.js +22 -8
- package/src/guards.js +277 -0
- package/src/vendor.js +1 -0
- package/types/electron.d.ts +4 -0
- package/types/index.d.ts +39 -1
- package/types/ssr.d.ts +1 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "fullscreen-engine",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.0",
|
|
4
4
|
"description": "Reusable, headless fullscreen engine for browsers, Electron, and Node.js (Puppeteer/CDP).",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/fullscreen.umd.cjs",
|
|
@@ -56,7 +56,7 @@
|
|
|
56
56
|
"test": "vitest run",
|
|
57
57
|
"test:coverage": "vitest run --coverage",
|
|
58
58
|
"test:watch": "vitest",
|
|
59
|
-
"lint": "node --check rollup.config.js && node --check vitest.config.js && node --check bin/fullscreen-engine.js && node --check src/index.js && node --check src/core.js && node --check src/config.js && node --check src/config-loader.js && node --check src/triggers.js && node --check src/vendor.js && node --check src/fallback.js && node --check src/events.js && node --check src/utils.js && node --check src/adapters/electron.js && node --check src/adapters/puppeteer.js && node --check src/adapters/ssr.js && node --check test/core.test.js && node --check test/adapters.test.js && node --check test/modules.test.js && node --check test/config.test.js",
|
|
59
|
+
"lint": "node --check rollup.config.js && node --check vitest.config.js && node --check bin/fullscreen-engine.js && node --check src/index.js && node --check src/core.js && node --check src/guards.js && node --check src/config.js && node --check src/config-loader.js && node --check src/triggers.js && node --check src/vendor.js && node --check src/fallback.js && node --check src/events.js && node --check src/utils.js && node --check src/adapters/electron.js && node --check src/adapters/puppeteer.js && node --check src/adapters/ssr.js && node --check test/core.test.js && node --check test/adapters.test.js && node --check test/modules.test.js && node --check test/config.test.js",
|
|
60
60
|
"prepublishOnly": "npm run lint && npm run build && npm test"
|
|
61
61
|
},
|
|
62
62
|
"devDependencies": {
|
package/src/adapters/electron.js
CHANGED
|
@@ -130,6 +130,7 @@ export function createElectronFullscreen(bridge, opts = {}) {
|
|
|
130
130
|
async function exit() {
|
|
131
131
|
if (destroyed) throw new Error('[fullscreen-engine/electron] destroyed');
|
|
132
132
|
if (exitLocked) {
|
|
133
|
+
emitter.emit('exitAttempt', { reason: 'api', state: getState() });
|
|
133
134
|
const err = new Error('[fullscreen-engine/electron] Exit blocked: preventExit is active');
|
|
134
135
|
emitError(err);
|
|
135
136
|
throw err;
|
package/src/adapters/ssr.js
CHANGED
|
@@ -13,6 +13,7 @@ export function createFullscreen() {
|
|
|
13
13
|
async request() { throw new Error('[fullscreen-engine/ssr] fullscreen unavailable in SSR'); },
|
|
14
14
|
async exit() {},
|
|
15
15
|
async toggle() { return this.request(); },
|
|
16
|
+
unlock() {},
|
|
16
17
|
isActive() { return false; },
|
|
17
18
|
isSupported() { return false; },
|
|
18
19
|
isFallback() { return false; },
|
package/src/config.js
CHANGED
|
@@ -99,7 +99,14 @@ export const PRESETS = Object.freeze({
|
|
|
99
99
|
core: Object.freeze({
|
|
100
100
|
fallback: 'css',
|
|
101
101
|
lockBody: true,
|
|
102
|
+
freezePage: true,
|
|
102
103
|
autoRelock: Object.freeze({ enabled: true, delay: 50, maxRetries: 5 }),
|
|
104
|
+
gestureUpgrade: true,
|
|
105
|
+
keyboardLock: true,
|
|
106
|
+
blockShortcuts: true,
|
|
107
|
+
confirmOnLeave: true,
|
|
108
|
+
blockContextMenu: true,
|
|
109
|
+
watchFocus: true,
|
|
103
110
|
preventExit: true,
|
|
104
111
|
suppressOnManualExit: true
|
|
105
112
|
}),
|
package/src/core.js
CHANGED
|
@@ -15,6 +15,11 @@ import { detectEnvironment } from './vendor.js';
|
|
|
15
15
|
import { createFallback } from './fallback.js';
|
|
16
16
|
import { isBrowser, isElectron, maybePromise } from './utils.js';
|
|
17
17
|
import { normalizeTriggers, createAutoTriggers } from './triggers.js';
|
|
18
|
+
import {
|
|
19
|
+
normalizeKeyboardLock,
|
|
20
|
+
normalizeBlockShortcuts,
|
|
21
|
+
createGuards
|
|
22
|
+
} from './guards.js';
|
|
18
23
|
|
|
19
24
|
function isValidElement(el) {
|
|
20
25
|
return (
|
|
@@ -57,6 +62,57 @@ export function createFullscreen(userOptions = {}) {
|
|
|
57
62
|
throw new TypeError('[fullscreen-engine] target must be a valid DOM Element');
|
|
58
63
|
}
|
|
59
64
|
|
|
65
|
+
const navigationUIOption = userOptions.navigationUI ?? 'hide';
|
|
66
|
+
if (navigationUIOption !== 'hide' && navigationUIOption !== 'show' && navigationUIOption !== 'auto') {
|
|
67
|
+
throw new TypeError(
|
|
68
|
+
`[fullscreen-engine] invalid navigationUI "${String(navigationUIOption)}": expected 'hide', 'show', or 'auto'`
|
|
69
|
+
);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
let exitButtons = [];
|
|
73
|
+
if (userOptions.exitButton !== undefined && userOptions.exitButton !== null) {
|
|
74
|
+
if (Array.isArray(userOptions.exitButton)) {
|
|
75
|
+
for (const btn of userOptions.exitButton) {
|
|
76
|
+
if (!isValidElement(btn)) {
|
|
77
|
+
throw new TypeError('[fullscreen-engine] exitButton must be a valid DOM Element or Element[]');
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
exitButtons = userOptions.exitButton.slice();
|
|
81
|
+
} else if (isValidElement(userOptions.exitButton)) {
|
|
82
|
+
exitButtons = [userOptions.exitButton];
|
|
83
|
+
} else {
|
|
84
|
+
throw new TypeError('[fullscreen-engine] exitButton must be a valid DOM Element or Element[]');
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
const freezePageOption = userOptions.freezePage ?? false;
|
|
89
|
+
if (typeof freezePageOption !== 'boolean') {
|
|
90
|
+
throw new TypeError('[fullscreen-engine] invalid freezePage option: expected boolean');
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
const gestureUpgradeOption = userOptions.gestureUpgrade ?? false;
|
|
94
|
+
if (typeof gestureUpgradeOption !== 'boolean') {
|
|
95
|
+
throw new TypeError('[fullscreen-engine] invalid gestureUpgrade option: expected boolean');
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
const keyboardLockConfig = normalizeKeyboardLock(userOptions.keyboardLock);
|
|
99
|
+
const blockShortcutsConfig = normalizeBlockShortcuts(userOptions.blockShortcuts);
|
|
100
|
+
|
|
101
|
+
const confirmOnLeaveOption = userOptions.confirmOnLeave ?? false;
|
|
102
|
+
if (typeof confirmOnLeaveOption !== 'boolean') {
|
|
103
|
+
throw new TypeError('[fullscreen-engine] invalid confirmOnLeave option: expected boolean');
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
const blockContextMenuOption = userOptions.blockContextMenu ?? false;
|
|
107
|
+
if (typeof blockContextMenuOption !== 'boolean') {
|
|
108
|
+
throw new TypeError('[fullscreen-engine] invalid blockContextMenu option: expected boolean');
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
const watchFocusOption = userOptions.watchFocus ?? false;
|
|
112
|
+
if (typeof watchFocusOption !== 'boolean') {
|
|
113
|
+
throw new TypeError('[fullscreen-engine] invalid watchFocus option: expected boolean');
|
|
114
|
+
}
|
|
115
|
+
|
|
60
116
|
const options = {
|
|
61
117
|
target: userOptions.target ?? null,
|
|
62
118
|
fallback: fallbackOption, // 'css' | 'none'
|
|
@@ -65,6 +121,15 @@ export function createFullscreen(userOptions = {}) {
|
|
|
65
121
|
zIndex: userOptions.zIndex ?? 2147483647,
|
|
66
122
|
onError: userOptions.onError ?? null,
|
|
67
123
|
autoDetectElectron: userOptions.autoDetectElectron ?? true,
|
|
124
|
+
navigationUI: navigationUIOption,
|
|
125
|
+
exitButton: userOptions.exitButton ?? null,
|
|
126
|
+
freezePage: freezePageOption,
|
|
127
|
+
gestureUpgrade: gestureUpgradeOption,
|
|
128
|
+
keyboardLock: keyboardLockConfig,
|
|
129
|
+
blockShortcuts: blockShortcutsConfig,
|
|
130
|
+
confirmOnLeave: confirmOnLeaveOption,
|
|
131
|
+
blockContextMenu: blockContextMenuOption,
|
|
132
|
+
watchFocus: watchFocusOption,
|
|
68
133
|
trigger: triggers.list,
|
|
69
134
|
hoverTarget: userOptions.hoverTarget ?? null,
|
|
70
135
|
hoverDelay: userOptions.hoverDelay ?? 0,
|
|
@@ -120,7 +185,8 @@ export function createFullscreen(userOptions = {}) {
|
|
|
120
185
|
? createFallback({
|
|
121
186
|
fallbackClass: options.fallbackClass,
|
|
122
187
|
lockBody: effectiveLockBody,
|
|
123
|
-
zIndex: options.zIndex
|
|
188
|
+
zIndex: options.zIndex,
|
|
189
|
+
freezePage: options.freezePage
|
|
124
190
|
})
|
|
125
191
|
: null;
|
|
126
192
|
|
|
@@ -130,6 +196,7 @@ export function createFullscreen(userOptions = {}) {
|
|
|
130
196
|
let lastSource = 'none';
|
|
131
197
|
let electronUnsub = null;
|
|
132
198
|
let escapeBound = false;
|
|
199
|
+
let gestureUpgradeBound = false;
|
|
133
200
|
let exitLocked = !!options.preventExit;
|
|
134
201
|
let manualUnlocking = false;
|
|
135
202
|
let relockTimer = null;
|
|
@@ -174,6 +241,7 @@ export function createFullscreen(userOptions = {}) {
|
|
|
174
241
|
if (exitLocked) {
|
|
175
242
|
if (typeof e.preventDefault === 'function') e.preventDefault();
|
|
176
243
|
if (typeof e.stopPropagation === 'function') e.stopPropagation();
|
|
244
|
+
emitter.emit('exitAttempt', { reason: 'escape', state: getState() });
|
|
177
245
|
emitError(new Error('[fullscreen-engine] Exit blocked: preventExit is active'));
|
|
178
246
|
return;
|
|
179
247
|
}
|
|
@@ -236,7 +304,12 @@ export function createFullscreen(userOptions = {}) {
|
|
|
236
304
|
if (state.active && state.source !== 'fallback' && fallback && fallback.active) {
|
|
237
305
|
fallback.exit();
|
|
238
306
|
}
|
|
239
|
-
|
|
307
|
+
const guardsHandlesEscape =
|
|
308
|
+
blockShortcutsConfig.enabled &&
|
|
309
|
+
(blockShortcutsConfig.rules || []).some((r) => r.key === 'escape');
|
|
310
|
+
syncEscapeListener(state.active && state.source === 'fallback' && !guardsHandlesEscape);
|
|
311
|
+
syncGestureUpgrade(state.active && state.source === 'fallback');
|
|
312
|
+
guards.sync(state.active, state.source);
|
|
240
313
|
if (state.active) {
|
|
241
314
|
relockRetries = 0;
|
|
242
315
|
clearRelockTimer();
|
|
@@ -253,6 +326,14 @@ export function createFullscreen(userOptions = {}) {
|
|
|
253
326
|
else {
|
|
254
327
|
emitter.emit('exit', state);
|
|
255
328
|
if (wasActive && relockConfig.enabled && !manualUnlocking) {
|
|
329
|
+
if (options.gestureUpgrade && hasFallback && fallback && !hasElectron) {
|
|
330
|
+
const target = resolveTarget();
|
|
331
|
+
if (target) {
|
|
332
|
+
fallback.enter(target);
|
|
333
|
+
notifyChange(false);
|
|
334
|
+
return;
|
|
335
|
+
}
|
|
336
|
+
}
|
|
256
337
|
scheduleRelock();
|
|
257
338
|
}
|
|
258
339
|
}
|
|
@@ -263,7 +344,11 @@ export function createFullscreen(userOptions = {}) {
|
|
|
263
344
|
if (typeof electronBridge.onChange === 'function') {
|
|
264
345
|
electronUnsub = electronBridge.onChange((on) => {
|
|
265
346
|
if (destroyed) return;
|
|
266
|
-
|
|
347
|
+
const next = !!on;
|
|
348
|
+
if (electronActive && !next && exitLocked) {
|
|
349
|
+
emitter.emit('exitAttempt', { reason: 'external', state: getState() });
|
|
350
|
+
}
|
|
351
|
+
electronActive = next;
|
|
267
352
|
notifyChange(false);
|
|
268
353
|
});
|
|
269
354
|
}
|
|
@@ -308,6 +393,70 @@ export function createFullscreen(userOptions = {}) {
|
|
|
308
393
|
|
|
309
394
|
bindNativeListeners();
|
|
310
395
|
|
|
396
|
+
// ---------- native request + gestureUpgrade helpers ----------
|
|
397
|
+
function invokeNativeRequest(target) {
|
|
398
|
+
return maybePromise(() => {
|
|
399
|
+
if (env.request === 'requestFullscreen') {
|
|
400
|
+
try {
|
|
401
|
+
return target[env.request]({ navigationUI: options.navigationUI });
|
|
402
|
+
} catch (optErr) {
|
|
403
|
+
if (optErr instanceof TypeError) {
|
|
404
|
+
return target[env.request]();
|
|
405
|
+
}
|
|
406
|
+
throw optErr;
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
return target[env.request]();
|
|
410
|
+
});
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
function clearGestureUpgrade() {
|
|
414
|
+
if (typeof document === 'undefined' || !gestureUpgradeBound) return;
|
|
415
|
+
document.removeEventListener('pointerdown', onGestureUpgrade, true);
|
|
416
|
+
gestureUpgradeBound = false;
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
function onGestureUpgrade() {
|
|
420
|
+
gestureUpgradeBound = false;
|
|
421
|
+
if (destroyed || manualUnlocking || !options.gestureUpgrade || !hasNative || !isBrowser()) return;
|
|
422
|
+
const st = getState();
|
|
423
|
+
if (!st.active || st.source !== 'fallback') return;
|
|
424
|
+
const target = resolveTarget();
|
|
425
|
+
if (!target) return;
|
|
426
|
+
invokeNativeRequest(target)
|
|
427
|
+
.then(() => {
|
|
428
|
+
if (destroyed) return;
|
|
429
|
+
if (fallback && fallback.active) {
|
|
430
|
+
fallback.exit();
|
|
431
|
+
}
|
|
432
|
+
notifyChange(false);
|
|
433
|
+
})
|
|
434
|
+
.catch((err) => {
|
|
435
|
+
emitError(err);
|
|
436
|
+
if (!destroyed && !manualUnlocking && getState().source === 'fallback') {
|
|
437
|
+
syncGestureUpgrade(true);
|
|
438
|
+
}
|
|
439
|
+
});
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
function syncGestureUpgrade(shouldArm) {
|
|
443
|
+
if (
|
|
444
|
+
!options.gestureUpgrade ||
|
|
445
|
+
!hasNative ||
|
|
446
|
+
hasElectron ||
|
|
447
|
+
!isBrowser() ||
|
|
448
|
+
manualUnlocking ||
|
|
449
|
+
!shouldArm
|
|
450
|
+
) {
|
|
451
|
+
clearGestureUpgrade();
|
|
452
|
+
return;
|
|
453
|
+
}
|
|
454
|
+
if (!gestureUpgradeBound) {
|
|
455
|
+
document.addEventListener('pointerdown', onGestureUpgrade, { capture: true, once: true });
|
|
456
|
+
gestureUpgradeBound = true;
|
|
457
|
+
}
|
|
458
|
+
}
|
|
459
|
+
|
|
311
460
|
// ---------- auto-trigger activation (gesture-safe) ----------
|
|
312
461
|
async function requestAuto() {
|
|
313
462
|
if (destroyed) return;
|
|
@@ -338,12 +487,13 @@ export function createFullscreen(userOptions = {}) {
|
|
|
338
487
|
}
|
|
339
488
|
}
|
|
340
489
|
|
|
341
|
-
async function exitInternal(fromAutoTrigger = false) {
|
|
490
|
+
async function exitInternal(fromAutoTrigger = false, reason = 'api') {
|
|
342
491
|
if (destroyed) {
|
|
343
492
|
if (!fromAutoTrigger) throw new Error('[fullscreen-engine] instance destroyed');
|
|
344
493
|
return;
|
|
345
494
|
}
|
|
346
495
|
if (exitLocked && !fromAutoTrigger) {
|
|
496
|
+
emitter.emit('exitAttempt', { reason, state: getState() });
|
|
347
497
|
const err = new Error('[fullscreen-engine] Exit blocked: preventExit is active');
|
|
348
498
|
emitError(err);
|
|
349
499
|
throw err;
|
|
@@ -399,6 +549,26 @@ export function createFullscreen(userOptions = {}) {
|
|
|
399
549
|
onExit: () => exitInternal(true)
|
|
400
550
|
});
|
|
401
551
|
|
|
552
|
+
const guards = createGuards({
|
|
553
|
+
keyboardLock: keyboardLockConfig,
|
|
554
|
+
blockShortcuts: blockShortcutsConfig,
|
|
555
|
+
confirmOnLeave: confirmOnLeaveOption,
|
|
556
|
+
blockContextMenu: blockContextMenuOption,
|
|
557
|
+
watchFocus: watchFocusOption,
|
|
558
|
+
isExitLocked: () => exitLocked,
|
|
559
|
+
onExitAttempt: (reason) => {
|
|
560
|
+
emitter.emit('exitAttempt', { reason, state: getState() });
|
|
561
|
+
},
|
|
562
|
+
onEscapeExit: () => {
|
|
563
|
+
if (!destroyed && fallback && fallback.active && !exitLocked) {
|
|
564
|
+
exit().catch((err) => emitError(err));
|
|
565
|
+
}
|
|
566
|
+
},
|
|
567
|
+
onFocusLost: (reason) => {
|
|
568
|
+
emitter.emit('focusLost', { reason, state: getState() });
|
|
569
|
+
}
|
|
570
|
+
});
|
|
571
|
+
|
|
402
572
|
// ---------- public API ----------
|
|
403
573
|
async function request() {
|
|
404
574
|
if (destroyed) throw new Error('[fullscreen-engine] instance destroyed');
|
|
@@ -424,7 +594,7 @@ export function createFullscreen(userOptions = {}) {
|
|
|
424
594
|
const target = resolveTarget();
|
|
425
595
|
if (!target) throw new Error('[fullscreen-engine] no target element');
|
|
426
596
|
try {
|
|
427
|
-
await
|
|
597
|
+
await invokeNativeRequest(target);
|
|
428
598
|
// Avoid duplicate emissions if native changeEvent already fired
|
|
429
599
|
notifyChange(false);
|
|
430
600
|
return;
|
|
@@ -461,9 +631,16 @@ export function createFullscreen(userOptions = {}) {
|
|
|
461
631
|
exitLocked = false;
|
|
462
632
|
manualUnlocking = true;
|
|
463
633
|
clearRelockTimer();
|
|
634
|
+
clearGestureUpgrade();
|
|
635
|
+
guards.unlock();
|
|
464
636
|
relockRetries = 0;
|
|
465
637
|
}
|
|
466
638
|
|
|
639
|
+
async function relock() {
|
|
640
|
+
manualUnlocking = false;
|
|
641
|
+
return request();
|
|
642
|
+
}
|
|
643
|
+
|
|
467
644
|
function isActive() {
|
|
468
645
|
return getState().active;
|
|
469
646
|
}
|
|
@@ -486,12 +663,30 @@ export function createFullscreen(userOptions = {}) {
|
|
|
486
663
|
return emitter.off(event, cb);
|
|
487
664
|
}
|
|
488
665
|
|
|
666
|
+
function onExitButtonClick() {
|
|
667
|
+
if (destroyed) return;
|
|
668
|
+
exitInternal(false, 'button').catch(() => {});
|
|
669
|
+
}
|
|
670
|
+
|
|
671
|
+
for (const btn of exitButtons) {
|
|
672
|
+
if (typeof btn.addEventListener === 'function') {
|
|
673
|
+
btn.addEventListener('click', onExitButtonClick);
|
|
674
|
+
}
|
|
675
|
+
}
|
|
676
|
+
|
|
489
677
|
function destroy() {
|
|
490
678
|
if (destroyed) return;
|
|
491
679
|
destroyed = true;
|
|
492
680
|
clearRelockTimer();
|
|
681
|
+
clearGestureUpgrade();
|
|
682
|
+
guards.destroy();
|
|
493
683
|
syncEscapeListener(false);
|
|
494
684
|
unbindNativeListeners();
|
|
685
|
+
for (const btn of exitButtons) {
|
|
686
|
+
if (typeof btn.removeEventListener === 'function') {
|
|
687
|
+
btn.removeEventListener('click', onExitButtonClick);
|
|
688
|
+
}
|
|
689
|
+
}
|
|
495
690
|
if (typeof electronUnsub === 'function') {
|
|
496
691
|
electronUnsub();
|
|
497
692
|
electronUnsub = null;
|
|
@@ -509,6 +704,7 @@ export function createFullscreen(userOptions = {}) {
|
|
|
509
704
|
exit,
|
|
510
705
|
toggle,
|
|
511
706
|
unlock,
|
|
707
|
+
relock,
|
|
512
708
|
isActive,
|
|
513
709
|
isSupported,
|
|
514
710
|
isFallback,
|
package/src/fallback.js
CHANGED
|
@@ -23,11 +23,22 @@ function sanitizeZIndex(val) {
|
|
|
23
23
|
return Number.isFinite(num) ? Math.trunc(num) : 2147483647;
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
-
function getStyleId(baseClass, lockClass, zIndex) {
|
|
27
|
-
return `__fullscreen_engine_style_${baseClass}_${lockClass}_${zIndex}__`;
|
|
26
|
+
function getStyleId(baseClass, lockClass, zIndex, freezePage = false) {
|
|
27
|
+
return `__fullscreen_engine_style_${baseClass}_${lockClass}_${zIndex}${freezePage ? '_freeze' : ''}__`;
|
|
28
28
|
}
|
|
29
29
|
|
|
30
|
-
function buildCSS(baseClass, lockClass, zIndex) {
|
|
30
|
+
function buildCSS(baseClass, lockClass, zIndex, freezePage = false) {
|
|
31
|
+
const freezeTargetCSS = freezePage
|
|
32
|
+
? `
|
|
33
|
+
overscroll-behavior: none !important;
|
|
34
|
+
touch-action: manipulation !important;
|
|
35
|
+
user-select: none !important;
|
|
36
|
+
-webkit-user-select: none !important;`
|
|
37
|
+
: '';
|
|
38
|
+
const freezeLockCSS = freezePage
|
|
39
|
+
? `
|
|
40
|
+
overscroll-behavior: none !important;`
|
|
41
|
+
: '';
|
|
31
42
|
return `
|
|
32
43
|
.${baseClass} {
|
|
33
44
|
position: fixed !important;
|
|
@@ -37,25 +48,27 @@ function buildCSS(baseClass, lockClass, zIndex) {
|
|
|
37
48
|
bottom: 0 !important;
|
|
38
49
|
width: 100vw !important;
|
|
39
50
|
height: 100vh !important;
|
|
51
|
+
height: 100dvh !important;
|
|
40
52
|
margin: 0 !important;
|
|
41
53
|
padding: 0 !important;
|
|
42
54
|
border: 0 !important;
|
|
43
55
|
z-index: ${zIndex} !important;
|
|
44
56
|
background: #000 !important;
|
|
45
|
-
overflow: auto !important
|
|
57
|
+
overflow: auto !important;${freezeTargetCSS}
|
|
46
58
|
}
|
|
47
59
|
html.${lockClass}, body.${lockClass} {
|
|
48
60
|
overflow: hidden !important;
|
|
61
|
+
scrollbar-width: none !important;${freezeLockCSS}
|
|
49
62
|
}
|
|
50
63
|
`;
|
|
51
64
|
}
|
|
52
65
|
|
|
53
|
-
function ensureStyle(styleId, baseClass, lockClass, zIndex) {
|
|
66
|
+
function ensureStyle(styleId, baseClass, lockClass, zIndex, freezePage = false) {
|
|
54
67
|
if (typeof document === 'undefined') return;
|
|
55
68
|
if (document.getElementById(styleId)) return;
|
|
56
69
|
const style = document.createElement('style');
|
|
57
70
|
style.id = styleId;
|
|
58
|
-
style.textContent = buildCSS(baseClass, lockClass, zIndex);
|
|
71
|
+
style.textContent = buildCSS(baseClass, lockClass, zIndex, freezePage);
|
|
59
72
|
(document.head || document.documentElement).appendChild(style);
|
|
60
73
|
}
|
|
61
74
|
|
|
@@ -69,7 +82,8 @@ export function createFallback(opts) {
|
|
|
69
82
|
const baseClass = sanitizeClassName(opts.fallbackClass, 'fs-engine-active');
|
|
70
83
|
const lockClass = opts.lockBody === false ? '__no_lock__' : 'fs-engine-scroll-lock';
|
|
71
84
|
const zIndex = sanitizeZIndex(opts.zIndex);
|
|
72
|
-
const
|
|
85
|
+
const freezePage = !!opts.freezePage;
|
|
86
|
+
const styleId = getStyleId(baseClass, lockClass, zIndex, freezePage);
|
|
73
87
|
let active = false;
|
|
74
88
|
let activeTarget = null;
|
|
75
89
|
let styleRegistered = false;
|
|
@@ -81,7 +95,7 @@ export function createFallback(opts) {
|
|
|
81
95
|
styleRefCounts.set(styleId, (styleRefCounts.get(styleId) ?? 0) + 1);
|
|
82
96
|
styleRegistered = true;
|
|
83
97
|
}
|
|
84
|
-
ensureStyle(styleId, baseClass, lockClass, zIndex);
|
|
98
|
+
ensureStyle(styleId, baseClass, lockClass, zIndex, freezePage);
|
|
85
99
|
activeTarget = target;
|
|
86
100
|
target.classList.add(baseClass);
|
|
87
101
|
if (opts.lockBody !== false && !lockApplied) {
|