lineadraw 0.10.0 → 0.11.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 +18 -7
- package/bin/lineadraw.mjs +60 -10
- package/dist/bridge.d.ts +1 -0
- package/dist/bridge.js +1 -1
- package/dist/{chunk-YYJAXJOY.js → chunk-7UFXC7OI.js} +1680 -141
- package/dist/chunk-7UFXC7OI.js.map +1 -0
- package/dist/chunk-FDLANLIC.js +1161 -0
- package/dist/chunk-FDLANLIC.js.map +1 -0
- package/dist/chunk-M3EDRSHW.js +81 -0
- package/dist/chunk-M3EDRSHW.js.map +1 -0
- package/dist/chunk-MYP7RUYK.js +9 -0
- package/dist/chunk-MYP7RUYK.js.map +1 -0
- package/dist/{chunk-L2CWZAKW.js → chunk-RNA2RDGL.js} +13 -6
- package/dist/chunk-RNA2RDGL.js.map +1 -0
- package/dist/dist-56K6CNML.js +188 -0
- package/dist/dist-56K6CNML.js.map +1 -0
- package/dist/dist-IEN64QSV.js +10 -0
- package/dist/dist-IEN64QSV.js.map +1 -0
- package/dist/emscripten-module-Q67P5WYC-ITCU5LXL.js +2424 -0
- package/dist/emscripten-module-Q67P5WYC-ITCU5LXL.js.map +1 -0
- package/dist/{exportDxf-C4CLQCC3.js → exportDxf-6XTXQ4XN.js} +2 -2
- package/dist/ffi-SHMEF5YV.js +82 -0
- package/dist/ffi-SHMEF5YV.js.map +1 -0
- package/dist/module-ES6BEMUI-BJFWC656.js +14 -0
- package/dist/module-ES6BEMUI-BJFWC656.js.map +1 -0
- package/dist/module-asyncify-2EFITU5U-7F5WZXRA.js +9 -0
- package/dist/module-asyncify-2EFITU5U-7F5WZXRA.js.map +1 -0
- package/dist/sdk.d.ts +868 -95
- package/dist/sdk.js +619 -558
- package/dist/sdk.js.map +1 -1
- package/lineadraw.d.ts +162 -8
- package/package.json +2 -2
- package/dist/chunk-L2CWZAKW.js.map +0 -1
- package/dist/chunk-YYJAXJOY.js.map +0 -1
- /package/dist/{exportDxf-C4CLQCC3.js.map → exportDxf-6XTXQ4XN.js.map} +0 -0
package/lineadraw.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// GENERATED — do not edit. Typings for the virtual "lineadraw" and
|
|
2
2
|
// "lineadraw/helpers" modules block scripts import from, emitted from
|
|
3
|
-
// packages/core/src/extensions/{scriptTypes,scriptHelpers,scriptBooleans}.ts.
|
|
3
|
+
// packages/core/src/extensions/{scriptTypes,scriptHelpers,scriptBooleans,scriptCurves}.ts.
|
|
4
4
|
// Regenerate with:
|
|
5
5
|
// npm run gen:lineadraw-dts -w @lineadraw/core
|
|
6
6
|
|
|
@@ -97,11 +97,64 @@ declare module "lineadraw" {
|
|
|
97
97
|
startAngle?: number;
|
|
98
98
|
endAngle?: number;
|
|
99
99
|
}>;
|
|
100
|
+
/**
|
|
101
|
+
* A NURBS curve (DXF SPLINE). `knots` number controlPoints + degree + 1,
|
|
102
|
+
* non-decreasing; `weights` (one per control point) make it rational. With
|
|
103
|
+
* `fitPoints` the curve was drawn through them. Easiest to create through
|
|
104
|
+
* points: `splineThrough(points)` from "lineadraw/helpers".
|
|
105
|
+
*/
|
|
106
|
+
export type SplineInput = ObjectInputShape<{
|
|
107
|
+
type: "spline";
|
|
108
|
+
degree: number;
|
|
109
|
+
controlPoints: readonly Vec2Like[];
|
|
110
|
+
knots: readonly number[];
|
|
111
|
+
weights?: readonly number[];
|
|
112
|
+
fitPoints?: readonly Vec2Like[];
|
|
113
|
+
/** Fit splines: the direction the curve leaves its first fit point. */
|
|
114
|
+
startTangent?: Vec2Like;
|
|
115
|
+
/** Fit splines: the direction the curve arrives at its last fit point. */
|
|
116
|
+
endTangent?: Vec2Like;
|
|
117
|
+
closed?: boolean;
|
|
118
|
+
}>;
|
|
119
|
+
/**
|
|
120
|
+
* A hatch boundary edge — the geometry of a line, an arc, an elliptic arc or
|
|
121
|
+
* a spline. An arc runs CCW from startAngle to endAngle (equal = a full
|
|
122
|
+
* circle); an ellipse in DXF form (parameters, 0 → 2π = whole). Edges are
|
|
123
|
+
* chained by their ends, stored in either direction. A polygon or bulged
|
|
124
|
+
* outline: `hatchLoop(points)` from "lineadraw/helpers".
|
|
125
|
+
*/
|
|
126
|
+
export type HatchEdgeInput = {
|
|
127
|
+
kind: "line";
|
|
128
|
+
a: Vec2Like;
|
|
129
|
+
b: Vec2Like;
|
|
130
|
+
} | {
|
|
131
|
+
kind: "arc";
|
|
132
|
+
center: Vec2Like;
|
|
133
|
+
radius: number;
|
|
134
|
+
startAngle: number;
|
|
135
|
+
endAngle: number;
|
|
136
|
+
} | {
|
|
137
|
+
kind: "ellipse";
|
|
138
|
+
center: Vec2Like;
|
|
139
|
+
majorAxis: Vec2Like;
|
|
140
|
+
ratio: number;
|
|
141
|
+
startAngle?: number;
|
|
142
|
+
endAngle?: number;
|
|
143
|
+
} | {
|
|
144
|
+
kind: "spline";
|
|
145
|
+
degree: number;
|
|
146
|
+
controlPoints: readonly Vec2Like[];
|
|
147
|
+
knots: readonly number[];
|
|
148
|
+
weights?: readonly number[];
|
|
149
|
+
/** Drawn through points: those points, as on a spline. */
|
|
150
|
+
fitPoints?: readonly Vec2Like[];
|
|
151
|
+
};
|
|
100
152
|
export type HatchInput = ObjectInputShape<{
|
|
101
153
|
type: "hatch";
|
|
102
|
-
/** loops[0] = outer boundary, the rest are holes (even-odd)
|
|
154
|
+
/** loops[0] = outer boundary, the rest are holes (even-odd); each a
|
|
155
|
+
* closed chain of edges (a circle, ellipse or closed spline is one). */
|
|
103
156
|
loops: readonly {
|
|
104
|
-
|
|
157
|
+
edges: readonly HatchEdgeInput[];
|
|
105
158
|
}[];
|
|
106
159
|
fill?: {
|
|
107
160
|
kind: "solid";
|
|
@@ -321,7 +374,7 @@ declare module "lineadraw" {
|
|
|
321
374
|
}>;
|
|
322
375
|
/** What a script WRITES — the union of the authoring DTOs above (what
|
|
323
376
|
* `document.add` takes). Reads return `ModelObject`. */
|
|
324
|
-
export type ModelObjectInput = LineInput | PointInput | PolylineInput | CircleInput | ArcInput | EllipseInput | HatchInput | TextInput | DimensionInput | BlockInput | TableInput | ViewportInput | CommentInput | ReferenceInput;
|
|
377
|
+
export type ModelObjectInput = LineInput | PointInput | PolylineInput | CircleInput | ArcInput | EllipseInput | SplineInput | HatchInput | TextInput | DimensionInput | BlockInput | TableInput | ViewportInput | CommentInput | ReferenceInput;
|
|
325
378
|
/** One child a block's `draw` may return: every input except viewports and
|
|
326
379
|
* comments (both are drawn only as a space's own objects — a block's would
|
|
327
380
|
* never show). An `asset` reference resolves in the document the instance
|
|
@@ -384,6 +437,17 @@ declare module "lineadraw" {
|
|
|
384
437
|
startAngle: number;
|
|
385
438
|
endAngle: number;
|
|
386
439
|
}>;
|
|
440
|
+
export type Spline = ObjectShape<{
|
|
441
|
+
type: "spline";
|
|
442
|
+
degree: number;
|
|
443
|
+
controlPoints: readonly Vec2[];
|
|
444
|
+
knots: readonly number[];
|
|
445
|
+
weights?: readonly number[];
|
|
446
|
+
fitPoints?: readonly Vec2[];
|
|
447
|
+
startTangent?: Vec2;
|
|
448
|
+
endTangent?: Vec2;
|
|
449
|
+
closed: boolean;
|
|
450
|
+
}>;
|
|
387
451
|
export type HatchFill = {
|
|
388
452
|
kind: "solid";
|
|
389
453
|
} | {
|
|
@@ -404,11 +468,37 @@ declare module "lineadraw" {
|
|
|
404
468
|
color2: string;
|
|
405
469
|
angle: number;
|
|
406
470
|
};
|
|
471
|
+
/** Stored hatch boundary edge — see HatchEdgeInput. */
|
|
472
|
+
export type HatchEdge = {
|
|
473
|
+
kind: "line";
|
|
474
|
+
a: Vec2;
|
|
475
|
+
b: Vec2;
|
|
476
|
+
} | {
|
|
477
|
+
kind: "arc";
|
|
478
|
+
center: Vec2;
|
|
479
|
+
radius: number;
|
|
480
|
+
startAngle: number;
|
|
481
|
+
endAngle: number;
|
|
482
|
+
} | {
|
|
483
|
+
kind: "ellipse";
|
|
484
|
+
center: Vec2;
|
|
485
|
+
majorAxis: Vec2;
|
|
486
|
+
ratio: number;
|
|
487
|
+
startAngle: number;
|
|
488
|
+
endAngle: number;
|
|
489
|
+
} | {
|
|
490
|
+
kind: "spline";
|
|
491
|
+
degree: number;
|
|
492
|
+
controlPoints: readonly Vec2[];
|
|
493
|
+
knots: readonly number[];
|
|
494
|
+
weights?: readonly number[];
|
|
495
|
+
fitPoints?: readonly Vec2[];
|
|
496
|
+
};
|
|
407
497
|
export type Hatch = ObjectShape<{
|
|
408
498
|
type: "hatch";
|
|
409
499
|
/** loops[0] = outer boundary, the rest are holes (even-odd). */
|
|
410
500
|
loops: readonly {
|
|
411
|
-
|
|
501
|
+
edges: readonly HatchEdge[];
|
|
412
502
|
}[];
|
|
413
503
|
fill: HatchFill;
|
|
414
504
|
scale: number;
|
|
@@ -545,7 +635,7 @@ declare module "lineadraw" {
|
|
|
545
635
|
styleOverride?: TextStyleOverride;
|
|
546
636
|
}>;
|
|
547
637
|
/** Any object as stored in the document — what reads hand to scripts. */
|
|
548
|
-
export type ModelObject = Line | Point | Polyline | Circle | Arc | Ellipse | Hatch | Text | Dimension | Block | Viewport | Comment | Table | Reference;
|
|
638
|
+
export type ModelObject = Line | Point | Polyline | Circle | Arc | Ellipse | Spline | Hatch | Text | Dimension | Block | Viewport | Comment | Table | Reference;
|
|
549
639
|
/**
|
|
550
640
|
* One choice of a "Select" parameter: the value (what scripts receive) with
|
|
551
641
|
* an optional properties-panel label. A plain string is shorthand for
|
|
@@ -958,6 +1048,7 @@ declare module "lineadraw" {
|
|
|
958
1048
|
}[];
|
|
959
1049
|
settings: {
|
|
960
1050
|
units: "mm" | "in";
|
|
1051
|
+
modelScale: number;
|
|
961
1052
|
};
|
|
962
1053
|
};
|
|
963
1054
|
/** What `renderSvg` draws: model space or one layout. */
|
|
@@ -1125,8 +1216,8 @@ declare module "lineadraw" {
|
|
|
1125
1216
|
/** A sheet: a bare preset (orientation from context — landscape for a new
|
|
1126
1217
|
* layout, the current one when patching), a preset with its orientation, or
|
|
1127
1218
|
* explicit millimetres. */
|
|
1128
|
-
export type SheetSpec = "A4" | "A3" | "A2" | "A1" | "A0" | {
|
|
1129
|
-
name: "A4" | "A3" | "A2" | "A1" | "A0";
|
|
1219
|
+
export type SheetSpec = "A5" | "A4" | "A3" | "A2" | "A1" | "A0" | "Letter" | {
|
|
1220
|
+
name: "A5" | "A4" | "A3" | "A2" | "A1" | "A0" | "Letter";
|
|
1130
1221
|
orientation: "portrait" | "landscape";
|
|
1131
1222
|
} | {
|
|
1132
1223
|
width: number;
|
|
@@ -1164,6 +1255,7 @@ declare module "lineadraw" {
|
|
|
1164
1255
|
version: number;
|
|
1165
1256
|
settings: {
|
|
1166
1257
|
units: "mm" | "in";
|
|
1258
|
+
modelScale: number;
|
|
1167
1259
|
};
|
|
1168
1260
|
layers: readonly Layer[];
|
|
1169
1261
|
currentLayerId: string;
|
|
@@ -2075,4 +2167,66 @@ declare module "lineadraw/helpers" {
|
|
|
2075
2167
|
export const difference: (subject: PolygonLike, ...clips: PolygonLike[]) => Ring[];
|
|
2076
2168
|
/** Where ALL the polygons overlap. Same result rings as `union`. */
|
|
2077
2169
|
export const intersection: (...polygons: PolygonLike[]) => Ring[];
|
|
2170
|
+
/** A point as scripts write it: [x, y] or { x, y }. */
|
|
2171
|
+
export type CurvePointLike = readonly [number, number] | {
|
|
2172
|
+
readonly x: number;
|
|
2173
|
+
readonly y: number;
|
|
2174
|
+
};
|
|
2175
|
+
/** A `spline` object input, ready for `document.add` or a block's `draw`. */
|
|
2176
|
+
export type SplineThrough = {
|
|
2177
|
+
type: "spline";
|
|
2178
|
+
degree: number;
|
|
2179
|
+
controlPoints: {
|
|
2180
|
+
x: number;
|
|
2181
|
+
y: number;
|
|
2182
|
+
}[];
|
|
2183
|
+
knots: number[];
|
|
2184
|
+
fitPoints: {
|
|
2185
|
+
x: number;
|
|
2186
|
+
y: number;
|
|
2187
|
+
}[];
|
|
2188
|
+
};
|
|
2189
|
+
/**
|
|
2190
|
+
* The smooth spline passing THROUGH `points` (in order) — what the Spline
|
|
2191
|
+
* tool draws. `degree` 3 (default) or 2; fewer points lower it. Throws on
|
|
2192
|
+
* fewer than two distinct points.
|
|
2193
|
+
*/
|
|
2194
|
+
export const splineThrough: (points: readonly CurvePointLike[], degree?: number) => SplineThrough;
|
|
2195
|
+
/** A loop point: [x, y, bulge?] or { x, y, bulge? } — the bulge (tan of a
|
|
2196
|
+
* quarter of the sweep, as on a polyline) bends the edge to the NEXT point
|
|
2197
|
+
* into an arc. */
|
|
2198
|
+
export type LoopPointLike = readonly [number, number, number?] | {
|
|
2199
|
+
readonly x: number;
|
|
2200
|
+
readonly y: number;
|
|
2201
|
+
readonly bulge?: number;
|
|
2202
|
+
};
|
|
2203
|
+
/** A hatch loop of lines and arcs, ready for a hatch's `loops`. */
|
|
2204
|
+
export type HatchLoopEdges = {
|
|
2205
|
+
edges: ({
|
|
2206
|
+
kind: "line";
|
|
2207
|
+
a: {
|
|
2208
|
+
x: number;
|
|
2209
|
+
y: number;
|
|
2210
|
+
};
|
|
2211
|
+
b: {
|
|
2212
|
+
x: number;
|
|
2213
|
+
y: number;
|
|
2214
|
+
};
|
|
2215
|
+
} | {
|
|
2216
|
+
kind: "arc";
|
|
2217
|
+
center: {
|
|
2218
|
+
x: number;
|
|
2219
|
+
y: number;
|
|
2220
|
+
};
|
|
2221
|
+
radius: number;
|
|
2222
|
+
startAngle: number;
|
|
2223
|
+
endAngle: number;
|
|
2224
|
+
})[];
|
|
2225
|
+
};
|
|
2226
|
+
/**
|
|
2227
|
+
* The closed hatch loop through `points`: straight edges between them, an
|
|
2228
|
+
* arc where a point carries a bulge — the way to hatch a polygon or a
|
|
2229
|
+
* polyline outline (`loops: rings.map(hatchLoop)` for polygon booleans).
|
|
2230
|
+
*/
|
|
2231
|
+
export const hatchLoop: (points: readonly LoopPointLike[]) => HatchLoopEdges;
|
|
2078
2232
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "lineadraw",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.11.0",
|
|
4
4
|
"description": "Linea for Node: the headless drawing SDK (lineadraw/sdk), block/command typings, marketplace tooling, and a CLI for the running desktop app",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Mikhail Koshelev",
|
|
@@ -60,4 +60,4 @@
|
|
|
60
60
|
"typescript-eslint": "^8.70.0",
|
|
61
61
|
"vitest": "^5.0.1"
|
|
62
62
|
}
|
|
63
|
-
}
|
|
63
|
+
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/bridge.ts"],"sourcesContent":["// A client for RUNNING Linea editors: the desktop app serves the bridge on\n// 127.0.0.1:7431 (docs/desktop-bridge.md in the linea repo) and every open\n// window — plus any paired web tab — registers with it. Operations are the\n// shared `linea_*` tool catalog, each one undo step in that editor;\n// `runScript` sends a whole `defineCommand` module, which runs inside the\n// editor against the real Drawing API as ONE step and ONE round trip.\n//\n// Deliberately dependency-free (node: built-ins + fetch): the `lineadraw`\n// CLI loads it on its own (dist/bridge.js) without the rest of the SDK.\n\nimport { existsSync, readFileSync } from \"node:fs\";\nimport { homedir } from \"node:os\";\nimport { isAbsolute, join, resolve } from \"node:path\";\n\n/** Where the desktop app keeps its bridge settings (`bridge.json`). */\nconst APP_ID = \"com.lineadraw.desktop\";\nexport const DEFAULT_BRIDGE_PORT = 7431;\n\n/** A running editor as the bridge lists it. */\nexport interface EditorInfo {\n /** The drawing's document id — the stable way to address it. */\n id: string;\n name: string;\n /** The file it is bound to; absent for an unsaved drawing / a web tab. */\n path?: string | null;\n kind: \"desktop\" | \"web\";\n readOnly: boolean;\n /** Changed since the last file save. */\n dirty: boolean;\n}\n\n/** `GET /status`: the app's version, the bridge port, the open editors. */\nexport interface BridgeStatus {\n version: string;\n port: number;\n editors: EditorInfo[];\n}\n\nexport interface BridgeOptions {\n /** Default: bridge.json's port, else 7431. */\n port?: number;\n /** Agent token, when the app requires one. Default: LINEA_BRIDGE_TOKEN,\n * else bridge.json's token. */\n token?: string;\n /** The bridge.json to read, or `false` to read none. Default: the\n * desktop app's own (per-OS app-data folder). */\n bridgeFile?: string | false;\n /** Injected fetch (tests, proxies). Default: the global one. */\n fetch?: typeof fetch;\n}\n\n/** A bridge or editor refusal: `code` is the bridge's (`ambiguous`,\n * `noSuchEditor`, `readOnly`, `validation`, `fileNotFound`…). */\nexport class BridgeError extends Error {\n readonly code?: string;\n readonly status?: number;\n /** The rest of the error body (e.g. `candidates` for `ambiguous`). */\n readonly details?: Record<string, unknown>;\n constructor(\n message: string,\n opts: {\n code?: string;\n status?: number;\n details?: Record<string, unknown>;\n cause?: unknown;\n } = {},\n ) {\n super(message, { cause: opts.cause });\n this.name = \"BridgeError\";\n this.code = opts.code;\n this.status = opts.status;\n this.details = opts.details;\n }\n}\n\n/** The desktop app's bridge.json path on this OS. */\nexport const bridgeFilePath = (): string => {\n const home = homedir();\n if (process.platform === \"win32\")\n return join(\n process.env.APPDATA ?? join(home, \"AppData\", \"Roaming\"),\n APP_ID,\n \"bridge.json\",\n );\n if (process.platform === \"darwin\")\n return join(home, \"Library\", \"Application Support\", APP_ID, \"bridge.json\");\n return join(\n process.env.XDG_DATA_HOME ?? join(home, \".local\", \"share\"),\n APP_ID,\n \"bridge.json\",\n );\n};\n\nconst readBridgeFile = (\n path: string | false,\n): { port?: number; token?: string } => {\n if (path === false || !existsSync(path)) return {};\n try {\n return JSON.parse(readFileSync(path, \"utf8\"));\n } catch {\n return {};\n }\n};\n\n/** One editor, addressed by document id, file path or (unique) name. */\nexport interface EditorHandle {\n /** How this handle addresses the editor. */\n readonly ref: string;\n /** Run one `linea_*` operation; resolves its result. */\n call<T = unknown>(\n operation: string,\n args?: Record<string, unknown>,\n ): Promise<T>;\n /**\n * Run a `defineCommand` module inside the editor as ONE undo step —\n * loops, reads and edits against the full Drawing API, one round trip.\n * `inputs` / `params` answer the module's declared ones (the user is\n * never asked).\n */\n runScript<T = unknown>(\n source: string,\n opts?: {\n inputs?: readonly (readonly [number, number])[];\n params?: Record<string, unknown>;\n },\n ): Promise<T>;\n /** Close it like its window's x; a dirty desktop drawing is refused\n * unless `discard`. */\n close(opts?: { discard?: boolean }): Promise<unknown>;\n}\n\n/** The running app: its editors and the operations they offer. */\nexport interface LineaBridge {\n /** The bridge's address, e.g. http://127.0.0.1:7431. */\n readonly url: string;\n status(): Promise<BridgeStatus>;\n /** The open editors. */\n editors(): Promise<EditorInfo[]>;\n /** The operations the bridge offers (name + description). */\n tools(): Promise<{ name: string; description?: string }[]>;\n /** Open a `.linea` file in a window of its own (an absolute path, or one\n * relative to the current directory); resolves once it has loaded. */\n open(path: string): Promise<EditorInfo>;\n /** A handle on one editor (id, path or unique name). Omitted: the only\n * open editor — with several, calls fail as `ambiguous`. */\n editor(ref?: string): EditorHandle;\n /** One operation on an editor (`editor` as for `editor()`). */\n call<T = unknown>(\n operation: string,\n args?: Record<string, unknown>,\n opts?: { editor?: string },\n ): Promise<T>;\n}\n\n/**\n * Connect to the running Linea desktop app's bridge: reads its bridge.json\n * (port, agent token), checks that it answers, and returns the client.\n * Rejects with a BridgeError when nothing answers.\n */\nexport const connectEditors = async (\n opts: BridgeOptions = {},\n): Promise<LineaBridge> => {\n const bridge = createBridge(opts);\n await bridge.status(); // fail fast, with the \"is it running?\" message\n return bridge;\n};\n\n/** The client without the reachability check (the CLI's one-shot calls). */\nexport const createBridge = (opts: BridgeOptions = {}): LineaBridge => {\n const file = readBridgeFile(opts.bridgeFile ?? bridgeFilePath());\n const port = opts.port ?? file.port ?? DEFAULT_BRIDGE_PORT;\n const token = opts.token ?? process.env.LINEA_BRIDGE_TOKEN ?? file.token;\n const doFetch = opts.fetch ?? fetch;\n const url = `http://127.0.0.1:${port}`;\n const headers: Record<string, string> = {\n \"content-type\": \"application/json\",\n };\n if (token) headers.authorization = `Bearer ${token}`;\n\n const request = async <T>(\n method: \"GET\" | \"POST\",\n path: string,\n body?: unknown,\n ): Promise<T> => {\n let response: Response;\n try {\n response = await doFetch(`${url}${path}`, {\n method,\n headers,\n body: body === undefined ? undefined : JSON.stringify(body),\n });\n } catch (e) {\n const c = (e as { cause?: { code?: string; message?: string } })?.cause;\n const cause = c?.code ?? c?.message ?? (e as Error)?.message ?? e;\n throw new BridgeError(\n `Nothing answers on ${url} (${cause}). Is the Linea desktop app running?`,\n { code: \"unreachable\", cause: e },\n );\n }\n const text = await response.text();\n let parsed: unknown = text;\n try {\n parsed = JSON.parse(text);\n } catch {\n // not JSON: keep the text\n }\n if (!response.ok) {\n const error = (parsed as { error?: Record<string, unknown> })?.error;\n const { code, message, ...details } = error ?? {};\n throw new BridgeError(\n typeof message === \"string\"\n ? message\n : `HTTP ${response.status}: ${text.slice(0, 200)}`,\n {\n code: typeof code === \"string\" ? code : undefined,\n status: response.status,\n details,\n },\n );\n }\n return parsed as T;\n };\n\n const call = <T>(\n operation: string,\n args: Record<string, unknown> = {},\n o: { editor?: string } = {},\n ): Promise<T> =>\n request<T>(\n \"POST\",\n `/api/${encodeURIComponent(operation)}${\n o.editor ? `?editor=${encodeURIComponent(o.editor)}` : \"\"\n }`,\n args,\n );\n\n const editor = (ref?: string): EditorHandle => ({\n ref: ref ?? \"\",\n call: (operation, args) => call(operation, args, { editor: ref }),\n runScript: (source, so = {}) =>\n call(\n \"linea_run_script\",\n {\n source,\n ...(so.inputs && { inputs: so.inputs }),\n ...(so.params && { params: so.params }),\n },\n { editor: ref },\n ),\n close: (co = {}) =>\n call(\n \"linea_close_document\",\n { discard: co.discard === true },\n { editor: ref },\n ),\n });\n\n return {\n url,\n status: () => request<BridgeStatus>(\"GET\", \"/status\"),\n editors: () => request<EditorInfo[]>(\"GET\", \"/api/editors\"),\n tools: async () =>\n (\n await request<{ tools?: { name: string; description?: string }[] }>(\n \"GET\",\n \"/api/tools\",\n )\n ).tools?.map(({ name, description }) => ({ name, description })) ?? [],\n open: (path) =>\n request<EditorInfo>(\"POST\", \"/api/linea_open_editor\", {\n path: isAbsolute(path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