lineadraw 0.8.0 → 0.9.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.
@@ -0,0 +1,102 @@
1
+ declare const DEFAULT_BRIDGE_PORT = 7431;
2
+ /** A running editor as the bridge lists it. */
3
+ interface EditorInfo {
4
+ /** The drawing's document id — the stable way to address it. */
5
+ id: string;
6
+ name: string;
7
+ /** The file it is bound to; absent for an unsaved drawing / a web tab. */
8
+ path?: string | null;
9
+ kind: "desktop" | "web";
10
+ readOnly: boolean;
11
+ /** Changed since the last file save. */
12
+ dirty: boolean;
13
+ }
14
+ /** `GET /status`: the app's version, the bridge port, the open editors. */
15
+ interface BridgeStatus {
16
+ version: string;
17
+ port: number;
18
+ editors: EditorInfo[];
19
+ }
20
+ interface BridgeOptions {
21
+ /** Default: bridge.json's port, else 7431. */
22
+ port?: number;
23
+ /** Agent token, when the app requires one. Default: LINEA_BRIDGE_TOKEN,
24
+ * else bridge.json's token. */
25
+ token?: string;
26
+ /** The bridge.json to read, or `false` to read none. Default: the
27
+ * desktop app's own (per-OS app-data folder). */
28
+ bridgeFile?: string | false;
29
+ /** Injected fetch (tests, proxies). Default: the global one. */
30
+ fetch?: typeof fetch;
31
+ }
32
+ /** A bridge or editor refusal: `code` is the bridge's (`ambiguous`,
33
+ * `noSuchEditor`, `readOnly`, `validation`, `fileNotFound`…). */
34
+ declare class BridgeError extends Error {
35
+ readonly code?: string;
36
+ readonly status?: number;
37
+ /** The rest of the error body (e.g. `candidates` for `ambiguous`). */
38
+ readonly details?: Record<string, unknown>;
39
+ constructor(message: string, opts?: {
40
+ code?: string;
41
+ status?: number;
42
+ details?: Record<string, unknown>;
43
+ cause?: unknown;
44
+ });
45
+ }
46
+ /** The desktop app's bridge.json path on this OS. */
47
+ declare const bridgeFilePath: () => string;
48
+ /** One editor, addressed by document id, file path or (unique) name. */
49
+ interface EditorHandle {
50
+ /** How this handle addresses the editor. */
51
+ readonly ref: string;
52
+ /** Run one `linea_*` operation; resolves its result. */
53
+ call<T = unknown>(operation: string, args?: Record<string, unknown>): Promise<T>;
54
+ /**
55
+ * Run a `defineCommand` module inside the editor as ONE undo step —
56
+ * loops, reads and edits against the full Drawing API, one round trip.
57
+ * `inputs` / `params` answer the module's declared ones (the user is
58
+ * never asked).
59
+ */
60
+ runScript<T = unknown>(source: string, opts?: {
61
+ inputs?: readonly (readonly [number, number])[];
62
+ params?: Record<string, unknown>;
63
+ }): Promise<T>;
64
+ /** Close it like its window's x; a dirty desktop drawing is refused
65
+ * unless `discard`. */
66
+ close(opts?: {
67
+ discard?: boolean;
68
+ }): Promise<unknown>;
69
+ }
70
+ /** The running app: its editors and the operations they offer. */
71
+ interface LineaBridge {
72
+ /** The bridge's address, e.g. http://127.0.0.1:7431. */
73
+ readonly url: string;
74
+ status(): Promise<BridgeStatus>;
75
+ /** The open editors. */
76
+ editors(): Promise<EditorInfo[]>;
77
+ /** The operations the bridge offers (name + description). */
78
+ tools(): Promise<{
79
+ name: string;
80
+ description?: string;
81
+ }[]>;
82
+ /** Open a `.linea` file in a window of its own (an absolute path, or one
83
+ * relative to the current directory); resolves once it has loaded. */
84
+ open(path: string): Promise<EditorInfo>;
85
+ /** A handle on one editor (id, path or unique name). Omitted: the only
86
+ * open editor — with several, calls fail as `ambiguous`. */
87
+ editor(ref?: string): EditorHandle;
88
+ /** One operation on an editor (`editor` as for `editor()`). */
89
+ call<T = unknown>(operation: string, args?: Record<string, unknown>, opts?: {
90
+ editor?: string;
91
+ }): Promise<T>;
92
+ }
93
+ /**
94
+ * Connect to the running Linea desktop app's bridge: reads its bridge.json
95
+ * (port, agent token), checks that it answers, and returns the client.
96
+ * Rejects with a BridgeError when nothing answers.
97
+ */
98
+ declare const connectEditors: (opts?: BridgeOptions) => Promise<LineaBridge>;
99
+ /** The client without the reachability check (the CLI's one-shot calls). */
100
+ declare const createBridge: (opts?: BridgeOptions) => LineaBridge;
101
+
102
+ export { BridgeError, type BridgeOptions, type BridgeStatus, DEFAULT_BRIDGE_PORT, type EditorHandle, type EditorInfo, type LineaBridge, bridgeFilePath, connectEditors, createBridge };
package/dist/bridge.js ADDED
@@ -0,0 +1,16 @@
1
+ import {
2
+ BridgeError,
3
+ DEFAULT_BRIDGE_PORT,
4
+ bridgeFilePath,
5
+ connectEditors,
6
+ createBridge
7
+ } from "./chunk-L2CWZAKW.js";
8
+ import "./chunk-PZ5AY32C.js";
9
+ export {
10
+ BridgeError,
11
+ DEFAULT_BRIDGE_PORT,
12
+ bridgeFilePath,
13
+ connectEditors,
14
+ createBridge
15
+ };
16
+ //# sourceMappingURL=bridge.js.map