Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion lib/generation/scene-generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -536,6 +536,11 @@ function fixElementDefaults(
elements: GeneratedSlideData['elements'],
assignedImages?: PdfImage[],
): GeneratedSlideData['elements'] {
// Index assigned images by id once (O(m)) so the per-image-element lookup
// below is O(1) instead of a `.find` nested inside this map (which made the
// pass O(elements × images)).
const imageMetaById = new Map((assignedImages ?? []).map((img) => [img.id, img]));

return elements.map((el) => {
// Fix line elements
if (el.type === 'line') {
Expand Down Expand Up @@ -595,7 +600,7 @@ function fixElementDefaults(

// Correct dimensions using known aspect ratio (src is still img_id at this point)
if (assignedImages && typeof imageEl.src === 'string') {
const imgMeta = assignedImages.find((img) => img.id === imageEl.src);
const imgMeta = imageMetaById.get(imageEl.src);
if (imgMeta?.width && imgMeta?.height) {
const knownRatio = imgMeta.width / imgMeta.height;
const curW = (el.width || 400) as number;
Expand Down
Loading