-
Notifications
You must be signed in to change notification settings - Fork 130
Expand file tree
/
Copy pathresolveImage.ts
More file actions
38 lines (35 loc) · 1.28 KB
/
resolveImage.ts
File metadata and controls
38 lines (35 loc) · 1.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import type { ImageFragment, ResolvedImageItem } from '@superdoc/contracts';
import { requireResolvedBlockAndMeasure, type BlockMapEntry } from './resolvedBlockLookup.js';
/** Mirrors fragmentKey() for image fragments. */
function resolveImageFragmentId(fragment: ImageFragment): string {
return `image:${fragment.blockId}:${fragment.x}:${fragment.y}`;
}
/**
* Resolves an image fragment into a ResolvedImageItem with the pre-extracted ImageBlock.
*/
export function resolveImageItem(
fragment: ImageFragment,
fragmentIndex: number,
pageIndex: number,
blockMap: Map<string, BlockMapEntry>,
): ResolvedImageItem {
const { block } = requireResolvedBlockAndMeasure(blockMap, fragment.blockId, 'image', 'image', 'image');
const item: ResolvedImageItem = {
kind: 'fragment',
fragmentKind: 'image',
id: resolveImageFragmentId(fragment),
pageIndex,
x: fragment.x,
y: fragment.y,
width: fragment.width,
height: fragment.height,
zIndex: fragment.isAnchored ? fragment.zIndex : undefined,
blockId: fragment.blockId,
fragmentIndex,
block,
};
if (fragment.pmStart != null) item.pmStart = fragment.pmStart;
if (fragment.pmEnd != null) item.pmEnd = fragment.pmEnd;
if (fragment.metadata != null) item.metadata = fragment.metadata;
return item;
}