vg-print 1.0.413 → 1.0.414
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/README.md +80 -1
- package/dist/chunk-MW6X4KTL-BVRq9FtF.js +87 -0
- package/dist/chunk-Q2Z2CG2I-DONVpEh7.js +8 -0
- package/dist/chunk-Y7FY32AO-S9q2Scd_.js +13 -0
- package/dist/download-m8kcgXF4.js +15 -0
- package/dist/index-DlSu6s5h.js +96305 -0
- package/dist/rasterize-34PCWURX-BTexhVJK.js +4 -0
- package/dist/style.css +1 -1
- package/dist/toBlob-B4chqTGf.js +4 -0
- package/dist/toCanvas-BbrxoG8s.js +4 -0
- package/dist/toImg-58cAJypF.js +27 -0
- package/dist/vg-print.es.js +30 -93264
- package/dist/vg-print.umd.js +298 -291
- package/package.json +2 -1
package/README.md
CHANGED
|
@@ -394,7 +394,7 @@ const designer = ref(null)
|
|
|
394
394
|
const preview = () => designer.value.preView()
|
|
395
395
|
// 浏览器打印
|
|
396
396
|
const printBrowser = () => designer.value.printView()
|
|
397
|
-
//
|
|
397
|
+
// 导出 PDF
|
|
398
398
|
const exportPdf = () => designer.value.toPdf()
|
|
399
399
|
// 导出图片
|
|
400
400
|
const exportImage = () => designer.value.toImage()
|
|
@@ -431,7 +431,10 @@ const disableAutoConnect = () => designer.value.disAutoConnect()
|
|
|
431
431
|
- `printView()` 浏览器打印;不依赖客户端,调起系统打印对话框
|
|
432
432
|
- `print()` 直接打印;需客户端已连接,按当前选定打印机输出
|
|
433
433
|
- `toPdf()` 导出 PDF;使用内置 A4 排版示例参数导出
|
|
434
|
+
- `toPdf2()` 导出 PDF;支持自定义参数,如缩放比例、页边距等(通过@zumer/snapdom库插件)
|
|
434
435
|
- `toImage()` 导出图片;使用内置 A4 排版示例参数导出
|
|
436
|
+
- `toImage2()` 导出图片;支持自定义参数,如缩放比例、页边距等(通过@zumer/snapdom库插件)
|
|
437
|
+
|
|
435
438
|
- `setHiwebSocket(host: string, token?: string, cb?: Function)` 设置客户端地址与令牌并尝试重连;`cb(status, msg)` 为连接回调
|
|
436
439
|
- `connect(cb?: Function)` 主动连接客户端;`cb(status, msg)` 为连接回调
|
|
437
440
|
- `disconnect()` 断开客户端连接
|
|
@@ -535,6 +538,15 @@ tpl.toPdf(this.printDataVar, '打印预览pdf', {
|
|
|
535
538
|
}
|
|
536
539
|
}
|
|
537
540
|
});
|
|
541
|
+
// 这是使用@zumer/snapdom库插件导出PDF的示例,使用方式和toPdf一样
|
|
542
|
+
tpl.toPdf2(this.printDataVar, '打印预览pdf', {
|
|
543
|
+
onProgress: (cur, total) => {
|
|
544
|
+
// 导出进度100%的时候关闭等待
|
|
545
|
+
if (cur === total) {
|
|
546
|
+
this.loading = false
|
|
547
|
+
}
|
|
548
|
+
}
|
|
549
|
+
});
|
|
538
550
|
|
|
539
551
|
// 导出图片(内置示例参数)
|
|
540
552
|
// 导出为多张图片,每张合成 6 页,自动下载 JPEG
|
|
@@ -571,6 +583,24 @@ tpl.toImage(this.printDataVar, {
|
|
|
571
583
|
}
|
|
572
584
|
}
|
|
573
585
|
})
|
|
586
|
+
|
|
587
|
+
// 这是使用@zumer/snapdom库插件导出图片的示例,使用方式和oImage一样
|
|
588
|
+
tpl.toImage2(this.printDataVar, {
|
|
589
|
+
paperWidth: 210,
|
|
590
|
+
paperHeight: 297,
|
|
591
|
+
limit: 6,
|
|
592
|
+
isDownload: true,
|
|
593
|
+
name: 'A4排版',
|
|
594
|
+
type: 'image/jpeg',
|
|
595
|
+
pixelRatio: 2,
|
|
596
|
+
onProgress: (cur, total) => {
|
|
597
|
+
console.log('toImage 进度', Math.floor((cur/total)*100))
|
|
598
|
+
// 导出进度100%的时候关闭等待
|
|
599
|
+
if (cur === total) {
|
|
600
|
+
this.loading = false
|
|
601
|
+
}
|
|
602
|
+
}
|
|
603
|
+
})
|
|
574
604
|
```
|
|
575
605
|
|
|
576
606
|
水印与授权行为说明:设计态与运行态分离。设计态不自动显示默认水印(由面板设置项决定);运行态按授权和面板内容合并控制。
|
|
@@ -585,7 +615,9 @@ import {
|
|
|
585
615
|
getHtml,
|
|
586
616
|
printBrowser,
|
|
587
617
|
exportPdf,
|
|
618
|
+
exportPdf2,
|
|
588
619
|
exportImage,
|
|
620
|
+
exportImage2,
|
|
589
621
|
getPrinterList,
|
|
590
622
|
refreshPrinterList,
|
|
591
623
|
getAddress,
|
|
@@ -643,6 +675,19 @@ exportPdf(tpl, printData, '打印预览pdf', {
|
|
|
643
675
|
}
|
|
644
676
|
})
|
|
645
677
|
|
|
678
|
+
// 插件方法
|
|
679
|
+
exportPdf2(tpl, printData, '打印预览pdf', {
|
|
680
|
+
paperWidth: 210,
|
|
681
|
+
paperHeight: 297,
|
|
682
|
+
scale: 2,
|
|
683
|
+
perPage: 6,
|
|
684
|
+
leftOffset:-1,
|
|
685
|
+
topOffset:-1,
|
|
686
|
+
onProgress: (cur: number, total: number) => {
|
|
687
|
+
console.log('toPdf 进度', Math.floor((cur/total)*100))
|
|
688
|
+
}
|
|
689
|
+
})
|
|
690
|
+
|
|
646
691
|
// 原生方法
|
|
647
692
|
await exportImage(tpl, printData, {
|
|
648
693
|
isDownload: true,
|
|
@@ -658,6 +703,20 @@ await exportImage(tpl, printData, {
|
|
|
658
703
|
}
|
|
659
704
|
})
|
|
660
705
|
|
|
706
|
+
// 插件方法
|
|
707
|
+
exportImage2(tpl, printData, {
|
|
708
|
+
paperWidth: 210,
|
|
709
|
+
paperHeight: 297,
|
|
710
|
+
limit: 6,
|
|
711
|
+
isDownload: true,
|
|
712
|
+
name: 'A4排版',
|
|
713
|
+
type: 'image/jpeg',
|
|
714
|
+
pixelRatio: 2,
|
|
715
|
+
onProgress: (cur: number, total: number) => {
|
|
716
|
+
console.log('toImage 进度', Math.floor((cur/total)*100))
|
|
717
|
+
}
|
|
718
|
+
})
|
|
719
|
+
|
|
661
720
|
// 6) 客户端直连打印(需要本地客户端)
|
|
662
721
|
setHiwebSocket('http://127.0.0.1:17521', 'your-token') // 遵循 autoConnect 状态
|
|
663
722
|
// 或者使用标准 API(设置即连接)
|
|
@@ -722,6 +781,10 @@ disconnect()
|
|
|
722
781
|
exportPdf(tpl, printData, '打印预览pdf', {
|
|
723
782
|
onProgress: (cur, total) => console.log('toPdf 进度', Math.floor((cur / total) * 100))
|
|
724
783
|
})
|
|
784
|
+
|
|
785
|
+
exportPdf2(tpl, printData, '打印预览pdf', {
|
|
786
|
+
onProgress: (cur, total) => console.log('toPdf 进度', Math.floor((cur / total) * 100))
|
|
787
|
+
})
|
|
725
788
|
```
|
|
726
789
|
|
|
727
790
|
#### 模式 B:排版导出(把小模板拼到大纸张,例如 A4)
|
|
@@ -740,6 +803,16 @@ exportPdf(tpl, printData, '打印预览pdf', {
|
|
|
740
803
|
scale: 2, // 清晰度/性能权衡(也可用 pixelRatio)
|
|
741
804
|
onProgress: (cur, total) => console.log('toPdf 进度', Math.floor((cur / total) * 100))
|
|
742
805
|
})
|
|
806
|
+
|
|
807
|
+
exportPdf2(tpl, printData, '打印预览pdf', {
|
|
808
|
+
paperWidth: 210, // mm
|
|
809
|
+
paperHeight: 297, // mm
|
|
810
|
+
perPage: 6, // 每页放 6 个(不够的到下一页)
|
|
811
|
+
leftOffset: -1, // -1 表示水平居中;>=0 表示左边距 mm
|
|
812
|
+
topOffset: -1, // -1 表示垂直居中;>=0 表示上边距 mm
|
|
813
|
+
scale: 2, // 清晰度/性能权衡(也可用 pixelRatio)
|
|
814
|
+
onProgress: (cur, total) => console.log('toPdf 进度', Math.floor((cur / total) * 100))
|
|
815
|
+
})
|
|
743
816
|
```
|
|
744
817
|
|
|
745
818
|
#### 排版规则(重点:perPage=0/不传的行为)
|
|
@@ -1256,6 +1329,9 @@ createApp(App).use(vgPrint).mount('#app')
|
|
|
1256
1329
|
- `printView()` Browser print
|
|
1257
1330
|
- `print()` Direct print
|
|
1258
1331
|
- `toPdf()` Export PDF
|
|
1332
|
+
- `toPdf2()` Export PDF with paper layout
|
|
1333
|
+
- `toImage()` Export Image
|
|
1334
|
+
- `toImage2()` Export Image with paper layout
|
|
1259
1335
|
- `toImage()` Export Image
|
|
1260
1336
|
- `setHiwebSocket(host, token, cb)` Set client address/token (Respects autoConnect state)
|
|
1261
1337
|
- `setHost(host, token, cb)` Set client address/token and connect immediately (Standard API)
|
|
@@ -1318,7 +1394,10 @@ exportPdf(tpl, printData, 'filename')
|
|
|
1318
1394
|
`exportPdf` / `exportImage` are lightweight wrappers around the template instance methods:
|
|
1319
1395
|
|
|
1320
1396
|
- `exportPdf(tpl, data, filename, options)` → `tpl.toPdf(data, filename, options)`
|
|
1397
|
+
- `exportPdf2(tpl, data, filename, options)` → `tpl.toPdf2(data, filename, options)`
|
|
1398
|
+
|
|
1321
1399
|
- `exportImage(tpl, data, options)` → `tpl.toImage(data, options)`
|
|
1400
|
+
- `exportImage2(tpl, data, options)` → `tpl.toImage2(data, options)`
|
|
1322
1401
|
|
|
1323
1402
|
#### Export PDF
|
|
1324
1403
|
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { l as b } from "./index-DlSu6s5h.js";
|
|
2
|
+
function M(e) {
|
|
3
|
+
return typeof e == "string" && /^data:image\/svg\+xml/i.test(e);
|
|
4
|
+
}
|
|
5
|
+
function C(e) {
|
|
6
|
+
let r = e.indexOf(",");
|
|
7
|
+
return r >= 0 ? decodeURIComponent(e.slice(r + 1)) : "";
|
|
8
|
+
}
|
|
9
|
+
function v(e) {
|
|
10
|
+
return `data:image/svg+xml;charset=utf-8,${encodeURIComponent(e)}`;
|
|
11
|
+
}
|
|
12
|
+
function F(e) {
|
|
13
|
+
let r = [], t = "", i = 0;
|
|
14
|
+
for (let o = 0; o < e.length; o++) {
|
|
15
|
+
let n = e[o];
|
|
16
|
+
n === "(" && i++, n === ")" && (i = Math.max(0, i - 1)), n === ";" && i === 0 ? (r.push(t), t = "") : t += n;
|
|
17
|
+
}
|
|
18
|
+
return t.trim() && r.push(t), r.map((o) => o.trim()).filter(Boolean);
|
|
19
|
+
}
|
|
20
|
+
function k(e) {
|
|
21
|
+
let r = [], t = "", i = 0;
|
|
22
|
+
for (let n = 0; n < e.length; n++) {
|
|
23
|
+
let s = e[n];
|
|
24
|
+
s === "(" && i++, s === ")" && (i = Math.max(0, i - 1)), s === "," && i === 0 ? (r.push(t.trim()), t = "") : t += s;
|
|
25
|
+
}
|
|
26
|
+
t.trim() && r.push(t.trim());
|
|
27
|
+
let o = [];
|
|
28
|
+
for (let n of r) {
|
|
29
|
+
if (/\binset\b/i.test(n)) continue;
|
|
30
|
+
let s = n.match(/-?\d+(?:\.\d+)?px/gi) || [], [l = "0px", a = "0px", m = "0px"] = s, u = n.replace(/-?\d+(?:\.\d+)?px/gi, "").replace(/\binset\b/ig, "").trim().replace(/\s{2,}/g, " "), d = !!u && u !== ",";
|
|
31
|
+
o.push(`drop-shadow(${l} ${a} ${m}${d ? ` ${u}` : ""})`);
|
|
32
|
+
}
|
|
33
|
+
return o.join(" ");
|
|
34
|
+
}
|
|
35
|
+
function y(e) {
|
|
36
|
+
let r = F(e), t = null, i = null, o = null, n = [];
|
|
37
|
+
for (let l of r) {
|
|
38
|
+
let a = l.indexOf(":");
|
|
39
|
+
if (a < 0) continue;
|
|
40
|
+
let m = l.slice(0, a).trim().toLowerCase(), u = l.slice(a + 1).trim();
|
|
41
|
+
m === "box-shadow" ? o = u : m === "filter" ? t = u : m === "-webkit-filter" ? i = u : n.push([m, u]);
|
|
42
|
+
}
|
|
43
|
+
if (o) {
|
|
44
|
+
let l = k(o);
|
|
45
|
+
l && (t = t ? `${t} ${l}` : l, i = i ? `${i} ${l}` : l);
|
|
46
|
+
}
|
|
47
|
+
let s = [...n];
|
|
48
|
+
return t && s.push(["filter", t]), i && s.push(["-webkit-filter", i]), s.map(([l, a]) => `${l}:${a}`).join(";");
|
|
49
|
+
}
|
|
50
|
+
function I(e) {
|
|
51
|
+
return e.replace(/([^{}]+)\{([^}]*)\}/g, (r, t, i) => `${t}{${y(i)}}`);
|
|
52
|
+
}
|
|
53
|
+
function N(e) {
|
|
54
|
+
return e = e.replace(/<style[^>]*>([\s\S]*?)<\/style>/gi, (r, t) => r.replace(t, I(t))), e = e.replace(/style=(['"])([\s\S]*?)\1/gi, (r, t, i) => `style=${t}${y(i)}${t}`), e;
|
|
55
|
+
}
|
|
56
|
+
function S(e) {
|
|
57
|
+
if (!b() || !M(e)) return e;
|
|
58
|
+
try {
|
|
59
|
+
let r = C(e), t = N(r);
|
|
60
|
+
return v(t);
|
|
61
|
+
} catch {
|
|
62
|
+
return e;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
async function R(e, r) {
|
|
66
|
+
let { width: t, height: i, scale: o = 1, dpr: n = 1, meta: s = {}, backgroundColor: l } = r;
|
|
67
|
+
e = S(e);
|
|
68
|
+
let a = new Image();
|
|
69
|
+
a.loading = "eager", a.decoding = "sync", a.crossOrigin = "anonymous", a.src = e, await a.decode();
|
|
70
|
+
let m = a.naturalWidth, u = a.naturalHeight, d = Number.isFinite(s.w0) ? s.w0 : m, x = Number.isFinite(s.h0) ? s.h0 : u, c, f, $ = Number.isFinite(t), w = Number.isFinite(i);
|
|
71
|
+
if ($ && w) c = Math.max(1, t), f = Math.max(1, i);
|
|
72
|
+
else if ($) {
|
|
73
|
+
let g = t / Math.max(1, d);
|
|
74
|
+
c = t, f = x * g;
|
|
75
|
+
} else if (w) {
|
|
76
|
+
let g = i / Math.max(1, x);
|
|
77
|
+
f = i, c = d * g;
|
|
78
|
+
} else c = m, f = u;
|
|
79
|
+
c = c * o, f = f * o;
|
|
80
|
+
let h = document.createElement("canvas");
|
|
81
|
+
h.width = c * n, h.height = f * n, h.style.width = `${c}px`, h.style.height = `${f}px`;
|
|
82
|
+
let p = h.getContext("2d");
|
|
83
|
+
return n !== 1 && p.scale(n, n), l && (p.save(), p.fillStyle = l, p.fillRect(0, 0, c, f), p.restore()), p.drawImage(a, 0, 0, c, f), h;
|
|
84
|
+
}
|
|
85
|
+
export {
|
|
86
|
+
R as W
|
|
87
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { W as a } from "./chunk-MW6X4KTL-BVRq9FtF.js";
|
|
2
|
+
async function o(r, t) {
|
|
3
|
+
let i = await a(r, t), e = new Image();
|
|
4
|
+
return e.src = i.toDataURL(`image/${t.format}`, t.quality), await e.decode(), e.style.width = `${i.width / t.dpr}px`, e.style.height = `${i.height / t.dpr}px`, e;
|
|
5
|
+
}
|
|
6
|
+
export {
|
|
7
|
+
o as d
|
|
8
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { W as m } from "./chunk-MW6X4KTL-BVRq9FtF.js";
|
|
2
|
+
async function a(n, e) {
|
|
3
|
+
let o = e.type;
|
|
4
|
+
if (o === "svg") {
|
|
5
|
+
let t = decodeURIComponent(n.split(",")[1]);
|
|
6
|
+
return new Blob([t], { type: "image/svg+xml" });
|
|
7
|
+
}
|
|
8
|
+
let i = await m(n, e);
|
|
9
|
+
return new Promise((t) => i.toBlob((l) => t(l), `image/${o}`, e.quality));
|
|
10
|
+
}
|
|
11
|
+
export {
|
|
12
|
+
a as m
|
|
13
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { m as f } from "./chunk-Y7FY32AO-S9q2Scd_.js";
|
|
2
|
+
import { W as t } from "./chunk-MW6X4KTL-BVRq9FtF.js";
|
|
3
|
+
async function w(n, e) {
|
|
4
|
+
let c = ((e == null ? void 0 : e.format) || (e == null ? void 0 : e.type) || "").toLowerCase(), a = c === "jpg" ? "jpeg" : c || "png", i = (e == null ? void 0 : e.filename) || `snapdom.${a}`, o = { ...e || {}, format: a, type: a };
|
|
5
|
+
if (o.dpr = 1, a === "svg") {
|
|
6
|
+
let d = await f(n, { ...o, type: "svg" }), l = URL.createObjectURL(d), m = document.createElement("a");
|
|
7
|
+
m.href = l, m.download = i, m.click(), URL.revokeObjectURL(l);
|
|
8
|
+
return;
|
|
9
|
+
}
|
|
10
|
+
let p = await t(n, o), r = document.createElement("a");
|
|
11
|
+
r.href = p.toDataURL(`image/${a}`, e == null ? void 0 : e.quality), r.download = i, r.click();
|
|
12
|
+
}
|
|
13
|
+
export {
|
|
14
|
+
w as download
|
|
15
|
+
};
|