jsgui3-server 0.0.134 → 0.0.136
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/AGENTS.md +6 -0
- package/README.md +114 -18
- package/TODO.md +81 -0
- package/cli.js +96 -0
- package/docs/simple-server-api-design.md +702 -0
- package/examples/controls/14d) window, canvas globe/ARCBALL-README.md +146 -0
- package/examples/controls/14d) window, canvas globe/Clipping.js +0 -0
- package/examples/controls/14d) window, canvas globe/EarthGlobeRenderer.js +280 -799
- package/examples/controls/14d) window, canvas globe/RenderingPipeline.js +43 -0
- package/examples/controls/14d) window, canvas globe/arcball-drag-behaviour.js +250 -0
- package/examples/controls/14d) window, canvas globe/arcball-drag-behaviour.test.js +141 -0
- package/examples/controls/14d) window, canvas globe/drag-behaviour-base.js +70 -0
- package/examples/controls/14d) window, canvas globe/drag-controller.js +181 -0
- package/examples/controls/14d) window, canvas globe/math.test.js +281 -0
- package/examples/controls/14d) window, canvas globe/pipeline/BaseStage.js +46 -0
- package/examples/controls/14d) window, canvas globe/pipeline/ClippingStage.js +29 -0
- package/examples/controls/14d) window, canvas globe/pipeline/ComposeStage.js +15 -0
- package/examples/controls/14d) window, canvas globe/pipeline/ContinentsStage.js +116 -0
- package/examples/controls/14d) window, canvas globe/pipeline/GridStage.js +105 -0
- package/examples/controls/14d) window, canvas globe/pipeline/HUDStage.js +10 -0
- package/examples/controls/14d) window, canvas globe/pipeline/ShadeSphereStage.js +153 -0
- package/examples/controls/14d) window, canvas globe/pipeline/TransformStage.js +23 -0
- package/examples/controls/14d) window, canvas globe/pipeline/clipping/FrontFaceStrategy.js +46 -0
- package/examples/controls/14d) window, canvas globe/pipeline/clipping/PlaneClipStrategy.js +339 -0
- package/module.js +3 -1
- package/package.json +10 -4
- package/resources/_old_website-resource.js +10 -2
- package/resources/jsbuilder/babel/deep_iterate/deep_iterate_babel.js +37 -0
- package/resources/local-server-info-resource.js +1 -1
- package/serve-factory.js +221 -0
- package/serve-helpers.js +95 -0
- package/server.js +93 -7
- package/tests/cli.test.js +66 -0
- package/tests/dummy-client.js +10 -0
- package/tests/serve.test.js +210 -0
- package/.vscode/settings.json +0 -13
package/AGENTS.md
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
# Agent Guidelines
|
|
2
|
+
|
|
3
|
+
- Use `snake_case` for variables, functions, and helper utilities introduced by agents.
|
|
4
|
+
- Use `Snake_Case` (PascalCase) for classes and constructors.
|
|
5
|
+
- Update existing agent-authored code to match these conventions when you make changes.
|
|
6
|
+
- If you must diverge from this convention, document the reason directly in the relevant file.
|
package/README.md
CHANGED
|
@@ -1,6 +1,66 @@
|
|
|
1
1
|
# Jsgui3 Server
|
|
2
2
|
|
|
3
|
-
JSGUI3 Server is a
|
|
3
|
+
JSGUI3 Server is a Node.js-based application server for serving modern JavaScript GUI applications to web clients. It provides a complete runtime environment for delivering dynamic, component-based user interfaces with integrated data binding, event handling, and automatic CSS/JS bundling.
|
|
4
|
+
|
|
5
|
+
## Quick Start
|
|
6
|
+
|
|
7
|
+
### Simplest Possible Server
|
|
8
|
+
|
|
9
|
+
```javascript
|
|
10
|
+
// server.js
|
|
11
|
+
const Server = require('jsgui3-server');
|
|
12
|
+
const { MyControl } = require('./client').controls;
|
|
13
|
+
|
|
14
|
+
Server.serve(MyControl);
|
|
15
|
+
// Server runs at http://localhost:8080
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
### With Port Configuration
|
|
19
|
+
|
|
20
|
+
```javascript
|
|
21
|
+
Server.serve(MyControl, { port: 3000 });
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
### Single Page with Metadata
|
|
25
|
+
|
|
26
|
+
```javascript
|
|
27
|
+
Server.serve({
|
|
28
|
+
page: {
|
|
29
|
+
content: MyControl,
|
|
30
|
+
title: 'My Awesome App',
|
|
31
|
+
description: 'A jsgui3 application'
|
|
32
|
+
},
|
|
33
|
+
port: 3000
|
|
34
|
+
});
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
### Multiple Pages
|
|
38
|
+
|
|
39
|
+
```javascript
|
|
40
|
+
Server.serve({
|
|
41
|
+
pages: {
|
|
42
|
+
'/': { content: HomeControl, title: 'Home' },
|
|
43
|
+
'/about': { content: AboutControl, title: 'About' },
|
|
44
|
+
'/contact': { content: ContactControl, title: 'Contact' }
|
|
45
|
+
},
|
|
46
|
+
port: 3000
|
|
47
|
+
});
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
### With API Endpoints
|
|
51
|
+
|
|
52
|
+
```javascript
|
|
53
|
+
Server.serve({
|
|
54
|
+
page: { content: DashboardControl, title: 'Dashboard' },
|
|
55
|
+
api: {
|
|
56
|
+
'metrics': () => ({ users: 1234, revenue: 56789 }),
|
|
57
|
+
'data': async ({ range }) => await fetchAnalytics(range)
|
|
58
|
+
},
|
|
59
|
+
port: 3000
|
|
60
|
+
});
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
> **Note:** The new `Server.serve()` API is the recommended approach for most use cases. See [Simple Server API Design](docs/simple-server-api-design.md) for complete documentation and advanced features.
|
|
4
64
|
|
|
5
65
|
## Architecture Overview
|
|
6
66
|
|
|
@@ -10,6 +70,7 @@ The server operates as a bridge between server-side JavaScript applications and
|
|
|
10
70
|
- **Data Model Management:** Handles shared data objects and real-time synchronization between multiple UI controls
|
|
11
71
|
- **CSS Bundling:** Dynamically compiles and serves CSS from component definitions
|
|
12
72
|
- **Event Coordination:** Manages client-server event communication and state synchronization
|
|
73
|
+
- **Convention Over Configuration:** Smart defaults with auto-discovery of client files
|
|
13
74
|
|
|
14
75
|
## Core Components
|
|
15
76
|
|
|
@@ -88,22 +149,30 @@ Controls in JSGUI3 follow a strict composition pattern:
|
|
|
88
149
|
|
|
89
150
|
```javascript
|
|
90
151
|
// Basic control creation pattern
|
|
91
|
-
|
|
92
|
-
|
|
152
|
+
# Jsgui3 Server
|
|
153
|
+
JSGUI3 Server is a Node.js-based server for hosting JSGUI3 controls and example apps in the browser. It serves HTML/JS/CSS generated by controls and publishers. Some features are evolving; see Status for scope.
|
|
154
|
+
|
|
155
|
+
## Quick start
|
|
156
|
+
|
|
157
|
+
- Show help: `node cli.js --help`
|
|
158
|
+
- Run a server: `node cli.js serve --port 8080`
|
|
159
|
+
- NPM scripts: `npm run cli`, `npm run serve`, `npm test`
|
|
160
|
+
- Examples: many apps under `examples/controls/` include their own `server.js`; run those directly with Node.
|
|
93
161
|
// ... other properties
|
|
94
162
|
});
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
163
|
+
## Architecture overview
|
|
164
|
+
The server provides:
|
|
165
|
+
- **Component serving:** Serves JSGUI3 controls and example apps to browsers
|
|
166
|
+
- **Routing and publishers:** HTTP route handling via the resource pool and publishers
|
|
167
|
+
- **CSS handling:** Collects/serves control CSS where provided by publishers
|
|
99
168
|
```
|
|
100
169
|
|
|
101
|
-
|
|
170
|
+
Configuration is performed in code within this repo; there is no separate `server.config.js` by default.
|
|
102
171
|
- **Window:** Top-level container with title bar, positioning, and dragging capabilities
|
|
103
172
|
- **Tabbed_Panel:** Container organizing content into tabs, supports both string labels and [label, control] pairs
|
|
104
|
-
|
|
105
|
-
-
|
|
106
|
-
-
|
|
173
|
+
3. **Request handling:**
|
|
174
|
+
- Serves HTML/JS/CSS using publishers
|
|
175
|
+
- Injects/collects CSS from control definitions where applicable
|
|
107
176
|
|
|
108
177
|
### Data Model System Details
|
|
109
178
|
|
|
@@ -119,16 +188,43 @@ The data binding system is built on observable patterns:
|
|
|
119
188
|
2. **Control Binding:**
|
|
120
189
|
```javascript
|
|
121
190
|
const control = new SomeControl({
|
|
191
|
+
```
|
|
192
|
+
jsgui3-server/
|
|
193
|
+
├── examples/
|
|
194
|
+
│ └── controls/ # Many runnable control demos
|
|
195
|
+
├── controls/
|
|
196
|
+
│ └── Active_HTML_Document.js # Base control/document class
|
|
197
|
+
├── publishers/ # HTTP publishers (website, webpage, function, assets)
|
|
198
|
+
├── resources/ # Resource implementations
|
|
199
|
+
├── website/ # Website-related classes
|
|
200
|
+
├── server.js # Server class
|
|
201
|
+
└── cli.js # Minimal CLI (serve/help/version)
|
|
202
|
+
```
|
|
122
203
|
context,
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
204
|
+
### CSS bundling
|
|
205
|
+
|
|
206
|
+
CSS may be collected from control classes and served alongside pages by publishers. Exact bundling/minification behavior depends on the website/webpage publisher and is subject to change.
|
|
207
|
+
|
|
208
|
+
## CLI usage
|
|
209
|
+
|
|
210
|
+
- Help: `node cli.js --help`
|
|
211
|
+
- Version: `node cli.js --version`
|
|
212
|
+
- Serve: `node cli.js serve --port 8080 [--host 127.0.0.1]`
|
|
213
|
+
|
|
214
|
+
NPM scripts:
|
|
215
|
+
|
|
216
|
+
- `npm run cli` — runs the CLI
|
|
217
|
+
- `npm run serve` — starts the server via the CLI
|
|
218
|
+
- `npm test` — runs a small CLI test suite
|
|
219
|
+
|
|
220
|
+
VS Code task:
|
|
221
|
+
|
|
222
|
+
- “Test: CLI” task is available for easy test runs.
|
|
126
223
|
|
|
127
|
-
|
|
128
|
-
- Controls automatically register change handlers on their data models
|
|
129
|
-
- `assign_data_model_value_change_handler()` method reestablishes bindings
|
|
130
|
-
- Multiple controls can share the same model for synchronized updates
|
|
224
|
+
## Status
|
|
131
225
|
|
|
226
|
+
- Active work-in-progress. Some features are incomplete or evolving.
|
|
227
|
+
- A default holding page and streamlined admin experience are planned; see `TODO.md` and `roadmap.md`.
|
|
132
228
|
### File Structure and Conventions
|
|
133
229
|
|
|
134
230
|
```
|
package/TODO.md
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
# TODO
|
|
2
|
+
|
|
3
|
+
A living list of near-term work. PRs welcome.
|
|
4
|
+
|
|
5
|
+
## Now
|
|
6
|
+
- CLI wiring (no bin yet):
|
|
7
|
+
- File: `cli.js` at repo root.
|
|
8
|
+
- Commands:
|
|
9
|
+
- `node cli.js serve [--port <n>] [--host <name>] [--root <path>]`
|
|
10
|
+
- `node cli.js --help`
|
|
11
|
+
- `node cli.js --version`
|
|
12
|
+
- Behavior:
|
|
13
|
+
- Starts the HTTP server using `server.js` exports.
|
|
14
|
+
- Reads env overrides: `PORT`, `HOST`, `ROOT`.
|
|
15
|
+
- NPM scripts:
|
|
16
|
+
- "serve": `node cli.js serve`
|
|
17
|
+
- "cli": `node cli.js`
|
|
18
|
+
- Add basic CLI tests with Node child_process. Cover `--help`, `--version`, and `serve --port 0` (ephemeral port) smoke.
|
|
19
|
+
- VS Code Task: "Test: CLI" added to enable Always Allow.
|
|
20
|
+
|
|
21
|
+
- Controls suite (server-admin and general UI):
|
|
22
|
+
- Stabilize and complete core controls for HTML documents:
|
|
23
|
+
- Window (drag, z-order, resize), Panel, Tabbed_Panel
|
|
24
|
+
- Inputs: Text_Input, Checkbox, Select, Date_Picker, Month_View
|
|
25
|
+
- Menus: Menu, Menu_Button, Context_Menu
|
|
26
|
+
- Layout primitives: Grid/Stack/Flex helpers
|
|
27
|
+
- Patterns to standardize:
|
|
28
|
+
- Constructor/activate lifecycle, context registration, data model binding
|
|
29
|
+
- CSS as static property; shared themes; dark/light tokens
|
|
30
|
+
- Accessibility: keyboard focus, ARIA attributes for inputs/menus
|
|
31
|
+
- Documentation and demos:
|
|
32
|
+
- Refresh `/examples/controls/*` to cover each control
|
|
33
|
+
- Add an index demo page linking to all examples
|
|
34
|
+
- Testing:
|
|
35
|
+
- Minimal DOM-less unit tests for control logic (state transitions)
|
|
36
|
+
- Screenshot smoke tests for a few controls (optional later)
|
|
37
|
+
|
|
38
|
+
- Server startup reliability:
|
|
39
|
+
- Default holding page: serve a simple HTML page when no website content configured
|
|
40
|
+
- Website publisher wiring: resolve "Possibly missing website publishing code." path in `publishers/http-website-publisher.js`
|
|
41
|
+
- Emit clear ready signal from server (single "Server ready") once listeners are bound
|
|
42
|
+
- Bind default host: prefer 127.0.0.1 unless `--host` provided; option to bind all IPv4
|
|
43
|
+
- Ensure `/admin` route available by default with basic status panel
|
|
44
|
+
|
|
45
|
+
## Next
|
|
46
|
+
- Add watch/dev: `node cli.js dev` to run a website in watch mode (if applicable).
|
|
47
|
+
- Add config file support: jsgui.config.{js,json} and `--config`.
|
|
48
|
+
- Add logging levels: `--verbose`, `--quiet`.
|
|
49
|
+
- Add graceful shutdown: handle SIGINT/SIGTERM; print URL.
|
|
50
|
+
- Document options in README.
|
|
51
|
+
|
|
52
|
+
- Tests robustness (Windows):
|
|
53
|
+
- Make CLI serve smoke tolerant to process termination exit codes on Windows (child.kill may yield code 1)
|
|
54
|
+
- Prefer asserting on explicit "Server ready" line once implemented, and remove fallback matches
|
|
55
|
+
|
|
56
|
+
- Admin app and file manager:
|
|
57
|
+
- Default admin UI available at `/admin` (protected later)
|
|
58
|
+
- Status panel: routes, publishers, website pages, resource pool summary
|
|
59
|
+
- File manager (local FS resource) to browse/serve a selected directory
|
|
60
|
+
- Quick start flow: pick a folder to serve; set index file; hot reload optional
|
|
61
|
+
|
|
62
|
+
- CSS bundling tidy-up:
|
|
63
|
+
- Ensure CSS is bundled once from all control classes
|
|
64
|
+
- Fix legacy bundle paths; remove dead code (see NYI markers)
|
|
65
|
+
|
|
66
|
+
## Later
|
|
67
|
+
- Package as a real CLI (bin) when UX is stable.
|
|
68
|
+
- E2E tests with a sample website directory fixture.
|
|
69
|
+
- Optional: Windows service or PM2 integration for production.
|
|
70
|
+
|
|
71
|
+
- Deployment workflows:
|
|
72
|
+
- `jsgui3-website` deploy function; multi-target hosting options
|
|
73
|
+
- Wizard for first-time deployment
|
|
74
|
+
|
|
75
|
+
## Implementation notes
|
|
76
|
+
- Keep CLI self-contained and dependency-free.
|
|
77
|
+
- Parse argv manually to avoid adding libs.
|
|
78
|
+
- Respect Windows PowerShell usage; scripts should run on Windows/macOS/Linux.
|
|
79
|
+
- Expose a tiny contract from `server.js`:
|
|
80
|
+
- Prefer a function `startServer(opts): { server, url, stop() }`.
|
|
81
|
+
- If absent, require and invoke existing start method.
|
package/cli.js
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
// Minimal CLI wiring without a bin entry. No external deps.
|
|
4
|
+
// Commands:
|
|
5
|
+
// node cli.js --help | --version
|
|
6
|
+
// node cli.js serve [--port <n>] [--host <addr>] [--root <path>]
|
|
7
|
+
|
|
8
|
+
const fs = require('fs');
|
|
9
|
+
const path = require('path');
|
|
10
|
+
|
|
11
|
+
function readPkg() {
|
|
12
|
+
try {
|
|
13
|
+
const pkgPath = path.join(__dirname, 'package.json');
|
|
14
|
+
const txt = fs.readFileSync(pkgPath, 'utf8');
|
|
15
|
+
return JSON.parse(txt);
|
|
16
|
+
} catch (e) {
|
|
17
|
+
return { name: 'jsgui3-server', version: '0.0.0' };
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function printHelp() {
|
|
22
|
+
const pkg = readPkg();
|
|
23
|
+
const name = pkg.name || 'jsgui3-server';
|
|
24
|
+
console.log(`${name} ${pkg.version || ''}`.trim());
|
|
25
|
+
console.log('');
|
|
26
|
+
console.log('Usage:');
|
|
27
|
+
console.log(' node cli.js --help');
|
|
28
|
+
console.log(' node cli.js --version');
|
|
29
|
+
console.log(' node cli.js serve [--port <n>] [--host <addr>] [--root <path>]');
|
|
30
|
+
console.log('');
|
|
31
|
+
console.log('Options:');
|
|
32
|
+
console.log(' --port <n> Port number (default 8080; 0 = ephemeral)');
|
|
33
|
+
console.log(' --host <addr> Bind to specific IPv4 address (eg 127.0.0.1)');
|
|
34
|
+
console.log(' --root <path> Project root (reserved; not yet wired)');
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function parseArgs(argv) {
|
|
38
|
+
const out = { _: [] };
|
|
39
|
+
for (let i = 0; i < argv.length; i++) {
|
|
40
|
+
const a = argv[i];
|
|
41
|
+
if (a === '--help' || a === '-h') out.help = true;
|
|
42
|
+
else if (a === '--version' || a === '-v') out.version = true;
|
|
43
|
+
else if (a === '--port') { out.port = Number(argv[++i]); }
|
|
44
|
+
else if (a === '--host') { out.host = argv[++i]; }
|
|
45
|
+
else if (a === '--root') { out.root = argv[++i]; }
|
|
46
|
+
else if (!a.startsWith('-')) out._.push(a);
|
|
47
|
+
else {
|
|
48
|
+
console.error('Unknown option:', a);
|
|
49
|
+
out.help = true;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
return out;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function main() {
|
|
56
|
+
const argv = process.argv.slice(2);
|
|
57
|
+
const args = parseArgs(argv);
|
|
58
|
+
const cmd = args._[0];
|
|
59
|
+
|
|
60
|
+
if (args.help || (!cmd && !args.version)) {
|
|
61
|
+
printHelp();
|
|
62
|
+
process.exit(0);
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
if (args.version) {
|
|
67
|
+
const pkg = readPkg();
|
|
68
|
+
console.log(pkg.version || '0.0.0');
|
|
69
|
+
process.exit(0);
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
if (cmd === 'serve') {
|
|
74
|
+
const JSGUI_Server = require('./server');
|
|
75
|
+
const port = Number.isFinite(args.port) ? args.port : undefined;
|
|
76
|
+
const host = args.host || undefined;
|
|
77
|
+
const options = {
|
|
78
|
+
name: 'jsgui3 server (cli)',
|
|
79
|
+
port,
|
|
80
|
+
host,
|
|
81
|
+
root: args.root || process.cwd()
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
JSGUI_Server.serve(options).catch(err => {
|
|
85
|
+
console.error('Failed to start server:', err);
|
|
86
|
+
process.exit(1);
|
|
87
|
+
});
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
console.error('Unknown command:', cmd);
|
|
92
|
+
printHelp();
|
|
93
|
+
process.exit(1);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
if (require.main === module) main();
|