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.
Files changed (46) hide show
  1. package/README.md +232 -2
  2. package/bin/fullscreen-engine.js +162 -0
  3. package/dist/adapters/electron.cjs +249 -0
  4. package/dist/adapters/electron.cjs.map +1 -0
  5. package/dist/adapters/electron.esm.js +247 -0
  6. package/dist/adapters/electron.esm.js.map +1 -0
  7. package/dist/adapters/puppeteer.cjs +125 -0
  8. package/dist/adapters/puppeteer.cjs.map +1 -0
  9. package/dist/adapters/puppeteer.esm.js +123 -0
  10. package/dist/adapters/puppeteer.esm.js.map +1 -0
  11. package/dist/adapters/ssr.cjs +31 -0
  12. package/dist/adapters/ssr.cjs.map +1 -0
  13. package/dist/adapters/ssr.esm.js +29 -0
  14. package/dist/adapters/ssr.esm.js.map +1 -0
  15. package/dist/config.cjs +1789 -0
  16. package/dist/config.cjs.map +1 -0
  17. package/dist/config.esm.js +1783 -0
  18. package/dist/config.esm.js.map +1 -0
  19. package/dist/fullscreen.esm.js +1673 -0
  20. package/dist/fullscreen.esm.js.map +1 -0
  21. package/dist/fullscreen.esm.min.js +3 -0
  22. package/dist/fullscreen.esm.min.js.map +1 -0
  23. package/dist/fullscreen.iife.js +1689 -0
  24. package/dist/fullscreen.iife.js.map +1 -0
  25. package/dist/fullscreen.umd.cjs +1690 -0
  26. package/dist/fullscreen.umd.cjs.map +1 -0
  27. package/dist/fullscreen.umd.min.cjs +3 -0
  28. package/dist/fullscreen.umd.min.cjs.map +1 -0
  29. package/package.json +82 -4
  30. package/src/adapters/electron.js +180 -0
  31. package/src/adapters/puppeteer.js +119 -0
  32. package/src/adapters/ssr.js +25 -0
  33. package/src/config-loader.js +114 -0
  34. package/src/config.js +180 -0
  35. package/src/core.js +524 -0
  36. package/src/events.js +63 -0
  37. package/src/fallback.js +136 -0
  38. package/src/index.js +23 -0
  39. package/src/triggers.js +282 -0
  40. package/src/utils.js +67 -0
  41. package/src/vendor.js +118 -0
  42. package/types/config.d.ts +40 -0
  43. package/types/electron.d.ts +45 -0
  44. package/types/index.d.ts +161 -0
  45. package/types/puppeteer.d.ts +23 -0
  46. package/types/ssr.d.ts +22 -0
@@ -0,0 +1,180 @@
1
+ /**
2
+ * Electron renderer-side adapter.
3
+ *
4
+ * Provide this on the renderer via contextBridge (window.fsNative).
5
+ */
6
+
7
+ import { Emitter } from '../events.js';
8
+
9
+ function normalizeAutoRelock(val) {
10
+ if (val === undefined || val === null || val === false) {
11
+ return { enabled: false, delay: 50, maxRetries: 3 };
12
+ }
13
+ if (val === true) {
14
+ return { enabled: true, delay: 50, maxRetries: 3 };
15
+ }
16
+ if (typeof val === 'object') {
17
+ const delayNum = Number(val.delay);
18
+ const retriesNum = Number(val.maxRetries);
19
+ return {
20
+ enabled: val.enabled ?? true,
21
+ delay: Number.isFinite(delayNum) ? Math.max(0, delayNum) : 50,
22
+ maxRetries: Number.isFinite(retriesNum) ? Math.max(1, Math.trunc(retriesNum)) : 3
23
+ };
24
+ }
25
+ throw new TypeError('[fullscreen-engine/electron] invalid autoRelock option: expected boolean or object');
26
+ }
27
+
28
+ export function createElectronFullscreen(bridge, opts = {}) {
29
+ if (!bridge || typeof bridge.set !== 'function') {
30
+ throw new Error('[fullscreen-engine/electron] bridge with .set() required');
31
+ }
32
+
33
+ const relockConfig = normalizeAutoRelock(opts.autoRelock);
34
+ const onError = typeof opts.onError === 'function' ? opts.onError : null;
35
+ const emitter = new Emitter();
36
+ let active = false;
37
+ let destroyed = false;
38
+ let unsubscribe = null;
39
+ let exitLocked = !!opts.preventExit;
40
+ let manualUnlocking = false;
41
+ let relockTimer = null;
42
+ let relockRetries = 0;
43
+
44
+ function emitError(err) {
45
+ emitter.emit('error', err);
46
+ if (onError) onError(err);
47
+ }
48
+
49
+ function clearRelockTimer() {
50
+ if (relockTimer !== null) {
51
+ clearTimeout(relockTimer);
52
+ relockTimer = null;
53
+ }
54
+ }
55
+
56
+ function getState() {
57
+ return {
58
+ active,
59
+ source: active ? 'electron' : 'none',
60
+ element: null,
61
+ supported: true
62
+ };
63
+ }
64
+
65
+ function scheduleRelock() {
66
+ if (destroyed || !relockConfig.enabled || manualUnlocking) return;
67
+ if (relockRetries >= relockConfig.maxRetries) {
68
+ emitError(new Error('[fullscreen-engine/electron] autoRelock failed after maxRetries'));
69
+ return;
70
+ }
71
+ clearRelockTimer();
72
+ relockTimer = setTimeout(() => {
73
+ relockTimer = null;
74
+ if (destroyed || !relockConfig.enabled || manualUnlocking || active) return;
75
+ relockRetries += 1;
76
+ request()
77
+ .catch((err) => {
78
+ emitError(err);
79
+ if (!destroyed && relockConfig.enabled && !manualUnlocking && !active) {
80
+ scheduleRelock();
81
+ }
82
+ });
83
+ }, relockConfig.delay);
84
+ }
85
+
86
+ function updateActive(next) {
87
+ const boolNext = !!next;
88
+ if (boolNext) {
89
+ relockRetries = 0;
90
+ clearRelockTimer();
91
+ }
92
+ if (boolNext === active) return;
93
+ const wasActive = active;
94
+ active = boolNext;
95
+ const state = getState();
96
+ emitter.emit('change', state);
97
+ if (active) emitter.emit('enter', state);
98
+ else {
99
+ emitter.emit('exit', state);
100
+ if (wasActive && relockConfig.enabled && !manualUnlocking) {
101
+ scheduleRelock();
102
+ }
103
+ }
104
+ }
105
+
106
+ if (typeof bridge.onChange === 'function') {
107
+ unsubscribe = bridge.onChange((on) => {
108
+ if (!destroyed) updateActive(on);
109
+ });
110
+ }
111
+
112
+ if (typeof bridge.get === 'function') {
113
+ Promise.resolve(bridge.get())
114
+ .then((on) => {
115
+ if (!destroyed) updateActive(on);
116
+ })
117
+ .catch(() => {});
118
+ }
119
+
120
+ async function request() {
121
+ if (destroyed) throw new Error('[fullscreen-engine/electron] destroyed');
122
+ manualUnlocking = false;
123
+ const res = await bridge.set(true);
124
+ if (res === false) {
125
+ throw new Error('[fullscreen-engine/electron] bridge.set(true) returned false');
126
+ }
127
+ updateActive(true);
128
+ }
129
+
130
+ async function exit() {
131
+ if (destroyed) throw new Error('[fullscreen-engine/electron] destroyed');
132
+ if (exitLocked) {
133
+ const err = new Error('[fullscreen-engine/electron] Exit blocked: preventExit is active');
134
+ emitError(err);
135
+ throw err;
136
+ }
137
+ const res = await bridge.set(false);
138
+ if (res === true) {
139
+ throw new Error('[fullscreen-engine/electron] bridge.set(false) failed to exit');
140
+ }
141
+ updateActive(false);
142
+ }
143
+
144
+ function unlock() {
145
+ exitLocked = false;
146
+ manualUnlocking = true;
147
+ clearRelockTimer();
148
+ relockRetries = 0;
149
+ }
150
+
151
+ async function relock() {
152
+ manualUnlocking = false;
153
+ return request();
154
+ }
155
+
156
+ return {
157
+ request,
158
+ exit,
159
+ async toggle() {
160
+ return active ? exit() : request();
161
+ },
162
+ unlock,
163
+ relock,
164
+ isActive() { return active; },
165
+ isSupported() { return true; },
166
+ getState,
167
+ on(event, cb) { return emitter.on(event, cb); },
168
+ once(event, cb) { return emitter.once(event, cb); },
169
+ off(event, cb) { return emitter.off(event, cb); },
170
+ destroy() {
171
+ if (destroyed) return;
172
+ destroyed = true;
173
+ clearRelockTimer();
174
+ if (typeof unsubscribe === 'function') unsubscribe();
175
+ unsubscribe = null;
176
+ active = false;
177
+ emitter.clear();
178
+ }
179
+ };
180
+ }
@@ -0,0 +1,119 @@
1
+ /**
2
+ * True backend fullscreen control from Node.js.
3
+ *
4
+ * Uses Chrome DevTools Protocol (CDP) via Puppeteer to control the
5
+ * browser window's fullscreen state. This works from a Node.js process.
6
+ */
7
+
8
+ export function createPuppeteerFullscreen(page, opts = {}) {
9
+ if (!page || typeof page.createCDPSession !== 'function') {
10
+ throw new Error('[fullscreen-engine/puppeteer] page with .createCDPSession() required');
11
+ }
12
+
13
+ let client = null;
14
+ let windowId = null;
15
+ let initPromise = null;
16
+ let active = false;
17
+ let destroyed = false;
18
+ let exitLocked = !!opts.preventExit;
19
+
20
+ async function ensure() {
21
+ if (destroyed) throw new Error('[fullscreen-engine/puppeteer] destroyed');
22
+ if (client && windowId !== null) return;
23
+ if (!initPromise) {
24
+ initPromise = (async () => {
25
+ let session = null;
26
+ try {
27
+ session = await page.createCDPSession();
28
+ const res = await session.send('Browser.getWindowForTarget');
29
+ if (destroyed) {
30
+ try { await session.detach(); } catch {}
31
+ throw new Error('[fullscreen-engine/puppeteer] destroyed');
32
+ }
33
+ client = session;
34
+ windowId = res.windowId;
35
+ } catch (err) {
36
+ if (session) {
37
+ try { await session.detach(); } catch {}
38
+ }
39
+ client = null;
40
+ windowId = null;
41
+ throw err;
42
+ } finally {
43
+ initPromise = null;
44
+ }
45
+ })();
46
+ }
47
+ return initPromise;
48
+ }
49
+
50
+ async function setState(state) {
51
+ if (destroyed) throw new Error('[fullscreen-engine/puppeteer] destroyed');
52
+ await ensure();
53
+ await client.send('Browser.setWindowBounds', {
54
+ windowId,
55
+ bounds: { windowState: state } // 'fullscreen' | 'normal' | 'minimized' | 'maximized'
56
+ });
57
+ active = state === 'fullscreen';
58
+ return active;
59
+ }
60
+
61
+ return {
62
+ async request() {
63
+ if (destroyed) throw new Error('[fullscreen-engine/puppeteer] destroyed');
64
+ if (active) return true;
65
+ return setState('fullscreen');
66
+ },
67
+ async exit() {
68
+ if (destroyed) throw new Error('[fullscreen-engine/puppeteer] destroyed');
69
+ if (exitLocked) {
70
+ throw new Error('[fullscreen-engine/puppeteer] Exit blocked: preventExit is active');
71
+ }
72
+ if (!active) {
73
+ const current = await this.getWindowState();
74
+ if (current !== 'fullscreen') return false;
75
+ }
76
+ return setState(opts.restoreState || 'normal');
77
+ },
78
+ async toggle() {
79
+ if (destroyed) throw new Error('[fullscreen-engine/puppeteer] destroyed');
80
+ const current = await this.getWindowState();
81
+ return current === 'fullscreen' ? this.exit() : this.request();
82
+ },
83
+ unlock() {
84
+ exitLocked = false;
85
+ },
86
+ async relock() {
87
+ if (destroyed) throw new Error('[fullscreen-engine/puppeteer] destroyed');
88
+ const current = await this.getWindowState();
89
+ if (current === 'fullscreen') return true;
90
+ return setState('fullscreen');
91
+ },
92
+ isActive() {
93
+ return active;
94
+ },
95
+ isSupported() {
96
+ return true;
97
+ },
98
+ async getWindowState() {
99
+ if (destroyed) throw new Error('[fullscreen-engine/puppeteer] destroyed');
100
+ await ensure();
101
+ const res = await client.send('Browser.getWindowBounds', { windowId });
102
+ const state = res.bounds.windowState;
103
+ active = state === 'fullscreen';
104
+ return state;
105
+ },
106
+ async destroy() {
107
+ if (destroyed) return;
108
+ destroyed = true;
109
+ if (initPromise) {
110
+ try { await initPromise; } catch {}
111
+ }
112
+ try { if (client) await client.detach(); } catch {}
113
+ client = null;
114
+ windowId = null;
115
+ initPromise = null;
116
+ active = false;
117
+ }
118
+ };
119
+ }
@@ -0,0 +1,25 @@
1
+ /**
2
+ * SSR / Node.js safe stub.
3
+ *
4
+ * Importing the main entry already works in Node (all guards are in place).
5
+ * But if you explicitly need a no-op controller (e.g. for template
6
+ * environments that can't tree-shake), use this:
7
+ *
8
+ * import { createFullscreen } from 'fullscreen-engine/adapters/ssr';
9
+ */
10
+
11
+ export function createFullscreen() {
12
+ return {
13
+ async request() { throw new Error('[fullscreen-engine/ssr] fullscreen unavailable in SSR'); },
14
+ async exit() {},
15
+ async toggle() { return this.request(); },
16
+ isActive() { return false; },
17
+ isSupported() { return false; },
18
+ isFallback() { return false; },
19
+ getState() { return { active: false, source: 'none', element: null, supported: false }; },
20
+ on() { return () => {}; },
21
+ once() { return () => {}; },
22
+ off() {},
23
+ destroy() {}
24
+ };
25
+ }
@@ -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,180 @@
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
+ autoRelock: Object.freeze({ enabled: true, delay: 50, maxRetries: 5 }),
103
+ preventExit: true,
104
+ suppressOnManualExit: true
105
+ }),
106
+ adapters: Object.freeze({
107
+ electron: Object.freeze({
108
+ autoRelock: Object.freeze({ enabled: true, delay: 50, maxRetries: 5 }),
109
+ preventExit: true
110
+ }),
111
+ puppeteer: Object.freeze({ preventExit: true }),
112
+ ssr: Object.freeze({ enabled: false })
113
+ })
114
+ })
115
+ });
116
+
117
+ export function defineConfig(config = {}) {
118
+ validateConfigShape(config, 'config');
119
+ return config;
120
+ }
121
+
122
+ export function resolveConfig(config = {}, overrides = {}) {
123
+ validateConfigShape(config, 'config');
124
+ validateConfigShape(overrides, 'overrides');
125
+
126
+ const mode = overrides.mode ?? config.mode ?? 'default';
127
+ const preset = PRESETS[mode];
128
+
129
+ const cfgAdapters = config.adapters || {};
130
+ const ovAdapters = overrides.adapters || {};
131
+
132
+ return {
133
+ mode,
134
+ core: mergeSection(mergeSection(preset.core, config.core), overrides.core),
135
+ adapters: {
136
+ electron: mergeSection(
137
+ mergeSection(preset.adapters.electron, cfgAdapters.electron),
138
+ ovAdapters.electron
139
+ ),
140
+ puppeteer: mergeSection(
141
+ mergeSection(preset.adapters.puppeteer, cfgAdapters.puppeteer),
142
+ ovAdapters.puppeteer
143
+ ),
144
+ ssr: mergeSection(
145
+ mergeSection(preset.adapters.ssr, cfgAdapters.ssr),
146
+ ovAdapters.ssr
147
+ )
148
+ }
149
+ };
150
+ }
151
+
152
+ export function initFullscreen(config = {}, context = {}) {
153
+ if (!isPlainObject(context)) {
154
+ throw new TypeError('[fullscreen-engine/config] context must be a plain object');
155
+ }
156
+
157
+ const resolved = resolveConfig(config, context.overrides || {});
158
+ if (context.target !== undefined) {
159
+ resolved.core.target = context.target;
160
+ }
161
+
162
+ if (context.bridge !== undefined || context.adapter === 'electron') {
163
+ const bridge =
164
+ context.bridge ?? (typeof window !== 'undefined' ? window.fsNative : null);
165
+ return createElectronFullscreen(bridge, resolved.adapters.electron);
166
+ }
167
+
168
+ if (context.page !== undefined || context.adapter === 'puppeteer') {
169
+ return createPuppeteerFullscreen(context.page, resolved.adapters.puppeteer);
170
+ }
171
+
172
+ if (context.adapter === 'ssr' || (isNode() && !isBrowser() && !isElectron())) {
173
+ if (resolved.adapters.ssr.enabled === false) {
174
+ throw new Error('[fullscreen-engine/config] SSR adapter is disabled by config');
175
+ }
176
+ return createSSRFullscreen();
177
+ }
178
+
179
+ return createFullscreen(resolved.core);
180
+ }