@embedpdf/plugin-tiling 1.0.7 → 1.0.8
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 +16 -6
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +14 -4
- package/dist/index.js.map +1 -1
- package/package.json +7 -7
package/dist/index.cjs
CHANGED
|
@@ -114,24 +114,32 @@ var tilingReducer = (state, action) => {
|
|
|
114
114
|
|
|
115
115
|
// src/lib/tiling-plugin.ts
|
|
116
116
|
var import_core = require("@embedpdf/core");
|
|
117
|
-
var
|
|
117
|
+
var import_models2 = require("@embedpdf/models");
|
|
118
118
|
|
|
119
119
|
// src/lib/utils.ts
|
|
120
|
+
var import_models = require("@embedpdf/models");
|
|
120
121
|
function calculateTilesForPage({
|
|
121
122
|
tileSize = 768,
|
|
122
123
|
overlapPx = 2.5,
|
|
123
124
|
extraRings = 0,
|
|
124
125
|
scale,
|
|
126
|
+
rotation,
|
|
125
127
|
page,
|
|
126
128
|
metric
|
|
127
129
|
}) {
|
|
128
130
|
const pageW = page.size.width * scale;
|
|
129
131
|
const pageH = page.size.height * scale;
|
|
130
132
|
const step = tileSize - overlapPx;
|
|
131
|
-
const
|
|
132
|
-
const
|
|
133
|
-
|
|
134
|
-
|
|
133
|
+
const containerSize = (0, import_models.transformSize)(page.size, rotation, scale);
|
|
134
|
+
const rotatedVisRect = {
|
|
135
|
+
origin: { x: metric.scaled.pageX, y: metric.scaled.pageY },
|
|
136
|
+
size: { width: metric.scaled.visibleWidth, height: metric.scaled.visibleHeight }
|
|
137
|
+
};
|
|
138
|
+
const unrotatedVisRect = (0, import_models.restoreRect)(containerSize, rotatedVisRect, rotation, 1);
|
|
139
|
+
const visLeft = unrotatedVisRect.origin.x;
|
|
140
|
+
const visTop = unrotatedVisRect.origin.y;
|
|
141
|
+
const visRight = visLeft + unrotatedVisRect.size.width;
|
|
142
|
+
const visBottom = visTop + unrotatedVisRect.size.height;
|
|
135
143
|
const maxCol = Math.floor((pageW - 1) / step);
|
|
136
144
|
const maxRow = Math.floor((pageH - 1) / step);
|
|
137
145
|
const startCol = Math.max(0, Math.floor(visLeft / step) - extraRings);
|
|
@@ -197,6 +205,7 @@ var TilingPlugin = class extends import_core.BasePlugin {
|
|
|
197
205
|
return;
|
|
198
206
|
}
|
|
199
207
|
const scale = this.coreState.core.scale;
|
|
208
|
+
const rotation = this.coreState.core.rotation;
|
|
200
209
|
const visibleTiles = {};
|
|
201
210
|
for (const scrollMetric of scrollMetrics.pageVisibilityMetrics) {
|
|
202
211
|
const pageIndex = scrollMetric.pageNumber - 1;
|
|
@@ -206,6 +215,7 @@ var TilingPlugin = class extends import_core.BasePlugin {
|
|
|
206
215
|
page,
|
|
207
216
|
metric: scrollMetric,
|
|
208
217
|
scale,
|
|
218
|
+
rotation,
|
|
209
219
|
tileSize: this.config.tileSize,
|
|
210
220
|
overlapPx: this.config.overlapPx,
|
|
211
221
|
extraRings: this.config.extraRings
|
|
@@ -236,7 +246,7 @@ var TilingPlugin = class extends import_core.BasePlugin {
|
|
|
236
246
|
});
|
|
237
247
|
task.wait(() => {
|
|
238
248
|
this.dispatch(markTileStatus(options.pageIndex, options.tile.id, "ready"));
|
|
239
|
-
},
|
|
249
|
+
}, import_models2.ignore);
|
|
240
250
|
return task;
|
|
241
251
|
}
|
|
242
252
|
};
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts","../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":["export * from './lib';\n","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; // Current zoom level\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 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 { 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 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 visLeft = metric.scaled.pageX;\n const visTop = metric.scaled.pageY;\n const visRight = visLeft + metric.scaled.visibleWidth;\n const visBottom = visTop + metric.scaled.visibleHeight;\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":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACIO,IAAM,mBAAmB;AAEzB,IAAM,WAA+C;AAAA,EAC1D,IAAI;AAAA,EACJ,MAAM;AAAA,EACN,SAAS;AAAA,EACT,UAAU,CAAC,QAAQ;AAAA,EACnB,UAAU,C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ources":["../src/index.ts","../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":["export * from './lib';\n","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":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACIO,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,IAAM,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;AAC1B,cAAM,YAAY,OAAO,GAAG;AAC5B,cAAM,WAAW,SAAS,SAAS;AACnC,cAAM,YAAY,UAAU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eAAe,YAAyB,UAA6B;AAC5E,SAAK,eAAe,KAAK,SAAS,YAAY;AAAA,EAChD;AAAA,EAEU,kBAAoC;AAC5C,WAAO;AAAA,MACL,YAAY,KAAK,WAAW,KAAK,IAAI;AAAA,MACrC,iBAAiB,KAAK,eAAe;AAAA,IACvC;AAAA,EACF;AAAA,EAEQ,WAAW,SAA4B;AAC7C,QAAI,CAAC,KAAK,kBAAkB;AAC1B,YAAM,IAAI,MAAM,kCAAkC;AAAA,IACpD;AAEA,SAAK,SAAS,eAAe,QAAQ,WAAW,QAAQ,KAAK,IAAI,WAAW,CAAC;AAE7E,UAAM,OAAO,KAAK,iBAAiB,eAAe;AAAA,MAChD,WAAW,QAAQ;AAAA,MACnB,MAAM,QAAQ,KAAK;AAAA,MACnB,aAAa,QAAQ,KAAK;AAAA,MAC1B,KAAK,QAAQ;AAAA,IACf,CAAC;AAED,SAAK,KAAK,MAAM;AACd,WAAK,SAAS,eAAe,QAAQ,WAAW,QAAQ,KAAK,IAAI,OAAO,CAAC;AAAA,IAC3E,GAAG,qBAAM;AAET,WAAO;AAAA,EACT;AACF;AAxGa,aACK,KAAK;;;AEfhB,IAAM,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;","names":["import_models"]}
|
package/dist/index.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { BasePluginConfig, EventHook, BasePlugin, PluginRegistry, StoreState, CoreState, PluginManifest, PluginPackage } from '@embedpdf/core';
|
|
2
|
-
import { Rect, Task, PdfErrorReason, PdfPageObject } from '@embedpdf/models';
|
|
2
|
+
import { Rect, Task, PdfErrorReason, Rotation, PdfPageObject } from '@embedpdf/models';
|
|
3
3
|
import { PageVisibilityMetrics } from '@embedpdf/plugin-scroll';
|
|
4
4
|
|
|
5
5
|
interface TilingPluginConfig extends BasePluginConfig {
|
|
@@ -36,6 +36,7 @@ interface CalculateTilesForPageOptions {
|
|
|
36
36
|
overlapPx: number;
|
|
37
37
|
extraRings: number;
|
|
38
38
|
scale: number;
|
|
39
|
+
rotation: Rotation;
|
|
39
40
|
page: PdfPageObject;
|
|
40
41
|
metric: PageVisibilityMetrics;
|
|
41
42
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { BasePluginConfig, EventHook, BasePlugin, PluginRegistry, StoreState, CoreState, PluginManifest, PluginPackage } from '@embedpdf/core';
|
|
2
|
-
import { Rect, Task, PdfErrorReason, PdfPageObject } from '@embedpdf/models';
|
|
2
|
+
import { Rect, Task, PdfErrorReason, Rotation, PdfPageObject } from '@embedpdf/models';
|
|
3
3
|
import { PageVisibilityMetrics } from '@embedpdf/plugin-scroll';
|
|
4
4
|
|
|
5
5
|
interface TilingPluginConfig extends BasePluginConfig {
|
|
@@ -36,6 +36,7 @@ interface CalculateTilesForPageOptions {
|
|
|
36
36
|
overlapPx: number;
|
|
37
37
|
extraRings: number;
|
|
38
38
|
scale: number;
|
|
39
|
+
rotation: Rotation;
|
|
39
40
|
page: PdfPageObject;
|
|
40
41
|
metric: PageVisibilityMetrics;
|
|
41
42
|
}
|
package/dist/index.js
CHANGED
|
@@ -91,21 +91,29 @@ import {
|
|
|
91
91
|
import { ignore } from "@embedpdf/models";
|
|
92
92
|
|
|
93
93
|
// src/lib/utils.ts
|
|
94
|
+
import { restoreRect, transformSize } from "@embedpdf/models";
|
|
94
95
|
function calculateTilesForPage({
|
|
95
96
|
tileSize = 768,
|
|
96
97
|
overlapPx = 2.5,
|
|
97
98
|
extraRings = 0,
|
|
98
99
|
scale,
|
|
100
|
+
rotation,
|
|
99
101
|
page,
|
|
100
102
|
metric
|
|
101
103
|
}) {
|
|
102
104
|
const pageW = page.size.width * scale;
|
|
103
105
|
const pageH = page.size.height * scale;
|
|
104
106
|
const step = tileSize - overlapPx;
|
|
105
|
-
const
|
|
106
|
-
const
|
|
107
|
-
|
|
108
|
-
|
|
107
|
+
const containerSize = transformSize(page.size, rotation, scale);
|
|
108
|
+
const rotatedVisRect = {
|
|
109
|
+
origin: { x: metric.scaled.pageX, y: metric.scaled.pageY },
|
|
110
|
+
size: { width: metric.scaled.visibleWidth, height: metric.scaled.visibleHeight }
|
|
111
|
+
};
|
|
112
|
+
const unrotatedVisRect = restoreRect(containerSize, rotatedVisRect, rotation, 1);
|
|
113
|
+
const visLeft = unrotatedVisRect.origin.x;
|
|
114
|
+
const visTop = unrotatedVisRect.origin.y;
|
|
115
|
+
const visRight = visLeft + unrotatedVisRect.size.width;
|
|
116
|
+
const visBottom = visTop + unrotatedVisRect.size.height;
|
|
109
117
|
const maxCol = Math.floor((pageW - 1) / step);
|
|
110
118
|
const maxRow = Math.floor((pageH - 1) / step);
|
|
111
119
|
const startCol = Math.max(0, Math.floor(visLeft / step) - extraRings);
|
|
@@ -171,6 +179,7 @@ var TilingPlugin = class extends BasePlugin {
|
|
|
171
179
|
return;
|
|
172
180
|
}
|
|
173
181
|
const scale = this.coreState.core.scale;
|
|
182
|
+
const rotation = this.coreState.core.rotation;
|
|
174
183
|
const visibleTiles = {};
|
|
175
184
|
for (const scrollMetric of scrollMetrics.pageVisibilityMetrics) {
|
|
176
185
|
const pageIndex = scrollMetric.pageNumber - 1;
|
|
@@ -180,6 +189,7 @@ var TilingPlugin = class extends BasePlugin {
|
|
|
180
189
|
page,
|
|
181
190
|
metric: scrollMetric,
|
|
182
191
|
scale,
|
|
192
|
+
rotation,
|
|
183
193
|
tileSize: this.config.tileSize,
|
|
184
194
|
overlapPx: this.config.overlapPx,
|
|
185
195
|
extraRings: this.config.extraRings
|
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; // Current zoom level\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 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 { 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 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 visLeft = metric.scaled.pageX;\n const visTop = metric.scaled.pageY;\n const visRight = visLeft + metric.scaled.visibleWidth;\n const visBottom = visTop + metric.scaled.visibleHeight;\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,EAC1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BAAkB,UAAU,MAAM;AAAA,EAC1F,SAAS,CAAC,OAAO,WAAW,cAAc,OAAO,MAAM;AAAA,EACvD;AACF;","names":[]}
|
|
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,IAAM,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;AAC1B,cAAM,YAAY,OAAO,GAAG;AAC5B,cAAM,WAAW,SAAS,SA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EA,SAAK,SAAS,mBAAmB,YAAY,CAAC;AAAA,EAChD;AAAA,EAES,eAAe,YAAyB,UAA6B;AAC5E,SAAK,eAAe,KAAK,SAAS,YAAY;AAAA,EAChD;AAAA,EAEU,kBAAoC;AAC5C,WAAO;AAAA,MACL,YAAY,KAAK,WAAW,KAAK,IAAI;AAAA,MACrC,iBAAiB,KAAK,eAAe;AAAA,IACvC;AAAA,EACF;AAAA,EAEQ,WAAW,SAA4B;AAC7C,QAAI,CAAC,KAAK,kBAAkB;AAC1B,YAAM,IAAI,MAAM,kCAAkC;AAAA,IACpD;AAEA,SAAK,SAAS,eAAe,QAAQ,WAAW,QAAQ,KAAK,IAAI,WAAW,CAAC;AAE7E,UAAM,OAAO,KAAK,iBAAiB,eAAe;AAAA,MAChD,WAAW,QAAQ;AAAA,MACnB,MAAM,QAAQ,KAAK;AAAA,MACnB,aAAa,QAAQ,KAAK;AAAA,MAC1B,KAAK,QAAQ;AAAA,IACf,CAAC;AAED,SAAK,KAAK,MAAM;AACd,WAAK,SAAS,eAAe,QAAQ,WAAW,QAAQ,KAAK,IAAI,OAAO,CAAC;AAAA,IAC3E,GAAG,MAAM;AAET,WAAO;AAAA,EACT;AACF;AAxGa,aACK,KAAK;;;AEfhB,IAAM,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;","names":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@embedpdf/plugin-tiling",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.8",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/index.cjs",
|
|
6
6
|
"module": "./dist/index.js",
|
|
@@ -23,22 +23,22 @@
|
|
|
23
23
|
}
|
|
24
24
|
},
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"@embedpdf/models": "1.0.
|
|
26
|
+
"@embedpdf/models": "1.0.8"
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {
|
|
29
29
|
"@types/react": "^18.2.0",
|
|
30
30
|
"tsup": "^8.0.0",
|
|
31
31
|
"typescript": "^5.0.0",
|
|
32
|
-
"@embedpdf/core": "1.0.
|
|
33
|
-
"@embedpdf/plugin-render": "1.0.
|
|
34
|
-
"@embedpdf/plugin-
|
|
35
|
-
"@embedpdf/plugin-
|
|
32
|
+
"@embedpdf/core": "1.0.8",
|
|
33
|
+
"@embedpdf/plugin-render": "1.0.8",
|
|
34
|
+
"@embedpdf/plugin-viewport": "1.0.8",
|
|
35
|
+
"@embedpdf/plugin-scroll": "1.0.8"
|
|
36
36
|
},
|
|
37
37
|
"peerDependencies": {
|
|
38
38
|
"react": ">=16.8.0",
|
|
39
39
|
"react-dom": ">=16.8.0",
|
|
40
40
|
"preact": "^10.26.4",
|
|
41
|
-
"@embedpdf/core": "1.0.
|
|
41
|
+
"@embedpdf/core": "1.0.8"
|
|
42
42
|
},
|
|
43
43
|
"files": [
|
|
44
44
|
"dist",
|