@mlightcad/cad-simple-viewer-cli 1.7.5 → 1.7.6
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 +21 -21
- package/README.md +163 -159
- package/dist/cli.js +2 -0
- package/dist/cli.js.map +1 -1
- package/dist/headlessGpu.js +129 -0
- package/dist/headlessGpu.js.map +1 -0
- package/dist/runHeadless.js +17 -7
- package/dist/runHeadless.js.map +1 -1
- package/dist-runner/assets/cad-html-plugin-CbUd7Vsr.js +1564 -0
- package/dist-runner/assets/{cad-pdf-plugin-Ch3nwhN6.js → cad-pdf-plugin-U1Ic2lCu.js} +86 -86
- package/dist-runner/assets/cad-svg-plugin-nmmfHWYw.js +16 -0
- package/dist-runner/assets/{index-DXwRjL3l.js → index-mwPW-JP3.js} +376 -322
- package/dist-runner/index.html +12 -12
- package/dist-runner/viewer-runtime.iife.js +275 -220
- package/dist-runner/workers/libredwg-parser-worker.js +20 -24
- package/dist-runner/workers/libredwg-web.wasm +0 -0
- package/dist-runner/workers/mtext-renderer-worker.js +2987 -2815
- package/examples/batch-export-html-multi-preview.mjs +306 -306
- package/examples/batch-export-html.mjs +105 -105
- package/examples/batch-export-png.mjs +103 -103
- package/examples/create-drawing-dxf.scr +15 -15
- package/examples/create-drawing-png.scr +19 -19
- package/examples/create-shapes-dxf.scr +17 -17
- package/examples/export-dxf.scr +5 -5
- package/examples/export-html-multi-preview.scr +20 -18
- package/examples/export-html-multi.scr +15 -13
- package/examples/export-html.scr +12 -12
- package/examples/export-pdf.scr +9 -9
- package/examples/export-png.scr +9 -9
- package/examples/freeze-layer-png.scr +15 -15
- package/examples/index.json +114 -114
- package/examples/open-quit.scr +2 -0
- package/package.json +10 -10
- package/dist-runner/assets/cad-html-plugin-DQwlPjG4.js +0 -1564
- package/dist-runner/assets/cad-svg-plugin-C84nxL1t.js +0 -16
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,163 @@
|
|
|
1
|
-
# @mlightcad/cad-simple-viewer-cli
|
|
2
|
-
|
|
3
|
-
[](https://opensource.org/licenses/MIT)
|
|
4
|
-
[](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
|
-
| `--
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
|
81
|
-
|
|
82
|
-
|
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
|
115
|
-
|
|
116
|
-
| `export-
|
|
117
|
-
| `export-
|
|
118
|
-
| `
|
|
119
|
-
| `
|
|
120
|
-
| `
|
|
121
|
-
| `
|
|
122
|
-
| `
|
|
123
|
-
| `
|
|
124
|
-
| `
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
1
|
+
# @mlightcad/cad-simple-viewer-cli
|
|
2
|
+
|
|
3
|
+
[](https://opensource.org/licenses/MIT)
|
|
4
|
+
[](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
|
+
| `--disable-gpu` | Force software WebGL (SwiftShader). Without this flag, hardware GPU is preferred and the CLI falls back to software automatically when no usable GPU is present |
|
|
72
|
+
| `--logfile <path>` | Append start / finish / download log lines |
|
|
73
|
+
|
|
74
|
+
Progressive rendering is always off in CLI mode so drawings open as quickly as possible (headless scripts do not need mid-open paints).
|
|
75
|
+
|
|
76
|
+
Headless Chromium prefers a real GPU for WebGL by default. If the machine has no usable GPU (or the driver is blocked), the CLI automatically falls back to software rendering — you do not need `--disable-gpu` for that case.
|
|
77
|
+
|
|
78
|
+
## AcCoreConsole mapping
|
|
79
|
+
|
|
80
|
+
| AcCoreConsole | cad-simple-viewer-cli |
|
|
81
|
+
|---------------|------------------------|
|
|
82
|
+
| `accoreconsole /i drawing.dwg /s script.scr` | `cad-simple-viewer-cli -i drawing.dwg -s script.scr` |
|
|
83
|
+
| `/i` | `-i, --input` (optional path or URL) |
|
|
84
|
+
| `/s` | `-s, --script` |
|
|
85
|
+
| plot / export path | `-o, --output` (download directory) |
|
|
86
|
+
|
|
87
|
+
## Script format
|
|
88
|
+
|
|
89
|
+
1. First non-blank line of each command is the **command name**
|
|
90
|
+
2. Following lines answer prompts (empty line = Enter / default / None)
|
|
91
|
+
3. Full-line `;` comments are ignored
|
|
92
|
+
4. `QUIT` / `EXIT` ends the script
|
|
93
|
+
|
|
94
|
+
Example — zoom extents, then PNG (long side 2048):
|
|
95
|
+
|
|
96
|
+
```
|
|
97
|
+
; export-png.scr
|
|
98
|
+
zoom
|
|
99
|
+
e
|
|
100
|
+
pngout
|
|
101
|
+
|
|
102
|
+
2048
|
|
103
|
+
quit
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
Useful commands (non-exhaustive): `zoom`, `pngout`, `cdxf`, `-chtml`, `chtml`, `cpdf`, `csvg`, `-layer`, `qnew`, `line`, `circle`, …
|
|
107
|
+
|
|
108
|
+
Layer edits need `--mode write`. Export commands write files via browser download; the CLI captures them into `-o`.
|
|
109
|
+
|
|
110
|
+
## Sample scripts
|
|
111
|
+
|
|
112
|
+
After install, examples live under `node_modules/@mlightcad/cad-simple-viewer-cli/examples/` (or the global package folder):
|
|
113
|
+
|
|
114
|
+
| Script | Purpose |
|
|
115
|
+
|--------|---------|
|
|
116
|
+
| `export-png.scr` | Zoom extents → PNG |
|
|
117
|
+
| `export-html.scr` | Offline HTML (`-chtml`) |
|
|
118
|
+
| `export-html-multi.scr` | Multi-file ACEX package zip (`-chtml` Multi) |
|
|
119
|
+
| `export-html-multi-preview.scr` | Multi ACEX zip + zoom-extents JPEG preview (one run) |
|
|
120
|
+
| `export-dxf.scr` | DXF download (`cdxf`) |
|
|
121
|
+
| `create-drawing-dxf.scr` | Blank drawing + LINE → DXF (no `-i`) |
|
|
122
|
+
| `create-shapes-dxf.scr` | Blank drawing + LINE + CIRCLE → DXF |
|
|
123
|
+
| `create-drawing-png.scr` | Blank drawing → PNG |
|
|
124
|
+
| `freeze-layer-png.scr` | `-layer` Off then PNG (`--mode write`; edit `LAYER_NAME`) |
|
|
125
|
+
| `batch-export-png.mjs` | Scan a folder of drawings → PNG |
|
|
126
|
+
| `batch-export-html.mjs` | Scan a folder → HTML |
|
|
127
|
+
| `batch-export-html-multi-preview.mjs` | Scan a folder → multi ACEX + preview, demo-drawings layout |
|
|
128
|
+
|
|
129
|
+
Batch helpers (from your project after `npm install -D`):
|
|
130
|
+
|
|
131
|
+
```bash
|
|
132
|
+
node node_modules/@mlightcad/cad-simple-viewer-cli/examples/batch-export-png.mjs ./drawings ./out-png
|
|
133
|
+
node node_modules/@mlightcad/cad-simple-viewer-cli/examples/batch-export-html.mjs ./drawings ./out-html
|
|
134
|
+
node node_modules/@mlightcad/cad-simple-viewer-cli/examples/batch-export-html-multi-preview.mjs ./drawings ./out-demo
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
## Programmatic API
|
|
138
|
+
|
|
139
|
+
```js
|
|
140
|
+
import { runHeadless } from '@mlightcad/cad-simple-viewer-cli'
|
|
141
|
+
|
|
142
|
+
const { outputDir, savedFiles } = await runHeadless({
|
|
143
|
+
inputPath: './drawing.dwg', // optional; omit for blank drawing
|
|
144
|
+
scriptPath: './export-png.scr',
|
|
145
|
+
outputDir: './out',
|
|
146
|
+
mode: 'read', // optional
|
|
147
|
+
openViewMode: 'extents', // optional: 'extents' | 'saved'
|
|
148
|
+
drawNoPlotLayers: false, // optional
|
|
149
|
+
circleSides: 50, // optional
|
|
150
|
+
baseUrl: 'https://cdn.example.com/cad-data/', // optional
|
|
151
|
+
locale: 'en', // optional
|
|
152
|
+
useGpu: true, // optional; default true (pass false for --disable-gpu)
|
|
153
|
+
logfile: './cli.log' // optional
|
|
154
|
+
})
|
|
155
|
+
|
|
156
|
+
console.log(outputDir, savedFiles)
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
## How it works
|
|
160
|
+
|
|
161
|
+
1. The published package includes a prebuilt Playwright runner (`dist-runner/`).
|
|
162
|
+
2. The CLI starts headless Chromium (GPU WebGL by default, SwiftShader fallback), opens the drawing (or a blank template) with progressive rendering forced off, waits for entity convert / deferred text geometry, then runs `AcApDocManager.runScript()`.
|
|
163
|
+
3. Export commands trigger downloads; the CLI writes captured files under `-o`.
|
package/dist/cli.js
CHANGED
|
@@ -58,6 +58,7 @@ program
|
|
|
58
58
|
.option('--circle-sides <n>', 'Max segments for circle tessellation (default: 50 draft)', parseCircleSides)
|
|
59
59
|
.option('--locale <code>', 'UI locale for prompts/keywords (e.g. en, zh)', 'en')
|
|
60
60
|
.option('--base-url <url>', 'Resource base URL for fonts and templates (default: CDN cad-data). Fonts load from <url>/fonts/', parseBaseUrl)
|
|
61
|
+
.option('--disable-gpu', 'Force software WebGL (SwiftShader); omit to prefer hardware GPU with automatic fallback')
|
|
61
62
|
.option('--logfile <path>', 'Append runtime log lines to this file')
|
|
62
63
|
.action(async (opts) => {
|
|
63
64
|
try {
|
|
@@ -82,6 +83,7 @@ program
|
|
|
82
83
|
circleSides: opts.circleSides,
|
|
83
84
|
baseUrl: opts.baseUrl,
|
|
84
85
|
locale: opts.locale,
|
|
86
|
+
useGpu: opts.disableGpu ? false : undefined,
|
|
85
87
|
logfile: opts.logfile ? path.resolve(opts.logfile) : undefined
|
|
86
88
|
});
|
|
87
89
|
if (result.savedFiles.length === 0) {
|
package/dist/cli.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";AACA,OAAO,IAAI,MAAM,WAAW,CAAA;AAE5B,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AAEnC,OAAO,EAGL,WAAW,EACZ,MAAM,kBAAkB,CAAA;AAEzB,MAAM,OAAO,GAAG,IAAI,OAAO,EAAE,CAAA;AAE7B,SAAS,SAAS,CAAC,KAAa;IAC9B,IAAI,KAAK,KAAK,MAAM,IAAI,KAAK,KAAK,OAAO,EAAE,CAAC;QAC1C,OAAO,KAAK,CAAA;IACd,CAAC;IACD,MAAM,IAAI,KAAK,CAAC,mBAAmB,KAAK,gCAAgC,CAAC,CAAA;AAC3E,CAAC;AAED,SAAS,iBAAiB,CAAC,KAAa;IACtC,IAAI,KAAK,KAAK,SAAS,IAAI,KAAK,KAAK,OAAO,EAAE,CAAC;QAC7C,OAAO,KAAK,CAAA;IACd,CAAC;IACD,MAAM,IAAI,KAAK,CACb,6BAA6B,KAAK,mCAAmC,CACtE,CAAA;AACH,CAAC;AAED,SAAS,gBAAgB,CAAC,IAAY,EAAE,KAAa;IACnD,MAAM,UAAU,GAAG,KAAK,CAAC,IAAI,EAAE,CAAC,WAAW,EAAE,CAAA;IAC7C,IAAI,UAAU,KAAK,MAAM,IAAI,UAAU,KAAK,GAAG,IAAI,UAAU,KAAK,KAAK,EAAE,CAAC;QACxE,OAAO,IAAI,CAAA;IACb,CAAC;IACD,IAAI,UAAU,KAAK,OAAO,IAAI,UAAU,KAAK,G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,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,SAAS;SAC/D,CAAC,CAAA;QAEF,IAAI,MAAM,CAAC,UAAU,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YACnC,OAAO,CAAC,GAAG,CACT,4DAA4D,MAAM,CAAC,SAAS,IAAI,CACjF,CAAA;QACH,CAAC;aAAM,CAAC;YACN,KAAK,MAAM,IAAI,IAAI,MAAM,CAAC,UAAU,EAAE,CAAC;gBACrC,OAAO,CAAC,GAAG,CAAC,SAAS,IAAI,EAAE,CAAC,CAAA;YAC9B,CAAC;QACH,CAAC;IACH,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,OAAO,GAAG,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAA;QACtE,OAAO,CAAC,KAAK,CAAC,iCAAiC,OAAO,EAAE,CAAC,CAAA;QACzD,IAAI,KAAK,YAAY,KAAK,IAAI,KAAK,CAAC,KAAK,EAAE,CAAC;YAC1C,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,KAAK,CAAC,CAAA;QAC5B,CAAC;QACD,OAAO,CAAC,QAAQ,GAAG,CAAC,CAAA;IACtB,CAAC;AACH,CAAC,CAAC,CAAA;AAEJ,OAAO,CAAC,KAAK,EAAE,CAAA"}
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import { chromium } from 'playwright';
|
|
2
|
+
/**
|
|
3
|
+
* Hardware backends for this OS, then SwiftShader.
|
|
4
|
+
*
|
|
5
|
+
* Playwright's headless Chromium otherwise stays on SwiftShader even when a
|
|
6
|
+
* GPU is present. Each entry is probed; the first real GPU wins.
|
|
7
|
+
*/
|
|
8
|
+
export function gpuBackendOrder(platform = process.platform) {
|
|
9
|
+
switch (platform) {
|
|
10
|
+
case 'win32':
|
|
11
|
+
return ['d3d11', 'd3d9', 'swiftshader'];
|
|
12
|
+
case 'darwin':
|
|
13
|
+
return ['metal', 'gl', 'swiftshader'];
|
|
14
|
+
default:
|
|
15
|
+
return ['vulkan', 'gl', 'egl', 'gles', 'swiftshader'];
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
/** True for CPU rasterizers (SwiftShader, llvmpipe, WARP, …). */
|
|
19
|
+
export function isSoftwareWebGlRenderer(renderer) {
|
|
20
|
+
return /swiftshader|llvmpipe|softpipe|lavapipe|microsoft basic render|software raster/i.test(renderer);
|
|
21
|
+
}
|
|
22
|
+
function chromiumArgsForBackend(backend) {
|
|
23
|
+
const shared = ['--ignore-gpu-blocklist', '--enable-gpu', '--enable-webgl'];
|
|
24
|
+
if (backend === 'swiftshader') {
|
|
25
|
+
return [
|
|
26
|
+
...shared,
|
|
27
|
+
'--use-gl=angle',
|
|
28
|
+
'--use-angle=swiftshader',
|
|
29
|
+
'--enable-unsafe-swiftshader'
|
|
30
|
+
];
|
|
31
|
+
}
|
|
32
|
+
if (backend === 'egl') {
|
|
33
|
+
return [...shared, '--use-gl=egl'];
|
|
34
|
+
}
|
|
35
|
+
return [...shared, '--use-gl=angle', `--use-angle=${backend}`];
|
|
36
|
+
}
|
|
37
|
+
async function probeWebGlRenderer(browser) {
|
|
38
|
+
const page = await browser.newPage();
|
|
39
|
+
try {
|
|
40
|
+
return await page.evaluate(() => {
|
|
41
|
+
const canvas = document.createElement('canvas');
|
|
42
|
+
const gl = canvas.getContext('webgl2') || canvas.getContext('webgl');
|
|
43
|
+
if (!gl)
|
|
44
|
+
return 'unavailable';
|
|
45
|
+
const ext = gl.getExtension('WEBGL_debug_renderer_info');
|
|
46
|
+
const renderer = ext
|
|
47
|
+
? gl.getParameter(ext.UNMASKED_RENDERER_WEBGL)
|
|
48
|
+
: gl.getParameter(gl.RENDERER);
|
|
49
|
+
return renderer ? String(renderer) : 'unavailable';
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
catch {
|
|
53
|
+
return 'unavailable';
|
|
54
|
+
}
|
|
55
|
+
finally {
|
|
56
|
+
await page.close().catch(() => undefined);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
async function launchSwiftShader(base) {
|
|
60
|
+
const browser = await chromium.launch({
|
|
61
|
+
...base,
|
|
62
|
+
args: chromiumArgsForBackend('swiftshader')
|
|
63
|
+
});
|
|
64
|
+
const renderer = await probeWebGlRenderer(browser);
|
|
65
|
+
return { browser, renderer, backend: 'swiftshader' };
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Launches headless Chromium for WebGL.
|
|
69
|
+
*
|
|
70
|
+
* With {@link LaunchHeadlessChromiumOptions.useGpu} `true` (default), probes
|
|
71
|
+
* hardware backends for this OS and falls back to SwiftShader when none work.
|
|
72
|
+
* With `useGpu` `false`, skips the probe and uses SwiftShader immediately.
|
|
73
|
+
*/
|
|
74
|
+
export async function launchHeadlessChromium(options = {}) {
|
|
75
|
+
const channel = options.channel;
|
|
76
|
+
const platform = options.platform ?? process.platform;
|
|
77
|
+
const useGpu = options.useGpu !== false;
|
|
78
|
+
const base = {
|
|
79
|
+
headless: true,
|
|
80
|
+
...(channel ? { channel } : {})
|
|
81
|
+
};
|
|
82
|
+
if (!useGpu) {
|
|
83
|
+
console.log('[cad-simple-viewer-cli] GPU disabled; using software renderer (SwiftShader)');
|
|
84
|
+
return launchSwiftShader(base);
|
|
85
|
+
}
|
|
86
|
+
let software;
|
|
87
|
+
const skipped = [];
|
|
88
|
+
for (const backend of gpuBackendOrder(platform)) {
|
|
89
|
+
let browser;
|
|
90
|
+
try {
|
|
91
|
+
browser = await chromium.launch({
|
|
92
|
+
...base,
|
|
93
|
+
args: chromiumArgsForBackend(backend)
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
catch (error) {
|
|
97
|
+
skipped.push(`${backend} (${error instanceof Error ? error.message : String(error)})`);
|
|
98
|
+
continue;
|
|
99
|
+
}
|
|
100
|
+
const renderer = await probeWebGlRenderer(browser);
|
|
101
|
+
if (renderer === 'unavailable') {
|
|
102
|
+
skipped.push(`${backend} (no WebGL)`);
|
|
103
|
+
await browser.close().catch(() => undefined);
|
|
104
|
+
continue;
|
|
105
|
+
}
|
|
106
|
+
if (!isSoftwareWebGlRenderer(renderer)) {
|
|
107
|
+
if (software) {
|
|
108
|
+
await software.browser.close().catch(() => undefined);
|
|
109
|
+
}
|
|
110
|
+
return { browser, renderer, backend };
|
|
111
|
+
}
|
|
112
|
+
skipped.push(`${backend} (${renderer})`);
|
|
113
|
+
if (!software) {
|
|
114
|
+
software = { browser, renderer, backend };
|
|
115
|
+
}
|
|
116
|
+
else {
|
|
117
|
+
await browser.close().catch(() => undefined);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
if (software) {
|
|
121
|
+
if (skipped.length > 0) {
|
|
122
|
+
console.log(`[cad-simple-viewer-cli] no hardware WebGL; using software renderer. Tried ${skipped.join('; ')}`);
|
|
123
|
+
}
|
|
124
|
+
return software;
|
|
125
|
+
}
|
|
126
|
+
console.log('[cad-simple-viewer-cli] no hardware WebGL; falling back to SwiftShader');
|
|
127
|
+
return launchSwiftShader(base);
|
|
128
|
+
}
|
|
129
|
+
//# sourceMappingURL=headlessGpu.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"headlessGpu.js","sourceRoot":"","sources":["../src/headlessGpu.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgB,QAAQ,EAAE,MAAM,YAAY,CAAA;AAuBnD;;;;;GAKG;AACH,MAAM,UAAU,eAAe,CAC7B,WAA4B,OAAO,CAAC,QAAQ;IAE5C,QAAQ,QAAQ,EAAE,CAAC;QACjB,KAAK,OAAO;YACV,OAAO,CAAC,OAAO,EAAE,MAAM,EAAE,aAAa,CAAC,CAAA;QACzC,KAAK,QAAQ;YACX,OAAO,CAAC,OAAO,EAAE,IAAI,EAAE,aAAa,CAAC,CAAA;QACvC;YACE,OAAO,CAAC,QAAQ,EAAE,IAAI,EAAE,KAAK,E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Q,EAAE,OAAO,EAAE,CAAA;QAC3C,CAAC;aAAM,CAAC;YACN,MAAM,OAAO,CAAC,KAAK,EAAE,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,CAAA;QAC9C,CAAC;IACH,CAAC;IAED,IAAI,QAAQ,EAAE,CAAC;QACb,IAAI,OAAO,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YACvB,OAAO,CAAC,GAAG,CACT,6EAA6E,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAClG,CAAA;QACH,CAAC;QACD,OAAO,QAAQ,CAAA;IACjB,CAAC;IAED,OAAO,CAAC,GAAG,CACT,wEAAwE,CACzE,CAAA;IACD,OAAO,iBAAiB,CAAC,IAAI,CAAC,CAAA;AAChC,CAAC"}
|
package/dist/runHeadless.js
CHANGED
|
@@ -3,7 +3,7 @@ import { mkdir, readFile, writeFile } from 'node:fs/promises';
|
|
|
3
3
|
import { createServer } from 'node:http';
|
|
4
4
|
import path from 'node:path';
|
|
5
5
|
import { fileURLToPath } from 'node:url';
|
|
6
|
-
import {
|
|
6
|
+
import { launchHeadlessChromium } from './headlessGpu.js';
|
|
7
7
|
/**
|
|
8
8
|
* Resolves the `@mlightcad/cad-simple-viewer-cli` package root
|
|
9
9
|
* (parent of the compiled `dist/` directory).
|
|
@@ -222,7 +222,7 @@ export class HeadlessCadSession {
|
|
|
222
222
|
this.server = server;
|
|
223
223
|
this.launchMs = launchMs;
|
|
224
224
|
}
|
|
225
|
-
static async create() {
|
|
225
|
+
static async create(options = {}) {
|
|
226
226
|
const runnerDir = runnerDistDir();
|
|
227
227
|
if (!existsSync(path.join(runnerDir, 'index.html'))) {
|
|
228
228
|
throw new Error('CLI runner is not built. Run "pnpm --filter @mlightcad/cad-simple-viewer-cli build".');
|
|
@@ -230,10 +230,12 @@ export class HeadlessCadSession {
|
|
|
230
230
|
const t0 = performance.now();
|
|
231
231
|
const server = await startCliStaticServer(runnerDir);
|
|
232
232
|
const channel = process.env.PLAYWRIGHT_BROWSER_CHANNEL;
|
|
233
|
-
const
|
|
234
|
-
|
|
235
|
-
|
|
233
|
+
const gpu = await launchHeadlessChromium({
|
|
234
|
+
channel,
|
|
235
|
+
useGpu: options.useGpu
|
|
236
236
|
});
|
|
237
|
+
const browser = gpu.browser;
|
|
238
|
+
console.log(`[cad-simple-viewer-cli] webgl: ${gpu.renderer} (${gpu.backend})`);
|
|
237
239
|
const context = await browser.newContext({ acceptDownloads: true });
|
|
238
240
|
const page = await context.newPage();
|
|
239
241
|
page.on('console', msg => {
|
|
@@ -251,6 +253,11 @@ export class HeadlessCadSession {
|
|
|
251
253
|
page.on('pageerror', error => {
|
|
252
254
|
console.error('[cad-simple-viewer-cli] page error:', error.message);
|
|
253
255
|
});
|
|
256
|
+
page.on('response', response => {
|
|
257
|
+
if (response.status() < 400)
|
|
258
|
+
return;
|
|
259
|
+
console.warn(`[cad-simple-viewer-cli] HTTP ${response.status()} ${response.url()}`);
|
|
260
|
+
});
|
|
254
261
|
await page.goto(`${server.url}/index.html`, { waitUntil: 'networkidle' });
|
|
255
262
|
const launchMs = performance.now() - t0;
|
|
256
263
|
console.log(`[cad-simple-viewer-cli] browser ready: ${launchMs.toFixed(0)} ms`);
|
|
@@ -368,7 +375,7 @@ export class HeadlessCadSession {
|
|
|
368
375
|
* browser and WASM parser stay warm across files.
|
|
369
376
|
*/
|
|
370
377
|
export async function runHeadless(options) {
|
|
371
|
-
const session = await HeadlessCadSession.create();
|
|
378
|
+
const session = await HeadlessCadSession.create({ useGpu: options.useGpu });
|
|
372
379
|
try {
|
|
373
380
|
return await session.run(options);
|
|
374
381
|
}
|
|
@@ -378,12 +385,15 @@ export async function runHeadless(options) {
|
|
|
378
385
|
}
|
|
379
386
|
/**
|
|
380
387
|
* Runs the same script against many drawings in one Chromium session.
|
|
388
|
+
*
|
|
389
|
+
* GPU preference is taken from the first job's {@link RunHeadlessOptions.useGpu}
|
|
390
|
+
* (default: hardware when available).
|
|
381
391
|
*/
|
|
382
392
|
export async function runHeadlessBatch(jobs) {
|
|
383
393
|
if (jobs.length === 0) {
|
|
384
394
|
return [];
|
|
385
395
|
}
|
|
386
|
-
const session = await HeadlessCadSession.create();
|
|
396
|
+
const session = await HeadlessCadSession.create({ useGpu: jobs[0].useGpu });
|
|
387
397
|
const results = [];
|
|
388
398
|
try {
|
|
389
399
|
for (const job of jobs) {
|