@embedpdf/plugin-print 1.0.11 → 1.0.12

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 (38) hide show
  1. package/dist/index.cjs +2 -372
  2. package/dist/index.cjs.map +1 -1
  3. package/dist/index.d.ts +1 -78
  4. package/dist/index.js +25 -173
  5. package/dist/index.js.map +1 -1
  6. package/dist/lib/index.d.ts +7 -0
  7. package/dist/lib/manifest.d.ts +4 -0
  8. package/dist/lib/print-plugin.d.ts +15 -0
  9. package/dist/lib/types.d.ts +56 -0
  10. package/dist/preact/adapter.d.ts +5 -0
  11. package/dist/preact/core.d.ts +1 -0
  12. package/dist/preact/index.cjs +2 -223
  13. package/dist/preact/index.cjs.map +1 -1
  14. package/dist/preact/index.d.ts +1 -76
  15. package/dist/preact/index.js +17 -20
  16. package/dist/preact/index.js.map +1 -1
  17. package/dist/react/adapter.d.ts +4 -0
  18. package/dist/react/core.d.ts +1 -0
  19. package/dist/react/index.cjs +2 -0
  20. package/dist/react/index.cjs.map +1 -0
  21. package/dist/react/index.d.ts +1 -0
  22. package/dist/react/index.js +238 -0
  23. package/dist/react/index.js.map +1 -0
  24. package/dist/shared-preact/components/index.d.ts +1 -0
  25. package/dist/shared-preact/components/print.d.ts +15 -0
  26. package/dist/shared-preact/hooks/index.d.ts +2 -0
  27. package/dist/shared-preact/hooks/use-print-action.d.ts +8 -0
  28. package/dist/shared-preact/hooks/use-print.d.ts +11 -0
  29. package/dist/shared-preact/index.d.ts +2 -0
  30. package/dist/shared-react/components/index.d.ts +1 -0
  31. package/dist/shared-react/components/print.d.ts +15 -0
  32. package/dist/shared-react/hooks/index.d.ts +2 -0
  33. package/dist/shared-react/hooks/use-print-action.d.ts +8 -0
  34. package/dist/shared-react/hooks/use-print.d.ts +11 -0
  35. package/dist/shared-react/index.d.ts +2 -0
  36. package/package.json +23 -14
  37. package/dist/index.d.cts +0 -78
  38. package/dist/preact/index.d.cts +0 -76
package/dist/index.cjs CHANGED
@@ -1,372 +1,2 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
-
20
- // src/index.ts
21
- var index_exports = {};
22
- __export(index_exports, {
23
- PRINT_PLUGIN_ID: () => PRINT_PLUGIN_ID,
24
- PageRangeType: () => PageRangeType,
25
- PrintPlugin: () => PrintPlugin,
26
- PrintPluginPackage: () => PrintPluginPackage,
27
- PrintQuality: () => PrintQuality,
28
- manifest: () => manifest
29
- });
30
- module.exports = __toCommonJS(index_exports);
31
-
32
- // src/lib/manifest.ts
33
- var PRINT_PLUGIN_ID = "print";
34
- var manifest = {
35
- id: PRINT_PLUGIN_ID,
36
- name: "Print Plugin",
37
- version: "1.0.0",
38
- provides: ["print"],
39
- requires: ["render"],
40
- optional: [],
41
- defaultConfig: {
42
- enabled: true
43
- }
44
- };
45
-
46
- // src/lib/print-plugin.ts
47
- var import_core2 = require("@embedpdf/core");
48
-
49
- // ../plugin-render/dist/index.js
50
- var import_core = require("@embedpdf/core");
51
-
52
- // ../models/dist/index.js
53
- var Rotation = /* @__PURE__ */ ((Rotation2) => {
54
- Rotation2[Rotation2["Degree0"] = 0] = "Degree0";
55
- Rotation2[Rotation2["Degree90"] = 1] = "Degree90";
56
- Rotation2[Rotation2["Degree180"] = 2] = "Degree180";
57
- Rotation2[Rotation2["Degree270"] = 3] = "Degree270";
58
- return Rotation2;
59
- })(Rotation || {});
60
- var PdfSoftHyphenMarker = "\xAD";
61
- var PdfZeroWidthSpace = "\u200B";
62
- var PdfWordJoiner = "\u2060";
63
- var PdfBomOrZwnbsp = "\uFEFF";
64
- var PdfNonCharacterFFFE = "\uFFFE";
65
- var PdfNonCharacterFFFF = "\uFFFF";
66
- var PdfUnwantedTextMarkers = Object.freeze([
67
- PdfSoftHyphenMarker,
68
- PdfZeroWidthSpace,
69
- PdfWordJoiner,
70
- PdfBomOrZwnbsp,
71
- PdfNonCharacterFFFE,
72
- PdfNonCharacterFFFF
73
- ]);
74
- var PdfUnwantedTextRegex = new RegExp(`[${PdfUnwantedTextMarkers.join("")}]`, "g");
75
- var PdfAnnotationFlagName = Object.freeze({
76
- [
77
- 1
78
- /* INVISIBLE */
79
- ]: "invisible",
80
- [
81
- 2
82
- /* HIDDEN */
83
- ]: "hidden",
84
- [
85
- 4
86
- /* PRINT */
87
- ]: "print",
88
- [
89
- 8
90
- /* NO_ZOOM */
91
- ]: "noZoom",
92
- [
93
- 16
94
- /* NO_ROTATE */
95
- ]: "noRotate",
96
- [
97
- 32
98
- /* NO_VIEW */
99
- ]: "noView",
100
- [
101
- 64
102
- /* READ_ONLY */
103
- ]: "readOnly",
104
- [
105
- 128
106
- /* LOCKED */
107
- ]: "locked",
108
- [
109
- 256
110
- /* TOGGLE_NOVIEW */
111
- ]: "toggleNoView"
112
- });
113
- var PdfAnnotationFlagValue = Object.entries(
114
- PdfAnnotationFlagName
115
- ).reduce(
116
- (acc, [bit, name]) => {
117
- acc[name] = Number(bit);
118
- return acc;
119
- },
120
- {}
121
- );
122
-
123
- // ../plugin-render/dist/index.js
124
- var RenderPlugin = class extends import_core.BasePlugin {
125
- constructor(id, registry, engine) {
126
- super(id, registry);
127
- this.engine = engine;
128
- }
129
- async initialize(_config) {
130
- }
131
- buildCapability() {
132
- return {
133
- renderPage: this.renderPage.bind(this),
134
- renderPageRect: this.renderPageRect.bind(this)
135
- };
136
- }
137
- renderPage({
138
- pageIndex,
139
- scaleFactor = 1,
140
- dpr = 1,
141
- rotation = Rotation.Degree0,
142
- options = { withAnnotations: false },
143
- imageType = "image/webp"
144
- }) {
145
- const coreState = this.coreState.core;
146
- if (!coreState.document) {
147
- throw new Error("document does not open");
148
- }
149
- const page = coreState.document.pages.find((page2) => page2.index === pageIndex);
150
- if (!page) {
151
- throw new Error("page does not exist");
152
- }
153
- return this.engine.renderPage(
154
- coreState.document,
155
- page,
156
- scaleFactor,
157
- rotation,
158
- dpr,
159
- options,
160
- imageType
161
- );
162
- }
163
- renderPageRect({
164
- pageIndex,
165
- scaleFactor = 1,
166
- dpr = 1,
167
- rect,
168
- rotation = Rotation.Degree0,
169
- options = { withAnnotations: false },
170
- imageType = "image/webp"
171
- }) {
172
- const coreState = this.coreState.core;
173
- if (!coreState.document) {
174
- throw new Error("document does not open");
175
- }
176
- const page = coreState.document.pages.find((page2) => page2.index === pageIndex);
177
- if (!page) {
178
- throw new Error("page does not exist");
179
- }
180
- return this.engine.renderPageRect(
181
- coreState.document,
182
- page,
183
- scaleFactor,
184
- rotation,
185
- dpr,
186
- rect,
187
- options,
188
- imageType
189
- );
190
- }
191
- };
192
- RenderPlugin.id = "render";
193
-
194
- // src/lib/types.ts
195
- var PrintQuality = /* @__PURE__ */ ((PrintQuality2) => {
196
- PrintQuality2["Normal"] = "normal";
197
- PrintQuality2["High"] = "high";
198
- return PrintQuality2;
199
- })(PrintQuality || {});
200
- var PageRangeType = /* @__PURE__ */ ((PageRangeType2) => {
201
- PageRangeType2["Current"] = "current";
202
- PageRangeType2["All"] = "all";
203
- PageRangeType2["Custom"] = "custom";
204
- return PageRangeType2;
205
- })(PageRangeType || {});
206
-
207
- // src/lib/print-plugin.ts
208
- var PrintPlugin = class extends import_core2.BasePlugin {
209
- constructor(id, registry, config) {
210
- super(id, registry);
211
- this.config = config;
212
- this.renderCapability = this.registry.getPlugin(RenderPlugin.id)?.provides();
213
- }
214
- async initialize(_config) {
215
- }
216
- buildCapability() {
217
- return {
218
- preparePrint: this.preparePrint.bind(this),
219
- parsePageRange: this.parsePageRange.bind(this)
220
- };
221
- }
222
- async preparePrint(options, onProgress, onPageReady) {
223
- const coreState = this.coreState.core;
224
- if (!coreState.document) {
225
- throw new Error("No document loaded");
226
- }
227
- const pagesToPrint = this.getPagesToPrint(options, coreState.document.pages.length);
228
- const totalPages = pagesToPrint.length;
229
- const batchSize = this.config?.batchSize || 3;
230
- onProgress?.({
231
- current: 0,
232
- total: totalPages,
233
- status: "preparing",
234
- message: `Preparing to render ${totalPages} page${totalPages !== 1 ? "s" : ""}...`
235
- });
236
- const scaleFactor = this.getScaleFactor(options.quality);
237
- const dpr = 1;
238
- for (let batchStart = 0; batchStart < pagesToPrint.length; batchStart += batchSize) {
239
- const batchEnd = Math.min(batchStart + batchSize, pagesToPrint.length);
240
- const batch = pagesToPrint.slice(batchStart, batchEnd);
241
- const batchPromises = batch.map(async (pageIndex, batchIndex) => {
242
- const overallIndex = batchStart + batchIndex;
243
- onProgress?.({
244
- current: overallIndex,
245
- total: totalPages,
246
- status: "rendering",
247
- message: `Rendering page ${pageIndex + 1}...`
248
- });
249
- const blob = await this.renderPage(pageIndex, scaleFactor, dpr, options.includeAnnotations);
250
- onPageReady?.({
251
- pageIndex,
252
- blob
253
- });
254
- return;
255
- });
256
- await Promise.all(batchPromises);
257
- }
258
- onProgress?.({
259
- current: totalPages,
260
- total: totalPages,
261
- status: "complete",
262
- message: "All pages rendered successfully"
263
- });
264
- }
265
- async renderPage(pageIndex, scaleFactor, dpr, withAnnotations) {
266
- return new Promise((resolve, reject) => {
267
- const renderTask = this.renderCapability.renderPage({
268
- pageIndex,
269
- scaleFactor,
270
- dpr,
271
- rotation: Rotation.Degree0,
272
- options: {
273
- withAnnotations
274
- }
275
- });
276
- renderTask.wait(
277
- (blob) => resolve(blob),
278
- (error) => reject(
279
- new Error(
280
- `Failed to render page ${pageIndex + 1}: ${error.reason.message || "Unknown error"}`
281
- )
282
- )
283
- );
284
- });
285
- }
286
- getScaleFactor(quality) {
287
- switch (quality) {
288
- case "high" /* High */:
289
- return 1.5;
290
- // Higher resolution for better print quality
291
- case "normal" /* Normal */:
292
- default:
293
- return 1;
294
- }
295
- }
296
- getPagesToPrint(options, totalPages) {
297
- const { pageRange } = options;
298
- switch (pageRange.type) {
299
- case "current" /* Current */:
300
- return pageRange.currentPage !== void 0 ? [pageRange.currentPage] : [0];
301
- case "all" /* All */:
302
- return Array.from({ length: totalPages }, (_, i) => i);
303
- case "custom" /* Custom */:
304
- if (!pageRange.pages) return [0];
305
- return pageRange.pages.filter((page) => page >= 0 && page < totalPages).sort((a, b) => a - b);
306
- default:
307
- return [0];
308
- }
309
- }
310
- parsePageRange(rangeString) {
311
- try {
312
- const totalPages = this.coreState.core.document?.pages.length || 0;
313
- const pages = [];
314
- const parts = rangeString.split(",").map((s) => s.trim());
315
- for (const part of parts) {
316
- if (part.includes("-")) {
317
- const [start, end] = part.split("-").map((s) => parseInt(s.trim()));
318
- if (isNaN(start) || isNaN(end)) {
319
- return { pages: [], isValid: false, error: `Invalid range: ${part}` };
320
- }
321
- if (start > end) {
322
- return { pages: [], isValid: false, error: `Invalid range: ${part} (start > end)` };
323
- }
324
- for (let i = start; i <= end; i++) {
325
- if (i >= 1 && i <= totalPages) {
326
- pages.push(i - 1);
327
- }
328
- }
329
- } else {
330
- const pageNum = parseInt(part);
331
- if (isNaN(pageNum)) {
332
- return { pages: [], isValid: false, error: `Invalid page number: ${part}` };
333
- }
334
- if (pageNum >= 1 && pageNum <= totalPages) {
335
- pages.push(pageNum - 1);
336
- }
337
- }
338
- }
339
- const uniquePages = [...new Set(pages)].sort((a, b) => a - b);
340
- return {
341
- pages: uniquePages,
342
- isValid: true
343
- };
344
- } catch (error) {
345
- return {
346
- pages: [],
347
- isValid: false,
348
- error: `Parsing error: ${error instanceof Error ? error.message : "Unknown error"}`
349
- };
350
- }
351
- }
352
- };
353
- PrintPlugin.id = "print";
354
-
355
- // src/lib/index.ts
356
- var PrintPluginPackage = {
357
- manifest,
358
- create: (registry, _engine, config) => new PrintPlugin(PRINT_PLUGIN_ID, registry, config),
359
- reducer: () => {
360
- },
361
- initialState: {}
362
- };
363
- // Annotate the CommonJS export names for ESM import in node:
364
- 0 && (module.exports = {
365
- PRINT_PLUGIN_ID,
366
- PageRangeType,
367
- PrintPlugin,
368
- PrintPluginPackage,
369
- PrintQuality,
370
- manifest
371
- });
372
- //# sourceMappingURL=index.cjs.map
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("@embedpdf/core"),r=require("@embedpdf/plugin-render"),t=require("@embedpdf/models"),n="print",a={id:n,name:"Print Plugin",version:"1.0.0",provides:["print"],requires:["render"],optional:[],defaultConfig:{enabled:!0}};var i=(e=>(e.Normal="normal",e.High="high",e))(i||{}),s=(e=>(e.Current="current",e.All="all",e.Custom="custom",e))(s||{});const o=class extends e.BasePlugin{constructor(e,t,n){var a;super(e,t),this.config=n,this.renderCapability=null==(a=this.registry.getPlugin(r.RenderPlugin.id))?void 0:a.provides()}async initialize(e){}buildCapability(){return{preparePrint:this.preparePrint.bind(this),parsePageRange:this.parsePageRange.bind(this)}}async preparePrint(e,r,t){var n;const a=this.coreState.core;if(!a.document)throw new Error("No document loaded");const i=this.getPagesToPrint(e,a.document.pages.length),s=i.length,o=(null==(n=this.config)?void 0:n.batchSize)||3;null==r||r({current:0,total:s,status:"preparing",message:`Preparing to render ${s} page${1!==s?"s":""}...`});const l=this.getScaleFactor(e.quality);for(let g=0;g<i.length;g+=o){const n=Math.min(g+o,i.length),a=i.slice(g,n).map((async(n,a)=>{null==r||r({current:g+a,total:s,status:"rendering",message:`Rendering page ${n+1}...`});const i=await this.renderPage(n,l,1,e.includeAnnotations);null==t||t({pageIndex:n,blob:i})}));await Promise.all(a)}null==r||r({current:s,total:s,status:"complete",message:"All pages rendered successfully"})}async renderPage(e,r,n,a){return new Promise(((i,s)=>{this.renderCapability.renderPage({pageIndex:e,scaleFactor:r,dpr:n,rotation:t.Rotation.Degree0,options:{withAnnotations:a}}).wait((e=>i(e)),(r=>s(new Error(`Failed to render page ${e+1}: ${r.reason.message||"Unknown error"}`))))}))}getScaleFactor(e){switch(e){case i.High:return 1.5;case i.Normal:default:return 1}}getPagesToPrint(e,r){const{pageRange:t}=e;switch(t.type){case s.Current:return void 0!==t.currentPage?[t.currentPage]:[0];case s.All:return Array.from({length:r},((e,r)=>r));case s.Custom:return t.pages?t.pages.filter((e=>e>=0&&e<r)).sort(((e,r)=>e-r)):[0];default:return[0]}}parsePageRange(e){var r;try{const t=(null==(r=this.coreState.core.document)?void 0:r.pages.length)||0,n=[],a=e.split(",").map((e=>e.trim()));for(const e of a)if(e.includes("-")){const[r,a]=e.split("-").map((e=>parseInt(e.trim())));if(isNaN(r)||isNaN(a))return{pages:[],isValid:!1,error:`Invalid range: ${e}`};if(r>a)return{pages:[],isValid:!1,error:`Invalid range: ${e} (start > end)`};for(let e=r;e<=a;e++)e>=1&&e<=t&&n.push(e-1)}else{const r=parseInt(e);if(isNaN(r))return{pages:[],isValid:!1,error:`Invalid page number: ${e}`};r>=1&&r<=t&&n.push(r-1)}return{pages:[...new Set(n)].sort(((e,r)=>e-r)),isValid:!0}}catch(t){return{pages:[],isValid:!1,error:`Parsing error: ${t instanceof Error?t.message:"Unknown error"}`}}}};o.id="print";let l=o;const g={manifest:a,create:(e,r,t)=>new l(n,e,t),reducer:()=>{},initialState:{}};exports.PRINT_PLUGIN_ID=n,exports.PageRangeType=s,exports.PrintPlugin=l,exports.PrintPluginPackage=g,exports.PrintQuality=i,exports.manifest=a;
2
+ //# sourceMappingURL=index.cjs.map