fullscreen-engine 1.0.0 → 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 +95 -49
- package/bin/fullscreen-engine.js +162 -0
- package/dist/adapters/electron.cjs +1 -1
- package/dist/adapters/electron.esm.js +1 -1
- package/dist/adapters/puppeteer.cjs +1 -1
- package/dist/adapters/puppeteer.esm.js +1 -1
- package/dist/adapters/ssr.cjs +1 -1
- package/dist/adapters/ssr.esm.js +1 -1
- 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 +507 -5
- 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 +511 -5
- package/dist/fullscreen.iife.js.map +1 -1
- package/dist/fullscreen.umd.cjs +511 -5
- 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/config-loader.js +114 -0
- package/src/config.js +180 -0
- package/src/index.js +2 -1
- package/types/config.d.ts +40 -0
- package/types/index.d.ts +55 -0
package/README.md
CHANGED
|
@@ -2,12 +2,12 @@
|
|
|
2
2
|
|
|
3
3
|
**Zero-dependency, headless fullscreen control engine for Browsers, Electron, Node.js (Puppeteer/CDP), and SSR.**
|
|
4
4
|
|
|
5
|
-
[](package.json)
|
|
6
6
|
[](package.json)
|
|
7
7
|
[](package.json)
|
|
8
8
|
[](rollup.config.js)
|
|
9
9
|
|
|
10
|
-
`fullscreen-engine` is a pure, deterministic control layer (**no UI, no pages, no demos**) that unifies W3C & vendor-prefixed DOM Fullscreen APIs, Electron `contextBridge` IPC, Chrome DevTools Protocol (Puppeteer), CSS viewport-fill fallback, hover/scroll auto-triggers,
|
|
10
|
+
`fullscreen-engine` is a pure, deterministic control layer (**no UI, no pages, no demos**) that unifies W3C & vendor-prefixed DOM Fullscreen APIs, Electron `contextBridge` IPC, Chrome DevTools Protocol (Puppeteer), CSS viewport-fill fallback, hover/scroll auto-triggers, Kiosk auto-relock/exit-blocking, and a single-file global config (`fullscreen.config.js`) behind one lightweight TypeScript-typed API.
|
|
11
11
|
|
|
12
12
|
---
|
|
13
13
|
|
|
@@ -20,6 +20,7 @@
|
|
|
20
20
|
| **Electron Renderer** | `window.fsNative` IPC bridge (`set`/`get`/`onChange`) | Yes (gesture-free IPC) | Yes (`delay`/`maxRetries` guard) | `fullscreen-engine` or `fullscreen-engine/adapters/electron` |
|
|
21
21
|
| **Node.js + Puppeteer** | CDP `Browser.setWindowBounds` / `getWindowBounds` | N/A | `preventExit`, `unlock()`, `relock()` | `fullscreen-engine/adapters/puppeteer` |
|
|
22
22
|
| **SSR / Node.js** | Import-safe no-op controller (`request`/`toggle` reject) | Safe no-op | N/A | `fullscreen-engine/adapters/ssr` |
|
|
23
|
+
| **Global Config & CLI** | `fullscreen.config.{js,mjs,cjs,json}` + `npx fullscreen-engine init` | Preset-driven (`default`, `kiosk`, `presentation`, `strict`) | Configured once in `fullscreen.config.js` | `fullscreen-engine` & `fullscreen-engine/config` |
|
|
23
24
|
|
|
24
25
|
---
|
|
25
26
|
|
|
@@ -33,6 +34,51 @@ Supports **ESM (`import`)**, **CommonJS (`require`)**, **UMD**, **IIFE**, and **
|
|
|
33
34
|
|
|
34
35
|
---
|
|
35
36
|
|
|
37
|
+
## Global Config (`fullscreen.config.js`) — Configure Once, Use Anywhere
|
|
38
|
+
|
|
39
|
+
Generate a starter config in any project root without touching engine internals:
|
|
40
|
+
|
|
41
|
+
```bash
|
|
42
|
+
npx fullscreen-engine init --preset kiosk
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
```js
|
|
46
|
+
// fullscreen.config.js
|
|
47
|
+
import { defineConfig } from 'fullscreen-engine';
|
|
48
|
+
|
|
49
|
+
export default defineConfig({
|
|
50
|
+
mode: 'kiosk', // 'default' | 'kiosk' | 'presentation' | 'strict'
|
|
51
|
+
core: {
|
|
52
|
+
fallback: 'css',
|
|
53
|
+
lockBody: true
|
|
54
|
+
},
|
|
55
|
+
adapters: {
|
|
56
|
+
electron: { autoRelock: true, preventExit: true },
|
|
57
|
+
puppeteer: { restoreState: 'normal', preventExit: true },
|
|
58
|
+
ssr: { enabled: true }
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
Initialize from the config in **Browser / React / Next.js**:
|
|
64
|
+
|
|
65
|
+
```js
|
|
66
|
+
import { initFullscreen } from 'fullscreen-engine';
|
|
67
|
+
import config from './fullscreen.config.js';
|
|
68
|
+
|
|
69
|
+
const fs = initFullscreen(config, { target: document.getElementById('app') });
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
Or auto-discover `fullscreen.config.{js,mjs,cjs,json}` in **Node.js / Electron / Puppeteer**:
|
|
73
|
+
|
|
74
|
+
```js
|
|
75
|
+
import { loadAndInit } from 'fullscreen-engine/config';
|
|
76
|
+
|
|
77
|
+
const fs = await loadAndInit({ page }); // or { bridge } / process.cwd()
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
---
|
|
81
|
+
|
|
36
82
|
## Quickstart: Browser & CSS Fallback
|
|
37
83
|
|
|
38
84
|
```js
|
|
@@ -79,68 +125,61 @@ const fs = createFullscreen({
|
|
|
79
125
|
|
|
80
126
|
## Kiosk Mode: `autoRelock`, `preventExit` & `unlock()`
|
|
81
127
|
|
|
82
|
-
Lock fullscreen
|
|
128
|
+
Lock fullscreen against accidental `Escape` exits or programmatic `exit()` calls until `unlock()` is invoked:
|
|
83
129
|
|
|
84
130
|
```js
|
|
131
|
+
import { createFullscreen } from 'fullscreen-engine';
|
|
132
|
+
|
|
85
133
|
const fs = createFullscreen({
|
|
86
134
|
fallback: 'css',
|
|
87
|
-
autoRelock: { delay: 50, maxRetries: 3 },
|
|
135
|
+
autoRelock: { enabled: true, delay: 50, maxRetries: 3 },
|
|
88
136
|
preventExit: true,
|
|
89
137
|
onError: (err) => console.warn(err.message)
|
|
90
138
|
});
|
|
91
139
|
|
|
92
140
|
await fs.request();
|
|
93
141
|
|
|
94
|
-
//
|
|
142
|
+
// Later, when an operator exits kiosk mode:
|
|
95
143
|
fs.unlock();
|
|
96
144
|
await fs.exit();
|
|
97
145
|
```
|
|
98
146
|
|
|
99
147
|
---
|
|
100
148
|
|
|
101
|
-
## Electron
|
|
149
|
+
## Electron Bridge (`fullscreen-engine/adapters/electron`)
|
|
102
150
|
|
|
103
151
|
```js
|
|
104
|
-
// preload.js
|
|
152
|
+
// preload.js (Electron main/preload)
|
|
105
153
|
const { contextBridge, ipcRenderer } = require('electron');
|
|
106
154
|
|
|
107
155
|
contextBridge.exposeInMainWorld('fsNative', {
|
|
108
156
|
set: (on) => ipcRenderer.invoke('fs:set', on),
|
|
109
157
|
get: () => ipcRenderer.invoke('fs:get'),
|
|
110
158
|
onChange: (cb) => {
|
|
111
|
-
const handler = (
|
|
112
|
-
ipcRenderer.on('fs:
|
|
113
|
-
return () => ipcRenderer.removeListener('fs:
|
|
159
|
+
const handler = (_evt, on) => cb(on);
|
|
160
|
+
ipcRenderer.on('fs:change', handler);
|
|
161
|
+
return () => ipcRenderer.removeListener('fs:change', handler);
|
|
114
162
|
}
|
|
115
163
|
});
|
|
164
|
+
```
|
|
116
165
|
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
if (!win) return false;
|
|
121
|
-
win.setFullScreen(!!on);
|
|
122
|
-
return win.isFullScreen();
|
|
123
|
-
});
|
|
166
|
+
```js
|
|
167
|
+
// renderer.js
|
|
168
|
+
import { createElectronFullscreen } from 'fullscreen-engine/adapters/electron';
|
|
124
169
|
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
170
|
+
const fs = createElectronFullscreen(window.fsNative, {
|
|
171
|
+
autoRelock: true,
|
|
172
|
+
preventExit: true
|
|
128
173
|
});
|
|
129
174
|
|
|
130
|
-
function bindWindowEvents(win) {
|
|
131
|
-
win.on('enter-full-screen', () => win.webContents.send('fs:changed', true));
|
|
132
|
-
win.on('leave-full-screen', () => win.webContents.send('fs:changed', false));
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
// renderer.js
|
|
136
|
-
import { createFullscreen } from 'fullscreen-engine';
|
|
137
|
-
const fs = createFullscreen({ autoDetectElectron: true });
|
|
138
175
|
await fs.request();
|
|
176
|
+
// fs.relock() re-locks preventExit and enters fullscreen
|
|
177
|
+
// fs.unlock() releases preventExit and clears pending relock timers
|
|
139
178
|
```
|
|
140
179
|
|
|
141
180
|
---
|
|
142
181
|
|
|
143
|
-
## Node.js + Puppeteer
|
|
182
|
+
## Node.js + Puppeteer / CDP (`fullscreen-engine/adapters/puppeteer`)
|
|
144
183
|
|
|
145
184
|
```js
|
|
146
185
|
import puppeteer from 'puppeteer';
|
|
@@ -148,40 +187,47 @@ import { createPuppeteerFullscreen } from 'fullscreen-engine/adapters/puppeteer'
|
|
|
148
187
|
|
|
149
188
|
const browser = await puppeteer.launch({ headless: false });
|
|
150
189
|
const page = await browser.newPage();
|
|
151
|
-
const ctl = createPuppeteerFullscreen(page, { restoreState: 'normal', preventExit: false });
|
|
152
190
|
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
```
|
|
191
|
+
const fs = createPuppeteerFullscreen(page, {
|
|
192
|
+
restoreState: 'normal', // 'normal' | 'maximized' | 'minimized'
|
|
193
|
+
preventExit: false
|
|
194
|
+
});
|
|
158
195
|
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
196
|
+
await fs.request();
|
|
197
|
+
await fs.exit();
|
|
198
|
+
await fs.destroy();
|
|
162
199
|
```
|
|
163
200
|
|
|
164
201
|
---
|
|
165
202
|
|
|
166
|
-
##
|
|
203
|
+
## SSR Safety (`fullscreen-engine/adapters/ssr`)
|
|
167
204
|
|
|
168
|
-
-
|
|
169
|
-
- **Events:** `change`, `enter`, `exit`, `error`
|
|
170
|
-
- **Options:** `target`, `fallback`, `fallbackClass`, `lockBody`, `zIndex`, `onError`, `autoDetectElectron`, `trigger`, `hoverTarget`, `hoverDelay`, `scrollTarget`, `scrollThreshold`, `autoExit`, `suppressOnManualExit`, `autoRelock`, `preventExit`
|
|
171
|
-
- **Helpers:** `detectEnvironment(root?)`, `isBrowser()`, `isNode()`, `isElectron()`, `Emitter`
|
|
205
|
+
Importing `fullscreen-engine` in Node.js or SSR frameworks (Next.js, Nuxt, Remix) is safe out of the box. For explicit no-op stubs in template environments:
|
|
172
206
|
|
|
173
|
-
|
|
207
|
+
```js
|
|
208
|
+
import { createFullscreen } from 'fullscreen-engine/adapters/ssr';
|
|
209
|
+
```
|
|
174
210
|
|
|
175
211
|
---
|
|
176
212
|
|
|
177
|
-
##
|
|
213
|
+
## API Overview
|
|
178
214
|
|
|
179
|
-
-
|
|
180
|
-
-
|
|
181
|
-
-
|
|
215
|
+
- **Main (`fullscreen-engine`):** `createFullscreen`, `defineConfig`, `resolveConfig`, `initFullscreen`, `PRESETS`, `detectEnvironment`, `Emitter`, `isBrowser`, `isNode`, `isElectron`
|
|
216
|
+
- **Config Loader (`fullscreen-engine/config`):** `CONFIG_FILES`, `findConfigFile`, `loadConfig`, `loadAndInit`, `PRESETS`, `defineConfig`, `resolveConfig`, `initFullscreen`
|
|
217
|
+
- **Controller Methods:** `request()`, `exit()`, `toggle()`, `unlock()`, `isActive()`, `isSupported()`, `isFallback()`, `getState()`, `on()`, `once()`, `off()`, `destroy()` (plus `relock()` on Electron & Puppeteer adapters)
|
|
218
|
+
- **CLI:** `npx fullscreen-engine init [--preset default|kiosk|presentation|strict] [--esm|--cjs|--json] [--force]`
|
|
219
|
+
- **Full Developer Documentation:** See [`docs/`](docs/index.md) (`docs/api/functions.md`, `docs/reference/configuration.md`, `docs/guides/advanced-usage.md`).
|
|
182
220
|
|
|
183
221
|
---
|
|
184
222
|
|
|
223
|
+
## Development
|
|
224
|
+
|
|
225
|
+
```bash
|
|
226
|
+
npm run lint
|
|
227
|
+
npm run build
|
|
228
|
+
npm test
|
|
229
|
+
```
|
|
230
|
+
|
|
185
231
|
## License
|
|
186
232
|
|
|
187
|
-
|
|
233
|
+
MIT
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* fullscreen-engine CLI
|
|
4
|
+
*
|
|
5
|
+
* Scaffolds a project-root fullscreen.config.{js,cjs,json} file so apps can
|
|
6
|
+
* configure all fullscreen, kiosk, auto-relock, and adapter features in one place.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import { existsSync, readFileSync, writeFileSync } from 'node:fs';
|
|
10
|
+
import { resolve } from 'node:path';
|
|
11
|
+
import { PRESETS } from '../src/config.js';
|
|
12
|
+
|
|
13
|
+
function printHelp() {
|
|
14
|
+
console.log(`fullscreen-engine CLI
|
|
15
|
+
|
|
16
|
+
Usage:
|
|
17
|
+
fullscreen-engine init [options]
|
|
18
|
+
|
|
19
|
+
Options:
|
|
20
|
+
--preset, --mode <name> Preset mode: default | kiosk | presentation | strict (default: "default")
|
|
21
|
+
--esm Generate ESM fullscreen.config.js
|
|
22
|
+
--cjs Generate CommonJS fullscreen.config.cjs
|
|
23
|
+
--json Generate JSON fullscreen.config.json
|
|
24
|
+
--force Overwrite an existing config file
|
|
25
|
+
-h, --help Show this help message`);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function isEsmProject(cwd) {
|
|
29
|
+
const pkgPath = resolve(cwd, 'package.json');
|
|
30
|
+
if (!existsSync(pkgPath)) return false;
|
|
31
|
+
try {
|
|
32
|
+
const pkg = JSON.parse(readFileSync(pkgPath, 'utf8'));
|
|
33
|
+
return pkg.type === 'module';
|
|
34
|
+
} catch {
|
|
35
|
+
return false;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function buildTemplate(format, mode) {
|
|
40
|
+
if (format === 'json') {
|
|
41
|
+
return (
|
|
42
|
+
JSON.stringify(
|
|
43
|
+
{
|
|
44
|
+
mode,
|
|
45
|
+
core: {
|
|
46
|
+
fallback: 'css',
|
|
47
|
+
lockBody: true
|
|
48
|
+
},
|
|
49
|
+
adapters: {
|
|
50
|
+
electron: {},
|
|
51
|
+
puppeteer: { restoreState: 'normal' },
|
|
52
|
+
ssr: { enabled: true }
|
|
53
|
+
}
|
|
54
|
+
},
|
|
55
|
+
null,
|
|
56
|
+
2
|
|
57
|
+
) + '\n'
|
|
58
|
+
);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const body = `{
|
|
62
|
+
// Preset mode: 'default' | 'kiosk' | 'presentation' | 'strict'
|
|
63
|
+
mode: '${mode}',
|
|
64
|
+
|
|
65
|
+
// Core browser / renderer options
|
|
66
|
+
core: {
|
|
67
|
+
fallback: 'css',
|
|
68
|
+
lockBody: true
|
|
69
|
+
},
|
|
70
|
+
|
|
71
|
+
// Adapter-specific overrides
|
|
72
|
+
adapters: {
|
|
73
|
+
electron: {},
|
|
74
|
+
puppeteer: {
|
|
75
|
+
restoreState: 'normal'
|
|
76
|
+
},
|
|
77
|
+
ssr: {
|
|
78
|
+
enabled: true
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}`;
|
|
82
|
+
|
|
83
|
+
if (format === 'cjs') {
|
|
84
|
+
return `/** @type {import('fullscreen-engine').FullscreenGlobalConfig} */\nmodule.exports = ${body};\n`;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
return `import { defineConfig } from 'fullscreen-engine';\n\nexport default defineConfig(${body});\n`;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
function main(argv) {
|
|
91
|
+
const args = argv.slice(2);
|
|
92
|
+
if (args.length === 0 || args.includes('-h') || args.includes('--help')) {
|
|
93
|
+
printHelp();
|
|
94
|
+
process.exit(0);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
const command = args[0];
|
|
98
|
+
if (command !== 'init') {
|
|
99
|
+
console.error(`[fullscreen-engine] Unknown command: "${command}"`);
|
|
100
|
+
printHelp();
|
|
101
|
+
process.exit(1);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
let mode = 'default';
|
|
105
|
+
let format = null;
|
|
106
|
+
let force = false;
|
|
107
|
+
|
|
108
|
+
for (let i = 1; i < args.length; i += 1) {
|
|
109
|
+
const arg = args[i];
|
|
110
|
+
if (arg === '--force') {
|
|
111
|
+
force = true;
|
|
112
|
+
} else if (arg === '--esm') {
|
|
113
|
+
format = 'esm';
|
|
114
|
+
} else if (arg === '--cjs') {
|
|
115
|
+
format = 'cjs';
|
|
116
|
+
} else if (arg === '--json') {
|
|
117
|
+
format = 'json';
|
|
118
|
+
} else if (arg === '--preset' || arg === '--mode') {
|
|
119
|
+
const next = args[i + 1];
|
|
120
|
+
if (!next || next.startsWith('-')) {
|
|
121
|
+
console.error(`[fullscreen-engine] Missing value for ${arg}`);
|
|
122
|
+
process.exit(1);
|
|
123
|
+
}
|
|
124
|
+
mode = next;
|
|
125
|
+
i += 1;
|
|
126
|
+
} else if (arg.startsWith('--preset=') || arg.startsWith('--mode=')) {
|
|
127
|
+
mode = arg.split('=')[1];
|
|
128
|
+
} else {
|
|
129
|
+
console.error(`[fullscreen-engine] Unknown option: "${arg}"`);
|
|
130
|
+
process.exit(1);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
if (!(mode in PRESETS)) {
|
|
135
|
+
console.error(
|
|
136
|
+
`[fullscreen-engine] Invalid preset "${mode}". Expected one of: ${Object.keys(PRESETS).join(', ')}`
|
|
137
|
+
);
|
|
138
|
+
process.exit(1);
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
const cwd = process.cwd();
|
|
142
|
+
const resolvedFormat = format || (isEsmProject(cwd) ? 'esm' : 'cjs');
|
|
143
|
+
const filename =
|
|
144
|
+
resolvedFormat === 'json'
|
|
145
|
+
? 'fullscreen.config.json'
|
|
146
|
+
: resolvedFormat === 'cjs'
|
|
147
|
+
? 'fullscreen.config.cjs'
|
|
148
|
+
: 'fullscreen.config.js';
|
|
149
|
+
|
|
150
|
+
const targetPath = resolve(cwd, filename);
|
|
151
|
+
if (existsSync(targetPath) && !force) {
|
|
152
|
+
console.error(
|
|
153
|
+
`[fullscreen-engine] ${filename} already exists. Use --force to overwrite.`
|
|
154
|
+
);
|
|
155
|
+
process.exit(1);
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
writeFileSync(targetPath, buildTemplate(resolvedFormat, mode), 'utf8');
|
|
159
|
+
console.log(`[fullscreen-engine] Created ${filename} (mode: ${mode})`);
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
main(process.argv);
|
package/dist/adapters/ssr.cjs
CHANGED
package/dist/adapters/ssr.esm.js
CHANGED