|
1 | | -import type { FlowMode, Fragment, Line } from './index.js'; |
| 1 | +import type { DrawingBlock, FlowMode, Fragment, ImageBlock, Line, TableBlock, TableMeasure } from './index.js'; |
2 | 2 |
|
3 | 3 | /** A fully resolved layout ready for the next-generation paint pipeline. */ |
4 | 4 | export type ResolvedLayout = { |
@@ -29,7 +29,12 @@ export type ResolvedPage = { |
29 | 29 | }; |
30 | 30 |
|
31 | 31 | /** Union of all resolved paint item kinds. */ |
32 | | -export type ResolvedPaintItem = ResolvedGroupItem | ResolvedFragmentItem; |
| 32 | +export type ResolvedPaintItem = |
| 33 | + | ResolvedGroupItem |
| 34 | + | ResolvedFragmentItem |
| 35 | + | ResolvedTableItem |
| 36 | + | ResolvedImageItem |
| 37 | + | ResolvedDrawingItem; |
33 | 38 |
|
34 | 39 | /** A group of nested resolved paint items (for future use). */ |
35 | 40 | export type ResolvedGroupItem = { |
@@ -139,6 +144,121 @@ export type ResolvedDropCapItem = { |
139 | 144 | height?: number; |
140 | 145 | }; |
141 | 146 |
|
| 147 | +// ============================================================================ |
| 148 | +// Kind-specific resolved items (PR7: table, image, drawing) |
| 149 | +// ============================================================================ |
| 150 | + |
| 151 | +/** |
| 152 | + * A resolved table fragment with pre-extracted block/measure data. |
| 153 | + * Replaces blockLookup.get() in the table render path. |
| 154 | + */ |
| 155 | +export type ResolvedTableItem = { |
| 156 | + kind: 'fragment'; |
| 157 | + /** Discriminant for table fragments. */ |
| 158 | + fragmentKind: 'table'; |
| 159 | + /** Stable identifier matching fragmentKey() semantics from the painter. */ |
| 160 | + id: string; |
| 161 | + /** 0-based page index this item belongs to. */ |
| 162 | + pageIndex: number; |
| 163 | + /** Left position in pixels. */ |
| 164 | + x: number; |
| 165 | + /** Top position in pixels. */ |
| 166 | + y: number; |
| 167 | + /** Width in pixels. */ |
| 168 | + width: number; |
| 169 | + /** Height in pixels (from fragment.height). */ |
| 170 | + height: number; |
| 171 | + /** Stacking order (tables typically don't have zIndex at fragment level). */ |
| 172 | + zIndex?: number; |
| 173 | + /** Block ID — written to data-block-id. */ |
| 174 | + blockId: string; |
| 175 | + /** Index within page.fragments — bridge to legacy rendering. */ |
| 176 | + fragmentIndex: number; |
| 177 | + /** Pre-extracted TableBlock (replaces blockLookup.get()). */ |
| 178 | + block: TableBlock; |
| 179 | + /** Pre-extracted TableMeasure (replaces blockLookup.get()). */ |
| 180 | + measure: TableMeasure; |
| 181 | + /** Pre-computed cell spacing: measure.cellSpacingPx ?? getCellSpacingPx(block.attrs?.cellSpacing). */ |
| 182 | + cellSpacingPx: number; |
| 183 | + /** Pre-computed effective column widths: fragment.columnWidths ?? measure.columnWidths. */ |
| 184 | + effectiveColumnWidths: number[]; |
| 185 | +}; |
| 186 | + |
| 187 | +/** |
| 188 | + * A resolved image fragment with pre-extracted block data. |
| 189 | + * Replaces blockLookup.get() in the image render path. |
| 190 | + */ |
| 191 | +export type ResolvedImageItem = { |
| 192 | + kind: 'fragment'; |
| 193 | + /** Discriminant for image fragments. */ |
| 194 | + fragmentKind: 'image'; |
| 195 | + /** Stable identifier matching fragmentKey() semantics from the painter. */ |
| 196 | + id: string; |
| 197 | + /** 0-based page index this item belongs to. */ |
| 198 | + pageIndex: number; |
| 199 | + /** Left position in pixels. */ |
| 200 | + x: number; |
| 201 | + /** Top position in pixels. */ |
| 202 | + y: number; |
| 203 | + /** Width in pixels. */ |
| 204 | + width: number; |
| 205 | + /** Height in pixels. */ |
| 206 | + height: number; |
| 207 | + /** Stacking order for anchored images. */ |
| 208 | + zIndex?: number; |
| 209 | + /** Block ID — written to data-block-id. */ |
| 210 | + blockId: string; |
| 211 | + /** Index within page.fragments — bridge to legacy rendering. */ |
| 212 | + fragmentIndex: number; |
| 213 | + /** Pre-extracted ImageBlock (replaces blockLookup.get()). */ |
| 214 | + block: ImageBlock; |
| 215 | +}; |
| 216 | + |
| 217 | +/** |
| 218 | + * A resolved drawing fragment with pre-extracted block data. |
| 219 | + * Replaces blockLookup.get() in the drawing render path. |
| 220 | + */ |
| 221 | +export type ResolvedDrawingItem = { |
| 222 | + kind: 'fragment'; |
| 223 | + /** Discriminant for drawing fragments. */ |
| 224 | + fragmentKind: 'drawing'; |
| 225 | + /** Stable identifier matching fragmentKey() semantics from the painter. */ |
| 226 | + id: string; |
| 227 | + /** 0-based page index this item belongs to. */ |
| 228 | + pageIndex: number; |
| 229 | + /** Left position in pixels. */ |
| 230 | + x: number; |
| 231 | + /** Top position in pixels. */ |
| 232 | + y: number; |
| 233 | + /** Width in pixels. */ |
| 234 | + width: number; |
| 235 | + /** Height in pixels. */ |
| 236 | + height: number; |
| 237 | + /** Stacking order for anchored drawings. */ |
| 238 | + zIndex?: number; |
| 239 | + /** Block ID — written to data-block-id. */ |
| 240 | + blockId: string; |
| 241 | + /** Index within page.fragments — bridge to legacy rendering. */ |
| 242 | + fragmentIndex: number; |
| 243 | + /** Pre-extracted DrawingBlock (replaces blockLookup.get()). */ |
| 244 | + block: DrawingBlock; |
| 245 | +}; |
| 246 | + |
| 247 | +/** Type guard: checks whether a resolved paint item is a ResolvedTableItem. */ |
| 248 | +export function isResolvedTableItem(item: ResolvedPaintItem): item is ResolvedTableItem { |
| 249 | + return item.kind === 'fragment' && 'fragmentKind' in item && item.fragmentKind === 'table' && 'measure' in item; |
| 250 | +} |
| 251 | + |
| 252 | +/** Type guard: checks whether a resolved paint item is a ResolvedImageItem. */ |
| 253 | +export function isResolvedImageItem(item: ResolvedPaintItem): item is ResolvedImageItem { |
| 254 | + return item.kind === 'fragment' && 'fragmentKind' in item && item.fragmentKind === 'image' && 'block' in item; |
| 255 | +} |
| 256 | + |
| 257 | +/** Type guard: checks whether a resolved paint item is a ResolvedDrawingItem. */ |
| 258 | +export function isResolvedDrawingItem(item: ResolvedPaintItem): item is ResolvedDrawingItem { |
| 259 | + return item.kind === 'fragment' && 'fragmentKind' in item && item.fragmentKind === 'drawing' && 'block' in item; |
| 260 | +} |
| 261 | + |
142 | 262 | /** Resolved list marker rendering data with pre-computed positioning. */ |
143 | 263 | export type ResolvedListMarkerItem = { |
144 | 264 | /** Marker text content (e.g., "1.", "a)", bullet). */ |
|
0 commit comments