@ai-matrx/print 0.4.0 → 0.5.0

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.js CHANGED
@@ -1,7 +1,5 @@
1
1
  // src/core.ts
2
- function escapeHtml(str) {
3
- return str.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&#39;");
4
- }
2
+ import { escapeHtml } from "@ai-matrx/kit/html-escape";
5
3
  function openPrintWindow(htmlDocument, filename = "print", windowFeatures = "width=920,height=720,scrollbars=yes") {
6
4
  const win = window.open("", "_blank", windowFeatures);
7
5
  if (!win) {
@@ -22,6 +20,9 @@ function openPrintWindow(htmlDocument, filename = "print", windowFeatures = "wid
22
20
  return "opened";
23
21
  }
24
22
 
23
+ // src/labels.ts
24
+ import { escapeHtml as escapeHtml2 } from "@ai-matrx/kit/html-escape";
25
+
25
26
  // src/qr.ts
26
27
  var QR_MIN_QUIET_ZONE_MODULES = 4;
27
28
  var DEFAULT_QR_EC_LEVEL = "M";
@@ -496,18 +497,18 @@ function buildLabelCellHtml(label, qrDataUri, t, layout, s) {
496
497
  const badgeText = label.badge?.trim() ? label.badge.trim() : "";
497
498
  if (layout.wide) {
498
499
  const lines = s.showLines && label.lines?.length ? label.lines.filter((l) => l.trim()).map(
499
- (l) => `<div class="lp-line" style="font-size:8pt;">${escapeHtml(l)}</div>`
500
+ (l) => `<div class="lp-line" style="font-size:8pt;">${escapeHtml2(l)}</div>`
500
501
  ).join("") : "";
501
- 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>` : "";
502
- 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>` : "";
503
- const image = isHttpUrl(label.imageUrl) ? `<img class="lp-img" src="${escapeHtml(label.imageUrl)}" alt="" style="height:${(t.labelHIn * 0.35).toFixed(3)}in;" />` : "";
502
+ 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;">${escapeHtml2(captionText)}</div></div>` : "";
503
+ 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;">${escapeHtml2(badgeText)}</div></div>` : "";
504
+ const image = isHttpUrl(label.imageUrl) ? `<img class="lp-img" src="${escapeHtml2(label.imageUrl)}" alt="" style="height:${(t.labelHIn * 0.35).toFixed(3)}in;" />` : "";
504
505
  return `<div class="lp-cell-wide" style="height:100%;padding:${layout.padIn}in;gap:${layout.padIn}in;">
505
506
  ${qr}
506
507
  <div class="lp-text">${badge2}${caption2}${lines}${image}</div>
507
508
  </div>`;
508
509
  }
509
- 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>` : "";
510
- 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>` : "";
510
+ 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;">${escapeHtml2(captionText)}</div></div>` : "";
511
+ 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;">${escapeHtml2(badgeText)}</div></div>` : "";
511
512
  return `<div class="lp-cell-stacked" style="height:100%;padding:${layout.padIn}in;">
512
513
  ${qr}
513
514
  ${badge}
@@ -528,12 +529,12 @@ function renderPages(t, cells) {
528
529
  return pages.join("\n");
529
530
  }
530
531
  function openSheetWindow(t, bodyHtml, title, withFitScript, warning) {
531
- 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>` : "";
532
+ 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;">${escapeHtml2(warning)}</div>` : "";
532
533
  const html = `<!DOCTYPE html>
533
534
  <html lang="en">
534
535
  <head>
535
536
  <meta charset="UTF-8">
536
- <title>${escapeHtml(title)} \u2014 ${escapeHtml(t.stockCode)}</title>
537
+ <title>${escapeHtml2(title)} \u2014 ${escapeHtml2(t.stockCode)}</title>
537
538
  <style>${sheetStyles(t)}</style>
538
539
  </head>
539
540
  <body>
@@ -541,7 +542,7 @@ ${warningHtml}
541
542
  <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;">
542
543
  <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>
543
544
  <button onclick="window.close()" style="padding:7px 14px;background:#f1f5f9;border:1px solid #cbd5e1;border-radius:6px;font-size:13px;cursor:pointer;">Close</button>
544
- <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>
545
+ <span style="color:#64748b;font-size:11px;">${escapeHtml2(t.stockCode)} \xB7 ${escapeHtml2(t.name)} \xB7 set printer to <strong>100% scale (no "fit to page"), no margins, Portrait</strong></span>
545
546
  </div>
546
547
  ${bodyHtml}
547
548
  ${withFitScript ? LP_FIT_SCRIPT : ""}
@@ -581,7 +582,7 @@ function buildCalibrationBody(t) {
581
582
  mark(gridR, gridB - 0.0104, true),
582
583
  mark(gridR - 0.0104, gridB, false)
583
584
  ].join("");
584
- 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>`;
585
+ 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 ${escapeHtml2(t.stockCode)} \xB7 hold against your label sheet: every outline must sit on a label</div>`;
585
586
  return `<div class="lp-page">${banner}${marks}${cells.join("\n")}</div>`;
586
587
  }
587
588
  function printCalibrationSheet(template) {