@ym-print/renderer-pdf 0.1.0-rc.2 → 0.1.0-rc.3

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.
@@ -1,6 +1,6 @@
1
1
  # Third-party notices
2
2
 
3
- @ym-print/renderer-pdf 0.1.0-rc.2 — original code: UNLICENSED.
3
+ @ym-print/renderer-pdf 0.1.0-rc.3 — original code: UNLICENSED.
4
4
 
5
5
  Bundled code and external packages keep their original licenses. Optional peers are loaded through their documented opt-in entry.
6
6
 
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "package": "@ym-print/renderer-pdf",
3
- "version": "0.1.0-rc.2",
3
+ "version": "0.1.0-rc.3",
4
4
  "license": "UNLICENSED",
5
5
  "licenseScope": "original YmPrintUnit code only",
6
6
  "dependencies": [
package/dist/index.js CHANGED
@@ -1,33 +1,36 @@
1
1
  import { PDFDocument as e } from "pdf-lib";
2
2
  import { PrintError as t, printLayout as n, umToPt as r } from "@ym-print/core";
3
3
  // src/index.ts
4
- async function i(i, a) {
5
- let o = n(i), s = await e.create();
6
- s.setTitle(i.name), s.setProducer("YmPrintUnit Web · raster pages");
7
- for (let e of o.pages) {
8
- let n = r(e.widthUm), i = r(e.heightUm), o = s.addPage([n, i]), c = a(e);
9
- if (Symbol.asyncIterator in c) for await (let e of c) {
10
- let { xPx: r, yPx: a, widthPx: c, heightPx: l, pageWidthPx: u, pageHeightPx: d } = e;
4
+ function i(e) {
5
+ return Array.isArray(e) ? e.map(i) : typeof e == "object" && e ? Object.fromEntries(Object.entries(e).map(([e, t]) => [e, i(t)])) : e;
6
+ }
7
+ async function a(a, o) {
8
+ let { name: s, pages: c } = n(a), l = c.map(i), u = await e.create();
9
+ u.setTitle(s), u.setProducer("YmPrintUnit Web · raster pages");
10
+ for (let e of l) {
11
+ let n = r(e.widthUm), i = r(e.heightUm), a = u.addPage([n, i]), s = o(e);
12
+ if (Symbol.asyncIterator in s) for await (let e of s) {
13
+ let { xPx: r, yPx: o, widthPx: s, heightPx: c, pageWidthPx: l, pageHeightPx: d } = e;
11
14
  if (![
12
15
  r,
13
- a,
16
+ o,
17
+ s,
14
18
  c,
15
19
  l,
16
- u,
17
20
  d
18
- ].every(Number.isSafeInteger) || r < 0 || a < 0 || c < 1 || l < 1 || u < 1 || d < 1 || r + c > u || a + l > d) throw new t("PDF_REGION_INVALID", "PDF 图片分条位置无效");
19
- let f = await s.embedPng(e.bytes);
20
- if (f.width !== c || f.height !== l) throw new t("PDF_REGION_INVALID", "PDF 分条像素尺寸不匹配");
21
- o.drawImage(f, {
22
- x: r / u * n,
23
- y: (d - a - l) / d * i,
24
- width: c / u * n,
25
- height: l / d * i
21
+ ].every(Number.isSafeInteger) || r < 0 || o < 0 || s < 1 || c < 1 || l < 1 || d < 1 || r + s > l || o + c > d) throw new t("PDF_REGION_INVALID", "PDF 图片分条位置无效");
22
+ let f = await u.embedPng(e.bytes);
23
+ if (f.width !== s || f.height !== c) throw new t("PDF_REGION_INVALID", "PDF 分条像素尺寸不匹配");
24
+ a.drawImage(f, {
25
+ x: r / l * n,
26
+ y: (d - o - c) / d * i,
27
+ width: s / l * n,
28
+ height: c / d * i
26
29
  });
27
30
  }
28
31
  else {
29
- let e = await s.embedPng(await c);
30
- o.drawImage(e, {
32
+ let e = await u.embedPng(await s);
33
+ a.drawImage(e, {
31
34
  x: 0,
32
35
  y: 0,
33
36
  width: n,
@@ -35,6 +38,6 @@ async function i(i, a) {
35
38
  });
36
39
  }
37
40
  }
38
- return s.save();
41
+ return u.save();
39
42
  }
40
- export { i as exportRasterPdf };
43
+ export { a as exportRasterPdf };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ym-print/renderer-pdf",
3
- "version": "0.1.0-rc.2",
3
+ "version": "0.1.0-rc.3",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "exports": {
@@ -22,7 +22,7 @@
22
22
  "dependency-licenses.json"
23
23
  ],
24
24
  "dependencies": {
25
- "@ym-print/core": "0.1.0-rc.2",
25
+ "@ym-print/core": "0.1.0-rc.3",
26
26
  "pdf-lib": "1.17.1"
27
27
  },
28
28
  "license": "UNLICENSED",