@embedpdf/plugin-tiling 1.0.11 → 1.0.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +2 -269
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +1 -86
- package/dist/index.js +21 -35
- package/dist/index.js.map +1 -1
- package/dist/lib/actions.d.ts +18 -0
- package/dist/lib/index.d.ts +8 -0
- package/dist/lib/manifest.d.ts +4 -0
- package/dist/lib/reducer.d.ts +5 -0
- package/dist/lib/tiling-plugin.d.ts +17 -0
- package/dist/lib/types.d.ts +46 -0
- package/dist/lib/utils.d.ts +8 -0
- package/dist/preact/adapter.d.ts +5 -0
- package/dist/preact/core.d.ts +1 -0
- package/dist/preact/index.cjs +2 -128
- package/dist/preact/index.cjs.map +1 -1
- package/dist/preact/index.d.ts +1 -23
- package/dist/preact/index.js +11 -19
- package/dist/preact/index.js.map +1 -1
- package/dist/react/adapter.d.ts +2 -0
- package/dist/react/core.d.ts +1 -0
- package/dist/react/index.cjs +2 -128
- package/dist/react/index.cjs.map +1 -1
- package/dist/react/index.d.ts +1 -23
- package/dist/react/index.js +10 -19
- package/dist/react/index.js.map +1 -1
- package/dist/shared-preact/components/index.d.ts +1 -0
- package/dist/shared-preact/components/tile-img.d.ts +9 -0
- package/dist/shared-preact/components/tiling-layer.d.ts +8 -0
- package/dist/shared-preact/hooks/index.d.ts +1 -0
- package/dist/shared-preact/hooks/use-tiling.d.ts +11 -0
- package/dist/shared-preact/index.d.ts +2 -0
- package/dist/shared-react/components/index.d.ts +1 -0
- package/dist/shared-react/components/tile-img.d.ts +9 -0
- package/dist/shared-react/components/tiling-layer.d.ts +8 -0
- package/dist/shared-react/hooks/index.d.ts +1 -0
- package/dist/shared-react/hooks/use-tiling.d.ts +11 -0
- package/dist/shared-react/index.d.ts +2 -0
- package/dist/vue/components/index.d.ts +2 -0
- package/dist/vue/components/tile-img.vue.d.ts +13 -0
- package/dist/vue/components/tiling-layer.vue.d.ts +8 -0
- package/dist/vue/hooks/index.d.ts +1 -0
- package/dist/vue/hooks/use-tiling.d.ts +5 -0
- package/dist/vue/index.cjs +2 -0
- package/dist/vue/index.cjs.map +1 -0
- package/dist/vue/index.d.ts +2 -0
- package/dist/vue/index.js +118 -0
- package/dist/vue/index.js.map +1 -0
- package/package.json +25 -14
- package/dist/index.d.cts +0 -86
- package/dist/preact/index.d.cts +0 -23
- package/dist/react/index.d.cts +0 -23
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/lib/manifest.ts","../src/lib/actions.ts","../src/lib/reducer.ts","../src/lib/tiling-plugin.ts","../src/lib/utils.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 {\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 { 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 { 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"],"mappings":";AAIO,IAAM,mBAAmB;AAEzB,IAAM,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,EACd;AACF;;;ACjBO,IAAM,uBAAuB;AAC7B,IAAM,mBAAmB;AAczB,IAAM,qBAAqB,CAAC,WAA6D;AAAA,EAC9F,MAAM;AAAA,EACN,SAAS;AACX;AAEO,IAAM,iBAAiB,CAC5B,WACA,QACA,YAC0B,EAAE,MAAM,kBAAkB,SAAS,EAAE,WAAW,QAAQ,OAAO,EAAE;;;ACrBtF,IAAM,eAA4B;AAAA,EACvC,cAAc,CAAC;AACjB;AAEO,I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.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,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,CAAC,EAAE,UAAU,MAAnC,mBAAsC;AAClD,cA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AAK,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;"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Tile, TileStatus } from './types';
|
|
2
|
+
export declare const UPDATE_VISIBLE_TILES = "UPDATE_VISIBLE_TILES";
|
|
3
|
+
export declare const MARK_TILE_STATUS = "MARK_TILE_STATUS";
|
|
4
|
+
export type UpdateVisibleTilesAction = {
|
|
5
|
+
type: typeof UPDATE_VISIBLE_TILES;
|
|
6
|
+
payload: Record<number, Tile[]>;
|
|
7
|
+
};
|
|
8
|
+
export type MarkTileStatusAction = {
|
|
9
|
+
type: typeof MARK_TILE_STATUS;
|
|
10
|
+
payload: {
|
|
11
|
+
pageIndex: number;
|
|
12
|
+
tileId: string;
|
|
13
|
+
status: TileStatus;
|
|
14
|
+
};
|
|
15
|
+
};
|
|
16
|
+
export type TilingAction = UpdateVisibleTilesAction | MarkTileStatusAction;
|
|
17
|
+
export declare const updateVisibleTiles: (tiles: Record<number, Tile[]>) => UpdateVisibleTilesAction;
|
|
18
|
+
export declare const markTileStatus: (pageIndex: number, tileId: string, status: TileStatus) => MarkTileStatusAction;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { PluginPackage } from '@embedpdf/core';
|
|
2
|
+
import { TilingAction } from './actions';
|
|
3
|
+
import { TilingPlugin } from './tiling-plugin';
|
|
4
|
+
import { TilingPluginConfig, TilingState } from './types';
|
|
5
|
+
export declare const TilingPluginPackage: PluginPackage<TilingPlugin, TilingPluginConfig, TilingState, TilingAction>;
|
|
6
|
+
export * from './tiling-plugin';
|
|
7
|
+
export * from './types';
|
|
8
|
+
export * from './manifest';
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { BasePlugin, CoreState, PluginRegistry, StoreState } from '@embedpdf/core';
|
|
2
|
+
import { TilingPluginConfig, TilingCapability, TilingState } from './types';
|
|
3
|
+
export declare class TilingPlugin extends BasePlugin<TilingPluginConfig, TilingCapability> {
|
|
4
|
+
static readonly id: "tiling";
|
|
5
|
+
private readonly tileRendering$;
|
|
6
|
+
private config;
|
|
7
|
+
private renderCapability;
|
|
8
|
+
private scrollCapability;
|
|
9
|
+
private viewportCapability;
|
|
10
|
+
constructor(id: string, registry: PluginRegistry, config: TilingPluginConfig);
|
|
11
|
+
initialize(): Promise<void>;
|
|
12
|
+
protected onCoreStoreUpdated(oldState: StoreState<CoreState>, newState: StoreState<CoreState>): void;
|
|
13
|
+
private calculateVisibleTiles;
|
|
14
|
+
onStoreUpdated(_prevState: TilingState, newState: TilingState): void;
|
|
15
|
+
protected buildCapability(): TilingCapability;
|
|
16
|
+
private renderTile;
|
|
17
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { BasePluginConfig, EventHook } from '@embedpdf/core';
|
|
2
|
+
import { PdfErrorReason, PdfPageObject, Rect, Rotation, Task } from '@embedpdf/models';
|
|
3
|
+
import { PageVisibilityMetrics } from '@embedpdf/plugin-scroll';
|
|
4
|
+
export interface TilingPluginConfig extends BasePluginConfig {
|
|
5
|
+
tileSize: number;
|
|
6
|
+
overlapPx: number;
|
|
7
|
+
extraRings: number;
|
|
8
|
+
}
|
|
9
|
+
export interface VisibleRect {
|
|
10
|
+
pageX: number;
|
|
11
|
+
pageY: number;
|
|
12
|
+
visibleWidth: number;
|
|
13
|
+
visibleHeight: number;
|
|
14
|
+
}
|
|
15
|
+
export type TileStatus = 'queued' | 'rendering' | 'ready';
|
|
16
|
+
export interface Tile {
|
|
17
|
+
status: TileStatus;
|
|
18
|
+
screenRect: Rect;
|
|
19
|
+
pageRect: Rect;
|
|
20
|
+
isFallback: boolean;
|
|
21
|
+
srcScale: number;
|
|
22
|
+
col: number;
|
|
23
|
+
row: number;
|
|
24
|
+
id: string;
|
|
25
|
+
}
|
|
26
|
+
export interface TilingState {
|
|
27
|
+
visibleTiles: Record<number, Tile[]>;
|
|
28
|
+
}
|
|
29
|
+
export interface TilingCapability {
|
|
30
|
+
renderTile: (options: RenderTileOptions) => Task<Blob, PdfErrorReason>;
|
|
31
|
+
onTileRendering: EventHook<Record<number, Tile[]>>;
|
|
32
|
+
}
|
|
33
|
+
export interface CalculateTilesForPageOptions {
|
|
34
|
+
tileSize: number;
|
|
35
|
+
overlapPx: number;
|
|
36
|
+
extraRings: number;
|
|
37
|
+
scale: number;
|
|
38
|
+
rotation: Rotation;
|
|
39
|
+
page: PdfPageObject;
|
|
40
|
+
metric: PageVisibilityMetrics;
|
|
41
|
+
}
|
|
42
|
+
export interface RenderTileOptions {
|
|
43
|
+
pageIndex: number;
|
|
44
|
+
tile: Tile;
|
|
45
|
+
dpr: number;
|
|
46
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { CalculateTilesForPageOptions, Tile } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* Build a grid where neighbouring tiles overlap by `overlapPx`
|
|
4
|
+
* (screen pixels). Inner tiles keep the full `tileSize`, edge
|
|
5
|
+
* tiles are clipped to the page bounds. All screen-space values
|
|
6
|
+
* are rounded to **integers** to avoid sub-pixel seams.
|
|
7
|
+
*/
|
|
8
|
+
export declare function calculateTilesForPage({ tileSize, overlapPx, extraRings, scale, rotation, page, metric, }: CalculateTilesForPageOptions): Tile[];
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { Fragment } from 'preact';
|
|
2
|
+
export { useEffect, useRef, useState, useCallback, useMemo } from 'preact/hooks';
|
|
3
|
+
export type { ComponentChildren as ReactNode } from 'preact';
|
|
4
|
+
export type CSSProperties = import('preact').JSX.CSSProperties;
|
|
5
|
+
export type HTMLAttributes<T = any> = import('preact').JSX.HTMLAttributes<T extends EventTarget ? T : never>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '@embedpdf/core/preact';
|
package/dist/preact/index.cjs
CHANGED
|
@@ -1,128 +1,2 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
|
|
20
|
-
// src/preact/index.ts
|
|
21
|
-
var preact_exports = {};
|
|
22
|
-
__export(preact_exports, {
|
|
23
|
-
TilingLayer: () => TilingLayer,
|
|
24
|
-
useTilingCapability: () => useTilingCapability,
|
|
25
|
-
useTilingPlugin: () => useTilingPlugin
|
|
26
|
-
});
|
|
27
|
-
module.exports = __toCommonJS(preact_exports);
|
|
28
|
-
|
|
29
|
-
// src/preact/hooks/use-tiling.ts
|
|
30
|
-
var import_preact = require("@embedpdf/core/preact");
|
|
31
|
-
var import_plugin_tiling = require("@embedpdf/plugin-tiling");
|
|
32
|
-
var useTilingPlugin = () => (0, import_preact.usePlugin)(import_plugin_tiling.TilingPlugin.id);
|
|
33
|
-
var useTilingCapability = () => (0, import_preact.useCapability)(import_plugin_tiling.TilingPlugin.id);
|
|
34
|
-
|
|
35
|
-
// src/preact/components/tiling-layer.tsx
|
|
36
|
-
var import_hooks2 = require("preact/hooks");
|
|
37
|
-
|
|
38
|
-
// src/preact/components/tile-img.tsx
|
|
39
|
-
var import_models = require("@embedpdf/models");
|
|
40
|
-
var import_hooks = require("preact/hooks");
|
|
41
|
-
var import_jsx_runtime = require("preact/jsx-runtime");
|
|
42
|
-
function TileImg({ pageIndex, tile, dpr, scale }) {
|
|
43
|
-
const { provides: tilingCapability } = useTilingCapability();
|
|
44
|
-
const [url, setUrl] = (0, import_hooks.useState)();
|
|
45
|
-
const urlRef = (0, import_hooks.useRef)(null);
|
|
46
|
-
const relativeScale = scale / tile.srcScale;
|
|
47
|
-
(0, import_hooks.useEffect)(() => {
|
|
48
|
-
if (tile.status === "ready" && urlRef.current) return;
|
|
49
|
-
if (!tilingCapability) return;
|
|
50
|
-
const task = tilingCapability.renderTile({ pageIndex, tile, dpr });
|
|
51
|
-
task.wait((blob) => {
|
|
52
|
-
const objectUrl = URL.createObjectURL(blob);
|
|
53
|
-
urlRef.current = objectUrl;
|
|
54
|
-
setUrl(objectUrl);
|
|
55
|
-
}, import_models.ignore);
|
|
56
|
-
return () => {
|
|
57
|
-
if (urlRef.current) {
|
|
58
|
-
URL.revokeObjectURL(urlRef.current);
|
|
59
|
-
urlRef.current = null;
|
|
60
|
-
} else {
|
|
61
|
-
task.abort({
|
|
62
|
-
code: import_models.PdfErrorCode.Cancelled,
|
|
63
|
-
message: "canceled render task"
|
|
64
|
-
});
|
|
65
|
-
}
|
|
66
|
-
};
|
|
67
|
-
}, [pageIndex, tile.id]);
|
|
68
|
-
const handleImageLoad = () => {
|
|
69
|
-
if (urlRef.current) {
|
|
70
|
-
URL.revokeObjectURL(urlRef.current);
|
|
71
|
-
urlRef.current = null;
|
|
72
|
-
}
|
|
73
|
-
};
|
|
74
|
-
if (!url) return null;
|
|
75
|
-
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
76
|
-
"img",
|
|
77
|
-
{
|
|
78
|
-
src: url,
|
|
79
|
-
onLoad: handleImageLoad,
|
|
80
|
-
style: {
|
|
81
|
-
position: "absolute",
|
|
82
|
-
left: tile.screenRect.origin.x * relativeScale,
|
|
83
|
-
top: tile.screenRect.origin.y * relativeScale,
|
|
84
|
-
width: tile.screenRect.size.width * relativeScale,
|
|
85
|
-
height: tile.screenRect.size.height * relativeScale,
|
|
86
|
-
display: "block"
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
);
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
// src/preact/components/tiling-layer.tsx
|
|
93
|
-
var import_jsx_runtime2 = require("preact/jsx-runtime");
|
|
94
|
-
function TilingLayer({ pageIndex, scale, style, ...props }) {
|
|
95
|
-
const { provides: tilingProvides } = useTilingCapability();
|
|
96
|
-
const [tiles, setTiles] = (0, import_hooks2.useState)([]);
|
|
97
|
-
(0, import_hooks2.useEffect)(() => {
|
|
98
|
-
if (tilingProvides) {
|
|
99
|
-
return tilingProvides.onTileRendering((tiles2) => setTiles(tiles2[pageIndex]));
|
|
100
|
-
}
|
|
101
|
-
}, [tilingProvides]);
|
|
102
|
-
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
103
|
-
"div",
|
|
104
|
-
{
|
|
105
|
-
style: {
|
|
106
|
-
...style
|
|
107
|
-
},
|
|
108
|
-
...props,
|
|
109
|
-
children: tiles?.map((tile) => /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
110
|
-
TileImg,
|
|
111
|
-
{
|
|
112
|
-
pageIndex,
|
|
113
|
-
tile,
|
|
114
|
-
dpr: window.devicePixelRatio,
|
|
115
|
-
scale
|
|
116
|
-
},
|
|
117
|
-
tile.id
|
|
118
|
-
))
|
|
119
|
-
}
|
|
120
|
-
);
|
|
121
|
-
}
|
|
122
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
123
|
-
0 && (module.exports = {
|
|
124
|
-
TilingLayer,
|
|
125
|
-
useTilingCapability,
|
|
126
|
-
useTilingPlugin
|
|
127
|
-
});
|
|
128
|
-
//# sourceMappingURL=index.cjs.map
|
|
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 c({pageIndex:e,tile:r,dpr:c,scale:l}){const{provides:u}=s(),[o,d]=i.useState(),a=i.useRef(null),p=l/r.srcScale;i.useEffect((()=>{if("ready"===r.status&&a.current)return;if(!u)return;const t=u.renderTile({pageIndex:e,tile:r,dpr:c});return t.wait((e=>{const r=URL.createObjectURL(e);a.current=r,d(r)}),n.ignore),()=>{a.current?(URL.revokeObjectURL(a.current),a.current=null):t.abort({code:n.PdfErrorCode.Cancelled,message:"canceled render task"})}}),[e,r.id]);return o?t.jsx("img",{src:o,onLoad:()=>{a.current&&(URL.revokeObjectURL(a.current),a.current=null)},style:{position:"absolute",left:r.screenRect.origin.x*p,top:r.screenRect.origin.y*p,width:r.screenRect.size.width*p,height:r.screenRect.size.height*p,display:"block"}}):null}exports.TilingLayer=function({pageIndex:e,scale:r,style:n,...l}){const{provides:u}=s(),[o,d]=i.useState([]);return i.useEffect((()=>{if(u)return u.onTileRendering((r=>d(r[e])))}),[u]),t.jsx("div",{style:{...n},...l,children:null==o?void 0:o.map((i=>t.jsx(c,{pageIndex:e,tile:i,dpr:window.devicePixelRatio,scale:r},i.id)))})},exports.useTilingCapability=s,exports.useTilingPlugin=()=>e.usePlugin(r.TilingPlugin.id);
|
|
2
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
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":["useTilingCapability","useCapability","TilingPlugin","id","TileImg","pageIndex","tile","dpr","scale","provides","tilingCapability","url","setUrl","useState","urlRef","useRef","relativeScale","srcScale","useEffect","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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AU,KACR,GAAIkC,EACK,OAAAA,EAAeG,iBAAiBF,GAAUC,EAASD,EAAMhD,KAAW,GAE5E,CAAC+C,IAGFjB,EAAAC,IAAC,MAAA,CACCG,MAAO,IACFA,MAEDY,EAEHK,SAAA,MAAAH,OAAA,EAAAA,EAAOI,KAAKnD,GACX6B,EAAAC,IAAChC,EAAA,CAECC,YACAC,OACAC,IAAKmD,OAAOC,iBACZnD,SAJKF,EAAKH,OASpB,wDFrC+B,IAAMyD,YAAwB1D,EAAAA,aAAaC"}
|
package/dist/preact/index.d.ts
CHANGED
|
@@ -1,23 +1 @@
|
|
|
1
|
-
|
|
2
|
-
import { TilingPlugin } from '@embedpdf/plugin-tiling';
|
|
3
|
-
import { JSX } from 'preact';
|
|
4
|
-
|
|
5
|
-
declare const useTilingPlugin: () => {
|
|
6
|
-
plugin: TilingPlugin | null;
|
|
7
|
-
isLoading: boolean;
|
|
8
|
-
ready: Promise<void>;
|
|
9
|
-
};
|
|
10
|
-
declare const useTilingCapability: () => {
|
|
11
|
-
provides: Readonly<_embedpdf_plugin_tiling.TilingCapability> | null;
|
|
12
|
-
isLoading: boolean;
|
|
13
|
-
ready: Promise<void>;
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
type TilingLayoutProps = Omit<JSX.HTMLAttributes<HTMLDivElement>, 'style'> & {
|
|
17
|
-
pageIndex: number;
|
|
18
|
-
scale: number;
|
|
19
|
-
style?: JSX.CSSProperties;
|
|
20
|
-
};
|
|
21
|
-
declare function TilingLayer({ pageIndex, scale, style, ...props }: TilingLayoutProps): JSX.Element;
|
|
22
|
-
|
|
23
|
-
export { TilingLayer, useTilingCapability, useTilingPlugin };
|
|
1
|
+
export * from '../shared-preact';
|
package/dist/preact/index.js
CHANGED
|
@@ -1,16 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
import { useCapability, usePlugin } from "@embedpdf/core/preact";
|
|
1
|
+
import { usePlugin, useCapability } from "@embedpdf/core/preact";
|
|
3
2
|
import { TilingPlugin } from "@embedpdf/plugin-tiling";
|
|
4
|
-
var useTilingPlugin = () => usePlugin(TilingPlugin.id);
|
|
5
|
-
var useTilingCapability = () => useCapability(TilingPlugin.id);
|
|
6
|
-
|
|
7
|
-
// src/preact/components/tiling-layer.tsx
|
|
8
|
-
import { useEffect as useEffect2, useState as useState2 } from "preact/hooks";
|
|
9
|
-
|
|
10
|
-
// src/preact/components/tile-img.tsx
|
|
11
|
-
import { ignore, PdfErrorCode } from "@embedpdf/models";
|
|
12
|
-
import { useEffect, useRef, useState } from "preact/hooks";
|
|
13
3
|
import { jsx } from "preact/jsx-runtime";
|
|
4
|
+
import "preact";
|
|
5
|
+
import { useState, useRef, useEffect } from "preact/hooks";
|
|
6
|
+
import { ignore, PdfErrorCode } from "@embedpdf/models";
|
|
7
|
+
const useTilingPlugin = () => usePlugin(TilingPlugin.id);
|
|
8
|
+
const useTilingCapability = () => useCapability(TilingPlugin.id);
|
|
14
9
|
function TileImg({ pageIndex, tile, dpr, scale }) {
|
|
15
10
|
const { provides: tilingCapability } = useTilingCapability();
|
|
16
11
|
const [url, setUrl] = useState();
|
|
@@ -60,25 +55,22 @@ function TileImg({ pageIndex, tile, dpr, scale }) {
|
|
|
60
55
|
}
|
|
61
56
|
);
|
|
62
57
|
}
|
|
63
|
-
|
|
64
|
-
// src/preact/components/tiling-layer.tsx
|
|
65
|
-
import { jsx as jsx2 } from "preact/jsx-runtime";
|
|
66
58
|
function TilingLayer({ pageIndex, scale, style, ...props }) {
|
|
67
59
|
const { provides: tilingProvides } = useTilingCapability();
|
|
68
|
-
const [tiles, setTiles] =
|
|
69
|
-
|
|
60
|
+
const [tiles, setTiles] = useState([]);
|
|
61
|
+
useEffect(() => {
|
|
70
62
|
if (tilingProvides) {
|
|
71
63
|
return tilingProvides.onTileRendering((tiles2) => setTiles(tiles2[pageIndex]));
|
|
72
64
|
}
|
|
73
65
|
}, [tilingProvides]);
|
|
74
|
-
return /* @__PURE__ */
|
|
66
|
+
return /* @__PURE__ */ jsx(
|
|
75
67
|
"div",
|
|
76
68
|
{
|
|
77
69
|
style: {
|
|
78
70
|
...style
|
|
79
71
|
},
|
|
80
72
|
...props,
|
|
81
|
-
children: tiles
|
|
73
|
+
children: tiles == null ? void 0 : tiles.map((tile) => /* @__PURE__ */ jsx(
|
|
82
74
|
TileImg,
|
|
83
75
|
{
|
|
84
76
|
pageIndex,
|
|
@@ -96,4 +88,4 @@ export {
|
|
|
96
88
|
useTilingCapability,
|
|
97
89
|
useTilingPlugin
|
|
98
90
|
};
|
|
99
|
-
//# sourceMappingURL=index.js.map
|
|
91
|
+
//# sourceMappingURL=index.js.map
|
package/dist/preact/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/
|
|
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,EA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