@mlightcad/cad-simple-viewer-cli 1.7.4 → 1.7.5

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/LICENSE CHANGED
@@ -1,21 +1,21 @@
1
- MIT License
2
-
3
- Copyright (c) 2026 mlightcad
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.
1
+ MIT License
2
+
3
+ Copyright (c) 2026 mlightcad
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 CHANGED
@@ -1,159 +1,159 @@
1
- # @mlightcad/cad-simple-viewer-cli
2
-
3
- [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
4
- [![npm version](https://img.shields.io/npm/v/@mlightcad/cad-simple-viewer-cli.svg)](https://www.npmjs.com/package/@mlightcad/cad-simple-viewer-cli)
5
-
6
- AcCoreConsole-style **headless** CLI for MLight CAD Viewer. Install from npm, open a DXF/DWG (or start blank), run an AutoCAD-like **`.scr` command script**, and save exports (`pngout`, `-chtml`, `cdxf`, …) to disk.
7
-
8
- Requires **Node.js 20+**. The CLI uses headless Chromium via Playwright; on first use you must install the browser once.
9
-
10
- ## Install
11
-
12
- ```bash
13
- npm install -g @mlightcad/cad-simple-viewer-cli
14
- npx playwright install chromium
15
- ```
16
-
17
- Or as a project dependency:
18
-
19
- ```bash
20
- npm install -D @mlightcad/cad-simple-viewer-cli
21
- npx playwright install chromium
22
- ```
23
-
24
- ## Quick start
25
-
26
- ```bash
27
- # Export a drawing to PNG (sample script shipped with the package)
28
- cad-simple-viewer-cli \
29
- -i ./drawing.dwg \
30
- -s node_modules/@mlightcad/cad-simple-viewer-cli/examples/export-png.scr \
31
- -o ./out
32
-
33
- # Global install: same, with your own script
34
- cad-simple-viewer-cli -i ./drawing.dxf -s ./export-png.scr -o ./out
35
-
36
- # Open from URL
37
- cad-simple-viewer-cli \
38
- -i https://cdn.jsdelivr.net/gh/mlightcad/cad-data@main/data/canteen.dwg \
39
- -s ./export-png.scr \
40
- -o ./out
41
-
42
- # No input file: start from a blank ISO drawing (write mode)
43
- cad-simple-viewer-cli -s ./create-drawing-dxf.scr -o ./out --mode write
44
-
45
- # Host fonts and templates yourself (fonts live under <base-url>/fonts/)
46
- cad-simple-viewer-cli \
47
- -i ./drawing.dwg \
48
- -s ./export-png.scr \
49
- --base-url https://cdn.example.com/cad-data/
50
- ```
51
-
52
- With a local install, use `npx`:
53
-
54
- ```bash
55
- npx cad-simple-viewer-cli -i ./drawing.dwg -s ./export-png.scr -o ./out
56
- ```
57
-
58
- ## Options
59
-
60
- | Option | Description |
61
- |--------|-------------|
62
- | `-i, --input <file-or-url>` | Local `.dxf` / `.dwg` path or `http(s)` URL. Omit to start from a blank ISO template |
63
- | `-s, --script <file>` | `.scr` command script (**required**) |
64
- | `-o, --output <dir>` | Directory for downloaded exports (default: input file’s directory, or cwd when no `-i`) |
65
- | `--mode <read\|write>` | Document open mode (default: `read` with `-i`, `write` without `-i`) |
66
- | `--open-view-mode <extents\|saved>` | Frame view after open: `extents` (full drawing) or `saved` (AutoCAD VPORT). Default: `extents` in read, `saved` in write |
67
- | `--draw-no-plot-layers <true\|false>` | Draw entities on non-plottable layers (default: `false`) |
68
- | `--circle-sides <n>` | Max segments for circle tessellation (default: `50` draft) |
69
- | `--locale <code>` | Prompt/keyword locale (`en`, `zh`, …) |
70
- | `--base-url <url>` | Resource base URL for fonts and templates (`http(s)`). Fonts load from `<url>/fonts/`. Default: CDN `cad-data` |
71
- | `--logfile <path>` | Append start / finish / download log lines |
72
-
73
- Progressive rendering is always off in CLI mode so drawings open as quickly as possible (headless scripts do not need mid-open paints).
74
-
75
- ## AcCoreConsole mapping
76
-
77
- | AcCoreConsole | cad-simple-viewer-cli |
78
- |---------------|------------------------|
79
- | `accoreconsole /i drawing.dwg /s script.scr` | `cad-simple-viewer-cli -i drawing.dwg -s script.scr` |
80
- | `/i` | `-i, --input` (optional path or URL) |
81
- | `/s` | `-s, --script` |
82
- | plot / export path | `-o, --output` (download directory) |
83
-
84
- ## Script format
85
-
86
- 1. First non-blank line of each command is the **command name**
87
- 2. Following lines answer prompts (empty line = Enter / default / None)
88
- 3. Full-line `;` comments are ignored
89
- 4. `QUIT` / `EXIT` ends the script
90
-
91
- Example — zoom extents, then PNG (long side 2048):
92
-
93
- ```
94
- ; export-png.scr
95
- zoom
96
- e
97
- pngout
98
-
99
- 2048
100
- quit
101
- ```
102
-
103
- Useful commands (non-exhaustive): `zoom`, `pngout`, `cdxf`, `-chtml`, `chtml`, `cpdf`, `csvg`, `-layer`, `qnew`, `line`, `circle`, …
104
-
105
- Layer edits need `--mode write`. Export commands write files via browser download; the CLI captures them into `-o`.
106
-
107
- ## Sample scripts
108
-
109
- After install, examples live under `node_modules/@mlightcad/cad-simple-viewer-cli/examples/` (or the global package folder):
110
-
111
- | Script | Purpose |
112
- |--------|---------|
113
- | `export-png.scr` | Zoom extents → PNG |
114
- | `export-html.scr` | Offline HTML (`-chtml`) |
115
- | `export-html-multi.scr` | Multi-file ACEX package zip (`-chtml` Multi) |
116
- | `export-html-multi-preview.scr` | Multi ACEX zip + zoom-extents JPEG preview (one run) |
117
- | `export-dxf.scr` | DXF download (`cdxf`) |
118
- | `create-drawing-dxf.scr` | Blank drawing + LINE → DXF (no `-i`) |
119
- | `create-shapes-dxf.scr` | Blank drawing + LINE + CIRCLE → DXF |
120
- | `create-drawing-png.scr` | Blank drawing → PNG |
121
- | `freeze-layer-png.scr` | `-layer` Off then PNG (`--mode write`; edit `LAYER_NAME`) |
122
- | `batch-export-png.mjs` | Scan a folder of drawings → PNG |
123
- | `batch-export-html.mjs` | Scan a folder → HTML |
124
- | `batch-export-html-multi-preview.mjs` | Scan a folder → multi ACEX + preview, demo-drawings layout |
125
-
126
- Batch helpers (from your project after `npm install -D`):
127
-
128
- ```bash
129
- node node_modules/@mlightcad/cad-simple-viewer-cli/examples/batch-export-png.mjs ./drawings ./out-png
130
- node node_modules/@mlightcad/cad-simple-viewer-cli/examples/batch-export-html.mjs ./drawings ./out-html
131
- node node_modules/@mlightcad/cad-simple-viewer-cli/examples/batch-export-html-multi-preview.mjs ./drawings ./out-demo
132
- ```
133
-
134
- ## Programmatic API
135
-
136
- ```js
137
- import { runHeadless } from '@mlightcad/cad-simple-viewer-cli'
138
-
139
- const { outputDir, savedFiles } = await runHeadless({
140
- inputPath: './drawing.dwg', // optional; omit for blank drawing
141
- scriptPath: './export-png.scr',
142
- outputDir: './out',
143
- mode: 'read', // optional
144
- openViewMode: 'extents', // optional: 'extents' | 'saved'
145
- drawNoPlotLayers: false, // optional
146
- circleSides: 50, // optional
147
- baseUrl: 'https://cdn.example.com/cad-data/', // optional
148
- locale: 'en', // optional
149
- logfile: './cli.log' // optional
150
- })
151
-
152
- console.log(outputDir, savedFiles)
153
- ```
154
-
155
- ## How it works
156
-
157
- 1. The published package includes a prebuilt Playwright runner (`dist-runner/`).
158
- 2. The CLI starts headless Chromium, opens the drawing (or a blank template) with progressive rendering forced off, waits for entity convert / deferred text geometry, then runs `AcApDocManager.runScript()`.
159
- 3. Export commands trigger downloads; the CLI writes captured files under `-o`.
1
+ # @mlightcad/cad-simple-viewer-cli
2
+
3
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
4
+ [![npm version](https://img.shields.io/npm/v/@mlightcad/cad-simple-viewer-cli.svg)](https://www.npmjs.com/package/@mlightcad/cad-simple-viewer-cli)
5
+
6
+ AcCoreConsole-style **headless** CLI for MLight CAD Viewer. Install from npm, open a DXF/DWG (or start blank), run an AutoCAD-like **`.scr` command script**, and save exports (`pngout`, `-chtml`, `cdxf`, …) to disk.
7
+
8
+ Requires **Node.js 20+**. The CLI uses headless Chromium via Playwright; on first use you must install the browser once.
9
+
10
+ ## Install
11
+
12
+ ```bash
13
+ npm install -g @mlightcad/cad-simple-viewer-cli
14
+ npx playwright install chromium
15
+ ```
16
+
17
+ Or as a project dependency:
18
+
19
+ ```bash
20
+ npm install -D @mlightcad/cad-simple-viewer-cli
21
+ npx playwright install chromium
22
+ ```
23
+
24
+ ## Quick start
25
+
26
+ ```bash
27
+ # Export a drawing to PNG (sample script shipped with the package)
28
+ cad-simple-viewer-cli \
29
+ -i ./drawing.dwg \
30
+ -s node_modules/@mlightcad/cad-simple-viewer-cli/examples/export-png.scr \
31
+ -o ./out
32
+
33
+ # Global install: same, with your own script
34
+ cad-simple-viewer-cli -i ./drawing.dxf -s ./export-png.scr -o ./out
35
+
36
+ # Open from URL
37
+ cad-simple-viewer-cli \
38
+ -i https://cdn.jsdelivr.net/gh/mlightcad/cad-data@main/data/canteen.dwg \
39
+ -s ./export-png.scr \
40
+ -o ./out
41
+
42
+ # No input file: start from a blank ISO drawing (write mode)
43
+ cad-simple-viewer-cli -s ./create-drawing-dxf.scr -o ./out --mode write
44
+
45
+ # Host fonts and templates yourself (fonts live under <base-url>/fonts/)
46
+ cad-simple-viewer-cli \
47
+ -i ./drawing.dwg \
48
+ -s ./export-png.scr \
49
+ --base-url https://cdn.example.com/cad-data/
50
+ ```
51
+
52
+ With a local install, use `npx`:
53
+
54
+ ```bash
55
+ npx cad-simple-viewer-cli -i ./drawing.dwg -s ./export-png.scr -o ./out
56
+ ```
57
+
58
+ ## Options
59
+
60
+ | Option | Description |
61
+ |--------|-------------|
62
+ | `-i, --input <file-or-url>` | Local `.dxf` / `.dwg` path or `http(s)` URL. Omit to start from a blank ISO template |
63
+ | `-s, --script <file>` | `.scr` command script (**required**) |
64
+ | `-o, --output <dir>` | Directory for downloaded exports (default: input file’s directory, or cwd when no `-i`) |
65
+ | `--mode <read\|write>` | Document open mode (default: `read` with `-i`, `write` without `-i`) |
66
+ | `--open-view-mode <extents\|saved>` | Frame view after open: `extents` (full drawing) or `saved` (AutoCAD VPORT). Default: `extents` in read, `saved` in write |
67
+ | `--draw-no-plot-layers <true\|false>` | Draw entities on non-plottable layers (default: `false`) |
68
+ | `--circle-sides <n>` | Max segments for circle tessellation (default: `50` draft) |
69
+ | `--locale <code>` | Prompt/keyword locale (`en`, `zh`, …) |
70
+ | `--base-url <url>` | Resource base URL for fonts and templates (`http(s)`). Fonts load from `<url>/fonts/`. Default: CDN `cad-data` |
71
+ | `--logfile <path>` | Append start / finish / download log lines |
72
+
73
+ Progressive rendering is always off in CLI mode so drawings open as quickly as possible (headless scripts do not need mid-open paints).
74
+
75
+ ## AcCoreConsole mapping
76
+
77
+ | AcCoreConsole | cad-simple-viewer-cli |
78
+ |---------------|------------------------|
79
+ | `accoreconsole /i drawing.dwg /s script.scr` | `cad-simple-viewer-cli -i drawing.dwg -s script.scr` |
80
+ | `/i` | `-i, --input` (optional path or URL) |
81
+ | `/s` | `-s, --script` |
82
+ | plot / export path | `-o, --output` (download directory) |
83
+
84
+ ## Script format
85
+
86
+ 1. First non-blank line of each command is the **command name**
87
+ 2. Following lines answer prompts (empty line = Enter / default / None)
88
+ 3. Full-line `;` comments are ignored
89
+ 4. `QUIT` / `EXIT` ends the script
90
+
91
+ Example — zoom extents, then PNG (long side 2048):
92
+
93
+ ```
94
+ ; export-png.scr
95
+ zoom
96
+ e
97
+ pngout
98
+
99
+ 2048
100
+ quit
101
+ ```
102
+
103
+ Useful commands (non-exhaustive): `zoom`, `pngout`, `cdxf`, `-chtml`, `chtml`, `cpdf`, `csvg`, `-layer`, `qnew`, `line`, `circle`, …
104
+
105
+ Layer edits need `--mode write`. Export commands write files via browser download; the CLI captures them into `-o`.
106
+
107
+ ## Sample scripts
108
+
109
+ After install, examples live under `node_modules/@mlightcad/cad-simple-viewer-cli/examples/` (or the global package folder):
110
+
111
+ | Script | Purpose |
112
+ |--------|---------|
113
+ | `export-png.scr` | Zoom extents → PNG |
114
+ | `export-html.scr` | Offline HTML (`-chtml`) |
115
+ | `export-html-multi.scr` | Multi-file ACEX package zip (`-chtml` Multi) |
116
+ | `export-html-multi-preview.scr` | Multi ACEX zip + zoom-extents JPEG preview (one run) |
117
+ | `export-dxf.scr` | DXF download (`cdxf`) |
118
+ | `create-drawing-dxf.scr` | Blank drawing + LINE → DXF (no `-i`) |
119
+ | `create-shapes-dxf.scr` | Blank drawing + LINE + CIRCLE → DXF |
120
+ | `create-drawing-png.scr` | Blank drawing → PNG |
121
+ | `freeze-layer-png.scr` | `-layer` Off then PNG (`--mode write`; edit `LAYER_NAME`) |
122
+ | `batch-export-png.mjs` | Scan a folder of drawings → PNG |
123
+ | `batch-export-html.mjs` | Scan a folder → HTML |
124
+ | `batch-export-html-multi-preview.mjs` | Scan a folder → multi ACEX + preview, demo-drawings layout |
125
+
126
+ Batch helpers (from your project after `npm install -D`):
127
+
128
+ ```bash
129
+ node node_modules/@mlightcad/cad-simple-viewer-cli/examples/batch-export-png.mjs ./drawings ./out-png
130
+ node node_modules/@mlightcad/cad-simple-viewer-cli/examples/batch-export-html.mjs ./drawings ./out-html
131
+ node node_modules/@mlightcad/cad-simple-viewer-cli/examples/batch-export-html-multi-preview.mjs ./drawings ./out-demo
132
+ ```
133
+
134
+ ## Programmatic API
135
+
136
+ ```js
137
+ import { runHeadless } from '@mlightcad/cad-simple-viewer-cli'
138
+
139
+ const { outputDir, savedFiles } = await runHeadless({
140
+ inputPath: './drawing.dwg', // optional; omit for blank drawing
141
+ scriptPath: './export-png.scr',
142
+ outputDir: './out',
143
+ mode: 'read', // optional
144
+ openViewMode: 'extents', // optional: 'extents' | 'saved'
145
+ drawNoPlotLayers: false, // optional
146
+ circleSides: 50, // optional
147
+ baseUrl: 'https://cdn.example.com/cad-data/', // optional
148
+ locale: 'en', // optional
149
+ logfile: './cli.log' // optional
150
+ })
151
+
152
+ console.log(outputDir, savedFiles)
153
+ ```
154
+
155
+ ## How it works
156
+
157
+ 1. The published package includes a prebuilt Playwright runner (`dist-runner/`).
158
+ 2. The CLI starts headless Chromium, opens the drawing (or a blank template) with progressive rendering forced off, waits for entity convert / deferred text geometry, then runs `AcApDocManager.runScript()`.
159
+ 3. Export commands trigger downloads; the CLI writes captured files under `-o`.