@levischuck/receiptline 0.1.3 → 0.1.4

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/index.js CHANGED
@@ -1,6 +1,6 @@
1
- import { decodeBase64 as Z, encodeBase64 as O } from "@levischuck/tiny-encodings";
2
- import { qrCode as _, EcLevel as M } from "@levischuck/tiny-qr";
3
- import { toSvgString as nt } from "@levischuck/tiny-qr-svg";
1
+ import { decodeBase64 as O, encodeBase64 as _ } from "@levischuck/tiny-encodings";
2
+ import { qrCode as G, EcLevel as C } from "@levischuck/tiny-qr";
3
+ import { toSvgString as it } from "@levischuck/tiny-qr-svg";
4
4
  class H {
5
5
  locked = !1;
6
6
  lockPromise = null;
@@ -163,6 +163,17 @@ class H {
163
163
  async relative(t) {
164
164
  return "";
165
165
  }
166
+ /**
167
+ * Set column context for text alignment.
168
+ * @param {number} index column index (0-based)
169
+ * @param {number} start column start position (unit: characters)
170
+ * @param {number} width column width (unit: characters)
171
+ * @param {number} align text alignment within column (0: left, 1: center, 2: right)
172
+ * @returns {Promise<string>} commands
173
+ */
174
+ async column(t, e, n, a) {
175
+ return "";
176
+ }
166
177
  /**
167
178
  * Print horizontal rule.
168
179
  * @param {number} width line width (unit: characters)
@@ -329,20 +340,20 @@ const y = {
329
340
  shift: 98,
330
341
  stop: 106
331
342
  };
332
- function j(i, t, e) {
343
+ function I(i, t, e) {
333
344
  i !== y.shift && e.push(i), t = t.replace(/^((?!\d{4,})[\x00-_])+/, (r) => (r.split("").forEach((s) => e.push((s.charCodeAt(0) + 64) % 96)), "")), t = t.replace(/^\d(?=(\d\d){2,}(\D|$))/, (r) => (e.push((r.charCodeAt(0) + 64) % 96), ""));
334
345
  const n = t.slice(1), a = n.search(/[^ -_]/);
335
- /^\d{4,}/.test(t) ? L(y.atoc, t, e) : a >= 0 && n.charCodeAt(a) < 32 ? (e.push(y.shift, t.charCodeAt(0) - 32), j(y.shift, n, e)) : t.length > 0 && E(y.atob, t, e);
346
+ /^\d{4,}/.test(t) ? B(y.atoc, t, e) : a >= 0 && n.charCodeAt(a) < 32 ? (e.push(y.shift, t.charCodeAt(0) - 32), I(y.shift, n, e)) : t.length > 0 && j(y.atob, t, e);
336
347
  }
337
- function E(i, t, e) {
348
+ function j(i, t, e) {
338
349
  i !== y.shift && e.push(i), t = t.replace(/^((?!\d{4,})[ -\x7f])+/, (r) => (r.split("").forEach((s) => e.push(s.charCodeAt(0) - 32)), "")), t = t.replace(/^\d(?=(\d\d){2,}(\D|$))/, (r) => (e.push(r.charCodeAt(0) - 32), ""));
339
350
  const n = t.slice(1), a = n.search(/[^ -_]/);
340
- /^\d{4,}/.test(t) ? L(y.btoc, t, e) : a >= 0 && n.charCodeAt(a) > 95 ? (e.push(y.shift, t.charCodeAt(0) + 64), E(y.shift, n, e)) : t.length > 0 && j(y.btoa, t, e);
351
+ /^\d{4,}/.test(t) ? B(y.btoc, t, e) : a >= 0 && n.charCodeAt(a) > 95 ? (e.push(y.shift, t.charCodeAt(0) + 64), j(y.shift, n, e)) : t.length > 0 && I(y.btoa, t, e);
341
352
  }
342
- function L(i, t, e) {
353
+ function B(i, t, e) {
343
354
  i !== y.shift && e.push(i), t = t.replace(/^\d{4,}/g, (a) => a.replace(/\d{2}/g, (r) => (e.push(Number(r)), "")));
344
355
  const n = t.search(/[^ -_]/);
345
- n >= 0 && t.charCodeAt(n) < 32 ? j(y.ctoa, t, e) : t.length > 0 && E(y.ctob, t, e);
356
+ n >= 0 && t.charCodeAt(n) < 32 ? I(y.ctoa, t, e) : t.length > 0 && j(y.ctob, t, e);
346
357
  }
347
358
  function st(i) {
348
359
  const t = {};
@@ -350,13 +361,13 @@ function st(i) {
350
361
  if (e.length > 0) {
351
362
  t.hri = i.hri, t.text = e.replace(/[\x00- \x7f]/g, " ");
352
363
  const n = [], a = e.search(/[^ -_]/);
353
- /^\d{2}$/.test(e) ? n.push(y.startc, Number(e)) : /^\d{4,}/.test(e) ? L(y.startc, e, n) : a >= 0 && e.charCodeAt(a) < 32 ? j(y.starta, e, n) : e.length > 0 && E(y.startb, e, n), n.push(n.reduce((h, o, c) => h + o * c) % 103, y.stop);
364
+ /^\d{2}$/.test(e) ? n.push(y.startc, Number(e)) : /^\d{4,}/.test(e) ? B(y.startc, e, n) : a >= 0 && e.charCodeAt(a) < 32 ? I(y.starta, e, n) : e.length > 0 && j(y.startb, e, n), n.push(n.reduce((h, o, c) => h + o * c) % 103, y.stop);
354
365
  const r = i.quietZone ? "a" : "0", s = n.reduce((h, o) => h + y.element[o], r) + r;
355
366
  t.widths = s.split("").map((h) => parseInt(h, 16) * i.width), t.length = i.width * (n.length * 11 + (i.quietZone ? 22 : 2)), t.height = i.height;
356
367
  }
357
368
  return t;
358
369
  }
359
- const C = {
370
+ const M = {
360
371
  escape: "cU,dA,dB,dC,dD,dE,dF,dG,dH,dI,dJ,dK,dL,dM,dN,dO,dP,dQ,dR,dS,dT,dU,dV,dW,dX,dY,dZ,cA,cB,cC,cD,cE, ,sA,sB,sC,$,%,sF,sG,sH,sI,sJ,+,sL,-,.,/,0,1,2,3,4,5,6,7,8,9,sZ,cF,cG,cH,cI,cJ,cV,A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z,cK,cL,cM,cN,cO,cW,pA,pB,pC,pD,pE,pF,pG,pH,pI,pJ,pK,pL,pM,pN,pO,pP,pQ,pR,pS,pT,pU,pV,pW,pX,pY,pZ,cP,cQ,cR,cS,cT".split(","),
361
372
  code: "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ-. $/+%dcsp".split("").reduce((i, t, e) => (i[t] = e, i), {}),
362
373
  element: "131112,111213,111312,111411,121113,121212,121311,111114,131211,141111,211113,211212,211311,221112,221211,231111,112113,112212,112311,122112,132111,111123,111222,111321,121122,131121,212112,212211,211122,211221,221121,222111,112122,112221,122121,123111,121131,311112,311211,321111,112131,113121,211131,121221,312111,311121,122211,111141,1111411".split(","),
@@ -368,9 +379,9 @@ function rt(i) {
368
379
  let e = i.data.replace(/((?!^[\x00-\x7f]+$).)*/, "");
369
380
  if (e.length > 0) {
370
381
  t.hri = i.hri, t.text = e.replace(/[\x00- \x7f]/g, " ");
371
- const n = e.split("").reduce((s, h) => s + C.escape[h.charCodeAt(0)], "").split("").map((s) => C.code[s]);
372
- n.push(n.reduceRight((s, h, o) => s + h * ((n.length - 1 - o) % 20 + 1)) % 47), n.push(n.reduceRight((s, h, o) => s + h * ((n.length - 1 - o) % 15 + 1)) % 47), n.unshift(C.start), n.push(C.stop);
373
- const a = i.quietZone ? "a" : "0", r = n.reduce((s, h) => s + C.element[h], a) + a;
382
+ const n = e.split("").reduce((s, h) => s + M.escape[h.charCodeAt(0)], "").split("").map((s) => M.code[s]);
383
+ n.push(n.reduceRight((s, h, o) => s + h * ((n.length - 1 - o) % 20 + 1)) % 47), n.push(n.reduceRight((s, h, o) => s + h * ((n.length - 1 - o) % 15 + 1)) % 47), n.unshift(M.start), n.push(M.stop);
384
+ const a = i.quietZone ? "a" : "0", r = n.reduce((s, h) => s + M.element[h], a) + a;
374
385
  t.widths = r.split("").map((s) => parseInt(s, 16) * i.width), t.length = i.width * (n.length * 9 + (i.quietZone ? 21 : 1)), t.height = i.height;
375
386
  }
376
387
  return t;
@@ -423,7 +434,7 @@ function ht(i) {
423
434
  let r = a + q.start, s = 0;
424
435
  for (; s < n.length; ) {
425
436
  const o = q.element[n[s++]], c = q.element[n[s++]];
426
- r += o.split("").reduce((d, u, l) => d + u + c[l], "");
437
+ r += o.split("").reduce((l, f, d) => l + f + c[d], "");
427
438
  }
428
439
  r += q.stop + a, t.widths = r.split("").map((o) => parseInt(o, 16) * i.width + 1 >> 1);
429
440
  const h = [16, 25, 32, 17, 26, 34];
@@ -489,7 +500,7 @@ function lt(i) {
489
500
  }
490
501
  return t;
491
502
  }
492
- const b = {
503
+ const x = {
493
504
  a: "3211,2221,2122,1411,1132,1231,1114,1312,1213,3112".split(","),
494
505
  b: "1123,1222,2212,1141,2311,1321,4111,2131,3121,2113".split(","),
495
506
  c: "3211,2221,2122,1411,1132,1231,1114,1312,1213,3112".split(","),
@@ -517,15 +528,15 @@ function dt(i) {
517
528
  }
518
529
  return t.push(i[7]), t;
519
530
  }
520
- function G(i) {
531
+ function K(i) {
521
532
  const t = {}, e = i.data.replace(/((?!^\d{12,13}$).)*/, "").split("").map((n) => Number(n));
522
533
  if (e.length > 0) {
523
534
  e[12] = 0, e[12] = (10 - e.reduce((a, r, s) => a + r * (s % 2 * 2 + 1)) % 10) % 10, t.hri = i.hri, t.text = e.join("");
524
- let n = (i.quietZone ? "b" : "0") + b.g[0];
525
- for (let a = 1; a < 7; a++) n += b[b.p[e[0]][a - 1]][e[a]];
526
- n += b.g[1];
527
- for (let a = 7; a < 13; a++) n += b.c[e[a]];
528
- n += b.g[0] + (i.quietZone ? "7" : "0"), t.widths = n.split("").map((a) => parseInt(a, 16) * i.width), t.length = i.width * (i.quietZone ? 113 : 95), t.height = i.height;
535
+ let n = (i.quietZone ? "b" : "0") + x.g[0];
536
+ for (let a = 1; a < 7; a++) n += x[x.p[e[0]][a - 1]][e[a]];
537
+ n += x.g[1];
538
+ for (let a = 7; a < 13; a++) n += x.c[e[a]];
539
+ n += x.g[0] + (i.quietZone ? "7" : "0"), t.widths = n.split("").map((a) => parseInt(a, 16) * i.width), t.length = i.width * (i.quietZone ? 113 : 95), t.height = i.height;
529
540
  }
530
541
  return t;
531
542
  }
@@ -534,11 +545,11 @@ function gt(i) {
534
545
  if (e.length > 0) {
535
546
  e[7] = 0, e[7] = (10 - e.reduce((r, s, h) => r + s * (3 - h % 2 * 2), 0) % 10) % 10, t.hri = i.hri, t.text = e.join("");
536
547
  const n = i.quietZone ? "7" : "0";
537
- let a = n + b.g[0];
538
- for (let r = 0; r < 4; r++) a += b.a[e[r] ?? 0];
539
- a += b.g[1];
540
- for (let r = 4; r < 8; r++) a += b.c[e[r] ?? 0];
541
- a += b.g[0] + n, t.widths = a.split("").map((r) => parseInt(r, 16) * i.width), t.length = i.width * (i.quietZone ? 81 : 67), t.height = i.height;
548
+ let a = n + x.g[0];
549
+ for (let r = 0; r < 4; r++) a += x.a[e[r] ?? 0];
550
+ a += x.g[1];
551
+ for (let r = 4; r < 8; r++) a += x.c[e[r] ?? 0];
552
+ a += x.g[0] + n, t.widths = a.split("").map((r) => parseInt(r, 16) * i.width), t.length = i.width * (i.quietZone ? 81 : 67), t.height = i.height;
542
553
  }
543
554
  return t;
544
555
  }
@@ -549,7 +560,7 @@ function ut(i) {
549
560
  width: i.width,
550
561
  height: i.height,
551
562
  quietZone: i.quietZone
552
- }, e = G(t);
563
+ }, e = K(t);
553
564
  return e.text && (e.text = e.text.slice(1)), e;
554
565
  }
555
566
  function pt(i) {
@@ -557,13 +568,13 @@ function pt(i) {
557
568
  if (e.length > 0) {
558
569
  e[7] = 0, e[7] = (10 - dt(e).reduce((r, s, h) => r + s * (3 - h % 2 * 2), 0) % 10) % 10, t.hri = i.hri, t.text = e.join("");
559
570
  const n = i.quietZone ? "7" : "0";
560
- let a = n + b.g[0];
561
- for (let r = 1; r < 7; r++) a += b[b.e[e[7] ?? 0][r - 1]][e[r] ?? 0];
562
- a += b.g[2] + n, t.widths = a.split("").map((r) => parseInt(r, 16) * i.width), t.length = i.width * (i.quietZone ? 65 : 51), t.height = i.height;
571
+ let a = n + x.g[0];
572
+ for (let r = 1; r < 7; r++) a += x[x.e[e[7] ?? 0][r - 1]][e[r] ?? 0];
573
+ a += x.g[2] + n, t.widths = a.split("").map((r) => parseInt(r, 16) * i.width), t.length = i.width * (i.quietZone ? 65 : 51), t.height = i.height;
563
574
  }
564
575
  return t;
565
576
  }
566
- function K(i) {
577
+ function J(i) {
567
578
  let t = {};
568
579
  switch (i.type) {
569
580
  case "upc":
@@ -571,7 +582,7 @@ function K(i) {
571
582
  break;
572
583
  case "ean":
573
584
  case "jan":
574
- t = i.data.length < 9 ? gt(i) : G(i);
585
+ t = i.data.length < 9 ? gt(i) : K(i);
575
586
  break;
576
587
  case "code39":
577
588
  t = lt(i);
@@ -592,7 +603,7 @@ function K(i) {
592
603
  }
593
604
  return t;
594
605
  }
595
- class F extends H {
606
+ class z extends H {
596
607
  charWidth = 12;
597
608
  receiptId = "";
598
609
  svgWidth = 576;
@@ -689,9 +700,9 @@ class F extends H {
689
700
  }
690
701
  // print vertical and horizontal rules:
691
702
  async vrhr(t, e, n, a) {
692
- const r = this.charWidth, s = r / 2, h = '<path d="' + t.reduce((c, d) => c + `h${r * d}h${s}v${-r}m0,${r}h${s}`, `M${s},0` + (n > 0 ? `v${s}q0,${s},${s},${s}` : `v${r}h${s}`)).replace(/h\d+v-\d+m0,\d+h\d+$/, a < 0 ? `q${s},0,${s},${-s}v${-s}` : `h${s}v${-r}`) + '" fill="none" stroke="#000" stroke-width="2"/>';
703
+ const r = this.charWidth, s = r / 2, h = '<path d="' + t.reduce((c, l) => c + `h${r * l}h${s}v${-r}m0,${r}h${s}`, `M${s},0` + (n > 0 ? `v${s}q0,${s},${s},${s}` : `v${r}h${s}`)).replace(/h\d+v-\d+m0,\d+h\d+$/, a < 0 ? `q${s},0,${s},${-s}v${-s}` : `h${s}v${-r}`) + '" fill="none" stroke="#000" stroke-width="2"/>';
693
704
  this.svgContent += `<g transform="translate(${(this.lineMargin + Math.max(-n, 0)) * r},${this.svgHeight})">${h}</g>`;
694
- const o = '<path d="' + e.reduce((c, d) => c + `h${r * d}h${s}v${r}m0,${-r}h${s}`, `M${s},${r + r}` + (n < 0 ? `v${-s}q0,${-s},${s},${-s}` : `v${-r}h${s}`)).replace(/h\d+v\d+m0,-\d+h\d+$/, a > 0 ? `q${s},0,${s},${s}v${s}` : `h${s}v${r}`) + '" fill="none" stroke="#000" stroke-width="2"/>';
705
+ const o = '<path d="' + e.reduce((c, l) => c + `h${r * l}h${s}v${r}m0,${-r}h${s}`, `M${s},${r + r}` + (n < 0 ? `v${-s}q0,${-s},${s},${-s}` : `v${-r}h${s}`)).replace(/h\d+v\d+m0,-\d+h\d+$/, a > 0 ? `q${s},0,${s},${s}v${s}` : `h${s}v${r}`) + '" fill="none" stroke="#000" stroke-width="2"/>';
695
706
  return this.svgContent += `<g transform="translate(${(this.lineMargin + Math.max(n, 0)) * r},${this.svgHeight})">${o}</g>`, "";
696
707
  }
697
708
  // set line spacing and feed new line:
@@ -729,7 +740,7 @@ class F extends H {
729
740
  let n = this.textPosition;
730
741
  const a = this.arrayFrom(t, e).reduce((s, h) => {
731
742
  const o = this.measureText(h, e) * this.textScale, c = Math.floor((n + o / 2) * this.charWidth / this.textScale);
732
- return n += o, s + `<tspan x="${c}">${h.replace(/[ &<>]/g, (d) => ({ " ": "&#xa0;", "&": "&amp;", "<": "&lt;", ">": "&gt;" })[d] || d)}</tspan>`;
743
+ return n += o, s + `<tspan x="${c}">${h.replace(/[ &<>]/g, (l) => ({ " ": "&#xa0;", "&": "&amp;", "<": "&lt;", ">": "&gt;" })[l] || l)}</tspan>`;
733
744
  }, ""), r = Object.keys(this.textAttributes).reduce((s, h) => s + ` ${h}="${this.textAttributes[h]}"`, "");
734
745
  return this.textElement += `<text${r}>${a}</text>`, this.textPosition += this.measureText(t, e) * this.textScale, "";
735
746
  }
@@ -744,32 +755,32 @@ class F extends H {
744
755
  }
745
756
  // print image:
746
757
  async image(t) {
747
- const e = Z(t), n = new DataView(e.buffer), a = n.getUint32(16, !1), r = n.getUint32(20, !1), s = `<image href="data:image/png;base64,${O(e)}" x="0" y="0" width="${a}" height="${r}"/>`, h = Math.floor(this.lineMargin * this.charWidth + (this.lineWidth * this.charWidth - a) * this.lineAlign / 2);
758
+ const e = O(t), n = new DataView(e.buffer), a = n.getUint32(16, !1), r = n.getUint32(20, !1), s = `<image href="data:image/png;base64,${_(e)}" x="0" y="0" width="${a}" height="${r}"/>`, h = Math.floor(this.lineMargin * this.charWidth + (this.lineWidth * this.charWidth - a) * this.lineAlign / 2);
748
759
  return this.svgContent += `<g transform="translate(${h},${this.svgHeight})">${s}</g>`, this.svgHeight += r, "";
749
760
  }
750
761
  // print QR Code:
751
762
  async qrcode(t, e) {
752
- const n = _({
763
+ const n = G({
753
764
  data: t.data,
754
- ec: t.level == "l" ? M.L : t.level == "m" ? M.M : t.level == "q" ? M.Q : M.H
755
- }), a = n.width, r = t.cell, s = await nt(n, {
765
+ ec: t.level == "l" ? C.L : t.level == "m" ? C.M : t.level == "q" ? C.Q : C.H
766
+ }), a = n.width, r = t.cell, s = await it(n, {
756
767
  moduleSize: r,
757
768
  margin: t.quietZone ? 4 : 0,
758
769
  output: "path"
759
- }), h = typeof s == "string" ? s : s.path || s.svg || String(s), o = a * r + (t.quietZone ? 8 : 0), c = Math.floor(this.lineMargin * this.charWidth + (this.lineWidth * this.charWidth - o) * this.lineAlign / 2), d = Math.floor(this.svgHeight);
760
- return this.svgContent += `<g transform="translate(${c},${d})" shape-rendering="crispEdges">
770
+ }), h = typeof s == "string" ? s : s.path || s.svg || String(s), o = a * r + (t.quietZone ? 8 : 0), c = Math.floor(this.lineMargin * this.charWidth + (this.lineWidth * this.charWidth - o) * this.lineAlign / 2), l = Math.floor(this.svgHeight);
771
+ return this.svgContent += `<g transform="translate(${c},${l})" shape-rendering="crispEdges">
761
772
  <path d="${h}" stroke="transparent" fill="black" shape-rendering="crispEdges" />
762
773
  </g>`, this.svgHeight += o, "";
763
774
  }
764
775
  // print barcode:
765
776
  async barcode(t, e) {
766
- const n = K(t), a = n.height;
777
+ const n = J(t), a = n.height;
767
778
  if (a !== void 0 && "length" in n && n.length !== void 0 && n.widths) {
768
779
  const r = n.length, s = a + (n.hri ? this.charWidth * 2 + 2 : 0);
769
780
  let h = '<path d="';
770
- if (n.widths.reduce((c, d, u) => (u % 2 === 1 && (h += `M${c},0h${d}v${a}h${-d}z`), c + d), 0), h += '" fill="#000"/>', n.hri && n.text) {
771
- const c = Math.floor((r - (this.measureText(n.text, e) - 1) * this.charWidth) / 2), d = this.arrayFrom(n.text, e).reduce((u, l, g) => u + `<tspan x="${c + this.charWidth * g}">${l.replace(/[ &<>]/g, (p) => ({ " ": "&#xa0;", "&": "&amp;", "<": "&lt;", ">": "&gt;" })[p] || p)}</tspan>`, "");
772
- h += `<text y="${s}">${d}</text>`;
781
+ if (n.widths.reduce((c, l, f) => (f % 2 === 1 && (h += `M${c},0h${l}v${a}h${-l}z`), c + l), 0), h += '" fill="#000"/>', n.hri && n.text) {
782
+ const c = Math.floor((r - (this.measureText(n.text, e) - 1) * this.charWidth) / 2), l = this.arrayFrom(n.text, e).reduce((f, d, g) => f + `<tspan x="${c + this.charWidth * g}">${d.replace(/[ &<>]/g, (u) => ({ " ": "&#xa0;", "&": "&amp;", "<": "&lt;", ">": "&gt;" })[u] || u)}</tspan>`, "");
783
+ h += `<text y="${s}">${l}</text>`;
773
784
  }
774
785
  const o = Math.floor(this.lineMargin * this.charWidth + (this.lineWidth * this.charWidth - r) * this.lineAlign / 2);
775
786
  this.svgContent += `<g transform="translate(${o},${this.svgHeight})">${h}</g>`, this.svgHeight += s;
@@ -966,10 +977,10 @@ const ft = /* @__PURE__ */ new Set([
966
977
  rArr: "⇒",
967
978
  dArr: "⇓",
968
979
  hArr: "⇔"
969
- }, T = {};
980
+ }, V = {};
970
981
  for (const [i, t] of Object.entries($t))
971
- T[t] || (T[t] = i);
972
- function I(i, t = !1) {
982
+ V[t] || (V[t] = i);
983
+ function F(i, t = !1) {
973
984
  if (!i || typeof i != "string")
974
985
  return i;
975
986
  let e = i;
@@ -988,12 +999,12 @@ const vt = {
988
999
  function bt(i, t) {
989
1000
  return t === "reactName" ? i : t === "exactName" || t === "eitherName" ? vt[i] ?? i : i;
990
1001
  }
991
- function V(i, t = {}) {
1002
+ function R(i, t = {}) {
992
1003
  const e = [];
993
1004
  let n, a, r;
994
1005
  if (i && typeof i == "object" && "node" in i) {
995
- const d = i;
996
- n = d.node, a = d.xml ?? t.xml, r = d.doctype ?? t.doctype;
1006
+ const l = i;
1007
+ n = l.node, a = l.xml ?? t.xml, r = l.doctype ?? t.doctype;
997
1008
  } else
998
1009
  n = i, a = t.xml, r = t.doctype;
999
1010
  a && (e.push(a), a.endsWith(`
@@ -1007,7 +1018,7 @@ function V(i, t = {}) {
1007
1018
  function P(i, t, e, n, a, r, s) {
1008
1019
  if (i != null) {
1009
1020
  if (typeof i == "string") {
1010
- t.push(I(i, !1));
1021
+ t.push(F(i, !1));
1011
1022
  return;
1012
1023
  }
1013
1024
  if (typeof i == "number" || typeof i == "bigint") {
@@ -1034,29 +1045,29 @@ function xt(i, t, e, n, a, r, s) {
1034
1045
  const o = i.type;
1035
1046
  let c = e;
1036
1047
  if (o === "svg" ? c = "SVG" : o === "math" && (c = "MATHML"), t.push("<"), t.push(o), i.props)
1037
- for (const [l, g] of Object.entries(i.props)) {
1038
- if (l === "children" || g === !1 || g === null || g === void 0)
1048
+ for (const [d, g] of Object.entries(i.props)) {
1049
+ if (d === "children" || g === !1 || g === null || g === void 0)
1039
1050
  continue;
1040
- const p = bt(l, s);
1051
+ const u = bt(d, s);
1041
1052
  if (g === !0)
1042
- t.push(" "), t.push(p);
1043
- else if (l === "style" && typeof g == "object") {
1044
- const f = Wt(g);
1045
- f && (t.push(' style="'), t.push(I(f, !0)), t.push('"'));
1053
+ t.push(" "), t.push(u);
1054
+ else if (d === "style" && typeof g == "object") {
1055
+ const p = Wt(g);
1056
+ p && (t.push(' style="'), t.push(F(p, !0)), t.push('"'));
1046
1057
  } else
1047
- t.push(" "), t.push(p), t.push('="'), t.push(I(String(g), !0)), t.push('"');
1058
+ t.push(" "), t.push(u), t.push('="'), t.push(F(String(g), !0)), t.push('"');
1048
1059
  }
1049
- const d = (h = i.props) == null ? void 0 : h.children;
1050
- let u;
1051
- if (d && typeof d == "object" && "then" in d && typeof d.then == "function" ? u = !1 : u = d != null && (Array.isArray(d) && d.length > 0 || !Array.isArray(d) && d !== !1), ft.has(o))
1060
+ const l = (h = i.props) == null ? void 0 : h.children;
1061
+ let f;
1062
+ if (l && typeof l == "object" && "then" in l && typeof l.then == "function" ? f = !1 : f = l != null && (Array.isArray(l) && l.length > 0 || !Array.isArray(l) && l !== !1), ft.has(o))
1052
1063
  r ? t.push(" />") : t.push(">");
1053
- else if (u) {
1064
+ else if (f) {
1054
1065
  t.push(">");
1055
- const l = d;
1056
- o === "script" && n || o === "style" && a ? (t.push("<![CDATA["), J(l, t, c, n, a, r, s), t.push("]]>")) : o === "script" || o === "style" ? Q(l, t) : P(l, t, c, n, a, r, s), t.push("</"), t.push(o), t.push(">");
1066
+ const d = l;
1067
+ o === "script" && n || o === "style" && a ? (t.push("<![CDATA["), Q(d, t, c, n, a, r, s), t.push("]]>")) : o === "script" || o === "style" ? X(d, t) : P(d, t, c, n, a, r, s), t.push("</"), t.push(o), t.push(">");
1057
1068
  } else wt.has(o), t.push("></"), t.push(o), t.push(">");
1058
1069
  }
1059
- function J(i, t, e, n, a, r, s, h) {
1070
+ function Q(i, t, e, n, a, r, s, h) {
1060
1071
  if (i != null) {
1061
1072
  if (typeof i == "string") {
1062
1073
  t.push(mt(i));
@@ -1068,13 +1079,13 @@ function J(i, t, e, n, a, r, s, h) {
1068
1079
  }
1069
1080
  if (Array.isArray(i)) {
1070
1081
  for (const o of i)
1071
- J(o, t, e, n, a, r, s);
1082
+ Q(o, t, e, n, a, r, s);
1072
1083
  return;
1073
1084
  }
1074
1085
  P(i, t, e, n, a, r, s);
1075
1086
  }
1076
1087
  }
1077
- function Q(i, t) {
1088
+ function X(i, t) {
1078
1089
  if (i != null) {
1079
1090
  if (typeof i == "string") {
1080
1091
  t.push(i);
@@ -1086,7 +1097,7 @@ function Q(i, t) {
1086
1097
  }
1087
1098
  if (Array.isArray(i)) {
1088
1099
  for (const e of i)
1089
- Q(e, t);
1100
+ X(e, t);
1090
1101
  return;
1091
1102
  }
1092
1103
  }
@@ -1133,7 +1144,7 @@ async function N(i) {
1133
1144
  }
1134
1145
  }
1135
1146
  function kt(i, t = {}) {
1136
- return i && typeof i == "object" && "node" in i ? V(i, t) : i === void 0 ? "" : V(i, t);
1147
+ return i && typeof i == "object" && "node" in i ? R(i, t) : i === void 0 ? "" : R(i, t);
1137
1148
  }
1138
1149
  async function At(i) {
1139
1150
  return await N(i);
@@ -1147,7 +1158,7 @@ function St(...i) {
1147
1158
  t.set(n, e), e += n.length;
1148
1159
  return t;
1149
1160
  }
1150
- async function Mt(i) {
1161
+ async function Ct(i) {
1151
1162
  const t = new CompressionStream("deflate"), e = t.writable.getWriter();
1152
1163
  e.write(i), e.close();
1153
1164
  const n = t.readable.getReader(), a = [];
@@ -1163,24 +1174,24 @@ async function Mt(i) {
1163
1174
  s.set(o, h), h += o.length;
1164
1175
  return s;
1165
1176
  }
1166
- const X = new Uint32Array(256);
1177
+ const Y = new Uint32Array(256);
1167
1178
  for (let i = 0; i < 256; i++) {
1168
1179
  let t = i;
1169
1180
  for (let e = 0; e < 8; e++)
1170
1181
  t = t & 1 ? 3988292384 ^ t >>> 1 : t >>> 1;
1171
- X[i] = t;
1182
+ Y[i] = t;
1172
1183
  }
1173
- function Ct(i) {
1184
+ function Mt(i) {
1174
1185
  let t = 4294967295;
1175
1186
  for (let e = 0; e < i.length; e++)
1176
- t = X[(t ^ i[e]) & 255] ^ t >>> 8;
1187
+ t = Y[(t ^ i[e]) & 255] ^ t >>> 8;
1177
1188
  return (t ^ 4294967295) >>> 0;
1178
1189
  }
1179
1190
  const Ht = new TextEncoder();
1180
1191
  function U(i, t) {
1181
1192
  const e = new Uint8Array(8 + t.length + 4), n = new DataView(e.buffer);
1182
1193
  n.setUint32(0, t.length), e.set(Ht.encode(i), 4), e.set(t, 8);
1183
- const a = Ct(e.subarray(4, e.length - 4));
1194
+ const a = Mt(e.subarray(4, e.length - 4));
1184
1195
  return n.setUint32(e.length - 4, a), e;
1185
1196
  }
1186
1197
  function qt(i) {
@@ -1191,14 +1202,14 @@ function Ut(i, t, e, n) {
1191
1202
  for (let o = 0; o < e; o++) {
1192
1203
  h.setUint8(o * r, 0);
1193
1204
  for (let c = 0; c < t; c++) {
1194
- const d = i.getUint8(o * t + c), u = o * r + 1 + Math.floor(c / a), l = (a - 1 - c % a) * n, g = h.getUint8(u);
1195
- h.setUint8(u, g | d << l);
1205
+ const l = i.getUint8(o * t + c), f = o * r + 1 + Math.floor(c / a), d = (a - 1 - c % a) * n, g = h.getUint8(f);
1206
+ h.setUint8(f, g | l << d);
1196
1207
  }
1197
1208
  }
1198
1209
  return s;
1199
1210
  }
1200
- const Nt = new Uint8Array([137, 80, 78, 71, 13, 10, 26, 10]), jt = new TextDecoder();
1201
- function Et(i) {
1211
+ const Nt = new Uint8Array([137, 80, 78, 71, 13, 10, 26, 10]), It = new TextDecoder();
1212
+ function jt(i) {
1202
1213
  switch (i) {
1203
1214
  case 0:
1204
1215
  return "greyscale";
@@ -1224,7 +1235,7 @@ function Pt(i) {
1224
1235
  throw new Error(`Invalid interlace method: ${i}`);
1225
1236
  }
1226
1237
  }
1227
- function Dt(i, t) {
1238
+ function Et(i, t) {
1228
1239
  const e = {
1229
1240
  0: [1, 2, 4, 8, 16],
1230
1241
  // Greyscale
@@ -1245,12 +1256,12 @@ function Dt(i, t) {
1245
1256
  );
1246
1257
  return !0;
1247
1258
  }
1248
- function zt(i, t) {
1259
+ function Dt(i, t) {
1249
1260
  if (t + 12 > i.byteLength)
1250
1261
  throw new Error(
1251
1262
  `Chunk at offset ${t} extends beyond data (need at least 12 bytes for header)`
1252
1263
  );
1253
- const e = i.getUint32(t, !1), n = new Uint8Array(i.buffer, i.byteOffset + t + 4, 4), a = jt.decode(n), r = 8 + e + 4;
1264
+ const e = i.getUint32(t, !1), n = new Uint8Array(i.buffer, i.byteOffset + t + 4, 4), a = It.decode(n), r = 8 + e + 4;
1254
1265
  if (t + r > i.byteLength)
1255
1266
  throw new Error(
1256
1267
  `Chunk "${a}" at offset ${t} extends beyond data (chunk size: ${r}, available: ${i.byteLength - t})`
@@ -1263,19 +1274,19 @@ function zt(i, t) {
1263
1274
  totalSize: r
1264
1275
  };
1265
1276
  }
1266
- function* Ft(i, t = 0) {
1277
+ function* zt(i, t = 0) {
1267
1278
  let e = t;
1268
1279
  for (; e < i.byteLength; ) {
1269
- const n = zt(i, e);
1280
+ const n = Dt(i, e);
1270
1281
  yield n, e += n.totalSize;
1271
1282
  }
1272
1283
  }
1273
- function It(i, t, e, n = 0) {
1274
- for (const a of Ft(i, n))
1284
+ function Ft(i, t, e, n = 0) {
1285
+ for (const a of zt(i, n))
1275
1286
  if (a.type === t)
1276
1287
  return e(a.data);
1277
1288
  }
1278
- function Lt(i) {
1289
+ function Bt(i) {
1279
1290
  if (i.byteLength !== 13)
1280
1291
  throw new Error(`IHDR chunk must be 13 bytes, got ${i.byteLength}`);
1281
1292
  const t = i.getUint32(0, !1), e = i.getUint32(4, !1), n = i.getUint8(8), a = i.getUint8(9), r = i.getUint8(10), s = i.getUint8(11), h = i.getUint8(12);
@@ -1291,8 +1302,8 @@ function Lt(i) {
1291
1302
  throw new Error(
1292
1303
  `Invalid filter method: ${s}. Only 0 (adaptive) is supported.`
1293
1304
  );
1294
- Dt(n, a);
1295
- const o = Et(a), c = Pt(h);
1305
+ Et(n, a);
1306
+ const o = jt(a), c = Pt(h);
1296
1307
  return {
1297
1308
  width: t,
1298
1309
  height: e,
@@ -1303,7 +1314,7 @@ function Lt(i) {
1303
1314
  interlaceMethod: c
1304
1315
  };
1305
1316
  }
1306
- function Bt(i) {
1317
+ function Lt(i) {
1307
1318
  if (i.byteLength < 8)
1308
1319
  throw new Error("Data too short to contain PNG signature");
1309
1320
  for (let t = 0; t < 8; t++)
@@ -1313,8 +1324,8 @@ function Bt(i) {
1313
1324
  }
1314
1325
  function Tt(i) {
1315
1326
  const t = i instanceof Uint8Array ? i.buffer : i, e = i instanceof Uint8Array ? i.byteOffset : 0, n = i.byteLength, a = new DataView(t, e, n);
1316
- Bt(a);
1317
- const r = It(a, "IHDR", Lt, 8);
1327
+ Lt(a);
1328
+ const r = Ft(a, "IHDR", Bt, 8);
1318
1329
  if (r === void 0)
1319
1330
  throw new Error("IHDR chunk not found in PNG");
1320
1331
  return r;
@@ -1336,13 +1347,13 @@ async function Vt(i, t, e, n) {
1336
1347
  throw new Error(
1337
1348
  `Color palette does not have enough colors (${s + 1}). Only ${n.length} were given!`
1338
1349
  );
1339
- const h = qt(s), o = new Uint8Array([137, 80, 78, 71, 13, 10, 26, 10]), c = new Uint8Array(13), d = new DataView(c.buffer);
1340
- d.setUint32(0, t), d.setUint32(4, e), d.setUint8(8, h), d.setUint8(9, 3), d.setUint8(10, 0), d.setUint8(11, 0), d.setUint8(12, 0);
1341
- const u = U("IHDR", c), l = new Uint8Array(n.length * 3), g = new DataView(l.buffer);
1350
+ const h = qt(s), o = new Uint8Array([137, 80, 78, 71, 13, 10, 26, 10]), c = new Uint8Array(13), l = new DataView(c.buffer);
1351
+ l.setUint32(0, t), l.setUint32(4, e), l.setUint8(8, h), l.setUint8(9, 3), l.setUint8(10, 0), l.setUint8(11, 0), l.setUint8(12, 0);
1352
+ const f = U("IHDR", c), d = new Uint8Array(n.length * 3), g = new DataView(d.buffer);
1342
1353
  for (let w = 0; w <= s; w++)
1343
1354
  g.setUint8(w * 3, n[w][0]), g.setUint8(w * 3 + 1, n[w][1]), g.setUint8(w * 3 + 2, n[w][2]);
1344
- const p = U("PLTE", l), f = Ut(a, t, e, h), $ = U("IDAT", await Mt(f)), x = U("IEND", new Uint8Array(0));
1345
- return St(o, u, p, $, x);
1355
+ const u = U("PLTE", d), p = Ut(a, t, e, h), $ = U("IDAT", await Ct(p)), v = U("IEND", new Uint8Array(0));
1356
+ return St(o, f, u, $, v);
1346
1357
  }
1347
1358
  async function Rt(i, t = {}) {
1348
1359
  var e;
@@ -1351,20 +1362,20 @@ async function Rt(i, t = {}) {
1351
1362
  moduleSize: a = 4,
1352
1363
  backgroundColor: r = [255, 255, 255],
1353
1364
  foregroundColor: s = [0, 0, 0]
1354
- } = t, { matrix: h } = i, o = ((e = h[0]) == null ? void 0 : e.length) ?? 0, c = h.length, d = (o + n * 2) * a, u = (c + n * 2) * a, l = new Uint8Array(d * u);
1355
- l.fill(0);
1365
+ } = t, { matrix: h } = i, o = ((e = h[0]) == null ? void 0 : e.length) ?? 0, c = h.length, l = (o + n * 2) * a, f = (c + n * 2) * a, d = new Uint8Array(l * f);
1366
+ d.fill(0);
1356
1367
  for (let g = 0; g < c; g++)
1357
- for (let p = 0; p < o; p++)
1358
- if (h[g][p])
1359
- for (let f = 0; f < a; f++)
1368
+ for (let u = 0; u < o; u++)
1369
+ if (h[g][u])
1370
+ for (let p = 0; p < a; p++)
1360
1371
  for (let $ = 0; $ < a; $++) {
1361
- const x = (p + n) * a + $, w = (g + n) * a + f;
1362
- l[w * d + x] = 1;
1372
+ const v = (u + n) * a + $, w = (g + n) * a + p;
1373
+ d[w * l + v] = 1;
1363
1374
  }
1364
1375
  return {
1365
- bytes: await Vt(l, d, u, [r, s]),
1366
- width: d,
1367
- height: u
1376
+ bytes: await Vt(d, l, f, [r, s]),
1377
+ width: l,
1378
+ height: f
1368
1379
  };
1369
1380
  }
1370
1381
  function Zt(i) {
@@ -1373,7 +1384,7 @@ function Zt(i) {
1373
1384
  n !== void 0 && (t[e] = n);
1374
1385
  return t;
1375
1386
  }
1376
- class Y extends H {
1387
+ class tt extends H {
1377
1388
  charWidth = 12;
1378
1389
  charHeight = 24;
1379
1390
  // Default to charWidth * 2, can be overridden
@@ -1401,9 +1412,11 @@ class Y extends H {
1401
1412
  // Queued text segments for current line
1402
1413
  pendingVrSvg = null;
1403
1414
  // Pending vertical rules SVG for overlay with text
1415
+ currentColumnInfo = null;
1416
+ // Current column context from parser
1404
1417
  // start printing:
1405
1418
  async open(t) {
1406
- return await super.open(t), this.charWidth = t.charWidth, this.charHeight = this.explicitCharHeight ?? t.charWidth * 2, this.actualFontCharacterWidth !== void 0 && this.actualFontCharacterWidth > 0 && (this._cpl = Math.floor(t.cpl * t.charWidth / this.actualFontCharacterWidth)), this.containerWidth = t.cpl * t.charWidth, this.estimatedHeight = 0, this.lineMargin = 0, this.lineAlign = 0, this.lineWidth = this.cpl, this.lineHeight = 1, this.textEncoding = t.encoding, this.feedMinimum = Number(t.spacing ? this.charHeight * 1.25 : this.charHeight), this.spacing = t.spacing, this.contentNodes = [], this.currentStyles = {}, this.textScale = 1, this.currentPosition = 0, this.lineSegments = [], this.pendingVrSvg = null, "";
1419
+ return await super.open(t), this.charWidth = t.charWidth, this.charHeight = this.explicitCharHeight ?? t.charWidth * 2, this.actualFontCharacterWidth !== void 0 && this.actualFontCharacterWidth > 0 && (this._cpl = Math.floor(t.cpl * t.charWidth / this.actualFontCharacterWidth)), this.containerWidth = t.cpl * t.charWidth, this.estimatedHeight = 0, this.lineMargin = 0, this.lineAlign = 0, this.lineWidth = this.cpl, this.lineHeight = 1, this.textEncoding = t.encoding, this.feedMinimum = Number(t.spacing ? this.charHeight * 1.25 : this.charHeight), this.spacing = t.spacing, this.contentNodes = [], this.currentStyles = {}, this.textScale = 1, this.currentPosition = 0, this.lineSegments = [], this.pendingVrSvg = null, this.currentColumnInfo = null, "";
1407
1420
  }
1408
1421
  setDefaultFont(t) {
1409
1422
  return this.defaultFont = t, this.defaultFont;
@@ -1498,6 +1511,10 @@ class Y extends H {
1498
1511
  async relative(t) {
1499
1512
  return this.currentPosition += t, "";
1500
1513
  }
1514
+ // set column context for text alignment:
1515
+ async column(t, e, n, a) {
1516
+ return this.currentColumnInfo = { index: t, start: e, width: n, align: a }, "";
1517
+ }
1501
1518
  // print horizontal rule:
1502
1519
  async hr(t) {
1503
1520
  const e = {
@@ -1516,10 +1533,10 @@ class Y extends H {
1516
1533
  }
1517
1534
  // print vertical rules:
1518
1535
  async vr(t, e) {
1519
- const n = this.charWidth, a = n / 2, r = this.charHeight * e, s = t.reduce((d, u) => d + u, 0) + t.length + 1;
1536
+ const n = this.charWidth, a = n / 2, r = this.charHeight * e, s = t.reduce((l, f) => l + f, 0) + t.length + 1;
1520
1537
  let h = `M${a},0v${r}`;
1521
- for (const d of t)
1522
- h += `m${d * n + n},${-r}v${r}`;
1538
+ for (const l of t)
1539
+ h += `m${l * n + n},${-r}v${r}`;
1523
1540
  const o = s * n, c = {
1524
1541
  type: "svg",
1525
1542
  props: {
@@ -1619,32 +1636,32 @@ class Y extends H {
1619
1636
  }
1620
1637
  // print vertical and horizontal rules:
1621
1638
  async vrhr(t, e, n, a) {
1622
- const r = this.charWidth, s = r / 2, h = t.reduce((f, $) => f + $, 0) + t.length + 1, o = e.reduce((f, $) => f + $, 0) + e.length + 1, c = Math.max(h, o), d = c * r, u = r * 2;
1623
- let l = `M${s},0` + (n > 0 ? `v${s}q0,${s},${s},${s}` : `v${r}h${s}`);
1624
- for (const f of t)
1625
- l += `h${r * f}h${s}v${-r}m0,${r}h${s}`;
1626
- l = l.replace(/h\d+v-\d+m0,\d+h\d+$/, a < 0 ? `q${s},0,${s},${-s}v${-s}` : `h${s}v${-r}`);
1639
+ const r = this.charWidth, s = r / 2, h = t.reduce((p, $) => p + $, 0) + t.length + 1, o = e.reduce((p, $) => p + $, 0) + e.length + 1, c = Math.max(h, o), l = c * r, f = r * 2;
1640
+ let d = `M${s},0` + (n > 0 ? `v${s}q0,${s},${s},${s}` : `v${r}h${s}`);
1641
+ for (const p of t)
1642
+ d += `h${r * p}h${s}v${-r}m0,${r}h${s}`;
1643
+ d = d.replace(/h\d+v-\d+m0,\d+h\d+$/, a < 0 ? `q${s},0,${s},${-s}v${-s}` : `h${s}v${-r}`);
1627
1644
  let g = `M${s},${r + r}` + (n < 0 ? `v${-s}q0,${-s},${s},${-s}` : `v${-r}h${s}`);
1628
- for (const f of e)
1629
- g += `h${r * f}h${s}v${r}m0,${-r}h${s}`;
1645
+ for (const p of e)
1646
+ g += `h${r * p}h${s}v${r}m0,${-r}h${s}`;
1630
1647
  g = g.replace(/h\d+v\d+m0,-\d+h\d+$/, a > 0 ? `q${s},0,${s},${s}v${s}` : `h${s}v${r}`);
1631
- const p = {
1648
+ const u = {
1632
1649
  type: "svg",
1633
1650
  props: {
1634
1651
  width: this.toWidthUnit(c),
1635
- height: `${u}`,
1636
- viewBox: `0 0 ${d} ${u}`,
1652
+ height: `${f}`,
1653
+ viewBox: `0 0 ${l} ${f}`,
1637
1654
  preserveAspectRatio: "none",
1638
1655
  style: {
1639
1656
  marginLeft: this.toWidthUnit(this.lineMargin + Math.max(-n, 0))
1640
1657
  },
1641
1658
  children: [
1642
- { type: "path", props: { d: l, fill: "none", stroke: "black", "stroke-width": "2", "vector-effect": "non-scaling-stroke" } },
1659
+ { type: "path", props: { d, fill: "none", stroke: "black", "stroke-width": "2", "vector-effect": "non-scaling-stroke" } },
1643
1660
  { type: "path", props: { d: g, fill: "none", stroke: "black", "stroke-width": "2", "vector-effect": "non-scaling-stroke" } }
1644
1661
  ]
1645
1662
  }
1646
1663
  };
1647
- return this.contentNodes.push(p), "";
1664
+ return this.contentNodes.push(u), "";
1648
1665
  }
1649
1666
  // set line spacing and feed new line:
1650
1667
  async vrlf(t) {
@@ -1719,7 +1736,8 @@ class Y extends H {
1719
1736
  text: n,
1720
1737
  styles: { ...this.currentStyles },
1721
1738
  scale: this.textScale,
1722
- charWidth: a
1739
+ charWidth: a,
1740
+ columnInfo: this.currentColumnInfo ? { ...this.currentColumnInfo } : null
1723
1741
  };
1724
1742
  return this.lineSegments.push(r), this.currentPosition += a * this.textScale, "";
1725
1743
  }
@@ -1742,74 +1760,135 @@ class Y extends H {
1742
1760
  };
1743
1761
  this.contentNodes.push(s), this.pendingVrSvg = null, this.estimatedHeight += e;
1744
1762
  }
1745
- return this.lineHeight = 1, this.lineSegments = [], this.currentPosition = 0, "";
1763
+ return this.lineHeight = 1, this.lineSegments = [], this.currentPosition = 0, this.currentColumnInfo = null, "";
1764
+ } else if (this.lineSegments.every((h) => h.columnInfo !== null)) {
1765
+ const h = ["left", "center", "right"], o = /* @__PURE__ */ new Map();
1766
+ for (const f of this.lineSegments) {
1767
+ const d = f.columnInfo.index;
1768
+ o.has(d) || o.set(d, []), o.get(d).push(f);
1769
+ }
1770
+ this.lineMargin > 0 && a.push({
1771
+ type: "span",
1772
+ props: {
1773
+ style: {
1774
+ flexBasis: this.toWidthUnit(this.lineMargin)
1775
+ }
1776
+ }
1777
+ });
1778
+ let c = this.lineMargin;
1779
+ const l = [...o.entries()].sort((f, d) => f[0] - d[0]);
1780
+ for (const [f, d] of l) {
1781
+ const g = d[0].columnInfo, u = this.lineMargin + g.start;
1782
+ if (u > c) {
1783
+ const m = u - c;
1784
+ a.push({
1785
+ type: "span",
1786
+ props: {
1787
+ style: {
1788
+ flexBasis: this.toWidthUnit(m)
1789
+ }
1790
+ }
1791
+ }), c = u;
1792
+ }
1793
+ const p = h[g.align] ?? "center", $ = g.align === 0 ? "flex-start" : g.align === 2 ? "flex-end" : "center", v = d.map((m) => m.styles && Object.keys(m.styles).length > 0 ? {
1794
+ type: "span",
1795
+ props: {
1796
+ style: m.styles,
1797
+ children: m.text
1798
+ }
1799
+ } : m.text), w = {
1800
+ type: "span",
1801
+ props: {
1802
+ style: {
1803
+ flexBasis: this.toWidthUnit(g.width),
1804
+ whiteSpace: "pre",
1805
+ display: "flex",
1806
+ justifyContent: $,
1807
+ textAlign: p
1808
+ },
1809
+ children: v.length === 1 ? v[0] : v
1810
+ }
1811
+ };
1812
+ a.push(w), c = u + g.width;
1813
+ }
1814
+ if (c < n) {
1815
+ const f = n - c;
1816
+ a.push({
1817
+ type: "span",
1818
+ props: {
1819
+ style: {
1820
+ flexBasis: this.toWidthUnit(f)
1821
+ }
1822
+ }
1823
+ });
1824
+ }
1746
1825
  } else {
1747
- const s = [...this.lineSegments].sort((u, l) => u.position - l.position);
1748
- let h = 0;
1749
- const o = (u) => Math.floor(u), c = (u) => {
1750
- const l = o(u);
1751
- return this.toWidthUnit(l);
1752
- }, d = (u) => {
1753
- const l = this.actualFontCharacterWidth ?? this.charWidth, g = u.match(/^(\d+(?:\.\d+)?)px$/);
1754
- if (g)
1755
- return parseFloat(g[1]) / l;
1756
- const p = u.match(/^(\d+(?:\.\d+)?)%$/);
1826
+ const h = [...this.lineSegments].sort((d, g) => d.position - g.position);
1827
+ let o = 0;
1828
+ const c = (d) => Math.floor(d), l = (d) => {
1829
+ const g = c(d);
1830
+ return this.toWidthUnit(g);
1831
+ }, f = (d) => {
1832
+ const g = this.actualFontCharacterWidth ?? this.charWidth, u = d.match(/^(\d+(?:\.\d+)?)px$/);
1833
+ if (u)
1834
+ return parseFloat(u[1]) / g;
1835
+ const p = d.match(/^(\d+(?:\.\d+)?)%$/);
1757
1836
  if (p)
1758
- return parseFloat(p[1]) / 100 * this.containerWidth / l;
1759
- const f = u.match(/^(\d+(?:\.\d+)?)ch$/);
1760
- return f ? parseFloat(f[1]) : 0;
1837
+ return parseFloat(p[1]) / 100 * this.containerWidth / g;
1838
+ const $ = d.match(/^(\d+(?:\.\d+)?)ch$/);
1839
+ return $ ? parseFloat($[1]) : 0;
1761
1840
  };
1762
- for (let u = 0; u < s.length; u++) {
1763
- const l = s[u], g = this.lineMargin + l.position, p = l.charWidth * l.scale;
1764
- if (g > h && a.length > 0) {
1765
- const k = g - h, v = a[a.length - 1];
1766
- if (v && v.props && v.props.style && typeof v.props.style == "object" && !Array.isArray(v.props.style)) {
1767
- const A = v.props.style, W = A.flexBasis;
1768
- if (W) {
1769
- const D = d(W) + k;
1770
- A.flexBasis = c(D);
1841
+ for (let d = 0; d < h.length; d++) {
1842
+ const g = h[d], u = this.lineMargin + g.position, p = g.charWidth * g.scale;
1843
+ if (u > o && a.length > 0) {
1844
+ const b = u - o, W = a[a.length - 1];
1845
+ if (W && W.props && W.props.style && typeof W.props.style == "object" && !Array.isArray(W.props.style)) {
1846
+ const k = W.props.style, S = k.flexBasis;
1847
+ if (S) {
1848
+ const E = f(S) + b;
1849
+ k.flexBasis = l(E);
1771
1850
  } else
1772
- A.flexBasis = c(k);
1851
+ k.flexBasis = l(b);
1773
1852
  }
1774
- } else if (g > h && a.length === 0) {
1775
- const k = g - h;
1853
+ } else if (u > o && a.length === 0) {
1854
+ const b = u - o;
1776
1855
  a.push({
1777
1856
  type: "span",
1778
1857
  props: {
1779
1858
  style: {
1780
- flexBasis: c(k)
1859
+ flexBasis: l(b)
1781
1860
  }
1782
1861
  }
1783
1862
  });
1784
1863
  }
1785
- const $ = {
1786
- flexBasis: c(p),
1864
+ const v = {
1865
+ flexBasis: l(p),
1787
1866
  whiteSpace: "pre"
1788
- }, x = l.styles && Object.keys(l.styles).length > 0, w = x ? l.styles : void 0, m = {
1867
+ }, w = g.styles && Object.keys(g.styles).length > 0, m = w ? g.styles : void 0, A = {
1789
1868
  type: "span",
1790
1869
  props: {
1791
- style: $,
1792
- children: x ? {
1870
+ style: v,
1871
+ children: w ? {
1793
1872
  // Wrap text in inner span with content styles
1794
1873
  type: "span",
1795
1874
  props: {
1796
- style: w,
1797
- children: l.text
1875
+ style: m,
1876
+ children: g.text
1798
1877
  }
1799
- } : l.text
1878
+ } : g.text
1800
1879
  }
1801
1880
  };
1802
- a.push(m), h = g + p;
1881
+ a.push(A), o = u + p;
1803
1882
  }
1804
- if (h < n && a.length > 0) {
1805
- const u = n - h, l = a[a.length - 1];
1806
- if (l && l.props && l.props.style && typeof l.props.style == "object" && !Array.isArray(l.props.style)) {
1807
- const g = l.props.style, p = g.flexBasis;
1883
+ if (o < n && a.length > 0) {
1884
+ const d = n - o, g = a[a.length - 1];
1885
+ if (g && g.props && g.props.style && typeof g.props.style == "object" && !Array.isArray(g.props.style)) {
1886
+ const u = g.props.style, p = u.flexBasis;
1808
1887
  if (p) {
1809
- const $ = d(p) + u;
1810
- g.flexBasis = c($);
1888
+ const v = f(p) + d;
1889
+ u.flexBasis = l(v);
1811
1890
  } else
1812
- g.flexBasis = c(u);
1891
+ u.flexBasis = l(d);
1813
1892
  }
1814
1893
  }
1815
1894
  }
@@ -1855,7 +1934,7 @@ class Y extends H {
1855
1934
  this.contentNodes.push(s), this.pendingVrSvg = null;
1856
1935
  } else
1857
1936
  this.contentNodes.push(r);
1858
- return this.estimatedHeight += e, this.lineHeight = 1, this.lineSegments = [], this.currentPosition = 0, "";
1937
+ return this.estimatedHeight += e, this.lineHeight = 1, this.lineSegments = [], this.currentPosition = 0, this.currentColumnInfo = null, "";
1859
1938
  }
1860
1939
  // insert commands:
1861
1940
  async command(t) {
@@ -1863,7 +1942,7 @@ class Y extends H {
1863
1942
  }
1864
1943
  // print image:
1865
1944
  async image(t) {
1866
- const e = this.lineAlign === 0 ? "flex-start" : this.lineAlign === 1 ? "center" : "flex-end", n = Z(t), a = Tt(n), r = a.width, s = a.height, h = {
1945
+ const e = this.lineAlign === 0 ? "flex-start" : this.lineAlign === 1 ? "center" : "flex-end", n = O(t), a = Tt(n), r = a.width, s = a.height, h = {
1867
1946
  type: "img",
1868
1947
  props: {
1869
1948
  src: `data:image/png;base64,${t}`,
@@ -1889,23 +1968,23 @@ class Y extends H {
1889
1968
  }
1890
1969
  // print QR Code (async version using PNG):
1891
1970
  async qrcode(t, e) {
1892
- const n = this.lineAlign === 0 ? "flex-start" : this.lineAlign === 1 ? "center" : "flex-end", a = _({
1971
+ const n = this.lineAlign === 0 ? "flex-start" : this.lineAlign === 1 ? "center" : "flex-end", a = G({
1893
1972
  data: t.data,
1894
- ec: t.level === "l" ? M.L : t.level === "m" ? M.M : t.level === "q" ? M.Q : M.H
1973
+ ec: t.level === "l" ? C.L : t.level === "m" ? C.M : t.level === "q" ? C.Q : C.H
1895
1974
  }), r = t.cell, s = t.quietZone ? 4 : 0, { bytes: h, width: o, height: c } = await Rt(a, {
1896
1975
  moduleSize: r,
1897
1976
  margin: s
1898
- }), u = {
1977
+ }), f = {
1899
1978
  type: "img",
1900
1979
  props: {
1901
- src: `data:image/png;base64,${O(h)}`,
1980
+ src: `data:image/png;base64,${_(h)}`,
1902
1981
  width: `${o}`,
1903
1982
  height: `${c}`,
1904
1983
  style: {
1905
1984
  imageRendering: "pixelated"
1906
1985
  }
1907
1986
  }
1908
- }, l = {
1987
+ }, d = {
1909
1988
  type: "div",
1910
1989
  props: {
1911
1990
  style: {
@@ -1914,18 +1993,18 @@ class Y extends H {
1914
1993
  width: this.toWidthUnit(this.lineWidth),
1915
1994
  display: "flex"
1916
1995
  },
1917
- children: [u]
1996
+ children: [f]
1918
1997
  }
1919
1998
  };
1920
- return this.contentNodes.push(l), this.estimatedHeight += c, "";
1999
+ return this.contentNodes.push(d), this.estimatedHeight += c, "";
1921
2000
  }
1922
2001
  // print barcode:
1923
2002
  async barcode(t, e) {
1924
- const n = K(t), a = n.height, r = this.lineAlign === 0 ? "flex-start" : this.lineAlign === 1 ? "center" : "flex-end";
2003
+ const n = J(t), a = n.height, r = this.lineAlign === 0 ? "flex-start" : this.lineAlign === 1 ? "center" : "flex-end";
1925
2004
  if (a !== void 0 && "length" in n && n.length !== void 0 && n.widths) {
1926
2005
  const s = n.length, h = a + (n.hri ? this.charHeight + 2 : 0);
1927
2006
  let o = "";
1928
- n.widths.reduce((l, g, p) => (p % 2 === 1 && (o += `M${l},0h${g}v${a}h${-g}z`), l + g), 0);
2007
+ n.widths.reduce((d, g, u) => (u % 2 === 1 && (o += `M${d},0h${g}v${a}h${-g}z`), d + g), 0);
1929
2008
  const c = [
1930
2009
  {
1931
2010
  type: "path",
@@ -1947,7 +2026,7 @@ class Y extends H {
1947
2026
  children: n.text
1948
2027
  }
1949
2028
  });
1950
- const d = {
2029
+ const l = {
1951
2030
  type: "svg",
1952
2031
  props: {
1953
2032
  width: `${s}`,
@@ -1955,7 +2034,7 @@ class Y extends H {
1955
2034
  viewBox: `0 0 ${s} ${h}`,
1956
2035
  children: c
1957
2036
  }
1958
- }, u = {
2037
+ }, f = {
1959
2038
  type: "div",
1960
2039
  props: {
1961
2040
  style: {
@@ -1964,10 +2043,10 @@ class Y extends H {
1964
2043
  width: this.toWidthUnit(this.lineWidth),
1965
2044
  display: "flex"
1966
2045
  },
1967
- children: d
2046
+ children: l
1968
2047
  }
1969
2048
  };
1970
- this.contentNodes.push(u), this.estimatedHeight += h;
2049
+ this.contentNodes.push(f), this.estimatedHeight += h;
1971
2050
  }
1972
2051
  return "";
1973
2052
  }
@@ -1978,7 +2057,7 @@ class Y extends H {
1978
2057
  return this.estimatedHeight;
1979
2058
  }
1980
2059
  }
1981
- class tt extends H {
2060
+ class et extends H {
1982
2061
  logs = [];
1983
2062
  /**
1984
2063
  * Start printing.
@@ -2030,6 +2109,18 @@ class tt extends H {
2030
2109
  async relative(t) {
2031
2110
  return this.logs.push(`relative(${t})`), "";
2032
2111
  }
2112
+ /**
2113
+ * Set column context for text alignment.
2114
+ * @param {number} index column index (0-based)
2115
+ * @param {number} start column start position (unit: characters)
2116
+ * @param {number} width column width (unit: characters)
2117
+ * @param {number} align text alignment within column (0: left, 1: center, 2: right)
2118
+ * @returns {Promise<string>} empty string
2119
+ */
2120
+ async column(t, e, n, a) {
2121
+ const r = ["left", "center", "right"];
2122
+ return this.logs.push(`column(index: ${t}, start: ${e}, width: ${n}, align: ${r[a] ?? a})`), "";
2123
+ }
2033
2124
  /**
2034
2125
  * Print horizontal rule.
2035
2126
  * @param {number} width line width (unit: characters)
@@ -2183,16 +2274,16 @@ class tt extends H {
2183
2274
  return 0;
2184
2275
  }
2185
2276
  }
2186
- const z = {
2277
+ const D = {
2187
2278
  base: new H(),
2188
- svg: new F(),
2189
- html: new Y(),
2190
- audit: new tt()
2279
+ svg: new z(),
2280
+ html: new tt(),
2281
+ audit: new et()
2191
2282
  };
2192
2283
  function Ot(i) {
2193
- const t = Object.assign({}, i), e = t.encoding && /^(cp(437|85[28]|86[0356]|1252|93[26]|949|950)|multilingual|shiftjis|gb18030|ksc5601|big5|tis620)$/.test(t.encoding) ? t.encoding : "cp437", n = typeof t.target == "string" ? t.target : void 0, r = (typeof t.target == "object" && t.target !== null ? t.target : void 0) || (n && n in z ? z[n] : z.svg);
2284
+ const t = Object.assign({}, i), e = t.encoding && /^(cp(437|85[28]|86[0356]|1252|93[26]|949|950)|multilingual|shiftjis|gb18030|ksc5601|big5|tis620)$/.test(t.encoding) ? t.encoding : "cp437", n = typeof t.target == "string" ? t.target : void 0, r = (typeof t.target == "object" && t.target !== null ? t.target : void 0) || (n && n in D ? D[n] : D.svg);
2194
2285
  let s;
2195
- return r instanceof Y || r instanceof F || r instanceof tt || r instanceof H ? s = r : s = new F(), {
2286
+ return r instanceof tt || r instanceof z || r instanceof et || r instanceof H ? s = r : s = new z(), {
2196
2287
  cpl: t.cpl || 48,
2197
2288
  charWidth: t.charWidth || 12,
2198
2289
  encoding: e,
@@ -2214,13 +2305,13 @@ function _t(i, t) {
2214
2305
  const h = n.replace(/^[\t ]+|[\t ]+$/g, "");
2215
2306
  if (s.align = 1 + Number(/^[\t ]/.test(n)) - Number(/[\t ]$/.test(n)), /^\{[^{}]*\}$/.test(h)) {
2216
2307
  if (s.property = h.slice(1, -1).replace(/\\;/g, "\\x3b").split(";").reduce((o, c) => {
2217
- const d = { a: "align", b: "border", c: "code", i: "image", o: "option", t: "text", w: "width", x: "command", _: "comment" };
2308
+ const l = { a: "align", b: "border", c: "code", i: "image", o: "option", t: "text", w: "width", x: "command", _: "comment" };
2218
2309
  return /^[\t ]*$/.test(c) || c.replace(
2219
2310
  /^[\t ]*([A-Za-z_]\w*)[\t ]*:[\t ]*([^\t ].*?)[\t ]*$/,
2220
- (l, g, p) => {
2221
- const f = g.replace(/^[abciotwx_]$/, ($) => d[$] || $);
2222
- return o[f] = R(p.replace(/\\n/g, `
2223
- `)), l;
2311
+ (d, g, u) => {
2312
+ const p = g.replace(/^[abciotwx_]$/, ($) => l[$] || $);
2313
+ return o[p] = Z(u.replace(/\\n/g, `
2314
+ `)), d;
2224
2315
  }
2225
2316
  ) === c && (s.error = h), o;
2226
2317
  }, {}), r.length === 1) {
@@ -2229,8 +2320,8 @@ function _t(i, t) {
2229
2320
  t.wrap = !/^nowrap$/.test(o);
2230
2321
  }
2231
2322
  if ("border" in s.property && s.property.border) {
2232
- const o = s.property.border.toLowerCase(), c = { line: -1, space: 1, none: 0 }, d = t.border;
2233
- t.border = /^(line|space|none)$/.test(o) ? c[o] ?? 1 : /^\d+$/.test(o) && Number(o) <= 2 ? Number(o) : 1, d >= 0 && t.border < 0 && (s.vr = "+"), d < 0 && t.border >= 0 && (s.vr = "-");
2323
+ const o = s.property.border.toLowerCase(), c = { line: -1, space: 1, none: 0 }, l = t.border;
2324
+ t.border = /^(line|space|none)$/.test(o) ? c[o] ?? 1 : /^\d+$/.test(o) && Number(o) <= 2 ? Number(o) : 1, l >= 0 && t.border < 0 && (s.vr = "+"), l < 0 && t.border >= 0 && (s.vr = "-");
2234
2325
  }
2235
2326
  if ("width" in s.property && s.property.width) {
2236
2327
  const o = s.property.width.toLowerCase().split(/[\t ]+|,/);
@@ -2278,7 +2369,7 @@ function _t(i, t) {
2278
2369
  s.hr = o === "-" || o === "=" ? o : void 0;
2279
2370
  } else
2280
2371
  s.text = h.replace(/[\x00-\x1f\x7f]|\\x[01][\dA-Fa-f]|\\x7[Ff]/g, "").replace(/\\[-=_"`^~]/g, (o) => "\\x" + o.charCodeAt(1).toString(16)).replace(/\\n/g, `
2281
- `).replace(/~/g, " ").split(/([_"`\n]|\^+)/).map((o) => R(o));
2372
+ `).replace(/~/g, " ").split(/([_"`\n]|\^+)/).map((o) => Z(o));
2282
2373
  if (s.wrap = t.wrap, s.border = t.border, t.width.length === 0)
2283
2374
  s.width = -1;
2284
2375
  else if ("text" in s)
@@ -2287,7 +2378,7 @@ function _t(i, t) {
2287
2378
  s.width = -1;
2288
2379
  else {
2289
2380
  const o = t.width.filter((c) => c > 0);
2290
- s.width = o.length > 0 ? o.reduce((c, d) => c + d, s.border < 0 ? o.length + 1 : (o.length - 1) * s.border) : 0;
2381
+ s.width = o.length > 0 ? o.reduce((c, l) => c + l, s.border < 0 ? o.length + 1 : (o.length - 1) * s.border) : 0;
2291
2382
  }
2292
2383
  return s.alignment = t.align, s;
2293
2384
  });
@@ -2296,27 +2387,27 @@ function _t(i, t) {
2296
2387
  e.push({ align: 1, text: [""], wrap: t.wrap, border: t.border, width: t.width[e.length] ?? 0, alignment: t.align });
2297
2388
  return e;
2298
2389
  }
2299
- function R(i) {
2390
+ function Z(i) {
2300
2391
  return i.replace(/\\$|\\x(.?$|[^\dA-Fa-f].|.[^\dA-Fa-f])/g, "").replace(/\\[^x]/g, "").replace(/\\x([\dA-Fa-f]{2})/g, (t, e) => String.fromCharCode(parseInt(e, 16)));
2301
2392
  }
2302
2393
  function Gt(i, t) {
2303
2394
  const e = [];
2304
2395
  let n = i.width, a = 1, r = [], s = !1, h = !1, o = !1, c = 0;
2305
- return i.text.forEach((d, u) => {
2306
- if (u % 2 === 0) {
2307
- let l = t.target.arrayFrom(d, t.encoding);
2308
- for (; l.length > 0; ) {
2309
- let g = 0, p = 0;
2310
- for (; p < l.length && (g = t.target.measureText(l[p] ?? "", t.encoding) * (c < 2 ? c + 1 : c - 1), !(g > n)); )
2311
- n -= g, g = 0, p++;
2312
- if (p > 0 && (r.push((s ? "1" : "0") + (h ? "1" : "0") + (o ? "1" : "0") + c), r.push(l.slice(0, p).join("")), a = Math.max(a, c < 3 ? c : c - 1), l = l.slice(p)), g > i.width) {
2313
- l = l.slice(1);
2396
+ return i.text.forEach((l, f) => {
2397
+ if (f % 2 === 0) {
2398
+ let d = t.target.arrayFrom(l, t.encoding);
2399
+ for (; d.length > 0; ) {
2400
+ let g = 0, u = 0;
2401
+ for (; u < d.length && (g = t.target.measureText(d[u] ?? "", t.encoding) * (c < 2 ? c + 1 : c - 1), !(g > n)); )
2402
+ n -= g, g = 0, u++;
2403
+ if (u > 0 && (r.push((s ? "1" : "0") + (h ? "1" : "0") + (o ? "1" : "0") + c), r.push(d.slice(0, u).join("")), a = Math.max(a, c < 3 ? c : c - 1), d = d.slice(u)), g > i.width) {
2404
+ d = d.slice(1);
2314
2405
  continue;
2315
2406
  }
2316
2407
  (g > n || n === 0) && (e.push({ data: r, margin: n * i.align / 2, height: a }), n = i.width, r = [], a = 1);
2317
2408
  }
2318
2409
  } else
2319
- switch (d) {
2410
+ switch (l) {
2320
2411
  case `
2321
2412
  `:
2322
2413
  e.push({ data: r, margin: n * i.align / 2, height: a }), n = i.width, r = [], a = 1;
@@ -2331,62 +2422,62 @@ function Gt(i, t) {
2331
2422
  o = !o;
2332
2423
  break;
2333
2424
  default:
2334
- const l = Math.min(d.length, 7);
2335
- c = c === l ? 0 : l;
2425
+ const d = Math.min(l.length, 7);
2426
+ c = c === d ? 0 : d;
2336
2427
  break;
2337
2428
  }
2338
2429
  }), r.length > 0 && e.push({ data: r, margin: n * i.align / 2, height: a }), e;
2339
2430
  }
2340
2431
  async function Kt(i, t, e) {
2341
- const n = [], a = i.every((f) => "text" in f), r = i[0] ?? { align: 1, text: [""], wrap: !0, border: 0, width: 0, alignment: 1 };
2342
- let s = i.filter((f) => f.width !== 0);
2432
+ const n = [], a = i.every((p) => "text" in p), r = i[0] ?? { align: 1, text: [""], wrap: !0, border: 0, width: 0, alignment: 1 };
2433
+ let s = i.filter((p) => p.width !== 0);
2343
2434
  a && (s = s.slice(0, Math.floor(r.border < 0 ? (t.target.cpl - 1) / 2 : (t.target.cpl + r.border) / (r.border + 1))));
2344
- const h = s.filter((f) => f.width > 0), o = s.filter((f) => f.width < 0);
2345
- let c = h.reduce((f, $) => f + $.width, 0), d = t.target.cpl - c;
2346
- a && s.length > 0 && (d -= r.border < 0 ? s.length + 1 : (s.length - 1) * r.border);
2347
- const u = o.length;
2348
- for (; u > d; ) {
2349
- const f = h.reduce(($, x) => $.width > x.width ? $ : x);
2350
- f.width--, d++;
2351
- }
2352
- u > 0 && (o.forEach((f, $) => f.width = Math.floor((d + $) / u)), d = 0);
2353
- const l = Math.floor(d * r.alignment / 2), g = t.target.cpl - d, p = d - l;
2435
+ const h = s.filter((p) => p.width > 0), o = s.filter((p) => p.width < 0);
2436
+ let c = h.reduce((p, $) => p + $.width, 0), l = t.target.cpl - c;
2437
+ a && s.length > 0 && (l -= r.border < 0 ? s.length + 1 : (s.length - 1) * r.border);
2438
+ const f = o.length;
2439
+ for (; f > l; ) {
2440
+ const p = h.reduce(($, v) => $.width > v.width ? $ : v);
2441
+ p.width--, l++;
2442
+ }
2443
+ f > 0 && (o.forEach((p, $) => p.width = Math.floor((l + $) / f)), l = 0);
2444
+ const d = Math.floor(l * r.alignment / 2), g = t.target.cpl - l, u = l - d;
2354
2445
  if (a) {
2355
- const f = s.map((w) => Gt(w, t)), $ = s.map((w) => w.width);
2446
+ const p = s.map((w) => Gt(w, t)), $ = s.map((w) => w.width);
2356
2447
  switch (e.line) {
2357
2448
  case "ready":
2358
2449
  n.push(
2359
- await t.target.normal() + await t.target.area(l, g, p) + await t.target.align(0) + await t.target.vrstart($) + await t.target.vrlf(!0)
2450
+ await t.target.normal() + await t.target.area(d, g, u) + await t.target.align(0) + await t.target.vrstart($) + await t.target.vrlf(!0)
2360
2451
  ), e.line = "running";
2361
2452
  break;
2362
2453
  case "horizontal":
2363
- const w = l - e.rules.left, m = g - e.rules.width, k = Math.min(l, e.rules.left), v = Math.min(p, e.rules.right);
2454
+ const w = d - e.rules.left, m = g - e.rules.width, A = Math.min(d, e.rules.left), b = Math.min(u, e.rules.right);
2364
2455
  n.push(
2365
- await t.target.normal() + await t.target.area(k, t.target.cpl - k - v, v) + await t.target.align(0) + await t.target.vrhr(e.rules.widths, $, w, w + m) + await t.target.lf()
2456
+ await t.target.normal() + await t.target.area(A, t.target.cpl - A - b, b) + await t.target.align(0) + await t.target.vrhr(e.rules.widths, $, w, w + m) + await t.target.lf()
2366
2457
  ), e.line = "running";
2367
2458
  break;
2368
2459
  }
2369
- e.rules = { left: l, width: g, right: p, widths: $ };
2370
- const x = r.wrap ? f.reduce((w, m) => Math.max(w, m.length), 1) : 1;
2371
- for (let w = 0; w < x; w++) {
2372
- let m = await t.target.normal() + await t.target.area(l, g, p) + await t.target.align(0), k = 0;
2460
+ e.rules = { left: d, width: g, right: u, widths: $ };
2461
+ const v = r.wrap ? p.reduce((w, m) => Math.max(w, m.length), 1) : 1;
2462
+ for (let w = 0; w < v; w++) {
2463
+ let m = await t.target.normal() + await t.target.area(d, g, u) + await t.target.align(0), A = 0;
2373
2464
  if (e.line === "running") {
2374
- const v = f.reduce((A, W) => w < W.length ? Math.max(A, W[w]?.height ?? 1) : A, 1);
2375
- m += await t.target.normal() + await t.target.absolute(k++) + await t.target.vr($, v);
2465
+ const b = p.reduce((W, k) => w < k.length ? Math.max(W, k[w]?.height ?? 1) : W, 1);
2466
+ m += await t.target.normal() + await t.target.absolute(A++) + await t.target.vr($, b);
2376
2467
  }
2377
- for (let v = 0; v < f.length; v++) {
2378
- const A = f[v];
2379
- if (A) {
2380
- if (m += await t.target.absolute(k), w < A.length) {
2381
- m += await t.target.relative(A[w]?.margin ?? 0);
2382
- const W = A[w]?.data ?? [];
2383
- for (let S = 0; S < W.length; S += 2) {
2384
- const D = Number(String(W[S])[0]), et = Number(String(W[S])[1]), it = Number(String(W[S])[2]), B = Number(String(W[S])[3]);
2385
- m += await t.target.normal(), D && (m += await t.target.ul()), et && (m += await t.target.em()), it && (m += await t.target.iv()), B && (m += await t.target.wh(B)), m += await t.target.text(String(W[S + 1]), t.encoding);
2468
+ for (let b = 0; b < p.length; b++) {
2469
+ const W = p[b];
2470
+ if (W) {
2471
+ if (m += await t.target.column(b, A, s[b]?.width ?? 0, s[b]?.align ?? 1), m += await t.target.absolute(A), w < W.length) {
2472
+ m += await t.target.relative(W[w]?.margin ?? 0);
2473
+ const k = W[w]?.data ?? [];
2474
+ for (let S = 0; S < k.length; S += 2) {
2475
+ const L = Number(String(k[S])[0]), E = Number(String(k[S])[1]), nt = Number(String(k[S])[2]), T = Number(String(k[S])[3]);
2476
+ m += await t.target.normal(), L && (m += await t.target.ul()), E && (m += await t.target.em()), nt && (m += await t.target.iv()), T && (m += await t.target.wh(T)), m += await t.target.text(String(k[S + 1]), t.encoding);
2386
2477
  }
2387
2478
  } else
2388
2479
  m += await t.target.normal() + await t.target.text(" ", t.encoding);
2389
- k += (s[v]?.width ?? 0) + Math.abs(r.border);
2480
+ A += (s[b]?.width ?? 0) + Math.abs(r.border);
2390
2481
  }
2391
2482
  }
2392
2483
  m += await t.target.lf(), n.push(m);
@@ -2409,7 +2500,7 @@ async function Kt(i, t, e) {
2409
2500
  switch (e.line) {
2410
2501
  case "waiting":
2411
2502
  n.push(
2412
- await t.target.normal() + await t.target.area(l, g, p) + await t.target.align(0) + await t.target.hr(g) + await t.target.lf()
2503
+ await t.target.normal() + await t.target.area(d, g, u) + await t.target.align(0) + await t.target.hr(g) + await t.target.lf()
2413
2504
  );
2414
2505
  break;
2415
2506
  case "running":
@@ -2432,13 +2523,13 @@ async function Kt(i, t, e) {
2432
2523
  break;
2433
2524
  }
2434
2525
  return "image" in r && r.image && n.push(
2435
- await t.target.normal() + await t.target.area(l, g, p) + await t.target.align(r.align) + await t.target.image(r.image)
2526
+ await t.target.normal() + await t.target.area(d, g, u) + await t.target.align(r.align) + await t.target.image(r.image)
2436
2527
  ), "code" in r && r.code && (r.code.type === "qrcode" ? n.push(
2437
- await t.target.normal() + await t.target.area(l, g, p) + await t.target.align(r.align) + await t.target.qrcode(r.code, t.encoding)
2528
+ await t.target.normal() + await t.target.area(d, g, u) + await t.target.align(r.align) + await t.target.qrcode(r.code, t.encoding)
2438
2529
  ) : n.push(
2439
- await t.target.normal() + await t.target.area(l, g, p) + await t.target.align(r.align) + await t.target.barcode(r.code, t.encoding)
2530
+ await t.target.normal() + await t.target.area(d, g, u) + await t.target.align(r.align) + await t.target.barcode(r.code, t.encoding)
2440
2531
  )), "command" in r && r.command && n.push(
2441
- await t.target.normal() + await t.target.area(l, g, p) + await t.target.align(r.align) + await t.target.command(r.command)
2532
+ await t.target.normal() + await t.target.area(d, g, u) + await t.target.align(r.align) + await t.target.command(r.command)
2442
2533
  ), n.join("");
2443
2534
  }
2444
2535
  async function Yt(i, t) {
@@ -2482,9 +2573,9 @@ async function Yt(i, t) {
2482
2573
  }
2483
2574
  }
2484
2575
  export {
2485
- tt as AuditTarget,
2576
+ et as AuditTarget,
2486
2577
  H as BaseTarget,
2487
- Y as HtmlTarget,
2488
- F as SvgTarget,
2578
+ tt as HtmlTarget,
2579
+ z as SvgTarget,
2489
2580
  Yt as transform
2490
2581
  };
@@ -43,6 +43,15 @@ export declare class AuditTarget extends BaseTarget {
43
43
  * @returns {Promise<string>} empty string
44
44
  */
45
45
  relative(position: number): Promise<string>;
46
+ /**
47
+ * Set column context for text alignment.
48
+ * @param {number} index column index (0-based)
49
+ * @param {number} start column start position (unit: characters)
50
+ * @param {number} width column width (unit: characters)
51
+ * @param {number} align text alignment within column (0: left, 1: center, 2: right)
52
+ * @returns {Promise<string>} empty string
53
+ */
54
+ column(index: number, start: number, width: number, align: number): Promise<string>;
46
55
  /**
47
56
  * Print horizontal rule.
48
57
  * @param {number} width line width (unit: characters)
@@ -74,6 +74,15 @@ export declare class BaseTarget implements BaseTargetInterface {
74
74
  * @returns {Promise<string>} commands
75
75
  */
76
76
  relative(position: number): Promise<string>;
77
+ /**
78
+ * Set column context for text alignment.
79
+ * @param {number} index column index (0-based)
80
+ * @param {number} start column start position (unit: characters)
81
+ * @param {number} width column width (unit: characters)
82
+ * @param {number} align text alignment within column (0: left, 1: center, 2: right)
83
+ * @returns {Promise<string>} commands
84
+ */
85
+ column(index: number, start: number, width: number, align: number): Promise<string>;
77
86
  /**
78
87
  * Print horizontal rule.
79
88
  * @param {number} width line width (unit: characters)
@@ -5,12 +5,19 @@ import { HtmlNode, HtmlStyle, HtmlElement } from '@levischuck/tiny-html';
5
5
  * Represents a text segment queued for rendering on a line.
6
6
  * Receipt printers accumulate positioning and text commands, then render on linefeed.
7
7
  */
8
+ interface ColumnInfo {
9
+ index: number;
10
+ start: number;
11
+ width: number;
12
+ align: number;
13
+ }
8
14
  interface LineSegment {
9
15
  position: number;
10
16
  text: string;
11
17
  styles: HtmlStyle;
12
18
  scale: number;
13
19
  charWidth: number;
20
+ columnInfo: ColumnInfo | null;
14
21
  }
15
22
  /**
16
23
  * HTML target class for ReceiptLine commands.
@@ -38,6 +45,7 @@ export declare class HtmlTarget extends BaseTarget {
38
45
  currentPosition: number;
39
46
  lineSegments: LineSegment[];
40
47
  pendingVrSvg: HtmlElement | null;
48
+ currentColumnInfo: ColumnInfo | null;
41
49
  open(printer: ParsedPrinter): Promise<string>;
42
50
  setDefaultFont(font: string): string;
43
51
  setActualFontCharacterWidth(width: number | undefined): void;
@@ -54,6 +62,7 @@ export declare class HtmlTarget extends BaseTarget {
54
62
  align(align: number): Promise<string>;
55
63
  absolute(position: number): Promise<string>;
56
64
  relative(position: number): Promise<string>;
65
+ column(index: number, start: number, width: number, align: number): Promise<string>;
57
66
  hr(width: number): Promise<string>;
58
67
  vr(widths: number[], height: number): Promise<string>;
59
68
  vrstart(widths: number[]): Promise<string>;
package/dist/types.d.ts CHANGED
@@ -20,6 +20,7 @@ export interface BaseTargetInterface {
20
20
  align(align: number): Promise<string>;
21
21
  absolute(position: number): Promise<string>;
22
22
  relative(position: number): Promise<string>;
23
+ column(index: number, start: number, width: number, align: number): Promise<string>;
23
24
  hr(width: number): Promise<string>;
24
25
  vr(widths: number[], height: number): Promise<string>;
25
26
  vrstart(widths: number[]): Promise<string>;
package/package.json CHANGED
@@ -5,7 +5,7 @@
5
5
  "type": "module",
6
6
  "license": "Apache-2.0",
7
7
  "author": "Open Foodservice System Consortium, Levi Schuck",
8
- "version": "0.1.3",
8
+ "version": "0.1.4",
9
9
  "devDependencies": {
10
10
  "@types/bun": "latest",
11
11
  "unplugin-dts": "^1.0.0-beta.6",