@geometra/server 0.1.0 → 0.2.1

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 ADDED
@@ -0,0 +1,38 @@
1
+ # @geometra/server
2
+
3
+ Server-side layout engine with WebSocket streaming for Geometra. Computes layouts on the server and streams them to thin clients.
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ npm install @geometra/server
9
+ ```
10
+
11
+ ## Key Export
12
+
13
+ - `createServer` -- creates a Geometra layout server with WebSocket support
14
+
15
+ ## Usage
16
+
17
+ ```ts
18
+ import { signal, box, text } from '@geometra/core/node'
19
+ import { createServer } from '@geometra/server'
20
+
21
+ const messages = signal(['Hello from server'])
22
+
23
+ function view() {
24
+ return box({ flexDirection: 'column', padding: 16, gap: 8 },
25
+ messages.value.map((m) =>
26
+ box({ backgroundColor: '#16213e', padding: 10, borderRadius: 8 }, [
27
+ text({ text: m, font: '14px Inter', lineHeight: 20, color: '#fff' }),
28
+ ]),
29
+ ),
30
+ )
31
+ }
32
+
33
+ const server = await createServer(view, { port: 3100, width: 800, height: 500 })
34
+ ```
35
+
36
+ ## Links
37
+
38
+ - [Main repo](https://github.com/AiGeekz/geometra)
@@ -1,28 +1,46 @@
1
1
  import type { ComputedLayout } from 'textura';
2
2
  import type { UIElement } from '@geometra/core';
3
+ /** Increment when the wire message shape changes in a non-backward-compatible way. */
4
+ export declare const PROTOCOL_VERSION = 1;
5
+ interface VersionedMessage {
6
+ protocolVersion?: number;
7
+ }
3
8
  /** Messages sent from server to client. */
4
- export type ServerMessage = {
9
+ export type ServerMessage = (VersionedMessage & {
5
10
  type: 'frame';
6
11
  layout: ComputedLayout;
7
12
  tree: UIElement;
8
- } | {
13
+ }) | (VersionedMessage & {
9
14
  type: 'patch';
10
15
  patches: LayoutPatch[];
11
- } | {
16
+ }) | (VersionedMessage & {
12
17
  type: 'error';
13
18
  message: string;
14
- };
19
+ });
15
20
  /** Messages sent from client to server. */
16
- export type ClientMessage = {
21
+ export type ClientMessage = (VersionedMessage & {
17
22
  type: 'event';
18
23
  eventType: string;
19
24
  x: number;
20
25
  y: number;
21
- } | {
26
+ }) | (VersionedMessage & {
27
+ type: 'key';
28
+ eventType: 'onKeyDown' | 'onKeyUp';
29
+ key: string;
30
+ code: string;
31
+ shiftKey: boolean;
32
+ ctrlKey: boolean;
33
+ metaKey: boolean;
34
+ altKey: boolean;
35
+ }) | (VersionedMessage & {
36
+ type: 'composition';
37
+ eventType: 'onCompositionStart' | 'onCompositionUpdate' | 'onCompositionEnd';
38
+ data: string;
39
+ }) | (VersionedMessage & {
22
40
  type: 'resize';
23
41
  width: number;
24
42
  height: number;
25
- };
43
+ });
26
44
  /** A patch describing a change to a single node's geometry. */
27
45
  export interface LayoutPatch {
28
46
  path: number[];
@@ -33,4 +51,5 @@ export interface LayoutPatch {
33
51
  }
34
52
  /** Diff two computed layouts and return patches for changed nodes. */
35
53
  export declare function diffLayout(prev: ComputedLayout, next: ComputedLayout, path?: number[]): LayoutPatch[];
54
+ export {};
36
55
  //# sourceMappingURL=protocol.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"protocol.d.ts","sourceRoot":"","sources":["../src/protocol.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAA;AAC7C,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAE/C,2CAA2C;AAC3C,MAAM,MAAM,aAAa,GACrB;IAAE,IAAI,EAAE,OAAO,CAAC;IAAC,MAAM,EAAE,cAAc,CAAC;IAAC,IAAI,EAAE,SAAS,CAAA;CAAE,GAC1D;IAAE,IAAI,EAAE,OAAO,CAAC;IAAC,OAAO,EAAE,WAAW,EAAE,CAAA;CAAE,GACzC;IAAE,IAAI,EAAE,OAAO,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,CAAA;AAEtC,2CAA2C;AAC3C,MAAM,MAAM,aAAa,GACrB;IAAE,IAAI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when the wire message shape changes in a non-backward-compatible way. */
2
+ export const PROTOCOL_VERSION = 1;
1
3
  /** Diff two computed layouts and return patches for changed nodes. */
2
4
  export function diffLayout(prev, next, path = []) {
3
5
  const patches = [];
@@ -1 +1 @@
1
- {"version":3,"file":"protocol.js","sourceRoot":"","sources":["../src/protocol.ts"],"names":[],"mappings":"AAuBA,sEAAsE;AACtE,MAAM,UAAU,UAAU,CACxB,IAAoB,EACpB,IAAoB,EACpB,OAAiB,EAAE;IAEnB,MAAM,OAAO,GAAkB,EAAE,CAAA;IAEjC,MAAM,KAAK,GAAgB,EAAE,IAAI,EAAE,CAAA;IACnC,IAAI,OAAO,GAAG,KAAK,CAAA;IAEnB,IAAI,IAAI,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC,EAAE,CAAC;QAAC,KAAK,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC;QAAC,OAAO,GAAG,IAAI,CAAA;IAAC,CAAC;IAC3D,IAAI,IAAI,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC,EAAE,CAAC;QAAC,KAAK,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC;QAAC,OAAO,GAAG,IAAI,CAAA;IAAC,CAAC;IAC3D,IAAI,IAAI,CAAC,KAAK,KAAK,IAAI,CAAC,KAAK,EAAE,CAAC;QAAC,KAAK,CAAC,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC;QAAC,OAAO,GAAG,IAAI,CAAA;IAAC,CAAC;IAC3E,IAAI,IAAI,CAAC,MAAM,KAAK,IAAI,CAAC,MAAM,EAAE,CAAC;QAAC,KAAK,CAAC,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC;QAAC,OAAO,GAAG,IAAI,CAAA;IAAC,CAAC;IAE/E,IAAI,OAAO;QAAE,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;IAEhC,MAAM,WAAW,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,QAAQ,CAAC,MAAM,EAAE,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AC;QAAC,KAAK,CAAC,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC;QAAC,OAAO,GAAG,IAAI,CAAA;IAAC,CAAC;IAC3E,IAAI,IAAI,CAAC,MAAM,KAAK,IAAI,CAAC,MAAM,EAAE,CAAC;QAAC,KAAK,CAAC,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC;QAAC,OAAO,GAAG,IAAI,CAAA;IAAC,CAAC;IAE/E,IAAI,OAAO;QAAE,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;IAEhC,MAAM,WAAW,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,QAAQ,CAAC,MAAM,EAAE,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAA;IACxE,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,WAAW,EAAE,CAAC,EAAE,EAAE,CAAC;QACrC,MAAM,SAAS,GAAG,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAA;QAClC,MAAM,SAAS,GAAG,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAA;QAClC,IAAI,SAAS,IAAI,SAAS,EAAE,CAAC;YAC3B,OAAO,CAAC,IAAI,CAAC,GAAG,UAAU,CAAC,SAAS,EAAE,SAAS,EAAE,CAAC,GAAG,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC,CAAA;QACjE,CAAC;IACH,CAAC;IAED,OAAO,OAAO,CAAA;AAChB,CAAC"}
package/dist/server.d.ts CHANGED
@@ -6,6 +6,8 @@ export interface TexturaServerOptions {
6
6
  width?: number;
7
7
  /** Root height. Default: 600. */
8
8
  height?: number;
9
+ /** Called on errors during layout computation or broadcasting. */
10
+ onError?: (error: unknown) => void;
9
11
  }
10
12
  export interface TexturaServer {
11
13
  /** Trigger a re-render for all connected clients. */
@@ -1 +1 @@
1
- {"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,SAAS,EAAiB,MAAM,gBAAgB,CAAA;AAI9D,MAAM,WAAW,oBAAoB;IACnC,wCAAwC;IACxC,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,gCAAgC;IAChC,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,iCAAiC;IACjC,MAAM,CAAC,EAAE,MAAM,CAAA;CAChB;AAED,MAAM,WAAW,aAAa;IAC5B,qDAAqD;IACrD,MAAM,IAAI,IAAI,CAAA;IACd,4BAA4B;IAC5B,KAAK,IAAI,IAAI,CAAA;CACd;AAED;;;;;GAKG;AACH,wBAAsB,YAAY,CAChC,IAAI,EAAE,MAAM,SAAS,EACrB,OAAO,GAAE,oBAAyB,GACjC,OAAO,CAAC,aAAa,CAAC,CAwFxB"}
1
+ {"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,SAAS,EAAiB,MAAM,gBAAgB,CAAA;AAI9D,MAAM,WAAW,oBAAoB;IACnC,wCAAwC;IACxC,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,gCAAgC;IAChC,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,iCAAiC;IACjC,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,kEAAkE;IAClE,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,IAAI,CAAA;CACnC;AAED,MAAM,WAAW,aAAa;IAC5B,qDAAqD;IACrD,MAAM,IAAI,IAAI,CAAA;IACd,4BAA4B;IAC5B,KAAK,IAAI,IAAI,CAAA;CACd;AAED;;;;;GAKG;AACH,wBAAsB,YAAY,CAChC,IAAI,EAAE,MAAM,SAAS,EACrB,OAAO,GAAE,oBAAyB,GACjC,OAAO,CAAC,aAAa,CAAC,CA0IxB"}
package/dist/server.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { WebSocketServer } from 'ws';
2
2
  import { init, computeLayout } from 'textura';
3
- import { toLayoutTree, dispatchHit } from '@geometra/core';
4
- import { diffLayout } from './protocol.js';
3
+ import { toLayoutTree, dispatchHit, dispatchKeyboardEvent, dispatchCompositionEvent } from '@geometra/core';
4
+ import { diffLayout, PROTOCOL_VERSION } from './protocol.js';
5
5
  /**
6
6
  * Create a Textura server that computes layout and streams geometry to clients.
7
7
  *
@@ -11,36 +11,54 @@ import { diffLayout } from './protocol.js';
11
11
  export async function createServer(view, options = {}) {
12
12
  await init();
13
13
  const port = options.port ?? 3100;
14
- const width = options.width ?? 800;
15
- const height = options.height ?? 600;
14
+ let width = options.width ?? 800;
15
+ let height = options.height ?? 600;
16
16
  const clients = new Set();
17
17
  let prevLayout = null;
18
18
  let currentTree = null;
19
19
  function computeAndBroadcast() {
20
- currentTree = view();
21
- const layoutTree = toLayoutTree(currentTree);
22
- const layout = computeLayout(layoutTree, { width, height });
23
- let msg;
24
- if (prevLayout) {
25
- const patches = diffLayout(prevLayout, layout);
26
- if (patches.length === 0)
27
- return;
28
- // If patches are more than half the tree, just send full frame
29
- if (patches.length > 20) {
30
- msg = { type: 'frame', layout, tree: currentTree };
20
+ try {
21
+ currentTree = view();
22
+ const layoutTree = toLayoutTree(currentTree);
23
+ const layout = computeLayout(layoutTree, { width, height });
24
+ let msg;
25
+ if (prevLayout) {
26
+ const patches = diffLayout(prevLayout, layout);
27
+ if (patches.length === 0)
28
+ return;
29
+ // If patches are more than half the tree, just send full frame
30
+ if (patches.length > 20) {
31
+ msg = { type: 'frame', layout, tree: currentTree, protocolVersion: PROTOCOL_VERSION };
32
+ }
33
+ else {
34
+ msg = { type: 'patch', patches, protocolVersion: PROTOCOL_VERSION };
35
+ }
31
36
  }
32
37
  else {
33
- msg = { type: 'patch', patches };
38
+ msg = { type: 'frame', layout, tree: currentTree, protocolVersion: PROTOCOL_VERSION };
39
+ }
40
+ prevLayout = layout;
41
+ const data = JSON.stringify(msg);
42
+ for (const client of clients) {
43
+ if (client.readyState === client.OPEN) {
44
+ client.send(data);
45
+ }
34
46
  }
35
47
  }
36
- else {
37
- msg = { type: 'frame', layout, tree: currentTree };
38
- }
39
- prevLayout = layout;
40
- const data = JSON.stringify(msg);
41
- for (const client of clients) {
42
- if (client.readyState === client.OPEN) {
43
- client.send(data);
48
+ catch (err) {
49
+ if (options.onError) {
50
+ options.onError(err);
51
+ }
52
+ else {
53
+ console.error('Geometra server error:', err);
54
+ }
55
+ // Send error to clients
56
+ const errorMsg = { type: 'error', message: String(err), protocolVersion: PROTOCOL_VERSION };
57
+ const data = JSON.stringify(errorMsg);
58
+ for (const client of clients) {
59
+ if (client.readyState === client.OPEN) {
60
+ client.send(data);
61
+ }
44
62
  }
45
63
  }
46
64
  }
@@ -49,7 +67,12 @@ export async function createServer(view, options = {}) {
49
67
  clients.add(ws);
50
68
  // Send current state immediately
51
69
  if (prevLayout && currentTree) {
52
- const msg = { type: 'frame', layout: prevLayout, tree: currentTree };
70
+ const msg = {
71
+ type: 'frame',
72
+ layout: prevLayout,
73
+ tree: currentTree,
74
+ protocolVersion: PROTOCOL_VERSION,
75
+ };
53
76
  ws.send(JSON.stringify(msg));
54
77
  }
55
78
  else {
@@ -58,11 +81,43 @@ export async function createServer(view, options = {}) {
58
81
  ws.on('message', (raw) => {
59
82
  try {
60
83
  const msg = JSON.parse(String(raw));
84
+ if (msg.protocolVersion && msg.protocolVersion > PROTOCOL_VERSION) {
85
+ const errorMsg = {
86
+ type: 'error',
87
+ message: `Client protocol ${msg.protocolVersion} is newer than server protocol ${PROTOCOL_VERSION}`,
88
+ protocolVersion: PROTOCOL_VERSION,
89
+ };
90
+ ws.send(JSON.stringify(errorMsg));
91
+ return;
92
+ }
61
93
  if (msg.type === 'event' && currentTree && prevLayout) {
62
94
  dispatchHit(currentTree, prevLayout, msg.eventType, msg.x, msg.y);
63
95
  // After event handling, signals may have changed — re-render
64
96
  computeAndBroadcast();
65
97
  }
98
+ else if (msg.type === 'key' && currentTree && prevLayout) {
99
+ dispatchKeyboardEvent(currentTree, prevLayout, msg.eventType, {
100
+ key: msg.key,
101
+ code: msg.code,
102
+ shiftKey: msg.shiftKey,
103
+ ctrlKey: msg.ctrlKey,
104
+ metaKey: msg.metaKey,
105
+ altKey: msg.altKey,
106
+ });
107
+ computeAndBroadcast();
108
+ }
109
+ else if (msg.type === 'composition' && currentTree && prevLayout) {
110
+ dispatchCompositionEvent(currentTree, prevLayout, msg.eventType, {
111
+ data: msg.data,
112
+ });
113
+ computeAndBroadcast();
114
+ }
115
+ else if (msg.type === 'resize') {
116
+ width = Math.max(1, msg.width);
117
+ height = Math.max(1, msg.height);
118
+ prevLayout = null;
119
+ computeAndBroadcast();
120
+ }
66
121
  }
67
122
  catch {
68
123
  // Ignore malformed messages
@@ -1 +1 @@
1
- {"version":3,"file":"server.js","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,IAAI,CAAA;AAEpC,OAAO,EAAE,IAAI,EAAE,aAAa,EAAE,MAAM,SAAS,CAAA;AAE7C,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAA;AAE1D,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAA;AAmB1C;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,YAAY,CAChC,IAAqB,EACrB,UAAgC,EAAE;IAElC,MAAM,IAAI,EAAE,CAAA;IAEZ,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,IAAI,IAAI,CAAA;IACjC,MAAM,KAAK,GAAG,OAAO,CAAC,KAAK,IAAI,GAAG,CAAA;IAClC,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM,IAAI,GAAG,CAAA;IAEpC,MAAM,OAAO,GAAG,IAAI,GAAG,EAAa,CAAA;IACpC,IAAI,UAAU,GAA0B,IAAI,CAAA;IAC5C,IAAI,WAAW,GAAqB,IAAI,CAAA;IAExC,SAAS,mBAAmB;QAC1B,WAAW,GAAG,IAAI,EAAE,CAAA;QACpB,MAAM,UAAU,GAAG,YAAY,CAAC,WAAW,CAAC,CA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;IAEF,iBAAiB;IACjB,mBAAmB,EAAE,CAAA;IAErB,OAAO;QACL,MAAM;YACJ,mBAAmB,EAAE,CAAA;QACvB,CAAC;QACD,KAAK;YACH,GAAG,CAAC,KAAK,EAAE,CAAA;YACX,OAAO,CAAC,KAAK,EAAE,CAAA;QACjB,CAAC;KACF,CAAA;AACH,CAAC"}
package/package.json CHANGED
@@ -1,15 +1,15 @@
1
1
  {
2
2
  "name": "@geometra/server",
3
- "version": "0.1.0",
3
+ "version": "0.2.1",
4
4
  "description": "Server-side layout engine with WebSocket geometry streaming",
5
5
  "license": "MIT",
6
6
  "type": "module",
7
7
  "repository": {
8
8
  "type": "git",
9
- "url": "https://github.com/razroo/textrura-framework",
9
+ "url": "https://github.com/razroo/geometra",
10
10
  "directory": "packages/server"
11
11
  },
12
- "homepage": "https://razroo.github.io/textrura-framework",
12
+ "homepage": "https://razroo.github.io/geometra",
13
13
  "keywords": [
14
14
  "textura",
15
15
  "server",
@@ -33,7 +33,7 @@
33
33
  "check": "tsc --noEmit"
34
34
  },
35
35
  "dependencies": {
36
- "@geometra/core": "^0.1.0",
36
+ "@geometra/core": "^0.2.1",
37
37
  "ws": "^8.18.0"
38
38
  },
39
39
  "devDependencies": {