Label position on the sheet
64-bitWhere each label is printed on the page, so that it lands on the die-cut label.
x = left + col × (label width + gap x); y = top + row × (label height + gap y)
The position is computed in 64-bit numbers and written rounded to 0.001 mm. The 10-label letter template's left margin of 3.96875 mm is therefore written as 3.969 mm.
export function labelSheets(items, template, { startAt = 0, module = 0.33 } = {}) {
const T = typeof template === 'string' ? TEMPLATES[template] : template;
if (!T) throw new Error('labels: no template ' + template); // i18n-ignore (for developers)
const per = T.cols * T.rows, pages = [], warnings = [];
let slots = [];
const flush = () => {
if (!slots.length) return;
pages.push(`<svg xmlns="http://www.w3.org/2000/svg" width="${T.page.w}mm" height="${T.page.h}mm" viewBox="0 0 ${T.page.w} ${T.page.h}" font-family="Arial, Helvetica, sans-serif" data-page="${pages.length + 1}"><rect width="${T.page.w}" height="${T.page.h}" fill="#fff"/>${slots.join('')}</svg>`);
slots = [];
};
let pos = Math.max(0, Math.min(per - 1, Math.floor(startAt) || 0));
for (const it of items) {
const c = pos % T.cols, r = Math.floor(pos / T.cols);
const x = T.left + c * (T.label.w + T.gapX), y = T.top + r * (T.label.h + T.gapY);
const { svg, warn } = labelSvg(it, x, y, T.label, { module });
slots.push(svg);
if (warn) warnings.push({ code: warn, id: it.id });
pos++;
if (pos >= per) { flush(); pos = 0; }
}
flush();
return { pages, perPage: per, count: items.length, warnings };
}