-
Notifications
You must be signed in to change notification settings - Fork 130
Expand file tree
/
Copy pathresolveDrawing.ts
More file actions
37 lines (34 loc) · 1.25 KB
/
resolveDrawing.ts
File metadata and controls
37 lines (34 loc) · 1.25 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
import type { DrawingFragment, ResolvedDrawingItem } from '@superdoc/contracts';
import { requireResolvedBlockAndMeasure, type BlockMapEntry } from './resolvedBlockLookup.js';
/** Mirrors fragmentKey() for drawing fragments. */
function resolveDrawingFragmentId(fragment: DrawingFragment): string {
return `drawing:${fragment.blockId}:${fragment.x}:${fragment.y}`;
}
/**
* Resolves a drawing fragment into a ResolvedDrawingItem with the pre-extracted DrawingBlock.
*/
export function resolveDrawingItem(
fragment: DrawingFragment,
fragmentIndex: number,
pageIndex: number,
blockMap: Map<string, BlockMapEntry>,
): ResolvedDrawingItem {
const { block } = requireResolvedBlockAndMeasure(blockMap, fragment.blockId, 'drawing', 'drawing', 'drawing');
const item: ResolvedDrawingItem = {
kind: 'fragment',
fragmentKind: 'drawing',
id: resolveDrawingFragmentId(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;
return item;
}