@embedpdf/plugin-render 1.0.16 → 1.0.18

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 CHANGED
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("@embedpdf/core"),n=require("@embedpdf/models"),t=class extends e.BasePlugin{constructor(e,n,t){super(e,n),this.engine=t}async initialize(e){}buildCapability(){return{renderPage:this.renderPage.bind(this),renderPageRect:this.renderPageRect.bind(this)}}renderPage({pageIndex:e,scaleFactor:t=1,dpr:r=1,rotation:o=n.Rotation.Degree0,options:i={withAnnotations:!1},imageType:d="image/webp"}){const a=this.coreState.core;if(!a.document)throw new Error("document does not open");const s=a.document.pages.find((n=>n.index===e));if(!s)throw new Error("page does not exist");return this.engine.renderPage(a.document,s,t,o,r,i,d)}renderPageRect({pageIndex:e,scaleFactor:t=1,dpr:r=1,rect:o,rotation:i=n.Rotation.Degree0,options:d={withAnnotations:!1},imageType:a="image/webp"}){const s=this.coreState.core;if(!s.document)throw new Error("document does not open");const c=s.document.pages.find((n=>n.index===e));if(!c)throw new Error("page does not exist");return this.engine.renderPageRect(s.document,c,t,i,r,o,d,a)}};t.id="render";let r=t;const o="render",i={manifest:{id:o,name:"Render Plugin",version:"1.0.0",provides:["render"],requires:[],optional:[],defaultConfig:{enabled:!0}},create:(e,n)=>new r(o,e,n),reducer:()=>{},initialState:{}};exports.RenderPlugin=r,exports.RenderPluginPackage=i;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("@embedpdf/core"),t=require("@embedpdf/models"),r=class extends e.BasePlugin{constructor(t,r,n){super(t,r),this.refreshPages$=e.createEmitter(),this.engine=n,this.coreStore.onAction(e.REFRESH_PAGES,(e=>{this.refreshPages$.emit(e.payload)}))}async initialize(e){}buildCapability(){return{renderPage:this.renderPage.bind(this),renderPageRect:this.renderPageRect.bind(this)}}onRefreshPages(e){return this.refreshPages$.on(e)}renderPage({pageIndex:e,scaleFactor:r=1,dpr:n=1,rotation:o=t.Rotation.Degree0,options:i={withAnnotations:!1},imageType:s="image/webp"}){const a=this.coreState.core;if(!a.document)throw new Error("document does not open");const d=a.document.pages.find((t=>t.index===e));if(!d)throw new Error("page does not exist");return this.engine.renderPage(a.document,d,r,o,n,i,s)}renderPageRect({pageIndex:e,scaleFactor:r=1,dpr:n=1,rect:o,rotation:i=t.Rotation.Degree0,options:s={withAnnotations:!1},imageType:a="image/webp"}){const d=this.coreState.core;if(!d.document)throw new Error("document does not open");const c=d.document.pages.find((t=>t.index===e));if(!c)throw new Error("page does not exist");return this.engine.renderPageRect(d.document,c,r,i,n,o,s,a)}};r.id="render";let n=r;const o="render",i={manifest:{id:o,name:"Render Plugin",version:"1.0.0",provides:["render"],requires:[],optional:[],defaultConfig:{enabled:!0}},create:(e,t)=>new n(o,e,t),reducer:()=>{},initialState:{}};exports.RenderPlugin=n,exports.RenderPluginPackage=i;
2
2
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
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} 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 imageType = 'image/webp',\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(\n coreState.document,\n page,\n scaleFactor,\n rotation,\n dpr,\n options,\n imageType,\n );\n }\n\n private renderPageRect({\n pageIndex,\n scaleFactor = 1,\n dpr = 1,\n rect,\n rotation = Rotation.Degree0,\n options = { withAnnotations: false },\n imageType = 'image/webp',\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 imageType,\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"],"names":["_RenderPlugin","BasePlugin","constructor","id","registry","engine","super","this","initialize","_config","buildCapability","renderPage","bind","renderPageRect","pageIndex","scaleFactor","dpr","rotation","Rotation","Degree0","options","withAnnotations","imageType","coreState","core","document","Error","page","pages","find","index","rect","RenderPlugin","RENDER_PLUGIN_ID","RenderPluginPackage","manifest","name","version","provides","requires","optional","defaultConfig","enabled","create","reducer","initialState"],"mappings":"gJASaA,EAAN,cAA2BC,EAAAA,WAIhC,WAAAC,CAAYC,EAAYC,EAA0BC,GAChDC,MAAMH,EAAIC,GACVG,KAAKF,OAASA,CAAA,CAGhB,gBAAMG,CAAWC,GAA4C,CAEnD,eAAAC,GACD,MAAA,CACLC,WAAYJ,KAAKI,WAAWC,KAAKL,MACjCM,eAAgBN,KAAKM,eAAeD,KAAKL,MAC3C,CAGM,UAAAI,EAAWG,UACjBA,EAAAC,YACAA,EAAc,EAAAC,IACdA,EAAM,EAAAC,SACNA,EAAWC,EAASA,SAAAC,QAAAC,QACpBA,EAAU,CAAEC,iBAAiB,GAAMC,UACnCA,EAAY,eAEN,MAAAC,EAAYhB,KAAKgB,UAAUC,KAE7B,IAACD,EAAUE,SACP,MAAA,IAAIC,MAAM,0BAGZ,MAAAC,EAAOJ,EAAUE,SAASG,MAAMC,MAAMF,GAASA,EAAKG,QAAUhB,IACpE,IAAKa,EACG,MAAA,IAAID,MAAM,uBAGlB,OAAOnB,KAAKF,OAAOM,WACjBY,EAAUE,SACVE,EACAZ,EACAE,EACAD,EACAI,EACAE,EACF,CAGM,cAAAT,EAAeC,UACrBA,EAAAC,YACAA,EAAc,EAAAC,IACdA,EAAM,EAAAe,KACNA,EAAAd,SACAA,EAAWC,EAASA,SAAAC,QAAAC,QACpBA,EAAU,CAAEC,iBAAiB,GAAMC,UACnCA,EAAY,eAEN,MAAAC,EAAYhB,KAAKgB,UAAUC,KAE7B,IAACD,EAAUE,SACP,MAAA,IAAIC,MAAM,0BAGZ,MAAAC,EAAOJ,EAAUE,SAASG,MAAMC,MAAMF,GAASA,EAAKG,QAAUhB,IACpE,IAAKa,EACG,MAAA,IAAID,MAAM,uBAGlB,OAAOnB,KAAKF,OAAOQ,eACjBU,EAAUE,SACVE,EACAZ,EACAE,EACAD,EACAe,EACAX,EACAE,EACF,GA5EFtB,EAAgBG,GAAK,SADhB,IAAM6B,EAANhC,ECNA,MAAMiC,EAAmB,SCEnBC,EAAuE,CAClFC,SDD0D,CAC1DhC,GAAI8B,EACJG,KAAM,gBACNC,QAAS,QACTC,SAAU,CAAC,UACXC,SAAU,GACVC,SAAU,GACVC,cAAe,CACbC,SAAS,ICNXC,OAAQ,CAACvC,EAAUC,IAAW,IAAI2B,EAAaC,EAAkB7B,EAAUC,GAC3EuC,QAAS,OACTC,aAAc,CAAA"}
1
+ {"version":3,"file":"index.cjs","sources":["../src/lib/render-plugin.ts","../src/lib/manifest.ts","../src/lib/index.ts"],"sourcesContent":["import {\n BasePlugin,\n createEmitter,\n PluginRegistry,\n REFRESH_PAGES,\n Unsubscribe,\n} 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 private readonly refreshPages$ = createEmitter<number[]>();\n\n constructor(id: string, registry: PluginRegistry, engine: PdfEngine) {\n super(id, registry);\n this.engine = engine;\n\n this.coreStore.onAction(REFRESH_PAGES, (action) => {\n this.refreshPages$.emit(action.payload);\n });\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 public onRefreshPages(fn: (pages: number[]) => void): Unsubscribe {\n return this.refreshPages$.on(fn);\n }\n\n private renderPage({\n pageIndex,\n scaleFactor = 1,\n dpr = 1,\n rotation = Rotation.Degree0,\n options = { withAnnotations: false },\n imageType = 'image/webp',\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(\n coreState.document,\n page,\n scaleFactor,\n rotation,\n dpr,\n options,\n imageType,\n );\n }\n\n private renderPageRect({\n pageIndex,\n scaleFactor = 1,\n dpr = 1,\n rect,\n rotation = Rotation.Degree0,\n options = { withAnnotations: false },\n imageType = 'image/webp',\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 imageType,\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"],"names":["_RenderPlugin","BasePlugin","constructor","id","registry","engine","super","this","refreshPages$","createEmitter","coreStore","onAction","REFRESH_PAGES","action","emit","payload","initialize","_config","buildCapability","renderPage","bind","renderPageRect","onRefreshPages","fn","on","pageIndex","scaleFactor","dpr","rotation","Rotation","Degree0","options","withAnnotations","imageType","coreState","core","document","Error","page","pages","find","index","rect","RenderPlugin","RENDER_PLUGIN_ID","RenderPluginPackage","manifest","name","version","provides","requires","optional","defaultConfig","enabled","create","reducer","initialState"],"mappings":"gJAeaA,EAAN,cAA2BC,EAAAA,WAMhC,WAAAC,CAAYC,EAAYC,EAA0BC,GAChDC,MAAMH,EAAIC,GAHKG,KAAAC,cAAgBC,kBAI/BF,KAAKF,OAASA,EAEdE,KAAKG,UAAUC,SAASC,EAAeA,eAACC,IACjCN,KAAAC,cAAcM,KAAKD,EAAOE,QAAO,GACvC,CAGH,gBAAMC,CAAWC,GAA4C,CAEnD,eAAAC,GACD,MAAA,CACLC,WAAYZ,KAAKY,WAAWC,KAAKb,MACjCc,eAAgBd,KAAKc,eAAeD,KAAKb,MAC3C,CAGK,cAAAe,CAAeC,GACb,OAAAhB,KAAKC,cAAcgB,GAAGD,EAAE,CAGzB,UAAAJ,EAAWM,UACjBA,EAAAC,YACAA,EAAc,EAAAC,IACdA,EAAM,EAAAC,SACNA,EAAWC,EAASA,SAAAC,QAAAC,QACpBA,EAAU,CAAEC,iBAAiB,GAAMC,UACnCA,EAAY,eAEN,MAAAC,EAAY3B,KAAK2B,UAAUC,KAE7B,IAACD,EAAUE,SACP,MAAA,IAAIC,MAAM,0BAGZ,MAAAC,EAAOJ,EAAUE,SAASG,MAAMC,MAAMF,GAASA,EAAKG,QAAUhB,IACpE,IAAKa,EACG,MAAA,IAAID,MAAM,uBAGlB,OAAO9B,KAAKF,OAAOc,WACjBe,EAAUE,SACVE,EACAZ,EACAE,EACAD,EACAI,EACAE,EACF,CAGM,cAAAZ,EAAeI,UACrBA,EAAAC,YACAA,EAAc,EAAAC,IACdA,EAAM,EAAAe,KACNA,EAAAd,SACAA,EAAWC,EAASA,SAAAC,QAAAC,QACpBA,EAAU,CAAEC,iBAAiB,GAAMC,UACnCA,EAAY,eAEN,MAAAC,EAAY3B,KAAK2B,UAAUC,KAE7B,IAACD,EAAUE,SACP,MAAA,IAAIC,MAAM,0BAGZ,MAAAC,EAAOJ,EAAUE,SAASG,MAAMC,MAAMF,GAASA,EAAKG,QAAUhB,IACpE,IAAKa,EACG,MAAA,IAAID,MAAM,uBAGlB,OAAO9B,KAAKF,OAAOgB,eACjBa,EAAUE,SACVE,EACAZ,EACAE,EACAD,EACAe,EACAX,EACAE,EACF,GAtFFjC,EAAgBG,GAAK,SADhB,IAAMwC,EAAN3C,ECZA,MAAM4C,EAAmB,SCEnBC,EAAuE,CAClFC,SDD0D,CAC1D3C,GAAIyC,EACJG,KAAM,gBACNC,QAAS,QACTC,SAAU,CAAC,UACXC,SAAU,GACVC,SAAU,GACVC,cAAe,CACbC,SAAS,ICNXC,OAAQ,CAAClD,EAAUC,IAAW,IAAIsC,EAAaC,EAAkBxC,EAAUC,GAC3EkD,QAAS,OACTC,aAAc,CAAA"}
package/dist/index.js CHANGED
@@ -1,9 +1,13 @@
1
- import { BasePlugin } from "@embedpdf/core";
1
+ import { BasePlugin, createEmitter, REFRESH_PAGES } from "@embedpdf/core";
2
2
  import { Rotation } from "@embedpdf/models";
3
3
  const _RenderPlugin = class _RenderPlugin extends BasePlugin {
4
4
  constructor(id, registry, engine) {
5
5
  super(id, registry);
6
+ this.refreshPages$ = createEmitter();
6
7
  this.engine = engine;
8
+ this.coreStore.onAction(REFRESH_PAGES, (action) => {
9
+ this.refreshPages$.emit(action.payload);
10
+ });
7
11
  }
8
12
  async initialize(_config) {
9
13
  }
@@ -13,6 +17,9 @@ const _RenderPlugin = class _RenderPlugin extends BasePlugin {
13
17
  renderPageRect: this.renderPageRect.bind(this)
14
18
  };
15
19
  }
20
+ onRefreshPages(fn) {
21
+ return this.refreshPages$.on(fn);
22
+ }
16
23
  renderPage({
17
24
  pageIndex,
18
25
  scaleFactor = 1,
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 { 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 imageType = 'image/webp',\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(\n coreState.document,\n page,\n scaleFactor,\n rotation,\n dpr,\n options,\n imageType,\n );\n }\n\n private renderPageRect({\n pageIndex,\n scaleFactor = 1,\n dpr = 1,\n rect,\n rotation = Rotation.Degree0,\n options = { withAnnotations: false },\n imageType = 'image/webp',\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 imageType,\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"],"names":["page"],"mappings":";;AASO,MAAM,gBAAN,MAAM,sBAAqB,WAAiD;AAAA,EAIjF,YAAY,IAAY,UAA0B,QAAmB;AACnE,UAAM,IAAI,QAAQ;AAClB,SAAK,SAAS;AAAA,EAAA;AAAA,EAGhB,MAAM,WAAW,SAA4C;AAAA,EAAA;AAAA,EAEnD,kBAAoC;AACrC,WAAA;AAAA,MACL,YAAY,KAAK,WAAW,KAAK,IAAI;AAAA,MACrC,gBAAgB,KAAK,eAAe,KAAK,IAAI;AAAA,IAC/C;AAAA,EAAA;AAAA,EAGM,WAAW;AAAA,IACjB;AAAA,IACA,cAAc;AAAA,IACd,MAAM;AAAA,IACN,WAAW,SAAS;AAAA,IACpB,UAAU,EAAE,iBAAiB,MAAM;AAAA,IACnC,YAAY;AAAA,EAAA,GACQ;AACd,UAAA,YAAY,KAAK,UAAU;AAE7B,QAAA,CAAC,UAAU,UAAU;AACjB,YAAA,IAAI,MAAM,wBAAwB;AAAA,IAAA;AAGpC,UAAA,OAAO,UAAU,SAAS,MAAM,KAAK,CAACA,UAASA,MAAK,UAAU,SAAS;AAC7E,QAAI,CAAC,MAAM;AACH,YAAA,IAAI,MAAM,qBAAqB;AAAA,IAAA;AAGvC,WAAO,KAAK,OAAO;AAAA,MACjB,UAAU;AAAA,MACV;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACF;AAAA,EAAA;AAAA,EAGM,eAAe;AAAA,IACrB;AAAA,IACA,cAAc;AAAA,IACd,MAAM;AAAA,IACN;AAAA,IACA,WAAW,SAAS;AAAA,IACpB,UAAU,EAAE,iBAAiB,MAAM;AAAA,IACnC,YAAY;AAAA,EAAA,GACY;AAClB,UAAA,YAAY,KAAK,UAAU;AAE7B,QAAA,CAAC,UAAU,UAAU;AACjB,YAAA,IAAI,MAAM,wBAAwB;AAAA,IAAA;AAGpC,UAAA,OAAO,UAAU,SAAS,MAAM,KAAK,CAACA,UAASA,MAAK,UAAU,SAAS;AAC7E,QAAI,CAAC,MAAM;AACH,YAAA,IAAI,MAAM,qBAAqB;AAAA,IAAA;AAGvC,WAAO,KAAK,OAAO;AAAA,MACjB,UAAU;AAAA,MACV;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACF;AAAA,EAAA;AAEJ;AA9EE,cAAgB,KAAK;AADhB,IAAM,eAAN;ACNA,MAAM,mBAAmB;AAEzB,MAAM,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,EAAA;AAEb;ACVO,MAAM,sBAAuE;AAAA,EAClF;AAAA,EACA,QAAQ,CAAC,UAAU,WAAW,IAAI,aAAa,kBAAkB,UAAU,MAAM;AAAA,EACjF,SAAS,MAAM;AAAA,EAAC;AAAA,EAChB,cAAc,CAAA;AAChB;"}
1
+ {"version":3,"file":"index.js","sources":["../src/lib/render-plugin.ts","../src/lib/manifest.ts","../src/lib/index.ts"],"sourcesContent":["import {\n BasePlugin,\n createEmitter,\n PluginRegistry,\n REFRESH_PAGES,\n Unsubscribe,\n} 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 private readonly refreshPages$ = createEmitter<number[]>();\n\n constructor(id: string, registry: PluginRegistry, engine: PdfEngine) {\n super(id, registry);\n this.engine = engine;\n\n this.coreStore.onAction(REFRESH_PAGES, (action) => {\n this.refreshPages$.emit(action.payload);\n });\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 public onRefreshPages(fn: (pages: number[]) => void): Unsubscribe {\n return this.refreshPages$.on(fn);\n }\n\n private renderPage({\n pageIndex,\n scaleFactor = 1,\n dpr = 1,\n rotation = Rotation.Degree0,\n options = { withAnnotations: false },\n imageType = 'image/webp',\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(\n coreState.document,\n page,\n scaleFactor,\n rotation,\n dpr,\n options,\n imageType,\n );\n }\n\n private renderPageRect({\n pageIndex,\n scaleFactor = 1,\n dpr = 1,\n rect,\n rotation = Rotation.Degree0,\n options = { withAnnotations: false },\n imageType = 'image/webp',\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 imageType,\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"],"names":["page"],"mappings":";;AAeO,MAAM,gBAAN,MAAM,sBAAqB,WAAiD;AAAA,EAMjF,YAAY,IAAY,UAA0B,QAAmB;AACnE,UAAM,IAAI,QAAQ;AAHpB,SAAiB,gBAAgB,cAAwB;AAIvD,SAAK,SAAS;AAEd,SAAK,UAAU,SAAS,eAAe,CAAC,WAAW;AAC5C,WAAA,cAAc,KAAK,OAAO,OAAO;AAAA,IAAA,CACvC;AAAA,EAAA;AAAA,EAGH,MAAM,WAAW,SAA4C;AAAA,EAAA;AAAA,EAEnD,kBAAoC;AACrC,WAAA;AAAA,MACL,YAAY,KAAK,WAAW,KAAK,IAAI;AAAA,MACrC,gBAAgB,KAAK,eAAe,KAAK,IAAI;AAAA,IAC/C;AAAA,EAAA;AAAA,EAGK,eAAe,IAA4C;AACzD,WAAA,KAAK,cAAc,GAAG,EAAE;AAAA,EAAA;AAAA,EAGzB,WAAW;AAAA,IACjB;AAAA,IACA,cAAc;AAAA,IACd,MAAM;AAAA,IACN,WAAW,SAAS;AAAA,IACpB,UAAU,EAAE,iBAAiB,MAAM;AAAA,IACnC,YAAY;AAAA,EAAA,GACQ;AACd,UAAA,YAAY,KAAK,UAAU;AAE7B,QAAA,CAAC,UAAU,UAAU;AACjB,YAAA,IAAI,MAAM,wBAAwB;AAAA,IAAA;AAGpC,UAAA,OAAO,UAAU,SAAS,MAAM,KAAK,CAACA,UAASA,MAAK,UAAU,SAAS;AAC7E,QAAI,CAAC,MAAM;AACH,YAAA,IAAI,MAAM,qBAAqB;AAAA,IAAA;AAGvC,WAAO,KAAK,OAAO;AAAA,MACjB,UAAU;AAAA,MACV;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACF;AAAA,EAAA;AAAA,EAGM,eAAe;AAAA,IACrB;AAAA,IACA,cAAc;AAAA,IACd,MAAM;AAAA,IACN;AAAA,IACA,WAAW,SAAS;AAAA,IACpB,UAAU,EAAE,iBAAiB,MAAM;AAAA,IACnC,YAAY;AAAA,EAAA,GACY;AAClB,UAAA,YAAY,KAAK,UAAU;AAE7B,QAAA,CAAC,UAAU,UAAU;AACjB,YAAA,IAAI,MAAM,wBAAwB;AAAA,IAAA;AAGpC,UAAA,OAAO,UAAU,SAAS,MAAM,KAAK,CAACA,UAASA,MAAK,UAAU,SAAS;AAC7E,QAAI,CAAC,MAAM;AACH,YAAA,IAAI,MAAM,qBAAqB;AAAA,IAAA;AAGvC,WAAO,KAAK,OAAO;AAAA,MACjB,UAAU;AAAA,MACV;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACF;AAAA,EAAA;AAEJ;AAxFE,cAAgB,KAAK;AADhB,IAAM,eAAN;ACZA,MAAM,mBAAmB;AAEzB,MAAM,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,EAAA;AAEb;ACVO,MAAM,sBAAuE;AAAA,EAClF;AAAA,EACA,QAAQ,CAAC,UAAU,WAAW,IAAI,aAAa,kBAAkB,UAAU,MAAM;AAAA,EACjF,SAAS,MAAM;AAAA,EAAC;AAAA,EAChB,cAAc,CAAA;AAChB;"}
@@ -1,12 +1,14 @@
1
- import { BasePlugin, PluginRegistry } from '@embedpdf/core';
1
+ import { BasePlugin, PluginRegistry, Unsubscribe } from '@embedpdf/core';
2
2
  import { RenderCapability, RenderPluginConfig } from './types';
3
3
  import { PdfEngine } from '@embedpdf/models';
4
4
  export declare class RenderPlugin extends BasePlugin<RenderPluginConfig, RenderCapability> {
5
5
  static readonly id: "render";
6
6
  private engine;
7
+ private readonly refreshPages$;
7
8
  constructor(id: string, registry: PluginRegistry, engine: PdfEngine);
8
9
  initialize(_config: RenderPluginConfig): Promise<void>;
9
10
  protected buildCapability(): RenderCapability;
11
+ onRefreshPages(fn: (pages: number[]) => void): Unsubscribe;
10
12
  private renderPage;
11
13
  private renderPageRect;
12
14
  }
@@ -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"),u=require("@embedpdf/core/preact"),c=require("@embedpdf/plugin-render"),d=()=>u.useCapability(c.RenderPlugin.id);exports.RenderLayer=function({pageIndex:u,scaleFactor:c=1,dpr:s=1,style:i,...o}){const{provides:a}=d(),[l,p]=t.useState(null),g=t.useRef(null);return t.useEffect((()=>{if(a){const e=a.renderPage({pageIndex:u,scaleFactor:c,dpr:s});return e.wait((e=>{const r=URL.createObjectURL(e);p(r),g.current=r}),n.ignore),()=>{g.current?(URL.revokeObjectURL(g.current),g.current=null):e.abort({code:n.PdfErrorCode.Cancelled,message:"canceled render task"})}}}),[u,c,s,a]),e.jsx(r.Fragment,{children:l&&e.jsx("img",{src:l,onLoad:()=>{g.current&&(URL.revokeObjectURL(g.current),g.current=null)},...o,style:{width:"100%",height:"100%",...i||{}}})})},exports.useRenderCapability=d,exports.useRenderPlugin=()=>u.usePlugin(c.RenderPlugin.id);
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"),u=require("@embedpdf/core/preact"),c=require("@embedpdf/plugin-render"),s=()=>u.usePlugin(c.RenderPlugin.id),d=()=>u.useCapability(c.RenderPlugin.id);exports.RenderLayer=function({pageIndex:u,scaleFactor:c=1,dpr:i=1,style:a,...o}){const{provides:l}=d(),{plugin:p}=s(),[g,f]=t.useState(null),R=t.useRef(null),[b,m]=t.useState(0);return t.useEffect((()=>{if(p)return p.onRefreshPages((e=>{e.includes(u)&&m((e=>e+1))}))}),[p]),t.useEffect((()=>{if(l){const e=l.renderPage({pageIndex:u,scaleFactor:c,dpr:i});return e.wait((e=>{const r=URL.createObjectURL(e);f(r),R.current=r}),n.ignore),()=>{R.current?(URL.revokeObjectURL(R.current),R.current=null):e.abort({code:n.PdfErrorCode.Cancelled,message:"canceled render task"})}}}),[u,c,i,l,b]),e.jsx(r.Fragment,{children:g&&e.jsx("img",{src:g,onLoad:()=>{R.current&&(URL.revokeObjectURL(R.current),R.current=null)},...o,style:{width:"100%",height:"100%",...a||{}}})})},exports.useRenderCapability=d,exports.useRenderPlugin=s;
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 } from '../hooks/use-render';\n\ntype RenderLayerProps = Omit<HTMLAttributes<HTMLImageElement>, 'style'> & {\n pageIndex: number;\n scaleFactor?: number;\n dpr?: number;\n style?: CSSProperties;\n};\n\nexport function RenderLayer({\n pageIndex,\n scaleFactor = 1,\n dpr = 1,\n style,\n ...props\n}: RenderLayerProps) {\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"],"names":["useRenderCapability","useCapability","RenderPlugin","id","pageIndex","scaleFactor","dpr","style","props","provides","renderProvides","imageUrl","setImageUrl","useState","urlRef","useRef","useEffect","task","renderPage","wait","blob","url","URL","createObjectURL","current","ignore","revokeObjectURL","abort","code","PdfErrorCode","Cancelled","message","jsx","Fragment","children","jsxRuntime","src","onLoad","width","height","usePlugin"],"mappings":"0QAIaA,EAAsB,IAAMC,gBAA4BC,EAAAA,aAAaC,wBCU3E,UAAqBC,UAC1BA,EAAAC,YACAA,EAAc,EAAAC,IACdA,EAAM,EAAAC,MACNA,KACGC,IAEH,MAAQC,SAAUC,GAAmBV,KAC9BW,EAAUC,GAAeC,EAAAA,SAAwB,MAClDC,EAASC,SAAsB,MAiCnC,OA/BFC,EAAAA,WAAU,KACR,GAAIN,EAAgB,CAClB,MAAMO,EAAOP,EAAeQ,WAAW,CAAEd,YAAWC,cAAaC,QAOjE,OANKW,EAAAE,MAAMC,IACH,MAAAC,EAAMC,IAAIC,gBAAgBH,GAChCR,EAAYS,GACZP,EAAOU,QAAUH,CAAA,GAChBI,UAEI,KACDX,EAAOU,SACLF,IAAAI,gBAAgBZ,EAAOU,SAC3BV,EAAOU,QAAU,MAEjBP,EAAKU,MAAM,CACTC,KAAMC,EAAaA,aAAAC,UACnBC,QAAS,wBACV,CAEL,IAED,CAAC3B,EAAWC,EAAaC,EAAKI,MAU/BsB,IAACC,YACEC,SACCvB,GAAAwB,EAAAH,IAAC,MAAA,CACCI,IAAKzB,EACL0B,OAZgB,KAClBvB,EAAOU,UACLF,IAAAI,gBAAgBZ,EAAOU,SAC3BV,EAAOU,QAAU,KAAA,KAUThB,EACJD,MAAO,CACL+B,MAAO,OACPC,OAAQ,UACJhC,GAAS,CAAA,MAMzB,wDDpE+B,IAAMiC,YAAwBtC,EAAAA,aAAaC"}
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, useRenderPlugin } from '../hooks/use-render';\n\ntype RenderLayerProps = Omit<HTMLAttributes<HTMLImageElement>, 'style'> & {\n pageIndex: number;\n scaleFactor?: number;\n dpr?: number;\n style?: CSSProperties;\n};\n\nexport function RenderLayer({\n pageIndex,\n scaleFactor = 1,\n dpr = 1,\n style,\n ...props\n}: RenderLayerProps) {\n const { provides: renderProvides } = useRenderCapability();\n const { plugin: renderPlugin } = useRenderPlugin();\n\n const [imageUrl, setImageUrl] = useState<string | null>(null);\n const urlRef = useRef<string | null>(null);\n const [refreshTick, setRefreshTick] = useState(0);\n\n useEffect(() => {\n if (!renderPlugin) return;\n return renderPlugin.onRefreshPages((pages) => {\n if (pages.includes(pageIndex)) {\n setRefreshTick((tick) => tick + 1);\n }\n });\n }, [renderPlugin]);\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, refreshTick]);\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":["useRenderPlugin","usePlugin","RenderPlugin","id","useRenderCapability","useCapability","pageIndex","scaleFactor","dpr","style","props","provides","renderProvides","plugin","renderPlugin","imageUrl","setImageUrl","useState","urlRef","useRef","refreshTick","setRefreshTick","useEffect","onRefreshPages","pages","includes","tick","task","renderPage","wait","blob","url","URL","createObjectURL","current","ignore","revokeObjectURL","abort","code","PdfErrorCode","Cancelled","message","jsx","Fragment","children","jsxRuntime","src","onLoad","width","height"],"mappings":"0QAGaA,EAAkB,IAAMC,YAAwBC,EAAAA,aAAaC,IAC7DC,EAAsB,IAAMC,gBAA4BH,EAAAA,aAAaC,wBCU3E,UAAqBG,UAC1BA,EAAAC,YACAA,EAAc,EAAAC,IACdA,EAAM,EAAAC,MACNA,KACGC,IAEH,MAAQC,SAAUC,GAAmBR,KAC7BS,OAAQC,GAAiBd,KAE1Be,EAAUC,GAAeC,EAAAA,SAAwB,MAClDC,EAASC,SAAsB,OAC9BC,EAAaC,GAAkBJ,EAAAA,SAAS,GA0C7C,OAxCFK,EAAAA,WAAU,KACR,GAAKR,EACE,OAAAA,EAAaS,gBAAgBC,IAC9BA,EAAMC,SAASnB,IACFe,GAACK,GAASA,EAAO,GAAC,GAEpC,GACA,CAACZ,IAEJQ,EAAAA,WAAU,KACR,GAAIV,EAAgB,CAClB,MAAMe,EAAOf,EAAegB,WAAW,CAAEtB,YAAWC,cAAaC,QAOjE,OANKmB,EAAAE,MAAMC,IACH,MAAAC,EAAMC,IAAIC,gBAAgBH,GAChCd,EAAYe,GACZb,EAAOgB,QAAUH,CAAA,GAChBI,UAEI,KACDjB,EAAOgB,SACLF,IAAAI,gBAAgBlB,EAAOgB,SAC3BhB,EAAOgB,QAAU,MAEjBP,EAAKU,MAAM,CACTC,KAAMC,EAAaA,aAAAC,UACnBC,QAAS,wBACV,CAEL,IAED,CAACnC,EAAWC,EAAaC,EAAKI,EAAgBQ,MAU/CsB,IAACC,YACEC,SACC7B,GAAA8B,EAAAH,IAAC,MAAA,CACCI,IAAK/B,EACLgC,OAZgB,KAClB7B,EAAOgB,UACLF,IAAAI,gBAAgBlB,EAAOgB,SAC3BhB,EAAOgB,QAAU,KAAA,KAUTxB,EACJD,MAAO,CACLuC,MAAO,OACPC,OAAQ,UACJxC,GAAS,CAAA,MAMzB"}
@@ -14,8 +14,18 @@ function RenderLayer({
14
14
  ...props
15
15
  }) {
16
16
  const { provides: renderProvides } = useRenderCapability();
17
+ const { plugin: renderPlugin } = useRenderPlugin();
17
18
  const [imageUrl, setImageUrl] = useState(null);
18
19
  const urlRef = useRef(null);
20
+ const [refreshTick, setRefreshTick] = useState(0);
21
+ useEffect(() => {
22
+ if (!renderPlugin) return;
23
+ return renderPlugin.onRefreshPages((pages) => {
24
+ if (pages.includes(pageIndex)) {
25
+ setRefreshTick((tick) => tick + 1);
26
+ }
27
+ });
28
+ }, [renderPlugin]);
19
29
  useEffect(() => {
20
30
  if (renderProvides) {
21
31
  const task = renderProvides.renderPage({ pageIndex, scaleFactor, dpr });
@@ -36,7 +46,7 @@ function RenderLayer({
36
46
  }
37
47
  };
38
48
  }
39
- }, [pageIndex, scaleFactor, dpr, renderProvides]);
49
+ }, [pageIndex, scaleFactor, dpr, renderProvides, refreshTick]);
40
50
  const handleImageLoad = () => {
41
51
  if (urlRef.current) {
42
52
  URL.revokeObjectURL(urlRef.current);
@@ -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 } from '../hooks/use-render';\n\ntype RenderLayerProps = Omit<HTMLAttributes<HTMLImageElement>, 'style'> & {\n pageIndex: number;\n scaleFactor?: number;\n dpr?: number;\n style?: CSSProperties;\n};\n\nexport function RenderLayer({\n pageIndex,\n scaleFactor = 1,\n dpr = 1,\n style,\n ...props\n}: RenderLayerProps) {\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"],"names":[],"mappings":";;;;;;AAGO,MAAM,kBAAkB,MAAM,UAAwB,aAAa,EAAE;AACrE,MAAM,sBAAsB,MAAM,cAA4B,aAAa,EAAE;ACU7E,SAAS,YAAY;AAAA,EAC1B;AAAA,EACA,cAAc;AAAA,EACd,MAAM;AAAA,EACN;AAAA,EACA,GAAG;AACL,GAAqB;AACnB,QAAM,EAAE,UAAU,eAAe,IAAI,oBAAoB;AACzD,QAAM,CAAC,UAAU,WAAW,IAAI,SAAwB,IAAI;AACtD,QAAA,SAAS,OAAsB,IAAI;AAEzC,YAAU,MAAM;AACd,QAAI,gBAAgB;AAClB,YAAM,OAAO,eAAe,WAAW,EAAE,WAAW,aAAa,KAAK;AACjE,WAAA,KAAK,CAAC,SAAS;AACZ,cAAA,MAAM,IAAI,gBAAgB,IAAI;AACpC,oBAAY,GAAG;AACf,eAAO,UAAU;AAAA,SAChB,MAAM;AAET,aAAO,MAAM;AACX,YAAI,OAAO,SAAS;AACd,cAAA,gBAAgB,OAAO,OAAO;AAClC,iBAAO,UAAU;AAAA,QAAA,OACZ;AACL,eAAK,MAAM;AAAA,YACT,MAAM,aAAa;AAAA,YACnB,SAAS;AAAA,UAAA,CACV;AAAA,QAAA;AAAA,MAEL;AAAA,IAAA;AAAA,KAED,CAAC,WAAW,aAAa,KAAK,cAAc,CAAC;AAEhD,QAAM,kBAAkB,MAAM;AAC5B,QAAI,OAAO,SAAS;AACd,UAAA,gBAAgB,OAAO,OAAO;AAClC,aAAO,UAAU;AAAA,IAAA;AAAA,EAErB;AAGE,SAAA,oBAAC,YACE,UACC,YAAA;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;"}
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, useRenderPlugin } from '../hooks/use-render';\n\ntype RenderLayerProps = Omit<HTMLAttributes<HTMLImageElement>, 'style'> & {\n pageIndex: number;\n scaleFactor?: number;\n dpr?: number;\n style?: CSSProperties;\n};\n\nexport function RenderLayer({\n pageIndex,\n scaleFactor = 1,\n dpr = 1,\n style,\n ...props\n}: RenderLayerProps) {\n const { provides: renderProvides } = useRenderCapability();\n const { plugin: renderPlugin } = useRenderPlugin();\n\n const [imageUrl, setImageUrl] = useState<string | null>(null);\n const urlRef = useRef<string | null>(null);\n const [refreshTick, setRefreshTick] = useState(0);\n\n useEffect(() => {\n if (!renderPlugin) return;\n return renderPlugin.onRefreshPages((pages) => {\n if (pages.includes(pageIndex)) {\n setRefreshTick((tick) => tick + 1);\n }\n });\n }, [renderPlugin]);\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, refreshTick]);\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;ACU7E,SAAS,YAAY;AAAA,EAC1B;AAAA,EACA,cAAc;AAAA,EACd,MAAM;AAAA,EACN;AAAA,EACA,GAAG;AACL,GAAqB;AACnB,QAAM,EAAE,UAAU,eAAe,IAAI,oBAAoB;AACzD,QAAM,EAAE,QAAQ,aAAa,IAAI,gBAAgB;AAEjD,QAAM,CAAC,UAAU,WAAW,IAAI,SAAwB,IAAI;AACtD,QAAA,SAAS,OAAsB,IAAI;AACzC,QAAM,CAAC,aAAa,cAAc,IAAI,SAAS,CAAC;AAEhD,YAAU,MAAM;AACd,QAAI,CAAC,aAAc;AACZ,WAAA,aAAa,eAAe,CAAC,UAAU;AACxC,UAAA,MAAM,SAAS,SAAS,GAAG;AACd,uBAAA,CAAC,SAAS,OAAO,CAAC;AAAA,MAAA;AAAA,IACnC,CACD;AAAA,EAAA,GACA,CAAC,YAAY,CAAC;AAEjB,YAAU,MAAM;AACd,QAAI,gBAAgB;AAClB,YAAM,OAAO,eAAe,WAAW,EAAE,WAAW,aAAa,KAAK;AACjE,WAAA,KAAK,CAAC,SAAS;AACZ,cAAA,MAAM,IAAI,gBAAgB,IAAI;AACpC,oBAAY,GAAG;AACf,eAAO,UAAU;AAAA,SAChB,MAAM;AAET,aAAO,MAAM;AACX,YAAI,OAAO,SAAS;AACd,cAAA,gBAAgB,OAAO,OAAO;AAClC,iBAAO,UAAU;AAAA,QAAA,OACZ;AACL,eAAK,MAAM;AAAA,YACT,MAAM,aAAa;AAAA,YACnB,SAAS;AAAA,UAAA,CACV;AAAA,QAAA;AAAA,MAEL;AAAA,IAAA;AAAA,EACF,GACC,CAAC,WAAW,aAAa,KAAK,gBAAgB,WAAW,CAAC;AAE7D,QAAM,kBAAkB,MAAM;AAC5B,QAAI,OAAO,SAAS;AACd,UAAA,gBAAgB,OAAO,OAAO;AAClC,aAAO,UAAU;AAAA,IAAA;AAAA,EAErB;AAGE,SAAA,oBAAC,YACE,UACC,YAAA;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;"}
@@ -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"),u=require("@embedpdf/plugin-render"),c=()=>n.useCapability(u.RenderPlugin.id);exports.RenderLayer=function({pageIndex:n,scaleFactor:u=1,dpr:d=1,style:s,...i}){const{provides:a}=c(),[l,o]=r.useState(null),p=r.useRef(null);return r.useEffect((()=>{if(a){const e=a.renderPage({pageIndex:n,scaleFactor:u,dpr:d});return e.wait((e=>{const r=URL.createObjectURL(e);o(r),p.current=r}),t.ignore),()=>{p.current?(URL.revokeObjectURL(p.current),p.current=null):e.abort({code:t.PdfErrorCode.Cancelled,message:"canceled render task"})}}}),[n,u,d,a]),e.jsx(r.Fragment,{children:l&&e.jsx("img",{src:l,onLoad:()=>{p.current&&(URL.revokeObjectURL(p.current),p.current=null)},...i,style:{width:"100%",height:"100%",...s||{}}})})},exports.useRenderCapability=c,exports.useRenderPlugin=()=>n.usePlugin(u.RenderPlugin.id);
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"),u=require("@embedpdf/plugin-render"),c=()=>n.usePlugin(u.RenderPlugin.id),s=()=>n.useCapability(u.RenderPlugin.id);exports.RenderLayer=function({pageIndex:n,scaleFactor:u=1,dpr:d=1,style:i,...a}){const{provides:l}=s(),{plugin:o}=c(),[g,p]=r.useState(null),f=r.useRef(null),[R,b]=r.useState(0);return r.useEffect((()=>{if(o)return o.onRefreshPages((e=>{e.includes(n)&&b((e=>e+1))}))}),[o]),r.useEffect((()=>{if(l){const e=l.renderPage({pageIndex:n,scaleFactor:u,dpr:d});return e.wait((e=>{const r=URL.createObjectURL(e);p(r),f.current=r}),t.ignore),()=>{f.current?(URL.revokeObjectURL(f.current),f.current=null):e.abort({code:t.PdfErrorCode.Cancelled,message:"canceled render task"})}}}),[n,u,d,l,R]),e.jsx(r.Fragment,{children:g&&e.jsx("img",{src:g,onLoad:()=>{f.current&&(URL.revokeObjectURL(f.current),f.current=null)},...a,style:{width:"100%",height:"100%",...i||{}}})})},exports.useRenderCapability=s,exports.useRenderPlugin=c;
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 } from '../hooks/use-render';\n\ntype RenderLayerProps = Omit<HTMLAttributes<HTMLImageElement>, 'style'> & {\n pageIndex: number;\n scaleFactor?: number;\n dpr?: number;\n style?: CSSProperties;\n};\n\nexport function RenderLayer({\n pageIndex,\n scaleFactor = 1,\n dpr = 1,\n style,\n ...props\n}: RenderLayerProps) {\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"],"names":["useRenderCapability","useCapability","RenderPlugin","id","pageIndex","scaleFactor","dpr","style","props","provides","renderProvides","imageUrl","setImageUrl","useState","urlRef","useRef","useEffect","task","renderPage","wait","blob","url","URL","createObjectURL","current","ignore","revokeObjectURL","abort","code","PdfErrorCode","Cancelled","message","jsx","Fragment","children","jsxRuntime","src","onLoad","width","height","usePlugin"],"mappings":"6OAIaA,EAAsB,IAAMC,gBAA4BC,EAAAA,aAAaC,wBCU3E,UAAqBC,UAC1BA,EAAAC,YACAA,EAAc,EAAAC,IACdA,EAAM,EAAAC,MACNA,KACGC,IAEH,MAAQC,SAAUC,GAAmBV,KAC9BW,EAAUC,GAAeC,EAAAA,SAAwB,MAClDC,EAASC,SAAsB,MAiCnC,OA/BFC,EAAAA,WAAU,KACR,GAAIN,EAAgB,CAClB,MAAMO,EAAOP,EAAeQ,WAAW,CAAEd,YAAWC,cAAaC,QAOjE,OANKW,EAAAE,MAAMC,IACH,MAAAC,EAAMC,IAAIC,gBAAgBH,GAChCR,EAAYS,GACZP,EAAOU,QAAUH,CAAA,GAChBI,UAEI,KACDX,EAAOU,SACLF,IAAAI,gBAAgBZ,EAAOU,SAC3BV,EAAOU,QAAU,MAEjBP,EAAKU,MAAM,CACTC,KAAMC,EAAaA,aAAAC,UACnBC,QAAS,wBACV,CAEL,IAED,CAAC3B,EAAWC,EAAaC,EAAKI,MAU/BsB,IAACC,YACEC,SACCvB,GAAAwB,EAAAH,IAAC,MAAA,CACCI,IAAKzB,EACL0B,OAZgB,KAClBvB,EAAOU,UACLF,IAAAI,gBAAgBZ,EAAOU,SAC3BV,EAAOU,QAAU,KAAA,KAUThB,EACJD,MAAO,CACL+B,MAAO,OACPC,OAAQ,UACJhC,GAAS,CAAA,MAMzB,wDDpE+B,IAAMiC,YAAwBtC,EAAAA,aAAaC"}
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, useRenderPlugin } from '../hooks/use-render';\n\ntype RenderLayerProps = Omit<HTMLAttributes<HTMLImageElement>, 'style'> & {\n pageIndex: number;\n scaleFactor?: number;\n dpr?: number;\n style?: CSSProperties;\n};\n\nexport function RenderLayer({\n pageIndex,\n scaleFactor = 1,\n dpr = 1,\n style,\n ...props\n}: RenderLayerProps) {\n const { provides: renderProvides } = useRenderCapability();\n const { plugin: renderPlugin } = useRenderPlugin();\n\n const [imageUrl, setImageUrl] = useState<string | null>(null);\n const urlRef = useRef<string | null>(null);\n const [refreshTick, setRefreshTick] = useState(0);\n\n useEffect(() => {\n if (!renderPlugin) return;\n return renderPlugin.onRefreshPages((pages) => {\n if (pages.includes(pageIndex)) {\n setRefreshTick((tick) => tick + 1);\n }\n });\n }, [renderPlugin]);\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, refreshTick]);\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":["useRenderPlugin","usePlugin","RenderPlugin","id","useRenderCapability","useCapability","pageIndex","scaleFactor","dpr","style","props","provides","renderProvides","plugin","renderPlugin","imageUrl","setImageUrl","useState","urlRef","useRef","refreshTick","setRefreshTick","useEffect","onRefreshPages","pages","includes","tick","task","renderPage","wait","blob","url","URL","createObjectURL","current","ignore","revokeObjectURL","abort","code","PdfErrorCode","Cancelled","message","jsx","Fragment","children","jsxRuntime","src","onLoad","width","height"],"mappings":"6OAGaA,EAAkB,IAAMC,YAAwBC,EAAAA,aAAaC,IAC7DC,EAAsB,IAAMC,gBAA4BH,EAAAA,aAAaC,wBCU3E,UAAqBG,UAC1BA,EAAAC,YACAA,EAAc,EAAAC,IACdA,EAAM,EAAAC,MACNA,KACGC,IAEH,MAAQC,SAAUC,GAAmBR,KAC7BS,OAAQC,GAAiBd,KAE1Be,EAAUC,GAAeC,EAAAA,SAAwB,MAClDC,EAASC,SAAsB,OAC9BC,EAAaC,GAAkBJ,EAAAA,SAAS,GA0C7C,OAxCFK,EAAAA,WAAU,KACR,GAAKR,EACE,OAAAA,EAAaS,gBAAgBC,IAC9BA,EAAMC,SAASnB,IACFe,GAACK,GAASA,EAAO,GAAC,GAEpC,GACA,CAACZ,IAEJQ,EAAAA,WAAU,KACR,GAAIV,EAAgB,CAClB,MAAMe,EAAOf,EAAegB,WAAW,CAAEtB,YAAWC,cAAaC,QAOjE,OANKmB,EAAAE,MAAMC,IACH,MAAAC,EAAMC,IAAIC,gBAAgBH,GAChCd,EAAYe,GACZb,EAAOgB,QAAUH,CAAA,GAChBI,UAEI,KACDjB,EAAOgB,SACLF,IAAAI,gBAAgBlB,EAAOgB,SAC3BhB,EAAOgB,QAAU,MAEjBP,EAAKU,MAAM,CACTC,KAAMC,EAAaA,aAAAC,UACnBC,QAAS,wBACV,CAEL,IAED,CAACnC,EAAWC,EAAaC,EAAKI,EAAgBQ,MAU/CsB,IAACC,YACEC,SACC7B,GAAA8B,EAAAH,IAAC,MAAA,CACCI,IAAK/B,EACLgC,OAZgB,KAClB7B,EAAOgB,UACLF,IAAAI,gBAAgBlB,EAAOgB,SAC3BhB,EAAOgB,QAAU,KAAA,KAUTxB,EACJD,MAAO,CACLuC,MAAO,OACPC,OAAQ,UACJxC,GAAS,CAAA,MAMzB"}
@@ -13,8 +13,18 @@ function RenderLayer({
13
13
  ...props
14
14
  }) {
15
15
  const { provides: renderProvides } = useRenderCapability();
16
+ const { plugin: renderPlugin } = useRenderPlugin();
16
17
  const [imageUrl, setImageUrl] = useState(null);
17
18
  const urlRef = useRef(null);
19
+ const [refreshTick, setRefreshTick] = useState(0);
20
+ useEffect(() => {
21
+ if (!renderPlugin) return;
22
+ return renderPlugin.onRefreshPages((pages) => {
23
+ if (pages.includes(pageIndex)) {
24
+ setRefreshTick((tick) => tick + 1);
25
+ }
26
+ });
27
+ }, [renderPlugin]);
18
28
  useEffect(() => {
19
29
  if (renderProvides) {
20
30
  const task = renderProvides.renderPage({ pageIndex, scaleFactor, dpr });
@@ -35,7 +45,7 @@ function RenderLayer({
35
45
  }
36
46
  };
37
47
  }
38
- }, [pageIndex, scaleFactor, dpr, renderProvides]);
48
+ }, [pageIndex, scaleFactor, dpr, renderProvides, refreshTick]);
39
49
  const handleImageLoad = () => {
40
50
  if (urlRef.current) {
41
51
  URL.revokeObjectURL(urlRef.current);
@@ -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 } from '../hooks/use-render';\n\ntype RenderLayerProps = Omit<HTMLAttributes<HTMLImageElement>, 'style'> & {\n pageIndex: number;\n scaleFactor?: number;\n dpr?: number;\n style?: CSSProperties;\n};\n\nexport function RenderLayer({\n pageIndex,\n scaleFactor = 1,\n dpr = 1,\n style,\n ...props\n}: RenderLayerProps) {\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"],"names":[],"mappings":";;;;;AAGO,MAAM,kBAAkB,MAAM,UAAwB,aAAa,EAAE;AACrE,MAAM,sBAAsB,MAAM,cAA4B,aAAa,EAAE;ACU7E,SAAS,YAAY;AAAA,EAC1B;AAAA,EACA,cAAc;AAAA,EACd,MAAM;AAAA,EACN;AAAA,EACA,GAAG;AACL,GAAqB;AACnB,QAAM,EAAE,UAAU,eAAe,IAAI,oBAAoB;AACzD,QAAM,CAAC,UAAU,WAAW,IAAI,SAAwB,IAAI;AACtD,QAAA,SAAS,OAAsB,IAAI;AAEzC,YAAU,MAAM;AACd,QAAI,gBAAgB;AAClB,YAAM,OAAO,eAAe,WAAW,EAAE,WAAW,aAAa,KAAK;AACjE,WAAA,KAAK,CAAC,SAAS;AACZ,cAAA,MAAM,IAAI,gBAAgB,IAAI;AACpC,oBAAY,GAAG;AACf,eAAO,UAAU;AAAA,SAChB,MAAM;AAET,aAAO,MAAM;AACX,YAAI,OAAO,SAAS;AACd,cAAA,gBAAgB,OAAO,OAAO;AAClC,iBAAO,UAAU;AAAA,QAAA,OACZ;AACL,eAAK,MAAM;AAAA,YACT,MAAM,aAAa;AAAA,YACnB,SAAS;AAAA,UAAA,CACV;AAAA,QAAA;AAAA,MAEL;AAAA,IAAA;AAAA,KAED,CAAC,WAAW,aAAa,KAAK,cAAc,CAAC;AAEhD,QAAM,kBAAkB,MAAM;AAC5B,QAAI,OAAO,SAAS;AACd,UAAA,gBAAgB,OAAO,OAAO;AAClC,aAAO,UAAU;AAAA,IAAA;AAAA,EAErB;AAGE,SAAA,oBAAC,YACE,UACC,YAAA;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;"}
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, useRenderPlugin } from '../hooks/use-render';\n\ntype RenderLayerProps = Omit<HTMLAttributes<HTMLImageElement>, 'style'> & {\n pageIndex: number;\n scaleFactor?: number;\n dpr?: number;\n style?: CSSProperties;\n};\n\nexport function RenderLayer({\n pageIndex,\n scaleFactor = 1,\n dpr = 1,\n style,\n ...props\n}: RenderLayerProps) {\n const { provides: renderProvides } = useRenderCapability();\n const { plugin: renderPlugin } = useRenderPlugin();\n\n const [imageUrl, setImageUrl] = useState<string | null>(null);\n const urlRef = useRef<string | null>(null);\n const [refreshTick, setRefreshTick] = useState(0);\n\n useEffect(() => {\n if (!renderPlugin) return;\n return renderPlugin.onRefreshPages((pages) => {\n if (pages.includes(pageIndex)) {\n setRefreshTick((tick) => tick + 1);\n }\n });\n }, [renderPlugin]);\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, refreshTick]);\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;ACU7E,SAAS,YAAY;AAAA,EAC1B;AAAA,EACA,cAAc;AAAA,EACd,MAAM;AAAA,EACN;AAAA,EACA,GAAG;AACL,GAAqB;AACnB,QAAM,EAAE,UAAU,eAAe,IAAI,oBAAoB;AACzD,QAAM,EAAE,QAAQ,aAAa,IAAI,gBAAgB;AAEjD,QAAM,CAAC,UAAU,WAAW,IAAI,SAAwB,IAAI;AACtD,QAAA,SAAS,OAAsB,IAAI;AACzC,QAAM,CAAC,aAAa,cAAc,IAAI,SAAS,CAAC;AAEhD,YAAU,MAAM;AACd,QAAI,CAAC,aAAc;AACZ,WAAA,aAAa,eAAe,CAAC,UAAU;AACxC,UAAA,MAAM,SAAS,SAAS,GAAG;AACd,uBAAA,CAAC,SAAS,OAAO,CAAC;AAAA,MAAA;AAAA,IACnC,CACD;AAAA,EAAA,GACA,CAAC,YAAY,CAAC;AAEjB,YAAU,MAAM;AACd,QAAI,gBAAgB;AAClB,YAAM,OAAO,eAAe,WAAW,EAAE,WAAW,aAAa,KAAK;AACjE,WAAA,KAAK,CAAC,SAAS;AACZ,cAAA,MAAM,IAAI,gBAAgB,IAAI;AACpC,oBAAY,GAAG;AACf,eAAO,UAAU;AAAA,SAChB,MAAM;AAET,aAAO,MAAM;AACX,YAAI,OAAO,SAAS;AACd,cAAA,gBAAgB,OAAO,OAAO;AAClC,iBAAO,UAAU;AAAA,QAAA,OACZ;AACL,eAAK,MAAM;AAAA,YACT,MAAM,aAAa;AAAA,YACnB,SAAS;AAAA,UAAA,CACV;AAAA,QAAA;AAAA,MAEL;AAAA,IAAA;AAAA,EACF,GACC,CAAC,WAAW,aAAa,KAAK,gBAAgB,WAAW,CAAC;AAE7D,QAAM,kBAAkB,MAAM;AAC5B,QAAI,OAAO,SAAS;AACd,UAAA,gBAAgB,OAAO,OAAO;AAClC,aAAO,UAAU;AAAA,IAAA;AAAA,EAErB;AAGE,SAAA,oBAAC,YACE,UACC,YAAA;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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@embedpdf/plugin-render",
3
- "version": "1.0.16",
3
+ "version": "1.0.18",
4
4
  "type": "module",
5
5
  "main": "./dist/index.cjs",
6
6
  "module": "./dist/index.js",
@@ -28,20 +28,20 @@
28
28
  }
29
29
  },
30
30
  "dependencies": {
31
- "@embedpdf/models": "1.0.16"
31
+ "@embedpdf/models": "1.0.18"
32
32
  },
33
33
  "devDependencies": {
34
34
  "@types/react": "^18.2.0",
35
35
  "typescript": "^5.0.0",
36
- "@embedpdf/core": "1.0.16",
37
- "@embedpdf/build": "1.0.0"
36
+ "@embedpdf/build": "1.0.0",
37
+ "@embedpdf/core": "1.0.18"
38
38
  },
39
39
  "peerDependencies": {
40
40
  "preact": "^10.26.4",
41
41
  "react": ">=16.8.0",
42
42
  "react-dom": ">=16.8.0",
43
43
  "vue": ">=3.2.0",
44
- "@embedpdf/core": "1.0.16"
44
+ "@embedpdf/core": "1.0.18"
45
45
  },
46
46
  "files": [
47
47
  "dist",