@zebrash/core 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.
Files changed (79) hide show
  1. package/dist/assets/fonts-browser.d.ts +2 -0
  2. package/dist/assets/fonts-browser.d.ts.map +1 -1
  3. package/dist/assets/fonts-browser.js +6 -0
  4. package/dist/assets/fonts.d.ts +3 -6
  5. package/dist/assets/fonts.d.ts.map +1 -1
  6. package/dist/assets/fonts.js +15 -5
  7. package/dist/assets/index.d.ts +1 -1
  8. package/dist/assets/index.d.ts.map +1 -1
  9. package/dist/assets/index.js +1 -1
  10. package/dist/drawer-options.d.ts +20 -2
  11. package/dist/drawer-options.d.ts.map +1 -1
  12. package/dist/drawer-options.js +3 -1
  13. package/dist/drawer.d.ts +27 -0
  14. package/dist/drawer.d.ts.map +1 -1
  15. package/dist/drawer.js +96 -0
  16. package/dist/index.d.ts +4 -1
  17. package/dist/index.d.ts.map +1 -1
  18. package/dist/index.js +4 -0
  19. package/dist/svg/emitter.d.ts +76 -0
  20. package/dist/svg/emitter.d.ts.map +1 -0
  21. package/dist/svg/emitter.js +207 -0
  22. package/dist/svg/font_embed.d.ts +12 -0
  23. package/dist/svg/font_embed.d.ts.map +1 -0
  24. package/dist/svg/font_embed.js +61 -0
  25. package/dist/svg-drawers/barcode_128.d.ts +3 -0
  26. package/dist/svg-drawers/barcode_128.d.ts.map +1 -0
  27. package/dist/svg-drawers/barcode_128.js +74 -0
  28. package/dist/svg-drawers/barcode_2of5.d.ts +3 -0
  29. package/dist/svg-drawers/barcode_2of5.d.ts.map +1 -0
  30. package/dist/svg-drawers/barcode_2of5.js +36 -0
  31. package/dist/svg-drawers/barcode_39.d.ts +3 -0
  32. package/dist/svg-drawers/barcode_39.d.ts.map +1 -0
  33. package/dist/svg-drawers/barcode_39.js +34 -0
  34. package/dist/svg-drawers/barcode_aztec.d.ts +3 -0
  35. package/dist/svg-drawers/barcode_aztec.d.ts.map +1 -0
  36. package/dist/svg-drawers/barcode_aztec.js +48 -0
  37. package/dist/svg-drawers/barcode_datamatrix.d.ts +3 -0
  38. package/dist/svg-drawers/barcode_datamatrix.d.ts.map +1 -0
  39. package/dist/svg-drawers/barcode_datamatrix.js +44 -0
  40. package/dist/svg-drawers/barcode_ean13.d.ts +3 -0
  41. package/dist/svg-drawers/barcode_ean13.d.ts.map +1 -0
  42. package/dist/svg-drawers/barcode_ean13.js +76 -0
  43. package/dist/svg-drawers/barcode_paint_svg.d.ts +35 -0
  44. package/dist/svg-drawers/barcode_paint_svg.d.ts.map +1 -0
  45. package/dist/svg-drawers/barcode_paint_svg.js +144 -0
  46. package/dist/svg-drawers/barcode_pdf417.d.ts +3 -0
  47. package/dist/svg-drawers/barcode_pdf417.d.ts.map +1 -0
  48. package/dist/svg-drawers/barcode_pdf417.js +43 -0
  49. package/dist/svg-drawers/barcode_qr.d.ts +3 -0
  50. package/dist/svg-drawers/barcode_qr.d.ts.map +1 -0
  51. package/dist/svg-drawers/barcode_qr.js +39 -0
  52. package/dist/svg-drawers/graphic_box.d.ts +3 -0
  53. package/dist/svg-drawers/graphic_box.d.ts.map +1 -0
  54. package/dist/svg-drawers/graphic_box.js +64 -0
  55. package/dist/svg-drawers/graphic_circle.d.ts +3 -0
  56. package/dist/svg-drawers/graphic_circle.d.ts.map +1 -0
  57. package/dist/svg-drawers/graphic_circle.js +19 -0
  58. package/dist/svg-drawers/graphic_diagonal_line.d.ts +3 -0
  59. package/dist/svg-drawers/graphic_diagonal_line.d.ts.map +1 -0
  60. package/dist/svg-drawers/graphic_diagonal_line.js +36 -0
  61. package/dist/svg-drawers/graphic_field.d.ts +3 -0
  62. package/dist/svg-drawers/graphic_field.d.ts.map +1 -0
  63. package/dist/svg-drawers/graphic_field.js +72 -0
  64. package/dist/svg-drawers/index.d.ts +10 -0
  65. package/dist/svg-drawers/index.d.ts.map +1 -0
  66. package/dist/svg-drawers/index.js +41 -0
  67. package/dist/svg-drawers/maxicode.d.ts +3 -0
  68. package/dist/svg-drawers/maxicode.d.ts.map +1 -0
  69. package/dist/svg-drawers/maxicode.js +87 -0
  70. package/dist/svg-drawers/svg_element_drawer.d.ts +13 -0
  71. package/dist/svg-drawers/svg_element_drawer.d.ts.map +1 -0
  72. package/dist/svg-drawers/svg_element_drawer.js +2 -0
  73. package/dist/svg-drawers/text_field.d.ts +3 -0
  74. package/dist/svg-drawers/text_field.d.ts.map +1 -0
  75. package/dist/svg-drawers/text_field.js +264 -0
  76. package/dist/svg-drawers/transform.d.ts +20 -0
  77. package/dist/svg-drawers/transform.d.ts.map +1 -0
  78. package/dist/svg-drawers/transform.js +52 -0
  79. package/package.json +1 -1
@@ -0,0 +1,43 @@
1
+ // SVG analogue of `drawers/barcode_pdf417.ts`.
2
+ import { encodePdf417, toMatrix as pdf417ToMatrix } from "../barcodes/pdf417/index.js";
3
+ import { adjustImageTypeSetPosition } from "../drawers/element_drawer.js";
4
+ import { paintBitMatrixCellsSvg } from "./barcode_paint_svg.js";
5
+ import { rotateForOrientation } from "./transform.js";
6
+ function asBitMatrix(rows) {
7
+ const height = rows.length;
8
+ const width = height > 0 ? rows[0].length : 0;
9
+ return {
10
+ width,
11
+ height,
12
+ at(x, y) {
13
+ return rows[y]?.[x] ?? false;
14
+ },
15
+ };
16
+ }
17
+ export function newBarcodePdf417SvgDrawer() {
18
+ return {
19
+ draw(emitter, element) {
20
+ const barcode = element;
21
+ if (!barcode || barcode._kind !== "BarcodePdf417WithData")
22
+ return;
23
+ const result = encodePdf417(barcode.data, barcode.security, barcode.columns);
24
+ const matrix = asBitMatrix(pdf417ToMatrix(result));
25
+ // PDF417 modules are 2px wide × rowHeight px tall (matches Go's
26
+ // images.NewScaled(barcode, 2, scaleY) at encoder.go:scaleX=2).
27
+ const moduleWidth = 2;
28
+ const moduleHeight = Math.max(barcode.rowHeight, 1);
29
+ const width = matrix.width * moduleWidth;
30
+ const height = matrix.height * moduleHeight;
31
+ const pos = adjustImageTypeSetPosition(width, height, barcode.position, barcode.orientation);
32
+ emitter.save();
33
+ try {
34
+ rotateForOrientation(emitter, width, height, pos, barcode.orientation);
35
+ paintBitMatrixCellsSvg(emitter, matrix, pos, moduleWidth, moduleHeight);
36
+ }
37
+ finally {
38
+ emitter.restore();
39
+ }
40
+ },
41
+ };
42
+ }
43
+ //# sourceMappingURL=barcode_pdf417.js.map
@@ -0,0 +1,3 @@
1
+ import type { SvgElementDrawer } from "./svg_element_drawer.ts";
2
+ export declare function newBarcodeQrSvgDrawer(): SvgElementDrawer;
3
+ //# sourceMappingURL=barcode_qr.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"barcode_qr.d.ts","sourceRoot":"","sources":["../../src/svg-drawers/barcode_qr.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAUhE,wBAAgB,qBAAqB,IAAI,gBAAgB,CAuBxD"}
@@ -0,0 +1,39 @@
1
+ // SVG analogue of `drawers/barcode_qr.ts`.
2
+ import { encodeQr } from "../barcodes/qrcode/index.js";
3
+ import { getQrInputData, } from "../elements/index.js";
4
+ import { paintBitMatrixCellsSvg } from "./barcode_paint_svg.js";
5
+ export function newBarcodeQrSvgDrawer() {
6
+ return {
7
+ draw(emitter, element) {
8
+ const barcode = element;
9
+ if (!barcode || barcode._kind !== "BarcodeQrWithData")
10
+ return;
11
+ const { data, level } = getQrInputData(barcode);
12
+ const matrix = encodeQr(data, 1, 1, mapQrErrorCorrectionLevel(level), { QuietZone: 0 });
13
+ const magnification = Math.max(barcode.magnification, 1);
14
+ const cellsHeight = matrix.height * magnification;
15
+ const pos = { ...barcode.position };
16
+ if (!pos.calculateFromBottom) {
17
+ pos.y += barcode.height;
18
+ }
19
+ else {
20
+ const ftOffset = magnification * 7;
21
+ pos.y = Math.max(pos.y - cellsHeight, 0) - ftOffset;
22
+ }
23
+ paintBitMatrixCellsSvg(emitter, matrix, pos, magnification);
24
+ },
25
+ };
26
+ }
27
+ function mapQrErrorCorrectionLevel(level) {
28
+ switch (level) {
29
+ case "L".charCodeAt(0):
30
+ return 0x01;
31
+ case "Q".charCodeAt(0):
32
+ return 0x03;
33
+ case "H".charCodeAt(0):
34
+ return 0x02;
35
+ default:
36
+ return 0x00;
37
+ }
38
+ }
39
+ //# sourceMappingURL=barcode_qr.js.map
@@ -0,0 +1,3 @@
1
+ import type { SvgElementDrawer } from "./svg_element_drawer.ts";
2
+ export declare function newGraphicBoxSvgDrawer(): SvgElementDrawer;
3
+ //# sourceMappingURL=graphic_box.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"graphic_box.d.ts","sourceRoot":"","sources":["../../src/svg-drawers/graphic_box.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAmBhE,wBAAgB,sBAAsB,IAAI,gBAAgB,CAmEzD"}
@@ -0,0 +1,64 @@
1
+ // SVG analogue of `drawers/graphic_box.ts` (and Go's
2
+ // `internal/drawers/graphic_box.go`).
3
+ import { LineColor } from "../elements/line_color.js";
4
+ const COLOR_BLACK = "#000000";
5
+ const COLOR_WHITE = "#ffffff";
6
+ function isGraphicBox(value) {
7
+ return (typeof value === "object" &&
8
+ value !== null &&
9
+ value._kind === "GraphicBox");
10
+ }
11
+ function colorOf(line) {
12
+ return line === LineColor.White ? COLOR_WHITE : COLOR_BLACK;
13
+ }
14
+ export function newGraphicBoxSvgDrawer() {
15
+ return {
16
+ draw(emitter, element) {
17
+ if (!isGraphicBox(element))
18
+ return;
19
+ let width = element.width;
20
+ let height = element.height;
21
+ const border = element.borderThickness;
22
+ if (border > width)
23
+ width = border;
24
+ if (border > height)
25
+ height = border;
26
+ const offset = border / 2;
27
+ const x = element.position.x + offset;
28
+ const y = element.position.y + offset;
29
+ let w = width - border;
30
+ let h = height - border;
31
+ if (w === 0 && h === 0) {
32
+ w = 1;
33
+ h = 1;
34
+ }
35
+ const color = colorOf(element.lineColor);
36
+ // Degenerate rectangles (one dimension reduces to zero after
37
+ // subtracting the border) are how ZPL labels build thin bars: e.g.
38
+ // `^GB184,,8,B` is a width=184 box with default height=0 and
39
+ // border=8, which the canvas drawer paints as a fat horizontal
40
+ // stroke. SVG explicitly skips rendering of `<rect width=0>` and
41
+ // `<rect height=0>` per spec, so we emit a filled `<rect>` with the
42
+ // visible footprint instead.
43
+ if (w === 0 || h === 0) {
44
+ emitter.rect(element.position.x, element.position.y, width, height, color);
45
+ return;
46
+ }
47
+ if (element.cornerRounding > 0) {
48
+ // Rounded box rendered as outer-minus-inner donut. Mirrors the
49
+ // canvas drawer's "fill outer, then destination-out inner" pattern,
50
+ // but expressed declaratively as a single path with even-odd fill.
51
+ const r1 = (element.cornerRounding * Math.min(width, height)) / 16;
52
+ const innerW = width - 2 * border;
53
+ const innerH = height - 2 * border;
54
+ const r2 = innerW > 0 && innerH > 0 ? (element.cornerRounding * Math.min(innerW, innerH)) / 16 : 0;
55
+ emitter.roundedDonut(element.position.x, element.position.y, width, height, r1, element.position.x + border, element.position.y + border, innerW, innerH, r2, color);
56
+ return;
57
+ }
58
+ // Unrounded: stroked rectangle outline. Border is centred on the path
59
+ // (matching the canvas drawer's offset-by-border/2 pattern).
60
+ emitter.rectStroke(x, y, w, h, color, border);
61
+ },
62
+ };
63
+ }
64
+ //# sourceMappingURL=graphic_box.js.map
@@ -0,0 +1,3 @@
1
+ import type { SvgElementDrawer } from "./svg_element_drawer.ts";
2
+ export declare function newGraphicCircleSvgDrawer(): SvgElementDrawer;
3
+ //# sourceMappingURL=graphic_circle.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"graphic_circle.d.ts","sourceRoot":"","sources":["../../src/svg-drawers/graphic_circle.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAYhE,wBAAgB,yBAAyB,IAAI,gBAAgB,CAgB5D"}
@@ -0,0 +1,19 @@
1
+ // SVG analogue of `drawers/graphic_circle.ts`.
2
+ import { LineColor } from "../elements/line_color.js";
3
+ function isGraphicCircle(value) {
4
+ return (typeof value === "object" &&
5
+ value !== null &&
6
+ value._kind === "GraphicCircle");
7
+ }
8
+ export function newGraphicCircleSvgDrawer() {
9
+ return {
10
+ draw(emitter, element) {
11
+ if (!isGraphicCircle(element))
12
+ return;
13
+ const color = element.lineColor === LineColor.White ? "#ffffff" : "#000000";
14
+ const radius = element.circleDiameter / 2;
15
+ emitter.circleStroke(element.position.x + radius, element.position.y + radius, radius, color, element.borderThickness);
16
+ },
17
+ };
18
+ }
19
+ //# sourceMappingURL=graphic_circle.js.map
@@ -0,0 +1,3 @@
1
+ import type { SvgElementDrawer } from "./svg_element_drawer.ts";
2
+ export declare function newGraphicDiagonalLineSvgDrawer(): SvgElementDrawer;
3
+ //# sourceMappingURL=graphic_diagonal_line.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"graphic_diagonal_line.d.ts","sourceRoot":"","sources":["../../src/svg-drawers/graphic_diagonal_line.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAYhE,wBAAgB,+BAA+B,IAAI,gBAAgB,CA4BlE"}
@@ -0,0 +1,36 @@
1
+ // SVG analogue of `drawers/graphic_diagonal_line.ts`.
2
+ import { LineColor } from "../elements/line_color.js";
3
+ function isGraphicDiagonalLine(value) {
4
+ return (typeof value === "object" &&
5
+ value !== null &&
6
+ value._kind === "GraphicDiagonalLine");
7
+ }
8
+ export function newGraphicDiagonalLineSvgDrawer() {
9
+ return {
10
+ draw(emitter, element) {
11
+ if (!isGraphicDiagonalLine(element))
12
+ return;
13
+ const color = element.lineColor === LineColor.White ? "#ffffff" : "#000000";
14
+ const { x, y } = element.position;
15
+ const w = element.width;
16
+ const h = element.height;
17
+ const b = element.borderThickness;
18
+ // Mirrors the canvas drawer's parallelogram, expressed as a polygon.
19
+ const points = element.topToBottom
20
+ ? [
21
+ [x, y],
22
+ [x + b, y],
23
+ [x + b + w, y + h],
24
+ [x + w, y + h],
25
+ ]
26
+ : [
27
+ [x, y + h],
28
+ [x + b, y + h],
29
+ [x + b + w, y],
30
+ [x + w, y],
31
+ ];
32
+ emitter.polygon(points, color);
33
+ },
34
+ };
35
+ }
36
+ //# sourceMappingURL=graphic_diagonal_line.js.map
@@ -0,0 +1,3 @@
1
+ import type { SvgElementDrawer } from "./svg_element_drawer.ts";
2
+ export declare function newGraphicFieldSvgDrawer(): SvgElementDrawer;
3
+ //# sourceMappingURL=graphic_field.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"graphic_field.d.ts","sourceRoot":"","sources":["../../src/svg-drawers/graphic_field.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAYhE,wBAAgB,wBAAwB,IAAI,gBAAgB,CAsD3D"}
@@ -0,0 +1,72 @@
1
+ // SVG analogue of `drawers/graphic_field.ts`. The only drawer that requires
2
+ // raster: the input is a packed-bit bitmap with no geometric structure to
3
+ // preserve, so we re-rasterise into a canvas and embed the PNG bytes as a
4
+ // data URL `<image>`.
5
+ import { platform } from "../platform.js";
6
+ function isGraphicField(value) {
7
+ return (typeof value === "object" &&
8
+ value !== null &&
9
+ value._kind === "GraphicField");
10
+ }
11
+ export function newGraphicFieldSvgDrawer() {
12
+ return {
13
+ async draw(emitter, element) {
14
+ if (!isGraphicField(element))
15
+ return;
16
+ const dataLen = element.totalBytes > 0
17
+ ? Math.min(element.totalBytes, element.data.length)
18
+ : element.data.length;
19
+ const width = element.rowBytes * 8;
20
+ const height = element.rowBytes > 0 ? Math.floor(dataLen / element.rowBytes) : 0;
21
+ if (width <= 0 || height <= 0)
22
+ return;
23
+ const magX = Math.max(1, element.magnificationX);
24
+ const magY = Math.max(1, element.magnificationY);
25
+ const dstW = width * magX;
26
+ const dstH = height * magY;
27
+ // Identical bit-unpack loop to the canvas drawer; the resulting canvas
28
+ // becomes the source for an embedded PNG.
29
+ const offscreen = platform.createCanvas(dstW, dstH);
30
+ const offCtx = offscreen.getContext("2d");
31
+ if (offCtx === null)
32
+ throw new Error("zebrash: failed to acquire 2D context for ^GF");
33
+ const imageData = offCtx.createImageData(dstW, dstH);
34
+ const buf = imageData.data;
35
+ for (let dy = 0; dy < dstH; dy++) {
36
+ const sy = Math.floor(dy / magY);
37
+ const rowOff = sy * element.rowBytes;
38
+ for (let dx = 0; dx < dstW; dx++) {
39
+ const sx = Math.floor(dx / magX);
40
+ const idx = rowOff + (sx >>> 3);
41
+ if (idx >= element.data.length)
42
+ continue;
43
+ const byte = element.data[idx] ?? 0;
44
+ const bit = (byte >> (7 - (sx & 7))) & 1;
45
+ if (bit === 0)
46
+ continue;
47
+ const off = (dy * dstW + dx) * 4;
48
+ buf[off] = 0;
49
+ buf[off + 1] = 0;
50
+ buf[off + 2] = 0;
51
+ buf[off + 3] = 255;
52
+ }
53
+ }
54
+ offCtx.putImageData(imageData, 0, 0);
55
+ const pngBytes = await platform.encodePng(offscreen);
56
+ const href = `data:image/png;base64,${base64Encode(pngBytes)}`;
57
+ emitter.image(href, element.position.x, element.position.y, dstW, dstH);
58
+ },
59
+ };
60
+ }
61
+ function base64Encode(bytes) {
62
+ if (typeof Buffer !== "undefined") {
63
+ return Buffer.from(bytes).toString("base64");
64
+ }
65
+ let bin = "";
66
+ const chunk = 0x8000;
67
+ for (let i = 0; i < bytes.length; i += chunk) {
68
+ bin += String.fromCharCode(...bytes.subarray(i, Math.min(i + chunk, bytes.length)));
69
+ }
70
+ return btoa(bin);
71
+ }
72
+ //# sourceMappingURL=graphic_field.js.map
@@ -0,0 +1,10 @@
1
+ export { type SvgElementDrawer } from "./svg_element_drawer.ts";
2
+ export { rotateAbout as svgRotateAbout, rotateForOrientation as svgRotateForOrientation, rotateImage as svgRotateImage, scaleAbout as svgScaleAbout, } from "./transform.ts";
3
+ import type { SvgElementDrawer } from "./svg_element_drawer.ts";
4
+ /**
5
+ * Returns the full set of SVG element drawers in the same order
6
+ * `defaultElementDrawers()` registers their canvas siblings, so the SVG
7
+ * pipeline mirrors the PNG one's element-dispatch behaviour.
8
+ */
9
+ export declare function defaultSvgElementDrawers(): SvgElementDrawer[];
10
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/svg-drawers/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAChE,OAAO,EACL,WAAW,IAAI,cAAc,EAC7B,oBAAoB,IAAI,uBAAuB,EAC/C,WAAW,IAAI,cAAc,EAC7B,UAAU,IAAI,aAAa,GAC5B,MAAM,gBAAgB,CAAC;AAExB,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAiBhE;;;;GAIG;AACH,wBAAgB,wBAAwB,IAAI,gBAAgB,EAAE,CAiB7D"}
@@ -0,0 +1,41 @@
1
+ // Aggregated public surface for the SVG element drawers.
2
+ export {} from "./svg_element_drawer.js";
3
+ export { rotateAbout as svgRotateAbout, rotateForOrientation as svgRotateForOrientation, rotateImage as svgRotateImage, scaleAbout as svgScaleAbout, } from "./transform.js";
4
+ import { newBarcode2of5SvgDrawer } from "./barcode_2of5.js";
5
+ import { newBarcode39SvgDrawer } from "./barcode_39.js";
6
+ import { newBarcode128SvgDrawer } from "./barcode_128.js";
7
+ import { newBarcodeAztecSvgDrawer } from "./barcode_aztec.js";
8
+ import { newBarcodeDatamatrixSvgDrawer } from "./barcode_datamatrix.js";
9
+ import { newBarcodeEan13SvgDrawer } from "./barcode_ean13.js";
10
+ import { newBarcodePdf417SvgDrawer } from "./barcode_pdf417.js";
11
+ import { newBarcodeQrSvgDrawer } from "./barcode_qr.js";
12
+ import { newGraphicBoxSvgDrawer } from "./graphic_box.js";
13
+ import { newGraphicCircleSvgDrawer } from "./graphic_circle.js";
14
+ import { newGraphicDiagonalLineSvgDrawer } from "./graphic_diagonal_line.js";
15
+ import { newGraphicFieldSvgDrawer } from "./graphic_field.js";
16
+ import { newMaxicodeSvgDrawer } from "./maxicode.js";
17
+ import { newTextFieldSvgDrawer } from "./text_field.js";
18
+ /**
19
+ * Returns the full set of SVG element drawers in the same order
20
+ * `defaultElementDrawers()` registers their canvas siblings, so the SVG
21
+ * pipeline mirrors the PNG one's element-dispatch behaviour.
22
+ */
23
+ export function defaultSvgElementDrawers() {
24
+ return [
25
+ newGraphicBoxSvgDrawer(),
26
+ newGraphicCircleSvgDrawer(),
27
+ newGraphicFieldSvgDrawer(),
28
+ newGraphicDiagonalLineSvgDrawer(),
29
+ newTextFieldSvgDrawer(),
30
+ newMaxicodeSvgDrawer(),
31
+ newBarcode128SvgDrawer(),
32
+ newBarcodeEan13SvgDrawer(),
33
+ newBarcode2of5SvgDrawer(),
34
+ newBarcode39SvgDrawer(),
35
+ newBarcodePdf417SvgDrawer(),
36
+ newBarcodeAztecSvgDrawer(),
37
+ newBarcodeDatamatrixSvgDrawer(),
38
+ newBarcodeQrSvgDrawer(),
39
+ ];
40
+ }
41
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,3 @@
1
+ import type { SvgElementDrawer } from "./svg_element_drawer.ts";
2
+ export declare function newMaxicodeSvgDrawer(): SvgElementDrawer;
3
+ //# sourceMappingURL=maxicode.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"maxicode.d.ts","sourceRoot":"","sources":["../../src/svg-drawers/maxicode.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAkBhE,wBAAgB,oBAAoB,IAAI,gBAAgB,CAyCvD"}
@@ -0,0 +1,87 @@
1
+ // SVG analogue of `drawers/maxicode.ts`.
2
+ //
3
+ // Modules are emitted as `<use href="#hex">` references against a single
4
+ // `<symbol>` defined in `<defs>`, instead of a `<polygon>` per cell —
5
+ // MaxiCode has 884 modules, so this saves ~80% of the output size.
6
+ import { MAXICODE_COLS, MAXICODE_ROWS, encodeMaxicode, } from "../barcodes/maxicode/index.js";
7
+ import { adjustImageTypeSetPosition } from "../drawers/element_drawer.js";
8
+ import { FieldOrientationNormal, getMaxicodeInputData, } from "../elements/index.js";
9
+ const BLACK = "#000000";
10
+ const HEX_SYMBOL_ID = "zb-mxc-hex";
11
+ export function newMaxicodeSvgDrawer() {
12
+ return {
13
+ draw(emitter, element, options) {
14
+ const barcode = element;
15
+ if (!barcode || barcode._kind !== "MaxicodeWithData")
16
+ return;
17
+ const inputData = getMaxicodeInputData(barcode);
18
+ const grid = encodeMaxicode(barcode.code.mode, 0, inputData);
19
+ const dpmm = options.dpmm;
20
+ const hexRectW = Math.round(0.76 * dpmm);
21
+ const hexRectH = Math.round(0.88 * dpmm);
22
+ const imageWidth = Math.trunc(28 * dpmm);
23
+ const imageHeight = Math.trunc(26.8 * dpmm);
24
+ const pos = adjustImageTypeSetPosition(imageWidth, imageHeight, barcode.position, FieldOrientationNormal);
25
+ // Define the hex `<symbol>` once — reused across every cell. Symbol
26
+ // dimensions match the canvas drawer's per-cell hexagon path.
27
+ const hexW = 0.76 * dpmm;
28
+ const hexH = 0.88 * dpmm;
29
+ emitter.defineSymbol(HEX_SYMBOL_ID, `<polygon points="${formatHexPoints(hexW, hexH)}" fill="${BLACK}"/>`);
30
+ emitter.save();
31
+ try {
32
+ emitter.translate(pos.x - hexRectW, pos.y - hexRectH);
33
+ drawMaxicodeGridSvg(emitter, grid, dpmm);
34
+ }
35
+ finally {
36
+ emitter.restore();
37
+ }
38
+ },
39
+ };
40
+ }
41
+ function formatHexPoints(w, h) {
42
+ return [
43
+ [w * 0.5, 0],
44
+ [w, h * 0.25],
45
+ [w, h * 0.75],
46
+ [w * 0.5, h],
47
+ [0, h * 0.75],
48
+ [0, h * 0.25],
49
+ ]
50
+ .map(([x, y]) => `${roundShort(x)},${roundShort(y)}`)
51
+ .join(" ");
52
+ }
53
+ function roundShort(v) {
54
+ if (Number.isInteger(v))
55
+ return v.toString();
56
+ return v
57
+ .toFixed(3)
58
+ .replace(/(\.\d*?)0+$/, "$1")
59
+ .replace(/\.$/, "");
60
+ }
61
+ /**
62
+ * Render a Maxicode grid: bullseye rings (three stroked circles) + a
63
+ * hexagonal module per dark cell. Mirrors `drawMaxicodeGrid` on the canvas
64
+ * side.
65
+ */
66
+ function drawMaxicodeGridSvg(emitter, grid, dpmm) {
67
+ const centerX = 13.64 * dpmm;
68
+ const centerY = 13.43 * dpmm;
69
+ const innerRadius = 0.85 * dpmm;
70
+ const centerRadius = 2.2 * dpmm;
71
+ const outerRadius = 3.54 * dpmm;
72
+ const ringStroke = 0.67 * dpmm;
73
+ for (const radius of [outerRadius, centerRadius, innerRadius]) {
74
+ emitter.circleStroke(centerX, centerY, radius, BLACK, ringStroke);
75
+ }
76
+ for (let row = 0; row < MAXICODE_ROWS; row++) {
77
+ const rowOffset = (row & 1) === 1 ? 1.32 : 0.88;
78
+ for (let col = 0; col < MAXICODE_COLS; col++) {
79
+ if (!grid.get(row, col))
80
+ continue;
81
+ const hexRectX = (col * 0.88 + rowOffset) * dpmm;
82
+ const hexRectY = (row * 0.76 + 0.76) * dpmm;
83
+ emitter.use(HEX_SYMBOL_ID, hexRectX, hexRectY);
84
+ }
85
+ }
86
+ }
87
+ //# sourceMappingURL=maxicode.js.map
@@ -0,0 +1,13 @@
1
+ import type { DrawerOptions } from "../drawer-options.ts";
2
+ import type { DrawerState } from "../drawers/drawer_state.ts";
3
+ import type { SvgEmitter } from "../svg/emitter.ts";
4
+ /**
5
+ * Emits one ZPL element as SVG. SVG-side analog of `ElementDrawer` —
6
+ * each per-element drawer (graphic box, text field, barcode, …) is realised
7
+ * as one of these. Mirrors the "every drawer early-returns if `el._kind`
8
+ * doesn't match" pattern from the canvas pipeline.
9
+ */
10
+ export interface SvgElementDrawer {
11
+ draw(emitter: SvgEmitter, element: unknown, options: DrawerOptions, state: DrawerState): void | Promise<void>;
12
+ }
13
+ //# sourceMappingURL=svg_element_drawer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"svg_element_drawer.d.ts","sourceRoot":"","sources":["../../src/svg-drawers/svg_element_drawer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAC;AAC9D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAEpD;;;;;GAKG;AACH,MAAM,WAAW,gBAAgB;IAC/B,IAAI,CACF,OAAO,EAAE,UAAU,EACnB,OAAO,EAAE,OAAO,EAChB,OAAO,EAAE,aAAa,EACtB,KAAK,EAAE,WAAW,GACjB,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CACzB"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=svg_element_drawer.js.map
@@ -0,0 +1,3 @@
1
+ import type { SvgElementDrawer } from "./svg_element_drawer.ts";
2
+ export declare function newTextFieldSvgDrawer(): SvgElementDrawer;
3
+ //# sourceMappingURL=text_field.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"text_field.d.ts","sourceRoot":"","sources":["../../src/svg-drawers/text_field.ts"],"names":[],"mappings":"AAYA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAsDhE,wBAAgB,qBAAqB,IAAI,gBAAgB,CAkFxD"}