@miclivs/cadcli 0.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.
Files changed (63) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +132 -0
  3. package/dist/commands/blocks.d.ts +4 -0
  4. package/dist/commands/blocks.js +22 -0
  5. package/dist/commands/edit.d.ts +8 -0
  6. package/dist/commands/edit.js +24 -0
  7. package/dist/commands/entities.d.ts +7 -0
  8. package/dist/commands/entities.js +26 -0
  9. package/dist/commands/info.d.ts +2 -0
  10. package/dist/commands/info.js +22 -0
  11. package/dist/commands/json.d.ts +2 -0
  12. package/dist/commands/json.js +20 -0
  13. package/dist/commands/layers.d.ts +4 -0
  14. package/dist/commands/layers.js +22 -0
  15. package/dist/commands/overview.d.ts +5 -0
  16. package/dist/commands/overview.js +59 -0
  17. package/dist/commands/search.d.ts +11 -0
  18. package/dist/commands/search.js +45 -0
  19. package/dist/commands/shared.d.ts +16 -0
  20. package/dist/commands/shared.js +40 -0
  21. package/dist/commands/svg.d.ts +2 -0
  22. package/dist/commands/svg.js +27 -0
  23. package/dist/commands/thumbnail.d.ts +2 -0
  24. package/dist/commands/thumbnail.js +31 -0
  25. package/dist/commands/view.d.ts +6 -0
  26. package/dist/commands/view.js +27 -0
  27. package/dist/core/adapter.d.ts +14 -0
  28. package/dist/core/adapter.js +165 -0
  29. package/dist/core/drawing.d.ts +14 -0
  30. package/dist/core/drawing.js +61 -0
  31. package/dist/core/errors.d.ts +5 -0
  32. package/dist/core/errors.js +10 -0
  33. package/dist/core/files.d.ts +7 -0
  34. package/dist/core/files.js +27 -0
  35. package/dist/core/libredwg.d.ts +37 -0
  36. package/dist/core/libredwg.js +86 -0
  37. package/dist/core/normalize.d.ts +3 -0
  38. package/dist/core/normalize.js +156 -0
  39. package/dist/core/overview.d.ts +35 -0
  40. package/dist/core/overview.js +227 -0
  41. package/dist/core/search-cache.d.ts +17 -0
  42. package/dist/core/search-cache.js +69 -0
  43. package/dist/core/search.d.ts +18 -0
  44. package/dist/core/search.js +137 -0
  45. package/dist/core/svg.d.ts +2 -0
  46. package/dist/core/svg.js +105 -0
  47. package/dist/index.d.ts +5 -0
  48. package/dist/index.js +1 -0
  49. package/dist/main.d.ts +2 -0
  50. package/dist/main.js +151 -0
  51. package/dist/sdk.d.ts +30 -0
  52. package/dist/sdk.js +57 -0
  53. package/dist/store.d.ts +6 -0
  54. package/dist/store.js +17 -0
  55. package/dist/types.d.ts +65 -0
  56. package/dist/types.js +1 -0
  57. package/dist/utils/exit-codes.d.ts +5 -0
  58. package/dist/utils/exit-codes.js +5 -0
  59. package/dist/utils/output.d.ts +19 -0
  60. package/dist/utils/output.js +26 -0
  61. package/package.json +76 -0
  62. package/patches/@node-projects%2Facad-ts@2.3.0.patch +48 -0
  63. package/skills/cadcli/SKILL.md +34 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Michael Liv
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,132 @@
1
+ # cadcli
2
+
3
+ Agent-friendly CAD inspection, search, viewing, and editing for DWG/DXF files.
4
+
5
+ ```bash
6
+ npm install -g @miclivs/cadcli
7
+ ```
8
+
9
+ Common inspection/search commands use a pure TypeScript parser by default. Native LibreDWG tools are only needed for high-fidelity `view` and jq-backed `edit`.
10
+
11
+ ## Why cadcli
12
+
13
+ CAD files are hard to inspect from scripts. `cadcli` gives agents and developers a predictable interface over DWG/DXF drawings: structured JSON for automation, concise human output in the terminal, SVG previews for visual checks, and safe copy-first editing.
14
+
15
+ ```bash
16
+ cadcli info floorplan.dwg --json
17
+ cadcli overview floorplan.dwg
18
+ cadcli search floorplan.dwg "conference" --layer A-TEXT --json
19
+ cadcli view floorplan.dwg -o preview.svg
20
+ cadcli edit floorplan.dwg --jq '.OBJECTS[]' -o edited.dwg
21
+ ```
22
+
23
+ ## Workflow
24
+
25
+ ```txt
26
+ info → overview → layers/blocks/entities → search → view → edit
27
+ ```
28
+
29
+ Start with `info` to understand the drawing, use `overview` to see the searchable vocabulary, narrow down with `layers`, `blocks`, `entities`, and `search`, render an SVG with `view`, then write edits to a new file with `edit -o`.
30
+
31
+ ## Commands
32
+
33
+ ```bash
34
+ cadcli info <file> # metadata, version, counts, bounds
35
+ cadcli overview <file> # search vocabulary by layer/type/block/text
36
+ --keywords 12 --samples 8
37
+ cadcli layers <file> [--total] # layers and entity counts
38
+ cadcli blocks <file> [--total] # block names and entity counts
39
+ cadcli entities <file> # entities, optionally filtered
40
+ --type LINE --layer A-WALL --limit 20 --total
41
+
42
+ cadcli search <file> [query] # search IDs, types, layers, text, raw fields
43
+ --query "door" --type TEXT --layer A-TEXT --limit 10 --score --no-snippets
44
+
45
+ cadcli view <file> [-o preview.svg] # high-fidelity SVG preview
46
+ cadcli edit <file> --jq <expr> -o out.dwg
47
+ cadcli json <file> [-o drawing.json] # normalized JSON
48
+ cadcli svg <file> [-o sketch.svg] # best-effort SVG from normalized JSON
49
+ cadcli thumbnail <file> [-o thumb.png] # embedded thumbnail when available
50
+ ```
51
+
52
+ All commands support `--json` for structured output and `-q, --quiet` where useful. Primary data goes to stdout; diagnostics and errors go to stderr.
53
+
54
+ ## Overview
55
+
56
+ `cadcli overview` is the map before the search. It shows the drawing's useful vocabulary broken down by layer, entity type, block, text keyword, and search hint so agents do not have to guess what to query.
57
+
58
+ ```txt
59
+ WORKFLOW: overview (you are here) → search/entities → view/edit
60
+
61
+ SUMMARY
62
+ DWG · 1906 entities · 33 layers · 42 blocks
63
+
64
+ LAYERS
65
+ A-TEXT
66
+ entities: 88
67
+ types: TEXT, MTEXT
68
+ keywords: conference room, office, lobby
69
+
70
+ SEARCH HINTS
71
+ conference room, office, A-TEXT, DOOR_SINGLE, TEXT
72
+ ```
73
+
74
+
75
+ ## Viewing vs SVG export
76
+
77
+ `cadcli view` is the high-fidelity SVG path.
78
+
79
+ `cadcli svg` renders a lightweight SVG from cadcli’s normalized JSON model. It is useful for quick agent previews and debugging, but it is not a replacement for `view`.
80
+
81
+ ## Editing
82
+
83
+ Editing is intentionally copy-first:
84
+
85
+ ```bash
86
+ cadcli edit drawing.dwg --jq '.OBJECTS[]' -o edited.dwg
87
+ ```
88
+
89
+ In-place edits are refused unless you explicitly pass `--overwrite`:
90
+
91
+ ```bash
92
+ cadcli edit drawing.dwg --jq '.OBJECTS[]' --overwrite
93
+ ```
94
+
95
+ ## SDK
96
+
97
+ ```ts
98
+ import { Dwg } from "@miclivs/cadcli";
99
+
100
+ const drawing = Dwg.open("floorplan.dwg");
101
+
102
+ console.log(await drawing.info());
103
+ console.log(await drawing.layers());
104
+ console.log(await drawing.search({ query: "conference", layer: "A-TEXT" }));
105
+
106
+ const preview = drawing.view();
107
+ console.log(preview.svg);
108
+ ```
109
+
110
+ The public SDK is intentionally small: `Dwg` plus stable CAD/result types. Native tool details stay behind the SDK methods.
111
+
112
+ ## Cache
113
+
114
+ Search indexes are cached automatically in the platform-standard cache directory:
115
+
116
+ ```txt
117
+ macOS ~/Library/Caches/cadcli
118
+ Linux $XDG_CACHE_HOME/cadcli or ~/.cache/cadcli
119
+ Windows %LOCALAPPDATA%\cadcli\Cache
120
+ ```
121
+
122
+ Set `CADCLI_CACHE_DIR` to override this location.
123
+
124
+ ## Requirements
125
+
126
+ Inspection, overview, layers, blocks, entities, search, JSON, and lightweight SVG export work through the default pure TypeScript parser.
127
+
128
+ Install native LibreDWG tools for advanced workflows: `dwgread` for high-fidelity `view`, and `dwgfilter` for edits.
129
+
130
+ ## License
131
+
132
+ MIT
@@ -0,0 +1,4 @@
1
+ import { type DrawingCommandOptions } from "./shared.js";
2
+ export declare function blocks(file: string, options: DrawingCommandOptions & {
3
+ total?: boolean;
4
+ }): Promise<void>;
@@ -0,0 +1,22 @@
1
+ import { dim, output } from "../utils/output.js";
2
+ import { drawingFor, handleCommandError, } from "./shared.js";
3
+ export async function blocks(file, options) {
4
+ try {
5
+ const items = await drawingFor(file, options).blocks();
6
+ output(options, {
7
+ json: () => options.total
8
+ ? { total: items.length, blocks: items }
9
+ : { blocks: items },
10
+ human: () => {
11
+ if (options.total)
12
+ console.log(String(items.length));
13
+ else
14
+ for (const block of items)
15
+ console.log(`${block.name} ${dim(`${block.entityCount} entities`)}`);
16
+ },
17
+ });
18
+ }
19
+ catch (err) {
20
+ handleCommandError(err);
21
+ }
22
+ }
@@ -0,0 +1,8 @@
1
+ import type { OutputOptions } from "../utils/output.js";
2
+ export interface EditOptions extends OutputOptions {
3
+ jq?: string;
4
+ output?: string;
5
+ overwrite?: boolean;
6
+ toolDir?: string;
7
+ }
8
+ export declare function edit(file: string, options: EditOptions): Promise<void>;
@@ -0,0 +1,24 @@
1
+ import { editWithLibreDwgFilter } from "../core/libredwg.js";
2
+ import { output, success } from "../utils/output.js";
3
+ import { handleCommandError, userError } from "./shared.js";
4
+ export async function edit(file, options) {
5
+ try {
6
+ if (!options.jq) {
7
+ throw userError("No edit expression specified. Use --jq <expression>.", "MISSING_EDIT_EXPRESSION");
8
+ }
9
+ const result = editWithLibreDwgFilter({
10
+ input: file,
11
+ output: options.output ?? file,
12
+ expression: options.jq,
13
+ overwrite: options.overwrite,
14
+ toolDir: options.toolDir,
15
+ });
16
+ output(options, {
17
+ json: () => ({ success: true, ...result }),
18
+ human: () => success(`Edited ${result.output} with LibreDWG dwgfilter`),
19
+ });
20
+ }
21
+ catch (err) {
22
+ handleCommandError(err);
23
+ }
24
+ }
@@ -0,0 +1,7 @@
1
+ import { type DrawingCommandOptions } from "./shared.js";
2
+ export declare function entities(file: string, options: DrawingCommandOptions & {
3
+ type?: string;
4
+ layer?: string;
5
+ limit?: string;
6
+ total?: boolean;
7
+ }): Promise<void>;
@@ -0,0 +1,26 @@
1
+ import { dim, output } from "../utils/output.js";
2
+ import { drawingFor, handleCommandError, parseLimit, } from "./shared.js";
3
+ export async function entities(file, options) {
4
+ try {
5
+ const items = await drawingFor(file, options).entities({
6
+ type: options.type,
7
+ layer: options.layer,
8
+ limit: parseLimit(options.limit),
9
+ });
10
+ output(options, {
11
+ json: () => options.total
12
+ ? { total: items.length, entities: items }
13
+ : { entities: items },
14
+ human: () => {
15
+ if (options.total)
16
+ console.log(String(items.length));
17
+ else
18
+ for (const entity of items)
19
+ console.log(`${entity.id} ${entity.type}${entity.layer ? ` ${dim(entity.layer)}` : ""}`);
20
+ },
21
+ });
22
+ }
23
+ catch (err) {
24
+ handleCommandError(err);
25
+ }
26
+ }
@@ -0,0 +1,2 @@
1
+ import { type DrawingCommandOptions } from "./shared.js";
2
+ export declare function info(file: string, options: DrawingCommandOptions): Promise<void>;
@@ -0,0 +1,22 @@
1
+ import { bold, dim, output } from "../utils/output.js";
2
+ import { drawingFor, handleCommandError, } from "./shared.js";
3
+ export async function info(file, options) {
4
+ try {
5
+ const summary = await drawingFor(file, options).info();
6
+ output(options, {
7
+ json: () => summary,
8
+ human: () => {
9
+ console.log(`${bold(summary.file)} ${dim(summary.format)}${summary.version ? ` ${dim(summary.version)}` : ""}`);
10
+ console.log(` entities ${summary.counts.entities}`);
11
+ console.log(` layers ${summary.counts.layers}`);
12
+ console.log(` blocks ${summary.counts.blocks}`);
13
+ console.log(` unsupported ${summary.counts.unsupported}`);
14
+ if (summary.bounds)
15
+ console.log(` bounds ${summary.bounds.minX},${summary.bounds.minY} → ${summary.bounds.maxX},${summary.bounds.maxY}`);
16
+ },
17
+ });
18
+ }
19
+ catch (err) {
20
+ handleCommandError(err);
21
+ }
22
+ }
@@ -0,0 +1,2 @@
1
+ import { type DrawingCommandOptions, type OutputFileOptions } from "./shared.js";
2
+ export declare function json(file: string, options: DrawingCommandOptions & OutputFileOptions): Promise<void>;
@@ -0,0 +1,20 @@
1
+ import { toJson } from "../core/drawing.js";
2
+ import { stringifyJson } from "../utils/output.js";
3
+ import { handleCommandError, writeCommandOutput, } from "./shared.js";
4
+ export async function json(file, options) {
5
+ try {
6
+ const doc = await toJson(file, {
7
+ reader: options.reader,
8
+ toolDir: options.toolDir,
9
+ });
10
+ const content = `${stringifyJson(doc)}\n`;
11
+ if (options.output) {
12
+ writeCommandOutput(options, content, () => ({ success: true, file: options.output }), `Wrote ${options.output}`);
13
+ return;
14
+ }
15
+ console.log(content.trimEnd());
16
+ }
17
+ catch (err) {
18
+ handleCommandError(err);
19
+ }
20
+ }
@@ -0,0 +1,4 @@
1
+ import { type DrawingCommandOptions } from "./shared.js";
2
+ export declare function layers(file: string, options: DrawingCommandOptions & {
3
+ total?: boolean;
4
+ }): Promise<void>;
@@ -0,0 +1,22 @@
1
+ import { dim, output } from "../utils/output.js";
2
+ import { drawingFor, handleCommandError, } from "./shared.js";
3
+ export async function layers(file, options) {
4
+ try {
5
+ const items = await drawingFor(file, options).layers();
6
+ output(options, {
7
+ json: () => options.total
8
+ ? { total: items.length, layers: items }
9
+ : { layers: items },
10
+ human: () => {
11
+ if (options.total)
12
+ console.log(String(items.length));
13
+ else
14
+ for (const layer of items)
15
+ console.log(`${layer.name} ${dim(`${layer.entityCount} entities`)}`);
16
+ },
17
+ });
18
+ }
19
+ catch (err) {
20
+ handleCommandError(err);
21
+ }
22
+ }
@@ -0,0 +1,5 @@
1
+ import { type DrawingCommandOptions } from "./shared.js";
2
+ export declare function overview(file: string, options: DrawingCommandOptions & {
3
+ keywords?: string;
4
+ samples?: string;
5
+ }): Promise<void>;
@@ -0,0 +1,59 @@
1
+ import { bold, dim, output } from "../utils/output.js";
2
+ import { drawingFor, handleCommandError, parseLimit, } from "./shared.js";
3
+ export async function overview(file, options) {
4
+ try {
5
+ const result = await drawingFor(file, options).overview({
6
+ keywords: parseLimit(options.keywords),
7
+ samples: parseLimit(options.samples),
8
+ });
9
+ output(options, {
10
+ json: () => result,
11
+ human: () => {
12
+ console.log(dim("WORKFLOW: overview (you are here) → search/entities → view/edit"));
13
+ console.log("");
14
+ console.log(bold("SUMMARY"));
15
+ console.log(` ${result.summary.format} · ${result.summary.counts.entities} entities · ${result.summary.counts.layers} layers · ${result.summary.counts.blocks} blocks`);
16
+ console.log("");
17
+ if (result.layers.length > 0) {
18
+ console.log(bold("LAYERS"));
19
+ for (const layer of result.layers) {
20
+ console.log(layer.name);
21
+ console.log(` ${dim("entities:")} ${layer.entities}`);
22
+ if (layer.types.length > 0) {
23
+ console.log(` ${dim("types:")} ${layer.types.join(", ")}`);
24
+ }
25
+ if (layer.keywords.length > 0) {
26
+ console.log(` ${dim("keywords:")} ${layer.keywords.join(", ")}`);
27
+ }
28
+ }
29
+ console.log("");
30
+ }
31
+ if (result.blocks.length > 0) {
32
+ console.log(bold("BLOCKS"));
33
+ console.log(` ${result.blocks
34
+ .slice(0, 12)
35
+ .map((block) => block.name)
36
+ .join(", ")}`);
37
+ console.log("");
38
+ }
39
+ if (result.text.keywords.length > 0) {
40
+ console.log(bold("TEXT"));
41
+ console.log(` ${dim("keywords:")} ${result.text.keywords.join(", ")}`);
42
+ if (result.text.samples.length > 0) {
43
+ console.log(` ${dim("samples:")} ${result.text.samples.join(" · ")}`);
44
+ }
45
+ console.log("");
46
+ }
47
+ if (result.searchHints.length > 0) {
48
+ console.log(bold("SEARCH HINTS"));
49
+ console.log(` ${result.searchHints.join(", ")}`);
50
+ console.log("");
51
+ }
52
+ console.log(dim("HINT: Use cadcli search <file> <query> or cadcli entities <file> --layer <name> to drill in."));
53
+ },
54
+ });
55
+ }
56
+ catch (err) {
57
+ handleCommandError(err);
58
+ }
59
+ }
@@ -0,0 +1,11 @@
1
+ import { type DrawingCommandOptions } from "./shared.js";
2
+ export interface SearchOptions extends DrawingCommandOptions {
3
+ query?: string;
4
+ type?: string;
5
+ layer?: string;
6
+ limit?: string;
7
+ total?: boolean;
8
+ score?: boolean;
9
+ snippets?: boolean;
10
+ }
11
+ export declare function search(file: string, options: SearchOptions): Promise<void>;
@@ -0,0 +1,45 @@
1
+ import { bold, dim, output } from "../utils/output.js";
2
+ import { drawingFor, handleCommandError, parseLimit, } from "./shared.js";
3
+ export async function search(file, options) {
4
+ try {
5
+ const results = await drawingFor(file, options).search({
6
+ query: options.query,
7
+ type: options.type,
8
+ layer: options.layer,
9
+ limit: parseLimit(options.limit),
10
+ snippets: options.snippets,
11
+ });
12
+ output(options, {
13
+ json: () => {
14
+ if (options.total)
15
+ return { total: results.length };
16
+ return {
17
+ results: results.map((result) => {
18
+ const { score, matches, ...rest } = result;
19
+ return {
20
+ ...rest,
21
+ ...(options.score ? { score } : {}),
22
+ ...(options.snippets === false ? {} : { matches }),
23
+ };
24
+ }),
25
+ };
26
+ },
27
+ human: () => {
28
+ if (options.total) {
29
+ console.log(String(results.length));
30
+ return;
31
+ }
32
+ for (const result of results) {
33
+ console.log(`${bold(result.entityId)} ${result.type}${result.layer ? ` ${dim(result.layer)}` : ""}${options.score ? ` ${dim(`score: ${result.score}`)}` : ""}`);
34
+ if (options.snippets !== false) {
35
+ for (const match of result.matches)
36
+ console.log(` ${dim(match)}`);
37
+ }
38
+ }
39
+ },
40
+ });
41
+ }
42
+ catch (err) {
43
+ handleCommandError(err);
44
+ }
45
+ }
@@ -0,0 +1,16 @@
1
+ import { DwgCliError } from "../core/errors.js";
2
+ import { Dwg } from "../sdk.js";
3
+ import type { DrawingReader } from "../types.js";
4
+ import type { OutputOptions } from "../utils/output.js";
5
+ export interface DrawingCommandOptions extends OutputOptions {
6
+ reader?: DrawingReader;
7
+ toolDir?: string;
8
+ }
9
+ export interface OutputFileOptions extends OutputOptions {
10
+ output?: string;
11
+ }
12
+ export declare function drawingFor(file: string, options: DrawingCommandOptions): Dwg;
13
+ export declare function userError(message: string, code?: string): DwgCliError;
14
+ export declare function handleCommandError(err: unknown): never;
15
+ export declare function parseLimit(value?: string): number | undefined;
16
+ export declare function writeCommandOutput(options: OutputFileOptions, content: string | Uint8Array, jsonPayload: () => unknown, humanMessage: string): void;
@@ -0,0 +1,40 @@
1
+ import { DwgCliError } from "../core/errors.js";
2
+ import { writeOutput } from "../core/files.js";
3
+ import { Dwg } from "../sdk.js";
4
+ import { EXIT_USER_ERROR } from "../utils/exit-codes.js";
5
+ import { error, output, success } from "../utils/output.js";
6
+ export function drawingFor(file, options) {
7
+ return Dwg.open(file, {
8
+ reader: options.reader,
9
+ toolDir: options.toolDir,
10
+ });
11
+ }
12
+ export function userError(message, code = "USER_ERROR") {
13
+ return new DwgCliError(message, code, EXIT_USER_ERROR);
14
+ }
15
+ export function handleCommandError(err) {
16
+ if (err instanceof DwgCliError) {
17
+ error(err.message);
18
+ process.exit(err.exitCode);
19
+ }
20
+ error(err instanceof Error ? err.message : String(err));
21
+ process.exit(1);
22
+ }
23
+ export function parseLimit(value) {
24
+ if (value === undefined)
25
+ return undefined;
26
+ const parsed = Number(value);
27
+ if (!Number.isInteger(parsed) || parsed < 0) {
28
+ throw userError(`Invalid limit: ${value}`, "INVALID_LIMIT");
29
+ }
30
+ return parsed;
31
+ }
32
+ export function writeCommandOutput(options, content, jsonPayload, humanMessage) {
33
+ if (!options.output)
34
+ return;
35
+ writeOutput(options.output, content);
36
+ output(options, {
37
+ json: jsonPayload,
38
+ human: () => success(humanMessage),
39
+ });
40
+ }
@@ -0,0 +1,2 @@
1
+ import { type DrawingCommandOptions, type OutputFileOptions } from "./shared.js";
2
+ export declare function svg(file: string, options: DrawingCommandOptions & OutputFileOptions): Promise<void>;
@@ -0,0 +1,27 @@
1
+ import { toSvg } from "../core/drawing.js";
2
+ import { handleCommandError, writeCommandOutput, } from "./shared.js";
3
+ export async function svg(file, options) {
4
+ try {
5
+ const result = await toSvg(file, {
6
+ reader: options.reader,
7
+ toolDir: options.toolDir,
8
+ });
9
+ if (options.output) {
10
+ writeCommandOutput(options, result.svg, () => ({
11
+ success: true,
12
+ file: options.output,
13
+ rendered: result.rendered,
14
+ unsupported: result.unsupported,
15
+ }), `Wrote ${options.output} (${result.rendered} rendered, ${result.unsupported} unsupported)`);
16
+ }
17
+ else if (options.json) {
18
+ console.log(JSON.stringify(result, null, 2));
19
+ }
20
+ else {
21
+ console.log(result.svg.trimEnd());
22
+ }
23
+ }
24
+ catch (err) {
25
+ handleCommandError(err);
26
+ }
27
+ }
@@ -0,0 +1,2 @@
1
+ import { type DrawingCommandOptions, type OutputFileOptions } from "./shared.js";
2
+ export declare function thumbnail(file: string, options: DrawingCommandOptions & OutputFileOptions): Promise<void>;
@@ -0,0 +1,31 @@
1
+ import { getThumbnail } from "../core/drawing.js";
2
+ import { output, success } from "../utils/output.js";
3
+ import { handleCommandError, writeCommandOutput, } from "./shared.js";
4
+ export async function thumbnail(file, options) {
5
+ try {
6
+ const result = await getThumbnail(file, {
7
+ reader: options.reader,
8
+ toolDir: options.toolDir,
9
+ });
10
+ if (!options.output) {
11
+ output(options, {
12
+ json: () => ({
13
+ mimeType: result.mimeType,
14
+ extension: result.extension,
15
+ bytes: result.data.length,
16
+ }),
17
+ human: () => success(`Thumbnail available (${result.mimeType}, ${result.data.length} bytes). Use -o to write it.`),
18
+ });
19
+ return;
20
+ }
21
+ writeCommandOutput(options, result.data, () => ({
22
+ success: true,
23
+ file: options.output,
24
+ mimeType: result.mimeType,
25
+ bytes: result.data.length,
26
+ }), `Wrote ${options.output}`);
27
+ }
28
+ catch (err) {
29
+ handleCommandError(err);
30
+ }
31
+ }
@@ -0,0 +1,6 @@
1
+ import type { OutputOptions } from "../utils/output.js";
2
+ export interface ViewOptions extends OutputOptions {
3
+ output?: string;
4
+ toolDir?: string;
5
+ }
6
+ export declare function view(file: string, options: ViewOptions): Promise<void>;
@@ -0,0 +1,27 @@
1
+ import { renderSvgWithLibreDwg } from "../core/libredwg.js";
2
+ import { handleCommandError, writeCommandOutput } from "./shared.js";
3
+ export async function view(file, options) {
4
+ try {
5
+ const result = renderSvgWithLibreDwg(file, { toolDir: options.toolDir });
6
+ const svg = result.svg;
7
+ const tool = result.tool;
8
+ if (options.output) {
9
+ writeCommandOutput(options, svg, () => ({
10
+ success: true,
11
+ file: options.output,
12
+ backend: "LibreDWG",
13
+ tool,
14
+ }), `Wrote ${options.output} with ${tool}`);
15
+ return;
16
+ }
17
+ if (options.json) {
18
+ console.log(JSON.stringify({ backend: "LibreDWG", tool, svg }, null, 2));
19
+ }
20
+ else {
21
+ console.log(svg.trimEnd());
22
+ }
23
+ }
24
+ catch (err) {
25
+ handleCommandError(err);
26
+ }
27
+ }
@@ -0,0 +1,14 @@
1
+ import type { CadDocument } from "@node-projects/acad-ts";
2
+ import type { DrawingReader, DwgFormat, ThumbnailResult } from "../types.js";
3
+ export declare function arrayBufferFor(bytes: Uint8Array): ArrayBuffer;
4
+ export declare function normalizeAcadDocument(doc: CadDocument): unknown;
5
+ export declare class AcadTsReader implements DrawingReader {
6
+ parse(_file: string, bytes: Uint8Array, format: DwgFormat): Promise<unknown>;
7
+ thumbnail(): Promise<ThumbnailResult | null>;
8
+ }
9
+ export declare class NativeLibreDwgReader implements DrawingReader {
10
+ private readonly toolDir?;
11
+ constructor(toolDir?: string | undefined);
12
+ parse(file: string, _bytes: Uint8Array, _format: DwgFormat): Promise<unknown>;
13
+ thumbnail(): Promise<ThumbnailResult | null>;
14
+ }