fullscreen-engine 0.0.0-stage → 1.1.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 +232 -2
- package/bin/fullscreen-engine.js +162 -0
- package/dist/adapters/electron.cjs +249 -0
- package/dist/adapters/electron.cjs.map +1 -0
- package/dist/adapters/electron.esm.js +247 -0
- package/dist/adapters/electron.esm.js.map +1 -0
- package/dist/adapters/puppeteer.cjs +125 -0
- package/dist/adapters/puppeteer.cjs.map +1 -0
- package/dist/adapters/puppeteer.esm.js +123 -0
- package/dist/adapters/puppeteer.esm.js.map +1 -0
- package/dist/adapters/ssr.cjs +31 -0
- package/dist/adapters/ssr.cjs.map +1 -0
- package/dist/adapters/ssr.esm.js +29 -0
- package/dist/adapters/ssr.esm.js.map +1 -0
- package/dist/config.cjs +1789 -0
- package/dist/config.cjs.map +1 -0
- package/dist/config.esm.js +1783 -0
- package/dist/config.esm.js.map +1 -0
- package/dist/fullscreen.esm.js +1673 -0
- package/dist/fullscreen.esm.js.map +1 -0
- package/dist/fullscreen.esm.min.js +3 -0
- package/dist/fullscreen.esm.min.js.map +1 -0
- package/dist/fullscreen.iife.js +1689 -0
- package/dist/fullscreen.iife.js.map +1 -0
- package/dist/fullscreen.umd.cjs +1690 -0
- package/dist/fullscreen.umd.cjs.map +1 -0
- package/dist/fullscreen.umd.min.cjs +3 -0
- package/dist/fullscreen.umd.min.cjs.map +1 -0
- package/package.json +82 -4
- package/src/adapters/electron.js +180 -0
- package/src/adapters/puppeteer.js +119 -0
- package/src/adapters/ssr.js +25 -0
- package/src/config-loader.js +114 -0
- package/src/config.js +180 -0
- package/src/core.js +524 -0
- package/src/events.js +63 -0
- package/src/fallback.js +136 -0
- package/src/index.js +23 -0
- package/src/triggers.js +282 -0
- package/src/utils.js +67 -0
- package/src/vendor.js +118 -0
- package/types/config.d.ts +40 -0
- package/types/electron.d.ts +45 -0
- package/types/index.d.ts +161 -0
- package/types/puppeteer.d.ts +23 -0
- package/types/ssr.d.ts +22 -0
package/src/fallback.js
ADDED
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CSS-based fake fullscreen fallback.
|
|
3
|
+
* Used when native API is unavailable (e.g. iPhone Safari)
|
|
4
|
+
* or when the request is rejected.
|
|
5
|
+
*
|
|
6
|
+
* This does NOT cover browser chrome; it only makes the target
|
|
7
|
+
* element fill the viewport. That's the best a page can do.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
const styleRefCounts = new Map();
|
|
11
|
+
const lockRefCounts = new Map();
|
|
12
|
+
|
|
13
|
+
function sanitizeClassName(name, fallback) {
|
|
14
|
+
const cleaned = String(name || '').replace(/[^a-zA-Z0-9_-]/g, '_');
|
|
15
|
+
return cleaned || fallback;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function sanitizeZIndex(val) {
|
|
19
|
+
if (val === null || val === undefined || val === '' || typeof val === 'boolean') {
|
|
20
|
+
return 2147483647;
|
|
21
|
+
}
|
|
22
|
+
const num = Number(val);
|
|
23
|
+
return Number.isFinite(num) ? Math.trunc(num) : 2147483647;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function getStyleId(baseClass, lockClass, zIndex) {
|
|
27
|
+
return `__fullscreen_engine_style_${baseClass}_${lockClass}_${zIndex}__`;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function buildCSS(baseClass, lockClass, zIndex) {
|
|
31
|
+
return `
|
|
32
|
+
.${baseClass} {
|
|
33
|
+
position: fixed !important;
|
|
34
|
+
top: 0 !important;
|
|
35
|
+
left: 0 !important;
|
|
36
|
+
right: 0 !important;
|
|
37
|
+
bottom: 0 !important;
|
|
38
|
+
width: 100vw !important;
|
|
39
|
+
height: 100vh !important;
|
|
40
|
+
margin: 0 !important;
|
|
41
|
+
padding: 0 !important;
|
|
42
|
+
border: 0 !important;
|
|
43
|
+
z-index: ${zIndex} !important;
|
|
44
|
+
background: #000 !important;
|
|
45
|
+
overflow: auto !important;
|
|
46
|
+
}
|
|
47
|
+
html.${lockClass}, body.${lockClass} {
|
|
48
|
+
overflow: hidden !important;
|
|
49
|
+
}
|
|
50
|
+
`;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function ensureStyle(styleId, baseClass, lockClass, zIndex) {
|
|
54
|
+
if (typeof document === 'undefined') return;
|
|
55
|
+
if (document.getElementById(styleId)) return;
|
|
56
|
+
const style = document.createElement('style');
|
|
57
|
+
style.id = styleId;
|
|
58
|
+
style.textContent = buildCSS(baseClass, lockClass, zIndex);
|
|
59
|
+
(document.head || document.documentElement).appendChild(style);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function removeStyle(styleId) {
|
|
63
|
+
if (typeof document === 'undefined') return;
|
|
64
|
+
const style = document.getElementById(styleId);
|
|
65
|
+
if (style) style.remove();
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export function createFallback(opts) {
|
|
69
|
+
const baseClass = sanitizeClassName(opts.fallbackClass, 'fs-engine-active');
|
|
70
|
+
const lockClass = opts.lockBody === false ? '__no_lock__' : 'fs-engine-scroll-lock';
|
|
71
|
+
const zIndex = sanitizeZIndex(opts.zIndex);
|
|
72
|
+
const styleId = getStyleId(baseClass, lockClass, zIndex);
|
|
73
|
+
let active = false;
|
|
74
|
+
let activeTarget = null;
|
|
75
|
+
let styleRegistered = false;
|
|
76
|
+
let lockApplied = false;
|
|
77
|
+
|
|
78
|
+
function enter(target) {
|
|
79
|
+
if (typeof document === 'undefined' || !target || !target.classList) return;
|
|
80
|
+
if (!styleRegistered) {
|
|
81
|
+
styleRefCounts.set(styleId, (styleRefCounts.get(styleId) ?? 0) + 1);
|
|
82
|
+
styleRegistered = true;
|
|
83
|
+
}
|
|
84
|
+
ensureStyle(styleId, baseClass, lockClass, zIndex);
|
|
85
|
+
activeTarget = target;
|
|
86
|
+
target.classList.add(baseClass);
|
|
87
|
+
if (opts.lockBody !== false && !lockApplied) {
|
|
88
|
+
lockRefCounts.set(lockClass, (lockRefCounts.get(lockClass) ?? 0) + 1);
|
|
89
|
+
lockApplied = true;
|
|
90
|
+
document.documentElement.classList.add(lockClass);
|
|
91
|
+
document.body && document.body.classList.add(lockClass);
|
|
92
|
+
}
|
|
93
|
+
active = true;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
function exit() {
|
|
97
|
+
if (typeof document === 'undefined') return;
|
|
98
|
+
if (activeTarget && activeTarget.classList) {
|
|
99
|
+
activeTarget.classList.remove(baseClass);
|
|
100
|
+
}
|
|
101
|
+
if (opts.lockBody !== false && lockApplied) {
|
|
102
|
+
lockApplied = false;
|
|
103
|
+
const nextLockCount = (lockRefCounts.get(lockClass) ?? 1) - 1;
|
|
104
|
+
if (nextLockCount <= 0) {
|
|
105
|
+
lockRefCounts.delete(lockClass);
|
|
106
|
+
document.documentElement.classList.remove(lockClass);
|
|
107
|
+
document.body && document.body.classList.remove(lockClass);
|
|
108
|
+
} else {
|
|
109
|
+
lockRefCounts.set(lockClass, nextLockCount);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
activeTarget = null;
|
|
113
|
+
active = false;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
function destroy() {
|
|
117
|
+
exit();
|
|
118
|
+
if (styleRegistered) {
|
|
119
|
+
styleRegistered = false;
|
|
120
|
+
const nextCount = (styleRefCounts.get(styleId) ?? 1) - 1;
|
|
121
|
+
if (nextCount <= 0) {
|
|
122
|
+
styleRefCounts.delete(styleId);
|
|
123
|
+
removeStyle(styleId);
|
|
124
|
+
} else {
|
|
125
|
+
styleRefCounts.set(styleId, nextCount);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
return {
|
|
131
|
+
enter,
|
|
132
|
+
exit,
|
|
133
|
+
destroy,
|
|
134
|
+
get active() { return active; }
|
|
135
|
+
};
|
|
136
|
+
}
|
package/src/index.js
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* fullscreen-engine
|
|
3
|
+
*
|
|
4
|
+
* Headless, reusable fullscreen engine.
|
|
5
|
+
* No UI, no pages, no demos — pure control module.
|
|
6
|
+
*
|
|
7
|
+
* Usage (browser / Electron renderer):
|
|
8
|
+
* import { createFullscreen } from 'fullscreen-engine';
|
|
9
|
+
* const fs = createFullscreen({ fallback: 'css' });
|
|
10
|
+
* await fs.request(); // must be inside a user gesture
|
|
11
|
+
* await fs.exit();
|
|
12
|
+
*
|
|
13
|
+
* Usage (Node.js + Puppeteer):
|
|
14
|
+
* import { createPuppeteerFullscreen } from 'fullscreen-engine/adapters/puppeteer';
|
|
15
|
+
* const ctl = createPuppeteerFullscreen(page);
|
|
16
|
+
* await ctl.request();
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
export { createFullscreen } from './core.js';
|
|
20
|
+
export { Emitter } from './events.js';
|
|
21
|
+
export { detectEnvironment } from './vendor.js';
|
|
22
|
+
export { isBrowser, isNode, isElectron } from './utils.js';
|
|
23
|
+
export { PRESETS, defineConfig, resolveConfig, initFullscreen } from './config.js';
|
package/src/triggers.js
ADDED
|
@@ -0,0 +1,282 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Auto-trigger controller for mouse hover and page scroll fullscreen activation.
|
|
3
|
+
*
|
|
4
|
+
* Pairs with CSS fallback (or Electron IPC bridge) so hover and scroll events
|
|
5
|
+
* can enter fullscreen without triggering browser user-gesture SecurityErrors.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { isBrowser } from './utils.js';
|
|
9
|
+
|
|
10
|
+
const VALID_TRIGGERS = new Set(['manual', 'hover', 'scroll']);
|
|
11
|
+
|
|
12
|
+
function normalizeThreshold(val) {
|
|
13
|
+
if (val === null || val === '' || typeof val === 'boolean') return 100;
|
|
14
|
+
const num = Number(val);
|
|
15
|
+
return Number.isFinite(num) ? Math.max(0, num) : 100;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export function normalizeTriggers(triggerOption) {
|
|
19
|
+
const raw = Array.isArray(triggerOption)
|
|
20
|
+
? triggerOption
|
|
21
|
+
: triggerOption !== undefined && triggerOption !== null
|
|
22
|
+
? [triggerOption]
|
|
23
|
+
: ['manual'];
|
|
24
|
+
|
|
25
|
+
for (const item of raw) {
|
|
26
|
+
if (!VALID_TRIGGERS.has(item)) {
|
|
27
|
+
throw new TypeError(`[fullscreen-engine] invalid trigger "${String(item)}": expected 'manual', 'hover', or 'scroll'`);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const hasHover = raw.includes('hover');
|
|
32
|
+
const hasScroll = raw.includes('scroll');
|
|
33
|
+
|
|
34
|
+
return {
|
|
35
|
+
list: raw,
|
|
36
|
+
hasHover,
|
|
37
|
+
hasScroll,
|
|
38
|
+
isAuto: hasHover || hasScroll
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export function createAutoTriggers({
|
|
43
|
+
triggers,
|
|
44
|
+
resolveHoverTarget,
|
|
45
|
+
resolveScrollTarget,
|
|
46
|
+
hoverDelay = 0,
|
|
47
|
+
scrollThreshold = 100,
|
|
48
|
+
autoExit = true,
|
|
49
|
+
suppressOnManualExit = true,
|
|
50
|
+
isActive,
|
|
51
|
+
onEnter,
|
|
52
|
+
onExit
|
|
53
|
+
}) {
|
|
54
|
+
if (!triggers.isAuto || !isBrowser()) {
|
|
55
|
+
return {
|
|
56
|
+
notifyManualExit() {},
|
|
57
|
+
destroy() {}
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const threshold = normalizeThreshold(scrollThreshold);
|
|
62
|
+
|
|
63
|
+
let destroyed = false;
|
|
64
|
+
let activeSource = null; // 'hover' | 'scroll' | null
|
|
65
|
+
let isHovered = false;
|
|
66
|
+
let hoverTimer = null;
|
|
67
|
+
let domReadyBound = false;
|
|
68
|
+
let enterSeq = 0;
|
|
69
|
+
let pendingExitSeq = null;
|
|
70
|
+
const suppressed = {
|
|
71
|
+
hover: false,
|
|
72
|
+
scroll: false
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
function clearHoverTimer() {
|
|
76
|
+
if (hoverTimer !== null) {
|
|
77
|
+
clearTimeout(hoverTimer);
|
|
78
|
+
hoverTimer = null;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// ---------- Hover & Scroll target state ----------
|
|
83
|
+
let boundHoverEl = null;
|
|
84
|
+
let boundScrollEl = null;
|
|
85
|
+
|
|
86
|
+
function getScrollY() {
|
|
87
|
+
if (boundScrollEl && typeof window !== 'undefined' && boundScrollEl !== window) {
|
|
88
|
+
return boundScrollEl.scrollTop ?? 0;
|
|
89
|
+
}
|
|
90
|
+
if (typeof window === 'undefined') return 0;
|
|
91
|
+
return (
|
|
92
|
+
window.scrollY ??
|
|
93
|
+
window.pageYOffset ??
|
|
94
|
+
(typeof document !== 'undefined' && document.documentElement
|
|
95
|
+
? document.documentElement.scrollTop
|
|
96
|
+
: 0) ??
|
|
97
|
+
0
|
|
98
|
+
);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
function isScrollPastThreshold() {
|
|
102
|
+
return getScrollY() >= threshold;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
function triggerEnter(source) {
|
|
106
|
+
if (destroyed) return;
|
|
107
|
+
if (suppressed[source]) return;
|
|
108
|
+
if (isActive()) return;
|
|
109
|
+
activeSource = source;
|
|
110
|
+
const seq = ++enterSeq;
|
|
111
|
+
Promise.resolve(onEnter(source))
|
|
112
|
+
.then(() => {
|
|
113
|
+
if (destroyed || seq !== enterSeq) {
|
|
114
|
+
if (pendingExitSeq === seq && isActive()) {
|
|
115
|
+
pendingExitSeq = null;
|
|
116
|
+
Promise.resolve(onExit(source)).catch(() => {});
|
|
117
|
+
}
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
if (!isActive() && activeSource === source) {
|
|
121
|
+
activeSource = null;
|
|
122
|
+
}
|
|
123
|
+
})
|
|
124
|
+
.catch(() => {
|
|
125
|
+
if (seq === enterSeq && activeSource === source) {
|
|
126
|
+
activeSource = null;
|
|
127
|
+
}
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
function triggerExit(source) {
|
|
132
|
+
if (destroyed || !autoExit) return;
|
|
133
|
+
if (activeSource !== source) return;
|
|
134
|
+
|
|
135
|
+
// Transfer ownership if the other trigger condition is still active
|
|
136
|
+
if (source === 'hover' && triggers.hasScroll && isScrollPastThreshold() && !suppressed.scroll) {
|
|
137
|
+
activeSource = 'scroll';
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
if (source === 'scroll' && triggers.hasHover && isHovered && !suppressed.hover) {
|
|
141
|
+
activeSource = 'hover';
|
|
142
|
+
return;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
if (!isActive()) {
|
|
146
|
+
pendingExitSeq = enterSeq;
|
|
147
|
+
activeSource = null;
|
|
148
|
+
return;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
activeSource = null;
|
|
152
|
+
onExit(source);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
// ---------- Hover handlers ----------
|
|
156
|
+
function onMouseEnter() {
|
|
157
|
+
if (destroyed) return;
|
|
158
|
+
isHovered = true;
|
|
159
|
+
if (suppressed.hover) return;
|
|
160
|
+
|
|
161
|
+
clearHoverTimer();
|
|
162
|
+
const delay = Math.max(0, Number(hoverDelay) || 0);
|
|
163
|
+
if (delay > 0) {
|
|
164
|
+
hoverTimer = setTimeout(() => {
|
|
165
|
+
hoverTimer = null;
|
|
166
|
+
if (isHovered && !destroyed) {
|
|
167
|
+
triggerEnter('hover');
|
|
168
|
+
}
|
|
169
|
+
}, delay);
|
|
170
|
+
} else {
|
|
171
|
+
triggerEnter('hover');
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
function onMouseLeave() {
|
|
176
|
+
if (destroyed) return;
|
|
177
|
+
isHovered = false;
|
|
178
|
+
clearHoverTimer();
|
|
179
|
+
suppressed.hover = false;
|
|
180
|
+
triggerExit('hover');
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
function bindHoverTarget() {
|
|
184
|
+
if (destroyed || !triggers.hasHover || boundHoverEl) return;
|
|
185
|
+
const el = typeof resolveHoverTarget === 'function' ? resolveHoverTarget() : null;
|
|
186
|
+
if (el && typeof el.addEventListener === 'function') {
|
|
187
|
+
boundHoverEl = el;
|
|
188
|
+
boundHoverEl.addEventListener('mouseenter', onMouseEnter);
|
|
189
|
+
boundHoverEl.addEventListener('mouseleave', onMouseLeave);
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
// ---------- Scroll handler ----------
|
|
194
|
+
function onScroll() {
|
|
195
|
+
if (destroyed) return;
|
|
196
|
+
if (isScrollPastThreshold()) {
|
|
197
|
+
triggerEnter('scroll');
|
|
198
|
+
} else {
|
|
199
|
+
suppressed.scroll = false;
|
|
200
|
+
triggerExit('scroll');
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
function bindScrollTarget() {
|
|
205
|
+
if (destroyed || !triggers.hasScroll || boundScrollEl) return;
|
|
206
|
+
const target =
|
|
207
|
+
typeof resolveScrollTarget === 'function'
|
|
208
|
+
? resolveScrollTarget()
|
|
209
|
+
: typeof window !== 'undefined'
|
|
210
|
+
? window
|
|
211
|
+
: null;
|
|
212
|
+
if (target && typeof target.addEventListener === 'function') {
|
|
213
|
+
boundScrollEl = target;
|
|
214
|
+
boundScrollEl.addEventListener('scroll', onScroll, { passive: true });
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
bindHoverTarget();
|
|
219
|
+
bindScrollTarget();
|
|
220
|
+
|
|
221
|
+
function onDomReady() {
|
|
222
|
+
domReadyBound = false;
|
|
223
|
+
bindHoverTarget();
|
|
224
|
+
bindScrollTarget();
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
const needsDeferredBind =
|
|
228
|
+
(triggers.hasHover && !boundHoverEl) || (triggers.hasScroll && !boundScrollEl);
|
|
229
|
+
|
|
230
|
+
if (
|
|
231
|
+
needsDeferredBind &&
|
|
232
|
+
typeof document !== 'undefined' &&
|
|
233
|
+
document.readyState === 'loading' &&
|
|
234
|
+
typeof document.addEventListener === 'function'
|
|
235
|
+
) {
|
|
236
|
+
domReadyBound = true;
|
|
237
|
+
document.addEventListener('DOMContentLoaded', onDomReady, { once: true });
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
function notifyManualExit() {
|
|
241
|
+
if (destroyed) return;
|
|
242
|
+
clearHoverTimer();
|
|
243
|
+
enterSeq += 1;
|
|
244
|
+
pendingExitSeq = null;
|
|
245
|
+
if (suppressOnManualExit) {
|
|
246
|
+
if (isHovered) suppressed.hover = true;
|
|
247
|
+
if (isScrollPastThreshold()) suppressed.scroll = true;
|
|
248
|
+
}
|
|
249
|
+
activeSource = null;
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
function destroy() {
|
|
253
|
+
if (destroyed) return;
|
|
254
|
+
destroyed = true;
|
|
255
|
+
clearHoverTimer();
|
|
256
|
+
enterSeq += 1;
|
|
257
|
+
pendingExitSeq = null;
|
|
258
|
+
if (
|
|
259
|
+
domReadyBound &&
|
|
260
|
+
typeof document !== 'undefined' &&
|
|
261
|
+
typeof document.removeEventListener === 'function'
|
|
262
|
+
) {
|
|
263
|
+
document.removeEventListener('DOMContentLoaded', onDomReady);
|
|
264
|
+
domReadyBound = false;
|
|
265
|
+
}
|
|
266
|
+
if (boundHoverEl && typeof boundHoverEl.removeEventListener === 'function') {
|
|
267
|
+
boundHoverEl.removeEventListener('mouseenter', onMouseEnter);
|
|
268
|
+
boundHoverEl.removeEventListener('mouseleave', onMouseLeave);
|
|
269
|
+
}
|
|
270
|
+
boundHoverEl = null;
|
|
271
|
+
if (boundScrollEl && typeof boundScrollEl.removeEventListener === 'function') {
|
|
272
|
+
boundScrollEl.removeEventListener('scroll', onScroll);
|
|
273
|
+
}
|
|
274
|
+
boundScrollEl = null;
|
|
275
|
+
activeSource = null;
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
return {
|
|
279
|
+
notifyManualExit,
|
|
280
|
+
destroy
|
|
281
|
+
};
|
|
282
|
+
}
|
package/src/utils.js
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Small, dependency-free helpers.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
export function isBrowser() {
|
|
6
|
+
return (
|
|
7
|
+
typeof window !== 'undefined' &&
|
|
8
|
+
typeof document !== 'undefined' &&
|
|
9
|
+
typeof document.createElement === 'function'
|
|
10
|
+
);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function isNode() {
|
|
14
|
+
return (
|
|
15
|
+
typeof process !== 'undefined' &&
|
|
16
|
+
!!(process.versions && process.versions.node) &&
|
|
17
|
+
!isBrowser()
|
|
18
|
+
);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export function isElectron() {
|
|
22
|
+
if (!isBrowser()) return false;
|
|
23
|
+
return !!(
|
|
24
|
+
(window.process && window.process.versions && window.process.versions.electron) ||
|
|
25
|
+
typeof window.fsNative !== 'undefined'
|
|
26
|
+
);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Wrap a function that may or may not return a Promise
|
|
31
|
+
* (older prefixed fullscreen methods don't return one).
|
|
32
|
+
*/
|
|
33
|
+
export function maybePromise(fn) {
|
|
34
|
+
return new Promise((resolve, reject) => {
|
|
35
|
+
try {
|
|
36
|
+
const result = fn();
|
|
37
|
+
if (result && typeof result.then === 'function') {
|
|
38
|
+
result.then(resolve, reject);
|
|
39
|
+
} else {
|
|
40
|
+
resolve(result);
|
|
41
|
+
}
|
|
42
|
+
} catch (err) {
|
|
43
|
+
reject(err);
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Call a function safely, swallow errors, forward to onError.
|
|
50
|
+
*/
|
|
51
|
+
export function safeCall(fn, onError) {
|
|
52
|
+
try {
|
|
53
|
+
return fn();
|
|
54
|
+
} catch (err) {
|
|
55
|
+
if (typeof onError === 'function') onError(err);
|
|
56
|
+
return undefined;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Detect a click/touch gesture from an event if the caller needs to know.
|
|
62
|
+
* (Engine itself does not require this; it's a helper for consumers.)
|
|
63
|
+
*/
|
|
64
|
+
export function isUserGesture(event) {
|
|
65
|
+
if (!event) return false;
|
|
66
|
+
return event.isTrusted === true;
|
|
67
|
+
}
|
package/src/vendor.js
ADDED
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Vendor / prefix detection for fullscreen APIs.
|
|
3
|
+
* Works in browsers; returns null in Node/SSR.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { isBrowser } from './utils.js';
|
|
7
|
+
|
|
8
|
+
const PREFIXES = ['webkit', 'moz', 'ms'];
|
|
9
|
+
|
|
10
|
+
function deriveVendorPrefix(reqMethod) {
|
|
11
|
+
if (!reqMethod) return '';
|
|
12
|
+
if (reqMethod.startsWith('webkit')) return 'webkit';
|
|
13
|
+
if (reqMethod.startsWith('moz')) return 'moz';
|
|
14
|
+
if (reqMethod.startsWith('ms')) return 'ms';
|
|
15
|
+
return '';
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export function detectEnvironment(root = null) {
|
|
19
|
+
if (!isBrowser()) return null;
|
|
20
|
+
|
|
21
|
+
const el = root || (typeof document !== 'undefined' ? document.documentElement : null);
|
|
22
|
+
if (!el) return null;
|
|
23
|
+
|
|
24
|
+
// request method
|
|
25
|
+
let request = null;
|
|
26
|
+
if (typeof el.requestFullscreen === 'function') request = 'requestFullscreen';
|
|
27
|
+
else {
|
|
28
|
+
for (const p of PREFIXES) {
|
|
29
|
+
const m = `${p}RequestFullscreen`;
|
|
30
|
+
const m2 = `${p}RequestFullScreen`; // Firefox older
|
|
31
|
+
if (typeof el[m] === 'function') { request = m; break; }
|
|
32
|
+
if (typeof el[m2] === 'function') { request = m2; break; }
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// exit method
|
|
37
|
+
let exit = null;
|
|
38
|
+
if (typeof document.exitFullscreen === 'function') exit = 'exitFullscreen';
|
|
39
|
+
else {
|
|
40
|
+
for (const p of PREFIXES) {
|
|
41
|
+
const m = `${p}ExitFullscreen`;
|
|
42
|
+
const m2 = `${p}CancelFullScreen`;
|
|
43
|
+
if (typeof document[m] === 'function') { exit = m; break; }
|
|
44
|
+
if (typeof document[m2] === 'function') { exit = m2; break; }
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// element property (who is fullscreen right now)
|
|
49
|
+
let elementProp = null;
|
|
50
|
+
for (const prop of [
|
|
51
|
+
'fullscreenElement',
|
|
52
|
+
'webkitFullscreenElement',
|
|
53
|
+
'mozFullScreenElement',
|
|
54
|
+
'msFullscreenElement'
|
|
55
|
+
]) {
|
|
56
|
+
if (prop in document) { elementProp = prop; break; }
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// enabled property (policy / iframe allowfullscreen check)
|
|
60
|
+
let enabledProp = null;
|
|
61
|
+
for (const prop of [
|
|
62
|
+
'fullscreenEnabled',
|
|
63
|
+
'webkitFullscreenEnabled',
|
|
64
|
+
'mozFullScreenEnabled',
|
|
65
|
+
'msFullscreenEnabled'
|
|
66
|
+
]) {
|
|
67
|
+
if (prop in document) { enabledProp = prop; break; }
|
|
68
|
+
}
|
|
69
|
+
const policyAllowed = enabledProp ? Boolean(document[enabledProp]) : true;
|
|
70
|
+
|
|
71
|
+
const vendorPrefix = deriveVendorPrefix(request);
|
|
72
|
+
|
|
73
|
+
// change event name
|
|
74
|
+
let changeEvent = null;
|
|
75
|
+
for (const evt of [
|
|
76
|
+
'fullscreenchange',
|
|
77
|
+
'webkitfullscreenchange',
|
|
78
|
+
'mozfullscreenchange',
|
|
79
|
+
'MSFullscreenChange',
|
|
80
|
+
'msfullscreenchange'
|
|
81
|
+
]) {
|
|
82
|
+
if (`on${evt}` in document) { changeEvent = evt; break; }
|
|
83
|
+
}
|
|
84
|
+
if (!changeEvent) {
|
|
85
|
+
if (vendorPrefix === 'webkit') changeEvent = 'webkitfullscreenchange';
|
|
86
|
+
else if (vendorPrefix === 'moz') changeEvent = 'mozfullscreenchange';
|
|
87
|
+
else if (vendorPrefix === 'ms') changeEvent = 'MSFullscreenChange';
|
|
88
|
+
else changeEvent = 'fullscreenchange';
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
// error event name
|
|
92
|
+
let errorEvent = null;
|
|
93
|
+
for (const evt of [
|
|
94
|
+
'fullscreenerror',
|
|
95
|
+
'webkitfullscreenerror',
|
|
96
|
+
'mozfullscreenerror',
|
|
97
|
+
'MSFullscreenError',
|
|
98
|
+
'msfullscreenerror'
|
|
99
|
+
]) {
|
|
100
|
+
if (`on${evt}` in document) { errorEvent = evt; break; }
|
|
101
|
+
}
|
|
102
|
+
if (!errorEvent) {
|
|
103
|
+
if (vendorPrefix === 'webkit') errorEvent = 'webkitfullscreenerror';
|
|
104
|
+
else if (vendorPrefix === 'moz') errorEvent = 'mozfullscreenerror';
|
|
105
|
+
else if (vendorPrefix === 'ms') errorEvent = 'MSFullscreenError';
|
|
106
|
+
else errorEvent = 'fullscreenerror';
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
return {
|
|
110
|
+
request,
|
|
111
|
+
exit,
|
|
112
|
+
elementProp,
|
|
113
|
+
enabledProp,
|
|
114
|
+
changeEvent,
|
|
115
|
+
errorEvent,
|
|
116
|
+
supported: !!(request && exit && elementProp && policyAllowed)
|
|
117
|
+
};
|
|
118
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
FullscreenGlobalConfig,
|
|
3
|
+
InitFullscreenContext,
|
|
4
|
+
ResolvedFullscreenConfig
|
|
5
|
+
} from './index.d.ts';
|
|
6
|
+
|
|
7
|
+
export {
|
|
8
|
+
PRESETS,
|
|
9
|
+
defineConfig,
|
|
10
|
+
resolveConfig,
|
|
11
|
+
initFullscreen
|
|
12
|
+
} from './index.d.ts';
|
|
13
|
+
|
|
14
|
+
export interface LoadConfigOptions {
|
|
15
|
+
required?: boolean;
|
|
16
|
+
overrides?: FullscreenGlobalConfig;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export interface LoadAndInitContext extends InitFullscreenContext {
|
|
20
|
+
required?: boolean;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export declare const CONFIG_FILES: readonly [
|
|
24
|
+
'fullscreen.config.js',
|
|
25
|
+
'fullscreen.config.mjs',
|
|
26
|
+
'fullscreen.config.cjs',
|
|
27
|
+
'fullscreen.config.json'
|
|
28
|
+
];
|
|
29
|
+
|
|
30
|
+
export function findConfigFile(cwd?: string): string | null;
|
|
31
|
+
|
|
32
|
+
export function loadConfig(
|
|
33
|
+
cwdOrPath?: string | LoadConfigOptions,
|
|
34
|
+
options?: LoadConfigOptions
|
|
35
|
+
): Promise<ResolvedFullscreenConfig>;
|
|
36
|
+
|
|
37
|
+
export function loadAndInit(
|
|
38
|
+
cwdOrPath?: string | LoadAndInitContext,
|
|
39
|
+
context?: LoadAndInitContext
|
|
40
|
+
): Promise<any>;
|