@ai-matrx/print 0.4.0 → 0.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/zpl.cjs CHANGED
@@ -43,9 +43,7 @@ __export(zpl_exports, {
43
43
  module.exports = __toCommonJS(zpl_exports);
44
44
 
45
45
  // src/core.ts
46
- function escapeHtml(str) {
47
- return str.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&#39;");
48
- }
46
+ var import_html_escape = require("@ai-matrx/kit/html-escape");
49
47
  function openPrintWindow(htmlDocument, filename = "print", windowFeatures = "width=920,height=720,scrollbars=yes") {
50
48
  const win = window.open("", "_blank", windowFeatures);
51
49
  if (!win) {
@@ -66,6 +64,9 @@ function openPrintWindow(htmlDocument, filename = "print", windowFeatures = "wid
66
64
  return "opened";
67
65
  }
68
66
 
67
+ // src/labels.ts
68
+ var import_html_escape2 = require("@ai-matrx/kit/html-escape");
69
+
69
70
  // src/qr.ts
70
71
  var QR_MIN_QUIET_ZONE_MODULES = 4;
71
72
  var DEFAULT_QR_EC_LEVEL = "M";
@@ -540,18 +541,18 @@ function buildLabelCellHtml(label, qrDataUri, t, layout, s) {
540
541
  const badgeText = label.badge?.trim() ? label.badge.trim() : "";
541
542
  if (layout.wide) {
542
543
  const lines = s.showLines && label.lines?.length ? label.lines.filter((l) => l.trim()).map(
543
- (l) => `<div class="lp-line" style="font-size:8pt;">${escapeHtml(l)}</div>`
544
+ (l) => `<div class="lp-line" style="font-size:8pt;">${(0, import_html_escape2.escapeHtml)(l)}</div>`
544
545
  ).join("") : "";
545
- const caption2 = captionText ? `<div class="lp-fit-wrap" style="max-height:${(t.labelHIn * 0.3).toFixed(3)}in;"><div class="lp-fit lp-caption" style="font-size:12pt;">${escapeHtml(captionText)}</div></div>` : "";
546
- const badge2 = badgeText ? `<div class="lp-fit-wrap" style="max-height:${layout.badgeZoneIn.toFixed(3)}in;"><div class="lp-fit lp-badge" style="font-size:24pt;">${escapeHtml(badgeText)}</div></div>` : "";
547
- const image = isHttpUrl(label.imageUrl) ? `<img class="lp-img" src="${escapeHtml(label.imageUrl)}" alt="" style="height:${(t.labelHIn * 0.35).toFixed(3)}in;" />` : "";
546
+ const caption2 = captionText ? `<div class="lp-fit-wrap" style="max-height:${(t.labelHIn * 0.3).toFixed(3)}in;"><div class="lp-fit lp-caption" style="font-size:12pt;">${(0, import_html_escape2.escapeHtml)(captionText)}</div></div>` : "";
547
+ const badge2 = badgeText ? `<div class="lp-fit-wrap" style="max-height:${layout.badgeZoneIn.toFixed(3)}in;"><div class="lp-fit lp-badge" style="font-size:24pt;">${(0, import_html_escape2.escapeHtml)(badgeText)}</div></div>` : "";
548
+ const image = isHttpUrl(label.imageUrl) ? `<img class="lp-img" src="${(0, import_html_escape2.escapeHtml)(label.imageUrl)}" alt="" style="height:${(t.labelHIn * 0.35).toFixed(3)}in;" />` : "";
548
549
  return `<div class="lp-cell-wide" style="height:100%;padding:${layout.padIn}in;gap:${layout.padIn}in;">
549
550
  ${qr}
550
551
  <div class="lp-text">${badge2}${caption2}${lines}${image}</div>
551
552
  </div>`;
552
553
  }
553
- const caption = captionText ? `<div class="lp-fit-wrap lp-caption-stacked" style="height:${Math.min(0.28, t.labelHIn * 0.16).toFixed(3)}in;"><div class="lp-fit lp-caption" style="font-size:9pt;">${escapeHtml(captionText)}</div></div>` : "";
554
- const badge = badgeText ? `<div class="lp-fit-wrap lp-badge-stacked" style="height:${layout.badgeZoneIn.toFixed(3)}in;"><div class="lp-fit lp-badge" style="font-size:18pt;">${escapeHtml(badgeText)}</div></div>` : "";
554
+ const caption = captionText ? `<div class="lp-fit-wrap lp-caption-stacked" style="height:${Math.min(0.28, t.labelHIn * 0.16).toFixed(3)}in;"><div class="lp-fit lp-caption" style="font-size:9pt;">${(0, import_html_escape2.escapeHtml)(captionText)}</div></div>` : "";
555
+ const badge = badgeText ? `<div class="lp-fit-wrap lp-badge-stacked" style="height:${layout.badgeZoneIn.toFixed(3)}in;"><div class="lp-fit lp-badge" style="font-size:18pt;">${(0, import_html_escape2.escapeHtml)(badgeText)}</div></div>` : "";
555
556
  return `<div class="lp-cell-stacked" style="height:100%;padding:${layout.padIn}in;">
556
557
  ${qr}
557
558
  ${badge}
@@ -572,12 +573,12 @@ function renderPages(t, cells) {
572
573
  return pages.join("\n");
573
574
  }
574
575
  function openSheetWindow(t, bodyHtml, title, withFitScript, warning) {
575
- const warningHtml = warning ? `<div class="screen-only lp-warning" style="font-family:sans-serif;font-size:12px;font-weight:600;padding:9px 16px;background:#fef2f2;color:#991b1b;border-bottom:1px solid #fecaca;">${escapeHtml(warning)}</div>` : "";
576
+ const warningHtml = warning ? `<div class="screen-only lp-warning" style="font-family:sans-serif;font-size:12px;font-weight:600;padding:9px 16px;background:#fef2f2;color:#991b1b;border-bottom:1px solid #fecaca;">${(0, import_html_escape2.escapeHtml)(warning)}</div>` : "";
576
577
  const html = `<!DOCTYPE html>
577
578
  <html lang="en">
578
579
  <head>
579
580
  <meta charset="UTF-8">
580
- <title>${escapeHtml(title)} \u2014 ${escapeHtml(t.stockCode)}</title>
581
+ <title>${(0, import_html_escape2.escapeHtml)(title)} \u2014 ${(0, import_html_escape2.escapeHtml)(t.stockCode)}</title>
581
582
  <style>${sheetStyles(t)}</style>
582
583
  </head>
583
584
  <body>
@@ -585,7 +586,7 @@ ${warningHtml}
585
586
  <div class="screen-only" style="font-family:sans-serif;font-size:12px;padding:10px 16px;background:#f8fafc;border-bottom:1px solid #e2e8f0;display:flex;gap:10px;align-items:center;flex-wrap:wrap;">
586
587
  <button onclick="window.print()" style="padding:7px 18px;background:#111;color:#fff;border:none;border-radius:6px;font-size:13px;font-weight:600;cursor:pointer;">Print / Save PDF</button>
587
588
  <button onclick="window.close()" style="padding:7px 14px;background:#f1f5f9;border:1px solid #cbd5e1;border-radius:6px;font-size:13px;cursor:pointer;">Close</button>
588
- <span style="color:#64748b;font-size:11px;">${escapeHtml(t.stockCode)} \xB7 ${escapeHtml(t.name)} \xB7 set printer to <strong>100% scale (no "fit to page"), no margins, Portrait</strong></span>
589
+ <span style="color:#64748b;font-size:11px;">${(0, import_html_escape2.escapeHtml)(t.stockCode)} \xB7 ${(0, import_html_escape2.escapeHtml)(t.name)} \xB7 set printer to <strong>100% scale (no "fit to page"), no margins, Portrait</strong></span>
589
590
  </div>
590
591
  ${bodyHtml}
591
592
  ${withFitScript ? LP_FIT_SCRIPT : ""}
@@ -625,7 +626,7 @@ function buildCalibrationBody(t) {
625
626
  mark(gridR, gridB - 0.0104, true),
626
627
  mark(gridR - 0.0104, gridB, false)
627
628
  ].join("");
628
- const banner = `<div style="position:absolute;left:0;right:0;top:${Math.max(0, t.marginTopIn - 0.3).toFixed(2)}in;text-align:center;font-size:7pt;color:#94a3b8;">Calibration \u2014 ${escapeHtml(t.stockCode)} \xB7 hold against your label sheet: every outline must sit on a label</div>`;
629
+ const banner = `<div style="position:absolute;left:0;right:0;top:${Math.max(0, t.marginTopIn - 0.3).toFixed(2)}in;text-align:center;font-size:7pt;color:#94a3b8;">Calibration \u2014 ${(0, import_html_escape2.escapeHtml)(t.stockCode)} \xB7 hold against your label sheet: every outline must sit on a label</div>`;
629
630
  return `<div class="lp-page">${banner}${marks}${cells.join("\n")}</div>`;
630
631
  }
631
632
  function printCalibrationSheet(template) {