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
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Node.js / Electron main-process global config auto-loader.
|
|
3
|
+
*
|
|
4
|
+
* Discovers and loads fullscreen.config.{js,mjs,cjs,json} from a project
|
|
5
|
+
* directory without requiring engine file edits.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { existsSync, readFileSync, statSync } from 'node:fs';
|
|
9
|
+
import { createRequire } from 'node:module';
|
|
10
|
+
import { extname, resolve } from 'node:path';
|
|
11
|
+
import { pathToFileURL } from 'node:url';
|
|
12
|
+
import { initFullscreen, resolveConfig } from './config.js';
|
|
13
|
+
|
|
14
|
+
export const CONFIG_FILES = Object.freeze([
|
|
15
|
+
'fullscreen.config.js',
|
|
16
|
+
'fullscreen.config.mjs',
|
|
17
|
+
'fullscreen.config.cjs',
|
|
18
|
+
'fullscreen.config.json'
|
|
19
|
+
]);
|
|
20
|
+
|
|
21
|
+
const CONFIG_EXTENSIONS = new Set(['.js', '.mjs', '.cjs', '.json']);
|
|
22
|
+
|
|
23
|
+
function isPlainObject(val) {
|
|
24
|
+
return typeof val === 'object' && val !== null && !Array.isArray(val);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export function findConfigFile(cwd = process.cwd()) {
|
|
28
|
+
const baseDir = resolve(cwd);
|
|
29
|
+
for (const filename of CONFIG_FILES) {
|
|
30
|
+
const candidate = resolve(baseDir, filename);
|
|
31
|
+
if (existsSync(candidate) && statSync(candidate).isFile()) {
|
|
32
|
+
return candidate;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
return null;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
async function readRawConfigFile(filePath) {
|
|
39
|
+
const ext = extname(filePath).toLowerCase();
|
|
40
|
+
try {
|
|
41
|
+
if (ext === '.json') {
|
|
42
|
+
const text = readFileSync(filePath, 'utf8');
|
|
43
|
+
return JSON.parse(text);
|
|
44
|
+
}
|
|
45
|
+
if (ext === '.cjs') {
|
|
46
|
+
const require = createRequire(import.meta.url);
|
|
47
|
+
const loaded = require(filePath);
|
|
48
|
+
return loaded && loaded.__esModule ? loaded.default : loaded;
|
|
49
|
+
}
|
|
50
|
+
const mod = await import(pathToFileURL(filePath).href);
|
|
51
|
+
return mod?.default ?? mod;
|
|
52
|
+
} catch (err) {
|
|
53
|
+
throw new Error(
|
|
54
|
+
`[fullscreen-engine/config] failed to load ${filePath}: ${err?.message || String(err)}`,
|
|
55
|
+
{ cause: err }
|
|
56
|
+
);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export async function loadConfig(cwdOrPath = process.cwd(), options = {}) {
|
|
61
|
+
let target = cwdOrPath;
|
|
62
|
+
let opts = options;
|
|
63
|
+
|
|
64
|
+
if (isPlainObject(cwdOrPath)) {
|
|
65
|
+
opts = cwdOrPath;
|
|
66
|
+
target = process.cwd();
|
|
67
|
+
}
|
|
68
|
+
if (!isPlainObject(opts)) {
|
|
69
|
+
throw new TypeError('[fullscreen-engine/config] loadConfig options must be a plain object');
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
const resolvedTarget = resolve(target);
|
|
73
|
+
const ext = extname(resolvedTarget).toLowerCase();
|
|
74
|
+
let filePath = null;
|
|
75
|
+
|
|
76
|
+
if (CONFIG_EXTENSIONS.has(ext)) {
|
|
77
|
+
if (!existsSync(resolvedTarget) || !statSync(resolvedTarget).isFile()) {
|
|
78
|
+
throw new Error(`[fullscreen-engine/config] config file not found: ${resolvedTarget}`);
|
|
79
|
+
}
|
|
80
|
+
filePath = resolvedTarget;
|
|
81
|
+
} else {
|
|
82
|
+
filePath = findConfigFile(resolvedTarget);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
if (!filePath) {
|
|
86
|
+
if (opts.required) {
|
|
87
|
+
throw new Error(
|
|
88
|
+
`[fullscreen-engine/config] no fullscreen.config.{js,mjs,cjs,json} found in ${resolvedTarget}`
|
|
89
|
+
);
|
|
90
|
+
}
|
|
91
|
+
return resolveConfig({}, opts.overrides || {});
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
const rawConfig = await readRawConfigFile(filePath);
|
|
95
|
+
return resolveConfig(rawConfig, opts.overrides || {});
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
export async function loadAndInit(cwdOrPath = process.cwd(), context = {}) {
|
|
99
|
+
let target = cwdOrPath;
|
|
100
|
+
let ctx = context;
|
|
101
|
+
|
|
102
|
+
if (isPlainObject(cwdOrPath)) {
|
|
103
|
+
ctx = cwdOrPath;
|
|
104
|
+
target = process.cwd();
|
|
105
|
+
}
|
|
106
|
+
if (!isPlainObject(ctx)) {
|
|
107
|
+
throw new TypeError('[fullscreen-engine/config] context must be a plain object');
|
|
108
|
+
}
|
|
109
|
+
const config = await loadConfig(target, {
|
|
110
|
+
required: ctx.required ?? false,
|
|
111
|
+
overrides: ctx.overrides || {}
|
|
112
|
+
});
|
|
113
|
+
return initFullscreen(config, ctx);
|
|
114
|
+
}
|
package/src/config.js
ADDED
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Global configuration engine for fullscreen-engine.
|
|
3
|
+
*
|
|
4
|
+
* Pure isomorphic module (no Node.js built-in imports) safe for Browser,
|
|
5
|
+
* Electron renderer, Puppeteer/Node, and SSR environments.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { createFullscreen } from './core.js';
|
|
9
|
+
import { createElectronFullscreen } from './adapters/electron.js';
|
|
10
|
+
import { createPuppeteerFullscreen } from './adapters/puppeteer.js';
|
|
11
|
+
import { createFullscreen as createSSRFullscreen } from './adapters/ssr.js';
|
|
12
|
+
import { isBrowser, isElectron, isNode } from './utils.js';
|
|
13
|
+
|
|
14
|
+
function isPlainObject(val) {
|
|
15
|
+
return typeof val === 'object' && val !== null && !Array.isArray(val);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function mergeAutoRelock(baseVal, nextVal) {
|
|
19
|
+
if (nextVal === undefined) return baseVal;
|
|
20
|
+
if (isPlainObject(baseVal) && isPlainObject(nextVal)) {
|
|
21
|
+
return { ...baseVal, ...nextVal };
|
|
22
|
+
}
|
|
23
|
+
return nextVal;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function mergeSection(base, ext) {
|
|
27
|
+
if (!ext) return { ...base };
|
|
28
|
+
const merged = { ...base, ...ext };
|
|
29
|
+
if ('autoRelock' in base || 'autoRelock' in ext) {
|
|
30
|
+
merged.autoRelock = mergeAutoRelock(base.autoRelock, ext.autoRelock);
|
|
31
|
+
}
|
|
32
|
+
return merged;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function validateConfigShape(cfg, label = 'config') {
|
|
36
|
+
if (!isPlainObject(cfg)) {
|
|
37
|
+
throw new TypeError(`[fullscreen-engine/config] ${label} must be a plain object`);
|
|
38
|
+
}
|
|
39
|
+
if (cfg.mode !== undefined && (typeof cfg.mode !== 'string' || !(cfg.mode in PRESETS))) {
|
|
40
|
+
throw new TypeError(`[fullscreen-engine/config] unknown mode/preset: ${String(cfg.mode)}`);
|
|
41
|
+
}
|
|
42
|
+
if (cfg.core !== undefined && !isPlainObject(cfg.core)) {
|
|
43
|
+
throw new TypeError(`[fullscreen-engine/config] ${label}.core must be a plain object`);
|
|
44
|
+
}
|
|
45
|
+
if (cfg.adapters !== undefined) {
|
|
46
|
+
if (!isPlainObject(cfg.adapters)) {
|
|
47
|
+
throw new TypeError(`[fullscreen-engine/config] ${label}.adapters must be a plain object`);
|
|
48
|
+
}
|
|
49
|
+
for (const key of ['electron', 'puppeteer', 'ssr']) {
|
|
50
|
+
if (cfg.adapters[key] !== undefined && !isPlainObject(cfg.adapters[key])) {
|
|
51
|
+
throw new TypeError(
|
|
52
|
+
`[fullscreen-engine/config] adapter "${key}" options must be a plain object`
|
|
53
|
+
);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export const PRESETS = Object.freeze({
|
|
60
|
+
default: Object.freeze({
|
|
61
|
+
core: Object.freeze({}),
|
|
62
|
+
adapters: Object.freeze({
|
|
63
|
+
electron: Object.freeze({}),
|
|
64
|
+
puppeteer: Object.freeze({}),
|
|
65
|
+
ssr: Object.freeze({ enabled: true })
|
|
66
|
+
})
|
|
67
|
+
}),
|
|
68
|
+
kiosk: Object.freeze({
|
|
69
|
+
core: Object.freeze({
|
|
70
|
+
fallback: 'css',
|
|
71
|
+
lockBody: true,
|
|
72
|
+
autoRelock: true,
|
|
73
|
+
preventExit: true,
|
|
74
|
+
suppressOnManualExit: true
|
|
75
|
+
}),
|
|
76
|
+
adapters: Object.freeze({
|
|
77
|
+
electron: Object.freeze({ autoRelock: true, preventExit: true }),
|
|
78
|
+
puppeteer: Object.freeze({ preventExit: true }),
|
|
79
|
+
ssr: Object.freeze({ enabled: true })
|
|
80
|
+
})
|
|
81
|
+
}),
|
|
82
|
+
presentation: Object.freeze({
|
|
83
|
+
core: Object.freeze({
|
|
84
|
+
fallback: 'css',
|
|
85
|
+
lockBody: true,
|
|
86
|
+
trigger: 'manual',
|
|
87
|
+
autoExit: false,
|
|
88
|
+
suppressOnManualExit: true,
|
|
89
|
+
autoRelock: false,
|
|
90
|
+
preventExit: false
|
|
91
|
+
}),
|
|
92
|
+
adapters: Object.freeze({
|
|
93
|
+
electron: Object.freeze({ autoRelock: false, preventExit: false }),
|
|
94
|
+
puppeteer: Object.freeze({ restoreState: 'normal', preventExit: false }),
|
|
95
|
+
ssr: Object.freeze({ enabled: true })
|
|
96
|
+
})
|
|
97
|
+
}),
|
|
98
|
+
strict: Object.freeze({
|
|
99
|
+
core: Object.freeze({
|
|
100
|
+
fallback: 'css',
|
|
101
|
+
lockBody: true,
|
|
102
|
+
freezePage: true,
|
|
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,
|
|
110
|
+
preventExit: true,
|
|
111
|
+
suppressOnManualExit: true
|
|
112
|
+
}),
|
|
113
|
+
adapters: Object.freeze({
|
|
114
|
+
electron: Object.freeze({
|
|
115
|
+
autoRelock: Object.freeze({ enabled: true, delay: 50, maxRetries: 5 }),
|
|
116
|
+
preventExit: true
|
|
117
|
+
}),
|
|
118
|
+
puppeteer: Object.freeze({ preventExit: true }),
|
|
119
|
+
ssr: Object.freeze({ enabled: false })
|
|
120
|
+
})
|
|
121
|
+
})
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
export function defineConfig(config = {}) {
|
|
125
|
+
validateConfigShape(config, 'config');
|
|
126
|
+
return config;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
export function resolveConfig(config = {}, overrides = {}) {
|
|
130
|
+
validateConfigShape(config, 'config');
|
|
131
|
+
validateConfigShape(overrides, 'overrides');
|
|
132
|
+
|
|
133
|
+
const mode = overrides.mode ?? config.mode ?? 'default';
|
|
134
|
+
const preset = PRESETS[mode];
|
|
135
|
+
|
|
136
|
+
const cfgAdapters = config.adapters || {};
|
|
137
|
+
const ovAdapters = overrides.adapters || {};
|
|
138
|
+
|
|
139
|
+
return {
|
|
140
|
+
mode,
|
|
141
|
+
core: mergeSection(mergeSection(preset.core, config.core), overrides.core),
|
|
142
|
+
adapters: {
|
|
143
|
+
electron: mergeSection(
|
|
144
|
+
mergeSection(preset.adapters.electron, cfgAdapters.electron),
|
|
145
|
+
ovAdapters.electron
|
|
146
|
+
),
|
|
147
|
+
puppeteer: mergeSection(
|
|
148
|
+
mergeSection(preset.adapters.puppeteer, cfgAdapters.puppeteer),
|
|
149
|
+
ovAdapters.puppeteer
|
|
150
|
+
),
|
|
151
|
+
ssr: mergeSection(
|
|
152
|
+
mergeSection(preset.adapters.ssr, cfgAdapters.ssr),
|
|
153
|
+
ovAdapters.ssr
|
|
154
|
+
)
|
|
155
|
+
}
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
export function initFullscreen(config = {}, context = {}) {
|
|
160
|
+
if (!isPlainObject(context)) {
|
|
161
|
+
throw new TypeError('[fullscreen-engine/config] context must be a plain object');
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
const resolved = resolveConfig(config, context.overrides || {});
|
|
165
|
+
if (context.target !== undefined) {
|
|
166
|
+
resolved.core.target = context.target;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
if (context.bridge !== undefined || context.adapter === 'electron') {
|
|
170
|
+
const bridge =
|
|
171
|
+
context.bridge ?? (typeof window !== 'undefined' ? window.fsNative : null);
|
|
172
|
+
return createElectronFullscreen(bridge, resolved.adapters.electron);
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
if (context.page !== undefined || context.adapter === 'puppeteer') {
|
|
176
|
+
return createPuppeteerFullscreen(context.page, resolved.adapters.puppeteer);
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
if (context.adapter === 'ssr' || (isNode() && !isBrowser() && !isElectron())) {
|
|
180
|
+
if (resolved.adapters.ssr.enabled === false) {
|
|
181
|
+
throw new Error('[fullscreen-engine/config] SSR adapter is disabled by config');
|
|
182
|
+
}
|
|
183
|
+
return createSSRFullscreen();
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
return createFullscreen(resolved.core);
|
|
187
|
+
}
|
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) {
|