@embedpdf/plugin-tiling 1.0.17 → 1.0.19
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 +13 -4
- package/dist/index.js.map +1 -1
- package/dist/lib/tiling-plugin.d.ts +3 -1
- package/dist/preact/index.cjs +1 -1
- package/dist/preact/index.cjs.map +1 -1
- package/dist/preact/index.js +11 -1
- package/dist/preact/index.js.map +1 -1
- package/dist/react/index.cjs +1 -1
- package/dist/react/index.cjs.map +1 -1
- package/dist/react/index.js +11 -1
- package/dist/react/index.js.map +1 -1
- package/package.json +10 -10
package/dist/index.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("@embedpdf/core"),i=require("@embedpdf/models"),t="tiling",s={id:t,name:"Tiling Plugin",version:"1.0.0",provides:["tiling"],requires:["render","scroll","viewport"],optional:[],defaultConfig:{enabled:!0,tileSize:768,overlapPx:2.5,extraRings:0}},r="UPDATE_VISIBLE_TILES",a="MARK_TILE_STATUS",l=e=>({type:r,payload:e}),o=(e,i,t)=>({type:a,payload:{pageIndex:e,tileId:i,status:t}});function n({tileSize:e=768,overlapPx:t=2.5,extraRings:s=0,scale:r,rotation:a,page:l,metric:o}){const n=l.size.width*r,c=l.size.height*r,d=e-t,h=i.transformSize(l.size,a,r),g={origin:{x:o.scaled.pageX,y:o.scaled.pageY},size:{width:o.scaled.visibleWidth,height:o.scaled.visibleHeight}},p=i.restoreRect(h,g,a,1),u=p.origin.x,
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("@embedpdf/core"),i=require("@embedpdf/models"),t="tiling",s={id:t,name:"Tiling Plugin",version:"1.0.0",provides:["tiling"],requires:["render","scroll","viewport"],optional:[],defaultConfig:{enabled:!0,tileSize:768,overlapPx:2.5,extraRings:0}},r="UPDATE_VISIBLE_TILES",a="MARK_TILE_STATUS",l=e=>({type:r,payload:e}),o=(e,i,t)=>({type:a,payload:{pageIndex:e,tileId:i,status:t}});function n({tileSize:e=768,overlapPx:t=2.5,extraRings:s=0,scale:r,rotation:a,page:l,metric:o}){const n=l.size.width*r,c=l.size.height*r,d=e-t,h=i.transformSize(l.size,a,r),g={origin:{x:o.scaled.pageX,y:o.scaled.pageY},size:{width:o.scaled.visibleWidth,height:o.scaled.visibleHeight}},p=i.restoreRect(h,g,a,1),u=p.origin.x,f=p.origin.y,b=u+p.size.width,y=f+p.size.height,v=Math.floor((n-1)/d),x=Math.floor((c-1)/d),m=Math.max(0,Math.floor(u/d)-s),S=Math.min(v,Math.floor((b-1)/d)+s),T=Math.max(0,Math.floor(f/d)-s),P=Math.min(x,Math.floor((y-1)/d)+s),w=[];for(let i=m;i<=S;i++){const t=i*d,s=Math.min(e,n-t),a=t/r,o=s/r;for(let n=T;n<=P;n++){const h=n*d,g=Math.min(e,c-h),p=h/r,u=g/r;w.push({id:`p${l.index}-${r}-x${t}-y${h}-w${s}-h${g}`,col:i,row:n,pageRect:{origin:{x:a,y:p},size:{width:o,height:u}},screenRect:{origin:{x:t,y:h},size:{width:s,height:g}},status:"queued",srcScale:r,isFallback:!1})}}return w}const c=class extends e.BasePlugin{constructor(i,t,s){super(i,t),this.tileRendering$=e.createBehaviorEmitter(),this.refreshPages$=e.createEmitter(),this.config=s,this.renderCapability=this.registry.getPlugin("render").provides(),this.scrollCapability=this.registry.getPlugin("scroll").provides(),this.viewportCapability=this.registry.getPlugin("viewport").provides(),this.scrollCapability.onScroll((e=>this.calculateVisibleTiles(e)),{mode:"throttle",wait:500,throttleMode:"trailing"}),this.coreStore.onAction(e.REFRESH_PAGES,(e=>{this.refreshPages$.emit(e.payload)}))}async initialize(){}onCoreStoreUpdated(e,i){e.core.scale!==i.core.scale&&this.calculateVisibleTiles(this.scrollCapability.getMetrics(this.viewportCapability.getMetrics()))}onRefreshPages(e){return this.refreshPages$.on(e)}calculateVisibleTiles(e){var i;if(!this.config.enabled)return void this.dispatch(l([]));const t=this.coreState.core.scale,s=this.coreState.core.rotation,r={};for(const a of e.pageVisibilityMetrics){const e=a.pageNumber-1,l=null==(i=this.coreState.core.document)?void 0:i.pages[e];if(!l)continue;const o=n({page:l,metric:a,scale:t,rotation:s,tileSize:this.config.tileSize,overlapPx:this.config.overlapPx,extraRings:this.config.extraRings});r[e]=o}this.dispatch(l(r))}onStoreUpdated(e,i){this.tileRendering$.emit(i.visibleTiles)}buildCapability(){return{renderTile:this.renderTile.bind(this),onTileRendering:this.tileRendering$.on}}renderTile(e){if(!this.renderCapability)throw new Error("Render capability not available.");this.dispatch(o(e.pageIndex,e.tile.id,"rendering"));const t=this.renderCapability.renderPageRect({pageIndex:e.pageIndex,rect:e.tile.pageRect,options:{scaleFactor:e.tile.srcScale,dpr:e.dpr}});return t.wait((()=>{this.dispatch(o(e.pageIndex,e.tile.id,"ready"))}),i.ignore),t}};c.id="tiling";let d=c;const h={manifest:s,create:(e,i)=>new d(t,e,i),reducer:(e,i)=>((e,i)=>{var t,s;switch(i.type){case r:{const s=i.payload,r={...e.visibleTiles};for(const e in s){const i=Number(e),a=s[i],l=r[i]??[],o=null==(t=l.find((e=>!e.isFallback)))?void 0:t.srcScale,n=a[0].srcScale;if(void 0!==o&&o!==n){const e=l.filter((e=>!e.isFallback&&"ready"===e.status)).map((e=>({...e,isFallback:!0}))),t=e.length>0?[]:l.filter((e=>e.isFallback));r[i]=[...t,...e,...a]}else{const e=new Set(a.map((e=>e.id))),t=[],s=new Set;for(const i of l)(i.isFallback||e.has(i.id))&&(t.push(i),s.add(i.id));for(const i of a)s.has(i.id)||t.push(i);r[i]=t}}return{...e,visibleTiles:r}}case a:{const{pageIndex:t,tileId:r,status:a}=i.payload,l=(null==(s=e.visibleTiles[t])?void 0:s.map((e=>e.id===r?{...e,status:a}:e)))??[],o=l.filter((e=>!e.isFallback)),n=o.every((e=>"ready"===e.status))?o:l;return{...e,visibleTiles:{...e.visibleTiles,[t]:n}}}default:return e}})(e,i),initialState:{visibleTiles:{}}};exports.TILING_PLUGIN_ID=t,exports.TilingPlugin=d,exports.TilingPluginPackage=h,exports.manifest=s;
|
|
2
2
|
//# sourceMappingURL=index.cjs.map
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","sources":["../src/lib/manifest.ts","../src/lib/actions.ts","../src/lib/utils.ts","../src/lib/tiling-plugin.ts","../src/lib/index.ts","../src/lib/reducer.ts"],"sourcesContent":["import { PluginManifest } from '@embedpdf/core';\n\nimport { TilingPluginConfig } from './types';\n\nexport const TILING_PLUGIN_ID = 'tiling';\n\nexport const manifest: PluginManifest<TilingPluginConfig> = {\n id: TILING_PLUGIN_ID,\n name: 'Tiling Plugin',\n version: '1.0.0',\n provides: ['tiling'],\n requires: ['render', 'scroll', 'viewport'],\n optional: [],\n defaultConfig: {\n enabled: true,\n tileSize: 768,\n overlapPx: 2.5,\n extraRings: 0,\n },\n};\n","import { Tile, TileStatus } from './types';\n\nexport const UPDATE_VISIBLE_TILES = 'UPDATE_VISIBLE_TILES';\nexport const MARK_TILE_STATUS = 'MARK_TILE_STATUS';\n\nexport type UpdateVisibleTilesAction = {\n type: typeof UPDATE_VISIBLE_TILES;\n payload: Record<number, Tile[]>;\n};\n\nexport type MarkTileStatusAction = {\n type: typeof MARK_TILE_STATUS;\n payload: { pageIndex: number; tileId: string; status: TileStatus };\n};\n\nexport type TilingAction = UpdateVisibleTilesAction | MarkTileStatusAction;\n\nexport const updateVisibleTiles = (tiles: Record<number, Tile[]>): UpdateVisibleTilesAction => ({\n type: UPDATE_VISIBLE_TILES,\n payload: tiles,\n});\n\nexport const markTileStatus = (\n pageIndex: number,\n tileId: string,\n status: TileStatus,\n): MarkTileStatusAction => ({ type: MARK_TILE_STATUS, payload: { pageIndex, tileId, status } });\n","import { Rect, restoreRect, transformSize } from '@embedpdf/models';\nimport { CalculateTilesForPageOptions, Tile } from './types';\n\n/**\n * Build a grid where neighbouring tiles overlap by `overlapPx`\n * (screen pixels). Inner tiles keep the full `tileSize`, edge\n * tiles are clipped to the page bounds. All screen-space values\n * are rounded to **integers** to avoid sub-pixel seams.\n */\nexport function calculateTilesForPage({\n tileSize = 768,\n overlapPx = 2.5,\n extraRings = 0,\n scale,\n rotation,\n page,\n metric,\n}: CalculateTilesForPageOptions): Tile[] {\n /* ---- work in screen-pixel space -------------------------------- */\n const pageW = page.size.width * scale; // px\n const pageH = page.size.height * scale; // px\n\n const step = tileSize - overlapPx; // shift between tiles\n\n const containerSize = transformSize(page.size, rotation, scale);\n const rotatedVisRect: Rect = {\n origin: { x: metric.scaled.pageX, y: metric.scaled.pageY },\n size: { width: metric.scaled.visibleWidth, height: metric.scaled.visibleHeight },\n };\n const unrotatedVisRect = restoreRect(containerSize, rotatedVisRect, rotation, 1);\n\n const visLeft = unrotatedVisRect.origin.x;\n const visTop = unrotatedVisRect.origin.y;\n const visRight = visLeft + unrotatedVisRect.size.width;\n const visBottom = visTop + unrotatedVisRect.size.height;\n\n const maxCol = Math.floor((pageW - 1) / step);\n const maxRow = Math.floor((pageH - 1) / step);\n\n const startCol = Math.max(0, Math.floor(visLeft / step) - extraRings);\n const endCol = Math.min(maxCol, Math.floor((visRight - 1) / step) + extraRings);\n const startRow = Math.max(0, Math.floor(visTop / step) - extraRings);\n const endRow = Math.min(maxRow, Math.floor((visBottom - 1) / step) + extraRings);\n\n /* ---- build tiles ---------------------------------------------- */\n const tiles: Tile[] = [];\n\n for (let col = startCol; col <= endCol; col++) {\n const xScreen = col * step; // px (integer)\n const wScreen = Math.min(tileSize, pageW - xScreen); // px (≤ tileSize)\n\n const xPage = xScreen / scale; // pt (may be frac.)\n const wPage = wScreen / scale; // pt\n\n for (let row = startRow; row <= endRow; row++) {\n const yScreen = row * step;\n const hScreen = Math.min(tileSize, pageH - yScreen);\n\n const yPage = yScreen / scale;\n const hPage = hScreen / scale;\n\n tiles.push({\n id: `p${page.index}-${scale}-x${xScreen}-y${yScreen}-w${wScreen}-h${hScreen}`,\n col,\n row,\n pageRect: { origin: { x: xPage, y: yPage }, size: { width: wPage, height: hPage } },\n screenRect: {\n origin: { x: xScreen, y: yScreen },\n size: { width: wScreen, height: hScreen },\n },\n status: 'queued',\n srcScale: scale,\n isFallback: false,\n });\n }\n }\n\n return tiles;\n}\n","import {\n BasePlugin,\n CoreState,\n createBehaviorEmitter,\n PluginRegistry,\n StoreState,\n} from '@embedpdf/core';\nimport { ignore } from '@embedpdf/models';\nimport { RenderCapability, RenderPlugin } from '@embedpdf/plugin-render';\nimport { ScrollCapability, ScrollMetrics, ScrollPlugin } from '@embedpdf/plugin-scroll';\nimport { ViewportCapability, ViewportPlugin } from '@embedpdf/plugin-viewport';\n\nimport { markTileStatus, updateVisibleTiles } from './actions';\nimport {\n TilingPluginConfig,\n TilingCapability,\n Tile,\n RenderTileOptions,\n TilingState,\n} from './types';\nimport { calculateTilesForPage } from './utils';\n\nexport class TilingPlugin extends BasePlugin<TilingPluginConfig, TilingCapability> {\n static readonly id = 'tiling' as const;\n\n private readonly tileRendering$ = createBehaviorEmitter<Record<number, Tile[]>>();\n\n private config: TilingPluginConfig;\n private renderCapability: RenderCapability;\n private scrollCapability: ScrollCapability;\n private viewportCapability: ViewportCapability;\n\n constructor(id: string, registry: PluginRegistry, config: TilingPluginConfig) {\n super(id, registry);\n\n this.config = config;\n\n this.renderCapability = this.registry.getPlugin<RenderPlugin>('render')!.provides();\n this.scrollCapability = this.registry.getPlugin<ScrollPlugin>('scroll')!.provides();\n this.viewportCapability = this.registry.getPlugin<ViewportPlugin>('viewport')!.provides();\n\n this.scrollCapability.onScroll((scrollMetrics) => this.calculateVisibleTiles(scrollMetrics), {\n mode: 'throttle',\n wait: 500,\n throttleMode: 'trailing',\n });\n }\n\n async initialize(): Promise<void> {\n // Fetch dependencies from the registry if needed\n }\n\n protected onCoreStoreUpdated(\n oldState: StoreState<CoreState>,\n newState: StoreState<CoreState>,\n ): void {\n if (oldState.core.scale !== newState.core.scale) {\n this.calculateVisibleTiles(\n this.scrollCapability.getMetrics(this.viewportCapability.getMetrics()),\n );\n }\n }\n\n private calculateVisibleTiles(scrollMetrics: ScrollMetrics): void {\n if (!this.config.enabled) {\n this.dispatch(updateVisibleTiles([]));\n return;\n }\n\n const scale = this.coreState.core.scale;\n const rotation = this.coreState.core.rotation;\n const visibleTiles: { [pageIndex: number]: Tile[] } = {};\n\n for (const scrollMetric of scrollMetrics.pageVisibilityMetrics) {\n const pageIndex = scrollMetric.pageNumber - 1; // Convert to 0-based index\n const page = this.coreState.core.document?.pages[pageIndex];\n if (!page) continue;\n\n // Calculate tiles for the page using the utility function\n const tiles = calculateTilesForPage({\n page,\n metric: scrollMetric,\n scale,\n rotation,\n tileSize: this.config.tileSize,\n overlapPx: this.config.overlapPx,\n extraRings: this.config.extraRings,\n });\n\n visibleTiles[pageIndex] = tiles;\n }\n\n this.dispatch(updateVisibleTiles(visibleTiles));\n }\n\n override onStoreUpdated(_prevState: TilingState, newState: TilingState): void {\n this.tileRendering$.emit(newState.visibleTiles);\n }\n\n protected buildCapability(): TilingCapability {\n return {\n renderTile: this.renderTile.bind(this),\n onTileRendering: this.tileRendering$.on,\n };\n }\n\n private renderTile(options: RenderTileOptions) {\n if (!this.renderCapability) {\n throw new Error('Render capability not available.');\n }\n\n this.dispatch(markTileStatus(options.pageIndex, options.tile.id, 'rendering'));\n\n const task = this.renderCapability.renderPageRect({\n pageIndex: options.pageIndex,\n rect: options.tile.pageRect,\n scaleFactor: options.tile.srcScale,\n dpr: options.dpr,\n });\n\n task.wait(() => {\n this.dispatch(markTileStatus(options.pageIndex, options.tile.id, 'ready'));\n }, ignore);\n\n return task;\n }\n}\n","import { PluginPackage } from '@embedpdf/core';\n\nimport { TilingAction } from './actions';\nimport { manifest, TILING_PLUGIN_ID } from './manifest';\nimport { initialState, tilingReducer } from './reducer';\nimport { TilingPlugin } from './tiling-plugin';\nimport { TilingPluginConfig, TilingState } from './types';\n\nexport const TilingPluginPackage: PluginPackage<\n TilingPlugin,\n TilingPluginConfig,\n TilingState,\n TilingAction\n> = {\n manifest,\n create: (registry, _engine, config) => new TilingPlugin(TILING_PLUGIN_ID, registry, config),\n reducer: (state, action) => tilingReducer(state, action),\n initialState,\n};\n\nexport * from './tiling-plugin';\nexport * from './types';\nexport * from './manifest';\n","import { Reducer } from '@embedpdf/core';\n\nimport { UPDATE_VISIBLE_TILES, MARK_TILE_STATUS, TilingAction } from './actions';\nimport { Tile, TilingState } from './types';\n\nexport const initialState: TilingState = {\n visibleTiles: {},\n};\n\nexport const tilingReducer: Reducer<TilingState, TilingAction> = (state, action) => {\n switch (action.type) {\n case UPDATE_VISIBLE_TILES: {\n const incoming = action.payload; // Record<number, Tile[]>\n const nextPages = { ...state.visibleTiles };\n\n for (const key in incoming) {\n const pageIndex = Number(key);\n const newTiles = incoming[pageIndex]; // all isFallback=false\n const prevTiles = nextPages[pageIndex] ?? [];\n\n const prevScale = prevTiles.find((t) => !t.isFallback)?.srcScale;\n const newScale = newTiles[0].srcScale;\n const zoomChanged = prevScale !== undefined && prevScale !== newScale;\n\n if (zoomChanged) {\n /* 1️⃣ ready tiles from the old zoom → new fallback */\n const promoted = prevTiles\n .filter((t) => !t.isFallback && t.status === 'ready')\n .map((t) => ({ ...t, isFallback: true }));\n\n /* 2️⃣ decide which fallback tiles to keep */\n const fallbackToCarry = promoted.length > 0 ? [] : prevTiles.filter((t) => t.isFallback);\n\n /* 3️⃣ final list = (maybe-kept fallback) + promoted + newTiles */\n nextPages[pageIndex] = [...fallbackToCarry, ...promoted, ...newTiles];\n } else {\n /* same zoom → keep current fallback, replace visible */\n const newIds = new Set(newTiles.map((t) => t.id));\n const keepers: Tile[] = []; // where we’ll collect surviving tiles\n const seenIds = new Set<string>();\n\n /* 2️⃣ loop prevTiles once */\n for (const t of prevTiles) {\n if (t.isFallback) {\n keepers.push(t); // always keep fallback\n seenIds.add(t.id);\n } else if (newIds.has(t.id)) {\n keepers.push(t); // keep old visible tile (preserves status)\n seenIds.add(t.id);\n }\n }\n\n /* 3️⃣ append *brand-new* tiles (not yet kept) */\n for (const t of newTiles) {\n if (!seenIds.has(t.id)) keepers.push(t);\n }\n\n /* 4️⃣ store result */\n nextPages[pageIndex] = keepers;\n }\n }\n\n return { ...state, visibleTiles: nextPages };\n }\n\n case MARK_TILE_STATUS: {\n const { pageIndex, tileId, status } = action.payload;\n const tiles =\n state.visibleTiles[pageIndex]?.map((t) =>\n t.id === tileId ? ({ ...t, status } as Tile) : t,\n ) ?? [];\n\n const newTiles = tiles.filter((t) => !t.isFallback);\n const allReady = newTiles.every((t) => t.status === 'ready');\n const finalTiles = allReady ? newTiles : tiles;\n\n return {\n ...state,\n visibleTiles: { ...state.visibleTiles, [pageIndex]: finalTiles },\n };\n }\n\n default:\n return state;\n }\n};\n"],"names":["TILING_PLUGIN_ID","manifest","id","name","version","provides","requires","optional","defaultConfig","enabled","tileSize","overlapPx","extraRings","UPDATE_VISIBLE_TILES","MARK_TILE_STATUS","updateVisibleTiles","tiles","type","payload","markTileStatus","pageIndex","tileId","status","calculateTilesForPage","scale","rotation","page","metric","pageW","size","width","pageH","height","step","containerSize","transformSize","rotatedVisRect","origin","x","scaled","pageX","y","pageY","visibleWidth","visibleHeight","unrotatedVisRect","restoreRect","visLeft","visTop","visRight","visBottom","maxCol","Math","floor","maxRow","startCol","max","endCol","min","startRow","endRow","col","xScreen","wScreen","xPage","wPage","row","yScreen","hScreen","yPage","hPage","push","index","pageRect","screenRect","srcScale","isFallback","_TilingPlugin","BasePlugin","constructor","registry","config","super","this","tileRendering$","createBehaviorEmitter","renderCapability","getPlugin","scrollCapability","viewportCapability","onScroll","scrollMetrics","calculateVisibleTiles","mode","wait","throttleMode","initialize","onCoreStoreUpdated","oldState","newState","core","getMetrics","dispatch","coreState","visibleTiles","scrollMetric","pageVisibilityMetrics","pageNumber","_a","document","pages","onStoreUpdated","_prevState","emit","buildCapability","renderTile","bind","onTileRendering","on","options","Error","tile","task","renderPageRect","rect","scaleFactor","dpr","ignore","TilingPlugin","TilingPluginPackage","create","_engine","reducer","state","action","incoming","nextPages","key","Number","newTiles","prevTiles","prevScale","find","t","newScale","promoted","filter","map","fallbackToCarry","length","newIds","Set","keepers","seenIds","has","add","_b","finalTiles","every","tilingReducer","initialState"],"mappings":"gJAIaA,EAAmB,SAEnBC,EAA+C,CAC1DC,GAAIF,EACJG,KAAM,gBACNC,QAAS,QACTC,SAAU,CAAC,UACXC,SAAU,CAAC,SAAU,SAAU,YAC/BC,SAAU,GACVC,cAAe,CACbC,SAAS,EACTC,SAAU,IACVC,UAAW,IACXC,WAAY,ICfHC,EAAuB,uBACvBC,EAAmB,mBAcnBC,EAAsBC,IAA6D,CAC9FC,KAAMJ,EACNK,QAASF,IAGEG,EAAiB,CAC5BC,EACAC,EACAC,KAC0B,CAAEL,KAAMH,EAAkBI,QAAS,CAAEE,YAAWC,SAAQC,YCjB7E,SAASC,GAAsBb,SACpCA,EAAW,IAAAC,UACXA,EAAY,IAAAC,WACZA,EAAa,EAAAY,MACbA,EAAAC,SACAA,EAAAC,KACAA,EAAAC,OACAA,IAGM,MAAAC,EAAQF,EAAKG,KAAKC,MAAQN,EAC1BO,EAAQL,EAAKG,KAAKG,OAASR,EAE3BS,EAAOvB,EAAWC,EAElBuB,EAAgBC,EAAAA,cAAcT,EAAKG,KAAMJ,EAAUD,GACnDY,EAAuB,CAC3BC,OAAQ,CAAEC,EAAGX,EAAOY,OAAOC,MAAOC,EAAGd,EAAOY,OAAOG,OACnDb,KAAM,CAAEC,MAAOH,EAAOY,OAAOI,aAAcX,OAAQL,EAAOY,OAAOK,gBAE7DC,EAAmBC,EAAAA,YAAYZ,EAAeE,EAAgBX,EAAU,GAExEsB,EAAUF,EAAiBR,OAAOC,EAClCU,EAASH,EAAiBR,OAAOI,EACjCQ,EAAWF,EAAUF,EAAiBhB,KAAKC,MAC3CoB,EAAYF,EAASH,E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,aAGnE4D,EAAApH,GAAa,IAAIgI,KAAoBH,KAAaN,EAAQ,KAC/D,CAEC,MAAAW,EAAS,IAAIC,IAAIZ,EAASQ,KAAKJ,GAAMA,EAAE7I,MACvCsJ,EAAkB,GAClBC,MAAcF,IAGpB,IAAA,MAAWR,KAAKH,GACVG,EAAEnE,YAGK0E,EAAOI,IAAIX,EAAE7I,OAFtBsJ,EAAQjF,KAAKwE,GACLU,EAAAE,IAAIZ,EAAE7I,KAQlB,IAAA,MAAW6I,KAAKJ,EACTc,EAAQC,IAAIX,EAAE7I,KAAKsJ,EAAQjF,KAAKwE,GAIvCP,EAAUpH,GAAaoI,CAAA,CACzB,CAGF,MAAO,IAAKnB,EAAO7B,aAAcgC,EAAU,CAG7C,KAAK1H,EAAkB,CACrB,MAAMM,UAAEA,EAAAC,OAAWA,EAAQC,OAAAA,GAAWgH,EAAOpH,QACvCF,GACJ,OAAA4I,EAAAvB,EAAM7B,aAAapF,SAAY,EAAAwI,EAAAT,KAAKJ,GAClCA,EAAE7I,KAAOmB,EAAU,IAAK0H,EAAGzH,UAAoByH,MAC5C,GAEDJ,EAAW3H,EAAMkI,QAAQH,IAAOA,EAAEnE,aAElCiF,EADWlB,EAASmB,OAAOf,GAAmB,UAAbA,EAAEzH,SACXqH,EAAW3H,EAElC,MAAA,IACFqH,EACH7B,aAAc,IAAK6B,EAAM7B,aAAcpF,CAACA,GAAYyI,GACtD,CAGF,QACS,OAAAxB,EAAA,EDnEiB0B,CAAc1B,EAAOC,GACjD0B,aCZuC,CACvCxD,aAAc,CAAA"}
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":["../src/lib/manifest.ts","../src/lib/actions.ts","../src/lib/utils.ts","../src/lib/tiling-plugin.ts","../src/lib/index.ts","../src/lib/reducer.ts"],"sourcesContent":["import { PluginManifest } from '@embedpdf/core';\n\nimport { TilingPluginConfig } from './types';\n\nexport const TILING_PLUGIN_ID = 'tiling';\n\nexport const manifest: PluginManifest<TilingPluginConfig> = {\n id: TILING_PLUGIN_ID,\n name: 'Tiling Plugin',\n version: '1.0.0',\n provides: ['tiling'],\n requires: ['render', 'scroll', 'viewport'],\n optional: [],\n defaultConfig: {\n enabled: true,\n tileSize: 768,\n overlapPx: 2.5,\n extraRings: 0,\n },\n};\n","import { Tile, TileStatus } from './types';\n\nexport const UPDATE_VISIBLE_TILES = 'UPDATE_VISIBLE_TILES';\nexport const MARK_TILE_STATUS = 'MARK_TILE_STATUS';\n\nexport type UpdateVisibleTilesAction = {\n type: typeof UPDATE_VISIBLE_TILES;\n payload: Record<number, Tile[]>;\n};\n\nexport type MarkTileStatusAction = {\n type: typeof MARK_TILE_STATUS;\n payload: { pageIndex: number; tileId: string; status: TileStatus };\n};\n\nexport type TilingAction = UpdateVisibleTilesAction | MarkTileStatusAction;\n\nexport const updateVisibleTiles = (tiles: Record<number, Tile[]>): UpdateVisibleTilesAction => ({\n type: UPDATE_VISIBLE_TILES,\n payload: tiles,\n});\n\nexport const markTileStatus = (\n pageIndex: number,\n tileId: string,\n status: TileStatus,\n): MarkTileStatusAction => ({ type: MARK_TILE_STATUS, payload: { pageIndex, tileId, status } });\n","import { Rect, restoreRect, transformSize } from '@embedpdf/models';\nimport { CalculateTilesForPageOptions, Tile } from './types';\n\n/**\n * Build a grid where neighbouring tiles overlap by `overlapPx`\n * (screen pixels). Inner tiles keep the full `tileSize`, edge\n * tiles are clipped to the page bounds. All screen-space values\n * are rounded to **integers** to avoid sub-pixel seams.\n */\nexport function calculateTilesForPage({\n tileSize = 768,\n overlapPx = 2.5,\n extraRings = 0,\n scale,\n rotation,\n page,\n metric,\n}: CalculateTilesForPageOptions): Tile[] {\n /* ---- work in screen-pixel space -------------------------------- */\n const pageW = page.size.width * scale; // px\n const pageH = page.size.height * scale; // px\n\n const step = tileSize - overlapPx; // shift between tiles\n\n const containerSize = transformSize(page.size, rotation, scale);\n const rotatedVisRect: Rect = {\n origin: { x: metric.scaled.pageX, y: metric.scaled.pageY },\n size: { width: metric.scaled.visibleWidth, height: metric.scaled.visibleHeight },\n };\n const unrotatedVisRect = restoreRect(containerSize, rotatedVisRect, rotation, 1);\n\n const visLeft = unrotatedVisRect.origin.x;\n const visTop = unrotatedVisRect.origin.y;\n const visRight = visLeft + unrotatedVisRect.size.width;\n const visBottom = visTop + unrotatedVisRect.size.height;\n\n const maxCol = Math.floor((pageW - 1) / step);\n const maxRow = Math.floor((pageH - 1) / step);\n\n const startCol = Math.max(0, Math.floor(visLeft / step) - extraRings);\n const endCol = Math.min(maxCol, Math.floor((visRight - 1) / step) + extraRings);\n const startRow = Math.max(0, Math.floor(visTop / step) - extraRings);\n const endRow = Math.min(maxRow, Math.floor((visBottom - 1) / step) + extraRings);\n\n /* ---- build tiles ---------------------------------------------- */\n const tiles: Tile[] = [];\n\n for (let col = startCol; col <= endCol; col++) {\n const xScreen = col * step; // px (integer)\n const wScreen = Math.min(tileSize, pageW - xScreen); // px (≤ tileSize)\n\n const xPage = xScreen / scale; // pt (may be frac.)\n const wPage = wScreen / scale; // pt\n\n for (let row = startRow; row <= endRow; row++) {\n const yScreen = row * step;\n const hScreen = Math.min(tileSize, pageH - yScreen);\n\n const yPage = yScreen / scale;\n const hPage = hScreen / scale;\n\n tiles.push({\n id: `p${page.index}-${scale}-x${xScreen}-y${yScreen}-w${wScreen}-h${hScreen}`,\n col,\n row,\n pageRect: { origin: { x: xPage, y: yPage }, size: { width: wPage, height: hPage } },\n screenRect: {\n origin: { x: xScreen, y: yScreen },\n size: { width: wScreen, height: hScreen },\n },\n status: 'queued',\n srcScale: scale,\n isFallback: false,\n });\n }\n }\n\n return tiles;\n}\n","import {\n BasePlugin,\n CoreState,\n createBehaviorEmitter,\n createEmitter,\n PluginRegistry,\n REFRESH_PAGES,\n StoreState,\n Unsubscribe,\n} from '@embedpdf/core';\nimport { ignore } from '@embedpdf/models';\nimport { RenderCapability, RenderPlugin } from '@embedpdf/plugin-render';\nimport { ScrollCapability, ScrollMetrics, ScrollPlugin } from '@embedpdf/plugin-scroll';\nimport { ViewportCapability, ViewportPlugin } from '@embedpdf/plugin-viewport';\n\nimport { markTileStatus, updateVisibleTiles } from './actions';\nimport {\n TilingPluginConfig,\n TilingCapability,\n Tile,\n RenderTileOptions,\n TilingState,\n} from './types';\nimport { calculateTilesForPage } from './utils';\n\nexport class TilingPlugin extends BasePlugin<TilingPluginConfig, TilingCapability> {\n static readonly id = 'tiling' as const;\n\n private readonly tileRendering$ = createBehaviorEmitter<Record<number, Tile[]>>();\n private readonly refreshPages$ = createEmitter<number[]>();\n\n private config: TilingPluginConfig;\n private renderCapability: RenderCapability;\n private scrollCapability: ScrollCapability;\n private viewportCapability: ViewportCapability;\n\n constructor(id: string, registry: PluginRegistry, config: TilingPluginConfig) {\n super(id, registry);\n\n this.config = config;\n\n this.renderCapability = this.registry.getPlugin<RenderPlugin>('render')!.provides();\n this.scrollCapability = this.registry.getPlugin<ScrollPlugin>('scroll')!.provides();\n this.viewportCapability = this.registry.getPlugin<ViewportPlugin>('viewport')!.provides();\n\n this.scrollCapability.onScroll((scrollMetrics) => this.calculateVisibleTiles(scrollMetrics), {\n mode: 'throttle',\n wait: 500,\n throttleMode: 'trailing',\n });\n\n this.coreStore.onAction(REFRESH_PAGES, (action) => {\n this.refreshPages$.emit(action.payload);\n });\n }\n\n async initialize(): Promise<void> {\n // Fetch dependencies from the registry if needed\n }\n\n protected onCoreStoreUpdated(\n oldState: StoreState<CoreState>,\n newState: StoreState<CoreState>,\n ): void {\n if (oldState.core.scale !== newState.core.scale) {\n this.calculateVisibleTiles(\n this.scrollCapability.getMetrics(this.viewportCapability.getMetrics()),\n );\n }\n }\n\n public onRefreshPages(fn: (pages: number[]) => void): Unsubscribe {\n return this.refreshPages$.on(fn);\n }\n\n private calculateVisibleTiles(scrollMetrics: ScrollMetrics): void {\n if (!this.config.enabled) {\n this.dispatch(updateVisibleTiles([]));\n return;\n }\n\n const scale = this.coreState.core.scale;\n const rotation = this.coreState.core.rotation;\n const visibleTiles: { [pageIndex: number]: Tile[] } = {};\n\n for (const scrollMetric of scrollMetrics.pageVisibilityMetrics) {\n const pageIndex = scrollMetric.pageNumber - 1; // Convert to 0-based index\n const page = this.coreState.core.document?.pages[pageIndex];\n if (!page) continue;\n\n // Calculate tiles for the page using the utility function\n const tiles = calculateTilesForPage({\n page,\n metric: scrollMetric,\n scale,\n rotation,\n tileSize: this.config.tileSize,\n overlapPx: this.config.overlapPx,\n extraRings: this.config.extraRings,\n });\n\n visibleTiles[pageIndex] = tiles;\n }\n\n this.dispatch(updateVisibleTiles(visibleTiles));\n }\n\n override onStoreUpdated(_prevState: TilingState, newState: TilingState): void {\n this.tileRendering$.emit(newState.visibleTiles);\n }\n\n protected buildCapability(): TilingCapability {\n return {\n renderTile: this.renderTile.bind(this),\n onTileRendering: this.tileRendering$.on,\n };\n }\n\n private renderTile(options: RenderTileOptions) {\n if (!this.renderCapability) {\n throw new Error('Render capability not available.');\n }\n\n this.dispatch(markTileStatus(options.pageIndex, options.tile.id, 'rendering'));\n\n const task = this.renderCapability.renderPageRect({\n pageIndex: options.pageIndex,\n rect: options.tile.pageRect,\n options: {\n scaleFactor: options.tile.srcScale,\n dpr: options.dpr,\n },\n });\n\n task.wait(() => {\n this.dispatch(markTileStatus(options.pageIndex, options.tile.id, 'ready'));\n }, ignore);\n\n return task;\n }\n}\n","import { PluginPackage } from '@embedpdf/core';\n\nimport { TilingAction } from './actions';\nimport { manifest, TILING_PLUGIN_ID } from './manifest';\nimport { initialState, tilingReducer } from './reducer';\nimport { TilingPlugin } from './tiling-plugin';\nimport { TilingPluginConfig, TilingState } from './types';\n\nexport const TilingPluginPackage: PluginPackage<\n TilingPlugin,\n TilingPluginConfig,\n TilingState,\n TilingAction\n> = {\n manifest,\n create: (registry, config) => new TilingPlugin(TILING_PLUGIN_ID, registry, config),\n reducer: (state, action) => tilingReducer(state, action),\n initialState,\n};\n\nexport * from './tiling-plugin';\nexport * from './types';\nexport * from './manifest';\n","import { Reducer } from '@embedpdf/core';\n\nimport { UPDATE_VISIBLE_TILES, MARK_TILE_STATUS, TilingAction } from './actions';\nimport { Tile, TilingState } from './types';\n\nexport const initialState: TilingState = {\n visibleTiles: {},\n};\n\nexport const tilingReducer: Reducer<TilingState, TilingAction> = (state, action) => {\n switch (action.type) {\n case UPDATE_VISIBLE_TILES: {\n const incoming = action.payload; // Record<number, Tile[]>\n const nextPages = { ...state.visibleTiles };\n\n for (const key in incoming) {\n const pageIndex = Number(key);\n const newTiles = incoming[pageIndex]; // all isFallback=false\n const prevTiles = nextPages[pageIndex] ?? [];\n\n const prevScale = prevTiles.find((t) => !t.isFallback)?.srcScale;\n const newScale = newTiles[0].srcScale;\n const zoomChanged = prevScale !== undefined && prevScale !== newScale;\n\n if (zoomChanged) {\n /* 1️⃣ ready tiles from the old zoom → new fallback */\n const promoted = prevTiles\n .filter((t) => !t.isFallback && t.status === 'ready')\n .map((t) => ({ ...t, isFallback: true }));\n\n /* 2️⃣ decide which fallback tiles to keep */\n const fallbackToCarry = promoted.length > 0 ? [] : prevTiles.filter((t) => t.isFallback);\n\n /* 3️⃣ final list = (maybe-kept fallback) + promoted + newTiles */\n nextPages[pageIndex] = [...fallbackToCarry, ...promoted, ...newTiles];\n } else {\n /* same zoom → keep current fallback, replace visible */\n const newIds = new Set(newTiles.map((t) => t.id));\n const keepers: Tile[] = []; // where we’ll collect surviving tiles\n const seenIds = new Set<string>();\n\n /* 2️⃣ loop prevTiles once */\n for (const t of prevTiles) {\n if (t.isFallback) {\n keepers.push(t); // always keep fallback\n seenIds.add(t.id);\n } else if (newIds.has(t.id)) {\n keepers.push(t); // keep old visible tile (preserves status)\n seenIds.add(t.id);\n }\n }\n\n /* 3️⃣ append *brand-new* tiles (not yet kept) */\n for (const t of newTiles) {\n if (!seenIds.has(t.id)) keepers.push(t);\n }\n\n /* 4️⃣ store result */\n nextPages[pageIndex] = keepers;\n }\n }\n\n return { ...state, visibleTiles: nextPages };\n }\n\n case MARK_TILE_STATUS: {\n const { pageIndex, tileId, status } = action.payload;\n const tiles =\n state.visibleTiles[pageIndex]?.map((t) =>\n t.id === tileId ? ({ ...t, status } as Tile) : t,\n ) ?? [];\n\n const newTiles = tiles.filter((t) => !t.isFallback);\n const allReady = newTiles.every((t) => t.status === 'ready');\n const finalTiles = allReady ? newTiles : tiles;\n\n return {\n ...state,\n visibleTiles: { ...state.visibleTiles, [pageIndex]: finalTiles },\n };\n }\n\n default:\n return state;\n }\n};\n"],"names":["TILING_PLUGIN_ID","manifest","id","name","version","provides","requires","optional","defaultConfig","enabled","tileSize","overlapPx","extraRings","UPDATE_VISIBLE_TILES","MARK_TILE_STATUS","updateVisibleTiles","tiles","type","payload","markTileStatus","pageIndex","tileId","status","calculateTilesForPage","scale","rotation","page","metric","pageW","size","width","pageH","height","step","containerSize","transformSize","rotatedVisRect","origin","x","scaled","pageX","y","pageY","visibleWidth","visibleHeight","unrotatedVisRect","restoreRect","visLeft","visTop","visRight","visBottom","maxCol","Math","floor","maxRow","startCol","max","endCol","min","startRow","endRow","col","xScreen","wScreen","xPage","wPage","row","yScreen","hScreen","yPage","hPage","push","index","pageRect","screenRect","srcScale","isFallback","_TilingPlugin","BasePlugin","constructor","registry","config","super","this","tileRendering$","createBehaviorEmitter","refreshPages$","createEmitter","renderCapability","getPlugin","scrollCapability","viewportCapability","onScroll","scrollMetrics","calculateVisibleTiles","mode","wait","throttleMode","coreStore","onAction","REFRESH_PAGES","action","emit","initialize","onCoreStoreUpdated","oldState","newState","core","getMetrics","onRefreshPages","fn","on","dispatch","coreState","visibleTiles","scrollMetric","pageVisibilityMetrics","pageNumber","_a","document","pages","onStoreUpdated","_prevState","buildCapability","renderTile","bind","onTileRendering","options","Error","tile","task","renderPageRect","rect","scaleFactor","dpr","ignore","TilingPlugin","TilingPluginPackage","create","reducer","state","incoming","nextPages","key","Number","newTiles","prevTiles","prevScale","find","t","newScale","promoted","filter","map","fallbackToCarry","length","newIds","Set","keepers","seenIds","has","add","_b","finalTiles","every","tilingReducer","initialState"],"mappings":"gJAI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IsI,KAAoBH,KAAaN,EAAQ,KAC/D,CAEC,MAAAW,EAAS,IAAIC,IAAIZ,EAASQ,KAAKJ,GAAMA,EAAEnJ,MACvC4J,EAAkB,GAClBC,MAAcF,IAGpB,IAAA,MAAWR,KAAKH,GACVG,EAAEzE,YAGKgF,EAAOI,IAAIX,EAAEnJ,OAFtB4J,EAAQvF,KAAK8E,GACLU,EAAAE,IAAIZ,EAAEnJ,KAQlB,IAAA,MAAWmJ,KAAKJ,EACTc,EAAQC,IAAIX,EAAEnJ,KAAK4J,EAAQvF,KAAK8E,GAIvCP,EAAU1H,GAAa0I,CAAA,CACzB,CAGF,MAAO,IAAKlB,EAAO1B,aAAc4B,EAAU,CAG7C,KAAKhI,EAAkB,CACrB,MAAMM,UAAEA,EAAAC,OAAWA,EAAQC,OAAAA,GAAW+E,EAAOnF,QACvCF,GACJ,OAAAkJ,EAAAtB,EAAM1B,aAAa9F,SAAY,EAAA8I,EAAAT,KAAKJ,GAClCA,EAAEnJ,KAAOmB,EAAU,IAAKgI,EAAG/H,UAAoB+H,MAC5C,GAEDJ,EAAWjI,EAAMwI,QAAQH,IAAOA,EAAEzE,aAElCuF,EADWlB,EAASmB,OAAOf,GAAmB,UAAbA,EAAE/H,SACX2H,EAAWjI,EAElC,MAAA,IACF4H,EACH1B,aAAc,IAAK0B,EAAM1B,aAAc9F,CAACA,GAAY+I,GACtD,CAGF,QACS,OAAAvB,EAAA,EDnEiByB,CAAczB,EAAOvC,GACjDiE,aCZuC,CACvCpD,aAAc,CAAA"}
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { BasePlugin, createBehaviorEmitter } from "@embedpdf/core";
|
|
1
|
+
import { BasePlugin, createBehaviorEmitter, createEmitter, REFRESH_PAGES } from "@embedpdf/core";
|
|
2
2
|
import { transformSize, restoreRect, ignore } from "@embedpdf/models";
|
|
3
3
|
const TILING_PLUGIN_ID = "tiling";
|
|
4
4
|
const manifest = {
|
|
@@ -140,6 +140,7 @@ const _TilingPlugin = class _TilingPlugin extends BasePlugin {
|
|
|
140
140
|
constructor(id, registry, config) {
|
|
141
141
|
super(id, registry);
|
|
142
142
|
this.tileRendering$ = createBehaviorEmitter();
|
|
143
|
+
this.refreshPages$ = createEmitter();
|
|
143
144
|
this.config = config;
|
|
144
145
|
this.renderCapability = this.registry.getPlugin("render").provides();
|
|
145
146
|
this.scrollCapability = this.registry.getPlugin("scroll").provides();
|
|
@@ -149,6 +150,9 @@ const _TilingPlugin = class _TilingPlugin extends BasePlugin {
|
|
|
149
150
|
wait: 500,
|
|
150
151
|
throttleMode: "trailing"
|
|
151
152
|
});
|
|
153
|
+
this.coreStore.onAction(REFRESH_PAGES, (action) => {
|
|
154
|
+
this.refreshPages$.emit(action.payload);
|
|
155
|
+
});
|
|
152
156
|
}
|
|
153
157
|
async initialize() {
|
|
154
158
|
}
|
|
@@ -159,6 +163,9 @@ const _TilingPlugin = class _TilingPlugin extends BasePlugin {
|
|
|
159
163
|
);
|
|
160
164
|
}
|
|
161
165
|
}
|
|
166
|
+
onRefreshPages(fn) {
|
|
167
|
+
return this.refreshPages$.on(fn);
|
|
168
|
+
}
|
|
162
169
|
calculateVisibleTiles(scrollMetrics) {
|
|
163
170
|
var _a;
|
|
164
171
|
if (!this.config.enabled) {
|
|
@@ -202,8 +209,10 @@ const _TilingPlugin = class _TilingPlugin extends BasePlugin {
|
|
|
202
209
|
const task = this.renderCapability.renderPageRect({
|
|
203
210
|
pageIndex: options.pageIndex,
|
|
204
211
|
rect: options.tile.pageRect,
|
|
205
|
-
|
|
206
|
-
|
|
212
|
+
options: {
|
|
213
|
+
scaleFactor: options.tile.srcScale,
|
|
214
|
+
dpr: options.dpr
|
|
215
|
+
}
|
|
207
216
|
});
|
|
208
217
|
task.wait(() => {
|
|
209
218
|
this.dispatch(markTileStatus(options.pageIndex, options.tile.id, "ready"));
|
|
@@ -215,7 +224,7 @@ _TilingPlugin.id = "tiling";
|
|
|
215
224
|
let TilingPlugin = _TilingPlugin;
|
|
216
225
|
const TilingPluginPackage = {
|
|
217
226
|
manifest,
|
|
218
|
-
create: (registry,
|
|
227
|
+
create: (registry, config) => new TilingPlugin(TILING_PLUGIN_ID, registry, config),
|
|
219
228
|
reducer: (state, action) => tilingReducer(state, action),
|
|
220
229
|
initialState
|
|
221
230
|
};
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../src/lib/manifest.ts","../src/lib/actions.ts","../src/lib/reducer.ts","../src/lib/utils.ts","../src/lib/tiling-plugin.ts","../src/lib/index.ts"],"sourcesContent":["import { PluginManifest } from '@embedpdf/core';\n\nimport { TilingPluginConfig } from './types';\n\nexport const TILING_PLUGIN_ID = 'tiling';\n\nexport const manifest: PluginManifest<TilingPluginConfig> = {\n id: TILING_PLUGIN_ID,\n name: 'Tiling Plugin',\n version: '1.0.0',\n provides: ['tiling'],\n requires: ['render', 'scroll', 'viewport'],\n optional: [],\n defaultConfig: {\n enabled: true,\n tileSize: 768,\n overlapPx: 2.5,\n extraRings: 0,\n },\n};\n","import { Tile, TileStatus } from './types';\n\nexport const UPDATE_VISIBLE_TILES = 'UPDATE_VISIBLE_TILES';\nexport const MARK_TILE_STATUS = 'MARK_TILE_STATUS';\n\nexport type UpdateVisibleTilesAction = {\n type: typeof UPDATE_VISIBLE_TILES;\n payload: Record<number, Tile[]>;\n};\n\nexport type MarkTileStatusAction = {\n type: typeof MARK_TILE_STATUS;\n payload: { pageIndex: number; tileId: string; status: TileStatus };\n};\n\nexport type TilingAction = UpdateVisibleTilesAction | MarkTileStatusAction;\n\nexport const updateVisibleTiles = (tiles: Record<number, Tile[]>): UpdateVisibleTilesAction => ({\n type: UPDATE_VISIBLE_TILES,\n payload: tiles,\n});\n\nexport const markTileStatus = (\n pageIndex: number,\n tileId: string,\n status: TileStatus,\n): MarkTileStatusAction => ({ type: MARK_TILE_STATUS, payload: { pageIndex, tileId, status } });\n","import { Reducer } from '@embedpdf/core';\n\nimport { UPDATE_VISIBLE_TILES, MARK_TILE_STATUS, TilingAction } from './actions';\nimport { Tile, TilingState } from './types';\n\nexport const initialState: TilingState = {\n visibleTiles: {},\n};\n\nexport const tilingReducer: Reducer<TilingState, TilingAction> = (state, action) => {\n switch (action.type) {\n case UPDATE_VISIBLE_TILES: {\n const incoming = action.payload; // Record<number, Tile[]>\n const nextPages = { ...state.visibleTiles };\n\n for (const key in incoming) {\n const pageIndex = Number(key);\n const newTiles = incoming[pageIndex]; // all isFallback=false\n const prevTiles = nextPages[pageIndex] ?? [];\n\n const prevScale = prevTiles.find((t) => !t.isFallback)?.srcScale;\n const newScale = newTiles[0].srcScale;\n const zoomChanged = prevScale !== undefined && prevScale !== newScale;\n\n if (zoomChanged) {\n /* 1️⃣ ready tiles from the old zoom → new fallback */\n const promoted = prevTiles\n .filter((t) => !t.isFallback && t.status === 'ready')\n .map((t) => ({ ...t, isFallback: true }));\n\n /* 2️⃣ decide which fallback tiles to keep */\n const fallbackToCarry = promoted.length > 0 ? [] : prevTiles.filter((t) => t.isFallback);\n\n /* 3️⃣ final list = (maybe-kept fallback) + promoted + newTiles */\n nextPages[pageIndex] = [...fallbackToCarry, ...promoted, ...newTiles];\n } else {\n /* same zoom → keep current fallback, replace visible */\n const newIds = new Set(newTiles.map((t) => t.id));\n const keepers: Tile[] = []; // where we’ll collect surviving tiles\n const seenIds = new Set<string>();\n\n /* 2️⃣ loop prevTiles once */\n for (const t of prevTiles) {\n if (t.isFallback) {\n keepers.push(t); // always keep fallback\n seenIds.add(t.id);\n } else if (newIds.has(t.id)) {\n keepers.push(t); // keep old visible tile (preserves status)\n seenIds.add(t.id);\n }\n }\n\n /* 3️⃣ append *brand-new* tiles (not yet kept) */\n for (const t of newTiles) {\n if (!seenIds.has(t.id)) keepers.push(t);\n }\n\n /* 4️⃣ store result */\n nextPages[pageIndex] = keepers;\n }\n }\n\n return { ...state, visibleTiles: nextPages };\n }\n\n case MARK_TILE_STATUS: {\n const { pageIndex, tileId, status } = action.payload;\n const tiles =\n state.visibleTiles[pageIndex]?.map((t) =>\n t.id === tileId ? ({ ...t, status } as Tile) : t,\n ) ?? [];\n\n const newTiles = tiles.filter((t) => !t.isFallback);\n const allReady = newTiles.every((t) => t.status === 'ready');\n const finalTiles = allReady ? newTiles : tiles;\n\n return {\n ...state,\n visibleTiles: { ...state.visibleTiles, [pageIndex]: finalTiles },\n };\n }\n\n default:\n return state;\n }\n};\n","import { Rect, restoreRect, transformSize } from '@embedpdf/models';\nimport { CalculateTilesForPageOptions, Tile } from './types';\n\n/**\n * Build a grid where neighbouring tiles overlap by `overlapPx`\n * (screen pixels). Inner tiles keep the full `tileSize`, edge\n * tiles are clipped to the page bounds. All screen-space values\n * are rounded to **integers** to avoid sub-pixel seams.\n */\nexport function calculateTilesForPage({\n tileSize = 768,\n overlapPx = 2.5,\n extraRings = 0,\n scale,\n rotation,\n page,\n metric,\n}: CalculateTilesForPageOptions): Tile[] {\n /* ---- work in screen-pixel space -------------------------------- */\n const pageW = page.size.width * scale; // px\n const pageH = page.size.height * scale; // px\n\n const step = tileSize - overlapPx; // shift between tiles\n\n const containerSize = transformSize(page.size, rotation, scale);\n const rotatedVisRect: Rect = {\n origin: { x: metric.scaled.pageX, y: metric.scaled.pageY },\n size: { width: metric.scaled.visibleWidth, height: metric.scaled.visibleHeight },\n };\n const unrotatedVisRect = restoreRect(containerSize, rotatedVisRect, rotation, 1);\n\n const visLeft = unrotatedVisRect.origin.x;\n const visTop = unrotatedVisRect.origin.y;\n const visRight = visLeft + unrotatedVisRect.size.width;\n const visBottom = visTop + unrotatedVisRect.size.height;\n\n const maxCol = Math.floor((pageW - 1) / step);\n const maxRow = Math.floor((pageH - 1) / step);\n\n const startCol = Math.max(0, Math.floor(visLeft / step) - extraRings);\n const endCol = Math.min(maxCol, Math.floor((visRight - 1) / step) + extraRings);\n const startRow = Math.max(0, Math.floor(visTop / step) - extraRings);\n const endRow = Math.min(maxRow, Math.floor((visBottom - 1) / step) + extraRings);\n\n /* ---- build tiles ---------------------------------------------- */\n const tiles: Tile[] = [];\n\n for (let col = startCol; col <= endCol; col++) {\n const xScreen = col * step; // px (integer)\n const wScreen = Math.min(tileSize, pageW - xScreen); // px (≤ tileSize)\n\n const xPage = xScreen / scale; // pt (may be frac.)\n const wPage = wScreen / scale; // pt\n\n for (let row = startRow; row <= endRow; row++) {\n const yScreen = row * step;\n const hScreen = Math.min(tileSize, pageH - yScreen);\n\n const yPage = yScreen / scale;\n const hPage = hScreen / scale;\n\n tiles.push({\n id: `p${page.index}-${scale}-x${xScreen}-y${yScreen}-w${wScreen}-h${hScreen}`,\n col,\n row,\n pageRect: { origin: { x: xPage, y: yPage }, size: { width: wPage, height: hPage } },\n screenRect: {\n origin: { x: xScreen, y: yScreen },\n size: { width: wScreen, height: hScreen },\n },\n status: 'queued',\n srcScale: scale,\n isFallback: false,\n });\n }\n }\n\n return tiles;\n}\n","import {\n BasePlugin,\n CoreState,\n createBehaviorEmitter,\n PluginRegistry,\n StoreState,\n} from '@embedpdf/core';\nimport { ignore } from '@embedpdf/models';\nimport { RenderCapability, RenderPlugin } from '@embedpdf/plugin-render';\nimport { ScrollCapability, ScrollMetrics, ScrollPlugin } from '@embedpdf/plugin-scroll';\nimport { ViewportCapability, ViewportPlugin } from '@embedpdf/plugin-viewport';\n\nimport { markTileStatus, updateVisibleTiles } from './actions';\nimport {\n TilingPluginConfig,\n TilingCapability,\n Tile,\n RenderTileOptions,\n TilingState,\n} from './types';\nimport { calculateTilesForPage } from './utils';\n\nexport class TilingPlugin extends BasePlugin<TilingPluginConfig, TilingCapability> {\n static readonly id = 'tiling' as const;\n\n private readonly tileRendering$ = createBehaviorEmitter<Record<number, Tile[]>>();\n\n private config: TilingPluginConfig;\n private renderCapability: RenderCapability;\n private scrollCapability: ScrollCapability;\n private viewportCapability: ViewportCapability;\n\n constructor(id: string, registry: PluginRegistry, config: TilingPluginConfig) {\n super(id, registry);\n\n this.config = config;\n\n this.renderCapability = this.registry.getPlugin<RenderPlugin>('render')!.provides();\n this.scrollCapability = this.registry.getPlugin<ScrollPlugin>('scroll')!.provides();\n this.viewportCapability = this.registry.getPlugin<ViewportPlugin>('viewport')!.provides();\n\n this.scrollCapability.onScroll((scrollMetrics) => this.calculateVisibleTiles(scrollMetrics), {\n mode: 'throttle',\n wait: 500,\n throttleMode: 'trailing',\n });\n }\n\n async initialize(): Promise<void> {\n // Fetch dependencies from the registry if needed\n }\n\n protected onCoreStoreUpdated(\n oldState: StoreState<CoreState>,\n newState: StoreState<CoreState>,\n ): void {\n if (oldState.core.scale !== newState.core.scale) {\n this.calculateVisibleTiles(\n this.scrollCapability.getMetrics(this.viewportCapability.getMetrics()),\n );\n }\n }\n\n private calculateVisibleTiles(scrollMetrics: ScrollMetrics): void {\n if (!this.config.enabled) {\n this.dispatch(updateVisibleTiles([]));\n return;\n }\n\n const scale = this.coreState.core.scale;\n const rotation = this.coreState.core.rotation;\n const visibleTiles: { [pageIndex: number]: Tile[] } = {};\n\n for (const scrollMetric of scrollMetrics.pageVisibilityMetrics) {\n const pageIndex = scrollMetric.pageNumber - 1; // Convert to 0-based index\n const page = this.coreState.core.document?.pages[pageIndex];\n if (!page) continue;\n\n // Calculate tiles for the page using the utility function\n const tiles = calculateTilesForPage({\n page,\n metric: scrollMetric,\n scale,\n rotation,\n tileSize: this.config.tileSize,\n overlapPx: this.config.overlapPx,\n extraRings: this.config.extraRings,\n });\n\n visibleTiles[pageIndex] = tiles;\n }\n\n this.dispatch(updateVisibleTiles(visibleTiles));\n }\n\n override onStoreUpdated(_prevState: TilingState, newState: TilingState): void {\n this.tileRendering$.emit(newState.visibleTiles);\n }\n\n protected buildCapability(): TilingCapability {\n return {\n renderTile: this.renderTile.bind(this),\n onTileRendering: this.tileRendering$.on,\n };\n }\n\n private renderTile(options: RenderTileOptions) {\n if (!this.renderCapability) {\n throw new Error('Render capability not available.');\n }\n\n this.dispatch(markTileStatus(options.pageIndex, options.tile.id, 'rendering'));\n\n const task = this.renderCapability.renderPageRect({\n pageIndex: options.pageIndex,\n rect: options.tile.pageRect,\n scaleFactor: options.tile.srcScale,\n dpr: options.dpr,\n });\n\n task.wait(() => {\n this.dispatch(markTileStatus(options.pageIndex, options.tile.id, 'ready'));\n }, ignore);\n\n return task;\n }\n}\n","import { PluginPackage } from '@embedpdf/core';\n\nimport { TilingAction } from './actions';\nimport { manifest, TILING_PLUGIN_ID } from './manifest';\nimport { initialState, tilingReducer } from './reducer';\nimport { TilingPlugin } from './tiling-plugin';\nimport { TilingPluginConfig, TilingState } from './types';\n\nexport const TilingPluginPackage: PluginPackage<\n TilingPlugin,\n TilingPluginConfig,\n TilingState,\n TilingAction\n> = {\n manifest,\n create: (registry, _engine, config) => new TilingPlugin(TILING_PLUGIN_ID, registry, config),\n reducer: (state, action) => tilingReducer(state, action),\n initialState,\n};\n\nexport * from './tiling-plugin';\nexport * from './types';\nexport * from './manifest';\n"],"names":[],"mappings":";;AAIO,MAAM,mBAAmB;AAEzB,MAAM,WAA+C;AAAA,EAC1D,IAAI;AAAA,EACJ,MAAM;AAAA,EACN,SAAS;AAAA,EACT,UAAU,CAAC,QAAQ;AAAA,EACnB,UAAU,CAAC,UAAU,UAAU,UAAU;AAAA,EACzC,UAAU,CAAC;AAAA,EACX,eAAe;AAAA,IACb,SAAS;AAAA,IACT,UAAU;AAAA,IACV,WAAW;AAAA,IACX,YAAY;AAAA,EAAA;AAEhB;ACjBO,MAAM,uBAAuB;AAC7B,MAAM,mBAAmB;AAcnB,MAAA,qBAAqB,CAAC,WAA6D;AAAA,EAC9F,MAAM;AAAA,EACN,SAAS;AACX;AAEO,MAAM,iBAAiB,CAC5B,WACA,QACA,YAC0B,EAAE,MAAM,kBAAkB,SAAS,EAAE,WAAW,QAAQ,OAAS,EAAA;ACrBtF,MAAM,eAA4B;AAAA,EACvC,cAAc,CAAA;AAChB;AAEa,MAAA,gBAAoD,CAAC,OAAO,WAAW;;AAClF,UAAQ,OAAO,MAAM;AAAA,IACnB,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AK,OAAO;AAAA,MAAA,CACzB;AAED,mBAAa,SAAS,IAAI;AAAA,IAAA;AAGvB,SAAA,SAAS,mBAAmB,YAAY,CAAC;AAAA,EAAA;AAAA,EAGvC,eAAe,YAAyB,UAA6B;AACvE,SAAA,eAAe,KAAK,SAAS,YAAY;AAAA,EAAA;AAAA,EAGtC,kBAAoC;AACrC,WAAA;AAAA,MACL,YAAY,KAAK,WAAW,KAAK,IAAI;AAAA,MACrC,iBAAiB,KAAK,eAAe;AAAA,IACvC;AAAA,EAAA;AAAA,EAGM,WAAW,SAA4B;AACzC,QAAA,CAAC,KAAK,kBAAkB;AACpB,YAAA,IAAI,MAAM,kCAAkC;AAAA,IAAA;AAG/C,SAAA,SAAS,eAAe,QAAQ,WAAW,QAAQ,KAAK,IAAI,WAAW,CAAC;AAEvE,UAAA,OAAO,KAAK,iBAAiB,eAAe;AAAA,MAChD,WAAW,QAAQ;AAAA,MACnB,MAAM,QAAQ,KAAK;AAAA,MACnB,aAAa,QAAQ,KAAK;AAAA,MAC1B,KAAK,QAAQ;AAAA,IAAA,CACd;AAED,SAAK,KAAK,MAAM;AACT,WAAA,SAAS,eAAe,QAAQ,WAAW,QAAQ,KAAK,IAAI,OAAO,CAAC;AAAA,OACxE,MAAM;AAEF,WAAA;AAAA,EAAA;AAEX;AAvGE,cAAgB,KAAK;AADhB,IAAM,eAAN;ACdA,MAAM,sBAKT;AAAA,EACF;AAAA,EACA,QAAQ,CAAC,UAAU,SAAS,WAAW,IAAI,aAAa,kBAAkB,UAAU,MAAM;AAAA,EAC1F,SAAS,CAAC,OAAO,WAAW,cAAc,OAAO,MAAM;AAAA,EACvD;AACF;"}
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../src/lib/manifest.ts","../src/lib/actions.ts","../src/lib/reducer.ts","../src/lib/utils.ts","../src/lib/tiling-plugin.ts","../src/lib/index.ts"],"sourcesContent":["import { PluginManifest } from '@embedpdf/core';\n\nimport { TilingPluginConfig } from './types';\n\nexport const TILING_PLUGIN_ID = 'tiling';\n\nexport const manifest: PluginManifest<TilingPluginConfig> = {\n id: TILING_PLUGIN_ID,\n name: 'Tiling Plugin',\n version: '1.0.0',\n provides: ['tiling'],\n requires: ['render', 'scroll', 'viewport'],\n optional: [],\n defaultConfig: {\n enabled: true,\n tileSize: 768,\n overlapPx: 2.5,\n extraRings: 0,\n },\n};\n","import { Tile, TileStatus } from './types';\n\nexport const UPDATE_VISIBLE_TILES = 'UPDATE_VISIBLE_TILES';\nexport const MARK_TILE_STATUS = 'MARK_TILE_STATUS';\n\nexport type UpdateVisibleTilesAction = {\n type: typeof UPDATE_VISIBLE_TILES;\n payload: Record<number, Tile[]>;\n};\n\nexport type MarkTileStatusAction = {\n type: typeof MARK_TILE_STATUS;\n payload: { pageIndex: number; tileId: string; status: TileStatus };\n};\n\nexport type TilingAction = UpdateVisibleTilesAction | MarkTileStatusAction;\n\nexport const updateVisibleTiles = (tiles: Record<number, Tile[]>): UpdateVisibleTilesAction => ({\n type: UPDATE_VISIBLE_TILES,\n payload: tiles,\n});\n\nexport const markTileStatus = (\n pageIndex: number,\n tileId: string,\n status: TileStatus,\n): MarkTileStatusAction => ({ type: MARK_TILE_STATUS, payload: { pageIndex, tileId, status } });\n","import { Reducer } from '@embedpdf/core';\n\nimport { UPDATE_VISIBLE_TILES, MARK_TILE_STATUS, TilingAction } from './actions';\nimport { Tile, TilingState } from './types';\n\nexport const initialState: TilingState = {\n visibleTiles: {},\n};\n\nexport const tilingReducer: Reducer<TilingState, TilingAction> = (state, action) => {\n switch (action.type) {\n case UPDATE_VISIBLE_TILES: {\n const incoming = action.payload; // Record<number, Tile[]>\n const nextPages = { ...state.visibleTiles };\n\n for (const key in incoming) {\n const pageIndex = Number(key);\n const newTiles = incoming[pageIndex]; // all isFallback=false\n const prevTiles = nextPages[pageIndex] ?? [];\n\n const prevScale = prevTiles.find((t) => !t.isFallback)?.srcScale;\n const newScale = newTiles[0].srcScale;\n const zoomChanged = prevScale !== undefined && prevScale !== newScale;\n\n if (zoomChanged) {\n /* 1️⃣ ready tiles from the old zoom → new fallback */\n const promoted = prevTiles\n .filter((t) => !t.isFallback && t.status === 'ready')\n .map((t) => ({ ...t, isFallback: true }));\n\n /* 2️⃣ decide which fallback tiles to keep */\n const fallbackToCarry = promoted.length > 0 ? [] : prevTiles.filter((t) => t.isFallback);\n\n /* 3️⃣ final list = (maybe-kept fallback) + promoted + newTiles */\n nextPages[pageIndex] = [...fallbackToCarry, ...promoted, ...newTiles];\n } else {\n /* same zoom → keep current fallback, replace visible */\n const newIds = new Set(newTiles.map((t) => t.id));\n const keepers: Tile[] = []; // where we’ll collect surviving tiles\n const seenIds = new Set<string>();\n\n /* 2️⃣ loop prevTiles once */\n for (const t of prevTiles) {\n if (t.isFallback) {\n keepers.push(t); // always keep fallback\n seenIds.add(t.id);\n } else if (newIds.has(t.id)) {\n keepers.push(t); // keep old visible tile (preserves status)\n seenIds.add(t.id);\n }\n }\n\n /* 3️⃣ append *brand-new* tiles (not yet kept) */\n for (const t of newTiles) {\n if (!seenIds.has(t.id)) keepers.push(t);\n }\n\n /* 4️⃣ store result */\n nextPages[pageIndex] = keepers;\n }\n }\n\n return { ...state, visibleTiles: nextPages };\n }\n\n case MARK_TILE_STATUS: {\n const { pageIndex, tileId, status } = action.payload;\n const tiles =\n state.visibleTiles[pageIndex]?.map((t) =>\n t.id === tileId ? ({ ...t, status } as Tile) : t,\n ) ?? [];\n\n const newTiles = tiles.filter((t) => !t.isFallback);\n const allReady = newTiles.every((t) => t.status === 'ready');\n const finalTiles = allReady ? newTiles : tiles;\n\n return {\n ...state,\n visibleTiles: { ...state.visibleTiles, [pageIndex]: finalTiles },\n };\n }\n\n default:\n return state;\n }\n};\n","import { Rect, restoreRect, transformSize } from '@embedpdf/models';\nimport { CalculateTilesForPageOptions, Tile } from './types';\n\n/**\n * Build a grid where neighbouring tiles overlap by `overlapPx`\n * (screen pixels). Inner tiles keep the full `tileSize`, edge\n * tiles are clipped to the page bounds. All screen-space values\n * are rounded to **integers** to avoid sub-pixel seams.\n */\nexport function calculateTilesForPage({\n tileSize = 768,\n overlapPx = 2.5,\n extraRings = 0,\n scale,\n rotation,\n page,\n metric,\n}: CalculateTilesForPageOptions): Tile[] {\n /* ---- work in screen-pixel space -------------------------------- */\n const pageW = page.size.width * scale; // px\n const pageH = page.size.height * scale; // px\n\n const step = tileSize - overlapPx; // shift between tiles\n\n const containerSize = transformSize(page.size, rotation, scale);\n const rotatedVisRect: Rect = {\n origin: { x: metric.scaled.pageX, y: metric.scaled.pageY },\n size: { width: metric.scaled.visibleWidth, height: metric.scaled.visibleHeight },\n };\n const unrotatedVisRect = restoreRect(containerSize, rotatedVisRect, rotation, 1);\n\n const visLeft = unrotatedVisRect.origin.x;\n const visTop = unrotatedVisRect.origin.y;\n const visRight = visLeft + unrotatedVisRect.size.width;\n const visBottom = visTop + unrotatedVisRect.size.height;\n\n const maxCol = Math.floor((pageW - 1) / step);\n const maxRow = Math.floor((pageH - 1) / step);\n\n const startCol = Math.max(0, Math.floor(visLeft / step) - extraRings);\n const endCol = Math.min(maxCol, Math.floor((visRight - 1) / step) + extraRings);\n const startRow = Math.max(0, Math.floor(visTop / step) - extraRings);\n const endRow = Math.min(maxRow, Math.floor((visBottom - 1) / step) + extraRings);\n\n /* ---- build tiles ---------------------------------------------- */\n const tiles: Tile[] = [];\n\n for (let col = startCol; col <= endCol; col++) {\n const xScreen = col * step; // px (integer)\n const wScreen = Math.min(tileSize, pageW - xScreen); // px (≤ tileSize)\n\n const xPage = xScreen / scale; // pt (may be frac.)\n const wPage = wScreen / scale; // pt\n\n for (let row = startRow; row <= endRow; row++) {\n const yScreen = row * step;\n const hScreen = Math.min(tileSize, pageH - yScreen);\n\n const yPage = yScreen / scale;\n const hPage = hScreen / scale;\n\n tiles.push({\n id: `p${page.index}-${scale}-x${xScreen}-y${yScreen}-w${wScreen}-h${hScreen}`,\n col,\n row,\n pageRect: { origin: { x: xPage, y: yPage }, size: { width: wPage, height: hPage } },\n screenRect: {\n origin: { x: xScreen, y: yScreen },\n size: { width: wScreen, height: hScreen },\n },\n status: 'queued',\n srcScale: scale,\n isFallback: false,\n });\n }\n }\n\n return tiles;\n}\n","import {\n BasePlugin,\n CoreState,\n createBehaviorEmitter,\n createEmitter,\n PluginRegistry,\n REFRESH_PAGES,\n StoreState,\n Unsubscribe,\n} from '@embedpdf/core';\nimport { ignore } from '@embedpdf/models';\nimport { RenderCapability, RenderPlugin } from '@embedpdf/plugin-render';\nimport { ScrollCapability, ScrollMetrics, ScrollPlugin } from '@embedpdf/plugin-scroll';\nimport { ViewportCapability, ViewportPlugin } from '@embedpdf/plugin-viewport';\n\nimport { markTileStatus, updateVisibleTiles } from './actions';\nimport {\n TilingPluginConfig,\n TilingCapability,\n Tile,\n RenderTileOptions,\n TilingState,\n} from './types';\nimport { calculateTilesForPage } from './utils';\n\nexport class TilingPlugin extends BasePlugin<TilingPluginConfig, TilingCapability> {\n static readonly id = 'tiling' as const;\n\n private readonly tileRendering$ = createBehaviorEmitter<Record<number, Tile[]>>();\n private readonly refreshPages$ = createEmitter<number[]>();\n\n private config: TilingPluginConfig;\n private renderCapability: RenderCapability;\n private scrollCapability: ScrollCapability;\n private viewportCapability: ViewportCapability;\n\n constructor(id: string, registry: PluginRegistry, config: TilingPluginConfig) {\n super(id, registry);\n\n this.config = config;\n\n this.renderCapability = this.registry.getPlugin<RenderPlugin>('render')!.provides();\n this.scrollCapability = this.registry.getPlugin<ScrollPlugin>('scroll')!.provides();\n this.viewportCapability = this.registry.getPlugin<ViewportPlugin>('viewport')!.provides();\n\n this.scrollCapability.onScroll((scrollMetrics) => this.calculateVisibleTiles(scrollMetrics), {\n mode: 'throttle',\n wait: 500,\n throttleMode: 'trailing',\n });\n\n this.coreStore.onAction(REFRESH_PAGES, (action) => {\n this.refreshPages$.emit(action.payload);\n });\n }\n\n async initialize(): Promise<void> {\n // Fetch dependencies from the registry if needed\n }\n\n protected onCoreStoreUpdated(\n oldState: StoreState<CoreState>,\n newState: StoreState<CoreState>,\n ): void {\n if (oldState.core.scale !== newState.core.scale) {\n this.calculateVisibleTiles(\n this.scrollCapability.getMetrics(this.viewportCapability.getMetrics()),\n );\n }\n }\n\n public onRefreshPages(fn: (pages: number[]) => void): Unsubscribe {\n return this.refreshPages$.on(fn);\n }\n\n private calculateVisibleTiles(scrollMetrics: ScrollMetrics): void {\n if (!this.config.enabled) {\n this.dispatch(updateVisibleTiles([]));\n return;\n }\n\n const scale = this.coreState.core.scale;\n const rotation = this.coreState.core.rotation;\n const visibleTiles: { [pageIndex: number]: Tile[] } = {};\n\n for (const scrollMetric of scrollMetrics.pageVisibilityMetrics) {\n const pageIndex = scrollMetric.pageNumber - 1; // Convert to 0-based index\n const page = this.coreState.core.document?.pages[pageIndex];\n if (!page) continue;\n\n // Calculate tiles for the page using the utility function\n const tiles = calculateTilesForPage({\n page,\n metric: scrollMetric,\n scale,\n rotation,\n tileSize: this.config.tileSize,\n overlapPx: this.config.overlapPx,\n extraRings: this.config.extraRings,\n });\n\n visibleTiles[pageIndex] = tiles;\n }\n\n this.dispatch(updateVisibleTiles(visibleTiles));\n }\n\n override onStoreUpdated(_prevState: TilingState, newState: TilingState): void {\n this.tileRendering$.emit(newState.visibleTiles);\n }\n\n protected buildCapability(): TilingCapability {\n return {\n renderTile: this.renderTile.bind(this),\n onTileRendering: this.tileRendering$.on,\n };\n }\n\n private renderTile(options: RenderTileOptions) {\n if (!this.renderCapability) {\n throw new Error('Render capability not available.');\n }\n\n this.dispatch(markTileStatus(options.pageIndex, options.tile.id, 'rendering'));\n\n const task = this.renderCapability.renderPageRect({\n pageIndex: options.pageIndex,\n rect: options.tile.pageRect,\n options: {\n scaleFactor: options.tile.srcScale,\n dpr: options.dpr,\n },\n });\n\n task.wait(() => {\n this.dispatch(markTileStatus(options.pageIndex, options.tile.id, 'ready'));\n }, ignore);\n\n return task;\n }\n}\n","import { PluginPackage } from '@embedpdf/core';\n\nimport { TilingAction } from './actions';\nimport { manifest, TILING_PLUGIN_ID } from './manifest';\nimport { initialState, tilingReducer } from './reducer';\nimport { TilingPlugin } from './tiling-plugin';\nimport { TilingPluginConfig, TilingState } from './types';\n\nexport const TilingPluginPackage: PluginPackage<\n TilingPlugin,\n TilingPluginConfig,\n TilingState,\n TilingAction\n> = {\n manifest,\n create: (registry, config) => new TilingPlugin(TILING_PLUGIN_ID, registry, config),\n reducer: (state, action) => tilingReducer(state, action),\n initialState,\n};\n\nexport * from './tiling-plugin';\nexport * from './types';\nexport * from './manifest';\n"],"names":[],"mappings":";;AAIO,MAAM,mBAAmB;AAEzB,MAAM,WAA+C;AAAA,EAC1D,IAAI;AAAA,EACJ,MAAM;AAAA,EACN,SAAS;AAAA,EACT,UAAU,CAAC,QAAQ;AAAA,EACnB,UAAU,CAAC,UAAU,UAAU,UAAU;AAAA,EACzC,UAAU,CAAC;AAAA,EACX,eAAe;AAAA,IACb,SAAS;AAAA,IACT,UAAU;AAAA,IACV,WAAW;AAAA,IACX,YAAY;AAAA,EAAA;AAEhB;ACjBO,MAAM,uBAAuB;AAC7B,MAAM,mBAAmB;AAcnB,MAAA,qBAAqB,CAAC,WAA6D;AAAA,EAC9F,MAAM;AAAA,EACN,SAAS;AACX;AAEO,MAAM,iBAAiB,CAC5B,WACA,QACA,YAC0B,EAAE,MAAM,kBAAkB,SAAS,EAAE,WAAW,QAAQ,OAAS,EAAA;ACrBtF,MAAM,eAA4B;AAAA,EACvC,cAAc,CAAA;AAChB;AAEa,MAAA,gBAAoD,CAAC,OAAO,WAAW;;AAClF,UAAQ,OAAO,MAAM;AAAA,IACnB,KAAK,sBAAsB;AACzB,YAAM,WAAW,OAAO;AACxB,YAAM,YAAY,EAAE,GAAG,MAAM,aAAa;AAE1C,iBAAW,OAAO,UAAU;AACpB,cAAA,YAAY,OAAO,GAAG;AACtB,cAAA,WAAW,SAAS,SAAS;AACnC,cAAM,YAAY,UAAU,SAAS,KAAK,CAAC;AAErC,cAAA,aAAY,eAAU,KAAK,CAAC,MAAM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;AAAA,IAAA;AAGvB,SAAA,SAAS,mBAAmB,YAAY,CAAC;AAAA,EAAA;AAAA,EAGvC,eAAe,YAAyB,UAA6B;AACvE,SAAA,eAAe,KAAK,SAAS,YAAY;AAAA,EAAA;AAAA,EAGtC,kBAAoC;AACrC,WAAA;AAAA,MACL,YAAY,KAAK,WAAW,KAAK,IAAI;AAAA,MACrC,iBAAiB,KAAK,eAAe;AAAA,IACvC;AAAA,EAAA;AAAA,EAGM,WAAW,SAA4B;AACzC,QAAA,CAAC,KAAK,kBAAkB;AACpB,YAAA,IAAI,MAAM,kCAAkC;AAAA,IAAA;AAG/C,SAAA,SAAS,eAAe,QAAQ,WAAW,QAAQ,KAAK,IAAI,WAAW,CAAC;AAEvE,UAAA,OAAO,KAAK,iBAAiB,eAAe;AAAA,MAChD,WAAW,QAAQ;AAAA,MACnB,MAAM,QAAQ,KAAK;AAAA,MACnB,SAAS;AAAA,QACP,aAAa,QAAQ,KAAK;AAAA,QAC1B,KAAK,QAAQ;AAAA,MAAA;AAAA,IACf,CACD;AAED,SAAK,KAAK,MAAM;AACT,WAAA,SAAS,eAAe,QAAQ,WAAW,QAAQ,KAAK,IAAI,OAAO,CAAC;AAAA,OACxE,MAAM;AAEF,WAAA;AAAA,EAAA;AAEX;AAlHE,cAAgB,KAAK;AADhB,IAAM,eAAN;ACjBA,MAAM,sBAKT;AAAA,EACF;AAAA,EACA,QAAQ,CAAC,UAAU,WAAW,IAAI,aAAa,kBAAkB,UAAU,MAAM;AAAA,EACjF,SAAS,CAAC,OAAO,WAAW,cAAc,OAAO,MAAM;AAAA,EACvD;AACF;"}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import { BasePlugin, CoreState, PluginRegistry, StoreState } from '@embedpdf/core';
|
|
1
|
+
import { BasePlugin, CoreState, PluginRegistry, StoreState, Unsubscribe } from '@embedpdf/core';
|
|
2
2
|
import { TilingPluginConfig, TilingCapability, TilingState } from './types';
|
|
3
3
|
export declare class TilingPlugin extends BasePlugin<TilingPluginConfig, TilingCapability> {
|
|
4
4
|
static readonly id: "tiling";
|
|
5
5
|
private readonly tileRendering$;
|
|
6
|
+
private readonly refreshPages$;
|
|
6
7
|
private config;
|
|
7
8
|
private renderCapability;
|
|
8
9
|
private scrollCapability;
|
|
@@ -10,6 +11,7 @@ export declare class TilingPlugin extends BasePlugin<TilingPluginConfig, TilingC
|
|
|
10
11
|
constructor(id: string, registry: PluginRegistry, config: TilingPluginConfig);
|
|
11
12
|
initialize(): Promise<void>;
|
|
12
13
|
protected onCoreStoreUpdated(oldState: StoreState<CoreState>, newState: StoreState<CoreState>): void;
|
|
14
|
+
onRefreshPages(fn: (pages: number[]) => void): Unsubscribe;
|
|
13
15
|
private calculateVisibleTiles;
|
|
14
16
|
onStoreUpdated(_prevState: TilingState, newState: TilingState): void;
|
|
15
17
|
protected buildCapability(): TilingCapability;
|
package/dist/preact/index.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("@embedpdf/core/preact"),r=require("@embedpdf/plugin-tiling"),t=require("preact/jsx-runtime");require("preact");const i=require("preact/hooks"),n=require("@embedpdf/models"),s=()=>e.useCapability(r.TilingPlugin.id);function
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("@embedpdf/core/preact"),r=require("@embedpdf/plugin-tiling"),t=require("preact/jsx-runtime");require("preact");const i=require("preact/hooks"),n=require("@embedpdf/models"),s=()=>e.usePlugin(r.TilingPlugin.id),c=()=>e.useCapability(r.TilingPlugin.id);function u({pageIndex:e,tile:r,dpr:u,scale:l}){const{provides:o}=c(),{plugin:d}=s(),[a,p]=i.useState(),g=i.useRef(null),[f,x]=i.useState(0),R=l/r.srcScale;i.useEffect((()=>{if(d)return d.onRefreshPages((r=>{r.includes(e)&&x((e=>e+1))}))}),[d]),i.useEffect((()=>{if("ready"===r.status&&g.current)return;if(!o)return;const t=o.renderTile({pageIndex:e,tile:r,dpr:u});return t.wait((e=>{const r=URL.createObjectURL(e);g.current=r,p(r)}),n.ignore),()=>{g.current?(URL.revokeObjectURL(g.current),g.current=null):t.abort({code:n.PdfErrorCode.Cancelled,message:"canceled render task"})}}),[e,r.id,f]);return a?t.jsx("img",{src:a,onLoad:()=>{g.current&&(URL.revokeObjectURL(g.current),g.current=null)},style:{position:"absolute",left:r.screenRect.origin.x*R,top:r.screenRect.origin.y*R,width:r.screenRect.size.width*R,height:r.screenRect.size.height*R,display:"block"}}):null}exports.TilingLayer=function({pageIndex:e,scale:r,style:n,...s}){const{provides:l}=c(),[o,d]=i.useState([]);return i.useEffect((()=>{if(l)return l.onTileRendering((r=>d(r[e])))}),[l]),t.jsx("div",{style:{...n},...s,children:null==o?void 0:o.map((i=>t.jsx(u,{pageIndex:e,tile:i,dpr:window.devicePixelRatio,scale:r},i.id)))})},exports.useTilingCapability=c,exports.useTilingPlugin=s;
|
|
2
2
|
//# sourceMappingURL=index.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","sources":["../../src/shared/hooks/use-tiling.ts","../../src/shared/components/tile-img.tsx","../../src/shared/components/tiling-layer.tsx"],"sourcesContent":["import { useCapability, usePlugin } from '@embedpdf/core/@framework';\nimport { TilingPlugin } from '@embedpdf/plugin-tiling';\n\nexport const useTilingPlugin = () => usePlugin<TilingPlugin>(TilingPlugin.id);\nexport const useTilingCapability = () => useCapability<TilingPlugin>(TilingPlugin.id);\n","import { ignore, PdfErrorCode } from '@embedpdf/models';\nimport { Tile } from '@embedpdf/plugin-tiling';\nimport { useEffect, useRef, useState } from '@framework';\n\nimport { useTilingCapability } from '../hooks/use-tiling';\n\ninterface TileImgProps {\n pageIndex: number;\n tile: Tile;\n dpr: number;\n scale: number;\n}\n\nexport function TileImg({ pageIndex, tile, dpr, scale }: TileImgProps) {\n const { provides: tilingCapability } = useTilingCapability();\n const [url, setUrl] = useState<string>();\n const urlRef = useRef<string | null>(null);\n\n const relativeScale = scale / tile.srcScale;\n\n /* kick off render exactly once per tile */\n useEffect(() => {\n if (tile.status === 'ready' && urlRef.current) return; // already done\n if (!tilingCapability) return;\n const task = tilingCapability.renderTile({ pageIndex, tile, dpr });\n task.wait((blob) => {\n const objectUrl = URL.createObjectURL(blob);\n urlRef.current = objectUrl;\n setUrl(objectUrl);\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 }, [pageIndex, tile.id]); // id includes scale, so unique\n\n const handleImageLoad = () => {\n if (urlRef.current) {\n URL.revokeObjectURL(urlRef.current);\n urlRef.current = null;\n }\n };\n\n if (!url) return null; // could render a placeholder\n return (\n <img\n src={url}\n onLoad={handleImageLoad}\n style={{\n position: 'absolute',\n left: tile.screenRect.origin.x * relativeScale,\n top: tile.screenRect.origin.y * relativeScale,\n width: tile.screenRect.size.width * relativeScale,\n height: tile.screenRect.size.height * relativeScale,\n display: 'block',\n }}\n />\n );\n}\n","import { Tile } from '@embedpdf/plugin-tiling';\nimport { useEffect, useState, HTMLAttributes, CSSProperties } from '@framework';\n\nimport { TileImg } from './tile-img';\nimport { useTilingCapability } from '../hooks/use-tiling';\n\ntype TilingLayoutProps = Omit<HTMLAttributes<HTMLDivElement>, 'style'> & {\n pageIndex: number;\n scale: number;\n style?: CSSProperties;\n};\n\nexport function TilingLayer({ pageIndex, scale, style, ...props }: TilingLayoutProps) {\n const { provides: tilingProvides } = useTilingCapability();\n const [tiles, setTiles] = useState<Tile[]>([]);\n\n useEffect(() => {\n if (tilingProvides) {\n return tilingProvides.onTileRendering((tiles) => setTiles(tiles[pageIndex]));\n }\n }, [tilingProvides]);\n\n return (\n <div\n style={{\n ...style,\n }}\n {...props}\n >\n {tiles?.map((tile) => (\n <TileImg\n key={tile.id}\n pageIndex={pageIndex}\n tile={tile}\n dpr={window.devicePixelRatio}\n scale={scale}\n />\n ))}\n </div>\n );\n}\n"],"names":["
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":["../../src/shared/hooks/use-tiling.ts","../../src/shared/components/tile-img.tsx","../../src/shared/components/tiling-layer.tsx"],"sourcesContent":["import { useCapability, usePlugin } from '@embedpdf/core/@framework';\nimport { TilingPlugin } from '@embedpdf/plugin-tiling';\n\nexport const useTilingPlugin = () => usePlugin<TilingPlugin>(TilingPlugin.id);\nexport const useTilingCapability = () => useCapability<TilingPlugin>(TilingPlugin.id);\n","import { ignore, PdfErrorCode } from '@embedpdf/models';\nimport { Tile } from '@embedpdf/plugin-tiling';\nimport { useEffect, useRef, useState } from '@framework';\n\nimport { useTilingCapability, useTilingPlugin } from '../hooks/use-tiling';\n\ninterface TileImgProps {\n pageIndex: number;\n tile: Tile;\n dpr: number;\n scale: number;\n}\n\nexport function TileImg({ pageIndex, tile, dpr, scale }: TileImgProps) {\n const { provides: tilingCapability } = useTilingCapability();\n const { plugin: tilingPlugin } = useTilingPlugin();\n\n const [url, setUrl] = useState<string>();\n const urlRef = useRef<string | null>(null);\n const [refreshTick, setRefreshTick] = useState(0);\n\n const relativeScale = scale / tile.srcScale;\n\n useEffect(() => {\n if (!tilingPlugin) return;\n return tilingPlugin.onRefreshPages((pages) => {\n if (pages.includes(pageIndex)) {\n setRefreshTick((tick) => tick + 1);\n }\n });\n }, [tilingPlugin]);\n\n /* kick off render exactly once per tile */\n useEffect(() => {\n if (tile.status === 'ready' && urlRef.current) return; // already done\n if (!tilingCapability) return;\n const task = tilingCapability.renderTile({ pageIndex, tile, dpr });\n task.wait((blob) => {\n const objectUrl = URL.createObjectURL(blob);\n urlRef.current = objectUrl;\n setUrl(objectUrl);\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 }, [pageIndex, tile.id, refreshTick]); // id includes scale, so unique\n\n const handleImageLoad = () => {\n if (urlRef.current) {\n URL.revokeObjectURL(urlRef.current);\n urlRef.current = null;\n }\n };\n\n if (!url) return null; // could render a placeholder\n return (\n <img\n src={url}\n onLoad={handleImageLoad}\n style={{\n position: 'absolute',\n left: tile.screenRect.origin.x * relativeScale,\n top: tile.screenRect.origin.y * relativeScale,\n width: tile.screenRect.size.width * relativeScale,\n height: tile.screenRect.size.height * relativeScale,\n display: 'block',\n }}\n />\n );\n}\n","import { Tile } from '@embedpdf/plugin-tiling';\nimport { useEffect, useState, HTMLAttributes, CSSProperties } from '@framework';\n\nimport { TileImg } from './tile-img';\nimport { useTilingCapability } from '../hooks/use-tiling';\n\ntype TilingLayoutProps = Omit<HTMLAttributes<HTMLDivElement>, 'style'> & {\n pageIndex: number;\n scale: number;\n style?: CSSProperties;\n};\n\nexport function TilingLayer({ pageIndex, scale, style, ...props }: TilingLayoutProps) {\n const { provides: tilingProvides } = useTilingCapability();\n const [tiles, setTiles] = useState<Tile[]>([]);\n\n useEffect(() => {\n if (tilingProvides) {\n return tilingProvides.onTileRendering((tiles) => setTiles(tiles[pageIndex]));\n }\n }, [tilingProvides]);\n\n return (\n <div\n style={{\n ...style,\n }}\n {...props}\n >\n {tiles?.map((tile) => (\n <TileImg\n key={tile.id}\n pageIndex={pageIndex}\n tile={tile}\n dpr={window.devicePixelRatio}\n scale={scale}\n />\n ))}\n </div>\n );\n}\n"],"names":["useTilingPlugin","usePlugin","TilingPlugin","id","useTilingCapability","useCapability","TileImg","pageIndex","tile","dpr","scale","provides","tilingCapability","plugin","tilingPlugin","url","setUrl","useState","urlRef","useRef","refreshTick","setRefreshTick","relativeScale","srcScale","useEffect","onRefreshPages","pages","includes","tick","status","current","task","renderTile","wait","blob","objectUrl","URL","createObjectURL","ignore","revokeObjectURL","abort","code","PdfErrorCode","Cancelled","message","jsxRuntime","jsx","src","onLoad","style","position","left","screenRect","origin","x","top","y","width","size","height","display","props","tilingProvides","tiles","setTiles","onTileRendering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AAK4C,WAAWM,KAAKD,MAAQnC,EACpCqC,OAAQnD,EAAK4C,WAAWM,KAAKC,OAASrC,EACtCsC,QAAS,WAXE,IAenB,qBClEO,UAAqBrD,UAAEA,EAAAG,MAAWA,QAAOuC,KAAUY,IACxD,MAAQlD,SAAUmD,GAAmB1D,KAC9B2D,EAAOC,GAAY/C,EAAAA,SAAiB,IASzC,OAPFO,EAAAA,WAAU,KACR,GAAIsC,EACK,OAAAA,EAAeG,iBAAiBF,GAAUC,EAASD,EAAMxD,KAAW,GAE5E,CAACuD,IAGFjB,EAAAC,IAAC,MAAA,CACCG,MAAO,IACFA,MAEDY,EAEHK,SAAA,MAAAH,OAAA,EAAAA,EAAOI,KAAK3D,GACXqC,EAAAC,IAACxC,EAAA,CAECC,YACAC,OACAC,IAAK2D,OAAOC,iBACZ3D,SAJKF,EAAKL,OASpB"}
|
package/dist/preact/index.js
CHANGED
|
@@ -8,9 +8,19 @@ const useTilingPlugin = () => usePlugin(TilingPlugin.id);
|
|
|
8
8
|
const useTilingCapability = () => useCapability(TilingPlugin.id);
|
|
9
9
|
function TileImg({ pageIndex, tile, dpr, scale }) {
|
|
10
10
|
const { provides: tilingCapability } = useTilingCapability();
|
|
11
|
+
const { plugin: tilingPlugin } = useTilingPlugin();
|
|
11
12
|
const [url, setUrl] = useState();
|
|
12
13
|
const urlRef = useRef(null);
|
|
14
|
+
const [refreshTick, setRefreshTick] = useState(0);
|
|
13
15
|
const relativeScale = scale / tile.srcScale;
|
|
16
|
+
useEffect(() => {
|
|
17
|
+
if (!tilingPlugin) return;
|
|
18
|
+
return tilingPlugin.onRefreshPages((pages) => {
|
|
19
|
+
if (pages.includes(pageIndex)) {
|
|
20
|
+
setRefreshTick((tick) => tick + 1);
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
}, [tilingPlugin]);
|
|
14
24
|
useEffect(() => {
|
|
15
25
|
if (tile.status === "ready" && urlRef.current) return;
|
|
16
26
|
if (!tilingCapability) return;
|
|
@@ -31,7 +41,7 @@ function TileImg({ pageIndex, tile, dpr, scale }) {
|
|
|
31
41
|
});
|
|
32
42
|
}
|
|
33
43
|
};
|
|
34
|
-
}, [pageIndex, tile.id]);
|
|
44
|
+
}, [pageIndex, tile.id, refreshTick]);
|
|
35
45
|
const handleImageLoad = () => {
|
|
36
46
|
if (urlRef.current) {
|
|
37
47
|
URL.revokeObjectURL(urlRef.current);
|
package/dist/preact/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../src/shared/hooks/use-tiling.ts","../../src/shared/components/tile-img.tsx","../../src/shared/components/tiling-layer.tsx"],"sourcesContent":["import { useCapability, usePlugin } from '@embedpdf/core/@framework';\nimport { TilingPlugin } from '@embedpdf/plugin-tiling';\n\nexport const useTilingPlugin = () => usePlugin<TilingPlugin>(TilingPlugin.id);\nexport const useTilingCapability = () => useCapability<TilingPlugin>(TilingPlugin.id);\n","import { ignore, PdfErrorCode } from '@embedpdf/models';\nimport { Tile } from '@embedpdf/plugin-tiling';\nimport { useEffect, useRef, useState } from '@framework';\n\nimport { useTilingCapability } from '../hooks/use-tiling';\n\ninterface TileImgProps {\n pageIndex: number;\n tile: Tile;\n dpr: number;\n scale: number;\n}\n\nexport function TileImg({ pageIndex, tile, dpr, scale }: TileImgProps) {\n const { provides: tilingCapability } = useTilingCapability();\n const [url, setUrl] = useState<string>();\n const urlRef = useRef<string | null>(null);\n\n const relativeScale = scale / tile.srcScale;\n\n /* kick off render exactly once per tile */\n useEffect(() => {\n if (tile.status === 'ready' && urlRef.current) return; // already done\n if (!tilingCapability) return;\n const task = tilingCapability.renderTile({ pageIndex, tile, dpr });\n task.wait((blob) => {\n const objectUrl = URL.createObjectURL(blob);\n urlRef.current = objectUrl;\n setUrl(objectUrl);\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 }, [pageIndex, tile.id]); // id includes scale, so unique\n\n const handleImageLoad = () => {\n if (urlRef.current) {\n URL.revokeObjectURL(urlRef.current);\n urlRef.current = null;\n }\n };\n\n if (!url) return null; // could render a placeholder\n return (\n <img\n src={url}\n onLoad={handleImageLoad}\n style={{\n position: 'absolute',\n left: tile.screenRect.origin.x * relativeScale,\n top: tile.screenRect.origin.y * relativeScale,\n width: tile.screenRect.size.width * relativeScale,\n height: tile.screenRect.size.height * relativeScale,\n display: 'block',\n }}\n />\n );\n}\n","import { Tile } from '@embedpdf/plugin-tiling';\nimport { useEffect, useState, HTMLAttributes, CSSProperties } from '@framework';\n\nimport { TileImg } from './tile-img';\nimport { useTilingCapability } from '../hooks/use-tiling';\n\ntype TilingLayoutProps = Omit<HTMLAttributes<HTMLDivElement>, 'style'> & {\n pageIndex: number;\n scale: number;\n style?: CSSProperties;\n};\n\nexport function TilingLayer({ pageIndex, scale, style, ...props }: TilingLayoutProps) {\n const { provides: tilingProvides } = useTilingCapability();\n const [tiles, setTiles] = useState<Tile[]>([]);\n\n useEffect(() => {\n if (tilingProvides) {\n return tilingProvides.onTileRendering((tiles) => setTiles(tiles[pageIndex]));\n }\n }, [tilingProvides]);\n\n return (\n <div\n style={{\n ...style,\n }}\n {...props}\n >\n {tiles?.map((tile) => (\n <TileImg\n key={tile.id}\n pageIndex={pageIndex}\n tile={tile}\n dpr={window.devicePixelRatio}\n scale={scale}\n />\n ))}\n </div>\n );\n}\n"],"names":["tiles"],"mappings":";;;;;;AAGO,MAAM,kBAAkB,MAAM,UAAwB,aAAa,EAAE;AACrE,MAAM,sBAAsB,MAAM,cAA4B,aAAa,EAAE;ACS7E,SAAS,QAAQ,EAAE,WAAW,MAAM,KAAK,SAAuB;AACrE,QAAM,EAAE,UAAU,iBAAiB,IAAI,oBAAoB;AAC3D,QAAM,CAAC,KAAK,MAAM,IAAI,SAAiB;AACjC,QAAA,SAAS,OAAsB,IAAI;
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../src/shared/hooks/use-tiling.ts","../../src/shared/components/tile-img.tsx","../../src/shared/components/tiling-layer.tsx"],"sourcesContent":["import { useCapability, usePlugin } from '@embedpdf/core/@framework';\nimport { TilingPlugin } from '@embedpdf/plugin-tiling';\n\nexport const useTilingPlugin = () => usePlugin<TilingPlugin>(TilingPlugin.id);\nexport const useTilingCapability = () => useCapability<TilingPlugin>(TilingPlugin.id);\n","import { ignore, PdfErrorCode } from '@embedpdf/models';\nimport { Tile } from '@embedpdf/plugin-tiling';\nimport { useEffect, useRef, useState } from '@framework';\n\nimport { useTilingCapability, useTilingPlugin } from '../hooks/use-tiling';\n\ninterface TileImgProps {\n pageIndex: number;\n tile: Tile;\n dpr: number;\n scale: number;\n}\n\nexport function TileImg({ pageIndex, tile, dpr, scale }: TileImgProps) {\n const { provides: tilingCapability } = useTilingCapability();\n const { plugin: tilingPlugin } = useTilingPlugin();\n\n const [url, setUrl] = useState<string>();\n const urlRef = useRef<string | null>(null);\n const [refreshTick, setRefreshTick] = useState(0);\n\n const relativeScale = scale / tile.srcScale;\n\n useEffect(() => {\n if (!tilingPlugin) return;\n return tilingPlugin.onRefreshPages((pages) => {\n if (pages.includes(pageIndex)) {\n setRefreshTick((tick) => tick + 1);\n }\n });\n }, [tilingPlugin]);\n\n /* kick off render exactly once per tile */\n useEffect(() => {\n if (tile.status === 'ready' && urlRef.current) return; // already done\n if (!tilingCapability) return;\n const task = tilingCapability.renderTile({ pageIndex, tile, dpr });\n task.wait((blob) => {\n const objectUrl = URL.createObjectURL(blob);\n urlRef.current = objectUrl;\n setUrl(objectUrl);\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 }, [pageIndex, tile.id, refreshTick]); // id includes scale, so unique\n\n const handleImageLoad = () => {\n if (urlRef.current) {\n URL.revokeObjectURL(urlRef.current);\n urlRef.current = null;\n }\n };\n\n if (!url) return null; // could render a placeholder\n return (\n <img\n src={url}\n onLoad={handleImageLoad}\n style={{\n position: 'absolute',\n left: tile.screenRect.origin.x * relativeScale,\n top: tile.screenRect.origin.y * relativeScale,\n width: tile.screenRect.size.width * relativeScale,\n height: tile.screenRect.size.height * relativeScale,\n display: 'block',\n }}\n />\n );\n}\n","import { Tile } from '@embedpdf/plugin-tiling';\nimport { useEffect, useState, HTMLAttributes, CSSProperties } from '@framework';\n\nimport { TileImg } from './tile-img';\nimport { useTilingCapability } from '../hooks/use-tiling';\n\ntype TilingLayoutProps = Omit<HTMLAttributes<HTMLDivElement>, 'style'> & {\n pageIndex: number;\n scale: number;\n style?: CSSProperties;\n};\n\nexport function TilingLayer({ pageIndex, scale, style, ...props }: TilingLayoutProps) {\n const { provides: tilingProvides } = useTilingCapability();\n const [tiles, setTiles] = useState<Tile[]>([]);\n\n useEffect(() => {\n if (tilingProvides) {\n return tilingProvides.onTileRendering((tiles) => setTiles(tiles[pageIndex]));\n }\n }, [tilingProvides]);\n\n return (\n <div\n style={{\n ...style,\n }}\n {...props}\n >\n {tiles?.map((tile) => (\n <TileImg\n key={tile.id}\n pageIndex={pageIndex}\n tile={tile}\n dpr={window.devicePixelRatio}\n scale={scale}\n />\n ))}\n </div>\n );\n}\n"],"names":["tiles"],"mappings":";;;;;;AAGO,MAAM,kBAAkB,MAAM,UAAwB,aAAa,EAAE;AACrE,MAAM,sBAAsB,MAAM,cAA4B,aAAa,EAAE;ACS7E,SAAS,QAAQ,EAAE,WAAW,MAAM,KAAK,SAAuB;AACrE,QAAM,EAAE,UAAU,iBAAiB,IAAI,oBAAoB;AAC3D,QAAM,EAAE,QAAQ,aAAa,IAAI,gBAAgB;AAEjD,QAAM,CAAC,KAAK,MAAM,IAAI,SAAiB;AACjC,QAAA,SAAS,OAAsB,IAAI;AACzC,QAAM,CAAC,aAAa,cAAc,IAAI,SAAS,CAAC;AAE1C,QAAA,gBAAgB,QAAQ,K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EO,SAAS,YAAY,EAAE,WAAW,OAAO,OAAO,GAAG,SAA4B;AACpF,QAAM,EAAE,UAAU,eAAe,IAAI,oBAAoB;AACzD,QAAM,CAAC,OAAO,QAAQ,IAAI,SAAiB,CAAA,CAAE;AAE7C,YAAU,MAAM;AACd,QAAI,gBAAgB;AACX,aAAA,eAAe,gBAAgB,CAACA,WAAU,SAASA,OAAM,SAAS,CAAC,CAAC;AAAA,IAAA;AAAA,EAC7E,GACC,CAAC,cAAc,CAAC;AAGjB,SAAA;AAAA,IAAC;AAAA,IAAA;AAAA,MACC,OAAO;AAAA,QACL,GAAG;AAAA,MACL;AAAA,MACC,GAAG;AAAA,MAEH,UAAA,+BAAO,IAAI,CAAC,SACX;AAAA,QAAC;AAAA,QAAA;AAAA,UAEC;AAAA,UACA;AAAA,UACA,KAAK,OAAO;AAAA,UACZ;AAAA,QAAA;AAAA,QAJK,KAAK;AAAA,MAMb;AAAA,IAAA;AAAA,EACH;AAEJ;"}
|
package/dist/react/index.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("@embedpdf/core/react"),r=require("@embedpdf/plugin-tiling"),t=require("react/jsx-runtime"),i=require("react"),n=require("@embedpdf/models"),s=()=>e.useCapability(r.TilingPlugin.id);function c({pageIndex:e,tile:r,dpr:c,scale:l}){const{provides:u}=s(),[
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("@embedpdf/core/react"),r=require("@embedpdf/plugin-tiling"),t=require("react/jsx-runtime"),i=require("react"),n=require("@embedpdf/models"),s=()=>e.usePlugin(r.TilingPlugin.id),u=()=>e.useCapability(r.TilingPlugin.id);function c({pageIndex:e,tile:r,dpr:c,scale:l}){const{provides:d}=u(),{plugin:o}=s(),[a,g]=i.useState(),p=i.useRef(null),[f,x]=i.useState(0),R=l/r.srcScale;i.useEffect((()=>{if(o)return o.onRefreshPages((r=>{r.includes(e)&&x((e=>e+1))}))}),[o]),i.useEffect((()=>{if("ready"===r.status&&p.current)return;if(!d)return;const t=d.renderTile({pageIndex:e,tile:r,dpr:c});return t.wait((e=>{const r=URL.createObjectURL(e);p.current=r,g(r)}),n.ignore),()=>{p.current?(URL.revokeObjectURL(p.current),p.current=null):t.abort({code:n.PdfErrorCode.Cancelled,message:"canceled render task"})}}),[e,r.id,f]);return a?t.jsx("img",{src:a,onLoad:()=>{p.current&&(URL.revokeObjectURL(p.current),p.current=null)},style:{position:"absolute",left:r.screenRect.origin.x*R,top:r.screenRect.origin.y*R,width:r.screenRect.size.width*R,height:r.screenRect.size.height*R,display:"block"}}):null}exports.TilingLayer=function({pageIndex:e,scale:r,style:n,...s}){const{provides:l}=u(),[d,o]=i.useState([]);return i.useEffect((()=>{if(l)return l.onTileRendering((r=>o(r[e])))}),[l]),t.jsx("div",{style:{...n},...s,children:null==d?void 0:d.map((i=>t.jsx(c,{pageIndex:e,tile:i,dpr:window.devicePixelRatio,scale:r},i.id)))})},exports.useTilingCapability=u,exports.useTilingPlugin=s;
|
|
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-tiling.ts","../../src/shared/components/tile-img.tsx","../../src/shared/components/tiling-layer.tsx"],"sourcesContent":["import { useCapability, usePlugin } from '@embedpdf/core/@framework';\nimport { TilingPlugin } from '@embedpdf/plugin-tiling';\n\nexport const useTilingPlugin = () => usePlugin<TilingPlugin>(TilingPlugin.id);\nexport const useTilingCapability = () => useCapability<TilingPlugin>(TilingPlugin.id);\n","import { ignore, PdfErrorCode } from '@embedpdf/models';\nimport { Tile } from '@embedpdf/plugin-tiling';\nimport { useEffect, useRef, useState } from '@framework';\n\nimport { useTilingCapability } from '../hooks/use-tiling';\n\ninterface TileImgProps {\n pageIndex: number;\n tile: Tile;\n dpr: number;\n scale: number;\n}\n\nexport function TileImg({ pageIndex, tile, dpr, scale }: TileImgProps) {\n const { provides: tilingCapability } = useTilingCapability();\n const [url, setUrl] = useState<string>();\n const urlRef = useRef<string | null>(null);\n\n const relativeScale = scale / tile.srcScale;\n\n /* kick off render exactly once per tile */\n useEffect(() => {\n if (tile.status === 'ready' && urlRef.current) return; // already done\n if (!tilingCapability) return;\n const task = tilingCapability.renderTile({ pageIndex, tile, dpr });\n task.wait((blob) => {\n const objectUrl = URL.createObjectURL(blob);\n urlRef.current = objectUrl;\n setUrl(objectUrl);\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 }, [pageIndex, tile.id]); // id includes scale, so unique\n\n const handleImageLoad = () => {\n if (urlRef.current) {\n URL.revokeObjectURL(urlRef.current);\n urlRef.current = null;\n }\n };\n\n if (!url) return null; // could render a placeholder\n return (\n <img\n src={url}\n onLoad={handleImageLoad}\n style={{\n position: 'absolute',\n left: tile.screenRect.origin.x * relativeScale,\n top: tile.screenRect.origin.y * relativeScale,\n width: tile.screenRect.size.width * relativeScale,\n height: tile.screenRect.size.height * relativeScale,\n display: 'block',\n }}\n />\n );\n}\n","import { Tile } from '@embedpdf/plugin-tiling';\nimport { useEffect, useState, HTMLAttributes, CSSProperties } from '@framework';\n\nimport { TileImg } from './tile-img';\nimport { useTilingCapability } from '../hooks/use-tiling';\n\ntype TilingLayoutProps = Omit<HTMLAttributes<HTMLDivElement>, 'style'> & {\n pageIndex: number;\n scale: number;\n style?: CSSProperties;\n};\n\nexport function TilingLayer({ pageIndex, scale, style, ...props }: TilingLayoutProps) {\n const { provides: tilingProvides } = useTilingCapability();\n const [tiles, setTiles] = useState<Tile[]>([]);\n\n useEffect(() => {\n if (tilingProvides) {\n return tilingProvides.onTileRendering((tiles) => setTiles(tiles[pageIndex]));\n }\n }, [tilingProvides]);\n\n return (\n <div\n style={{\n ...style,\n }}\n {...props}\n >\n {tiles?.map((tile) => (\n <TileImg\n key={tile.id}\n pageIndex={pageIndex}\n tile={tile}\n dpr={window.devicePixelRatio}\n scale={scale}\n />\n ))}\n </div>\n );\n}\n"],"names":["
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":["../../src/shared/hooks/use-tiling.ts","../../src/shared/components/tile-img.tsx","../../src/shared/components/tiling-layer.tsx"],"sourcesContent":["import { useCapability, usePlugin } from '@embedpdf/core/@framework';\nimport { TilingPlugin } from '@embedpdf/plugin-tiling';\n\nexport const useTilingPlugin = () => usePlugin<TilingPlugin>(TilingPlugin.id);\nexport const useTilingCapability = () => useCapability<TilingPlugin>(TilingPlugin.id);\n","import { ignore, PdfErrorCode } from '@embedpdf/models';\nimport { Tile } from '@embedpdf/plugin-tiling';\nimport { useEffect, useRef, useState } from '@framework';\n\nimport { useTilingCapability, useTilingPlugin } from '../hooks/use-tiling';\n\ninterface TileImgProps {\n pageIndex: number;\n tile: Tile;\n dpr: number;\n scale: number;\n}\n\nexport function TileImg({ pageIndex, tile, dpr, scale }: TileImgProps) {\n const { provides: tilingCapability } = useTilingCapability();\n const { plugin: tilingPlugin } = useTilingPlugin();\n\n const [url, setUrl] = useState<string>();\n const urlRef = useRef<string | null>(null);\n const [refreshTick, setRefreshTick] = useState(0);\n\n const relativeScale = scale / tile.srcScale;\n\n useEffect(() => {\n if (!tilingPlugin) return;\n return tilingPlugin.onRefreshPages((pages) => {\n if (pages.includes(pageIndex)) {\n setRefreshTick((tick) => tick + 1);\n }\n });\n }, [tilingPlugin]);\n\n /* kick off render exactly once per tile */\n useEffect(() => {\n if (tile.status === 'ready' && urlRef.current) return; // already done\n if (!tilingCapability) return;\n const task = tilingCapability.renderTile({ pageIndex, tile, dpr });\n task.wait((blob) => {\n const objectUrl = URL.createObjectURL(blob);\n urlRef.current = objectUrl;\n setUrl(objectUrl);\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 }, [pageIndex, tile.id, refreshTick]); // id includes scale, so unique\n\n const handleImageLoad = () => {\n if (urlRef.current) {\n URL.revokeObjectURL(urlRef.current);\n urlRef.current = null;\n }\n };\n\n if (!url) return null; // could render a placeholder\n return (\n <img\n src={url}\n onLoad={handleImageLoad}\n style={{\n position: 'absolute',\n left: tile.screenRect.origin.x * relativeScale,\n top: tile.screenRect.origin.y * relativeScale,\n width: tile.screenRect.size.width * relativeScale,\n height: tile.screenRect.size.height * relativeScale,\n display: 'block',\n }}\n />\n );\n}\n","import { Tile } from '@embedpdf/plugin-tiling';\nimport { useEffect, useState, HTMLAttributes, CSSProperties } from '@framework';\n\nimport { TileImg } from './tile-img';\nimport { useTilingCapability } from '../hooks/use-tiling';\n\ntype TilingLayoutProps = Omit<HTMLAttributes<HTMLDivElement>, 'style'> & {\n pageIndex: number;\n scale: number;\n style?: CSSProperties;\n};\n\nexport function TilingLayer({ pageIndex, scale, style, ...props }: TilingLayoutProps) {\n const { provides: tilingProvides } = useTilingCapability();\n const [tiles, setTiles] = useState<Tile[]>([]);\n\n useEffect(() => {\n if (tilingProvides) {\n return tilingProvides.onTileRendering((tiles) => setTiles(tiles[pageIndex]));\n }\n }, [tilingProvides]);\n\n return (\n <div\n style={{\n ...style,\n }}\n {...props}\n >\n {tiles?.map((tile) => (\n <TileImg\n key={tile.id}\n pageIndex={pageIndex}\n tile={tile}\n dpr={window.devicePixelRatio}\n scale={scale}\n />\n ))}\n </div>\n );\n}\n"],"names":["useTilingPlugin","usePlugin","TilingPlugin","id","useTilingCapability","useCapability","TileImg","pageIndex","tile","dpr","scale","provides","tilingCapability","plugin","tilingPlugin","url","setUrl","useState","urlRef","useRef","refreshTick","setRefreshTick","relativeScale","srcScale","useEffect","onRefreshPages","pages","includes","tick","status","current","task","renderTile","wait","blob","objectUrl","URL","createObjectURL","ignore","revokeObjectURL","abort","code","PdfErrorCode","Cancelled","message","jsxRuntime","jsx","src","onLoad","style","position","left","screenRect","origin","x","top","y","width","size","height","display","props","tilingProvides","tiles","setTiles","onTileRendering","children","map","window","devicePixelRatio"],"mappings":"6OAGaA,EAAkB,IAAMC,YAAwBC,EAAAA,aAAaC,IAC7DC,EAAsB,IAAMC,gBAA4BH,EAAAA,aAAaC,ICS3E,SAASG,GAAQC,UAAEA,EAAAC,KAAWA,EAAMC,IAAAA,EAAAC,MAAKA,IAC9C,MAAQC,SAAUC,GAAqBR,KAC/BS,OAAQC,GAAiBd,KAE1Be,EAAKC,GAAUC,aAChBC,EAASC,SAAsB,OAC9BC,EAAaC,GAAkBJ,EAAAA,SAAS,GAEzCK,EAAgBZ,EAAQF,EAAKe,SAEnCC,EAAAA,WAAU,KACR,GAAKV,EACE,OAAAA,EAAaW,gBAAgBC,IAC9BA,EAAMC,SAASpB,IACFc,GAACO,GAASA,EAAO,GAAC,GAEpC,GACA,CAACd,IAGJU,EAAAA,WAAU,KACR,GAAoB,UAAhBhB,EAAKqB,QAAsBX,EAAOY,QAAS,OAC/C,IAAKlB,EAAkB,OACvB,MAAMmB,EAAOnB,EAAiBoB,WAAW,CAAEzB,YAAWC,OAAMC,QAO5D,OANKsB,EAAAE,MAAMC,IACH,MAAAC,EAAYC,IAAIC,gBAAgBH,GACtChB,EAAOY,QAAUK,EACjBnB,EAAOmB,EAAS,GACfG,UAEI,KACDpB,EAAOY,SACLM,IAAAG,gBAAgBrB,EAAOY,SAC3BZ,EAAOY,QAAU,MAEjBC,EAAKS,MAAM,CACTC,KAAMC,EAAaA,aAAAC,UACnBC,QAAS,wBACV,CAEL,GACC,CAACrC,EAAWC,EAAKL,GAAIiB,IASpB,OAACL,EAEH8B,EAAAC,IAAC,MAAA,CACCC,IAAKhC,EACLiC,OAXoB,KAClB9B,EAAOY,UACLM,IAAAG,gBAAgBrB,EAAOY,SAC3BZ,EAAOY,QAAU,KAAA,EASjBmB,MAAO,CACLC,SAAU,WACVC,KAAM3C,EAAK4C,WAAWC,OAAOC,EAAIhC,EACjCiC,IAAK/C,EAAK4C,WAAWC,OAAOG,EAAIlC,EAChCmC,MAAOjD,EAAK4C,WAAWM,KAAKD,MAAQnC,EACpCqC,OAAQnD,EAAK4C,WAAWM,KAAKC,OAASrC,EACtCsC,QAAS,WAXE,IAenB,qBClEO,UAAqBrD,UAAEA,EAAAG,MAAWA,QAAOuC,KAAUY,IACxD,MAAQlD,SAAUmD,GAAmB1D,KAC9B2D,EAAOC,GAAY/C,EAAAA,SAAiB,IASzC,OAPFO,EAAAA,WAAU,KACR,GAAIsC,EACK,OAAAA,EAAeG,iBAAiBF,GAAUC,EAASD,EAAMxD,KAAW,GAE5E,CAACuD,IAGFjB,EAAAC,IAAC,MAAA,CACCG,MAAO,IACFA,MAEDY,EAEHK,SAAA,MAAAH,OAAA,EAAAA,EAAOI,KAAK3D,GACXqC,EAAAC,IAACxC,EAAA,CAECC,YACAC,OACAC,IAAK2D,OAAOC,iBACZ3D,SAJKF,EAAKL,OASpB"}
|
package/dist/react/index.js
CHANGED
|
@@ -7,9 +7,19 @@ const useTilingPlugin = () => usePlugin(TilingPlugin.id);
|
|
|
7
7
|
const useTilingCapability = () => useCapability(TilingPlugin.id);
|
|
8
8
|
function TileImg({ pageIndex, tile, dpr, scale }) {
|
|
9
9
|
const { provides: tilingCapability } = useTilingCapability();
|
|
10
|
+
const { plugin: tilingPlugin } = useTilingPlugin();
|
|
10
11
|
const [url, setUrl] = useState();
|
|
11
12
|
const urlRef = useRef(null);
|
|
13
|
+
const [refreshTick, setRefreshTick] = useState(0);
|
|
12
14
|
const relativeScale = scale / tile.srcScale;
|
|
15
|
+
useEffect(() => {
|
|
16
|
+
if (!tilingPlugin) return;
|
|
17
|
+
return tilingPlugin.onRefreshPages((pages) => {
|
|
18
|
+
if (pages.includes(pageIndex)) {
|
|
19
|
+
setRefreshTick((tick) => tick + 1);
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
}, [tilingPlugin]);
|
|
13
23
|
useEffect(() => {
|
|
14
24
|
if (tile.status === "ready" && urlRef.current) return;
|
|
15
25
|
if (!tilingCapability) return;
|
|
@@ -30,7 +40,7 @@ function TileImg({ pageIndex, tile, dpr, scale }) {
|
|
|
30
40
|
});
|
|
31
41
|
}
|
|
32
42
|
};
|
|
33
|
-
}, [pageIndex, tile.id]);
|
|
43
|
+
}, [pageIndex, tile.id, refreshTick]);
|
|
34
44
|
const handleImageLoad = () => {
|
|
35
45
|
if (urlRef.current) {
|
|
36
46
|
URL.revokeObjectURL(urlRef.current);
|
package/dist/react/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../src/shared/hooks/use-tiling.ts","../../src/shared/components/tile-img.tsx","../../src/shared/components/tiling-layer.tsx"],"sourcesContent":["import { useCapability, usePlugin } from '@embedpdf/core/@framework';\nimport { TilingPlugin } from '@embedpdf/plugin-tiling';\n\nexport const useTilingPlugin = () => usePlugin<TilingPlugin>(TilingPlugin.id);\nexport const useTilingCapability = () => useCapability<TilingPlugin>(TilingPlugin.id);\n","import { ignore, PdfErrorCode } from '@embedpdf/models';\nimport { Tile } from '@embedpdf/plugin-tiling';\nimport { useEffect, useRef, useState } from '@framework';\n\nimport { useTilingCapability } from '../hooks/use-tiling';\n\ninterface TileImgProps {\n pageIndex: number;\n tile: Tile;\n dpr: number;\n scale: number;\n}\n\nexport function TileImg({ pageIndex, tile, dpr, scale }: TileImgProps) {\n const { provides: tilingCapability } = useTilingCapability();\n const [url, setUrl] = useState<string>();\n const urlRef = useRef<string | null>(null);\n\n const relativeScale = scale / tile.srcScale;\n\n /* kick off render exactly once per tile */\n useEffect(() => {\n if (tile.status === 'ready' && urlRef.current) return; // already done\n if (!tilingCapability) return;\n const task = tilingCapability.renderTile({ pageIndex, tile, dpr });\n task.wait((blob) => {\n const objectUrl = URL.createObjectURL(blob);\n urlRef.current = objectUrl;\n setUrl(objectUrl);\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 }, [pageIndex, tile.id]); // id includes scale, so unique\n\n const handleImageLoad = () => {\n if (urlRef.current) {\n URL.revokeObjectURL(urlRef.current);\n urlRef.current = null;\n }\n };\n\n if (!url) return null; // could render a placeholder\n return (\n <img\n src={url}\n onLoad={handleImageLoad}\n style={{\n position: 'absolute',\n left: tile.screenRect.origin.x * relativeScale,\n top: tile.screenRect.origin.y * relativeScale,\n width: tile.screenRect.size.width * relativeScale,\n height: tile.screenRect.size.height * relativeScale,\n display: 'block',\n }}\n />\n );\n}\n","import { Tile } from '@embedpdf/plugin-tiling';\nimport { useEffect, useState, HTMLAttributes, CSSProperties } from '@framework';\n\nimport { TileImg } from './tile-img';\nimport { useTilingCapability } from '../hooks/use-tiling';\n\ntype TilingLayoutProps = Omit<HTMLAttributes<HTMLDivElement>, 'style'> & {\n pageIndex: number;\n scale: number;\n style?: CSSProperties;\n};\n\nexport function TilingLayer({ pageIndex, scale, style, ...props }: TilingLayoutProps) {\n const { provides: tilingProvides } = useTilingCapability();\n const [tiles, setTiles] = useState<Tile[]>([]);\n\n useEffect(() => {\n if (tilingProvides) {\n return tilingProvides.onTileRendering((tiles) => setTiles(tiles[pageIndex]));\n }\n }, [tilingProvides]);\n\n return (\n <div\n style={{\n ...style,\n }}\n {...props}\n >\n {tiles?.map((tile) => (\n <TileImg\n key={tile.id}\n pageIndex={pageIndex}\n tile={tile}\n dpr={window.devicePixelRatio}\n scale={scale}\n />\n ))}\n </div>\n );\n}\n"],"names":["tiles"],"mappings":";;;;;AAGO,MAAM,kBAAkB,MAAM,UAAwB,aAAa,EAAE;AACrE,MAAM,sBAAsB,MAAM,cAA4B,aAAa,EAAE;ACS7E,SAAS,QAAQ,EAAE,WAAW,MAAM,KAAK,SAAuB;AACrE,QAAM,EAAE,UAAU,iBAAiB,IAAI,oBAAoB;AAC3D,QAAM,CAAC,KAAK,MAAM,IAAI,SAAiB;AACjC,QAAA,SAAS,OAAsB,IAAI;
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../src/shared/hooks/use-tiling.ts","../../src/shared/components/tile-img.tsx","../../src/shared/components/tiling-layer.tsx"],"sourcesContent":["import { useCapability, usePlugin } from '@embedpdf/core/@framework';\nimport { TilingPlugin } from '@embedpdf/plugin-tiling';\n\nexport const useTilingPlugin = () => usePlugin<TilingPlugin>(TilingPlugin.id);\nexport const useTilingCapability = () => useCapability<TilingPlugin>(TilingPlugin.id);\n","import { ignore, PdfErrorCode } from '@embedpdf/models';\nimport { Tile } from '@embedpdf/plugin-tiling';\nimport { useEffect, useRef, useState } from '@framework';\n\nimport { useTilingCapability, useTilingPlugin } from '../hooks/use-tiling';\n\ninterface TileImgProps {\n pageIndex: number;\n tile: Tile;\n dpr: number;\n scale: number;\n}\n\nexport function TileImg({ pageIndex, tile, dpr, scale }: TileImgProps) {\n const { provides: tilingCapability } = useTilingCapability();\n const { plugin: tilingPlugin } = useTilingPlugin();\n\n const [url, setUrl] = useState<string>();\n const urlRef = useRef<string | null>(null);\n const [refreshTick, setRefreshTick] = useState(0);\n\n const relativeScale = scale / tile.srcScale;\n\n useEffect(() => {\n if (!tilingPlugin) return;\n return tilingPlugin.onRefreshPages((pages) => {\n if (pages.includes(pageIndex)) {\n setRefreshTick((tick) => tick + 1);\n }\n });\n }, [tilingPlugin]);\n\n /* kick off render exactly once per tile */\n useEffect(() => {\n if (tile.status === 'ready' && urlRef.current) return; // already done\n if (!tilingCapability) return;\n const task = tilingCapability.renderTile({ pageIndex, tile, dpr });\n task.wait((blob) => {\n const objectUrl = URL.createObjectURL(blob);\n urlRef.current = objectUrl;\n setUrl(objectUrl);\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 }, [pageIndex, tile.id, refreshTick]); // id includes scale, so unique\n\n const handleImageLoad = () => {\n if (urlRef.current) {\n URL.revokeObjectURL(urlRef.current);\n urlRef.current = null;\n }\n };\n\n if (!url) return null; // could render a placeholder\n return (\n <img\n src={url}\n onLoad={handleImageLoad}\n style={{\n position: 'absolute',\n left: tile.screenRect.origin.x * relativeScale,\n top: tile.screenRect.origin.y * relativeScale,\n width: tile.screenRect.size.width * relativeScale,\n height: tile.screenRect.size.height * relativeScale,\n display: 'block',\n }}\n />\n );\n}\n","import { Tile } from '@embedpdf/plugin-tiling';\nimport { useEffect, useState, HTMLAttributes, CSSProperties } from '@framework';\n\nimport { TileImg } from './tile-img';\nimport { useTilingCapability } from '../hooks/use-tiling';\n\ntype TilingLayoutProps = Omit<HTMLAttributes<HTMLDivElement>, 'style'> & {\n pageIndex: number;\n scale: number;\n style?: CSSProperties;\n};\n\nexport function TilingLayer({ pageIndex, scale, style, ...props }: TilingLayoutProps) {\n const { provides: tilingProvides } = useTilingCapability();\n const [tiles, setTiles] = useState<Tile[]>([]);\n\n useEffect(() => {\n if (tilingProvides) {\n return tilingProvides.onTileRendering((tiles) => setTiles(tiles[pageIndex]));\n }\n }, [tilingProvides]);\n\n return (\n <div\n style={{\n ...style,\n }}\n {...props}\n >\n {tiles?.map((tile) => (\n <TileImg\n key={tile.id}\n pageIndex={pageIndex}\n tile={tile}\n dpr={window.devicePixelRatio}\n scale={scale}\n />\n ))}\n </div>\n );\n}\n"],"names":["tiles"],"mappings":";;;;;AAGO,MAAM,kBAAkB,MAAM,UAAwB,aAAa,EAAE;AACrE,MAAM,sBAAsB,MAAM,cAA4B,aAAa,EAAE;ACS7E,SAAS,QAAQ,EAAE,WAAW,MAAM,KAAK,SAAuB;AACrE,QAAM,EAAE,UAAU,iBAAiB,IAAI,oBAAoB;AAC3D,QAAM,EAAE,QAAQ,aAAa,IAAI,gBAAgB;AAEjD,QAAM,CAAC,KAAK,MAAM,IAAI,SAAiB;AACjC,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AAA,QACpC,QAAQ,KAAK,WAAW,KAAK,SAAS;AAAA,QACtC,SAAS;AAAA,MAAA;AAAA,IACX;AAAA,EACF;AAEJ;AClEO,SAAS,YAAY,EAAE,WAAW,OAAO,OAAO,GAAG,SAA4B;AACpF,QAAM,EAAE,UAAU,eAAe,IAAI,oBAAoB;AACzD,QAAM,CAAC,OAAO,QAAQ,IAAI,SAAiB,CAAA,CAAE;AAE7C,YAAU,MAAM;AACd,QAAI,gBAAgB;AACX,aAAA,eAAe,gBAAgB,CAACA,WAAU,SAASA,OAAM,SAAS,CAAC,CAAC;AAAA,IAAA;AAAA,EAC7E,GACC,CAAC,cAAc,CAAC;AAGjB,SAAA;AAAA,IAAC;AAAA,IAAA;AAAA,MACC,OAAO;AAAA,QACL,GAAG;AAAA,MACL;AAAA,MACC,GAAG;AAAA,MAEH,UAAA,+BAAO,IAAI,CAAC,SACX;AAAA,QAAC;AAAA,QAAA;AAAA,UAEC;AAAA,UACA;AAAA,UACA,KAAK,OAAO;AAAA,UACZ;AAAA,QAAA;AAAA,QAJK,KAAK;AAAA,MAMb;AAAA,IAAA;AAAA,EACH;AAEJ;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@embedpdf/plugin-tiling",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.19",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/index.cjs",
|
|
6
6
|
"module": "./dist/index.js",
|
|
@@ -28,26 +28,26 @@
|
|
|
28
28
|
}
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@embedpdf/models": "1.0.
|
|
31
|
+
"@embedpdf/models": "1.0.19"
|
|
32
32
|
},
|
|
33
33
|
"devDependencies": {
|
|
34
34
|
"@types/react": "^18.2.0",
|
|
35
35
|
"typescript": "^5.0.0",
|
|
36
|
-
"@embedpdf/core": "1.0.17",
|
|
37
36
|
"@embedpdf/build": "1.0.0",
|
|
38
|
-
"@embedpdf/plugin-
|
|
39
|
-
"@embedpdf/plugin-
|
|
40
|
-
"@embedpdf/plugin-viewport": "1.0.
|
|
37
|
+
"@embedpdf/plugin-render": "1.0.19",
|
|
38
|
+
"@embedpdf/plugin-scroll": "1.0.19",
|
|
39
|
+
"@embedpdf/plugin-viewport": "1.0.19",
|
|
40
|
+
"@embedpdf/core": "1.0.19"
|
|
41
41
|
},
|
|
42
42
|
"peerDependencies": {
|
|
43
43
|
"react": ">=16.8.0",
|
|
44
44
|
"react-dom": ">=16.8.0",
|
|
45
45
|
"preact": "^10.26.4",
|
|
46
46
|
"vue": ">=3.2.0",
|
|
47
|
-
"@embedpdf/core": "1.0.
|
|
48
|
-
"@embedpdf/plugin-render": "1.0.
|
|
49
|
-
"@embedpdf/plugin-
|
|
50
|
-
"@embedpdf/plugin-
|
|
47
|
+
"@embedpdf/core": "1.0.19",
|
|
48
|
+
"@embedpdf/plugin-render": "1.0.19",
|
|
49
|
+
"@embedpdf/plugin-scroll": "1.0.19",
|
|
50
|
+
"@embedpdf/plugin-viewport": "1.0.19"
|
|
51
51
|
},
|
|
52
52
|
"files": [
|
|
53
53
|
"dist",
|