@mlightcad/cad-pdf-plugin 1.6.3 → 1.7.1

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 (42) hide show
  1. package/README.md +39 -23
  2. package/dist/cad-pdf-plugin-register.js +11 -10
  3. package/dist/cad-pdf-plugin-register.umd.cjs +1 -1
  4. package/dist/cad-pdf-plugin.js +17050 -41432
  5. package/dist/cad-pdf-plugin.umd.cjs +13 -270
  6. package/lib/AcApConvertToPdfCmd.d.ts +13 -2
  7. package/lib/AcApConvertToPdfCmd.d.ts.map +1 -1
  8. package/lib/AcApConvertToPdfCmd.js +153 -7
  9. package/lib/AcApConvertToPdfCmd.js.map +1 -1
  10. package/lib/AcApPdfConvertor.d.ts +18 -8
  11. package/lib/AcApPdfConvertor.d.ts.map +1 -1
  12. package/lib/AcApPdfConvertor.js +87 -94
  13. package/lib/AcApPdfConvertor.js.map +1 -1
  14. package/lib/AcApPdfExportOptions.d.ts +38 -0
  15. package/lib/AcApPdfExportOptions.d.ts.map +1 -0
  16. package/lib/AcApPdfExportOptions.js +12 -0
  17. package/lib/AcApPdfExportOptions.js.map +1 -0
  18. package/lib/AcApPdfFontResolver.d.ts +20 -0
  19. package/lib/AcApPdfFontResolver.d.ts.map +1 -0
  20. package/lib/AcApPdfFontResolver.js +105 -0
  21. package/lib/AcApPdfFontResolver.js.map +1 -0
  22. package/lib/AcApPdfGlyphProvider.d.ts +15 -0
  23. package/lib/AcApPdfGlyphProvider.d.ts.map +1 -0
  24. package/lib/AcApPdfGlyphProvider.js +277 -0
  25. package/lib/AcApPdfGlyphProvider.js.map +1 -0
  26. package/lib/AcApPdfPlugin.d.ts +13 -3
  27. package/lib/AcApPdfPlugin.d.ts.map +1 -1
  28. package/lib/AcApPdfPlugin.js +19 -7
  29. package/lib/AcApPdfPlugin.js.map +1 -1
  30. package/lib/createPdfPlugin.d.ts +3 -2
  31. package/lib/createPdfPlugin.d.ts.map +1 -1
  32. package/lib/createPdfPlugin.js +4 -2
  33. package/lib/createPdfPlugin.js.map +1 -1
  34. package/lib/index.d.ts +4 -0
  35. package/lib/index.d.ts.map +1 -1
  36. package/lib/index.js +3 -0
  37. package/lib/index.js.map +1 -1
  38. package/lib/register.d.ts +7 -3
  39. package/lib/register.d.ts.map +1 -1
  40. package/lib/register.js +12 -5
  41. package/lib/register.js.map +1 -1
  42. package/package.json +9 -9
package/README.md CHANGED
@@ -3,18 +3,21 @@
3
3
  [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
4
4
  [![npm version](https://img.shields.io/npm/v/@mlightcad/cad-pdf-plugin.svg)](https://www.npmjs.com/package/@mlightcad/cad-pdf-plugin)
5
5
 
6
- PDF **export** and **import** plugin for [`@mlightcad/cad-simple-viewer`](../cad-simple-viewer). Registers two system commands:
6
+ PDF **export** and **import** plugin for [`@mlightcad/cad-simple-viewer`](../cad-simple-viewer). Registers system commands:
7
7
 
8
8
  | Command | Description |
9
9
  |---------|-------------|
10
- | `cpdf` | Export the current drawing to a vector PDF (SVG pipeline → jsPDF) |
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 |
11
12
  | `ipdf` | Import vector geometry from a PDF file into model space |
12
13
 
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
+ 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`.
14
15
 
15
16
  ## Key features
16
17
 
17
- - **Vector PDF export** — renders model-space entities via `@mlightcad/cad-svg-plugin`, then converts SVG to PDF with `svg2pdf.js`
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
18
21
  - **PDF import** — parses vector paths from the first page of a PDF (lines, polylines, Bézier curves) and appends CAD entities
19
22
  - **Plugin API** — implements `AcApPlugin`; register once with `registerLazyPdfPlugin`
20
23
  - **Framework-agnostic** — no Vue/React dependency; works anywhere `cad-simple-viewer` runs
@@ -29,13 +32,11 @@ Peer dependencies:
29
32
 
30
33
  - `@mlightcad/cad-simple-viewer`
31
34
  - `@mlightcad/data-model`
32
- - `@mlightcad/cad-svg-plugin`
35
+ - `@mlightcad/pdf-renderer`
33
36
 
34
37
  Runtime dependencies (bundled with this package):
35
38
 
36
- - `jspdf`
37
- - `pdfjs-dist`
38
- - `svg2pdf.js`
39
+ - `pdfjs-dist` (import only)
39
40
 
40
41
  ## Build
41
42
 
@@ -49,7 +50,7 @@ pnpm --filter @mlightcad/cad-pdf-plugin build
49
50
 
50
51
  ### Lazy registration (recommended)
51
52
 
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
+ 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`:
53
54
 
54
55
  ```typescript
55
56
  import { AcApDocManager } from '@mlightcad/cad-simple-viewer'
@@ -79,14 +80,16 @@ AcApDocManager.instance.pluginManager.registerLazyPlugin({
79
80
  After registration, users (or your UI) invoke commands through the editor:
80
81
 
81
82
  ```typescript
82
- // Export current drawing to PDF
83
- await AcApDocManager.instance.editor.executeCommand('cpdf')
83
+ // Export current drawing to PDF (command-line prompts)
84
+ await AcApDocManager.instance.editor.executeCommand('-cpdf')
84
85
 
85
86
  // Open file picker and import PDF vectors
86
87
  await AcApDocManager.instance.editor.executeCommand('ipdf')
87
88
  ```
88
89
 
89
- `cad-viewer` registers this plugin automatically via `registerLazyPlugins()` in its app bootstrap.
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.
90
93
 
91
94
  ### Eager registration
92
95
 
@@ -104,11 +107,21 @@ You can bypass the command layer and call the convertors directly:
104
107
 
105
108
  ```typescript
106
109
  import { AcApContext } from '@mlightcad/cad-simple-viewer'
107
- import { AcApPdfConvertor, AcApPdfImportConvertor } from '@mlightcad/cad-pdf-plugin'
110
+ import {
111
+ AcApPdfConvertor,
112
+ AcApPdfImportConvertor,
113
+ resolveAcApPdfExportOptions
114
+ } from '@mlightcad/cad-pdf-plugin'
108
115
 
109
116
  // Export
110
117
  const context: AcApContext = /* active context */
111
- await new AcApPdfConvertor().convert(context)
118
+ await new AcApPdfConvertor().convert(
119
+ context,
120
+ resolveAcApPdfExportOptions({
121
+ modelSpaceFit: 'extents',
122
+ exportLayouts: true
123
+ })
124
+ )
112
125
 
113
126
  // Import from bytes
114
127
  const buffer: ArrayBuffer = /* PDF file */
@@ -117,11 +130,12 @@ await new AcApPdfImportConvertor().convert(context, buffer, 1) // page 1
117
130
 
118
131
  ## How it works
119
132
 
120
- ### Export (`cpdf`)
133
+ ### Export (`-cpdf` / dialog)
121
134
 
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`.
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.
125
139
 
126
140
  ### Import (`ipdf`)
127
141
 
@@ -139,9 +153,10 @@ Import is **vector-only**; raster/scanned PDF pages produce no entities. Only th
139
153
  | `PDF_PLUGIN_NAME`, `PDF_PLUGIN_TRIGGERS` | Plugin id and command triggers |
140
154
  | `@mlightcad/cad-pdf-plugin/register` | `registerLazyPdfPlugin` and registration constants |
141
155
  | `AcApPdfPlugin` | `AcApPlugin` implementation |
142
- | `AcApConvertToPdfCmd` | `cpdf` command class |
156
+ | `AcApConvertToPdfCmd` | `-cpdf` / fallback `cpdf` command class |
143
157
  | `AcApImportPdfCmd` | `ipdf` command class |
144
- | `AcApPdfConvertor` | SVG → PDF export utility |
158
+ | `AcApPdfConvertor` | CAD → PDF export utility |
159
+ | `AcApPdfExportOptions`, `resolveAcApPdfExportOptions` | Export option types and defaults |
145
160
  | `AcApPdfImportConvertor` | PDF → CAD entities import utility |
146
161
 
147
162
  ## Project layout
@@ -150,14 +165,15 @@ Import is **vector-only**; raster/scanned PDF pages produce no entities. Only th
150
165
  |------|------|
151
166
  | `src/register.ts` | Lazy plugin registration (`/register` entry) and `createPdfPlugin` |
152
167
  | `src/AcApPdfPlugin.ts` | Plugin lifecycle (`onLoad` / `onUnload`) |
153
- | `src/AcApConvertToPdfCmd.ts` | `cpdf` command |
168
+ | `src/AcApConvertToPdfCmd.ts` | `-cpdf` command (command-line prompts) |
154
169
  | `src/AcApImportPdfCmd.ts` | `ipdf` command |
155
- | `src/AcApPdfConvertor.ts` | Export pipeline (SVG renderer + jsPDF) |
170
+ | `src/AcApPdfConvertor.ts` | Export pipeline (`exportDatabaseToPdf`) |
171
+ | `src/AcApPdfExportOptions.ts` | Export option types and defaults |
156
172
  | `src/AcApPdfImportConvertor.ts` | Import pipeline (pdf.js operator parsing) |
157
173
 
158
174
  ## Role in MLightCAD
159
175
 
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.
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.
161
177
 
162
178
  ## License
163
179
 
@@ -1,16 +1,17 @@
1
- const t = "PdfPlugin", e = ["cpdf", "ipdf"];
2
- function i(n) {
3
- n.registerLazyPlugin({
4
- name: t,
5
- triggers: [...e],
1
+ const s = "PdfPlugin", o = ["-cpdf", "cpdf", "ipdf"];
2
+ function P(r, e = {}) {
3
+ const t = e.disableExport === !0, i = t ? ["ipdf"] : [...o];
4
+ r.registerLazyPlugin({
5
+ name: s,
6
+ triggers: [...i],
6
7
  loader: async () => {
7
- const { createPdfPlugin: r } = await import("@mlightcad/cad-pdf-plugin");
8
- return r();
8
+ const { createPdfPlugin: n } = await import("@mlightcad/cad-pdf-plugin");
9
+ return n({ disableExport: t });
9
10
  }
10
11
  });
11
12
  }
12
13
  export {
13
- t as PDF_PLUGIN_NAME,
14
- e as PDF_PLUGIN_TRIGGERS,
15
- i as registerLazyPdfPlugin
14
+ s as PDF_PLUGIN_NAME,
15
+ o as PDF_PLUGIN_TRIGGERS,
16
+ P as registerLazyPdfPlugin
16
17
  };
@@ -1 +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;
1
+ "use strict";var o=Object.create;var n=Object.defineProperty;var a=Object.getOwnPropertyDescriptor;var d=Object.getOwnPropertyNames;var c=Object.getPrototypeOf,l=Object.prototype.hasOwnProperty;var u=(t,e,r,P)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of d(e))!l.call(t,i)&&i!==r&&n(t,i,{get:()=>e[i],enumerable:!(P=a(e,i))||P.enumerable});return t};var f=(t,e,r)=>(r=t!=null?o(c(t)):{},u(e||!t||!t.__esModule?n(r,"default",{value:t,enumerable:!0}):r,t));Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s="PdfPlugin",g=["-cpdf","cpdf","ipdf"];function p(t,e={}){const r=e.disableExport===!0,P=r?["ipdf"]:[...g];t.registerLazyPlugin({name:s,triggers:[...P],loader:async()=>{const{createPdfPlugin:i}=await import("@mlightcad/cad-pdf-plugin");return i({disableExport:r})}})}exports.PDF_PLUGIN_NAME=s;exports.PDF_PLUGIN_TRIGGERS=g;exports.registerLazyPdfPlugin=p;