@mlightcad/cad-pdf-plugin 1.7.6-preview.0 → 1.7.7-preview.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/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,180 +1,180 @@
1
- # @mlightcad/cad-pdf-plugin
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-pdf-plugin.svg)](https://www.npmjs.com/package/@mlightcad/cad-pdf-plugin)
5
-
6
- PDF **export** and **import** plugin for [`@mlightcad/cad-simple-viewer`](../cad-simple-viewer). Registers system commands:
7
-
8
- | Command | Description |
9
- |---------|-------------|
10
- | `-cpdf` | Export via **command-line prompts** (no dialog; AutoCAD-style `-` prefix) |
11
- | `cpdf` | Same as `-cpdf` when no UI command is registered. In [`cad-viewer`](../cad-viewer), `cpdf` opens an **export options dialog** instead |
12
- | `ipdf` | Import vector geometry from a PDF file into model space |
13
-
14
- The plugin is designed for **lazy loading** so PDF libraries (`pdf-lib` via `@mlightcad/pdf-renderer`, `pdfjs-dist`) are only downloaded when a user runs `-cpdf` / `cpdf` or `ipdf`.
15
-
16
- ## Key features
17
-
18
- - **Vector PDF export** — renders model space and each paper-space layout as PDF pages with `@mlightcad/pdf-renderer` (native AcGi PDF backend). Paper-space pages include model content shown through viewports, clipped to each viewport frame.
19
- - **Busy indicator** — export shows the same conversion spinner as `chtml` so the browser stays responsive
20
- - **Export options** — model-space framing (`Extents` / `Display`) and optional paper-space layouts
21
- - **PDF import** — parses vector paths from the first page of a PDF (lines, polylines, Bézier curves) and appends CAD entities
22
- - **Plugin API** — implements `AcApPlugin`; register once with `registerLazyPdfPlugin`
23
- - **Framework-agnostic** — no Vue/React dependency; works anywhere `cad-simple-viewer` runs
24
-
25
- ## Installation
26
-
27
- ```bash
28
- pnpm add @mlightcad/cad-pdf-plugin
29
- ```
30
-
31
- Peer dependencies:
32
-
33
- - `@mlightcad/cad-simple-viewer`
34
- - `@mlightcad/data-model`
35
- - `@mlightcad/pdf-renderer`
36
-
37
- Runtime dependencies (bundled with this package):
38
-
39
- - `pdfjs-dist` (import only)
40
-
41
- ## Build
42
-
43
- Produces `dist/index.js` (main library) and `dist/register.js` (lazy-registration entry).
44
-
45
- ```bash
46
- pnpm --filter @mlightcad/cad-pdf-plugin build
47
- ```
48
-
49
- ## Usage
50
-
51
- ### Lazy registration (recommended)
52
-
53
- Register the plugin with the document manager's plugin manager. Import from the `/register` subpath so only the registration stub enters your initial bundle; the main plugin chunk loads on first use of `-cpdf`, `cpdf`, or `ipdf`:
54
-
55
- ```typescript
56
- import { AcApDocManager } from '@mlightcad/cad-simple-viewer'
57
- import { registerLazyPdfPlugin } from '@mlightcad/cad-pdf-plugin/register'
58
-
59
- registerLazyPdfPlugin(AcApDocManager.instance.pluginManager)
60
- ```
61
-
62
- Do **not** import `registerLazyPdfPlugin` from the package root in application code — that resolves to the full library build and defeats lazy loading.
63
-
64
- Equivalent manual registration:
65
-
66
- ```typescript
67
- import {
68
- createPdfPlugin,
69
- PDF_PLUGIN_NAME,
70
- PDF_PLUGIN_TRIGGERS
71
- } from '@mlightcad/cad-pdf-plugin'
72
-
73
- AcApDocManager.instance.pluginManager.registerLazyPlugin({
74
- name: PDF_PLUGIN_NAME,
75
- triggers: [...PDF_PLUGIN_TRIGGERS],
76
- loader: createPdfPlugin
77
- })
78
- ```
79
-
80
- After registration, users (or your UI) invoke commands through the editor:
81
-
82
- ```typescript
83
- // Export current drawing to PDF (command-line prompts)
84
- await AcApDocManager.instance.editor.executeCommand('-cpdf')
85
-
86
- // Open file picker and import PDF vectors
87
- await AcApDocManager.instance.editor.executeCommand('ipdf')
88
- ```
89
-
90
- In [`cad-viewer`](../cad-viewer), use `cpdf` to open the export options dialog; `-cpdf` remains available on the command line for prompt-based export.
91
-
92
- `cad-viewer` registers this plugin automatically via `registerLazyPlugins()` in its app bootstrap and registers the `cpdf` dialog command separately.
93
-
94
- ### Eager registration
95
-
96
- If you prefer loading PDF support up front:
97
-
98
- ```typescript
99
- import { AcApPdfPlugin } from '@mlightcad/cad-pdf-plugin'
100
-
101
- await AcApDocManager.instance.pluginManager.loadPlugin(new AcApPdfPlugin())
102
- ```
103
-
104
- ### Programmatic convertors
105
-
106
- You can bypass the command layer and call the convertors directly:
107
-
108
- ```typescript
109
- import { AcApContext } from '@mlightcad/cad-simple-viewer'
110
- import {
111
- AcApPdfConvertor,
112
- AcApPdfImportConvertor,
113
- resolveAcApPdfExportOptions
114
- } from '@mlightcad/cad-pdf-plugin'
115
-
116
- // Export
117
- const context: AcApContext = /* active context */
118
- await new AcApPdfConvertor().convert(
119
- context,
120
- resolveAcApPdfExportOptions({
121
- modelSpaceFit: 'extents',
122
- exportLayouts: true
123
- })
124
- )
125
-
126
- // Import from bytes
127
- const buffer: ArrayBuffer = /* PDF file */
128
- await new AcApPdfImportConvertor().convert(context, buffer, 1) // page 1
129
- ```
130
-
131
- ## How it works
132
-
133
- ### Export (`-cpdf` / dialog)
134
-
135
- 1. Collect options: model-space framing (`Extents` / `Display`) and whether to export layouts.
136
- 2. Show the application busy overlay (same animation pattern as `chtml`).
137
- 3. Call `@mlightcad/pdf-renderer` `exportDatabaseToPdf`. With layouts enabled, model space and every paper space become one PDF page each.
138
- 4. Download the resulting PDF bytes.
139
-
140
- ### Import (`ipdf`)
141
-
142
- 1. Show a native file picker (`.pdf`).
143
- 2. Use `pdfjs-dist` to read operator lists from the selected page.
144
- 3. Convert path operators (move, line, cubic Bézier, close) into `AcDbLine` / `AcDbPolyline` entities in model space.
145
-
146
- Import is **vector-only**; raster/scanned PDF pages produce no entities. Only the requested page is processed (default: page 1).
147
-
148
- ## Main exports
149
-
150
- | Export | Role |
151
- |--------|------|
152
- | `createPdfPlugin` | Async factory used by lazy loader |
153
- | `PDF_PLUGIN_NAME`, `PDF_PLUGIN_TRIGGERS` | Plugin id and command triggers |
154
- | `@mlightcad/cad-pdf-plugin/register` | `registerLazyPdfPlugin` and registration constants |
155
- | `AcApPdfPlugin` | `AcApPlugin` implementation |
156
- | `AcApConvertToPdfCmd` | `-cpdf` / fallback `cpdf` command class |
157
- | `AcApImportPdfCmd` | `ipdf` command class |
158
- | `AcApPdfConvertor` | CAD → PDF export utility |
159
- | `AcApPdfExportOptions`, `resolveAcApPdfExportOptions` | Export option types and defaults |
160
- | `AcApPdfImportConvertor` | PDF → CAD entities import utility |
161
-
162
- ## Project layout
163
-
164
- | Path | Role |
165
- |------|------|
166
- | `src/register.ts` | Lazy plugin registration (`/register` entry) and `createPdfPlugin` |
167
- | `src/AcApPdfPlugin.ts` | Plugin lifecycle (`onLoad` / `onUnload`) |
168
- | `src/AcApConvertToPdfCmd.ts` | `-cpdf` command (command-line prompts) |
169
- | `src/AcApImportPdfCmd.ts` | `ipdf` command |
170
- | `src/AcApPdfConvertor.ts` | Export pipeline (`exportDatabaseToPdf`) |
171
- | `src/AcApPdfExportOptions.ts` | Export option types and defaults |
172
- | `src/AcApPdfImportConvertor.ts` | Import pipeline (pdf.js operator parsing) |
173
-
174
- ## Role in MLightCAD
175
-
176
- This package extends `cad-simple-viewer` with optional PDF I/O. Export uses `@mlightcad/pdf-renderer`; import uses `pdfjs-dist`. Heavy PDF dependencies stay out of the core viewer bundle through lazy loading.
177
-
178
- ## License
179
-
180
- MIT
1
+ # @mlightcad/cad-pdf-plugin
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-pdf-plugin.svg)](https://www.npmjs.com/package/@mlightcad/cad-pdf-plugin)
5
+
6
+ PDF **export** and **import** plugin for [`@mlightcad/cad-simple-viewer`](../cad-simple-viewer). Registers system commands:
7
+
8
+ | Command | Description |
9
+ |---------|-------------|
10
+ | `-cpdf` | Export via **command-line prompts** (no dialog; AutoCAD-style `-` prefix) |
11
+ | `cpdf` | Same as `-cpdf` when no UI command is registered. In [`cad-viewer`](../cad-viewer), `cpdf` opens an **export options dialog** instead |
12
+ | `ipdf` | Import vector geometry from a PDF file into model space |
13
+
14
+ The plugin is designed for **lazy loading** so PDF libraries (`pdf-lib` via `@mlightcad/pdf-renderer`, `pdfjs-dist`) are only downloaded when a user runs `-cpdf` / `cpdf` or `ipdf`.
15
+
16
+ ## Key features
17
+
18
+ - **Vector PDF export** — renders model space and each paper-space layout as PDF pages with `@mlightcad/pdf-renderer` (native AcGi PDF backend). Paper-space pages include model content shown through viewports, clipped to each viewport frame.
19
+ - **Busy indicator** — export shows the same conversion spinner as `chtml` so the browser stays responsive
20
+ - **Export options** — model-space framing (`Extents` / `Display`) and optional paper-space layouts
21
+ - **PDF import** — parses vector paths from the first page of a PDF (lines, polylines, Bézier curves) and appends CAD entities
22
+ - **Plugin API** — implements `AcApPlugin`; register once with `registerLazyPdfPlugin`
23
+ - **Framework-agnostic** — no Vue/React dependency; works anywhere `cad-simple-viewer` runs
24
+
25
+ ## Installation
26
+
27
+ ```bash
28
+ pnpm add @mlightcad/cad-pdf-plugin
29
+ ```
30
+
31
+ Peer dependencies:
32
+
33
+ - `@mlightcad/cad-simple-viewer`
34
+ - `@mlightcad/data-model`
35
+ - `@mlightcad/pdf-renderer`
36
+
37
+ Runtime dependencies (bundled with this package):
38
+
39
+ - `pdfjs-dist` (import only)
40
+
41
+ ## Build
42
+
43
+ Produces `dist/index.js` (main library) and `dist/register.js` (lazy-registration entry).
44
+
45
+ ```bash
46
+ pnpm --filter @mlightcad/cad-pdf-plugin build
47
+ ```
48
+
49
+ ## Usage
50
+
51
+ ### Lazy registration (recommended)
52
+
53
+ Register the plugin with the document manager's plugin manager. Import from the `/register` subpath so only the registration stub enters your initial bundle; the main plugin chunk loads on first use of `-cpdf`, `cpdf`, or `ipdf`:
54
+
55
+ ```typescript
56
+ import { AcApDocManager } from '@mlightcad/cad-simple-viewer'
57
+ import { registerLazyPdfPlugin } from '@mlightcad/cad-pdf-plugin/register'
58
+
59
+ registerLazyPdfPlugin(AcApDocManager.instance.pluginManager)
60
+ ```
61
+
62
+ Do **not** import `registerLazyPdfPlugin` from the package root in application code — that resolves to the full library build and defeats lazy loading.
63
+
64
+ Equivalent manual registration:
65
+
66
+ ```typescript
67
+ import {
68
+ createPdfPlugin,
69
+ PDF_PLUGIN_NAME,
70
+ PDF_PLUGIN_TRIGGERS
71
+ } from '@mlightcad/cad-pdf-plugin'
72
+
73
+ AcApDocManager.instance.pluginManager.registerLazyPlugin({
74
+ name: PDF_PLUGIN_NAME,
75
+ triggers: [...PDF_PLUGIN_TRIGGERS],
76
+ loader: createPdfPlugin
77
+ })
78
+ ```
79
+
80
+ After registration, users (or your UI) invoke commands through the editor:
81
+
82
+ ```typescript
83
+ // Export current drawing to PDF (command-line prompts)
84
+ await AcApDocManager.instance.editor.executeCommand('-cpdf')
85
+
86
+ // Open file picker and import PDF vectors
87
+ await AcApDocManager.instance.editor.executeCommand('ipdf')
88
+ ```
89
+
90
+ In [`cad-viewer`](../cad-viewer), use `cpdf` to open the export options dialog; `-cpdf` remains available on the command line for prompt-based export.
91
+
92
+ `cad-viewer` registers this plugin automatically via `registerLazyPlugins()` in its app bootstrap and registers the `cpdf` dialog command separately.
93
+
94
+ ### Eager registration
95
+
96
+ If you prefer loading PDF support up front:
97
+
98
+ ```typescript
99
+ import { AcApPdfPlugin } from '@mlightcad/cad-pdf-plugin'
100
+
101
+ await AcApDocManager.instance.pluginManager.loadPlugin(new AcApPdfPlugin())
102
+ ```
103
+
104
+ ### Programmatic convertors
105
+
106
+ You can bypass the command layer and call the convertors directly:
107
+
108
+ ```typescript
109
+ import { AcApContext } from '@mlightcad/cad-simple-viewer'
110
+ import {
111
+ AcApPdfConvertor,
112
+ AcApPdfImportConvertor,
113
+ resolveAcApPdfExportOptions
114
+ } from '@mlightcad/cad-pdf-plugin'
115
+
116
+ // Export
117
+ const context: AcApContext = /* active context */
118
+ await new AcApPdfConvertor().convert(
119
+ context,
120
+ resolveAcApPdfExportOptions({
121
+ modelSpaceFit: 'extents',
122
+ exportLayouts: true
123
+ })
124
+ )
125
+
126
+ // Import from bytes
127
+ const buffer: ArrayBuffer = /* PDF file */
128
+ await new AcApPdfImportConvertor().convert(context, buffer, 1) // page 1
129
+ ```
130
+
131
+ ## How it works
132
+
133
+ ### Export (`-cpdf` / dialog)
134
+
135
+ 1. Collect options: model-space framing (`Extents` / `Display`) and whether to export layouts.
136
+ 2. Show the application busy overlay (same animation pattern as `chtml`).
137
+ 3. Call `@mlightcad/pdf-renderer` `exportDatabaseToPdf`. With layouts enabled, model space and every paper space become one PDF page each.
138
+ 4. Download the resulting PDF bytes.
139
+
140
+ ### Import (`ipdf`)
141
+
142
+ 1. Show a native file picker (`.pdf`).
143
+ 2. Use `pdfjs-dist` to read operator lists from the selected page.
144
+ 3. Convert path operators (move, line, cubic Bézier, close) into `AcDbLine` / `AcDbPolyline` entities in model space.
145
+
146
+ Import is **vector-only**; raster/scanned PDF pages produce no entities. Only the requested page is processed (default: page 1).
147
+
148
+ ## Main exports
149
+
150
+ | Export | Role |
151
+ |--------|------|
152
+ | `createPdfPlugin` | Async factory used by lazy loader |
153
+ | `PDF_PLUGIN_NAME`, `PDF_PLUGIN_TRIGGERS` | Plugin id and command triggers |
154
+ | `@mlightcad/cad-pdf-plugin/register` | `registerLazyPdfPlugin` and registration constants |
155
+ | `AcApPdfPlugin` | `AcApPlugin` implementation |
156
+ | `AcApConvertToPdfCmd` | `-cpdf` / fallback `cpdf` command class |
157
+ | `AcApImportPdfCmd` | `ipdf` command class |
158
+ | `AcApPdfConvertor` | CAD → PDF export utility |
159
+ | `AcApPdfExportOptions`, `resolveAcApPdfExportOptions` | Export option types and defaults |
160
+ | `AcApPdfImportConvertor` | PDF → CAD entities import utility |
161
+
162
+ ## Project layout
163
+
164
+ | Path | Role |
165
+ |------|------|
166
+ | `src/register.ts` | Lazy plugin registration (`/register` entry) and `createPdfPlugin` |
167
+ | `src/AcApPdfPlugin.ts` | Plugin lifecycle (`onLoad` / `onUnload`) |
168
+ | `src/AcApConvertToPdfCmd.ts` | `-cpdf` command (command-line prompts) |
169
+ | `src/AcApImportPdfCmd.ts` | `ipdf` command |
170
+ | `src/AcApPdfConvertor.ts` | Export pipeline (`exportDatabaseToPdf`) |
171
+ | `src/AcApPdfExportOptions.ts` | Export option types and defaults |
172
+ | `src/AcApPdfImportConvertor.ts` | Import pipeline (pdf.js operator parsing) |
173
+
174
+ ## Role in MLightCAD
175
+
176
+ This package extends `cad-simple-viewer` with optional PDF I/O. Export uses `@mlightcad/pdf-renderer`; import uses `pdfjs-dist`. Heavy PDF dependencies stay out of the core viewer bundle through lazy loading.
177
+
178
+ ## License
179
+
180
+ MIT
@@ -19388,7 +19388,7 @@ class QV extends uY {
19388
19388
  await new TV().importFromFilePicker(I);
19389
19389
  }
19390
19390
  }
19391
- const UV = "1.7.6-preview.0", rV = {
19391
+ const UV = "1.7.7-preview.0", rV = {
19392
19392
  version: UV
19393
19393
  };
19394
19394
  class OV {