@mlightcad/cad-pdf-plugin 1.5.5 → 1.5.7
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 +164 -157
- package/dist/cad-pdf-plugin-register.js +16 -0
- package/dist/cad-pdf-plugin-register.umd.cjs +1 -0
- package/dist/cad-pdf-plugin.js +42183 -0
- package/dist/cad-pdf-plugin.umd.cjs +312 -0
- package/lib/AcApPdfPlugin.d.ts.map +1 -1
- package/lib/AcApPdfPlugin.js +2 -1
- package/lib/AcApPdfPlugin.js.map +1 -1
- package/lib/createPdfPlugin.d.ts +8 -0
- package/lib/createPdfPlugin.d.ts.map +1 -0
- package/lib/createPdfPlugin.js +50 -0
- package/lib/createPdfPlugin.js.map +1 -0
- package/lib/index.d.ts +2 -1
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +2 -1
- package/lib/index.js.map +1 -1
- package/lib/{registerLazyPdfPlugin.d.ts → register.d.ts} +3 -8
- package/lib/register.d.ts.map +1 -0
- package/lib/{registerLazyPdfPlugin.js → register.js} +15 -21
- package/lib/register.js.map +1 -0
- package/package.json +24 -11
- package/dist/AcApPdfPlugin-CXWCd8bg.js +0 -34
- package/dist/html2canvas.esm-d2sM-0Wm.js +0 -4870
- package/dist/index-DNe5YnrC.js +0 -30983
- package/dist/index.es-DxTvd7sT.js +0 -5645
- package/dist/index.js +0 -11
- package/dist/index.umd.cjs +0 -312
- package/dist/purify.es-CxNDhYDZ.js +0 -663
- package/lib/registerLazyPdfPlugin.d.ts.map +0 -1
- package/lib/registerLazyPdfPlugin.js.map +0 -1
package/LICENSE
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c)
|
|
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,157 +1,164 @@
|
|
|
1
|
-
# @mlightcad/cad-pdf-plugin
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
- **
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
```
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
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
|
-
|
|
117
|
-
|
|
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
|
-
|
|
1
|
+
# @mlightcad/cad-pdf-plugin
|
|
2
|
+
|
|
3
|
+
[](https://opensource.org/licenses/MIT)
|
|
4
|
+
[](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 two system commands:
|
|
7
|
+
|
|
8
|
+
| Command | Description |
|
|
9
|
+
|---------|-------------|
|
|
10
|
+
| `cpdf` | Export the current drawing to a vector PDF (SVG pipeline → jsPDF) |
|
|
11
|
+
| `ipdf` | Import vector geometry from a PDF file into model space |
|
|
12
|
+
|
|
13
|
+
The plugin is designed for **lazy loading** so PDF libraries (`jspdf`, `pdfjs-dist`, `svg2pdf.js`) are only downloaded when a user runs `cpdf` or `ipdf`.
|
|
14
|
+
|
|
15
|
+
## Key features
|
|
16
|
+
|
|
17
|
+
- **Vector PDF export** — renders model-space entities via `@mlightcad/cad-svg-plugin`, then converts SVG to PDF with `svg2pdf.js`
|
|
18
|
+
- **PDF import** — parses vector paths from the first page of a PDF (lines, polylines, Bézier curves) and appends CAD entities
|
|
19
|
+
- **Plugin API** — implements `AcApPlugin`; register once with `registerLazyPdfPlugin`
|
|
20
|
+
- **Framework-agnostic** — no Vue/React dependency; works anywhere `cad-simple-viewer` runs
|
|
21
|
+
|
|
22
|
+
## Installation
|
|
23
|
+
|
|
24
|
+
```bash
|
|
25
|
+
pnpm add @mlightcad/cad-pdf-plugin
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
Peer dependencies:
|
|
29
|
+
|
|
30
|
+
- `@mlightcad/cad-simple-viewer`
|
|
31
|
+
- `@mlightcad/data-model`
|
|
32
|
+
- `@mlightcad/cad-svg-plugin`
|
|
33
|
+
|
|
34
|
+
Runtime dependencies (bundled with this package):
|
|
35
|
+
|
|
36
|
+
- `jspdf`
|
|
37
|
+
- `pdfjs-dist`
|
|
38
|
+
- `svg2pdf.js`
|
|
39
|
+
|
|
40
|
+
## Build
|
|
41
|
+
|
|
42
|
+
Produces `dist/index.js` (main library) and `dist/register.js` (lazy-registration entry).
|
|
43
|
+
|
|
44
|
+
```bash
|
|
45
|
+
pnpm --filter @mlightcad/cad-pdf-plugin build
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
## Usage
|
|
49
|
+
|
|
50
|
+
### Lazy registration (recommended)
|
|
51
|
+
|
|
52
|
+
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` or `ipdf`:
|
|
53
|
+
|
|
54
|
+
```typescript
|
|
55
|
+
import { AcApDocManager } from '@mlightcad/cad-simple-viewer'
|
|
56
|
+
import { registerLazyPdfPlugin } from '@mlightcad/cad-pdf-plugin/register'
|
|
57
|
+
|
|
58
|
+
registerLazyPdfPlugin(AcApDocManager.instance.pluginManager)
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
Do **not** import `registerLazyPdfPlugin` from the package root in application code — that resolves to the full library build and defeats lazy loading.
|
|
62
|
+
|
|
63
|
+
Equivalent manual registration:
|
|
64
|
+
|
|
65
|
+
```typescript
|
|
66
|
+
import {
|
|
67
|
+
createPdfPlugin,
|
|
68
|
+
PDF_PLUGIN_NAME,
|
|
69
|
+
PDF_PLUGIN_TRIGGERS
|
|
70
|
+
} from '@mlightcad/cad-pdf-plugin'
|
|
71
|
+
|
|
72
|
+
AcApDocManager.instance.pluginManager.registerLazyPlugin({
|
|
73
|
+
name: PDF_PLUGIN_NAME,
|
|
74
|
+
triggers: [...PDF_PLUGIN_TRIGGERS],
|
|
75
|
+
loader: createPdfPlugin
|
|
76
|
+
})
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
After registration, users (or your UI) invoke commands through the editor:
|
|
80
|
+
|
|
81
|
+
```typescript
|
|
82
|
+
// Export current drawing to PDF
|
|
83
|
+
await AcApDocManager.instance.editor.executeCommand('cpdf')
|
|
84
|
+
|
|
85
|
+
// Open file picker and import PDF vectors
|
|
86
|
+
await AcApDocManager.instance.editor.executeCommand('ipdf')
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
`cad-viewer` registers this plugin automatically via `registerLazyPlugins()` in its app bootstrap.
|
|
90
|
+
|
|
91
|
+
### Eager registration
|
|
92
|
+
|
|
93
|
+
If you prefer loading PDF support up front:
|
|
94
|
+
|
|
95
|
+
```typescript
|
|
96
|
+
import { AcApPdfPlugin } from '@mlightcad/cad-pdf-plugin'
|
|
97
|
+
|
|
98
|
+
await AcApDocManager.instance.pluginManager.loadPlugin(new AcApPdfPlugin())
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
### Programmatic convertors
|
|
102
|
+
|
|
103
|
+
You can bypass the command layer and call the convertors directly:
|
|
104
|
+
|
|
105
|
+
```typescript
|
|
106
|
+
import { AcApContext } from '@mlightcad/cad-simple-viewer'
|
|
107
|
+
import { AcApPdfConvertor, AcApPdfImportConvertor } from '@mlightcad/cad-pdf-plugin'
|
|
108
|
+
|
|
109
|
+
// Export
|
|
110
|
+
const context: AcApContext = /* active context */
|
|
111
|
+
await new AcApPdfConvertor().convert(context)
|
|
112
|
+
|
|
113
|
+
// Import from bytes
|
|
114
|
+
const buffer: ArrayBuffer = /* PDF file */
|
|
115
|
+
await new AcApPdfImportConvertor().convert(context, buffer, 1) // page 1
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
## How it works
|
|
119
|
+
|
|
120
|
+
### Export (`cpdf`)
|
|
121
|
+
|
|
122
|
+
1. Iterate model-space entities and render with `AcSvgRenderer` (respects linetype scale, lineweight display, font mapping, background/foreground colors).
|
|
123
|
+
2. Parse the SVG and pass it to `svg2pdf.js` inside a `jsPDF` document sized to the SVG viewBox.
|
|
124
|
+
3. Trigger a browser download as `drawing.pdf`.
|
|
125
|
+
|
|
126
|
+
### Import (`ipdf`)
|
|
127
|
+
|
|
128
|
+
1. Show a native file picker (`.pdf`).
|
|
129
|
+
2. Use `pdfjs-dist` to read operator lists from the selected page.
|
|
130
|
+
3. Convert path operators (move, line, cubic Bézier, close) into `AcDbLine` / `AcDbPolyline` entities in model space.
|
|
131
|
+
|
|
132
|
+
Import is **vector-only**; raster/scanned PDF pages produce no entities. Only the requested page is processed (default: page 1).
|
|
133
|
+
|
|
134
|
+
## Main exports
|
|
135
|
+
|
|
136
|
+
| Export | Role |
|
|
137
|
+
|--------|------|
|
|
138
|
+
| `createPdfPlugin` | Async factory used by lazy loader |
|
|
139
|
+
| `PDF_PLUGIN_NAME`, `PDF_PLUGIN_TRIGGERS` | Plugin id and command triggers |
|
|
140
|
+
| `@mlightcad/cad-pdf-plugin/register` | `registerLazyPdfPlugin` and registration constants |
|
|
141
|
+
| `AcApPdfPlugin` | `AcApPlugin` implementation |
|
|
142
|
+
| `AcApConvertToPdfCmd` | `cpdf` command class |
|
|
143
|
+
| `AcApImportPdfCmd` | `ipdf` command class |
|
|
144
|
+
| `AcApPdfConvertor` | SVG → PDF export utility |
|
|
145
|
+
| `AcApPdfImportConvertor` | PDF → CAD entities import utility |
|
|
146
|
+
|
|
147
|
+
## Project layout
|
|
148
|
+
|
|
149
|
+
| Path | Role |
|
|
150
|
+
|------|------|
|
|
151
|
+
| `src/register.ts` | Lazy plugin registration (`/register` entry) and `createPdfPlugin` |
|
|
152
|
+
| `src/AcApPdfPlugin.ts` | Plugin lifecycle (`onLoad` / `onUnload`) |
|
|
153
|
+
| `src/AcApConvertToPdfCmd.ts` | `cpdf` command |
|
|
154
|
+
| `src/AcApImportPdfCmd.ts` | `ipdf` command |
|
|
155
|
+
| `src/AcApPdfConvertor.ts` | Export pipeline (SVG renderer + jsPDF) |
|
|
156
|
+
| `src/AcApPdfImportConvertor.ts` | Import pipeline (pdf.js operator parsing) |
|
|
157
|
+
|
|
158
|
+
## Role in MLightCAD
|
|
159
|
+
|
|
160
|
+
This package extends `cad-simple-viewer` with optional PDF I/O. It depends on `cad-svg-plugin` for export quality parity with the existing SVG export command (`csvg`) and keeps heavy PDF dependencies out of the core viewer bundle through lazy loading.
|
|
161
|
+
|
|
162
|
+
## License
|
|
163
|
+
|
|
164
|
+
MIT
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
const t = "PdfPlugin", e = ["cpdf", "ipdf"];
|
|
2
|
+
function i(n) {
|
|
3
|
+
n.registerLazyPlugin({
|
|
4
|
+
name: t,
|
|
5
|
+
triggers: [...e],
|
|
6
|
+
loader: async () => {
|
|
7
|
+
const { createPdfPlugin: r } = await import("@mlightcad/cad-pdf-plugin");
|
|
8
|
+
return r();
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
}
|
|
12
|
+
export {
|
|
13
|
+
t as PDF_PLUGIN_NAME,
|
|
14
|
+
e as PDF_PLUGIN_TRIGGERS,
|
|
15
|
+
i as registerLazyPdfPlugin
|
|
16
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var o=Object.create;var n=Object.defineProperty;var s=Object.getOwnPropertyDescriptor;var u=Object.getOwnPropertyNames;var c=Object.getPrototypeOf,d=Object.prototype.hasOwnProperty;var l=(e,t,P,i)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of u(t))!d.call(e,r)&&r!==P&&n(e,r,{get:()=>t[r],enumerable:!(i=s(t,r))||i.enumerable});return e};var f=(e,t,P)=>(P=e!=null?o(c(e)):{},l(t||!e||!e.__esModule?n(P,"default",{value:e,enumerable:!0}):P,e));Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const g="PdfPlugin",a=["cpdf","ipdf"];function G(e){e.registerLazyPlugin({name:g,triggers:[...a],loader:async()=>{const{createPdfPlugin:t}=await import("@mlightcad/cad-pdf-plugin");return t()}})}exports.PDF_PLUGIN_NAME=g;exports.PDF_PLUGIN_TRIGGERS=a;exports.registerLazyPdfPlugin=G;
|