@embedpdf/plugin-render 1.0.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 ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 CloudPDF
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/dist/index.cjs ADDED
@@ -0,0 +1,117 @@
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
+ RenderPlugin: () => RenderPlugin,
24
+ RenderPluginPackage: () => RenderPluginPackage
25
+ });
26
+ module.exports = __toCommonJS(index_exports);
27
+
28
+ // src/lib/render-plugin.ts
29
+ var import_core = require("@embedpdf/core");
30
+ var import_models = require("@embedpdf/models");
31
+ var RenderPlugin = class extends import_core.BasePlugin {
32
+ constructor(id, registry, engine) {
33
+ super(id, registry);
34
+ this.engine = engine;
35
+ }
36
+ async initialize(_config) {
37
+ }
38
+ buildCapability() {
39
+ return {
40
+ renderPage: this.renderPage.bind(this),
41
+ renderPageRect: this.renderPageRect.bind(this)
42
+ };
43
+ }
44
+ renderPage({
45
+ pageIndex,
46
+ scaleFactor = 1,
47
+ dpr = 1,
48
+ rotation = import_models.Rotation.Degree0,
49
+ options = { withAnnotations: false }
50
+ }) {
51
+ const coreState = this.coreState.core;
52
+ if (!coreState.document) {
53
+ throw new Error("document does not open");
54
+ }
55
+ const page = coreState.document.pages.find((page2) => page2.index === pageIndex);
56
+ if (!page) {
57
+ throw new Error("page does not exist");
58
+ }
59
+ return this.engine.renderPage(coreState.document, page, scaleFactor, rotation, dpr, options);
60
+ }
61
+ renderPageRect({
62
+ pageIndex,
63
+ scaleFactor = 1,
64
+ dpr = 1,
65
+ rect,
66
+ rotation = import_models.Rotation.Degree0,
67
+ options = { withAnnotations: false }
68
+ }) {
69
+ const coreState = this.coreState.core;
70
+ if (!coreState.document) {
71
+ throw new Error("document does not open");
72
+ }
73
+ const page = coreState.document.pages.find((page2) => page2.index === pageIndex);
74
+ if (!page) {
75
+ throw new Error("page does not exist");
76
+ }
77
+ return this.engine.renderPageRect(
78
+ coreState.document,
79
+ page,
80
+ scaleFactor,
81
+ rotation,
82
+ dpr,
83
+ rect,
84
+ options
85
+ );
86
+ }
87
+ };
88
+ RenderPlugin.id = "render";
89
+
90
+ // src/lib/manifest.ts
91
+ var RENDER_PLUGIN_ID = "render";
92
+ var manifest = {
93
+ id: RENDER_PLUGIN_ID,
94
+ name: "Render Plugin",
95
+ version: "1.0.0",
96
+ provides: ["render"],
97
+ requires: [],
98
+ optional: [],
99
+ defaultConfig: {
100
+ enabled: true
101
+ }
102
+ };
103
+
104
+ // src/lib/index.ts
105
+ var RenderPluginPackage = {
106
+ manifest,
107
+ create: (registry, engine) => new RenderPlugin(RENDER_PLUGIN_ID, registry, engine),
108
+ reducer: () => {
109
+ },
110
+ initialState: {}
111
+ };
112
+ // Annotate the CommonJS export names for ESM import in node:
113
+ 0 && (module.exports = {
114
+ RenderPlugin,
115
+ RenderPluginPackage
116
+ });
117
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts","../src/lib/render-plugin.ts","../src/lib/manifest.ts","../src/lib/index.ts"],"sourcesContent":["export * from './lib';\n","import { BasePlugin, PluginRegistry } from '@embedpdf/core';\nimport {\n RenderCapability,\n RenderPageOptions,\n RenderPageRectOptions,\n RenderPluginConfig,\n} from './types';\nimport { PdfEngine, Rotation } from '@embedpdf/models';\n\nexport class RenderPlugin extends BasePlugin<RenderPluginConfig, RenderCapability> {\n static readonly id = 'render' as const;\n private engine: PdfEngine;\n\n constructor(id: string, registry: PluginRegistry, engine: PdfEngine) {\n super(id, registry);\n this.engine = engine;\n }\n\n async initialize(_config: RenderPluginConfig): Promise<void> {}\n\n protected buildCapability(): RenderCapability {\n return {\n renderPage: this.renderPage.bind(this),\n renderPageRect: this.renderPageRect.bind(this),\n };\n }\n\n private renderPage({\n pageIndex,\n scaleFactor = 1,\n dpr = 1,\n rotation = Rotation.Degree0,\n options = { withAnnotations: false },\n }: RenderPageOptions) {\n const coreState = this.coreState.core;\n\n if (!coreState.document) {\n throw new Error('document does not open');\n }\n\n const page = coreState.document.pages.find((page) => page.index === pageIndex);\n if (!page) {\n throw new Error('page does not exist');\n }\n\n return this.engine.renderPage(coreState.document, page, scaleFactor, rotation, dpr, options);\n }\n\n private renderPageRect({\n pageIndex,\n scaleFactor = 1,\n dpr = 1,\n rect,\n rotation = Rotation.Degree0,\n options = { withAnnotations: false },\n }: RenderPageRectOptions) {\n const coreState = this.coreState.core;\n\n if (!coreState.document) {\n throw new Error('document does not open');\n }\n\n const page = coreState.document.pages.find((page) => page.index === pageIndex);\n if (!page) {\n throw new Error('page does not exist');\n }\n\n return this.engine.renderPageRect(\n coreState.document,\n page,\n scaleFactor,\n rotation,\n dpr,\n rect,\n options,\n );\n }\n}\n","import { PluginManifest } from '@embedpdf/core';\nimport { RenderPluginConfig } from './types';\n\nexport const RENDER_PLUGIN_ID = 'render';\n\nexport const manifest: PluginManifest<RenderPluginConfig> = {\n id: RENDER_PLUGIN_ID,\n name: 'Render Plugin',\n version: '1.0.0',\n provides: ['render'],\n requires: [],\n optional: [],\n defaultConfig: {\n enabled: true,\n },\n};\n","import { PluginPackage } from '@embedpdf/core';\nimport { RenderPluginConfig } from './types';\nimport { RenderPlugin } from './render-plugin';\nimport { manifest, RENDER_PLUGIN_ID } from './manifest';\n\nexport const RenderPluginPackage: PluginPackage<RenderPlugin, RenderPluginConfig> = {\n manifest,\n create: (registry, engine) => new RenderPlugin(RENDER_PLUGIN_ID, registry, engine),\n reducer: () => {},\n initialState: {},\n};\n\nexport * from './render-plugin';\nexport * from './types';\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,kBAA2C;AAO3C,oBAAoC;AAE7B,IAAM,eAAN,cAA2B,uBAAiD;AAAA,EAIjF,YAAY,IAAY,UAA0B,QAAmB;AACnE,UAAM,IAAI,QAAQ;AAClB,SAAK,SAAS;AAAA,EAChB;AAAA,EAEA,MAAM,WAAW,SAA4C;AAAA,EAAC;AAAA,EAEpD,kBAAoC;AAC5C,WAAO;AAAA,MACL,YAAY,KAAK,WAAW,KAAK,IAAI;AAAA,MACrC,gBAAgB,KAAK,eAAe,KAAK,IAAI;AAAA,IAC/C;AAAA,EACF;AAAA,EAEQ,WAAW;AAAA,IACjB;AAAA,IACA,cAAc;AAAA,IACd,MAAM;AAAA,IACN,WAAW,uBAAS;AAAA,IACpB,UAAU,EAAE,iBAAiB,MAAM;AAAA,EACrC,GAAsB;AACpB,UAAM,YAAY,KAAK,UAAU;AAEjC,QAAI,CAAC,UAAU,UAAU;AACvB,YAAM,IAAI,MAAM,wBAAwB;AAAA,IAC1C;AAEA,UAAM,OAAO,UAAU,SAAS,MAAM,KAAK,CAACA,UAASA,MAAK,UAAU,SAAS;AAC7E,QAAI,CAAC,MAAM;AACT,YAAM,IAAI,MAAM,qBAAqB;AAAA,IACvC;AAEA,WAAO,KAAK,OAAO,WAAW,UAAU,UAAU,MAAM,aAAa,UAAU,KAAK,OAAO;AAAA,EAC7F;AAAA,EAEQ,eAAe;AAAA,IACrB;AAAA,IACA,cAAc;AAAA,IACd,MAAM;AAAA,IACN;AAAA,IACA,WAAW,uBAAS;AAAA,IACpB,UAAU,EAAE,iBAAiB,MAAM;AAAA,EACrC,GAA0B;AACxB,UAAM,YAAY,KAAK,UAAU;AAEjC,QAAI,CAAC,UAAU,UAAU;AACvB,YAAM,IAAI,MAAM,wBAAwB;AAAA,IAC1C;AAEA,UAAM,OAAO,UAAU,SAAS,MAAM,KAAK,CAACA,UAASA,MAAK,UAAU,SAAS;AAC7E,QAAI,CAAC,MAAM;AACT,YAAM,IAAI,MAAM,qBAAqB;AAAA,IACvC;AAEA,WAAO,KAAK,OAAO;AAAA,MACjB,UAAU;AAAA,MACV;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACF;AAAA,EACF;AACF;AApEa,aACK,KAAK;;;ACPhB,IAAM,mBAAmB;AAEzB,IAAM,WAA+C;AAAA,EAC1D,IAAI;AAAA,EACJ,MAAM;AAAA,EACN,SAAS;AAAA,EACT,UAAU,CAAC,QAAQ;AAAA,EACnB,UAAU,CAAC;AAAA,EACX,UAAU,CAAC;AAAA,EACX,eAAe;AAAA,IACb,SAAS;AAAA,EACX;AACF;;;ACVO,IAAM,sBAAuE;AAAA,EAClF;AAAA,EACA,QAAQ,CAAC,UAAU,WAAW,IAAI,aAAa,kBAAkB,UAAU,MAAM;AAAA,EACjF,SAAS,MAAM;AAAA,EAAC;AAAA,EAChB,cAAc,CAAC;AACjB;","names":["page"]}
@@ -0,0 +1,42 @@
1
+ import { BasePluginConfig, BasePlugin, PluginRegistry, PluginPackage } from '@embedpdf/core';
2
+ import { Rotation, Task, PdfErrorReason, Rect, PdfEngine } from '@embedpdf/models';
3
+
4
+ interface RenderPluginConfig extends BasePluginConfig {
5
+ }
6
+ interface RenderPageRectOptions {
7
+ pageIndex: number;
8
+ scaleFactor?: number;
9
+ rotation?: Rotation;
10
+ dpr?: number;
11
+ rect: Rect;
12
+ options?: {
13
+ withAnnotations: boolean;
14
+ };
15
+ }
16
+ interface RenderPageOptions {
17
+ pageIndex: number;
18
+ scaleFactor?: number;
19
+ dpr?: number;
20
+ rotation?: Rotation;
21
+ options?: {
22
+ withAnnotations: boolean;
23
+ };
24
+ }
25
+ interface RenderCapability {
26
+ renderPage: (options: RenderPageOptions) => Task<Blob, PdfErrorReason>;
27
+ renderPageRect: (options: RenderPageRectOptions) => Task<Blob, PdfErrorReason>;
28
+ }
29
+
30
+ declare class RenderPlugin extends BasePlugin<RenderPluginConfig, RenderCapability> {
31
+ static readonly id: "render";
32
+ private engine;
33
+ constructor(id: string, registry: PluginRegistry, engine: PdfEngine);
34
+ initialize(_config: RenderPluginConfig): Promise<void>;
35
+ protected buildCapability(): RenderCapability;
36
+ private renderPage;
37
+ private renderPageRect;
38
+ }
39
+
40
+ declare const RenderPluginPackage: PluginPackage<RenderPlugin, RenderPluginConfig>;
41
+
42
+ export { type RenderCapability, type RenderPageOptions, type RenderPageRectOptions, RenderPlugin, type RenderPluginConfig, RenderPluginPackage };
@@ -0,0 +1,42 @@
1
+ import { BasePluginConfig, BasePlugin, PluginRegistry, PluginPackage } from '@embedpdf/core';
2
+ import { Rotation, Task, PdfErrorReason, Rect, PdfEngine } from '@embedpdf/models';
3
+
4
+ interface RenderPluginConfig extends BasePluginConfig {
5
+ }
6
+ interface RenderPageRectOptions {
7
+ pageIndex: number;
8
+ scaleFactor?: number;
9
+ rotation?: Rotation;
10
+ dpr?: number;
11
+ rect: Rect;
12
+ options?: {
13
+ withAnnotations: boolean;
14
+ };
15
+ }
16
+ interface RenderPageOptions {
17
+ pageIndex: number;
18
+ scaleFactor?: number;
19
+ dpr?: number;
20
+ rotation?: Rotation;
21
+ options?: {
22
+ withAnnotations: boolean;
23
+ };
24
+ }
25
+ interface RenderCapability {
26
+ renderPage: (options: RenderPageOptions) => Task<Blob, PdfErrorReason>;
27
+ renderPageRect: (options: RenderPageRectOptions) => Task<Blob, PdfErrorReason>;
28
+ }
29
+
30
+ declare class RenderPlugin extends BasePlugin<RenderPluginConfig, RenderCapability> {
31
+ static readonly id: "render";
32
+ private engine;
33
+ constructor(id: string, registry: PluginRegistry, engine: PdfEngine);
34
+ initialize(_config: RenderPluginConfig): Promise<void>;
35
+ protected buildCapability(): RenderCapability;
36
+ private renderPage;
37
+ private renderPageRect;
38
+ }
39
+
40
+ declare const RenderPluginPackage: PluginPackage<RenderPlugin, RenderPluginConfig>;
41
+
42
+ export { type RenderCapability, type RenderPageOptions, type RenderPageRectOptions, RenderPlugin, type RenderPluginConfig, RenderPluginPackage };
package/dist/index.js ADDED
@@ -0,0 +1,89 @@
1
+ // src/lib/render-plugin.ts
2
+ import { BasePlugin } from "@embedpdf/core";
3
+ import { Rotation } from "@embedpdf/models";
4
+ var RenderPlugin = class extends BasePlugin {
5
+ constructor(id, registry, engine) {
6
+ super(id, registry);
7
+ this.engine = engine;
8
+ }
9
+ async initialize(_config) {
10
+ }
11
+ buildCapability() {
12
+ return {
13
+ renderPage: this.renderPage.bind(this),
14
+ renderPageRect: this.renderPageRect.bind(this)
15
+ };
16
+ }
17
+ renderPage({
18
+ pageIndex,
19
+ scaleFactor = 1,
20
+ dpr = 1,
21
+ rotation = Rotation.Degree0,
22
+ options = { withAnnotations: false }
23
+ }) {
24
+ const coreState = this.coreState.core;
25
+ if (!coreState.document) {
26
+ throw new Error("document does not open");
27
+ }
28
+ const page = coreState.document.pages.find((page2) => page2.index === pageIndex);
29
+ if (!page) {
30
+ throw new Error("page does not exist");
31
+ }
32
+ return this.engine.renderPage(coreState.document, page, scaleFactor, rotation, dpr, options);
33
+ }
34
+ renderPageRect({
35
+ pageIndex,
36
+ scaleFactor = 1,
37
+ dpr = 1,
38
+ rect,
39
+ rotation = Rotation.Degree0,
40
+ options = { withAnnotations: false }
41
+ }) {
42
+ const coreState = this.coreState.core;
43
+ if (!coreState.document) {
44
+ throw new Error("document does not open");
45
+ }
46
+ const page = coreState.document.pages.find((page2) => page2.index === pageIndex);
47
+ if (!page) {
48
+ throw new Error("page does not exist");
49
+ }
50
+ return this.engine.renderPageRect(
51
+ coreState.document,
52
+ page,
53
+ scaleFactor,
54
+ rotation,
55
+ dpr,
56
+ rect,
57
+ options
58
+ );
59
+ }
60
+ };
61
+ RenderPlugin.id = "render";
62
+
63
+ // src/lib/manifest.ts
64
+ var RENDER_PLUGIN_ID = "render";
65
+ var manifest = {
66
+ id: RENDER_PLUGIN_ID,
67
+ name: "Render Plugin",
68
+ version: "1.0.0",
69
+ provides: ["render"],
70
+ requires: [],
71
+ optional: [],
72
+ defaultConfig: {
73
+ enabled: true
74
+ }
75
+ };
76
+
77
+ // src/lib/index.ts
78
+ var RenderPluginPackage = {
79
+ manifest,
80
+ create: (registry, engine) => new RenderPlugin(RENDER_PLUGIN_ID, registry, engine),
81
+ reducer: () => {
82
+ },
83
+ initialState: {}
84
+ };
85
+ export {
86
+ RenderPlugin,
87
+ RenderPluginPackage
88
+ };
89
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/lib/render-plugin.ts","../src/lib/manifest.ts","../src/lib/index.ts"],"sourcesContent":["import { BasePlugin, PluginRegistry } from '@embedpdf/core';\nimport {\n RenderCapability,\n RenderPageOptions,\n RenderPageRectOptions,\n RenderPluginConfig,\n} from './types';\nimport { PdfEngine, Rotation } from '@embedpdf/models';\n\nexport class RenderPlugin extends BasePlugin<RenderPluginConfig, RenderCapability> {\n static readonly id = 'render' as const;\n private engine: PdfEngine;\n\n constructor(id: string, registry: PluginRegistry, engine: PdfEngine) {\n super(id, registry);\n this.engine = engine;\n }\n\n async initialize(_config: RenderPluginConfig): Promise<void> {}\n\n protected buildCapability(): RenderCapability {\n return {\n renderPage: this.renderPage.bind(this),\n renderPageRect: this.renderPageRect.bind(this),\n };\n }\n\n private renderPage({\n pageIndex,\n scaleFactor = 1,\n dpr = 1,\n rotation = Rotation.Degree0,\n options = { withAnnotations: false },\n }: RenderPageOptions) {\n const coreState = this.coreState.core;\n\n if (!coreState.document) {\n throw new Error('document does not open');\n }\n\n const page = coreState.document.pages.find((page) => page.index === pageIndex);\n if (!page) {\n throw new Error('page does not exist');\n }\n\n return this.engine.renderPage(coreState.document, page, scaleFactor, rotation, dpr, options);\n }\n\n private renderPageRect({\n pageIndex,\n scaleFactor = 1,\n dpr = 1,\n rect,\n rotation = Rotation.Degree0,\n options = { withAnnotations: false },\n }: RenderPageRectOptions) {\n const coreState = this.coreState.core;\n\n if (!coreState.document) {\n throw new Error('document does not open');\n }\n\n const page = coreState.document.pages.find((page) => page.index === pageIndex);\n if (!page) {\n throw new Error('page does not exist');\n }\n\n return this.engine.renderPageRect(\n coreState.document,\n page,\n scaleFactor,\n rotation,\n dpr,\n rect,\n options,\n );\n }\n}\n","import { PluginManifest } from '@embedpdf/core';\nimport { RenderPluginConfig } from './types';\n\nexport const RENDER_PLUGIN_ID = 'render';\n\nexport const manifest: PluginManifest<RenderPluginConfig> = {\n id: RENDER_PLUGIN_ID,\n name: 'Render Plugin',\n version: '1.0.0',\n provides: ['render'],\n requires: [],\n optional: [],\n defaultConfig: {\n enabled: true,\n },\n};\n","import { PluginPackage } from '@embedpdf/core';\nimport { RenderPluginConfig } from './types';\nimport { RenderPlugin } from './render-plugin';\nimport { manifest, RENDER_PLUGIN_ID } from './manifest';\n\nexport const RenderPluginPackage: PluginPackage<RenderPlugin, RenderPluginConfig> = {\n manifest,\n create: (registry, engine) => new RenderPlugin(RENDER_PLUGIN_ID, registry, engine),\n reducer: () => {},\n initialState: {},\n};\n\nexport * from './render-plugin';\nexport * from './types';\n"],"mappings":";AAAA,SAAS,kBAAkC;AAO3C,SAAoB,gBAAgB;AAE7B,IAAM,eAAN,cAA2B,WAAiD;AAAA,EAIjF,YAAY,IAAY,UAA0B,QAAmB;AACnE,UAAM,IAAI,QAAQ;AAClB,SAAK,SAAS;AAAA,EAChB;AAAA,EAEA,MAAM,WAAW,SAA4C;AAAA,EAAC;AAAA,EAEpD,kBAAoC;AAC5C,WAAO;AAAA,MACL,YAAY,KAAK,WAAW,KAAK,IAAI;AAAA,MACrC,gBAAgB,KAAK,eAAe,KAAK,IAAI;AAAA,IAC/C;AAAA,EACF;AAAA,EAEQ,WAAW;AAAA,IACjB;AAAA,IACA,cAAc;AAAA,IACd,MAAM;AAAA,IACN,WAAW,SAAS;AAAA,IACpB,UAAU,EAAE,iBAAiB,MAAM;AAAA,EACrC,GAAsB;AACpB,UAAM,YAAY,KAAK,UAAU;AAEjC,QAAI,CAAC,UAAU,UAAU;AACvB,YAAM,IAAI,MAAM,wBAAwB;AAAA,IAC1C;AAEA,UAAM,OAAO,UAAU,SAAS,MAAM,KAAK,CAACA,UAASA,MAAK,UAAU,SAAS;AAC7E,QAAI,CAAC,MAAM;AACT,YAAM,IAAI,MAAM,qBAAqB;AAAA,IACvC;AAEA,WAAO,KAAK,OAAO,WAAW,UAAU,UAAU,MAAM,aAAa,UAAU,KAAK,OAAO;AAAA,EAC7F;AAAA,EAEQ,eAAe;AAAA,IACrB;AAAA,IACA,cAAc;AAAA,IACd,MAAM;AAAA,IACN;AAAA,IACA,WAAW,SAAS;AAAA,IACpB,UAAU,EAAE,iBAAiB,MAAM;AAAA,EACrC,GAA0B;AACxB,UAAM,YAAY,KAAK,UAAU;AAEjC,QAAI,CAAC,UAAU,UAAU;AACvB,YAAM,IAAI,MAAM,wBAAwB;AAAA,IAC1C;AAEA,UAAM,OAAO,UAAU,SAAS,MAAM,KAAK,CAACA,UAASA,MAAK,UAAU,SAAS;AAC7E,QAAI,CAAC,MAAM;AACT,YAAM,IAAI,MAAM,qBAAqB;AAAA,IACvC;AAEA,WAAO,KAAK,OAAO;AAAA,MACjB,UAAU;AAAA,MACV;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACF;AAAA,EACF;AACF;AApEa,aACK,KAAK;;;ACPhB,IAAM,mBAAmB;AAEzB,IAAM,WAA+C;AAAA,EAC1D,IAAI;AAAA,EACJ,MAAM;AAAA,EACN,SAAS;AAAA,EACT,UAAU,CAAC,QAAQ;AAAA,EACnB,UAAU,CAAC;AAAA,EACX,UAAU,CAAC;AAAA,EACX,eAAe;AAAA,IACb,SAAS;AAAA,EACX;AACF;;;ACVO,IAAM,sBAAuE;AAAA,EAClF;AAAA,EACA,QAAQ,CAAC,UAAU,WAAW,IAAI,aAAa,kBAAkB,UAAU,MAAM;AAAA,EACjF,SAAS,MAAM;AAAA,EAAC;AAAA,EAChB,cAAc,CAAC;AACjB;","names":["page"]}
@@ -0,0 +1,97 @@
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/preact/index.ts
21
+ var preact_exports = {};
22
+ __export(preact_exports, {
23
+ RenderLayer: () => RenderLayer,
24
+ useRender: () => useRender,
25
+ useRenderCapability: () => useRenderCapability
26
+ });
27
+ module.exports = __toCommonJS(preact_exports);
28
+
29
+ // src/preact/hooks/use-render.ts
30
+ var import_preact = require("@embedpdf/core/preact");
31
+ var import_plugin_render = require("@embedpdf/plugin-render");
32
+ var useRender = () => (0, import_preact.usePlugin)(import_plugin_render.RenderPlugin.id);
33
+ var useRenderCapability = () => (0, import_preact.useCapability)(import_plugin_render.RenderPlugin.id);
34
+
35
+ // src/preact/components/render-layer.tsx
36
+ var import_preact2 = require("preact");
37
+ var import_hooks = require("preact/hooks");
38
+ var import_models = require("@embedpdf/models");
39
+ var import_jsx_runtime = require("preact/jsx-runtime");
40
+ function RenderLayer({
41
+ pageIndex,
42
+ scaleFactor = 1,
43
+ dpr = 1,
44
+ style,
45
+ ...props
46
+ }) {
47
+ const { provides: renderProvides } = useRenderCapability();
48
+ const [imageUrl, setImageUrl] = (0, import_hooks.useState)(null);
49
+ const urlRef = (0, import_hooks.useRef)(null);
50
+ (0, import_hooks.useEffect)(() => {
51
+ if (renderProvides) {
52
+ const task = renderProvides.renderPage({ pageIndex, scaleFactor, dpr });
53
+ task.wait((blob) => {
54
+ const url = URL.createObjectURL(blob);
55
+ setImageUrl(url);
56
+ urlRef.current = url;
57
+ }, import_models.ignore);
58
+ return () => {
59
+ if (urlRef.current) {
60
+ URL.revokeObjectURL(urlRef.current);
61
+ urlRef.current = null;
62
+ } else {
63
+ task.abort({
64
+ code: import_models.PdfErrorCode.Cancelled,
65
+ message: "canceled render task"
66
+ });
67
+ }
68
+ };
69
+ }
70
+ }, [pageIndex, scaleFactor, dpr, renderProvides]);
71
+ const handleImageLoad = () => {
72
+ if (urlRef.current) {
73
+ URL.revokeObjectURL(urlRef.current);
74
+ urlRef.current = null;
75
+ }
76
+ };
77
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_preact2.Fragment, { children: imageUrl && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
78
+ "img",
79
+ {
80
+ src: imageUrl,
81
+ onLoad: handleImageLoad,
82
+ ...props,
83
+ style: {
84
+ width: "100%",
85
+ height: "100%",
86
+ ...style || {}
87
+ }
88
+ }
89
+ ) });
90
+ }
91
+ // Annotate the CommonJS export names for ESM import in node:
92
+ 0 && (module.exports = {
93
+ RenderLayer,
94
+ useRender,
95
+ useRenderCapability
96
+ });
97
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/preact/index.ts","../../src/preact/hooks/use-render.ts","../../src/preact/components/render-layer.tsx"],"sourcesContent":["export * from './hooks';\nexport * from './components';\n","import { useCapability, usePlugin } from '@embedpdf/core/preact';\nimport { RenderPlugin } from '@embedpdf/plugin-render';\n\nexport const useRender = () => usePlugin<RenderPlugin>(RenderPlugin.id);\nexport const useRenderCapability = () => useCapability<RenderPlugin>(RenderPlugin.id);\n","/** @jsxImportSource preact */\nimport { ComponentChildren, Fragment, JSX } from 'preact';\nimport { useEffect, useRef, useState } from 'preact/hooks';\nimport { ignore, PdfErrorCode } from '@embedpdf/models';\n\nimport { useRenderCapability } from '../hooks/use-render';\n\ntype RenderLayoutProps = Omit<JSX.HTMLAttributes<HTMLImageElement>, 'style'> & {\n pageIndex: number;\n scaleFactor?: number;\n dpr?: number;\n style?: JSX.CSSProperties;\n};\n\nexport function RenderLayer({\n pageIndex,\n scaleFactor = 1,\n dpr = 1,\n style,\n ...props\n}: RenderLayoutProps) {\n const { provides: renderProvides } = useRenderCapability();\n const [imageUrl, setImageUrl] = useState<string | null>(null);\n const urlRef = useRef<string | null>(null);\n\n useEffect(() => {\n if (renderProvides) {\n const task = renderProvides.renderPage({ pageIndex, scaleFactor, dpr });\n task.wait((blob) => {\n const url = URL.createObjectURL(blob);\n setImageUrl(url);\n urlRef.current = url;\n }, ignore);\n\n return () => {\n if (urlRef.current) {\n URL.revokeObjectURL(urlRef.current);\n urlRef.current = null;\n } else {\n task.abort({\n code: PdfErrorCode.Cancelled,\n message: 'canceled render task',\n });\n }\n };\n }\n }, [pageIndex, scaleFactor, dpr, renderProvides]);\n\n const handleImageLoad = () => {\n if (urlRef.current) {\n URL.revokeObjectURL(urlRef.current);\n urlRef.current = null;\n }\n };\n\n return (\n <Fragment>\n {imageUrl && (\n <img\n src={imageUrl}\n onLoad={handleImageLoad}\n {...props}\n style={{\n width: '100%',\n height: '100%',\n ...(style || {}),\n }}\n />\n )}\n </Fragment>\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,oBAAyC;AACzC,2BAA6B;AAEtB,IAAM,YAAY,UAAM,yBAAwB,kCAAa,EAAE;AAC/D,IAAM,sBAAsB,UAAM,6BAA4B,kCAAa,EAAE;;;ACHpF,IAAAA,iBAAiD;AACjD,mBAA4C;AAC5C,oBAAqC;AAuD7B;AA5CD,SAAS,YAAY;AAAA,EAC1B;AAAA,EACA,cAAc;AAAA,EACd,MAAM;AAAA,EACN;AAAA,EACA,GAAG;AACL,GAAsB;AACpB,QAAM,EAAE,UAAU,eAAe,IAAI,oBAAoB;AACzD,QAAM,CAAC,UAAU,WAAW,QAAI,uBAAwB,IAAI;AAC5D,QAAM,aAAS,qBAAsB,IAAI;AAEzC,8BAAU,MAAM;AACd,QAAI,gBAAgB;AAClB,YAAM,OAAO,eAAe,WAAW,EAAE,WAAW,aAAa,IAAI,CAAC;AACtE,WAAK,KAAK,CAAC,SAAS;AAClB,cAAM,MAAM,IAAI,gBAAgB,IAAI;AACpC,oBAAY,GAAG;AACf,eAAO,UAAU;AAAA,MACnB,GAAG,oBAAM;AAET,aAAO,MAAM;AACX,YAAI,OAAO,SAAS;AAClB,cAAI,gBAAgB,OAAO,OAAO;AAClC,iBAAO,UAAU;AAAA,QACnB,OAAO;AACL,eAAK,MAAM;AAAA,YACT,MAAM,2BAAa;AAAA,YACnB,SAAS;AAAA,UACX,CAAC;AAAA,QACH;AAAA,MACF;AAAA,IACF;AAAA,EACF,GAAG,CAAC,WAAW,aAAa,KAAK,cAAc,CAAC;AAEhD,QAAM,kBAAkB,MAAM;AAC5B,QAAI,OAAO,SAAS;AAClB,UAAI,gBAAgB,OAAO,OAAO;AAClC,aAAO,UAAU;AAAA,IACnB;AAAA,EACF;AAEA,SACE,4CAAC,2BACE,sBACC;AAAA,IAAC;AAAA;AAAA,MACC,KAAK;AAAA,MACL,QAAQ;AAAA,MACP,GAAG;AAAA,MACJ,OAAO;AAAA,QACL,OAAO;AAAA,QACP,QAAQ;AAAA,QACR,GAAI,SAAS,CAAC;AAAA,MAChB;AAAA;AAAA,EACF,GAEJ;AAEJ;","names":["import_preact"]}
@@ -0,0 +1,26 @@
1
+ import * as _embedpdf_plugin_render from '@embedpdf/plugin-render';
2
+ import { RenderPlugin } from '@embedpdf/plugin-render';
3
+ import { JSX } from 'preact';
4
+
5
+ declare const useRender: () => {
6
+ plugin: RenderPlugin | null;
7
+ isLoading: boolean;
8
+ ready: Promise<void>;
9
+ };
10
+ declare const useRenderCapability: () => {
11
+ provides: Readonly<_embedpdf_plugin_render.RenderCapability> | null;
12
+ isLoading: boolean;
13
+ ready: Promise<void>;
14
+ };
15
+
16
+ /** @jsxImportSource preact */
17
+
18
+ type RenderLayoutProps = Omit<JSX.HTMLAttributes<HTMLImageElement>, 'style'> & {
19
+ pageIndex: number;
20
+ scaleFactor?: number;
21
+ dpr?: number;
22
+ style?: JSX.CSSProperties;
23
+ };
24
+ declare function RenderLayer({ pageIndex, scaleFactor, dpr, style, ...props }: RenderLayoutProps): JSX.Element;
25
+
26
+ export { RenderLayer, useRender, useRenderCapability };
@@ -0,0 +1,26 @@
1
+ import * as _embedpdf_plugin_render from '@embedpdf/plugin-render';
2
+ import { RenderPlugin } from '@embedpdf/plugin-render';
3
+ import { JSX } from 'preact';
4
+
5
+ declare const useRender: () => {
6
+ plugin: RenderPlugin | null;
7
+ isLoading: boolean;
8
+ ready: Promise<void>;
9
+ };
10
+ declare const useRenderCapability: () => {
11
+ provides: Readonly<_embedpdf_plugin_render.RenderCapability> | null;
12
+ isLoading: boolean;
13
+ ready: Promise<void>;
14
+ };
15
+
16
+ /** @jsxImportSource preact */
17
+
18
+ type RenderLayoutProps = Omit<JSX.HTMLAttributes<HTMLImageElement>, 'style'> & {
19
+ pageIndex: number;
20
+ scaleFactor?: number;
21
+ dpr?: number;
22
+ style?: JSX.CSSProperties;
23
+ };
24
+ declare function RenderLayer({ pageIndex, scaleFactor, dpr, style, ...props }: RenderLayoutProps): JSX.Element;
25
+
26
+ export { RenderLayer, useRender, useRenderCapability };
@@ -0,0 +1,68 @@
1
+ // src/preact/hooks/use-render.ts
2
+ import { useCapability, usePlugin } from "@embedpdf/core/preact";
3
+ import { RenderPlugin } from "@embedpdf/plugin-render";
4
+ var useRender = () => usePlugin(RenderPlugin.id);
5
+ var useRenderCapability = () => useCapability(RenderPlugin.id);
6
+
7
+ // src/preact/components/render-layer.tsx
8
+ import { Fragment } from "preact";
9
+ import { useEffect, useRef, useState } from "preact/hooks";
10
+ import { ignore, PdfErrorCode } from "@embedpdf/models";
11
+ import { jsx } from "preact/jsx-runtime";
12
+ function RenderLayer({
13
+ pageIndex,
14
+ scaleFactor = 1,
15
+ dpr = 1,
16
+ style,
17
+ ...props
18
+ }) {
19
+ const { provides: renderProvides } = useRenderCapability();
20
+ const [imageUrl, setImageUrl] = useState(null);
21
+ const urlRef = useRef(null);
22
+ useEffect(() => {
23
+ if (renderProvides) {
24
+ const task = renderProvides.renderPage({ pageIndex, scaleFactor, dpr });
25
+ task.wait((blob) => {
26
+ const url = URL.createObjectURL(blob);
27
+ setImageUrl(url);
28
+ urlRef.current = url;
29
+ }, ignore);
30
+ return () => {
31
+ if (urlRef.current) {
32
+ URL.revokeObjectURL(urlRef.current);
33
+ urlRef.current = null;
34
+ } else {
35
+ task.abort({
36
+ code: PdfErrorCode.Cancelled,
37
+ message: "canceled render task"
38
+ });
39
+ }
40
+ };
41
+ }
42
+ }, [pageIndex, scaleFactor, dpr, renderProvides]);
43
+ const handleImageLoad = () => {
44
+ if (urlRef.current) {
45
+ URL.revokeObjectURL(urlRef.current);
46
+ urlRef.current = null;
47
+ }
48
+ };
49
+ return /* @__PURE__ */ jsx(Fragment, { children: imageUrl && /* @__PURE__ */ jsx(
50
+ "img",
51
+ {
52
+ src: imageUrl,
53
+ onLoad: handleImageLoad,
54
+ ...props,
55
+ style: {
56
+ width: "100%",
57
+ height: "100%",
58
+ ...style || {}
59
+ }
60
+ }
61
+ ) });
62
+ }
63
+ export {
64
+ RenderLayer,
65
+ useRender,
66
+ useRenderCapability
67
+ };
68
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/preact/hooks/use-render.ts","../../src/preact/components/render-layer.tsx"],"sourcesContent":["import { useCapability, usePlugin } from '@embedpdf/core/preact';\nimport { RenderPlugin } from '@embedpdf/plugin-render';\n\nexport const useRender = () => usePlugin<RenderPlugin>(RenderPlugin.id);\nexport const useRenderCapability = () => useCapability<RenderPlugin>(RenderPlugin.id);\n","/** @jsxImportSource preact */\nimport { ComponentChildren, Fragment, JSX } from 'preact';\nimport { useEffect, useRef, useState } from 'preact/hooks';\nimport { ignore, PdfErrorCode } from '@embedpdf/models';\n\nimport { useRenderCapability } from '../hooks/use-render';\n\ntype RenderLayoutProps = Omit<JSX.HTMLAttributes<HTMLImageElement>, 'style'> & {\n pageIndex: number;\n scaleFactor?: number;\n dpr?: number;\n style?: JSX.CSSProperties;\n};\n\nexport function RenderLayer({\n pageIndex,\n scaleFactor = 1,\n dpr = 1,\n style,\n ...props\n}: RenderLayoutProps) {\n const { provides: renderProvides } = useRenderCapability();\n const [imageUrl, setImageUrl] = useState<string | null>(null);\n const urlRef = useRef<string | null>(null);\n\n useEffect(() => {\n if (renderProvides) {\n const task = renderProvides.renderPage({ pageIndex, scaleFactor, dpr });\n task.wait((blob) => {\n const url = URL.createObjectURL(blob);\n setImageUrl(url);\n urlRef.current = url;\n }, ignore);\n\n return () => {\n if (urlRef.current) {\n URL.revokeObjectURL(urlRef.current);\n urlRef.current = null;\n } else {\n task.abort({\n code: PdfErrorCode.Cancelled,\n message: 'canceled render task',\n });\n }\n };\n }\n }, [pageIndex, scaleFactor, dpr, renderProvides]);\n\n const handleImageLoad = () => {\n if (urlRef.current) {\n URL.revokeObjectURL(urlRef.current);\n urlRef.current = null;\n }\n };\n\n return (\n <Fragment>\n {imageUrl && (\n <img\n src={imageUrl}\n onLoad={handleImageLoad}\n {...props}\n style={{\n width: '100%',\n height: '100%',\n ...(style || {}),\n }}\n />\n )}\n </Fragment>\n );\n}\n"],"mappings":";AAAA,SAAS,eAAe,iBAAiB;AACzC,SAAS,oBAAoB;AAEtB,IAAM,YAAY,MAAM,UAAwB,aAAa,EAAE;AAC/D,IAAM,sBAAsB,MAAM,cAA4B,aAAa,EAAE;;;ACHpF,SAA4B,gBAAqB;AACjD,SAAS,WAAW,QAAQ,gBAAgB;AAC5C,SAAS,QAAQ,oBAAoB;AAuD7B;AA5CD,SAAS,YAAY;AAAA,EAC1B;AAAA,EACA,cAAc;AAAA,EACd,MAAM;AAAA,EACN;AAAA,EACA,GAAG;AACL,GAAsB;AACpB,QAAM,EAAE,UAAU,eAAe,IAAI,oBAAoB;AACzD,QAAM,CAAC,UAAU,WAAW,IAAI,SAAwB,IAAI;AAC5D,QAAM,SAAS,OAAsB,IAAI;AAEzC,YAAU,MAAM;AACd,QAAI,gBAAgB;AAClB,YAAM,OAAO,eAAe,WAAW,EAAE,WAAW,aAAa,IAAI,CAAC;AACtE,WAAK,KAAK,CAAC,SAAS;AAClB,cAAM,MAAM,IAAI,gBAAgB,IAAI;AACpC,oBAAY,GAAG;AACf,eAAO,UAAU;AAAA,MACnB,GAAG,MAAM;AAET,aAAO,MAAM;AACX,YAAI,OAAO,SAAS;AAClB,cAAI,gBAAgB,OAAO,OAAO;AAClC,iBAAO,UAAU;AAAA,QACnB,OAAO;AACL,eAAK,MAAM;AAAA,YACT,MAAM,aAAa;AAAA,YACnB,SAAS;AAAA,UACX,CAAC;AAAA,QACH;AAAA,MACF;AAAA,IACF;AAAA,EACF,GAAG,CAAC,WAAW,aAAa,KAAK,cAAc,CAAC;AAEhD,QAAM,kBAAkB,MAAM;AAC5B,QAAI,OAAO,SAAS;AAClB,UAAI,gBAAgB,OAAO,OAAO;AAClC,aAAO,UAAU;AAAA,IACnB;AAAA,EACF;AAEA,SACE,oBAAC,YACE,sBACC;AAAA,IAAC;AAAA;AAAA,MACC,KAAK;AAAA,MACL,QAAQ;AAAA,MACP,GAAG;AAAA,MACJ,OAAO;AAAA,QACL,OAAO;AAAA,QACP,QAAQ;AAAA,QACR,GAAI,SAAS,CAAC;AAAA,MAChB;AAAA;AAAA,EACF,GAEJ;AAEJ;","names":[]}
@@ -0,0 +1,96 @@
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/react/index.ts
21
+ var react_exports = {};
22
+ __export(react_exports, {
23
+ RenderLayer: () => RenderLayer,
24
+ useRender: () => useRender,
25
+ useRenderCapability: () => useRenderCapability
26
+ });
27
+ module.exports = __toCommonJS(react_exports);
28
+
29
+ // src/react/hooks/use-render.ts
30
+ var import_react = require("@embedpdf/core/react");
31
+ var import_plugin_render = require("@embedpdf/plugin-render");
32
+ var useRender = () => (0, import_react.usePlugin)(import_plugin_render.RenderPlugin.id);
33
+ var useRenderCapability = () => (0, import_react.useCapability)(import_plugin_render.RenderPlugin.id);
34
+
35
+ // src/react/components/render-layer.tsx
36
+ var import_react2 = require("react");
37
+ var import_models = require("@embedpdf/models");
38
+ var import_jsx_runtime = require("react/jsx-runtime");
39
+ function RenderLayer({
40
+ pageIndex,
41
+ scaleFactor = 1,
42
+ dpr = 1,
43
+ style,
44
+ ...props
45
+ }) {
46
+ const { provides: renderProvides } = useRenderCapability();
47
+ const [imageUrl, setImageUrl] = (0, import_react2.useState)(null);
48
+ const urlRef = (0, import_react2.useRef)(null);
49
+ (0, import_react2.useEffect)(() => {
50
+ if (renderProvides) {
51
+ const task = renderProvides.renderPage({ pageIndex, scaleFactor, dpr });
52
+ task.wait((blob) => {
53
+ const url = URL.createObjectURL(blob);
54
+ setImageUrl(url);
55
+ urlRef.current = url;
56
+ }, import_models.ignore);
57
+ return () => {
58
+ if (urlRef.current) {
59
+ URL.revokeObjectURL(urlRef.current);
60
+ urlRef.current = null;
61
+ } else {
62
+ task.abort({
63
+ code: import_models.PdfErrorCode.Cancelled,
64
+ message: "canceled render task"
65
+ });
66
+ }
67
+ };
68
+ }
69
+ }, [pageIndex, scaleFactor, dpr, renderProvides]);
70
+ const handleImageLoad = () => {
71
+ if (urlRef.current) {
72
+ URL.revokeObjectURL(urlRef.current);
73
+ urlRef.current = null;
74
+ }
75
+ };
76
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react2.Fragment, { children: imageUrl && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
77
+ "img",
78
+ {
79
+ src: imageUrl,
80
+ onLoad: handleImageLoad,
81
+ ...props,
82
+ style: {
83
+ width: "100%",
84
+ height: "100%",
85
+ ...style || {}
86
+ }
87
+ }
88
+ ) });
89
+ }
90
+ // Annotate the CommonJS export names for ESM import in node:
91
+ 0 && (module.exports = {
92
+ RenderLayer,
93
+ useRender,
94
+ useRenderCapability
95
+ });
96
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/react/index.ts","../../src/react/hooks/use-render.ts","../../src/react/components/render-layer.tsx"],"sourcesContent":["export * from './hooks';\nexport * from './components';\n","import { useCapability, usePlugin } from '@embedpdf/core/react';\nimport { RenderPlugin } from '@embedpdf/plugin-render';\n\nexport const useRender = () => usePlugin<RenderPlugin>(RenderPlugin.id);\nexport const useRenderCapability = () => useCapability<RenderPlugin>(RenderPlugin.id);\n","import { Fragment, useEffect, useRef, useState } from 'react';\nimport { ignore, PdfErrorCode } from '@embedpdf/models';\n\nimport { useRenderCapability } from '../hooks/use-render';\n\ntype RenderLayoutProps = Omit<React.HTMLAttributes<HTMLImageElement>, 'style'> & {\n pageIndex: number;\n scaleFactor?: number;\n dpr?: number;\n style?: React.CSSProperties;\n};\n\nexport function RenderLayer({\n pageIndex,\n scaleFactor = 1,\n dpr = 1,\n style,\n ...props\n}: RenderLayoutProps) {\n const { provides: renderProvides } = useRenderCapability();\n const [imageUrl, setImageUrl] = useState<string | null>(null);\n const urlRef = useRef<string | null>(null);\n\n useEffect(() => {\n if (renderProvides) {\n const task = renderProvides.renderPage({ pageIndex, scaleFactor, dpr });\n task.wait((blob) => {\n const url = URL.createObjectURL(blob);\n setImageUrl(url);\n urlRef.current = url;\n }, ignore);\n\n return () => {\n if (urlRef.current) {\n URL.revokeObjectURL(urlRef.current);\n urlRef.current = null;\n } else {\n task.abort({\n code: PdfErrorCode.Cancelled,\n message: 'canceled render task',\n });\n }\n };\n }\n }, [pageIndex, scaleFactor, dpr, renderProvides]);\n\n const handleImageLoad = () => {\n if (urlRef.current) {\n URL.revokeObjectURL(urlRef.current);\n urlRef.current = null;\n }\n };\n\n return (\n <Fragment>\n {imageUrl && (\n <img\n src={imageUrl}\n onLoad={handleImageLoad}\n {...props}\n style={{\n width: '100%',\n height: '100%',\n ...(style || {}),\n }}\n />\n )}\n </Fragment>\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,mBAAyC;AACzC,2BAA6B;AAEtB,IAAM,YAAY,UAAM,wBAAwB,kCAAa,EAAE;AAC/D,IAAM,sBAAsB,UAAM,4BAA4B,kCAAa,EAAE;;;ACJpF,IAAAA,gBAAsD;AACtD,oBAAqC;AAuD7B;AA5CD,SAAS,YAAY;AAAA,EAC1B;AAAA,EACA,cAAc;AAAA,EACd,MAAM;AAAA,EACN;AAAA,EACA,GAAG;AACL,GAAsB;AACpB,QAAM,EAAE,UAAU,eAAe,IAAI,oBAAoB;AACzD,QAAM,CAAC,UAAU,WAAW,QAAI,wBAAwB,IAAI;AAC5D,QAAM,aAAS,sBAAsB,IAAI;AAEzC,+BAAU,MAAM;AACd,QAAI,gBAAgB;AAClB,YAAM,OAAO,eAAe,WAAW,EAAE,WAAW,aAAa,IAAI,CAAC;AACtE,WAAK,KAAK,CAAC,SAAS;AAClB,cAAM,MAAM,IAAI,gBAAgB,IAAI;AACpC,oBAAY,GAAG;AACf,eAAO,UAAU;AAAA,MACnB,GAAG,oBAAM;AAET,aAAO,MAAM;AACX,YAAI,OAAO,SAAS;AAClB,cAAI,gBAAgB,OAAO,OAAO;AAClC,iBAAO,UAAU;AAAA,QACnB,OAAO;AACL,eAAK,MAAM;AAAA,YACT,MAAM,2BAAa;AAAA,YACnB,SAAS;AAAA,UACX,CAAC;AAAA,QACH;AAAA,MACF;AAAA,IACF;AAAA,EACF,GAAG,CAAC,WAAW,aAAa,KAAK,cAAc,CAAC;AAEhD,QAAM,kBAAkB,MAAM;AAC5B,QAAI,OAAO,SAAS;AAClB,UAAI,gBAAgB,OAAO,OAAO;AAClC,aAAO,UAAU;AAAA,IACnB;AAAA,EACF;AAEA,SACE,4CAAC,0BACE,sBACC;AAAA,IAAC;AAAA;AAAA,MACC,KAAK;AAAA,MACL,QAAQ;AAAA,MACP,GAAG;AAAA,MACJ,OAAO;AAAA,QACL,OAAO;AAAA,QACP,QAAQ;AAAA,QACR,GAAI,SAAS,CAAC;AAAA,MAChB;AAAA;AAAA,EACF,GAEJ;AAEJ;","names":["import_react"]}
@@ -0,0 +1,24 @@
1
+ import * as _embedpdf_plugin_render from '@embedpdf/plugin-render';
2
+ import { RenderPlugin } from '@embedpdf/plugin-render';
3
+ import * as react_jsx_runtime from 'react/jsx-runtime';
4
+
5
+ declare const useRender: () => {
6
+ plugin: RenderPlugin | null;
7
+ isLoading: boolean;
8
+ ready: Promise<void>;
9
+ };
10
+ declare const useRenderCapability: () => {
11
+ provides: Readonly<_embedpdf_plugin_render.RenderCapability> | null;
12
+ isLoading: boolean;
13
+ ready: Promise<void>;
14
+ };
15
+
16
+ type RenderLayoutProps = Omit<React.HTMLAttributes<HTMLImageElement>, 'style'> & {
17
+ pageIndex: number;
18
+ scaleFactor?: number;
19
+ dpr?: number;
20
+ style?: React.CSSProperties;
21
+ };
22
+ declare function RenderLayer({ pageIndex, scaleFactor, dpr, style, ...props }: RenderLayoutProps): react_jsx_runtime.JSX.Element;
23
+
24
+ export { RenderLayer, useRender, useRenderCapability };
@@ -0,0 +1,24 @@
1
+ import * as _embedpdf_plugin_render from '@embedpdf/plugin-render';
2
+ import { RenderPlugin } from '@embedpdf/plugin-render';
3
+ import * as react_jsx_runtime from 'react/jsx-runtime';
4
+
5
+ declare const useRender: () => {
6
+ plugin: RenderPlugin | null;
7
+ isLoading: boolean;
8
+ ready: Promise<void>;
9
+ };
10
+ declare const useRenderCapability: () => {
11
+ provides: Readonly<_embedpdf_plugin_render.RenderCapability> | null;
12
+ isLoading: boolean;
13
+ ready: Promise<void>;
14
+ };
15
+
16
+ type RenderLayoutProps = Omit<React.HTMLAttributes<HTMLImageElement>, 'style'> & {
17
+ pageIndex: number;
18
+ scaleFactor?: number;
19
+ dpr?: number;
20
+ style?: React.CSSProperties;
21
+ };
22
+ declare function RenderLayer({ pageIndex, scaleFactor, dpr, style, ...props }: RenderLayoutProps): react_jsx_runtime.JSX.Element;
23
+
24
+ export { RenderLayer, useRender, useRenderCapability };
@@ -0,0 +1,67 @@
1
+ // src/react/hooks/use-render.ts
2
+ import { useCapability, usePlugin } from "@embedpdf/core/react";
3
+ import { RenderPlugin } from "@embedpdf/plugin-render";
4
+ var useRender = () => usePlugin(RenderPlugin.id);
5
+ var useRenderCapability = () => useCapability(RenderPlugin.id);
6
+
7
+ // src/react/components/render-layer.tsx
8
+ import { Fragment, useEffect, useRef, useState } from "react";
9
+ import { ignore, PdfErrorCode } from "@embedpdf/models";
10
+ import { jsx } from "react/jsx-runtime";
11
+ function RenderLayer({
12
+ pageIndex,
13
+ scaleFactor = 1,
14
+ dpr = 1,
15
+ style,
16
+ ...props
17
+ }) {
18
+ const { provides: renderProvides } = useRenderCapability();
19
+ const [imageUrl, setImageUrl] = useState(null);
20
+ const urlRef = useRef(null);
21
+ useEffect(() => {
22
+ if (renderProvides) {
23
+ const task = renderProvides.renderPage({ pageIndex, scaleFactor, dpr });
24
+ task.wait((blob) => {
25
+ const url = URL.createObjectURL(blob);
26
+ setImageUrl(url);
27
+ urlRef.current = url;
28
+ }, ignore);
29
+ return () => {
30
+ if (urlRef.current) {
31
+ URL.revokeObjectURL(urlRef.current);
32
+ urlRef.current = null;
33
+ } else {
34
+ task.abort({
35
+ code: PdfErrorCode.Cancelled,
36
+ message: "canceled render task"
37
+ });
38
+ }
39
+ };
40
+ }
41
+ }, [pageIndex, scaleFactor, dpr, renderProvides]);
42
+ const handleImageLoad = () => {
43
+ if (urlRef.current) {
44
+ URL.revokeObjectURL(urlRef.current);
45
+ urlRef.current = null;
46
+ }
47
+ };
48
+ return /* @__PURE__ */ jsx(Fragment, { children: imageUrl && /* @__PURE__ */ jsx(
49
+ "img",
50
+ {
51
+ src: imageUrl,
52
+ onLoad: handleImageLoad,
53
+ ...props,
54
+ style: {
55
+ width: "100%",
56
+ height: "100%",
57
+ ...style || {}
58
+ }
59
+ }
60
+ ) });
61
+ }
62
+ export {
63
+ RenderLayer,
64
+ useRender,
65
+ useRenderCapability
66
+ };
67
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/react/hooks/use-render.ts","../../src/react/components/render-layer.tsx"],"sourcesContent":["import { useCapability, usePlugin } from '@embedpdf/core/react';\nimport { RenderPlugin } from '@embedpdf/plugin-render';\n\nexport const useRender = () => usePlugin<RenderPlugin>(RenderPlugin.id);\nexport const useRenderCapability = () => useCapability<RenderPlugin>(RenderPlugin.id);\n","import { Fragment, useEffect, useRef, useState } from 'react';\nimport { ignore, PdfErrorCode } from '@embedpdf/models';\n\nimport { useRenderCapability } from '../hooks/use-render';\n\ntype RenderLayoutProps = Omit<React.HTMLAttributes<HTMLImageElement>, 'style'> & {\n pageIndex: number;\n scaleFactor?: number;\n dpr?: number;\n style?: React.CSSProperties;\n};\n\nexport function RenderLayer({\n pageIndex,\n scaleFactor = 1,\n dpr = 1,\n style,\n ...props\n}: RenderLayoutProps) {\n const { provides: renderProvides } = useRenderCapability();\n const [imageUrl, setImageUrl] = useState<string | null>(null);\n const urlRef = useRef<string | null>(null);\n\n useEffect(() => {\n if (renderProvides) {\n const task = renderProvides.renderPage({ pageIndex, scaleFactor, dpr });\n task.wait((blob) => {\n const url = URL.createObjectURL(blob);\n setImageUrl(url);\n urlRef.current = url;\n }, ignore);\n\n return () => {\n if (urlRef.current) {\n URL.revokeObjectURL(urlRef.current);\n urlRef.current = null;\n } else {\n task.abort({\n code: PdfErrorCode.Cancelled,\n message: 'canceled render task',\n });\n }\n };\n }\n }, [pageIndex, scaleFactor, dpr, renderProvides]);\n\n const handleImageLoad = () => {\n if (urlRef.current) {\n URL.revokeObjectURL(urlRef.current);\n urlRef.current = null;\n }\n };\n\n return (\n <Fragment>\n {imageUrl && (\n <img\n src={imageUrl}\n onLoad={handleImageLoad}\n {...props}\n style={{\n width: '100%',\n height: '100%',\n ...(style || {}),\n }}\n />\n )}\n </Fragment>\n );\n}\n"],"mappings":";AAAA,SAAS,eAAe,iBAAiB;AACzC,SAAS,oBAAoB;AAEtB,IAAM,YAAY,MAAM,UAAwB,aAAa,EAAE;AAC/D,IAAM,sBAAsB,MAAM,cAA4B,aAAa,EAAE;;;ACJpF,SAAS,UAAU,WAAW,QAAQ,gBAAgB;AACtD,SAAS,QAAQ,oBAAoB;AAuD7B;AA5CD,SAAS,YAAY;AAAA,EAC1B;AAAA,EACA,cAAc;AAAA,EACd,MAAM;AAAA,EACN;AAAA,EACA,GAAG;AACL,GAAsB;AACpB,QAAM,EAAE,UAAU,eAAe,IAAI,oBAAoB;AACzD,QAAM,CAAC,UAAU,WAAW,IAAI,SAAwB,IAAI;AAC5D,QAAM,SAAS,OAAsB,IAAI;AAEzC,YAAU,MAAM;AACd,QAAI,gBAAgB;AAClB,YAAM,OAAO,eAAe,WAAW,EAAE,WAAW,aAAa,IAAI,CAAC;AACtE,WAAK,KAAK,CAAC,SAAS;AAClB,cAAM,MAAM,IAAI,gBAAgB,IAAI;AACpC,oBAAY,GAAG;AACf,eAAO,UAAU;AAAA,MACnB,GAAG,MAAM;AAET,aAAO,MAAM;AACX,YAAI,OAAO,SAAS;AAClB,cAAI,gBAAgB,OAAO,OAAO;AAClC,iBAAO,UAAU;AAAA,QACnB,OAAO;AACL,eAAK,MAAM;AAAA,YACT,MAAM,aAAa;AAAA,YACnB,SAAS;AAAA,UACX,CAAC;AAAA,QACH;AAAA,MACF;AAAA,IACF;AAAA,EACF,GAAG,CAAC,WAAW,aAAa,KAAK,cAAc,CAAC;AAEhD,QAAM,kBAAkB,MAAM;AAC5B,QAAI,OAAO,SAAS;AAClB,UAAI,gBAAgB,OAAO,OAAO;AAClC,aAAO,UAAU;AAAA,IACnB;AAAA,EACF;AAEA,SACE,oBAAC,YACE,sBACC;AAAA,IAAC;AAAA;AAAA,MACC,KAAK;AAAA,MACL,QAAQ;AAAA,MACP,GAAG;AAAA,MACJ,OAAO;AAAA,QACL,OAAO;AAAA,QACP,QAAQ;AAAA,QACR,GAAI,SAAS,CAAC;AAAA,MAChB;AAAA;AAAA,EACF,GAEJ;AAEJ;","names":[]}
package/package.json ADDED
@@ -0,0 +1,66 @@
1
+ {
2
+ "name": "@embedpdf/plugin-render",
3
+ "version": "1.0.0",
4
+ "type": "module",
5
+ "main": "./dist/index.cjs",
6
+ "module": "./dist/index.js",
7
+ "types": "./dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./dist/index.d.ts",
11
+ "import": "./dist/index.js",
12
+ "require": "./dist/index.cjs"
13
+ },
14
+ "./preact": {
15
+ "types": "./dist/preact/index.d.ts",
16
+ "import": "./dist/preact/index.js",
17
+ "require": "./dist/preact/index.cjs"
18
+ },
19
+ "./react": {
20
+ "types": "./dist/react/index.d.ts",
21
+ "import": "./dist/react/index.js",
22
+ "require": "./dist/react/index.cjs"
23
+ }
24
+ },
25
+ "dependencies": {
26
+ "@embedpdf/models": "1.0.0"
27
+ },
28
+ "devDependencies": {
29
+ "@types/react": "^18.2.0",
30
+ "tsup": "^8.0.0",
31
+ "typescript": "^5.0.0",
32
+ "@embedpdf/plugin-loader": "1.0.0",
33
+ "@embedpdf/core": "1.0.0"
34
+ },
35
+ "peerDependencies": {
36
+ "react": ">=16.8.0",
37
+ "react-dom": ">=16.8.0",
38
+ "preact": "^10.26.4",
39
+ "@embedpdf/core": "1.0.0",
40
+ "@embedpdf/plugin-loader": "1.0.0"
41
+ },
42
+ "files": [
43
+ "dist",
44
+ "README.md"
45
+ ],
46
+ "repository": {
47
+ "type": "git",
48
+ "url": "https://github.com/embedpdf/embed-pdf-viewer",
49
+ "directory": "packages/plugin-render"
50
+ },
51
+ "homepage": "https://www.embedpdf.com/docs",
52
+ "bugs": {
53
+ "url": "https://github.com/embedpdf/embed-pdf-viewer/issues"
54
+ },
55
+ "publishConfig": {
56
+ "access": "public"
57
+ },
58
+ "scripts": {
59
+ "build": "PROJECT_CWD=$(pwd) pnpm -w p:build",
60
+ "build:watch": "PROJECT_CWD=$(pwd) pnpm -w p:build:watch",
61
+ "clean": "PROJECT_CWD=$(pwd) pnpm -w p:clean",
62
+ "lint": "PROJECT_CWD=$(pwd) pnpm -w p:lint",
63
+ "lint:fix": "PROJECT_CWD=$(pwd) pnpm -w p:lint:fix",
64
+ "typecheck": "PROJECT_CWD=$(pwd) pnpm -w p:typecheck"
65
+ }
66
+ }