Markups carried onto a revised sheet
64-bitThe points and rectangle of each markup on the new sheet, scaled when the new page has another size.
k = min(w₂ ÷ w₁, h₂ ÷ h₁); p′ = origin₂ + (p − origin₁) × k
Pages within 1 point of each other in width and height are treated as the same and the points are copied unchanged. Otherwise one factor scales pts and rect about the view origins; the markup's holes are not mapped and stay at their old coordinates. The scaled line width is rounded to 0.01 and the font size to 0.1 with a floor of 4.
export function carryMarkups(markups, toKey, { from, to, skipClosed = false } = {}) {
const items = [], sources = [];
let left = 0, scaled = 0, closed = 0;
const same = !from || !to || sameSize(from, to);
const k = same ? 1 : Math.min(to.width / from.width, to.height / from.height);
const fx = (p) => (same ? p : [to.view[0] + (p[0] - from.view[0]) * k, to.view[1] + (p[1] - from.view[1]) * k]);
for (const m of markups) {
if (m.type === 'foreign' || m.locked) { left++; continue; }
if (skipClosed && CLOSED.has(m.status)) { closed++; continue; }
const c = clone(m);
delete c.id;
c.sheet = toKey;
c.src = null;
if (c.pts) c.pts = c.pts.map(fx);
if (c.rect) { const a = fx([c.rect[0], c.rect[1]]), b = fx([c.rect[2], c.rect[3]]); c.rect = [a[0], a[1], b[0], b[1]]; }
if (!same) {
scaled++;
c.style = { ...c.style, width: Math.round(c.style.width * k * 100) / 100, fontSize: Math.max(4, Math.round(c.style.fontSize * k * 10) / 10) };
}
c.replies = (c.replies || []).map((r) => ({ ...r, id: undefined }));
items.push(c);
sources.push(m.id);
}
return { items, sources, left, scaled, closed };
}