@embedpdf/plugin-render 1.4.1 → 2.0.0-next.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/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +59 -27
- package/dist/index.js.map +1 -1
- package/dist/lib/render-plugin.d.ts +13 -5
- package/dist/lib/types.d.ts +17 -2
- package/dist/preact/adapter.d.ts +2 -2
- package/dist/preact/index.cjs +1 -1
- package/dist/preact/index.cjs.map +1 -1
- package/dist/preact/index.js +41 -37
- package/dist/preact/index.js.map +1 -1
- package/dist/react/adapter.d.ts +1 -1
- package/dist/react/index.cjs +1 -1
- package/dist/react/index.cjs.map +1 -1
- package/dist/react/index.js +41 -37
- package/dist/react/index.js.map +1 -1
- package/dist/shared/components/render-layer.d.ts +23 -4
- package/dist/shared-preact/components/render-layer.d.ts +23 -4
- package/dist/shared-react/components/render-layer.d.ts +23 -4
- package/dist/svelte/components/RenderLayer.svelte.d.ts +14 -0
- package/dist/svelte/index.cjs +1 -1
- package/dist/svelte/index.cjs.map +1 -1
- package/dist/svelte/index.js +46 -36
- package/dist/svelte/index.js.map +1 -1
- package/dist/vue/components/render-layer.vue.d.ts +12 -5
- package/dist/vue/index.cjs +1 -1
- package/dist/vue/index.cjs.map +1 -1
- package/dist/vue/index.js +69 -57
- package/dist/vue/index.js.map +1 -1
- package/package.json +5 -5
package/dist/index.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("@embedpdf/core"),
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("@embedpdf/core"),t=class extends e.BasePlugin{constructor(e,t,n){super(e,t),this.withForms=!1,this.withAnnotations=!1,this.withForms=(null==n?void 0:n.withForms)??!1,this.withAnnotations=(null==n?void 0:n.withAnnotations)??!1}buildCapability(){return{renderPage:e=>this.renderPage(e),renderPageRect:e=>this.renderPageRect(e),forDocument:e=>this.createRenderScope(e)}}createRenderScope(e){return{renderPage:t=>this.renderPage(t,e),renderPageRect:t=>this.renderPageRect(t,e)}}renderPage({pageIndex:e,options:t},n){const i=n??this.getActiveDocumentId(),o=this.coreState.core.documents[i];if(!(null==o?void 0:o.document))throw new Error(`Document ${i} not loaded`);const r=o.document.pages.find(t=>t.index===e);if(!r)throw new Error(`Page ${e} not found in document ${i}`);const s={...t??{},withForms:(null==t?void 0:t.withForms)??this.withForms,withAnnotations:(null==t?void 0:t.withAnnotations)??this.withAnnotations};return this.engine.renderPage(o.document,r,s)}renderPageRect({pageIndex:e,rect:t,options:n},i){const o=i??this.getActiveDocumentId(),r=this.coreState.core.documents[o];if(!(null==r?void 0:r.document))throw new Error(`Document ${o} not loaded`);const s=r.document.pages.find(t=>t.index===e);if(!s)throw new Error(`Page ${e} not found in document ${o}`);const d={...n??{},withForms:(null==n?void 0:n.withForms)??this.withForms,withAnnotations:(null==n?void 0:n.withAnnotations)??this.withAnnotations};return this.engine.renderPageRect(r.document,s,t,d)}async initialize(e){this.logger.info("RenderPlugin","Initialize","Render plugin initialized")}async destroy(){super.destroy()}};t.id="render";let n=t;const i="render",o={manifest:{id:i,name:"Render Plugin",version:"1.0.0",provides:["render"],requires:[],optional:[],defaultConfig:{enabled:!0}},create:(e,t)=>new n(i,e,t),reducer:()=>{},initialState:{}};exports.RenderPlugin=n,exports.RenderPluginPackage=o;
|
|
2
2
|
//# sourceMappingURL=index.cjs.map
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","sources":["../src/lib/render-plugin.ts","../src/lib/manifest.ts","../src/lib/index.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"file":"index.cjs","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 RenderScope,\n} from './types';\n\n/**\n * Render Plugin - Simplified version that relies on core state for refresh tracking\n *\n * Key insight: Page refresh tracking is in DocumentState.pageRefreshVersions\n * This allows ANY plugin to observe page refreshes, not just the render plugin.\n */\nexport class RenderPlugin extends BasePlugin<RenderPluginConfig, RenderCapability> {\n static readonly id = 'render' as const;\n\n private withForms = false;\n private withAnnotations = false;\n\n constructor(id: string, registry: PluginRegistry, config?: RenderPluginConfig) {\n super(id, registry);\n\n this.withForms = config?.withForms ?? false;\n this.withAnnotations = config?.withAnnotations ?? false;\n }\n\n // No onDocumentLoadingStarted or onDocumentClosed needed!\n\n protected buildCapability(): RenderCapability {\n return {\n // Active document operations\n renderPage: (options: RenderPageOptions) => this.renderPage(options),\n renderPageRect: (options: RenderPageRectOptions) => this.renderPageRect(options),\n\n // Document-scoped operations\n forDocument: (documentId: string) => this.createRenderScope(documentId),\n };\n }\n\n // ─────────────────────────────────────────────────────────\n // Document Scoping\n // ─────────────────────────────────────────────────────────\n\n private createRenderScope(documentId: string): RenderScope {\n return {\n renderPage: (options: RenderPageOptions) => this.renderPage(options, documentId),\n renderPageRect: (options: RenderPageRectOptions) => this.renderPageRect(options, documentId),\n };\n }\n\n // ─────────────────────────────────────────────────────────\n // Core Operations\n // ─────────────────────────────────────────────────────────\n\n private renderPage({ pageIndex, options }: RenderPageOptions, documentId?: string) {\n const id = documentId ?? this.getActiveDocumentId();\n const coreDoc = this.coreState.core.documents[id];\n\n if (!coreDoc?.document) {\n throw new Error(`Document ${id} not loaded`);\n }\n\n const page = coreDoc.document.pages.find((p) => p.index === pageIndex);\n if (!page) {\n throw new Error(`Page ${pageIndex} not found in document ${id}`);\n }\n\n const mergedOptions = {\n ...(options ?? {}),\n withForms: options?.withForms ?? this.withForms,\n withAnnotations: options?.withAnnotations ?? this.withAnnotations,\n };\n\n return this.engine.renderPage(coreDoc.document, page, mergedOptions);\n }\n\n private renderPageRect({ pageIndex, rect, options }: RenderPageRectOptions, documentId?: string) {\n const id = documentId ?? this.getActiveDocumentId();\n const coreDoc = this.coreState.core.documents[id];\n\n if (!coreDoc?.document) {\n throw new Error(`Document ${id} not loaded`);\n }\n\n const page = coreDoc.document.pages.find((p) => p.index === pageIndex);\n if (!page) {\n throw new Error(`Page ${pageIndex} not found in document ${id}`);\n }\n\n const mergedOptions = {\n ...(options ?? {}),\n withForms: options?.withForms ?? this.withForms,\n withAnnotations: options?.withAnnotations ?? this.withAnnotations,\n };\n\n return this.engine.renderPageRect(coreDoc.document, page, rect, mergedOptions);\n }\n\n // ─────────────────────────────────────────────────────────\n // Lifecycle\n // ─────────────────────────────────────────────────────────\n\n async initialize(_config: RenderPluginConfig): Promise<void> {\n this.logger.info('RenderPlugin', 'Initialize', 'Render plugin initialized');\n }\n\n async destroy(): Promise<void> {\n super.destroy();\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, config) => new RenderPlugin(RENDER_PLUGIN_ID, registry, config),\n reducer: () => {},\n initialState: {},\n};\n\nexport * from './render-plugin';\nexport * from './types';\n"],"names":["_RenderPlugin","BasePlugin","constructor","id","registry","config","super","this","withForms","withAnnotations","buildCapability","renderPage","options","renderPageRect","forDocument","documentId","createRenderScope","pageIndex","getActiveDocumentId","coreDoc","coreState","core","documents","document","Error","page","pages","find","p","index","mergedOptions","engine","rect","initialize","_config","logger","info","destroy","RenderPlugin","RENDER_PLUGIN_ID","RenderPluginPackage","manifest","name","version","provides","requires","optional","defaultConfig","enabled","create","reducer","initialState"],"mappings":"kHAeaA,EAAN,cAA2BC,EAAAA,WAMhC,WAAAC,CAAYC,EAAYC,EAA0BC,GAChDC,MAAMH,EAAIC,GAJZG,KAAQC,WAAY,EACpBD,KAAQE,iBAAkB,EAKxBF,KAAKC,iBAAYH,WAAQG,aAAa,EACtCD,KAAKE,uBAAkBJ,WAAQI,mBAAmB,CACpD,CAIU,eAAAC,GACR,MAAO,CAELC,WAAaC,GAA+BL,KAAKI,WAAWC,GAC5DC,eAAiBD,GAAmCL,KAAKM,eAAeD,GAGxEE,YAAcC,GAAuBR,KAAKS,kBAAkBD,GAEhE,CAMQ,iBAAAC,CAAkBD,GACxB,MAAO,CACLJ,WAAaC,GAA+BL,KAAKI,WAAWC,EAASG,GACrEF,eAAiBD,GAAmCL,KAAKM,eAAeD,EAASG,GAErF,CAMQ,UAAAJ,EAAWM,UAAEA,EAAAL,QAAWA,GAA8BG,GAC5D,MAAMZ,EAAKY,GAAcR,KAAKW,sBACxBC,EAAUZ,KAAKa,UAAUC,KAAKC,UAAUnB,GAE9C,WAAKgB,WAASI,UACZ,MAAM,IAAIC,MAAM,YAAYrB,gBAG9B,MAAMsB,EAAON,EAAQI,SAASG,MAAMC,KAAMC,GAAMA,EAAEC,QAAUZ,GAC5D,IAAKQ,EACH,MAAM,IAAID,MAAM,QAAQP,2BAAmCd,KAG7D,MAAM2B,EAAgB,IAChBlB,GAAW,CAAA,EACfJ,WAAW,MAAAI,OAAA,EAAAA,EAASJ,YAAaD,KAAKC,UACtCC,iBAAiB,MAAAG,OAAA,EAAAA,EAASH,kBAAmBF,KAAKE,iBAGpD,OAAOF,KAAKwB,OAAOpB,WAAWQ,EAAQI,SAAUE,EAAMK,EACxD,CAEQ,cAAAjB,EAAeI,UAAEA,EAAAe,KAAWA,EAAApB,QAAMA,GAAkCG,GAC1E,MAAMZ,EAAKY,GAAcR,KAAKW,sBACxBC,EAAUZ,KAAKa,UAAUC,KAAKC,UAAUnB,GAE9C,WAAKgB,WAASI,UACZ,MAAM,IAAIC,MAAM,YAAYrB,gBAG9B,MAAMsB,EAAON,EAAQI,SAASG,MAAMC,KAAMC,GAAMA,EAAEC,QAAUZ,GAC5D,IAAKQ,EACH,MAAM,IAAID,MAAM,QAAQP,2BAAmCd,KAG7D,MAAM2B,EAAgB,IAChBlB,GAAW,CAAA,EACfJ,WAAW,MAAAI,OAAA,EAAAA,EAASJ,YAAaD,KAAKC,UACtCC,iBAAiB,MAAAG,OAAA,EAAAA,EAASH,kBAAmBF,KAAKE,iBAGpD,OAAOF,KAAKwB,OAAOlB,eAAeM,EAAQI,SAAUE,EAAMO,EAAMF,EAClE,CAMA,gBAAMG,CAAWC,GACf3B,KAAK4B,OAAOC,KAAK,eAAgB,aAAc,4BACjD,CAEA,aAAMC,GACJ/B,MAAM+B,SACR,GA9FArC,EAAgBG,GAAK,SADhB,IAAMmC,EAANtC,ECZA,MAAMuC,EAAmB,SCEnBC,EAAuE,CAClFC,SDD0D,CAC1DtC,GAAIoC,EACJG,KAAM,gBACNC,QAAS,QACTC,SAAU,CAAC,UACXC,SAAU,GACVC,SAAU,GACVC,cAAe,CACbC,SAAS,ICNXC,OAAQ,CAAC7C,EAAUC,IAAW,IAAIiC,EAAaC,EAAkBnC,EAAUC,GAC3E6C,QAAS,OACTC,aAAc,CAAA"}
|
package/dist/index.js
CHANGED
|
@@ -1,44 +1,76 @@
|
|
|
1
|
-
import { BasePlugin
|
|
1
|
+
import { BasePlugin } from "@embedpdf/core";
|
|
2
2
|
const _RenderPlugin = class _RenderPlugin extends BasePlugin {
|
|
3
|
-
constructor(id, registry) {
|
|
3
|
+
constructor(id, registry, config) {
|
|
4
4
|
super(id, registry);
|
|
5
|
-
this.
|
|
6
|
-
this.
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
}
|
|
10
|
-
async initialize(_config) {
|
|
5
|
+
this.withForms = false;
|
|
6
|
+
this.withAnnotations = false;
|
|
7
|
+
this.withForms = (config == null ? void 0 : config.withForms) ?? false;
|
|
8
|
+
this.withAnnotations = (config == null ? void 0 : config.withAnnotations) ?? false;
|
|
11
9
|
}
|
|
10
|
+
// No onDocumentLoadingStarted or onDocumentClosed needed!
|
|
12
11
|
buildCapability() {
|
|
13
12
|
return {
|
|
14
|
-
|
|
15
|
-
|
|
13
|
+
// Active document operations
|
|
14
|
+
renderPage: (options) => this.renderPage(options),
|
|
15
|
+
renderPageRect: (options) => this.renderPageRect(options),
|
|
16
|
+
// Document-scoped operations
|
|
17
|
+
forDocument: (documentId) => this.createRenderScope(documentId)
|
|
16
18
|
};
|
|
17
19
|
}
|
|
18
|
-
|
|
19
|
-
|
|
20
|
+
// ─────────────────────────────────────────────────────────
|
|
21
|
+
// Document Scoping
|
|
22
|
+
// ─────────────────────────────────────────────────────────
|
|
23
|
+
createRenderScope(documentId) {
|
|
24
|
+
return {
|
|
25
|
+
renderPage: (options) => this.renderPage(options, documentId),
|
|
26
|
+
renderPageRect: (options) => this.renderPageRect(options, documentId)
|
|
27
|
+
};
|
|
20
28
|
}
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
29
|
+
// ─────────────────────────────────────────────────────────
|
|
30
|
+
// Core Operations
|
|
31
|
+
// ─────────────────────────────────────────────────────────
|
|
32
|
+
renderPage({ pageIndex, options }, documentId) {
|
|
33
|
+
const id = documentId ?? this.getActiveDocumentId();
|
|
34
|
+
const coreDoc = this.coreState.core.documents[id];
|
|
35
|
+
if (!(coreDoc == null ? void 0 : coreDoc.document)) {
|
|
36
|
+
throw new Error(`Document ${id} not loaded`);
|
|
25
37
|
}
|
|
26
|
-
const page =
|
|
38
|
+
const page = coreDoc.document.pages.find((p) => p.index === pageIndex);
|
|
27
39
|
if (!page) {
|
|
28
|
-
throw new Error(
|
|
40
|
+
throw new Error(`Page ${pageIndex} not found in document ${id}`);
|
|
29
41
|
}
|
|
30
|
-
|
|
42
|
+
const mergedOptions = {
|
|
43
|
+
...options ?? {},
|
|
44
|
+
withForms: (options == null ? void 0 : options.withForms) ?? this.withForms,
|
|
45
|
+
withAnnotations: (options == null ? void 0 : options.withAnnotations) ?? this.withAnnotations
|
|
46
|
+
};
|
|
47
|
+
return this.engine.renderPage(coreDoc.document, page, mergedOptions);
|
|
31
48
|
}
|
|
32
|
-
renderPageRect({ pageIndex, rect, options }) {
|
|
33
|
-
const
|
|
34
|
-
|
|
35
|
-
|
|
49
|
+
renderPageRect({ pageIndex, rect, options }, documentId) {
|
|
50
|
+
const id = documentId ?? this.getActiveDocumentId();
|
|
51
|
+
const coreDoc = this.coreState.core.documents[id];
|
|
52
|
+
if (!(coreDoc == null ? void 0 : coreDoc.document)) {
|
|
53
|
+
throw new Error(`Document ${id} not loaded`);
|
|
36
54
|
}
|
|
37
|
-
const page =
|
|
55
|
+
const page = coreDoc.document.pages.find((p) => p.index === pageIndex);
|
|
38
56
|
if (!page) {
|
|
39
|
-
throw new Error(
|
|
57
|
+
throw new Error(`Page ${pageIndex} not found in document ${id}`);
|
|
40
58
|
}
|
|
41
|
-
|
|
59
|
+
const mergedOptions = {
|
|
60
|
+
...options ?? {},
|
|
61
|
+
withForms: (options == null ? void 0 : options.withForms) ?? this.withForms,
|
|
62
|
+
withAnnotations: (options == null ? void 0 : options.withAnnotations) ?? this.withAnnotations
|
|
63
|
+
};
|
|
64
|
+
return this.engine.renderPageRect(coreDoc.document, page, rect, mergedOptions);
|
|
65
|
+
}
|
|
66
|
+
// ─────────────────────────────────────────────────────────
|
|
67
|
+
// Lifecycle
|
|
68
|
+
// ─────────────────────────────────────────────────────────
|
|
69
|
+
async initialize(_config) {
|
|
70
|
+
this.logger.info("RenderPlugin", "Initialize", "Render plugin initialized");
|
|
71
|
+
}
|
|
72
|
+
async destroy() {
|
|
73
|
+
super.destroy();
|
|
42
74
|
}
|
|
43
75
|
};
|
|
44
76
|
_RenderPlugin.id = "render";
|
|
@@ -57,7 +89,7 @@ const manifest = {
|
|
|
57
89
|
};
|
|
58
90
|
const RenderPluginPackage = {
|
|
59
91
|
manifest,
|
|
60
|
-
create: (registry) => new RenderPlugin(RENDER_PLUGIN_ID, registry),
|
|
92
|
+
create: (registry, config) => new RenderPlugin(RENDER_PLUGIN_ID, registry, config),
|
|
61
93
|
reducer: () => {
|
|
62
94
|
},
|
|
63
95
|
initialState: {}
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../src/lib/render-plugin.ts","../src/lib/manifest.ts","../src/lib/index.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"file":"index.js","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 RenderScope,\n} from './types';\n\n/**\n * Render Plugin - Simplified version that relies on core state for refresh tracking\n *\n * Key insight: Page refresh tracking is in DocumentState.pageRefreshVersions\n * This allows ANY plugin to observe page refreshes, not just the render plugin.\n */\nexport class RenderPlugin extends BasePlugin<RenderPluginConfig, RenderCapability> {\n static readonly id = 'render' as const;\n\n private withForms = false;\n private withAnnotations = false;\n\n constructor(id: string, registry: PluginRegistry, config?: RenderPluginConfig) {\n super(id, registry);\n\n this.withForms = config?.withForms ?? false;\n this.withAnnotations = config?.withAnnotations ?? false;\n }\n\n // No onDocumentLoadingStarted or onDocumentClosed needed!\n\n protected buildCapability(): RenderCapability {\n return {\n // Active document operations\n renderPage: (options: RenderPageOptions) => this.renderPage(options),\n renderPageRect: (options: RenderPageRectOptions) => this.renderPageRect(options),\n\n // Document-scoped operations\n forDocument: (documentId: string) => this.createRenderScope(documentId),\n };\n }\n\n // ─────────────────────────────────────────────────────────\n // Document Scoping\n // ─────────────────────────────────────────────────────────\n\n private createRenderScope(documentId: string): RenderScope {\n return {\n renderPage: (options: RenderPageOptions) => this.renderPage(options, documentId),\n renderPageRect: (options: RenderPageRectOptions) => this.renderPageRect(options, documentId),\n };\n }\n\n // ─────────────────────────────────────────────────────────\n // Core Operations\n // ─────────────────────────────────────────────────────────\n\n private renderPage({ pageIndex, options }: RenderPageOptions, documentId?: string) {\n const id = documentId ?? this.getActiveDocumentId();\n const coreDoc = this.coreState.core.documents[id];\n\n if (!coreDoc?.document) {\n throw new Error(`Document ${id} not loaded`);\n }\n\n const page = coreDoc.document.pages.find((p) => p.index === pageIndex);\n if (!page) {\n throw new Error(`Page ${pageIndex} not found in document ${id}`);\n }\n\n const mergedOptions = {\n ...(options ?? {}),\n withForms: options?.withForms ?? this.withForms,\n withAnnotations: options?.withAnnotations ?? this.withAnnotations,\n };\n\n return this.engine.renderPage(coreDoc.document, page, mergedOptions);\n }\n\n private renderPageRect({ pageIndex, rect, options }: RenderPageRectOptions, documentId?: string) {\n const id = documentId ?? this.getActiveDocumentId();\n const coreDoc = this.coreState.core.documents[id];\n\n if (!coreDoc?.document) {\n throw new Error(`Document ${id} not loaded`);\n }\n\n const page = coreDoc.document.pages.find((p) => p.index === pageIndex);\n if (!page) {\n throw new Error(`Page ${pageIndex} not found in document ${id}`);\n }\n\n const mergedOptions = {\n ...(options ?? {}),\n withForms: options?.withForms ?? this.withForms,\n withAnnotations: options?.withAnnotations ?? this.withAnnotations,\n };\n\n return this.engine.renderPageRect(coreDoc.document, page, rect, mergedOptions);\n }\n\n // ─────────────────────────────────────────────────────────\n // Lifecycle\n // ─────────────────────────────────────────────────────────\n\n async initialize(_config: RenderPluginConfig): Promise<void> {\n this.logger.info('RenderPlugin', 'Initialize', 'Render plugin initialized');\n }\n\n async destroy(): Promise<void> {\n super.destroy();\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, config) => new RenderPlugin(RENDER_PLUGIN_ID, registry, config),\n reducer: () => {},\n initialState: {},\n};\n\nexport * from './render-plugin';\nexport * from './types';\n"],"names":[],"mappings":"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"}
|
|
@@ -1,12 +1,20 @@
|
|
|
1
|
-
import { BasePlugin, PluginRegistry
|
|
1
|
+
import { BasePlugin, PluginRegistry } from '@embedpdf/core';
|
|
2
2
|
import { RenderCapability, RenderPluginConfig } from './types';
|
|
3
|
+
/**
|
|
4
|
+
* Render Plugin - Simplified version that relies on core state for refresh tracking
|
|
5
|
+
*
|
|
6
|
+
* Key insight: Page refresh tracking is in DocumentState.pageRefreshVersions
|
|
7
|
+
* This allows ANY plugin to observe page refreshes, not just the render plugin.
|
|
8
|
+
*/
|
|
3
9
|
export declare class RenderPlugin extends BasePlugin<RenderPluginConfig, RenderCapability> {
|
|
4
10
|
static readonly id: "render";
|
|
5
|
-
private
|
|
6
|
-
|
|
7
|
-
|
|
11
|
+
private withForms;
|
|
12
|
+
private withAnnotations;
|
|
13
|
+
constructor(id: string, registry: PluginRegistry, config?: RenderPluginConfig);
|
|
8
14
|
protected buildCapability(): RenderCapability;
|
|
9
|
-
|
|
15
|
+
private createRenderScope;
|
|
10
16
|
private renderPage;
|
|
11
17
|
private renderPageRect;
|
|
18
|
+
initialize(_config: RenderPluginConfig): Promise<void>;
|
|
19
|
+
destroy(): Promise<void>;
|
|
12
20
|
}
|
package/dist/lib/types.d.ts
CHANGED
|
@@ -1,6 +1,16 @@
|
|
|
1
1
|
import { BasePluginConfig } from '@embedpdf/core';
|
|
2
2
|
import { PdfErrorReason, PdfRenderPageOptions, Rect, Task } from '@embedpdf/models';
|
|
3
3
|
export interface RenderPluginConfig extends BasePluginConfig {
|
|
4
|
+
/**
|
|
5
|
+
* Initialize and draw form widgets during renders.
|
|
6
|
+
* Defaults to `false`.
|
|
7
|
+
*/
|
|
8
|
+
withForms?: boolean;
|
|
9
|
+
/**
|
|
10
|
+
* Whether to render annotations
|
|
11
|
+
* Defaults to `false`.
|
|
12
|
+
*/
|
|
13
|
+
withAnnotations?: boolean;
|
|
4
14
|
}
|
|
5
15
|
export interface RenderPageRectOptions {
|
|
6
16
|
pageIndex: number;
|
|
@@ -11,7 +21,12 @@ export interface RenderPageOptions {
|
|
|
11
21
|
pageIndex: number;
|
|
12
22
|
options: PdfRenderPageOptions;
|
|
13
23
|
}
|
|
24
|
+
export interface RenderScope {
|
|
25
|
+
renderPage(options: RenderPageOptions): Task<Blob, PdfErrorReason>;
|
|
26
|
+
renderPageRect(options: RenderPageRectOptions): Task<Blob, PdfErrorReason>;
|
|
27
|
+
}
|
|
14
28
|
export interface RenderCapability {
|
|
15
|
-
renderPage
|
|
16
|
-
renderPageRect
|
|
29
|
+
renderPage(options: RenderPageOptions): Task<Blob, PdfErrorReason>;
|
|
30
|
+
renderPageRect(options: RenderPageRectOptions): Task<Blob, PdfErrorReason>;
|
|
31
|
+
forDocument(documentId: string): RenderScope;
|
|
17
32
|
}
|
package/dist/preact/adapter.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Fragment } from 'preact';
|
|
2
|
-
import { useEffect, useRef, useState } from 'preact/hooks';
|
|
3
|
-
export { Fragment, useEffect, useRef, useState };
|
|
2
|
+
import { useEffect, useRef, useState, useMemo } from 'preact/hooks';
|
|
3
|
+
export { Fragment, useEffect, useRef, useState, useMemo };
|
|
4
4
|
export type CSSProperties = import('preact').JSX.CSSProperties;
|
|
5
5
|
export type HTMLAttributes<T = any> = import('preact').JSX.HTMLAttributes<T extends EventTarget ? T : never>;
|
package/dist/preact/index.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("preact/jsx-runtime"),r=require("preact"),t=require("preact/hooks"),n=require("@embedpdf/models"),
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("preact/jsx-runtime"),r=require("preact"),t=require("preact/hooks"),n=require("@embedpdf/models"),o=require("@embedpdf/core/preact"),u=require("@embedpdf/plugin-render"),s=()=>o.useCapability(u.RenderPlugin.id);exports.RenderLayer=function({documentId:u,pageIndex:c,scale:d,dpr:i,style:l,...a}){const{provides:p}=s(),g=o.useDocumentState(u),[m,b]=t.useState(null),f=t.useRef(null),R=t.useMemo(()=>g&&g.pageRefreshVersions[c]||0,[g,c]),x=t.useMemo(()=>void 0!==d?d:(null==g?void 0:g.scale)??1,[d,null==g?void 0:g.scale]),y=t.useMemo(()=>void 0!==i?i:window.devicePixelRatio,[i]);return t.useEffect(()=>{if(!p)return;const e=p.forDocument(u).renderPage({pageIndex:c,options:{scaleFactor:x,dpr:y}});return e.wait(e=>{const r=URL.createObjectURL(e);b(r),f.current=r},n.ignore),()=>{f.current?(URL.revokeObjectURL(f.current),f.current=null):e.abort({code:n.PdfErrorCode.Cancelled,message:"canceled render task"})}},[u,c,x,y,p,R]),e.jsx(r.Fragment,{children:m&&e.jsx("img",{src:m,onLoad:()=>{f.current&&(URL.revokeObjectURL(f.current),f.current=null)},...a,style:{width:"100%",height:"100%",...l||{}}})})},exports.useRenderCapability=s,exports.useRenderPlugin=()=>o.usePlugin(u.RenderPlugin.id),Object.keys(u).forEach(e=>{"default"===e||Object.prototype.hasOwnProperty.call(exports,e)||Object.defineProperty(exports,e,{enumerable:!0,get:()=>u[e]})});
|
|
2
2
|
//# sourceMappingURL=index.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","sources":["../../src/shared/hooks/use-render.ts","../../src/shared/components/render-layer.tsx"],"sourcesContent":["import { useCapability, usePlugin } from '@embedpdf/core/@framework';\nimport { RenderPlugin } from '@embedpdf/plugin-render';\n\nexport const useRenderPlugin = () => usePlugin<RenderPlugin>(RenderPlugin.id);\nexport const useRenderCapability = () => useCapability<RenderPlugin>(RenderPlugin.id);\n","import { Fragment, useEffect, useRef, useState } from '@framework';\nimport type { CSSProperties, HTMLAttributes } from '@framework';\n\nimport { ignore, PdfErrorCode } from '@embedpdf/models';\n\nimport { useRenderCapability
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":["../../src/shared/hooks/use-render.ts","../../src/shared/components/render-layer.tsx"],"sourcesContent":["import { useCapability, usePlugin } from '@embedpdf/core/@framework';\nimport { RenderPlugin } from '@embedpdf/plugin-render';\n\nexport const useRenderPlugin = () => usePlugin<RenderPlugin>(RenderPlugin.id);\nexport const useRenderCapability = () => useCapability<RenderPlugin>(RenderPlugin.id);\n","import { Fragment, useEffect, useRef, useState, useMemo } from '@framework';\nimport type { CSSProperties, HTMLAttributes } from '@framework';\n\nimport { ignore, PdfErrorCode, Rotation } from '@embedpdf/models';\n\nimport { useRenderCapability } from '../hooks/use-render';\nimport { useDocumentState } from '@embedpdf/core/@framework';\n\ntype RenderLayerProps = Omit<HTMLAttributes<HTMLImageElement>, 'style'> & {\n /**\n * The ID of the document to render from\n */\n documentId: string;\n /**\n * The page index to render (0-based)\n */\n pageIndex: number;\n /**\n * Optional scale override. If not provided, uses document's current scale.\n */\n scale?: number;\n /**\n * Optional device pixel ratio override. If not provided, uses window.devicePixelRatio.\n */\n dpr?: number;\n /**\n * Additional styles for the image element\n */\n style?: CSSProperties;\n};\n\n/**\n * RenderLayer Component\n *\n * Renders a PDF page with smart prop handling:\n * - If scale/dpr/rotation props are provided, they override document state\n * - If not provided, component uses document's current state values\n * - Automatically re-renders when:\n * 1. Document state changes (scale, rotation)\n * 2. Page is refreshed (via REFRESH_PAGES action in core)\n */\nexport function RenderLayer({\n documentId,\n pageIndex,\n scale: scaleOverride,\n dpr: dprOverride,\n style,\n ...props\n}: RenderLayerProps) {\n const { provides: renderProvides } = useRenderCapability();\n const documentState = useDocumentState(documentId);\n\n const [imageUrl, setImageUrl] = useState<string | null>(null);\n const urlRef = useRef<string | null>(null);\n\n // Get refresh version from core state\n const refreshVersion = useMemo(() => {\n if (!documentState) return 0;\n return documentState.pageRefreshVersions[pageIndex] || 0;\n }, [documentState, pageIndex]);\n\n // Determine actual render options: use overrides if provided, otherwise fall back to document state\n const actualScale = useMemo(() => {\n if (scaleOverride !== undefined) return scaleOverride;\n return documentState?.scale ?? 1;\n }, [scaleOverride, documentState?.scale]);\n\n const actualDpr = useMemo(() => {\n if (dprOverride !== undefined) return dprOverride;\n return window.devicePixelRatio;\n }, [dprOverride]);\n\n useEffect(() => {\n if (!renderProvides) return;\n\n const task = renderProvides.forDocument(documentId).renderPage({\n pageIndex,\n options: {\n scaleFactor: actualScale,\n dpr: actualDpr,\n },\n });\n\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 }, [documentId, pageIndex, actualScale, actualDpr, renderProvides, refreshVersion]);\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"],"names":["useRenderCapability","useCapability","RenderPlugin","id","documentId","pageIndex","scale","scaleOverride","dpr","dprOverride","style","props","provides","renderProvides","documentState","useDocumentState","imageUrl","setImageUrl","useState","urlRef","useRef","refreshVersion","useMemo","pageRefreshVersions","actualScale","actualDpr","window","devicePixelRatio","useEffect","task","forDocument","renderPage","options","scaleFactor","wait","blob","url","URL","createObjectURL","current","ignore","revokeObjectURL","abort","code","PdfErrorCode","Cancelled","message","jsx","Fragment","children","src","onLoad","width","height","usePlugin"],"mappings":"0QAIaA,EAAsB,IAAMC,gBAA4BC,EAAAA,aAAaC,wBCqC3E,UAAqBC,WAC1BA,EAAAC,UACAA,EACAC,MAAOC,EACPC,IAAKC,EAAAC,MACLA,KACGC,IAEH,MAAQC,SAAUC,GAAmBb,IAC/Bc,EAAgBC,EAAAA,iBAAiBX,IAEhCY,EAAUC,GAAeC,EAAAA,SAAwB,MAClDC,EAASC,EAAAA,OAAsB,MAG/BC,EAAiBC,EAAAA,QAAQ,IACxBR,GACEA,EAAcS,oBAAoBlB,IADd,EAE1B,CAACS,EAAeT,IAGbmB,EAAcF,EAAAA,QAAQ,SACJ,IAAlBf,EAAoCA,SACjCO,WAAeR,QAAS,EAC9B,CAACC,EAAe,MAAAO,OAAA,EAAAA,EAAeR,QAE5BmB,EAAYH,EAAAA,QAAQ,SACJ,IAAhBb,EAAkCA,EAC/BiB,OAAOC,iBACb,CAAClB,IAuCJ,OArCAmB,EAAAA,UAAU,KACR,IAAKf,EAAgB,OAErB,MAAMgB,EAAOhB,EAAeiB,YAAY1B,GAAY2B,WAAW,CAC7D1B,YACA2B,QAAS,CACPC,YAAaT,EACbhB,IAAKiB,KAUT,OANAI,EAAKK,KAAMC,IACT,MAAMC,EAAMC,IAAIC,gBAAgBH,GAChClB,EAAYmB,GACZjB,EAAOoB,QAAUH,GAChBI,EAAAA,QAEI,KACDrB,EAAOoB,SACTF,IAAII,gBAAgBtB,EAAOoB,SAC3BpB,EAAOoB,QAAU,MAEjBV,EAAKa,MAAM,CACTC,KAAMC,EAAAA,aAAaC,UACnBC,QAAS,2BAId,CAAC1C,EAAYC,EAAWmB,EAAaC,EAAWZ,EAAgBQ,MAUjE0B,IAACC,EAAAA,UACEC,SAAAjC,GACC+B,EAAAA,IAAC,MAAA,CACCG,IAAKlC,EACLmC,OAZgB,KAClBhC,EAAOoB,UACTF,IAAII,gBAAgBtB,EAAOoB,SAC3BpB,EAAOoB,QAAU,UAUT5B,EACJD,MAAO,CACL0C,MAAO,OACPC,OAAQ,UACJ3C,GAAS,CAAA,MAMzB,wDD1H+B,IAAM4C,YAAwBpD,EAAAA,aAAaC"}
|
package/dist/preact/index.js
CHANGED
|
@@ -1,58 +1,62 @@
|
|
|
1
1
|
import { jsx } from "preact/jsx-runtime";
|
|
2
2
|
import { Fragment } from "preact";
|
|
3
|
-
import { useState, useRef, useEffect } from "preact/hooks";
|
|
3
|
+
import { useState, useRef, useMemo, useEffect } from "preact/hooks";
|
|
4
4
|
import { ignore, PdfErrorCode } from "@embedpdf/models";
|
|
5
|
-
import { usePlugin, useCapability } from "@embedpdf/core/preact";
|
|
5
|
+
import { usePlugin, useCapability, useDocumentState } from "@embedpdf/core/preact";
|
|
6
6
|
import { RenderPlugin } from "@embedpdf/plugin-render";
|
|
7
7
|
export * from "@embedpdf/plugin-render";
|
|
8
8
|
const useRenderPlugin = () => usePlugin(RenderPlugin.id);
|
|
9
9
|
const useRenderCapability = () => useCapability(RenderPlugin.id);
|
|
10
10
|
function RenderLayer({
|
|
11
|
+
documentId,
|
|
11
12
|
pageIndex,
|
|
12
|
-
scale,
|
|
13
|
-
|
|
14
|
-
dpr,
|
|
13
|
+
scale: scaleOverride,
|
|
14
|
+
dpr: dprOverride,
|
|
15
15
|
style,
|
|
16
16
|
...props
|
|
17
17
|
}) {
|
|
18
18
|
const { provides: renderProvides } = useRenderCapability();
|
|
19
|
-
const
|
|
20
|
-
const actualScale = scale ?? scaleFactor ?? 1;
|
|
19
|
+
const documentState = useDocumentState(documentId);
|
|
21
20
|
const [imageUrl, setImageUrl] = useState(null);
|
|
22
21
|
const urlRef = useRef(null);
|
|
23
|
-
const
|
|
22
|
+
const refreshVersion = useMemo(() => {
|
|
23
|
+
if (!documentState) return 0;
|
|
24
|
+
return documentState.pageRefreshVersions[pageIndex] || 0;
|
|
25
|
+
}, [documentState, pageIndex]);
|
|
26
|
+
const actualScale = useMemo(() => {
|
|
27
|
+
if (scaleOverride !== void 0) return scaleOverride;
|
|
28
|
+
return (documentState == null ? void 0 : documentState.scale) ?? 1;
|
|
29
|
+
}, [scaleOverride, documentState == null ? void 0 : documentState.scale]);
|
|
30
|
+
const actualDpr = useMemo(() => {
|
|
31
|
+
if (dprOverride !== void 0) return dprOverride;
|
|
32
|
+
return window.devicePixelRatio;
|
|
33
|
+
}, [dprOverride]);
|
|
24
34
|
useEffect(() => {
|
|
25
|
-
if (!
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
35
|
+
if (!renderProvides) return;
|
|
36
|
+
const task = renderProvides.forDocument(documentId).renderPage({
|
|
37
|
+
pageIndex,
|
|
38
|
+
options: {
|
|
39
|
+
scaleFactor: actualScale,
|
|
40
|
+
dpr: actualDpr
|
|
29
41
|
}
|
|
30
42
|
});
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
task.abort({
|
|
49
|
-
code: PdfErrorCode.Cancelled,
|
|
50
|
-
message: "canceled render task"
|
|
51
|
-
});
|
|
52
|
-
}
|
|
53
|
-
};
|
|
54
|
-
}
|
|
55
|
-
}, [pageIndex, actualScale, dpr, renderProvides, refreshTick]);
|
|
43
|
+
task.wait((blob) => {
|
|
44
|
+
const url = URL.createObjectURL(blob);
|
|
45
|
+
setImageUrl(url);
|
|
46
|
+
urlRef.current = url;
|
|
47
|
+
}, ignore);
|
|
48
|
+
return () => {
|
|
49
|
+
if (urlRef.current) {
|
|
50
|
+
URL.revokeObjectURL(urlRef.current);
|
|
51
|
+
urlRef.current = null;
|
|
52
|
+
} else {
|
|
53
|
+
task.abort({
|
|
54
|
+
code: PdfErrorCode.Cancelled,
|
|
55
|
+
message: "canceled render task"
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
}, [documentId, pageIndex, actualScale, actualDpr, renderProvides, refreshVersion]);
|
|
56
60
|
const handleImageLoad = () => {
|
|
57
61
|
if (urlRef.current) {
|
|
58
62
|
URL.revokeObjectURL(urlRef.current);
|
package/dist/preact/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../src/shared/hooks/use-render.ts","../../src/shared/components/render-layer.tsx"],"sourcesContent":["import { useCapability, usePlugin } from '@embedpdf/core/@framework';\nimport { RenderPlugin } from '@embedpdf/plugin-render';\n\nexport const useRenderPlugin = () => usePlugin<RenderPlugin>(RenderPlugin.id);\nexport const useRenderCapability = () => useCapability<RenderPlugin>(RenderPlugin.id);\n","import { Fragment, useEffect, useRef, useState } from '@framework';\nimport type { CSSProperties, HTMLAttributes } from '@framework';\n\nimport { ignore, PdfErrorCode } from '@embedpdf/models';\n\nimport { useRenderCapability
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../src/shared/hooks/use-render.ts","../../src/shared/components/render-layer.tsx"],"sourcesContent":["import { useCapability, usePlugin } from '@embedpdf/core/@framework';\nimport { RenderPlugin } from '@embedpdf/plugin-render';\n\nexport const useRenderPlugin = () => usePlugin<RenderPlugin>(RenderPlugin.id);\nexport const useRenderCapability = () => useCapability<RenderPlugin>(RenderPlugin.id);\n","import { Fragment, useEffect, useRef, useState, useMemo } from '@framework';\nimport type { CSSProperties, HTMLAttributes } from '@framework';\n\nimport { ignore, PdfErrorCode, Rotation } from '@embedpdf/models';\n\nimport { useRenderCapability } from '../hooks/use-render';\nimport { useDocumentState } from '@embedpdf/core/@framework';\n\ntype RenderLayerProps = Omit<HTMLAttributes<HTMLImageElement>, 'style'> & {\n /**\n * The ID of the document to render from\n */\n documentId: string;\n /**\n * The page index to render (0-based)\n */\n pageIndex: number;\n /**\n * Optional scale override. If not provided, uses document's current scale.\n */\n scale?: number;\n /**\n * Optional device pixel ratio override. If not provided, uses window.devicePixelRatio.\n */\n dpr?: number;\n /**\n * Additional styles for the image element\n */\n style?: CSSProperties;\n};\n\n/**\n * RenderLayer Component\n *\n * Renders a PDF page with smart prop handling:\n * - If scale/dpr/rotation props are provided, they override document state\n * - If not provided, component uses document's current state values\n * - Automatically re-renders when:\n * 1. Document state changes (scale, rotation)\n * 2. Page is refreshed (via REFRESH_PAGES action in core)\n */\nexport function RenderLayer({\n documentId,\n pageIndex,\n scale: scaleOverride,\n dpr: dprOverride,\n style,\n ...props\n}: RenderLayerProps) {\n const { provides: renderProvides } = useRenderCapability();\n const documentState = useDocumentState(documentId);\n\n const [imageUrl, setImageUrl] = useState<string | null>(null);\n const urlRef = useRef<string | null>(null);\n\n // Get refresh version from core state\n const refreshVersion = useMemo(() => {\n if (!documentState) return 0;\n return documentState.pageRefreshVersions[pageIndex] || 0;\n }, [documentState, pageIndex]);\n\n // Determine actual render options: use overrides if provided, otherwise fall back to document state\n const actualScale = useMemo(() => {\n if (scaleOverride !== undefined) return scaleOverride;\n return documentState?.scale ?? 1;\n }, [scaleOverride, documentState?.scale]);\n\n const actualDpr = useMemo(() => {\n if (dprOverride !== undefined) return dprOverride;\n return window.devicePixelRatio;\n }, [dprOverride]);\n\n useEffect(() => {\n if (!renderProvides) return;\n\n const task = renderProvides.forDocument(documentId).renderPage({\n pageIndex,\n options: {\n scaleFactor: actualScale,\n dpr: actualDpr,\n },\n });\n\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 }, [documentId, pageIndex, actualScale, actualDpr, renderProvides, refreshVersion]);\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"],"names":[],"mappings":";;;;;;;AAGO,MAAM,kBAAkB,MAAM,UAAwB,aAAa,EAAE;AACrE,MAAM,sBAAsB,MAAM,cAA4B,aAAa,EAAE;ACqC7E,SAAS,YAAY;AAAA,EAC1B;AAAA,EACA;AAAA,EACA,OAAO;AAAA,EACP,KAAK;AAAA,EACL;AAAA,EACA,GAAG;AACL,GAAqB;AACnB,QAAM,EAAE,UAAU,eAAA,IAAmB,oBAAA;AACrC,QAAM,gBAAgB,iBAAiB,UAAU;AAEjD,QAAM,CAAC,UAAU,WAAW,IAAI,SAAwB,IAAI;AAC5D,QAAM,SAAS,OAAsB,IAAI;AAGzC,QAAM,iBAAiB,QAAQ,MAAM;AACnC,QAAI,CAAC,cAAe,QAAO;AAC3B,WAAO,cAAc,oBAAoB,SAAS,KAAK;AAAA,EACzD,GAAG,CAAC,eAAe,SAAS,CAAC;AAG7B,QAAM,cAAc,QAAQ,MAAM;AAChC,QAAI,kBAAkB,OAAW,QAAO;AACxC,YAAO,+CAAe,UAAS;AAAA,EACjC,GAAG,CAAC,eAAe,+CAAe,KAAK,CAAC;AAExC,QAAM,YAAY,QAAQ,MAAM;AAC9B,QAAI,gBAAgB,OAAW,QAAO;AACtC,WAAO,OAAO;AAAA,EAChB,GAAG,CAAC,WAAW,CAAC;AAEhB,YAAU,MAAM;AACd,QAAI,CAAC,eAAgB;AAErB,UAAM,OAAO,eAAe,YAAY,UAAU,EAAE,WAAW;AAAA,MAC7D;AAAA,MACA,SAAS;AAAA,QACP,aAAa;AAAA,QACb,KAAK;AAAA,MAAA;AAAA,IACP,CACD;AAED,SAAK,KAAK,CAAC,SAAS;AAClB,YAAM,MAAM,IAAI,gBAAgB,IAAI;AACpC,kBAAY,GAAG;AACf,aAAO,UAAU;AAAA,IACnB,GAAG,MAAM;AAET,WAAO,MAAM;AACX,UAAI,OAAO,SAAS;AAClB,YAAI,gBAAgB,OAAO,OAAO;AAClC,eAAO,UAAU;AAAA,MACnB,OAAO;AACL,aAAK,MAAM;AAAA,UACT,MAAM,aAAa;AAAA,UACnB,SAAS;AAAA,QAAA,CACV;AAAA,MACH;AAAA,IACF;AAAA,EACF,GAAG,CAAC,YAAY,WAAW,aAAa,WAAW,gBAAgB,cAAc,CAAC;AAElF,QAAM,kBAAkB,MAAM;AAC5B,QAAI,OAAO,SAAS;AAClB,UAAI,gBAAgB,OAAO,OAAO;AAClC,aAAO,UAAU;AAAA,IACnB;AAAA,EACF;AAEA,SACE,oBAAC,YACE,UAAA,YACC;AAAA,IAAC;AAAA,IAAA;AAAA,MACC,KAAK;AAAA,MACL,QAAQ;AAAA,MACP,GAAG;AAAA,MACJ,OAAO;AAAA,QACL,OAAO;AAAA,QACP,QAAQ;AAAA,QACR,GAAI,SAAS,CAAA;AAAA,MAAC;AAAA,IAChB;AAAA,EAAA,GAGN;AAEJ;"}
|
package/dist/react/adapter.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { Fragment, useEffect, useRef, useState } from 'react';
|
|
1
|
+
export { Fragment, useEffect, useRef, useState, useMemo } from 'react';
|
|
2
2
|
export type { CSSProperties, HTMLAttributes } from 'react';
|
package/dist/react/index.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),r=require("react"),t=require("@embedpdf/models"),n=require("@embedpdf/core/react"),
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),r=require("react"),t=require("@embedpdf/models"),n=require("@embedpdf/core/react"),o=require("@embedpdf/plugin-render"),u=()=>n.useCapability(o.RenderPlugin.id);exports.RenderLayer=function({documentId:o,pageIndex:s,scale:c,dpr:d,style:i,...l}){const{provides:a}=u(),p=n.useDocumentState(o),[g,m]=r.useState(null),b=r.useRef(null),f=r.useMemo(()=>p&&p.pageRefreshVersions[s]||0,[p,s]),R=r.useMemo(()=>void 0!==c?c:(null==p?void 0:p.scale)??1,[c,null==p?void 0:p.scale]),x=r.useMemo(()=>void 0!==d?d:window.devicePixelRatio,[d]);return r.useEffect(()=>{if(!a)return;const e=a.forDocument(o).renderPage({pageIndex:s,options:{scaleFactor:R,dpr:x}});return e.wait(e=>{const r=URL.createObjectURL(e);m(r),b.current=r},t.ignore),()=>{b.current?(URL.revokeObjectURL(b.current),b.current=null):e.abort({code:t.PdfErrorCode.Cancelled,message:"canceled render task"})}},[o,s,R,x,a,f]),e.jsx(r.Fragment,{children:g&&e.jsx("img",{src:g,onLoad:()=>{b.current&&(URL.revokeObjectURL(b.current),b.current=null)},...l,style:{width:"100%",height:"100%",...i||{}}})})},exports.useRenderCapability=u,exports.useRenderPlugin=()=>n.usePlugin(o.RenderPlugin.id),Object.keys(o).forEach(e=>{"default"===e||Object.prototype.hasOwnProperty.call(exports,e)||Object.defineProperty(exports,e,{enumerable:!0,get:()=>o[e]})});
|
|
2
2
|
//# sourceMappingURL=index.cjs.map
|
package/dist/react/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","sources":["../../src/shared/hooks/use-render.ts","../../src/shared/components/render-layer.tsx"],"sourcesContent":["import { useCapability, usePlugin } from '@embedpdf/core/@framework';\nimport { RenderPlugin } from '@embedpdf/plugin-render';\n\nexport const useRenderPlugin = () => usePlugin<RenderPlugin>(RenderPlugin.id);\nexport const useRenderCapability = () => useCapability<RenderPlugin>(RenderPlugin.id);\n","import { Fragment, useEffect, useRef, useState } from '@framework';\nimport type { CSSProperties, HTMLAttributes } from '@framework';\n\nimport { ignore, PdfErrorCode } from '@embedpdf/models';\n\nimport { useRenderCapability
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":["../../src/shared/hooks/use-render.ts","../../src/shared/components/render-layer.tsx"],"sourcesContent":["import { useCapability, usePlugin } from '@embedpdf/core/@framework';\nimport { RenderPlugin } from '@embedpdf/plugin-render';\n\nexport const useRenderPlugin = () => usePlugin<RenderPlugin>(RenderPlugin.id);\nexport const useRenderCapability = () => useCapability<RenderPlugin>(RenderPlugin.id);\n","import { Fragment, useEffect, useRef, useState, useMemo } from '@framework';\nimport type { CSSProperties, HTMLAttributes } from '@framework';\n\nimport { ignore, PdfErrorCode, Rotation } from '@embedpdf/models';\n\nimport { useRenderCapability } from '../hooks/use-render';\nimport { useDocumentState } from '@embedpdf/core/@framework';\n\ntype RenderLayerProps = Omit<HTMLAttributes<HTMLImageElement>, 'style'> & {\n /**\n * The ID of the document to render from\n */\n documentId: string;\n /**\n * The page index to render (0-based)\n */\n pageIndex: number;\n /**\n * Optional scale override. If not provided, uses document's current scale.\n */\n scale?: number;\n /**\n * Optional device pixel ratio override. If not provided, uses window.devicePixelRatio.\n */\n dpr?: number;\n /**\n * Additional styles for the image element\n */\n style?: CSSProperties;\n};\n\n/**\n * RenderLayer Component\n *\n * Renders a PDF page with smart prop handling:\n * - If scale/dpr/rotation props are provided, they override document state\n * - If not provided, component uses document's current state values\n * - Automatically re-renders when:\n * 1. Document state changes (scale, rotation)\n * 2. Page is refreshed (via REFRESH_PAGES action in core)\n */\nexport function RenderLayer({\n documentId,\n pageIndex,\n scale: scaleOverride,\n dpr: dprOverride,\n style,\n ...props\n}: RenderLayerProps) {\n const { provides: renderProvides } = useRenderCapability();\n const documentState = useDocumentState(documentId);\n\n const [imageUrl, setImageUrl] = useState<string | null>(null);\n const urlRef = useRef<string | null>(null);\n\n // Get refresh version from core state\n const refreshVersion = useMemo(() => {\n if (!documentState) return 0;\n return documentState.pageRefreshVersions[pageIndex] || 0;\n }, [documentState, pageIndex]);\n\n // Determine actual render options: use overrides if provided, otherwise fall back to document state\n const actualScale = useMemo(() => {\n if (scaleOverride !== undefined) return scaleOverride;\n return documentState?.scale ?? 1;\n }, [scaleOverride, documentState?.scale]);\n\n const actualDpr = useMemo(() => {\n if (dprOverride !== undefined) return dprOverride;\n return window.devicePixelRatio;\n }, [dprOverride]);\n\n useEffect(() => {\n if (!renderProvides) return;\n\n const task = renderProvides.forDocument(documentId).renderPage({\n pageIndex,\n options: {\n scaleFactor: actualScale,\n dpr: actualDpr,\n },\n });\n\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 }, [documentId, pageIndex, actualScale, actualDpr, renderProvides, refreshVersion]);\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"],"names":["useRenderCapability","useCapability","RenderPlugin","id","documentId","pageIndex","scale","scaleOverride","dpr","dprOverride","style","props","provides","renderProvides","documentState","useDocumentState","imageUrl","setImageUrl","useState","urlRef","useRef","refreshVersion","useMemo","pageRefreshVersions","actualScale","actualDpr","window","devicePixelRatio","useEffect","task","forDocument","renderPage","options","scaleFactor","wait","blob","url","URL","createObjectURL","current","ignore","revokeObjectURL","abort","code","PdfErrorCode","Cancelled","message","jsx","Fragment","children","src","onLoad","width","height","usePlugin"],"mappings":"6OAIaA,EAAsB,IAAMC,gBAA4BC,EAAAA,aAAaC,wBCqC3E,UAAqBC,WAC1BA,EAAAC,UACAA,EACAC,MAAOC,EACPC,IAAKC,EAAAC,MACLA,KACGC,IAEH,MAAQC,SAAUC,GAAmBb,IAC/Bc,EAAgBC,EAAAA,iBAAiBX,IAEhCY,EAAUC,GAAeC,EAAAA,SAAwB,MAClDC,EAASC,EAAAA,OAAsB,MAG/BC,EAAiBC,EAAAA,QAAQ,IACxBR,GACEA,EAAcS,oBAAoBlB,IADd,EAE1B,CAACS,EAAeT,IAGbmB,EAAcF,EAAAA,QAAQ,SACJ,IAAlBf,EAAoCA,SACjCO,WAAeR,QAAS,EAC9B,CAACC,EAAe,MAAAO,OAAA,EAAAA,EAAeR,QAE5BmB,EAAYH,EAAAA,QAAQ,SACJ,IAAhBb,EAAkCA,EAC/BiB,OAAOC,iBACb,CAAClB,IAuCJ,OArCAmB,EAAAA,UAAU,KACR,IAAKf,EAAgB,OAErB,MAAMgB,EAAOhB,EAAeiB,YAAY1B,GAAY2B,WAAW,CAC7D1B,YACA2B,QAAS,CACPC,YAAaT,EACbhB,IAAKiB,KAUT,OANAI,EAAKK,KAAMC,IACT,MAAMC,EAAMC,IAAIC,gBAAgBH,GAChClB,EAAYmB,GACZjB,EAAOoB,QAAUH,GAChBI,EAAAA,QAEI,KACDrB,EAAOoB,SACTF,IAAII,gBAAgBtB,EAAOoB,SAC3BpB,EAAOoB,QAAU,MAEjBV,EAAKa,MAAM,CACTC,KAAMC,EAAAA,aAAaC,UACnBC,QAAS,2BAId,CAAC1C,EAAYC,EAAWmB,EAAaC,EAAWZ,EAAgBQ,MAUjE0B,IAACC,EAAAA,UACEC,SAAAjC,GACC+B,EAAAA,IAAC,MAAA,CACCG,IAAKlC,EACLmC,OAZgB,KAClBhC,EAAOoB,UACTF,IAAII,gBAAgBtB,EAAOoB,SAC3BpB,EAAOoB,QAAU,UAUT5B,EACJD,MAAO,CACL0C,MAAO,OACPC,OAAQ,UACJ3C,GAAS,CAAA,MAMzB,wDD1H+B,IAAM4C,YAAwBpD,EAAAA,aAAaC"}
|